From 5ea1f5a9e96a3c937531516176cabc7226bed9da Mon Sep 17 00:00:00 2001 From: glisse Date: Tue, 6 Oct 2015 15:31:40 +0000 Subject: Introduce Options::contiguous_vertices. For now only used and checked in find_vertex. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/contiguous_vertices@833 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ceee8ba85eb21991a836b8f1d1117bcaafeb8c1b --- src/Simplex_tree/concept/SimplexTreeOptions.h | 2 ++ src/Simplex_tree/include/gudhi/Simplex_tree.h | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/concept/SimplexTreeOptions.h b/src/Simplex_tree/concept/SimplexTreeOptions.h index a50a2bf1..4a88f936 100644 --- a/src/Simplex_tree/concept/SimplexTreeOptions.h +++ b/src/Simplex_tree/concept/SimplexTreeOptions.h @@ -37,5 +37,7 @@ struct SimplexTreeOptions { static constexpr bool store_key; /// If true, each simplex has extra storage for one `Filtration_value`, and this value is propagated by operations like `Gudhi::Simplex_tree::expansion`. Without it, `Persistent_cohomology` degenerates to computing usual (non-persistent) cohomology. static constexpr bool store_filtration; + /// If true, the list of vertices present in the complex must always be 0, ..., num_vertices-1, without any hole. + static constexpr bool contiguous_vertices; }; diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 96565ff1..d19071fb 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -85,6 +85,7 @@ struct Simplex_tree_options_full_featured { typedef int Simplex_key; static const bool store_key = true; static const bool store_filtration = true; + static const bool contiguous_vertices = true; }; /** @@ -564,9 +565,21 @@ class Simplex_tree { /** \brief Returns the Simplex_handle corresponding to the 0-simplex * representing the vertex with Vertex_handle v. */ Simplex_handle find_vertex(Vertex_handle v) { - return root_.members_.begin() + v; + if (Options::contiguous_vertices) { + assert(contiguous_vertices()); + return root_.members_.begin() + v; + } else { + return root_.members_.find(v); + } + } + + /** \private \brief Test if the vertices have contiguous numbering: 0, 1, etc. */ + bool contiguous_vertices() const { + if(root_.members_.empty()) return true; + if(root_.members_.front()!=0) return false; + if(root_.members_.back()!=root_.members_.size()-1) return false; + return true; } - //{ return root_.members_.find(v); } private: /** \brief Inserts a simplex represented by a vector of vertex. -- cgit v1.2.3 From 82424630adfec94295157491a3379bc7888d5f12 Mon Sep 17 00:00:00 2001 From: glisse Date: Thu, 8 Oct 2015 12:28:13 +0000 Subject: Fix contiguous_vertices(). Use it in boundary iterator. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/contiguous_vertices@838 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5b4475f39fe6adf2190223a753625057260e8805 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 5 +++-- .../include/gudhi/Simplex_tree/Simplex_tree_iterators.h | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index d19071fb..30faebc8 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -573,11 +573,12 @@ class Simplex_tree { } } + public: /** \private \brief Test if the vertices have contiguous numbering: 0, 1, etc. */ bool contiguous_vertices() const { if(root_.members_.empty()) return true; - if(root_.members_.front()!=0) return false; - if(root_.members_.back()!=root_.members_.size()-1) return false; + if(root_.members_.begin()->first!=0) return false; + if(std::prev(root_.members_.end())->first!=root_.members_.size()-1) return false; return true; } diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index f83f5ea8..856fdbdd 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -135,14 +135,27 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< } Siblings * for_sib = sib_; - for (auto rit = suffix_.rbegin(); rit != suffix_.rend(); ++rit) { + Siblings * new_sib = sib_->oncles(); + auto rit = suffix_.rbegin(); + if (SimplexTree::Options::contiguous_vertices + && new_sib == nullptr + && rit != suffix_.rend()) { + // We reached the root, use a short-cut to find a vertex. We could also + // optimize finding the second vertex of a segment, but people are + // expected to call endpoints(). + assert(st_->contiguous_vertices()); + sh_ = for_sib->members_.begin()+*rit; + for_sib = sh_->second.children(); + ++rit; + } + for (; rit != suffix_.rend(); ++rit) { sh_ = for_sib->find(*rit); for_sib = sh_->second.children(); } sh_ = for_sib->find(last_); // sh_ points to the right simplex now suffix_.push_back(next_); next_ = sib_->parent(); - sib_ = sib_->oncles(); + sib_ = new_sib; } // Most of the storage should be moved to the range, iterators should be light. -- cgit v1.2.3 From ff6ad8b959f6c20380f3d68ebb1bbbf1224adcfd Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 13 Oct 2015 15:34:28 +0000 Subject: Manual merge of skb_simplex_insertion after last trunk big modifications on Skbl git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@855 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d7f7721e2963de439a28040196423d4c0df07d3f --- src/Contraction/example/Rips_contraction.cpp | 4 +- src/Contraction/include/gudhi/Edge_contraction.h | 4 +- .../include/gudhi/Skeleton_blocker_contractor.h | 11 +- src/GudhUI/model/Model.h | 6 +- src/GudhUI/utils/Is_manifold.h | 2 +- src/GudhUI/view/Viewer_instructor.cpp | 2 +- src/GudhUI/view/Viewer_instructor.h | 4 +- .../example/Skeleton_blocker_from_simplices.cpp | 29 +- .../example/Skeleton_blocker_iteration.cpp | 7 +- .../example/Skeleton_blocker_link.cpp | 2 +- .../include/gudhi/Skeleton_blocker.h | 33 +- .../Skeleton_blocker_complex_visitor.h | 10 +- .../Skeleton_blocker_link_superior.h | 6 +- .../Skeleton_blocker/Skeleton_blocker_off_io.h | 8 +- .../Skeleton_blocker_sub_complex.h | 24 +- .../include/gudhi/Skeleton_blocker/internal/Trie.h | 34 +- .../Skeleton_blockers_blockers_iterators.h | 4 +- .../Skeleton_blockers_simplices_iterators.h | 109 +- .../Skeleton_blockers_triangles_iterators.h | 18 +- .../include/gudhi/Skeleton_blocker_complex.h | 176 ++- .../gudhi/Skeleton_blocker_geometric_complex.h | 10 +- .../include/gudhi/Skeleton_blocker_link_complex.h | 53 +- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 92 +- src/Skeleton_blocker/test/TestGeometricComplex.cpp | 154 +- src/Skeleton_blocker/test/TestSimplifiable.cpp | 620 ++++---- .../test/TestSkeletonBlockerComplex.cpp | 1632 ++++++++++---------- 26 files changed, 1619 insertions(+), 1435 deletions(-) (limited to 'src') diff --git a/src/Contraction/example/Rips_contraction.cpp b/src/Contraction/example/Rips_contraction.cpp index d21246ed..f80cc2dc 100644 --- a/src/Contraction/example/Rips_contraction.cpp +++ b/src/Contraction/example/Rips_contraction.cpp @@ -49,7 +49,7 @@ void build_rips(ComplexType& complex, double offset) { for (auto p = vertices.begin(); p != vertices.end(); ++p) for (auto q = p; ++q != vertices.end(); /**/) { if (squared_dist(complex.point(*p), complex.point(*q)) < 4 * offset * offset) - complex.add_edge(*p, *q); + complex.add_edge_without_blockers(*p, *q); } } @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) { contractor.contract_edges(); std::cout << "Counting final number of simplices \n"; - unsigned num_simplices = std::distance(complex.simplex_range().begin(), complex.simplex_range().end()); + unsigned num_simplices = std::distance(complex.complex_simplex_range().begin(), complex.complex_simplex_range().end()); std::cout << "Final complex has " << complex.num_vertices() << " vertices, " << diff --git a/src/Contraction/include/gudhi/Edge_contraction.h b/src/Contraction/include/gudhi/Edge_contraction.h index dfce8d1b..b996d9fb 100644 --- a/src/Contraction/include/gudhi/Edge_contraction.h +++ b/src/Contraction/include/gudhi/Edge_contraction.h @@ -158,7 +158,7 @@ void build_rips(ComplexType& complex, double offset){ for (auto p = vertices.begin(); p != vertices.end(); ++p) for (auto q = p; ++q != vertices.end(); ) if (eucl_distance(complex.point(*p), complex.point(*q)) < 2 * offset) - complex.add_edge(*p,*q); + complex.add_edge_without_blockers(*p,*q); } int main (int argc, char *argv[]) @@ -194,7 +194,7 @@ int main (int argc, char *argv[]) contractor.contract_edges(); std::cout << "Counting final number of simplices \n"; - unsigned num_simplices = std::distance(complex.simplex_range().begin(),complex.simplex_range().end()); + unsigned num_simplices = std::distance(complex.star_simplex_range().begin(),complex.star_simplex_range().end()); std::cout << "Final complex has "<< complex.num_vertices()<<" vertices, "<< diff --git a/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h b/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h index 2759b540..d6350a2c 100644 --- a/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h +++ b/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h @@ -107,13 +107,8 @@ typename GeometricSimplifiableComplex::Vertex_handle> { public: typedef typename GeometricSimplifiableComplex::Graph_vertex Graph_vertex; typedef typename GeometricSimplifiableComplex::Vertex_handle Vertex_handle; - typedef typename GeometricSimplifiableComplex::Simplex_handle Simplex_handle; - typedef typename GeometricSimplifiableComplex::Simplex_handle_iterator Simplex_handle_iterator; - - - + typedef typename GeometricSimplifiableComplex::Simplex Simplex; typedef typename GeometricSimplifiableComplex::Root_vertex_handle Root_vertex_handle; - typedef typename GeometricSimplifiableComplex::Graph_edge Graph_edge; typedef typename GeometricSimplifiableComplex::Edge_handle Edge_handle; typedef typename GeometricSimplifiableComplex::Point Point; @@ -535,14 +530,14 @@ typename GeometricSimplifiableComplex::Vertex_handle> { * All the edges that passes through the blocker may be edge-contractible * again and are thus reinserted in the heap. */ - void on_delete_blocker(const Simplex_handle * blocker) override { + void on_delete_blocker(const Simplex * blocker) override { // we go for all pairs xy that belongs to the blocker // note that such pairs xy are necessarily edges of the complex // by definition of a blocker // todo uniqument utile pour la link condition // laisser a l'utilisateur ? booleen update_heap_on_removed_blocker? - Simplex_handle blocker_copy(*blocker); + Simplex blocker_copy(*blocker); for (auto x = blocker_copy.begin(); x != blocker_copy.end(); ++x) { for (auto y = x; ++y != blocker_copy.end();) { auto edge_descr(complex_[std::make_pair(*x, *y)]); diff --git a/src/GudhUI/model/Model.h b/src/GudhUI/model/Model.h index d78cbad9..07a67a0c 100644 --- a/src/GudhUI/model/Model.h +++ b/src/GudhUI/model/Model.h @@ -249,7 +249,7 @@ class Model { int euler = 0; int dimension = 0; Clock clock; - for (const auto &s : complex_.simplex_range()) { + for (const auto &s : complex_.complex_simplex_range()) { num_simplices++; dimension = (std::max)(s.dimension(), dimension); if (s.dimension() % 2 == 0) @@ -281,7 +281,7 @@ class Model { unsigned num_simplices = 0; int euler = 0; int dimension = 0; - for (const auto &s : complex_.simplex_range()) { + for (const auto &s : complex_.complex_simplex_range()) { num_simplices++; dimension = (std::max)(s.dimension(), dimension); if (s.dimension() % 2 == 0) @@ -328,7 +328,7 @@ class Model { void save_complex_in_file_for_chomp() { std::ofstream file; file.open("chomp.sim"); - for (const auto &s : complex_.simplex_range()) { + for (const auto &s : complex_.complex_simplex_range()) { bool first = true; file << "("; for (auto x : s) { diff --git a/src/GudhUI/utils/Is_manifold.h b/src/GudhUI/utils/Is_manifold.h index b6b19ee0..0640ea47 100644 --- a/src/GudhUI/utils/Is_manifold.h +++ b/src/GudhUI/utils/Is_manifold.h @@ -69,7 +69,7 @@ template class Is_manifold { private: unsigned local_dimension(Vertex_handle v) { unsigned dim = 0; - for (const auto& s : input_complex_.simplex_range(v)) + for (const auto& s : input_complex_.star_simplex_range(v)) dim = (std::max)(dim, (unsigned) s.dimension()); return dim; } diff --git a/src/GudhUI/view/Viewer_instructor.cpp b/src/GudhUI/view/Viewer_instructor.cpp index 4446d209..1ddd4d8b 100644 --- a/src/GudhUI/view/Viewer_instructor.cpp +++ b/src/GudhUI/view/Viewer_instructor.cpp @@ -159,7 +159,7 @@ void Viewer_instructor::set_color_edge(Edge_handle eh) { viewer_->set_color(Color(view_params_.light_edges, view_params_.light_edges, view_params_.light_edges)); } -void Viewer_instructor::set_color_triangle(const Simplex_handle& triangle) { +void Viewer_instructor::set_color_triangle(const Simplex& triangle) { viewer_->set_color(Color(view_params_.light_triangles, view_params_.light_triangles, view_params_.light_triangles)); } diff --git a/src/GudhUI/view/Viewer_instructor.h b/src/GudhUI/view/Viewer_instructor.h index 31a1d273..82c8e346 100644 --- a/src/GudhUI/view/Viewer_instructor.h +++ b/src/GudhUI/view/Viewer_instructor.h @@ -52,7 +52,7 @@ class Viewer_instructor : public QWidget { typedef Complex::Point Point; typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Edge_handle Edge_handle; - typedef Complex::Simplex_handle Simplex_handle; + typedef Complex::Simplex Simplex; Viewer* viewer_; View_parameter view_params_; @@ -98,7 +98,7 @@ class Viewer_instructor : public QWidget { void set_color_vertex(Vertex_handle vh); void set_color_edge(Edge_handle eh); - void set_color_triangle(const Simplex_handle& triangle); + void set_color_triangle(const Simplex& triangle); private: /** diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp index 2738c01c..5935a56d 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp @@ -35,24 +35,23 @@ using namespace skbl; typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; -typedef Complex::Simplex_handle Simplex_handle; -typedef Complex::Simplex_handle Simplex; +typedef Complex::Simplex Simplex; int main(int argc, char *argv[]) { - std::vector simplices; + std::vector simplices; // add 4 triangles of a tetrahedron 0123 - simplices.push_back(Simplex_handle(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); - simplices.push_back(Simplex_handle(Vertex_handle(3), Vertex_handle(0), Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(3), Vertex_handle(0), Vertex_handle(1))); + simplices.push_back(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); + simplices.push_back(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); + simplices.push_back(Simplex(Vertex_handle(3), Vertex_handle(0), Vertex_handle(2))); + simplices.push_back(Simplex(Vertex_handle(3), Vertex_handle(0), Vertex_handle(1))); // get complex from top faces Complex complex(make_complex_from_top_faces(simplices.begin(), simplices.end())); std::cout << "Simplices:" << std::endl; - for (const Simplex & s : complex.simplex_range()) + for (const Simplex & s : complex.complex_simplex_range()) std::cout << s << " "; std::cout << std::endl; @@ -61,16 +60,16 @@ int main(int argc, char *argv[]) { // now build a complex from its full list of simplices simplices.clear(); - simplices.push_back(Simplex_handle(Vertex_handle(0))); - simplices.push_back(Simplex_handle(Vertex_handle(1))); - simplices.push_back(Simplex_handle(Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(0), Vertex_handle(1))); - simplices.push_back(Simplex_handle(Vertex_handle(1), Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(2), Vertex_handle(0))); + simplices.push_back(Simplex(Vertex_handle(0))); + simplices.push_back(Simplex(Vertex_handle(1))); + simplices.push_back(Simplex(Vertex_handle(2))); + simplices.push_back(Simplex(Vertex_handle(0), Vertex_handle(1))); + simplices.push_back(Simplex(Vertex_handle(1), Vertex_handle(2))); + simplices.push_back(Simplex(Vertex_handle(2), Vertex_handle(0))); complex = Complex(simplices.begin(), simplices.end()); std::cout << "Simplices:" << std::endl; - for (const Simplex & s : complex.simplex_range()) + for (const Simplex & s : complex.complex_simplex_range()) std::cout << s << " "; std::cout << std::endl; diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp index 69557694..41b5ee00 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp @@ -37,7 +37,7 @@ using namespace skbl; typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; -typedef Complex::Simplex_handle Simplex; +typedef Complex::Simplex Simplex; Complex build_complete_complex(int n) { // build a full complex with n vertices and 2^n-1 simplices @@ -46,8 +46,7 @@ Complex build_complete_complex(int n) { complex.add_vertex(); for (int i = 0; i < n; i++) for (int j = 0; j < i; j++) - // note that add_edge, add the edge and all its cofaces - complex.add_edge(Vertex_handle(i), Vertex_handle(j)); + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); return complex; } @@ -77,7 +76,7 @@ int main(int argc, char *argv[]) { // we use a reference to a simplex instead of a copy // value here because a simplex is a set of integers // and copying it cost time - for (const Simplex & s : complex.simplex_range()) { + for (const Simplex & s : complex.complex_simplex_range()) { ++num_simplices; if (s.dimension() % 2 == 0) euler += 1; diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp index 002cbc49..5c717938 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp @@ -35,7 +35,7 @@ using namespace skbl; typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Root_vertex_handle Root_vertex_handle; -typedef Complex::Simplex_handle Simplex; +typedef Complex::Simplex Simplex; int main(int argc, char *argv[]) { // build a full complex with 4 vertices and 2^4-1 simplices diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h index 792a7994..e1f53f48 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h @@ -129,7 +129,7 @@ of a simplicial complex. \code{.cpp} typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; - typedef Complex::Simplex_handle Simplex; + typedef Complex::Simplex Simplex; const int n = 15; @@ -139,8 +139,7 @@ of a simplicial complex. complex.add_vertex(); for(int i=0;i simplices; + std::vector simplices; //add 4 triangles of a tetrahedron 0123 - simplices.push_back(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3))); - simplices.push_back(Simplex_handle(Vertex_handle(3),Vertex_handle(0),Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(3),Vertex_handle(0),Vertex_handle(1))); + simplices.push_back(Simplex(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); + simplices.push_back(Simplex(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3))); + simplices.push_back(Simplex(Vertex_handle(3),Vertex_handle(0),Vertex_handle(2))); + simplices.push_back(Simplex(Vertex_handle(3),Vertex_handle(0),Vertex_handle(1))); Complex complex; //get complex from top faces make_complex_from_top_faces(complex,simplices.begin(),simplices.end()); std::cout << "Simplices:"<(parent_complex, alpha_parent_adress, true) { } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h index ec000986..ad2d2f85 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h @@ -61,7 +61,7 @@ class Skeleton_blocker_off_flag_visitor_reader { if (!load_only_points_) { for (size_t i = 0; i < face.size(); ++i) for (size_t j = i + 1; j < face.size(); ++j) { - complex_.add_edge(Vertex_handle(face[i]), Vertex_handle(face[j])); + complex_.add_edge_without_blockers(Vertex_handle(face[i]), Vertex_handle(face[j])); } } } @@ -76,12 +76,12 @@ template class Skeleton_blocker_off_visitor_reader { Complex& complex_; typedef typename Complex::Vertex_handle Vertex_handle; - typedef typename Complex::Simplex_handle Simplex_handle; + typedef typename Complex::Simplex Simplex; typedef typename Complex::Point Point; const bool load_only_points_; std::vector points_; - std::vector maximal_faces_; + std::vector maximal_faces_; public: explicit Skeleton_blocker_off_visitor_reader(Complex& complex, bool load_only_points = false) : @@ -99,7 +99,7 @@ class Skeleton_blocker_off_visitor_reader { void maximal_face(const std::vector& face) { if (!load_only_points_) { - Simplex_handle s; + Simplex s; for (auto x : face) s.add_vertex(Vertex_handle(x)); maximal_faces_.emplace_back(s); diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h index b33b9606..50a83345 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h @@ -66,12 +66,12 @@ class Skeleton_blocker_sub_complex : public ComplexType { public: using ComplexType::add_vertex; - using ComplexType::add_edge; + using ComplexType::add_edge_without_blockers; using ComplexType::add_blocker; typedef typename ComplexType::Vertex_handle Vertex_handle; typedef typename ComplexType::Root_vertex_handle Root_vertex_handle; - typedef typename ComplexType::Simplex_handle Simplex_handle; + typedef typename ComplexType::Simplex Simplex; typedef typename ComplexType::Root_simplex_handle Root_simplex_handle; protected: @@ -109,11 +109,11 @@ class Skeleton_blocker_sub_complex : public ComplexType { * It assumes that both vertices corresponding to v1_root and v2_root are present * in the sub-complex. */ - void add_edge(Root_vertex_handle v1_root, Root_vertex_handle v2_root) { + void add_edge_without_blockers(Root_vertex_handle v1_root, Root_vertex_handle v2_root) { auto v1_sub(this->get_address(v1_root)); auto v2_sub(this->get_address(v2_root)); assert(v1_sub && v2_sub); - this->ComplexType::add_edge(*v1_sub, *v2_sub); + this->ComplexType::add_edge_without_blockers(*v1_sub, *v2_sub); } /** @@ -124,7 +124,7 @@ class Skeleton_blocker_sub_complex : public ComplexType { void add_blocker(const Root_simplex_handle& blocker_root) { auto blocker_sub = this->get_address(blocker_root); assert(blocker_sub); - this->add_blocker(new Simplex_handle(*blocker_sub)); + this->add_blocker(new Simplex(*blocker_sub)); } public: @@ -133,7 +133,7 @@ class Skeleton_blocker_sub_complex : public ComplexType { * vertices of 'simplex'. */ void make_restricted_complex(const ComplexType & parent_complex, - const Simplex_handle& simplex) { + const Simplex& simplex) { this->clear(); // add vertices to the sub complex for (auto x : simplex) { @@ -145,11 +145,11 @@ class Skeleton_blocker_sub_complex : public ComplexType { // add edges to the sub complex for (auto x : simplex) { // x_neigh is the neighbor of x intersected with vertices_simplex - Simplex_handle x_neigh; + Simplex x_neigh; parent_complex.add_neighbours(x, x_neigh, true); x_neigh.intersection(simplex); for (auto y : x_neigh) { - this->add_edge(parent_complex[x].get_id(), parent_complex[y].get_id()); + this->add_edge_without_blockers(parent_complex[x].get_id(), parent_complex[y].get_id()); } } @@ -158,9 +158,9 @@ class Skeleton_blocker_sub_complex : public ComplexType { // check if it is the first time we encounter the blocker if (simplex.contains(*blocker)) { Root_simplex_handle blocker_root(parent_complex.get_id(*(blocker))); - Simplex_handle blocker_restr( + Simplex blocker_restr( *(this->get_simplex_address(blocker_root))); - this->add_blocker(new Simplex_handle(blocker_restr)); + this->add_blocker(new Simplex(blocker_restr)); } } } @@ -188,7 +188,7 @@ class Skeleton_blocker_sub_complex : public ComplexType { // * Allocates a simplex in L corresponding to the simplex s in K // * with its local adresses and returns an AddressSimplex. // */ - // boost::optional get_address(const Root_simplex_handle & s) const; + // boost::optional get_address(const Root_simplex_handle & s) const; // private: /** @@ -220,7 +220,7 @@ bool proper_face_in_union( // we test that all vertices of 'addresses_sigma_in_link' but 'vertex_to_be_ignored' // are in link1 if it is the case we construct the corresponding simplex bool vertices_sigma_are_in_link = true; - typename ComplexType::Simplex_handle sigma_in_link; + typename ComplexType::Simplex sigma_in_link; for (int i = 0; i < addresses_sigma_in_link.size(); ++i) { if (i != vertex_to_be_ignored) { if (!addresses_sigma_in_link[i]) { diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h index aa0416ef..499980c4 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h @@ -36,7 +36,7 @@ namespace skbl { template struct Trie { - typedef SimplexHandle Simplex_handle; + typedef SimplexHandle Simplex; typedef typename SimplexHandle::Vertex_handle Vertex_handle; Vertex_handle v; @@ -64,7 +64,7 @@ struct Trie { } } - typedef typename Simplex_handle::Simplex_vertex_const_iterator Simplex_vertex_const_iterator; + typedef typename Simplex::Simplex_vertex_const_iterator Simplex_vertex_const_iterator; Trie* make_trie(Simplex_vertex_const_iterator s_it, Simplex_vertex_const_iterator s_end) { if (s_it == s_end) { @@ -97,7 +97,7 @@ struct Trie { return; } - void maximal_faces_helper(std::vector& res) const { + void maximal_faces_helper(std::vector& res) const { if (is_leaf()) res.push_back(simplex()); else for (auto child : childs) @@ -108,14 +108,14 @@ struct Trie { /** * adds the simplex to the trie */ - void add_simplex(const Simplex_handle& s) { + void add_simplex(const Simplex& s) { if (s.empty()) return; assert(v == s.first_vertex()); add_simplex_helper(s.begin(), s.end()); } - std::vector maximal_faces() const { - std::vector res; + std::vector maximal_faces() const { + std::vector res; maximal_faces_helper(res); return res; } @@ -123,14 +123,14 @@ struct Trie { /** * Goes to the root in the trie to consitute simplex */ - void add_vertices_up_to_the_root(Simplex_handle& res) const { + void add_vertices_up_to_the_root(Simplex& res) const { res.add_vertex(v); if (parent_) parent_->add_vertices_up_to_the_root(res); } - Simplex_handle simplex() const { - Simplex_handle res; + Simplex simplex() const { + Simplex res; add_vertices_up_to_the_root(res); return res; } @@ -156,7 +156,7 @@ struct Trie { /** * true iff the simplex corresponds to one node in the trie */ - bool contains(const Simplex_handle& s) const { + bool contains(const Simplex& s) const { Trie const* current = this; if (s.empty()) return true; if (current->v != s.first_vertex()) return false; @@ -196,9 +196,9 @@ struct Trie { template struct Tries { typedef typename SimplexHandle::Vertex_handle Vertex_handle; - typedef SimplexHandle Simplex_handle; + typedef SimplexHandle Simplex; - typedef Trie STrie; + typedef Trie STrie; template Tries(unsigned num_vertices, SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end) : @@ -218,14 +218,14 @@ struct Tries { // return a simplex that consists in all u such uv is an edge and u>v - Simplex_handle positive_neighbors(Vertex_handle v) const { - Simplex_handle res; + Simplex positive_neighbors(Vertex_handle v) const { + Simplex res; for (auto child : cofaces_[v]->childs) res.add_vertex(child->v); return res; } - bool contains(const Simplex_handle& s) const { + bool contains(const Simplex& s) const { auto first_v = s.first_vertex(); return cofaces_[first_v]->contains(s); } @@ -238,8 +238,8 @@ struct Tries { // init_next_dimension must be called first - std::vector next_dimension_simplices() const { - std::vector res; + std::vector next_dimension_simplices() const { + std::vector res; while (!to_see_.empty() && to_see_.front()->simplex().dimension() == current_dimension_) { res.emplace_back(to_see_.front()->simplex()); for (auto child : to_see_.front()->childs) diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h index 56a20a24..4a437ac6 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h @@ -31,7 +31,7 @@ namespace skbl { /** * @brief Iterator through the blockers of a vertex. */ -// ReturnType = const Simplex_handle* or Simplex_handle* +// ReturnType = const Simplex* or Simplex* // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator template @@ -83,7 +83,7 @@ ReturnType /** * @brief Iterator through the blockers of a vertex */ -// ReturnType = const Simplex_handle* or Simplex_handle* +// ReturnType = const Simplex* or Simplex* // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator template diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h index 4d71b3f5..ce565166 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h @@ -48,20 +48,20 @@ namespace skbl { template class Simplex_around_vertex_iterator : public boost::iterator_facade < Simplex_around_vertex_iterator -, typename SkeletonBlockerComplex::Simplex_handle +, typename SkeletonBlockerComplex::Simplex , boost::forward_traversal_tag -, typename SkeletonBlockerComplex::Simplex_handle +, typename SkeletonBlockerComplex::Simplex > { friend class boost::iterator_core_access; typedef SkeletonBlockerComplex Complex; typedef typename Complex::Vertex_handle Vertex_handle; typedef typename Complex::Edge_handle Edge_handle; - typedef typename Complex::Simplex_handle Simplex_handle; + typedef typename Complex::Simplex Simplex; // Link_vertex_handle == Complex_Vertex_handle but this renaming helps avoiding confusion typedef typename Link::Vertex_handle Link_vertex_handle; - typedef typename Gudhi::skbl::Trie Trie; + typedef typename Gudhi::skbl::Trie Trie; private: const Complex* complex; @@ -120,7 +120,7 @@ public boost::iterator_facade < Simplex_around_vertex_iteratorvertex_range(link_vh)) { if (link_vh < nv) { - Simplex_handle simplex_node_plus_nv(res->simplex()); + Simplex simplex_node_plus_nv(res->simplex()); simplex_node_plus_nv.add_vertex(parent_vertex(nv)); if (complex->contains(simplex_node_plus_nv)) { res->add_child(build_trie(nv, res)); @@ -176,13 +176,13 @@ public boost::iterator_facade < Simplex_around_vertex_iteratorsimplex(); } - Simplex_handle get_trie_address() const { + Simplex get_trie_address() const { assert(!nodes_to_be_seen.empty()); return nodes_to_be_seen.front(); } @@ -200,9 +200,9 @@ public boost::iterator_facade < Simplex_around_vertex_iterator class Simplex_iterator : public boost::iterator_facade < Simplex_iterator -, typename SkeletonBlockerComplex::Simplex_handle +, typename SkeletonBlockerComplex::Simplex , boost::forward_traversal_tag -, typename SkeletonBlockerComplex::Simplex_handle +, typename SkeletonBlockerComplex::Simplex > { typedef Skeleton_blocker_link_superior Link; @@ -213,7 +213,7 @@ public boost::iterator_facade < Simplex_iterator typedef SkeletonBlockerComplex Complex; typedef typename Complex::Vertex_handle Vertex_handle; typedef typename Complex::Edge_handle Edge_handle; - typedef typename Complex::Simplex_handle Simplex_handle; + typedef typename Complex::Simplex Simplex; typedef typename Complex::Complex_vertex_iterator Complex_vertex_iterator; typedef typename Link::Vertex_handle Link_vertex_handle; @@ -290,7 +290,7 @@ public boost::iterator_facade < Simplex_iterator } } - Simplex_handle dereference() const { + Simplex dereference() const { return current_simplex_around_current_vertex_.dereference(); } @@ -304,6 +304,93 @@ public boost::iterator_facade < Simplex_iterator } }; +/** + * Iterator through the maximal faces of the coboundary of a simplex. + */ +template +class Simplex_coboundary_iterator : +public boost::iterator_facade < Simplex_coboundary_iterator +, typename SkeletonBlockerComplex::Simplex, boost::forward_traversal_tag, typename SkeletonBlockerComplex::Simplex> { + friend class boost::iterator_core_access; + typedef SkeletonBlockerComplex Complex; + typedef typename Complex::Vertex_handle Vertex_handle; + typedef typename Complex::Edge_handle Edge_handle; + typedef typename Complex::Simplex Simplex; + typedef typename Complex::Complex_vertex_iterator Complex_vertex_iterator; + + // Link_vertex_handle == Complex_Vertex_handle but this renaming helps avoiding confusion + typedef typename Link::Vertex_handle Link_vertex_handle; + + private: + const Complex* complex; + const Simplex& sigma; + std::shared_ptr link; + Complex_vertex_iterator current_vertex; + Complex_vertex_iterator link_vertex_end; + + public: + Simplex_coboundary_iterator() : complex(0) {} + + Simplex_coboundary_iterator(const Complex* complex_, const Simplex& sigma_) : + complex(complex_), + sigma(sigma_), + //need only vertices of the link hence the true flag + link(new Link(*complex_, sigma_, false, true)) { + auto link_vertex_range = link->vertex_range(); + current_vertex = link_vertex_range.begin(); + link_vertex_end = link_vertex_range.end(); + } + + Simplex_coboundary_iterator(const Simplex_coboundary_iterator& other) : + complex(other.complex), + sigma(other.sigma), + link(other.link), + current_vertex(other.current_vertex), + link_vertex_end(other.link_vertex_end) { } + + // returns an iterator to the end + Simplex_coboundary_iterator(const Complex* complex_,const Simplex& sigma_, bool end) : + complex(complex_), + sigma(sigma_) { + // to represent an end iterator without having to build a useless link, we use + // the convection that link is not initialized. + } + + private: + Vertex_handle parent_vertex(Link_vertex_handle link_vh) const { + return complex->convert_handle_from_another_complex(*link, link_vh); + } + +public: + friend std::ostream& operator<<(std::ostream& stream, const Simplex_coboundary_iterator& sci) { + return stream; + } + + // assume that iterator points to the same complex and comes from the same simplex + bool equal(const Simplex_coboundary_iterator& other) const { + assert(complex == other.complex && sigma == other.sigma); + if(is_end()) return other.is_end(); + if(other.is_end()) return is_end(); + return *current_vertex == *(other.current_vertex); + } + + void increment() { + ++current_vertex; + } + + Simplex dereference() const { + Simplex res(sigma); + res.add_vertex(parent_vertex(*current_vertex)); + return res; + } + +private: + bool is_end() const { + return !link || current_vertex == link_vertex_end; + } +}; + + } // namespace skbl } // namespace Gudhi diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h index 28f5805d..116023d7 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h @@ -37,15 +37,15 @@ namespace skbl { template class Triangle_around_vertex_iterator : public boost::iterator_facade < Triangle_around_vertex_iterator -, typename Complex::Simplex_handle const +, typename Complex::Simplex const , boost::forward_traversal_tag -, typename Complex::Simplex_handle const> { +, typename Complex::Simplex const> { friend class boost::iterator_core_access; template friend class Triangle_iterator; private: typedef typename LinkType::Vertex_handle Vertex_handle; typedef typename LinkType::Root_vertex_handle Root_vertex_handle; - typedef typename LinkType::Simplex_handle Simplex_handle; + typedef typename LinkType::Simplex Simplex; typedef typename Complex::Complex_edge_iterator Complex_edge_iterator_; const Complex* complex_; @@ -87,10 +87,10 @@ class Triangle_around_vertex_iterator : public boost::iterator_facade return (complex_ == other.complex_) && ((finished() && other.finished()) || current_edge_ == other.current_edge_); } - Simplex_handle dereference() const { + Simplex dereference() const { Root_vertex_handle v1 = (*link_)[*current_edge_].first(); Root_vertex_handle v2 = (*link_)[*current_edge_].second(); - return Simplex_handle(v_, *(complex_->get_address(v1)), *(complex_->get_address(v2))); + return Simplex(v_, *(complex_->get_address(v1)), *(complex_->get_address(v2))); } void increment() { @@ -112,14 +112,14 @@ class Triangle_around_vertex_iterator : public boost::iterator_facade template class Triangle_iterator : public boost::iterator_facade< Triangle_iterator , -typename SkeletonBlockerComplex::Simplex_handle const +typename SkeletonBlockerComplex::Simplex const , boost::forward_traversal_tag -, typename SkeletonBlockerComplex::Simplex_handle const> { +, typename SkeletonBlockerComplex::Simplex const> { friend class boost::iterator_core_access; private: typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; typedef typename SkeletonBlockerComplex::Root_vertex_handle Root_vertex_handle; - typedef typename SkeletonBlockerComplex::Simplex_handle Simplex_handle; + typedef typename SkeletonBlockerComplex::Simplex Simplex; typedef typename SkeletonBlockerComplex::Superior_triangle_around_vertex_iterator STAVI; typedef typename SkeletonBlockerComplex::Complex_vertex_iterator Complex_vertex_iterator; @@ -175,7 +175,7 @@ typename SkeletonBlockerComplex::Simplex_handle const current_vertex_ == other.current_vertex_ && current_triangle_ == other.current_triangle_)); } - Simplex_handle dereference() const { + Simplex dereference() const { return *current_triangle_; } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index 07f371a2..78384abf 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -94,16 +94,16 @@ class Skeleton_blocker_complex { /** * @brief A ordered set of integers that represents a simplex. */ - typedef Skeleton_blocker_simplex Simplex_handle; + typedef Skeleton_blocker_simplex Simplex; typedef Skeleton_blocker_simplex Root_simplex_handle; /** * @brief Handle to a blocker of the complex. */ - typedef Simplex_handle* Blocker_handle; + typedef Simplex* Blocker_handle; typedef typename Root_simplex_handle::Simplex_vertex_const_iterator Root_simplex_iterator; - typedef typename Simplex_handle::Simplex_vertex_const_iterator Simplex_handle_iterator; + typedef typename Simplex::Simplex_vertex_const_iterator Simplex_handle_iterator; protected: typedef typename boost::adjacency_list::edge_descriptor Edge_handle; protected: - typedef std::multimap BlockerMap; - typedef typename std::multimap::value_type BlockerPair; - typedef typename std::multimap::iterator BlockerMapIterator; - typedef typename std::multimap::const_iterator BlockerMapConstIterator; + typedef std::multimap BlockerMap; + typedef typename std::multimap::value_type BlockerPair; + typedef typename std::multimap::iterator BlockerMapIterator; + typedef typename std::multimap::const_iterator BlockerMapConstIterator; protected: int num_vertices_; @@ -174,7 +174,7 @@ class Skeleton_blocker_complex { private: // typedef Trie> STrie; - typedef Trie STrie; + typedef Trie STrie; public: /** @@ -207,12 +207,12 @@ class Skeleton_blocker_complex { while (num_vertex-- >= 0) add_vertex(); for (const auto& e : edges) - add_edge(e.first, e.second); + add_edge_without_blockers(e.first, e.second); } template void add_blockers(SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end) { - Tries tries(num_vertices(), simplex_begin, simplex_end); + Tries tries(num_vertices(), simplex_begin, simplex_end); tries.init_next_dimension(); auto simplices(tries.next_dimension_simplices()); @@ -221,7 +221,7 @@ class Skeleton_blocker_complex { for (auto& sigma : simplices) { // common_positive_neighbors is the set of vertices u such that // for all s in sigma, us is an edge and u>s - Simplex_handle common_positive_neighbors(tries.positive_neighbors(sigma.last_vertex())); + Simplex common_positive_neighbors(tries.positive_neighbors(sigma.last_vertex())); for (auto sigma_it = sigma.rbegin(); sigma_it != sigma.rend(); ++sigma_it) if (sigma_it != sigma.rbegin()) common_positive_neighbors.intersection(tries.positive_neighbors(*sigma_it)); @@ -427,7 +427,7 @@ class Skeleton_blocker_complex { * @return true iff the simplicial complex contains all vertices * of simplex sigma */ - bool contains_vertices(const Simplex_handle & sigma) const { + bool contains_vertices(const Simplex & sigma) const { for (auto vertex : sigma) if (!contains_vertex(vertex)) return false; @@ -535,41 +535,68 @@ class Skeleton_blocker_complex { * @details it assumes that the edge is present in the complex */ - Simplex_handle get_vertices(Edge_handle edge_handle) const { + Simplex get_vertices(Edge_handle edge_handle) const { auto edge((*this)[edge_handle]); - return Simplex_handle((*this)[edge.first()], (*this)[edge.second()]); + return Simplex((*this)[edge.first()], (*this)[edge.second()]); } /** - * @brief Adds an edge between vertices a and b and all its cofaces. + * @brief Adds an edge between vertices a and b. + * @details For instance, the complex contains edge 01 and 12, then calling + * add_edge with vertex 0 and 2 will create a complex containing + * the edges 01, 12, 20 but not the triangle 012 (and hence this complex + * will contains a blocker 012). */ - Edge_handle add_edge(Vertex_handle a, Vertex_handle b) { + Edge_handle add_edge(Vertex_handle a, Vertex_handle b) { + //if the edge is already there we musnt go further + //as we may add blockers that should not be here + if(contains_edge(a,b)) + return *((*this)[std::make_pair(a,b)]); + auto res = add_edge_without_blockers(a,b); + add_blockers_after_simplex_insertion(Simplex(a,b)); + return res; + } + + /** + * @brief Adds all edges of s in the complex. + */ + void add_edge(const Simplex& s) { + for(auto i = s.begin(); i != s.end(); ++i) + for(auto j = i; ++j != s.end(); /**/) + add_edge(*i,*j); + } + + /** + * @brief Adds an edge between vertices a and b without blockers. + * @details For instance, the complex contains edge 01 and 12, then calling + * add_edge with vertex 0 and 2 will create a complex containing + * the triangle 012. + */ + Edge_handle add_edge_without_blockers(Vertex_handle a, Vertex_handle b) { assert(contains_vertex(a) && contains_vertex(b)); assert(a != b); auto edge_handle((*this)[std::make_pair(a, b)]); - // std::pair pair_descr_bool = (*this)[std::make_pair(a,b)]; - // Edge_handle edge_descr; - // bool edge_present = pair_descr_bool.second; if (!edge_handle) { edge_handle = boost::add_edge(a.vertex, b.vertex, skeleton).first; (*this)[*edge_handle].setId(get_id(a), get_id(b)); degree_[a.vertex]++; degree_[b.vertex]++; if (visitor) - visitor->on_add_edge(a, b); + visitor->on_add_edge_without_blockers(a, b); } return *edge_handle; } + /** - * @brief Adds all edges and their cofaces of a simplex to the simplicial complex. + * @brief Adds all edges of s in the complex without adding blockers. */ - void add_edges(const Simplex_handle & sigma) { - Simplex_handle_iterator i, j; - for (i = sigma.begin(); i != sigma.end(); ++i) - for (j = i, j++; j != sigma.end(); ++j) - add_edge(*i, *j); + void add_edge_without_blockers(Simplex s) { + for(auto i = s.begin(); i != s.end(); ++i){ + for(auto j = i; ++j != s.end(); /**/) + add_edge_without_blockers(*i,*j); + } } /** @@ -627,7 +654,7 @@ class Skeleton_blocker_complex { * @return true iff the simplicial complex contains all vertices * and all edges of simplex sigma */ - bool contains_edges(const Simplex_handle & sigma) const { + bool contains_edges(const Simplex & sigma) const { for (auto i = sigma.begin(); i != sigma.end(); ++i) { if (!contains_vertex(*i)) return false; @@ -649,15 +676,14 @@ class Skeleton_blocker_complex { * @brief Adds the simplex to the set of blockers and * returns a Blocker_handle toward it if was not present before and 0 otherwise. */ - Blocker_handle add_blocker(const Simplex_handle& blocker) { + Blocker_handle add_blocker(const Simplex& blocker) { assert(blocker.dimension() > 1); if (contains_blocker(blocker)) { - // std::cerr << "ATTEMPT TO ADD A BLOCKER ALREADY THERE ---> BLOCKER IGNORED" << endl; return 0; } else { if (visitor) visitor->on_add_blocker(blocker); - Blocker_handle blocker_pt = new Simplex_handle(blocker); + Blocker_handle blocker_pt = new Simplex(blocker); num_blockers_++; auto vertex = blocker_pt->begin(); while (vertex != blocker_pt->end()) { @@ -739,7 +765,7 @@ class Skeleton_blocker_complex { * * @remark contrarily to delete_blockers does not call the destructor */ - void remove_blocker(const Simplex_handle& sigma) { + void remove_blocker(const Simplex& sigma) { assert(contains_blocker(sigma)); for (auto vertex : sigma) remove_blocker(sigma, vertex); @@ -777,7 +803,7 @@ class Skeleton_blocker_complex { /** * @return true iff s is a blocker of the simplicial complex */ - bool contains_blocker(const Simplex_handle & s) const { + bool contains_blocker(const Simplex & s) const { if (s.dimension() < 2) return false; @@ -795,7 +821,7 @@ class Skeleton_blocker_complex { * @return true iff a blocker of the simplicial complex * is a face of sigma. */ - bool blocks(const Simplex_handle & sigma) const { + bool blocks(const Simplex & sigma) const { for (auto s : sigma) for (auto blocker : const_blocker_range(s)) if (sigma.contains(*blocker)) @@ -810,7 +836,7 @@ class Skeleton_blocker_complex { * @details Adds to simplex the neighbours of v e.g. \f$ n \leftarrow n \cup N(v) \f$. * If keep_only_superior is true then only vertices that are greater than v are added. */ - virtual void add_neighbours(Vertex_handle v, Simplex_handle & n, + virtual void add_neighbours(Vertex_handle v, Simplex & n, bool keep_only_superior = false) const { boost_adjacency_iterator ai, ai_end; for (tie(ai, ai_end) = adjacent_vertices(v.vertex, skeleton); ai != ai_end; @@ -833,7 +859,7 @@ class Skeleton_blocker_complex { * todo revoir * */ - virtual void add_neighbours(const Simplex_handle &alpha, Simplex_handle & res, + virtual void add_neighbours(const Simplex &alpha, Simplex & res, bool keep_only_superior = false) const { res.clear(); auto alpha_vertex = alpha.begin(); @@ -848,9 +874,9 @@ class Skeleton_blocker_complex { * not neighbours of v e.g. \f$ res \leftarrow res \cap N(v) \f$. * If 'keep_only_superior' is true then only vertices that are greater than v are keeped. */ - virtual void keep_neighbours(Vertex_handle v, Simplex_handle& res, + virtual void keep_neighbours(Vertex_handle v, Simplex& res, bool keep_only_superior = false) const { - Simplex_handle nv; + Simplex nv; add_neighbours(v, nv, keep_only_superior); res.intersection(nv); } @@ -860,9 +886,9 @@ class Skeleton_blocker_complex { * neighbours of v eg \f$ res \leftarrow res \setminus N(v) \f$. * If 'keep_only_superior' is true then only vertices that are greater than v are added. */ - virtual void remove_neighbours(Vertex_handle v, Simplex_handle & res, + virtual void remove_neighbours(Vertex_handle v, Simplex & res, bool keep_only_superior = false) const { - Simplex_handle nv; + Simplex nv; add_neighbours(v, nv, keep_only_superior); res.difference(nv); } @@ -874,7 +900,7 @@ class Skeleton_blocker_complex { * Constructs the link of 'simplex' with points coordinates. */ Link_complex link(Vertex_handle v) const { - return Link_complex(*this, Simplex_handle(v)); + return Link_complex(*this, Simplex(v)); } /** @@ -887,7 +913,7 @@ class Skeleton_blocker_complex { /** * Constructs the link of 'simplex' with points coordinates. */ - Link_complex link(const Simplex_handle& simplex) const { + Link_complex link(const Simplex& simplex) const { return Link_complex(*this, simplex); } @@ -899,11 +925,11 @@ class Skeleton_blocker_complex { */ // xxx rename get_address et place un using dans sub_complex - boost::optional get_simplex_address( + boost::optional get_simplex_address( const Root_simplex_handle& s) const { - boost::optional res; + boost::optional res; - Simplex_handle s_address; + Simplex s_address; // Root_simplex_const_iterator i; for (auto i = s.begin(); i != s.end(); ++i) { boost::optional address = get_address(*i); @@ -920,7 +946,7 @@ class Skeleton_blocker_complex { * @brief returns a simplex with vertices which are the id of vertices of the * argument. */ - Root_simplex_handle get_id(const Simplex_handle& local_simplex) const { + Root_simplex_handle get_id(const Simplex& local_simplex) const { Root_simplex_handle global_simplex; for (auto x = local_simplex.begin(); x != local_simplex.end(); ++x) { global_simplex.add_vertex(get_id(*x)); @@ -932,7 +958,7 @@ class Skeleton_blocker_complex { * @brief returns true iff the simplex s belongs to the simplicial * complex. */ - virtual bool contains(const Simplex_handle & s) const { + virtual bool contains(const Simplex & s) const { if (s.dimension() == -1) { return false; } else if (s.dimension() == 0) { @@ -1061,7 +1087,7 @@ class Skeleton_blocker_complex { * Furthermore, all simplices tau of the form sigma \setminus simplex_to_be_removed must be added * whenever the dimension of tau is at least 2. */ - void update_blockers_after_remove_star_of_vertex_or_edge(const Simplex_handle& simplex_to_be_removed); + void update_blockers_after_remove_star_of_vertex_or_edge(const Simplex& simplex_to_be_removed); public: /** @@ -1078,31 +1104,36 @@ class Skeleton_blocker_complex { /** * Remove the star of the simplex 'sigma' which needs to belong to the complex */ - void remove_star(const Simplex_handle& sigma); + void remove_star(const Simplex& sigma); /** - * @brief add a maximal simplex plus all its cofaces. - * @details the simplex must have dimension greater than one (otherwise use add_vertex or add_edge). + * @brief add a simplex. + * @details the simplex must have dimension greater than one (otherwise use add_vertex or add_edge_without_blockers). + * and all vertices lower than the higher vertex of sigma must already be in the complex. + * if some edges of sigma are not in the complex, then insert_edges_of_sigma flag must be + * set to true. */ - void add_simplex(const Simplex_handle& sigma); + void add_simplex(const Simplex& sigma, bool insert_edges_of_sigma = false); private: + void add_blockers_after_simplex_insertion(Simplex s); + /** * remove all blockers that contains sigma */ - void remove_blocker_containing_simplex(const Simplex_handle& sigma); + void remove_blocker_containing_simplex(const Simplex& sigma); /** * remove all blockers that contains sigma */ - void remove_blocker_include_in_simplex(const Simplex_handle& sigma); + void remove_blocker_include_in_simplex(const Simplex& sigma); public: enum simplifiable_status { NOT_HOMOTOPY_EQ, MAYBE_HOMOTOPY_EQ, HOMOTOPY_EQ }; - simplifiable_status is_remove_star_homotopy_preserving(const Simplex_handle& simplex) { + simplifiable_status is_remove_star_homotopy_preserving(const Simplex& simplex) { // todo write a virtual method 'link' in Skeleton_blocker_complex which will be overloaded by the current one of // Skeleton_blocker_geometric_complex // then call it there to build the link and return the value of link.is_contractible() @@ -1174,7 +1205,7 @@ class Skeleton_blocker_complex { * that may be used to construct a new blocker after contracting ab. * It requires that the link condition is satisfied. */ - void tip_blockers(Vertex_handle a, Vertex_handle b, std::vector & buffer) const; + void tip_blockers(Vertex_handle a, Vertex_handle b, std::vector & buffer) const; private: /** @@ -1217,7 +1248,7 @@ class Skeleton_blocker_complex { private: void get_blockers_to_be_added_after_contraction(Vertex_handle a, Vertex_handle b, - std::set& blockers_to_add); + std::set& blockers_to_add); /** * delete all blockers that passes through a or b */ @@ -1358,12 +1389,28 @@ class Skeleton_blocker_complex { /** * @brief Returns a Complex_simplex_around_vertex_range over all the simplices around a vertex of the complex */ - Complex_simplex_around_vertex_range simplex_range(Vertex_handle v) const { + Complex_simplex_around_vertex_range star_simplex_range(Vertex_handle v) const { assert(contains_vertex(v)); return Complex_simplex_around_vertex_range( Complex_simplex_around_vertex_iterator(this, v), Complex_simplex_around_vertex_iterator(this, v, true)); } + typedef Simplex_coboundary_iterator Complex_simplex_coboundary_iterator; + + /** + * @brief Range over the simplices of the coboundary of a simplex. + * Methods .begin() and .end() return a Complex_simplex_coboundary_iterator. + */ + typedef boost::iterator_range < Complex_simplex_coboundary_iterator > Complex_coboundary_range; + + /** + * @brief Returns a Complex_simplex_coboundary_iterator over the simplices of the coboundary of a simplex. + */ + Complex_coboundary_range coboundary_range(const Simplex& s) const { + assert(contains(s)); + return Complex_coboundary_range(Complex_simplex_coboundary_iterator(this, s), + Complex_simplex_coboundary_iterator(this, s, true)); + } // typedef Simplex_iterator Complex_simplex_iterator; typedef Simplex_iterator Complex_simplex_iterator; @@ -1373,7 +1420,7 @@ class Skeleton_blocker_complex { /** * @brief Returns a Complex_simplex_range over all the simplices of the complex */ - Complex_simplex_range simplex_range() const { + Complex_simplex_range complex_simplex_range() const { Complex_simplex_iterator end(this, true); if (empty()) { return Complex_simplex_range(end, end); @@ -1393,7 +1440,7 @@ class Skeleton_blocker_complex { * @brief Iterator over the blockers adjacent to a vertex */ typedef Blocker_iterator_around_vertex_internal< - typename std::multimap::iterator, + typename std::multimap::iterator, Blocker_handle> Complex_blocker_around_vertex_iterator; @@ -1401,7 +1448,7 @@ class Skeleton_blocker_complex { * @brief Iterator over (constant) blockers adjacent to a vertex */ typedef Blocker_iterator_around_vertex_internal< - typename std::multimap::const_iterator, + typename std::multimap::const_iterator, const Blocker_handle> Const_complex_blocker_around_vertex_iterator; @@ -1433,7 +1480,7 @@ class Skeleton_blocker_complex { * @brief Iterator over the blockers. */ typedef Blocker_iterator_internal< - typename std::multimap::iterator, + typename std::multimap::iterator, Blocker_handle> Complex_blocker_iterator; @@ -1441,7 +1488,7 @@ class Skeleton_blocker_complex { * @brief Iterator over the (constant) blockers. */ typedef Blocker_iterator_internal< - typename std::multimap::const_iterator, + typename std::multimap::const_iterator, const Blocker_handle> Const_complex_blocker_iterator; @@ -1517,8 +1564,9 @@ class Skeleton_blocker_complex { template Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, SimplexHandleIterator simplex_end, bool is_flag_complex = false) { - typedef typename Complex::Simplex_handle Simplex_handle; - std::vector simplices; + //todo use add_simplex instead! should be more efficient and more elegant :) + typedef typename Complex::Simplex Simplex; + std::vector simplices; for (auto top_face = simplex_begin; top_face != simplex_end; ++top_face) { auto subfaces_topface = subfaces(*top_face); simplices.insert(simplices.end(), subfaces_topface.begin(), subfaces_topface.end()); diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h index b8395251..5c898152 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h @@ -46,7 +46,7 @@ public Skeleton_blocker_complex { typedef typename SimplifiableSkeletonblocker::Vertex_handle Vertex_handle; typedef typename SimplifiableSkeletonblocker::Root_vertex_handle Root_vertex_handle; typedef typename SimplifiableSkeletonblocker::Edge_handle Edge_handle; - typedef typename SimplifiableSkeletonblocker::Simplex_handle Simplex_handle; + typedef typename SimplifiableSkeletonblocker::Simplex Simplex; typedef typename SimplifiableSkeletonblocker::Graph_vertex Graph_vertex; @@ -140,7 +140,7 @@ public Skeleton_blocker_complex { * Constructs the link of 'simplex' with points coordinates. */ Geometric_link link(Vertex_handle v) const { - Geometric_link link(*this, Simplex_handle(v)); + Geometric_link link(*this, Simplex(v)); // we now add the point info add_points_to_link(link); return link; @@ -149,7 +149,7 @@ public Skeleton_blocker_complex { /** * Constructs the link of 'simplex' with points coordinates. */ - Geometric_link link(const Simplex_handle& simplex) const { + Geometric_link link(const Simplex& simplex) const { Geometric_link link(*this, simplex); // we now add the point info add_points_to_link(link); @@ -172,13 +172,13 @@ public Skeleton_blocker_complex { * Constructs the abstract link of v (without points coordinates). */ Abstract_link abstract_link(Vertex_handle v) const { - return Abstract_link(*this, Simplex_handle(v)); + return Abstract_link(*this, Simplex(v)); } /** * Constructs the link of 'simplex' with points coordinates. */ - Abstract_link abstract_link(const Simplex_handle& simplex) const { + Abstract_link abstract_link(const Simplex& simplex) const { return Abstract_link(*this, simplex); } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h index 95d8fa97..85a6b0b5 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h @@ -52,12 +52,11 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< typedef typename ComplexType::Vertex_handle Vertex_handle; typedef typename ComplexType::Root_vertex_handle Root_vertex_handle; - typedef typename ComplexType::Simplex_handle Simplex_handle; + typedef typename ComplexType::Simplex Simplex; typedef typename ComplexType::Root_simplex_handle Root_simplex_handle; typedef typename ComplexType::Blocker_handle Blocker_handle; - typedef typename ComplexType::Simplex_handle::Simplex_vertex_const_iterator Simplex_handle_iterator; typedef typename ComplexType::Root_simplex_handle::Simplex_vertex_const_iterator Root_simplex_handle_iterator; explicit Skeleton_blocker_link_complex(bool only_superior_vertices = false) @@ -67,13 +66,15 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< /** * If the parameter only_superior_vertices is true, * only vertices greater than the one of alpha are added. + * Only vertices are computed if only_vertices is true. */ Skeleton_blocker_link_complex(const ComplexType & parent_complex, - const Simplex_handle& alpha_parent_adress, - bool only_superior_vertices = false) + const Simplex& alpha_parent_adress, + bool only_superior_vertices = false, + bool only_vertices = false) : only_superior_vertices_(only_superior_vertices) { if (!alpha_parent_adress.empty()) - build_link(parent_complex, alpha_parent_adress); + build_link(parent_complex, alpha_parent_adress, only_vertices); } /** @@ -84,7 +85,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< Vertex_handle a_parent_adress, bool only_superior_vertices = false) : only_superior_vertices_(only_superior_vertices) { - Simplex_handle alpha_simplex(a_parent_adress); + Simplex alpha_simplex(a_parent_adress); build_link(parent_complex, alpha_simplex); } @@ -96,7 +97,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< Edge_handle edge, bool only_superior_vertices = false) : only_superior_vertices_(only_superior_vertices) { - Simplex_handle alpha_simplex(parent_complex.first_vertex(edge), + Simplex alpha_simplex(parent_complex.first_vertex(edge), parent_complex.second_vertex(edge)); build_link(parent_complex, alpha_simplex); } @@ -108,7 +109,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< * are greater than vertices of alpha_parent_adress are added. */ void compute_link_vertices(const ComplexType & parent_complex, - const Simplex_handle& alpha_parent_adress, + const Simplex& alpha_parent_adress, bool only_superior_vertices, bool is_alpha_blocker = false) { if (alpha_parent_adress.dimension() == 0) { @@ -119,7 +120,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< only_superior_vertices_); } else { // we compute the intersection of neighbors of alpha and store it in link_vertices - Simplex_handle link_vertices_parent; + Simplex link_vertices_parent; parent_complex.add_neighbours(alpha_parent_adress, link_vertices_parent, only_superior_vertices); // For all vertex 'v' in this intersection, we go through all its adjacent blockers. @@ -162,13 +163,8 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< } void compute_link_edges(const ComplexType & parent_complex, - const Simplex_handle& alpha_parent_adress, + const Simplex& alpha_parent_adress, bool is_alpha_blocker = false) { - Simplex_handle_iterator y_link, x_parent, y_parent; - // ---------------------------- - // Compute edges in the link - // ------------------------- - if (this->num_vertices() <= 1) return; @@ -194,7 +190,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< } } if (new_edge) - this->add_edge(*x_link, *y_link); + this->add_edge_without_blockers(*x_link, *y_link); } } } @@ -217,7 +213,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< * the blocker is anticollapsed. */ void compute_link_blockers(const ComplexType & parent_complex, - const Simplex_handle& alpha_parent, + const Simplex& alpha_parent, bool is_alpha_blocker = false) { for (auto x_link : this->vertex_range()) { Vertex_handle x_parent = *this->give_equivalent_vertex(parent_complex, @@ -225,7 +221,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< for (auto blocker_parent : parent_complex.const_blocker_range(x_parent)) { if (!is_alpha_blocker || *blocker_parent != alpha_parent) { - Simplex_handle sigma_parent(*blocker_parent); + Simplex sigma_parent(*blocker_parent); sigma_parent.difference(alpha_parent); @@ -239,7 +235,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< for (auto a : alpha_parent) { for (auto eta_parent : parent_complex.const_blocker_range(a)) { if (!is_alpha_blocker || *eta_parent != alpha_parent) { - Simplex_handle eta_minus_alpha(*eta_parent); + Simplex eta_minus_alpha(*eta_parent); eta_minus_alpha.difference(alpha_parent); if (eta_minus_alpha != sigma_parent && sigma_parent.contains_difference(*eta_parent, @@ -253,7 +249,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< break; } if (is_new_blocker) - this->add_blocker(new Simplex_handle(*sigma_link)); + this->add_blocker(new Simplex(*sigma_link)); } } } @@ -268,14 +264,15 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< * with vertices that are greater than vertices of alpha_parent_adress. */ void build_link(const ComplexType & parent_complex, - const Simplex_handle& alpha_parent_adress, - bool is_alpha_blocker = false) { + const Simplex& alpha_parent_adress, + bool is_alpha_blocker = false, + bool only_vertices = false) { assert(is_alpha_blocker || parent_complex.contains(alpha_parent_adress)); - compute_link_vertices(parent_complex, alpha_parent_adress, - only_superior_vertices_); - compute_link_edges(parent_complex, alpha_parent_adress, is_alpha_blocker); - compute_link_blockers(parent_complex, alpha_parent_adress, - is_alpha_blocker); + compute_link_vertices(parent_complex, alpha_parent_adress, only_superior_vertices_); + if(!only_vertices) { + compute_link_edges(parent_complex, alpha_parent_adress, is_alpha_blocker); + compute_link_blockers(parent_complex, alpha_parent_adress, is_alpha_blocker); + } } /** @@ -284,7 +281,7 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< * removed from the blockers of the complex. */ friend void build_link_of_blocker(const ComplexType & parent_complex, - Simplex_handle& blocker, + Simplex& blocker, Skeleton_blocker_link_complex & result) { assert(blocker.dimension() >= 2); assert(parent_complex.contains_blocker(blocker)); diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h index 17a237a7..49a1ea8b 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -133,7 +133,7 @@ void Skeleton_blocker_complex::remove_all_popable_blockers(Ve template void Skeleton_blocker_complex::remove_star(Vertex_handle v) { // we remove the blockers that are not consistent anymore - update_blockers_after_remove_star_of_vertex_or_edge(Simplex_handle(v)); + update_blockers_after_remove_star_of_vertex_or_edge(Simplex(v)); while (this->degree(v) > 0) { Vertex_handle w(* (adjacent_vertices(v.vertex, this->skeleton).first)); this->remove_edge(v, w); @@ -148,7 +148,7 @@ void Skeleton_blocker_complex::remove_star(Vertex_handle v) { */ template void Skeleton_blocker_complex::update_blockers_after_remove_star_of_vertex_or_edge( - const Simplex_handle& simplex_to_be_removed) { + const Simplex& simplex_to_be_removed) { std::list blockers_to_update; if (simplex_to_be_removed.empty()) return; @@ -159,7 +159,7 @@ void Skeleton_blocker_complex::update_blockers_after_remove_s } for (auto blocker_to_update : blockers_to_update) { - Simplex_handle sub_blocker_to_be_added; + Simplex sub_blocker_to_be_added; bool sub_blocker_need_to_be_added = (blocker_to_update->dimension() - simplex_to_be_removed.dimension()) >= 2; if (sub_blocker_need_to_be_added) { @@ -178,7 +178,7 @@ void Skeleton_blocker_complex::update_blockers_after_remove_s */ template void Skeleton_blocker_complex::remove_star(Vertex_handle a, Vertex_handle b) { - update_blockers_after_remove_star_of_vertex_or_edge(Simplex_handle(a, b)); + update_blockers_after_remove_star_of_vertex_or_edge(Simplex(a, b)); // we remove the edge this->remove_edge(a, b); } @@ -195,7 +195,7 @@ void Skeleton_blocker_complex::remove_star(Edge_handle e) { * Remove the star of the simplex 'sigma' which needs to belong to the complex */ template -void Skeleton_blocker_complex::remove_star(const Simplex_handle& sigma) { +void Skeleton_blocker_complex::remove_star(const Simplex& sigma) { assert(this->contains(sigma)); if (sigma.dimension() == 0) { remove_star(sigma.first_vertex()); @@ -207,34 +207,36 @@ void Skeleton_blocker_complex::remove_star(const Simplex_hand } } -/** - * @brief add a maximal simplex plus all its cofaces. All vertices lower than the higher vertex of - * sigma must already be present. - * @details the simplex must have dimension greater than one (otherwise use add_vertex or add_edge). - */ template -void Skeleton_blocker_complex::add_simplex(const Simplex_handle& sigma) { +void Skeleton_blocker_complex::add_simplex(const Simplex& sigma, bool insert_edges_of_sigma) { + // to add a simplex s, all blockers included in s are first removed + // and then all simplex in the coboundary of s are added as blockers assert(!this->contains(sigma)); assert(sigma.dimension() > 1); + assert(contains_vertices(sigma)); - int num_vertex_to_add = 0; - for (auto v : sigma) - if (!contains_vertex(v)) ++num_vertex_to_add; - while (num_vertex_to_add--) add_vertex(); - - for (auto u_it = sigma.begin(); u_it != sigma.end(); ++u_it) - for (auto v_it = u_it; ++v_it != sigma.end(); /**/) { - // std::cout << "add edge" << *u_it << " " << *v_it << std::endl; - add_edge(*u_it, *v_it); - } + if(insert_edges_of_sigma) + add_edge(sigma); + else + assert(contains_edges(sigma)); remove_blocker_include_in_simplex(sigma); + add_blockers_after_simplex_insertion(sigma); +} + +template +void Skeleton_blocker_complex::add_blockers_after_simplex_insertion(Simplex sigma){ + if(sigma.dimension() < 1) return; + + for(auto s : coboundary_range(sigma)) { + this->add_blocker(s); + } } /** * remove all blockers that contains sigma */ template -void Skeleton_blocker_complex::remove_blocker_containing_simplex(const Simplex_handle& sigma) { +void Skeleton_blocker_complex::remove_blocker_containing_simplex(const Simplex& sigma) { std::vector blockers_to_remove; for (auto blocker : this->blocker_range(sigma.first_vertex())) { if (blocker->contains(sigma)) @@ -248,14 +250,26 @@ void Skeleton_blocker_complex::remove_blocker_containing_simp * remove all blockers that contains sigma */ template -void Skeleton_blocker_complex::remove_blocker_include_in_simplex(const Simplex_handle& sigma) { - std::vector blockers_to_remove; - for (auto blocker : this->blocker_range(sigma.first_vertex())) { - if (sigma.contains(*blocker)) - blockers_to_remove.push_back(blocker); +void Skeleton_blocker_complex::remove_blocker_include_in_simplex(const Simplex& sigma) { + //todo write efficiently by using only superior blockers + //eg for all s, check blockers whose vertices are all greater than s + std::set blockers_to_remove; + for(auto s : sigma) { + for (auto blocker : this->blocker_range(s)) { + if (sigma.contains(*blocker)) + blockers_to_remove.insert(blocker); + } } - for (auto blocker_to_update : blockers_to_remove) + for (auto blocker_to_update : blockers_to_remove) { + auto s = *blocker_to_update; this->delete_blocker(blocker_to_update); + //now if there is a vertex v in the link of s + //and v is not included in sigma then v.s is a blocker + //(all faces of v.s are there since v belongs to the link of s) + for(const auto& b : coboundary_range(s)) + if(!sigma.contains(b)) + this->add_blocker(b); + } } /** @@ -265,21 +279,21 @@ void Skeleton_blocker_complex::remove_blocker_include_in_simp */ template void Skeleton_blocker_complex::tip_blockers(Vertex_handle a, Vertex_handle b, - std::vector & buffer) const { + std::vector & buffer) const { for (auto const & blocker : this->const_blocker_range(a)) { - Simplex_handle beta = (*blocker); + Simplex beta = (*blocker); beta.remove_vertex(a); buffer.push_back(beta); } - Simplex_handle n; + Simplex n; this->add_neighbours(b, n); this->remove_neighbours(a, n); n.remove_vertex(a); for (Vertex_handle y : n) { - Simplex_handle beta; + Simplex beta; beta.add_vertex(y); buffer.push_back(beta); } @@ -296,7 +310,7 @@ void Skeleton_blocker_complex::tip_blockers(Vertex_handle a, template void Skeleton_blocker_complex::swap_edge(Vertex_handle a, Vertex_handle b, Vertex_handle x) { - this->add_edge(a, x); + this->add_edge_without_blockers(a, x); if (this->visitor) this->visitor->on_swaped_edge(a, b, x); this->remove_edge(b, x); } @@ -341,13 +355,13 @@ Skeleton_blocker_complex::contract_edge(Vertex_handle a, Vert assert(this->contains_vertex(b)); if (this->contains_edge(a, b)) - this->add_edge(a, b); + this->add_edge_without_blockers(a, b); // if some blockers passes through 'ab', we need to remove them. if (!link_condition(a, b)) delete_blockers_around_edge(a, b); - std::set blockers_to_add; + std::set blockers_to_add; get_blockers_to_be_added_after_contraction(a, b, blockers_to_add); @@ -369,7 +383,7 @@ Skeleton_blocker_complex::contract_edge(Vertex_handle a, Vert template void Skeleton_blocker_complex::get_blockers_to_be_added_after_contraction(Vertex_handle a, Vertex_handle b, - std::set& blockers_to_add) { + std::set& blockers_to_add) { blockers_to_add.clear(); typedef Skeleton_blocker_link_complex > LinkComplexType; @@ -377,19 +391,19 @@ Skeleton_blocker_complex::get_blockers_to_be_added_after_cont LinkComplexType link_a(*this, a); LinkComplexType link_b(*this, b); - std::vector vector_alpha, vector_beta; + std::vector vector_alpha, vector_beta; tip_blockers(a, b, vector_alpha); tip_blockers(b, a, vector_beta); for (auto alpha = vector_alpha.begin(); alpha != vector_alpha.end(); ++alpha) { for (auto beta = vector_beta.begin(); beta != vector_beta.end(); ++beta) { - Simplex_handle sigma = *alpha; + Simplex sigma = *alpha; sigma.union_vertices(*beta); Root_simplex_handle sigma_id = this->get_id(sigma); if (this->contains(sigma) && proper_faces_in_union> (sigma_id, link_a, link_b)) { - // Blocker_handle blocker = new Simplex_handle(sigma); + // Blocker_handle blocker = new Simplex(sigma); sigma.add_vertex(a); blockers_to_add.insert(sigma); } diff --git a/src/Skeleton_blocker/test/TestGeometricComplex.cpp b/src/Skeleton_blocker/test/TestGeometricComplex.cpp index bd7af89b..084e2b6b 100644 --- a/src/Skeleton_blocker/test/TestGeometricComplex.cpp +++ b/src/Skeleton_blocker/test/TestGeometricComplex.cpp @@ -1,24 +1,24 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): David Salinas - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include #include @@ -33,8 +33,8 @@ using namespace std; using namespace Gudhi; using namespace skbl; -struct Geometry_trait{ - typedef std::vector Point; +struct Geometry_trait { + typedef std::vector Point; }; typedef Geometry_trait::Point Point; @@ -42,79 +42,77 @@ typedef Skeleton_blocker_simple_geometric_traits Complex_geometr typedef Skeleton_blocker_geometric_complex< Complex_geometric_traits > Complex; typedef Complex::Vertex_handle Vertex_handle; +bool test_constructor1() { + Complex complex; + Skeleton_blocker_off_reader off_reader("test2.off", complex); + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file" << std::endl; + return false; + } -bool test_constructor1(){ - Complex complex; - Skeleton_blocker_off_reader off_reader("test2.off",complex); - if(!off_reader.is_valid()){ - std::cerr << "Unable to read file"< off_writer("tmp.off", complex); + Complex same; + Skeleton_blocker_off_reader off_reader2("tmp.off", same); - Skeleton_blocker_off_writer off_writer("tmp.off",complex); - Complex same; - Skeleton_blocker_off_reader off_reader2("tmp.off",same); + std::cout << "\ncomplex:" << complex.to_string() << endl; + std::cout << "\nsame:" << same.to_string() << endl; - std::cout<<"\ncomplex:"< off_reader("test2.off",complex); - if(!off_reader.is_valid()){ - std::cerr << "Unable to read file"< off_reader("test2.off", complex); + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file" << std::endl; + return false; + } + std::cout << "complex has " << + complex.num_vertices() << " vertices, " << + complex.num_blockers() << " blockers, " << + complex.num_edges() << " edges and" << + complex.num_triangles() << " triangles."; - if(complex.num_vertices()!=7 || complex.num_edges()!=12 || complex.num_triangles() !=6) - return false; + if (complex.num_vertices() != 7 || complex.num_edges() != 12 || complex.num_triangles() != 6) + return false; - auto link_0 = complex.abstract_link(Vertex_handle(0)); + auto link_0 = complex.abstract_link(Vertex_handle(0)); - std::cout<<"\n link(0):"<. - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include @@ -41,316 +41,382 @@ template class Skeleton_blocker_sub_complex; typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Root_vertex_handle Root_vertex_handle; -typedef Skeleton_blocker_simplex Simplex_handle; +typedef Skeleton_blocker_simplex Simplex; // true iff v \in complex -bool assert_vertex(Complex &complex,Vertex_handle v){ - Simplex_handle simplex(v); - bool test = complex.contains(simplex); - assert(test); - return test; + +bool assert_vertex(Complex &complex, Vertex_handle v) { + Simplex simplex(v); + bool test = complex.contains(simplex); + assert(test); + return test; } // true iff the blocker (a,b,c) is in complex -bool assert_blocker(Complex &complex,Root_vertex_handle a,Root_vertex_handle b,Root_vertex_handle c){ - return complex.contains_blocker(Simplex_handle(*complex.get_address(a),*complex.get_address(b),*complex.get_address(c))); - //return complex.contains_blocker((a),(b),(c)); +bool assert_blocker(Complex &complex, Root_vertex_handle a, Root_vertex_handle b, Root_vertex_handle c) { + + return complex.contains_blocker(Simplex(*complex.get_address(a), *complex.get_address(b), *complex.get_address(c))); + //return complex.contains_blocker((a),(b),(c)); } -void build_complete(int n,Complex& complex){ - complex.clear(); - for(int i=0;i(b), static_cast(z)); - complex.add_blocker(Simplex_handle(static_cast(a), static_cast(x), - static_cast(y))); - complex.add_blocker(Simplex_handle(static_cast(b), static_cast(x), - static_cast(y))); - - // Print result - cerr << "complex before complex"<< complex.to_string()<(a),static_cast(b)); - // Print result - cerr << "ContractEdge(0,1)\n"; - PRINT(complex.to_string()); - - // verification - for (int i=0;i<5;i++) - if (i!=1) assert_vertex(complex, static_cast(i)); - bool test1 = !complex.contains_edge(static_cast(a),static_cast(b)); - bool test2 = assert_blocker(complex,Root_vertex_handle(a),Root_vertex_handle(x),Root_vertex_handle(y)); - bool test3 = complex.num_edges()==6; - bool test4 = complex.num_blockers()==1; - Simplex_handle sigma; - sigma.add_vertex(static_cast(a)); - sigma.add_vertex(static_cast(x)); - sigma.add_vertex(static_cast(y)); - sigma.add_vertex(static_cast(z)); - bool test5 = !(complex.contains(sigma)); - return test1&&test2&&test3&&test4&&test5; +bool test_contraction1() { + + enum { + a, b, x, y, z, n + }; + Complex complex(n); + build_complete(n, complex); + complex.remove_edge(static_cast (b), static_cast (z)); + complex.add_blocker(Simplex(static_cast (a), static_cast (x), + static_cast (y))); + complex.add_blocker(Simplex(static_cast (b), static_cast (x), + static_cast (y))); + + // Print result + cerr << "complex before complex" << complex.to_string() << endl; + + cerr << endl << endl; + complex.contract_edge(static_cast (a), static_cast (b)); + // Print result + cerr << "ContractEdge(0,1)\n"; + PRINT(complex.to_string()); + + // verification + for (int i = 0; i < 5; i++) + if (i != 1) assert_vertex(complex, static_cast (i)); + bool test1 = !complex.contains_edge(static_cast (a), static_cast (b)); + bool test2 = assert_blocker(complex, Root_vertex_handle(a), Root_vertex_handle(x), Root_vertex_handle(y)); + bool test3 = complex.num_edges() == 6; + bool test4 = complex.num_blockers() == 1; + Simplex sigma; + sigma.add_vertex(static_cast (a)); + sigma.add_vertex(static_cast (x)); + sigma.add_vertex(static_cast (y)); + sigma.add_vertex(static_cast (z)); + bool test5 = !(complex.contains(sigma)); + return test1 && test2 && test3 && test4&&test5; } +bool test_contraction2() { -bool test_contraction2(){ - enum { a, b, x, y, z, n }; - Complex complex(n); - build_complete(n,complex); - complex.remove_edge(static_cast(b),static_cast(x)); - Simplex_handle blocker; - blocker.add_vertex(static_cast(a)); - blocker.add_vertex(static_cast(y)); - blocker.add_vertex(static_cast(z)); + enum { + a, b, x, y, z, n + }; + Complex complex(n); + build_complete(n, complex); + complex.remove_edge(static_cast (b), static_cast (x)); + Simplex blocker; + blocker.add_vertex(static_cast (a)); + blocker.add_vertex(static_cast (y)); + blocker.add_vertex(static_cast (z)); - complex.add_blocker(blocker); + complex.add_blocker(blocker); - // Print result - cerr << "complex complex"<< complex.to_string(); - cerr <(a),static_cast(b)); + // Print result + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + complex.contract_edge(static_cast (a), static_cast (b)); - cerr << "complex.ContractEdge(a,b)"<< complex.to_string(); + cerr << "complex.ContractEdge(a,b)" << complex.to_string(); - cerr <(a), static_cast(x), - static_cast(y),static_cast(z))); - test = test && complex.num_blockers()==1; - return test; + // there should be one blocker (a,c,d,e) in the complex + bool test; + test = complex.contains_blocker(Simplex(static_cast (a), static_cast (x), + static_cast (y), static_cast (z))); + test = test && complex.num_blockers() == 1; + return test; } -bool test_link_condition1(){ +bool test_link_condition1() { - Complex complex(0); - // Build the complexes - build_complete(4,complex); - complex.add_blocker(Simplex_handle(static_cast(0), static_cast(1), static_cast(2))); + Complex complex(0); + // Build the complexes + build_complete(4, complex); + complex.add_blocker(Simplex(static_cast (0), static_cast (1), static_cast (2))); - // Print result - cerr << "complex complex"<< complex.to_string(); - cerr <(2), static_cast(4)); - complex.add_edge(static_cast(3), static_cast(4)); - // Print result - cerr << "initial complex :\n"<< complex.to_string(); - cerr <(1), static_cast(2), static_cast(3)); - complex.remove_star(simplex_123); - cerr << "complex.remove_star(1,2,3):\n"<< complex.to_string(); - cerr < Ocomplex \n"; - return blocker123_here; +bool test_collapse0() { + Complex complex(5); + build_complete(4, complex); + complex.add_vertex(); + complex.add_edge_without_blockers(static_cast (2), static_cast (4)); + complex.add_edge_without_blockers(static_cast (3), static_cast (4)); + // Print result + cerr << "initial complex :\n" << complex.to_string(); + cerr << endl << endl; + + Simplex simplex_123(static_cast (1), static_cast (2), static_cast (3)); + complex.remove_star(simplex_123); + cerr << "complex.remove_star(1,2,3):\n" << complex.to_string(); + cerr << endl << endl; + + // verification + bool blocker123_here = complex.contains_blocker(simplex_123); + cerr << "----> Ocomplex \n"; + return blocker123_here; } - -bool test_collapse1(){ - Complex complex(5); - build_complete(4,complex); - complex.add_blocker(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2),Vertex_handle(3))); - // Print result - cerr << "initial complex :\n"<< complex.to_string(); - cerr < Ocomplex \n"; - return res; +bool test_collapse1() { + Complex complex(5); + build_complete(4, complex); + complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); + // Print result + cerr << "initial complex :\n" << complex.to_string(); + cerr << endl << endl; + + Simplex simplex_123(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + complex.remove_star(simplex_123); + cerr << "complex.remove_star(1,2,3):\n" << complex.to_string(); + cerr << endl << endl; + + // verification + bool res = complex.contains_blocker(simplex_123); + res = res && complex.num_blockers() == 1; + cerr << "----> Ocomplex \n"; + return res; } -bool test_collapse2(){ - Complex complex(5); - build_complete(4,complex); - complex.add_vertex(); - complex.add_edge(Vertex_handle(1),Vertex_handle(4)); - complex.add_edge(Vertex_handle(2),Vertex_handle(4)); - complex.add_edge(Vertex_handle(3),Vertex_handle(4)); - complex.add_blocker(Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3),Vertex_handle(4))); - // Print result - cerr << "initial complex :\n"<< complex.to_string(); - cerr <(2)); - cerr << "complex after remove star of 2:\n"<< complex.to_string(); - - bool blocker134_here = complex.contains_blocker(Simplex_handle(Vertex_handle(1),Vertex_handle(3),Vertex_handle(4))); - bool blocker1234_here = complex.contains_blocker(Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3),Vertex_handle(4))); - return blocker134_here && !blocker1234_here; +bool test_collapse3() { + Complex complex(5); + build_complete(4, complex); + complex.add_vertex(); + complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4)); + complex.add_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3), Vertex_handle(4))); + // Print result + cerr << "initial complex:\n" << complex.to_string(); + cerr << endl << endl; + + complex.remove_star(static_cast (2)); + cerr << "complex after remove star of 2:\n" << complex.to_string(); + + bool blocker134_here = complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(3), Vertex_handle(4))); + bool blocker1234_here = complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3), Vertex_handle(4))); + return blocker134_here && !blocker1234_here; } -bool test_add_simplex(){ - Complex complex(5); - build_complete(4,complex); - complex.add_blocker(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); - // Print result - cerr << "initial complex:\n"<< complex.to_string(); - cerr < simplices(complex.simplex_range().begin(),complex.simplex_range().end()); - sort(simplices.begin(),simplices.end(),[&](const Simplex_handle& s1,const Simplex_handle& s2){ - return s1.dimension()1) - copy.add_simplex(simplex); - } + std::vector simplices(complex.complex_simplex_range().begin(), complex.complex_simplex_range().end()); + sort(simplices.begin(), simplices.end(), [&](const Simplex& s1, const Simplex & s2) { + return s1.dimension() < s2.dimension(); + }); + for (const auto & simplex : simplices) { + if (!copy.contains(simplex) && simplex.dimension() == 1) + copy.add_edge_without_blockers(simplex.first_vertex(), simplex.last_vertex()); + if (!copy.contains(simplex) && simplex.dimension() > 1) + copy.add_simplex(simplex); + } - cerr << "complex after add_simplex:\n"<< copy.to_string(); + cerr << "complex after add_simplex:\n" << copy.to_string(); - return complex.num_blockers()==copy.num_blockers() && - complex.num_edges()==copy.num_edges() && - complex.num_vertices()==copy.num_vertices(); + return complex.num_blockers() == copy.num_blockers() && + complex.num_edges() == copy.num_edges() && + complex.num_vertices() == copy.num_vertices(); } +bool test_add_simplex3() { + Complex complex(5); + build_complete(5, complex); + complex.remove_edge(Vertex_handle(3), Vertex_handle(4)); + Simplex sigma(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2)); + complex.add_blocker(sigma); + // Print result + cerr << "initial complex:\n" << complex.to_string(); + cerr << endl << endl; + complex.add_simplex(sigma); + //should create two blockers 0123 and 0124 + cerr << "complex after adding simplex 012:\n" << complex.to_string(); + return complex.num_blockers() == 2 + && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))) + && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(4))); +} - -bool test_remove_popable_blockers(){ - Complex complex; - build_complete(4,complex); - complex.add_vertex(); - complex.add_edge(Vertex_handle(3),Vertex_handle(4)); - complex.add_edge(Vertex_handle(2),Vertex_handle(4)); - Simplex_handle sigma1=Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3)); - Simplex_handle sigma2=Simplex_handle(Vertex_handle(2),Vertex_handle(3),Vertex_handle(4)); - - complex.add_blocker(sigma1); - complex.add_blocker(sigma2); - cerr << "complex complex"<< complex.to_string(); - cerr < 0) + return false; + if (i >= 2 && complex.num_blockers() != 1) { + Simplex b; + for (int k = 0; k < i; k++) + b.add_vertex(Vertex_handle(i)); + if (!complex.contains_blocker(b)) + return false; + } + TESTVALUE(complex.blockers_to_string()); + } + Simplex s; + for (int k = 0; k < n; k++) + s.add_vertex(Vertex_handle(k)); + return complex.num_blockers() == 1 && complex.contains_blocker(s); } +bool test_add_edge() { + Complex complex(4); + for (unsigned i = 0u; i < 4; i++) + complex.add_edge(Vertex_handle(i), Vertex_handle((i + 1) % 4)); + + // Print result + cerr << "initial complex:\n" << complex.to_string(); + cerr << endl << endl; + complex.add_edge(Vertex_handle(1), Vertex_handle(3)); + //should create two blockers 013 and 012 + cerr << "complex after adding edge 13:\n" << complex.to_string(); + return complex.num_blockers() == 2 + && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(3))) + && complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); +} +bool test_remove_popable_blockers() { + Complex complex; + build_complete(4, complex); + complex.add_vertex(); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(4)); + Simplex sigma1 = Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + Simplex sigma2 = Simplex(Vertex_handle(2), Vertex_handle(3), Vertex_handle(4)); + + complex.add_blocker(sigma1); + complex.add_blocker(sigma2); + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + cerr << "complex.RemovePopableBlockers();" << endl; + complex.remove_popable_blockers(); + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + + bool test1 = (complex.num_blockers() == 1); + + + // test 2 + complex.clear(); + build_complete(4, complex); + complex.add_vertex(); + complex.add_vertex(); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(5)); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(5)); + complex.add_edge_without_blockers(Vertex_handle(4), Vertex_handle(5)); + sigma1 = Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + sigma2 = Simplex(Vertex_handle(2), Vertex_handle(3), Vertex_handle(4)); + + complex.add_blocker(sigma1); + complex.add_blocker(sigma2); + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + cerr << "complex.RemovePopableBlockers();" << endl; + complex.remove_popable_blockers(); + cerr << "complex complex" << complex.to_string(); + + cerr << endl << endl; + bool test2 = (complex.num_blockers() == 0); + return test1&&test2; +} -int main (int argc, char *argv[]) -{ - Tests tests_simplifiable_complex; - tests_simplifiable_complex.add("Test contraction 1",test_contraction1); - tests_simplifiable_complex.add("Test contraction 2",test_contraction2); - tests_simplifiable_complex.add("Test Link condition 1",test_link_condition1); - tests_simplifiable_complex.add("Test remove popable blockers",test_remove_popable_blockers); +int main(int argc, char *argv[]) { + Tests tests_simplifiable_complex; + tests_simplifiable_complex.add("Test contraction 1", test_contraction1); + tests_simplifiable_complex.add("Test contraction 2", test_contraction2); + tests_simplifiable_complex.add("Test Link condition 1", test_link_condition1); + tests_simplifiable_complex.add("Test remove popable blockers", test_remove_popable_blockers); - tests_simplifiable_complex.add("Test collapse 0",test_collapse0); - tests_simplifiable_complex.add("Test collapse 1",test_collapse1); - tests_simplifiable_complex.add("Test collapse 2",test_collapse2); - tests_simplifiable_complex.add("Test collapse 3",test_collapse3); + tests_simplifiable_complex.add("Test collapse 0", test_collapse0); + tests_simplifiable_complex.add("Test collapse 1", test_collapse1); + tests_simplifiable_complex.add("Test collapse 2", test_collapse2); + tests_simplifiable_complex.add("Test collapse 3", test_collapse3); - tests_simplifiable_complex.add("Test add simplex",test_add_simplex); - tests_simplifiable_complex.add("Test add simplex2",test_add_simplex2); + tests_simplifiable_complex.add("Test add edge",test_add_edge); + tests_simplifiable_complex.add("Test add simplex", test_add_simplex); + tests_simplifiable_complex.add("Test add simplex2", test_add_simplex2); + tests_simplifiable_complex.add("Test add simplex3",test_add_simplex3); + tests_simplifiable_complex.add("Test add simplex4",test_add_simplex4); - tests_simplifiable_complex.run(); + tests_simplifiable_complex.run(); - if(tests_simplifiable_complex.run()) - return EXIT_SUCCESS; - else - return EXIT_FAILURE; + if (tests_simplifiable_complex.run()) + return EXIT_SUCCESS; + else + return EXIT_FAILURE; } diff --git a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp index 319e3c43..418638e8 100644 --- a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp +++ b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp @@ -42,911 +42,893 @@ using namespace skbl; typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Root_vertex_handle Root_vertex_handle; -typedef Complex::Simplex_handle Simplex_handle; +typedef Complex::Simplex Simplex; typedef Complex::Root_simplex_handle Root_simplex_handle; -typedef Simplex_handle::Simplex_vertex_const_iterator Simplex_vertex_const_iterator; +typedef Simplex::Simplex_vertex_const_iterator Simplex_vertex_const_iterator; typedef Complex::Edge_handle Edge_handle; // true if v in complex -bool assert_vertex(Complex &complex,Vertex_handle v){ - //assert(complex.contains(v)); - return complex.contains(static_cast(v)); -} - -bool assert_simplex(Complex &complex,Root_vertex_handle a,Root_vertex_handle b,Root_vertex_handle c){ - return true; - // AddressSimplex simplex((a),(b),(c)); - // return complex.contains(&simplex); -} -// true iff the blocker (a,b,c) is in complex -bool assert_blocker(Complex &complex,Root_vertex_handle a,Root_vertex_handle b,Root_vertex_handle c){ - return true; - //return complex.contains_blocker((a),(b),(c)); +bool assert_vertex(Complex &complex, Vertex_handle v) { + //assert(complex.contains(v)); + return complex.contains(static_cast (v)); } -// true iff the blocker (a,b,c,d) is in complex -bool assert_blocker(Complex &complex,Root_vertex_handle a,Root_vertex_handle b,Root_vertex_handle c,Root_vertex_handle d){ - return true; - //Simplex blocker (a,b,c,d); - //return complex.contains_blocker(&blocker); -} - - - -void build_complete(int n,Complex& complex){ - complex.clear(); - for(int i=0;i=0;i--) - // for(int j=i-1;j>=0;j--) - // complex.add_edge(Vertex_handle(i),Vertex_handle(j)); - - for(int i=0;i expected_num_simplices; - - expected_num_simplices[Vertex_handle(0)] = 4; - expected_num_simplices[Vertex_handle(1)] = 6; - expected_num_simplices[Vertex_handle(2)] = 11; - expected_num_simplices[Vertex_handle(3)] = 9; - expected_num_simplices[Vertex_handle(4)] = 7; - expected_num_simplices[Vertex_handle(5)] = 7; - - for(auto pair : expected_num_simplices){ - unsigned num_simplices_around = 0; - for(const auto& simplex : complex.simplex_range(pair.first)){ - simplex.dimension(); - DBGVALUE(simplex); - ++num_simplices_around; - } - - correct_number_simplices = correct_number_simplices && (num_simplices_around == pair.second); - - DBGMSG("current vertex:",pair.first); - DBGMSG("expected_num_simplices:",pair.second); - DBGMSG("found:",num_simplices_around); - } - return correct_number_simplices; +bool assert_blocker(Complex &complex, Root_vertex_handle a, Root_vertex_handle b, Root_vertex_handle c) { + return true; + //return complex.contains_blocker((a),(b),(c)); } +// true iff the blocker (a,b,c,d) is in complex - -bool test_iterator_simplices2(){ - Complex complex(2); - complex.add_edge(Vertex_handle(0),Vertex_handle(1)); - - for(const auto& s:complex.triangle_range()){ - s.dimension(); - return false; // there are no triangles - } - - unsigned num_simplices = 0 ; - - - DBGVALUE(complex.to_string()); - - for(const auto& simplex : complex.simplex_range(Vertex_handle(0))){ - simplex.dimension(); - DBGVALUE(simplex); - } - - - for(const auto& simplex : complex.simplex_range()){ - DBGVALUE(simplex); - simplex.dimension(); - ++num_simplices; - } - bool correct_number_simplices = (num_simplices == 3); - return correct_number_simplices; +bool assert_blocker(Complex &complex, Root_vertex_handle a, Root_vertex_handle b, Root_vertex_handle c, Root_vertex_handle d) { + return true; + //Simplex blocker (a,b,c,d); + //return complex.contains_blocker(&blocker); +} + +void build_complete(int n, Complex& complex) { + complex.clear(); + for (int i = 0; i < n; i++) + complex.add_vertex(); + + // for(int i=n-1;i>=0;i--) + // for(int j=i-1;j>=0;j--) + // complex.add_edge_without_blockers(Vertex_handle(i),Vertex_handle(j)); + + for (int i = 0; i < n; i++) + for (int j = 0; j < i; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); +} + +bool test_simplex() { + // PRINT("test simplex"); + Simplex simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + for (auto i = simplex.begin(); i != simplex.end(); ++i) { + PRINT(*i); + auto j = i; + for (++j; + j != simplex.end(); + ++j) { + PRINT(*j); + } + } + return simplex.dimension() == 3; +} + +bool test_iterator_vertices1() { + int n = 10; + Complex complex(10); + cerr << "complex.num_vertices():" << complex.num_vertices() << endl; + int num_vertex_seen = 0; + for (auto vi : complex.vertex_range()) { + cerr << "vertex:" << vi << endl; + ++num_vertex_seen; + } + return num_vertex_seen == n; +} + +bool test_iterator_vertices2() { + int n = 10; + Complex complex(10); + build_complete(10, complex); + cerr << "complex.num_vertices():" << complex.num_vertices() << endl; + cerr << "complex.num_edges():" << complex.num_edges() << endl; + int num_vertex_seen = 0; + for (auto vi : complex.vertex_range(Vertex_handle(2))) { + cerr << "vertex:" << vi << endl; + ++num_vertex_seen; + } + std::cerr << "num_vertex_seen:" << num_vertex_seen << std::endl; + return num_vertex_seen == (n - 1); +} + +bool test_iterator_edge() { + const int n = 10; + Complex complex(n); + for (int i = 0; i < n; i++) + for (int j = 0; j < i; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); + complex.remove_edge(Vertex_handle(2), Vertex_handle(3)); + complex.remove_edge(Vertex_handle(3), Vertex_handle(5)); + cerr << "complex.num_edges():" << complex.num_edges() << endl; + int num_edges_seen = 0; + for (auto edge : complex.edge_range()) { + cerr << "edge :" << complex[edge] << endl; + ++num_edges_seen; + } + + return num_edges_seen == n * (n - 1) / 2 - 2; +} + +bool test_iterator_edge2() { + const int n = 10; + Complex complex(n); + for (int i = 0; i < n; i++) + for (int j = 0; j < i; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); + complex.remove_edge(Vertex_handle(2), Vertex_handle(3)); + complex.remove_edge(Vertex_handle(3), Vertex_handle(5)); + cerr << "complex.num_edges():" << complex.num_edges() << endl; + int num_neigbors_seen = 0; + for (auto neighbor : complex.vertex_range(Vertex_handle(2))) { + cerr << "neighbor" << neighbor << endl; + ++num_neigbors_seen; + } + return num_neigbors_seen == 8; +} + +bool test_iterator_edge3() { + const int n = 10; + Complex complex(n); + for (int i = 0; i < n; i++) + for (int j = 0; j < i; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); + complex.remove_edge(Vertex_handle(2), Vertex_handle(3)); + complex.remove_edge(Vertex_handle(3), Vertex_handle(5)); + cerr << "complex.num_edges():" << complex.num_edges() << endl; + int num_neigbors_seen = 0; + for (auto edge : complex.edge_range(Vertex_handle(2))) { + std::cerr << edge << std::endl; + ++num_neigbors_seen; + } + return num_neigbors_seen == 8; +} + +bool test_iterator_triangles() { + const int n = 7; + Complex complex(n); + //create a "ring" around '0' + for (int i = 1; i < n; i++) + complex.add_edge_without_blockers(Vertex_handle(0), Vertex_handle(i)); + for (int i = 1; i < n - 1; i++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(i + 1)); + complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(6)); + + PRINT(complex.to_string()); + + int num_triangles_seen = 0; + //for (auto t : complex.triangle_range(5)){ + TEST("triangles around 5 (should be 2 of them):"); + for (auto t : complex.triangle_range(Vertex_handle(5))) { + PRINT(t); + ++num_triangles_seen; + } + bool test = (num_triangles_seen == 2); + + num_triangles_seen = 0; + TEST("triangles around 0 (should be 6 of them):"); + for (auto t : complex.triangle_range(Vertex_handle(0))) { + PRINT(t); + ++num_triangles_seen; + } + test = test && (num_triangles_seen == 6); + + // we now add another triangle + complex.add_vertex(); + complex.add_edge_without_blockers(Vertex_handle(4), Vertex_handle(7)); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(7)); + complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(6))); + num_triangles_seen = 0; + + TEST("triangles (should be 6 of them):"); + num_triangles_seen = 0; + for (auto t : complex.triangle_range()) { + PRINT(t); + ++num_triangles_seen; + } + test = test && (num_triangles_seen == 6); + PRINT(num_triangles_seen); + + return test; } -bool test_iterator_simplices3(){ - Complex complex(3); - complex.add_edge(Vertex_handle(0),Vertex_handle(1)); - complex.add_edge(Vertex_handle(1),Vertex_handle(2)); - complex.add_edge(Vertex_handle(2),Vertex_handle(0)); - complex.add_blocker(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); - - unsigned num_simplices = 0 ; - - for(const auto& simplex : complex.simplex_range(Vertex_handle(0))){ - simplex.dimension(); - DBGVALUE(simplex); - } - +//#include "combinatorics/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h" - for(const auto& simplex : complex.simplex_range()){ - DBGVALUE(simplex); - simplex.dimension(); - ++num_simplices; - } - bool correct_number_simplices = (num_simplices == 6); - return correct_number_simplices; +bool test_iterator_simplices() { + Complex complex(6); + complex.add_edge_without_blockers(Vertex_handle(0), Vertex_handle(1)); + complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(2)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(0)); + complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(3)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(3)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(5)); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(5)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(4), Vertex_handle(5)); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4)); + + complex.add_blocker(Simplex(Vertex_handle(2), Vertex_handle(3), Vertex_handle(4), Vertex_handle(5))); + + bool correct_number_simplices = true; + + std::map expected_num_simplices; + + expected_num_simplices[Vertex_handle(0)] = 4; + expected_num_simplices[Vertex_handle(1)] = 6; + expected_num_simplices[Vertex_handle(2)] = 11; + expected_num_simplices[Vertex_handle(3)] = 9; + expected_num_simplices[Vertex_handle(4)] = 7; + expected_num_simplices[Vertex_handle(5)] = 7; + + for (auto pair : expected_num_simplices) { + unsigned num_simplices_around = 0; + for (const auto& simplex : complex.star_simplex_range(pair.first)) { + simplex.dimension(); + DBGVALUE(simplex); + ++num_simplices_around; + } + + correct_number_simplices = correct_number_simplices && (num_simplices_around == pair.second); + + DBGMSG("current vertex:", pair.first); + DBGMSG("expected_num_simplices:", pair.second); + DBGMSG("found:", num_simplices_around); + } + return correct_number_simplices; +} + +bool test_iterator_simplices2() { + Complex complex(2); + complex.add_edge_without_blockers(Vertex_handle(0), Vertex_handle(1)); + + for (const auto& s : complex.triangle_range()) { + s.dimension(); + return false; // there are no triangles + } + + unsigned num_simplices = 0; + + + DBGVALUE(complex.to_string()); + + for (const auto& simplex : complex.star_simplex_range(Vertex_handle(0))) { + simplex.dimension(); + DBGVALUE(simplex); + } + + + for (const auto& simplex : complex.complex_simplex_range()) { + DBGVALUE(simplex); + simplex.dimension(); + ++num_simplices; + } + bool correct_number_simplices = (num_simplices == 3); + return correct_number_simplices; +} + +bool test_iterator_simplices3() { + Complex complex(3); + complex.add_edge_without_blockers(Vertex_handle(0), Vertex_handle(1)); + complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(2)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(0)); + complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); + + unsigned num_simplices = 0; + + for (const auto& simplex : complex.star_simplex_range(Vertex_handle(0))) { + simplex.dimension(); + DBGVALUE(simplex); + } + + + for (const auto& simplex : complex.complex_simplex_range()) { + DBGVALUE(simplex); + simplex.dimension(); + ++num_simplices; + } + bool correct_number_simplices = (num_simplices == 6); + return correct_number_simplices; +} + +bool test_iterator_simplices4() { + Complex empty_complex; + for (auto v : empty_complex.vertex_range()) { + (void) v; + } + for (auto e : empty_complex.edge_range()) { + empty_complex[e]; + } + for (auto t : empty_complex.triangle_range()) { + t.dimension(); + } + for (auto s : empty_complex.complex_simplex_range()) { + s.dimension(); + } + return true; } -bool test_iterator_simplices4(){ - Complex empty_complex; - for(auto v : empty_complex.vertex_range()){ - (void) v; - } - for(auto e : empty_complex.edge_range()){ - empty_complex[e]; - } - for(auto t : empty_complex.triangle_range()){ - t.dimension(); - } - for(auto s : empty_complex.simplex_range()){ - s.dimension(); - } - return true; +bool test_iterator_coboundary() { + Complex c(4); + build_complete(4, c); + c.remove_edge(Vertex_handle(0), Vertex_handle(2)); + PRINT(c.to_string()); + Simplex s02(Vertex_handle(0), Vertex_handle(2)); + int n = 0; + std::set expected; + expected.insert(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); + expected.insert(Simplex(Vertex_handle(0), Vertex_handle(2), Vertex_handle(3))); + for (const auto & s : c.coboundary_range(s02)) { + PRINT(s); + if (expected.find(s) == expected.end()) + return false; + ++n; + } + return n == 2; } - template -auto blocker_range(Map map) -> decltype( map | boost::adaptors::map_values){ - return map| boost::adaptors::map_values ; -} - - -bool test_iterator_blockers(){ - Complex complex; - Simplex_handle alpha; - Simplex_handle vertex_set_expected; - // Build the complexes - for (int i=0;i<20;i++){ - complex.add_vertex(); - } - for (int i=10;i<15;i++){ - for (int j=i+1;j<15;j++) - complex.add_edge(Vertex_handle(i),Vertex_handle(j)); - } - - complex.add_blocker(Simplex_handle(Vertex_handle(10),Vertex_handle(11),Vertex_handle(12))); - complex.add_blocker(Simplex_handle(Vertex_handle(2),Vertex_handle(1),Vertex_handle(10))); - complex.add_blocker(Simplex_handle(Vertex_handle(10),Vertex_handle(9),Vertex_handle(15))); - complex.add_blocker(Simplex_handle(Vertex_handle(1),Vertex_handle(9),Vertex_handle(8))); - - // Print result - int num_blockers=0; - for(auto blockers : complex.blocker_range(Vertex_handle(10))){ - TESTVALUE(*blockers) ; - num_blockers++; - } - bool test = (num_blockers==3); - - num_blockers=0; - for (auto blockers : complex.blocker_range()){ - TESTVALUE(*blockers) ; - num_blockers++; - } - test = test && (num_blockers==4) ; - - return test; -} - - -bool test_link0(){ - - enum { a, b, c, d, n }; - Complex complex(n); - complex.add_edge(Vertex_handle(b),Vertex_handle(c));complex.add_edge(Vertex_handle(c),Vertex_handle(d)); - Simplex_handle alpha = Simplex_handle(Vertex_handle(c)); - Skeleton_blocker_link_complex L(complex,alpha); - - auto L2 = complex.link(alpha); - if(L!=L2) return false; - - PRINT(L.num_vertices()); - PRINT(L.to_string()); - - bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(b))); - bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(d))); - bool test3 = L.num_edges()==0; - bool test4 = L.num_blockers()==0; - return test1&&test2&&test3&&test4; - -} - -bool test_link1(){ - Complex complex; - - - // Build the complexes - for (int i=0;i<20;i++){ - complex.add_vertex(); - } - for (int i=10;i<15;i++){ - for (int j=i+1;j<15;j++) - complex.add_edge(Vertex_handle(i),Vertex_handle(j)); - } - Simplex_handle alpha(Vertex_handle(12),Vertex_handle(14)); - Skeleton_blocker_link_complex L(complex,alpha); - // Complexes built - - auto L2 = complex.link(alpha); - if(L!=L2) return false; - - // verification - bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(10))); - bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(11))); - bool test3 = L.contains_vertex(*L.get_address(Root_vertex_handle(13))); - bool test4 = L.num_edges()==3; - bool test5 = L.num_blockers()==0; - Root_simplex_handle simplex; - simplex.add_vertex(Root_vertex_handle(10)); - simplex.add_vertex(Root_vertex_handle(11)); - simplex.add_vertex(Root_vertex_handle(13)); - bool test6(L.get_simplex_address(simplex)); - bool test7 = L.contains(*(L.get_simplex_address(simplex))); - cerr <<"----> Ocomplex \n"; - return test1&&test2&&test3&&test4&&test5&&test6&&test7 ; - -} - - -bool test_link2(){ - Complex complex; - - Simplex_handle alpha; - Simplex_handle vertex_set_expected; - // Build the complexes - for (int i=0;i<20;i++){ - complex.add_vertex(); - } - for (int i=10;i<15;i++){ - for (int j=i+1;j<15;j++) - complex.add_edge(Vertex_handle(i),Vertex_handle(j)); - } - complex.add_blocker(Simplex_handle(Vertex_handle(10),Vertex_handle(11),Vertex_handle(13))); - alpha = Simplex_handle(Vertex_handle(12),Vertex_handle(14)); - Skeleton_blocker_link_complex L(complex,alpha); - // Complexes built - - // Print result - cerr << "complex complex"<< complex.to_string(); - cerr < Ocomplex \n"; - return test1&&test2&&test3&&test4&&test5&&test6 ; -} - -bool test_link3(){ - Complex complex; - - Simplex_handle alpha; - Simplex_handle vertex_set_expected; - // Build the complexes - for (int i=0;i<20;i++){ - complex.add_vertex(); - } - for (int i=10;i<15;i++){ - for (int j=i+1;j<15;j++) - complex.add_edge(Vertex_handle(i),Vertex_handle(j)); - } - complex.add_blocker(Simplex_handle(Vertex_handle(10),Vertex_handle(11),Vertex_handle(12))); - alpha = Simplex_handle(Vertex_handle(12),Vertex_handle(14)); - Skeleton_blocker_link_complex L(complex,alpha); - // Complexes built - - // Print result - cerr << "complex complex"<< complex.to_string(); - cerr < L(complex,alpha); - // Complexes built - - // verification - bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(10))); - bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(11))); - bool test3 = L.contains_vertex(*L.get_address(Root_vertex_handle(13))); - bool test4 = L.num_edges()==3; - bool test5 = L.num_blockers()==1; - Root_simplex_handle simplex; - simplex.add_vertex(Root_vertex_handle(10)); - simplex.add_vertex(Root_vertex_handle(11)); - simplex.add_vertex(Root_vertex_handle(13)); - bool test6 = L.contains_blocker(*(L.get_simplex_address(simplex))); - cerr <<"----> Ocomplex \n"; - return test1&&test2&&test3&&test4&&test5&&test6 ; - -} - -bool test_link5(){ - Complex complex(0,new Print_complex_visitor()); - // Build the complexes - build_complete(4,complex); - complex.add_blocker(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2),Vertex_handle(3))); +auto blocker_range(Map map) -> decltype(map | boost::adaptors::map_values) { + return map | boost::adaptors::map_values; +} + +bool test_iterator_blockers() { + Complex complex; + Simplex alpha; + Simplex vertex_set_expected; + // Build the complexes + for (int i = 0; i < 20; i++) { + complex.add_vertex(); + } + for (int i = 10; i < 15; i++) { + for (int j = i + 1; j < 15; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); + } + + complex.add_blocker(Simplex(Vertex_handle(10), Vertex_handle(11), Vertex_handle(12))); + complex.add_blocker(Simplex(Vertex_handle(2), Vertex_handle(1), Vertex_handle(10))); + complex.add_blocker(Simplex(Vertex_handle(10), Vertex_handle(9), Vertex_handle(15))); + complex.add_blocker(Simplex(Vertex_handle(1), Vertex_handle(9), Vertex_handle(8))); + + // Print result + int num_blockers = 0; + for (auto blockers : complex.blocker_range(Vertex_handle(10))) { + TESTVALUE(*blockers); + num_blockers++; + } + bool test = (num_blockers == 3); + + num_blockers = 0; + for (auto blockers : complex.blocker_range()) { + TESTVALUE(*blockers); + num_blockers++; + } + test = test && (num_blockers == 4); + + return test; +} + +bool test_link0() { + + enum { + a, b, c, d, n + }; + Complex complex(n); + complex.add_edge_without_blockers(Vertex_handle(b), Vertex_handle(c)); + complex.add_edge_without_blockers(Vertex_handle(c), Vertex_handle(d)); + Simplex alpha = Simplex(Vertex_handle(c)); + Skeleton_blocker_link_complex L(complex, alpha); + + auto L2 = complex.link(alpha); + if (L != L2) return false; + + PRINT(L.num_vertices()); + PRINT(L.to_string()); + + bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(b))); + bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(d))); + bool test3 = L.num_edges() == 0; + bool test4 = L.num_blockers() == 0; + return test1 && test2 && test3&&test4; + +} + +bool test_link1() { + Complex complex; + + + // Build the complexes + for (int i = 0; i < 20; i++) { + complex.add_vertex(); + } + for (int i = 10; i < 15; i++) { + for (int j = i + 1; j < 15; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); + } + Simplex alpha(Vertex_handle(12), Vertex_handle(14)); + Skeleton_blocker_link_complex L(complex, alpha); + // Complexes built + + auto L2 = complex.link(alpha); + if (L != L2) return false; + + // verification + bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(10))); + bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(11))); + bool test3 = L.contains_vertex(*L.get_address(Root_vertex_handle(13))); + bool test4 = L.num_edges() == 3; + bool test5 = L.num_blockers() == 0; + Root_simplex_handle simplex; + simplex.add_vertex(Root_vertex_handle(10)); + simplex.add_vertex(Root_vertex_handle(11)); + simplex.add_vertex(Root_vertex_handle(13)); + bool test6(L.get_simplex_address(simplex)); + bool test7 = L.contains(*(L.get_simplex_address(simplex))); + cerr << "----> Ocomplex \n"; + return test1 && test2 && test3 && test4 && test5 && test6&&test7; + +} + +bool test_link2() { + Complex complex; + + Simplex alpha; + Simplex vertex_set_expected; + // Build the complexes + for (int i = 0; i < 20; i++) { + complex.add_vertex(); + } + for (int i = 10; i < 15; i++) { + for (int j = i + 1; j < 15; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); + } + complex.add_blocker(Simplex(Vertex_handle(10), Vertex_handle(11), Vertex_handle(13))); + alpha = Simplex(Vertex_handle(12), Vertex_handle(14)); + Skeleton_blocker_link_complex L(complex, alpha); + // Complexes built + + // Print result + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + cerr << "L= Link_complex(" << alpha << ") : \n" << L.to_string(); + + auto L2 = complex.link(alpha); + if (L != L2) return false; + + + // verification + bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(10))); + bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(11))); + bool test3 = L.contains_vertex(*L.get_address(Root_vertex_handle(13))); + bool test4 = L.num_edges() == 3; + bool test5 = L.num_blockers() == 1; + Root_simplex_handle simplex; + simplex.add_vertex(Root_vertex_handle(10)); + simplex.add_vertex(Root_vertex_handle(11)); + simplex.add_vertex(Root_vertex_handle(13)); + bool test6 = L.contains_blocker(*(L.get_simplex_address(simplex))); + cerr << "----> Ocomplex \n"; + return test1 && test2 && test3 && test4 && test5&&test6; +} + +bool test_link3() { + Complex complex; + + Simplex alpha; + Simplex vertex_set_expected; + // Build the complexes + for (int i = 0; i < 20; i++) { + complex.add_vertex(); + } + for (int i = 10; i < 15; i++) { + for (int j = i + 1; j < 15; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); + } + complex.add_blocker(Simplex(Vertex_handle(10), Vertex_handle(11), Vertex_handle(12))); + alpha = Simplex(Vertex_handle(12), Vertex_handle(14)); + Skeleton_blocker_link_complex L(complex, alpha); + // Complexes built + + // Print result + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + cerr << "L= Link_complex(" << alpha << ") : \n" << L.to_string(); + + auto L2 = complex.link(alpha); + if (L != L2) return false; + + + // verification + bool test = assert_vertex(L, *L.get_address(Root_vertex_handle(10))); + test = test && assert_vertex(L, *L.get_address(Root_vertex_handle(11))); + test = test && assert_vertex(L, *L.get_address(Root_vertex_handle(13))); + test = test && L.num_edges() == 2; + test = test && L.contains_edge(*L.get_address(Root_vertex_handle(10)), *L.get_address(Root_vertex_handle(13))); + test = test && L.contains_edge(*L.get_address(Root_vertex_handle(13)), *L.get_address(Root_vertex_handle(11))); + test = test && L.num_blockers() == 0; + return test; +} + +bool test_link4() { + Complex complex; + + // Build the complexes + for (int i = 0; i < 20; i++) { + complex.add_vertex(); + } + for (int i = 10; i < 15; i++) { + for (int j = i + 1; j < 15; j++) + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(j)); + } + complex.add_blocker(Simplex(Vertex_handle(10), Vertex_handle(11), Vertex_handle(12), Vertex_handle(13))); + Simplex alpha(Vertex_handle(12), Vertex_handle(14)); + Skeleton_blocker_link_complex L(complex, alpha); + // Complexes built + + // verification + bool test1 = L.contains_vertex(*L.get_address(Root_vertex_handle(10))); + bool test2 = L.contains_vertex(*L.get_address(Root_vertex_handle(11))); + bool test3 = L.contains_vertex(*L.get_address(Root_vertex_handle(13))); + bool test4 = L.num_edges() == 3; + bool test5 = L.num_blockers() == 1; + Root_simplex_handle simplex; + simplex.add_vertex(Root_vertex_handle(10)); + simplex.add_vertex(Root_vertex_handle(11)); + simplex.add_vertex(Root_vertex_handle(13)); + bool test6 = L.contains_blocker(*(L.get_simplex_address(simplex))); + cerr << "----> Ocomplex \n"; + return test1 && test2 && test3 && test4 && test5&&test6; + +} + +bool test_link5() { + Complex complex(0, new Print_complex_visitor()); + // Build the complexes + build_complete(4, complex); + complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); + + Simplex alpha(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2)); + + + Skeleton_blocker_link_complex L(complex, alpha); // Complexes built + + // Print result + PRINT(complex.to_string()); + cerr << endl << endl; + PRINT(L.to_string()); + + // verification + return L.num_vertices() == 0; +} + +bool test_link6() { + Complex complex(0, new Print_complex_visitor()); + // Build the complexes + build_complete(4, complex); + complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); - Simplex_handle alpha(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2)); + Simplex alpha(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2)); + Skeleton_blocker_link_complex link_blocker_alpha; - Skeleton_blocker_link_complex L(complex,alpha); // Complexes built + build_link_of_blocker(complex, alpha, link_blocker_alpha); + + // Print result + PRINT(complex.to_string()); + cerr << endl << endl; + PRINT(link_blocker_alpha.to_string()); - // Print result - PRINT(complex.to_string()); - cerr <()); - // Build the complexes - build_complete(4,complex); - complex.add_blocker(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); - - Simplex_handle alpha(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2)); - - Skeleton_blocker_link_complex link_blocker_alpha; +bool test_link7() { + Complex complex(0, new Print_complex_visitor()); + // Build the complexes + build_complete(6, complex); + complex.add_vertex(); + complex.add_vertex(); + for (int i = 3; i < 6; ++i) { + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(6)); + complex.add_edge_without_blockers(Vertex_handle(i), Vertex_handle(7)); + } + complex.add_edge_without_blockers(Vertex_handle(6), Vertex_handle(7)); + complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); + complex.add_blocker(Simplex(Vertex_handle(3), Vertex_handle(4), Vertex_handle(5))); - build_link_of_blocker(complex,alpha,link_blocker_alpha); - - // Print result - PRINT(complex.to_string()); - cerr < link_blocker_alpha; -bool test_link7(){ - Complex complex(0,new Print_complex_visitor()); - // Build the complexes - build_complete(6,complex); - complex.add_vertex(); - complex.add_vertex(); - for(int i = 3; i<6; ++i){ - complex.add_edge(Vertex_handle(i),Vertex_handle(6)); - complex.add_edge(Vertex_handle(i),Vertex_handle(7)); - } - complex.add_edge(Vertex_handle(6),Vertex_handle(7)); - complex.add_blocker(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); - complex.add_blocker(Simplex_handle(Vertex_handle(3),Vertex_handle(4),Vertex_handle(5))); + build_link_of_blocker(complex, alpha, link_blocker_alpha); - Simplex_handle alpha(Vertex_handle(3),Vertex_handle(4),Vertex_handle(5)); + //the result should be the edge {6,7} plus the blocker {0,1,2} - Skeleton_blocker_link_complex link_blocker_alpha; + // Print result + PRINT(complex.to_string()); + cerr << endl << endl; + DBGVALUE(link_blocker_alpha.to_string()); - build_link_of_blocker(complex,alpha,link_blocker_alpha); + Skeleton_blocker_link_complex link_blocker_alpha_cpy = link_blocker_alpha; - //the result should be the edge {6,7} plus the blocker {0,1,2} + DBGVALUE(link_blocker_alpha_cpy.to_string()); - // Print result - PRINT(complex.to_string()); - cerr < link_blocker_alpha_cpy = link_blocker_alpha; + DBGVALUE(equal_complexes); - DBGVALUE(link_blocker_alpha_cpy.to_string()); - - bool equal_complexes = - (link_blocker_alpha.num_vertices() == link_blocker_alpha_cpy.num_vertices()) - &&(link_blocker_alpha.num_blockers() == link_blocker_alpha_cpy.num_blockers()) - &&(link_blocker_alpha.num_edges() == link_blocker_alpha_cpy.num_edges()) - ; - DBGVALUE((link_blocker_alpha.num_blockers() == link_blocker_alpha_cpy.num_blockers())); - DBGVALUE((link_blocker_alpha.num_blockers() )); - DBGVALUE(( link_blocker_alpha_cpy.num_blockers())); - - DBGVALUE(equal_complexes); - - // verification - return link_blocker_alpha.num_vertices()==5 && link_blocker_alpha.num_edges()==4 && link_blocker_alpha.num_blockers()==1 && equal_complexes; + // verification + return link_blocker_alpha.num_vertices() == 5 && link_blocker_alpha.num_edges() == 4 && link_blocker_alpha.num_blockers() == 1 && equal_complexes; } - - - - - - - template -void add_triangle_edges(int a,int b,int c,list& simplices){ - typedef SimplexHandle Simplex_handle; - typedef typename SimplexHandle::Vertex_handle Vertex_handle; +void add_triangle_edges(int a, int b, int c, list& simplices) { + typedef SimplexHandle Simplex; + typedef typename SimplexHandle::Vertex_handle Vertex_handle; - simplices.push_back(Simplex_handle(Vertex_handle(a),Vertex_handle(b) )); - simplices.push_back(Simplex_handle(Vertex_handle(b),Vertex_handle(c) )); - simplices.push_back(Simplex_handle(Vertex_handle(c),Vertex_handle(a) )); + simplices.push_back(Simplex(Vertex_handle(a), Vertex_handle(b))); + simplices.push_back(Simplex(Vertex_handle(b), Vertex_handle(c))); + simplices.push_back(Simplex(Vertex_handle(c), Vertex_handle(a))); } template -void add_triangle(int a,int b,int c,list& simplices){ - typedef SimplexHandle Simplex_handle; - typedef typename SimplexHandle::Vertex_handle Vertex_handle; - simplices.push_back(Simplex_handle(Vertex_handle(a),Vertex_handle(b),Vertex_handle(c))); +void add_triangle(int a, int b, int c, list& simplices) { + typedef SimplexHandle Simplex; + typedef typename SimplexHandle::Vertex_handle Vertex_handle; + simplices.push_back(Simplex(Vertex_handle(a), Vertex_handle(b), Vertex_handle(c))); } -bool test_constructor(){ - list simplices; - - simplices.push_back(Simplex_handle(Vertex_handle(0))); - simplices.push_back(Simplex_handle(Vertex_handle(1))); - simplices.push_back(Simplex_handle(Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(3))); - simplices.push_back(Simplex_handle(Vertex_handle(4))); - simplices.push_back(Simplex_handle(Vertex_handle(5))); +bool test_constructor() { + list simplices; - simplices.push_back(Simplex_handle(Vertex_handle(3),Vertex_handle(5) )); + simplices.push_back(Simplex(Vertex_handle(0))); + simplices.push_back(Simplex(Vertex_handle(1))); + simplices.push_back(Simplex(Vertex_handle(2))); + simplices.push_back(Simplex(Vertex_handle(3))); + simplices.push_back(Simplex(Vertex_handle(4))); + simplices.push_back(Simplex(Vertex_handle(5))); - add_triangle_edges(0,1,5,simplices); - add_triangle_edges(1,2,3,simplices); - add_triangle_edges(2,3,4,simplices); - add_triangle_edges(1,3,4,simplices); - add_triangle_edges(1,2,4,simplices); - - - add_triangle(0,1,5,simplices); - add_triangle(1,2,3,simplices); - add_triangle(1,3,4,simplices); - add_triangle(1,2,4,simplices); - add_triangle(2,3,4,simplices); - - Complex complex(simplices.begin(),simplices.end()); - - PRINT(complex.to_string()); - - return ( complex.num_vertices()==6&&complex.num_edges()==10&& complex.num_blockers()==2); -} - - -list subfaces(Simplex_handle top_face){ - list res; - if(top_face.dimension()==-1) return res; - if(top_face.dimension()==0) { - res.push_back(top_face); - return res; - } - else{ - Vertex_handle first_vertex = top_face.first_vertex(); - top_face.remove_vertex(first_vertex); - res = subfaces(top_face); - list copy = res; - for(auto& simplex : copy){ - simplex.add_vertex(first_vertex); - } - res.push_back(Simplex_handle(first_vertex)); - res.splice(res.end(),copy); - return res; - } -} - - -bool test_constructor2(){ - Simplex_handle simplex; - for(int i =0 ; i < 5;++i) - simplex.add_vertex(static_cast(i)); - - list simplices(subfaces(simplex)); - simplices.remove(simplex); - - Complex complex(simplices.begin(),simplices.end()); - - PRINT(complex.to_string()); - - for(auto b : complex.const_blocker_range()){ - cout << "b:"< simplices; - auto subf(subfaces(Sh(Vh(0),Vh(1),Vh(2)))); - subf.pop_back(); //remove max face -> now a blocker 012 - simplices.insert(simplices.begin(),subf.begin(),subf.end()); - DBGCONT(simplices); - Complex complex(simplices.begin(),simplices.end()); - DBGVALUE(complex.to_string()); + add_triangle(0, 1, 5, simplices); + add_triangle(1, 2, 3, simplices); + add_triangle(1, 3, 4, simplices); + add_triangle(1, 2, 4, simplices); + add_triangle(2, 3, 4, simplices); - if(complex.num_blockers()!=1) return false; - Sh expected_blocker(Vh(0),Vh(1),Vh(2)); - for(auto b : complex.const_blocker_range()) - if(*b!=expected_blocker) return false; + Complex complex(simplices.begin(), simplices.end()); + PRINT(complex.to_string()); - return complex.num_vertices()==3 && complex.num_blockers()==1; + return ( complex.num_vertices() == 6 && complex.num_edges() == 10 && complex.num_blockers() == 2); } -bool test_constructor4(){ - typedef Vertex_handle Vh; - typedef Simplex_handle Sh; - std::vector simplices; - auto subf(subfaces(Sh(Vh(0),Vh(1),Vh(2),Vh(3)))); - simplices.insert(simplices.begin(),subf.begin(),subf.end()); - - simplices.push_back(Sh(Vh(4))); - simplices.push_back(Sh(Vh(4),Vh(1))); - simplices.push_back(Sh(Vh(4),Vh(0))); - - DBGCONT(simplices); - Complex complex(simplices.begin(),simplices.end()); - - DBGVALUE(complex.to_string()); - if(complex.num_blockers()!=1) return false; - Sh expected_blocker(Vh(0),Vh(1),Vh(4)); - for(auto b : complex.const_blocker_range()) - if(*b!=expected_blocker) return false; - - return complex.num_vertices()==5 && complex.num_blockers()==1 && complex.num_edges()==8; +list subfaces(Simplex top_face) { + list res; + if (top_face.dimension() == -1) return res; + if (top_face.dimension() == 0) { + res.push_back(top_face); + return res; + } else { + Vertex_handle first_vertex = top_face.first_vertex(); + top_face.remove_vertex(first_vertex); + res = subfaces(top_face); + list copy = res; + for (auto& simplex : copy) { + simplex.add_vertex(first_vertex); + } + res.push_back(Simplex(first_vertex)); + res.splice(res.end(), copy); + return res; + } } +bool test_constructor2() { + Simplex simplex; + for (int i = 0; i < 5; ++i) + simplex.add_vertex(static_cast (i)); + list simplices(subfaces(simplex)); + simplices.remove(simplex); -bool test_constructor5(){ - typedef Vertex_handle Vh; - typedef Simplex_handle Sh; - std::vector simplices; - auto subf(subfaces(Sh(Vh(0),Vh(1),Vh(2)))); - simplices.insert(simplices.begin(),subf.begin(),subf.end()); - - simplices.push_back(Sh(Vh(3))); - simplices.push_back(Sh(Vh(3),Vh(1))); - simplices.push_back(Sh(Vh(3),Vh(2))); - simplices.push_back(Sh(Vh(4))); - simplices.push_back(Sh(Vh(4),Vh(1))); - simplices.push_back(Sh(Vh(4),Vh(0))); - simplices.push_back(Sh(Vh(5))); - simplices.push_back(Sh(Vh(5),Vh(2))); - simplices.push_back(Sh(Vh(5),Vh(0))); - - DBGCONT(simplices); - Complex complex(simplices.begin(),simplices.end()); + Complex complex(simplices.begin(), simplices.end()); - DBGVALUE(complex.to_string()); + PRINT(complex.to_string()); - return complex.num_vertices()==6 && complex.num_blockers()==3 && complex.num_edges()==9; -} - - -bool test_constructor6(){ - typedef Vertex_handle Vh; - typedef Simplex_handle Sh; - std::vector simplices; - auto subf(subfaces(Sh(Vh(0),Vh(1),Vh(2),Vh(3)))); - for(auto s:subf){ - Sh s1(Vh(0),Vh(1),Vh(2),Vh(3)); - Sh s2(Vh(1),Vh(2),Vh(3)); - if(s!=s1 && s!=s2) simplices.push_back(s); - } + for (auto b : complex.const_blocker_range()) { + cout << "b:" << b << endl; + } - DBGCONT(simplices); - Complex complex(simplices.begin(),simplices.end()); - - DBGVALUE(complex.to_string()); - - if(complex.num_blockers()!=1) return false; - Sh expected_blocker(Vh(1),Vh(2),Vh(3)); - for(auto b : complex.const_blocker_range()) - if(*b!=expected_blocker) return false; - return complex.num_vertices()==4 && complex.num_blockers()==1 && complex.num_edges()==6; + return ( complex.num_vertices() == 5 && complex.num_edges() == 10 && complex.num_blockers() == 1); } +bool test_constructor3() { + typedef Vertex_handle Vh; + typedef Simplex Sh; + std::vector simplices; + auto subf(subfaces(Sh(Vh(0), Vh(1), Vh(2)))); + subf.pop_back(); //remove max face -> now a blocker 012 + simplices.insert(simplices.begin(), subf.begin(), subf.end()); + DBGCONT(simplices); + Complex complex(simplices.begin(), simplices.end()); -bool test_constructor7(){ - typedef Vertex_handle Vh; - typedef Simplex_handle Sh; - std::vector simplices; - simplices.push_back(Sh(Vh(0),Vh(1),Vh(2))); - simplices.push_back(Sh(Vh(1),Vh(2),Vh(3))); - simplices.push_back(Sh(Vh(3),Vh(0),Vh(2))); - simplices.push_back(Sh(Vh(3),Vh(0),Vh(1))); + DBGVALUE(complex.to_string()); - //get complex from top faces - Complex complex(make_complex_from_top_faces(simplices.begin(),simplices.end())); + if (complex.num_blockers() != 1) return false; + Sh expected_blocker(Vh(0), Vh(1), Vh(2)); + for (auto b : complex.const_blocker_range()) + if (*b != expected_blocker) return false; - DBGVALUE(complex.to_string()); - if(complex.num_blockers()!=1) return false; - Sh expected_blocker(Vh(0),Vh(1),Vh(2),Vh(3)); - for(auto b : complex.const_blocker_range()) - if(*b!=expected_blocker) return false; - return complex.num_vertices()==4 && complex.num_blockers()==1 && complex.num_edges()==6; + return complex.num_vertices() == 3 && complex.num_blockers() == 1; } +bool test_constructor4() { + typedef Vertex_handle Vh; + typedef Simplex Sh; + std::vector simplices; + auto subf(subfaces(Sh(Vh(0), Vh(1), Vh(2), Vh(3)))); + simplices.insert(simplices.begin(), subf.begin(), subf.end()); -bool test_constructor8(){ - typedef Vertex_handle Vh; - typedef Simplex_handle Sh; - std::vector simplices; - simplices.push_back(Sh(Vh(0),Vh(1))); - simplices.push_back(Sh(Vh(2),Vh(1))); - simplices.push_back(Sh(Vh(0),Vh(2))); - simplices.push_back(Sh(Vh(3),Vh(1))); - simplices.push_back(Sh(Vh(2),Vh(3))); + simplices.push_back(Sh(Vh(4))); + simplices.push_back(Sh(Vh(4), Vh(1))); + simplices.push_back(Sh(Vh(4), Vh(0))); - //get complex from top faces - Complex complex(make_complex_from_top_faces(simplices.begin(),simplices.end())); + DBGCONT(simplices); + Complex complex(simplices.begin(), simplices.end()); - DBGVALUE(complex.to_string()); + DBGVALUE(complex.to_string()); + if (complex.num_blockers() != 1) return false; + Sh expected_blocker(Vh(0), Vh(1), Vh(4)); + for (auto b : complex.const_blocker_range()) + if (*b != expected_blocker) return false; - return complex.num_vertices()==4 && complex.num_blockers()==2 && complex.num_edges()==5; + return complex.num_vertices() == 5 && complex.num_blockers() == 1 && complex.num_edges() == 8; } - - - - -int main (int argc, char *argv[]) -{ - Tests tests_complex; - tests_complex.add("test simplex",test_simplex); - tests_complex.add("test_link0",test_link0); - tests_complex.add("test_link1",test_link1); - tests_complex.add("test_link2",test_link2); - tests_complex.add("test_link3",test_link3); - tests_complex.add("test_link4",test_link4); - tests_complex.add("test_link5",test_link5); - tests_complex.add("test_link6",test_link6); - tests_complex.add("test_link7",test_link7); - - tests_complex.add("test iterator vertices 1",test_iterator_vertices1); - tests_complex.add("test iterator vertices 2",test_iterator_vertices2); - tests_complex.add("test iterator edges",test_iterator_edge); - tests_complex.add("test iterator edges 2",test_iterator_edge2); - tests_complex.add("test iterator edges 3",test_iterator_edge3); - - tests_complex.add("test iterator simplices",test_iterator_simplices); - tests_complex.add("test iterator simplices2",test_iterator_simplices2); - tests_complex.add("test iterator simplices3",test_iterator_simplices3); - tests_complex.add("test iterator simplices4",test_iterator_simplices4); - - - tests_complex.add("test iterator blockers",test_iterator_blockers); - tests_complex.add("test_iterator_triangles",test_iterator_triangles); - - tests_complex.add("test_constructor_list_simplices",test_constructor); - tests_complex.add("test_constructor_list_simplices2",test_constructor2); - tests_complex.add("test_constructor_list_simplices3",test_constructor3); - tests_complex.add("test_constructor_list_simplices4",test_constructor4); - tests_complex.add("test_constructor_list_simplices5",test_constructor5); - tests_complex.add("test_constructor_list_simplices6",test_constructor6); - tests_complex.add("test_constructor_list_simplices7",test_constructor7); - tests_complex.add("test_constructor_list_simplices8",test_constructor8); - - - if(tests_complex.run()){ - return EXIT_SUCCESS; - } - else{ - return EXIT_FAILURE; - } - - // test_iterator_simplices(); +bool test_constructor5() { + typedef Vertex_handle Vh; + typedef Simplex Sh; + std::vector simplices; + auto subf(subfaces(Sh(Vh(0), Vh(1), Vh(2)))); + simplices.insert(simplices.begin(), subf.begin(), subf.end()); + + simplices.push_back(Sh(Vh(3))); + simplices.push_back(Sh(Vh(3), Vh(1))); + simplices.push_back(Sh(Vh(3), Vh(2))); + simplices.push_back(Sh(Vh(4))); + simplices.push_back(Sh(Vh(4), Vh(1))); + simplices.push_back(Sh(Vh(4), Vh(0))); + simplices.push_back(Sh(Vh(5))); + simplices.push_back(Sh(Vh(5), Vh(2))); + simplices.push_back(Sh(Vh(5), Vh(0))); + + DBGCONT(simplices); + Complex complex(simplices.begin(), simplices.end()); + + DBGVALUE(complex.to_string()); + + return complex.num_vertices() == 6 && complex.num_blockers() == 3 && complex.num_edges() == 9; +} + +bool test_constructor6() { + typedef Vertex_handle Vh; + typedef Simplex Sh; + std::vector simplices; + auto subf(subfaces(Sh(Vh(0), Vh(1), Vh(2), Vh(3)))); + for (auto s : subf) { + Sh s1(Vh(0), Vh(1), Vh(2), Vh(3)); + Sh s2(Vh(1), Vh(2), Vh(3)); + if (s != s1 && s != s2) simplices.push_back(s); + } + + DBGCONT(simplices); + Complex complex(simplices.begin(), simplices.end()); + + DBGVALUE(complex.to_string()); + + if (complex.num_blockers() != 1) return false; + Sh expected_blocker(Vh(1), Vh(2), Vh(3)); + for (auto b : complex.const_blocker_range()) + if (*b != expected_blocker) return false; + return complex.num_vertices() == 4 && complex.num_blockers() == 1 && complex.num_edges() == 6; +} + +bool test_constructor7() { + typedef Vertex_handle Vh; + typedef Simplex Sh; + std::vector simplices; + simplices.push_back(Sh(Vh(0), Vh(1), Vh(2))); + simplices.push_back(Sh(Vh(1), Vh(2), Vh(3))); + simplices.push_back(Sh(Vh(3), Vh(0), Vh(2))); + simplices.push_back(Sh(Vh(3), Vh(0), Vh(1))); + + //get complex from top faces + Complex complex(make_complex_from_top_faces(simplices.begin(), simplices.end())); + + DBGVALUE(complex.to_string()); + + if (complex.num_blockers() != 1) return false; + Sh expected_blocker(Vh(0), Vh(1), Vh(2), Vh(3)); + for (auto b : complex.const_blocker_range()) + if (*b != expected_blocker) return false; + return complex.num_vertices() == 4 && complex.num_blockers() == 1 && complex.num_edges() == 6; +} + +bool test_constructor8() { + typedef Vertex_handle Vh; + typedef Simplex Sh; + std::vector simplices; + simplices.push_back(Sh(Vh(0), Vh(1))); + simplices.push_back(Sh(Vh(2), Vh(1))); + simplices.push_back(Sh(Vh(0), Vh(2))); + simplices.push_back(Sh(Vh(3), Vh(1))); + simplices.push_back(Sh(Vh(2), Vh(3))); + + //get complex from top faces + Complex complex(make_complex_from_top_faces(simplices.begin(), simplices.end())); + + DBGVALUE(complex.to_string()); + + return complex.num_vertices() == 4 && complex.num_blockers() == 2 && complex.num_edges() == 5; +} + +int main(int argc, char *argv[]) { + Tests tests_complex; + tests_complex.add("test simplex", test_simplex); + tests_complex.add("test_link0", test_link0); + tests_complex.add("test_link1", test_link1); + tests_complex.add("test_link2", test_link2); + tests_complex.add("test_link3", test_link3); + tests_complex.add("test_link4", test_link4); + tests_complex.add("test_link5", test_link5); + tests_complex.add("test_link6", test_link6); + tests_complex.add("test_link7", test_link7); + + tests_complex.add("test_constructor_list_simplices", test_constructor); + tests_complex.add("test_constructor_list_simplices2", test_constructor2); + tests_complex.add("test_constructor_list_simplices3", test_constructor3); + tests_complex.add("test_constructor_list_simplices4", test_constructor4); + tests_complex.add("test_constructor_list_simplices5", test_constructor5); + tests_complex.add("test_constructor_list_simplices6", test_constructor6); + tests_complex.add("test_constructor_list_simplices7", test_constructor7); + tests_complex.add("test_constructor_list_simplices8", test_constructor8); + + tests_complex.add("test iterator vertices 1", test_iterator_vertices1); + tests_complex.add("test iterator vertices 2", test_iterator_vertices2); + tests_complex.add("test iterator edges", test_iterator_edge); + tests_complex.add("test iterator edges 2", test_iterator_edge2); + tests_complex.add("test iterator edges 3", test_iterator_edge3); + tests_complex.add("test iterator blockers", test_iterator_blockers); + tests_complex.add("test_iterator_triangles", test_iterator_triangles); + tests_complex.add("test iterator simplices", test_iterator_simplices); + tests_complex.add("test iterator simplices2", test_iterator_simplices2); + tests_complex.add("test iterator simplices3", test_iterator_simplices3); + tests_complex.add("test iterator simplices4", test_iterator_simplices4); + tests_complex.add("test iterator coboundary", test_iterator_coboundary); + + if (tests_complex.run()) { + return EXIT_SUCCESS; + } else { + return EXIT_FAILURE; + } + + // test_iterator_simplices(); } -- cgit v1.2.3 From 52dbe195ea62ca333c7e6834d9b92e4d9e5557ea Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 16 Oct 2015 15:25:35 +0000 Subject: Sort in parallel in initialize_filtration using TBB. No build machinery support for now. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/tbb@858 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 94071e9da20993dff60743ac75125f26ad62e55e --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 4c6a95e8..edb1d7c9 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -35,6 +35,10 @@ #include #include +#ifdef GUDHI_USE_TBB +#include +#endif + #include #include #include @@ -788,8 +792,12 @@ class Simplex_tree { * heuristic consists in inserting the cofaces of a simplex as soon as * possible. */ +#ifdef GUDHI_USE_TBB + tbb::parallel_sort(filtration_vect_, is_before_in_filtration(this)); +#else std::stable_sort(filtration_vect_.begin(), filtration_vect_.end(), is_before_in_filtration(this)); +#endif } private: -- cgit v1.2.3 From b6c3298ce211935f65cc174cc86c0c6a5073035f Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 17 Oct 2015 18:55:35 +0000 Subject: Simplify operator== for the boundary iterator. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/contiguous_vertices@862 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 48228705e9f310ed842e214c5d8849e8f1e0c670 --- .../include/gudhi/Simplex_tree/Simplex_tree_iterators.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index f77bac15..c5027f22 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -99,8 +99,7 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< // any end() iterator explicit Simplex_tree_boundary_simplex_iterator(SimplexTree * st) - : last_(st->null_vertex()), - sib_(NULL) { + : sh_(st->null_simplex()) { } Simplex_tree_boundary_simplex_iterator(SimplexTree * st, Simplex_handle sh) @@ -113,7 +112,7 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< if (sib_ != NULL) { sh_ = sib_->find(next_); } else { - last_ = st->null_vertex(); + sh_ = st->null_simplex(); } // vertex: == end() } @@ -121,16 +120,17 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< friend class boost::iterator_core_access; // valid when iterating along the SAME boundary. bool equal(Simplex_tree_boundary_simplex_iterator const& other) const { - return (sib_ == other.sib_ && last_ == other.last_); + return sh_ == other.sh_; } Simplex_handle const& dereference() const { + assert(sh_ != st_->null_simplex()); return sh_; } void increment() { if (sib_ == NULL) { - last_ = st_->null_vertex(); + sh_ = st_->null_simplex(); return; } -- cgit v1.2.3 From 20cb0d7a919005ba20d0a76cca38a73d3a119480 Mon Sep 17 00:00:00 2001 From: salinasd Date: Sun, 18 Oct 2015 10:44:55 +0000 Subject: GH: dim3 restriction, skbl: num_simplices methods git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@865 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e7f9d48c4e6af222b6f158e906a3a592027d39b8 --- src/Contraction/example/Garland_heckbert.cpp | 23 ++++++++++------ .../include/gudhi/Skeleton_blocker_complex.h | 31 ++++++++++++++++++---- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 4 +-- .../test/TestSkeletonBlockerComplex.cpp | 22 +++++++++++++-- 4 files changed, 62 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index 70f29b6a..681426e0 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -145,13 +145,13 @@ class GH_visitor : public Gudhi::contraction::Contraction_visitor { int main(int argc, char *argv[]) { if (argc != 4) { - std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save " - << "the result to output.off.\n"; + std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; return EXIT_FAILURE; } Complex complex; - + typedef typename Complex::Vertex_handle Vertex_handle; + // load the points Skeleton_blocker_off_reader off_reader(argv[1], complex); if (!off_reader.is_valid()) { @@ -159,8 +159,12 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; + if(!complex.empty() && !complex.point(Vertex_handle(0)).dimension()==3) { + std::cerr << "Only points of dimension 3 are supported." << std::endl; + return EXIT_FAILURE; + } + std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; int num_contractions = atoi(argv[3]); @@ -171,22 +175,25 @@ int main(int argc, char *argv[]) { new GH_cost(complex), new GH_placement(complex), contraction::make_link_valid_contraction(), - new GH_visitor(complex)); + new GH_visitor(complex) + ); std::cout << "Contract " << num_contractions << " edges" << std::endl; contractor.contract_edges(num_contractions); std::cout << "Final complex has " << complex.num_vertices() << " vertices, " << - complex.num_edges() << " edges and" << + complex.num_edges() << " edges and " << complex.num_triangles() << " triangles." << std::endl; - // write simplified complex + //write simplified complex Skeleton_blocker_off_writer off_writer(argv[2], complex); return EXIT_SUCCESS; } +#endif // GARLAND_HECKBERT_H_ + + -#endif // GARLAND_HECKBERT_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index 78384abf..b1995783 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -134,8 +134,8 @@ class Skeleton_blocker_complex { typedef typename std::multimap::const_iterator BlockerMapConstIterator; protected: - int num_vertices_; - int num_blockers_; + size_t num_vertices_; + size_t num_blockers_; typedef Skeleton_blocker_complex_visitor Visitor; // typedef Visitor* Visitor_ptr; @@ -164,10 +164,10 @@ class Skeleton_blocker_complex { /** *@brief constructs a simplicial complex with a given number of vertices and a visitor. */ - explicit Skeleton_blocker_complex(int num_vertices_ = 0, Visitor* visitor_ = NULL) + explicit Skeleton_blocker_complex(size_t num_vertices_ = 0, Visitor* visitor_ = NULL) : visitor(visitor_) { clear(); - for (int i = 0; i < num_vertices_; ++i) { + for (size_t i = 0; i < num_vertices_; ++i) { add_vertex(); } } @@ -998,10 +998,31 @@ class Skeleton_blocker_complex { return std::distance(triangles.begin(), triangles.end()); } + + /* + * @brief returns the number of simplices of a given dimension in the complex. + */ + size_t num_simplices() const { + auto simplices = complex_simplex_range(); + return std::distance(simplices.begin(), simplices.end()); + } + + /* + * @brief returns the number of simplices of a given dimension in the complex. + */ + size_t num_simplices(unsigned dimension) const { + //todo iterator on k-simplices + size_t res = 0; + for(const auto& s: complex_simplex_range()) + if(s.dimension() == dimension) + ++res; + return res; + } + /* * @brief returns the number of blockers in the complex. */ - int num_blockers() const { + size_t num_blockers() const { return num_blockers_; } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h index 49a1ea8b..79a7ed79 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -45,9 +45,7 @@ bool Skeleton_blocker_complex::is_popable_blocker(Blocker_han assert(this->contains_blocker(*sigma)); Skeleton_blocker_link_complex link_blocker_sigma; build_link_of_blocker(*this, *sigma, link_blocker_sigma); - - bool res = link_blocker_sigma.is_contractible() == CONTRACTIBLE; - return res; + return link_blocker_sigma.is_contractible() == CONTRACTIBLE; } /** diff --git a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp index 418638e8..69abd279 100644 --- a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp +++ b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp @@ -104,6 +104,23 @@ bool test_simplex() { return simplex.dimension() == 3; } +bool test_num_simplices() { + int n = 4; + Complex complex; + build_complete(n, complex); + size_t sum = 0; + for (int i = 0; i < n; i++) { + PRINT(complex.num_simplices(i)); + sum += complex.num_simplices(i); + } + return + complex.num_vertices() == n && + complex.num_edges() == 6 && + sum == 15 && + complex.num_simplices() == 15; +} + + bool test_iterator_vertices1() { int n = 10; Complex complex(10); @@ -118,7 +135,7 @@ bool test_iterator_vertices1() { bool test_iterator_vertices2() { int n = 10; - Complex complex(10); + Complex complex; build_complete(10, complex); cerr << "complex.num_vertices():" << complex.num_vertices() << endl; cerr << "complex.num_edges():" << complex.num_edges() << endl; @@ -348,7 +365,7 @@ bool test_iterator_simplices4() { } bool test_iterator_coboundary() { - Complex c(4); + Complex c; build_complete(4, c); c.remove_edge(Vertex_handle(0), Vertex_handle(2)); PRINT(c.to_string()); @@ -892,6 +909,7 @@ bool test_constructor8() { int main(int argc, char *argv[]) { Tests tests_complex; tests_complex.add("test simplex", test_simplex); + tests_complex.add("test_num_simplices", test_num_simplices); tests_complex.add("test_link0", test_link0); tests_complex.add("test_link1", test_link1); tests_complex.add("test_link2", test_link2); -- cgit v1.2.3 From 91a2adbaeec76b4ee172123a5a833065f910f5ab Mon Sep 17 00:00:00 2001 From: glisse Date: Sun, 18 Oct 2015 20:31:25 +0000 Subject: Also use TBB to build Hasse_complex in parallel. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/tbb@870 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6633f9b8261cfb2acfb62d1f4748df73375086bd --- src/Hasse_complex/include/gudhi/Hasse_complex.h | 30 +++++++++----- src/common/include/gudhi/allocator.h | 55 +++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 src/common/include/gudhi/allocator.h (limited to 'src') diff --git a/src/Hasse_complex/include/gudhi/Hasse_complex.h b/src/Hasse_complex/include/gudhi/Hasse_complex.h index 67079687..af9ae5e9 100644 --- a/src/Hasse_complex/include/gudhi/Hasse_complex.h +++ b/src/Hasse_complex/include/gudhi/Hasse_complex.h @@ -29,6 +29,12 @@ #include // for pair #include +#include + +#ifdef GUDHI_USE_TBB +#include +#endif + namespace Gudhi { template < class HasseCpx > @@ -97,20 +103,24 @@ class Hasse_complex { template < class Complex_ds > Hasse_complex(Complex_ds & cpx) - : complex_() + : complex_(cpx.num_simplices()) , vertices_() , threshold_(cpx.filtration()) , num_vertices_() , dim_max_(cpx.dimension()) { - complex_.reserve(cpx.num_simplices()); - int idx = 0; - for (auto cpx_sh : cpx.filtration_simplex_range()) { - complex_.push_back(Hasse_simp(cpx, cpx_sh)); - if (dimension(idx) == 0) { + int size = complex_.size(); +#ifdef GUDHI_USE_TBB + tbb::parallel_for(0,size,[&](int idx){new (&complex_[idx]) Hasse_simp(cpx, cpx.simplex(idx));}); + for (int idx=0; idx complex_; + std::vector< Hasse_simp, Gudhi::no_init_allocator > complex_; std::vector vertices_; Filtration_value threshold_; size_t num_vertices_; @@ -218,7 +228,7 @@ std::istream& operator>>(std::istream & is // read all simplices in the file as a list of vertices while (read_hasse_simplex(is, boundary, fil)) { // insert every simplex in the simplex tree - hcpx.complex_.push_back(Hasse_simplex< Hasse_complex >(key, fil, boundary)); + hcpx.complex_.emplace_back(key, fil, boundary); if (max_dim < hcpx.dimension(key)) { max_dim = hcpx.dimension(key); diff --git a/src/common/include/gudhi/allocator.h b/src/common/include/gudhi/allocator.h new file mode 100644 index 00000000..b825173b --- /dev/null +++ b/src/common/include/gudhi/allocator.h @@ -0,0 +1,55 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Marc Glisse + * + * Copyright (C) 2015 INRIA Saclay - Ile de France + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUDHI_ALLOCATOR_H_ +#define GUDHI_ALLOCATOR_H_ + +#include +#include + +namespace Gudhi { + +/** \private + * An allocator that can be used to build an uninitialized vector. + */ +template > +struct no_init_allocator : Base { + typedef std::allocator_traits Base_traits; + template struct rebind { + typedef no_init_allocator> other; + }; + + // Inherit constructors. + using Base::Base; + + // Do nothing: that's the whole point! + template + void construct(P*)noexcept{} + + template void construct(P*p, U&&...u){ + Base_traits::construct(*(Base*)this, p, std::forward(u)...); + } +}; + +} // namespace Gudhi + +#endif // GUDHI_ALLOCATOR_H_ -- cgit v1.2.3 From 2814e25cbc70160e57f426ec708f6d99180ef5fd Mon Sep 17 00:00:00 2001 From: glisse Date: Sun, 25 Oct 2015 21:41:01 +0000 Subject: Example to compute persistence of a Rips filtration "in parallel". On a machine with a gazillion cores, it gains a factor >2 at the expense of some memory. At this point, construction of the Rips graph and expansion are not negligible anymore and could use some parallelism. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/tbb@875 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 53d6a74338f1346bd7d1ca018ec15dd1ee8287e8 --- src/Hasse_complex/include/gudhi/Hasse_complex.h | 14 +- .../example/parallel_rips_persistence.cpp | 180 +++++++++++++++++++++ 2 files changed, 187 insertions(+), 7 deletions(-) create mode 100644 src/Persistent_cohomology/example/parallel_rips_persistence.cpp (limited to 'src') diff --git a/src/Hasse_complex/include/gudhi/Hasse_complex.h b/src/Hasse_complex/include/gudhi/Hasse_complex.h index af9ae5e9..38887264 100644 --- a/src/Hasse_complex/include/gudhi/Hasse_complex.h +++ b/src/Hasse_complex/include/gudhi/Hasse_complex.h @@ -44,8 +44,7 @@ struct Hasse_simplex { template< class Complex_ds > Hasse_simplex(Complex_ds & cpx , typename Complex_ds::Simplex_handle sh) - : key_(cpx.key(sh)) - , filtration_(cpx.filtration(sh)) + : filtration_(cpx.filtration(sh)) , boundary_() { boundary_.reserve(cpx.dimension(sh) + 1); for (auto b_sh : cpx.boundary_simplex_range(sh)) { @@ -55,7 +54,7 @@ struct Hasse_simplex { Hasse_simplex(typename HasseCpx::Simplex_key key , typename HasseCpx::Filtration_value fil - , std::vector boundary) + , std::vector const& boundary) : key_(key) , filtration_(fil) , boundary_(boundary) { } @@ -197,11 +196,12 @@ class Hasse_complex { } void initialize_filtration() { + // Setting the keys is done by pcoh, Simplex_tree doesn't do it either. +#if 0 Simplex_key key = 0; - for (auto & h_simp : complex_) { - h_simp.key_ = key; - ++key; - } + for (auto & h_simp : complex_) + h_simp.key_ = key++; +#endif } std::vector< Hasse_simp, Gudhi::no_init_allocator > complex_; diff --git a/src/Persistent_cohomology/example/parallel_rips_persistence.cpp b/src/Persistent_cohomology/example/parallel_rips_persistence.cpp new file mode 100644 index 00000000..425a5b2c --- /dev/null +++ b/src/Persistent_cohomology/example/parallel_rips_persistence.cpp @@ -0,0 +1,180 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria, Marc Glisse + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France), + * 2015 INRIA Saclay Île de France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include "gudhi/Hasse_complex.h" + +#include + +#ifdef GUDHI_USE_TBB +#include +#endif + +#include +#include + +//////////////////////////////////////////////////////////////// +// // +// WARNING: persistence computation itself is not parallel, // +// and this uses more memory than rips_persistence. // +// // +//////////////////////////////////////////////////////////////// + +using namespace Gudhi; +using namespace Gudhi::persistent_cohomology; + +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string filepoints; + std::string filediag; + Filtration_value threshold; + int dim_max; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, filepoints, filediag, threshold, dim_max, p, min_persistence); + + // Extract the points from the file filepoints + typedef std::vector Point_t; + std::vector< Point_t > points; + read_points(filepoints, points); + + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); + + // Construct the Rips complex in a Simplex Tree + Simplex_tree<>& st = *new Simplex_tree<>; + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); + + std::cout << "The complex contains " << st.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << st.dimension() << " \n"; + +#ifdef GUDHI_USE_TBB + // Unnecessary, but clarifies which operations are parallel. + tbb::task_scheduler_init ts; +#endif + + // Sort the simplices in the order of the filtration + st.initialize_filtration(); + int count = 0; + for (auto sh : st.filtration_simplex_range()) + st.assign_key(sh, count++); + + // Convert to a more convenient representation. + Hasse_complex<> hcpx(st); + +#ifdef GUDHI_USE_TBB + ts.terminate(); +#endif + + // Free some space. + delete &st; + + // Compute the persistence diagram of the complex + persistent_cohomology::Persistent_cohomology< Hasse_complex<>, Field_Zp > pcoh(hcpx); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } +} + +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&filepoints), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", po::value(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} -- cgit v1.2.3 From a57e87727ea3cbf73ac8e4ce0fe65a19de1fe2d9 Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 9 Nov 2015 16:54:45 +0000 Subject: New Simplex_tree_options_fast_persistence, while Simplex_tree_options_full_featured switches to the safe default of allowing non-contiguous vertices. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/contiguous_vertices@896 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 60bc11a90027ed17233903d22a6494198f30eeb1 --- .../example/performance_rips_persistence.cpp | 2 +- .../example/rips_multifield_persistence.cpp | 5 +-- .../example/rips_persistence.cpp | 5 +-- src/Simplex_tree/include/gudhi/Simplex_tree.h | 36 ++++++++++++++++------ src/Simplex_tree/test/simplex_tree_unit_test.cpp | 2 +- 5 files changed, 34 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/example/performance_rips_persistence.cpp b/src/Persistent_cohomology/example/performance_rips_persistence.cpp index 0e912d57..b0366c6c 100644 --- a/src/Persistent_cohomology/example/performance_rips_persistence.cpp +++ b/src/Persistent_cohomology/example/performance_rips_persistence.cpp @@ -85,7 +85,7 @@ int main(int argc, char * argv[]) { std::cout << "Compute Rips graph in " << enlapsed_sec << " sec.\n"; // Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; + Simplex_tree st; start = std::chrono::system_clock::now(); // insert the proximity graph in the simplex tree diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index 5277bf7a..c5cd775d 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -68,7 +68,8 @@ int main(int argc, char * argv[]) { , euclidean_distance); // Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; + typedef Simplex_tree ST; + ST st; // insert the proximity graph in the simplex tree st.insert_graph(prox_graph); // expand the graph until dimension dim_max @@ -78,7 +79,7 @@ int main(int argc, char * argv[]) { st.initialize_filtration(); // Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Multi_field > pcoh(st); + Persistent_cohomology pcoh(st); // initializes the coefficient field for homology pcoh.init_coefficients(min_p, max_p); // compute persistent homology, disgarding persistent features of life shorter than min_persistence diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp index 9b1ef42f..2d926a0d 100644 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_persistence.cpp @@ -65,7 +65,8 @@ int main(int argc, char * argv[]) { , euclidean_distance); // Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; + typedef Simplex_tree ST; + ST st; // insert the proximity graph in the simplex tree st.insert_graph(prox_graph); // expand the graph until dimension dim_max @@ -78,7 +79,7 @@ int main(int argc, char * argv[]) { st.initialize_filtration(); // Compute the persistence diagram of the complex - persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st); + persistent_cohomology::Persistent_cohomology pcoh(st); // initializes the coefficient field for homology pcoh.init_coefficients(p); diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 74ae1713..b9c2a245 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -77,16 +77,7 @@ namespace Gudhi { * @{ */ -/// Model of SimplexTreeOptions. -struct Simplex_tree_options_full_featured { - typedef linear_indexing_tag Indexing_tag; - typedef int Vertex_handle; - typedef double Filtration_value; - typedef int Simplex_key; - static const bool store_key = true; - static const bool store_filtration = true; - static const bool contiguous_vertices = true; -}; +struct Simplex_tree_options_full_featured; /** * \brief Simplex Tree data structure for representing simplicial complexes. @@ -1159,6 +1150,31 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { return is; } + +/// Model of SimplexTreeOptions. +struct Simplex_tree_options_full_featured { + typedef linear_indexing_tag Indexing_tag; + typedef int Vertex_handle; + typedef double Filtration_value; + typedef int Simplex_key; + static const bool store_key = true; + static const bool store_filtration = true; + static const bool contiguous_vertices = false; +}; + +/** Model of SimplexTreeOptions, faster than + `Simplex_tree_options_full_featured` but note the unsafe + `contiguous_vertices` option. */ +struct Simplex_tree_options_fast_persistence { + typedef linear_indexing_tag Indexing_tag; + typedef int Vertex_handle; + typedef float Filtration_value; + typedef int Simplex_key; + static const bool store_key = true; + static const bool store_filtration = true; + static const bool contiguous_vertices = true; +}; + /** @} */ // end defgroup simplex_tree } // namespace Gudhi diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index fff00d77..c2e214c0 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -509,7 +509,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Find in the simplex_tree // ------------------------------------------------------------------------------------------------------------------ typeVectorVertex simpleSimplexVector{1}; - Simplex_tree<>::Simplex_handle simplexFound = st.find(simpleSimplexVector); + typeST::Simplex_handle simplexFound = st.find(simpleSimplexVector); std::cout << "**************IS THE SIMPLEX {1} IN THE SIMPLEX TREE ?\n"; if (simplexFound != st.null_simplex()) std::cout << "***+ YES IT IS!\n"; -- cgit v1.2.3 From 50351a117c7f2622ce2eb5d1d08f561cb9baaa89 Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 9 Nov 2015 18:28:26 +0000 Subject: Change SimplexTreeUT so it can test several versions of Simplex_tree. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/contiguous_vertices@897 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 55d2cf5d87323a54675fe787df3e76dc31a2d684 --- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 99 ++++++++++++++---------- 1 file changed, 57 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index c2e214c0..beb3dc11 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -4,10 +4,12 @@ #include // std::pair, std::make_pair #include // float comparison #include +#include // greater #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE "simplex_tree" #include +#include // ^ // /!\ Nothing else from Simplex_tree shall be included to test includes are well defined. @@ -15,26 +17,25 @@ using namespace Gudhi; -typedef Simplex_tree<> typeST; -typedef std::pair typePairSimplexBool; -typedef std::vector typeVectorVertex; -typedef std::pair typeSimplex; +typedef boost::mpl::list, Simplex_tree> list_of_tested_variants; const Vertex_handle DEFAULT_VERTEX_HANDLE = (const Vertex_handle) - 1; const Filtration_value DEFAULT_FILTRATION_VALUE = (const Filtration_value) 0.0; +template void test_empty_simplex_tree(typeST& tst) { BOOST_CHECK(tst.null_vertex() == DEFAULT_VERTEX_HANDLE); BOOST_CHECK(tst.filtration() == DEFAULT_FILTRATION_VALUE); BOOST_CHECK(tst.num_vertices() == (size_t) 0); BOOST_CHECK(tst.num_simplices() == (size_t) 0); - typeST::Siblings* STRoot = tst.root(); - BOOST_CHECK(STRoot != NULL); - BOOST_CHECK(STRoot->oncles() == NULL); + typename typeST::Siblings* STRoot = tst.root(); + BOOST_CHECK(STRoot != nullptr); + BOOST_CHECK(STRoot->oncles() == nullptr); BOOST_CHECK(STRoot->parent() == DEFAULT_VERTEX_HANDLE); BOOST_CHECK(tst.dimension() == -1); } +template void test_iterators_on_empty_simplex_tree(typeST& tst) { std::cout << "Iterator on vertices: " << std::endl; for (auto vertex : tst.complex_vertex_range()) { @@ -56,8 +57,9 @@ void test_iterators_on_empty_simplex_tree(typeST& tst) { } } -BOOST_AUTO_TEST_CASE(simplex_tree_when_empty) { - const Filtration_value DEFAULT_FILTRATION_VALUE = 0; +BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_when_empty, typeST, list_of_tested_variants) { + typedef std::pair typePairSimplexBool; + typedef std::vector typeVectorVertex; std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF DEFAULT CONSTRUCTOR" << std::endl; @@ -72,7 +74,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_when_empty) { BOOST_CHECK(simplexVectorEmpty.empty() == true); typePairSimplexBool returnEmptyValue = st.insert_simplex(simplexVectorEmpty, DEFAULT_FILTRATION_VALUE); - BOOST_CHECK(returnEmptyValue.first == typeST::Simplex_handle(NULL)); + BOOST_CHECK(returnEmptyValue.first == typename typeST::Simplex_handle(nullptr)); BOOST_CHECK(returnEmptyValue.second == true); test_empty_simplex_tree(st); @@ -84,7 +86,7 @@ bool AreAlmostTheSame(float a, float b) { return std::fabs(a - b) < std::numeric_limits::epsilon(); } -BOOST_AUTO_TEST_CASE(simplex_tree_from_file) { +BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_from_file, typeST, list_of_tested_variants) { // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF SIMPLEX TREE FROM A FILE" << std::endl; @@ -101,7 +103,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_from_file) { // Check BOOST_CHECK(st.num_simplices() == 143353); BOOST_CHECK(st.dimension() == 3); - BOOST_CHECK(st.filtration() == 0.4); + BOOST_CHECK(AreAlmostTheSame(st.filtration(), 0.4)); int previous_size = 0; for (auto f_simplex : st.filtration_simplex_range()) { @@ -119,6 +121,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_from_file) { simplex_tree_stream.close(); } +template void test_simplex_tree_contains(typeST& simplexTree, typeSimplex& simplex, int pos) { auto f_simplex = simplexTree.filtration_simplex_range().begin() + pos; @@ -135,16 +138,18 @@ void test_simplex_tree_contains(typeST& simplexTree, typeSimplex& simplex, int p } } +template void test_simplex_tree_insert_returns_true(const typePairSimplexBool& returnValue) { BOOST_CHECK(returnValue.second == true); - typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned != typeST::Simplex_handle(NULL)); + typename typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + BOOST_CHECK(shReturned != typename typeST::Simplex_handle(nullptr)); } // Global variables Filtration_value max_fil = DEFAULT_FILTRATION_VALUE; int dim_max = -1; +template void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, const Filtration_value& fil) { if (vectorSize > dim_max + 1) { dim_max = vectorSize - 1; @@ -173,11 +178,17 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons BOOST_CHECK(simplexTree.num_simplices() == num_simp); } -BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { +BOOST_AUTO_TEST_CASE_TEMPLATE(simplex_tree_insertion, typeST, list_of_tested_variants) { + typedef std::pair typePairSimplexBool; + typedef std::vector typeVectorVertex; + typedef std::pair typeSimplex; const Filtration_value FIRST_FILTRATION_VALUE = 0.1; const Filtration_value SECOND_FILTRATION_VALUE = 0.2; const Filtration_value THIRD_FILTRATION_VALUE = 0.3; const Filtration_value FOURTH_FILTRATION_VALUE = 0.4; + // reset since we run the test several times + dim_max = -1; + max_fil = DEFAULT_FILTRATION_VALUE; // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; @@ -191,7 +202,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex firstSimplex = std::make_pair(firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); typePairSimplexBool returnValue = st.insert_simplex(firstSimplex.first, firstSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, firstSimplexVector.size(), firstSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 1); @@ -202,7 +213,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex secondSimplex = std::make_pair(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = st.insert_simplex(secondSimplex.first, secondSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, secondSimplexVector.size(), secondSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 2); @@ -213,7 +224,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex thirdSimplex = std::make_pair(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = st.insert_simplex(thirdSimplex.first, thirdSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, thirdSimplexVector.size(), thirdSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 2); // Not incremented !! @@ -224,7 +235,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex fourthSimplex = std::make_pair(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = st.insert_simplex(fourthSimplex.first, fourthSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, fourthSimplexVector.size(), fourthSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 3); @@ -235,7 +246,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex fifthSimplex = std::make_pair(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = st.insert_simplex(fifthSimplex.first, fifthSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, fifthSimplexVector.size(), fifthSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 3); // Not incremented !! @@ -246,7 +257,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex sixthSimplex = std::make_pair(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = st.insert_simplex(sixthSimplex.first, sixthSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, sixthSimplexVector.size(), sixthSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 3); // Not incremented !! @@ -257,7 +268,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex seventhSimplex = std::make_pair(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); returnValue = st.insert_simplex(seventhSimplex.first, seventhSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, seventhSimplexVector.size(), seventhSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 3); // Not incremented !! @@ -268,7 +279,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex eighthSimplex = std::make_pair(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = st.insert_simplex(eighthSimplex.first, eighthSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, eighthSimplexVector.size(), eighthSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 4); @@ -279,7 +290,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { typeSimplex ninethSimplex = std::make_pair(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = st.insert_simplex(ninethSimplex.first, ninethSimplex.second); - test_simplex_tree_insert_returns_true(returnValue); + test_simplex_tree_insert_returns_true(returnValue); set_and_test_simplex_tree_dim_fil(st, ninethSimplexVector.size(), ninethSimplex.second); BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented !! @@ -292,8 +303,8 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { returnValue = st.insert_simplex(tenthSimplex.first, tenthSimplex.second); BOOST_CHECK(returnValue.second == false); - typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); + typename typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + BOOST_CHECK(shReturned == typename typeST::Simplex_handle(nullptr)); BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented !! BOOST_CHECK(st.dimension() == dim_max); BOOST_CHECK(AreAlmostTheSame(st.filtration(), max_fil)); @@ -307,7 +318,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { BOOST_CHECK(returnValue.second == false); shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); + BOOST_CHECK(shReturned == typename typeST::Simplex_handle(nullptr)); BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented !! BOOST_CHECK(st.dimension() == dim_max); BOOST_CHECK(AreAlmostTheSame(st.filtration(), max_fil)); @@ -362,9 +373,10 @@ BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { } -bool sort_in_decr_order (Vertex_handle i,Vertex_handle j) { return (i>j); } - -BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { +BOOST_AUTO_TEST_CASE_TEMPLATE(NSimplexAndSubfaces_tree_insertion, typeST, list_of_tested_variants) { + typedef std::pair typePairSimplexBool; + typedef std::vector typeVectorVertex; + typedef std::pair typeSimplex; std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF RECURSIVE INSERTION" << std::endl; typeST st; @@ -382,7 +394,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector1.begin(), SimplexVector1.end(), sort_in_decr_order); + std::sort(SimplexVector1.begin(), SimplexVector1.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector1[position] << std::endl; @@ -401,7 +413,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector2.begin(), SimplexVector2.end(), sort_in_decr_order); + std::sort(SimplexVector2.begin(), SimplexVector2.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector2[position] << std::endl; @@ -420,7 +432,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector3.begin(), SimplexVector3.end(), sort_in_decr_order); + std::sort(SimplexVector3.begin(), SimplexVector3.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector3[position] << std::endl; @@ -450,7 +462,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector5.begin(), SimplexVector5.end(), sort_in_decr_order); + std::sort(SimplexVector5.begin(), SimplexVector5.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector5[position] << std::endl; @@ -469,7 +481,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Check it is well inserted BOOST_CHECK(true == returnValue.second); position = 0; - std::sort(SimplexVector6.begin(), SimplexVector6.end(), sort_in_decr_order); + std::sort(SimplexVector6.begin(), SimplexVector6.end(), std::greater()); for (auto vertex : st.simplex_vertex_range(returnValue.first)) { // Check returned Simplex_handle std::cout << "vertex = " << vertex << " | vector[" << position << "] = " << SimplexVector6[position] << std::endl; @@ -509,7 +521,7 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { // Find in the simplex_tree // ------------------------------------------------------------------------------------------------------------------ typeVectorVertex simpleSimplexVector{1}; - typeST::Simplex_handle simplexFound = st.find(simpleSimplexVector); + typename typeST::Simplex_handle simplexFound = st.find(simpleSimplexVector); std::cout << "**************IS THE SIMPLEX {1} IN THE SIMPLEX TREE ?\n"; if (simplexFound != st.null_simplex()) std::cout << "***+ YES IT IS!\n"; @@ -570,14 +582,15 @@ BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { } } -void test_cofaces(typeST& st, std::vector expected, int dim, std::vector res) { - typeST::Cofaces_simplex_range cofaces; +template +void test_cofaces(typeST& st, const std::vector& expected, int dim, const std::vector& res) { + typename typeST::Cofaces_simplex_range cofaces; if (dim == 0) cofaces = st.star_simplex_range(st.find(expected)); else cofaces = st.cofaces_simplex_range(st.find(expected), dim); for (auto simplex = cofaces.begin(); simplex != cofaces.end(); ++simplex) { - typeST::Simplex_vertex_range rg = st.simplex_vertex_range(*simplex); + typename typeST::Simplex_vertex_range rg = st.simplex_vertex_range(*simplex); for (auto vertex = rg.begin(); vertex != rg.end(); ++vertex) { std::cout << "(" << *vertex << ")"; } @@ -586,7 +599,8 @@ void test_cofaces(typeST& st, std::vector expected, int dim, std: } } -BOOST_AUTO_TEST_CASE(coface_on_simplex_tree) { +BOOST_AUTO_TEST_CASE_TEMPLATE(coface_on_simplex_tree, typeST, list_of_tested_variants) { + typedef std::vector typeVectorVertex; std::cout << "********************************************************************" << std::endl; std::cout << "TEST COFACE ALGORITHM" << std::endl; typeST st; @@ -616,7 +630,7 @@ BOOST_AUTO_TEST_CASE(coface_on_simplex_tree) { st.set_dimension(3); std::vector simplex_result; - std::vector result; + std::vector result; std::cout << "First test - Star of (3):" << std::endl; simplex_result = {3}; @@ -684,7 +698,8 @@ BOOST_AUTO_TEST_CASE(coface_on_simplex_tree) { } -BOOST_AUTO_TEST_CASE(copy_move_on_simplex_tree) { +BOOST_AUTO_TEST_CASE_TEMPLATE(copy_move_on_simplex_tree, typeST, list_of_tested_variants) { + typedef std::vector typeVectorVertex; std::cout << "********************************************************************" << std::endl; std::cout << "TEST COPY MOVE CONSTRUCTORS" << std::endl; typeST st; -- cgit v1.2.3 From eecc6eef3ca893894c885eed6e7fb5861cea074b Mon Sep 17 00:00:00 2001 From: glisse Date: Mon, 9 Nov 2015 20:02:44 +0000 Subject: Specific test for non-contiguous vertices. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/contiguous_vertices@898 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5295613117e6a66147dec38327b437bcf5b253c3 --- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src') diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index beb3dc11..874c3363 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -759,3 +759,39 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(copy_move_on_simplex_tree, typeST, list_of_tested_ std::cout << "Printing st once again- address = " << &st << std::endl; } + +template +void test_simplex_is_vertex(typeST& st, typename typeST::Simplex_handle sh, typename typeST::Vertex_handle v) { + BOOST_CHECK(st.dimension(sh) == 0); + auto&& r = st.simplex_vertex_range(sh); + auto i = std::begin(r); + BOOST_CHECK(*i == v); + BOOST_CHECK(++i == std::end(r)); +} + +BOOST_AUTO_TEST_CASE(non_contiguous) { + typedef Simplex_tree<> typeST; + typedef typeST::Vertex_handle Vertex_handle; + typedef typeST::Simplex_handle Simplex_handle; + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST NON-CONTIGUOUS VERTICES" << std::endl; + typeST st; + Vertex_handle e[] = {3,-7}; + std::cout << "Insert" << std::endl; + st.insert_simplex_and_subfaces(e); + BOOST_CHECK(st.num_vertices() == 2); + BOOST_CHECK(st.num_simplices() == 3); + std::cout << "Find" << std::endl; + Simplex_handle sh = st.find(e); + BOOST_CHECK(sh != st.null_simplex()); + std::cout << "Endpoints" << std::endl; + auto p = st.endpoints(sh); + test_simplex_is_vertex(st, p.first, 3); + test_simplex_is_vertex(st, p.second, -7); + std::cout << "Boundary" << std::endl; + auto&& b = st.boundary_simplex_range(sh); + auto i = std::begin(b); + test_simplex_is_vertex(st, *i, -7); + test_simplex_is_vertex(st, *++i, 3); + BOOST_CHECK(++i == std::end(b)); +} -- cgit v1.2.3 From 416b251a88afb83d05d4fb891863e8b99afdab2b Mon Sep 17 00:00:00 2001 From: glisse Date: Tue, 10 Nov 2015 16:30:43 +0000 Subject: Use Simplex_tree_options_fast_persistence in one more place. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/contiguous_vertices@899 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b22785182c0140dd36d1a4876c240aa4deabef75 --- src/Persistent_cohomology/example/alpha_shapes_persistence.cpp | 7 ++++--- src/Persistent_cohomology/example/persistence_from_file.cpp | 2 +- src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp index 6d5eebcf..92c0b065 100644 --- a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp @@ -66,7 +66,8 @@ typedef Alpha_shape_3::Edge Edge_3; typedef std::list Vertex_list; // gudhi type definition -typedef Simplex_tree<>::Vertex_handle Simplex_tree_vertex; +typedef Simplex_tree ST; +typedef ST::Vertex_handle Simplex_tree_vertex; typedef std::map Alpha_shape_simplex_tree_map; typedef std::pair Alpha_shape_simplex_tree_pair; typedef std::vector< Simplex_tree_vertex > Simplex_tree_vector_vertex; @@ -184,7 +185,7 @@ int main(int argc, char * const argv[]) { // Loop on objects vector Vertex_list vertex_list; - Simplex_tree<> simplex_tree; + ST simplex_tree; Alpha_shape_simplex_tree_map map_cgal_simplex_tree; std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); int dim_max = 0; @@ -281,7 +282,7 @@ int main(int argc, char * const argv[]) { std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; // Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree); + Persistent_cohomology< ST, Field_Zp > pcoh(simplex_tree); // initializes the coefficient field for homology pcoh.init_coefficients(coeff_field_characteristic); diff --git a/src/Persistent_cohomology/example/persistence_from_file.cpp b/src/Persistent_cohomology/example/persistence_from_file.cpp index 8eb8d0f3..67235467 100644 --- a/src/Persistent_cohomology/example/persistence_from_file.cpp +++ b/src/Persistent_cohomology/example/persistence_from_file.cpp @@ -54,7 +54,7 @@ int main(int argc, char * argv[]) { << std::endl; std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl; - // Construct the Rips complex in a Simplex Tree + // Read the list of simplices from a file. Simplex_tree<> simplex_tree; std::ifstream simplex_tree_stream(simplex_tree_file); diff --git a/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp b/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp index 45efe3ed..49d358ab 100644 --- a/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp +++ b/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp @@ -62,7 +62,8 @@ typedef Alpha_shape_3::Edge Edge; typedef std::list Vertex_list; // gudhi type definition -typedef Gudhi::Simplex_tree<>::Vertex_handle Simplex_tree_vertex; +typedef Gudhi::Simplex_tree<> Simplex_tree; +typedef Simplex_tree::Vertex_handle Simplex_tree_vertex; typedef std::map Alpha_shape_simplex_tree_map; typedef std::pair Alpha_shape_simplex_tree_pair; typedef std::vector< Simplex_tree_vertex > Simplex_tree_vector_vertex; @@ -161,7 +162,7 @@ int main(int argc, char * const argv[]) { // Loop on objects vector Vertex_list vertex_list; - Gudhi::Simplex_tree<> simplex_tree; + Simplex_tree simplex_tree; Alpha_shape_simplex_tree_map map_cgal_simplex_tree; std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); for (auto object_iterator : the_objects) { -- cgit v1.2.3 From 6f73317041162da6dcc8bc5f52ca62a560b12ec4 Mon Sep 17 00:00:00 2001 From: glisse Date: Tue, 10 Nov 2015 16:37:17 +0000 Subject: Update a comment in plain_homology. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@901 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9a04cd581e4b4a2ea26c474ec0928a67b990dc98 --- src/Persistent_cohomology/example/plain_homology.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/Persistent_cohomology/example/plain_homology.cpp b/src/Persistent_cohomology/example/plain_homology.cpp index e293e013..0a692717 100644 --- a/src/Persistent_cohomology/example/plain_homology.cpp +++ b/src/Persistent_cohomology/example/plain_homology.cpp @@ -27,6 +27,10 @@ using namespace Gudhi; +/* We could perfectly well use the default Simplex_tree<> (which uses + * Simplex_tree_options_full_featured), the following simply demonstrates + * how to save on storage by not storing a filtration value. */ + struct MyOptions : Simplex_tree_options_full_featured { // Implicitly use 0 as filtration value for all simplices static const bool store_filtration = false; -- cgit v1.2.3 From e8941294bae84a6185860425177ba8237068dcf4 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 11 Nov 2015 17:00:19 +0000 Subject: Allow st.find({1,2,3}) on good compilers. That includes VS 2015 but not 2013, however I believe it will just ignore the change so it should not hurt. (I'll revert otherwise) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@904 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8f29072c7f5bfa24de5033ada6b377deaf0c8689 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 4c6a95e8..ea61fa2e 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -39,6 +39,7 @@ #include #include #include // for greater<> +#include namespace Gudhi { @@ -531,7 +532,7 @@ class Simplex_tree { * The type InputVertexRange must be a range of Vertex_handle * on which we can call std::begin() function */ - template + template> Simplex_handle find(const InputVertexRange & s) { auto first = std::begin(s); auto last = std::end(s); @@ -625,7 +626,7 @@ class Simplex_tree { * * The type InputVertexRange must be a range for which .begin() and * .end() return input iterators, with 'value_type' Vertex_handle. */ - template + template> std::pair insert_simplex(const InputVertexRange & simplex, Filtration_value filtration = 0) { auto first = std::begin(simplex); @@ -654,7 +655,7 @@ class Simplex_tree { * output pair to the Simplex_handle of the simplex. Otherwise, we set the Simplex_handle part to * null_simplex. */ - template + template> std::pair insert_simplex_and_subfaces(const InputVertexRange& Nsimplex, Filtration_value filtration = 0) { auto first = std::begin(Nsimplex); -- cgit v1.2.3 From 340944d185b9c02f93400e2ff6bf764a5c027e91 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 11 Nov 2015 21:20:28 +0000 Subject: Make annotations_in_boundary a vector, sorted once after construction, with entries sharing the same annotation accumulated as we go. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@907 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 68351e5d61b1e3eb0b2d6c3623d7d213da9371d4 --- .../include/gudhi/Persistent_cohomology.h | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index d096792f..3875afc6 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,9 +431,13 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity, in a map. - std::map annotations_in_boundary; - std::pair::iterator, bool> result_insert_bound; + // with multiplicity. +#if 0 + std::vector> annotations_in_boundary; +#else + static std::vector> annotations_in_boundary; + annotations_in_boundary.clear(); +#endif int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -445,22 +449,29 @@ class Persistent_cohomology { // Find its annotation vector curr_col = ds_repr_[dsets_.find_set(key)]; if (curr_col != NULL) { // and insert it in annotations_in_boundary with multyiplicative factor "sign". - result_insert_bound = annotations_in_boundary.insert(std::pair(curr_col, sign)); - if (!(result_insert_bound.second)) { - result_insert_bound.first->second += sign; - } + annotations_in_boundary.emplace_back(curr_col, sign); } } sign = -sign; } + std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - for (auto ann_ref : annotations_in_boundary) { - if (ann_ref.second != coeff_field_.additive_identity()) { // For all columns in the boundary, - for (auto cell_ref : ann_ref.first->col_) { // insert every cell in map_a_ds with multiplicity - Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, ann_ref.second); // coefficient * multiplicity + auto ann_it = annotations_in_boundary.begin(); + while (ann_it != annotations_in_boundary.end()) { + auto col = ann_it->first; + int coef = ann_it->second; + for (;;) { + if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) + break; + coef += ann_it->second; + } + // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. + if (coef != coeff_field_.additive_identity()) { // For all columns in the boundary, + for (auto cell_ref : col->col_) { // insert every cell in map_a_ds with multiplicity + Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, coef); // coefficient * multiplicity if (w_y != coeff_field_.additive_identity()) { // if != 0 result_insert_a_ds = map_a_ds.insert(std::pair(cell_ref.key_, w_y)); -- cgit v1.2.3 From 484f3f7f57946d0a82b18c78f954a836dc4e1d57 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 11 Nov 2015 21:24:18 +0000 Subject: Revert the last commit, this was supposed to go to a branch. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@908 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 66d468165b97b852fbe897bea212c85ac9fb0e14 --- .../include/gudhi/Persistent_cohomology.h | 33 ++++++++-------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 3875afc6..d096792f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,13 +431,9 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity. -#if 0 - std::vector> annotations_in_boundary; -#else - static std::vector> annotations_in_boundary; - annotations_in_boundary.clear(); -#endif + // with multiplicity, in a map. + std::map annotations_in_boundary; + std::pair::iterator, bool> result_insert_bound; int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -449,29 +445,22 @@ class Persistent_cohomology { // Find its annotation vector curr_col = ds_repr_[dsets_.find_set(key)]; if (curr_col != NULL) { // and insert it in annotations_in_boundary with multyiplicative factor "sign". - annotations_in_boundary.emplace_back(curr_col, sign); + result_insert_bound = annotations_in_boundary.insert(std::pair(curr_col, sign)); + if (!(result_insert_bound.second)) { + result_insert_bound.first->second += sign; + } } } sign = -sign; } - std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - auto ann_it = annotations_in_boundary.begin(); - while (ann_it != annotations_in_boundary.end()) { - auto col = ann_it->first; - int coef = ann_it->second; - for (;;) { - if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) - break; - coef += ann_it->second; - } - // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. - if (coef != coeff_field_.additive_identity()) { // For all columns in the boundary, - for (auto cell_ref : col->col_) { // insert every cell in map_a_ds with multiplicity - Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, coef); // coefficient * multiplicity + for (auto ann_ref : annotations_in_boundary) { + if (ann_ref.second != coeff_field_.additive_identity()) { // For all columns in the boundary, + for (auto cell_ref : ann_ref.first->col_) { // insert every cell in map_a_ds with multiplicity + Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, ann_ref.second); // coefficient * multiplicity if (w_y != coeff_field_.additive_identity()) { // if != 0 result_insert_a_ds = map_a_ds.insert(std::pair(cell_ref.key_, w_y)); -- cgit v1.2.3 From fc91de9f736c13f38d096fc1da78c688e7992fe7 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 11 Nov 2015 21:25:38 +0000 Subject: Make annotations_in_boundary a vector, sorted once after construction, with entries sharing the same annotation accumulated as we go. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@909 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 34b2ae74dc017c18a90e08caee6f707b6b0d4cc2 --- .../include/gudhi/Persistent_cohomology.h | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index d096792f..3875afc6 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,9 +431,13 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity, in a map. - std::map annotations_in_boundary; - std::pair::iterator, bool> result_insert_bound; + // with multiplicity. +#if 0 + std::vector> annotations_in_boundary; +#else + static std::vector> annotations_in_boundary; + annotations_in_boundary.clear(); +#endif int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -445,22 +449,29 @@ class Persistent_cohomology { // Find its annotation vector curr_col = ds_repr_[dsets_.find_set(key)]; if (curr_col != NULL) { // and insert it in annotations_in_boundary with multyiplicative factor "sign". - result_insert_bound = annotations_in_boundary.insert(std::pair(curr_col, sign)); - if (!(result_insert_bound.second)) { - result_insert_bound.first->second += sign; - } + annotations_in_boundary.emplace_back(curr_col, sign); } } sign = -sign; } + std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - for (auto ann_ref : annotations_in_boundary) { - if (ann_ref.second != coeff_field_.additive_identity()) { // For all columns in the boundary, - for (auto cell_ref : ann_ref.first->col_) { // insert every cell in map_a_ds with multiplicity - Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, ann_ref.second); // coefficient * multiplicity + auto ann_it = annotations_in_boundary.begin(); + while (ann_it != annotations_in_boundary.end()) { + auto col = ann_it->first; + int coef = ann_it->second; + for (;;) { + if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) + break; + coef += ann_it->second; + } + // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. + if (coef != coeff_field_.additive_identity()) { // For all columns in the boundary, + for (auto cell_ref : col->col_) { // insert every cell in map_a_ds with multiplicity + Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, coef); // coefficient * multiplicity if (w_y != coeff_field_.additive_identity()) { // if != 0 result_insert_a_ds = map_a_ds.insert(std::pair(cell_ref.key_, w_y)); -- cgit v1.2.3 From ccf7f9e5b8840f57c68dec83e2153c3cc5804b61 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:07:20 +0000 Subject: Clean-up. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@912 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f5652acf2ed5eb6f11428d2907963b5d1a1359be --- .../include/gudhi/Persistent_cohomology.h | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 3875afc6..2d6a85c1 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -431,13 +431,14 @@ class Persistent_cohomology { std::map & map_a_ds, Simplex_handle sigma, int dim_sigma) { // traverses the boundary of sigma, keeps track of the annotation vectors, - // with multiplicity. -#if 0 - std::vector> annotations_in_boundary; -#else - static std::vector> annotations_in_boundary; - annotations_in_boundary.clear(); -#endif + // with multiplicity. We used to sum the coefficients directly in + // annotations_in_boundary by using a map, we now do it later. + typedef std::pair annotation_t; + std::vector annotations_in_boundary; + /* A small speed boost is possible with the following non-thread-safe: + static std::vector> annotations_in_boundary; + annotations_in_boundary.clear(); + */ int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; @@ -454,18 +455,18 @@ class Persistent_cohomology { } sign = -sign; } - std::sort(annotations_in_boundary.begin(),annotations_in_boundary.end(),[](auto&a,auto&b){return a.first // to represent a sparse vector. std::pair::iterator, bool> result_insert_a_ds; - auto ann_it = annotations_in_boundary.begin(); - while (ann_it != annotations_in_boundary.end()) { - auto col = ann_it->first; + for (auto ann_it = annotations_in_boundary.begin(); ann_it != annotations_in_boundary.end(); /**/) { + Column* col = ann_it->first; int coef = ann_it->second; - for (;;) { - if (++ann_it == annotations_in_boundary.end() || ann_it->first != col) - break; + while (++ann_it != annotations_in_boundary.end() && ann_it->first == col) { coef += ann_it->second; } // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. -- cgit v1.2.3 From 32a6d46672102e17f7ae09fe130382aa7e487884 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:14:03 +0000 Subject: Rename variable. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@913 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 0afbcbee5739c1649d1c9b968d9f0748c7d1d219 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 2d6a85c1..1d8c2ca2 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -465,14 +465,14 @@ class Persistent_cohomology { for (auto ann_it = annotations_in_boundary.begin(); ann_it != annotations_in_boundary.end(); /**/) { Column* col = ann_it->first; - int coef = ann_it->second; + int mult = ann_it->second; while (++ann_it != annotations_in_boundary.end() && ann_it->first == col) { - coef += ann_it->second; + mult += ann_it->second; } // The following test is just a heuristic, it is not required, and it is fine that is misses p == 0. - if (coef != coeff_field_.additive_identity()) { // For all columns in the boundary, + if (mult != coeff_field_.additive_identity()) { // For all columns in the boundary, for (auto cell_ref : col->col_) { // insert every cell in map_a_ds with multiplicity - Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, coef); // coefficient * multiplicity + Arith_element w_y = coeff_field_.times(cell_ref.coefficient_, mult); // coefficient * multiplicity if (w_y != coeff_field_.additive_identity()) { // if != 0 result_insert_a_ds = map_a_ds.insert(std::pair(cell_ref.key_, w_y)); -- cgit v1.2.3 From bdb1e5517822d935da93d83c8950cbbd11560698 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:27:56 +0000 Subject: Using a static variable really helps. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/annotations_in_boundary@914 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 695a6f642399c2646e5a26fac20173fbd57fe160 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 1d8c2ca2..609f40a2 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -434,11 +434,9 @@ class Persistent_cohomology { // with multiplicity. We used to sum the coefficients directly in // annotations_in_boundary by using a map, we now do it later. typedef std::pair annotation_t; - std::vector annotations_in_boundary; - /* A small speed boost is possible with the following non-thread-safe: - static std::vector> annotations_in_boundary; - annotations_in_boundary.clear(); - */ + // Danger: not thread-safe! + static std::vector annotations_in_boundary; + annotations_in_boundary.clear(); int sign = 1 - 2 * (dim_sigma % 2); // \in {-1,1} provides the sign in the // alternate sum in the boundary. Simplex_key key; -- cgit v1.2.3 From fe40846f6cbdf355a2b7c1f2624c5c0e023fa8bb Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 13 Nov 2015 20:47:42 +0000 Subject: Unobfuscate a multiplication. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@915 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 771fd96e47209ceee8ffa05519134f0c8069b1cf --- .../include/gudhi/Persistent_cohomology/Multi_field.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h index 0591fc95..38bc08d1 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h @@ -81,8 +81,7 @@ class Multi_field { // set m to primorial(bound_prime) prod_characteristics_ = 1; for (auto p : primes_) { - mpz_mul_ui(prod_characteristics_.get_mpz_t(), - prod_characteristics_.get_mpz_t(), p); + prod_characteristics_ *= p; } // Uvect_ -- cgit v1.2.3 From 0e156a914ecfa1e8d71a8bee49400ed66a191637 Mon Sep 17 00:00:00 2001 From: salinasd Date: Sat, 14 Nov 2015 15:21:34 +0000 Subject: skbl: correct typo in test and small renamings git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@918 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 543ae94051051e1a79f95192db24fcd411dbea28 --- .../example/Skeleton_blocker_link.cpp | 7 ++- .../Skeleton_blocker/Skeleton_blocker_simplex.h | 4 +- .../include/gudhi/Skeleton_blocker_complex.h | 58 +++++++++++----------- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 15 ++++-- src/Skeleton_blocker/test/TestSimplifiable.cpp | 2 +- .../test/TestSkeletonBlockerComplex.cpp | 2 +- 6 files changed, 48 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp index 5c717938..5e429728 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp @@ -39,9 +39,12 @@ typedef Complex::Simplex Simplex; int main(int argc, char *argv[]) { // build a full complex with 4 vertices and 2^4-1 simplices - // Initial vertices are (0,1,2,3,4) - Simplex tetrahedron(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + + // Create a complex with four vertices (0,1,2,3) Complex complex; + + // Add a tetrahedron to this complex + Simplex tetrahedron(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); complex.add_simplex(tetrahedron); cout << "complex:" << complex.to_string() << endl; diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h index 0d838d50..714bf23c 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h @@ -218,7 +218,7 @@ class Skeleton_blocker_simplex { } /** - * Returns the first vertex of the (oriented) simplex. + * Returns the first and smallest vertex of the simplex. * * Be careful : assumes the simplex is non-empty. */ @@ -228,7 +228,7 @@ class Skeleton_blocker_simplex { } /** - * Returns the last vertex of the (oriented) simplex. + * Returns the last and greatest vertex of the simplex. * * Be careful : assumes the simplex is non-empty. */ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index b1995783..cf156a58 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -23,16 +23,26 @@ #ifndef SKELETON_BLOCKER_COMPLEX_H_ #define SKELETON_BLOCKER_COMPLEX_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include #include #include - #include #include #include - #include #include @@ -40,18 +50,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - namespace Gudhi { namespace skbl { @@ -182,25 +180,28 @@ class Skeleton_blocker_complex { * @details is_flag_complex indicates if the complex is a flag complex or not (to know if blockers have to be computed or not). */ template - Skeleton_blocker_complex(SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end, + Skeleton_blocker_complex(SimpleHandleOutputIterator simplices_begin, SimpleHandleOutputIterator simplices_end, bool is_flag_complex = false, Visitor* visitor_ = NULL) : num_vertices_(0), num_blockers_(0), visitor(visitor_) { - add_vertex_and_edges(simplex_begin, simplex_end); + add_vertices_and_edges(simplices_begin, simplices_end); if (!is_flag_complex) // need to compute blockers - add_blockers(simplex_begin, simplex_end); + add_blockers(simplices_begin, simplices_end); } private: + /** + * Add vertices and edges of a simplex in one pass + */ template - void add_vertex_and_edges(SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end) { + void add_vertices_and_edges(SimpleHandleOutputIterator simplices_begin, SimpleHandleOutputIterator simplices_end) { std::vector> edges; // first pass to add vertices and edges int num_vertex = -1; - for (auto s_it = simplex_begin; s_it != simplex_end; ++s_it) { + for (auto s_it = simplices_begin; s_it != simplices_end; ++s_it) { if (s_it->dimension() == 0) num_vertex = (std::max)(num_vertex, s_it->first_vertex().vertex); if (s_it->dimension() == 1) edges.emplace_back(s_it->first_vertex(), s_it->last_vertex()); } @@ -210,9 +211,10 @@ class Skeleton_blocker_complex { add_edge_without_blockers(e.first, e.second); } + template - void add_blockers(SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end) { - Tries tries(num_vertices(), simplex_begin, simplex_end); + void add_blockers(SimpleHandleOutputIterator simplices_begin, SimpleHandleOutputIterator simplices_end) { + Tries tries(num_vertices(), simplices_begin, simplices_end); tries.init_next_dimension(); auto simplices(tries.next_dimension_simplices()); @@ -378,6 +380,7 @@ class Skeleton_blocker_complex { /** * @brief Adds a vertex to the simplicial complex and returns its Vertex_handle. + * @remark Vertex representation is contiguous. */ Vertex_handle add_vertex() { Vertex_handle address(boost::add_vertex(skeleton)); @@ -1128,13 +1131,10 @@ class Skeleton_blocker_complex { void remove_star(const Simplex& sigma); /** - * @brief add a simplex. - * @details the simplex must have dimension greater than one (otherwise use add_vertex or add_edge_without_blockers). - * and all vertices lower than the higher vertex of sigma must already be in the complex. - * if some edges of sigma are not in the complex, then insert_edges_of_sigma flag must be - * set to true. + * @brief add a simplex and all its faces. + * @details the simplex must have dimension greater than one (otherwise use add_vertex or add_edge_without_blockers). */ - void add_simplex(const Simplex& sigma, bool insert_edges_of_sigma = false); + void add_simplex(const Simplex& sigma); private: void add_blockers_after_simplex_insertion(Simplex s); @@ -1583,12 +1583,12 @@ class Skeleton_blocker_complex { * return the total number of simplices */ template -Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, SimplexHandleIterator simplex_end, +Complex make_complex_from_top_faces(SimplexHandleIterator simplices_begin, SimplexHandleIterator simplices_end, bool is_flag_complex = false) { //todo use add_simplex instead! should be more efficient and more elegant :) typedef typename Complex::Simplex Simplex; std::vector simplices; - for (auto top_face = simplex_begin; top_face != simplex_end; ++top_face) { + for (auto top_face = simplices_begin; top_face != simplices_end; ++top_face) { auto subfaces_topface = subfaces(*top_face); simplices.insert(simplices.end(), subfaces_topface.begin(), subfaces_topface.end()); } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h index 79a7ed79..1b7d58ff 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -206,21 +206,26 @@ void Skeleton_blocker_complex::remove_star(const Simplex& sig } template -void Skeleton_blocker_complex::add_simplex(const Simplex& sigma, bool insert_edges_of_sigma) { +void Skeleton_blocker_complex::add_simplex(const Simplex& sigma) { // to add a simplex s, all blockers included in s are first removed // and then all simplex in the coboundary of s are added as blockers assert(!this->contains(sigma)); assert(sigma.dimension() > 1); + if (!contains_vertices(sigma)) { + std::cerr << "add_simplex: Some vertices were not present in the complex, adding them" << std::endl; + size_t num_vertices_to_add = sigma.last_vertex() - this->num_vertices() + 1; + for (size_t i = 0; i < num_vertices_to_add; ++i) + this->add_vertex(); + } assert(contains_vertices(sigma)); - - if(insert_edges_of_sigma) + if(!contains_edges(sigma)) add_edge(sigma); - else - assert(contains_edges(sigma)); remove_blocker_include_in_simplex(sigma); add_blockers_after_simplex_insertion(sigma); } + + template void Skeleton_blocker_complex::add_blockers_after_simplex_insertion(Simplex sigma){ if(sigma.dimension() < 1) return; diff --git a/src/Skeleton_blocker/test/TestSimplifiable.cpp b/src/Skeleton_blocker/test/TestSimplifiable.cpp index 76d5ba89..b0855ce9 100644 --- a/src/Skeleton_blocker/test/TestSimplifiable.cpp +++ b/src/Skeleton_blocker/test/TestSimplifiable.cpp @@ -310,7 +310,7 @@ bool test_add_simplex4() { for (int k = 0; k < n; k++) s.add_vertex(Vertex_handle(k)); s.remove_vertex(Vertex_handle(i)); - complex.add_simplex(s, true); + complex.add_simplex(s); //at step i there is only blocker 0..i if (i < 2 && complex.num_blockers() > 0) diff --git a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp index 69abd279..42482e23 100644 --- a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp +++ b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp @@ -367,7 +367,7 @@ bool test_iterator_simplices4() { bool test_iterator_coboundary() { Complex c; build_complete(4, c); - c.remove_edge(Vertex_handle(0), Vertex_handle(2)); + c.remove_edge(Vertex_handle(1), Vertex_handle(3)); PRINT(c.to_string()); Simplex s02(Vertex_handle(0), Vertex_handle(2)); int n = 0; -- cgit v1.2.3 From b15b9c7f6f5dd232dee897c96d65f5f77e215314 Mon Sep 17 00:00:00 2001 From: glisse Date: Sun, 15 Nov 2015 10:04:32 +0000 Subject: Fix for older libstdc++. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@922 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d370bbf81488ef6b07a17d63ad43ba2b813e2210 --- src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 609f40a2..2a405830 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -455,7 +455,7 @@ class Persistent_cohomology { } // Place identical annotations consecutively so we can easily sum their multiplicities. std::sort(annotations_in_boundary.begin(), annotations_in_boundary.end(), - [](annotation_t& a, annotation_t& b) { return a.first < b.first; }); + [](annotation_t const& a, annotation_t const& b) { return a.first < b.first; }); // Sum the annotations with multiplicity, using a map // to represent a sparse vector. -- cgit v1.2.3 From c6c91153dde643af2c5b9c78a1b1b9b65349c292 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 16 Nov 2015 10:09:38 +0000 Subject: cpplint fixes before merge git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@923 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: de9fc0770d273730de876a6ed54646847362bc7d --- src/Contraction/example/Garland_heckbert.cpp | 14 +++--- .../example/Skeleton_blocker_link.cpp | 5 +- .../include/gudhi/Skeleton_blocker_complex.h | 58 +++++++++++----------- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 29 ++++++----- 4 files changed, 53 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index 681426e0..3ba9501b 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -145,13 +145,14 @@ class GH_visitor : public Gudhi::contraction::Contraction_visitor { int main(int argc, char *argv[]) { if (argc != 4) { - std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; + std::cerr << "Usage " << argv[0] << + " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; return EXIT_FAILURE; } Complex complex; typedef typename Complex::Vertex_handle Vertex_handle; - + // load the points Skeleton_blocker_off_reader off_reader(argv[1], complex); if (!off_reader.is_valid()) { @@ -159,9 +160,9 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(!complex.empty() && !complex.point(Vertex_handle(0)).dimension()==3) { + if (!complex.empty() && !(complex.point(Vertex_handle(0)).dimension() == 3)) { std::cerr << "Only points of dimension 3 are supported." << std::endl; - return EXIT_FAILURE; + return EXIT_FAILURE; } std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; @@ -175,8 +176,7 @@ int main(int argc, char *argv[]) { new GH_cost(complex), new GH_placement(complex), contraction::make_link_valid_contraction(), - new GH_visitor(complex) - ); + new GH_visitor(complex)); std::cout << "Contract " << num_contractions << " edges" << std::endl; contractor.contract_edges(num_contractions); @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) { complex.num_edges() << " edges and " << complex.num_triangles() << " triangles." << std::endl; - //write simplified complex + // write simplified complex Skeleton_blocker_off_writer off_writer(argv[2], complex); return EXIT_SUCCESS; diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp index 5e429728..698a8106 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp @@ -39,7 +39,7 @@ typedef Complex::Simplex Simplex; int main(int argc, char *argv[]) { // build a full complex with 4 vertices and 2^4-1 simplices - + // Create a complex with four vertices (0,1,2,3) Complex complex; @@ -64,7 +64,8 @@ int main(int argc, char *argv[]) { // To access to the initial vertices eg (0,1,2,3,4), Root_vertex_handle must be used. // For instance, to test if the link contains the vertex that was labeled i: for (int i = 0; i < 5; ++i) - cout << "link.contains_vertex(Root_vertex_handle(" << i << ")):" << link.contains_vertex(Root_vertex_handle(i)) << endl; + cout << "link.contains_vertex(Root_vertex_handle(" << i << ")):" << + link.contains_vertex(Root_vertex_handle(i)) << endl; return EXIT_SUCCESS; } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index cf156a58..6612722e 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -23,18 +23,6 @@ #ifndef SKELETON_BLOCKER_COMPLEX_H_ #define SKELETON_BLOCKER_COMPLEX_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include #include @@ -50,6 +38,18 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + namespace Gudhi { namespace skbl { @@ -550,13 +550,13 @@ class Skeleton_blocker_complex { * the edges 01, 12, 20 but not the triangle 012 (and hence this complex * will contains a blocker 012). */ - Edge_handle add_edge(Vertex_handle a, Vertex_handle b) { - //if the edge is already there we musnt go further - //as we may add blockers that should not be here - if(contains_edge(a,b)) - return *((*this)[std::make_pair(a,b)]); - auto res = add_edge_without_blockers(a,b); - add_blockers_after_simplex_insertion(Simplex(a,b)); + Edge_handle add_edge(Vertex_handle a, Vertex_handle b) { + // if the edge is already there we musnt go further + // as we may add blockers that should not be here + if (contains_edge(a, b)) + return *((*this)[std::make_pair(a, b)]); + auto res = add_edge_without_blockers(a, b); + add_blockers_after_simplex_insertion(Simplex(a, b)); return res; } @@ -564,9 +564,9 @@ class Skeleton_blocker_complex { * @brief Adds all edges of s in the complex. */ void add_edge(const Simplex& s) { - for(auto i = s.begin(); i != s.end(); ++i) - for(auto j = i; ++j != s.end(); /**/) - add_edge(*i,*j); + for (auto i = s.begin(); i != s.end(); ++i) + for (auto j = i; ++j != s.end(); /**/) + add_edge(*i, *j); } /** @@ -596,9 +596,9 @@ class Skeleton_blocker_complex { * @brief Adds all edges of s in the complex without adding blockers. */ void add_edge_without_blockers(Simplex s) { - for(auto i = s.begin(); i != s.end(); ++i){ - for(auto j = i; ++j != s.end(); /**/) - add_edge_without_blockers(*i,*j); + for (auto i = s.begin(); i != s.end(); ++i) { + for (auto j = i; ++j != s.end(); /**/) + add_edge_without_blockers(*i, *j); } } @@ -1014,10 +1014,10 @@ class Skeleton_blocker_complex { * @brief returns the number of simplices of a given dimension in the complex. */ size_t num_simplices(unsigned dimension) const { - //todo iterator on k-simplices + // TODO(DS): iterator on k-simplices size_t res = 0; - for(const auto& s: complex_simplex_range()) - if(s.dimension() == dimension) + for (const auto& s : complex_simplex_range()) + if (s.dimension() == dimension) ++res; return res; } @@ -1585,7 +1585,7 @@ class Skeleton_blocker_complex { template Complex make_complex_from_top_faces(SimplexHandleIterator simplices_begin, SimplexHandleIterator simplices_end, bool is_flag_complex = false) { - //todo use add_simplex instead! should be more efficient and more elegant :) + // TODO(DS): use add_simplex instead! should be more efficient and more elegant :) typedef typename Complex::Simplex Simplex; std::vector simplices; for (auto top_face = simplices_begin; top_face != simplices_end; ++top_face) { diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h index 1b7d58ff..94a125c1 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -218,7 +218,7 @@ void Skeleton_blocker_complex::add_simplex(const Simplex& sig this->add_vertex(); } assert(contains_vertices(sigma)); - if(!contains_edges(sigma)) + if (!contains_edges(sigma)) add_edge(sigma); remove_blocker_include_in_simplex(sigma); add_blockers_after_simplex_insertion(sigma); @@ -227,10 +227,10 @@ void Skeleton_blocker_complex::add_simplex(const Simplex& sig template -void Skeleton_blocker_complex::add_blockers_after_simplex_insertion(Simplex sigma){ - if(sigma.dimension() < 1) return; +void Skeleton_blocker_complex::add_blockers_after_simplex_insertion(Simplex sigma) { + if (sigma.dimension() < 1) return; - for(auto s : coboundary_range(sigma)) { + for (auto s : coboundary_range(sigma)) { this->add_blocker(s); } } @@ -254,10 +254,10 @@ void Skeleton_blocker_complex::remove_blocker_containing_simp */ template void Skeleton_blocker_complex::remove_blocker_include_in_simplex(const Simplex& sigma) { - //todo write efficiently by using only superior blockers - //eg for all s, check blockers whose vertices are all greater than s + // TODO(DS): write efficiently by using only superior blockers + // eg for all s, check blockers whose vertices are all greater than s std::set blockers_to_remove; - for(auto s : sigma) { + for (auto s : sigma) { for (auto blocker : this->blocker_range(s)) { if (sigma.contains(*blocker)) blockers_to_remove.insert(blocker); @@ -266,11 +266,11 @@ void Skeleton_blocker_complex::remove_blocker_include_in_simp for (auto blocker_to_update : blockers_to_remove) { auto s = *blocker_to_update; this->delete_blocker(blocker_to_update); - //now if there is a vertex v in the link of s - //and v is not included in sigma then v.s is a blocker - //(all faces of v.s are there since v belongs to the link of s) - for(const auto& b : coboundary_range(s)) - if(!sigma.contains(b)) + // now if there is a vertex v in the link of s + // and v is not included in sigma then v.s is a blocker + // (all faces of v.s are there since v belongs to the link of s) + for (const auto& b : coboundary_range(s)) + if (!sigma.contains(b)) this->add_blocker(b); } } @@ -384,9 +384,8 @@ Skeleton_blocker_complex::contract_edge(Vertex_handle a, Vert } template -void -Skeleton_blocker_complex::get_blockers_to_be_added_after_contraction(Vertex_handle a, Vertex_handle b, - std::set& blockers_to_add) { +void Skeleton_blocker_complex::get_blockers_to_be_added_after_contraction(Vertex_handle a, + Vertex_handle b, std::set& blockers_to_add) { blockers_to_add.clear(); typedef Skeleton_blocker_link_complex > LinkComplexType; -- cgit v1.2.3 From 91213bb50dbb53ec0257665da9a2e76ecabde2a2 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 16 Nov 2015 10:40:34 +0000 Subject: Visual 2013 fix about typename not allowed. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@924 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 641ead33dd7c9a97dd84e085e2d131d05c6ce8fb --- src/Contraction/example/Garland_heckbert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index 3ba9501b..b545a066 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) { } Complex complex; - typedef typename Complex::Vertex_handle Vertex_handle; + typedef Complex::Vertex_handle Vertex_handle; // load the points Skeleton_blocker_off_reader off_reader(argv[1], complex); -- cgit v1.2.3 From 061e43a2a48525bc5a69482a1ea80f20ff505e55 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 20 Nov 2015 16:13:33 +0000 Subject: Bug on gudhi installation doc page git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@928 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7fb83a82e11210bce9842a80779455681d6508f3 --- src/common/doc/main_page.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index 689e7a4d..41b8ba1e 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -56,6 +56,7 @@ * The following example requires the GNU Multiple Precision Arithmetic * Library (GMP) and will not be built if GMP is not installed: * \li Persistent_cohomology/rips_multifield_persistence + * * Having GMP version 4.2 or higher installed is recommended. * * \subsection cgal CGAL: @@ -72,19 +73,15 @@ * * \subsection demos Demos and examples * To build the demos and libraries, run the following commands in a terminal: - * \verbatim - * cd /path-to-gudhi/ - * mkdir build - * cd build/ - * cmake .. - * make - * \endverbatim +\verbatim cd /path-to-gudhi/ +mkdir build +cd build/ +cmake .. +make \endverbatim * * \subsection testsuites Test suites * To test your build, run the following command in a terminal: - * \verbatim - * make test - * \endverbatim + * \verbatim make test \endverbatim * * \section Contributions Bug reports and contributions * Please help us improving the quality of the GUDHI library. You may report bugs or suggestions to: -- cgit v1.2.3 From 1b802ff1bb1a4e245d3c3bb544a047df15e09a32 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 10 Dec 2015 15:55:03 +0000 Subject: Add cmake script to find TBB git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/tbb@939 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4caa2f3a1362b07219b7e7e7ca0d059cd73bdac0 --- src/cmake/modules/FindTBB.cmake | 433 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 433 insertions(+) create mode 100644 src/cmake/modules/FindTBB.cmake (limited to 'src') diff --git a/src/cmake/modules/FindTBB.cmake b/src/cmake/modules/FindTBB.cmake new file mode 100644 index 00000000..414a929b --- /dev/null +++ b/src/cmake/modules/FindTBB.cmake @@ -0,0 +1,433 @@ +# Locate Intel Threading Building Blocks include paths and libraries +# FindTBB.cmake can be found at https://code.google.com/p/findtbb/ +# Written by Hannes Hofmann +# Improvements by Gino van den Bergen , +# Florian Uhlig , +# Jiri Marsik + +# The MIT License +# +# Copyright (c) 2011 Hannes Hofmann +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# GvdB: This module uses the environment variable TBB_ARCH_PLATFORM which defines architecture and compiler. +# e.g. "ia32/vc8" or "em64t/cc4.1.0_libc2.4_kernel2.6.16.21" +# TBB_ARCH_PLATFORM is set by the build script tbbvars[.bat|.sh|.csh], which can be found +# in the TBB installation directory (TBB_INSTALL_DIR). +# +# GvdB: Mac OS X distribution places libraries directly in lib directory. +# +# For backwards compatibility, you may explicitely set the CMake variables TBB_ARCHITECTURE and TBB_COMPILER. +# TBB_ARCHITECTURE [ ia32 | em64t | itanium ] +# which architecture to use +# TBB_COMPILER e.g. vc9 or cc3.2.3_libc2.3.2_kernel2.4.21 or cc4.0.1_os10.4.9 +# which compiler to use (detected automatically on Windows) + +# This module respects +# TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR} + +# This module defines +# TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. +# TBB_LIBRARY_DIRS, where to find TBB libraries +# TBB_INSTALL_DIR, the base TBB install directory. +# TBB_LIBRARIES, all the following TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). Note that if the debug versions are not found, the release versions will be used instead for the debug mode. +# TBB_RELEASE_LIBRARY, the TBB release library +# TBB_MALLOC_RELEASE_LIBRARY, the TBB release malloc library +# TBB_DEBUG_LIBRARY, the TBB debug library +# TBB_MALLOC_DEBUG_LIBRARY, the TBB debug malloc library +# TBB_FOUND, If false, don't try to use TBB. +# TBB_INTERFACE_VERSION, as defined in tbb/tbb_stddef.h +# TBB_MALLOCPROXY_DEBUG_LIBRARY, the TBB debug malloc_proxy library (not included in TBB_LIBRARIES since it's optionnal) +# TBB_MALLOCPROXY_RELEASE_LIBRARY, the TBB release malloc_proxy library (not included in TBB_LIBRARIES since it's optionnal) + +include(CheckCXXSourceCompiles) + +# Usage: +# try_TBB_with_pthread( [additional linker args...]) +function(try_TBB_with_pthread result_var) + set(TBB_try_ts_source " + #include + int main() { + tbb::enumerable_thread_specific< + bool*, + tbb::cache_aligned_allocator, + tbb::ets_key_per_instance> grid; + } + ") + set(CMAKE_REQUIRED_LIBRARIES ${ALL_TBB_LIBRARIES} ${ARGN}) + set(CMAKE_REQUIRED_INCLUDES ${TBB_INCLUDE_DIR}) + check_cxx_source_compiles("${TBB_try_ts_source}" ${result_var}) + set(${result_var} ${${result_var}} PARENT_SCOPE) +endfunction(try_TBB_with_pthread) + +if (WIN32) + # has em64t/vc8 em64t/vc9 + # has ia32/vc7.1 ia32/vc8 ia32/vc9 + set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB") + set(_TBB_LIB_RELEASE_NAME "tbb") + set(_TBB_LIB_MALLOC_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc") + set(_TBB_LIB_MALLOCPROXY_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc_proxy") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_RELEASE_NAME}_debug") + if (MSVC71) + set (_TBB_COMPILER "vc7.1") + endif(MSVC71) + if (MSVC80) + set(_TBB_COMPILER "vc8") + endif(MSVC80) + if (MSVC90) + set(_TBB_COMPILER "vc9") + endif(MSVC90) + if(MSVC10) + set(_TBB_COMPILER "vc10") + endif(MSVC10) + if(MSVC11) + set(_TBB_COMPILER "vc11") + endif(MSVC11) + if(MSVC12) + set(_TBB_COMPILER "vc12") + endif(MSVC12) + #note there was no MSVC13 + if(MSVC14) + if(RUNNING_CGAL_AUTO_TEST) + set (TBB_FOUND "NO") + return()#binaries for TBB not publicly available when CGAL-4.7 is published + endif(RUNNING_CGAL_AUTO_TEST) + message(STATUS "[Warning] FindTBB.cmake: TBB 4.4 (latest available when CGAL-4.7 is published) does not provide support for MSVC 2015.") + endif(MSVC14) + # Todo: add other Windows compilers such as ICL. + set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) +endif (WIN32) + +if (UNIX) + if (APPLE) + # MAC + set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions") + # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug + set(_TBB_LIB_RELEASE_NAME "tbb") + set(_TBB_LIB_MALLOC_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc") + #set(_TBB_LIB_MALLOCPROXY_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc_proxy") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_RELEASE_NAME}_debug") + #set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_RELEASE_NAME}_debug") + # default flavor on apple: ia32/cc4.0.1_os10.4.9 + # Jiri: There is no reason to presume there is only one flavor and + # that user's setting of variables should be ignored. + if(NOT TBB_COMPILER) + set(_TBB_COMPILER "cc4.0.1_os10.4.9") + elseif (NOT TBB_COMPILER) + set(_TBB_COMPILER ${TBB_COMPILER}) + endif(NOT TBB_COMPILER) + if(NOT TBB_ARCHITECTURE) + set(_TBB_ARCHITECTURE "ia32") + elseif(NOT TBB_ARCHITECTURE) + set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) + endif(NOT TBB_ARCHITECTURE) + else (APPLE) + # LINUX + set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include") + set(_TBB_LIB_RELEASE_NAME "tbb") + set(_TBB_LIB_MALLOC_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc") + set(_TBB_LIB_MALLOCPROXY_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc_proxy") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_RELEASE_NAME}_debug") + # has em64t/cc3.2.3_libc2.3.2_kernel2.4.21 em64t/cc3.3.3_libc2.3.3_kernel2.6.5 em64t/cc3.4.3_libc2.3.4_kernel2.6.9 em64t/cc4.1.0_libc2.4_kernel2.6.16.21 + # has ia32/* + # has itanium/* + set(_TBB_COMPILER ${TBB_COMPILER}) + set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) + endif (APPLE) +endif (UNIX) + +if (CMAKE_SYSTEM MATCHES "SunOS.*") +# SUN +# not yet supported +# has em64t/cc3.4.3_kernel5.10 +# has ia32/* +endif (CMAKE_SYSTEM MATCHES "SunOS.*") + + +#-- Clear the public variables +set (TBB_FOUND "NO") + + +#-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR} +# first: use CMake variable TBB_INSTALL_DIR +if (TBB_INSTALL_DIR) + set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR}) +endif (TBB_INSTALL_DIR) +# second: use environment variable +if (NOT _TBB_INSTALL_DIR) + if (NOT "$ENV{TBBROOT}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBBROOT}) + endif (NOT "$ENV{TBBROOT}" STREQUAL "") + if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR}) + endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") + # Intel recommends setting TBB21_INSTALL_DIR + if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR}) + endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") + if (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBB22_INSTALL_DIR}) + endif (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") + if (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBB30_INSTALL_DIR}) + endif (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") +endif (NOT _TBB_INSTALL_DIR) +# third: try to find path automatically +if (NOT _TBB_INSTALL_DIR) + if (_TBB_DEFAULT_INSTALL_DIR) + set (_TBB_INSTALL_DIR ${_TBB_DEFAULT_INSTALL_DIR}) + endif (_TBB_DEFAULT_INSTALL_DIR) +endif (NOT _TBB_INSTALL_DIR) +# sanity check +if (NOT _TBB_INSTALL_DIR) + message ("ERROR: Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}") +else (NOT _TBB_INSTALL_DIR) +# finally: set the cached CMake variable TBB_INSTALL_DIR +if (NOT TBB_INSTALL_DIR) + set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory") + mark_as_advanced(TBB_INSTALL_DIR) +endif (NOT TBB_INSTALL_DIR) + + +#-- A macro to rewrite the paths of the library. This is necessary, because +# find_library() always found the em64t/vc9 version of the TBB libs +macro(TBB_CORRECT_LIB_DIR var_name) +# if (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") + string(REPLACE em64t "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) +# endif (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") + string(REPLACE ia32 "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) + string(REPLACE vc7.1 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) + string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) + string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) + string(REPLACE vc10 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) + string(REPLACE vc11 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) +endmacro(TBB_CORRECT_LIB_DIR var_content) + + +#-- Look for include directory and set ${TBB_INCLUDE_DIR} +set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include) +# Jiri: tbbvars now sets the CPATH environment variable to the directory +# containing the headers. +# LR: search first with NO_DEFAULT_PATH... +find_path(TBB_INCLUDE_DIR + tbb/task_scheduler_init.h + PATHS ${TBB_INC_SEARCH_DIR} ENV CPATH + NO_DEFAULT_PATH +) +if(NOT TBB_INCLUDE_DIR) +# LR: ... and then search again with NO_DEFAULT_PATH if nothing was found in +# hinted paths + find_path(TBB_INCLUDE_DIR + tbb/task_scheduler_init.h + PATHS ${TBB_INC_SEARCH_DIR} ENV CPATH + ) +endif() +mark_as_advanced(TBB_INCLUDE_DIR) + + +#-- Look for libraries +# GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh] +if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") + set (_TBB_LIBRARY_DIR + ${_TBB_INSTALL_DIR}/lib/$ENV{TBB_ARCH_PLATFORM} + ${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib + ) +endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") +# Jiri: This block isn't mutually exclusive with the previous one +# (hence no else), instead I test if the user really specified +# the variables in question. +if ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) + # HH: deprecated + message(STATUS "[Warning] FindTBB.cmake: The use of TBB_ARCHITECTURE and TBB_COMPILER is deprecated and may not be supported in future versions. Please set \$ENV{TBB_ARCH_PLATFORM} (using tbbvars.[bat|csh|sh]).") + # Jiri: It doesn't hurt to look in more places, so I store the hints from + # ENV{TBB_ARCH_PLATFORM} and the TBB_ARCHITECTURE and TBB_COMPILER + # variables and search them both. + set (_TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}/lib" ${_TBB_LIBRARY_DIR}) +endif ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) + +# GvdB: Mac OS X distribution places libraries directly in lib directory. +list(APPEND _TBB_LIBRARY_DIR ${_TBB_INSTALL_DIR}/lib) + +# Jiri: No reason not to check the default paths. From recent versions, +# tbbvars has started exporting the LIBRARY_PATH and LD_LIBRARY_PATH +# variables, which now point to the directories of the lib files. +# It all makes more sense to use the ${_TBB_LIBRARY_DIR} as a HINTS +# argument instead of the implicit PATHS as it isn't hard-coded +# but computed by system introspection. Searching the LIBRARY_PATH +# and LD_LIBRARY_PATH environment variables is now even more important +# that tbbvars doesn't export TBB_ARCH_PLATFORM and it facilitates +# the use of TBB built from sources. +# LR: search first with NO_DEFAULT_PATH... +find_library(TBB_RELEASE_LIBRARY ${_TBB_LIB_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH NO_DEFAULT_PATH) +find_library(TBB_MALLOC_RELEASE_LIBRARY ${_TBB_LIB_MALLOC_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH NO_DEFAULT_PATH) +find_library(TBB_MALLOCPROXY_RELEASE_LIBRARY ${_TBB_LIB_MALLOCPROXY_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH NO_DEFAULT_PATH) +if(NOT TBB_RELEASE_LIBRARY OR NOT TBB_MALLOC_RELEASE_LIBRARY OR NOT TBB_MALLOCPROXY_RELEASE_LIBRARY) +# LR: ... and then search again with NO_DEFAULT_PATH if nothing was found +# in hinted paths + find_library(TBB_RELEASE_LIBRARY ${_TBB_LIB_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) + find_library(TBB_MALLOC_RELEASE_LIBRARY ${_TBB_LIB_MALLOC_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) + find_library(TBB_MALLOCPROXY_RELEASE_LIBRARY ${_TBB_LIB_MALLOCPROXY_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) +endif() + +#Extract path from TBB_RELEASE_LIBRARY name +get_filename_component(TBB_RELEASE_LIBRARY_DIR ${TBB_RELEASE_LIBRARY} PATH) + +#TBB_CORRECT_LIB_DIR(TBB_RELEASE_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOC_RELEASE_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_RELEASE_LIBRARY) +mark_as_advanced(TBB_RELEASE_LIBRARY TBB_MALLOC_RELEASE_LIBRARY TBB_MALLOCPROXY_RELEASE_LIBRARY) + +#-- Look for debug libraries +# Jiri: Changed the same way as for the release libraries. +find_library(TBB_DEBUG_LIBRARY ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH NO_DEFAULT_PATH) +find_library(TBB_MALLOC_DEBUG_LIBRARY ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH NO_DEFAULT_PATH) +find_library(TBB_MALLOCPROXY_DEBUG_LIBRARY ${_TBB_LIB_MALLOCPROXY_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH NO_DEFAULT_PATH) +if(NOT TBB_DEBUG_LIBRARY OR NOT TBB_MALLOC_DEBUG_LIBRARY OR NOT TBB_MALLOCPROXY_DEBUG_LIBRARY) + find_library(TBB_DEBUG_LIBRARY ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) + find_library(TBB_MALLOC_DEBUG_LIBRARY ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) + find_library(TBB_MALLOCPROXY_DEBUG_LIBRARY ${_TBB_LIB_MALLOCPROXY_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) +endif() + +# Jiri: Self-built TBB stores the debug libraries in a separate directory. +# Extract path from TBB_DEBUG_LIBRARY name +get_filename_component(TBB_DEBUG_LIBRARY_DIR ${TBB_DEBUG_LIBRARY} PATH) + +#TBB_CORRECT_LIB_DIR(TBB_DEBUG_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOC_DEBUG_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_DEBUG_LIBRARY) +mark_as_advanced(TBB_DEBUG_LIBRARY TBB_MALLOC_DEBUG_LIBRARY TBB_MALLOCPROXY_DEBUG_LIBRARY) + +if (TBB_INCLUDE_DIR) + if (TBB_RELEASE_LIBRARY) + set (TBB_FOUND "YES") + + # NOTE: Removed because we don't want to link with the malloc_proxy by default + #if (NOT "${TBB_MALLOCPROXY_RELEASE_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_RELEASE_LIBRARY-NOTFOUND") + # mark_as_advanced(TBB_MALLOCPROXY_RELEASE_LIBRARY) + # set (_TBB_MALLOCPROXY optimized ${TBB_MALLOCPROXY_RELEASE_LIBRARY}) + #endif (NOT "${TBB_MALLOCPROXY_RELEASE_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_RELEASE_LIBRARY-NOTFOUND") + #if (NOT "${TBB_MALLOCPROXY_DEBUG_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_DEBUG_LIBRARY-NOTFOUND") + # mark_as_advanced(TBB_MALLOCPROXY_DEBUG_LIBRARY) + # set (_TBB_MALLOCPROXY ${_TBB_MALLOCPROXY} debug ${TBB_MALLOCPROXY_DEBUG_LIBRARY}) + #endif (NOT "${TBB_MALLOCPROXY_DEBUG_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_DEBUG_LIBRARY-NOTFOUND") + + # TBB release library + set (ALL_TBB_LIBRARIES optimized ${TBB_RELEASE_LIBRARY}) + + # TBB debug library found? + if (TBB_DEBUG_LIBRARY) + list(APPEND ALL_TBB_LIBRARIES debug ${TBB_DEBUG_LIBRARY}) + else (TBB_DEBUG_LIBRARY) + # Otherwise, link with the release library even in debug mode + list(APPEND ALL_TBB_LIBRARIES debug ${TBB_RELEASE_LIBRARY}) + endif (TBB_DEBUG_LIBRARY) + + # TBB malloc - release + if (TBB_MALLOC_RELEASE_LIBRARY) + list(APPEND ALL_TBB_LIBRARIES optimized ${TBB_MALLOC_RELEASE_LIBRARY}) + + # TBB malloc - debug + if (TBB_MALLOC_DEBUG_LIBRARY) + list(APPEND ALL_TBB_LIBRARIES debug ${TBB_MALLOC_DEBUG_LIBRARY}) + else (TBB_MALLOC_DEBUG_LIBRARY) + list(APPEND ALL_TBB_LIBRARIES debug ${TBB_MALLOC_RELEASE_LIBRARY}) + endif (TBB_MALLOC_DEBUG_LIBRARY) + endif (TBB_MALLOC_RELEASE_LIBRARY) + + if(UNIX AND NOT APPLE) + # On Fedora, code using TBB might need -pthread + + # First check without pthread + try_TBB_with_pthread(TBB_without_pthread) + + if(NOT TBB_without_pthread) + # Then check with -pthread + try_TBB_with_pthread(TBB_with_pthread -pthread) + if(TBB_with_pthread) + list(APPEND ALL_TBB_LIBRARIES general -pthread) + endif(TBB_with_pthread) + endif(NOT TBB_without_pthread) + endif(UNIX AND NOT APPLE) + + set (TBB_LIBRARIES ${ALL_TBB_LIBRARIES} + CACHE PATH "TBB libraries" FORCE) + + # Include dirs + set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) + + # Library dirs + if( "${TBB_DEBUG_LIBRARY_DIR}" STREQUAL "" OR "${TBB_RELEASE_LIBRARY_DIR}" STREQUAL "${TBB_DEBUG_LIBRARY_DIR}" ) + set (TBB_LIBRARY_DIRS + ${TBB_RELEASE_LIBRARY_DIR} + CACHE PATH "TBB library directories" FORCE) + else( "${TBB_DEBUG_LIBRARY_DIR}" STREQUAL "" OR "${TBB_RELEASE_LIBRARY_DIR}" STREQUAL "${TBB_DEBUG_LIBRARY_DIR}" ) + set (TBB_LIBRARY_DIRS + ${TBB_RELEASE_LIBRARY_DIR} ${TBB_DEBUG_LIBRARY_DIR} + CACHE PATH "TBB library directories" FORCE) + endif( "${TBB_DEBUG_LIBRARY_DIR}" STREQUAL "" OR "${TBB_RELEASE_LIBRARY_DIR}" STREQUAL "${TBB_DEBUG_LIBRARY_DIR}" ) + + message(STATUS "Found Intel TBB") + endif (TBB_RELEASE_LIBRARY) +endif (TBB_INCLUDE_DIR) + +if (NOT TBB_FOUND) + if(NOT TBB_FIND_QUIETLY) + message("ERROR: Intel TBB NOT found! Please define the TBBROOT (or TBB_INSTALL_DIR) and/or TBB_ARCH_PLATFORM environment variables.") + message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}") + endif(NOT TBB_FIND_QUIETLY) + SET(TBB_INSTALL_DIR "TBB_INSTALL_DIR_NOT_FOUND" CACHE STRING "Intel TBB install directory") + # do only throw fatal, if this pkg is REQUIRED + if (TBB_FIND_REQUIRED) + message(FATAL_ERROR "Could NOT find TBB library.") + endif (TBB_FIND_REQUIRED) +endif (NOT TBB_FOUND) + +endif (NOT _TBB_INSTALL_DIR) + +if (TBB_FOUND) + set(TBB_INTERFACE_VERSION 0) + FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) + STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") + set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") +endif (TBB_FOUND) + +set(TBB_USE_FILE "UseTBB") + +### ** Emacs settings ** +### Local Variables: +### cmake-tab-width: 4 +### End: -- cgit v1.2.3 From 9aa0cbbea297ea5996eb0d7fa2fcec3f3b773c98 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 10 Dec 2015 16:03:15 +0000 Subject: Forgot UseTBB.cmake git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/tbb@940 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: bf6c4d9a54798895a34b89d655f7817534feb8b5 --- src/cmake/modules/UseTBB.cmake | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/cmake/modules/UseTBB.cmake (limited to 'src') diff --git a/src/cmake/modules/UseTBB.cmake b/src/cmake/modules/UseTBB.cmake new file mode 100644 index 00000000..9d09bf3e --- /dev/null +++ b/src/cmake/modules/UseTBB.cmake @@ -0,0 +1,6 @@ +# This module setups the compiler for using TBB library. +# It assumes that find_package(TBB) was already called. + +include_directories ( ${TBB_INCLUDE_DIRS} ) +link_directories( ${TBB_LIBRARY_DIRS} ) +add_definitions( -DNOMINMAX -DGUDHI_LINKED_WITH_TBB ) -- cgit v1.2.3 From f82dc289e2ebe3eb257c42f27876fbc1c64341dd Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 11 Dec 2015 08:08:40 +0000 Subject: Clarify the semantics of FilteredComplex::simplex(key). git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@941 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a2cb908a642ef53c5de25ba5113e03bb45652b9b --- src/Persistent_cohomology/concept/FilteredComplex.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/concept/FilteredComplex.h b/src/Persistent_cohomology/concept/FilteredComplex.h index 1834903b..e124d524 100644 --- a/src/Persistent_cohomology/concept/FilteredComplex.h +++ b/src/Persistent_cohomology/concept/FilteredComplex.h @@ -65,9 +65,9 @@ struct FilteredComplex Simplex_key key ( Simplex_handle sh ); /** \brief Returns the simplex associated to a key. * - * If key is different from null_key(), there must be a unique - * simplex having this key. */ - Simplex_handle simplex ( Simplex_key key ); + * If key is different from null_key(), returns the simplex that + * has index idx in the filtration. */ + Simplex_handle simplex ( Simplex_key idx ); /** \brief Assign a key to a simplex. */ void assign_key(Simplex_handle sh, Simplex_key key); -- cgit v1.2.3 From 4f73cb4a01692dbbe9547177b5b59425eae0d157 Mon Sep 17 00:00:00 2001 From: glisse Date: Tue, 15 Dec 2015 12:24:25 +0000 Subject: Don't use boost::tuple. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@946 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3988b09fafda67297cac8bd68629310cdfdc607e --- src/GudhUI/utils/K_nearest_builder.h | 10 ++++------ .../include/gudhi/Persistent_cohomology.h | 3 +-- .../gudhi/Persistent_cohomology/Persistent_cohomology_column.h | 1 - 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/GudhUI/utils/K_nearest_builder.h b/src/GudhUI/utils/K_nearest_builder.h index cab24b7c..7be0a4f4 100644 --- a/src/GudhUI/utils/K_nearest_builder.h +++ b/src/GudhUI/utils/K_nearest_builder.h @@ -29,12 +29,10 @@ #include #include #include -#include -#include #include -#include #include +#include #include "utils/UI_utils.h" #include "model/Complex_typedefs.h" @@ -43,9 +41,9 @@ template class K_nearest_builder { private: typedef Geometry_trait Kernel; typedef Point Point_d; - typedef boost::tuple Point_d_with_id; + typedef std::pair Point_d_with_id; typedef CGAL::Search_traits_d Traits_base; - typedef CGAL::Search_traits_adapter, + typedef CGAL::Search_traits_adapter, Traits_base> Traits; typedef CGAL::Orthogonal_k_neighbor_search Neighbor_search; typedef Neighbor_search::Tree Tree; @@ -81,7 +79,7 @@ template class K_nearest_builder { for (auto p : complex_.vertex_range()) { Neighbor_search search(tree, complex_.point(p), k + 1); for (auto it = ++search.begin(); it != search.end(); ++it) { - Vertex_handle q(boost::get<1>(it->first)); + Vertex_handle q(std::get<1>(it->first)); if (p != q && complex_.contains_vertex(p) && complex_.contains_vertex(q)) complex_.add_edge(p, q); } diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 2a405830..643b810c 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -223,7 +222,7 @@ class Persistent_cohomology { // Sparse column type for the annotation of the boundary of an element. typedef std::vector > A_ds_type; // Persistent interval type. The Arith_element field is used for the multi-field framework. - typedef boost::tuple Persistent_interval; + typedef std::tuple Persistent_interval; /** \brief Initializes the Persistent_cohomology class. * diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h index 612658e6..5deb2d88 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h @@ -23,7 +23,6 @@ #ifndef PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ #define PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ -#include #include #include -- cgit v1.2.3 From d91d9248c66451a765f58b6d03db2124b52c3ae2 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 7 Jan 2016 13:34:00 +0000 Subject: Cppcheck fixes after merge git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@951 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4b66d24e46b604e2066c4c2e506b147af4be7e6a --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 6 +++--- .../include/gudhi/Simplex_tree/Simplex_tree_iterators.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 408c0588..50c67185 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -571,9 +571,9 @@ class Simplex_tree { public: /** \private \brief Test if the vertices have contiguous numbering: 0, 1, etc. */ bool contiguous_vertices() const { - if(root_.members_.empty()) return true; - if(root_.members_.begin()->first!=0) return false; - if(std::prev(root_.members_.end())->first!=root_.members_.size()-1) return false; + if (root_.members_.empty()) return true; + if (root_.members_.begin()->first != 0) return false; + if (std::prev(root_.members_.end())->first != root_.members_.size()-1) return false; return true; } diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index c5027f22..794060ee 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -99,11 +99,13 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< // any end() iterator explicit Simplex_tree_boundary_simplex_iterator(SimplexTree * st) - : sh_(st->null_simplex()) { + : sib_(NULL), + sh_(st->null_simplex()) { } Simplex_tree_boundary_simplex_iterator(SimplexTree * st, Simplex_handle sh) : suffix_(), + sib_(st->self_siblings(sh)), st_(st) { last_ = sh->first; Siblings * sib = st->self_siblings(sh); @@ -137,9 +139,7 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< Siblings * for_sib = sib_; Siblings * new_sib = sib_->oncles(); auto rit = suffix_.rbegin(); - if (SimplexTree::Options::contiguous_vertices - && new_sib == nullptr - && rit != suffix_.rend()) { + if (SimplexTree::Options::contiguous_vertices && new_sib == nullptr && rit != suffix_.rend()) { // We reached the root, use a short-cut to find a vertex. We could also // optimize finding the second vertex of a segment, but people are // expected to call endpoints(). -- cgit v1.2.3 From 0a5b697f959d673fd51d70058fd3fe90f7c15125 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 7 Jan 2016 15:11:09 +0000 Subject: TBB find package mechanism with definition for code purpose. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/tbb@952 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9b4dcb962d1af208feccf831171029479d37831e --- CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 4 ++++ src/cmake/modules/UseTBB.cmake | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index ae089562..edf7e63f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,10 @@ endif() find_package(CGAL) +# Find TBB package for parallel sort - not mandatory, just optional. +set(TBB_FIND_QUIETLY ON) +find_package(TBB) + # Required programs for unitary tests purpose FIND_PROGRAM( GCOVR_PATH gcovr ) if (GCOVR_PATH) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a84090e9..0e8de7cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,10 @@ endif() find_package(CGAL) +# Find TBB package for parallel sort - not mandatory, just optional. +set(TBB_FIND_QUIETLY ON) +find_package(TBB) + if(NOT Boost_FOUND) message(FATAL_ERROR "NOTICE: This demo requires Boost and will not be compiled.") else() diff --git a/src/cmake/modules/UseTBB.cmake b/src/cmake/modules/UseTBB.cmake index 9d09bf3e..e1ef5dfe 100644 --- a/src/cmake/modules/UseTBB.cmake +++ b/src/cmake/modules/UseTBB.cmake @@ -3,4 +3,4 @@ include_directories ( ${TBB_INCLUDE_DIRS} ) link_directories( ${TBB_LIBRARY_DIRS} ) -add_definitions( -DNOMINMAX -DGUDHI_LINKED_WITH_TBB ) +add_definitions( -DNOMINMAX -DGUDHI_USE_TBB ) -- cgit v1.2.3 From 9aa92aa2b504d9530125a6a164f76c11f45d8bb5 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 8 Jan 2016 15:03:16 +0000 Subject: cpplint and cppcheck fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@956 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f54c0a2a375e8818c7162aec05249e446361834b --- src/Hasse_complex/include/gudhi/Hasse_complex.h | 10 ++-- .../example/parallel_rips_persistence.cpp | 2 +- src/Simplex_tree/include/gudhi/Simplex_tree.h | 4 +- .../gudhi/Simplex_tree/Simplex_tree_iterators.h | 60 ++++++++++++---------- .../gudhi/Simplex_tree/Simplex_tree_siblings.h | 2 +- src/common/include/gudhi/allocator.h | 10 ++-- 6 files changed, 47 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/Hasse_complex/include/gudhi/Hasse_complex.h b/src/Hasse_complex/include/gudhi/Hasse_complex.h index 38887264..8b06b771 100644 --- a/src/Hasse_complex/include/gudhi/Hasse_complex.h +++ b/src/Hasse_complex/include/gudhi/Hasse_complex.h @@ -23,14 +23,14 @@ #ifndef HASSE_COMPLEX_H_ #define HASSE_COMPLEX_H_ +#include + #include #include #include // for pair #include -#include - #ifdef GUDHI_USE_TBB #include #endif @@ -109,12 +109,12 @@ class Hasse_complex { , dim_max_(cpx.dimension()) { int size = complex_.size(); #ifdef GUDHI_USE_TBB - tbb::parallel_for(0,size,[&](int idx){new (&complex_[idx]) Hasse_simp(cpx, cpx.simplex(idx));}); - for (int idx=0; idx #include #include -#include "gudhi/Hasse_complex.h" +#include #include diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 356deb3a..708cdef9 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -528,7 +528,7 @@ class Simplex_tree { * The type InputVertexRange must be a range of Vertex_handle * on which we can call std::begin() function */ - template> + template> Simplex_handle find(const InputVertexRange & s) { auto first = std::begin(s); auto last = std::end(s); @@ -635,7 +635,7 @@ class Simplex_tree { * * The type InputVertexRange must be a range for which .begin() and * .end() return input iterators, with 'value_type' Vertex_handle. */ - template> + template> std::pair insert_simplex(const InputVertexRange & simplex, Filtration_value filtration = 0) { auto first = std::begin(simplex); diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index 794060ee..936b7a1f 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -54,7 +54,7 @@ class Simplex_tree_simplex_vertex_iterator : public boost::iterator_facade< explicit Simplex_tree_simplex_vertex_iterator(SimplexTree * st) : // any end() iterator - sib_(NULL), + sib_(nullptr), v_(st->null_vertex()) { } @@ -99,19 +99,19 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< // any end() iterator explicit Simplex_tree_boundary_simplex_iterator(SimplexTree * st) - : sib_(NULL), - sh_(st->null_simplex()) { + : sib_(nullptr), + sh_(st->null_simplex()), + st_(st) { } Simplex_tree_boundary_simplex_iterator(SimplexTree * st, Simplex_handle sh) - : suffix_(), - sib_(st->self_siblings(sh)), + : last_(sh->first), + sib_(nullptr), st_(st) { - last_ = sh->first; Siblings * sib = st->self_siblings(sh); next_ = sib->parent(); - sib_ = sib->oncles(); /* \todo check if NULL*/ - if (sib_ != NULL) { + sib_ = sib->oncles(); + if (sib_ != nullptr) { sh_ = sib_->find(next_); } else { sh_ = st->null_simplex(); @@ -131,7 +131,7 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< } void increment() { - if (sib_ == NULL) { + if (sib_ == nullptr) { sh_ = st_->null_simplex(); return; } @@ -189,13 +189,15 @@ class Simplex_tree_complex_simplex_iterator : public boost::iterator_facade< // any end() iterator Simplex_tree_complex_simplex_iterator() - : st_(NULL) { + : sib_(nullptr), + st_(nullptr) { } explicit Simplex_tree_complex_simplex_iterator(SimplexTree * st) - : st_(st) { - if (st == NULL || st->root() == NULL || st->root()->members().empty()) { - st_ = NULL; + : sib_(nullptr), + st_(st) { + if (st == nullptr || st->root() == nullptr || st->root()->members().empty()) { + st_ = nullptr; } else { sh_ = st->root()->members().begin(); sib_ = st->root(); @@ -210,10 +212,10 @@ class Simplex_tree_complex_simplex_iterator : public boost::iterator_facade< // valid when iterating along the SAME boundary. bool equal(Simplex_tree_complex_simplex_iterator const& other) const { - if (other.st_ == NULL) { - return (st_ == NULL); + if (other.st_ == nullptr) { + return (st_ == nullptr); } - if (st_ == NULL) { + if (st_ == nullptr) { return false; } return (&(sh_->second) == &(other.sh_->second)); @@ -227,8 +229,8 @@ class Simplex_tree_complex_simplex_iterator : public boost::iterator_facade< void increment() { ++sh_; if (sh_ == sib_->members().end()) { - if (sib_->oncles() == NULL) { - st_ = NULL; + if (sib_->oncles() == nullptr) { + st_ = nullptr; return; } // reach the end sh_ = sib_->oncles()->members().find(sib_->parent()); @@ -261,15 +263,19 @@ class Simplex_tree_skeleton_simplex_iterator : public boost::iterator_facade< // any end() iterator Simplex_tree_skeleton_simplex_iterator() - : st_(NULL) { + : sib_(nullptr), + st_(nullptr), + dim_skel_(0), + curr_dim_(0) { } Simplex_tree_skeleton_simplex_iterator(SimplexTree * st, int dim_skel) - : st_(st), + : sib_(nullptr), + st_(st), dim_skel_(dim_skel), curr_dim_(0) { - if (st == NULL || st->root() == NULL || st->root()->members().empty()) { - st_ = NULL; + if (st == nullptr || st->root() == nullptr || st->root()->members().empty()) { + st_ = nullptr; } else { sh_ = st->root()->members().begin(); sib_ = st->root(); @@ -285,10 +291,10 @@ class Simplex_tree_skeleton_simplex_iterator : public boost::iterator_facade< // valid when iterating along the SAME boundary. bool equal(Simplex_tree_skeleton_simplex_iterator const& other) const { - if (other.st_ == NULL) { - return (st_ == NULL); + if (other.st_ == nullptr) { + return (st_ == nullptr); } - if (st_ == NULL) { + if (st_ == nullptr) { return false; } return (&(sh_->second) == &(other.sh_->second)); @@ -302,8 +308,8 @@ class Simplex_tree_skeleton_simplex_iterator : public boost::iterator_facade< void increment() { ++sh_; if (sh_ == sib_->members().end()) { - if (sib_->oncles() == NULL) { - st_ = NULL; + if (sib_->oncles() == nullptr) { + st_ = nullptr; return; } // reach the end sh_ = sib_->oncles()->members().find(sib_->parent()); diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h index 158ee1f7..072afc8d 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h @@ -57,7 +57,7 @@ class Simplex_tree_siblings { /* Default constructor.*/ Simplex_tree_siblings() - : oncles_(NULL), + : oncles_(nullptr), parent_(-1), members_() { } diff --git a/src/common/include/gudhi/allocator.h b/src/common/include/gudhi/allocator.h index b825173b..4ede14e4 100644 --- a/src/common/include/gudhi/allocator.h +++ b/src/common/include/gudhi/allocator.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef GUDHI_ALLOCATOR_H_ -#define GUDHI_ALLOCATOR_H_ +#ifndef ALLOCATOR_H_ +#define ALLOCATOR_H_ #include #include @@ -43,13 +43,13 @@ struct no_init_allocator : Base { // Do nothing: that's the whole point! template - void construct(P*)noexcept{} + void construct(P*) noexcept {} - template void construct(P*p, U&&...u){ + template void construct(P*p, U&&...u) { Base_traits::construct(*(Base*)this, p, std::forward(u)...); } }; } // namespace Gudhi -#endif // GUDHI_ALLOCATOR_H_ +#endif // ALLOCATOR_H_ -- cgit v1.2.3 From 22a90cae3ce7ca63ca712a74281410e61e829dd2 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 14 Jan 2016 14:31:08 +0000 Subject: AddressSanitizer bug fixes on Simplex tree copy constructor. debug_tree function git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_insert_with_subfaces_fix@967 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: dd4b15dc8f2a4795d3a0b6fdcf4938aff152906b --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 42 +++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 708cdef9..0a406076 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -325,11 +325,10 @@ class Simplex_tree { Simplex_tree(const Simplex_tree& simplex_source) : null_vertex_(simplex_source.null_vertex_), threshold_(simplex_source.threshold_), + root_(nullptr, null_vertex_ , simplex_source.root_.members_), filtration_vect_(), dimension_(simplex_source.dimension_) { auto root_source = simplex_source.root_; - auto memb_source = root_source.members(); - root_ = Siblings(nullptr, null_vertex_, memb_source); rec_copy(&root_, &root_source); } @@ -341,7 +340,7 @@ class Simplex_tree { Siblings * newsib = new Siblings(sib, sh_source->first); newsib->members_.reserve(sh_source->second.children()->members().size()); for (auto & child : sh_source->second.children()->members()) - newsib->members_.emplace_hint(newsib->members_.end(), child.first, Node(sib, child.second.filtration())); + newsib->members_.emplace_hint(newsib->members_.end(), child.first, Node(newsib, child.second.filtration())); rec_copy(newsib, sh_source->second.children()); sh->second.assign_children(newsib); } @@ -1105,6 +1104,43 @@ class Simplex_tree { os << filtration(sh) << " \n"; } } +/***************************************************************************************************************/ + public: + /** \brief Prints the simplex_tree hierarchically. + * Since it prints the vertices recursively, one can watch its tree shape. + */ + void debug_tree() { + std::cout << "{" << &root_ << "} -------------------------------------------------------------------" << std::endl; + for (auto sh = root_.members().begin(); sh != root_.members().end(); ++sh) { + std::cout << sh->first << " [" << sh->second.filtration() << "] "; + if (has_children(sh)) { + rec_debug_tree(sh->second.children()); + } else { + std::cout << " {- " << sh->second.children() << "} "; + } + std::cout << std::endl; + } + std::cout << "--------------------------------------------------------------------------------------" << std::endl; + } + + + /** \brief Recursively prints the simplex_tree, using depth first search. */ + private: + void rec_debug_tree(Siblings * sib) { + std::cout << " {" << sib << "} ("; + for (auto sh = sib->members().begin(); sh != sib->members().end(); ++sh) { + std::cout << " " << sh->first << " [" << sh->second.filtration() << "] "; + if (has_children(sh)) { + rec_debug_tree(sh->second.children()); + } else { + std::cout << " {- " << sh->second.children() << "} "; + } + } + std::cout << ")"; + } + +/*****************************************************************************************************************/ + private: Vertex_handle null_vertex_; -- cgit v1.2.3 From 3b3ceceb624d48775ceb28ab455f0f547df9e6c4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 19 Jan 2016 14:00:27 +0000 Subject: Try different values for xUnit git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Win64_Boost_Xunit_fix@977 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b3e39a4858a4be139236be0a87619164a35ea7c0 --- src/Simplex_tree/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Simplex_tree/test/CMakeLists.txt b/src/Simplex_tree/test/CMakeLists.txt index c9eae163..b1256768 100644 --- a/src/Simplex_tree/test/CMakeLists.txt +++ b/src/Simplex_tree/test/CMakeLists.txt @@ -24,5 +24,5 @@ file(COPY "simplex_tree_for_unit_test.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DI add_test(NAME SimplexTreeUT COMMAND ${CMAKE_CURRENT_BINARY_DIR}/SimplexTreeUT # XML format for Jenkins xUnit plugin - --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/SimplexTreeUT.xml --log_level=test_suite --report_level=no) + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/SimplexTreeUT.xml --log_level=all --report_level=no) -- cgit v1.2.3 From f4ac13983d5d977cab5c575184e9b21ee000485f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 19 Jan 2016 15:07:56 +0000 Subject: rollback git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Win64_Boost_Xunit_fix@978 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6aeb45f999861185cda0d0961f22b4a08b413927 --- src/Simplex_tree/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Simplex_tree/test/CMakeLists.txt b/src/Simplex_tree/test/CMakeLists.txt index b1256768..c9eae163 100644 --- a/src/Simplex_tree/test/CMakeLists.txt +++ b/src/Simplex_tree/test/CMakeLists.txt @@ -24,5 +24,5 @@ file(COPY "simplex_tree_for_unit_test.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DI add_test(NAME SimplexTreeUT COMMAND ${CMAKE_CURRENT_BINARY_DIR}/SimplexTreeUT # XML format for Jenkins xUnit plugin - --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/SimplexTreeUT.xml --log_level=all --report_level=no) + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/SimplexTreeUT.xml --log_level=test_suite --report_level=no) -- cgit v1.2.3 From 98bb425ef8c401b2eb8d161393c389b5cf6070c8 Mon Sep 17 00:00:00 2001 From: salinasd Date: Sun, 31 Jan 2016 14:56:30 +0000 Subject: remove creation of useless visitor for test that were just used for display git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_insert_with_subfaces_fix@990 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 13b3baec7f449d1d74cfaca2211571b468be1486 --- src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp index 42482e23..71b1833b 100644 --- a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp +++ b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp @@ -601,7 +601,7 @@ bool test_link4() { } bool test_link5() { - Complex complex(0, new Print_complex_visitor()); + Complex complex(0); // Build the complexes build_complete(4, complex); complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); @@ -621,7 +621,7 @@ bool test_link5() { } bool test_link6() { - Complex complex(0, new Print_complex_visitor()); + Complex complex(0); // Build the complexes build_complete(4, complex); complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); @@ -642,7 +642,7 @@ bool test_link6() { } bool test_link7() { - Complex complex(0, new Print_complex_visitor()); + Complex complex(0); // Build the complexes build_complete(6, complex); complex.add_vertex(); -- cgit v1.2.3 From d15e4b04a8b333d0adc09e321241a6a5daa9b94a Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 4 Feb 2016 12:17:04 +0000 Subject: test with include CGAL_USE_FILE to fix windows issue git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Win64_Boost_Xunit_fix@1000 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 11a5fb78933306cfc83951174b38a03837fef58a --- src/Simplex_tree/example/CMakeLists.txt | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/example/CMakeLists.txt b/src/Simplex_tree/example/CMakeLists.txt index c70cfe35..de75415d 100644 --- a/src/Simplex_tree/example/CMakeLists.txt +++ b/src/Simplex_tree/example/CMakeLists.txt @@ -14,11 +14,24 @@ add_test(mini_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/mini_simplex_tree) # An example with Simplex-tree using CGAL alpha_shapes_3 if(GMP_FOUND AND CGAL_FOUND) - message("CGAL_lib = ${CGAL_LIBRARIES_DIR}") - message("GMP_LIBRARIES = ${GMP_LIBRARIES}") - INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR}) - INCLUDE_DIRECTORIES(${CGAL_INCLUDE_DIRS}) - add_executable ( simplex_tree_from_alpha_shapes_3 simplex_tree_from_alpha_shapes_3.cpp ) - target_link_libraries(simplex_tree_from_alpha_shapes_3 ${GMP_LIBRARIES} ${CGAL_LIBRARY}) - add_test(simplex_tree_from_alpha_shapes_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_alpha_shapes_3 ${CMAKE_SOURCE_DIR}/data/points/bunny_5000) + include( ${CGAL_USE_FILE} ) + # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. + # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 + # A workaround is to add "-std=c++11" again. + # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html + # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html + # but it implies to use cmake version 3.1 at least. + if(NOT MSVC) + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11) + if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() + endif() + # - End of workaround + + INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR}) + add_executable ( simplex_tree_from_alpha_shapes_3 simplex_tree_from_alpha_shapes_3.cpp ) + target_link_libraries(simplex_tree_from_alpha_shapes_3 ${GMP_LIBRARIES} ${CGAL_LIBRARY}) + add_test(simplex_tree_from_alpha_shapes_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_alpha_shapes_3 ${CMAKE_SOURCE_DIR}/data/points/bunny_5000) endif() -- cgit v1.2.3 From 6892c6dbcf1eeaa27825d416503413a74808b625 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 4 Feb 2016 12:44:23 +0000 Subject: requires boost also git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Win64_Boost_Xunit_fix@1001 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: aca5ee1d5587d2e613691a539bb166ac592c137c --- src/Simplex_tree/example/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Simplex_tree/example/CMakeLists.txt b/src/Simplex_tree/example/CMakeLists.txt index de75415d..a86b99a1 100644 --- a/src/Simplex_tree/example/CMakeLists.txt +++ b/src/Simplex_tree/example/CMakeLists.txt @@ -32,6 +32,6 @@ if(GMP_FOUND AND CGAL_FOUND) INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR}) add_executable ( simplex_tree_from_alpha_shapes_3 simplex_tree_from_alpha_shapes_3.cpp ) - target_link_libraries(simplex_tree_from_alpha_shapes_3 ${GMP_LIBRARIES} ${CGAL_LIBRARY}) + target_link_libraries(simplex_tree_from_alpha_shapes_3 ${GMP_LIBRARIES} ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY}) add_test(simplex_tree_from_alpha_shapes_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_alpha_shapes_3 ${CMAKE_SOURCE_DIR}/data/points/bunny_5000) endif() -- cgit v1.2.3 From c85b24f7e0c489093e0c5ccca934eb53fafab623 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 4 Feb 2016 16:11:42 +0000 Subject: CMake strategy modification git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Win64_Boost_Xunit_fix@1003 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c917934525e020b54b2f4506b5c9d060a28c9d89 --- CMakeLists.txt | 105 +++++++++++++++----------- data/points/generator/CMakeLists.txt | 16 ---- src/Bottleneck/test/CMakeLists.txt | 4 - src/CMakeLists.txt | 67 ++++++++++------ src/GudhUI/CMakeLists.txt | 20 ----- src/Persistent_cohomology/test/CMakeLists.txt | 4 - src/Simplex_tree/example/CMakeLists.txt | 17 ----- src/Simplex_tree/test/CMakeLists.txt | 4 - src/Skeleton_blocker/test/CMakeLists.txt | 4 - 9 files changed, 105 insertions(+), 136 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index edf7e63f..8ced7b0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,52 +7,71 @@ configure_file(GUDHIVersion.cmake.in "${PROJECT_BINARY_DIR}/GUDHIVersion.cmake" find_package(Boost REQUIRED COMPONENTS system filesystem unit_test_framework chrono timer program_options thread REQUIRED) -set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/src/cmake/modules/") -set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/src/cmake/modules/") -message("CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}") -message("CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}") - -enable_testing() - -if(MSVC) - # Turn off some VC++ warnings - SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wpedantic -Wsign-compare") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") -endif() - -set(Boost_USE_STATIC_LIBS ON) -set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_RUNTIME OFF) - -find_package(GMP) -if(GMP_FOUND) - find_package(GMPXX) -endif() - -find_package(CGAL) - -# Find TBB package for parallel sort - not mandatory, just optional. -set(TBB_FIND_QUIETLY ON) -find_package(TBB) - -# Required programs for unitary tests purpose -FIND_PROGRAM( GCOVR_PATH gcovr ) -if (GCOVR_PATH) - message("gcovr found in ${GCOVR_PATH}") -endif() -# Required programs for unitary tests purpose -FIND_PROGRAM( GPROF_PATH gprof ) -if (GPROF_PATH) - message("gprof found in ${GPROF_PATH}") -endif() - - if(NOT Boost_FOUND) message(FATAL_ERROR "NOTICE: This demo requires Boost and will not be compiled.") else() + + set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/src/cmake/modules/") + set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/src/cmake/modules/") + message("CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}") + message("CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}") + + enable_testing() + + find_package(GMP) + if(GMP_FOUND) + INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR}) + find_package(GMPXX) + if(GMPXX_FOUND) + INCLUDE_DIRECTORIES(${GMPXX_INCLUDE_DIR}) + endif() + endif() + + # find CGAL package before set of CXX flags because + # in CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. + # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 + set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "Force CGAL to maintain CMAKE flags") + find_package(CGAL) + if(CGAL_FOUND) + include( ${CGAL_USE_FILE} ) + set(CMAKE_CXX_CGAL_FOR_GUDHI_FLAGS "-frounding-math") + endif() + + if(MSVC) + # Turn off some VC++ warnings + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wpedantic -Wsign-compare ${CMAKE_CXX_CGAL_FOR_GUDHI_FLAGS}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0") + # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + endif() + + if(CMAKE_BUILD_TYPE MATCHES Debug) + message("Compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") + else() + message("Compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") + endif() + + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_MULTITHREADED ON) + set(Boost_USE_STATIC_RUNTIME OFF) + + # Find TBB package for parallel sort - not mandatory, just optional. + set(TBB_FIND_QUIETLY ON) + find_package(TBB) + + # Required programs for unitary tests purpose + FIND_PROGRAM( GCOVR_PATH gcovr ) + if (GCOVR_PATH) + message("gcovr found in ${GCOVR_PATH}") + endif() + # Required programs for unitary tests purpose + FIND_PROGRAM( GPROF_PATH gprof ) + if (GPROF_PATH) + message("gprof found in ${GPROF_PATH}") + endif() + + # BOOST ISSUE result_of vs C++11 add_definitions(-DBOOST_RESULT_OF_USE_DECLTYPE) # BOOST ISSUE with Libraries name resolution under Windows diff --git a/data/points/generator/CMakeLists.txt b/data/points/generator/CMakeLists.txt index 26b44446..c01a380d 100644 --- a/data/points/generator/CMakeLists.txt +++ b/data/points/generator/CMakeLists.txt @@ -5,22 +5,6 @@ if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.6.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") - include( ${CGAL_USE_FILE} ) - # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. - # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 - # A workaround is to add "-std=c++11" again. - # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html - # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html - # but it implies to use cmake version 3.1 at least. - if(NOT MSVC) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11) - if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() - endif() - # - End of workaround - find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) include( ${EIGEN3_USE_FILE} ) diff --git a/src/Bottleneck/test/CMakeLists.txt b/src/Bottleneck/test/CMakeLists.txt index 3dfd80cd..ad63c080 100644 --- a/src/Bottleneck/test/CMakeLists.txt +++ b/src/Bottleneck/test/CMakeLists.txt @@ -4,14 +4,10 @@ project(GUDHIBottleneckUT) if (GCOVR_PATH) # for gcovr to make coverage reports - Corbera Jenkins plugin set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage") endif() if (GPROF_PATH) # for gprof to make coverage reports - Jenkins set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pg") endif() add_executable ( BottleneckUT bottleneck_unit_test.cpp ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3c38483c..a67e7c92 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,33 +9,52 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") find_package(Boost REQUIRED COMPONENTS system filesystem program_options chrono timer REQUIRED) -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release") -endif() -if(MSVC) - SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -endif() - -set(Boost_USE_STATIC_LIBS ON) -set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_RUNTIME OFF) - -find_package(GMP) -if(GMP_FOUND) - find_package(GMPXX) -endif() - -find_package(CGAL) - -# Find TBB package for parallel sort - not mandatory, just optional. -set(TBB_FIND_QUIETLY ON) -find_package(TBB) - if(NOT Boost_FOUND) message(FATAL_ERROR "NOTICE: This demo requires Boost and will not be compiled.") else() + + find_package(GMP) + if(GMP_FOUND) + INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR}) + find_package(GMPXX) + if(GMPXX_FOUND) + INCLUDE_DIRECTORIES(${GMPXX_INCLUDE_DIR}) + endif() + endif() + + # find CGAL package before set of CXX flags because + # in CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. + # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 + set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "Force CGAL to maintain CMAKE flags") + find_package(CGAL) + if(CGAL_FOUND) + include( ${CGAL_USE_FILE} ) + set(CMAKE_CXX_CGAL_FOR_GUDHI_FLAGS "-frounding-math") + endif() + + if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") + endif() + if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${CMAKE_CXX_CGAL_FOR_GUDHI_FLAGS}") + endif() + + if(CMAKE_BUILD_TYPE MATCHES Debug) + message("Compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") + else() + message("Compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") + endif() + + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_MULTITHREADED ON) + set(Boost_USE_STATIC_RUNTIME OFF) + + # Find TBB package for parallel sort - not mandatory, just optional. + set(TBB_FIND_QUIETLY ON) + find_package(TBB) + # BOOST ISSUE result_of vs C++11 add_definitions(-DBOOST_RESULT_OF_USE_DECLTYPE) # BOOST ISSUE with Libraries name resolution under Windows diff --git a/src/GudhUI/CMakeLists.txt b/src/GudhUI/CMakeLists.txt index 71f4fd1a..1ee43d91 100644 --- a/src/GudhUI/CMakeLists.txt +++ b/src/GudhUI/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 2.8) project(GudhUI) -find_package(CGAL COMPONENTS Qt4) find_package(Qt4) find_package(QGLViewer) find_package(OpenGL) @@ -14,27 +13,8 @@ if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) SET(Boost_USE_STATIC_LIBS ON) SET(Boost_USE_MULTITHREAD OFF) - INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) - LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) - include(${QT_USE_FILE}) - include(${CGAL_USE_FILE}) - # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. - # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 - # A workaround is to add "-std=c++11" again. - # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html - # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html - # but it implies to use cmake version 3.1 at least. - if(NOT MSVC) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11) - if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() - endif() - # - End of workaround - include_directories (${QGLVIEWER_INCLUDE_DIR}) include_directories(.) diff --git a/src/Persistent_cohomology/test/CMakeLists.txt b/src/Persistent_cohomology/test/CMakeLists.txt index ed63a6ac..d16be5be 100644 --- a/src/Persistent_cohomology/test/CMakeLists.txt +++ b/src/Persistent_cohomology/test/CMakeLists.txt @@ -4,14 +4,10 @@ project(GUDHIPersistentCohomologyUT) if (GCOVR_PATH) # for gcovr to make coverage reports - Corbera Jenkins plugin set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage") endif() if (GPROF_PATH) # for gprof to make coverage reports - Jenkins set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pg") endif() add_executable ( PersistentCohomologyUT persistent_cohomology_unit_test.cpp ) diff --git a/src/Simplex_tree/example/CMakeLists.txt b/src/Simplex_tree/example/CMakeLists.txt index a86b99a1..200161a6 100644 --- a/src/Simplex_tree/example/CMakeLists.txt +++ b/src/Simplex_tree/example/CMakeLists.txt @@ -14,23 +14,6 @@ add_test(mini_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/mini_simplex_tree) # An example with Simplex-tree using CGAL alpha_shapes_3 if(GMP_FOUND AND CGAL_FOUND) - include( ${CGAL_USE_FILE} ) - # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. - # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 - # A workaround is to add "-std=c++11" again. - # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html - # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html - # but it implies to use cmake version 3.1 at least. - if(NOT MSVC) - include(CheckCXXCompilerFlag) - CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11) - if(COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif() - endif() - # - End of workaround - - INCLUDE_DIRECTORIES(${GMP_INCLUDE_DIR}) add_executable ( simplex_tree_from_alpha_shapes_3 simplex_tree_from_alpha_shapes_3.cpp ) target_link_libraries(simplex_tree_from_alpha_shapes_3 ${GMP_LIBRARIES} ${CGAL_LIBRARY} ${Boost_SYSTEM_LIBRARY}) add_test(simplex_tree_from_alpha_shapes_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_alpha_shapes_3 ${CMAKE_SOURCE_DIR}/data/points/bunny_5000) diff --git a/src/Simplex_tree/test/CMakeLists.txt b/src/Simplex_tree/test/CMakeLists.txt index c9eae163..1f2f7d33 100644 --- a/src/Simplex_tree/test/CMakeLists.txt +++ b/src/Simplex_tree/test/CMakeLists.txt @@ -4,14 +4,10 @@ project(GUDHISimplexTreeUT) if (GCOVR_PATH) # for gcovr to make coverage reports - Corbera Jenkins plugin set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage") endif() if (GPROF_PATH) # for gprof to make coverage reports - Jenkins set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pg") endif() add_executable ( SimplexTreeUT simplex_tree_unit_test.cpp ) diff --git a/src/Skeleton_blocker/test/CMakeLists.txt b/src/Skeleton_blocker/test/CMakeLists.txt index 8b6fb672..5e063845 100644 --- a/src/Skeleton_blocker/test/CMakeLists.txt +++ b/src/Skeleton_blocker/test/CMakeLists.txt @@ -4,14 +4,10 @@ project(GUDHIskbl) if (GCOVR_PATH) # for gcovr to make coverage reports - Corbera Jenkins plugin set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage") endif() if (GPROF_PATH) # for gprof to make coverage reports - Jenkins set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pg") endif() add_executable(TestSkeletonBlockerComplex TestSkeletonBlockerComplex.cpp) -- cgit v1.2.3 From abb3faa7088cd6e59f769f2f3b31ecd1b3b0fc0e Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 9 Feb 2016 15:54:58 +0000 Subject: Finally, let CGAL set the flags, but before setting CXX_FLAGS with "-std=c++11" git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/Win64_Boost_Xunit_fix@1011 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: faeca77f4eebf969e608b0c3be67893d646845a9 --- CMakeLists.txt | 17 ++++++++--------- src/CMakeLists.txt | 21 ++++++++++----------- 2 files changed, 18 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ced7b0d..0ee142c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,29 +27,28 @@ else() endif() endif() - # find CGAL package before set of CXX flags because - # in CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. + # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CMAKE_CXX_FLAGS are overwritten. # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 - set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "Force CGAL to maintain CMAKE flags") + # A workaround is to include(${CGAL_USE_FILE}) before adding "-std=c++11". + # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html + # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html + # but it implies to use cmake version 3.1 at least. find_package(CGAL) if(CGAL_FOUND) include( ${CGAL_USE_FILE} ) - set(CMAKE_CXX_CGAL_FOR_GUDHI_FLAGS "-frounding-math") endif() if(MSVC) # Turn off some VC++ warnings set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wpedantic -Wsign-compare ${CMAKE_CXX_CGAL_FOR_GUDHI_FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0") - # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wpedantic -Wsign-compare") endif() if(CMAKE_BUILD_TYPE MATCHES Debug) - message("Compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") + message("++ Debug compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") else() - message("Compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") + message("++ Release compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") endif() set(Boost_USE_STATIC_LIBS ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a67e7c92..97d53306 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,29 +22,28 @@ else() endif() endif() - # find CGAL package before set of CXX flags because - # in CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. + # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CMAKE_CXX_FLAGS are overwritten. # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 - set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "Force CGAL to maintain CMAKE flags") + # A workaround is to include(${CGAL_USE_FILE}) before adding "-std=c++11". + # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html + # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html + # but it implies to use cmake version 3.1 at least. find_package(CGAL) if(CGAL_FOUND) include( ${CGAL_USE_FILE} ) - set(CMAKE_CXX_CGAL_FOR_GUDHI_FLAGS "-frounding-math") - endif() - - if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release") endif() + if(MSVC) + # Turn off some VC++ warnings set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${CMAKE_CXX_CGAL_FOR_GUDHI_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wpedantic -Wsign-compare") endif() if(CMAKE_BUILD_TYPE MATCHES Debug) - message("Compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") + message("++ Debug compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") else() - message("Compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") + message("++ Release compilation flags are: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") endif() set(Boost_USE_STATIC_LIBS ON) -- cgit v1.2.3