From 56fdae5689fa3b99384a597af50cd92d2a4141d7 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 30 Jan 2015 10:39:46 +0000 Subject: Add insert_simplex_and_subfaces. Insert renamed insert_simplex. TU modified. Filtration propagation to be done. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@446 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 26cbe4f4abb3bdd5fb88959fd94f6ef30d283c3f --- .../example/alpha_shapes_persistence.cpp | 9 +- src/Simplex_tree/example/simple_simplex_tree.cpp | 22 +- .../example/simplex_tree_from_alpha_shapes_3.cpp | 4 +- src/Simplex_tree/include/gudhi/Simplex_tree.h | 37 +- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 813 ++++++++++++--------- 5 files changed, 519 insertions(+), 366 deletions(-) diff --git a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp index 0591a0ca..3a50c84c 100644 --- a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp @@ -135,13 +135,12 @@ int main (int argc, char * const argv[]) usage(argv[0]); } - float min_persistence = 0.0; - returnedScanValue = sscanf(argv[3], "%f", &min_persistence); + Filtration_value min_persistence = 0.0; + returnedScanValue = sscanf(argv[3], "%lf", &min_persistence); if ((returnedScanValue == EOF) || (min_persistence < -1.0)) { std::cerr << "Error: " << argv[3] << " is not correct\n"; usage(argv[0]); } - //Filtration_value min_persistence = (Filtration_value)min_persist_int; // program args management if (argc != 4) { @@ -257,7 +256,7 @@ int main (int argc, char * const argv[]) if (filtr > filtration_max) { filtration_max = filtr; } - simplex_tree.insert(the_simplex_tree, filtr); + simplex_tree.insert_simplex(the_simplex_tree, filtr); if (the_alpha_value_iterator != the_alpha_values.end()) ++the_alpha_value_iterator; else @@ -295,7 +294,7 @@ int main (int argc, char * const argv[]) Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh( simplex_tree ); pcoh.init_coefficients( coeff_field_characteristic ); //initializes the coefficient field for homology - pcoh.compute_persistent_cohomology( (Filtration_value)min_persistence ); + pcoh.compute_persistent_cohomology( min_persistence ); pcoh.output_diagram(); diff --git a/src/Simplex_tree/example/simple_simplex_tree.cpp b/src/Simplex_tree/example/simple_simplex_tree.cpp index 11b96a0d..4ecad752 100644 --- a/src/Simplex_tree/example/simple_simplex_tree.cpp +++ b/src/Simplex_tree/example/simple_simplex_tree.cpp @@ -61,7 +61,7 @@ int main (int argc, char * const argv[]) firstSimplexVector.push_back(FIRST_VERTEX_HANDLE); typeSimplex firstSimplex = std::make_pair(firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); typePairSimplexBool returnValue = - simplexTree.insert ( firstSimplex.first, firstSimplex.second ); + simplexTree.insert_simplex ( firstSimplex.first, firstSimplex.second ); if (returnValue.second == true) { @@ -80,7 +80,7 @@ int main (int argc, char * const argv[]) secondSimplexVector.push_back(SECOND_VERTEX_HANDLE); typeSimplex secondSimplex = std::make_pair(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( secondSimplex.first, secondSimplex.second ); + simplexTree.insert_simplex ( secondSimplex.first, secondSimplex.second ); if (returnValue.second == true) { @@ -100,7 +100,7 @@ int main (int argc, char * const argv[]) thirdSimplexVector.push_back(SECOND_VERTEX_HANDLE); typeSimplex thirdSimplex = std::make_pair(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( thirdSimplex.first, thirdSimplex.second ); + simplexTree.insert_simplex ( thirdSimplex.first, thirdSimplex.second ); if (returnValue.second == true) { @@ -119,7 +119,7 @@ int main (int argc, char * const argv[]) fourthSimplexVector.push_back(THIRD_VERTEX_HANDLE); typeSimplex fourthSimplex = std::make_pair(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( fourthSimplex.first, fourthSimplex.second ); + simplexTree.insert_simplex ( fourthSimplex.first, fourthSimplex.second ); if (returnValue.second == true) { @@ -139,7 +139,7 @@ int main (int argc, char * const argv[]) fifthSimplexVector.push_back(FIRST_VERTEX_HANDLE); typeSimplex fifthSimplex = std::make_pair(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( fifthSimplex.first, fifthSimplex.second ); + simplexTree.insert_simplex ( fifthSimplex.first, fifthSimplex.second ); if (returnValue.second == true) { @@ -159,7 +159,7 @@ int main (int argc, char * const argv[]) sixthSimplexVector.push_back(SECOND_VERTEX_HANDLE); typeSimplex sixthSimplex = std::make_pair(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( sixthSimplex.first, sixthSimplex.second ); + simplexTree.insert_simplex ( sixthSimplex.first, sixthSimplex.second ); if (returnValue.second == true) { @@ -180,7 +180,7 @@ int main (int argc, char * const argv[]) seventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); typeSimplex seventhSimplex = std::make_pair(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( seventhSimplex.first, seventhSimplex.second ); + simplexTree.insert_simplex ( seventhSimplex.first, seventhSimplex.second ); if (returnValue.second == true) { @@ -199,7 +199,7 @@ int main (int argc, char * const argv[]) eighthSimplexVector.push_back(FOURTH_VERTEX_HANDLE); typeSimplex eighthSimplex = std::make_pair(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( eighthSimplex.first, eighthSimplex.second ); + simplexTree.insert_simplex ( eighthSimplex.first, eighthSimplex.second ); if (returnValue.second == true) { @@ -219,7 +219,7 @@ int main (int argc, char * const argv[]) ninethSimplexVector.push_back(FIRST_VERTEX_HANDLE); typeSimplex ninethSimplex = std::make_pair(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( ninethSimplex.first, ninethSimplex.second ); + simplexTree.insert_simplex ( ninethSimplex.first, ninethSimplex.second ); if (returnValue.second == true) { @@ -238,7 +238,7 @@ int main (int argc, char * const argv[]) tenthSimplexVector.push_back(FIRST_VERTEX_HANDLE); typeSimplex tenthSimplex = std::make_pair(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value returnValue = - simplexTree.insert ( tenthSimplex.first, tenthSimplex.second ); + simplexTree.insert_simplex ( tenthSimplex.first, tenthSimplex.second ); if (returnValue.second == true) { @@ -259,7 +259,7 @@ int main (int argc, char * const argv[]) eleventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); typeSimplex eleventhSimplex = std::make_pair(eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); returnValue = - simplexTree.insert ( eleventhSimplex.first, eleventhSimplex.second ); + simplexTree.insert_simplex ( eleventhSimplex.first, eleventhSimplex.second ); if (returnValue.second == true) { diff --git a/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp b/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp index d831e31e..5f797e93 100644 --- a/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp +++ b/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp @@ -200,7 +200,7 @@ int main (int argc, char * const argv[]) // alpha shape not found Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); #ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert_simplex " << vertex << std::endl; #endif // DEBUG_TRACES the_simplex_tree.push_back(vertex); map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex,vertex)); @@ -218,7 +218,7 @@ int main (int argc, char * const argv[]) #ifdef DEBUG_TRACES std::cout << "filtration = " << *the_alpha_value_iterator << std::endl; #endif // DEBUG_TRACES - simplex_tree.insert(the_simplex_tree, std::sqrt(*the_alpha_value_iterator)); + simplex_tree.insert_simplex(the_simplex_tree, std::sqrt(*the_alpha_value_iterator)); if (the_alpha_value_iterator != the_alpha_values.end()) ++the_alpha_value_iterator; else diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 8d5dddce..2fbcb18c 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -234,7 +234,7 @@ class Simplex_tree { * * The filtration must be valid. If the filtration has not been initialized yet, the * method initializes it (i.e. order the simplices). */ - Filtration_simplex_range filtration_simplex_range(linear_indexing_tag) { + Filtration_simplex_range filtration_simplex_range(Indexing_tag) { if (filtration_vect_.empty()) { initialize_filtration(); } @@ -449,7 +449,7 @@ class Simplex_tree { * The type RandomAccessVertexRange must be a range for which .begin() and * .end() return random access iterators, with 'value_type' Vertex_handle. */ template - std::pair insert(RandomAccessVertexRange & simplex, + std::pair insert_simplex(RandomAccessVertexRange & simplex, Filtration_value filtration) { if (simplex.empty()) { return std::pair(null_simplex(), true); @@ -479,6 +479,37 @@ class Simplex_tree { 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) { + 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()]); + } + // (N-1)-Simplex recursive call + insert_simplex_and_subfaces(NsimplexMinusOne); + } + // N-Simplex insert + insert_simplex(Nsimplex, filtration); + } else if (Nsimplex.size() == 1) { + // 1-Simplex insert - End of recursivity + insert_simplex(Nsimplex, filtration); + } else { + // Nothing to insert - empty vector + } + } + /** \brief Assign a value 'key' to the key of the simplex * represented by the Simplex_handle 'sh'. */ void assign_key(Simplex_handle sh, Simplex_key key) { @@ -832,7 +863,7 @@ std::istream& operator>>(std::istream & is, Simplex_tree & st) { if (max_fil < fil) { max_fil = fil; } - st.insert(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); diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 6c82586a..eaec4881 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -14,343 +14,345 @@ #include "gudhi/reader_utils.h" #include "gudhi/Simplex_tree.h" - using namespace Gudhi; typedef Simplex_tree<> typeST; -typedef std::pair< typeST::Simplex_handle, bool > typePairSimplexBool; -typedef std::vector< Vertex_handle > typeVectorVertex; +typedef std::pair typePairSimplexBool; +typedef std::vector typeVectorVertex; typedef std::pair typeSimplex; -const Vertex_handle DEFAULT_VERTEX_HANDLE = (const Vertex_handle)-1; - -void test_empty_simplex_tree(typeST& tst) -{ - BOOST_CHECK( tst.null_vertex() == DEFAULT_VERTEX_HANDLE ); - BOOST_CHECK( tst.filtration() == Filtration_value(0) ); - BOOST_CHECK( tst.num_vertices() == (size_t)0 ); - BOOST_CHECK( tst.num_simplices() == (size_t)0 ); - typeST::Siblings* STRoot = tst.root(); - BOOST_CHECK( STRoot != NULL ); - BOOST_CHECK( STRoot->oncles() == NULL ); - BOOST_CHECK( STRoot->parent() == DEFAULT_VERTEX_HANDLE ); - BOOST_CHECK( tst.dimension() == -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); + BOOST_CHECK(tst.num_vertices() == (size_t) 0); + BOOST_CHECK(tst.num_simplices() == (size_t) 0); + typeST::Siblings* STRoot = tst.root(); + BOOST_CHECK(STRoot != NULL); + BOOST_CHECK(STRoot->oncles() == NULL); + BOOST_CHECK(STRoot->parent() == DEFAULT_VERTEX_HANDLE); + 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 - } - std::cout << "Iterator on simplices: " << std::endl; - for( auto simplex : tst.complex_simplex_range() ) - { - BOOST_CHECK( false); // shall be empty - } - - 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 - std::cout << "test_iterators_on_empty_simplex_tree - filtration=" << tst.filtration(f_simplex) << std::endl; - } +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 + } + 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 + } + + 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 + std::cout << "test_iterators_on_empty_simplex_tree - filtration=" + << tst.filtration(f_simplex) << std::endl; + } } BOOST_AUTO_TEST_CASE( simplex_tree_when_empty ) { - const Filtration_value DEFAULT_FILTRATION_VALUE = 0; + const Filtration_value DEFAULT_FILTRATION_VALUE = 0; - // TEST OF DEFAULT CONSTRUCTOR - std::cout << "********************************************************************" << std::endl; - std::cout << "TEST OF DEFAULT CONSTRUCTOR" << std::endl; - typeST st; + // TEST OF DEFAULT CONSTRUCTOR + std::cout << "********************************************************************" << std::endl; + 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 OF EMPTY INSERTION - std::cout << "TEST OF EMPTY INSERTION" << std::endl; - typeVectorVertex simplexVectorEmpty; - BOOST_CHECK(simplexVectorEmpty.empty() == true); - typePairSimplexBool returnEmptyValue = st.insert ( simplexVectorEmpty, DEFAULT_FILTRATION_VALUE ); - BOOST_CHECK(returnEmptyValue.first == typeST::Simplex_handle(NULL)); - BOOST_CHECK(returnEmptyValue.second == true); + 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); + 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(); +bool AreAlmostTheSame(float a, float b) { + return std::fabs(a - b) < std::numeric_limits::epsilon(); } 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; - typeST st; - - std::string inputFile("simplex_tree_for_unit_test.txt"); - std::ifstream simplex_tree_stream(inputFile.c_str()); - simplex_tree_stream >> st; - - // Display the Simplex_tree - std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; - std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; - - // Check - BOOST_CHECK(st.num_simplices() == 143353); - BOOST_CHECK(st.dimension() == 3); - BOOST_CHECK(st.filtration() == 0.4); - - int previous_size=0; - for( auto f_simplex : st.filtration_simplex_range() ) - { - // Size of simplex - int size=0; - 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) - previous_size = size; - } - simplex_tree_stream.close(); + // TEST OF INSERTION + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF SIMPLEX TREE FROM A FILE" << std::endl; + typeST st; + + std::string inputFile("simplex_tree_for_unit_test.txt"); + std::ifstream simplex_tree_stream(inputFile.c_str()); + simplex_tree_stream >> st; + + // Display the Simplex_tree + std::cout << "The complex contains " << st.num_simplices() << " simplices" << std::endl; + std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; + + // Check + BOOST_CHECK(st.num_simplices() == 143353); + BOOST_CHECK(st.dimension() == 3); + BOOST_CHECK(st.filtration() == 0.4); + + int previous_size = 0; + for( auto f_simplex : st.filtration_simplex_range() ) + { + // Size of simplex + int size = 0; + 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) + previous_size = size; + } + simplex_tree_stream.close(); } -void test_simplex_tree_contains(typeST& simplexTree, typeSimplex& simplex, int pos) -{ - 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) ); - - //typeVectorVertex::iterator simplexIter = simplex.first.end()-1; - int simplexIndex=simplex.first.size()-1; - for( auto vertex : simplexTree.simplex_vertex_range(*f_simplex) ) - { - //std::cout << "test_simplex_tree_contains - vertex=" << vertex << "||" << *simplexIter << std::endl; - //BOOST_CHECK( vertex == *simplexIter); - //simplexIter--; - std::cout << "test_simplex_tree_contains - vertex=" << vertex << "||" << simplex.first.at(simplexIndex) << std::endl; - BOOST_CHECK(vertex == simplex.first.at(simplexIndex)); - BOOST_CHECK(simplexIndex >= 0); - simplexIndex--; - } +void test_simplex_tree_contains(typeST& simplexTree, typeSimplex& simplex, int pos) { + 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) ); + + 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(simplexIndex >= 0); + simplexIndex--; + } } -void test_simplex_tree_insert_returns_true(const typePairSimplexBool& returnValue) -{ - BOOST_CHECK(returnValue.second == true); - typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned != typeST::Simplex_handle(NULL)); +void test_simplex_tree_insert_returns_true(const typePairSimplexBool& returnValue) { + BOOST_CHECK(returnValue.second == true); + typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + BOOST_CHECK(shReturned != typeST::Simplex_handle(NULL)); } // Global variables -Filtration_value max_fil = 0.0; +Filtration_value max_fil = DEFAULT_FILTRATION_VALUE; int dim_max = -1; -void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, const Filtration_value& fil) -{ - if (vectorSize > dim_max+1) - { - dim_max = vectorSize-1; - simplexTree.set_dimension(dim_max); - std::cout << " set_and_test_simplex_tree_dim_fil - dim_max=" << dim_max << std::endl; - } - if (fil > max_fil) - { - max_fil = fil; - simplexTree.set_filtration(max_fil); - std::cout << " set_and_test_simplex_tree_dim_fil - max_fil=" << max_fil << std::endl; - } - unsigned int nb_simplices = simplexTree.num_simplices() + 1; - simplexTree.set_num_simplices(nb_simplices); - - BOOST_CHECK( simplexTree.dimension() == dim_max ); - BOOST_CHECK( AreAlmostTheSame(simplexTree.filtration(), max_fil) ); - BOOST_CHECK( simplexTree.num_simplices() == nb_simplices ); +void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, const Filtration_value& fil) { + if (vectorSize > dim_max + 1) { + dim_max = vectorSize - 1; + simplexTree.set_dimension(dim_max); + std::cout << " set_and_test_simplex_tree_dim_fil - dim_max=" << dim_max + << std::endl; + } + if (fil > max_fil) { + max_fil = fil; + simplexTree.set_filtration(max_fil); + std::cout << " set_and_test_simplex_tree_dim_fil - max_fil=" << max_fil + << std::endl; + } + unsigned int nb_simplices = simplexTree.num_simplices() + 1; + simplexTree.set_num_simplices(nb_simplices); + + BOOST_CHECK(simplexTree.dimension() == dim_max); + BOOST_CHECK(AreAlmostTheSame(simplexTree.filtration(), max_fil)); + BOOST_CHECK(simplexTree.num_simplices() == nb_simplices); } 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; - const Filtration_value FOURTH_FILTRATION_VALUE = 0.4; - 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; - - // TEST OF INSERTION - std::cout << "********************************************************************" << std::endl; - std::cout << "TEST OF INSERTION" << std::endl; - typeST st; - - // ++ FIRST - std::cout << " - INSERT 0" << std::endl; - typeVectorVertex firstSimplexVector; - firstSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( firstSimplexVector.size() == 1 ); - typeSimplex firstSimplex = std::make_pair(firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - typePairSimplexBool returnValue = - st.insert ( firstSimplex.first, firstSimplex.second ); - - 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 ); - - // ++ SECOND - std::cout << " - INSERT 1" << std::endl; - typeVectorVertex secondSimplexVector; - secondSimplexVector.push_back(SECOND_VERTEX_HANDLE); - BOOST_CHECK( secondSimplexVector.size() == 1 ); - typeSimplex secondSimplex = std::make_pair(secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert ( secondSimplex.first, secondSimplex.second ); - - 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 ); - - // ++ 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 ); - typeSimplex thirdSimplex = std::make_pair(thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert ( thirdSimplex.first, thirdSimplex.second ); - - 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 !! - - // ++ FOURTH - std::cout << " - INSERT 2" << std::endl; - typeVectorVertex fourthSimplexVector; - fourthSimplexVector.push_back(THIRD_VERTEX_HANDLE); - BOOST_CHECK( fourthSimplexVector.size() == 1 ); - typeSimplex fourthSimplex = std::make_pair(fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert ( fourthSimplex.first, fourthSimplex.second ); - - 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 ); - - // ++ 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 ); - typeSimplex fifthSimplex = std::make_pair(fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert ( fifthSimplex.first, fifthSimplex.second ); - - 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 !! - - // ++ 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 ); - typeSimplex sixthSimplex = std::make_pair(sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert ( sixthSimplex.first, sixthSimplex.second ); - - 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 !! - - // ++ SEVENTH - std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex seventhSimplexVector; - seventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); - seventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); - seventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( seventhSimplexVector.size() == 3 ); - typeSimplex seventhSimplex = std::make_pair(seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); - returnValue = - st.insert ( seventhSimplex.first, seventhSimplex.second ); - - 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 !! - - // ++ EIGHTH - std::cout << " - INSERT 3" << std::endl; - typeVectorVertex eighthSimplexVector; - eighthSimplexVector.push_back(FOURTH_VERTEX_HANDLE); - BOOST_CHECK( eighthSimplexVector.size() == 1 ); - typeSimplex eighthSimplex = std::make_pair(eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); - returnValue = - st.insert ( eighthSimplex.first, eighthSimplex.second ); - - 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 ); - - // ++ 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 ); - typeSimplex ninethSimplex = std::make_pair(ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); - returnValue = - st.insert ( ninethSimplex.first, ninethSimplex.second ); - - 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 !! - - // ++ TENTH - std::cout << " - INSERT 0 (already inserted)" << std::endl; - typeVectorVertex tenthSimplexVector; - tenthSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( tenthSimplexVector.size() == 1 ); - typeSimplex tenthSimplex = std::make_pair(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value - returnValue = - st.insert ( tenthSimplex.first, tenthSimplex.second ); - - BOOST_CHECK(returnValue.second == false); - typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); - 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; - typeVectorVertex eleventhSimplexVector; - eleventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); - eleventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); - eleventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); - BOOST_CHECK( eleventhSimplexVector.size() == 3 ); - typeSimplex eleventhSimplex = std::make_pair(eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); - returnValue = - st.insert ( eleventhSimplex.first, eleventhSimplex.second ); - - BOOST_CHECK(returnValue.second == false); - shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator - BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); - BOOST_CHECK( st.num_vertices() == (size_t)4 ); // Not incremented !! - BOOST_CHECK( st.dimension() == dim_max ); - BOOST_CHECK( AreAlmostTheSame(st.filtration(), max_fil) ); + const Filtration_value FIRST_FILTRATION_VALUE = 0.1; + const Filtration_value SECOND_FILTRATION_VALUE = 0.2; + const Filtration_value THIRD_FILTRATION_VALUE = 0.3; + const Filtration_value FOURTH_FILTRATION_VALUE = 0.4; + 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; + + // TEST OF INSERTION + std::cout << "********************************************************************" << std::endl; + std::cout << "TEST OF INSERTION" << std::endl; + typeST st; + + // ++ FIRST + std::cout << " - INSERT 0" << std::endl; + typeVectorVertex firstSimplexVector; + firstSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( firstSimplexVector.size() == 1 ); + typeSimplex firstSimplex = std::make_pair( + firstSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + typePairSimplexBool returnValue = st.insert_simplex(firstSimplex.first, + firstSimplex.second); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, firstSimplexVector.size(), firstSimplex.second); + 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 ); + typeSimplex secondSimplex = std::make_pair( + secondSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = + st.insert_simplex ( secondSimplex.first, secondSimplex.second ); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, secondSimplexVector.size(), secondSimplex.second); + 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 ); + typeSimplex thirdSimplex = std::make_pair( + thirdSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = + st.insert_simplex ( thirdSimplex.first, thirdSimplex.second ); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, thirdSimplexVector.size(), thirdSimplex.second); + 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 ); + typeSimplex fourthSimplex = std::make_pair( + fourthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = + st.insert_simplex ( fourthSimplex.first, fourthSimplex.second ); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, fourthSimplexVector.size(), fourthSimplex.second); + 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 ); + typeSimplex fifthSimplex = std::make_pair( + fifthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = + st.insert_simplex ( fifthSimplex.first, fifthSimplex.second ); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, fifthSimplexVector.size(), fifthSimplex.second); + 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 ); + typeSimplex sixthSimplex = std::make_pair( + sixthSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = + st.insert_simplex ( sixthSimplex.first, sixthSimplex.second ); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, sixthSimplexVector.size(), sixthSimplex.second); + BOOST_CHECK( st.num_vertices() == (size_t)3 ); // Not incremented !! + + // ++ SEVENTH + std::cout << " - INSERT (2,1,0)" << std::endl; + typeVectorVertex seventhSimplexVector; + seventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); + seventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); + seventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( seventhSimplexVector.size() == 3 ); + typeSimplex seventhSimplex = std::make_pair( + seventhSimplexVector, Filtration_value(THIRD_FILTRATION_VALUE)); + returnValue = + st.insert_simplex ( seventhSimplex.first, seventhSimplex.second ); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, seventhSimplexVector.size(), seventhSimplex.second); + 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 ); + typeSimplex eighthSimplex = std::make_pair( + eighthSimplexVector, Filtration_value(FIRST_FILTRATION_VALUE)); + returnValue = + st.insert_simplex ( eighthSimplex.first, eighthSimplex.second ); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, eighthSimplexVector.size(), eighthSimplex.second); + 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 ); + typeSimplex ninethSimplex = std::make_pair( + ninethSimplexVector, Filtration_value(SECOND_FILTRATION_VALUE)); + returnValue = + st.insert_simplex ( ninethSimplex.first, ninethSimplex.second ); + + test_simplex_tree_insert_returns_true (returnValue); + set_and_test_simplex_tree_dim_fil(st, ninethSimplexVector.size(), ninethSimplex.second); + 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 ); + typeSimplex tenthSimplex = std::make_pair( + tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value + returnValue = + st.insert_simplex ( tenthSimplex.first, tenthSimplex.second ); + + BOOST_CHECK(returnValue.second == false); + typeST::Simplex_handle shReturned = returnValue.first; // Simplex_handle = boost::container::flat_map< Vertex_handle, Node >::iterator + BOOST_CHECK(shReturned == typeST::Simplex_handle(NULL)); + 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; + typeVectorVertex eleventhSimplexVector; + eleventhSimplexVector.push_back(THIRD_VERTEX_HANDLE); + eleventhSimplexVector.push_back(SECOND_VERTEX_HANDLE); + eleventhSimplexVector.push_back(FIRST_VERTEX_HANDLE); + BOOST_CHECK( eleventhSimplexVector.size() == 3 ); + typeSimplex eleventhSimplex = std::make_pair( + eleventhSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); + returnValue = + 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 + 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) ); /* Inserted simplex: */ /* 1 */ @@ -359,48 +361,169 @@ BOOST_AUTO_TEST_CASE( simplex_tree_insertion ) /* o---o---o */ /* 2 0 3 */ - // [0.1] 0 - // [0.1] 1 - // [0.1] 2 - // [0.1] 3 - // [0.2] 1 0 - // [0.2] 2 0 - // [0.2] 2 1 - // [0.2] 3 0 - // [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 - std::cout << "simplex_tree_insertion - second - 1" << std::endl; - 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 - std::cout << "simplex_tree_insertion - fourth - 2" << std::endl; - 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 - std::cout << "simplex_tree_insertion - sixth - 6" << std::endl; - 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 - std::cout << "simplex_tree_insertion - eighth - 3" << std::endl; - 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 - - // 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; - } + // [0.1] 0 + // [0.1] 1 + // [0.1] 2 + // [0.1] 3 + // [0.2] 1 0 + // [0.2] 2 0 + // [0.2] 2 1 + // [0.2] 3 0 + // [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 + std::cout << "simplex_tree_insertion - second - 1" << std::endl; + 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 + std::cout << "simplex_tree_insertion - fourth - 2" << std::endl; + 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 + std::cout << "simplex_tree_insertion - sixth - 6" << std::endl; + 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 + std::cout << "simplex_tree_insertion - eighth - 3" << std::endl; + 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 + + // 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; + } + +} + +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 + // 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; + } } -- cgit v1.2.3