From 572c8f53ba26d39eaec39f48cdbdd64c0b7894c2 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 7 Mar 2017 21:47:18 +0000 Subject: Add doc for exact alpha CMake for exact alpha Factorization git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_3d_fix@2170 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b2ac281dd21313602590fc834e7ad22bbf081021 --- .../doc/Intro_persistent_cohomology.h | 12 +++++ src/Persistent_cohomology/example/CMakeLists.txt | 4 ++ .../example/alpha_complex_3d_persistence.cpp | 54 ++++++++++---------- .../example/exact_alpha_complex_3d_persistence.cpp | 56 +++++++++++---------- .../periodic_alpha_complex_3d_persistence.cpp | 57 +++------------------- src/common/doc/main_page.h | 5 ++ 6 files changed, 84 insertions(+), 104 deletions(-) diff --git a/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h b/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h index 40dd3f93..d758687c 100644 --- a/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h +++ b/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h @@ -172,6 +172,18 @@ Persistent_cohomology/alpha_complex_3d_persistence.cpp computes the persiste 2 1 0.0934117 1.00003 2 2 0.56444 1.03938 \endcode +\li +Persistent_cohomology/exact_alpha_complex_3d_persistence.cpp computes the persistent homology with +\f$\mathbb{Z}/2\mathbb{Z}\f$ coefficients of the alpha complex on points sampling from an OFF file. +Here, as CGAL computes the exact values, it is slower, but it is necessary when points are on a grid +for instance. +\code $> ./exact_alpha_complex_3d_persistence ../../data/points/tore3D_300.off 2 0.45 \endcode +\code Simplex_tree dim: 3 +2 0 0 inf +2 1 0.0682162 1.0001 +2 1 0.0934117 1.00003 +2 2 0.56444 1.03938 \endcode + \li Persistent_cohomology/alpha_complex_persistence.cpp computes the persistent homology with \f$\mathbb{Z}/p\mathbb{Z}\f$ coefficients of the alpha complex on points sampling from an OFF file. diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index d2a84b1e..a7905284 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -55,11 +55,15 @@ endif(GMP_FOUND) if(CGAL_FOUND) add_executable(alpha_complex_3d_persistence alpha_complex_3d_persistence.cpp) target_link_libraries(alpha_complex_3d_persistence ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) + add_executable(exact_alpha_complex_3d_persistence exact_alpha_complex_3d_persistence.cpp) + target_link_libraries(exact_alpha_complex_3d_persistence ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) if (TBB_FOUND) target_link_libraries(alpha_complex_3d_persistence ${TBB_LIBRARIES}) + target_link_libraries(exact_alpha_complex_3d_persistence ${TBB_LIBRARIES}) endif(TBB_FOUND) add_test(alpha_complex_3d_persistence_2_0_5 ${CMAKE_CURRENT_BINARY_DIR}/alpha_complex_3d_persistence ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off 2 0.45) + add_test(exact_alpha_complex_3d_persistence_2_0_5 ${CMAKE_CURRENT_BINARY_DIR}/exact_alpha_complex_3d_persistence ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off 2 0.45) if (NOT CGAL_VERSION VERSION_LESS 4.7.0) diff --git a/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp index 371acede..ffb98283 100644 --- a/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp @@ -42,36 +42,37 @@ #include // Alpha_shape_3 templates type definitions -typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; -typedef CGAL::Alpha_shape_vertex_base_3 Vb; -typedef CGAL::Alpha_shape_cell_base_3 Fb; -typedef CGAL::Triangulation_data_structure_3 Tds; -typedef CGAL::Delaunay_triangulation_3 Triangulation_3; -typedef CGAL::Alpha_shape_3 Alpha_shape_3; +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Vb = CGAL::Alpha_shape_vertex_base_3; +using Fb = CGAL::Alpha_shape_cell_base_3; +using Tds = CGAL::Triangulation_data_structure_3; +using Triangulation_3 = CGAL::Delaunay_triangulation_3; +using Alpha_shape_3 = CGAL::Alpha_shape_3; // From file type definition -typedef Kernel::Point_3 Point_3; +using Point_3 = Kernel::Point_3; // filtration with alpha values needed type definition -typedef Alpha_shape_3::FT Alpha_value_type; -typedef CGAL::Object Object; -typedef CGAL::Dispatch_output_iterator< -CGAL::cpp11::tuple, -CGAL::cpp11::tuple >, - std::back_insert_iterator< std::vector > > > Dispatch; -typedef Alpha_shape_3::Cell_handle Cell_handle; -typedef Alpha_shape_3::Facet Facet; -typedef Alpha_shape_3::Edge Edge_3; -typedef std::list Vertex_list; +using Alpha_value_type = Alpha_shape_3::FT; +using Object = CGAL::Object; +using Dispatch = CGAL::Dispatch_output_iterator< + CGAL::cpp11::tuple, + CGAL::cpp11::tuple >, + std::back_insert_iterator< std::vector > > >; +using Cell_handle = Alpha_shape_3::Cell_handle; +using Facet = Alpha_shape_3::Facet; +using Edge_3 = Alpha_shape_3::Edge; +using Vertex_handle = Alpha_shape_3::Vertex_handle; +using Vertex_list = std::list; // gudhi type definition -typedef Gudhi::Simplex_tree ST; -typedef ST::Filtration_value Filtration_value; -typedef ST::Vertex_handle Simplex_tree_vertex; -typedef std::map Alpha_shape_simplex_tree_map; -typedef std::pair Alpha_shape_simplex_tree_pair; -typedef std::vector< Simplex_tree_vertex > Simplex_tree_vector_vertex; -typedef Gudhi::persistent_cohomology::Persistent_cohomology< ST, Gudhi::persistent_cohomology::Field_Zp > PCOH; +using ST = Gudhi::Simplex_tree; +using Filtration_value = ST::Filtration_value; +using Simplex_tree_vertex = ST::Vertex_handle; +using Alpha_shape_simplex_tree_map = std::map; +using Alpha_shape_simplex_tree_pair = std::pair; +using Simplex_tree_vector_vertex = std::vector< Simplex_tree_vertex >; +using PCOH = Gudhi::persistent_cohomology::Persistent_cohomology< ST, Gudhi::persistent_cohomology::Field_Zp >; void usage(const std::string& progName) { std::cerr << "Usage: " << progName << @@ -161,10 +162,9 @@ int main(int argc, char * const argv[]) { // Edge_3 is of dim 1 dim_max = 1; } - } else if (const Alpha_shape_3::Vertex_handle * vertex = - CGAL::object_cast(&object_iterator)) { + } else if (const Vertex_handle * vertex = CGAL::object_cast(&object_iterator)) { count_vertices++; - vertex_list = from_vertex(*vertex); + vertex_list = from_vertex(*vertex); } // Construction of the vector of simplex_tree vertex from list of alpha_shapes vertex Simplex_tree_vector_vertex the_simplex_tree; diff --git a/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp index fc6ee8dd..c016a596 100644 --- a/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp @@ -42,37 +42,38 @@ #include // Alpha_shape_3 templates type definitions -typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; -typedef CGAL::Tag_true Exact_tag; -typedef CGAL::Alpha_shape_vertex_base_3 Vb; -typedef CGAL::Alpha_shape_cell_base_3 Fb; -typedef CGAL::Triangulation_data_structure_3 Tds; -typedef CGAL::Delaunay_triangulation_3 Triangulation_3; -typedef CGAL::Alpha_shape_3 Alpha_shape_3; +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Exact_tag = CGAL::Tag_true; +using Vb = CGAL::Alpha_shape_vertex_base_3; +using Fb = CGAL::Alpha_shape_cell_base_3; +using Tds = CGAL::Triangulation_data_structure_3; +using Triangulation_3 = CGAL::Delaunay_triangulation_3; +using Alpha_shape_3 = CGAL::Alpha_shape_3; // From file type definition -typedef Kernel::Point_3 Point_3; +using Point_3 = Kernel::Point_3; // filtration with alpha values needed type definition -typedef Alpha_shape_3::FT Alpha_value_type; -typedef CGAL::Object Object; -typedef CGAL::Dispatch_output_iterator< -CGAL::cpp11::tuple, -CGAL::cpp11::tuple >, - std::back_insert_iterator< std::vector > > > Dispatch; -typedef Alpha_shape_3::Cell_handle Cell_handle; -typedef Alpha_shape_3::Facet Facet; -typedef Alpha_shape_3::Edge Edge_3; -typedef Alpha_shape_3::Vertex_handle Vertex_handle; -typedef std::list Vertex_list; +using Alpha_value_type = Alpha_shape_3::FT; +using Object = CGAL::Object; +using Dispatch = CGAL::Dispatch_output_iterator< + CGAL::cpp11::tuple, + CGAL::cpp11::tuple >, + std::back_insert_iterator< std::vector > > >; +using Cell_handle = Alpha_shape_3::Cell_handle; +using Facet = Alpha_shape_3::Facet; +using Edge_3 = Alpha_shape_3::Edge; +using Vertex_handle = Alpha_shape_3::Vertex_handle; +using Vertex_list = std::list; // gudhi type definition -typedef Gudhi::Simplex_tree ST; -typedef ST::Vertex_handle Simplex_tree_vertex; -typedef std::map Alpha_shape_simplex_tree_map; -typedef std::pair Alpha_shape_simplex_tree_pair; -typedef std::vector< Simplex_tree_vertex > Simplex_tree_vector_vertex; -typedef Gudhi::persistent_cohomology::Persistent_cohomology< ST, Gudhi::persistent_cohomology::Field_Zp > PCOH; +using ST = Gudhi::Simplex_tree; +using Filtration_value = ST::Filtration_value; +using Simplex_tree_vertex = ST::Vertex_handle; +using Alpha_shape_simplex_tree_map = std::map; +using Alpha_shape_simplex_tree_pair = std::pair; +using Simplex_tree_vector_vertex = std::vector< Simplex_tree_vertex >; +using PCOH = Gudhi::persistent_cohomology::Persistent_cohomology< ST, Gudhi::persistent_cohomology::Field_Zp >; void usage(char * const progName) { std::cerr << "Usage: " << progName << @@ -90,7 +91,7 @@ int main(int argc, char * const argv[]) { int coeff_field_characteristic = atoi(argv[2]); Filtration_value min_persistence = 0.0; - int returnedScanValue = sscanf(argv[3], "%lf", &min_persistence); + int returnedScanValue = sscanf(argv[3], "%f", &min_persistence); if ((returnedScanValue == EOF) || (min_persistence < -1.0)) { std::cerr << "Error: " << argv[3] << " is not correct\n"; usage(argv[0]); @@ -188,7 +189,8 @@ int main(int argc, char * const argv[]) { } } // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/CGAL::to_double(the_alpha_value_iterator->approx()); + // you can also use the_alpha_value_iterator->exact() + Filtration_value filtr = /*std::sqrt*/CGAL::to_double(the_alpha_value_iterator->exact()); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; #endif // DEBUG_TRACES diff --git a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp index dbc42706..4f6ea40e 100644 --- a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp @@ -31,6 +31,8 @@ #include #include +#include "alpha_complex_3d_helper.h" + #include #include #include @@ -67,6 +69,7 @@ using Dispatch = CGAL::Dispatch_output_iterator< using Cell_handle = Alpha_shape_3::Cell_handle; using Facet = Alpha_shape_3::Facet; using Edge_3 = Alpha_shape_3::Edge; +using Vertex_handle = Alpha_shape_3::Vertex_handle; using Vertex_list = std::list; // gudhi type definition @@ -79,52 +82,6 @@ using Simplex_tree_vector_vertex = std::vector< Simplex_tree_vertex >; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< ST, Gudhi::persistent_cohomology::Field_Zp >; -Vertex_list from(const Cell_handle& ch) { - Vertex_list the_list; - for (auto i = 0; i < 4; i++) { -#ifdef DEBUG_TRACES - std::cout << "from cell[" << i << "]=" << ch->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES - the_list.push_back(ch->vertex(i)); - } - return the_list; -} - -Vertex_list from(const Facet& fct) { - Vertex_list the_list; - for (auto i = 0; i < 4; i++) { - if (fct.second != i) { -#ifdef DEBUG_TRACES - std::cout << "from facet=[" << i << "]" << fct.first->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES - the_list.push_back(fct.first->vertex(i)); - } - } - return the_list; -} - -Vertex_list from(const Edge_3& edg) { - Vertex_list the_list; - for (auto i = 0; i < 4; i++) { - if ((edg.second == i) || (edg.third == i)) { -#ifdef DEBUG_TRACES - std::cout << "from edge[" << i << "]=" << edg.first->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES - the_list.push_back(edg.first->vertex(i)); - } - } - return the_list; -} - -Vertex_list from(const Alpha_shape_3::Vertex_handle& vh) { - Vertex_list the_list; -#ifdef DEBUG_TRACES - std::cout << "from vertex=" << vh->point() << std::endl; -#endif // DEBUG_TRACES - the_list.push_back(vh); - return the_list; -} - void usage(char * const progName) { std::cerr << "Usage: " << progName << " path_to_file_graph path_to_iso_cuboid_3_file coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; @@ -203,21 +160,21 @@ int main(int argc, char * const argv[]) { for (auto object_iterator : the_objects) { // Retrieve Alpha shape vertex list from object if (const Cell_handle * cell = CGAL::object_cast(&object_iterator)) { - vertex_list = from(*cell); + vertex_list = from_cell(*cell); count_cells++; if (dim_max < 3) { // Cell is of dim 3 dim_max = 3; } } else if (const Facet * facet = CGAL::object_cast(&object_iterator)) { - vertex_list = from(*facet); + vertex_list = from_facet(*facet); count_facets++; if (dim_max < 2) { // Facet is of dim 2 dim_max = 2; } } else if (const Edge_3 * edge = CGAL::object_cast(&object_iterator)) { - vertex_list = from(*edge); + vertex_list = from_edge(*edge); count_edges++; if (dim_max < 1) { // Edge_3 is of dim 1 @@ -226,7 +183,7 @@ int main(int argc, char * const argv[]) { } else if (const Alpha_shape_3::Vertex_handle * vertex = CGAL::object_cast(&object_iterator)) { count_vertices++; - vertex_list = from(*vertex); + vertex_list = from_vertex(*vertex); } // Construction of the vector of simplex_tree vertex from list of alpha_shapes vertex Simplex_tree_vector_vertex the_simplex_tree; diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index 5ca0a6bc..34ad1710 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -259,6 +259,8 @@ make \endverbatim * Library (CGAL \cite cgal:eb-15b) and will not be built if CGAL is not installed: * \li * Persistent_cohomology/alpha_complex_3d_persistence.cpp + * \li + * Persistent_cohomology/exact_alpha_complex_3d_persistence.cpp * \li * Simplex_tree/example_alpha_shapes_3_simplex_tree_from_off_file.cpp * @@ -350,6 +352,8 @@ make \endverbatim * Persistent_cohomology/rips_persistence.cpp * \li * Persistent_cohomology/rips_persistence_step_by_step.cpp + * \li + * Persistent_cohomology/exact_alpha_complex_3d_persistence.cpp * \li * Persistent_cohomology/periodic_alpha_complex_3d_persistence.cpp * \li @@ -394,6 +398,7 @@ make \endverbatim * @example Persistent_cohomology/alpha_complex_3d_persistence.cpp * @example Persistent_cohomology/alpha_complex_persistence.cpp * @example Persistent_cohomology/rips_persistence_via_boundary_matrix.cpp + * @example Persistent_cohomology/exact_alpha_complex_3d_persistence.cpp * @example Persistent_cohomology/periodic_alpha_complex_3d_persistence.cpp * @example Persistent_cohomology/persistence_from_file.cpp * @example Persistent_cohomology/persistence_from_simple_simplex_tree.cpp -- cgit v1.2.3