summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Simplex_tree/include/gudhi/Simplex_tree.h104
-rw-r--r--src/Simplex_tree/test/simplex_tree_unit_test.cpp488
2 files changed, 409 insertions, 183 deletions
diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h
index 9d0cf755..0c2c851a 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:
@@ -156,6 +156,8 @@ class Simplex_tree {
typedef Simplex_tree_simplex_vertex_iterator<Simplex_tree> Simplex_vertex_iterator;
/** \brief Range over the vertices of a simplex. */
typedef boost::iterator_range<Simplex_vertex_iterator> Simplex_vertex_range;
+ /** \brief Range over the cofaces of a simplex. */
+ typedef std::vector<Simplex_handle> Cofaces_simplex_range;
/** \brief Iterator over the simplices of the boundary of a simplex.
*
* 'value_type' is Simplex_handle. */
@@ -187,8 +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(
@@ -206,6 +207,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 +254,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 (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.
@@ -386,6 +390,8 @@ class Simplex_tree {
bool has_children(Simplex_handle sh) const {
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
@@ -397,8 +403,8 @@ class Simplex_tree {
*/
template<class RandomAccessVertexRange>
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());
@@ -599,6 +605,94 @@ 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<Vertex_handle> &vertices, Siblings *curr_sib, int curr_nbVertices, std::vector<Simplex_handle>& 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
+ {
+ 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<Vertex_handle> 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<Vertex_handle>())); // must be sorted in decreasing order
+ bool star = codimension == 0;
+ rec_coface(copy, &root_, 1, cofaces, star, codimension + (int)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..55a055a0 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 <boost/test/included/unit_test.hpp>
+#include <boost/range/adaptor/reversed.hpp>
#include <boost/system/error_code.hpp>
#include <boost/chrono/thread_clock.hpp>
#include <iostream>
#include <string>
+#include <algorithm>
#include <utility> // std::pair, std::make_pair
@@ -24,6 +26,7 @@ typedef std::pair<typeVectorVertex, Filtration_value> 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,6 +174,23 @@ 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<Vertex_handle> v, int dim, std::vector<typeST::Simplex_handle> 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());
+ }
+}
+
BOOST_AUTO_TEST_CASE( simplex_tree_insertion )
{
const Filtration_value FIRST_FILTRATION_VALUE = 0.1;
@@ -408,183 +429,294 @@ 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 );
-
- 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;
- }
+ 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<Vertex_handle> v;
+ std::vector<Vertex_handle> simplex;
+ std::vector<typeST::Simplex_handle> 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;
+ */
}