From e6992894cf4e9b76acee98e2c1ad840a3ebd7274 Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 4 Oct 2016 18:07:42 +0000 Subject: Fixed a major bug in the Active_witness_iterator git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1633 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d4f474b44835b11e65a152f9d3fe87cc32b527f5 --- .../test/simple_witness_complex.cpp | 86 +++++++++++++++++----- 1 file changed, 66 insertions(+), 20 deletions(-) (limited to 'src/Witness_complex/test/simple_witness_complex.cpp') diff --git a/src/Witness_complex/test/simple_witness_complex.cpp b/src/Witness_complex/test/simple_witness_complex.cpp index 03df78ee..30b168c1 100644 --- a/src/Witness_complex/test/simple_witness_complex.cpp +++ b/src/Witness_complex/test/simple_witness_complex.cpp @@ -25,6 +25,8 @@ #include #include +#include + #include #include @@ -34,26 +36,70 @@ typedef Gudhi::Simplex_tree<> Simplex_tree; typedef std::vector< Vertex_handle > typeVectorVertex; -typedef Gudhi::witness_complex::Witness_complex WitnessComplex; +typedef CGAL::Epick_d Kernel; +typedef typename Kernel::FT FT; +typedef typename Kernel::Point_d Point_d; +typedef Gudhi::witness_complex::Witness_complex WitnessComplex; + +/* All landmarks and witnesses are taken on the grid in the following manner. + LWLWL 2W4W7 + WW.WW WW.WW + L...L 1...6 + WW.WW WW.WW + LWLWL 0W3W5 + + Witness complex consists of 8 vertices, 12 edges and 4 triangles + */ BOOST_AUTO_TEST_CASE(simple_witness_complex) { - Simplex_tree complex; - std::vector< typeVectorVertex > knn; - - knn.push_back({1, 0, 5, 2, 6, 3, 4}); - knn.push_back({2, 6, 4, 5, 0, 1, 3}); - knn.push_back({3, 4, 2, 1, 5, 6, 0}); - knn.push_back({4, 2, 1, 3, 5, 6, 0}); - knn.push_back({5, 1, 6, 0, 2, 3, 4}); - knn.push_back({6, 0, 5, 2, 1, 3, 4}); - knn.push_back({0, 5, 6, 1, 2, 3, 4}); - knn.push_back({2, 6, 4, 5, 3, 1, 0}); - knn.push_back({1, 2, 5, 4, 3, 6, 0}); - knn.push_back({3, 4, 0, 6, 5, 1, 2}); - knn.push_back({5, 0, 1, 3, 6, 2, 4}); - knn.push_back({5, 6, 1, 0, 2, 3, 4}); - knn.push_back({1, 6, 0, 5, 2, 3, 4}); - WitnessComplex witnessComplex(knn, 7, 7, complex); - - BOOST_CHECK(witnessComplex.is_witness_complex(knn, false)); + Simplex_tree complex, relaxed_complex; + + std::vector witnesses, landmarks; + + landmarks.push_back(Point_d(std::vector{-2,-2})); + landmarks.push_back(Point_d(std::vector{-2, 0})); + landmarks.push_back(Point_d(std::vector{-2, 2})); + landmarks.push_back(Point_d(std::vector{ 0,-2})); + landmarks.push_back(Point_d(std::vector{ 0, 2})); + landmarks.push_back(Point_d(std::vector{ 2,-2})); + landmarks.push_back(Point_d(std::vector{ 2, 0})); + landmarks.push_back(Point_d(std::vector{ 2, 2})); + witnesses.push_back(Point_d(std::vector{-2,-1})); + witnesses.push_back(Point_d(std::vector{-2, 1})); + witnesses.push_back(Point_d(std::vector{-1,-2})); + witnesses.push_back(Point_d(std::vector{-1,-1})); + witnesses.push_back(Point_d(std::vector{-1, 1})); + witnesses.push_back(Point_d(std::vector{-1, 2})); + witnesses.push_back(Point_d(std::vector{ 1,-2})); + witnesses.push_back(Point_d(std::vector{ 1,-1})); + witnesses.push_back(Point_d(std::vector{ 1, 1})); + witnesses.push_back(Point_d(std::vector{ 1, 2})); + witnesses.push_back(Point_d(std::vector{ 2,-1})); + witnesses.push_back(Point_d(std::vector{ 2, 1})); + + // landmarks.push_back(Point_d(std::vector{1,0})); + // landmarks.push_back(Point_d(std::vector{0,0})); + // landmarks.push_back(Point_d(std::vector{0,1})); + // witnesses.push_back(Point_d(std::vector{1,0})); + + WitnessComplex witness_complex(landmarks.begin(), + landmarks.end(), + witnesses.begin(), + witnesses.end()); + // witness_complex.create_complex(complex, 0); + + //std::cout << complex << "\n"; + + // BOOST_CHECK(complex.num_simplices() == 24); + + witness_complex.create_complex(relaxed_complex, 8.01); + + std::cout << "Num_simplices: " << relaxed_complex.num_simplices() << "\n"; + std::cout << relaxed_complex << "\n"; + + //BOOST_CHECK(relaxed_complex.num_simplices() == 24); + + //BOOST_CHECK(witnessComplex.is_witness_complex(knn, false)); + + } -- cgit v1.2.3 From 30eb48c287ef6453a095535306b2a9acf672472a Mon Sep 17 00:00:00 2001 From: skachano Date: Tue, 4 Oct 2016 19:49:40 +0000 Subject: Strong witness is ready as well git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1636 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1e50ece69054b45787353c37877fdfa970209f20 --- src/Witness_complex/test/simple_witness_complex.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/Witness_complex/test/simple_witness_complex.cpp') diff --git a/src/Witness_complex/test/simple_witness_complex.cpp b/src/Witness_complex/test/simple_witness_complex.cpp index 30b168c1..0c2c3710 100644 --- a/src/Witness_complex/test/simple_witness_complex.cpp +++ b/src/Witness_complex/test/simple_witness_complex.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -40,6 +41,7 @@ typedef CGAL::Epick_d Kernel; typedef typename Kernel::FT FT; typedef typename Kernel::Point_d Point_d; typedef Gudhi::witness_complex::Witness_complex WitnessComplex; +typedef Gudhi::witness_complex::Strong_witness_complex StrongWitnessComplex; /* All landmarks and witnesses are taken on the grid in the following manner. LWLWL 2W4W7 @@ -52,7 +54,7 @@ typedef Gudhi::witness_complex::Witness_complex WitnessComplex; */ BOOST_AUTO_TEST_CASE(simple_witness_complex) { - Simplex_tree complex, relaxed_complex; + Simplex_tree complex, relaxed_complex, strong_relaxed_complex; std::vector witnesses, landmarks; @@ -92,11 +94,20 @@ BOOST_AUTO_TEST_CASE(simple_witness_complex) { // BOOST_CHECK(complex.num_simplices() == 24); - witness_complex.create_complex(relaxed_complex, 8.01); + // witness_complex.create_complex(relaxed_complex, 8.01); - std::cout << "Num_simplices: " << relaxed_complex.num_simplices() << "\n"; - std::cout << relaxed_complex << "\n"; + // std::cout << "Num_simplices: " << relaxed_complex.num_simplices() << "\n"; + // std::cout << relaxed_complex << "\n"; + StrongWitnessComplex strong_witness_complex(landmarks.begin(), + landmarks.end(), + witnesses.begin(), + witnesses.end()); + + strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); + std::cout << "Num_simplices: " << strong_relaxed_complex.num_simplices() << "\n"; + std::cout << strong_relaxed_complex << "\n"; + //BOOST_CHECK(relaxed_complex.num_simplices() == 24); //BOOST_CHECK(witnessComplex.is_witness_complex(knn, false)); -- cgit v1.2.3 From d439da1345822fe25f58adb631f7d0cd9749ecfc Mon Sep 17 00:00:00 2001 From: skachano Date: Wed, 5 Oct 2016 17:06:15 +0000 Subject: Modified existing tests and examples git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/relaxed-witness@1647 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: cd187fe5bc9174403aa5dc96c74871c697b3a5e6 --- src/Witness_complex/example/CMakeLists.txt | 10 +- .../example/example_witness_complex_off.cpp | 86 ++++++ .../example/example_witness_complex_sphere.cpp | 98 +++++++ src/Witness_complex/example/output.h | 308 --------------------- src/Witness_complex/example/output_tikz.h | 178 ------------ .../example/witness_complex_from_file.cpp | 106 ------- .../example/witness_complex_sphere.cpp | 99 ------- src/Witness_complex/test/CMakeLists.txt | 10 +- .../test/simple_witness_complex.cpp | 116 -------- .../test/test_simple_witness_complex.cpp | 103 +++++++ 10 files changed, 295 insertions(+), 819 deletions(-) create mode 100644 src/Witness_complex/example/example_witness_complex_off.cpp create mode 100644 src/Witness_complex/example/example_witness_complex_sphere.cpp delete mode 100644 src/Witness_complex/example/output.h delete mode 100644 src/Witness_complex/example/output_tikz.h delete mode 100644 src/Witness_complex/example/witness_complex_from_file.cpp delete mode 100644 src/Witness_complex/example/witness_complex_sphere.cpp delete mode 100644 src/Witness_complex/test/simple_witness_complex.cpp create mode 100644 src/Witness_complex/test/test_simple_witness_complex.cpp (limited to 'src/Witness_complex/test/simple_witness_complex.cpp') diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt index 0054775d..469c9aac 100644 --- a/src/Witness_complex/example/CMakeLists.txt +++ b/src/Witness_complex/example/CMakeLists.txt @@ -1,17 +1,13 @@ cmake_minimum_required(VERSION 2.6) project(Witness_complex_examples) -# A simple example - add_executable( witness_complex_from_file witness_complex_from_file.cpp ) - add_test( witness_complex_from_bunny ${CMAKE_CURRENT_BINARY_DIR}/witness_complex_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 100) if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.6.0) if (EIGEN3_FOUND) - add_executable ( witness_complex_sphere witness_complex_sphere.cpp ) - target_link_libraries(witness_complex_sphere ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) - add_test( witness_complex_sphere_10 ${CMAKE_CURRENT_BINARY_DIR}/witness_complex_sphere 10) - add_executable ( relaxed_witness_persistence relaxed_witness_persistence.cpp ) + add_executable( Witness_complex_example_off example_witness_complex_off.cpp ) + add_executable ( Witness_complex_example_sphere example_witness_complex_sphere.cpp ) + #add_executable ( relaxed_witness_persistence relaxed_witness_persistence.cpp ) endif(EIGEN3_FOUND) endif (NOT CGAL_VERSION VERSION_LESS 4.6.0) endif() diff --git a/src/Witness_complex/example/example_witness_complex_off.cpp b/src/Witness_complex/example/example_witness_complex_off.cpp new file mode 100644 index 00000000..6b0060d9 --- /dev/null +++ b/src/Witness_complex/example/example_witness_complex_off.cpp @@ -0,0 +1,86 @@ +/* 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): Siargey Kachanovich + * + * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +typedef CGAL::Epick_d K; +typedef typename K::Point_d Point_d; +typedef typename Gudhi::witness_complex::Witness_complex Witness_complex; +typedef std::vector< Vertex_handle > typeVectorVertex; +typedef std::vector< Point_d > Point_vector; + +int main(int argc, char * const argv[]) { + if (argc != 4) { + std::cerr << "Usage: " << argv[0] + << " path_to_point_file nbL alpha^2\n"; + return 0; + } + + std::string file_name = argv[1]; + int nbL = atoi(argv[2]); + double alpha2 = atof(argv[3]); + clock_t start, end; + + // Construct the Simplex Tree + Gudhi::Simplex_tree<> simplex_tree; + + // Read the point file + Point_vector point_vector, landmarks; + Gudhi::Points_off_reader off_reader(file_name); + if (!off_reader.is_valid()) { + std::cerr << "Witness complex - Unable to read file " << file_name << "\n"; + exit(-1); // ----- >> + } + point_vector = Point_vector(off_reader.get_point_cloud()); + + std::cout << "Successfully read " << point_vector.size() << " points.\n"; + std::cout << "Ambient dimension is " << point_vector[0].dimension() << ".\n"; + + // Choose landmarks + Gudhi::subsampling::pick_n_random_points(point_vector, nbL, std::back_inserter(landmarks)); + + // Compute witness complex + start = clock(); + Witness_complex witness_complex(landmarks.begin(), + landmarks.end(), + point_vector.begin(), + point_vector.end()); + witness_complex.create_complex(simplex_tree, alpha2); + end = clock(); + std::cout << "Witness complex took " + << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; + std::cout << "Number of simplices is: " << simplex_tree.num_simplices() << "\n"; +} diff --git a/src/Witness_complex/example/example_witness_complex_sphere.cpp b/src/Witness_complex/example/example_witness_complex_sphere.cpp new file mode 100644 index 00000000..8e2c5ff6 --- /dev/null +++ b/src/Witness_complex/example/example_witness_complex_sphere.cpp @@ -0,0 +1,98 @@ +/* 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): Siargey Kachanovich + * + * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#define BOOST_PARAMETER_MAX_ARITY 12 + + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "generators.h" + +/** Write a gnuplot readable file. + * Data range is a random access range of pairs (arg, value) + */ +template < typename Data_range > +void write_data(Data_range & data, std::string filename) { + std::ofstream ofs(filename, std::ofstream::out); + for (auto entry : data) + ofs << entry.first << ", " << entry.second << "\n"; + ofs.close(); +} + +int main(int argc, char * const argv[]) { + typedef Gudhi::witness_complex::Witness_complex> Witness_complex; + + if (argc != 2) { + std::cerr << "Usage: " << argv[0] + << " number_of_landmarks \n"; + return 0; + } + + int number_of_landmarks = atoi(argv[1]); + clock_t start, end; + + std::vector< std::pair > l_time; + + // Read the point file + for (int nbP = 500; nbP < 10000; nbP += 500) { + // Construct the Simplex Tree + Gudhi::Simplex_tree<> simplex_tree; + Point_Vector point_vector, landmarks; + generate_points_sphere(point_vector, nbP, 4); + std::cout << "Successfully generated " << point_vector.size() << " points.\n"; + std::cout << "Ambient dimension is " << point_vector[0].size() << ".\n"; + + // Choose landmarks + start = clock(); + Gudhi::subsampling::pick_n_random_points(point_vector, number_of_landmarks, std::back_inserter(landmarks)); + + // Compute witness complex + Witness_complex witness_complex(landmarks.begin(), + landmarks.end(), + point_vector.begin(), + point_vector.end()); + witness_complex.create_complex(simplex_tree, 0); + end = clock(); + double time = static_cast(end - start) / CLOCKS_PER_SEC; + std::cout << "Witness complex for " << number_of_landmarks << " landmarks took " + << time << " s. \n"; + //assert(1 == 0); + //std::cout << simplex_tree << "\n"; + std::cout << "Number of simplices is: " << simplex_tree.num_simplices() << "\n"; + l_time.push_back(std::make_pair(nbP, time)); + } + write_data(l_time, "w_time.dat"); +} diff --git a/src/Witness_complex/example/output.h b/src/Witness_complex/example/output.h deleted file mode 100644 index d3f534af..00000000 --- a/src/Witness_complex/example/output.h +++ /dev/null @@ -1,308 +0,0 @@ -#ifndef OUTPUT_H -#define OUTPUT_H - -#include -#include -#include - -#include - -#include -#include - -//typename Gudhi::Witness_complex<> Witness_complex; - -typedef CGAL::Epick_d K; -typedef K::Point_d Point_d; -typedef std::vector Point_Vector; -typedef CGAL::Delaunay_triangulation Delaunay_triangulation; - -/** \brief Write the table of the nearest landmarks to each witness - * to a file. - */ -template -void write_wl( std::string file_name, std::vector< std::vector > & WL) -{ - std::ofstream ofs (file_name, std::ofstream::out); - for (auto w : WL) - { - for (auto l: w) - ofs << l << " "; - ofs << "\n"; - } - ofs.close(); -} - -/** \brief Write the coordinates of points in points to a file. - * - */ -void write_points( std::string file_name, std::vector< Point_d > & points) -{ - std::ofstream ofs (file_name, std::ofstream::out); - for (auto w : points) - { - for (auto it = w.cartesian_begin(); it != w.cartesian_end(); ++it) - ofs << *it << " "; - ofs << "\n"; - } - ofs.close(); -} - -/** Write edges of a witness complex in a file. - * The format of an edge is coordinates of u \n coordinates of v \n\n\n - * This format is compatible with gnuplot - */ -template< typename STree > -void write_edges(std::string file_name, STree& witness_complex, Point_Vector& landmarks) -{ - std::ofstream ofs (file_name, std::ofstream::out); - for (auto u: witness_complex.complex_vertex_range()) - for (auto v: witness_complex.complex_vertex_range()) - { - std::vector edge = {u,v}; - if (u < v && witness_complex.find(edge) != witness_complex.null_simplex()) - { - for (auto it = landmarks[u].cartesian_begin(); it != landmarks[u].cartesian_end(); ++it) - ofs << *it << " "; - ofs << "\n"; - for (auto it = landmarks[v].cartesian_begin(); it != landmarks[v].cartesian_end(); ++it) - ofs << *it << " "; - ofs << "\n\n\n"; - } - } - ofs.close(); -} - -/** \brief Write triangles (tetrahedra in 3d) of a simplicial complex in a file, compatible with medit. - * `landmarks_ind` represents the set of landmark indices in W - * `st` is the Simplex_tree to be visualized, - * `shr` is the Simplex_handle_range of simplices in `st` to be visualized - * `is2d` should be true if the simplicial complex is 2d, false if 3d - * `l_is_v` = landmark is vertex - */ -template -void write_witness_mesh(Point_Vector& W, std::vector& landmarks_ind, STree& st, SimplexHandleRange const & shr, bool is2d, bool l_is_v, std::string file_name = "witness.mesh") -{ - std::ofstream ofs (file_name, std::ofstream::out); - if (is2d) - ofs << "MeshVersionFormatted 1\nDimension 2\n"; - else - ofs << "MeshVersionFormatted 1\nDimension 3\n"; - - if (!l_is_v) - ofs << "Vertices\n" << W.size() << "\n"; - else - ofs << "Vertices\n" << landmarks_ind.size() << "\n"; - - if (l_is_v) - for (auto p_it : landmarks_ind) { - for (auto coord = W[p_it].cartesian_begin(); coord != W[p_it].cartesian_end() && coord != W[p_it].cartesian_begin()+3 ; ++coord) - ofs << *coord << " "; - ofs << "508\n"; - } - else - for (auto p_it : W) { - for (auto coord = p_it.cartesian_begin(); coord != p_it.cartesian_end() && coord != p_it.cartesian_begin()+3 ; ++coord) - ofs << *coord << " "; - ofs << "508\n"; - } - - // int num_triangles = W.size(), num_tetrahedra = 0; - int num_edges = 0, num_triangles = 0, num_tetrahedra = 0; - if (!l_is_v) { - for (auto sh_it : shr) - if (st.dimension(sh_it) == 1) - num_edges++; - else if (st.dimension(sh_it) == 2) - num_triangles++; - else if (st.dimension(sh_it) == 3) - num_tetrahedra++; - ofs << "Edges " << num_edges << "\n"; - for (auto sh_it : shr) { - if (st.dimension(sh_it) == 1) { - for (auto v_it : st.simplex_vertex_range(sh_it)) - ofs << landmarks_ind[v_it]+1 << " "; - ofs << "200\n"; - } - } - ofs << "Triangles " << num_triangles << "\n"; - for (unsigned i = 0; i < W.size(); ++i) - ofs << i << " " << i << " " << i << " " << "508\n"; - for (auto sh_it : shr) - { - if (st.dimension(sh_it) == 2) { - for (auto v_it : st.simplex_vertex_range(sh_it)) - ofs << landmarks_ind[v_it]+1 << " "; - ofs << "508\n"; - } - } - ofs << "Tetrahedra " << num_tetrahedra << "\n"; - for (auto sh_it : shr) - { - if (st.dimension(sh_it) == 3) { - for (auto v_it : st.simplex_vertex_range(sh_it)) - ofs << landmarks_ind[v_it]+1 << " "; - ofs << "250\n"; - } - } - } - else { - for (auto sh_it : shr) - if (st.dimension(sh_it) == 1) - num_edges++; - else if (st.dimension(sh_it) == 2) - num_triangles++; - else if (st.dimension(sh_it) == 3) - num_tetrahedra++; - ofs << "Edges " << num_edges << "\n"; - for (auto sh_it : shr) { - if (st.dimension(sh_it) == 1) { - for (auto v_it : st.simplex_vertex_range(sh_it)) - ofs << v_it+1 << " "; - ofs << "200\n"; - } - } - ofs << "Triangles " << num_triangles << "\n"; - for (auto sh_it : shr) - { - if (st.dimension(sh_it) == 2) { - for (auto v_it : st.simplex_vertex_range(sh_it)) - ofs << v_it+1 << " "; - ofs << "508\n"; - } - } - ofs << "Tetrahedra " << num_tetrahedra << "\n"; - for (auto sh_it : shr) - { - if (st.dimension(sh_it) == 3) { - for (auto v_it : st.simplex_vertex_range(sh_it)) - ofs << v_it+1 << " "; - ofs << "250\n"; - } - } - } - - ofs << "End\n"; - /* - else - { - ofs << "Tetrahedra " << t.number_of_finite_full_cells()+1 << "\n"; - for (auto fc_it = t.full_cells_begin(); fc_it != t.full_cells_end(); ++fc_it) - { - if (t.is_infinite(fc_it)) - continue; - for (auto vh_it = fc_it->vertices_begin(); vh_it != fc_it->vertices_end(); ++vh_it) - ofs << index_of_vertex[*vh_it] << " "; - ofs << "508\n"; - } - ofs << nbV << " " << nbV << " " << nbV << " " << nbV << " " << 208 << "\n"; - ofs << "End\n"; - } - */ - ofs.close(); -} - -void write_witness_mesh(Point_Vector& W, std::vector& landmarks_ind, Gudhi::Simplex_tree<>& st, bool is2d, bool l_is_v, std::string file_name = "witness.mesh") -{ - write_witness_mesh(W, landmarks_ind, st, st.complex_simplex_range(), is2d, l_is_v, file_name); -} - -/** \brief Write triangles (tetrahedra in 3d) of a Delaunay - * triangulation in a file, compatible with medit. - */ -void write_delaunay_mesh(Delaunay_triangulation& t, const Point_d& p, bool is2d) -{ - std::ofstream ofs ("delaunay.mesh", std::ofstream::out); - int nbV = t.number_of_vertices()+1; - if (is2d) - ofs << "MeshVersionFormatted 1\nDimension 2\n"; - else - ofs << "MeshVersionFormatted 1\nDimension 3\n"; - ofs << "Vertices\n" << nbV << "\n"; - int ind = 1; //index of a vertex - std::map index_of_vertex; - for (auto v_it = t.vertices_begin(); v_it != t.vertices_end(); ++v_it) - { - if (t.is_infinite(v_it)) - continue; - // Add maximum 3 coordinates - for (auto coord = v_it->point().cartesian_begin(); coord != v_it->point().cartesian_end() && coord != v_it->point().cartesian_begin()+3; ++coord) - ofs << *coord << " "; - ofs << "508\n"; - index_of_vertex[v_it] = ind++; - } - for (auto coord = p.cartesian_begin(); coord != p.cartesian_end(); ++coord) - ofs << *coord << " "; - ofs << "208\n"; - if (is2d) - { - ofs << "Triangles " << t.number_of_finite_full_cells()+1 << "\n"; - for (auto fc_it = t.full_cells_begin(); fc_it != t.full_cells_end(); ++fc_it) - { - if (t.is_infinite(fc_it)) - continue; - for (auto vh_it = fc_it->vertices_begin(); vh_it != fc_it->vertices_end(); ++vh_it) - ofs << index_of_vertex[*vh_it] << " "; - ofs << "508\n"; - } - ofs << nbV << " " << nbV << " " << nbV << " " << 208 << "\n"; - ofs << "End\n"; - } - else if (p.size() == 3) - { - ofs << "Tetrahedra " << t.number_of_finite_full_cells()+1 << "\n"; - for (auto fc_it = t.full_cells_begin(); fc_it != t.full_cells_end(); ++fc_it) - { - if (t.is_infinite(fc_it)) - continue; - for (auto vh_it = fc_it->vertices_begin(); vh_it != fc_it->vertices_end(); ++vh_it) - ofs << index_of_vertex[*vh_it] << " "; - ofs << "508\n"; - } - ofs << nbV << " " << nbV << " " << nbV << " " << nbV << " " << 208 << "\n"; - ofs << "End\n"; - } - else if (p.size() == 4) - { - ofs << "Tetrahedra " << 5*(t.number_of_finite_full_cells())+1 << "\n"; - for (auto fc_it = t.full_cells_begin(); fc_it != t.full_cells_end(); ++fc_it) - { - if (t.is_infinite(fc_it)) - continue; - for (auto vh_it = fc_it->vertices_begin(); vh_it != fc_it->vertices_end(); ++vh_it) - { - for (auto vh_it2 = fc_it->vertices_begin(); vh_it2 != fc_it->vertices_end(); ++vh_it2) - if (vh_it != vh_it2) - ofs << index_of_vertex[*vh_it2] << " "; - ofs << "508\n"; - } - } - ofs << nbV << " " << nbV << " " << nbV << " " << nbV << " " << 208 << "\n"; - ofs << "End\n"; - } - ofs.close(); -} - -/////////////////////////////////////////////////////////////////////// -// PRINT VECTOR -/////////////////////////////////////////////////////////////////////// - -template -void print_vector(std::vector v) -{ - std::cout << "["; - if (!v.empty()) - { - std::cout << *(v.begin()); - for (auto it = v.begin()+1; it != v.end(); ++it) - { - std::cout << ","; - std::cout << *it; - } - } - std::cout << "]"; -} - - -#endif diff --git a/src/Witness_complex/example/output_tikz.h b/src/Witness_complex/example/output_tikz.h deleted file mode 100644 index 281c65b7..00000000 --- a/src/Witness_complex/example/output_tikz.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef OUTPUT_TIKZ_H -#define OUTPUT_TIKZ_H - -#include -#include -#include -#include -#include - -typedef double FT; - - -//////////////////AUX///////////////////// - -void write_preamble(std::ofstream& ofs) -{ - ofs << "\\documentclass{standalone}\n" - << "\\usepackage{tikz}\n\n" - << "\\begin{document}\n" - << "\\begin{tikzpicture}\n"; -} - -void write_end(std::ofstream& ofs) -{ - ofs << "\\end{tikzpicture}\n" - << "\\end{document}"; -} - - -/////////////////MAIN////////////////////// - -void write_tikz_plot(std::vector data, std::string filename) -{ - int n = data.size(); - FT vmax = *(std::max_element(data.begin(), data.end())); - //std::cout << std::log10(vmax) << " " << std::floor(std::log10(vmax)); - - FT order10 = pow(10,std::floor(std::log10(vmax))); - int digit = std::floor( vmax / order10) + 1; - if (digit == 4 || digit == 6) digit = 5; - if (digit > 6) digit = 10; - FT plot_max = digit*order10; - std::cout << plot_max << " " << vmax; - FT hstep = 10.0/(n-1); - FT wstep = 10.0 / plot_max; - - std::cout << "(eps_max-eps_min)/(N-48) = " << (vmax-*data.begin())/(data.size()-48) << "\n"; - std::ofstream ofs(filename, std::ofstream::out); - - ofs << - "\\documentclass{standalone}\n" << - "\\usepackage[utf8]{inputenc}\n" << - "\\usepackage{amsmath}\n" << - "\\usepackage{tikz}\n\n" << - "\\begin{document}\n" << - "\\begin{tikzpicture}\n"; - - ofs << "\\draw[->] (0,0) -- (0,11);" << std::endl << - "\\draw[->] (0,0) -- (11,0);" << std::endl << - "\\foreach \\i in {1,...,10}" << std::endl << - "\\draw (0,\\i) -- (-0.05,\\i);" << std::endl << - "\\foreach \\i in {1,...,10}" << std::endl << - "\\draw (\\i,0) -- (\\i,-0.05);" << std::endl << std::endl << - - "\\foreach \\i in {1,...,10}" << std::endl << - "\\draw[dashed] (-0.05,\\i) -- (11,\\i);" << std::endl << std::endl << - - "\\node at (-0.5,11) {$*$}; " << std::endl << - "\\node at (11,-0.5) {$*$}; " << std::endl << - "\\node at (-0.5,-0.5) {0}; " << std::endl << - "\\node at (-0.5,10) {" << plot_max << "}; " << std::endl << - "%\\node at (10,-0.5) {2}; " << std::endl; - - ofs << "\\draw[red] (0," << wstep*data[0] << ")"; - for (int i = 1; i < n; ++i) - ofs << " -- (" << hstep*i << "," << wstep*data[i] << ")"; - ofs << ";\n"; - - ofs << - "\\end{tikzpicture}\n" << - "\\end{document}"; - - ofs.close(); -} - - -// A little script to make a tikz histogram of epsilon distribution -// Returns the average epsilon -void write_histogram(std::vector histo, std::string file_name = "histogram.tikz", std::string xaxis = "$\\epsilon/\\epsilon_{max}$", std::string yaxis = "$\\epsilon$", FT max_x = 1) -{ - int n = histo.size(); - - std::ofstream ofs (file_name, std::ofstream::out); - FT barwidth = 20.0/n; - FT max_value = *(std::max_element(histo.begin(), histo.end())); - std::cout << max_value << std::endl; - FT ten_power = pow(10, ceil(log10(max_value))); - FT max_histo = ten_power; - if (max_value/ten_power > 1) { - if (max_value/ten_power < 2) - max_histo = 0.2*ten_power; - else if (max_value/ten_power < 5) - max_histo = 0.5*ten_power; - } - std::cout << ceil(log10(max_value)) << std::endl << max_histo << std::endl; - FT unitht = max_histo/10.0; - write_preamble(ofs); - - ofs << "\\draw[->] (0,0) -- (0,11);\n" << - "\\draw[->] (0,0) -- (21,0);\n" << - "\\foreach \\i in {1,...,10}\n" << - "\\draw (0,\\i) -- (-0.1,\\i);\n" << - "\\foreach \\i in {1,...,20}\n" << - "\\draw (\\i,0) -- (\\i,-0.1);\n" << - - "\\node at (-1,11) {" << yaxis << "};\n" << - "\\node at (22,-1) {" << xaxis << "};\n" << - "\\node at (-0.5,-0.5) {0};\n" << - "\\node at (-0.5,10) {" << max_histo << "};\n" << - "\\node at (20,-0.5) {" << max_x << "};\n"; - - for (int i = 0; i < n; ++i) - ofs << "\\draw (" << barwidth*i << "," << histo[i]/unitht << ") -- (" - << barwidth*(i+1) << "," << histo[i]/unitht << ") -- (" - << barwidth*(i+1) << ",0) -- (" << barwidth*i << ",0) -- cycle;\n"; - - write_end(ofs); - ofs.close(); -} - -struct Pers_interval { - double alpha_start, alpha_end; - int dim; - Pers_interval(double alpha_start_, double alpha_end_, int dim_) - : alpha_start(alpha_start_), alpha_end(alpha_end_), dim(dim_) - {} -}; - -void write_barcodes(std::string in_file, double alpha2, std::string out_file = "barcodes.tikz.tex") -{ - std::ifstream ifs(in_file, std::ios::in); - std::string line; - std::vector pers_intervals; - while (getline(ifs, line)) { - int p, dim; - double alpha_start, alpha_end; - std::istringstream iss(line); - iss >> p >> dim >> alpha_start >> alpha_end; - if (alpha_start != alpha_end) { - if (alpha_end < alpha_start) - alpha_end = alpha2; - pers_intervals.push_back(Pers_interval(alpha_start, alpha_end, dim)); - } - } - ifs.close(); - std::ofstream ofs (out_file, std::ofstream::out); - write_preamble(ofs); - double barwidth = 0.01; - int i = 0; - for (auto interval: pers_intervals) { - std::string color = "black"; - switch (interval.dim) { - case 0: color = "orange"; break; - case 1: color = "red"; break; - case 2: color = "blue"; break; - case 3: color = "green"; break; - case 4: color = "yellow"; break; - default: color = "orange"; break; - } - ofs << "\\fill[" << color << "] (" << interval.alpha_start << "," << barwidth*i << ") rectangle (" - << interval.alpha_end << "," << barwidth*(i+1) <<");\n"; - i++; - } - write_end(ofs); - ofs.close(); -} - -#endif diff --git a/src/Witness_complex/example/witness_complex_from_file.cpp b/src/Witness_complex/example/witness_complex_from_file.cpp deleted file mode 100644 index e5859b2a..00000000 --- a/src/Witness_complex/example/witness_complex_from_file.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Siargey Kachanovich - * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -typedef CGAL::Epick_d K; -typedef typename K::Point_d Point_d; -typedef typename Gudhi::witness_complex::Witness_complex Witness_complex; -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef std::vector< Point_d > Point_vector; - -/** - * \brief Customized version of read_points - * which takes into account a possible nbP first line - * - */ -inline void -read_points_cust(std::string file_name, Point_vector & points) { - std::ifstream in_file(file_name.c_str(), std::ios::in); - if (!in_file.is_open()) { - std::cerr << "Unable to open file " << file_name << std::endl; - return; - } - std::string line; - double x; - while (getline(in_file, line)) { - std::vector< double > point; - std::istringstream iss(line); - while (iss >> x) { - point.push_back(x); - } - if (point.size() != 1) - points.push_back(Point_d(point)); - } - in_file.close(); -} - -int main(int argc, char * const argv[]) { - if (argc != 4) { - std::cerr << "Usage: " << argv[0] - << " path_to_point_file nbL alpha^2\n"; - return 0; - } - - std::string file_name = argv[1]; - int nbL = atoi(argv[2]); - double alpha2 = atof(argv[3]); - clock_t start, end; - - // Construct the Simplex Tree - Gudhi::Simplex_tree<> simplex_tree; - - // Read the point file - Point_vector point_vector, landmarks; - read_points_cust(file_name, point_vector); - std::cout << "Successfully read " << point_vector.size() << " points.\n"; - std::cout << "Ambient dimension is " << point_vector[0].dimension() << ".\n"; - - // Choose landmarks - Gudhi::subsampling::pick_n_random_points(point_vector, nbL, std::back_inserter(landmarks)); - - // Compute witness complex - start = clock(); - Witness_complex witness_complex(landmarks.begin(), - landmarks.end(), - point_vector.begin(), - point_vector.end()); - witness_complex.create_complex(simplex_tree, alpha2); - end = clock(); - std::cout << "Witness complex took " - << static_cast(end - start) / CLOCKS_PER_SEC << " s. \n"; - std::cout << "Number of simplices is: " << simplex_tree.num_simplices() << "\n"; -} diff --git a/src/Witness_complex/example/witness_complex_sphere.cpp b/src/Witness_complex/example/witness_complex_sphere.cpp deleted file mode 100644 index fe7f628f..00000000 --- a/src/Witness_complex/example/witness_complex_sphere.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Siargey Kachanovich - * - * Copyright (C) 2015 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#define BOOST_PARAMETER_MAX_ARITY 12 - - -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include "generators.h" - -/** Write a gnuplot readable file. - * Data range is a random access range of pairs (arg, value) - */ -template < typename Data_range > -void write_data(Data_range & data, std::string filename) { - std::ofstream ofs(filename, std::ofstream::out); - for (auto entry : data) - ofs << entry.first << ", " << entry.second << "\n"; - ofs.close(); -} - -int main(int argc, char * const argv[]) { - typedef Gudhi::witness_complex::Witness_complex> Witness_complex; - - if (argc != 2) { - std::cerr << "Usage: " << argv[0] - << " number_of_landmarks \n"; - return 0; - } - - int number_of_landmarks = atoi(argv[1]); - clock_t start, end; - - std::vector< std::pair > l_time; - - // Read the point file - for (int nbP = 500; nbP < 10000; nbP += 500) { - // Construct the Simplex Tree - Gudhi::Simplex_tree<> simplex_tree; - Point_Vector point_vector, landmarks; - generate_points_sphere(point_vector, nbP, 4); - std::cout << "Successfully generated " << point_vector.size() << " points.\n"; - std::cout << "Ambient dimension is " << point_vector[0].size() << ".\n"; - - // Choose landmarks - start = clock(); - Gudhi::subsampling::pick_n_random_points(point_vector, number_of_landmarks, std::back_inserter(landmarks)); - - // Compute witness complex - Witness_complex witness_complex(landmarks.begin(), - landmarks.end(), - point_vector.begin(), - point_vector.end()); - witness_complex.create_complex(simplex_tree, 0.1); - end = clock(); - double time = static_cast(end - start) / CLOCKS_PER_SEC; - std::cout << "Witness complex for " << number_of_landmarks << " landmarks took " - << time << " s. \n"; - //assert(1 == 0); - //std::cout << simplex_tree << "\n"; - std::cout << "Number of simplices is: " << simplex_tree.num_simplices() << "\n"; - l_time.push_back(std::make_pair(nbP, time)); - } - write_data(l_time, "w_time.dat"); -} diff --git a/src/Witness_complex/test/CMakeLists.txt b/src/Witness_complex/test/CMakeLists.txt index bb55b0f1..751f533c 100644 --- a/src/Witness_complex/test/CMakeLists.txt +++ b/src/Witness_complex/test/CMakeLists.txt @@ -10,14 +10,14 @@ if (GPROF_PATH) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") endif() -add_executable ( simple_witness_complexUT simple_witness_complex.cpp ) -target_link_libraries(simple_witness_complexUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +add_executable ( Witness_complex_test_simple_witness_complex test_simple_witness_complex.cpp ) +target_link_libraries(Witness_complex_test_simple_witness_complex ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) # Unitary tests definition and xml result file generation -add_test(NAME simple_witness_complexUT - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/simple_witness_complexUT +add_test(NAME simple_witness_complex + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/Witness_complex_test_simple_witness_complex # XML format for Jenkins xUnit plugin - --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/simple_witness_complexUT.xml --log_level=test_suite --report_level=no) + --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/Witness_complex_test_simple_witness_complex.xml --log_level=test_suite --report_level=no) add_executable ( witness_complex_pointsUT witness_complex_points.cpp ) target_link_libraries(witness_complex_pointsUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) diff --git a/src/Witness_complex/test/simple_witness_complex.cpp b/src/Witness_complex/test/simple_witness_complex.cpp deleted file mode 100644 index 0c2c3710..00000000 --- a/src/Witness_complex/test/simple_witness_complex.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Siargey Kachanovich - * - * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE "simple_witness_complex" -#include -#include - -#include - -#include -#include -#include - -#include -#include -#include - -typedef Gudhi::Simplex_tree<> Simplex_tree; -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef CGAL::Epick_d Kernel; -typedef typename Kernel::FT FT; -typedef typename Kernel::Point_d Point_d; -typedef Gudhi::witness_complex::Witness_complex WitnessComplex; -typedef Gudhi::witness_complex::Strong_witness_complex StrongWitnessComplex; - -/* All landmarks and witnesses are taken on the grid in the following manner. - LWLWL 2W4W7 - WW.WW WW.WW - L...L 1...6 - WW.WW WW.WW - LWLWL 0W3W5 - - Witness complex consists of 8 vertices, 12 edges and 4 triangles - */ - -BOOST_AUTO_TEST_CASE(simple_witness_complex) { - Simplex_tree complex, relaxed_complex, strong_relaxed_complex; - - std::vector witnesses, landmarks; - - landmarks.push_back(Point_d(std::vector{-2,-2})); - landmarks.push_back(Point_d(std::vector{-2, 0})); - landmarks.push_back(Point_d(std::vector{-2, 2})); - landmarks.push_back(Point_d(std::vector{ 0,-2})); - landmarks.push_back(Point_d(std::vector{ 0, 2})); - landmarks.push_back(Point_d(std::vector{ 2,-2})); - landmarks.push_back(Point_d(std::vector{ 2, 0})); - landmarks.push_back(Point_d(std::vector{ 2, 2})); - witnesses.push_back(Point_d(std::vector{-2,-1})); - witnesses.push_back(Point_d(std::vector{-2, 1})); - witnesses.push_back(Point_d(std::vector{-1,-2})); - witnesses.push_back(Point_d(std::vector{-1,-1})); - witnesses.push_back(Point_d(std::vector{-1, 1})); - witnesses.push_back(Point_d(std::vector{-1, 2})); - witnesses.push_back(Point_d(std::vector{ 1,-2})); - witnesses.push_back(Point_d(std::vector{ 1,-1})); - witnesses.push_back(Point_d(std::vector{ 1, 1})); - witnesses.push_back(Point_d(std::vector{ 1, 2})); - witnesses.push_back(Point_d(std::vector{ 2,-1})); - witnesses.push_back(Point_d(std::vector{ 2, 1})); - - // landmarks.push_back(Point_d(std::vector{1,0})); - // landmarks.push_back(Point_d(std::vector{0,0})); - // landmarks.push_back(Point_d(std::vector{0,1})); - // witnesses.push_back(Point_d(std::vector{1,0})); - - WitnessComplex witness_complex(landmarks.begin(), - landmarks.end(), - witnesses.begin(), - witnesses.end()); - // witness_complex.create_complex(complex, 0); - - //std::cout << complex << "\n"; - - // BOOST_CHECK(complex.num_simplices() == 24); - - // witness_complex.create_complex(relaxed_complex, 8.01); - - // std::cout << "Num_simplices: " << relaxed_complex.num_simplices() << "\n"; - // std::cout << relaxed_complex << "\n"; - - StrongWitnessComplex strong_witness_complex(landmarks.begin(), - landmarks.end(), - witnesses.begin(), - witnesses.end()); - - strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); - std::cout << "Num_simplices: " << strong_relaxed_complex.num_simplices() << "\n"; - std::cout << strong_relaxed_complex << "\n"; - - //BOOST_CHECK(relaxed_complex.num_simplices() == 24); - - //BOOST_CHECK(witnessComplex.is_witness_complex(knn, false)); - - -} diff --git a/src/Witness_complex/test/test_simple_witness_complex.cpp b/src/Witness_complex/test/test_simple_witness_complex.cpp new file mode 100644 index 00000000..abd0a0dd --- /dev/null +++ b/src/Witness_complex/test/test_simple_witness_complex.cpp @@ -0,0 +1,103 @@ +/* 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): Siargey Kachanovich + * + * Copyright (C) 2016 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE "simple_witness_complex" +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +typedef Gudhi::Simplex_tree<> Simplex_tree; +typedef std::vector< Vertex_handle > typeVectorVertex; +typedef CGAL::Epick_d Kernel; +typedef typename Kernel::FT FT; +typedef typename Kernel::Point_d Point_d; +typedef Gudhi::witness_complex::Witness_complex WitnessComplex; +typedef Gudhi::witness_complex::Strong_witness_complex StrongWitnessComplex; + +/* All landmarks and witnesses are taken on the grid in the following manner. + LWLWL + WW.WW + L...L + WW.WW + LWLWL + + Witness complex consists of 8 vertices, 12 edges and 4 triangles + */ + +BOOST_AUTO_TEST_CASE(simple_witness_complex) { + Simplex_tree complex, relaxed_complex, strong_relaxed_complex; + + std::vector witnesses, landmarks; + + landmarks.push_back(Point_d(std::vector{-2,-2})); + landmarks.push_back(Point_d(std::vector{-2, 0})); + landmarks.push_back(Point_d(std::vector{-2, 2})); + landmarks.push_back(Point_d(std::vector{ 0,-2})); + landmarks.push_back(Point_d(std::vector{ 0, 2})); + landmarks.push_back(Point_d(std::vector{ 2,-2})); + landmarks.push_back(Point_d(std::vector{ 2, 0})); + landmarks.push_back(Point_d(std::vector{ 2, 2})); + witnesses.push_back(Point_d(std::vector{-2,-1})); + witnesses.push_back(Point_d(std::vector{-2, 1})); + witnesses.push_back(Point_d(std::vector{-1,-2})); + witnesses.push_back(Point_d(std::vector{-1,-1})); + witnesses.push_back(Point_d(std::vector{-1, 1})); + witnesses.push_back(Point_d(std::vector{-1, 2})); + witnesses.push_back(Point_d(std::vector{ 1,-2})); + witnesses.push_back(Point_d(std::vector{ 1,-1})); + witnesses.push_back(Point_d(std::vector{ 1, 1})); + witnesses.push_back(Point_d(std::vector{ 1, 2})); + witnesses.push_back(Point_d(std::vector{ 2,-1})); + witnesses.push_back(Point_d(std::vector{ 2, 1})); + + WitnessComplex witness_complex(landmarks.begin(), + landmarks.end(), + witnesses.begin(), + witnesses.end()); + witness_complex.create_complex(complex, 0); + + BOOST_CHECK(complex.num_simplices() == 24); + + witness_complex.create_complex(relaxed_complex, 8.01); + + BOOST_CHECK(relaxed_complex.num_simplices() == 239); + + StrongWitnessComplex strong_witness_complex(landmarks.begin(), + landmarks.end(), + witnesses.begin(), + witnesses.end()); + + strong_witness_complex.create_complex(strong_relaxed_complex, 9.1); + + BOOST_CHECK(strong_relaxed_complex.num_simplices() == 239); + +} -- cgit v1.2.3