From ff6ad8b959f6c20380f3d68ebb1bbbf1224adcfd Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 13 Oct 2015 15:34:28 +0000 Subject: Manual merge of skb_simplex_insertion after last trunk big modifications on Skbl git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@855 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d7f7721e2963de439a28040196423d4c0df07d3f --- src/Skeleton_blocker/test/TestSimplifiable.cpp | 620 ++++++++++++++----------- 1 file changed, 343 insertions(+), 277 deletions(-) (limited to 'src/Skeleton_blocker/test/TestSimplifiable.cpp') diff --git a/src/Skeleton_blocker/test/TestSimplifiable.cpp b/src/Skeleton_blocker/test/TestSimplifiable.cpp index 09176934..76d5ba89 100644 --- a/src/Skeleton_blocker/test/TestSimplifiable.cpp +++ b/src/Skeleton_blocker/test/TestSimplifiable.cpp @@ -1,24 +1,24 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): David Salinas - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): David Salinas + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include @@ -41,316 +41,382 @@ template class Skeleton_blocker_sub_complex; typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Root_vertex_handle Root_vertex_handle; -typedef Skeleton_blocker_simplex Simplex_handle; +typedef Skeleton_blocker_simplex Simplex; // true iff v \in complex -bool assert_vertex(Complex &complex,Vertex_handle v){ - Simplex_handle simplex(v); - bool test = complex.contains(simplex); - assert(test); - return test; + +bool assert_vertex(Complex &complex, Vertex_handle v) { + Simplex simplex(v); + bool test = complex.contains(simplex); + assert(test); + return test; } // true iff the blocker (a,b,c) is in complex -bool assert_blocker(Complex &complex,Root_vertex_handle a,Root_vertex_handle b,Root_vertex_handle c){ - return complex.contains_blocker(Simplex_handle(*complex.get_address(a),*complex.get_address(b),*complex.get_address(c))); - //return complex.contains_blocker((a),(b),(c)); +bool assert_blocker(Complex &complex, Root_vertex_handle a, Root_vertex_handle b, Root_vertex_handle c) { + + return complex.contains_blocker(Simplex(*complex.get_address(a), *complex.get_address(b), *complex.get_address(c))); + //return complex.contains_blocker((a),(b),(c)); } -void build_complete(int n,Complex& complex){ - complex.clear(); - for(int i=0;i(b), static_cast(z)); - complex.add_blocker(Simplex_handle(static_cast(a), static_cast(x), - static_cast(y))); - complex.add_blocker(Simplex_handle(static_cast(b), static_cast(x), - static_cast(y))); - - // Print result - cerr << "complex before complex"<< complex.to_string()<(a),static_cast(b)); - // Print result - cerr << "ContractEdge(0,1)\n"; - PRINT(complex.to_string()); - - // verification - for (int i=0;i<5;i++) - if (i!=1) assert_vertex(complex, static_cast(i)); - bool test1 = !complex.contains_edge(static_cast(a),static_cast(b)); - bool test2 = assert_blocker(complex,Root_vertex_handle(a),Root_vertex_handle(x),Root_vertex_handle(y)); - bool test3 = complex.num_edges()==6; - bool test4 = complex.num_blockers()==1; - Simplex_handle sigma; - sigma.add_vertex(static_cast(a)); - sigma.add_vertex(static_cast(x)); - sigma.add_vertex(static_cast(y)); - sigma.add_vertex(static_cast(z)); - bool test5 = !(complex.contains(sigma)); - return test1&&test2&&test3&&test4&&test5; +bool test_contraction1() { + + enum { + a, b, x, y, z, n + }; + Complex complex(n); + build_complete(n, complex); + complex.remove_edge(static_cast (b), static_cast (z)); + complex.add_blocker(Simplex(static_cast (a), static_cast (x), + static_cast (y))); + complex.add_blocker(Simplex(static_cast (b), static_cast (x), + static_cast (y))); + + // Print result + cerr << "complex before complex" << complex.to_string() << endl; + + cerr << endl << endl; + complex.contract_edge(static_cast (a), static_cast (b)); + // Print result + cerr << "ContractEdge(0,1)\n"; + PRINT(complex.to_string()); + + // verification + for (int i = 0; i < 5; i++) + if (i != 1) assert_vertex(complex, static_cast (i)); + bool test1 = !complex.contains_edge(static_cast (a), static_cast (b)); + bool test2 = assert_blocker(complex, Root_vertex_handle(a), Root_vertex_handle(x), Root_vertex_handle(y)); + bool test3 = complex.num_edges() == 6; + bool test4 = complex.num_blockers() == 1; + Simplex sigma; + sigma.add_vertex(static_cast (a)); + sigma.add_vertex(static_cast (x)); + sigma.add_vertex(static_cast (y)); + sigma.add_vertex(static_cast (z)); + bool test5 = !(complex.contains(sigma)); + return test1 && test2 && test3 && test4&&test5; } +bool test_contraction2() { -bool test_contraction2(){ - enum { a, b, x, y, z, n }; - Complex complex(n); - build_complete(n,complex); - complex.remove_edge(static_cast(b),static_cast(x)); - Simplex_handle blocker; - blocker.add_vertex(static_cast(a)); - blocker.add_vertex(static_cast(y)); - blocker.add_vertex(static_cast(z)); + enum { + a, b, x, y, z, n + }; + Complex complex(n); + build_complete(n, complex); + complex.remove_edge(static_cast (b), static_cast (x)); + Simplex blocker; + blocker.add_vertex(static_cast (a)); + blocker.add_vertex(static_cast (y)); + blocker.add_vertex(static_cast (z)); - complex.add_blocker(blocker); + complex.add_blocker(blocker); - // Print result - cerr << "complex complex"<< complex.to_string(); - cerr <(a),static_cast(b)); + // Print result + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + complex.contract_edge(static_cast (a), static_cast (b)); - cerr << "complex.ContractEdge(a,b)"<< complex.to_string(); + cerr << "complex.ContractEdge(a,b)" << complex.to_string(); - cerr <(a), static_cast(x), - static_cast(y),static_cast(z))); - test = test && complex.num_blockers()==1; - return test; + // there should be one blocker (a,c,d,e) in the complex + bool test; + test = complex.contains_blocker(Simplex(static_cast (a), static_cast (x), + static_cast (y), static_cast (z))); + test = test && complex.num_blockers() == 1; + return test; } -bool test_link_condition1(){ +bool test_link_condition1() { - Complex complex(0); - // Build the complexes - build_complete(4,complex); - complex.add_blocker(Simplex_handle(static_cast(0), static_cast(1), static_cast(2))); + Complex complex(0); + // Build the complexes + build_complete(4, complex); + complex.add_blocker(Simplex(static_cast (0), static_cast (1), static_cast (2))); - // Print result - cerr << "complex complex"<< complex.to_string(); - cerr <(2), static_cast(4)); - complex.add_edge(static_cast(3), static_cast(4)); - // Print result - cerr << "initial complex :\n"<< complex.to_string(); - cerr <(1), static_cast(2), static_cast(3)); - complex.remove_star(simplex_123); - cerr << "complex.remove_star(1,2,3):\n"<< complex.to_string(); - cerr < Ocomplex \n"; - return blocker123_here; +bool test_collapse0() { + Complex complex(5); + build_complete(4, complex); + complex.add_vertex(); + complex.add_edge_without_blockers(static_cast (2), static_cast (4)); + complex.add_edge_without_blockers(static_cast (3), static_cast (4)); + // Print result + cerr << "initial complex :\n" << complex.to_string(); + cerr << endl << endl; + + Simplex simplex_123(static_cast (1), static_cast (2), static_cast (3)); + complex.remove_star(simplex_123); + cerr << "complex.remove_star(1,2,3):\n" << complex.to_string(); + cerr << endl << endl; + + // verification + bool blocker123_here = complex.contains_blocker(simplex_123); + cerr << "----> Ocomplex \n"; + return blocker123_here; } - -bool test_collapse1(){ - Complex complex(5); - build_complete(4,complex); - complex.add_blocker(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2),Vertex_handle(3))); - // Print result - cerr << "initial complex :\n"<< complex.to_string(); - cerr < Ocomplex \n"; - return res; +bool test_collapse1() { + Complex complex(5); + build_complete(4, complex); + complex.add_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); + // Print result + cerr << "initial complex :\n" << complex.to_string(); + cerr << endl << endl; + + Simplex simplex_123(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + complex.remove_star(simplex_123); + cerr << "complex.remove_star(1,2,3):\n" << complex.to_string(); + cerr << endl << endl; + + // verification + bool res = complex.contains_blocker(simplex_123); + res = res && complex.num_blockers() == 1; + cerr << "----> Ocomplex \n"; + return res; } -bool test_collapse2(){ - Complex complex(5); - build_complete(4,complex); - complex.add_vertex(); - complex.add_edge(Vertex_handle(1),Vertex_handle(4)); - complex.add_edge(Vertex_handle(2),Vertex_handle(4)); - complex.add_edge(Vertex_handle(3),Vertex_handle(4)); - complex.add_blocker(Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3),Vertex_handle(4))); - // Print result - cerr << "initial complex :\n"<< complex.to_string(); - cerr <(2)); - cerr << "complex after remove star of 2:\n"<< complex.to_string(); - - bool blocker134_here = complex.contains_blocker(Simplex_handle(Vertex_handle(1),Vertex_handle(3),Vertex_handle(4))); - bool blocker1234_here = complex.contains_blocker(Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3),Vertex_handle(4))); - return blocker134_here && !blocker1234_here; +bool test_collapse3() { + Complex complex(5); + build_complete(4, complex); + complex.add_vertex(); + complex.add_edge_without_blockers(Vertex_handle(1), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4)); + complex.add_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3), Vertex_handle(4))); + // Print result + cerr << "initial complex:\n" << complex.to_string(); + cerr << endl << endl; + + complex.remove_star(static_cast (2)); + cerr << "complex after remove star of 2:\n" << complex.to_string(); + + bool blocker134_here = complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(3), Vertex_handle(4))); + bool blocker1234_here = complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3), Vertex_handle(4))); + return blocker134_here && !blocker1234_here; } -bool test_add_simplex(){ - Complex complex(5); - build_complete(4,complex); - complex.add_blocker(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); - // Print result - cerr << "initial complex:\n"<< complex.to_string(); - cerr < simplices(complex.simplex_range().begin(),complex.simplex_range().end()); - sort(simplices.begin(),simplices.end(),[&](const Simplex_handle& s1,const Simplex_handle& s2){ - return s1.dimension()1) - copy.add_simplex(simplex); - } + std::vector simplices(complex.complex_simplex_range().begin(), complex.complex_simplex_range().end()); + sort(simplices.begin(), simplices.end(), [&](const Simplex& s1, const Simplex & s2) { + return s1.dimension() < s2.dimension(); + }); + for (const auto & simplex : simplices) { + if (!copy.contains(simplex) && simplex.dimension() == 1) + copy.add_edge_without_blockers(simplex.first_vertex(), simplex.last_vertex()); + if (!copy.contains(simplex) && simplex.dimension() > 1) + copy.add_simplex(simplex); + } - cerr << "complex after add_simplex:\n"<< copy.to_string(); + cerr << "complex after add_simplex:\n" << copy.to_string(); - return complex.num_blockers()==copy.num_blockers() && - complex.num_edges()==copy.num_edges() && - complex.num_vertices()==copy.num_vertices(); + return complex.num_blockers() == copy.num_blockers() && + complex.num_edges() == copy.num_edges() && + complex.num_vertices() == copy.num_vertices(); } +bool test_add_simplex3() { + Complex complex(5); + build_complete(5, complex); + complex.remove_edge(Vertex_handle(3), Vertex_handle(4)); + Simplex sigma(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2)); + complex.add_blocker(sigma); + // Print result + cerr << "initial complex:\n" << complex.to_string(); + cerr << endl << endl; + complex.add_simplex(sigma); + //should create two blockers 0123 and 0124 + cerr << "complex after adding simplex 012:\n" << complex.to_string(); + return complex.num_blockers() == 2 + && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))) + && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(4))); +} - -bool test_remove_popable_blockers(){ - Complex complex; - build_complete(4,complex); - complex.add_vertex(); - complex.add_edge(Vertex_handle(3),Vertex_handle(4)); - complex.add_edge(Vertex_handle(2),Vertex_handle(4)); - Simplex_handle sigma1=Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3)); - Simplex_handle sigma2=Simplex_handle(Vertex_handle(2),Vertex_handle(3),Vertex_handle(4)); - - complex.add_blocker(sigma1); - complex.add_blocker(sigma2); - cerr << "complex complex"<< complex.to_string(); - cerr < 0) + return false; + if (i >= 2 && complex.num_blockers() != 1) { + Simplex b; + for (int k = 0; k < i; k++) + b.add_vertex(Vertex_handle(i)); + if (!complex.contains_blocker(b)) + return false; + } + TESTVALUE(complex.blockers_to_string()); + } + Simplex s; + for (int k = 0; k < n; k++) + s.add_vertex(Vertex_handle(k)); + return complex.num_blockers() == 1 && complex.contains_blocker(s); } +bool test_add_edge() { + Complex complex(4); + for (unsigned i = 0u; i < 4; i++) + complex.add_edge(Vertex_handle(i), Vertex_handle((i + 1) % 4)); + + // Print result + cerr << "initial complex:\n" << complex.to_string(); + cerr << endl << endl; + complex.add_edge(Vertex_handle(1), Vertex_handle(3)); + //should create two blockers 013 and 012 + cerr << "complex after adding edge 13:\n" << complex.to_string(); + return complex.num_blockers() == 2 + && complex.contains_blocker(Simplex(Vertex_handle(0), Vertex_handle(1), Vertex_handle(3))) + && complex.contains_blocker(Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); +} +bool test_remove_popable_blockers() { + Complex complex; + build_complete(4, complex); + complex.add_vertex(); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(4)); + Simplex sigma1 = Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + Simplex sigma2 = Simplex(Vertex_handle(2), Vertex_handle(3), Vertex_handle(4)); + + complex.add_blocker(sigma1); + complex.add_blocker(sigma2); + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + cerr << "complex.RemovePopableBlockers();" << endl; + complex.remove_popable_blockers(); + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + + bool test1 = (complex.num_blockers() == 1); + + + // test 2 + complex.clear(); + build_complete(4, complex); + complex.add_vertex(); + complex.add_vertex(); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(4)); + complex.add_edge_without_blockers(Vertex_handle(2), Vertex_handle(5)); + complex.add_edge_without_blockers(Vertex_handle(3), Vertex_handle(5)); + complex.add_edge_without_blockers(Vertex_handle(4), Vertex_handle(5)); + sigma1 = Simplex(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + sigma2 = Simplex(Vertex_handle(2), Vertex_handle(3), Vertex_handle(4)); + + complex.add_blocker(sigma1); + complex.add_blocker(sigma2); + cerr << "complex complex" << complex.to_string(); + cerr << endl << endl; + cerr << "complex.RemovePopableBlockers();" << endl; + complex.remove_popable_blockers(); + cerr << "complex complex" << complex.to_string(); + + cerr << endl << endl; + bool test2 = (complex.num_blockers() == 0); + return test1&&test2; +} -int main (int argc, char *argv[]) -{ - Tests tests_simplifiable_complex; - tests_simplifiable_complex.add("Test contraction 1",test_contraction1); - tests_simplifiable_complex.add("Test contraction 2",test_contraction2); - tests_simplifiable_complex.add("Test Link condition 1",test_link_condition1); - tests_simplifiable_complex.add("Test remove popable blockers",test_remove_popable_blockers); +int main(int argc, char *argv[]) { + Tests tests_simplifiable_complex; + tests_simplifiable_complex.add("Test contraction 1", test_contraction1); + tests_simplifiable_complex.add("Test contraction 2", test_contraction2); + tests_simplifiable_complex.add("Test Link condition 1", test_link_condition1); + tests_simplifiable_complex.add("Test remove popable blockers", test_remove_popable_blockers); - tests_simplifiable_complex.add("Test collapse 0",test_collapse0); - tests_simplifiable_complex.add("Test collapse 1",test_collapse1); - tests_simplifiable_complex.add("Test collapse 2",test_collapse2); - tests_simplifiable_complex.add("Test collapse 3",test_collapse3); + tests_simplifiable_complex.add("Test collapse 0", test_collapse0); + tests_simplifiable_complex.add("Test collapse 1", test_collapse1); + tests_simplifiable_complex.add("Test collapse 2", test_collapse2); + tests_simplifiable_complex.add("Test collapse 3", test_collapse3); - tests_simplifiable_complex.add("Test add simplex",test_add_simplex); - tests_simplifiable_complex.add("Test add simplex2",test_add_simplex2); + tests_simplifiable_complex.add("Test add edge",test_add_edge); + tests_simplifiable_complex.add("Test add simplex", test_add_simplex); + tests_simplifiable_complex.add("Test add simplex2", test_add_simplex2); + tests_simplifiable_complex.add("Test add simplex3",test_add_simplex3); + tests_simplifiable_complex.add("Test add simplex4",test_add_simplex4); - tests_simplifiable_complex.run(); + tests_simplifiable_complex.run(); - if(tests_simplifiable_complex.run()) - return EXIT_SUCCESS; - else - return EXIT_FAILURE; + if (tests_simplifiable_complex.run()) + return EXIT_SUCCESS; + else + return EXIT_FAILURE; } -- cgit v1.2.3 From 0e156a914ecfa1e8d71a8bee49400ed66a191637 Mon Sep 17 00:00:00 2001 From: salinasd Date: Sat, 14 Nov 2015 15:21:34 +0000 Subject: skbl: correct typo in test and small renamings git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/skb_simplex_insertion_merge@918 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 543ae94051051e1a79f95192db24fcd411dbea28 --- .../example/Skeleton_blocker_link.cpp | 7 ++- .../Skeleton_blocker/Skeleton_blocker_simplex.h | 4 +- .../include/gudhi/Skeleton_blocker_complex.h | 58 +++++++++++----------- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 15 ++++-- src/Skeleton_blocker/test/TestSimplifiable.cpp | 2 +- .../test/TestSkeletonBlockerComplex.cpp | 2 +- 6 files changed, 48 insertions(+), 40 deletions(-) (limited to 'src/Skeleton_blocker/test/TestSimplifiable.cpp') diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp index 5c717938..5e429728 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp @@ -39,9 +39,12 @@ typedef Complex::Simplex Simplex; int main(int argc, char *argv[]) { // build a full complex with 4 vertices and 2^4-1 simplices - // Initial vertices are (0,1,2,3,4) - Simplex tetrahedron(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + + // Create a complex with four vertices (0,1,2,3) Complex complex; + + // Add a tetrahedron to this complex + Simplex tetrahedron(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); complex.add_simplex(tetrahedron); cout << "complex:" << complex.to_string() << endl; diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h index 0d838d50..714bf23c 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h @@ -218,7 +218,7 @@ class Skeleton_blocker_simplex { } /** - * Returns the first vertex of the (oriented) simplex. + * Returns the first and smallest vertex of the simplex. * * Be careful : assumes the simplex is non-empty. */ @@ -228,7 +228,7 @@ class Skeleton_blocker_simplex { } /** - * Returns the last vertex of the (oriented) simplex. + * Returns the last and greatest vertex of the simplex. * * Be careful : assumes the simplex is non-empty. */ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index b1995783..cf156a58 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -23,16 +23,26 @@ #ifndef SKELETON_BLOCKER_COMPLEX_H_ #define SKELETON_BLOCKER_COMPLEX_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include #include #include - #include #include #include - #include #include @@ -40,18 +50,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - namespace Gudhi { namespace skbl { @@ -182,25 +180,28 @@ class Skeleton_blocker_complex { * @details is_flag_complex indicates if the complex is a flag complex or not (to know if blockers have to be computed or not). */ template - Skeleton_blocker_complex(SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end, + Skeleton_blocker_complex(SimpleHandleOutputIterator simplices_begin, SimpleHandleOutputIterator simplices_end, bool is_flag_complex = false, Visitor* visitor_ = NULL) : num_vertices_(0), num_blockers_(0), visitor(visitor_) { - add_vertex_and_edges(simplex_begin, simplex_end); + add_vertices_and_edges(simplices_begin, simplices_end); if (!is_flag_complex) // need to compute blockers - add_blockers(simplex_begin, simplex_end); + add_blockers(simplices_begin, simplices_end); } private: + /** + * Add vertices and edges of a simplex in one pass + */ template - void add_vertex_and_edges(SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end) { + void add_vertices_and_edges(SimpleHandleOutputIterator simplices_begin, SimpleHandleOutputIterator simplices_end) { std::vector> edges; // first pass to add vertices and edges int num_vertex = -1; - for (auto s_it = simplex_begin; s_it != simplex_end; ++s_it) { + for (auto s_it = simplices_begin; s_it != simplices_end; ++s_it) { if (s_it->dimension() == 0) num_vertex = (std::max)(num_vertex, s_it->first_vertex().vertex); if (s_it->dimension() == 1) edges.emplace_back(s_it->first_vertex(), s_it->last_vertex()); } @@ -210,9 +211,10 @@ class Skeleton_blocker_complex { add_edge_without_blockers(e.first, e.second); } + template - void add_blockers(SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end) { - Tries tries(num_vertices(), simplex_begin, simplex_end); + void add_blockers(SimpleHandleOutputIterator simplices_begin, SimpleHandleOutputIterator simplices_end) { + Tries tries(num_vertices(), simplices_begin, simplices_end); tries.init_next_dimension(); auto simplices(tries.next_dimension_simplices()); @@ -378,6 +380,7 @@ class Skeleton_blocker_complex { /** * @brief Adds a vertex to the simplicial complex and returns its Vertex_handle. + * @remark Vertex representation is contiguous. */ Vertex_handle add_vertex() { Vertex_handle address(boost::add_vertex(skeleton)); @@ -1128,13 +1131,10 @@ class Skeleton_blocker_complex { void remove_star(const Simplex& sigma); /** - * @brief add a simplex. - * @details the simplex must have dimension greater than one (otherwise use add_vertex or add_edge_without_blockers). - * and all vertices lower than the higher vertex of sigma must already be in the complex. - * if some edges of sigma are not in the complex, then insert_edges_of_sigma flag must be - * set to true. + * @brief add a simplex and all its faces. + * @details the simplex must have dimension greater than one (otherwise use add_vertex or add_edge_without_blockers). */ - void add_simplex(const Simplex& sigma, bool insert_edges_of_sigma = false); + void add_simplex(const Simplex& sigma); private: void add_blockers_after_simplex_insertion(Simplex s); @@ -1583,12 +1583,12 @@ class Skeleton_blocker_complex { * return the total number of simplices */ template -Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, SimplexHandleIterator simplex_end, +Complex make_complex_from_top_faces(SimplexHandleIterator simplices_begin, SimplexHandleIterator simplices_end, bool is_flag_complex = false) { //todo use add_simplex instead! should be more efficient and more elegant :) typedef typename Complex::Simplex Simplex; std::vector simplices; - for (auto top_face = simplex_begin; top_face != simplex_end; ++top_face) { + for (auto top_face = simplices_begin; top_face != simplices_end; ++top_face) { auto subfaces_topface = subfaces(*top_face); simplices.insert(simplices.end(), subfaces_topface.begin(), subfaces_topface.end()); } diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h index 79a7ed79..1b7d58ff 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -206,21 +206,26 @@ void Skeleton_blocker_complex::remove_star(const Simplex& sig } template -void Skeleton_blocker_complex::add_simplex(const Simplex& sigma, bool insert_edges_of_sigma) { +void Skeleton_blocker_complex::add_simplex(const Simplex& sigma) { // to add a simplex s, all blockers included in s are first removed // and then all simplex in the coboundary of s are added as blockers assert(!this->contains(sigma)); assert(sigma.dimension() > 1); + if (!contains_vertices(sigma)) { + std::cerr << "add_simplex: Some vertices were not present in the complex, adding them" << std::endl; + size_t num_vertices_to_add = sigma.last_vertex() - this->num_vertices() + 1; + for (size_t i = 0; i < num_vertices_to_add; ++i) + this->add_vertex(); + } assert(contains_vertices(sigma)); - - if(insert_edges_of_sigma) + if(!contains_edges(sigma)) add_edge(sigma); - else - assert(contains_edges(sigma)); remove_blocker_include_in_simplex(sigma); add_blockers_after_simplex_insertion(sigma); } + + template void Skeleton_blocker_complex::add_blockers_after_simplex_insertion(Simplex sigma){ if(sigma.dimension() < 1) return; diff --git a/src/Skeleton_blocker/test/TestSimplifiable.cpp b/src/Skeleton_blocker/test/TestSimplifiable.cpp index 76d5ba89..b0855ce9 100644 --- a/src/Skeleton_blocker/test/TestSimplifiable.cpp +++ b/src/Skeleton_blocker/test/TestSimplifiable.cpp @@ -310,7 +310,7 @@ bool test_add_simplex4() { for (int k = 0; k < n; k++) s.add_vertex(Vertex_handle(k)); s.remove_vertex(Vertex_handle(i)); - complex.add_simplex(s, true); + complex.add_simplex(s); //at step i there is only blocker 0..i if (i < 2 && complex.num_blockers() > 0) diff --git a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp index 69abd279..42482e23 100644 --- a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp +++ b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp @@ -367,7 +367,7 @@ bool test_iterator_simplices4() { bool test_iterator_coboundary() { Complex c; build_complete(4, c); - c.remove_edge(Vertex_handle(0), Vertex_handle(2)); + c.remove_edge(Vertex_handle(1), Vertex_handle(3)); PRINT(c.to_string()); Simplex s02(Vertex_handle(0), Vertex_handle(2)); int n = 0; -- cgit v1.2.3