summaryrefslogtreecommitdiff
path: root/src/python/include
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-06-19 20:29:46 +0200
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-06-19 20:29:46 +0200
commitdc9fc58500cc9f1be70e0d34a24cb634d4fc6c34 (patch)
tree950dc29ec544600ad94267fd442b10a15826a9e3 /src/python/include
parent3dd89cf0e7c47b98e150d32ede46e0f4514f5e2b (diff)
When 3d points are on a 2d plane case - Fixes also default_filtration_value=True in 3d
Diffstat (limited to 'src/python/include')
-rw-r--r--src/python/include/Alpha_complex_factory.h17
-rw-r--r--src/python/include/Alpha_complex_interface.h47
2 files changed, 38 insertions, 26 deletions
diff --git a/src/python/include/Alpha_complex_factory.h b/src/python/include/Alpha_complex_factory.h
index 69b584c5..7d98f454 100644
--- a/src/python/include/Alpha_complex_factory.h
+++ b/src/python/include/Alpha_complex_factory.h
@@ -48,7 +48,7 @@ static CgalPointType pt_cython_to_cgal(std::vector<double> const& vec) {
class Abstract_alpha_complex {
public:
virtual std::vector<double> get_point(int vh) = 0;
- virtual void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
+ virtual bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
bool default_filtration_value) = 0;
};
@@ -68,9 +68,9 @@ class Exact_Alphacomplex_dD : public Abstract_alpha_complex {
return pt_cgal_to_cython(point);
}
- void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
+ bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
bool default_filtration_value){
- alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value);
+ return alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value);
}
private:
@@ -93,9 +93,9 @@ class Inexact_Alphacomplex_dD : public Abstract_alpha_complex {
Point const& point = alpha_complex_.get_point(vh);
return pt_cgal_to_cython(point);
}
- void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
+ bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
bool default_filtration_value){
- alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value);
+ return alpha_complex_.create_complex(*simplex_tree, max_alpha_square, exact_version_, default_filtration_value);
}
private:
@@ -122,12 +122,9 @@ class Alphacomplex_3D : public Abstract_alpha_complex {
return pt_cgal_to_cython(point);
}
- void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
+ bool create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
bool default_filtration_value){
- alpha_complex_.create_complex(*simplex_tree, max_alpha_square);
- if (default_filtration_value) {
- // TODO
- }
+ return alpha_complex_.create_complex(*simplex_tree, max_alpha_square);
}
private:
diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h
index 0b946f8e..604ff85e 100644
--- a/src/python/include/Alpha_complex_interface.h
+++ b/src/python/include/Alpha_complex_interface.h
@@ -27,21 +27,10 @@ namespace alpha_complex {
class Alpha_complex_interface {
public:
- Alpha_complex_interface(const std::vector<std::vector<double>>& points, bool fast_version, bool exact_version) {
- if (points.size() > 0 && points[0].size() == 3) {
- if (fast_version)
- alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::FAST>>(points);
- else if (exact_version)
- alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::EXACT>>(points);
- else
- alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::SAFE>>(points);
- } else {
- if (fast_version) {
- alpha_ptr_ = std::make_unique<Inexact_Alphacomplex_dD>(points, exact_version);
- } else {
- alpha_ptr_ = std::make_unique<Exact_Alphacomplex_dD>(points, exact_version);
- }
- }
+ Alpha_complex_interface(const std::vector<std::vector<double>>& points, bool fast_version, bool exact_version)
+ : points_(points.begin(), points.end()),
+ fast_version_(fast_version),
+ exact_version_(exact_version) {
}
std::vector<double> get_point(int vh) {
@@ -50,11 +39,37 @@ class Alpha_complex_interface {
void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square,
bool default_filtration_value) {
- alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value);
+ if (points_.size() > 0) {
+ std::size_t dimension = points_[0].size();
+ if (dimension == 3 && !default_filtration_value) {
+ if (fast_version_)
+ alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::FAST>>(points_);
+ else if (exact_version_)
+ alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::EXACT>>(points_);
+ else
+ alpha_ptr_ = std::make_unique<Alphacomplex_3D<Gudhi::alpha_complex::complexity::SAFE>>(points_);
+ if (!alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value)) {
+ // create_simplex_tree will fail if all points are on a 2d plane - Retry with dimension 2
+ dimension--;
+ }
+ }
+ // Not ** else ** because we have to take into account if 3d fails
+ if (dimension != 3 || default_filtration_value) {
+ if (fast_version_) {
+ alpha_ptr_ = std::make_unique<Inexact_Alphacomplex_dD>(points_, exact_version_);
+ } else {
+ alpha_ptr_ = std::make_unique<Exact_Alphacomplex_dD>(points_, exact_version_);
+ }
+ alpha_ptr_->create_simplex_tree(simplex_tree, max_alpha_square, default_filtration_value);
+ }
+ }
}
private:
std::unique_ptr<Abstract_alpha_complex> alpha_ptr_;
+ std::vector<std::vector<double>> points_;
+ bool fast_version_;
+ bool exact_version_;
};
} // namespace alpha_complex