From c336a0789b088c729308f0ff31eb5e9a92375ca4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 16 Jun 2015 14:01:45 +0000 Subject: This development includes the Simplex_tree coface and star functions implementation Simplex_tree find function fix (when find on an empty RandomAccessVertexRange) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@620 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5310514623bb7040a4118fa9c6898a5ce894d0c4 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 106 +++++++++++++++++++++++ src/Simplex_tree/test/simplex_tree_unit_test.cpp | 46 ++++++++++ 2 files changed, 152 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 b79e3c8f..a66aa9d1 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -398,7 +398,10 @@ class Simplex_tree { template Simplex_handle find(RandomAccessVertexRange & s) { if (s.begin() == s.end()) + { std::cerr << "Empty simplex \n"; + return null_simplex(); + } sort(s.begin(), s.end()); @@ -599,6 +602,109 @@ class Simplex_tree { std::stable_sort(filtration_vect_.begin(), filtration_vect_.end(), is_before_in_filtration(this)); } + +private: + + /** Recursive search of cofaces + */ + template + void rec_coface(RandomAccessVertexRange &vertices, Siblings *curr_sib, Dictionary *curr_res, std::vector& cofaces, unsigned int length, unsigned long codimension) + { + for (auto sib = curr_sib->members().begin(); sib != curr_sib->members().end() && (vertices.empty() || sib->first <= vertices[vertices.size()-1]); ++sib) + { + bool continueRecursion = (codimension == length || curr_res->size() <= codimension); // dimension of actual simplex <= codimension + if (vertices.empty()) + { + if (curr_res->size() >= length && continueRecursion) + // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface + { + curr_res->emplace(sib->first, sib->second); + bool egalDim = (codimension == length || curr_res->size() == codimension); // dimension of actual simplex == codimension + if (egalDim) + cofaces.push_back(*curr_res); + if (has_children(sib)) + rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); + curr_res->erase(curr_res->end()-1); + } + } + else if (continueRecursion) + { + if (sib->first == vertices[vertices.size()-1]) // If curr_sib matches with the top vertex + { + curr_res->emplace(sib->first, sib->second); + bool egalDim = (codimension == length || curr_res->size() == codimension); // dimension of actual simplex == codimension + if (vertices.size() == 1 && curr_res->size() > length && egalDim) + cofaces.push_back(*curr_res); + if (has_children(sib)) + { // Rec call + Vertex_handle tmp = vertices[vertices.size()-1]; + vertices.pop_back(); + rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); + vertices.push_back(tmp); + } + curr_res->erase(curr_res->end()-1); + } + else // (sib->first < vertices[vertices.size()-1]) + { + if (has_children(sib)) + { + curr_res->emplace(sib->first, sib->second); + rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); + curr_res->erase(curr_res->end()-1); + } + } + } + } + } + +public: + /** \brief Compute the star of a n simplex + * \param vertices List of vertices which represent the n simplex. + * \return Vector of Dictionary, empty vector if no cofaces found. + */ + + std::vector star(const Simplex_handle &vertices) { + return coface(vertices, 0); + } + + + + /** \brief Compute the cofaces of a n simplex + * \param vertices List of vertices which represent the n simplex. + * \param codimension The function returns the n+codimension-simplices. If codimension = 0, return all cofaces (equivalent of star function) + * \return Vector of Dictionary, empty vector if no cofaces found. + * \warning n+codimension must be lower than Simplex_tree dimension, otherwise an an empty vector is returned. + */ + + std::vector coface(const Simplex_handle &vertices, int codimension) { + std::vector cofaces; + if (dimension_ == -1) + { + std::cerr << "Simplex_tree::coface - empty simplex tree" << std::endl; + return cofaces; // ----->> + } + if (vertices == null_simplex()) { + std::cerr << "Simplex_tree::coface - empty vertices list" << std::endl; + return cofaces; // ----->> + } + if (codimension < 0) { + std::cerr << "Simplex_tree::coface - codimension is empty" << std::endl; + return cofaces; // ----->> + } + std::vector copy; + Simplex_vertex_range rg = simplex_vertex_range(vertices); + for (auto it = rg.begin(); it != rg.end(); ++it) + copy.push_back(*it); + if (codimension + copy.size() > (unsigned long)(dimension_ + 1) || (codimension == 0 && copy.size() > (unsigned long)dimension_) ) { + std::cerr << "Simplex_tree::coface - codimension + vertices list size cannot be greater than Simplex_tree dimension" << std::endl; + return cofaces; // ----->> + } + std::sort(copy.begin(), copy.end(), std::greater()); // must be sorted in decreasing order + Dictionary res; + rec_coface(copy, &root_, &res, cofaces, copy.size(), codimension + copy.size()); + return cofaces; + } + private: /** \brief Returns true iff the list of vertices of sh1 diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 6b0a1f3d..f685f079 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -170,6 +170,25 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons BOOST_CHECK(simplexTree.num_simplices() == nb_simplices); } +void test_cofaces(typeST& st, std::vector v, int dim, int res) +{ + std::vector cofaces; + if (dim == 0) + cofaces = st.star(st.find(v)); + else + cofaces = st.coface(st.find(v), dim); + BOOST_CHECK(cofaces.size() == (size_t)res); + for (unsigned long i = 0; i < cofaces.size(); ++i) + { + std::cout << "("; + auto j = cofaces[i].begin(); + std::cout << j->first; + for (auto j = cofaces[i].begin() + 1; j != cofaces[i].end(); ++j) + std::cout << "," << j->first; + std::cout << ")" << std::endl; + } +} + BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) { const Filtration_value FIRST_FILTRATION_VALUE = 0.1; @@ -587,4 +606,31 @@ BOOST_AUTO_TEST_CASE( NSimplexAndSubfaces_tree_insertion ) std::cout << std::endl; } + std::cout << "********************************************************************" << std::endl; + // TEST COFACE ALGORITHM + st.set_dimension(3); + std::cout << "COFACE ALGORITHM" << std::endl; + std::vector v; + v.push_back(3); + std::cout << "Star of (3):" << std::endl; + test_cofaces(st, v, 0, 4); + v.clear(); + v.push_back(1); + v.push_back(7); + std::cout << "Star of (1,7): " << std::endl; + test_cofaces(st, v, 0, 3); + std::cout << "Cofaces of (1,7) of dimension 2: " << std::endl; + test_cofaces(st, v, 1, 2); + std::cout << "Cofaces with a codimension too high (codimension + vetices > tree.dimension)" << std::endl; + test_cofaces(st, v, 5, 0); + std::cout << "Cofaces with an empty codimension" << std::endl; + test_cofaces(st, v, -1, 0); + std::cout << "Cofaces in an empty simplex tree" << std::endl; + typeST empty_tree; + test_cofaces(empty_tree, v, 1, 0); + std::cout << "Cofaces of an empty simplex" << std::endl; + v.clear(); + test_cofaces(st, v, 1, 0); + + } -- cgit v1.2.3 From 6969ac7694dcbc859a770c9eccf997e64e08fff3 Mon Sep 17 00:00:00 2001 From: anmoreau Date: Wed, 17 Jun 2015 13:33:18 +0000 Subject: Fix doc - coface function now returns std::vector - test function now tests the whole result - debug code deleted git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@621 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b4e55297e8891d45941006f3817787b293a47cc1 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 77 ++-- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 432 +++++++++++++---------- 2 files changed, 275 insertions(+), 234 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 a66aa9d1..26a8eba6 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -122,7 +122,7 @@ class Simplex_tree { public: /** \brief Handle type to a simplex contained in the simplicial complex represented - * byt he simplex tree. */ + * by the simplex tree. */ typedef typename Dictionary::iterator Simplex_handle; private: @@ -397,11 +397,8 @@ class Simplex_tree { */ template Simplex_handle find(RandomAccessVertexRange & s) { - if (s.begin() == s.end()) - { - std::cerr << "Empty simplex \n"; + if (s.begin() == s.end()) // Empty simplex return null_simplex(); - } sort(s.begin(), s.end()); @@ -606,9 +603,18 @@ class Simplex_tree { private: /** Recursive search of cofaces + * This function uses DFS + *\param vertices contains a list of vertices, which represent the simplex. + *\param curr_res contains a list of vertices, which represent the current path in the tree. + *\param cofaces contains a list of Simplex_handle, representing all the cofaces asked. + *\param length length of the vertices list + * Prefix actions : When the bottom vertex matches with the current vertex in the tree, we remove the bottom vertex from vertices. + * Infix actions : Then we call or not the recursion. + * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_res so that we didn't change the parameters. + * If the vertices list is empty, we need to check if the size of the curr_res list matches with the dimension of the cofaces asked. */ template - void rec_coface(RandomAccessVertexRange &vertices, Siblings *curr_sib, Dictionary *curr_res, std::vector& cofaces, unsigned int length, unsigned long codimension) + void rec_coface(RandomAccessVertexRange &vertices, Siblings *curr_sib, RandomAccessVertexRange *curr_res, std::vector& cofaces, unsigned int length, unsigned long codimension) { for (auto sib = curr_sib->members().begin(); sib != curr_sib->members().end() && (vertices.empty() || sib->first <= vertices[vertices.size()-1]); ++sib) { @@ -618,23 +624,23 @@ private: if (curr_res->size() >= length && continueRecursion) // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface { - curr_res->emplace(sib->first, sib->second); + curr_res->push_back(sib->first); bool egalDim = (codimension == length || curr_res->size() == codimension); // dimension of actual simplex == codimension if (egalDim) - cofaces.push_back(*curr_res); + cofaces.push_back(find(*curr_res)); if (has_children(sib)) rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); - curr_res->erase(curr_res->end()-1); + curr_res->pop_back(); } } else if (continueRecursion) { if (sib->first == vertices[vertices.size()-1]) // If curr_sib matches with the top vertex { - curr_res->emplace(sib->first, sib->second); + curr_res->push_back(sib->first); bool egalDim = (codimension == length || curr_res->size() == codimension); // dimension of actual simplex == codimension if (vertices.size() == 1 && curr_res->size() > length && egalDim) - cofaces.push_back(*curr_res); + cofaces.push_back(find(*curr_res)); if (has_children(sib)) { // Rec call Vertex_handle tmp = vertices[vertices.size()-1]; @@ -642,15 +648,15 @@ private: rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); vertices.push_back(tmp); } - curr_res->erase(curr_res->end()-1); + curr_res->pop_back(); } else // (sib->first < vertices[vertices.size()-1]) { if (has_children(sib)) { - curr_res->emplace(sib->first, sib->second); + curr_res->push_back(sib->first); rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); - curr_res->erase(curr_res->end()-1); + curr_res->pop_back(); } } } @@ -659,48 +665,39 @@ private: public: /** \brief Compute the star of a n simplex - * \param vertices List of vertices which represent the n simplex. - * \return Vector of Dictionary, empty vector if no cofaces found. + * \param vertices handles the simplex of which we search the star + * \return Vector of Simplex_handle, empty vector if no cofaces found. */ - std::vector star(const Simplex_handle &vertices) { + std::vector star(const Simplex_handle &vertices) { return coface(vertices, 0); } /** \brief Compute the cofaces of a n simplex - * \param vertices List of vertices which represent the n simplex. - * \param codimension The function returns the n+codimension-simplices. If codimension = 0, return all cofaces (equivalent of star function) - * \return Vector of Dictionary, empty vector if no cofaces found. + * \param vertices handles the n-simplex of which we search the n+codimension cofaces + * \param codimension The function returns the n+codimension-cofaces of the n-simplex. If codimension = 0, return all cofaces (equivalent of star function) + * \return Vector of Simplex_handle, empty vector if no cofaces found. * \warning n+codimension must be lower than Simplex_tree dimension, otherwise an an empty vector is returned. */ - std::vector coface(const Simplex_handle &vertices, int codimension) { - std::vector cofaces; - if (dimension_ == -1) - { - std::cerr << "Simplex_tree::coface - empty simplex tree" << std::endl; - return cofaces; // ----->> - } - if (vertices == null_simplex()) { - std::cerr << "Simplex_tree::coface - empty vertices list" << std::endl; - return cofaces; // ----->> - } - if (codimension < 0) { - std::cerr << "Simplex_tree::coface - codimension is empty" << std::endl; - return cofaces; // ----->> - } + std::vector coface(const Simplex_handle &vertices, int codimension) { + std::vector cofaces; + if (dimension_ == -1) // Empty simplex tree + return cofaces; + if (vertices == null_simplex()) // Empty simplex + return cofaces; + if (codimension < 0) // codimension must be positive or null integer + return cofaces; std::vector copy; Simplex_vertex_range rg = simplex_vertex_range(vertices); for (auto it = rg.begin(); it != rg.end(); ++it) copy.push_back(*it); - if (codimension + copy.size() > (unsigned long)(dimension_ + 1) || (codimension == 0 && copy.size() > (unsigned long)dimension_) ) { - std::cerr << "Simplex_tree::coface - codimension + vertices list size cannot be greater than Simplex_tree dimension" << std::endl; - return cofaces; // ----->> - } + if (codimension + copy.size() > (unsigned long)(dimension_ + 1) || (codimension == 0 && copy.size() > (unsigned long)dimension_) ) // n+codimension greater than dimension_ + return cofaces; std::sort(copy.begin(), copy.end(), std::greater()); // must be sorted in decreasing order - Dictionary res; + std::vector res; rec_coface(copy, &root_, &res, cofaces, copy.size(), codimension + copy.size()); return cofaces; } diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index f685f079..eaae4149 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -1,9 +1,11 @@ #define BOOST_TEST_MODULE simplex_tree test #include +#include #include #include #include #include +#include #include // std::pair, std::make_pair @@ -24,6 +26,7 @@ typedef std::pair typeSimplex; const Vertex_handle DEFAULT_VERTEX_HANDLE = (const Vertex_handle) -1; const Filtration_value DEFAULT_FILTRATION_VALUE = (const Filtration_value) 0.0; + void test_empty_simplex_tree(typeST& tst) { BOOST_CHECK(tst.null_vertex() == DEFAULT_VERTEX_HANDLE); BOOST_CHECK(tst.filtration() == DEFAULT_FILTRATION_VALUE); @@ -36,6 +39,7 @@ void test_empty_simplex_tree(typeST& tst) { BOOST_CHECK(tst.dimension() == -1); } + void test_iterators_on_empty_simplex_tree(typeST& tst) { std::cout << "Iterator on vertices: " << std::endl; for (auto vertex : tst.complex_vertex_range()) { @@ -170,22 +174,25 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons BOOST_CHECK(simplexTree.num_simplices() == nb_simplices); } -void test_cofaces(typeST& st, std::vector v, int dim, int res) +void test_cofaces(typeST& st, std::vector v, int dim, std::vector> res) { - std::vector cofaces; + std::vector cofaces; if (dim == 0) cofaces = st.star(st.find(v)); else cofaces = st.coface(st.find(v), dim); - BOOST_CHECK(cofaces.size() == (size_t)res); + std::vector currentVertices; for (unsigned long i = 0; i < cofaces.size(); ++i) { - std::cout << "("; - auto j = cofaces[i].begin(); - std::cout << j->first; - for (auto j = cofaces[i].begin() + 1; j != cofaces[i].end(); ++j) - std::cout << "," << j->first; - std::cout << ")" << std::endl; + typeST::Simplex_vertex_range rg = st.simplex_vertex_range(cofaces[i]); + currentVertices.clear(); + for (auto j = rg.begin(); j != rg.end(); ++j) + { + std::cout << "(" << *j << ")"; + currentVertices.push_back(*j); + } + BOOST_CHECK(std::find(res.begin(), res.end(), currentVertices)!=res.end()); + std::cout << std::endl; } } @@ -427,210 +434,247 @@ BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) BOOST_AUTO_TEST_CASE( NSimplexAndSubfaces_tree_insertion ) { - Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle)0; - Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle) 1; - Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle) 2; - Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle) 3; - Vertex_handle FIFTH_VERTEX_HANDLE = (Vertex_handle) 4; - Vertex_handle SIXTH_VERTEX_HANDLE = (Vertex_handle) 5; - Vertex_handle SEVENTH_VERTEX_HANDLE = (Vertex_handle) 6; - Vertex_handle EIGHTH_VERTEX_HANDLE = (Vertex_handle) 7; - - // TEST OF INSERTION - std::cout << "********************************************************************" << std::endl; - std::cout << "TEST OF INSERTION" << std::endl; - typeST st; - - // ++ FIRST - std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex SimplexVector1; - SimplexVector1.push_back(THIRD_VERTEX_HANDLE); - SimplexVector1.push_back(SECOND_VERTEX_HANDLE); - SimplexVector1.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector1.size() == 3 ); - st.insert_simplex_and_subfaces ( SimplexVector1 ); - - BOOST_CHECK( st.num_vertices() == (size_t)3 ); // +3 (2, 1 and 0 are not existing) - - // ++ SECOND - std::cout << " - INSERT 3" << std::endl; - typeVectorVertex SimplexVector2; - SimplexVector2.push_back(FOURTH_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector2.size() == 1 ); - st.insert_simplex_and_subfaces ( SimplexVector2 ); - - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // +1 (3 is not existing) - - // ++ THIRD - std::cout << " - INSERT (0,3)" << std::endl; - typeVectorVertex SimplexVector3; - SimplexVector3.push_back(FOURTH_VERTEX_HANDLE); - SimplexVector3.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector3.size() == 2 ); - st.insert_simplex_and_subfaces ( SimplexVector3 ); - - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented (all are existing) - - // ++ FOURTH - std::cout << " - INSERT (1,0) (already inserted)" << std::endl; - typeVectorVertex SimplexVector4; - SimplexVector4.push_back(SECOND_VERTEX_HANDLE); - SimplexVector4.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector4.size() == 2 ); - st.insert_simplex_and_subfaces ( SimplexVector4 ); - - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented (all are existing) - - // ++ FIFTH - std::cout << " - INSERT (3,4,5)" << std::endl; - typeVectorVertex SimplexVector5; - SimplexVector5.push_back(FOURTH_VERTEX_HANDLE); - SimplexVector5.push_back(FIFTH_VERTEX_HANDLE); - SimplexVector5.push_back(SIXTH_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector5.size() == 3 ); - st.insert_simplex_and_subfaces ( SimplexVector5 ); - - BOOST_CHECK( st.num_vertices() == (size_t)6 ); - - // ++ SIXTH - std::cout << " - INSERT (0,1,6,7)" << std::endl; - typeVectorVertex SimplexVector6; - SimplexVector6.push_back(FIRST_VERTEX_HANDLE); - SimplexVector6.push_back(SECOND_VERTEX_HANDLE); - SimplexVector6.push_back(SEVENTH_VERTEX_HANDLE); - SimplexVector6.push_back(EIGHTH_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector6.size() == 4 ); - st.insert_simplex_and_subfaces ( SimplexVector6 ); + Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle)0; + Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle) 1; + Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle) 2; + Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle) 3; + Vertex_handle FIFTH_VERTEX_HANDLE = (Vertex_handle) 4; + Vertex_handle SIXTH_VERTEX_HANDLE = (Vertex_handle) 5; + Vertex_handle SEVENTH_VERTEX_HANDLE = (Vertex_handle) 6; + Vertex_handle EIGHTH_VERTEX_HANDLE = (Vertex_handle) 7; + + // TEST OF INSERTION + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF INSERTION" << std::endl; + typeST st; + + // ++ FIRST + std::cout << " - INSERT (2,1,0)" << std::endl; + typeVectorVertex SimplexVector1; + SimplexVector1.push_back(THIRD_VERTEX_HANDLE); + SimplexVector1.push_back(SECOND_VERTEX_HANDLE); + SimplexVector1.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( SimplexVector1.size() == 3 ); + st.insert_simplex_and_subfaces ( SimplexVector1 ); + + BOOST_CHECK( st.num_vertices() == (size_t)3 ); // +3 (2, 1 and 0 are not existing) + + // ++ SECOND + std::cout << " - INSERT 3" << std::endl; + typeVectorVertex SimplexVector2; + SimplexVector2.push_back(FOURTH_VERTEX_HANDLE); + BOOST_CHECK( SimplexVector2.size() == 1 ); + st.insert_simplex_and_subfaces ( SimplexVector2 ); + + BOOST_CHECK( st.num_vertices() == (size_t)4 ); // +1 (3 is not existing) + + // ++ THIRD + std::cout << " - INSERT (0,3)" << std::endl; + typeVectorVertex SimplexVector3; + SimplexVector3.push_back(FOURTH_VERTEX_HANDLE); + SimplexVector3.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( SimplexVector3.size() == 2 ); + st.insert_simplex_and_subfaces ( SimplexVector3 ); + + BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented (all are existing) + + // ++ FOURTH + std::cout << " - INSERT (1,0) (already inserted)" << std::endl; + typeVectorVertex SimplexVector4; + SimplexVector4.push_back(SECOND_VERTEX_HANDLE); + SimplexVector4.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( SimplexVector4.size() == 2 ); + st.insert_simplex_and_subfaces ( SimplexVector4 ); + + BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented (all are existing) + + // ++ FIFTH + std::cout << " - INSERT (3,4,5)" << std::endl; + typeVectorVertex SimplexVector5; + SimplexVector5.push_back(FOURTH_VERTEX_HANDLE); + SimplexVector5.push_back(FIFTH_VERTEX_HANDLE); + SimplexVector5.push_back(SIXTH_VERTEX_HANDLE); + BOOST_CHECK( SimplexVector5.size() == 3 ); + st.insert_simplex_and_subfaces ( SimplexVector5 ); + + BOOST_CHECK( st.num_vertices() == (size_t)6 ); + + // ++ SIXTH + std::cout << " - INSERT (0,1,6,7)" << std::endl; + typeVectorVertex SimplexVector6; + SimplexVector6.push_back(FIRST_VERTEX_HANDLE); + SimplexVector6.push_back(SECOND_VERTEX_HANDLE); + SimplexVector6.push_back(SEVENTH_VERTEX_HANDLE); + SimplexVector6.push_back(EIGHTH_VERTEX_HANDLE); + BOOST_CHECK( SimplexVector6.size() == 4 ); + st.insert_simplex_and_subfaces ( SimplexVector6 ); + + BOOST_CHECK( st.num_vertices() == (size_t)8 ); // +2 (6 and 7 are not existing - 0 and 1 are already existing) + + /* Inserted simplex: */ + /* 1 6 */ + /* o---o */ + /* /X\7/ */ + /* o---o---o---o */ + /* 2 0 3\X/4 */ + /* o */ + /* 5 */ + /* */ + /* In other words: */ + /* A facet [2,1,0] */ + /* An edge [0,3] */ + /* A facet [3,4,5] */ + /* A cell [0,1,6,7] */ + + typeSimplex simplexPair1 = std::make_pair(SimplexVector1, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair2 = std::make_pair(SimplexVector2, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair3 = std::make_pair(SimplexVector3, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair4 = std::make_pair(SimplexVector4, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair5 = std::make_pair(SimplexVector5, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair6 = std::make_pair(SimplexVector6, DEFAULT_FILTRATION_VALUE); + test_simplex_tree_contains(st,simplexPair1,6); // (2,1,0) is in position 6 + test_simplex_tree_contains(st,simplexPair2,7); // (3) is in position 7 + test_simplex_tree_contains(st,simplexPair3,8); // (3,0) is in position 8 + test_simplex_tree_contains(st,simplexPair4,2); // (1,0) is in position 2 + test_simplex_tree_contains(st,simplexPair5,14); // (3,4,5) is in position 14 + test_simplex_tree_contains(st,simplexPair6,26); // (7,6,1,0) is in position 26 + + // ------------------------------------------------------------------------------------------------------------------ + // Find in the simplex_tree + // ------------------------------------------------------------------------------------------------------------------ + typeVectorVertex simpleSimplexVector; + simpleSimplexVector.push_back(SECOND_VERTEX_HANDLE); + Simplex_tree<>::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"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is found + BOOST_CHECK(simplexFound != st.null_simplex()); + + Vertex_handle UNKNOWN_VERTEX_HANDLE = (Vertex_handle) 15; + typeVectorVertex unknownSimplexVector; + unknownSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); + simplexFound = st.find(unknownSimplexVector); + std::cout << "**************IS THE SIMPLEX {15} IN THE SIMPLEX TREE ?\n"; + if (simplexFound != st.null_simplex()) + std::cout << "***+ YES IT IS!\n"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is NOT found + BOOST_CHECK(simplexFound == st.null_simplex()); + + simplexFound = st.find(SimplexVector6); + std::cout << "**************IS THE SIMPLEX {0,1,6,7} IN THE SIMPLEX TREE ?\n"; + if (simplexFound != st.null_simplex()) + std::cout << "***+ YES IT IS!\n"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is found + BOOST_CHECK(simplexFound != st.null_simplex()); + + typeVectorVertex otherSimplexVector; + otherSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); + otherSimplexVector.push_back(SECOND_VERTEX_HANDLE); + simplexFound = st.find(otherSimplexVector); + std::cout << "**************IS THE SIMPLEX {15,1} IN THE SIMPLEX TREE ?\n"; + if (simplexFound != st.null_simplex()) + std::cout << "***+ YES IT IS!\n"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is NOT found + BOOST_CHECK(simplexFound == st.null_simplex()); + + typeVectorVertex invSimplexVector; + invSimplexVector.push_back(SECOND_VERTEX_HANDLE); + invSimplexVector.push_back(THIRD_VERTEX_HANDLE); + invSimplexVector.push_back(FIRST_VERTEX_HANDLE); + simplexFound = st.find(invSimplexVector); + std::cout << "**************IS THE SIMPLEX {1,2,0} IN THE SIMPLEX TREE ?\n"; + if (simplexFound != st.null_simplex()) + std::cout << "***+ YES IT IS!\n"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is found + BOOST_CHECK(simplexFound != st.null_simplex()); - BOOST_CHECK( st.num_vertices() == (size_t)8 ); // +2 (6 and 7 are not existing - 0 and 1 are already existing) - /* Inserted simplex: */ - /* 1 6 */ - /* o---o */ - /* /X\7/ */ - /* o---o---o---o */ - /* 2 0 3\X/4 */ - /* o */ - /* 5 */ - /* */ - /* In other words: */ - /* A facet [2,1,0] */ - /* An edge [0,3] */ - /* A facet [3,4,5] */ - /* A cell [0,1,6,7] */ - - typeSimplex simplexPair1 = std::make_pair(SimplexVector1, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair2 = std::make_pair(SimplexVector2, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair3 = std::make_pair(SimplexVector3, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair4 = std::make_pair(SimplexVector4, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair5 = std::make_pair(SimplexVector5, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair6 = std::make_pair(SimplexVector6, DEFAULT_FILTRATION_VALUE); - test_simplex_tree_contains(st,simplexPair1,6); // (2,1,0) is in position 6 - test_simplex_tree_contains(st,simplexPair2,7); // (3) is in position 7 - test_simplex_tree_contains(st,simplexPair3,8); // (3,0) is in position 8 - test_simplex_tree_contains(st,simplexPair4,2); // (1,0) is in position 2 - test_simplex_tree_contains(st,simplexPair5,14); // (3,4,5) is in position 14 - test_simplex_tree_contains(st,simplexPair6,26); // (7,6,1,0) is in position 26 - - // ------------------------------------------------------------------------------------------------------------------ - // Find in the simplex_tree - // ------------------------------------------------------------------------------------------------------------------ - typeVectorVertex simpleSimplexVector; - simpleSimplexVector.push_back(SECOND_VERTEX_HANDLE); - Simplex_tree<>::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"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is found - BOOST_CHECK(simplexFound != st.null_simplex()); - - Vertex_handle UNKNOWN_VERTEX_HANDLE = (Vertex_handle) 15; - typeVectorVertex unknownSimplexVector; - unknownSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); - simplexFound = st.find(unknownSimplexVector); - std::cout << "**************IS THE SIMPLEX {15} IN THE SIMPLEX TREE ?\n"; - if (simplexFound != st.null_simplex()) - std::cout << "***+ YES IT IS!\n"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is NOT found - BOOST_CHECK(simplexFound == st.null_simplex()); - - simplexFound = st.find(SimplexVector6); - std::cout << "**************IS THE SIMPLEX {0,1,6,7} IN THE SIMPLEX TREE ?\n"; - if (simplexFound != st.null_simplex()) - std::cout << "***+ YES IT IS!\n"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is found - BOOST_CHECK(simplexFound != st.null_simplex()); - - typeVectorVertex otherSimplexVector; - otherSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); - otherSimplexVector.push_back(SECOND_VERTEX_HANDLE); - simplexFound = st.find(otherSimplexVector); - std::cout << "**************IS THE SIMPLEX {15,1} IN THE SIMPLEX TREE ?\n"; - if (simplexFound != st.null_simplex()) - std::cout << "***+ YES IT IS!\n"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is NOT found - BOOST_CHECK(simplexFound == st.null_simplex()); - - typeVectorVertex invSimplexVector; - invSimplexVector.push_back(SECOND_VERTEX_HANDLE); - invSimplexVector.push_back(THIRD_VERTEX_HANDLE); - invSimplexVector.push_back(FIRST_VERTEX_HANDLE); - simplexFound = st.find(invSimplexVector); - std::cout << "**************IS THE SIMPLEX {1,2,0} IN THE SIMPLEX TREE ?\n"; - if (simplexFound != st.null_simplex()) - std::cout << "***+ YES IT IS!\n"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is found - BOOST_CHECK(simplexFound != st.null_simplex()); - - // Display the Simplex_tree - Can not be done in the middle of 2 inserts - std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; - std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - for( auto f_simplex : st.filtration_simplex_range() ) - { - std::cout << " " << "[" << st.filtration(f_simplex) << "] "; - for( auto vertex : st.simplex_vertex_range(f_simplex) ) - { - std::cout << (int)vertex << " "; - } - std::cout << std::endl; - } + // Display the Simplex_tree - Can not be done in the middle of 2 inserts + std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; + std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; + std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + for( auto f_simplex : st.filtration_simplex_range() ) + { + std::cout << " " << "[" << st.filtration(f_simplex) << "] "; + for( auto vertex : st.simplex_vertex_range(f_simplex) ) + { + std::cout << (int)vertex << " "; + } + std::cout << std::endl; + } + std::cout << "********************************************************************" << std::endl; // TEST COFACE ALGORITHM st.set_dimension(3); std::cout << "COFACE ALGORITHM" << std::endl; std::vector v; + std::vector> result; v.push_back(3); + std::cout << "First test : " << std::endl; std::cout << "Star of (3):" << std::endl; - test_cofaces(st, v, 0, 4); + int firstCoface[] = {3, 0}; + int secondCoface[] = {4, 3}; + int thirdCoface[] = {5, 4, 3}; + int fourthCoface[] = {5, 3}; + result.push_back(std::vector(firstCoface, firstCoface + 2)); + result.push_back(std::vector(secondCoface, secondCoface + 2)); + result.push_back(std::vector(thirdCoface, thirdCoface + 3)); + result.push_back(std::vector(fourthCoface, fourthCoface + 2)); + test_cofaces(st, v, 0, result); v.clear(); + result.clear(); + v.push_back(1); v.push_back(7); + std::cout << "Second test : " << std::endl; std::cout << "Star of (1,7): " << std::endl; - test_cofaces(st, v, 0, 3); - std::cout << "Cofaces of (1,7) of dimension 2: " << std::endl; - test_cofaces(st, v, 1, 2); + int firstCoface2[] = {7, 6, 1, 0}; + int secondCoface2[] = {7, 1, 0}; + int thirdCoface2[] = {7 ,6, 1}; + result.push_back(std::vector(firstCoface2, firstCoface2 + 4)); + result.push_back(std::vector(secondCoface2, secondCoface2 + 3)); + result.push_back(std::vector(thirdCoface2, thirdCoface2 + 3)); + test_cofaces(st, v, 0, result); + result.clear(); + + std::cout << "Third test : " << std::endl; + std::cout << "2-dimension Cofaces of simplex(1,7) : " << std::endl; + int secondCoface3[] = {7, 1, 0}; + int firstCoface3[] = {7, 6, 1}; + result.push_back(std::vector(firstCoface3, firstCoface3 + 3)); + result.push_back(std::vector(secondCoface3, secondCoface3 + 3)); + test_cofaces(st, v, 1, result); + result.clear(); + std::cout << "Cofaces with a codimension too high (codimension + vetices > tree.dimension)" << std::endl; - test_cofaces(st, v, 5, 0); + test_cofaces(st, v, 5, result); std::cout << "Cofaces with an empty codimension" << std::endl; - test_cofaces(st, v, -1, 0); + test_cofaces(st, v, -1, result); std::cout << "Cofaces in an empty simplex tree" << std::endl; typeST empty_tree; - test_cofaces(empty_tree, v, 1, 0); + test_cofaces(empty_tree, v, 1, result); std::cout << "Cofaces of an empty simplex" << std::endl; v.clear(); - test_cofaces(st, v, 1, 0); - + test_cofaces(st, v, 1, result); + + /* + // TEST Off read + std::cout << "********************************************************************" << std::endl; + typeST st2; + st2.tree_from_off("test.off"); + std::cout << st2; + */ } -- cgit v1.2.3 From 7a8800cd5b94201cba53458897cad23856e3d3ee Mon Sep 17 00:00:00 2001 From: anmoreau Date: Thu, 18 Jun 2015 08:33:57 +0000 Subject: Fix : name of parameters and functions git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@622 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 15c8419159a268dcb5b8bbfa63fb01adc8851905 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 18 +++++++++--------- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 4 ++-- 2 files changed, 11 insertions(+), 11 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 26a8eba6..eb423082 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -627,7 +627,7 @@ private: curr_res->push_back(sib->first); bool egalDim = (codimension == length || curr_res->size() == codimension); // dimension of actual simplex == codimension if (egalDim) - cofaces.push_back(find(*curr_res)); + cofaces.push_back(curr_sib->members().find(sib->first)); if (has_children(sib)) rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); curr_res->pop_back(); @@ -640,7 +640,7 @@ private: curr_res->push_back(sib->first); bool egalDim = (codimension == length || curr_res->size() == codimension); // dimension of actual simplex == codimension if (vertices.size() == 1 && curr_res->size() > length && egalDim) - cofaces.push_back(find(*curr_res)); + cofaces.push_back(curr_sib->members().find(sib->first)); if (has_children(sib)) { // Rec call Vertex_handle tmp = vertices[vertices.size()-1]; @@ -665,33 +665,33 @@ private: public: /** \brief Compute the star of a n simplex - * \param vertices handles the simplex of which we search the star + * \param simplex handles the simplex of which we search the star * \return Vector of Simplex_handle, empty vector if no cofaces found. */ - std::vector star(const Simplex_handle &vertices) { - return coface(vertices, 0); + std::vector star_simplex_range(const Simplex_handle simplex) { + return cofaces_simplex_range(simplex, 0); } /** \brief Compute the cofaces of a n simplex - * \param vertices handles the n-simplex of which we search the n+codimension cofaces + * \param simplex handles the n-simplex of which we search the n+codimension cofaces * \param codimension The function returns the n+codimension-cofaces of the n-simplex. If codimension = 0, return all cofaces (equivalent of star function) * \return Vector of Simplex_handle, empty vector if no cofaces found. * \warning n+codimension must be lower than Simplex_tree dimension, otherwise an an empty vector is returned. */ - std::vector coface(const Simplex_handle &vertices, int codimension) { + std::vector cofaces_simplex_range(const Simplex_handle simplex, int codimension) { std::vector cofaces; if (dimension_ == -1) // Empty simplex tree return cofaces; - if (vertices == null_simplex()) // Empty simplex + if (simplex == null_simplex()) // Empty simplex return cofaces; if (codimension < 0) // codimension must be positive or null integer return cofaces; std::vector copy; - Simplex_vertex_range rg = simplex_vertex_range(vertices); + Simplex_vertex_range rg = simplex_vertex_range(simplex); for (auto it = rg.begin(); it != rg.end(); ++it) copy.push_back(*it); if (codimension + copy.size() > (unsigned long)(dimension_ + 1) || (codimension == 0 && copy.size() > (unsigned long)dimension_) ) // n+codimension greater than dimension_ diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index eaae4149..f8de1c24 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -178,9 +178,9 @@ void test_cofaces(typeST& st, std::vector v, int dim, std::vector { std::vector cofaces; if (dim == 0) - cofaces = st.star(st.find(v)); + cofaces = st.star_simplex_range(st.find(v)); else - cofaces = st.coface(st.find(v), dim); + cofaces = st.cofaces_simplex_range(st.find(v), dim); std::vector currentVertices; for (unsigned long i = 0; i < cofaces.size(); ++i) { -- cgit v1.2.3 From 9d3c9ae3ccd861c00d113c17da7ec896eece7dac Mon Sep 17 00:00:00 2001 From: anmoreau Date: Fri, 19 Jun 2015 09:47:36 +0000 Subject: multiple fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@627 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 54af67a192141448c344e7bbc59b1e55ff660f30 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 33 ++++++++++++--------------- 1 file changed, 15 insertions(+), 18 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 eb423082..241b692f 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -613,19 +613,18 @@ private: * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_res so that we didn't change the parameters. * If the vertices list is empty, we need to check if the size of the curr_res list matches with the dimension of the cofaces asked. */ - template - void rec_coface(RandomAccessVertexRange &vertices, Siblings *curr_sib, RandomAccessVertexRange *curr_res, std::vector& cofaces, unsigned int length, unsigned long codimension) + void rec_coface(std::vector &vertices, Siblings *curr_sib, std::vector *curr_res, std::vector& cofaces, int length, long codimension) { - for (auto sib = curr_sib->members().begin(); sib != curr_sib->members().end() && (vertices.empty() || sib->first <= vertices[vertices.size()-1]); ++sib) + for (auto sib = curr_sib->members().begin(); sib != curr_sib->members().end() && (vertices.empty() || sib->first <= vertices.back()); ++sib) { - bool continueRecursion = (codimension == length || curr_res->size() <= codimension); // dimension of actual simplex <= codimension + bool continueRecursion = (codimension == length || (int)curr_res->size() <= codimension); // dimension of actual simplex <= codimension if (vertices.empty()) { - if (curr_res->size() >= length && continueRecursion) + if ((int)curr_res->size() >= length && continueRecursion) // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface { curr_res->push_back(sib->first); - bool egalDim = (codimension == length || curr_res->size() == codimension); // dimension of actual simplex == codimension + bool egalDim = (codimension == length || (int)curr_res->size() == codimension); // dimension of actual simplex == codimension if (egalDim) cofaces.push_back(curr_sib->members().find(sib->first)); if (has_children(sib)) @@ -635,22 +634,22 @@ private: } else if (continueRecursion) { - if (sib->first == vertices[vertices.size()-1]) // If curr_sib matches with the top vertex + if (sib->first == vertices.back()) // If curr_sib matches with the top vertex { curr_res->push_back(sib->first); - bool egalDim = (codimension == length || curr_res->size() == codimension); // dimension of actual simplex == codimension - if (vertices.size() == 1 && curr_res->size() > length && egalDim) + bool equalDim = (codimension == length || (int)curr_res->size() == codimension); // dimension of actual simplex == codimension + if (vertices.size() == 1 && (int)curr_res->size() > length && equalDim) cofaces.push_back(curr_sib->members().find(sib->first)); if (has_children(sib)) { // Rec call - Vertex_handle tmp = vertices[vertices.size()-1]; + Vertex_handle tmp = vertices.back(); vertices.pop_back(); rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); vertices.push_back(tmp); } curr_res->pop_back(); } - else // (sib->first < vertices[vertices.size()-1]) + else // (sib->first < vertices.back() { if (has_children(sib)) { @@ -665,7 +664,7 @@ private: public: /** \brief Compute the star of a n simplex - * \param simplex handles the simplex of which we search the star + * \param simplex represent the simplex of which we search the star * \return Vector of Simplex_handle, empty vector if no cofaces found. */ @@ -676,7 +675,7 @@ public: /** \brief Compute the cofaces of a n simplex - * \param simplex handles the n-simplex of which we search the n+codimension cofaces + * \param simplex represent the n-simplex of which we search the n+codimension cofaces * \param codimension The function returns the n+codimension-cofaces of the n-simplex. If codimension = 0, return all cofaces (equivalent of star function) * \return Vector of Simplex_handle, empty vector if no cofaces found. * \warning n+codimension must be lower than Simplex_tree dimension, otherwise an an empty vector is returned. @@ -690,15 +689,13 @@ public: return cofaces; if (codimension < 0) // codimension must be positive or null integer return cofaces; - std::vector copy; Simplex_vertex_range rg = simplex_vertex_range(simplex); - for (auto it = rg.begin(); it != rg.end(); ++it) - copy.push_back(*it); - if (codimension + copy.size() > (unsigned long)(dimension_ + 1) || (codimension == 0 && copy.size() > (unsigned long)dimension_) ) // n+codimension greater than dimension_ + std::vector copy(rg.begin(), rg.end()); + if (codimension + (int)copy.size() > dimension_ + 1 || (codimension == 0 && (int)copy.size() > dimension_) ) // n+codimension greater than dimension_ return cofaces; std::sort(copy.begin(), copy.end(), std::greater()); // must be sorted in decreasing order std::vector res; - rec_coface(copy, &root_, &res, cofaces, copy.size(), codimension + copy.size()); + rec_coface(copy, &root_, &res, cofaces, (int)copy.size(), codimension + (int)copy.size()); return cofaces; } -- cgit v1.2.3 From fbdb713ed3f321e7a983eb4c50a8b26a37f3c193 Mon Sep 17 00:00:00 2001 From: glisse Date: Fri, 19 Jun 2015 12:52:35 +0000 Subject: Trivial clean-ups - add static/const to some member functions - remove an unused variable - don't pass int by const& git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/constify-ST@632 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d8742bf06caf10115ba4b5157e81bfd7bf8d6e15 --- src/Alpha_shapes/include/gudhi/Alpha_shapes.h | 2 +- .../include/gudhi/Persistent_cohomology/Field_Zp.h | 2 +- src/Simplex_tree/include/gudhi/Simplex_tree.h | 32 +++++++++++----------- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h index b8efdb4d..e988f683 100644 --- a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h +++ b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h @@ -171,7 +171,7 @@ class Alpha_shapes { /** \brief Returns the number of simplices in the complex. * * Does not count the empty simplex. */ - const unsigned int& num_simplices() const { + unsigned int num_simplices() const { return _st.num_simplices(); } diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h index 2349cdac..2a4c8692 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h @@ -85,7 +85,7 @@ class Field_Zp { return add_id_all; } /** \brief Returns the multiplicative identity \f$1_{\Bbbk}\f$ of the field.*/ - const Element& multiplicative_identity(Element P = 0) const { + const Element& multiplicative_identity(Element = 0) const { return mult_id_all; } /** Returns the inverse in the field. Modifies P.*/ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index b79e3c8f..9d0cf755 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -325,7 +325,7 @@ class Simplex_tree { /** \brief Returns the filtration value of a simplex. * * Called on the null_simplex, returns INFINITY. */ - Filtration_value filtration(Simplex_handle sh) { + Filtration_value filtration(Simplex_handle sh) const { if (sh != null_simplex()) { return sh->second.filtration(); } else { @@ -333,34 +333,34 @@ class Simplex_tree { } // filtration(); } } /** \brief Returns an upper bound of the filtration values of the simplices. */ - Filtration_value filtration() { + Filtration_value filtration() const { return threshold_; } /** \brief Returns a Simplex_handle different from all Simplex_handles * associated to the simplices in the simplicial complex. * * One can call filtration(null_simplex()). */ - Simplex_handle null_simplex() { + Simplex_handle null_simplex() const { return Dictionary_it(NULL); } /** \brief Returns a key different for all keys associated to the * simplices of the simplicial complex. */ - Simplex_key null_key() { + Simplex_key null_key() const { return -1; } /** \brief Returns a Vertex_handle different from all Vertex_handles associated * to the vertices of the simplicial complex. */ - Vertex_handle null_vertex() { + Vertex_handle null_vertex() const { return null_vertex_; } /** \brief Returns the number of vertices in the complex. */ - size_t num_vertices() { + size_t num_vertices() const { return root_.members_.size(); } /** \brief Returns the number of simplices in the complex. * * Does not count the empty simplex. */ - const unsigned int& num_simplices() const { + unsigned int num_simplices() const { return num_simplices_; } @@ -377,13 +377,13 @@ class Simplex_tree { return dim - 1; } /** \brief Returns an upper bound on the dimension of the simplicial complex. */ - int dimension() { + int dimension() const { return dimension_; } /** \brief Returns true iff the node in the simplex tree pointed by * sh has children.*/ - bool has_children(Simplex_handle sh) { + bool has_children(Simplex_handle sh) const { return (sh->second.children()->parent() == sh->first); } @@ -563,7 +563,7 @@ class Simplex_tree { threshold_ = fil; } /** Set a number of simplices for the simplicial complex. */ - void set_num_simplices(const unsigned int& num_simplices) { + void set_num_simplices(unsigned int num_simplices) { num_simplices_ = num_simplices; } /** Set a dimension for the simplicial complex. */ @@ -771,10 +771,10 @@ class Simplex_tree { } /** \brief Intersects Dictionary 1 [begin1;end1) with Dictionary 2 [begin2,end2) * and assigns the maximal possible Filtration_value to the Nodes. */ - void intersection(std::vector >& intersection, - Dictionary_it begin1, Dictionary_it end1, - Dictionary_it begin2, Dictionary_it end2, - Filtration_value filtration) { + static void intersection(std::vector >& intersection, + Dictionary_it begin1, Dictionary_it end1, + Dictionary_it begin2, Dictionary_it end2, + Filtration_value filtration) { if (begin1 == end1 || begin2 == end2) return; // ----->> while (true) { @@ -801,8 +801,8 @@ class Simplex_tree { } } /** Maximum over 3 values.*/ - Filtration_value maximum(Filtration_value a, Filtration_value b, - Filtration_value c) { + static Filtration_value maximum(Filtration_value a, Filtration_value b, + Filtration_value c) { Filtration_value max = (a < b) ? b : a; return ((max < c) ? c : max); } -- cgit v1.2.3 From 4eb1939d74050c9193daecba2f69471b915180b2 Mon Sep 17 00:00:00 2001 From: anmoreau Date: Tue, 23 Jun 2015 15:01:05 +0000 Subject: multiple fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@634 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 0bcb4f121da2714128c3ae8ab0da2000e815d339 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 109 ++++++++++++---------- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 114 +++++++++++++++-------- 2 files changed, 134 insertions(+), 89 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 241b692f..a355c334 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -156,6 +156,12 @@ class Simplex_tree { typedef Simplex_tree_simplex_vertex_iterator Simplex_vertex_iterator; /** \brief Range over the vertices of a simplex. */ typedef boost::iterator_range Simplex_vertex_range; + /** \brief Range over the cofaces of a simplex. */ + /** \brief Iterator over the cofaces of a simplex. + * + * 'value_type' is Vertex_handle. */ + typedef typename std::vector::iterator Coface_simplex_iterator; + typedef boost::iterator_range Coface_simplex_range; /** \brief Iterator over the simplices of the boundary of a simplex. * * 'value_type' is Simplex_handle. */ @@ -187,8 +193,7 @@ class Simplex_tree { /** \name Range and iterator methods * @{ */ - /** \brief Returns a range over the vertices of the simplicial complex. - * + /** \brief Returns a range over the vertices of the simplicial complex. * * The order is increasing according to < on Vertex_handles.*/ Complex_vertex_range complex_vertex_range() { return Complex_vertex_range( @@ -206,6 +211,7 @@ class Simplex_tree { Complex_simplex_iterator()); } + /** \brief Returns a range over the simplices of the dim-skeleton of the simplicial complex. * * The \f$d\f$-skeleton of a simplicial complex \f$\mathbf{K}\f$ is the simplicial complex containing the @@ -252,10 +258,12 @@ class Simplex_tree { * equal to \f$(-1)^{\text{dim} \sigma}\f$ the canonical orientation on the simplex. */ Simplex_vertex_range simplex_vertex_range(Simplex_handle sh) { +// assert (simplex != null_simplex()); // Empty simplex return Simplex_vertex_range(Simplex_vertex_iterator(this, sh), Simplex_vertex_iterator(this)); } + /** \brief Returns a range over the simplices of the boundary of a simplex. * * The boundary of a simplex is the set of codimension \f$1\f$ subsimplices of the simplex. @@ -386,6 +394,12 @@ class Simplex_tree { bool has_children(Simplex_handle sh) { return (sh->second.children()->parent() == sh->first); } + + /** \brief Returns true iff the node in the simplex tree pointed by + * sh has children.*/ + bool has_children(Dit_value_t sh) { + return (sh.second.children()->parent() == sh.first); + } /** \brief Given a range of Vertex_handles, returns the Simplex_handle * of the simplex in the simplicial complex containing the corresponding @@ -607,55 +621,57 @@ private: *\param vertices contains a list of vertices, which represent the simplex. *\param curr_res contains a list of vertices, which represent the current path in the tree. *\param cofaces contains a list of Simplex_handle, representing all the cofaces asked. - *\param length length of the vertices list + *\param length length of the vertex list "vertices" * Prefix actions : When the bottom vertex matches with the current vertex in the tree, we remove the bottom vertex from vertices. * Infix actions : Then we call or not the recursion. * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_res so that we didn't change the parameters. * If the vertices list is empty, we need to check if the size of the curr_res list matches with the dimension of the cofaces asked. */ - void rec_coface(std::vector &vertices, Siblings *curr_sib, std::vector *curr_res, std::vector& cofaces, int length, long codimension) + void rec_coface(std::vector &vertices, Siblings *curr_sib, std::vector &curr_res, std::vector& cofaces, int length, int nbVertices) { - for (auto sib = curr_sib->members().begin(); sib != curr_sib->members().end() && (vertices.empty() || sib->first <= vertices.back()); ++sib) + if (!(nbVertices == length || (int)curr_res.size() <= nbVertices)) // dimension of actual simplex <= nbVertices + return; +// for (auto simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) + for (auto& simplex : curr_sib->members()) { - bool continueRecursion = (codimension == length || (int)curr_res->size() <= codimension); // dimension of actual simplex <= codimension if (vertices.empty()) + { + // if ((int)curr_res.size() >= length && continueRecursion) + // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface + curr_res.push_back(simplex.first); + bool equalDim = (nbVertices == length || (int)curr_res.size() == nbVertices); // dimension of actual simplex == nbVertices + if (equalDim) + cofaces.push_back(curr_sib->members().find(simplex.first)); + if (has_children(simplex)) + rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); + curr_res.pop_back(); + } + else { - if ((int)curr_res->size() >= length && continueRecursion) - // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface + if (simplex.first == vertices.back()) // If curr_sib matches with the top vertex { - curr_res->push_back(sib->first); - bool egalDim = (codimension == length || (int)curr_res->size() == codimension); // dimension of actual simplex == codimension - if (egalDim) - cofaces.push_back(curr_sib->members().find(sib->first)); - if (has_children(sib)) - rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); - curr_res->pop_back(); - } - } - else if (continueRecursion) - { - if (sib->first == vertices.back()) // If curr_sib matches with the top vertex - { - curr_res->push_back(sib->first); - bool equalDim = (codimension == length || (int)curr_res->size() == codimension); // dimension of actual simplex == codimension - if (vertices.size() == 1 && (int)curr_res->size() > length && equalDim) - cofaces.push_back(curr_sib->members().find(sib->first)); - if (has_children(sib)) + curr_res.push_back(simplex.first); + bool equalDim = (nbVertices == length || (int)curr_res.size() == nbVertices); // dimension of actual simplex == nbVertices + if (vertices.size() == 1 && (int)curr_res.size() > length && equalDim) + cofaces.push_back(curr_sib->members().find(simplex.first)); + if (has_children(simplex)) { // Rec call Vertex_handle tmp = vertices.back(); vertices.pop_back(); - rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); + rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); vertices.push_back(tmp); } - curr_res->pop_back(); + curr_res.pop_back(); } - else // (sib->first < vertices.back() + else if (simplex.first > vertices.back()) + return; + else // (simplex.first < vertices.back() { - if (has_children(sib)) + if (has_children(simplex)) { - curr_res->push_back(sib->first); - rec_coface(vertices, sib->second.children(), curr_res, cofaces, length, codimension); - curr_res->pop_back(); + curr_res.push_back(simplex.first); + rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); + curr_res.pop_back(); } } } @@ -668,8 +684,8 @@ public: * \return Vector of Simplex_handle, empty vector if no cofaces found. */ - std::vector star_simplex_range(const Simplex_handle simplex) { - return cofaces_simplex_range(simplex, 0); + Coface_simplex_range star_simplex_range(const Simplex_handle simplex) { + return coface_simplex_range(simplex, 0); } @@ -678,27 +694,24 @@ public: * \param simplex represent the n-simplex of which we search the n+codimension cofaces * \param codimension The function returns the n+codimension-cofaces of the n-simplex. If codimension = 0, return all cofaces (equivalent of star function) * \return Vector of Simplex_handle, empty vector if no cofaces found. - * \warning n+codimension must be lower than Simplex_tree dimension, otherwise an an empty vector is returned. */ - std::vector cofaces_simplex_range(const Simplex_handle simplex, int codimension) { + Coface_simplex_range coface_simplex_range(const Simplex_handle simplex, int codimension) { std::vector cofaces; - if (dimension_ == -1) // Empty simplex tree - return cofaces; - if (simplex == null_simplex()) // Empty simplex - return cofaces; - if (codimension < 0) // codimension must be positive or null integer - return cofaces; + assert (simplex != null_simplex()); // Empty simplex + assert (codimension >= 0); // codimension must be positive or null integer Simplex_vertex_range rg = simplex_vertex_range(simplex); std::vector copy(rg.begin(), rg.end()); if (codimension + (int)copy.size() > dimension_ + 1 || (codimension == 0 && (int)copy.size() > dimension_) ) // n+codimension greater than dimension_ - return cofaces; - std::sort(copy.begin(), copy.end(), std::greater()); // must be sorted in decreasing order + return Coface_simplex_range(cofaces.begin(), cofaces.end()); + assert(std::is_sorted(copy.begin(), copy.end(), std::greater())); // must be sorted in decreasing order std::vector res; - rec_coface(copy, &root_, &res, cofaces, (int)copy.size(), codimension + (int)copy.size()); - return cofaces; + rec_coface(copy, &root_, res, cofaces, (int)copy.size(), codimension + (int)copy.size()); + return Coface_simplex_range(cofaces.begin(), cofaces.end()); } - + + + private: /** \brief Returns true iff the list of vertices of sh1 diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index f8de1c24..344cb009 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -174,25 +174,20 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons BOOST_CHECK(simplexTree.num_simplices() == nb_simplices); } -void test_cofaces(typeST& st, std::vector v, int dim, std::vector> res) -{ - std::vector cofaces; +void test_cofaces(typeST& st, std::vector v, int dim, std::vector res) { + typeST::Coface_simplex_range cofaces; if (dim == 0) cofaces = st.star_simplex_range(st.find(v)); else - cofaces = st.cofaces_simplex_range(st.find(v), dim); - std::vector currentVertices; - for (unsigned long i = 0; i < cofaces.size(); ++i) + cofaces = st.coface_simplex_range(st.find(v), dim); + for (auto simplex = cofaces.begin(); simplex != cofaces.end(); ++simplex) { - typeST::Simplex_vertex_range rg = st.simplex_vertex_range(cofaces[i]); - currentVertices.clear(); - for (auto j = rg.begin(); j != rg.end(); ++j) - { - std::cout << "(" << *j << ")"; - currentVertices.push_back(*j); + typeST::Simplex_vertex_range rg = st.simplex_vertex_range(*simplex); + for (auto vertex = rg.begin(); vertex != rg.end(); ++vertex) { + std::cout << "(" << *vertex << ")" ; } - BOOST_CHECK(std::find(res.begin(), res.end(), currentVertices)!=res.end()); std::cout << std::endl; + BOOST_CHECK(std::find(res.begin(), res.end(), *simplex)!=res.end()); } } @@ -620,18 +615,32 @@ BOOST_AUTO_TEST_CASE( NSimplexAndSubfaces_tree_insertion ) st.set_dimension(3); std::cout << "COFACE ALGORITHM" << std::endl; std::vector v; - std::vector> result; + std::vector simplex; + std::vector result; v.push_back(3); std::cout << "First test : " << std::endl; std::cout << "Star of (3):" << std::endl; - int firstCoface[] = {3, 0}; - int secondCoface[] = {4, 3}; - int thirdCoface[] = {5, 4, 3}; - int fourthCoface[] = {5, 3}; - result.push_back(std::vector(firstCoface, firstCoface + 2)); - result.push_back(std::vector(secondCoface, secondCoface + 2)); - result.push_back(std::vector(thirdCoface, thirdCoface + 3)); - result.push_back(std::vector(fourthCoface, fourthCoface + 2)); + simplex.push_back(3); + simplex.push_back(0); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(4); + simplex.push_back(3); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(5); + simplex.push_back(4); + simplex.push_back(3); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(5); + simplex.push_back(3); + result.push_back(st.find(simplex)); + simplex.clear(); + test_cofaces(st, v, 0, result); v.clear(); result.clear(); @@ -640,34 +649,57 @@ BOOST_AUTO_TEST_CASE( NSimplexAndSubfaces_tree_insertion ) v.push_back(7); std::cout << "Second test : " << std::endl; std::cout << "Star of (1,7): " << std::endl; - int firstCoface2[] = {7, 6, 1, 0}; - int secondCoface2[] = {7, 1, 0}; - int thirdCoface2[] = {7 ,6, 1}; - result.push_back(std::vector(firstCoface2, firstCoface2 + 4)); - result.push_back(std::vector(secondCoface2, secondCoface2 + 3)); - result.push_back(std::vector(thirdCoface2, thirdCoface2 + 3)); + + simplex.push_back(7); + simplex.push_back(6); + simplex.push_back(1); + simplex.push_back(0); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(7); + simplex.push_back(1); + simplex.push_back(0); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(7); + simplex.push_back(6); + simplex.push_back(1); + result.push_back(st.find(simplex)); + simplex.clear(); + test_cofaces(st, v, 0, result); result.clear(); std::cout << "Third test : " << std::endl; std::cout << "2-dimension Cofaces of simplex(1,7) : " << std::endl; - int secondCoface3[] = {7, 1, 0}; - int firstCoface3[] = {7, 6, 1}; - result.push_back(std::vector(firstCoface3, firstCoface3 + 3)); - result.push_back(std::vector(secondCoface3, secondCoface3 + 3)); + + simplex.push_back(7); + simplex.push_back(1); + simplex.push_back(0); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(7); + simplex.push_back(6); + simplex.push_back(1); + result.push_back(st.find(simplex)); + simplex.clear(); + test_cofaces(st, v, 1, result); result.clear(); - std::cout << "Cofaces with a codimension too high (codimension + vetices > tree.dimension)" << std::endl; + std::cout << "Cofaces with a codimension too high (codimension + vetices > tree.dimension) :" << std::endl; test_cofaces(st, v, 5, result); - std::cout << "Cofaces with an empty codimension" << std::endl; - test_cofaces(st, v, -1, result); - std::cout << "Cofaces in an empty simplex tree" << std::endl; - typeST empty_tree; - test_cofaces(empty_tree, v, 1, result); - std::cout << "Cofaces of an empty simplex" << std::endl; - v.clear(); - test_cofaces(st, v, 1, result); +// std::cout << "Cofaces with an empty codimension" << std::endl; +// test_cofaces(st, v, -1, result); +// std::cout << "Cofaces in an empty simplex tree" << std::endl; +// typeST empty_tree; +// test_cofaces(empty_tree, v, 1, result); +// std::cout << "Cofaces of an empty simplex" << std::endl; +// v.clear(); +// test_cofaces(st, v, 1, result); /* // TEST Off read -- cgit v1.2.3 From 39dbac0617b4a542f47225a9dcf6f088a12be5be Mon Sep 17 00:00:00 2001 From: anmoreau Date: Tue, 23 Jun 2015 15:17:53 +0000 Subject: multiple fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@636 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 36023554707626e7c66d52777f4d4b9245e95317 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 3 +-- 1 file changed, 1 insertion(+), 2 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 a355c334..ad9f7dd7 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -258,7 +258,7 @@ class Simplex_tree { * equal to \f$(-1)^{\text{dim} \sigma}\f$ the canonical orientation on the simplex. */ Simplex_vertex_range simplex_vertex_range(Simplex_handle sh) { -// assert (simplex != null_simplex()); // Empty simplex + assert (sh != null_simplex()); // Empty simplex return Simplex_vertex_range(Simplex_vertex_iterator(this, sh), Simplex_vertex_iterator(this)); } @@ -698,7 +698,6 @@ public: Coface_simplex_range coface_simplex_range(const Simplex_handle simplex, int codimension) { std::vector cofaces; - assert (simplex != null_simplex()); // Empty simplex assert (codimension >= 0); // codimension must be positive or null integer Simplex_vertex_range rg = simplex_vertex_range(simplex); std::vector copy(rg.begin(), rg.end()); -- cgit v1.2.3 From a602092b3437afb3271196f21dea4f4e944436c3 Mon Sep 17 00:00:00 2001 From: anmoreau Date: Wed, 24 Jun 2015 08:49:50 +0000 Subject: Multiple fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@637 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d44b4ced5406c0b8ab305ec752077f9b5c242d4d --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 16 ++++++---------- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 2 +- 2 files changed, 7 insertions(+), 11 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 ad9f7dd7..4dee1432 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -157,11 +157,7 @@ class Simplex_tree { /** \brief Range over the vertices of a simplex. */ typedef boost::iterator_range Simplex_vertex_range; /** \brief Range over the cofaces of a simplex. */ - /** \brief Iterator over the cofaces of a simplex. - * - * 'value_type' is Vertex_handle. */ - typedef typename std::vector::iterator Coface_simplex_iterator; - typedef boost::iterator_range Coface_simplex_range; + typedef std::vector Coface_simplex_range; /** \brief Iterator over the simplices of the boundary of a simplex. * * 'value_type' is Simplex_handle. */ @@ -397,7 +393,7 @@ class Simplex_tree { /** \brief Returns true iff the node in the simplex tree pointed by * sh has children.*/ - bool has_children(Dit_value_t sh) { + bool has_children(Dit_value_t & sh) { return (sh.second.children()->parent() == sh.first); } @@ -685,7 +681,7 @@ public: */ Coface_simplex_range star_simplex_range(const Simplex_handle simplex) { - return coface_simplex_range(simplex, 0); + return cofaces_simplex_range(simplex, 0); } @@ -696,8 +692,8 @@ public: * \return Vector of Simplex_handle, empty vector if no cofaces found. */ - Coface_simplex_range coface_simplex_range(const Simplex_handle simplex, int codimension) { - std::vector cofaces; + Coface_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension) { + Coface_simplex_range cofaces; assert (codimension >= 0); // codimension must be positive or null integer Simplex_vertex_range rg = simplex_vertex_range(simplex); std::vector copy(rg.begin(), rg.end()); @@ -706,7 +702,7 @@ public: assert(std::is_sorted(copy.begin(), copy.end(), std::greater())); // must be sorted in decreasing order std::vector res; rec_coface(copy, &root_, res, cofaces, (int)copy.size(), codimension + (int)copy.size()); - return Coface_simplex_range(cofaces.begin(), cofaces.end()); + return cofaces; } diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 344cb009..968a67b3 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -179,7 +179,7 @@ void test_cofaces(typeST& st, std::vector v, int dim, std::vector if (dim == 0) cofaces = st.star_simplex_range(st.find(v)); else - cofaces = st.coface_simplex_range(st.find(v), dim); + cofaces = st.cofaces_simplex_range(st.find(v), dim); for (auto simplex = cofaces.begin(); simplex != cofaces.end(); ++simplex) { typeST::Simplex_vertex_range rg = st.simplex_vertex_range(*simplex); -- cgit v1.2.3 From 07faa8ef38b4ffe8c9e8e5e4e70717ff2500e08f Mon Sep 17 00:00:00 2001 From: anmoreau Date: Thu, 25 Jun 2015 11:39:49 +0000 Subject: fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@650 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ad75901b33f5037cbb8234b5179cea436a46b23b --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 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 4dee1432..47a96303 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -625,20 +625,19 @@ private: */ void rec_coface(std::vector &vertices, Siblings *curr_sib, std::vector &curr_res, std::vector& cofaces, int length, int nbVertices) { - if (!(nbVertices == length || (int)curr_res.size() <= nbVertices)) // dimension of actual simplex <= nbVertices + bool star = nbVertices == length; + if (!(star || (int)curr_res.size() <= nbVertices)) // dimension of actual simplex <= nbVertices return; -// for (auto simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) for (auto& simplex : curr_sib->members()) { if (vertices.empty()) { - // if ((int)curr_res.size() >= length && continueRecursion) // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface curr_res.push_back(simplex.first); - bool equalDim = (nbVertices == length || (int)curr_res.size() == nbVertices); // dimension of actual simplex == nbVertices - if (equalDim) + bool addCoface = (star || (int)curr_res.size() == nbVertices); // dimension of actual simplex == nbVertices + if (addCoface) cofaces.push_back(curr_sib->members().find(simplex.first)); - if (has_children(simplex)) + if ((!addCoface || star) && has_children(simplex)) // Rec call rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); curr_res.pop_back(); } @@ -648,10 +647,11 @@ private: { curr_res.push_back(simplex.first); bool equalDim = (nbVertices == length || (int)curr_res.size() == nbVertices); // dimension of actual simplex == nbVertices - if (vertices.size() == 1 && (int)curr_res.size() > length && equalDim) + bool addCoface = vertices.size() == 1 && (int)curr_res.size() > length && equalDim; + if (addCoface) cofaces.push_back(curr_sib->members().find(simplex.first)); - if (has_children(simplex)) - { // Rec call + if ((!addCoface || star) && has_children(simplex)) + { // Rec call Vertex_handle tmp = vertices.back(); vertices.pop_back(); rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); -- cgit v1.2.3 From 51127c161fc6fdaf7f8ec77a4a476faa6e219b52 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 26 Jun 2015 09:08:22 +0000 Subject: -Werror on user version compilation git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/gudhi_ci@656 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 54943d15cd2f0ec784fbf447485e637517bad32d --- src/Alpha_shapes/include/gudhi/Alpha_shapes.h | 2 +- .../include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h | 5 +++-- src/CMakeLists.txt | 4 +++- src/GudhUI/model/Model.h | 3 ++- src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp | 6 ++++-- 5 files changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h index b8efdb4d..deece712 100644 --- a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h +++ b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h @@ -171,7 +171,7 @@ class Alpha_shapes { /** \brief Returns the number of simplices in the complex. * * Does not count the empty simplex. */ - const unsigned int& num_simplices() const { + const unsigned int num_simplices() const { return _st.num_simplices(); } diff --git a/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h b/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h index 693b393e..b38ca4d6 100644 --- a/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h +++ b/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h @@ -190,15 +190,16 @@ class Delaunay_triangulation_off_writer { } // Finite cells list - for (auto cit = save_complex.finite_full_cells_begin(); cit != save_complex.finite_full_cells_end(); ++cit) { + /*for (auto cit = save_complex.finite_full_cells_begin(); cit != save_complex.finite_full_cells_end(); ++cit) { stream << std::distance(cit->vertices_begin(), cit->vertices_end()) << " "; // Dimension for (auto vit = cit->vertices_begin(); vit != cit->vertices_end(); ++vit) { auto vertexHdl = *vit; + std::cout << // auto vertexHdl = std::distance(save_complex.vertices_begin(), *vit) - 1; // stream << std::distance(save_complex.vertices_begin(), *(vit)) - 1 << " "; } stream << std::endl; - } + }*/ stream.close(); } else { std::cerr << "could not open file " << name_file << std::endl; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3be05c4f..7869bc4b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,9 @@ 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") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wpedantic -Wsign-compare -Werror") + 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) diff --git a/src/GudhUI/model/Model.h b/src/GudhUI/model/Model.h index 87545989..17a7d278 100644 --- a/src/GudhUI/model/Model.h +++ b/src/GudhUI/model/Model.h @@ -315,7 +315,8 @@ private: void run_chomp(){ save_complex_in_file_for_chomp(); std::cout << "Call CHOMP library\n"; - system("utils/homsimpl chomp.sim"); + int returnValue = system("utils/homsimpl chomp.sim"); + std::cout << "CHOMP returns" << returnValue << std::endl; } void save_complex_in_file_for_chomp(){ diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp index 92fa17f3..126e32ec 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp @@ -64,8 +64,10 @@ int main (int argc, char *argv[]){ // or edges, complex.num_vertices() and complex.num_edges() are // more appropriated! unsigned num_vertices = 0; - for(auto v : complex.vertex_range()) - ++num_vertices; + for(auto v : complex.vertex_range()) { + std::cout << "Vertex " << v < Date: Tue, 30 Jun 2015 09:36:11 +0000 Subject: clang requires include fstream (Persistent_cohomology.h) clang build fails if include guard macro are not correctly defined + goole style fix (Skeleton_blockers_simplices_iterators.h) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/compil_fix@665 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4bbc74ac4726af768816c322bf77e104a1dcf1e6 --- .../include/gudhi/Persistent_cohomology.h | 1 + .../Skeleton_blockers_simplices_iterators.h | 585 ++++++++++----------- 2 files changed, 276 insertions(+), 310 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 b0d68f09..8bd265d8 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -37,6 +37,7 @@ #include #include #include +#include // std::ofstream namespace Gudhi { 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 666ce430..f9d4d072 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 @@ -1,46 +1,42 @@ - /* 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 . - */ -#ifndef GUDHI_KELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ +/* 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 . + */ +#ifndef GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ #define GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ +#include "boost/iterator/iterator_facade.hpp" + #include #include #include -#include "gudhi/Utils.h" -#include "boost/iterator/iterator_facade.hpp" - #include "gudhi/Skeleton_blocker_link_complex.h" #include "gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h" - #include "gudhi/Skeleton_blocker/internal/Trie.h" - +#include "gudhi/Utils.h" namespace Gudhi { - namespace skbl { - /** * Link may be Skeleton_blocker_link_complex to iterate over all * simplices around a vertex OR @@ -49,299 +45,268 @@ namespace skbl { * The iteration is done by computing a trie with the link and doing a breadth-first traversal * of the trie. */ -template +template class Simplex_around_vertex_iterator : - public boost::iterator_facade < Simplex_around_vertex_iterator +public boost::iterator_facade < Simplex_around_vertex_iterator , typename SkeletonBlockerComplex::Simplex_handle , boost::forward_traversal_tag , typename SkeletonBlockerComplex::Simplex_handle -> -{ - 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 Link::Vertex_handle Link_vertex_handle; - // Link_vertex_handle == Complex_Vertex_handle but this renaming helps avoiding confusion - - typedef typename Gudhi::skbl::Trie Trie; - - -private: - const Complex* complex; - Vertex_handle v; - std::shared_ptr link_v; - std::shared_ptr trie; - std::list nodes_to_be_seen; // todo deque - -public: - Simplex_around_vertex_iterator():complex(0){ - } - - Simplex_around_vertex_iterator(const Complex* complex_,Vertex_handle v_): - complex(complex_), - v(v_), - link_v(new Link(*complex_,v_)), - trie(new Trie(v_)){ - compute_trie_and_nodes_to_be_seen(); - } - - // todo avoid useless copy - // todo currently just work if copy begin iterator - Simplex_around_vertex_iterator(const Simplex_around_vertex_iterator& other): - complex(other.complex), - v(other.v), - link_v(other.link_v), - trie(other.trie), - nodes_to_be_seen(other.nodes_to_be_seen){ - if(!other.is_end()){ - } - } - - /** - * returns an iterator to the end - */ - Simplex_around_vertex_iterator(const Complex* complex_,Vertex_handle v_,bool end): - complex(complex_), - v(v_){ - set_end(); - } - -private: - - - void compute_trie_and_nodes_to_be_seen(){ - // once we go through every simplices passing through v0 - // we remove v0. That way, it prevents from passing a lot of times - // though edges leaving v0. - // another solution would have been to provides an adjacency iterator - // to superior vertices that avoids lower ones. - while(!link_v->empty()){ - auto v0 = *(link_v->vertex_range().begin()); - trie->add_child(build_trie(v0,trie.get())); - link_v->remove_vertex(v0); - } - nodes_to_be_seen.push_back(trie.get()); - } - - Trie* build_trie(Link_vertex_handle link_vh,Trie* parent){ - Trie* res = new Trie(parent_vertex(link_vh),parent); - for(Link_vertex_handle nv : link_v->vertex_range(link_vh)) { - if(link_vh < nv){ - Simplex_handle 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)); - } - } - } - return res; - } - - bool is_node_in_complex(Trie* trie){ - return true; - } - - Vertex_handle parent_vertex(Link_vertex_handle link_vh) const{ - return complex->convert_handle_from_another_complex(*link_v,link_vh); - } - - - -public: - - friend std::ostream& operator<<(std::ostream& stream, const Simplex_around_vertex_iterator& savi){ - stream<< savi.trie<< std::endl; ; - stream << "("<childs){ - nodes_to_be_seen.push_back(childs.get()); - } - - } - - Simplex_handle dereference() const{ - assert(!nodes_to_be_seen.empty()); - Trie* first_node = nodes_to_be_seen.front(); - return first_node->simplex(); - } - -//private: - Simplex_handle get_trie_address() const{ - assert(!nodes_to_be_seen.empty()); - return nodes_to_be_seen.front(); - } - -private: - void set_end(){ - nodes_to_be_seen.clear(); - } - - bool is_end() const{ - return nodes_to_be_seen.empty(); - } +> { + 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; + + // 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; + + private: + const Complex* complex; + Vertex_handle v; + std::shared_ptr link_v; + std::shared_ptr trie; + std::list nodes_to_be_seen; // todo deque + + public: + Simplex_around_vertex_iterator() : complex(0) {} + + Simplex_around_vertex_iterator(const Complex* complex_, Vertex_handle v_) : + complex(complex_), + v(v_), + link_v(new Link(*complex_, v_)), + trie(new Trie(v_)) { + compute_trie_and_nodes_to_be_seen(); + } + + // todo avoid useless copy + // todo currently just work if copy begin iterator + Simplex_around_vertex_iterator(const Simplex_around_vertex_iterator& other) : + complex(other.complex), + v(other.v), + link_v(other.link_v), + trie(other.trie), + nodes_to_be_seen(other.nodes_to_be_seen) { + if (!other.is_end()) {} + } + + /** + * returns an iterator to the end + */ + Simplex_around_vertex_iterator(const Complex* complex_, Vertex_handle v_, bool end) : + complex(complex_), + v(v_) { + set_end(); + } + + private: + void compute_trie_and_nodes_to_be_seen() { + // once we go through every simplices passing through v0 + // we remove v0. That way, it prevents from passing a lot of times + // though edges leaving v0. + // another solution would have been to provides an adjacency iterator + // to superior vertices that avoids lower ones. + while (!link_v->empty()) { + auto v0 = *(link_v->vertex_range().begin()); + trie->add_child(build_trie(v0, trie.get())); + link_v->remove_vertex(v0); + } + nodes_to_be_seen.push_back(trie.get()); + } + + Trie* build_trie(Link_vertex_handle link_vh, Trie* parent) { + Trie* res = new Trie(parent_vertex(link_vh), parent); + for (Link_vertex_handle nv : link_v->vertex_range(link_vh)) { + if (link_vh < nv) { + Simplex_handle 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)); + } + } + } + return res; + } + + bool is_node_in_complex(Trie* trie) { + return true; + } + + Vertex_handle parent_vertex(Link_vertex_handle link_vh) const { + return complex->convert_handle_from_another_complex(*link_v, link_vh); + } + + public: + friend std::ostream& operator<<(std::ostream& stream, const Simplex_around_vertex_iterator& savi) { + stream << savi.trie << std::endl; + stream << "(" << savi.nodes_to_be_seen.size() << ") nodes to see\n"; + return stream; + } + + bool equal(const Simplex_around_vertex_iterator& other) const { + bool same_complex = (complex == other.complex); + if (!same_complex) + return false; + + if (!(v == other.v)) + return false; + + bool both_empty = nodes_to_be_seen.empty() && other.nodes_to_be_seen.empty(); + if (both_empty) + return true; + + bool both_non_empty = !nodes_to_be_seen.empty() && !other.nodes_to_be_seen.empty(); + + if (!both_non_empty) return false; //one is empty the other is not + + bool same_node = (**(nodes_to_be_seen.begin()) == **(other.nodes_to_be_seen.begin())); + return same_node; + } + + void increment() { + assert(!is_end()); + Trie* first_node = nodes_to_be_seen.front(); + + nodes_to_be_seen.pop_front(); + + for (auto childs : first_node->childs) { + nodes_to_be_seen.push_back(childs.get()); + } + + } + + Simplex_handle dereference() const { + assert(!nodes_to_be_seen.empty()); + Trie* first_node = nodes_to_be_seen.front(); + return first_node->simplex(); + } + + Simplex_handle get_trie_address() const { + assert(!nodes_to_be_seen.empty()); + return nodes_to_be_seen.front(); + } + + private: + void set_end() { + nodes_to_be_seen.clear(); + } + + bool is_end() const { + return nodes_to_be_seen.empty(); + } }; - - template class Simplex_iterator : - public boost::iterator_facade < Simplex_iterator +public boost::iterator_facade < Simplex_iterator , typename SkeletonBlockerComplex::Simplex_handle , boost::forward_traversal_tag , typename SkeletonBlockerComplex::Simplex_handle -> -{ - typedef Skeleton_blocker_link_superior Link; - - friend class boost::iterator_core_access; - - template friend class Skeleton_blocker_complex; - - - 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::Complex_vertex_iterator Complex_vertex_iterator; - - - typedef typename Link::Vertex_handle Link_vertex_handle; - -private: - - const Complex* complex_; - Complex_vertex_iterator current_vertex_; - - typedef Simplex_around_vertex_iterator SAVI; - SAVI current_simplex_around_current_vertex_; - SAVI simplices_around_current_vertex_end_; - - -public: - Simplex_iterator():complex_(0){} - - // should not be called if the complex is empty - Simplex_iterator(const Complex* complex): - complex_(complex), - current_vertex_(complex->vertex_range().begin()), - current_simplex_around_current_vertex_(complex,*current_vertex_), - simplices_around_current_vertex_end_(complex,*current_vertex_,true) - { - assert(!complex->empty()); - } - -private: - // todo return to private - Simplex_iterator(const Complex* complex,bool end): - complex_(complex) - { - set_end(); - } - -public: - - Simplex_iterator(const Simplex_iterator& other) - : - complex_(other.complex_), - current_vertex_(other.current_vertex_), - current_simplex_around_current_vertex_(other.current_simplex_around_current_vertex_), - simplices_around_current_vertex_end_(other.simplices_around_current_vertex_end_) - { - } - - friend Simplex_iterator make_begin_iterator(const Complex* complex){ - if(complex->empty()) - return make_end_simplex_iterator(complex); - else - return Simplex_iterator(complex); - } - - friend Simplex_iterator make_end_simplex_iterator(const Complex* complex){ - return Simplex_iterator(complex,true); - } - - bool equal(const Simplex_iterator& other) const{ - if(complex_!=other.complex_) return false; - if(current_vertex_!=other.current_vertex_) return false; - if(is_end() && other.is_end()) return true; - if(current_simplex_around_current_vertex_ != other.current_simplex_around_current_vertex_) - return false; - return true; - } - - void increment(){ - if(current_simplex_around_current_vertex_!= simplices_around_current_vertex_end_){ - current_simplex_around_current_vertex_.increment(); - if( current_simplex_around_current_vertex_== simplices_around_current_vertex_end_) - goto_next_vertex(); - } - else{ - goto_next_vertex(); - } - } - - void goto_next_vertex(){ - current_vertex_.increment(); - if(!is_end()){ - current_simplex_around_current_vertex_= SAVI(complex_,*current_vertex_); - simplices_around_current_vertex_end_ = SAVI(complex_,*current_vertex_,true); - } - } - - Simplex_handle dereference() const{ - return current_simplex_around_current_vertex_.dereference(); - } - -private: - void set_end(){ - current_vertex_ = complex_->vertex_range().end(); - } - - bool is_end() const{ - return (current_vertex_ == complex_->vertex_range().end()); - } +> { + typedef Skeleton_blocker_link_superior Link; + + friend class boost::iterator_core_access; + + template friend class Skeleton_blocker_complex; + + 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::Complex_vertex_iterator Complex_vertex_iterator; + typedef typename Link::Vertex_handle Link_vertex_handle; + + private: + const Complex* complex_; + Complex_vertex_iterator current_vertex_; + + typedef Simplex_around_vertex_iterator SAVI; + SAVI current_simplex_around_current_vertex_; + SAVI simplices_around_current_vertex_end_; + + public: + Simplex_iterator() : complex_(0) { } + + Simplex_iterator(const Complex* complex) : + complex_(complex), + current_vertex_(complex->vertex_range().begin()), + current_simplex_around_current_vertex_(complex, *current_vertex_), + simplices_around_current_vertex_end_(complex, *current_vertex_, true) { + // should not be called if the complex is empty + assert(!complex->empty()); + } + + private: + // todo return to private + Simplex_iterator(const Complex* complex, bool end) : + complex_(complex) { + set_end(); + } + + public: + Simplex_iterator(const Simplex_iterator& other) + : + complex_(other.complex_), + current_vertex_(other.current_vertex_), + current_simplex_around_current_vertex_(other.current_simplex_around_current_vertex_), + simplices_around_current_vertex_end_(other.simplices_around_current_vertex_end_) { } + + friend Simplex_iterator make_begin_iterator(const Complex* complex) { + if (complex->empty()) + return make_end_simplex_iterator(complex); + else + return Simplex_iterator(complex); + } + + friend Simplex_iterator make_end_simplex_iterator(const Complex* complex) { + return Simplex_iterator(complex, true); + } + + bool equal(const Simplex_iterator& other) const { + if (complex_ != other.complex_) return false; + if (current_vertex_ != other.current_vertex_) return false; + if (is_end() && other.is_end()) return true; + if (current_simplex_around_current_vertex_ != other.current_simplex_around_current_vertex_) + return false; + return true; + } + + void increment() { + if (current_simplex_around_current_vertex_ != simplices_around_current_vertex_end_) { + current_simplex_around_current_vertex_.increment(); + if (current_simplex_around_current_vertex_ == simplices_around_current_vertex_end_) + goto_next_vertex(); + } else { + goto_next_vertex(); + } + } + + void goto_next_vertex() { + current_vertex_.increment(); + if (!is_end()) { + current_simplex_around_current_vertex_ = SAVI(complex_, *current_vertex_); + simplices_around_current_vertex_end_ = SAVI(complex_, *current_vertex_, true); + } + } + + Simplex_handle dereference() const { + return current_simplex_around_current_vertex_.dereference(); + } + + private: + void set_end() { + current_vertex_ = complex_->vertex_range().end(); + } + + bool is_end() const { + return (current_vertex_ == complex_->vertex_range().end()); + } }; +} // namespace skbl -} - -} // namespace GUDHI - - - - +} // namespace Gudhi -#endif /* SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ */ +#endif // GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ -- cgit v1.2.3 From ed7051a54f1a1320ddbf99893662f146ef791934 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 30 Jun 2015 11:48:48 +0000 Subject: for_each fix - clang issue but not used. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/compil_fix@666 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 6eb72f54de768bbc00410ef88b77a4009e9b9882 --- .../include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') 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 10d64e98..0a2fcb9a 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 @@ -69,7 +69,9 @@ class Skeleton_blocker_simplex { } Skeleton_blocker_simplex(std::initializer_list& list) { - for_each(list.begin(), list.end(), add_vertex); + std::for_each(list.begin(), list.end(), [&] (T const& elt) { + add_vertex(elt); + }); } template -- cgit v1.2.3 From 5a9dee66373ff67ef1f3ecc13f57e3ce449ba921 Mon Sep 17 00:00:00 2001 From: anmoreau Date: Tue, 30 Jun 2015 17:11:21 +0000 Subject: fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@670 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 37d77e33cbff77414eea51e4ff91c865f6707850 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 44 +++++++++++++----------- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 2 +- 2 files changed, 24 insertions(+), 22 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 47a96303..b9723c04 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -157,7 +157,7 @@ class Simplex_tree { /** \brief Range over the vertices of a simplex. */ typedef boost::iterator_range Simplex_vertex_range; /** \brief Range over the cofaces of a simplex. */ - typedef std::vector Coface_simplex_range; + typedef std::vector Cofaces_simplex_range; /** \brief Iterator over the simplices of the boundary of a simplex. * * 'value_type' is Simplex_handle. */ @@ -391,12 +391,15 @@ class Simplex_tree { return (sh->second.children()->parent() == sh->first); } + private: /** \brief Returns true iff the node in the simplex tree pointed by * sh has children.*/ bool has_children(Dit_value_t & sh) { return (sh.second.children()->parent() == sh.first); } + public: + /** \brief Given a range of Vertex_handles, returns the Simplex_handle * of the simplex in the simplicial complex containing the corresponding * vertices. Return null_simplex() if the simplex is not in the complex. @@ -614,40 +617,40 @@ private: /** Recursive search of cofaces * This function uses DFS - *\param vertices contains a list of vertices, which represent the simplex. - *\param curr_res contains a list of vertices, which represent the current path in the tree. + *\param vertices contains a list of vertices, which represent the vertices of the simplex not found yet. + *\param curr_res represents the number of vertices of the simplex found. *\param cofaces contains a list of Simplex_handle, representing all the cofaces asked. - *\param length length of the vertex list "vertices" + *\param length number of vertices in the Simplex_handle of which we search the cofaces. * Prefix actions : When the bottom vertex matches with the current vertex in the tree, we remove the bottom vertex from vertices. * Infix actions : Then we call or not the recursion. * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_res so that we didn't change the parameters. * If the vertices list is empty, we need to check if the size of the curr_res list matches with the dimension of the cofaces asked. */ - void rec_coface(std::vector &vertices, Siblings *curr_sib, std::vector &curr_res, std::vector& cofaces, int length, int nbVertices) + void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_res, std::vector& cofaces, int length, int nbVertices) { bool star = nbVertices == length; - if (!(star || (int)curr_res.size() <= nbVertices)) // dimension of actual simplex <= nbVertices + if (!(star || curr_res <= nbVertices)) // dimension of actual simplex <= nbVertices return; for (auto& simplex : curr_sib->members()) { if (vertices.empty()) { // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface - curr_res.push_back(simplex.first); - bool addCoface = (star || (int)curr_res.size() == nbVertices); // dimension of actual simplex == nbVertices + curr_res++; + bool addCoface = (star || curr_res == nbVertices); // dimension of actual simplex == nbVertices if (addCoface) cofaces.push_back(curr_sib->members().find(simplex.first)); if ((!addCoface || star) && has_children(simplex)) // Rec call rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); - curr_res.pop_back(); + curr_res--; } else { if (simplex.first == vertices.back()) // If curr_sib matches with the top vertex { - curr_res.push_back(simplex.first); - bool equalDim = (nbVertices == length || (int)curr_res.size() == nbVertices); // dimension of actual simplex == nbVertices - bool addCoface = vertices.size() == 1 && (int)curr_res.size() > length && equalDim; + curr_res++; + bool equalDim = (nbVertices == length || curr_res == nbVertices); // dimension of actual simplex == nbVertices + bool addCoface = vertices.size() == 1 && curr_res > length && equalDim; if (addCoface) cofaces.push_back(curr_sib->members().find(simplex.first)); if ((!addCoface || star) && has_children(simplex)) @@ -657,7 +660,7 @@ private: rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); vertices.push_back(tmp); } - curr_res.pop_back(); + curr_res--; } else if (simplex.first > vertices.back()) return; @@ -665,9 +668,9 @@ private: { if (has_children(simplex)) { - curr_res.push_back(simplex.first); + curr_res++; rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); - curr_res.pop_back(); + curr_res--; } } } @@ -680,7 +683,7 @@ public: * \return Vector of Simplex_handle, empty vector if no cofaces found. */ - Coface_simplex_range star_simplex_range(const Simplex_handle simplex) { + Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex) { return cofaces_simplex_range(simplex, 0); } @@ -692,16 +695,15 @@ public: * \return Vector of Simplex_handle, empty vector if no cofaces found. */ - Coface_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension) { - Coface_simplex_range cofaces; + Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension) { + Cofaces_simplex_range cofaces; assert (codimension >= 0); // codimension must be positive or null integer Simplex_vertex_range rg = simplex_vertex_range(simplex); std::vector copy(rg.begin(), rg.end()); if (codimension + (int)copy.size() > dimension_ + 1 || (codimension == 0 && (int)copy.size() > dimension_) ) // n+codimension greater than dimension_ - return Coface_simplex_range(cofaces.begin(), cofaces.end()); + return cofaces; assert(std::is_sorted(copy.begin(), copy.end(), std::greater())); // must be sorted in decreasing order - std::vector res; - rec_coface(copy, &root_, res, cofaces, (int)copy.size(), codimension + (int)copy.size()); + rec_coface(copy, &root_, 0, cofaces, (int)copy.size(), codimension + (int)copy.size()); return cofaces; } diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 968a67b3..a6328663 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -175,7 +175,7 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons } void test_cofaces(typeST& st, std::vector v, int dim, std::vector res) { - typeST::Coface_simplex_range cofaces; + typeST::Cofaces_simplex_range cofaces; if (dim == 0) cofaces = st.star_simplex_range(st.find(v)); else -- cgit v1.2.3 From 66d91feb5c6491b24e0765af777e35162e4cdc31 Mon Sep 17 00:00:00 2001 From: salinasd Date: Sat, 4 Jul 2015 15:41:57 +0000 Subject: Fix skbl compiling issue on clang + one issue of returning a local reference in Alpha_shapes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/compil_fix@677 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b14047d0df46ea255bb801191c6672aa06eab3c7 --- src/Alpha_shapes/include/gudhi/Alpha_shapes.h | 2 +- .../example/Garland_heckbert/Error_quadric.h | 2 +- src/GudhUI/CMakeLists.txt | 3 +- .../Skeleton_blocker/Skeleton_blocker_off_io.h | 2 +- .../gudhi/Skeleton_blocker_geometric_complex.h | 34 ++++++++++++++-------- 5 files changed, 27 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h index b8efdb4d..ae2ee80d 100644 --- a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h +++ b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h @@ -171,7 +171,7 @@ class Alpha_shapes { /** \brief Returns the number of simplices in the complex. * * Does not count the empty simplex. */ - const unsigned int& num_simplices() const { + unsigned num_simplices() const { return _st.num_simplices(); } diff --git a/src/Contraction/example/Garland_heckbert/Error_quadric.h b/src/Contraction/example/Garland_heckbert/Error_quadric.h index 725a3a56..72134c9d 100644 --- a/src/Contraction/example/Garland_heckbert/Error_quadric.h +++ b/src/Contraction/example/Garland_heckbert/Error_quadric.h @@ -122,7 +122,7 @@ public : * Return the point such that it minimizes the gradient of the quadric. * Det must be passed with the determinant value of the gradient (should be non zero). */ - inline Point solve_linear_gradient(double det = grad_determinant()) const{ + inline Point solve_linear_gradient(double det) const{ return Point({ (-coeff[1]*coeff[5]*coeff[8]+coeff[1]*coeff[7]*coeff[6]+coeff[2]*coeff[8]*coeff[4]-coeff[2]*coeff[5]*coeff[6]-coeff[3]*coeff[4]*coeff[7]+coeff[3]*coeff[5]*coeff[5])/ det, (coeff[0]*coeff[5]*coeff[8]-coeff[0]*coeff[7]*coeff[6]-coeff[5]*coeff[2]*coeff[3]-coeff[1]*coeff[2]*coeff[8]+coeff[6]*coeff[2]*coeff[2]+coeff[1]*coeff[3]*coeff[7])/det, diff --git a/src/GudhUI/CMakeLists.txt b/src/GudhUI/CMakeLists.txt index ddbae969..9348868a 100644 --- a/src/GudhUI/CMakeLists.txt +++ b/src/GudhUI/CMakeLists.txt @@ -5,6 +5,7 @@ find_package(CGAL COMPONENTS Qt4) find_package(Qt4) find_package(QGLViewer) find_package(OpenGL) + message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}") message("CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}") message("CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}") @@ -66,5 +67,5 @@ if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) target_link_libraries( GudhUI ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) else() - message(STATUS "NOTICE: This demo requires CGAL, the QGLViewer, OpenGL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: GudhUI requires CGAL, the QGLViewer, OpenGL and Qt4, and will not be compiled.") endif() 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 aaaab8b0..6ad1fdd3 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 @@ -107,7 +107,7 @@ class Skeleton_blocker_off_visitor_reader { } void done() { - complex_ = make_complex_from_top_faces(maximal_faces_.begin(), maximal_faces_.end(), + complex_ = make_complex_from_top_faces(maximal_faces_.begin(), maximal_faces_.end(), points_.begin(), points_.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 437482cb..8cea123a 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h @@ -79,22 +79,13 @@ public Skeleton_blocker_complex { (*this)[Vertex_handle(current++)].point() = Point(point->begin(), point->end()); } - template - friend Skeleton_blocker_geometric_complex make_complex_from_top_faces( + template + SkeletonBlockerGeometricComplex make_complex_from_top_faces( SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end, PointIterator points_begin, PointIterator points_end, - bool is_flag_complex = false) { - Skeleton_blocker_geometric_complex complex; - unsigned current = 0; - complex = - make_complex_from_top_faces(simplex_begin, simplex_end, is_flag_complex); - for (auto point = points_begin; point != points_end; ++point) - // complex.point(Vertex_handle(current++)) = Point(point->begin(),point->end()); - complex.point(Vertex_handle(current++)) = Point(*point); - return complex; - } + bool is_flag_complex); /** * @brief Constructor with a list of simplices. @@ -215,6 +206,25 @@ public Skeleton_blocker_complex { } }; + +template +SkeletonBlockerGeometricComplex make_complex_from_top_faces( + SimpleHandleOutputIterator simplex_begin, + SimpleHandleOutputIterator simplex_end, + PointIterator points_begin, + PointIterator points_end, + bool is_flag_complex = false) { + typedef SkeletonBlockerGeometricComplex SBGC; + SkeletonBlockerGeometricComplex complex; + unsigned current = 0; + complex = + make_complex_from_top_faces(simplex_begin, simplex_end, is_flag_complex); + for (auto point = points_begin; point != points_end; ++point) + // complex.point(Vertex_handle(current++)) = Point(point->begin(),point->end()); + complex.point(typename SBGC::Vertex_handle(current++)) = typename SBGC::Point(*point); + return complex; +} + } // namespace skbl } // namespace Gudhi -- cgit v1.2.3 From c8c2f91db880218bb7ab275fbadda53a23f88d35 Mon Sep 17 00:00:00 2001 From: glisse Date: Sun, 5 Jul 2015 16:55:58 +0000 Subject: Typo + comment out debug printing git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@678 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 896977355b7928fa20f5e85ec9eb2bb920a9ad90 --- src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h | 2 +- .../include/gudhi/Skeleton_blocker_simplifiable_complex.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h index 049db6d5..289819b5 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h @@ -109,7 +109,7 @@ and point access in addition. \subsection Visitor The class Skeleton_blocker_complex has a visitor that is called when usual operations such as adding an edge or remove a vertex are called. -You may want to use this visitor to compute statistics or to update another data-structure (for instance this visitor is heavily used in the \ref contr package. +You may want to use this visitor to compute statistics or to update another data-structure (for instance this visitor is heavily used in the \ref contr package). 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 86a12d90..dd8d898e 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -223,7 +223,7 @@ void Skeleton_blocker_complex::add_simplex(const Simplex_hand 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; + // std::cout << "add edge" << *u_it << " " << *v_it << std::endl; add_edge(*u_it, *v_it); } remove_blocker_include_in_simplex(sigma); -- cgit v1.2.3 From d37567802b2ca616ce3029e29972d450863a4946 Mon Sep 17 00:00:00 2001 From: salinasd Date: Sun, 5 Jul 2015 18:30:38 +0000 Subject: Suppression d'une declaration inutile dans skbl geometric git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/compil_fix@679 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3057def5d61e468d9cb3061234279df8ec96df52 --- .../include/gudhi/Skeleton_blocker_geometric_complex.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src') 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 8cea123a..3eff1ba3 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h @@ -79,14 +79,6 @@ public Skeleton_blocker_complex { (*this)[Vertex_handle(current++)].point() = Point(point->begin(), point->end()); } - template - SkeletonBlockerGeometricComplex make_complex_from_top_faces( - SimpleHandleOutputIterator simplex_begin, - SimpleHandleOutputIterator simplex_end, - PointIterator points_begin, - PointIterator points_end, - bool is_flag_complex); - /** * @brief Constructor with a list of simplices. * Points of every vertex are the point constructed with default constructor. -- cgit v1.2.3 From 6930f8cebfbea8678603bc55e4eea293d2e3e902 Mon Sep 17 00:00:00 2001 From: anmoreau Date: Mon, 6 Jul 2015 15:19:18 +0000 Subject: Fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@682 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e9d8b582ff8b566596daea71760f683443e8a329 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 34 ++++++++++----------------- 1 file changed, 13 insertions(+), 21 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 b9723c04..cb189d76 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -391,13 +391,6 @@ class Simplex_tree { return (sh->second.children()->parent() == sh->first); } - private: - /** \brief Returns true iff the node in the simplex tree pointed by - * sh has children.*/ - bool has_children(Dit_value_t & sh) { - return (sh.second.children()->parent() == sh.first); - } - public: /** \brief Given a range of Vertex_handles, returns the Simplex_handle @@ -621,55 +614,54 @@ private: *\param curr_res represents the number of vertices of the simplex found. *\param cofaces contains a list of Simplex_handle, representing all the cofaces asked. *\param length number of vertices in the Simplex_handle of which we search the cofaces. + *\param nbVertices number of vertices of the cofaces we search * Prefix actions : When the bottom vertex matches with the current vertex in the tree, we remove the bottom vertex from vertices. * Infix actions : Then we call or not the recursion. * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_res so that we didn't change the parameters. - * If the vertices list is empty, we need to check if the size of the curr_res list matches with the dimension of the cofaces asked. + * If the vertices list is empty, we need to check if curr_res matches with the dimension of the cofaces asked. */ void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_res, std::vector& cofaces, int length, int nbVertices) { bool star = nbVertices == length; if (!(star || curr_res <= nbVertices)) // dimension of actual simplex <= nbVertices return; - for (auto& simplex : curr_sib->members()) + curr_res++; + for (Simplex_handle simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) { if (vertices.empty()) { // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface - curr_res++; bool addCoface = (star || curr_res == nbVertices); // dimension of actual simplex == nbVertices if (addCoface) - cofaces.push_back(curr_sib->members().find(simplex.first)); + cofaces.push_back(simplex); if ((!addCoface || star) && has_children(simplex)) // Rec call - rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); + rec_coface(vertices, simplex->second.children(), curr_res, cofaces, length, nbVertices); curr_res--; } else { - if (simplex.first == vertices.back()) // If curr_sib matches with the top vertex + if (simplex->first == vertices.back()) // If curr_sib matches with the top vertex { - curr_res++; - bool equalDim = (nbVertices == length || curr_res == nbVertices); // dimension of actual simplex == nbVertices + bool equalDim = (star || curr_res == nbVertices); // dimension of actual simplex == nbVertices bool addCoface = vertices.size() == 1 && curr_res > length && equalDim; if (addCoface) - cofaces.push_back(curr_sib->members().find(simplex.first)); + cofaces.push_back(simplex); if ((!addCoface || star) && has_children(simplex)) { // Rec call Vertex_handle tmp = vertices.back(); vertices.pop_back(); - rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); + rec_coface(vertices, simplex->second.children(), curr_res, cofaces, length, nbVertices); vertices.push_back(tmp); } curr_res--; } - else if (simplex.first > vertices.back()) + else if (simplex->first > vertices.back()) return; - else // (simplex.first < vertices.back() + else // (simplex->first < vertices.back() { if (has_children(simplex)) { - curr_res++; - rec_coface(vertices, simplex.second.children(), curr_res, cofaces, length, nbVertices); + rec_coface(vertices, simplex->second.children(), curr_res, cofaces, length, nbVertices); curr_res--; } } -- cgit v1.2.3 From 51192ba9c5991a4d232417dd49ce15a14b400599 Mon Sep 17 00:00:00 2001 From: anmoreau Date: Mon, 6 Jul 2015 15:22:36 +0000 Subject: Fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@683 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c15bed57474202a9bf05aabc7eb33ac1b3c32a41 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 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 cb189d76..f2b726f9 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -611,49 +611,49 @@ private: /** Recursive search of cofaces * This function uses DFS *\param vertices contains a list of vertices, which represent the vertices of the simplex not found yet. - *\param curr_res represents the number of vertices of the simplex found. + *\param curr_nbVertices represents the number of vertices of the simplex found. *\param cofaces contains a list of Simplex_handle, representing all the cofaces asked. *\param length number of vertices in the Simplex_handle of which we search the cofaces. *\param nbVertices number of vertices of the cofaces we search * Prefix actions : When the bottom vertex matches with the current vertex in the tree, we remove the bottom vertex from vertices. * Infix actions : Then we call or not the recursion. - * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_res so that we didn't change the parameters. - * If the vertices list is empty, we need to check if curr_res matches with the dimension of the cofaces asked. + * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_nbVertices so that we didn't change the parameters. + * If the vertices list is empty, we need to check if curr_nbVertices matches with the dimension of the cofaces asked. */ - void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_res, std::vector& cofaces, int length, int nbVertices) + void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_nbVertices, std::vector& cofaces, int length, int nbVertices) { bool star = nbVertices == length; - if (!(star || curr_res <= nbVertices)) // dimension of actual simplex <= nbVertices + if (!(star || curr_nbVertices <= nbVertices)) // dimension of actual simplex <= nbVertices return; - curr_res++; + curr_nbVertices++; for (Simplex_handle simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) { if (vertices.empty()) { // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface - bool addCoface = (star || curr_res == nbVertices); // dimension of actual simplex == nbVertices + bool addCoface = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices if (addCoface) cofaces.push_back(simplex); if ((!addCoface || star) && has_children(simplex)) // Rec call - rec_coface(vertices, simplex->second.children(), curr_res, cofaces, length, nbVertices); - curr_res--; + rec_coface(vertices, simplex->second.children(), curr_nbVertices, cofaces, length, nbVertices); + curr_nbVertices--; } else { if (simplex->first == vertices.back()) // If curr_sib matches with the top vertex { - bool equalDim = (star || curr_res == nbVertices); // dimension of actual simplex == nbVertices - bool addCoface = vertices.size() == 1 && curr_res > length && equalDim; + bool equalDim = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices + bool addCoface = vertices.size() == 1 && curr_nbVertices > length && equalDim; if (addCoface) cofaces.push_back(simplex); if ((!addCoface || star) && has_children(simplex)) { // Rec call Vertex_handle tmp = vertices.back(); vertices.pop_back(); - rec_coface(vertices, simplex->second.children(), curr_res, cofaces, length, nbVertices); + rec_coface(vertices, simplex->second.children(), curr_nbVertices, cofaces, length, nbVertices); vertices.push_back(tmp); } - curr_res--; + curr_nbVertices--; } else if (simplex->first > vertices.back()) return; @@ -661,8 +661,8 @@ private: { if (has_children(simplex)) { - rec_coface(vertices, simplex->second.children(), curr_res, cofaces, length, nbVertices); - curr_res--; + rec_coface(vertices, simplex->second.children(), curr_nbVertices, cofaces, length, nbVertices); + curr_nbVertices--; } } } -- cgit v1.2.3 From c1786d69f0c19768c15238189ad595f4a2e0e73a Mon Sep 17 00:00:00 2001 From: salinasd Date: Mon, 6 Jul 2015 18:54:34 +0000 Subject: skbl Marc comments git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/compil_fix@684 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b1ed33835e0bffcb1160a90a09cd583889da551e --- .../Skeleton_blocker/Skeleton_blocker_sub_complex.h | 16 +--------------- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 9 ++++++--- 2 files changed, 7 insertions(+), 18 deletions(-) (limited to 'src') 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 e906df75..40e26c68 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 @@ -75,25 +75,11 @@ class Skeleton_blocker_sub_complex : public ComplexType { typedef typename ComplexType::Root_simplex_handle Root_simplex_handle; protected: - ///** - //* @brief Returns true iff the simplex formed by all vertices contained in 'addresses_sigma_in_link' - //* but 'vertex_to_be_ignored' is in 'link' - //*/ - /* - template friend bool - proper_face_in_union( - Skeleton_blocker_sub_complex & link, - std::vector > & addresses_sigma_in_link, - int vertex_to_be_ignored);*/ - + /** * @brief Determines whether all proper faces of simplex 'sigma' belong to 'link1' \cup 'link2' * where 'link1' and 'link2' are subcomplexes of the same complex of type ComplexType */ - // template friend bool - // proper_faces_in_union(Skeleton_blocker_simplex & sigma, Skeleton_blocker_sub_complex & link1, Skeleton_blocker_sub_complex & link2){ - // template friend bool - // proper_faces_in_union(Skeleton_blocker_simplex & sigma, Skeleton_blocker_sub_complex & link1, Skeleton_blocker_sub_complex & link2); typedef std::map IdAddressMap; typedef typename IdAddressMap::value_type AddressPair; typedef typename IdAddressMap::iterator IdAddressMapIterator; 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 86a12d90..fa9741b7 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -208,7 +208,8 @@ void Skeleton_blocker_complex::remove_star(const Simplex_hand } /** - * @brief add a maximal simplex plus all its cofaces. + * @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 @@ -338,9 +339,11 @@ void Skeleton_blocker_complex::contract_edge(Vertex_handle a, Vertex_handle b) { assert(this->contains_vertex(a)); assert(this->contains_vertex(b)); - assert(this->contains_edge(a, b)); - // if some blockers passes through 'ab', we remove them. + if(this->contains_edge(a, b)) + this->add_edge(a, b); + + // if some blockers passes through 'ab', we need to remove them. if (!link_condition(a, b)) delete_blockers_around_edge(a, b); -- cgit v1.2.3 From 832a6b5d65d25514ce4bd6a7fb6bcaa37856cda3 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Jul 2015 07:39:29 +0000 Subject: Alpha_shapes removal. Alpha_complex will be added on feature delivery git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/compil_fix@685 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5e661587777dc5e07ae6ee42f2f5f207189c6a13 --- CMakeLists.txt | 3 - src/Alpha_shapes/example/CMakeLists.txt | 32 ---- .../example/Delaunay_triangulation_off_rw.cpp | 105 ---------- .../Simplex_tree_from_delaunay_triangulation.cpp | 103 ---------- src/Alpha_shapes/include/gudhi/Alpha_shapes.h | 200 ------------------- .../Alpha_shapes/Delaunay_triangulation_off_io.h | 213 --------------------- src/Alpha_shapes/test/Alpha_shapes_unit_test.cpp | 126 ------------ src/Alpha_shapes/test/CMakeLists.txt | 48 ----- src/Alpha_shapes/test/README | 14 -- src/Alpha_shapes/test/S4_100.off | 102 ---------- src/Alpha_shapes/test/S8_10.off | 12 -- src/CMakeLists.txt | 1 - 12 files changed, 959 deletions(-) delete mode 100644 src/Alpha_shapes/example/CMakeLists.txt delete mode 100644 src/Alpha_shapes/example/Delaunay_triangulation_off_rw.cpp delete mode 100644 src/Alpha_shapes/example/Simplex_tree_from_delaunay_triangulation.cpp delete mode 100644 src/Alpha_shapes/include/gudhi/Alpha_shapes.h delete mode 100644 src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h delete mode 100644 src/Alpha_shapes/test/Alpha_shapes_unit_test.cpp delete mode 100644 src/Alpha_shapes/test/CMakeLists.txt delete mode 100644 src/Alpha_shapes/test/README delete mode 100644 src/Alpha_shapes/test/S4_100.off delete mode 100644 src/Alpha_shapes/test/S8_10.off (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 02e0c614..7091eef6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,6 @@ else() message(STATUS "boost include dirs:" ${Boost_INCLUDE_DIRS}) include_directories(src/common/include/) - include_directories(src/Alpha_shapes/include/) include_directories(src/Bottleneck/include/) include_directories(src/Contraction/include/) include_directories(src/Hasse_complex/include/) @@ -73,8 +72,6 @@ else() add_subdirectory(src/Skeleton_blocker/example) add_subdirectory(src/Contraction/example) add_subdirectory(src/Hasse_complex/example) - add_subdirectory(src/Alpha_shapes/example) - add_subdirectory(src/Alpha_shapes/test) add_subdirectory(src/Bottleneck/example) add_subdirectory(src/Bottleneck/test) diff --git a/src/Alpha_shapes/example/CMakeLists.txt b/src/Alpha_shapes/example/CMakeLists.txt deleted file mode 100644 index 753238a5..00000000 --- a/src/Alpha_shapes/example/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -project(GUDHIAlphaShapesExample) - -# need CGAL 4.6 -# cmake -DCGAL_DIR=~/workspace/CGAL-4.6-beta1 ../../.. -if(CGAL_FOUND) - if (NOT CGAL_VERSION VERSION_LESS 4.6.0) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - - include( ${CGAL_USE_FILE} ) - - find_package(Eigen3 3.1.0) - if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") - - add_executable ( dtoffrw Delaunay_triangulation_off_rw.cpp ) - target_link_libraries(dtoffrw ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) - add_test(dtoffrw_tore3D ${CMAKE_CURRENT_BINARY_DIR}/dtoffrw ${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off 3) - - # uncomment to display debug traces - # add_definitions(-DDEBUG_TRACES) - add_executable ( stfromdt Simplex_tree_from_delaunay_triangulation.cpp ) - target_link_libraries(stfromdt ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for Alpha shapes feature.") - endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Alpha shapes feature. Version 4.6.0 is required.") - endif () -endif() diff --git a/src/Alpha_shapes/example/Delaunay_triangulation_off_rw.cpp b/src/Alpha_shapes/example/Delaunay_triangulation_off_rw.cpp deleted file mode 100644 index 03f6440d..00000000 --- a/src/Alpha_shapes/example/Delaunay_triangulation_off_rw.cpp +++ /dev/null @@ -1,105 +0,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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (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 . - */ - -// to construct a Delaunay_triangulation from a OFF file -#include "gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -// Use dynamic_dimension_tag for the user to be able to set dimension -typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > K; -typedef CGAL::Delaunay_triangulation T; -// The triangulation uses the default instanciation of the -// TriangulationDataStructure template parameter - -void usage(char * const progName) { - std::cerr << "Usage: " << progName << " filename.off dimension" << std::endl; - exit(-1); // ----- >> -} - -int main(int argc, char **argv) { - if (argc != 3) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct" << std::endl; - usage(argv[0]); - } - - int dimension = 0; - int returnedScanValue = sscanf(argv[2], "%d", &dimension); - if ((returnedScanValue == EOF) || (dimension <= 0)) { - std::cerr << "Error: " << argv[2] << " is not correct" << std::endl; - usage(argv[0]); - } - - T dt(dimension); - std::string offFileName(argv[1]); - Gudhi::alphashapes::Delaunay_triangulation_off_reader off_reader(offFileName, dt, true, true); - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offFileName << std::endl; - exit(-1); // ----- >> - } - - std::cout << "number of vertices=" << dt.number_of_vertices() << std::endl; - std::cout << "number of full cells=" << dt.number_of_full_cells() << std::endl; - std::cout << "number of finite full cells=" << dt.number_of_finite_full_cells() << std::endl; - - // Points list - /*for (T::Vertex_iterator vit = dt.vertices_begin(); vit != dt.vertices_end(); ++vit) { - for (auto Coord = vit->point().cartesian_begin(); Coord != vit->point().cartesian_end(); ++Coord) { - std::cout << *Coord << " "; - } - std::cout << std::endl; - } - std::cout << std::endl;*/ - - int i = 0, j = 0; - typedef T::Full_cell_iterator Full_cell_iterator; - typedef T::Facet Facet; - - for (Full_cell_iterator cit = dt.full_cells_begin(); cit != dt.full_cells_end(); ++cit) { - if (!dt.is_infinite(cit)) { - j++; - continue; - } - Facet fct(cit, cit->index(dt.infinite_vertex())); - i++; - } - std::cout << "There are " << i << " facets on the convex hull." << std::endl; - std::cout << "There are " << j << " facets not on the convex hull." << std::endl; - - - std::string offOutputFile("out.off"); - Gudhi::alphashapes::Delaunay_triangulation_off_writer off_writer(offOutputFile, dt); - - return 0; -} \ No newline at end of file diff --git a/src/Alpha_shapes/example/Simplex_tree_from_delaunay_triangulation.cpp b/src/Alpha_shapes/example/Simplex_tree_from_delaunay_triangulation.cpp deleted file mode 100644 index 3a17b519..00000000 --- a/src/Alpha_shapes/example/Simplex_tree_from_delaunay_triangulation.cpp +++ /dev/null @@ -1,103 +0,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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (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 . - */ - -// to construct a Delaunay_triangulation from a OFF file -#include "gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h" -#include "gudhi/Alpha_shapes.h" - -// to construct a simplex_tree from Delaunay_triangulation -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -// Use dynamic_dimension_tag for the user to be able to set dimension -typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > K; -typedef CGAL::Delaunay_triangulation T; -// The triangulation uses the default instanciation of the -// TriangulationDataStructure template parameter - -void usage(char * const progName) { - std::cerr << "Usage: " << progName << " filename.off dimension" << std::endl; - exit(-1); // ----- >> -} - -int main(int argc, char **argv) { - if (argc != 3) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct" << std::endl; - usage(argv[0]); - } - - int dimension = 0; - int returnedScanValue = sscanf(argv[2], "%d", &dimension); - if ((returnedScanValue == EOF) || (dimension <= 0)) { - std::cerr << "Error: " << argv[2] << " is not correct" << std::endl; - usage(argv[0]); - } - - // ---------------------------------------------------------------------------- - // - // Init of an alpha-shape from a Delaunay triangulation - // - // ---------------------------------------------------------------------------- - T dt(dimension); - std::string off_file_name(argv[1]); - - Gudhi::alphashapes::Delaunay_triangulation_off_reader off_reader(off_file_name, dt, false, false); - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << off_file_name << std::endl; - exit(-1); // ----- >> - } - - std::cout << "number of vertices=" << dt.number_of_vertices() << std::endl; - std::cout << "number of full cells=" << dt.number_of_full_cells() << std::endl; - std::cout << "number of finite full cells=" << dt.number_of_finite_full_cells() << std::endl; - - Gudhi::alphashapes::Alpha_shapes alpha_shapes_from_dt(dt); - //std::cout << alpha_shapes_from_dt << std::endl; - - // ---------------------------------------------------------------------------- - // - // Init of an alpha-shape from a OFF file - // - // ---------------------------------------------------------------------------- - Gudhi::alphashapes::Alpha_shapes alpha_shapes_from_file(off_file_name, dimension); - //std::cout << alpha_shapes_from_file << std::endl; - - std::cout << "alpha_shapes_from_file.dimension()=" << alpha_shapes_from_file.dimension() << std::endl; - std::cout << "alpha_shapes_from_file.filtration()=" << alpha_shapes_from_file.filtration() << std::endl; - std::cout << "alpha_shapes_from_file.num_simplices()=" << alpha_shapes_from_file.num_simplices() << std::endl; - std::cout << "alpha_shapes_from_file.num_vertices()=" << alpha_shapes_from_file.num_vertices() << std::endl; - - return 0; -} \ No newline at end of file diff --git a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h b/src/Alpha_shapes/include/gudhi/Alpha_shapes.h deleted file mode 100644 index ae2ee80d..00000000 --- a/src/Alpha_shapes/include/gudhi/Alpha_shapes.h +++ /dev/null @@ -1,200 +0,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): Vincent Rouvreau - * - * Copyright (C) 2015 INRIA Saclay (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 SRC_ALPHA_SHAPES_INCLUDE_GUDHI_ALPHA_SHAPES_H_ -#define SRC_ALPHA_SHAPES_INCLUDE_GUDHI_ALPHA_SHAPES_H_ - -// to construct a Delaunay_triangulation from a OFF file -#include - -// to construct a simplex_tree from Delaunay_triangulation -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace Gudhi { - -namespace alphashapes { - -/** \defgroup alpha_shapes Alpha shapes in dimension N - * -
Implementations:
- Alpha shapes in dimension N are a subset of Delaunay Triangulation in dimension N. - - - * \author Vincent Rouvreau - * \version 1.0 - * \date 2015 - * \copyright GNU General Public License v3. - * @{ - */ - -/** - * \brief Alpha shapes data structure. - * - * \details Every simplex \f$[v_0, \cdots ,v_d]\f$ admits a canonical orientation - * induced by the order relation on vertices \f$ v_0 < \cdots < v_d \f$. - * - * Details may be found in \cite boissonnatmariasimplextreealgorithmica. - * - * \implements FilteredComplex - * - */ -class Alpha_shapes { - private: - // From Simplex_tree - /** \brief Type required to insert into a simplex_tree (with or without subfaces).*/ - typedef std::vector typeVectorVertex; - - // From CGAL - /** \brief Kernel for the Delaunay_triangulation. - * Dimension can be set dynamically. - */ - typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Kernel; - /** \brief Delaunay_triangulation type required to create an alpha-shape. - */ - typedef CGAL::Delaunay_triangulation Delaunay_triangulation; - - private: - /** \brief Upper bound on the simplex tree of the simplicial complex.*/ - Gudhi::Simplex_tree<> _st; - - public: - - Alpha_shapes(std::string off_file_name, int dimension) { - Delaunay_triangulation dt(dimension); - Gudhi::alphashapes::Delaunay_triangulation_off_reader - off_reader(off_file_name, dt, true, true); - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << off_file_name << std::endl; - exit(-1); // ----- >> - } -#ifdef DEBUG_TRACES - std::cout << "number of vertices=" << dt.number_of_vertices() << std::endl; - std::cout << "number of full cells=" << dt.number_of_full_cells() << std::endl; - std::cout << "number of finite full cells=" << dt.number_of_finite_full_cells() << std::endl; -#endif // DEBUG_TRACES - init(dt); - } - - template - Alpha_shapes(T triangulation) { - init(triangulation); - } - - ~Alpha_shapes() { } - - private: - - template - void init(T triangulation) { - _st.set_dimension(triangulation.maximal_dimension()); - _st.set_filtration(0.0); - // triangulation points list - for (auto vit = triangulation.finite_vertices_begin(); - vit != triangulation.finite_vertices_end(); ++vit) { - typeVectorVertex vertexVector; - Vertex_handle vertexHdl = std::distance(triangulation.finite_vertices_begin(), vit); - vertexVector.push_back(vertexHdl); - - // Insert each point in the simplex tree - _st.insert_simplex(vertexVector, 0.0); - -#ifdef DEBUG_TRACES - std::cout << "P" << vertexHdl << ":"; - for (auto Coord = vit->point().cartesian_begin(); Coord != vit->point().cartesian_end(); ++Coord) { - std::cout << *Coord << " "; - } - std::cout << std::endl; -#endif // DEBUG_TRACES - } - // triangulation finite full cells list - for (auto cit = triangulation.finite_full_cells_begin(); - cit != triangulation.finite_full_cells_end(); ++cit) { - typeVectorVertex vertexVector; - for (auto vit = cit->vertices_begin(); vit != cit->vertices_end(); ++vit) { - // Vertex handle is distance - 1 - Vertex_handle vertexHdl = std::distance(triangulation.vertices_begin(), *vit) - 1; - vertexVector.push_back(vertexHdl); - } - // Insert each point in the simplex tree - _st.insert_simplex_and_subfaces(vertexVector, 0.0); - -#ifdef DEBUG_TRACES - std::cout << "C" << std::distance(triangulation.finite_full_cells_begin(), cit) << ":"; - for (auto value : vertexVector) { - std::cout << value << ' '; - } - std::cout << std::endl; -#endif // DEBUG_TRACES - } - } - - public: - - /** \brief Returns the number of vertices in the complex. */ - size_t num_vertices() { - return _st.num_vertices(); - } - - /** \brief Returns the number of simplices in the complex. - * - * Does not count the empty simplex. */ - unsigned num_simplices() const { - return _st.num_simplices(); - } - - /** \brief Returns an upper bound on the dimension of the simplicial complex. */ - int dimension() { - return _st.dimension(); - } - - /** \brief Returns an upper bound of the filtration values of the simplices. */ - Filtration_value filtration() { - return _st.filtration(); - } - - friend std::ostream& operator<<(std::ostream& os, const Alpha_shapes& alpha_shape) { - // TODO: Program terminated with signal SIGABRT, Aborted - Maybe because of copy constructor - Gudhi::Simplex_tree<> st = alpha_shape._st; - os << st << std::endl; - return os; - } -}; - -} // namespace alphashapes - -} // namespace Gudhi - -#endif // SRC_ALPHA_SHAPES_INCLUDE_GUDHI_ALPHA_SHAPES_H_ diff --git a/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h b/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h deleted file mode 100644 index 693b393e..00000000 --- a/src/Alpha_shapes/include/gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h +++ /dev/null @@ -1,213 +0,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): Vincent Rouvreau - * - * Copyright (C) 2015 INRIA Saclay (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 SRC_ALPHA_SHAPES_INCLUDE_GUDHI_ALPHA_SHAPES_DELAUNAY_TRIANGULATION_OFF_IO_H_ -#define SRC_ALPHA_SHAPES_INCLUDE_GUDHI_ALPHA_SHAPES_DELAUNAY_TRIANGULATION_OFF_IO_H_ - -#include -#include -#include - -#include "gudhi/Off_reader.h" - -namespace Gudhi { - -namespace alphashapes { - -/** - *@brief Off reader visitor with flag that can be passed to Off_reader to read a Delaunay_triangulation_complex. - */ -template -class Delaunay_triangulation_off_flag_visitor_reader { - Complex& complex_; - typedef typename Complex::Point Point; - - const bool load_only_points_; - - public: - explicit Delaunay_triangulation_off_flag_visitor_reader(Complex& complex, bool load_only_points = false) : - complex_(complex), - load_only_points_(load_only_points) { } - - void init(int dim, int num_vertices, int num_faces, int num_edges) { -#ifdef DEBUG_TRACES - std::cout << "init" << std::endl; -#endif // DEBUG_TRACES - } - - void point(const std::vector& point) { -#ifdef DEBUG_TRACES - std::cout << "p "; - for (auto coordinate: point) { - std::cout << coordinate << " | "; - } - std::cout << std::endl; -#endif // DEBUG_TRACES - complex_.insert(Point(point.size(), point.begin(), point.end())); - } - - void maximal_face(const std::vector& face) { - // For alpha shapes, only points are read - } - - void done() { -#ifdef DEBUG_TRACES - std::cout << "done" << std::endl; -#endif // DEBUG_TRACES - } -}; - -/** - *@brief Off reader visitor that can be passed to Off_reader to read a Delaunay_triangulation_complex. - */ -template -class Delaunay_triangulation_off_visitor_reader { - Complex& complex_; - // typedef typename Complex::Vertex_handle Vertex_handle; - // typedef typename Complex::Simplex_handle Simplex_handle; - typedef typename Complex::Point Point; - - const bool load_only_points_; - std::vector points_; - // std::vector maximal_faces_; - - public: - explicit Delaunay_triangulation_off_visitor_reader(Complex& complex, bool load_only_points = false) : - complex_(complex), - load_only_points_(load_only_points) { } - - void init(int dim, int num_vertices, int num_faces, int num_edges) { -#ifdef DEBUG_TRACES - std::cout << "init - " << num_vertices << std::endl; -#endif // DEBUG_TRACES - // maximal_faces_.reserve(num_faces); - points_.reserve(num_vertices); - } - - void point(const std::vector& point) { -#ifdef DEBUG_TRACES - std::cout << "p "; - for (auto coordinate: point) { - std::cout << coordinate << " | "; - } - std::cout << std::endl; -#endif // DEBUG_TRACES - points_.emplace_back(Point(point.size(), point.begin(), point.end())); - } - - void maximal_face(const std::vector& face) { - // For alpha shapes, only points are read - } - - void done() { - complex_.insert(points_.begin(), points_.end()); -#ifdef DEBUG_TRACES - std::cout << "done" << std::endl; -#endif // DEBUG_TRACES - } -}; - -/** - *@brief Class that allows to load a Delaunay_triangulation_complex from an off file. - */ -template -class Delaunay_triangulation_off_reader { - public: - /** - * name_file : file to read - * read_complex : complex that will receive the file content - * read_only_points : specify true if only the points must be read - */ - Delaunay_triangulation_off_reader(const std::string & name_file, Complex& read_complex, bool read_only_points = false, - bool is_flag = false) : valid_(false) { - std::ifstream stream(name_file); - if (stream.is_open()) { - if (is_flag) { - // For alpha shapes, only points are read - Delaunay_triangulation_off_flag_visitor_reader off_visitor(read_complex, true); - Off_reader off_reader(stream); - valid_ = off_reader.read(off_visitor); - } else { - // For alpha shapes, only points are read - Delaunay_triangulation_off_visitor_reader off_visitor(read_complex, true); - Off_reader off_reader(stream); - valid_ = off_reader.read(off_visitor); - } - } - } - - /** - * return true if reading did not meet problems. - */ - bool is_valid() const { - return valid_; - } - - private: - bool valid_; -}; - -template -class Delaunay_triangulation_off_writer { - public: - /** - * name_file : file where the off will be written - * save_complex : complex that be outputted in the file - * for now only save triangles. - */ - Delaunay_triangulation_off_writer(const std::string & name_file, const Complex& save_complex) { - std::ofstream stream(name_file); - if (stream.is_open()) { - // OFF header - stream << "OFF" << std::endl; - // no endl on next line - don't know why... - stream << save_complex.number_of_vertices() << " " << save_complex.number_of_finite_full_cells() << " 0"; - - // Points list - for (auto vit = save_complex.vertices_begin(); vit != save_complex.vertices_end(); ++vit) { - for (auto Coord = vit->point().cartesian_begin(); Coord != vit->point().cartesian_end(); ++Coord) { - stream << *Coord << " "; - } - stream << std::endl; - } - - // Finite cells list - for (auto cit = save_complex.finite_full_cells_begin(); cit != save_complex.finite_full_cells_end(); ++cit) { - stream << std::distance(cit->vertices_begin(), cit->vertices_end()) << " "; // Dimension - for (auto vit = cit->vertices_begin(); vit != cit->vertices_end(); ++vit) { - auto vertexHdl = *vit; - // auto vertexHdl = std::distance(save_complex.vertices_begin(), *vit) - 1; - // stream << std::distance(save_complex.vertices_begin(), *(vit)) - 1 << " "; - } - stream << std::endl; - } - stream.close(); - } else { - std::cerr << "could not open file " << name_file << std::endl; - } - } -}; - -} // namespace alphashapes - -} // namespace Gudhi - -#endif // SRC_ALPHA_SHAPES_INCLUDE_GUDHI_ALPHA_SHAPES_DELAUNAY_TRIANGULATION_OFF_IO_H_ diff --git a/src/Alpha_shapes/test/Alpha_shapes_unit_test.cpp b/src/Alpha_shapes/test/Alpha_shapes_unit_test.cpp deleted file mode 100644 index b4c32321..00000000 --- a/src/Alpha_shapes/test/Alpha_shapes_unit_test.cpp +++ /dev/null @@ -1,126 +0,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): Vincent Rouvreau - * - * Copyright (C) 2015 INRIA Saclay (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 . - */ - -#define BOOST_TEST_MODULE alpha_shapes test -#include -#include -#include -// to construct a Delaunay_triangulation from a OFF file -#include "gudhi/Alpha_shapes/Delaunay_triangulation_off_io.h" -#include "gudhi/Alpha_shapes.h" - -// to construct a simplex_tree from Delaunay_triangulation -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -// Use dynamic_dimension_tag for the user to be able to set dimension -typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > K; -typedef CGAL::Delaunay_triangulation T; -// The triangulation uses the default instanciation of the -// TriangulationDataStructure template parameter - -BOOST_AUTO_TEST_CASE( OFF_file ) { - // ---------------------------------------------------------------------------- - // - // Init of an alpha-shape from a OFF file - // - // ---------------------------------------------------------------------------- - std::string off_file_name("S4_100.off"); - std::cout << "========== OFF FILE NAME = " << off_file_name << " ==========" << std::endl; - - Gudhi::alphashapes::Alpha_shapes alpha_shapes_from_file(off_file_name, 4); - - const int DIMENSION = 4; - std::cout << "alpha_shapes_from_file.dimension()=" << alpha_shapes_from_file.dimension() << std::endl; - BOOST_CHECK(alpha_shapes_from_file.dimension() == DIMENSION); - - const double FILTRATION = 0.0; - std::cout << "alpha_shapes_from_file.filtration()=" << alpha_shapes_from_file.filtration() << std::endl; - BOOST_CHECK(alpha_shapes_from_file.filtration() == FILTRATION); - - const int NUMBER_OF_VERTICES = 100; - std::cout << "alpha_shapes_from_file.num_vertices()=" << alpha_shapes_from_file.num_vertices() << std::endl; - BOOST_CHECK(alpha_shapes_from_file.num_vertices() == NUMBER_OF_VERTICES); - - const int NUMBER_OF_SIMPLICES = 6779; - std::cout << "alpha_shapes_from_file.num_simplices()=" << alpha_shapes_from_file.num_simplices() << std::endl; - BOOST_CHECK(alpha_shapes_from_file.num_simplices() == NUMBER_OF_SIMPLICES); - -} - -BOOST_AUTO_TEST_CASE( Delaunay_triangulation ) { - // ---------------------------------------------------------------------------- - // - // Init of an alpha-shape from a Delauny triangulation - // - // ---------------------------------------------------------------------------- - T dt(8); - std::string off_file_name("S8_10.off"); - std::cout << "========== OFF FILE NAME = " << off_file_name << " ==========" << std::endl; - - Gudhi::alphashapes::Delaunay_triangulation_off_reader off_reader(off_file_name, dt, true, true); - std::cout << "off_reader.is_valid()=" << off_reader.is_valid() << std::endl; - BOOST_CHECK(off_reader.is_valid()); - - const int NUMBER_OF_VERTICES = 10; - std::cout << "dt.number_of_vertices()=" << dt.number_of_vertices() << std::endl; - BOOST_CHECK(dt.number_of_vertices() == NUMBER_OF_VERTICES); - - const int NUMBER_OF_FULL_CELLS = 30; - std::cout << "dt.number_of_full_cells()=" << dt.number_of_full_cells() << std::endl; - BOOST_CHECK(dt.number_of_full_cells() == NUMBER_OF_FULL_CELLS); - - const int NUMBER_OF_FINITE_FULL_CELLS = 6; - std::cout << "dt.number_of_finite_full_cells()=" << dt.number_of_finite_full_cells() << std::endl; - BOOST_CHECK(dt.number_of_finite_full_cells() == NUMBER_OF_FINITE_FULL_CELLS); - - Gudhi::alphashapes::Alpha_shapes alpha_shapes_from_dt(dt); - - const int DIMENSION = 8; - std::cout << "alpha_shapes_from_dt.dimension()=" << alpha_shapes_from_dt.dimension() << std::endl; - BOOST_CHECK(alpha_shapes_from_dt.dimension() == DIMENSION); - - const double FILTRATION = 0.0; - std::cout << "alpha_shapes_from_dt.filtration()=" << alpha_shapes_from_dt.filtration() << std::endl; - BOOST_CHECK(alpha_shapes_from_dt.filtration() == FILTRATION); - - std::cout << "alpha_shapes_from_dt.num_vertices()=" << alpha_shapes_from_dt.num_vertices() << std::endl; - BOOST_CHECK(alpha_shapes_from_dt.num_vertices() == NUMBER_OF_VERTICES); - - const int NUMBER_OF_SIMPLICES = 997; - std::cout << "alpha_shapes_from_dt.num_simplices()=" << alpha_shapes_from_dt.num_simplices() << std::endl; - BOOST_CHECK(alpha_shapes_from_dt.num_simplices() == NUMBER_OF_SIMPLICES); -} - diff --git a/src/Alpha_shapes/test/CMakeLists.txt b/src/Alpha_shapes/test/CMakeLists.txt deleted file mode 100644 index e0d33827..00000000 --- a/src/Alpha_shapes/test/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -project(GUDHIAlphaShapesUT) - -# need CGAL 4.6 -# cmake -DCGAL_DIR=~/workspace/CGAL-4.6-beta1 ../../.. -if(CGAL_FOUND) - if (NOT CGAL_VERSION VERSION_LESS 4.6.0) - message(STATUS "CGAL version: ${CGAL_VERSION}.") - - include( ${CGAL_USE_FILE} ) - - find_package(Eigen3 3.1.0) - if (EIGEN3_FOUND) - message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.") - include( ${EIGEN3_USE_FILE} ) - include_directories (BEFORE "../../include") - - 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() - - # uncomment to display debug traces - # add_definitions(-DDEBUG_TRACES) - add_executable ( AlphaShapesUT Alpha_shapes_unit_test.cpp ) - target_link_libraries(AlphaShapesUT ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) - add_test(NAME AlphaShapesUT - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/AlphaShapesUT - # XML format for Jenkins xUnit plugin - --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/AlphaShapesUT.xml --log_level=test_suite --report_level=no) - - - else() - message(WARNING "Eigen3 not found. Version 3.1.0 is required for Alpha shapes feature.") - endif() - else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Alpha shapes feature. Version 4.6.0 is required.") - endif () -endif() - diff --git a/src/Alpha_shapes/test/README b/src/Alpha_shapes/test/README deleted file mode 100644 index cddd46ca..00000000 --- a/src/Alpha_shapes/test/README +++ /dev/null @@ -1,14 +0,0 @@ -To compile: -*********** - -cd /path-to-gudhi/ -cmake . -cd /path-to-test/ -make - -To launch with details: -*********************** - -./AlphaShapesUT --report_level=detailed --log_level=all - - ==> echo $? returns 0 in case of success (non-zero otherwise) diff --git a/src/Alpha_shapes/test/S4_100.off b/src/Alpha_shapes/test/S4_100.off deleted file mode 100644 index 0a5dc58c..00000000 --- a/src/Alpha_shapes/test/S4_100.off +++ /dev/null @@ -1,102 +0,0 @@ -OFF -100 0 0 -0.562921 -0.735261 -0.256472 0.277007 --0.803733 -0.0527915 -0.315125 0.501918 --0.24946 -0.354982 -0.410773 -0.801887 -0.916381 -0.0512295 0.371049 0.141223 -0.182222 0.940836 -0.171362 -0.228599 --0.787145 -0.129213 0.568102 -0.202402 -0.0187866 -0.22093 -0.832882 -0.507095 --0.4702 -0.533814 0.353776 0.607286 --0.159798 -0.504771 0.263586 0.806346 -0.295546 0.162541 0.452931 0.825279 -0.242043 -0.107437 -0.913612 -0.308521 -0.875759 -0.113035 -0.469189 -0.0114505 -0.547877 -0.762247 -0.256972 -0.229729 --0.172302 0.521057 0.412013 -0.727363 --0.724729 -0.0574074 -0.0290602 0.686023 -0.700434 -0.102636 0.687285 0.162779 --0.681386 0.0946893 0.610047 0.393178 --0.847553 -0.357132 0.383743 0.0827718 -0.72297 -0.161631 -0.608517 0.284424 -0.757394 0.141549 0.196065 -0.606528 -0.78094 0.00901997 0.434536 0.448586 -0.14166 -0.619339 0.614589 -0.467582 -0.473105 -0.537832 -0.0103746 0.697711 --0.208004 0.536218 0.818027 0.00605288 -0.743694 -0.628926 0.188072 0.126488 --0.462228 -0.278147 0.35514 -0.76345 --0.17361 0.249211 0.758567 -0.57648 -0.416958 -0.254924 -0.576373 -0.654946 --0.590751 -0.286089 -0.424896 0.623402 --0.639538 -0.739693 -0.203745 0.0482932 -0.0731787 0.132121 0.864022 0.480266 --0.149644 -0.164724 -0.249746 -0.94239 --0.348592 0.0120379 -0.928656 -0.126239 -0.395328 -0.54513 0.149976 -0.723917 --0.974164 0.14707 0.157191 0.068302 --0.166425 0.119943 -0.627304 -0.751269 -0.031947 -0.358518 -0.708301 -0.607251 -0.93781 -0.155368 -0.30951 0.0240237 -0.276094 -0.753155 -0.597088 -0.00387459 --0.642876 -0.200551 -0.263517 -0.690687 -0.178711 0.604987 -0.262989 0.729993 --0.520347 0.497922 -0.676144 0.155374 --0.703999 0.500219 -0.484381 0.139789 --0.131013 0.835735 0.506779 0.166004 --0.536116 -0.566557 0.229226 0.582279 --0.334105 0.158252 0.926091 0.0754059 --0.0362677 0.296076 0.897108 0.325915 --0.57486 0.798575 0.15324 -0.0912754 -0.498602 0.0186805 0.72824 0.469801 --0.960329 0.0473356 0.261005 -0.0860505 -0.899134 -0.381392 -0.214508 0.00921711 -0.570576 0.567224 0.393019 -0.445237 --0.761763 -0.614589 -0.0546476 -0.197513 -0.188584 0.289531 0.174031 0.922129 --0.458506 -0.583876 0.639297 -0.2004 -0.785343 -0.21571 0.0794082 -0.574804 -0.0819036 0.65961 -0.247426 0.704973 -0.573125 0.49706 0.373026 0.534145 --0.513286 -0.626226 0.208535 -0.548536 -0.460558 0.468686 0.507832 -0.55707 -0.716158 -0.488201 0.388209 -0.313164 -0.881074 0.152441 0.380128 -0.236589 -0.885793 0.0386389 0.161009 -0.433537 --0.365162 0.298384 0.292846 0.831784 -0.364934 0.632269 -0.197205 -0.654346 --0.31469 -0.429991 0.665304 -0.522923 --0.734198 0.462914 -0.135691 -0.477756 --0.422885 0.674444 -0.364143 -0.483419 -0.829218 -0.154622 -0.381147 0.378439 -0.887881 0.310479 -0.109528 0.321363 --0.354398 -0.693974 0.456019 -0.429941 --0.492045 -0.160008 0.044387 0.854587 -0.0595532 0.158421 0.412577 -0.895062 --0.211441 0.491794 -0.153521 0.83058 --0.33558 -0.504711 0.353831 -0.71236 --0.735211 -0.197714 0.525626 0.379593 -0.465818 -0.424245 0.769469 -0.104627 --0.641071 -0.286339 -0.704442 -0.103923 --0.00446569 0.0249849 -0.194417 -0.980591 --0.610081 -0.252448 0.176698 -0.729966 --0.0859217 -0.154471 0.715027 0.676382 -0.091315 0.0723382 -0.855023 -0.505337 -0.165362 0.200983 -0.428242 -0.865373 --0.587465 0.303019 -0.152442 0.734729 -0.454946 -0.319828 0.437063 -0.706902 --0.384368 0.277509 0.879225 -0.0470385 -0.523335 -0.330233 -0.208592 0.757335 -0.895086 0.0448492 0.268089 -0.353466 --0.0272491 -0.567336 -0.72254 -0.39411 --0.0745014 -0.121818 -0.882466 0.448179 -0.382304 -0.240135 0.851109 -0.267941 --0.418057 -0.852847 -0.3128 0.00606452 --0.554046 0.304237 0.272381 -0.725453 -0.155115 -0.0894732 -0.245017 -0.952838 -0.114459 -0.130722 0.953669 0.245614 -0.0913002 -0.462466 0.244433 0.847374 --0.198849 0.0785111 0.131441 -0.967997 --0.303154 -0.686484 0.639333 0.167604 -0.521455 0.256835 -0.0584503 -0.811606 --0.109787 0.870544 0.161523 0.451676 diff --git a/src/Alpha_shapes/test/S8_10.off b/src/Alpha_shapes/test/S8_10.off deleted file mode 100644 index 1d67e10f..00000000 --- a/src/Alpha_shapes/test/S8_10.off +++ /dev/null @@ -1,12 +0,0 @@ -OFF -10 0 0 -0.440036 -0.574754 -0.200485 0.216537 -0.501251 -0.0329236 -0.196529 0.313023 --0.129367 -0.184089 -0.213021 -0.415848 0.783529 -0.0438025 0.317256 0.120749 -0.132429 0.683748 -0.124536 -0.166133 -0.540695 -0.0887576 0.390234 -0.139031 -0.0137399 -0.161581 -0.609142 -0.370872 -0.320669 -0.364053 0.24127 0.41416 --0.115313 -0.36425 0.190208 0.581871 0.204605 0.112527 0.313562 0.571337 -0.168272 -0.0746917 -0.635156 -0.214488 0.629498 -0.0812499 -0.337255 -0.00823068 -0.369896 -0.514626 -0.173493 -0.1551 -0.127105 0.384377 0.303936 -0.536566 --0.49013 -0.0388242 -0.0196532 0.463953 0.515962 -0.0756047 0.506276 0.119908 --0.434258 0.060347 0.388793 0.250579 -0.653127 -0.275207 0.295714 0.0637842 -0.596172 -0.133284 -0.501793 0.234541 0.428452 0.0800735 0.110912 -0.343109 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3be05c4f..9f6db2c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,7 +44,6 @@ else() add_subdirectory(example/Skeleton_blocker) add_subdirectory(example/Contraction) add_subdirectory(example/Hasse_complex) - add_subdirectory(example/Alpha_shapes) add_subdirectory(example/Bottleneck) # GudhUI -- cgit v1.2.3 From 505a0c3159b1c1a74884b8e28d9eb18aafa57cca Mon Sep 17 00:00:00 2001 From: anmoreau Date: Tue, 7 Jul 2015 10:05:01 +0000 Subject: Fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@687 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 537ff69dd4c762a196c80d051995c3a4145f7c99 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 28 +++++++++--------------- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 10 +++++++++ 2 files changed, 20 insertions(+), 18 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 f2b726f9..f5add449 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -613,58 +613,49 @@ private: *\param vertices contains a list of vertices, which represent the vertices of the simplex not found yet. *\param curr_nbVertices represents the number of vertices of the simplex found. *\param cofaces contains a list of Simplex_handle, representing all the cofaces asked. - *\param length number of vertices in the Simplex_handle of which we search the cofaces. + *\param star true if we need the star of the simplex *\param nbVertices number of vertices of the cofaces we search * Prefix actions : When the bottom vertex matches with the current vertex in the tree, we remove the bottom vertex from vertices. * Infix actions : Then we call or not the recursion. * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_nbVertices so that we didn't change the parameters. * If the vertices list is empty, we need to check if curr_nbVertices matches with the dimension of the cofaces asked. */ - void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_nbVertices, std::vector& cofaces, int length, int nbVertices) + void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_nbVertices, std::vector& cofaces, bool star, int nbVertices) { - bool star = nbVertices == length; if (!(star || curr_nbVertices <= nbVertices)) // dimension of actual simplex <= nbVertices return; - curr_nbVertices++; for (Simplex_handle simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) { if (vertices.empty()) { // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface - bool addCoface = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices + bool addCoface = (star || curr_nbVertices == nbVertices); // Add a coface if we wan't the star or if the number of vertices of the current simplex matches with nbVertices if (addCoface) cofaces.push_back(simplex); if ((!addCoface || star) && has_children(simplex)) // Rec call - rec_coface(vertices, simplex->second.children(), curr_nbVertices, cofaces, length, nbVertices); - curr_nbVertices--; + rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); } else { if (simplex->first == vertices.back()) // If curr_sib matches with the top vertex { bool equalDim = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices - bool addCoface = vertices.size() == 1 && curr_nbVertices > length && equalDim; + bool addCoface = vertices.size() == 1 && equalDim; if (addCoface) cofaces.push_back(simplex); - if ((!addCoface || star) && has_children(simplex)) + if ((!addCoface || star) && has_children(simplex)) // Rec call { // Rec call Vertex_handle tmp = vertices.back(); vertices.pop_back(); - rec_coface(vertices, simplex->second.children(), curr_nbVertices, cofaces, length, nbVertices); + rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); vertices.push_back(tmp); } - curr_nbVertices--; } else if (simplex->first > vertices.back()) return; else // (simplex->first < vertices.back() - { if (has_children(simplex)) - { - rec_coface(vertices, simplex->second.children(), curr_nbVertices, cofaces, length, nbVertices); - curr_nbVertices--; - } - } + rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); } } } @@ -695,7 +686,8 @@ public: if (codimension + (int)copy.size() > dimension_ + 1 || (codimension == 0 && (int)copy.size() > dimension_) ) // n+codimension greater than dimension_ return cofaces; assert(std::is_sorted(copy.begin(), copy.end(), std::greater())); // must be sorted in decreasing order - rec_coface(copy, &root_, 0, cofaces, (int)copy.size(), codimension + (int)copy.size()); + bool star = codimension == 0; + rec_coface(copy, &root_, 1, cofaces, star, codimension + (int)copy.size()); return cofaces; } diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index a6328663..55a055a0 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -620,6 +620,11 @@ BOOST_AUTO_TEST_CASE( NSimplexAndSubfaces_tree_insertion ) v.push_back(3); std::cout << "First test : " << std::endl; std::cout << "Star of (3):" << std::endl; + + simplex.push_back(3); + result.push_back(st.find(simplex)); + simplex.clear(); + simplex.push_back(3); simplex.push_back(0); result.push_back(st.find(simplex)); @@ -650,6 +655,11 @@ BOOST_AUTO_TEST_CASE( NSimplexAndSubfaces_tree_insertion ) std::cout << "Second test : " << std::endl; std::cout << "Star of (1,7): " << std::endl; + simplex.push_back(7); + simplex.push_back(1); + result.push_back(st.find(simplex)); + simplex.clear(); + simplex.push_back(7); simplex.push_back(6); simplex.push_back(1); -- cgit v1.2.3 From 41ac7d00bac4c1cead095354dc2e8032855d3730 Mon Sep 17 00:00:00 2001 From: anmoreau Date: Tue, 7 Jul 2015 12:51:31 +0000 Subject: fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@690 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c321cdfd965487fb41801f4456838637512d0c2d --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 0c2c851a..75471e3a 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -189,7 +189,7 @@ class Simplex_tree { /** \name Range and iterator methods * @{ */ - /** \brief Returns a range over the vertices of the simplicial complex. * + /** \brief Returns a range over the vertices of the simplicial complex. * The order is increasing according to < on Vertex_handles.*/ Complex_vertex_range complex_vertex_range() { return Complex_vertex_range( -- cgit v1.2.3 From 7302345da9d33699b2478ded8ee3f0f9bfa3e715 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Jul 2015 14:17:48 +0000 Subject: Fix ident + cpplint git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@691 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f282adfdec4429e426a46be9f83d149c69892ec5 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 329 +++++----- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 800 +++++++++++------------ 2 files changed, 561 insertions(+), 568 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 75471e3a..2507f783 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -35,9 +35,10 @@ #include #include #include +#include // for greater<> namespace Gudhi { - + /** \defgroup simplex_tree Filtered Complexes * * A simplicial complex \f$\mathbf{K}\f$ @@ -72,6 +73,7 @@ namespace Gudhi { * \copyright GNU General Public License v3. * @{ */ + /** * \brief Simplex Tree data structure for representing simplicial complexes. * @@ -84,8 +86,8 @@ namespace Gudhi { * */ template class Simplex_tree { @@ -130,6 +132,7 @@ class Simplex_tree { typedef typename Dictionary_it::value_type Dit_value_t; struct return_first { + Vertex_handle operator()(const Dit_value_t& p_sh) const { return p_sh.first; } @@ -185,7 +188,7 @@ class Simplex_tree { /** \brief Range over the simplices of the simplicial complex, ordered by the filtration. */ typedef boost::iterator_range Filtration_simplex_range; - /* @} */ // end name range and iterator types + /* @} */ // end name range and iterator types /** \name Range and iterator methods * @{ */ @@ -193,8 +196,8 @@ class Simplex_tree { * The order is increasing according to < on Vertex_handles.*/ Complex_vertex_range complex_vertex_range() { return Complex_vertex_range( - boost::make_transform_iterator(root_.members_.begin(), return_first()), - boost::make_transform_iterator(root_.members_.end(), return_first())); + boost::make_transform_iterator(root_.members_.begin(), return_first()), + boost::make_transform_iterator(root_.members_.end(), return_first())); } /** \brief Returns a range over the simplices of the simplicial complex. @@ -207,7 +210,6 @@ class Simplex_tree { Complex_simplex_iterator()); } - /** \brief Returns a range over the simplices of the dim-skeleton of the simplicial complex. * * The \f$d\f$-skeleton of a simplicial complex \f$\mathbf{K}\f$ is the simplicial complex containing the @@ -247,6 +249,7 @@ class Simplex_tree { Filtration_simplex_range filtration_simplex_range() { return filtration_simplex_range(Indexing_tag()); } + /** \brief Returns a range over the vertices of a simplex. * * The order in which the vertices are visited is the decreasing order for < on Vertex_handles, @@ -254,12 +257,11 @@ class Simplex_tree { * equal to \f$(-1)^{\text{dim} \sigma}\f$ the canonical orientation on the simplex. */ Simplex_vertex_range simplex_vertex_range(Simplex_handle sh) { - assert (sh != null_simplex()); // Empty simplex + assert(sh != null_simplex()); // Empty simplex return Simplex_vertex_range(Simplex_vertex_iterator(this, sh), Simplex_vertex_iterator(this)); } - /** \brief Returns a range over the simplices of the boundary of a simplex. * * The boundary of a simplex is the set of codimension \f$1\f$ subsimplices of the simplex. @@ -279,19 +281,18 @@ class Simplex_tree { Boundary_simplex_iterator(this)); } - /** @} */ // end range and iterator methods + /** @} */ // end range and iterator methods /** \name Constructor/Destructor * @{ */ /** \brief Constructs an empty simplex tree. */ Simplex_tree() : null_vertex_(-1), - threshold_(0), - num_simplices_(0), - root_(NULL, null_vertex_), - filtration_vect_(), - dimension_(-1) { - } + threshold_(0), + num_simplices_(0), + root_(NULL, null_vertex_), + filtration_vect_(), + dimension_(-1) { } /** \brief Destructor; deallocates the whole tree structure. */ ~Simplex_tree() { @@ -301,7 +302,7 @@ class Simplex_tree { } } } - /** @} */ // end constructor/destructor + /** @} */ // end constructor/destructor private: /** Recursive deletion. */ void rec_delete(Siblings * sib) { @@ -320,12 +321,14 @@ class Simplex_tree { Simplex_key key(Simplex_handle sh) { return sh->second.key(); } + /** \brief Returns the simplex associated to a key. * * The filtration must be initialized. */ Simplex_handle simplex(Simplex_key key) { return filtration_vect_[key]; } + /** \brief Returns the filtration value of a simplex. * * Called on the null_simplex, returns INFINITY. */ @@ -334,12 +337,14 @@ class Simplex_tree { return sh->second.filtration(); } else { return INFINITY; - } // filtration(); } + } // filtration(); } } + /** \brief Returns an upper bound of the filtration values of the simplices. */ Filtration_value filtration() const { return threshold_; } + /** \brief Returns a Simplex_handle different from all Simplex_handles * associated to the simplices in the simplicial complex. * @@ -347,20 +352,24 @@ class Simplex_tree { Simplex_handle null_simplex() const { return Dictionary_it(NULL); } + /** \brief Returns a key different for all keys associated to the * simplices of the simplicial complex. */ Simplex_key null_key() const { return -1; } + /** \brief Returns a Vertex_handle different from all Vertex_handles associated * to the vertices of the simplicial complex. */ Vertex_handle null_vertex() const { return null_vertex_; } + /** \brief Returns the number of vertices in the complex. */ size_t num_vertices() const { return root_.members_.size(); } + /** \brief Returns the number of simplices in the complex. * * Does not count the empty simplex. */ @@ -380,6 +389,7 @@ class Simplex_tree { } return dim - 1; } + /** \brief Returns an upper bound on the dimension of the simplicial complex. */ int dimension() const { return dimension_; @@ -390,9 +400,8 @@ class Simplex_tree { bool has_children(Simplex_handle sh) const { return (sh->second.children()->parent() == sh->first); } - - public: + public: /** \brief Given a range of Vertex_handles, returns the Simplex_handle * of the simplex in the simplicial complex containing the corresponding * vertices. Return null_simplex() if the simplex is not in the complex. @@ -404,7 +413,7 @@ class Simplex_tree { template Simplex_handle find(RandomAccessVertexRange & s) { if (s.begin() == s.end()) // Empty simplex - return null_simplex(); + return null_simplex(); sort(s.begin(), s.end()); @@ -429,7 +438,7 @@ class Simplex_tree { Simplex_handle find_vertex(Vertex_handle v) { return root_.members_.begin() + v; } -//{ return root_.members_.find(v); } + //{ return root_.members_.find(v); } /** \brief Insert a simplex, represented by a range of Vertex_handles, in the simplicial complex. * @@ -456,12 +465,12 @@ class Simplex_tree { * .end() return random access iterators, with 'value_type' Vertex_handle. */ template std::pair insert_simplex(RandomAccessVertexRange & simplex, - Filtration_value filtration) { + Filtration_value filtration) { if (simplex.empty()) { return std::pair(null_simplex(), true); } - sort(simplex.begin(), simplex.end()); // must be sorted in increasing order + sort(simplex.begin(), simplex.end()); // must be sorted in increasing order Siblings * curr_sib = &root_; std::pair res_insert; @@ -474,34 +483,33 @@ class Simplex_tree { curr_sib = res_insert.first->second.children(); } res_insert = curr_sib->members_.emplace(*vi, Node(curr_sib, filtration)); - if (!res_insert.second) { // if already in the complex - if (res_insert.first->second.filtration() > filtration) { // if filtration value modified + if (!res_insert.second) { // if already in the complex + if (res_insert.first->second.filtration() > filtration) { // if filtration value modified res_insert.first->second.assign_filtration(filtration); return res_insert; } - return std::pair(null_simplex(), false); // if filtration value unchanged + return std::pair(null_simplex(), false); // if filtration value unchanged } // otherwise the insertion has succeeded return res_insert; } - /** \brief Insert a N-simplex and all his subfaces, from a N-simplex represented by a range of * Vertex_handles, in the simplicial complex. * * @param[in] Nsimplex range of Vertex_handles, representing the vertices of the new N-simplex * @param[in] filtration the filtration value assigned to the new N-simplex. - */ + */ template void insert_simplex_and_subfaces(RandomAccessVertexRange& Nsimplex, - Filtration_value filtration = 0.0) { + Filtration_value filtration = 0.0) { if (Nsimplex.size() > 1) { for (unsigned int NIndex = 0; NIndex < Nsimplex.size(); NIndex++) { // insert N (N-1)-Simplex RandomAccessVertexRange NsimplexMinusOne; for (unsigned int NListIter = 0; NListIter < Nsimplex.size() - 1; NListIter++) { // (N-1)-Simplex creation - NsimplexMinusOne.push_back( Nsimplex[(NIndex + NListIter) % Nsimplex.size()]); + NsimplexMinusOne.push_back(Nsimplex[(NIndex + NListIter) % Nsimplex.size()]); } // (N-1)-Simplex recursive call insert_simplex_and_subfaces(NsimplexMinusOne, filtration); @@ -534,8 +542,8 @@ class Simplex_tree { * optimized version of the boundary computation. */ std::pair endpoints(Simplex_handle sh) { return std::pair( - root_.members_.find(sh->first), - root_.members_.find(self_siblings(sh)->parent())); + root_.members_.find(sh->first), + root_.members_.find(self_siblings(sh)->parent())); } /** Returns the Siblings containing a simplex.*/ @@ -546,12 +554,12 @@ class Simplex_tree { return sh->second.children(); } -// void display_simplex(Simplex_handle sh) -// { -// std::cout << " " << "[" << filtration(sh) << "] "; -// for( auto vertex : simplex_vertex_range(sh) ) -// { std::cout << vertex << " "; } -// } + // void display_simplex(Simplex_handle sh) + // { + // std::cout << " " << "[" << filtration(sh) << "] "; + // for( auto vertex : simplex_vertex_range(sh) ) + // { std::cout << vertex << " "; } + // } // void print(Simplex_handle sh, std::ostream& os = std::cout) // { for(auto v : simplex_vertex_range(sh)) {os << v << " ";} @@ -563,15 +571,16 @@ class Simplex_tree { return &root_; } - public: /** Set an upper bound for the filtration values. */ void set_filtration(Filtration_value fil) { threshold_ = fil; } + /** Set a number of simplices for the simplicial complex. */ void set_num_simplices(unsigned int num_simplices) { num_simplices_ = num_simplices; } + /** Set a dimension for the simplicial complex. */ void set_dimension(int dimension) { dimension_ = dimension; @@ -597,7 +606,7 @@ class Simplex_tree { filtration_vect_.clear(); filtration_vect_.reserve(num_simplices()); for (auto cpx_it = complex_simplex_range().begin(); - cpx_it != complex_simplex_range().end(); ++cpx_it) { + cpx_it != complex_simplex_range().end(); ++cpx_it) { filtration_vect_.push_back(*cpx_it); } @@ -605,94 +614,86 @@ class Simplex_tree { std::stable_sort(filtration_vect_.begin(), filtration_vect_.end(), is_before_in_filtration(this)); } - -private: - - /** Recursive search of cofaces - * This function uses DFS - *\param vertices contains a list of vertices, which represent the vertices of the simplex not found yet. - *\param curr_nbVertices represents the number of vertices of the simplex we reached by going through the tree. - *\param cofaces contains a list of Simplex_handle, representing all the cofaces asked. - *\param star true if we need the star of the simplex - *\param nbVertices number of vertices of the cofaces we search - * Prefix actions : When the bottom vertex matches with the current vertex in the tree, we remove the bottom vertex from vertices. - * Infix actions : Then we call or not the recursion. - * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_nbVertices so that we didn't change the parameters. - * If the vertices list is empty, we need to check if curr_nbVertices matches with the dimension of the cofaces asked. - */ - void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_nbVertices, std::vector& cofaces, bool star, int nbVertices) - { - if (!(star || curr_nbVertices <= nbVertices)) // dimension of actual simplex <= nbVertices - return; - for (Simplex_handle simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) + + private: + /** Recursive search of cofaces + * This function uses DFS + *\param vertices contains a list of vertices, which represent the vertices of the simplex not found yet. + *\param curr_nbVertices represents the number of vertices of the simplex we reached by going through the tree. + *\param cofaces contains a list of Simplex_handle, representing all the cofaces asked. + *\param star true if we need the star of the simplex + *\param nbVertices number of vertices of the cofaces we search + * Prefix actions : When the bottom vertex matches with the current vertex in the tree, we remove the bottom vertex from vertices. + * Infix actions : Then we call or not the recursion. + * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_nbVertices so that we didn't change the parameters. + * If the vertices list is empty, we need to check if curr_nbVertices matches with the dimension of the cofaces asked. + */ + void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_nbVertices, std::vector& cofaces, bool star, int nbVertices) { + if (!(star || curr_nbVertices <= nbVertices)) // dimension of actual simplex <= nbVertices + return; + for (Simplex_handle simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) { + if (vertices.empty()) { + // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface + bool addCoface = (star || curr_nbVertices == nbVertices); // Add a coface if we wan't the star or if the number of vertices of the current simplex matches with nbVertices + if (addCoface) + cofaces.push_back(simplex); + if ((!addCoface || star) && has_children(simplex)) // Rec call + rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); + } else { + if (simplex->first == vertices.back()) // If curr_sib matches with the top vertex { - if (vertices.empty()) - { - // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface - bool addCoface = (star || curr_nbVertices == nbVertices); // Add a coface if we wan't the star or if the number of vertices of the current simplex matches with nbVertices - if (addCoface) - cofaces.push_back(simplex); - if ((!addCoface || star) && has_children(simplex)) // Rec call - rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); - } - else - { - if (simplex->first == vertices.back()) // If curr_sib matches with the top vertex - { - bool equalDim = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices - bool addCoface = vertices.size() == 1 && equalDim; - if (addCoface) - cofaces.push_back(simplex); - if ((!addCoface || star) && has_children(simplex)) // Rec call - { // Rec call - Vertex_handle tmp = vertices.back(); - vertices.pop_back(); - rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); - vertices.push_back(tmp); - } - } - else if (simplex->first > vertices.back()) - return; - else // (simplex->first < vertices.back() - if (has_children(simplex)) - rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); - } - } + bool equalDim = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices + bool addCoface = vertices.size() == 1 && equalDim; + if (addCoface) + cofaces.push_back(simplex); + if ((!addCoface || star) && has_children(simplex)) // Rec call + { // Rec call + Vertex_handle tmp = vertices.back(); + vertices.pop_back(); + rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); + vertices.push_back(tmp); + } + } else if (simplex->first > vertices.back()) + return; + else // (simplex->first < vertices.back() + if (has_children(simplex)) + rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); + } } + } -public: - /** \brief Compute the star of a n simplex - * \param simplex represent the simplex of which we search the star - * \return Vector of Simplex_handle, empty vector if no cofaces found. - */ - - Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex) { - return cofaces_simplex_range(simplex, 0); - } - - - - /** \brief Compute the cofaces of a n simplex - * \param simplex represent the n-simplex of which we search the n+codimension cofaces - * \param codimension The function returns the n+codimension-cofaces of the n-simplex. If codimension = 0, return all cofaces (equivalent of star function) - * \return Vector of Simplex_handle, empty vector if no cofaces found. - */ - - Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension) { - Cofaces_simplex_range cofaces; - assert (codimension >= 0); // codimension must be positive or null integer - Simplex_vertex_range rg = simplex_vertex_range(simplex); - std::vector copy(rg.begin(), rg.end()); - if (codimension + (int)copy.size() > dimension_ + 1 || (codimension == 0 && (int)copy.size() > dimension_) ) // n+codimension greater than dimension_ - return cofaces; - assert(std::is_sorted(copy.begin(), copy.end(), std::greater())); // must be sorted in decreasing order - bool star = codimension == 0; - rec_coface(copy, &root_, 1, cofaces, star, codimension + (int)copy.size()); - return cofaces; - } + public: + /** \brief Compute the star of a n simplex + * \param simplex represent the simplex of which we search the star + * \return Vector of Simplex_handle, empty vector if no cofaces found. + */ + Cofaces_simplex_range star_simplex_range(const Simplex_handle simplex) { + return cofaces_simplex_range(simplex, 0); + } + /** \brief Compute the cofaces of a n simplex + * \param simplex represent the n-simplex of which we search the n+codimension cofaces + * \param codimension The function returns the n+codimension-cofaces of the n-simplex. If codimension = 0, + * return all cofaces (equivalent of star function) + * \return Vector of Simplex_handle, empty vector if no cofaces found. + */ + Cofaces_simplex_range cofaces_simplex_range(const Simplex_handle simplex, int codimension) { + Cofaces_simplex_range cofaces; + // codimension must be positive or null integer + assert(codimension >= 0); + Simplex_vertex_range rg = simplex_vertex_range(simplex); + std::vector copy(rg.begin(), rg.end()); + if (codimension + static_cast(copy.size()) > dimension_ + 1 || + (codimension == 0 && static_cast(copy.size()) > dimension_)) // n+codimension greater than dimension_ + return cofaces; + // must be sorted in decreasing order + assert(std::is_sorted(copy.begin(), copy.end(), std::greater())); + bool star = codimension == 0; + rec_coface(copy, &root_, 1, cofaces, star, codimension + static_cast(copy.size())); + return cofaces; + } private: /** \brief Returns true iff the list of vertices of sh1 @@ -717,6 +718,7 @@ public: } return ((it1 == rg1.end()) && (it2 != rg2.end())); } + /** \brief StrictWeakOrdering, for the simplices, defined by the filtration. * * It corresponds to the partial order @@ -724,16 +726,16 @@ public: * Reverse lexicographic order has the property to always consider the subsimplex of a simplex * to be smaller. The filtration function must be monotonic. */ struct is_before_in_filtration { + explicit is_before_in_filtration(Simplex_tree * st) - : st_(st) { - } + : st_(st) { } bool operator()(const Simplex_handle sh1, const Simplex_handle sh2) const { if (st_->filtration(sh1) != st_->filtration(sh2)) { return st_->filtration(sh1) < st_->filtration(sh2); } - return st_->reverse_lexicographic_order(sh1, sh2); // is sh1 a proper subface of sh2 + return st_->reverse_lexicographic_order(sh1, sh2); // is sh1 a proper subface of sh2 } Simplex_tree * st_; @@ -760,7 +762,7 @@ public: * must be undirected_tag. */ template void insert_graph(const OneSkeletonGraph& skel_graph) { - assert(num_simplices() == 0); // the simplex tree must be empty + assert(num_simplices() == 0); // the simplex tree must be empty if (boost::num_vertices(skel_graph) == 0) { return; @@ -778,30 +780,31 @@ public: typename boost::graph_traits::vertex_iterator v_it, v_it_end; for (std::tie(v_it, v_it_end) = boost::vertices(skel_graph); v_it != v_it_end; - ++v_it) { + ++v_it) { root_.members_.emplace_hint( - root_.members_.end(), *v_it, - Node(&root_, boost::get(vertex_filtration_t(), skel_graph, *v_it))); + root_.members_.end(), *v_it, + Node(&root_, boost::get(vertex_filtration_t(), skel_graph, *v_it))); } typename boost::graph_traits::edge_iterator e_it, e_it_end; for (std::tie(e_it, e_it_end) = boost::edges(skel_graph); e_it != e_it_end; - ++e_it) { + ++e_it) { auto u = source(*e_it, skel_graph); auto v = target(*e_it, skel_graph); - if (u < v) { // count edges only once { std::swap(u,v); } // u < v + if (u < v) { // count edges only once { std::swap(u,v); } // u < v auto sh = find_vertex(u); if (!has_children(sh)) { sh->second.assign_children(new Siblings(&root_, sh->first)); } sh->second.children()->members().emplace( - v, - Node(sh->second.children(), - boost::get(edge_filtration_t(), skel_graph, *e_it))); + v, + Node(sh->second.children(), + boost::get(edge_filtration_t(), skel_graph, *e_it))); } } } + /** \brief Expands the Simplex_tree containing only its one skeleton * until dimension max_dim. * @@ -816,7 +819,7 @@ public: void expansion(int max_dim) { dimension_ = max_dim; for (Dictionary_it root_it = root_.members_.begin(); - root_it != root_.members_.end(); ++root_it) { + root_it != root_.members_.end(); ++root_it) { if (has_children(root_it)) { siblings_expansion(root_it->second.children(), max_dim - 1); } @@ -826,8 +829,8 @@ public: private: /** \brief Recursive expansion of the simplex tree.*/ - void siblings_expansion(Siblings * siblings, // must contain elements - int k) { + void siblings_expansion(Siblings * siblings, // must contain elements + int k) { if (dimension_ > k) { dimension_ = k; } @@ -836,33 +839,34 @@ public: Dictionary_it next = siblings->members().begin(); ++next; - static std::vector > inter; // static, not thread-safe. + static std::vector > inter; // static, not thread-safe. for (Dictionary_it s_h = siblings->members().begin(); - s_h != siblings->members().end(); ++s_h, ++next) { + s_h != siblings->members().end(); ++s_h, ++next) { Simplex_handle root_sh = find_vertex(s_h->first); if (has_children(root_sh)) { intersection( - inter, // output intersection - next, // begin - siblings->members().end(), // end - root_sh->second.children()->members().begin(), - root_sh->second.children()->members().end(), - s_h->second.filtration()); + inter, // output intersection + next, // begin + siblings->members().end(), // end + root_sh->second.children()->members().begin(), + root_sh->second.children()->members().end(), + s_h->second.filtration()); if (inter.size() != 0) { this->num_simplices_ += inter.size(); - Siblings * new_sib = new Siblings(siblings, // oncles - s_h->first, // parent - inter); // boost::container::ordered_unique_range_t + Siblings * new_sib = new Siblings(siblings, // oncles + s_h->first, // parent + inter); // boost::container::ordered_unique_range_t inter.clear(); s_h->second.assign_children(new_sib); siblings_expansion(new_sib, k - 1); } else { - s_h->second.assign_children(siblings); // ensure the children property + s_h->second.assign_children(siblings); // ensure the children property inter.clear(); } } } } + /** \brief Intersects Dictionary 1 [begin1;end1) with Dictionary 2 [begin2,end2) * and assigns the maximal possible Filtration_value to the Nodes. */ static void intersection(std::vector >& intersection, @@ -870,17 +874,17 @@ public: Dictionary_it begin2, Dictionary_it end2, Filtration_value filtration) { if (begin1 == end1 || begin2 == end2) - return; // ----->> + return; // ----->> while (true) { if (begin1->first == begin2->first) { intersection.push_back( - std::pair( - begin1->first, - Node(NULL, maximum(begin1->second.filtration(), begin2->second.filtration(), filtration)))); + std::pair( + begin1->first, + Node(NULL, maximum(begin1->second.filtration(), begin2->second.filtration(), filtration)))); ++begin1; ++begin2; if (begin1 == end1 || begin2 == end2) - return; // ----->> + return; // ----->> } else { if (begin1->first < begin2->first) { ++begin1; @@ -889,11 +893,12 @@ public: } else { ++begin2; if (begin2 == end2) - return; // ----->> + return; // ----->> } } } } + /** Maximum over 3 values.*/ static Filtration_value maximum(Filtration_value a, Filtration_value b, Filtration_value c) { @@ -934,6 +939,7 @@ public: }; // Print a Simplex_tree in os. + template std::ostream& operator<<(std::ostream & os, Simplex_tree & st) { for (auto sh : st.filtration_simplex_range()) { @@ -941,10 +947,11 @@ std::ostream& operator<<(std::ostream & os, Simplex_tree & st) { for (auto v : st.simplex_vertex_range(sh)) { os << v << " "; } - os << st.filtration(sh) << "\n"; // TODO(VR): why adding the key ?? not read ?? << " " << st.key(sh) << " \n"; + os << st.filtration(sh) << "\n"; // TODO(VR): why adding the key ?? not read ?? << " " << st.key(sh) << " \n"; } return os; } + template std::istream& operator>>(std::istream & is, Simplex_tree & st) { // assert(st.num_simplices() == 0); @@ -954,16 +961,16 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { typename Simplex_tree::Filtration_value max_fil = 0; int max_dim = -1; size_t num_simplices = 0; - while (read_simplex(is, simplex, fil)) { // read all simplices in the file as a list of vertices + while (read_simplex(is, simplex, fil)) { // read all simplices in the file as a list of vertices ++num_simplices; - int dim = static_cast(simplex.size() - 1); // Warning : simplex_size needs to be casted in int - Can be 0 + int dim = static_cast (simplex.size() - 1); // Warning : simplex_size needs to be casted in int - Can be 0 if (max_dim < dim) { max_dim = dim; } if (max_fil < fil) { max_fil = fil; } - st.insert_simplex(simplex, fil); // insert every simplex in the simplex tree + st.insert_simplex(simplex, fil); // insert every simplex in the simplex tree simplex.clear(); } st.set_num_simplices(num_simplices); @@ -972,8 +979,8 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { return is; } +/** @} */ // end defgroup simplex_tree -/** @} */ // end defgroup simplex_tree } // namespace Gudhi #endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_H_ diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 55a055a0..7f2172a2 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -23,10 +23,9 @@ typedef std::pair typePairSimplexBool; typedef std::vector typeVectorVertex; typedef std::pair typeSimplex; -const Vertex_handle DEFAULT_VERTEX_HANDLE = (const Vertex_handle) -1; +const Vertex_handle DEFAULT_VERTEX_HANDLE = (const Vertex_handle) - 1; const Filtration_value DEFAULT_FILTRATION_VALUE = (const Filtration_value) 0.0; - void test_empty_simplex_tree(typeST& tst) { BOOST_CHECK(tst.null_vertex() == DEFAULT_VERTEX_HANDLE); BOOST_CHECK(tst.filtration() == DEFAULT_FILTRATION_VALUE); @@ -39,30 +38,28 @@ void test_empty_simplex_tree(typeST& tst) { BOOST_CHECK(tst.dimension() == -1); } - void test_iterators_on_empty_simplex_tree(typeST& tst) { std::cout << "Iterator on vertices: " << std::endl; for (auto vertex : tst.complex_vertex_range()) { std::cout << "vertice:" << vertex << std::endl; - BOOST_CHECK(false); // shall be empty + BOOST_CHECK(false); // shall be empty } std::cout << "Iterator on simplices: " << std::endl; for (auto simplex : tst.complex_simplex_range()) { - BOOST_CHECK(simplex != simplex); // shall be empty - to remove warning of non-used simplex + BOOST_CHECK(simplex != simplex); // shall be empty - to remove warning of non-used simplex } std::cout << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; for (auto f_simplex : tst.filtration_simplex_range()) { - BOOST_CHECK(false); // shall be empty + BOOST_CHECK(false); // shall be empty std::cout << "test_iterators_on_empty_simplex_tree - filtration=" << tst.filtration(f_simplex) << std::endl; } } -BOOST_AUTO_TEST_CASE( simplex_tree_when_empty ) -{ +BOOST_AUTO_TEST_CASE(simplex_tree_when_empty) { const Filtration_value DEFAULT_FILTRATION_VALUE = 0; // TEST OF DEFAULT CONSTRUCTOR @@ -70,29 +67,28 @@ BOOST_AUTO_TEST_CASE( simplex_tree_when_empty ) std::cout << "TEST OF DEFAULT CONSTRUCTOR" << std::endl; typeST st; - test_empty_simplex_tree (st); + test_empty_simplex_tree(st); - test_iterators_on_empty_simplex_tree (st); + test_iterators_on_empty_simplex_tree(st); // TEST OF EMPTY INSERTION std::cout << "TEST OF EMPTY INSERTION" << std::endl; typeVectorVertex simplexVectorEmpty; BOOST_CHECK(simplexVectorEmpty.empty() == true); typePairSimplexBool returnEmptyValue = st.insert_simplex(simplexVectorEmpty, - DEFAULT_FILTRATION_VALUE); + DEFAULT_FILTRATION_VALUE); BOOST_CHECK(returnEmptyValue.first == typeST::Simplex_handle(NULL)); BOOST_CHECK(returnEmptyValue.second == true); - test_empty_simplex_tree (st); + test_empty_simplex_tree(st); - test_iterators_on_empty_simplex_tree (st); + test_iterators_on_empty_simplex_tree(st); } 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(simplex_tree_from_file) { // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; std::cout << "TEST OF SIMPLEX TREE FROM A FILE" << std::endl; @@ -112,16 +108,14 @@ BOOST_AUTO_TEST_CASE( simplex_tree_from_file ) BOOST_CHECK(st.filtration() == 0.4); int previous_size = 0; - for( auto f_simplex : st.filtration_simplex_range() ) - { + for (auto f_simplex : st.filtration_simplex_range()) { // Size of simplex int size = 0; - for( auto vertex : st.simplex_vertex_range(f_simplex) ) - { + for (auto vertex : st.simplex_vertex_range(f_simplex)) { size++; } - BOOST_CHECK(AreAlmostTheSame(st.filtration(f_simplex),(0.1* size))); // Specific test: filtration = 0.1 * simplex_size - BOOST_CHECK(previous_size <= size);// Check list is sorted (because of sorted filtrations in simplex_tree.txt) + BOOST_CHECK(AreAlmostTheSame(st.filtration(f_simplex), (0.1 * size))); // Specific test: filtration = 0.1 * simplex_size + BOOST_CHECK(previous_size <= size); // Check list is sorted (because of sorted filtrations in simplex_tree.txt) previous_size = size; } simplex_tree_stream.close(); @@ -131,13 +125,12 @@ void test_simplex_tree_contains(typeST& simplexTree, typeSimplex& simplex, int p auto f_simplex = simplexTree.filtration_simplex_range().begin() + pos; std::cout << "test_simplex_tree_contains - filtration=" << simplexTree.filtration(*f_simplex) << "||" << simplex.second << std::endl; - BOOST_CHECK( AreAlmostTheSame(simplexTree.filtration(*f_simplex),simplex.second) ); + BOOST_CHECK(AreAlmostTheSame(simplexTree.filtration(*f_simplex), simplex.second)); - int simplexIndex=simplex.first.size()-1; - for( auto vertex : simplexTree.simplex_vertex_range(*f_simplex) ) - { + int simplexIndex = simplex.first.size() - 1; + for (auto vertex : simplexTree.simplex_vertex_range(*f_simplex)) { std::cout << "test_simplex_tree_contains - vertex=" << vertex << "||" << simplex.first.at(simplexIndex) << std::endl; - BOOST_CHECK(vertex == simplex.first.at(simplexIndex)); + BOOST_CHECK(vertex == simplex.first.at(simplexIndex)); BOOST_CHECK(simplexIndex >= 0); simplexIndex--; } @@ -145,7 +138,7 @@ void test_simplex_tree_contains(typeST& simplexTree, typeSimplex& simplex, int p 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 + typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator BOOST_CHECK(shReturned != typeST::Simplex_handle(NULL)); } @@ -175,24 +168,22 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons } void test_cofaces(typeST& st, std::vector v, int dim, std::vector res) { - typeST::Cofaces_simplex_range cofaces; - if (dim == 0) - cofaces = st.star_simplex_range(st.find(v)); - else - cofaces = st.cofaces_simplex_range(st.find(v), dim); - for (auto simplex = cofaces.begin(); simplex != cofaces.end(); ++simplex) - { - typeST::Simplex_vertex_range rg = st.simplex_vertex_range(*simplex); - for (auto vertex = rg.begin(); vertex != rg.end(); ++vertex) { - std::cout << "(" << *vertex << ")" ; - } - std::cout << std::endl; - BOOST_CHECK(std::find(res.begin(), res.end(), *simplex)!=res.end()); - } + typeST::Cofaces_simplex_range cofaces; + if (dim == 0) + cofaces = st.star_simplex_range(st.find(v)); + else + cofaces = st.cofaces_simplex_range(st.find(v), dim); + for (auto simplex = cofaces.begin(); simplex != cofaces.end(); ++simplex) { + typeST::Simplex_vertex_range rg = st.simplex_vertex_range(*simplex); + for (auto vertex = rg.begin(); vertex != rg.end(); ++vertex) { + std::cout << "(" << *vertex << ")"; + } + std::cout << std::endl; + BOOST_CHECK(std::find(res.begin(), res.end(), *simplex) != res.end()); + } } -BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) -{ +BOOST_AUTO_TEST_CASE(simplex_tree_insertion) { const Filtration_value FIRST_FILTRATION_VALUE = 0.1; const Filtration_value SECOND_FILTRATION_VALUE = 0.2; const Filtration_value THIRD_FILTRATION_VALUE = 0.3; @@ -211,88 +202,88 @@ BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) std::cout << " - INSERT 0" << std::endl; typeVectorVertex firstSimplexVector; firstSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( firstSimplexVector.size() == 1 ); + BOOST_CHECK(firstSimplexVector.size() == 1); typeSimplex firstSimplex = std::make_pair( - firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); typePairSimplexBool returnValue = st.insert_simplex(firstSimplex.first, - firstSimplex.second); + 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 ); + BOOST_CHECK(st.num_vertices() == (size_t) 1); // ++ SECOND std::cout << " - INSERT 1" << std::endl; typeVectorVertex secondSimplexVector; secondSimplexVector.push_back(SECOND_VERTEX_HANDLE); - BOOST_CHECK( secondSimplexVector.size() == 1 ); + BOOST_CHECK(secondSimplexVector.size() == 1); typeSimplex secondSimplex = std::make_pair( - secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( secondSimplex.first, secondSimplex.second ); + 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 ); + BOOST_CHECK(st.num_vertices() == (size_t) 2); // ++ THIRD std::cout << " - INSERT (0,1)" << std::endl; typeVectorVertex thirdSimplexVector; thirdSimplexVector.push_back(FIRST_VERTEX_HANDLE); thirdSimplexVector.push_back(SECOND_VERTEX_HANDLE); - BOOST_CHECK( thirdSimplexVector.size() == 2 ); + BOOST_CHECK(thirdSimplexVector.size() == 2); typeSimplex thirdSimplex = std::make_pair( - thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( thirdSimplex.first, thirdSimplex.second ); + 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 !! + BOOST_CHECK(st.num_vertices() == (size_t) 2); // Not incremented !! // ++ FOURTH std::cout << " - INSERT 2" << std::endl; typeVectorVertex fourthSimplexVector; fourthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - BOOST_CHECK( fourthSimplexVector.size() == 1 ); + BOOST_CHECK(fourthSimplexVector.size() == 1); typeSimplex fourthSimplex = std::make_pair( - fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( fourthSimplex.first, fourthSimplex.second ); + 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 ); + BOOST_CHECK(st.num_vertices() == (size_t) 3); // ++ FIFTH std::cout << " - INSERT (2,0)" << std::endl; typeVectorVertex fifthSimplexVector; fifthSimplexVector.push_back(THIRD_VERTEX_HANDLE); fifthSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( fifthSimplexVector.size() == 2 ); + BOOST_CHECK(fifthSimplexVector.size() == 2); typeSimplex fifthSimplex = std::make_pair( - fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( fifthSimplex.first, fifthSimplex.second ); + 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 !! + BOOST_CHECK(st.num_vertices() == (size_t) 3); // Not incremented !! // ++ SIXTH std::cout << " - INSERT (2,1)" << std::endl; typeVectorVertex sixthSimplexVector; sixthSimplexVector.push_back(THIRD_VERTEX_HANDLE); sixthSimplexVector.push_back(SECOND_VERTEX_HANDLE); - BOOST_CHECK( sixthSimplexVector.size() == 2 ); + BOOST_CHECK(sixthSimplexVector.size() == 2); typeSimplex sixthSimplex = std::make_pair( - sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( sixthSimplex.first, sixthSimplex.second ); + 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 !! + BOOST_CHECK(st.num_vertices() == (size_t) 3); // Not incremented !! // ++ SEVENTH std::cout << " - INSERT (2,1,0)" << std::endl; @@ -300,61 +291,61 @@ BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) seventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); seventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); seventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( seventhSimplexVector.size() == 3 ); + BOOST_CHECK(seventhSimplexVector.size() == 3); typeSimplex seventhSimplex = std::make_pair( - seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); + seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( seventhSimplex.first, seventhSimplex.second ); + 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 !! + BOOST_CHECK(st.num_vertices() == (size_t) 3); // Not incremented !! // ++ EIGHTH std::cout << " - INSERT 3" << std::endl; typeVectorVertex eighthSimplexVector; eighthSimplexVector.push_back(FOURTH_VERTEX_HANDLE); - BOOST_CHECK( eighthSimplexVector.size() == 1 ); + BOOST_CHECK(eighthSimplexVector.size() == 1); typeSimplex eighthSimplex = std::make_pair( - eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( eighthSimplex.first, eighthSimplex.second ); + 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 ); + BOOST_CHECK(st.num_vertices() == (size_t) 4); // ++ NINETH std::cout << " - INSERT (3,0)" << std::endl; typeVectorVertex ninethSimplexVector; ninethSimplexVector.push_back(FOURTH_VERTEX_HANDLE); ninethSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( ninethSimplexVector.size() == 2 ); + BOOST_CHECK(ninethSimplexVector.size() == 2); typeSimplex ninethSimplex = std::make_pair( - ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( ninethSimplex.first, ninethSimplex.second ); + 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 !! + BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented !! // ++ TENTH std::cout << " - INSERT 0 (already inserted)" << std::endl; typeVectorVertex tenthSimplexVector; tenthSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( tenthSimplexVector.size() == 1 ); + BOOST_CHECK(tenthSimplexVector.size() == 1); typeSimplex tenthSimplex = std::make_pair( - tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value + tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value returnValue = - st.insert_simplex ( tenthSimplex.first, tenthSimplex.second ); + 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 + typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented !! - BOOST_CHECK( st.dimension() == dim_max ); - BOOST_CHECK( AreAlmostTheSame(st.filtration(), max_fil) ); + BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented !! + BOOST_CHECK(st.dimension() == dim_max); + BOOST_CHECK(AreAlmostTheSame(st.filtration(), max_fil)); // ++ ELEVENTH std::cout << " - INSERT (2,1,0) (already inserted)" << std::endl; @@ -362,18 +353,18 @@ BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) eleventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); eleventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); eleventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( eleventhSimplexVector.size() == 3 ); + BOOST_CHECK(eleventhSimplexVector.size() == 3); typeSimplex eleventhSimplex = std::make_pair( - eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); + eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); returnValue = - st.insert_simplex ( eleventhSimplex.first, eleventhSimplex.second ); + st.insert_simplex(eleventhSimplex.first, eleventhSimplex.second); BOOST_CHECK(returnValue.second == false); - shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); - BOOST_CHECK( st.num_vertices() == (size_t)4 );// Not incremented !! - BOOST_CHECK( st.dimension() == dim_max ); - BOOST_CHECK( AreAlmostTheSame(st.filtration(), max_fil) ); + BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented !! + BOOST_CHECK(st.dimension() == dim_max); + BOOST_CHECK(AreAlmostTheSame(st.filtration(), max_fil)); /* Inserted simplex: */ /* 1 */ @@ -393,330 +384,325 @@ BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) // [0.3] 2 1 0 // !! Be careful, simplex are sorted by filtration value on insertion !! std::cout << "simplex_tree_insertion - first - 0" << std::endl; - test_simplex_tree_contains(st, firstSimplex, 0);// (0) -> 0 + test_simplex_tree_contains(st, firstSimplex, 0); // (0) -> 0 std::cout << "simplex_tree_insertion - second - 1" << std::endl; - test_simplex_tree_contains(st, secondSimplex, 1);// (1) -> 1 + test_simplex_tree_contains(st, secondSimplex, 1); // (1) -> 1 std::cout << "simplex_tree_insertion - third - 4" << std::endl; - test_simplex_tree_contains(st, thirdSimplex, 4);// (0,1) -> 4 + test_simplex_tree_contains(st, thirdSimplex, 4); // (0,1) -> 4 std::cout << "simplex_tree_insertion - fourth - 2" << std::endl; - test_simplex_tree_contains(st, fourthSimplex, 2);// (2) -> 2 + test_simplex_tree_contains(st, fourthSimplex, 2); // (2) -> 2 std::cout << "simplex_tree_insertion - fifth - 5" << std::endl; - test_simplex_tree_contains(st, fifthSimplex, 5);// (2,0) -> 5 + test_simplex_tree_contains(st, fifthSimplex, 5); // (2,0) -> 5 std::cout << "simplex_tree_insertion - sixth - 6" << std::endl; - test_simplex_tree_contains(st, sixthSimplex, 6);//(2,1) -> 6 + test_simplex_tree_contains(st, sixthSimplex, 6); //(2,1) -> 6 std::cout << "simplex_tree_insertion - seventh - 8" << std::endl; - test_simplex_tree_contains(st, seventhSimplex, 8);// (2,1,0) -> 8 + test_simplex_tree_contains(st, seventhSimplex, 8); // (2,1,0) -> 8 std::cout << "simplex_tree_insertion - eighth - 3" << std::endl; - test_simplex_tree_contains(st, eighthSimplex, 3);// (3) -> 3 + test_simplex_tree_contains(st, eighthSimplex, 3); // (3) -> 3 std::cout << "simplex_tree_insertion - nineth - 7" << std::endl; - test_simplex_tree_contains(st, ninethSimplex, 7);// (3,0) -> 7 + test_simplex_tree_contains(st, ninethSimplex, 7); // (3,0) -> 7 // Display the Simplex_tree - Can not be done in the middle of 2 inserts std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - for( auto f_simplex : st.filtration_simplex_range() ) - { + for (auto f_simplex : st.filtration_simplex_range()) { std::cout << " " << "[" << st.filtration(f_simplex) << "] "; - for( auto vertex : st.simplex_vertex_range(f_simplex) ) - { - std::cout << (int)vertex << " "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << (int) vertex << " "; } std::cout << std::endl; } } -BOOST_AUTO_TEST_CASE( NSimplexAndSubfaces_tree_insertion ) -{ - Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle)0; - Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle) 1; - Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle) 2; - Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle) 3; - Vertex_handle FIFTH_VERTEX_HANDLE = (Vertex_handle) 4; - Vertex_handle SIXTH_VERTEX_HANDLE = (Vertex_handle) 5; - Vertex_handle SEVENTH_VERTEX_HANDLE = (Vertex_handle) 6; - Vertex_handle EIGHTH_VERTEX_HANDLE = (Vertex_handle) 7; - - // TEST OF INSERTION - std::cout << "********************************************************************" << std::endl; - std::cout << "TEST OF INSERTION" << std::endl; - typeST st; - - // ++ FIRST - std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex SimplexVector1; - SimplexVector1.push_back(THIRD_VERTEX_HANDLE); - SimplexVector1.push_back(SECOND_VERTEX_HANDLE); - SimplexVector1.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector1.size() == 3 ); - st.insert_simplex_and_subfaces ( SimplexVector1 ); - - BOOST_CHECK( st.num_vertices() == (size_t)3 ); // +3 (2, 1 and 0 are not existing) - - // ++ SECOND - std::cout << " - INSERT 3" << std::endl; - typeVectorVertex SimplexVector2; - SimplexVector2.push_back(FOURTH_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector2.size() == 1 ); - st.insert_simplex_and_subfaces ( SimplexVector2 ); - - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // +1 (3 is not existing) - - // ++ THIRD - std::cout << " - INSERT (0,3)" << std::endl; - typeVectorVertex SimplexVector3; - SimplexVector3.push_back(FOURTH_VERTEX_HANDLE); - SimplexVector3.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector3.size() == 2 ); - st.insert_simplex_and_subfaces ( SimplexVector3 ); - - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented (all are existing) - - // ++ FOURTH - std::cout << " - INSERT (1,0) (already inserted)" << std::endl; - typeVectorVertex SimplexVector4; - SimplexVector4.push_back(SECOND_VERTEX_HANDLE); - SimplexVector4.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector4.size() == 2 ); - st.insert_simplex_and_subfaces ( SimplexVector4 ); - - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented (all are existing) - - // ++ FIFTH - std::cout << " - INSERT (3,4,5)" << std::endl; - typeVectorVertex SimplexVector5; - SimplexVector5.push_back(FOURTH_VERTEX_HANDLE); - SimplexVector5.push_back(FIFTH_VERTEX_HANDLE); - SimplexVector5.push_back(SIXTH_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector5.size() == 3 ); - st.insert_simplex_and_subfaces ( SimplexVector5 ); - - BOOST_CHECK( st.num_vertices() == (size_t)6 ); - - // ++ SIXTH - std::cout << " - INSERT (0,1,6,7)" << std::endl; - typeVectorVertex SimplexVector6; - SimplexVector6.push_back(FIRST_VERTEX_HANDLE); - SimplexVector6.push_back(SECOND_VERTEX_HANDLE); - SimplexVector6.push_back(SEVENTH_VERTEX_HANDLE); - SimplexVector6.push_back(EIGHTH_VERTEX_HANDLE); - BOOST_CHECK( SimplexVector6.size() == 4 ); - st.insert_simplex_and_subfaces ( SimplexVector6 ); - - BOOST_CHECK( st.num_vertices() == (size_t)8 ); // +2 (6 and 7 are not existing - 0 and 1 are already existing) - - /* Inserted simplex: */ - /* 1 6 */ - /* o---o */ - /* /X\7/ */ - /* o---o---o---o */ - /* 2 0 3\X/4 */ - /* o */ - /* 5 */ - /* */ - /* In other words: */ - /* A facet [2,1,0] */ - /* An edge [0,3] */ - /* A facet [3,4,5] */ - /* A cell [0,1,6,7] */ - - typeSimplex simplexPair1 = std::make_pair(SimplexVector1, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair2 = std::make_pair(SimplexVector2, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair3 = std::make_pair(SimplexVector3, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair4 = std::make_pair(SimplexVector4, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair5 = std::make_pair(SimplexVector5, DEFAULT_FILTRATION_VALUE); - typeSimplex simplexPair6 = std::make_pair(SimplexVector6, DEFAULT_FILTRATION_VALUE); - test_simplex_tree_contains(st,simplexPair1,6); // (2,1,0) is in position 6 - test_simplex_tree_contains(st,simplexPair2,7); // (3) is in position 7 - test_simplex_tree_contains(st,simplexPair3,8); // (3,0) is in position 8 - test_simplex_tree_contains(st,simplexPair4,2); // (1,0) is in position 2 - test_simplex_tree_contains(st,simplexPair5,14); // (3,4,5) is in position 14 - test_simplex_tree_contains(st,simplexPair6,26); // (7,6,1,0) is in position 26 - - // ------------------------------------------------------------------------------------------------------------------ - // Find in the simplex_tree - // ------------------------------------------------------------------------------------------------------------------ - typeVectorVertex simpleSimplexVector; - simpleSimplexVector.push_back(SECOND_VERTEX_HANDLE); - Simplex_tree<>::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"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is found - BOOST_CHECK(simplexFound != st.null_simplex()); - - Vertex_handle UNKNOWN_VERTEX_HANDLE = (Vertex_handle) 15; - typeVectorVertex unknownSimplexVector; - unknownSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); - simplexFound = st.find(unknownSimplexVector); - std::cout << "**************IS THE SIMPLEX {15} IN THE SIMPLEX TREE ?\n"; - if (simplexFound != st.null_simplex()) - std::cout << "***+ YES IT IS!\n"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is NOT found - BOOST_CHECK(simplexFound == st.null_simplex()); - - simplexFound = st.find(SimplexVector6); - std::cout << "**************IS THE SIMPLEX {0,1,6,7} IN THE SIMPLEX TREE ?\n"; - if (simplexFound != st.null_simplex()) - std::cout << "***+ YES IT IS!\n"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is found - BOOST_CHECK(simplexFound != st.null_simplex()); - - typeVectorVertex otherSimplexVector; - otherSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); - otherSimplexVector.push_back(SECOND_VERTEX_HANDLE); - simplexFound = st.find(otherSimplexVector); - std::cout << "**************IS THE SIMPLEX {15,1} IN THE SIMPLEX TREE ?\n"; - if (simplexFound != st.null_simplex()) - std::cout << "***+ YES IT IS!\n"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is NOT found - BOOST_CHECK(simplexFound == st.null_simplex()); - - typeVectorVertex invSimplexVector; - invSimplexVector.push_back(SECOND_VERTEX_HANDLE); - invSimplexVector.push_back(THIRD_VERTEX_HANDLE); - invSimplexVector.push_back(FIRST_VERTEX_HANDLE); - simplexFound = st.find(invSimplexVector); - std::cout << "**************IS THE SIMPLEX {1,2,0} IN THE SIMPLEX TREE ?\n"; - if (simplexFound != st.null_simplex()) - std::cout << "***+ YES IT IS!\n"; - else - std::cout << "***- NO IT ISN'T\n"; - // Check it is found - BOOST_CHECK(simplexFound != st.null_simplex()); - - - - // Display the Simplex_tree - Can not be done in the middle of 2 inserts - std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; - std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - for( auto f_simplex : st.filtration_simplex_range() ) - { - std::cout << " " << "[" << st.filtration(f_simplex) << "] "; - for( auto vertex : st.simplex_vertex_range(f_simplex) ) - { - std::cout << (int)vertex << " "; - } - std::cout << std::endl; - } - - std::cout << "********************************************************************" << std::endl; - // TEST COFACE ALGORITHM - st.set_dimension(3); - std::cout << "COFACE ALGORITHM" << std::endl; - std::vector v; - std::vector simplex; - std::vector result; - v.push_back(3); - std::cout << "First test : " << std::endl; - std::cout << "Star of (3):" << std::endl; - - simplex.push_back(3); - result.push_back(st.find(simplex)); - simplex.clear(); - - simplex.push_back(3); - simplex.push_back(0); - result.push_back(st.find(simplex)); - simplex.clear(); - - simplex.push_back(4); - simplex.push_back(3); - result.push_back(st.find(simplex)); - simplex.clear(); - - simplex.push_back(5); - simplex.push_back(4); - simplex.push_back(3); - result.push_back(st.find(simplex)); - simplex.clear(); - - simplex.push_back(5); - simplex.push_back(3); - result.push_back(st.find(simplex)); - simplex.clear(); - - test_cofaces(st, v, 0, result); - v.clear(); - result.clear(); - - v.push_back(1); - v.push_back(7); - std::cout << "Second test : " << std::endl; - std::cout << "Star of (1,7): " << std::endl; - - simplex.push_back(7); - simplex.push_back(1); - result.push_back(st.find(simplex)); - simplex.clear(); - - simplex.push_back(7); - simplex.push_back(6); - simplex.push_back(1); - simplex.push_back(0); - result.push_back(st.find(simplex)); - simplex.clear(); - - simplex.push_back(7); - simplex.push_back(1); - simplex.push_back(0); - result.push_back(st.find(simplex)); - simplex.clear(); - - simplex.push_back(7); - simplex.push_back(6); - simplex.push_back(1); - result.push_back(st.find(simplex)); - simplex.clear(); - - test_cofaces(st, v, 0, result); - result.clear(); - - std::cout << "Third test : " << std::endl; - std::cout << "2-dimension Cofaces of simplex(1,7) : " << std::endl; - - simplex.push_back(7); - simplex.push_back(1); - simplex.push_back(0); - result.push_back(st.find(simplex)); - simplex.clear(); - - simplex.push_back(7); - simplex.push_back(6); - simplex.push_back(1); - result.push_back(st.find(simplex)); - simplex.clear(); - - test_cofaces(st, v, 1, result); - result.clear(); - - std::cout << "Cofaces with a codimension too high (codimension + vetices > tree.dimension) :" << std::endl; - test_cofaces(st, v, 5, result); -// std::cout << "Cofaces with an empty codimension" << std::endl; -// test_cofaces(st, v, -1, result); -// std::cout << "Cofaces in an empty simplex tree" << std::endl; -// typeST empty_tree; -// test_cofaces(empty_tree, v, 1, result); -// std::cout << "Cofaces of an empty simplex" << std::endl; -// v.clear(); -// test_cofaces(st, v, 1, result); - - /* - // TEST Off read - std::cout << "********************************************************************" << std::endl; - typeST st2; - st2.tree_from_off("test.off"); - std::cout << st2; - */ +BOOST_AUTO_TEST_CASE(NSimplexAndSubfaces_tree_insertion) { + Vertex_handle FIRST_VERTEX_HANDLE = (Vertex_handle) 0; + Vertex_handle SECOND_VERTEX_HANDLE = (Vertex_handle) 1; + Vertex_handle THIRD_VERTEX_HANDLE = (Vertex_handle) 2; + Vertex_handle FOURTH_VERTEX_HANDLE = (Vertex_handle) 3; + Vertex_handle FIFTH_VERTEX_HANDLE = (Vertex_handle) 4; + Vertex_handle SIXTH_VERTEX_HANDLE = (Vertex_handle) 5; + Vertex_handle SEVENTH_VERTEX_HANDLE = (Vertex_handle) 6; + Vertex_handle EIGHTH_VERTEX_HANDLE = (Vertex_handle) 7; + + // TEST OF INSERTION + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF INSERTION" << std::endl; + typeST st; + + // ++ FIRST + std::cout << " - INSERT (2,1,0)" << std::endl; + typeVectorVertex SimplexVector1; + SimplexVector1.push_back(THIRD_VERTEX_HANDLE); + SimplexVector1.push_back(SECOND_VERTEX_HANDLE); + SimplexVector1.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK(SimplexVector1.size() == 3); + st.insert_simplex_and_subfaces(SimplexVector1); + + BOOST_CHECK(st.num_vertices() == (size_t) 3); // +3 (2, 1 and 0 are not existing) + + // ++ SECOND + std::cout << " - INSERT 3" << std::endl; + typeVectorVertex SimplexVector2; + SimplexVector2.push_back(FOURTH_VERTEX_HANDLE); + BOOST_CHECK(SimplexVector2.size() == 1); + st.insert_simplex_and_subfaces(SimplexVector2); + + BOOST_CHECK(st.num_vertices() == (size_t) 4); // +1 (3 is not existing) + + // ++ THIRD + std::cout << " - INSERT (0,3)" << std::endl; + typeVectorVertex SimplexVector3; + SimplexVector3.push_back(FOURTH_VERTEX_HANDLE); + SimplexVector3.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK(SimplexVector3.size() == 2); + st.insert_simplex_and_subfaces(SimplexVector3); + + BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented (all are existing) + + // ++ FOURTH + std::cout << " - INSERT (1,0) (already inserted)" << std::endl; + typeVectorVertex SimplexVector4; + SimplexVector4.push_back(SECOND_VERTEX_HANDLE); + SimplexVector4.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK(SimplexVector4.size() == 2); + st.insert_simplex_and_subfaces(SimplexVector4); + + BOOST_CHECK(st.num_vertices() == (size_t) 4); // Not incremented (all are existing) + + // ++ FIFTH + std::cout << " - INSERT (3,4,5)" << std::endl; + typeVectorVertex SimplexVector5; + SimplexVector5.push_back(FOURTH_VERTEX_HANDLE); + SimplexVector5.push_back(FIFTH_VERTEX_HANDLE); + SimplexVector5.push_back(SIXTH_VERTEX_HANDLE); + BOOST_CHECK(SimplexVector5.size() == 3); + st.insert_simplex_and_subfaces(SimplexVector5); + + BOOST_CHECK(st.num_vertices() == (size_t) 6); + + // ++ SIXTH + std::cout << " - INSERT (0,1,6,7)" << std::endl; + typeVectorVertex SimplexVector6; + SimplexVector6.push_back(FIRST_VERTEX_HANDLE); + SimplexVector6.push_back(SECOND_VERTEX_HANDLE); + SimplexVector6.push_back(SEVENTH_VERTEX_HANDLE); + SimplexVector6.push_back(EIGHTH_VERTEX_HANDLE); + BOOST_CHECK(SimplexVector6.size() == 4); + st.insert_simplex_and_subfaces(SimplexVector6); + + BOOST_CHECK(st.num_vertices() == (size_t) 8); // +2 (6 and 7 are not existing - 0 and 1 are already existing) + + /* Inserted simplex: */ + /* 1 6 */ + /* o---o */ + /* /X\7/ */ + /* o---o---o---o */ + /* 2 0 3\X/4 */ + /* o */ + /* 5 */ + /* */ + /* In other words: */ + /* A facet [2,1,0] */ + /* An edge [0,3] */ + /* A facet [3,4,5] */ + /* A cell [0,1,6,7] */ + + typeSimplex simplexPair1 = std::make_pair(SimplexVector1, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair2 = std::make_pair(SimplexVector2, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair3 = std::make_pair(SimplexVector3, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair4 = std::make_pair(SimplexVector4, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair5 = std::make_pair(SimplexVector5, DEFAULT_FILTRATION_VALUE); + typeSimplex simplexPair6 = std::make_pair(SimplexVector6, DEFAULT_FILTRATION_VALUE); + test_simplex_tree_contains(st, simplexPair1, 6); // (2,1,0) is in position 6 + test_simplex_tree_contains(st, simplexPair2, 7); // (3) is in position 7 + test_simplex_tree_contains(st, simplexPair3, 8); // (3,0) is in position 8 + test_simplex_tree_contains(st, simplexPair4, 2); // (1,0) is in position 2 + test_simplex_tree_contains(st, simplexPair5, 14); // (3,4,5) is in position 14 + test_simplex_tree_contains(st, simplexPair6, 26); // (7,6,1,0) is in position 26 + + // ------------------------------------------------------------------------------------------------------------------ + // Find in the simplex_tree + // ------------------------------------------------------------------------------------------------------------------ + typeVectorVertex simpleSimplexVector; + simpleSimplexVector.push_back(SECOND_VERTEX_HANDLE); + Simplex_tree<>::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"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is found + BOOST_CHECK(simplexFound != st.null_simplex()); + + Vertex_handle UNKNOWN_VERTEX_HANDLE = (Vertex_handle) 15; + typeVectorVertex unknownSimplexVector; + unknownSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); + simplexFound = st.find(unknownSimplexVector); + std::cout << "**************IS THE SIMPLEX {15} IN THE SIMPLEX TREE ?\n"; + if (simplexFound != st.null_simplex()) + std::cout << "***+ YES IT IS!\n"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is NOT found + BOOST_CHECK(simplexFound == st.null_simplex()); + + simplexFound = st.find(SimplexVector6); + std::cout << "**************IS THE SIMPLEX {0,1,6,7} IN THE SIMPLEX TREE ?\n"; + if (simplexFound != st.null_simplex()) + std::cout << "***+ YES IT IS!\n"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is found + BOOST_CHECK(simplexFound != st.null_simplex()); + + typeVectorVertex otherSimplexVector; + otherSimplexVector.push_back(UNKNOWN_VERTEX_HANDLE); + otherSimplexVector.push_back(SECOND_VERTEX_HANDLE); + simplexFound = st.find(otherSimplexVector); + std::cout << "**************IS THE SIMPLEX {15,1} IN THE SIMPLEX TREE ?\n"; + if (simplexFound != st.null_simplex()) + std::cout << "***+ YES IT IS!\n"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is NOT found + BOOST_CHECK(simplexFound == st.null_simplex()); + + typeVectorVertex invSimplexVector; + invSimplexVector.push_back(SECOND_VERTEX_HANDLE); + invSimplexVector.push_back(THIRD_VERTEX_HANDLE); + invSimplexVector.push_back(FIRST_VERTEX_HANDLE); + simplexFound = st.find(invSimplexVector); + std::cout << "**************IS THE SIMPLEX {1,2,0} IN THE SIMPLEX TREE ?\n"; + if (simplexFound != st.null_simplex()) + std::cout << "***+ YES IT IS!\n"; + else + std::cout << "***- NO IT ISN'T\n"; + // Check it is found + BOOST_CHECK(simplexFound != st.null_simplex()); + + + + // Display the Simplex_tree - Can not be done in the middle of 2 inserts + std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; + std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; + std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + for (auto f_simplex : st.filtration_simplex_range()) { + std::cout << " " << "[" << st.filtration(f_simplex) << "] "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << (int) vertex << " "; + } + std::cout << std::endl; + } + + std::cout << "********************************************************************" << std::endl; + // TEST COFACE ALGORITHM + st.set_dimension(3); + std::cout << "COFACE ALGORITHM" << std::endl; + std::vector v; + std::vector simplex; + std::vector result; + v.push_back(3); + std::cout << "First test : " << std::endl; + std::cout << "Star of (3):" << std::endl; + + simplex.push_back(3); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(3); + simplex.push_back(0); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(4); + simplex.push_back(3); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(5); + simplex.push_back(4); + simplex.push_back(3); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(5); + simplex.push_back(3); + result.push_back(st.find(simplex)); + simplex.clear(); + + test_cofaces(st, v, 0, result); + v.clear(); + result.clear(); + + v.push_back(1); + v.push_back(7); + std::cout << "Second test : " << std::endl; + std::cout << "Star of (1,7): " << std::endl; + + simplex.push_back(7); + simplex.push_back(1); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(7); + simplex.push_back(6); + simplex.push_back(1); + simplex.push_back(0); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(7); + simplex.push_back(1); + simplex.push_back(0); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(7); + simplex.push_back(6); + simplex.push_back(1); + result.push_back(st.find(simplex)); + simplex.clear(); + + test_cofaces(st, v, 0, result); + result.clear(); + + std::cout << "Third test : " << std::endl; + std::cout << "2-dimension Cofaces of simplex(1,7) : " << std::endl; + + simplex.push_back(7); + simplex.push_back(1); + simplex.push_back(0); + result.push_back(st.find(simplex)); + simplex.clear(); + + simplex.push_back(7); + simplex.push_back(6); + simplex.push_back(1); + result.push_back(st.find(simplex)); + simplex.clear(); + + test_cofaces(st, v, 1, result); + result.clear(); + + std::cout << "Cofaces with a codimension too high (codimension + vetices > tree.dimension) :" << std::endl; + test_cofaces(st, v, 5, result); + // std::cout << "Cofaces with an empty codimension" << std::endl; + // test_cofaces(st, v, -1, result); + // std::cout << "Cofaces in an empty simplex tree" << std::endl; + // typeST empty_tree; + // test_cofaces(empty_tree, v, 1, result); + // std::cout << "Cofaces of an empty simplex" << std::endl; + // v.clear(); + // test_cofaces(st, v, 1, result); + + /* + // TEST Off read + std::cout << "********************************************************************" << std::endl; + typeST st2; + st2.tree_from_off("test.off"); + std::cout << st2; + */ } -- cgit v1.2.3 From c265cc17993fb6319af9baea9ca431e171815335 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Jul 2015 14:30:02 +0000 Subject: cpplint fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@692 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 85df90931dc594c38fa7dd564ec1c731b5be748b --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 53 +++++++++++++++------------ 1 file changed, 29 insertions(+), 24 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 2507f783..0a383492 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -132,7 +132,6 @@ class Simplex_tree { typedef typename Dictionary_it::value_type Dit_value_t; struct return_first { - Vertex_handle operator()(const Dit_value_t& p_sh) const { return p_sh.first; } @@ -469,8 +468,8 @@ class Simplex_tree { if (simplex.empty()) { return std::pair(null_simplex(), true); } - - sort(simplex.begin(), simplex.end()); // must be sorted in increasing order + // must be sorted in increasing order + sort(simplex.begin(), simplex.end()); Siblings * curr_sib = &root_; std::pair res_insert; @@ -483,12 +482,15 @@ class Simplex_tree { curr_sib = res_insert.first->second.children(); } res_insert = curr_sib->members_.emplace(*vi, Node(curr_sib, filtration)); - if (!res_insert.second) { // if already in the complex - if (res_insert.first->second.filtration() > filtration) { // if filtration value modified + if (!res_insert.second) { + // if already in the complex + if (res_insert.first->second.filtration() > filtration) { + // if filtration value modified res_insert.first->second.assign_filtration(filtration); return res_insert; } - return std::pair(null_simplex(), false); // if filtration value unchanged + // if filtration value unchanged + return std::pair(null_simplex(), false); } // otherwise the insertion has succeeded return res_insert; @@ -637,27 +639,30 @@ class Simplex_tree { bool addCoface = (star || curr_nbVertices == nbVertices); // Add a coface if we wan't the star or if the number of vertices of the current simplex matches with nbVertices if (addCoface) cofaces.push_back(simplex); - if ((!addCoface || star) && has_children(simplex)) // Rec call + if ((!addCoface || star) && has_children(simplex)) // Rec call rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); } else { - if (simplex->first == vertices.back()) // If curr_sib matches with the top vertex + if (simplex->first == vertices.back()) // If curr_sib matches with the top vertex { - bool equalDim = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices + bool equalDim = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices bool addCoface = vertices.size() == 1 && equalDim; if (addCoface) cofaces.push_back(simplex); - if ((!addCoface || star) && has_children(simplex)) // Rec call - { // Rec call + if ((!addCoface || star) && has_children(simplex)) + { + // Rec call Vertex_handle tmp = vertices.back(); vertices.pop_back(); rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); vertices.push_back(tmp); } - } else if (simplex->first > vertices.back()) + } else if (simplex->first > vertices.back()) { return; - else // (simplex->first < vertices.back() + } else { + // (simplex->first < vertices.back() if (has_children(simplex)) - rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); + rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); + } } } } @@ -726,7 +731,6 @@ class Simplex_tree { * Reverse lexicographic order has the property to always consider the subsimplex of a simplex * to be smaller. The filtration function must be monotonic. */ struct is_before_in_filtration { - explicit is_before_in_filtration(Simplex_tree * st) : st_(st) { } @@ -829,7 +833,7 @@ class Simplex_tree { private: /** \brief Recursive expansion of the simplex tree.*/ - void siblings_expansion(Siblings * siblings, // must contain elements + void siblings_expansion(Siblings * siblings, // must contain elements int k) { if (dimension_ > k) { dimension_ = k; @@ -839,28 +843,29 @@ class Simplex_tree { Dictionary_it next = siblings->members().begin(); ++next; - static std::vector > inter; // static, not thread-safe. + static std::vector > inter; // static, not thread-safe. for (Dictionary_it s_h = siblings->members().begin(); s_h != siblings->members().end(); ++s_h, ++next) { Simplex_handle root_sh = find_vertex(s_h->first); if (has_children(root_sh)) { intersection( - inter, // output intersection - next, // begin - siblings->members().end(), // end + inter, // output intersection + next, // begin + siblings->members().end(), // end root_sh->second.children()->members().begin(), root_sh->second.children()->members().end(), s_h->second.filtration()); if (inter.size() != 0) { this->num_simplices_ += inter.size(); - Siblings * new_sib = new Siblings(siblings, // oncles - s_h->first, // parent - inter); // boost::container::ordered_unique_range_t + Siblings * new_sib = new Siblings(siblings, // oncles + s_h->first, // parent + inter); // boost::container::ordered_unique_range_t inter.clear(); s_h->second.assign_children(new_sib); siblings_expansion(new_sib, k - 1); } else { - s_h->second.assign_children(siblings); // ensure the children property + // ensure the children property + s_h->second.assign_children(siblings); inter.clear(); } } -- cgit v1.2.3 From 2cdff70bfd4dd1307cea047017fa58fb116207a8 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Jul 2015 14:44:01 +0000 Subject: cpplint fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@693 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c59d90f177f6b7bc2192189cff926336fec6d97d --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 62 +++++++++++++++------------ 1 file changed, 34 insertions(+), 28 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 0a383492..3ed59c04 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_H_ -#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_H_ +#ifndef SIMPLEX_TREE_H_ +#define SIMPLEX_TREE_H_ #include #include @@ -86,9 +86,8 @@ namespace Gudhi { * */ template class Simplex_tree { public: @@ -187,7 +186,7 @@ class Simplex_tree { /** \brief Range over the simplices of the simplicial complex, ordered by the filtration. */ typedef boost::iterator_range Filtration_simplex_range; - /* @} */ // end name range and iterator types + /* @} */ // end name range and iterator types /** \name Range and iterator methods * @{ */ @@ -256,7 +255,7 @@ class Simplex_tree { * equal to \f$(-1)^{\text{dim} \sigma}\f$ the canonical orientation on the simplex. */ Simplex_vertex_range simplex_vertex_range(Simplex_handle sh) { - assert(sh != null_simplex()); // Empty simplex + assert(sh != null_simplex()); // Empty simplex return Simplex_vertex_range(Simplex_vertex_iterator(this, sh), Simplex_vertex_iterator(this)); } @@ -280,7 +279,7 @@ class Simplex_tree { Boundary_simplex_iterator(this)); } - /** @} */ // end range and iterator methods + /** @} */ // end range and iterator methods /** \name Constructor/Destructor * @{ */ @@ -301,9 +300,9 @@ class Simplex_tree { } } } - /** @} */ // end constructor/destructor + /** @} */ // end constructor/destructor private: - /** Recursive deletion. */ + // Recursive deletion void rec_delete(Siblings * sib) { for (auto sh = sib->members().begin(); sh != sib->members().end(); ++sh) { if (has_children(sh)) { @@ -336,7 +335,7 @@ class Simplex_tree { return sh->second.filtration(); } else { return INFINITY; - } // filtration(); } + } } /** \brief Returns an upper bound of the filtration values of the simplices. */ @@ -411,7 +410,7 @@ class Simplex_tree { */ template Simplex_handle find(RandomAccessVertexRange & s) { - if (s.begin() == s.end()) // Empty simplex + if (s.begin() == s.end()) // Empty simplex return null_simplex(); sort(s.begin(), s.end()); @@ -630,13 +629,17 @@ class Simplex_tree { * Postfix actions : Finally, we add back the removed vertex into vertices, and remove this vertex from curr_nbVertices so that we didn't change the parameters. * If the vertices list is empty, we need to check if curr_nbVertices matches with the dimension of the cofaces asked. */ - void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_nbVertices, std::vector& cofaces, bool star, int nbVertices) { - if (!(star || curr_nbVertices <= nbVertices)) // dimension of actual simplex <= nbVertices + void rec_coface(std::vector &vertices, Siblings *curr_sib, int curr_nbVertices, + std::vector& cofaces, bool star, int nbVertices) { + if (!(star || curr_nbVertices <= nbVertices)) // dimension of actual simplex <= nbVertices return; for (Simplex_handle simplex = curr_sib->members().begin(); simplex != curr_sib->members().end(); ++simplex) { if (vertices.empty()) { - // If we reached the end of the vertices, and the simplex has more vertices than the given simplex, we found a coface - bool addCoface = (star || curr_nbVertices == nbVertices); // Add a coface if we wan't the star or if the number of vertices of the current simplex matches with nbVertices + // If we reached the end of the vertices, and the simplex has more vertices than the given simplex + // => we found a coface + + // Add a coface if we wan't the star or if the number of vertices of the current simplex matches with nbVertices + bool addCoface = (star || curr_nbVertices == nbVertices); if (addCoface) cofaces.push_back(simplex); if ((!addCoface || star) && has_children(simplex)) // Rec call @@ -690,7 +693,7 @@ class Simplex_tree { assert(codimension >= 0); Simplex_vertex_range rg = simplex_vertex_range(simplex); std::vector copy(rg.begin(), rg.end()); - if (codimension + static_cast(copy.size()) > dimension_ + 1 || + if (codimension + static_cast(copy.size()) > dimension_ + 1 || (codimension == 0 && static_cast(copy.size()) > dimension_)) // n+codimension greater than dimension_ return cofaces; // must be sorted in decreasing order @@ -879,17 +882,17 @@ class Simplex_tree { Dictionary_it begin2, Dictionary_it end2, Filtration_value filtration) { if (begin1 == end1 || begin2 == end2) - return; // ----->> + return; // ----->> while (true) { if (begin1->first == begin2->first) { - intersection.push_back( - std::pair( - begin1->first, - Node(NULL, maximum(begin1->second.filtration(), begin2->second.filtration(), filtration)))); + intersection.push_back(std::pair(begin1->first, + Node(NULL, + maximum(begin1->second.filtration(), + begin2->second.filtration(), filtration)))); ++begin1; ++begin2; if (begin1 == end1 || begin2 == end2) - return; // ----->> + return; // ----->> } else { if (begin1->first < begin2->first) { ++begin1; @@ -898,7 +901,7 @@ class Simplex_tree { } else { ++begin2; if (begin2 == end2) - return; // ----->> + return; // ----->> } } } @@ -966,16 +969,19 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { typename Simplex_tree::Filtration_value max_fil = 0; int max_dim = -1; size_t num_simplices = 0; - while (read_simplex(is, simplex, fil)) { // read all simplices in the file as a list of vertices + while (read_simplex(is, simplex, fil)) { + // read all simplices in the file as a list of vertices ++num_simplices; - int dim = static_cast (simplex.size() - 1); // Warning : simplex_size needs to be casted in int - Can be 0 + // Warning : simplex_size needs to be casted in int - Can be 0 + int dim = static_cast (simplex.size() - 1); if (max_dim < dim) { max_dim = dim; } if (max_fil < fil) { max_fil = fil; } - st.insert_simplex(simplex, fil); // insert every simplex in the simplex tree + // insert every simplex in the simplex tree + st.insert_simplex(simplex, fil); simplex.clear(); } st.set_num_simplices(num_simplices); @@ -988,4 +994,4 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { } // namespace Gudhi -#endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_H_ +#endif // SIMPLEX_TREE_H_ -- cgit v1.2.3 From 76fa90a05998bd2015afb53f96e0512cd41826af Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Jul 2015 14:53:07 +0000 Subject: cpplint fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/coface@694 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 80593486ab7473309e5ae00305561a331e527cc5 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 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 3ed59c04..95a6d090 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -637,7 +637,7 @@ class Simplex_tree { if (vertices.empty()) { // If we reached the end of the vertices, and the simplex has more vertices than the given simplex // => we found a coface - + // Add a coface if we wan't the star or if the number of vertices of the current simplex matches with nbVertices bool addCoface = (star || curr_nbVertices == nbVertices); if (addCoface) @@ -645,14 +645,13 @@ class Simplex_tree { if ((!addCoface || star) && has_children(simplex)) // Rec call rec_coface(vertices, simplex->second.children(), curr_nbVertices + 1, cofaces, star, nbVertices); } else { - if (simplex->first == vertices.back()) // If curr_sib matches with the top vertex - { + if (simplex->first == vertices.back()) { + // If curr_sib matches with the top vertex bool equalDim = (star || curr_nbVertices == nbVertices); // dimension of actual simplex == nbVertices bool addCoface = vertices.size() == 1 && equalDim; if (addCoface) cofaces.push_back(simplex); - if ((!addCoface || star) && has_children(simplex)) - { + if ((!addCoface || star) && has_children(simplex)) { // Rec call Vertex_handle tmp = vertices.back(); vertices.pop_back(); @@ -741,8 +740,8 @@ class Simplex_tree { if (st_->filtration(sh1) != st_->filtration(sh2)) { return st_->filtration(sh1) < st_->filtration(sh2); } - - return st_->reverse_lexicographic_order(sh1, sh2); // is sh1 a proper subface of sh2 + // is sh1 a proper subface of sh2 + return st_->reverse_lexicographic_order(sh1, sh2); } Simplex_tree * st_; @@ -769,7 +768,8 @@ class Simplex_tree { * must be undirected_tag. */ template void insert_graph(const OneSkeletonGraph& skel_graph) { - assert(num_simplices() == 0); // the simplex tree must be empty + // the simplex tree must be empty + assert(num_simplices() == 0); if (boost::num_vertices(skel_graph) == 0) { return; @@ -798,7 +798,8 @@ class Simplex_tree { ++e_it) { auto u = source(*e_it, skel_graph); auto v = target(*e_it, skel_graph); - if (u < v) { // count edges only once { std::swap(u,v); } // u < v + if (u < v) { + // count edges only once { std::swap(u,v); } // u < v auto sh = find_vertex(u); if (!has_children(sh)) { sh->second.assign_children(new Siblings(&root_, sh->first)); @@ -955,7 +956,7 @@ std::ostream& operator<<(std::ostream & os, Simplex_tree & st) { for (auto v : st.simplex_vertex_range(sh)) { os << v << " "; } - os << st.filtration(sh) << "\n"; // TODO(VR): why adding the key ?? not read ?? << " " << st.key(sh) << " \n"; + os << st.filtration(sh) << "\n"; // TODO(VR): why adding the key ?? not read ?? << " " << st.key(sh) << " \n"; } return os; } @@ -990,7 +991,7 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { return is; } -/** @} */ // end defgroup simplex_tree +/** @} */ // end defgroup simplex_tree } // namespace Gudhi -- cgit v1.2.3 From 91c03d57fa9a674a177199c759476209a81707e4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 8 Jul 2015 08:45:28 +0000 Subject: Clang boost test segmentation fault fix git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@697 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ddfc6fe41d7112fd6b6c68eadf45e468f2c8904b --- src/Bottleneck/test/bottleneck_unit_test.cpp | 6 +++--- .../test/persistent_cohomology_unit_test.cpp | 11 +++++------ .../test/persistent_cohomology_unit_test_multi_field.cpp | 11 +++++------ src/Simplex_tree/test/simplex_tree_unit_test.cpp | 11 ++++------- 4 files changed, 17 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/Bottleneck/test/bottleneck_unit_test.cpp b/src/Bottleneck/test/bottleneck_unit_test.cpp index 068b8690..c60f5d8a 100644 --- a/src/Bottleneck/test/bottleneck_unit_test.cpp +++ b/src/Bottleneck/test/bottleneck_unit_test.cpp @@ -1,6 +1,6 @@ -#define BOOST_TEST_MODULE bottleneck test - -#include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "bottleneck" +#include #include "gudhi/Graph_matching.h" #include diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp index 55bc7066..194b3e74 100644 --- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp +++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test.cpp @@ -1,15 +1,14 @@ -#define BOOST_TEST_MODULE persistent_cohomology test -#include -#include -#include #include #include - +#include #include // std::pair, std::make_pair - #include // float comparison #include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "persistent_cohomology" +#include + #include "gudhi/graph_simplicial_complex.h" #include "gudhi/reader_utils.h" #include "gudhi/Simplex_tree.h" diff --git a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp index 18a4725e..703682e1 100644 --- a/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp +++ b/src/Persistent_cohomology/test/persistent_cohomology_unit_test_multi_field.cpp @@ -1,15 +1,14 @@ -#define BOOST_TEST_MODULE persistent_cohomology_multi_field test -#include -#include -#include #include #include - +#include #include // std::pair, std::make_pair - #include // float comparison #include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "persistent_cohomology_multi_field" +#include + #include "gudhi/graph_simplicial_complex.h" #include "gudhi/reader_utils.h" #include "gudhi/Simplex_tree.h" diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 7f2172a2..6f6e9bb1 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -1,17 +1,14 @@ -#define BOOST_TEST_MODULE simplex_tree test -#include -#include -#include -#include #include #include #include - #include // std::pair, std::make_pair - #include // float comparison #include +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "simplex_tree" +#include + #include "gudhi/graph_simplicial_complex.h" #include "gudhi/reader_utils.h" #include "gudhi/Simplex_tree.h" -- cgit v1.2.3 From 5eb277d21b1d8825171305e19da84f1949c47fe3 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 11 Jul 2015 09:32:02 +0000 Subject: More static/const on member functions in Simplex_tree. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@699 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 80933ccb090cf7f8119d81c77fee10155f6341f4 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 10 +++++----- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 1 + 2 files changed, 6 insertions(+), 5 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 95a6d090..61e07f84 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -316,21 +316,21 @@ class Simplex_tree { /** \brief Returns the key associated to a simplex. * * The filtration must be initialized. */ - Simplex_key key(Simplex_handle sh) { + static Simplex_key key(Simplex_handle sh) { return sh->second.key(); } /** \brief Returns the simplex associated to a key. * * The filtration must be initialized. */ - Simplex_handle simplex(Simplex_key key) { + Simplex_handle simplex(Simplex_key key) const { return filtration_vect_[key]; } /** \brief Returns the filtration value of a simplex. * * Called on the null_simplex, returns INFINITY. */ - Filtration_value filtration(Simplex_handle sh) const { + static Filtration_value filtration(Simplex_handle sh) { if (sh != null_simplex()) { return sh->second.filtration(); } else { @@ -347,13 +347,13 @@ class Simplex_tree { * associated to the simplices in the simplicial complex. * * One can call filtration(null_simplex()). */ - Simplex_handle null_simplex() const { + static Simplex_handle null_simplex() { return Dictionary_it(NULL); } /** \brief Returns a key different for all keys associated to the * simplices of the simplicial complex. */ - Simplex_key null_key() const { + static Simplex_key null_key() { return -1; } diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 6f6e9bb1..566d6d90 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -109,6 +109,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_from_file) { // Size of simplex int size = 0; for (auto vertex : st.simplex_vertex_range(f_simplex)) { + (void) vertex; size++; } BOOST_CHECK(AreAlmostTheSame(st.filtration(f_simplex), (0.1 * size))); // Specific test: filtration = 0.1 * simplex_size -- cgit v1.2.3 From 16ff459809374b1d8616a81dda2340c7f3942912 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 11 Jul 2015 14:35:23 +0000 Subject: Clean-ups Use vector instead of list. Use emplace more. Use std::max. Some const. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@701 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 275156e94b4c9900c0af43ed7b74c7bff40bd7fd --- .../include/gudhi/Persistent_cohomology.h | 32 ++++++++++---------- src/Simplex_tree/include/gudhi/Simplex_tree.h | 35 +++++++--------------- .../gudhi/Simplex_tree/Simplex_tree_siblings.h | 11 ++++--- 3 files changed, 31 insertions(+), 47 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 8bd265d8..896a7a9f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -336,18 +336,18 @@ class Persistent_cohomology { if (ds_parent_[key] == key // root of its tree && zero_cocycles_.find(key) == zero_cocycles_.end()) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(key), cpx_->null_simplex(), coeff_field_.characteristic())); + persistent_pairs_.emplace_back( + cpx_->simplex(key), cpx_->null_simplex(), coeff_field_.characteristic()); } } for (auto zero_idx : zero_cocycles_) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(zero_idx.second), cpx_->null_simplex(), coeff_field_.characteristic())); + persistent_pairs_.emplace_back( + cpx_->simplex(zero_idx.second), cpx_->null_simplex(), coeff_field_.characteristic()); } // Compute infinite interval of dimension > 0 for (auto cocycle : transverse_idx_) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(cocycle.first), cpx_->null_simplex(), cocycle.second.characteristics_)); + persistent_pairs_.emplace_back( + cpx_->simplex(cocycle.first), cpx_->null_simplex(), cocycle.second.characteristics_); } } @@ -387,8 +387,8 @@ class Persistent_cohomology { if (cpx_->filtration(cpx_->simplex(idx_coc_u)) < cpx_->filtration(cpx_->simplex(idx_coc_v))) { // Kill cocycle [idx_coc_v], which is younger. if (interval_length_policy(cpx_->simplex(idx_coc_v), sigma)) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(idx_coc_v), sigma, coeff_field_.characteristic())); + persistent_pairs_.emplace_back( + cpx_->simplex(idx_coc_v), sigma, coeff_field_.characteristic()); } // Maintain the index of the 0-cocycle alive. if (kv != idx_coc_v) { @@ -402,8 +402,8 @@ class Persistent_cohomology { } } else { // Kill cocycle [idx_coc_u], which is younger. if (interval_length_policy(cpx_->simplex(idx_coc_u), sigma)) { - persistent_pairs_.push_back( - Persistent_interval(cpx_->simplex(idx_coc_u), sigma, coeff_field_.characteristic())); + persistent_pairs_.emplace_back( + cpx_->simplex(idx_coc_u), sigma, coeff_field_.characteristic()); } // Maintain the index of the 0-cocycle alive. if (ku != idx_coc_u) { @@ -553,9 +553,9 @@ class Persistent_cohomology { Arith_element charac) { // Create a finite persistent interval for which the interval exists if (interval_length_policy(cpx_->simplex(death_key), sigma)) { - persistent_pairs_.push_back(Persistent_interval(cpx_->simplex(death_key) // creator - , sigma // destructor - , charac)); // fields + persistent_pairs_.emplace_back(cpx_->simplex(death_key) // creator + , sigma // destructor + , charac); // fields } auto death_key_row = transverse_idx_.find(death_key); // Find the beginning of the row. @@ -695,7 +695,7 @@ class Persistent_cohomology { void output_diagram(std::ostream& ostream = std::cout) { cmp_intervals_by_length cmp(cpx_); - persistent_pairs_.sort(cmp); + std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp); bool has_infinity = std::numeric_limits::has_infinity; for (auto pair : persistent_pairs_) { // Special case on windows, inf is "1.#INF" (cf. unitary tests and R package TDA) @@ -714,7 +714,7 @@ class Persistent_cohomology { { std::ofstream diagram_out(diagram_name.c_str()); cmp_intervals_by_length cmp( cpx_ ); - persistent_pairs_.sort( cmp ); + std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp); for(auto pair : persistent_pairs_) { diagram_out << cpx_->dimension(get<0>(pair)) << " " @@ -761,7 +761,7 @@ class Persistent_cohomology { /* Key -> row. */ std::map transverse_idx_; /* Persistent intervals. */ - std::list persistent_pairs_; + std::vector persistent_pairs_; length_interval interval_length_policy; boost::object_pool column_pool_; diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 61e07f84..2916ca97 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -881,40 +881,25 @@ class Simplex_tree { static void intersection(std::vector >& intersection, Dictionary_it begin1, Dictionary_it end1, Dictionary_it begin2, Dictionary_it end2, - Filtration_value filtration) { + Filtration_value filtration_) { if (begin1 == end1 || begin2 == end2) return; // ----->> while (true) { if (begin1->first == begin2->first) { - intersection.push_back(std::pair(begin1->first, - Node(NULL, - maximum(begin1->second.filtration(), - begin2->second.filtration(), filtration)))); - ++begin1; - ++begin2; - if (begin1 == end1 || begin2 == end2) + Filtration_value filt = (std::max)({begin1->second.filtration(), begin2->second.filtration(), filtration_}); + intersection.push_back(std::pair(begin1->first, Node(NULL, filt))); + if (++begin1 == end1 || ++begin2 == end2) + return; // ----->> + } else if (begin1->first < begin2->first) { + if (++begin1 == end1) + return; + } else /* begin1->first > begin2->first */ { + if (++begin2 == end2) return; // ----->> - } else { - if (begin1->first < begin2->first) { - ++begin1; - if (begin1 == end1) - return; - } else { - ++begin2; - if (begin2 == end2) - return; // ----->> - } } } } - /** Maximum over 3 values.*/ - static Filtration_value maximum(Filtration_value a, Filtration_value b, - Filtration_value c) { - Filtration_value max = (a < b) ? b : a; - return ((max < c) ? c : max); - } - public: /** \brief Write the hasse diagram of the simplicial complex in os. * 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 977fafa1..d6cbacaa 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 @@ -77,8 +77,8 @@ class Simplex_tree_siblings { parent_(parent), members_(boost::container::ordered_unique_range, members.begin(), members.end()) { - for (auto map_it = members_.begin(); map_it != members_.end(); map_it++) { - map_it->second.assign_children(this); + for (auto& map_el : members_) { + map_el.second.assign_children(this); } } @@ -96,8 +96,7 @@ class Simplex_tree_siblings { return; } if (sh == members_.end()) { - members_.insert( - std::pair(v, Node(this, filtration_value))); + members_.emplace(v, Node(this, filtration_value)); return; } } @@ -110,7 +109,7 @@ class Simplex_tree_siblings { return oncles_; } - Vertex_handle parent() { + Vertex_handle parent() const { return parent_; } @@ -118,7 +117,7 @@ class Simplex_tree_siblings { return members_; } - size_t size() { + size_t size() const { return members_.size(); } -- cgit v1.2.3 From 8e75cf8acd691c22ca972a5c0c5bf12580af2e78 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 11 Jul 2015 15:43:50 +0000 Subject: Clean-ups Avoid duplicate search with find+insert. No need to store 0 and 1 and return them by reference. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@702 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 28403136284a9fe2044b9d51bc2f10861b3a09e7 --- .../include/gudhi/Persistent_cohomology/Field_Zp.h | 18 +++++++----------- .../include/gudhi/Persistent_cohomology/Multi_field.h | 6 +++--- .../include/gudhi/Simplex_tree/Simplex_tree_siblings.h | 14 ++++---------- 3 files changed, 14 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h index 2a4c8692..a12019f8 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h @@ -41,9 +41,7 @@ class Field_Zp { Field_Zp() : Prime(0), - inverse_(), - mult_id_all(1), - add_id_all(0) { + inverse_() { } void init(int charac) { @@ -81,14 +79,14 @@ class Field_Zp { } /** \brief Returns the additive idendity \f$0_{\Bbbk}\f$ of the field.*/ - const Element& additive_identity() const { - return add_id_all; + Element additive_identity() const { + return 0; } /** \brief Returns the multiplicative identity \f$1_{\Bbbk}\f$ of the field.*/ - const Element& multiplicative_identity(Element = 0) const { - return mult_id_all; + Element multiplicative_identity(Element = 0) const { + return 1; } - /** Returns the inverse in the field. Modifies P.*/ + /** Returns the inverse in the field. Modifies P. ??? */ std::pair inverse(Element x, Element P) { return std::pair(inverse_[x], P); } // <------ return the product of field characteristic for which x is invertible @@ -101,7 +99,7 @@ class Field_Zp { } /** \brief Returns the characteristic \f$p\f$ of the field.*/ - const int& characteristic() const { + int characteristic() const { return Prime; } @@ -109,8 +107,6 @@ class Field_Zp { int Prime; /** Property map Element -> Element, which associate to an element its inverse in the field.*/ std::vector inverse_; - const Element mult_id_all; - const Element add_id_all; }; } // namespace persistent_cohomology 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 c6fd5282..555d696f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h @@ -142,7 +142,7 @@ class Multi_field { return prod_characteristics_; } - /** Returns the inverse in the field. Modifies P.*/ + /** Returns the inverse in the field. Modifies P. ??? */ std::pair inverse(Element x, Element QS) { Element QR; mpz_gcd(QR.get_mpz_t(), x.get_mpz_t(), QS.get_mpz_t()); // QR <- gcd(x,QS) @@ -153,12 +153,12 @@ class Multi_field { mpz_invert(inv_qt.get_mpz_t(), x.get_mpz_t(), QT.get_mpz_t()); assert(prod_characteristics_ > 0); // division by zero + non negative values - return std::pair( - (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT); + return { (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT }; } /** Returns -x * y.*/ Element times_minus(const Element& x, const Element& y) { assert(prod_characteristics_ > 0); // division by zero + non negative values + /* This assumes that (x*y)%pc cannot be zero, but Field_Zp has specific code for the 0 case ??? */ return prod_characteristics_ - ((x * y) % prod_characteristics_); } 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 d6cbacaa..de350f2d 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 @@ -90,18 +90,12 @@ class Simplex_tree_siblings { * present in the node. */ void insert(Vertex_handle v, Filtration_value filtration_value) { - typename Dictionary::iterator sh = members_.find(v); - if (sh != members_.end() && sh->second.filtration() > filtration_value) { - sh->second.assign_filtration(filtration_value); - return; - } - if (sh == members_.end()) { - members_.emplace(v, Node(this, filtration_value)); - return; - } + auto ins = members_.emplace(v, Node(this, filtration_value)); + if (!ins.second && filtration(ins.first) > filtration_value) + ins.first->second.assign_filtration(filtration_value); } - typename Dictionary::iterator find(Vertex_handle v) { + Dictionary_it find(Vertex_handle v) { return members_.find(v); } -- cgit v1.2.3 From e43188c536ce73c30fb31241696ed19d9192bc16 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 15 Jul 2015 13:56:01 +0000 Subject: One more push_back -> emplace_back git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@718 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 430daad1596f44ae8c334be868a9177aa8a5d9fc --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 2916ca97..107c0f63 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -887,7 +887,7 @@ class Simplex_tree { while (true) { if (begin1->first == begin2->first) { Filtration_value filt = (std::max)({begin1->second.filtration(), begin2->second.filtration(), filtration_}); - intersection.push_back(std::pair(begin1->first, Node(NULL, filt))); + intersection.emplace_back(begin1->first, Node(NULL, filt)); if (++begin1 == end1 || ++begin2 == end2) return; // ----->> } else if (begin1->first < begin2->first) { -- cgit v1.2.3 From f904023210531c72c2762a07c59d68c5b2a0d048 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 15 Jul 2015 16:36:52 +0000 Subject: Use C++11 range for. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@720 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fd3824262b699310e424db4a4bdc4d9a6a1ba477 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 6 ++---- 1 file changed, 2 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 107c0f63..a7244c3d 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -606,10 +606,8 @@ class Simplex_tree { void initialize_filtration() { filtration_vect_.clear(); filtration_vect_.reserve(num_simplices()); - for (auto cpx_it = complex_simplex_range().begin(); - cpx_it != complex_simplex_range().end(); ++cpx_it) { - filtration_vect_.push_back(*cpx_it); - } + for (Simplex_handle sh : complex_simplex_range()) + filtration_vect_.push_back(sh); // the stable sort ensures the ordering heuristic std::stable_sort(filtration_vect_.begin(), filtration_vect_.end(), -- cgit v1.2.3 From 8259dcb8ae5e21d78b333dddc7bf508907808e95 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 12 Aug 2015 08:54:44 +0000 Subject: Only one find_package for Boost. Double header inclusion issue. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@727 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 83ad3a5a97a3c169f6c25ef1ba8fad07f0730a7a --- CMakeLists.txt | 1 - src/CMakeLists.txt | 1 - 2 files changed, 2 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index d2c07e48..6bea06e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,6 @@ set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -find_package(Boost) find_package(GMP) if(GMP_FOUND) find_package(GMPXX) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9f6db2c7..545b0b58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,7 +19,6 @@ set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) -find_package(Boost) find_package(GMP) if(GMP_FOUND) find_package(GMPXX) -- cgit v1.2.3 From 3e72827aa8baf2af1efe682673ae1abd1327ab47 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 15 Aug 2015 03:18:41 +0000 Subject: Cleanup endpoints(Simplex_handle). git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@728 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4e45582a3811d3b646ace0ae6429c6789f40df61 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 5 ++--- 1 file changed, 2 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 a7244c3d..b300e144 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -542,9 +542,8 @@ class Simplex_tree { * and edge. sh must point to a 1-dimensional simplex. This is an * optimized version of the boundary computation. */ std::pair endpoints(Simplex_handle sh) { - return std::pair( - root_.members_.find(sh->first), - root_.members_.find(self_siblings(sh)->parent())); + assert(dimension(sh) == 1); + return { find_vertex(sh->first), find_vertex(self_siblings(sh)->parent()) }; } /** Returns the Siblings containing a simplex.*/ -- cgit v1.2.3 From e734e9d6063b83f4bb389b8073e456cbba0b7f3a Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 15 Aug 2015 08:36:23 +0000 Subject: Remove unnecessary friends (they were befriending the wrong classes anyway). Use variadic templates to be more robust to a change in the number of template parameters. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@732 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 5d2e7af2d656a26159e2e331fd0de92ed9b3bc04 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 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 b300e144..153401d6 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -110,13 +110,6 @@ class Simplex_tree { /* Type of dictionary Vertex_handle -> Node for traversing the simplex tree. */ typedef typename boost::container::flat_map Dictionary; - friend class Simplex_tree_node_explicit_storage< Simplex_tree >; - friend class Simplex_tree_siblings< Simplex_tree, Dictionary>; - friend class Simplex_tree_simplex_vertex_iterator< Simplex_tree >; - friend class Simplex_tree_boundary_simplex_iterator< Simplex_tree >; - friend class Simplex_tree_complex_simplex_iterator< Simplex_tree >; - friend class Simplex_tree_skeleton_simplex_iterator< Simplex_tree >; - /* \brief Set of nodes sharing a same parent in the simplex tree. */ /* \brief Set of nodes sharing a same parent in the simplex tree. */ typedef Simplex_tree_siblings Siblings; @@ -931,8 +924,8 @@ class Simplex_tree { // Print a Simplex_tree in os. -template -std::ostream& operator<<(std::ostream & os, Simplex_tree & st) { +template +std::ostream& operator<<(std::ostream & os, Simplex_tree & st) { for (auto sh : st.filtration_simplex_range()) { os << st.dimension(sh) << " "; for (auto v : st.simplex_vertex_range(sh)) { @@ -943,13 +936,14 @@ std::ostream& operator<<(std::ostream & os, Simplex_tree & st) { return os; } -template -std::istream& operator>>(std::istream & is, Simplex_tree & st) { +template +std::istream& operator>>(std::istream & is, Simplex_tree & st) { // assert(st.num_simplices() == 0); - std::vector::Vertex_handle> simplex; - typename Simplex_tree::Filtration_value fil; - typename Simplex_tree::Filtration_value max_fil = 0; + typedef Simplex_tree ST; + std::vector simplex; + typename ST::Filtration_value fil; + typename ST::Filtration_value max_fil = 0; int max_dim = -1; size_t num_simplices = 0; while (read_simplex(is, simplex, fil)) { -- cgit v1.2.3