-- cgit v1.2.3 From 157e6fa3aa86e9de270a9f3a9b6b6acdc37abf5f Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 16:16:50 +0000 Subject: Move 2 examples from Bitmap_cubical_complex to utilities git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2492 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 40e5f550edb48780d2cf1fe322a5c1d7dd5c80b0 --- .../example/Bitmap_cubical_complex.cpp | 80 --------------------- ...ubical_complex_periodic_boundary_conditions.cpp | 81 ---------------------- src/Bitmap_cubical_complex/example/CMakeLists.txt | 28 -------- .../utilities/Bitmap_cubical_complex.cpp | 80 +++++++++++++++++++++ ...ubical_complex_periodic_boundary_conditions.cpp | 81 ++++++++++++++++++++++ .../utilities/CMakeLists.txt | 31 +++++++++ 6 files changed, 192 insertions(+), 189 deletions(-) delete mode 100644 src/Bitmap_cubical_complex/example/Bitmap_cubical_complex.cpp delete mode 100644 src/Bitmap_cubical_complex/example/Bitmap_cubical_complex_periodic_boundary_conditions.cpp create mode 100644 src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex.cpp create mode 100644 src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex_periodic_boundary_conditions.cpp create mode 100644 src/Bitmap_cubical_complex/utilities/CMakeLists.txt diff --git a/src/Bitmap_cubical_complex/example/Bitmap_cubical_complex.cpp b/src/Bitmap_cubical_complex/example/Bitmap_cubical_complex.cpp deleted file mode 100644 index 67735ba1..00000000 --- a/src/Bitmap_cubical_complex/example/Bitmap_cubical_complex.cpp +++ /dev/null @@ -1,80 +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): Pawel Dlotko - * - * Copyright (C) 2015 INRIA Saclay (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 - -// standard stuff -#include -#include -#include -#include - -int main(int argc, char** argv) { - std::cout << "This program computes persistent homology, by using bitmap_cubical_complex class, of cubical " << - "complexes provided in text files in Perseus style (the only numbered in the first line is a dimension D of a" << - "bitmap. In the lines I between 2 and D+1 there are numbers of top dimensional cells in the direction I. Let " << - "N denote product of the numbers in the lines between 2 and D. In the lines D+2 to D+2+N there are " << - "filtrations of top dimensional cells. We assume that the cells are in the lexicographical order. See " << - "CubicalOneSphere.txt or CubicalTwoSphere.txt for example.\n" << std::endl; - - if (argc != 2) { - std::cerr << "Wrong number of parameters. Please provide the name of a file with a Perseus style bitmap at " << - "the input. The program will now terminate.\n"; - return 1; - } - - typedef Gudhi::cubical_complex::Bitmap_cubical_complex_base Bitmap_cubical_complex_base; - typedef Gudhi::cubical_complex::Bitmap_cubical_complex Bitmap_cubical_complex; - typedef Gudhi::persistent_cohomology::Field_Zp Field_Zp; - typedef Gudhi::persistent_cohomology::Persistent_cohomology Persistent_cohomology; - - Bitmap_cubical_complex b(argv[1]); - - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(b); - int p = 2; - double min_persistence = 0; - - pcoh.init_coefficients(p); // initializes the coefficient field for homology - pcoh.compute_persistent_cohomology(min_persistence); - - std::string output_file_name(argv[1]); - output_file_name += "_persistence"; - - std::size_t last_in_path = output_file_name.find_last_of("/\\"); - - if (last_in_path != std::string::npos) { - output_file_name = output_file_name.substr(last_in_path+1); - } - - std::ofstream out(output_file_name.c_str()); - pcoh.output_diagram(out); - out.close(); - - std::cout << "Result in file: " << output_file_name << "\n"; - - return 0; -} - diff --git a/src/Bitmap_cubical_complex/example/Bitmap_cubical_complex_periodic_boundary_conditions.cpp b/src/Bitmap_cubical_complex/example/Bitmap_cubical_complex_periodic_boundary_conditions.cpp deleted file mode 100644 index f8754345..00000000 --- a/src/Bitmap_cubical_complex/example/Bitmap_cubical_complex_periodic_boundary_conditions.cpp +++ /dev/null @@ -1,81 +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): Pawel Dlotko - * - * Copyright (C) 2015 INRIA Saclay (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 - -// standard stuff -#include -#include -#include - -int main(int argc, char** argv) { - std::cout << "This program computes persistent homology, by using " << - "Bitmap_cubical_complex_periodic_boundary_conditions class, of cubical complexes provided in text files in " << - "Perseus style (the only numbered in the first line is a dimension D of a bitmap. In the lines I between 2 " << - "and D+1 there are numbers of top dimensional cells in the direction I. Let N denote product of the numbers " << - "in the lines between 2 and D. In the lines D+2 to D+2+N there are filtrations of top dimensional cells. We " << - "assume that the cells are in the lexicographical order. See CubicalOneSphere.txt or CubicalTwoSphere.txt for" << - " example.\n" << std::endl; - - if (argc != 2) { - std::cerr << "Wrong number of parameters. Please provide the name of a file with a Perseus style bitmap at " << - "the input. The program will now terminate.\n"; - return 1; - } - - typedef Gudhi::cubical_complex::Bitmap_cubical_complex_periodic_boundary_conditions_base Bitmap_base; - typedef Gudhi::cubical_complex::Bitmap_cubical_complex< Bitmap_base > Bitmap_cubical_complex; - - Bitmap_cubical_complex b(argv[1]); - - typedef Gudhi::persistent_cohomology::Field_Zp Field_Zp; - typedef Gudhi::persistent_cohomology::Persistent_cohomology Persistent_cohomology; - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(b, true); - - int p = 2; - double min_persistence = 0; - pcoh.init_coefficients(p); // initializes the coefficient field for homology - pcoh.compute_persistent_cohomology(min_persistence); - - std::string output_file_name(argv[1]); - output_file_name += "_persistence"; - - std::size_t last_in_path = output_file_name.find_last_of("/\\"); - - if (last_in_path != std::string::npos) { - output_file_name = output_file_name.substr(last_in_path+1); - } - - std::ofstream out(output_file_name.c_str()); - pcoh.output_diagram(out); - out.close(); - - std::cout << "Result in file: " << output_file_name << "\n"; - - return 0; -} - diff --git a/src/Bitmap_cubical_complex/example/CMakeLists.txt b/src/Bitmap_cubical_complex/example/CMakeLists.txt index 47f5e0c6..567f25d9 100644 --- a/src/Bitmap_cubical_complex/example/CMakeLists.txt +++ b/src/Bitmap_cubical_complex/example/CMakeLists.txt @@ -1,18 +1,6 @@ cmake_minimum_required(VERSION 2.6) project(Bitmap_cubical_complex_examples) -add_executable ( Bitmap_cubical_complex Bitmap_cubical_complex.cpp ) -target_link_libraries(Bitmap_cubical_complex ${Boost_SYSTEM_LIBRARY}) -if (TBB_FOUND) - target_link_libraries(Bitmap_cubical_complex ${TBB_LIBRARIES}) -endif() - -add_test(NAME Bitmap_cubical_complex_example_persistence_one_sphere COMMAND $ - "${CMAKE_SOURCE_DIR}/data/bitmap/CubicalOneSphere.txt") - -add_test(NAME Bitmap_cubical_complex_example_persistence_two_sphere COMMAND $ - "${CMAKE_SOURCE_DIR}/data/bitmap/CubicalTwoSphere.txt") - add_executable ( Random_bitmap_cubical_complex Random_bitmap_cubical_complex.cpp ) target_link_libraries(Random_bitmap_cubical_complex ${Boost_SYSTEM_LIBRARY}) if (TBB_FOUND) @@ -21,20 +9,4 @@ endif() add_test(NAME Bitmap_cubical_complex_example_random COMMAND $ "2" "100" "100") -add_executable ( Bitmap_cubical_complex_periodic_boundary_conditions Bitmap_cubical_complex_periodic_boundary_conditions.cpp ) -target_link_libraries(Bitmap_cubical_complex_periodic_boundary_conditions ${Boost_SYSTEM_LIBRARY}) -if (TBB_FOUND) - target_link_libraries(Bitmap_cubical_complex_periodic_boundary_conditions ${TBB_LIBRARIES}) -endif() - -add_test(NAME Bitmap_cubical_complex_example_periodic_boundary_conditions_2d_torus - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/bitmap/2d_torus.txt") - -add_test(NAME Bitmap_cubical_complex_example_periodic_boundary_conditions_3d_torus - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/bitmap/3d_torus.txt") - -install(TARGETS Bitmap_cubical_complex DESTINATION bin) install(TARGETS Random_bitmap_cubical_complex DESTINATION bin) -install(TARGETS Bitmap_cubical_complex_periodic_boundary_conditions DESTINATION bin) diff --git a/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex.cpp b/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex.cpp new file mode 100644 index 00000000..67735ba1 --- /dev/null +++ b/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex.cpp @@ -0,0 +1,80 @@ +/* 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): Pawel Dlotko + * + * Copyright (C) 2015 INRIA Saclay (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 + +// standard stuff +#include +#include +#include +#include + +int main(int argc, char** argv) { + std::cout << "This program computes persistent homology, by using bitmap_cubical_complex class, of cubical " << + "complexes provided in text files in Perseus style (the only numbered in the first line is a dimension D of a" << + "bitmap. In the lines I between 2 and D+1 there are numbers of top dimensional cells in the direction I. Let " << + "N denote product of the numbers in the lines between 2 and D. In the lines D+2 to D+2+N there are " << + "filtrations of top dimensional cells. We assume that the cells are in the lexicographical order. See " << + "CubicalOneSphere.txt or CubicalTwoSphere.txt for example.\n" << std::endl; + + if (argc != 2) { + std::cerr << "Wrong number of parameters. Please provide the name of a file with a Perseus style bitmap at " << + "the input. The program will now terminate.\n"; + return 1; + } + + typedef Gudhi::cubical_complex::Bitmap_cubical_complex_base Bitmap_cubical_complex_base; + typedef Gudhi::cubical_complex::Bitmap_cubical_complex Bitmap_cubical_complex; + typedef Gudhi::persistent_cohomology::Field_Zp Field_Zp; + typedef Gudhi::persistent_cohomology::Persistent_cohomology Persistent_cohomology; + + Bitmap_cubical_complex b(argv[1]); + + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(b); + int p = 2; + double min_persistence = 0; + + pcoh.init_coefficients(p); // initializes the coefficient field for homology + pcoh.compute_persistent_cohomology(min_persistence); + + std::string output_file_name(argv[1]); + output_file_name += "_persistence"; + + std::size_t last_in_path = output_file_name.find_last_of("/\\"); + + if (last_in_path != std::string::npos) { + output_file_name = output_file_name.substr(last_in_path+1); + } + + std::ofstream out(output_file_name.c_str()); + pcoh.output_diagram(out); + out.close(); + + std::cout << "Result in file: " << output_file_name << "\n"; + + return 0; +} + diff --git a/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex_periodic_boundary_conditions.cpp b/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex_periodic_boundary_conditions.cpp new file mode 100644 index 00000000..f8754345 --- /dev/null +++ b/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex_periodic_boundary_conditions.cpp @@ -0,0 +1,81 @@ +/* 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): Pawel Dlotko + * + * Copyright (C) 2015 INRIA Saclay (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 + +// standard stuff +#include +#include +#include + +int main(int argc, char** argv) { + std::cout << "This program computes persistent homology, by using " << + "Bitmap_cubical_complex_periodic_boundary_conditions class, of cubical complexes provided in text files in " << + "Perseus style (the only numbered in the first line is a dimension D of a bitmap. In the lines I between 2 " << + "and D+1 there are numbers of top dimensional cells in the direction I. Let N denote product of the numbers " << + "in the lines between 2 and D. In the lines D+2 to D+2+N there are filtrations of top dimensional cells. We " << + "assume that the cells are in the lexicographical order. See CubicalOneSphere.txt or CubicalTwoSphere.txt for" << + " example.\n" << std::endl; + + if (argc != 2) { + std::cerr << "Wrong number of parameters. Please provide the name of a file with a Perseus style bitmap at " << + "the input. The program will now terminate.\n"; + return 1; + } + + typedef Gudhi::cubical_complex::Bitmap_cubical_complex_periodic_boundary_conditions_base Bitmap_base; + typedef Gudhi::cubical_complex::Bitmap_cubical_complex< Bitmap_base > Bitmap_cubical_complex; + + Bitmap_cubical_complex b(argv[1]); + + typedef Gudhi::persistent_cohomology::Field_Zp Field_Zp; + typedef Gudhi::persistent_cohomology::Persistent_cohomology Persistent_cohomology; + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(b, true); + + int p = 2; + double min_persistence = 0; + pcoh.init_coefficients(p); // initializes the coefficient field for homology + pcoh.compute_persistent_cohomology(min_persistence); + + std::string output_file_name(argv[1]); + output_file_name += "_persistence"; + + std::size_t last_in_path = output_file_name.find_last_of("/\\"); + + if (last_in_path != std::string::npos) { + output_file_name = output_file_name.substr(last_in_path+1); + } + + std::ofstream out(output_file_name.c_str()); + pcoh.output_diagram(out); + out.close(); + + std::cout << "Result in file: " << output_file_name << "\n"; + + return 0; +} + diff --git a/src/Bitmap_cubical_complex/utilities/CMakeLists.txt b/src/Bitmap_cubical_complex/utilities/CMakeLists.txt new file mode 100644 index 00000000..43fb8c86 --- /dev/null +++ b/src/Bitmap_cubical_complex/utilities/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 2.6) +project(Bitmap_cubical_complex_utilities) + +add_executable ( Bitmap_cubical_complex Bitmap_cubical_complex.cpp ) +target_link_libraries(Bitmap_cubical_complex ${Boost_SYSTEM_LIBRARY}) +if (TBB_FOUND) + target_link_libraries(Bitmap_cubical_complex ${TBB_LIBRARIES}) +endif() + +add_test(NAME Bitmap_cubical_complex_utility_persistence_one_sphere COMMAND $ + "${CMAKE_SOURCE_DIR}/data/bitmap/CubicalOneSphere.txt") + +add_test(NAME Bitmap_cubical_complex_utility_persistence_two_sphere COMMAND $ + "${CMAKE_SOURCE_DIR}/data/bitmap/CubicalTwoSphere.txt") + +add_executable ( Bitmap_cubical_complex_periodic_boundary_conditions Bitmap_cubical_complex_periodic_boundary_conditions.cpp ) +target_link_libraries(Bitmap_cubical_complex_periodic_boundary_conditions ${Boost_SYSTEM_LIBRARY}) +if (TBB_FOUND) + target_link_libraries(Bitmap_cubical_complex_periodic_boundary_conditions ${TBB_LIBRARIES}) +endif() + +add_test(NAME Bitmap_cubical_complex_utility_periodic_boundary_conditions_2d_torus + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/bitmap/2d_torus.txt") + +add_test(NAME Bitmap_cubical_complex_utility_periodic_boundary_conditions_3d_torus + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/bitmap/3d_torus.txt") + +install(TARGETS Bitmap_cubical_complex DESTINATION bin) +install(TARGETS Bitmap_cubical_complex_periodic_boundary_conditions DESTINATION bin) -- cgit v1.2.3 From 5096889af20a04d25439ffbe5c37e663c11087bc Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 16:20:12 +0000 Subject: Move 1 example from Bottleneck_distance to utilities git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2493 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9ca00220e5c3c4e2d2ad9c3aa3b3a54ed320f223 --- src/Bottleneck_distance/example/CMakeLists.txt | 13 -- .../alpha_rips_persistence_bottleneck_distance.cpp | 190 --------------------- src/Bottleneck_distance/utilities/CMakeLists.txt | 19 +++ .../alpha_rips_persistence_bottleneck_distance.cpp | 190 +++++++++++++++++++++ 4 files changed, 209 insertions(+), 203 deletions(-) delete mode 100644 src/Bottleneck_distance/example/alpha_rips_persistence_bottleneck_distance.cpp create mode 100644 src/Bottleneck_distance/utilities/CMakeLists.txt create mode 100644 src/Bottleneck_distance/utilities/alpha_rips_persistence_bottleneck_distance.cpp diff --git a/src/Bottleneck_distance/example/CMakeLists.txt b/src/Bottleneck_distance/example/CMakeLists.txt index 0534a2c4..93eb7b2f 100644 --- a/src/Bottleneck_distance/example/CMakeLists.txt +++ b/src/Bottleneck_distance/example/CMakeLists.txt @@ -5,22 +5,9 @@ if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) add_executable (bottleneck_read_file_example bottleneck_read_file_example.cpp) add_executable (bottleneck_basic_example bottleneck_basic_example.cpp) - add_executable (alpha_rips_persistence_bottleneck_distance alpha_rips_persistence_bottleneck_distance.cpp) - target_link_libraries(alpha_rips_persistence_bottleneck_distance ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - if (TBB_FOUND) - target_link_libraries(bottleneck_read_file_example ${TBB_LIBRARIES}) - target_link_libraries(bottleneck_basic_example ${TBB_LIBRARIES}) - target_link_libraries(alpha_rips_persistence_bottleneck_distance ${TBB_LIBRARIES}) - endif(TBB_FOUND) - add_test(NAME Bottleneck_distance_example_basic COMMAND $) - add_test(NAME Bottleneck_distance_example_alpha_rips_persistence_bottleneck - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.15" "-m" "0.12" "-d" "3" "-p" "3") - install(TARGETS bottleneck_read_file_example DESTINATION bin) install(TARGETS bottleneck_basic_example DESTINATION bin) - install(TARGETS alpha_rips_persistence_bottleneck_distance DESTINATION bin) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) diff --git a/src/Bottleneck_distance/example/alpha_rips_persistence_bottleneck_distance.cpp b/src/Bottleneck_distance/example/alpha_rips_persistence_bottleneck_distance.cpp deleted file mode 100644 index fd164b22..00000000 --- a/src/Bottleneck_distance/example/alpha_rips_persistence_bottleneck_distance.cpp +++ /dev/null @@ -1,190 +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): Vincent Rouvreau - * - * Copyright (C) 2017 INRIA - * - * 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 // infinity -#include // for pair -#include // for transform - - -// Types definition -using Simplex_tree = Gudhi::Simplex_tree; -using Filtration_value = Simplex_tree::Filtration_value; -using Rips_complex = Gudhi::rips_complex::Rips_complex; -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; -using Point_d = Kernel::Point_d; -using Points_off_reader = Gudhi::Points_off_reader; - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence); - -static inline std::pair compute_root_square(std::pair input) { - return std::make_pair(std::sqrt(input.first), std::sqrt(input.second)); -} - -int main(int argc, char * argv[]) { - std::string off_file_points; - Filtration_value threshold; - int dim_max; - int p; - Filtration_value min_persistence; - - program_options(argc, argv, off_file_points, threshold, dim_max, p, min_persistence); - - Points_off_reader off_reader(off_file_points); - - // -------------------------------------------- - // Rips persistence - // -------------------------------------------- - Rips_complex rips_complex(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); - - // Construct the Rips complex in a Simplex Tree - Simplex_tree rips_stree; - - rips_complex.create_complex(rips_stree, dim_max); - std::cout << "The Rips complex contains " << rips_stree.num_simplices() << " simplices and has dimension " - << rips_stree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - rips_stree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology rips_pcoh(rips_stree); - // initializes the coefficient field for homology - rips_pcoh.init_coefficients(p); - rips_pcoh.compute_persistent_cohomology(min_persistence); - - // rips_pcoh.output_diagram(); - - // -------------------------------------------- - // Alpha persistence - // -------------------------------------------- - Gudhi::alpha_complex::Alpha_complex alpha_complex(off_reader.get_point_cloud()); - - Simplex_tree alpha_stree; - alpha_complex.create_complex(alpha_stree, threshold * threshold); - std::cout << "The Alpha complex contains " << alpha_stree.num_simplices() << " simplices and has dimension " - << alpha_stree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - alpha_stree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology alpha_pcoh(alpha_stree); - // initializes the coefficient field for homology - alpha_pcoh.init_coefficients(p); - alpha_pcoh.compute_persistent_cohomology(min_persistence * min_persistence); - - // alpha_pcoh.output_diagram(); - - // -------------------------------------------- - // Bottleneck distance between both persistence - // -------------------------------------------- - double max_b_distance {}; - for (int dim = 0; dim < dim_max; dim ++) { - std::vector< std::pair< Filtration_value , Filtration_value > > rips_intervals; - std::vector< std::pair< Filtration_value , Filtration_value > > alpha_intervals; - rips_intervals = rips_pcoh.intervals_in_dimension(dim); - alpha_intervals = alpha_pcoh.intervals_in_dimension(dim); - std::transform(alpha_intervals.begin(), alpha_intervals.end(), alpha_intervals.begin(), compute_root_square); - - double bottleneck_distance = Gudhi::persistence_diagram::bottleneck_distance(rips_intervals, alpha_intervals); - std::cout << "In dimension " << dim << ", bottleneck distance = " << bottleneck_distance << std::endl; - if (bottleneck_distance > max_b_distance) - max_b_distance = bottleneck_distance; - } - std::cout << "================================================================================" << std::endl; - std::cout << "Bottleneck distance is " << max_b_distance << std::endl; - - return 0; -} - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of an OFF file containing a point set.\n"); - - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} diff --git a/src/Bottleneck_distance/utilities/CMakeLists.txt b/src/Bottleneck_distance/utilities/CMakeLists.txt new file mode 100644 index 00000000..ba4de11e --- /dev/null +++ b/src/Bottleneck_distance/utilities/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.6) +project(Bottleneck_distance_utilities) + +if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) + add_executable (alpha_rips_persistence_bottleneck_distance alpha_rips_persistence_bottleneck_distance.cpp) + target_link_libraries(alpha_rips_persistence_bottleneck_distance ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(bottleneck_read_file_example ${TBB_LIBRARIES}) + target_link_libraries(bottleneck_basic_example ${TBB_LIBRARIES}) + target_link_libraries(alpha_rips_persistence_bottleneck_distance ${TBB_LIBRARIES}) + endif(TBB_FOUND) + + add_test(NAME Bottleneck_distance_example_alpha_rips_persistence_bottleneck + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.15" "-m" "0.12" "-d" "3" "-p" "3") + + install(TARGETS alpha_rips_persistence_bottleneck_distance DESTINATION bin) + +endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) diff --git a/src/Bottleneck_distance/utilities/alpha_rips_persistence_bottleneck_distance.cpp b/src/Bottleneck_distance/utilities/alpha_rips_persistence_bottleneck_distance.cpp new file mode 100644 index 00000000..fd164b22 --- /dev/null +++ b/src/Bottleneck_distance/utilities/alpha_rips_persistence_bottleneck_distance.cpp @@ -0,0 +1,190 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2017 INRIA + * + * 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 // infinity +#include // for pair +#include // for transform + + +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; +using Point_d = Kernel::Point_d; +using Points_off_reader = Gudhi::Points_off_reader; + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +static inline std::pair compute_root_square(std::pair input) { + return std::make_pair(std::sqrt(input.first), std::sqrt(input.second)); +} + +int main(int argc, char * argv[]) { + std::string off_file_points; + Filtration_value threshold; + int dim_max; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, off_file_points, threshold, dim_max, p, min_persistence); + + Points_off_reader off_reader(off_file_points); + + // -------------------------------------------- + // Rips persistence + // -------------------------------------------- + Rips_complex rips_complex(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); + + // Construct the Rips complex in a Simplex Tree + Simplex_tree rips_stree; + + rips_complex.create_complex(rips_stree, dim_max); + std::cout << "The Rips complex contains " << rips_stree.num_simplices() << " simplices and has dimension " + << rips_stree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + rips_stree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology rips_pcoh(rips_stree); + // initializes the coefficient field for homology + rips_pcoh.init_coefficients(p); + rips_pcoh.compute_persistent_cohomology(min_persistence); + + // rips_pcoh.output_diagram(); + + // -------------------------------------------- + // Alpha persistence + // -------------------------------------------- + Gudhi::alpha_complex::Alpha_complex alpha_complex(off_reader.get_point_cloud()); + + Simplex_tree alpha_stree; + alpha_complex.create_complex(alpha_stree, threshold * threshold); + std::cout << "The Alpha complex contains " << alpha_stree.num_simplices() << " simplices and has dimension " + << alpha_stree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + alpha_stree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology alpha_pcoh(alpha_stree); + // initializes the coefficient field for homology + alpha_pcoh.init_coefficients(p); + alpha_pcoh.compute_persistent_cohomology(min_persistence * min_persistence); + + // alpha_pcoh.output_diagram(); + + // -------------------------------------------- + // Bottleneck distance between both persistence + // -------------------------------------------- + double max_b_distance {}; + for (int dim = 0; dim < dim_max; dim ++) { + std::vector< std::pair< Filtration_value , Filtration_value > > rips_intervals; + std::vector< std::pair< Filtration_value , Filtration_value > > alpha_intervals; + rips_intervals = rips_pcoh.intervals_in_dimension(dim); + alpha_intervals = alpha_pcoh.intervals_in_dimension(dim); + std::transform(alpha_intervals.begin(), alpha_intervals.end(), alpha_intervals.begin(), compute_root_square); + + double bottleneck_distance = Gudhi::persistence_diagram::bottleneck_distance(rips_intervals, alpha_intervals); + std::cout << "In dimension " << dim << ", bottleneck distance = " << bottleneck_distance << std::endl; + if (bottleneck_distance > max_b_distance) + max_b_distance = bottleneck_distance; + } + std::cout << "================================================================================" << std::endl; + std::cout << "Bottleneck distance is " << max_b_distance << std::endl; + + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&off_file_points), + "Name of an OFF file containing a point set.\n"); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} -- cgit v1.2.3 From 14f55cf58e9be168e6be635ddafebc6c86cc7eea Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 16:48:08 +0000 Subject: Convert more examples into utilities git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2494 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 54fa703f0489cba059a8df973738118f6a092f70 --- src/Contraction/example/CMakeLists.txt | 5 +- src/Contraction/example/Garland_heckbert.cpp | 195 --------------- .../example/Garland_heckbert/Error_quadric.h | 182 -------------- src/Contraction/utilities/CMakeLists.txt | 7 + src/Contraction/utilities/Garland_heckbert.cpp | 195 +++++++++++++++ .../utilities/Garland_heckbert/Error_quadric.h | 182 ++++++++++++++ src/Persistent_cohomology/example/CMakeLists.txt | 35 --- .../example/alpha_complex_3d_helper.h | 76 ------ .../example/alpha_complex_3d_persistence.cpp | 243 ------------------- .../example/alpha_complex_persistence.cpp | 125 ---------- .../example/exact_alpha_complex_3d_persistence.cpp | 2 +- .../periodic_alpha_complex_3d_persistence.cpp | 262 --------------------- .../example/rips_distance_matrix_persistence.cpp | 144 ----------- .../example/rips_persistence.cpp | 147 ------------ .../weighted_alpha_complex_3d_persistence.cpp | 2 +- src/Persistent_cohomology/utilities/CMakeLists.txt | 56 +++++ .../utilities/alpha_complex_3d_helper.h | 76 ++++++ .../utilities/alpha_complex_3d_persistence.cpp | 243 +++++++++++++++++++ .../utilities/alpha_complex_persistence.cpp | 125 ++++++++++ .../periodic_alpha_complex_3d_persistence.cpp | 262 +++++++++++++++++++++ .../utilities/rips_distance_matrix_persistence.cpp | 144 +++++++++++ .../utilities/rips_persistence.cpp | 147 ++++++++++++ src/Witness_complex/example/CMakeLists.txt | 14 -- .../example/example_strong_witness_complex_off.cpp | 79 ------- .../example/example_strong_witness_persistence.cpp | 171 -------------- src/Witness_complex/utilities/CMakeLists.txt | 26 ++ .../example_strong_witness_complex_off.cpp | 79 +++++++ .../example_strong_witness_persistence.cpp | 171 ++++++++++++++ 28 files changed, 1716 insertions(+), 1679 deletions(-) delete mode 100644 src/Contraction/example/Garland_heckbert.cpp delete mode 100644 src/Contraction/example/Garland_heckbert/Error_quadric.h create mode 100644 src/Contraction/utilities/CMakeLists.txt create mode 100644 src/Contraction/utilities/Garland_heckbert.cpp create mode 100644 src/Contraction/utilities/Garland_heckbert/Error_quadric.h delete mode 100644 src/Persistent_cohomology/example/alpha_complex_3d_helper.h delete mode 100644 src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp delete mode 100644 src/Persistent_cohomology/example/alpha_complex_persistence.cpp delete mode 100644 src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp delete mode 100644 src/Persistent_cohomology/example/rips_distance_matrix_persistence.cpp delete mode 100644 src/Persistent_cohomology/example/rips_persistence.cpp create mode 100644 src/Persistent_cohomology/utilities/CMakeLists.txt create mode 100644 src/Persistent_cohomology/utilities/alpha_complex_3d_helper.h create mode 100644 src/Persistent_cohomology/utilities/alpha_complex_3d_persistence.cpp create mode 100644 src/Persistent_cohomology/utilities/alpha_complex_persistence.cpp create mode 100644 src/Persistent_cohomology/utilities/periodic_alpha_complex_3d_persistence.cpp create mode 100644 src/Persistent_cohomology/utilities/rips_distance_matrix_persistence.cpp create mode 100644 src/Persistent_cohomology/utilities/rips_persistence.cpp delete mode 100644 src/Witness_complex/example/example_strong_witness_complex_off.cpp delete mode 100644 src/Witness_complex/example/example_strong_witness_persistence.cpp create mode 100644 src/Witness_complex/utilities/CMakeLists.txt create mode 100644 src/Witness_complex/utilities/example_strong_witness_complex_off.cpp create mode 100644 src/Witness_complex/utilities/example_strong_witness_persistence.cpp diff --git a/src/Contraction/example/CMakeLists.txt b/src/Contraction/example/CMakeLists.txt index b2b38dea..5cd32daf 100644 --- a/src/Contraction/example/CMakeLists.txt +++ b/src/Contraction/example/CMakeLists.txt @@ -3,10 +3,8 @@ project(Contraction_examples) add_executable(RipsContraction Rips_contraction.cpp) -add_executable(GarlandHeckbert Garland_heckbert.cpp) -target_link_libraries(RipsContraction ${Boost_TIMER_LIBRARY} ${Boost_SYSTEM_LIBRARY}) -target_link_libraries(GarlandHeckbert ${Boost_TIMER_LIBRARY} ${Boost_SYSTEM_LIBRARY}) +target_link_libraries(RipsContraction ${Boost_TIMER_LIBRARY} ${Boost_SYSTEM_LIBRARY}) add_test(NAME Contraction_example_tore3D_0.2 COMMAND $ @@ -18,4 +16,3 @@ add_test(NAME Contraction_example_tore3D_0.2 COMMAND $. - * - */ - - -#ifndef GARLAND_HECKBERT_H_ -#define GARLAND_HECKBERT_H_ - -#include -#include -#include -#include - -#include -#include - -#include "Garland_heckbert/Error_quadric.h" - -struct Geometry_trait { - typedef Point_d Point; -}; - -/** - * The vertex stored in the complex contains a quadric. - */ -struct Garland_heckbert_traits - : public Gudhi::skeleton_blocker::Skeleton_blocker_simple_geometric_traits { - public: - struct Garland_heckbert_vertex : public Simple_geometric_vertex { - Error_quadric quadric; - }; - typedef Garland_heckbert_vertex Graph_vertex; -}; - -using Complex = Gudhi::skeleton_blocker::Skeleton_blocker_geometric_complex< Garland_heckbert_traits >; -using EdgeProfile = Gudhi::contraction::Edge_profile; -using Complex_contractor = Gudhi::contraction::Skeleton_blocker_contractor; - -/** - * How the new vertex is placed after an edge collapse : here it is placed at - * the point minimizing the cost of the quadric. - */ -class GH_placement : public Gudhi::contraction::Placement_policy { - Complex& complex_; - - public: - typedef Gudhi::contraction::Placement_policy::Placement_type Placement_type; - - GH_placement(Complex& complex) : complex_(complex) { (void)complex_; } - - Placement_type operator()(const EdgeProfile& profile) const override { - auto sum_quad(profile.v0().quadric); - sum_quad += profile.v1().quadric; - - boost::optional min_quadric_pt(sum_quad.min_cost()); - if (min_quadric_pt) - return Placement_type(*min_quadric_pt); - else - return profile.p0(); - } -}; - -/** - * How much cost an edge collapse : here the costs is given by a quadric - * which expresses a squared distances with triangles planes. - */ -class GH_cost : public Gudhi::contraction::Cost_policy { - Complex& complex_; - - public: - typedef Gudhi::contraction::Cost_policy::Cost_type Cost_type; - - GH_cost(Complex& complex) : complex_(complex) { (void)complex_; } - - Cost_type operator()(EdgeProfile const& profile, boost::optional const& new_point) const override { - Cost_type res; - if (new_point) { - auto sum_quad(profile.v0().quadric); - sum_quad += profile.v1().quadric; - res = sum_quad.cost(*new_point); - } - return res; - } -}; - -/** - * Visitor that is called at several moment. - * Here we initializes the quadrics of every vertex at the on_started call back - * and we update them when contracting an edge (the quadric become the sum of both quadrics). - */ -class GH_visitor : public Gudhi::contraction::Contraction_visitor { - Complex& complex_; - - public: - GH_visitor(Complex& complex) : complex_(complex) { (void)complex_; } - - // Compute quadrics for every vertex v - // The quadric of v consists in the sum of quadric - // of every triangles passing through v weighted by its area - - void on_started(Complex & complex) override { - for (auto v : complex.vertex_range()) { - auto & quadric_v(complex[v].quadric); - for (auto t : complex.triangle_range(v)) { - auto t_it = t.begin(); - const auto& p0(complex.point(*t_it++)); - const auto& p1(complex.point(*t_it++)); - const auto& p2(complex.point(*t_it++)); - quadric_v += Error_quadric(p0, p1, p2); - } - } - } - - /** - * @brief Called when an edge is about to be contracted and replaced by a vertex whose position is *placement. - */ - void on_contracting(EdgeProfile const &profile, boost::optional< Point > placement) - override { - profile.v0().quadric += profile.v1().quadric; - } -}; - -int main(int argc, char *argv[]) { - if (argc != 4) { - std::cerr << "Usage " << argv[0] << - " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; - return EXIT_FAILURE; - } - - Complex complex; - typedef Complex::Vertex_handle Vertex_handle; - - // load the points - Gudhi::skeleton_blocker::Skeleton_blocker_off_reader off_reader(argv[1], complex); - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file:" << argv[1] << std::endl; - return EXIT_FAILURE; - } - - if (!complex.empty() && !(complex.point(Vertex_handle(0)).dimension() == 3)) { - std::cerr << "Only points of dimension 3 are supported." << std::endl; - return EXIT_FAILURE; - } - - std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; - - int num_contractions = atoi(argv[3]); - - boost::timer::auto_cpu_timer t; - - // constructs the contractor object with Garland Heckbert policies. - Complex_contractor contractor(complex, - new GH_cost(complex), - new GH_placement(complex), - Gudhi::contraction::make_link_valid_contraction(), - new GH_visitor(complex)); - - std::cout << "Contract " << num_contractions << " edges" << std::endl; - contractor.contract_edges(num_contractions); - - std::cout << "Final complex has " << - complex.num_vertices() << " vertices, " << - complex.num_edges() << " edges and " << - complex.num_triangles() << " triangles." << std::endl; - - // write simplified complex - Gudhi::skeleton_blocker::Skeleton_blocker_off_writer off_writer(argv[2], complex); - - return EXIT_SUCCESS; -} - -#endif // GARLAND_HECKBERT_H_ - - - - diff --git a/src/Contraction/example/Garland_heckbert/Error_quadric.h b/src/Contraction/example/Garland_heckbert/Error_quadric.h deleted file mode 100644 index e7dafaa0..00000000 --- a/src/Contraction/example/Garland_heckbert/Error_quadric.h +++ /dev/null @@ -1,182 +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): David Salinas - * - * Copyright (C) 2014 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 . - * - */ - -#ifndef GARLAND_HECKBERT_ERROR_QUADRIC_H_ -#define GARLAND_HECKBERT_ERROR_QUADRIC_H_ - -#include - -#include -#include - -template class Error_quadric { - private: - double coeff[10]; - - public: - Error_quadric() { - clear(); - } - - /** - * Quadric corresponding to the L2 distance to the plane. - * - * According to the notation of Garland Heckbert, they - * denote a quadric symetric matrix as : - * Q = [ q11 q12 q13 q14] - * [ q12 q22 q23 q24] - * [ q13 q23 q33 q34] - * [ q14 q24 q34 q44] - * - * which is represented by a vector with 10 elts that - * are denoted ci for clarity with : - * Q = [ c0 c1 c2 c3 ] - * [ c1 c4 c5 c6 ] - * [ c2 c5 c7 c8 ] - * [ c3 c6 c8 c9 ] - * - * The constructor return the quadrics that represents - * the squared distance to the plane defined by triangle p0,p1,p2 - * times the area of triangle p0,p1,p2. - */ - Error_quadric(const Point & p0, const Point & p1, const Point & p2) { - Point normal(unit_normal(p0, p1, p2)); - double a = normal[0]; - double b = normal[1]; - double c = normal[2]; - double d = -a * p0[0] - b * p0[1] - c * p0[2]; - coeff[0] = a*a; - coeff[1] = a*b; - coeff[2] = a*c; - coeff[3] = a*d; - coeff[4] = b*b; - coeff[5] = b*c; - coeff[6] = b*d; - coeff[7] = c*c; - coeff[8] = c*d; - coeff[9] = d*d; - - double area_p0p1p2 = std::sqrt(squared_area(p0, p1, p2)); - for (auto& x : coeff) - x *= area_p0p1p2; - } - - inline double squared_area(const Point& p0, const Point& p1, const Point& p2) { - // if (x1,x2,x3) = p1-p0 and (y1,y2,y3) = p2-p0 - // then the squared area is = (u^2+v^2+w^2)/4 - // with: u = x2 * y3 - x3 * y2; - // v = x3 * y1 - x1 * y3; - // w = x1 * y2 - x2 * y1; - Point p0p1(p1 - p0); - Point p0p2(p2 - p0); - double A = p0p1[1] * p0p2[2] - p0p1[2] * p0p2[1]; - double B = p0p1[2] * p0p2[0] - p0p1[0] * p0p2[2]; - double C = p0p1[0] * p0p2[1] - p0p1[1] * p0p2[0]; - return 1. / 4. * (A * A + B * B + C * C); - } - - void clear() { - for (auto& x : coeff) - x = 0; - } - - Error_quadric& operator+=(const Error_quadric& other) { - if (this != &other) { - for (int i = 0; i < 10; ++i) - coeff[i] += other.coeff[i]; - } - return *this; - } - - /** - * @return The quadric quost defined by the scalar product v^T Q v where Q is the quadratic form of Garland/Heckbert - */ - inline double cost(const Point& point) const { - double cost = - coeff[0] * point.x() * point.x() + coeff[4] * point.y() * point.y() + coeff[7] * point.z() * point.z() - + 2 * (coeff[1] * point.x() * point.y() + coeff[5] * point.y() * point.z() + coeff[2] * point.z() * point.x()) - + 2 * (coeff[3] * point.x() + coeff[6] * point.y() + coeff[8] * point.z()) - + coeff[9]; - if (cost < 0) { - return 0; - } else { - return cost; - } - } - - inline double grad_determinant() const { - return - coeff[0] * coeff[4] * coeff[7] - - coeff[0] * coeff[5] * coeff[5] - - coeff[1] * coeff[1] * coeff[7] - + 2 * coeff[1] * coeff[5] * coeff[2] - - coeff[4] * coeff[2] * coeff[2]; - } - - /** - * Return the point such that it minimizes the gradient of the quadric. - * Det must be passed with the determinant value of the gradient (should be non zero). - */ - inline Point solve_linear_gradient(double det) const { - return Point({ - (-coeff[1] * coeff[5] * coeff[8] + coeff[1] * coeff[7] * coeff[6] + coeff[2] * coeff[8] * coeff[4] - - coeff[2] * coeff[5] * coeff[6] - coeff[3] * coeff[4] * coeff[7] + coeff[3] * coeff[5] * coeff[5]) - / det, - (coeff[0] * coeff[5] * coeff[8] - coeff[0] * coeff[7] * coeff[6] - coeff[5] * coeff[2] * coeff[3] - - coeff[1] * coeff[2] * coeff[8] + coeff[6] * coeff[2] * coeff[2] + coeff[1] * coeff[3] * coeff[7]) - / det, - (-coeff[8] * coeff[0] * coeff[4] + coeff[8] * coeff[1] * coeff[1] + coeff[2] * coeff[3] * coeff[4] + - coeff[5] * coeff[0] * coeff[6] - coeff[5] * coeff[1] * coeff[3] - coeff[1] * coeff[2] * coeff[6]) - / det - }); - } - - /** - * returns the point that minimizes the quadric. - * It inverses the quadric if its determinant is higher that a given threshold . - * If the determinant is lower than this value the returned value is uninitialized. - */ - boost::optional min_cost(double scale = 1) const { - // const double min_determinant = 1e-4 * scale*scale; - const double min_determinant = 1e-5; - boost::optional pt_res; - double det = grad_determinant(); - if (std::abs(det) > min_determinant) - pt_res = solve_linear_gradient(det); - return pt_res; - } - - friend std::ostream& operator<<(std::ostream& stream, const Error_quadric& quadric) { - stream << "\n[ " << quadric.coeff[0] << "," << quadric.coeff[1] << "," << quadric.coeff[2] << "," << - quadric.coeff[3] << ";\n"; - stream << " " << quadric.coeff[1] << "," << quadric.coeff[4] << "," << quadric.coeff[5] << "," << - quadric.coeff[6] << ";\n"; - stream << " " << quadric.coeff[2] << "," << quadric.coeff[5] << "," << quadric.coeff[7] << "," << - quadric.coeff[8] << ";\n"; - stream << " " << quadric.coeff[3] << "," << quadric.coeff[6] << "," << quadric.coeff[8] << "," << - quadric.coeff[9] << "]"; - return stream; - } -}; - -#endif // GARLAND_HECKBERT_ERROR_QUADRIC_H_ diff --git a/src/Contraction/utilities/CMakeLists.txt b/src/Contraction/utilities/CMakeLists.txt new file mode 100644 index 00000000..77aa99d5 --- /dev/null +++ b/src/Contraction/utilities/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.6) +project(Contraction_utilities) + +add_executable(GarlandHeckbert Garland_heckbert.cpp) +target_link_libraries(GarlandHeckbert ${Boost_TIMER_LIBRARY} ${Boost_SYSTEM_LIBRARY}) + +install(TARGETS GarlandHeckbert DESTINATION bin) diff --git a/src/Contraction/utilities/Garland_heckbert.cpp b/src/Contraction/utilities/Garland_heckbert.cpp new file mode 100644 index 00000000..8b5a6a6c --- /dev/null +++ b/src/Contraction/utilities/Garland_heckbert.cpp @@ -0,0 +1,195 @@ +/* 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-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 . + * + */ + + +#ifndef GARLAND_HECKBERT_H_ +#define GARLAND_HECKBERT_H_ + +#include +#include +#include +#include + +#include +#include + +#include "Garland_heckbert/Error_quadric.h" + +struct Geometry_trait { + typedef Point_d Point; +}; + +/** + * The vertex stored in the complex contains a quadric. + */ +struct Garland_heckbert_traits + : public Gudhi::skeleton_blocker::Skeleton_blocker_simple_geometric_traits { + public: + struct Garland_heckbert_vertex : public Simple_geometric_vertex { + Error_quadric quadric; + }; + typedef Garland_heckbert_vertex Graph_vertex; +}; + +using Complex = Gudhi::skeleton_blocker::Skeleton_blocker_geometric_complex< Garland_heckbert_traits >; +using EdgeProfile = Gudhi::contraction::Edge_profile; +using Complex_contractor = Gudhi::contraction::Skeleton_blocker_contractor; + +/** + * How the new vertex is placed after an edge collapse : here it is placed at + * the point minimizing the cost of the quadric. + */ +class GH_placement : public Gudhi::contraction::Placement_policy { + Complex& complex_; + + public: + typedef Gudhi::contraction::Placement_policy::Placement_type Placement_type; + + GH_placement(Complex& complex) : complex_(complex) { (void)complex_; } + + Placement_type operator()(const EdgeProfile& profile) const override { + auto sum_quad(profile.v0().quadric); + sum_quad += profile.v1().quadric; + + boost::optional min_quadric_pt(sum_quad.min_cost()); + if (min_quadric_pt) + return Placement_type(*min_quadric_pt); + else + return profile.p0(); + } +}; + +/** + * How much cost an edge collapse : here the costs is given by a quadric + * which expresses a squared distances with triangles planes. + */ +class GH_cost : public Gudhi::contraction::Cost_policy { + Complex& complex_; + + public: + typedef Gudhi::contraction::Cost_policy::Cost_type Cost_type; + + GH_cost(Complex& complex) : complex_(complex) { (void)complex_; } + + Cost_type operator()(EdgeProfile const& profile, boost::optional const& new_point) const override { + Cost_type res; + if (new_point) { + auto sum_quad(profile.v0().quadric); + sum_quad += profile.v1().quadric; + res = sum_quad.cost(*new_point); + } + return res; + } +}; + +/** + * Visitor that is called at several moment. + * Here we initializes the quadrics of every vertex at the on_started call back + * and we update them when contracting an edge (the quadric become the sum of both quadrics). + */ +class GH_visitor : public Gudhi::contraction::Contraction_visitor { + Complex& complex_; + + public: + GH_visitor(Complex& complex) : complex_(complex) { (void)complex_; } + + // Compute quadrics for every vertex v + // The quadric of v consists in the sum of quadric + // of every triangles passing through v weighted by its area + + void on_started(Complex & complex) override { + for (auto v : complex.vertex_range()) { + auto & quadric_v(complex[v].quadric); + for (auto t : complex.triangle_range(v)) { + auto t_it = t.begin(); + const auto& p0(complex.point(*t_it++)); + const auto& p1(complex.point(*t_it++)); + const auto& p2(complex.point(*t_it++)); + quadric_v += Error_quadric(p0, p1, p2); + } + } + } + + /** + * @brief Called when an edge is about to be contracted and replaced by a vertex whose position is *placement. + */ + void on_contracting(EdgeProfile const &profile, boost::optional< Point > placement) + override { + profile.v0().quadric += profile.v1().quadric; + } +}; + +int main(int argc, char *argv[]) { + if (argc != 4) { + std::cerr << "Usage " << argv[0] << + " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; + return EXIT_FAILURE; + } + + Complex complex; + typedef Complex::Vertex_handle Vertex_handle; + + // load the points + Gudhi::skeleton_blocker::Skeleton_blocker_off_reader off_reader(argv[1], complex); + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file:" << argv[1] << std::endl; + return EXIT_FAILURE; + } + + if (!complex.empty() && !(complex.point(Vertex_handle(0)).dimension() == 3)) { + std::cerr << "Only points of dimension 3 are supported." << std::endl; + return EXIT_FAILURE; + } + + std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; + + int num_contractions = atoi(argv[3]); + + boost::timer::auto_cpu_timer t; + + // constructs the contractor object with Garland Heckbert policies. + Complex_contractor contractor(complex, + new GH_cost(complex), + new GH_placement(complex), + Gudhi::contraction::make_link_valid_contraction(), + new GH_visitor(complex)); + + std::cout << "Contract " << num_contractions << " edges" << std::endl; + contractor.contract_edges(num_contractions); + + std::cout << "Final complex has " << + complex.num_vertices() << " vertices, " << + complex.num_edges() << " edges and " << + complex.num_triangles() << " triangles." << std::endl; + + // write simplified complex + Gudhi::skeleton_blocker::Skeleton_blocker_off_writer off_writer(argv[2], complex); + + return EXIT_SUCCESS; +} + +#endif // GARLAND_HECKBERT_H_ + + + + diff --git a/src/Contraction/utilities/Garland_heckbert/Error_quadric.h b/src/Contraction/utilities/Garland_heckbert/Error_quadric.h new file mode 100644 index 00000000..e7dafaa0 --- /dev/null +++ b/src/Contraction/utilities/Garland_heckbert/Error_quadric.h @@ -0,0 +1,182 @@ +/* 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-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 . + * + */ + +#ifndef GARLAND_HECKBERT_ERROR_QUADRIC_H_ +#define GARLAND_HECKBERT_ERROR_QUADRIC_H_ + +#include + +#include +#include + +template class Error_quadric { + private: + double coeff[10]; + + public: + Error_quadric() { + clear(); + } + + /** + * Quadric corresponding to the L2 distance to the plane. + * + * According to the notation of Garland Heckbert, they + * denote a quadric symetric matrix as : + * Q = [ q11 q12 q13 q14] + * [ q12 q22 q23 q24] + * [ q13 q23 q33 q34] + * [ q14 q24 q34 q44] + * + * which is represented by a vector with 10 elts that + * are denoted ci for clarity with : + * Q = [ c0 c1 c2 c3 ] + * [ c1 c4 c5 c6 ] + * [ c2 c5 c7 c8 ] + * [ c3 c6 c8 c9 ] + * + * The constructor return the quadrics that represents + * the squared distance to the plane defined by triangle p0,p1,p2 + * times the area of triangle p0,p1,p2. + */ + Error_quadric(const Point & p0, const Point & p1, const Point & p2) { + Point normal(unit_normal(p0, p1, p2)); + double a = normal[0]; + double b = normal[1]; + double c = normal[2]; + double d = -a * p0[0] - b * p0[1] - c * p0[2]; + coeff[0] = a*a; + coeff[1] = a*b; + coeff[2] = a*c; + coeff[3] = a*d; + coeff[4] = b*b; + coeff[5] = b*c; + coeff[6] = b*d; + coeff[7] = c*c; + coeff[8] = c*d; + coeff[9] = d*d; + + double area_p0p1p2 = std::sqrt(squared_area(p0, p1, p2)); + for (auto& x : coeff) + x *= area_p0p1p2; + } + + inline double squared_area(const Point& p0, const Point& p1, const Point& p2) { + // if (x1,x2,x3) = p1-p0 and (y1,y2,y3) = p2-p0 + // then the squared area is = (u^2+v^2+w^2)/4 + // with: u = x2 * y3 - x3 * y2; + // v = x3 * y1 - x1 * y3; + // w = x1 * y2 - x2 * y1; + Point p0p1(p1 - p0); + Point p0p2(p2 - p0); + double A = p0p1[1] * p0p2[2] - p0p1[2] * p0p2[1]; + double B = p0p1[2] * p0p2[0] - p0p1[0] * p0p2[2]; + double C = p0p1[0] * p0p2[1] - p0p1[1] * p0p2[0]; + return 1. / 4. * (A * A + B * B + C * C); + } + + void clear() { + for (auto& x : coeff) + x = 0; + } + + Error_quadric& operator+=(const Error_quadric& other) { + if (this != &other) { + for (int i = 0; i < 10; ++i) + coeff[i] += other.coeff[i]; + } + return *this; + } + + /** + * @return The quadric quost defined by the scalar product v^T Q v where Q is the quadratic form of Garland/Heckbert + */ + inline double cost(const Point& point) const { + double cost = + coeff[0] * point.x() * point.x() + coeff[4] * point.y() * point.y() + coeff[7] * point.z() * point.z() + + 2 * (coeff[1] * point.x() * point.y() + coeff[5] * point.y() * point.z() + coeff[2] * point.z() * point.x()) + + 2 * (coeff[3] * point.x() + coeff[6] * point.y() + coeff[8] * point.z()) + + coeff[9]; + if (cost < 0) { + return 0; + } else { + return cost; + } + } + + inline double grad_determinant() const { + return + coeff[0] * coeff[4] * coeff[7] + - coeff[0] * coeff[5] * coeff[5] + - coeff[1] * coeff[1] * coeff[7] + + 2 * coeff[1] * coeff[5] * coeff[2] + - coeff[4] * coeff[2] * coeff[2]; + } + + /** + * Return the point such that it minimizes the gradient of the quadric. + * Det must be passed with the determinant value of the gradient (should be non zero). + */ + inline Point solve_linear_gradient(double det) const { + return Point({ + (-coeff[1] * coeff[5] * coeff[8] + coeff[1] * coeff[7] * coeff[6] + coeff[2] * coeff[8] * coeff[4] - + coeff[2] * coeff[5] * coeff[6] - coeff[3] * coeff[4] * coeff[7] + coeff[3] * coeff[5] * coeff[5]) + / det, + (coeff[0] * coeff[5] * coeff[8] - coeff[0] * coeff[7] * coeff[6] - coeff[5] * coeff[2] * coeff[3] - + coeff[1] * coeff[2] * coeff[8] + coeff[6] * coeff[2] * coeff[2] + coeff[1] * coeff[3] * coeff[7]) + / det, + (-coeff[8] * coeff[0] * coeff[4] + coeff[8] * coeff[1] * coeff[1] + coeff[2] * coeff[3] * coeff[4] + + coeff[5] * coeff[0] * coeff[6] - coeff[5] * coeff[1] * coeff[3] - coeff[1] * coeff[2] * coeff[6]) + / det + }); + } + + /** + * returns the point that minimizes the quadric. + * It inverses the quadric if its determinant is higher that a given threshold . + * If the determinant is lower than this value the returned value is uninitialized. + */ + boost::optional min_cost(double scale = 1) const { + // const double min_determinant = 1e-4 * scale*scale; + const double min_determinant = 1e-5; + boost::optional pt_res; + double det = grad_determinant(); + if (std::abs(det) > min_determinant) + pt_res = solve_linear_gradient(det); + return pt_res; + } + + friend std::ostream& operator<<(std::ostream& stream, const Error_quadric& quadric) { + stream << "\n[ " << quadric.coeff[0] << "," << quadric.coeff[1] << "," << quadric.coeff[2] << "," << + quadric.coeff[3] << ";\n"; + stream << " " << quadric.coeff[1] << "," << quadric.coeff[4] << "," << quadric.coeff[5] << "," << + quadric.coeff[6] << ";\n"; + stream << " " << quadric.coeff[2] << "," << quadric.coeff[5] << "," << quadric.coeff[7] << "," << + quadric.coeff[8] << ";\n"; + stream << " " << quadric.coeff[3] << "," << quadric.coeff[6] << "," << quadric.coeff[8] << "," << + quadric.coeff[9] << "]"; + return stream; + } +}; + +#endif // GARLAND_HECKBERT_ERROR_QUADRIC_H_ diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index a9884c49..eb31e050 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -7,12 +7,6 @@ target_link_libraries(plain_homology ${Boost_SYSTEM_LIBRARY}) add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp) target_link_libraries(persistence_from_simple_simplex_tree ${Boost_SYSTEM_LIBRARY}) -add_executable(rips_distance_matrix_persistence rips_distance_matrix_persistence.cpp) -target_link_libraries(rips_distance_matrix_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - -add_executable(rips_persistence rips_persistence.cpp) -target_link_libraries(rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - add_executable(rips_persistence_step_by_step rips_persistence_step_by_step.cpp) target_link_libraries(rips_persistence_step_by_step ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) @@ -25,8 +19,6 @@ target_link_libraries(persistence_from_file ${Boost_SYSTEM_LIBRARY} ${Boost_PROG if (TBB_FOUND) target_link_libraries(plain_homology ${TBB_LIBRARIES}) target_link_libraries(persistence_from_simple_simplex_tree ${TBB_LIBRARIES}) - target_link_libraries(rips_distance_matrix_persistence ${TBB_LIBRARIES}) - target_link_libraries(rips_persistence ${TBB_LIBRARIES}) target_link_libraries(rips_persistence_step_by_step ${TBB_LIBRARIES}) target_link_libraries(rips_persistence_via_boundary_matrix ${TBB_LIBRARIES}) target_link_libraries(persistence_from_file ${TBB_LIBRARIES}) @@ -35,10 +27,6 @@ endif() add_test(NAME Persistent_cohomology_example_plain_homology COMMAND $) add_test(NAME Persistent_cohomology_example_from_simple_simplex_tree COMMAND $ "1" "0") -add_test(NAME Persistent_cohomology_example_from_rips_distance_matrix COMMAND $ - "${CMAKE_SOURCE_DIR}/data/distance_matrix/full_square_distance_matrix.csv" "-r" "1.0" "-d" "3" "-p" "3" "-m" "0") -add_test(NAME Persistent_cohomology_example_from_rips_on_tore_3D COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "3") add_test(NAME Persistent_cohomology_example_from_rips_step_by_step_on_tore_3D COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "3") add_test(NAME Persistent_cohomology_example_via_boundary_matrix COMMAND $ @@ -50,8 +38,6 @@ add_test(NAME Persistent_cohomology_example_from_file_3_3_100 COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") add_test(NAME Persistent_cohomology_example_exact_alpha_complex_3d COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") add_test(NAME Persistent_cohomology_example_weighted_alpha_complex_3d COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.weights" "2" "0.45") - install(TARGETS alpha_complex_3d_persistence DESTINATION bin) install(TARGETS exact_alpha_complex_3d_persistence DESTINATION bin) install(TARGETS weighted_alpha_complex_3d_persistence DESTINATION bin) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) - add_executable (alpha_complex_persistence alpha_complex_persistence.cpp) - target_link_libraries(alpha_complex_persistence - ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - - add_executable(periodic_alpha_complex_3d_persistence periodic_alpha_complex_3d_persistence.cpp) - target_link_libraries(periodic_alpha_complex_3d_persistence ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) - add_executable(custom_persistence_sort custom_persistence_sort.cpp) target_link_libraries(custom_persistence_sort ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) if (TBB_FOUND) - target_link_libraries(alpha_complex_persistence ${TBB_LIBRARIES}) - target_link_libraries(periodic_alpha_complex_3d_persistence ${TBB_LIBRARIES}) target_link_libraries(custom_persistence_sort ${TBB_LIBRARIES}) endif(TBB_FOUND) - add_test(NAME Persistent_cohomology_example_alpha_complex COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "-p" "2" "-m" "0.45") - add_test(NAME Persistent_cohomology_example_periodic_alpha_complex_3d COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off" "${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt" "2" "0") add_test(NAME Persistent_cohomology_example_custom_persistence_sort COMMAND $) - install(TARGETS alpha_complex_persistence DESTINATION bin) - install(TARGETS periodic_alpha_complex_3d_persistence DESTINATION bin) install(TARGETS custom_persistence_sort DESTINATION bin) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) diff --git a/src/Persistent_cohomology/example/alpha_complex_3d_helper.h b/src/Persistent_cohomology/example/alpha_complex_3d_helper.h deleted file mode 100644 index 7865e4ec..00000000 --- a/src/Persistent_cohomology/example/alpha_complex_3d_helper.h +++ /dev/null @@ -1,76 +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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (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 . - */ - -#ifndef ALPHA_COMPLEX_3D_HELPER_H_ -#define ALPHA_COMPLEX_3D_HELPER_H_ - -template -Vertex_list from_cell(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; -} - -template -Vertex_list from_facet(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; -} - -template -Vertex_list from_edge(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; -} - -template -Vertex_list from_vertex(const 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; -} - -#endif // ALPHA_COMPLEX_3D_HELPER_H_ diff --git a/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp deleted file mode 100644 index fd227b82..00000000 --- a/src/Persistent_cohomology/example/alpha_complex_3d_persistence.cpp +++ /dev/null @@ -1,243 +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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA - * - * 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 -#include -#include -#include -#include - -#include "alpha_complex_3d_helper.h" - -// Alpha_shape_3 templates type definitions -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 -using Point_3 = Kernel::Point_3; - -// filtration with alpha values needed type definition -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 -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 << - " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; - exit(-1); -} - -int main(int argc, char * const argv[]) { - // program args management - if (argc != 4) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - - int coeff_field_characteristic = atoi(argv[2]); - - Filtration_value min_persistence = 0.0; - 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]); - } - - // Read points from file - std::string offInputFile(argv[1]); - // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); - // Check the read operation was correct - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); - } - - // Retrieve the triangulation - std::vector lp = off_reader.get_point_cloud(); - - // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. - Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); -#ifdef DEBUG_TRACES - std::cout << "Alpha shape computed in GENERAL mode" << std::endl; -#endif // DEBUG_TRACES - - // filtration with alpha values from alpha shape - std::vector the_objects; - std::vector the_alpha_values; - - Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), - std::back_inserter(the_alpha_values)); - - as.filtration_with_alpha_values(disp); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - - Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; - - // Loop on objects vector - Vertex_list vertex_list; - ST simplex_tree; - Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max = 0; - Filtration_value filtration_max = 0.0; - 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(*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(*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(*edge); - count_edges++; - if (dim_max < 1) { - // Edge_3 is of dim 1 - dim_max = 1; - } - } else if (const Vertex_handle * vertex = CGAL::object_cast(&object_iterator)) { - count_vertices++; - 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; - for (auto the_alpha_shape_vertex : vertex_list) { - Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) { - // alpha shape not found - Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); - } else { - // alpha shape found - Simplex_tree_vertex vertex = the_map_iterator->second; -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - } - } - // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); -#ifdef DEBUG_TRACES - std::cout << "filtration = " << filtr << std::endl; -#endif // DEBUG_TRACES - if (filtr > filtration_max) { - filtration_max = filtr; - } - simplex_tree.insert_simplex(the_simplex_tree, filtr); - if (the_alpha_value_iterator != the_alpha_values.end()) - ++the_alpha_value_iterator; - else - std::cout << "This shall not happen" << std::endl; - } - simplex_tree.set_filtration(filtration_max); - simplex_tree.set_dimension(dim_max); - -#ifdef DEBUG_TRACES - std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; - - - std::cout << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; - std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; - std::cout << " Dimension = " << simplex_tree.dimension() << " "; - std::cout << " filtration = " << simplex_tree.filtration() << std::endl << std::endl; -#endif // DEBUG_TRACES - -#ifdef DEBUG_TRACES - std::cout << "Iterator on vertices: " << std::endl; - for (auto vertex : simplex_tree.complex_vertex_range()) { - std::cout << vertex << " "; - } -#endif // DEBUG_TRACES - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; - // Compute the persistence diagram of the complex - PCOH pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - pcoh.output_diagram(); - - return 0; -} diff --git a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp b/src/Persistent_cohomology/example/alpha_complex_persistence.cpp deleted file mode 100644 index 9e84e91f..00000000 --- a/src/Persistent_cohomology/example/alpha_complex_persistence.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include - -#include - -#include -#include -// to construct a simplex_tree from alpha complex -#include - -#include -#include -#include // for numeric_limits - -using Simplex_tree = Gudhi::Simplex_tree<>; -using Filtration_value = Simplex_tree::Filtration_value; - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & output_file_diag - , Filtration_value & alpha_square_max_value - , int & coeff_field_characteristic - , Filtration_value & min_persistence); - -int main(int argc, char **argv) { - std::string off_file_points; - std::string output_file_diag; - Filtration_value alpha_square_max_value; - int coeff_field_characteristic; - Filtration_value min_persistence; - - program_options(argc, argv, off_file_points, output_file_diag, alpha_square_max_value, - coeff_field_characteristic, min_persistence); - - // ---------------------------------------------------------------------------- - // Init of an alpha complex from an OFF file - // ---------------------------------------------------------------------------- - using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; - Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); - - Simplex_tree simplex; - if (alpha_complex_from_file.create_complex(simplex, alpha_square_max_value)) { - // ---------------------------------------------------------------------------- - // Display information about the alpha complex - // ---------------------------------------------------------------------------- - std::cout << "Simplicial complex is of dimension " << simplex.dimension() << - " - " << simplex.num_simplices() << " simplices - " << - simplex.num_vertices() << " vertices." << std::endl; - - // Sort the simplices in the order of the filtration - simplex.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; - // Compute the persistence diagram of the complex - Gudhi::persistent_cohomology::Persistent_cohomology< Simplex_tree, - Gudhi::persistent_cohomology::Field_Zp > pcoh(simplex); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (output_file_diag.empty()) { - pcoh.output_diagram(); - } else { - std::cout << "Result in file: " << output_file_diag << std::endl; - std::ofstream out(output_file_diag); - pcoh.output_diagram(out); - out.close(); - } - } - - return 0; -} - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & output_file_diag - , Filtration_value & alpha_square_max_value - , int & coeff_field_characteristic - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of file containing a point set. Format is one point per line: X1 ... Xd "); - - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&output_file_diag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-alpha-square-value,r", - po::value(&alpha_square_max_value)->default_value(std::numeric_limits::infinity()), - "Maximal alpha square value for the Alpha complex construction.") - ("field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of an Alpha complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} 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 8a335075..fa49dcee 100644 --- a/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp @@ -40,7 +40,7 @@ #include #include -#include "alpha_complex_3d_helper.h" +#include "../utilities/alpha_complex_3d_helper.h" // Alpha_shape_3 templates type definitions using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; diff --git a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp deleted file mode 100644 index 8928cfc2..00000000 --- a/src/Persistent_cohomology/example/periodic_alpha_complex_3d_persistence.cpp +++ /dev/null @@ -1,262 +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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA - * - * 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 -#include -#include -#include -#include -#include -#include - -#include "alpha_complex_3d_helper.h" - -// Traits -using K = CGAL::Exact_predicates_inexact_constructions_kernel; -using PK = CGAL::Periodic_3_Delaunay_triangulation_traits_3; -// Vertex type -using DsVb = CGAL::Periodic_3_triangulation_ds_vertex_base_3<>; -using Vb = CGAL::Triangulation_vertex_base_3; -using AsVb = CGAL::Alpha_shape_vertex_base_3; -// Cell type -using DsCb = CGAL::Periodic_3_triangulation_ds_cell_base_3<>; -using Cb = CGAL::Triangulation_cell_base_3; -using AsCb = CGAL::Alpha_shape_cell_base_3; -using Tds = CGAL::Triangulation_data_structure_3; -using P3DT3 = CGAL::Periodic_3_Delaunay_triangulation_3; -using Alpha_shape_3 = CGAL::Alpha_shape_3; -using Point_3 = PK::Point_3; - -// filtration with alpha values needed type definition -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 -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 Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< - ST, Gudhi::persistent_cohomology::Field_Zp >; - -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"; - exit(-1); -} - -int main(int argc, char * const argv[]) { - // program args management - if (argc != 5) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - - int coeff_field_characteristic = atoi(argv[3]); - Filtration_value min_persistence = strtof(argv[4], nullptr); - - // Read points from file - std::string offInputFile(argv[1]); - // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); - // Check the read operation was correct - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); - } - - // Read iso_cuboid_3 information from file - std::ifstream iso_cuboid_str(argv[2]); - double x_min, y_min, z_min, x_max, y_max, z_max; - if (iso_cuboid_str.good()) { - iso_cuboid_str >> x_min >> y_min >> z_min >> x_max >> y_max >> z_max; - } else { - std::cerr << "Unable to read file " << argv[2] << std::endl; - usage(argv[0]); - } - - // Retrieve the triangulation - std::vector lp = off_reader.get_point_cloud(); - - // Define the periodic cube - P3DT3 pdt(PK::Iso_cuboid_3(x_min, y_min, z_min, x_max, y_max, z_max)); - // Heuristic for inserting large point sets (if pts is reasonably large) - pdt.insert(lp.begin(), lp.end(), true); - // As pdt won't be modified anymore switch to 1-sheeted cover if possible - if (pdt.is_triangulation_in_1_sheet()) pdt.convert_to_1_sheeted_covering(); - std::cout << "Periodic Delaunay computed." << std::endl; - - // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. This is the default mode - // Maybe need to set it to GENERAL mode - Alpha_shape_3 as(pdt, 0, Alpha_shape_3::GENERAL); - - // filtration with alpha values from alpha shape - std::vector the_objects; - std::vector the_alpha_values; - - Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), - std::back_inserter(the_alpha_values)); - - as.filtration_with_alpha_values(disp); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - - Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; - - // Loop on objects vector - Vertex_list vertex_list; - ST simplex_tree; - Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max = 0; - Filtration_value filtration_max = 0.0; - 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(*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(*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(*edge); - count_edges++; - if (dim_max < 1) { - // Edge_3 is of dim 1 - dim_max = 1; - } - } else if (const Alpha_shape_3::Vertex_handle * vertex = - CGAL::object_cast(&object_iterator)) { - count_vertices++; - 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; - for (auto the_alpha_shape_vertex : vertex_list) { - Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) { - // alpha shape not found - Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); - } else { - // alpha shape found - Simplex_tree_vertex vertex = the_map_iterator->second; -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - } - } - // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); -#ifdef DEBUG_TRACES - std::cout << "filtration = " << filtr << std::endl; -#endif // DEBUG_TRACES - if (filtr > filtration_max) { - filtration_max = filtr; - } - simplex_tree.insert_simplex(the_simplex_tree, filtr); - if (the_alpha_value_iterator != the_alpha_values.end()) - ++the_alpha_value_iterator; - else - std::cout << "This shall not happen" << std::endl; - } - simplex_tree.set_filtration(filtration_max); - simplex_tree.set_dimension(dim_max); - -#ifdef DEBUG_TRACES - std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; - - - std::cout << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; - std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; - std::cout << " Dimension = " << simplex_tree.dimension() << " "; - std::cout << " filtration = " << simplex_tree.filtration() << std::endl << std::endl; -#endif // DEBUG_TRACES - -#ifdef DEBUG_TRACES - std::cout << "Iterator on vertices: " << std::endl; - for (auto vertex : simplex_tree.complex_vertex_range()) { - std::cout << vertex << " "; - } -#endif // DEBUG_TRACES - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree, true); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - pcoh.output_diagram(); - - return 0; -} diff --git a/src/Persistent_cohomology/example/rips_distance_matrix_persistence.cpp b/src/Persistent_cohomology/example/rips_distance_matrix_persistence.cpp deleted file mode 100644 index 8517e7f6..00000000 --- a/src/Persistent_cohomology/example/rips_distance_matrix_persistence.cpp +++ /dev/null @@ -1,144 +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): Pawel Dlotko, Vincent Rouvreau - * - * Copyright (C) 2016 INRIA - * - * 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 // infinity - -// Types definition -using Simplex_tree = Gudhi::Simplex_tree; -using Filtration_value = Simplex_tree::Filtration_value; -using Rips_complex = Gudhi::rips_complex::Rips_complex; -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -using Distance_matrix = std::vector>; - -void program_options(int argc, char * argv[] - , std::string & csv_matrix_file - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { - std::string csv_matrix_file; - std::string filediag; - Filtration_value threshold; - int dim_max; - int p; - Filtration_value min_persistence; - - program_options(argc, argv, csv_matrix_file, filediag, threshold, dim_max, p, min_persistence); - - Distance_matrix distances = read_lower_triangular_matrix_from_csv_file(csv_matrix_file); - Rips_complex rips_complex_from_file(distances, threshold); - - // Construct the Rips complex in a Simplex Tree - Simplex_tree simplex_tree; - - rips_complex_from_file.create_complex(simplex_tree, dim_max); - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; - std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(p); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (filediag.empty()) { - pcoh.output_diagram(); - } else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); - } - return 0; -} - -void program_options(int argc, char * argv[] - , std::string & csv_matrix_file - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&csv_matrix_file), - "Name of file containing a distance matrix. Can be square or lower triangular matrix. Separator is ';'."); - - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of distance matrix.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp deleted file mode 100644 index d504798b..00000000 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ /dev/null @@ -1,147 +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): Clément Maria - * - * Copyright (C) 2014 INRIA - * - * 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 // infinity - -// Types definition -using Simplex_tree = Gudhi::Simplex_tree; -using Filtration_value = Simplex_tree::Filtration_value; -using Rips_complex = Gudhi::rips_complex::Rips_complex; -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -using Point = std::vector; -using Points_off_reader = Gudhi::Points_off_reader; - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { - std::string off_file_points; - std::string filediag; - Filtration_value threshold; - int dim_max; - int p; - Filtration_value min_persistence; - - program_options(argc, argv, off_file_points, filediag, threshold, dim_max, p, min_persistence); - - Points_off_reader off_reader(off_file_points); - Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); - - // Construct the Rips complex in a Simplex Tree - Simplex_tree simplex_tree; - - rips_complex_from_file.create_complex(simplex_tree, dim_max); - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; - std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(p); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (filediag.empty()) { - pcoh.output_diagram(); - } else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); - } - - return 0; -} - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of an OFF file containing a point set.\n"); - - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} diff --git a/src/Persistent_cohomology/example/weighted_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/weighted_alpha_complex_3d_persistence.cpp index 34b90933..4a2b10f3 100644 --- a/src/Persistent_cohomology/example/weighted_alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/weighted_alpha_complex_3d_persistence.cpp @@ -42,7 +42,7 @@ #include #include -#include "alpha_complex_3d_helper.h" +#include "../utilities/alpha_complex_3d_helper.h" // Traits using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; diff --git a/src/Persistent_cohomology/utilities/CMakeLists.txt b/src/Persistent_cohomology/utilities/CMakeLists.txt new file mode 100644 index 00000000..2c1e50af --- /dev/null +++ b/src/Persistent_cohomology/utilities/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 2.6) +project(Persistent_cohomology_utilities) + +add_executable(rips_distance_matrix_persistence rips_distance_matrix_persistence.cpp) +target_link_libraries(rips_distance_matrix_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) + +add_executable(rips_persistence rips_persistence.cpp) +target_link_libraries(rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) + +if (TBB_FOUND) + target_link_libraries(rips_distance_matrix_persistence ${TBB_LIBRARIES}) + target_link_libraries(rips_persistence ${TBB_LIBRARIES}) +endif() + +add_test(NAME Persistent_cohomology_example_from_rips_distance_matrix COMMAND $ + "${CMAKE_SOURCE_DIR}/data/distance_matrix/full_square_distance_matrix.csv" "-r" "1.0" "-d" "3" "-p" "3" "-m" "0") +add_test(NAME Persistent_cohomology_example_from_rips_on_tore_3D COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "3") + +install(TARGETS rips_distance_matrix_persistence DESTINATION bin) +install(TARGETS rips_persistence DESTINATION bin) + +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}) + + if (TBB_FOUND) + target_link_libraries(alpha_complex_3d_persistence ${TBB_LIBRARIES}) + endif(TBB_FOUND) + add_test(NAME Persistent_cohomology_example_alpha_complex_3d COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") + + install(TARGETS alpha_complex_3d_persistence DESTINATION bin) + + if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) + add_executable (alpha_complex_persistence alpha_complex_persistence.cpp) + target_link_libraries(alpha_complex_persistence + ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) + + add_executable(periodic_alpha_complex_3d_persistence periodic_alpha_complex_3d_persistence.cpp) + target_link_libraries(periodic_alpha_complex_3d_persistence ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY}) + + if (TBB_FOUND) + target_link_libraries(alpha_complex_persistence ${TBB_LIBRARIES}) + target_link_libraries(periodic_alpha_complex_3d_persistence ${TBB_LIBRARIES}) + endif(TBB_FOUND) + add_test(NAME Persistent_cohomology_example_alpha_complex COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "-p" "2" "-m" "0.45") + add_test(NAME Persistent_cohomology_example_periodic_alpha_complex_3d COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off" "${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt" "2" "0") + + install(TARGETS alpha_complex_persistence DESTINATION bin) + install(TARGETS periodic_alpha_complex_3d_persistence DESTINATION bin) + + endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) +endif(CGAL_FOUND) diff --git a/src/Persistent_cohomology/utilities/alpha_complex_3d_helper.h b/src/Persistent_cohomology/utilities/alpha_complex_3d_helper.h new file mode 100644 index 00000000..7865e4ec --- /dev/null +++ b/src/Persistent_cohomology/utilities/alpha_complex_3d_helper.h @@ -0,0 +1,76 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (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 . + */ + +#ifndef ALPHA_COMPLEX_3D_HELPER_H_ +#define ALPHA_COMPLEX_3D_HELPER_H_ + +template +Vertex_list from_cell(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; +} + +template +Vertex_list from_facet(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; +} + +template +Vertex_list from_edge(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; +} + +template +Vertex_list from_vertex(const 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; +} + +#endif // ALPHA_COMPLEX_3D_HELPER_H_ diff --git a/src/Persistent_cohomology/utilities/alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/utilities/alpha_complex_3d_persistence.cpp new file mode 100644 index 00000000..fd227b82 --- /dev/null +++ b/src/Persistent_cohomology/utilities/alpha_complex_3d_persistence.cpp @@ -0,0 +1,243 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA + * + * 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 +#include +#include +#include +#include + +#include "alpha_complex_3d_helper.h" + +// Alpha_shape_3 templates type definitions +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 +using Point_3 = Kernel::Point_3; + +// filtration with alpha values needed type definition +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 +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 << + " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; + exit(-1); +} + +int main(int argc, char * const argv[]) { + // program args management + if (argc != 4) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = atoi(argv[2]); + + Filtration_value min_persistence = 0.0; + 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]); + } + + // Read points from file + std::string offInputFile(argv[1]); + // Read the OFF file (input file name given as parameter) and triangulate points + Gudhi::Points_3D_off_reader off_reader(offInputFile); + // Check the read operation was correct + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file " << offInputFile << std::endl; + usage(argv[0]); + } + + // Retrieve the triangulation + std::vector lp = off_reader.get_point_cloud(); + + // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. + Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); +#ifdef DEBUG_TRACES + std::cout << "Alpha shape computed in GENERAL mode" << std::endl; +#endif // DEBUG_TRACES + + // filtration with alpha values from alpha shape + std::vector the_objects; + std::vector the_alpha_values; + + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); + + as.filtration_with_alpha_values(disp); +#ifdef DEBUG_TRACES + std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; +#endif // DEBUG_TRACES + + Alpha_shape_3::size_type count_vertices = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; + + // Loop on objects vector + Vertex_list vertex_list; + ST simplex_tree; + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; + std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); + int dim_max = 0; + Filtration_value filtration_max = 0.0; + 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(*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(*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(*edge); + count_edges++; + if (dim_max < 1) { + // Edge_3 is of dim 1 + dim_max = 1; + } + } else if (const Vertex_handle * vertex = CGAL::object_cast(&object_iterator)) { + count_vertices++; + 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; + for (auto the_alpha_shape_vertex : vertex_list) { + Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); + if (the_map_iterator == map_cgal_simplex_tree.end()) { + // alpha shape not found + Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { + // alpha shape found + Simplex_tree_vertex vertex = the_map_iterator->second; +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + } + } + // Construction of the simplex_tree + Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); +#ifdef DEBUG_TRACES + std::cout << "filtration = " << filtr << std::endl; +#endif // DEBUG_TRACES + if (filtr > filtration_max) { + filtration_max = filtr; + } + simplex_tree.insert_simplex(the_simplex_tree, filtr); + if (the_alpha_value_iterator != the_alpha_values.end()) + ++the_alpha_value_iterator; + else + std::cout << "This shall not happen" << std::endl; + } + simplex_tree.set_filtration(filtration_max); + simplex_tree.set_dimension(dim_max); + +#ifdef DEBUG_TRACES + std::cout << "vertices \t\t" << count_vertices << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; + + + std::cout << "Information of the Simplex Tree: " << std::endl; + std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; + std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; + std::cout << " Dimension = " << simplex_tree.dimension() << " "; + std::cout << " filtration = " << simplex_tree.filtration() << std::endl << std::endl; +#endif // DEBUG_TRACES + +#ifdef DEBUG_TRACES + std::cout << "Iterator on vertices: " << std::endl; + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; + // Compute the persistence diagram of the complex + PCOH pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + pcoh.output_diagram(); + + return 0; +} diff --git a/src/Persistent_cohomology/utilities/alpha_complex_persistence.cpp b/src/Persistent_cohomology/utilities/alpha_complex_persistence.cpp new file mode 100644 index 00000000..9e84e91f --- /dev/null +++ b/src/Persistent_cohomology/utilities/alpha_complex_persistence.cpp @@ -0,0 +1,125 @@ +#include + +#include + +#include +#include +// to construct a simplex_tree from alpha complex +#include + +#include +#include +#include // for numeric_limits + +using Simplex_tree = Gudhi::Simplex_tree<>; +using Filtration_value = Simplex_tree::Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , std::string & output_file_diag + , Filtration_value & alpha_square_max_value + , int & coeff_field_characteristic + , Filtration_value & min_persistence); + +int main(int argc, char **argv) { + std::string off_file_points; + std::string output_file_diag; + Filtration_value alpha_square_max_value; + int coeff_field_characteristic; + Filtration_value min_persistence; + + program_options(argc, argv, off_file_points, output_file_diag, alpha_square_max_value, + coeff_field_characteristic, min_persistence); + + // ---------------------------------------------------------------------------- + // Init of an alpha complex from an OFF file + // ---------------------------------------------------------------------------- + using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); + + Simplex_tree simplex; + if (alpha_complex_from_file.create_complex(simplex, alpha_square_max_value)) { + // ---------------------------------------------------------------------------- + // Display information about the alpha complex + // ---------------------------------------------------------------------------- + std::cout << "Simplicial complex is of dimension " << simplex.dimension() << + " - " << simplex.num_simplices() << " simplices - " << + simplex.num_vertices() << " vertices." << std::endl; + + // Sort the simplices in the order of the filtration + simplex.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; + // Compute the persistence diagram of the complex + Gudhi::persistent_cohomology::Persistent_cohomology< Simplex_tree, + Gudhi::persistent_cohomology::Field_Zp > pcoh(simplex); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (output_file_diag.empty()) { + pcoh.output_diagram(); + } else { + std::cout << "Result in file: " << output_file_diag << std::endl; + std::ofstream out(output_file_diag); + pcoh.output_diagram(out); + out.close(); + } + } + + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , std::string & output_file_diag + , Filtration_value & alpha_square_max_value + , int & coeff_field_characteristic + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&off_file_points), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("output-file,o", po::value(&output_file_diag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-alpha-square-value,r", + po::value(&alpha_square_max_value)->default_value(std::numeric_limits::infinity()), + "Maximal alpha square value for the Alpha complex construction.") + ("field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of an Alpha complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Persistent_cohomology/utilities/periodic_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/utilities/periodic_alpha_complex_3d_persistence.cpp new file mode 100644 index 00000000..8928cfc2 --- /dev/null +++ b/src/Persistent_cohomology/utilities/periodic_alpha_complex_3d_persistence.cpp @@ -0,0 +1,262 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "alpha_complex_3d_helper.h" + +// Traits +using K = CGAL::Exact_predicates_inexact_constructions_kernel; +using PK = CGAL::Periodic_3_Delaunay_triangulation_traits_3; +// Vertex type +using DsVb = CGAL::Periodic_3_triangulation_ds_vertex_base_3<>; +using Vb = CGAL::Triangulation_vertex_base_3; +using AsVb = CGAL::Alpha_shape_vertex_base_3; +// Cell type +using DsCb = CGAL::Periodic_3_triangulation_ds_cell_base_3<>; +using Cb = CGAL::Triangulation_cell_base_3; +using AsCb = CGAL::Alpha_shape_cell_base_3; +using Tds = CGAL::Triangulation_data_structure_3; +using P3DT3 = CGAL::Periodic_3_Delaunay_triangulation_3; +using Alpha_shape_3 = CGAL::Alpha_shape_3; +using Point_3 = PK::Point_3; + +// filtration with alpha values needed type definition +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 +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 Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< + ST, Gudhi::persistent_cohomology::Field_Zp >; + +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"; + exit(-1); +} + +int main(int argc, char * const argv[]) { + // program args management + if (argc != 5) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = atoi(argv[3]); + Filtration_value min_persistence = strtof(argv[4], nullptr); + + // Read points from file + std::string offInputFile(argv[1]); + // Read the OFF file (input file name given as parameter) and triangulate points + Gudhi::Points_3D_off_reader off_reader(offInputFile); + // Check the read operation was correct + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file " << offInputFile << std::endl; + usage(argv[0]); + } + + // Read iso_cuboid_3 information from file + std::ifstream iso_cuboid_str(argv[2]); + double x_min, y_min, z_min, x_max, y_max, z_max; + if (iso_cuboid_str.good()) { + iso_cuboid_str >> x_min >> y_min >> z_min >> x_max >> y_max >> z_max; + } else { + std::cerr << "Unable to read file " << argv[2] << std::endl; + usage(argv[0]); + } + + // Retrieve the triangulation + std::vector lp = off_reader.get_point_cloud(); + + // Define the periodic cube + P3DT3 pdt(PK::Iso_cuboid_3(x_min, y_min, z_min, x_max, y_max, z_max)); + // Heuristic for inserting large point sets (if pts is reasonably large) + pdt.insert(lp.begin(), lp.end(), true); + // As pdt won't be modified anymore switch to 1-sheeted cover if possible + if (pdt.is_triangulation_in_1_sheet()) pdt.convert_to_1_sheeted_covering(); + std::cout << "Periodic Delaunay computed." << std::endl; + + // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. This is the default mode + // Maybe need to set it to GENERAL mode + Alpha_shape_3 as(pdt, 0, Alpha_shape_3::GENERAL); + + // filtration with alpha values from alpha shape + std::vector the_objects; + std::vector the_alpha_values; + + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); + + as.filtration_with_alpha_values(disp); +#ifdef DEBUG_TRACES + std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; +#endif // DEBUG_TRACES + + Alpha_shape_3::size_type count_vertices = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; + + // Loop on objects vector + Vertex_list vertex_list; + ST simplex_tree; + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; + std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); + int dim_max = 0; + Filtration_value filtration_max = 0.0; + 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(*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(*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(*edge); + count_edges++; + if (dim_max < 1) { + // Edge_3 is of dim 1 + dim_max = 1; + } + } else if (const Alpha_shape_3::Vertex_handle * vertex = + CGAL::object_cast(&object_iterator)) { + count_vertices++; + 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; + for (auto the_alpha_shape_vertex : vertex_list) { + Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); + if (the_map_iterator == map_cgal_simplex_tree.end()) { + // alpha shape not found + Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { + // alpha shape found + Simplex_tree_vertex vertex = the_map_iterator->second; +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + } + } + // Construction of the simplex_tree + Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); +#ifdef DEBUG_TRACES + std::cout << "filtration = " << filtr << std::endl; +#endif // DEBUG_TRACES + if (filtr > filtration_max) { + filtration_max = filtr; + } + simplex_tree.insert_simplex(the_simplex_tree, filtr); + if (the_alpha_value_iterator != the_alpha_values.end()) + ++the_alpha_value_iterator; + else + std::cout << "This shall not happen" << std::endl; + } + simplex_tree.set_filtration(filtration_max); + simplex_tree.set_dimension(dim_max); + +#ifdef DEBUG_TRACES + std::cout << "vertices \t\t" << count_vertices << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; + + + std::cout << "Information of the Simplex Tree: " << std::endl; + std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; + std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; + std::cout << " Dimension = " << simplex_tree.dimension() << " "; + std::cout << " filtration = " << simplex_tree.filtration() << std::endl << std::endl; +#endif // DEBUG_TRACES + +#ifdef DEBUG_TRACES + std::cout << "Iterator on vertices: " << std::endl; + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree, true); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + pcoh.output_diagram(); + + return 0; +} diff --git a/src/Persistent_cohomology/utilities/rips_distance_matrix_persistence.cpp b/src/Persistent_cohomology/utilities/rips_distance_matrix_persistence.cpp new file mode 100644 index 00000000..8517e7f6 --- /dev/null +++ b/src/Persistent_cohomology/utilities/rips_distance_matrix_persistence.cpp @@ -0,0 +1,144 @@ +/* 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): Pawel Dlotko, Vincent Rouvreau + * + * Copyright (C) 2016 INRIA + * + * 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 // infinity + +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Distance_matrix = std::vector>; + +void program_options(int argc, char * argv[] + , std::string & csv_matrix_file + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string csv_matrix_file; + std::string filediag; + Filtration_value threshold; + int dim_max; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, csv_matrix_file, filediag, threshold, dim_max, p, min_persistence); + + Distance_matrix distances = read_lower_triangular_matrix_from_csv_file(csv_matrix_file); + Rips_complex rips_complex_from_file(distances, threshold); + + // Construct the Rips complex in a Simplex Tree + Simplex_tree simplex_tree; + + rips_complex_from_file.create_complex(simplex_tree, dim_max); + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & csv_matrix_file + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&csv_matrix_file), + "Name of file containing a distance matrix. Can be square or lower triangular matrix. Separator is ';'."); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of distance matrix.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Persistent_cohomology/utilities/rips_persistence.cpp b/src/Persistent_cohomology/utilities/rips_persistence.cpp new file mode 100644 index 00000000..d504798b --- /dev/null +++ b/src/Persistent_cohomology/utilities/rips_persistence.cpp @@ -0,0 +1,147 @@ +/* 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): Clément Maria + * + * Copyright (C) 2014 INRIA + * + * 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 // infinity + +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Point = std::vector; +using Points_off_reader = Gudhi::Points_off_reader; + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string off_file_points; + std::string filediag; + Filtration_value threshold; + int dim_max; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, off_file_points, filediag, threshold, dim_max, p, min_persistence); + + Points_off_reader off_reader(off_file_points); + Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); + + // Construct the Rips complex in a Simplex Tree + Simplex_tree simplex_tree; + + rips_complex_from_file.create_complex(simplex_tree, dim_max); + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&off_file_points), + "Name of an OFF file containing a point set.\n"); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt index 1e18d024..83d9127e 100644 --- a/src/Witness_complex/example/CMakeLists.txt +++ b/src/Witness_complex/example/CMakeLists.txt @@ -15,41 +15,27 @@ install(TARGETS Witness_complex_example_nearest_landmark_table DESTINATION bin) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) add_executable( Witness_complex_example_off example_witness_complex_off.cpp ) target_link_libraries(Witness_complex_example_off ${Boost_SYSTEM_LIBRARY}) - add_executable( Witness_complex_example_strong_off example_strong_witness_complex_off.cpp ) - target_link_libraries(Witness_complex_example_strong_off ${Boost_SYSTEM_LIBRARY}) add_executable ( Witness_complex_example_sphere example_witness_complex_sphere.cpp ) target_link_libraries(Witness_complex_example_sphere ${Boost_SYSTEM_LIBRARY}) add_executable ( Witness_complex_example_witness_persistence example_witness_complex_persistence.cpp ) target_link_libraries(Witness_complex_example_witness_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - add_executable ( Witness_complex_example_strong_witness_persistence example_strong_witness_persistence.cpp ) - target_link_libraries(Witness_complex_example_strong_witness_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - if (TBB_FOUND) target_link_libraries(Witness_complex_example_witness_persistence ${TBB_LIBRARIES}) - target_link_libraries(Witness_complex_example_strong_witness_persistence ${TBB_LIBRARIES}) endif() add_test(NAME Witness_complex_example_off_test_torus COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "20" "1.0" "3") - add_test(NAME Witness_complex_example_strong_off_test_torus - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "20" "1.0" "3") add_test(NAME Witness_complex_example_test_sphere_10 COMMAND $ "10") add_test(NAME Witness_complex_example_test_torus_persistence COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-l" "20" "-a" "0.5") - add_test(NAME Witness_complex_example_strong_test_torus_persistence - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-l" "20" "-a" "0.5") install(TARGETS Witness_complex_example_off DESTINATION bin) - install(TARGETS Witness_complex_example_strong_off DESTINATION bin) install(TARGETS Witness_complex_example_sphere DESTINATION bin) install(TARGETS Witness_complex_example_witness_persistence DESTINATION bin) - install(TARGETS Witness_complex_example_strong_witness_persistence DESTINATION bin) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) diff --git a/src/Witness_complex/example/example_strong_witness_complex_off.cpp b/src/Witness_complex/example/example_strong_witness_complex_off.cpp deleted file mode 100644 index 0ee9ee90..00000000 --- a/src/Witness_complex/example/example_strong_witness_complex_off.cpp +++ /dev/null @@ -1,79 +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 (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 - -using K = CGAL::Epick_d; -using Point_d = typename K::Point_d; -using Witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; -using Point_vector = std::vector; - -int main(int argc, char * const argv[]) { - if (argc != 5) { - std::cerr << "Usage: " << argv[0] - << " path_to_point_file number_of_landmarks max_squared_alpha limit_dimension\n"; - return 0; - } - - std::string file_name = argv[1]; - int nbL = atoi(argv[2]), lim_dim = atoi(argv[4]); - double alpha2 = atof(argv[3]); - clock_t start, end; - 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 << "Strong 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, - point_vector); - - witness_complex.create_complex(simplex_tree, alpha2, lim_dim); - end = clock(); - std::cout << "Strong 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_strong_witness_persistence.cpp b/src/Witness_complex/example/example_strong_witness_persistence.cpp deleted file mode 100644 index f786fe7b..00000000 --- a/src/Witness_complex/example/example_strong_witness_persistence.cpp +++ /dev/null @@ -1,171 +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 (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 // infinity - -using K = CGAL::Epick_d; -using Point_d = K::Point_d; - -using Point_vector = std::vector; -using Strong_witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; -using SimplexTree = Gudhi::Simplex_tree<>; - -using Filtration_value = SimplexTree::Filtration_value; - -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; - -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { - std::string file_name; - std::string filediag; - Filtration_value max_squared_alpha; - int p, nbL, lim_d; - Filtration_value min_persistence; - SimplexTree simplex_tree; - - program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, lim_d, min_persistence); - - // Extract the points from the file file_name - Point_vector witnesses, 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); // ----- >> - } - witnesses = Point_vector(off_reader.get_point_cloud()); - std::cout << "Successfully read " << witnesses.size() << " points.\n"; - std::cout << "Ambient dimension is " << witnesses[0].dimension() << ".\n"; - - // Choose landmarks from witnesses - Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); - - // Compute witness complex - Strong_witness_complex strong_witness_complex(landmarks, - witnesses); - - strong_witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); - - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; - std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(p); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (filediag.empty()) { - pcoh.output_diagram(); - } else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); - } - - return 0; -} - -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&file_name), - "Name of file containing a point set in off format."); - - po::options_description visible("Allowed options", 100); - Filtration_value default_alpha = std::numeric_limits::infinity(); - visible.add_options() - ("help,h", "produce help message") - ("landmarks,l", po::value(&nbL), - "Number of landmarks to choose from the point cloud.") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), - "Maximal squared relaxation parameter.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence)->default_value(0), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") - ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), - "Maximal dimension of the strong witness complex we want to compute."); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - po::variables_map vm; - - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Strong witness complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} - diff --git a/src/Witness_complex/utilities/CMakeLists.txt b/src/Witness_complex/utilities/CMakeLists.txt new file mode 100644 index 00000000..67cc69e9 --- /dev/null +++ b/src/Witness_complex/utilities/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 2.6) +project(Witness_complex_utilities) + +# CGAL and Eigen3 are required for Euclidean version of Witness +if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) + add_executable( Witness_complex_example_strong_off example_strong_witness_complex_off.cpp ) + target_link_libraries(Witness_complex_example_strong_off ${Boost_SYSTEM_LIBRARY}) + + add_executable ( Witness_complex_example_strong_witness_persistence example_strong_witness_persistence.cpp ) + target_link_libraries(Witness_complex_example_strong_witness_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) + + if (TBB_FOUND) + target_link_libraries(Witness_complex_example_strong_witness_persistence ${TBB_LIBRARIES}) + endif() + + add_test(NAME Witness_complex_example_strong_off_test_torus + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "20" "1.0" "3") + add_test(NAME Witness_complex_example_strong_test_torus_persistence + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-l" "20" "-a" "0.5") + + install(TARGETS Witness_complex_example_strong_off DESTINATION bin) + install(TARGETS Witness_complex_example_strong_witness_persistence DESTINATION bin) + +endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) diff --git a/src/Witness_complex/utilities/example_strong_witness_complex_off.cpp b/src/Witness_complex/utilities/example_strong_witness_complex_off.cpp new file mode 100644 index 00000000..0ee9ee90 --- /dev/null +++ b/src/Witness_complex/utilities/example_strong_witness_complex_off.cpp @@ -0,0 +1,79 @@ +/* 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 (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 + +using K = CGAL::Epick_d; +using Point_d = typename K::Point_d; +using Witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; +using Point_vector = std::vector; + +int main(int argc, char * const argv[]) { + if (argc != 5) { + std::cerr << "Usage: " << argv[0] + << " path_to_point_file number_of_landmarks max_squared_alpha limit_dimension\n"; + return 0; + } + + std::string file_name = argv[1]; + int nbL = atoi(argv[2]), lim_dim = atoi(argv[4]); + double alpha2 = atof(argv[3]); + clock_t start, end; + 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 << "Strong 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, + point_vector); + + witness_complex.create_complex(simplex_tree, alpha2, lim_dim); + end = clock(); + std::cout << "Strong 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/utilities/example_strong_witness_persistence.cpp b/src/Witness_complex/utilities/example_strong_witness_persistence.cpp new file mode 100644 index 00000000..f786fe7b --- /dev/null +++ b/src/Witness_complex/utilities/example_strong_witness_persistence.cpp @@ -0,0 +1,171 @@ +/* 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 (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 // infinity + +using K = CGAL::Epick_d; +using Point_d = K::Point_d; + +using Point_vector = std::vector; +using Strong_witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; +using SimplexTree = Gudhi::Simplex_tree<>; + +using Filtration_value = SimplexTree::Filtration_value; + +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , int & dim_max + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string file_name; + std::string filediag; + Filtration_value max_squared_alpha; + int p, nbL, lim_d; + Filtration_value min_persistence; + SimplexTree simplex_tree; + + program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, lim_d, min_persistence); + + // Extract the points from the file file_name + Point_vector witnesses, 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); // ----- >> + } + witnesses = Point_vector(off_reader.get_point_cloud()); + std::cout << "Successfully read " << witnesses.size() << " points.\n"; + std::cout << "Ambient dimension is " << witnesses[0].dimension() << ".\n"; + + // Choose landmarks from witnesses + Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); + + // Compute witness complex + Strong_witness_complex strong_witness_complex(landmarks, + witnesses); + + strong_witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); + + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + + return 0; +} + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , int & dim_max + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&file_name), + "Name of file containing a point set in off format."); + + po::options_description visible("Allowed options", 100); + Filtration_value default_alpha = std::numeric_limits::infinity(); + visible.add_options() + ("help,h", "produce help message") + ("landmarks,l", po::value(&nbL), + "Number of landmarks to choose from the point cloud.") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), + "Maximal squared relaxation parameter.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence)->default_value(0), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") + ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), + "Maximal dimension of the strong witness complex we want to compute."); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + po::variables_map vm; + + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Strong witness complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} + -- cgit v1.2.3 From 3f6290ba33cedec91ca69866d1be33bb4887e31f Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 31 May 2017 17:25:00 +0000 Subject: Mention utilities git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2495 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 40a98c7df253c4938fdadfb8b6ec59174c9f1f4f --- src/common/doc/main_page.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index bd4615f5..6ff3f94d 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -269,7 +269,7 @@ make doxygen * Having CGAL version 4.4.0 or higher installed is recommended. The procedure to install this library according to * your operating system is detailed here http://doc.cgal.org/latest/Manual/installation.html * - * The following examples require the Computational Geometry Algorithms + * The following examples/utilities require the Computational Geometry Algorithms * Library (CGAL \cite cgal:eb-15b) and will not be built if CGAL is not installed: * \li * Persistent_cohomology/alpha_complex_3d_persistence.cpp @@ -343,7 +343,7 @@ make doxygen * * Having Intel® TBB installed is recommended to parallelize and accelerate some GUDHI computations. * - * The following examples are using Intel® TBB if installed: + * The following examples/utilities are using Intel® TBB if installed: * \li * Alpha_complex/Alpha_complex_from_off.cpp * \li -- cgit v1.2.3 From 0a66874247cb6ab10a2d96e22ecd5009113291d2 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 1 Jun 2017 08:42:39 +0000 Subject: Split and fix README file git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2496 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 0eecb1e37fd208522de15369ac8cf4c960c214c5 --- src/Persistent_cohomology/example/README | 121 +++-------------------------- src/Persistent_cohomology/utilities/README | 114 +++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 110 deletions(-) create mode 100644 src/Persistent_cohomology/utilities/README diff --git a/src/Persistent_cohomology/example/README b/src/Persistent_cohomology/example/README index 794b94ae..f39d9584 100644 --- a/src/Persistent_cohomology/example/README +++ b/src/Persistent_cohomology/example/README @@ -1,43 +1,14 @@ -To build the example, run in a Terminal: +To build the examples, run in a Terminal: -cd /path-to-example/ +cd /path-to-examples/ cmake . make *********************************************************************************************************************** Example of use of RIPS: -Computation of the persistent homology with Z/2Z coefficients of the Rips complex on points -sampling a Klein bottle: - -./rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 2 - -output: -2 0 0 inf -2 1 0.0983494 inf -2 1 0.104347 inf -2 2 0.138335 inf - - -Every line is of this format: p1*...*pr dim b d -where - p1*...*pr is the product of prime numbers pi such that the homology feature exists in homology with Z/piZ coefficients. - dim is the dimension of the homological feature, - b and d are respectively the birth and death of the feature and - - - -with Z/3Z coefficients: - -./rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 3 - -output: -3 0 0 inf -3 1 0.0983494 inf -3 1 0.104347 inf -3 2 0.138335 inf - -and the computation with Z/2Z and Z/3Z coefficients simultaneously: +Computation of the persistent homology with Z/2Z and Z/3Z coefficients simultaneously of the Rips complex +on points sampling a 3D torus: ./rips_multifield_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.12 -d 3 -p 2 -q 3 @@ -53,7 +24,13 @@ output: 6 0 0 0.12047 6 0 0 0.120414 -and finally the computation with all Z/pZ for 2 <= p <= 71 (20 first prime numbers): +Every line is of this format: p1*...*pr dim b d +where + p1*...*pr is the product of prime numbers pi such that the homology feature exists in homology with Z/piZ coefficients. + dim is the dimension of the homological feature, + b and d are respectively the birth and death of the feature and + +and the computation with all Z/pZ for 2 <= p <= 71 (20 first prime numbers): ./rips_multifield_persistence ../../data/points/Kl.off -r 0.25 -m 0.5 -d 3 -p 2 -q 71 @@ -69,82 +46,6 @@ output: 557940830126698960967415390 0 0 0.12047 557940830126698960967415390 0 0 0.120414 -*********************************************************************************************************************** -Example of use of ALPHA: - -For a more verbose mode, please run cmake with option "DEBUG_TRACES=TRUE" and recompile the programs. - -1) 3D special case ------------------- -Computation of the persistent homology with Z/2Z coefficients of the alpha complex on points -sampling a torus 3D: - -./alpha_complex_3d_persistence ../../data/points/tore3D_300.off 2 0.45 - -output: -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 - -Here we retrieve expected Betti numbers on a tore 3D: -Betti numbers[0] = 1 -Betti numbers[1] = 2 -Betti numbers[2] = 1 - -N.B.: - alpha_complex_3d_persistence accepts only OFF files in 3D dimension. - - filtration values are alpha square values - -2) d-Dimension case -------------------- -Computation of the persistent homology with Z/2Z coefficients of the alpha complex on points -sampling a torus 3D: - -./alpha_complex_persistence -r 32 -p 2 -m 0.45 ../../data/points/tore3D_300.off - -output: -Alpha complex is of dimension 3 - 9273 simplices - 300 vertices. -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 - -Here we retrieve expected Betti numbers on a tore 3D: -Betti numbers[0] = 1 -Betti numbers[1] = 2 -Betti numbers[2] = 1 - -N.B.: - alpha_complex_persistence accepts OFF files in d-Dimension. - - filtration values are alpha square values - -3) 3D periodic special case ---------------------------- -./periodic_alpha_complex_3d_persistence ../../data/points/grid_10_10_10_in_0_1.off ../../data/points/iso_cuboid_3_in_0_1.txt 3 1.0 - -output: -Periodic Delaunay computed. -Simplex_tree dim: 3 -3 0 0 inf -3 1 0.0025 inf -3 1 0.0025 inf -3 1 0.0025 inf -3 2 0.005 inf -3 2 0.005 inf -3 2 0.005 inf -3 3 0.0075 inf - -Here we retrieve expected Betti numbers on a tore 3D: -Betti numbers[0] = 1 -Betti numbers[1] = 3 -Betti numbers[2] = 3 -Betti numbers[3] = 1 - -N.B.: - periodic_alpha_complex_3d_persistence accepts only OFF files in 3D dimension. In this example, the periodic cube -is hard coded to { x = [0,1]; y = [0,1]; z = [0,1] } - - filtration values are alpha square values - *********************************************************************************************************************** Example of use of PLAIN HOMOLOGY: diff --git a/src/Persistent_cohomology/utilities/README b/src/Persistent_cohomology/utilities/README new file mode 100644 index 00000000..76e960da --- /dev/null +++ b/src/Persistent_cohomology/utilities/README @@ -0,0 +1,114 @@ +To build the utilities, run in a Terminal: + +cd /path-to-utilities/ +cmake . +make + +*********************************************************************************************************************** +Example of use of RIPS: + +Computation of the persistent homology with Z/2Z coefficients of the Rips complex on points +sampling a 3D torus: + +./rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 2 + +output: +2 0 0 inf +2 1 0.0983494 inf +2 1 0.104347 inf +2 2 0.138335 inf + + +Every line is of this format: p1*...*pr dim b d +where + p1*...*pr is the product of prime numbers pi such that the homology feature exists in homology with Z/piZ coefficients. + dim is the dimension of the homological feature, + b and d are respectively the birth and death of the feature and + + + +with Z/3Z coefficients: + +./rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 3 + +output: +3 0 0 inf +3 1 0.0983494 inf +3 1 0.104347 inf +3 2 0.138335 inf + +*********************************************************************************************************************** +Example of use of ALPHA: + +For a more verbose mode, please run cmake with option "DEBUG_TRACES=TRUE" and recompile the programs. + +1) 3D special case +------------------ +Computation of the persistent homology with Z/2Z coefficients of the alpha complex on points +sampling a torus 3D: + +./alpha_complex_3d_persistence ../../data/points/tore3D_300.off 2 0.45 + +output: +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 + +Here we retrieve expected Betti numbers on a tore 3D: +Betti numbers[0] = 1 +Betti numbers[1] = 2 +Betti numbers[2] = 1 + +N.B.: - alpha_complex_3d_persistence accepts only OFF files in 3D dimension. + - filtration values are alpha square values + +2) d-Dimension case +------------------- +Computation of the persistent homology with Z/2Z coefficients of the alpha complex on points +sampling a torus 3D: + +./alpha_complex_persistence -r 32 -p 2 -m 0.45 ../../data/points/tore3D_300.off + +output: +Alpha complex is of dimension 3 - 9273 simplices - 300 vertices. +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 + +Here we retrieve expected Betti numbers on a tore 3D: +Betti numbers[0] = 1 +Betti numbers[1] = 2 +Betti numbers[2] = 1 + +N.B.: - alpha_complex_persistence accepts OFF files in d-Dimension. + - filtration values are alpha square values + +3) 3D periodic special case +--------------------------- +./periodic_alpha_complex_3d_persistence ../../data/points/grid_10_10_10_in_0_1.off ../../data/points/iso_cuboid_3_in_0_1.txt 3 1.0 + +output: +Periodic Delaunay computed. +Simplex_tree dim: 3 +3 0 0 inf +3 1 0.0025 inf +3 1 0.0025 inf +3 1 0.0025 inf +3 2 0.005 inf +3 2 0.005 inf +3 2 0.005 inf +3 3 0.0075 inf + +Here we retrieve expected Betti numbers on a tore 3D: +Betti numbers[0] = 1 +Betti numbers[1] = 3 +Betti numbers[2] = 3 +Betti numbers[3] = 1 + +N.B.: - periodic_alpha_complex_3d_persistence accepts only OFF files in 3D dimension. In this example, the periodic cube +is hard coded to { x = [0,1]; y = [0,1]; z = [0,1] } + - filtration values are alpha square values -- cgit v1.2.3 From 73efba37dfcab3f9b8589cb3b0b80f6d7dd7bd0b Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 4 Oct 2017 10:24:04 +0000 Subject: Document utilies in README files using Markdown + move/rename some utilities Only missing doc for now: Garland_heckbert git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2752 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7ba0113762b6622130835dc9e372acfae29c2db8 --- src/Alpha_complex/utilities/CMakeLists.txt | 37 +++ src/Alpha_complex/utilities/README | 131 ++++++++++ .../utilities/alpha_complex_3d_helper.h | 76 ++++++ .../utilities/alpha_complex_3d_persistence.cpp | 242 +++++++++++++++++++ .../utilities/alpha_complex_persistence.cpp | 125 ++++++++++ .../periodic_alpha_complex_3d_persistence.cpp | 268 +++++++++++++++++++++ .../utilities/Bitmap_cubical_complex.cpp | 4 +- ...ubical_complex_periodic_boundary_conditions.cpp | 4 +- src/Bitmap_cubical_complex/utilities/README | 24 ++ src/Bottleneck_distance/utilities/README | 19 ++ src/Persistent_cohomology/utilities/CMakeLists.txt | 33 --- src/Persistent_cohomology/utilities/README | 150 ++++-------- .../utilities/alpha_complex_3d_helper.h | 76 ------ .../utilities/alpha_complex_3d_persistence.cpp | 242 ------------------- .../utilities/alpha_complex_persistence.cpp | 125 ---------- .../periodic_alpha_complex_3d_persistence.cpp | 268 --------------------- src/Witness_complex/example/CMakeLists.txt | 21 +- .../example/example_strong_witness_complex_off.cpp | 79 ++++++ .../example_witness_complex_persistence.cpp | 171 ------------- src/Witness_complex/utilities/CMakeLists.txt | 26 +- src/Witness_complex/utilities/README | 72 ++++++ .../example_strong_witness_complex_off.cpp | 79 ------ .../example_strong_witness_persistence.cpp | 171 ------------- .../utilities/strong_witness_persistence.cpp | 171 +++++++++++++ .../utilities/weak_witness_persistence.cpp | 171 +++++++++++++ src/common/utilities/README | 26 +- 26 files changed, 1506 insertions(+), 1305 deletions(-) create mode 100644 src/Alpha_complex/utilities/CMakeLists.txt create mode 100644 src/Alpha_complex/utilities/README create mode 100644 src/Alpha_complex/utilities/alpha_complex_3d_helper.h create mode 100644 src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp create mode 100644 src/Alpha_complex/utilities/alpha_complex_persistence.cpp create mode 100644 src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp create mode 100644 src/Bitmap_cubical_complex/utilities/README create mode 100644 src/Bottleneck_distance/utilities/README delete mode 100644 src/Persistent_cohomology/utilities/alpha_complex_3d_helper.h delete mode 100644 src/Persistent_cohomology/utilities/alpha_complex_3d_persistence.cpp delete mode 100644 src/Persistent_cohomology/utilities/alpha_complex_persistence.cpp delete mode 100644 src/Persistent_cohomology/utilities/periodic_alpha_complex_3d_persistence.cpp create mode 100644 src/Witness_complex/example/example_strong_witness_complex_off.cpp delete mode 100644 src/Witness_complex/example/example_witness_complex_persistence.cpp create mode 100644 src/Witness_complex/utilities/README delete mode 100644 src/Witness_complex/utilities/example_strong_witness_complex_off.cpp delete mode 100644 src/Witness_complex/utilities/example_strong_witness_persistence.cpp create mode 100644 src/Witness_complex/utilities/strong_witness_persistence.cpp create mode 100644 src/Witness_complex/utilities/weak_witness_persistence.cpp diff --git a/src/Alpha_complex/utilities/CMakeLists.txt b/src/Alpha_complex/utilities/CMakeLists.txt new file mode 100644 index 00000000..69dbc28a --- /dev/null +++ b/src/Alpha_complex/utilities/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 2.6) +project(Alpha_complex_utilities) + +if(CGAL_FOUND) + add_executable(alpha_complex_3d_persistence alpha_complex_3d_persistence.cpp) + target_link_libraries(alpha_complex_3d_persistence ${CGAL_LIBRARY}) + + if (TBB_FOUND) + target_link_libraries(alpha_complex_3d_persistence ${TBB_LIBRARIES}) + endif(TBB_FOUND) + add_test(NAME Alpha_complex_utilities_alpha_complex_3d_persistence COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") + + install(TARGETS alpha_complex_3d_persistence DESTINATION bin) + + if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) + add_executable (alpha_complex_persistence alpha_complex_persistence.cpp) + target_link_libraries(alpha_complex_persistence + ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) + + add_executable(periodic_alpha_complex_3d_persistence periodic_alpha_complex_3d_persistence.cpp) + target_link_libraries(periodic_alpha_complex_3d_persistence ${CGAL_LIBRARY}) + + if (TBB_FOUND) + target_link_libraries(alpha_complex_persistence ${TBB_LIBRARIES}) + target_link_libraries(periodic_alpha_complex_3d_persistence ${TBB_LIBRARIES}) + endif(TBB_FOUND) + add_test(NAME Alpha_complex_utilities_alpha_complex_persistence COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "-p" "2" "-m" "0.45") + add_test(NAME Alpha_complex_utilities_periodic_alpha_complex_3d_persistence COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off" "${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt" "2" "0") + + install(TARGETS alpha_complex_persistence DESTINATION bin) + install(TARGETS periodic_alpha_complex_3d_persistence DESTINATION bin) + + endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) +endif(CGAL_FOUND) diff --git a/src/Alpha_complex/utilities/README b/src/Alpha_complex/utilities/README new file mode 100644 index 00000000..30e1b187 --- /dev/null +++ b/src/Alpha_complex/utilities/README @@ -0,0 +1,131 @@ +# Alpha_complex # + +## `alpha_complex_3d_persistence` ## +This program computes the persistent homology with coefficient field Z/pZ of the 3D alpha complex built from a 3D point cloud. The output diagram contains one bar per line, written with the convention: + +`p dim b d` + +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers *pi* such that the homology feature exists in homology with *Z/piZ* coefficients). + +**Usage** +`alpha_complex_3d_persistence

` +where +`` is the path to the input point cloud in OFF format. +`

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. +`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. It must be a floating-point number >= -1. + +**Example** +`alpha_complex_3d_persistence ../../data/points/tore3D_300.off 2 0.45` + +outputs: +``` +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 +``` + +Here we retrieve expected Betti numbers on a tore 3D: +``` +Betti numbers[0] = 1 +Betti numbers[1] = 2 +Betti numbers[2] = 1 +``` + +N.B.: +* `alpha_complex_3d_persistence` only accepts OFF files in dimension 3. +* Filtration values are alpha square values. + + + + +## `periodic_alpha_complex_3d_persistence` ## +This program computes the persistent homology with coefficient field Z/pZ of the 3D periodic alpha complex built from a 3D point cloud. The output diagram contains one bar per line, written with the convention: + +`p dim b d` + +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers *pi* such that the homology feature exists in homology with *Z/piZ* coefficients). + +**Usage** +`periodic_alpha_complex_3d_persistence

` +where +`` is the path to the input point cloud in OFF format. +`

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. +`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. It must be a floating-point number >= -1. + +**Example** +`periodic_alpha_complex_3d_persistence ../../data/points/grid_10_10_10_in_0_1.off ../../data/points/iso_cuboid_3_in_0_1.txt 3 1.0` + +outputs: +``` +Periodic Delaunay computed. +Simplex_tree dim: 3 +3 0 0 inf +3 1 0.0025 inf +3 1 0.0025 inf +3 1 0.0025 inf +3 2 0.005 inf +3 2 0.005 inf +3 2 0.005 inf +3 3 0.0075 inf +``` + +Here we retrieve expected Betti numbers on an 3D iso-oriented cuboids: +``` +Betti numbers[0] = 1 +Betti numbers[1] = 3 +Betti numbers[2] = 3 +Betti numbers[3] = 1 +``` + +N.B.: +* `periodic_alpha_complex_3d_persistence` only accepts OFF files in dimension 3. +* In this example, the periodic cube is hard coded to { x = [0,1]; y = [0,1]; z = [0,1] } +* Filtration values are alpha square values. + + + + + +## `alpha_complex_persistence` ## +This program computes the persistent homology with coefficient field Z/pZ of the dD alpha complex built from a dD point cloud. The output diagram contains one bar per line, written with the convention: + +`p dim b d` + +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers pi such that the homology feature exists in homology with Z/piZ coefficients). + +**Usage** +`alpha_complex_persistence [options] ` + +**Allowed options** + +* `-h [ --help ]` Produce help message +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. By default, print in std::cout. +* `-r [ --max-alpha-square-value ]` (default = inf) Maximal alpha square value for the Alpha complex construction. +* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. + +**Example** +`alpha_complex_persistence -r 32 -p 2 -m 0.45 ../../data/points/tore3D_300.off` + +outputs: +``` +Alpha complex is of dimension 3 - 9273 simplices - 300 vertices. +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 +``` + +Here we retrieve expected Betti numbers on a tore 3D: +``` +Betti numbers[0] = 1 +Betti numbers[1] = 2 +Betti numbers[2] = 1 +``` + +N.B.: +* `alpha_complex_persistence` only accepts OFF files in dimension d. +* Filtration values are alpha square values. diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_helper.h b/src/Alpha_complex/utilities/alpha_complex_3d_helper.h new file mode 100644 index 00000000..7865e4ec --- /dev/null +++ b/src/Alpha_complex/utilities/alpha_complex_3d_helper.h @@ -0,0 +1,76 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (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 . + */ + +#ifndef ALPHA_COMPLEX_3D_HELPER_H_ +#define ALPHA_COMPLEX_3D_HELPER_H_ + +template +Vertex_list from_cell(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; +} + +template +Vertex_list from_facet(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; +} + +template +Vertex_list from_edge(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; +} + +template +Vertex_list from_vertex(const 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; +} + +#endif // ALPHA_COMPLEX_3D_HELPER_H_ diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp new file mode 100644 index 00000000..f63ff0f6 --- /dev/null +++ b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp @@ -0,0 +1,242 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA + * + * 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 +#include +#include +#include +#include + +#include "alpha_complex_3d_helper.h" + +// Alpha_shape_3 templates type definitions +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 +using Point_3 = Kernel::Point_3; + +// filtration with alpha values needed type definition +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 +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:\n" << progName << " path_to_OFF_file coeff_field_characteristic[integer " << + "> 0] min_persistence[float >= -1.0]\n"; + std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; + exit(-1); +} + +int main(int argc, char * const argv[]) { + // program args management + if (argc != 4) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = atoi(argv[2]); + + Filtration_value min_persistence = 0.0; + 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]); + } + + // Read points from file + std::string offInputFile(argv[1]); + // Read the OFF file (input file name given as parameter) and triangulate points + Gudhi::Points_3D_off_reader off_reader(offInputFile); + // Check the read operation was correct + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file " << offInputFile << std::endl; + usage(argv[0]); + } + + // Retrieve the triangulation + std::vector lp = off_reader.get_point_cloud(); + + // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. + Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); +#ifdef DEBUG_TRACES + std::cout << "Alpha shape computed in GENERAL mode" << std::endl; +#endif // DEBUG_TRACES + + // filtration with alpha values from alpha shape + std::vector the_objects; + std::vector the_alpha_values; + + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); + + as.filtration_with_alpha_values(disp); +#ifdef DEBUG_TRACES + std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; +#endif // DEBUG_TRACES + + Alpha_shape_3::size_type count_vertices = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; + + // Loop on objects vector + Vertex_list vertex_list; + ST simplex_tree; + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; + std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); + int dim_max = 0; + Filtration_value filtration_max = 0.0; + 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(*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(*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(*edge); + count_edges++; + if (dim_max < 1) { + // Edge_3 is of dim 1 + dim_max = 1; + } + } else if (const Vertex_handle * vertex = CGAL::object_cast(&object_iterator)) { + count_vertices++; + 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; + for (auto the_alpha_shape_vertex : vertex_list) { + Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); + if (the_map_iterator == map_cgal_simplex_tree.end()) { + // alpha shape not found + Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { + // alpha shape found + Simplex_tree_vertex vertex = the_map_iterator->second; +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + } + } + // Construction of the simplex_tree + Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); +#ifdef DEBUG_TRACES + std::cout << "filtration = " << filtr << std::endl; +#endif // DEBUG_TRACES + if (filtr > filtration_max) { + filtration_max = filtr; + } + simplex_tree.insert_simplex(the_simplex_tree, filtr); + if (the_alpha_value_iterator != the_alpha_values.end()) + ++the_alpha_value_iterator; + else + std::cout << "This shall not happen" << std::endl; + } + simplex_tree.set_dimension(dim_max); + +#ifdef DEBUG_TRACES + std::cout << "vertices \t\t" << count_vertices << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; + + + std::cout << "Information of the Simplex Tree: " << std::endl; + std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; + std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; + std::cout << " Dimension = " << simplex_tree.dimension() << " "; +#endif // DEBUG_TRACES + +#ifdef DEBUG_TRACES + std::cout << "Iterator on vertices: " << std::endl; + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; + // Compute the persistence diagram of the complex + PCOH pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + pcoh.output_diagram(); + + return 0; +} diff --git a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp new file mode 100644 index 00000000..9e84e91f --- /dev/null +++ b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp @@ -0,0 +1,125 @@ +#include + +#include + +#include +#include +// to construct a simplex_tree from alpha complex +#include + +#include +#include +#include // for numeric_limits + +using Simplex_tree = Gudhi::Simplex_tree<>; +using Filtration_value = Simplex_tree::Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , std::string & output_file_diag + , Filtration_value & alpha_square_max_value + , int & coeff_field_characteristic + , Filtration_value & min_persistence); + +int main(int argc, char **argv) { + std::string off_file_points; + std::string output_file_diag; + Filtration_value alpha_square_max_value; + int coeff_field_characteristic; + Filtration_value min_persistence; + + program_options(argc, argv, off_file_points, output_file_diag, alpha_square_max_value, + coeff_field_characteristic, min_persistence); + + // ---------------------------------------------------------------------------- + // Init of an alpha complex from an OFF file + // ---------------------------------------------------------------------------- + using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; + Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); + + Simplex_tree simplex; + if (alpha_complex_from_file.create_complex(simplex, alpha_square_max_value)) { + // ---------------------------------------------------------------------------- + // Display information about the alpha complex + // ---------------------------------------------------------------------------- + std::cout << "Simplicial complex is of dimension " << simplex.dimension() << + " - " << simplex.num_simplices() << " simplices - " << + simplex.num_vertices() << " vertices." << std::endl; + + // Sort the simplices in the order of the filtration + simplex.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; + // Compute the persistence diagram of the complex + Gudhi::persistent_cohomology::Persistent_cohomology< Simplex_tree, + Gudhi::persistent_cohomology::Field_Zp > pcoh(simplex); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (output_file_diag.empty()) { + pcoh.output_diagram(); + } else { + std::cout << "Result in file: " << output_file_diag << std::endl; + std::ofstream out(output_file_diag); + pcoh.output_diagram(out); + out.close(); + } + } + + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , std::string & output_file_diag + , Filtration_value & alpha_square_max_value + , int & coeff_field_characteristic + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&off_file_points), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("output-file,o", po::value(&output_file_diag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-alpha-square-value,r", + po::value(&alpha_square_max_value)->default_value(std::numeric_limits::infinity()), + "Maximal alpha square value for the Alpha complex construction.") + ("field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of an Alpha complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp new file mode 100644 index 00000000..8140a3c5 --- /dev/null +++ b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp @@ -0,0 +1,268 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "alpha_complex_3d_helper.h" + +// Traits +using K = CGAL::Exact_predicates_inexact_constructions_kernel; +using PK = CGAL::Periodic_3_Delaunay_triangulation_traits_3; +// Vertex type +using DsVb = CGAL::Periodic_3_triangulation_ds_vertex_base_3<>; +using Vb = CGAL::Triangulation_vertex_base_3; +using AsVb = CGAL::Alpha_shape_vertex_base_3; +// Cell type +using DsCb = CGAL::Periodic_3_triangulation_ds_cell_base_3<>; +using Cb = CGAL::Triangulation_cell_base_3; +using AsCb = CGAL::Alpha_shape_cell_base_3; +using Tds = CGAL::Triangulation_data_structure_3; +using P3DT3 = CGAL::Periodic_3_Delaunay_triangulation_3; +using Alpha_shape_3 = CGAL::Alpha_shape_3; +using Point_3 = PK::Point_3; + +// filtration with alpha values needed type definition +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 +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 Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< + ST, Gudhi::persistent_cohomology::Field_Zp >; + +void usage(char * const progName) { + std::cerr << "Usage:\n" << progName << " path_to_OFF_file path_to_iso_cuboid_3_file coeff_field_characteristic[" << + "integer > 0] min_persistence[float >= -1.0]\n" << + " path_to_OFF_file is the path to your points cloud in OFF format.\n" << + " path_to_iso_cuboid_3_file is the path to the iso cuboid file with the following format :\n" << + " x_min y_min z_min x_max y_max z_max\n" << + " In this example, the periodic cube will be " << + "{ x = [x_min,x_max]; y = [y_min,y_max]; z = [z_min,z_max] }.\n" << + " For more information, please refer to\n" << + " https://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Iso__cuboid__3.html\n"; + + exit(-1); +} + +int main(int argc, char * const argv[]) { + // program args management + if (argc != 5) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = atoi(argv[3]); + Filtration_value min_persistence = strtof(argv[4], nullptr); + + // Read points from file + std::string offInputFile(argv[1]); + // Read the OFF file (input file name given as parameter) and triangulate points + Gudhi::Points_3D_off_reader off_reader(offInputFile); + // Check the read operation was correct + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file " << offInputFile << std::endl; + usage(argv[0]); + } + + // Read iso_cuboid_3 information from file + std::ifstream iso_cuboid_str(argv[2]); + double x_min, y_min, z_min, x_max, y_max, z_max; + if (iso_cuboid_str.good()) { + iso_cuboid_str >> x_min >> y_min >> z_min >> x_max >> y_max >> z_max; + } else { + std::cerr << "Unable to read file " << argv[2] << std::endl; + usage(argv[0]); + } + + // Retrieve the triangulation + std::vector lp = off_reader.get_point_cloud(); + + // Define the periodic cube + P3DT3 pdt(PK::Iso_cuboid_3(x_min, y_min, z_min, x_max, y_max, z_max)); + // Heuristic for inserting large point sets (if pts is reasonably large) + pdt.insert(lp.begin(), lp.end(), true); + // As pdt won't be modified anymore switch to 1-sheeted cover if possible + if (pdt.is_triangulation_in_1_sheet()) pdt.convert_to_1_sheeted_covering(); + std::cout << "Periodic Delaunay computed." << std::endl; + + // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. This is the default mode + // Maybe need to set it to GENERAL mode + Alpha_shape_3 as(pdt, 0, Alpha_shape_3::GENERAL); + + // filtration with alpha values from alpha shape + std::vector the_objects; + std::vector the_alpha_values; + + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); + + as.filtration_with_alpha_values(disp); +#ifdef DEBUG_TRACES + std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; +#endif // DEBUG_TRACES + + Alpha_shape_3::size_type count_vertices = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; + + // Loop on objects vector + Vertex_list vertex_list; + ST simplex_tree; + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; + std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); + int dim_max = 0; + Filtration_value filtration_max = 0.0; + 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(*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(*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(*edge); + count_edges++; + if (dim_max < 1) { + // Edge_3 is of dim 1 + dim_max = 1; + } + } else if (const Alpha_shape_3::Vertex_handle * vertex = + CGAL::object_cast(&object_iterator)) { + count_vertices++; + 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; + for (auto the_alpha_shape_vertex : vertex_list) { + Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); + if (the_map_iterator == map_cgal_simplex_tree.end()) { + // alpha shape not found + Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { + // alpha shape found + Simplex_tree_vertex vertex = the_map_iterator->second; +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + } + } + // Construction of the simplex_tree + Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); +#ifdef DEBUG_TRACES + std::cout << "filtration = " << filtr << std::endl; +#endif // DEBUG_TRACES + if (filtr > filtration_max) { + filtration_max = filtr; + } + simplex_tree.insert_simplex(the_simplex_tree, filtr); + if (the_alpha_value_iterator != the_alpha_values.end()) + ++the_alpha_value_iterator; + else + std::cout << "This shall not happen" << std::endl; + } + simplex_tree.set_dimension(dim_max); + +#ifdef DEBUG_TRACES + std::cout << "vertices \t\t" << count_vertices << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; + + + std::cout << "Information of the Simplex Tree: " << std::endl; + std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; + std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; + std::cout << " Dimension = " << simplex_tree.dimension() << " "; +#endif // DEBUG_TRACES + +#ifdef DEBUG_TRACES + std::cout << "Iterator on vertices: " << std::endl; + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree, true); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + pcoh.output_diagram(); + + return 0; +} diff --git a/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex.cpp b/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex.cpp index 67735ba1..e126caea 100644 --- a/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex.cpp +++ b/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex.cpp @@ -32,8 +32,8 @@ #include int main(int argc, char** argv) { - std::cout << "This program computes persistent homology, by using bitmap_cubical_complex class, of cubical " << - "complexes provided in text files in Perseus style (the only numbered in the first line is a dimension D of a" << + std::cout << "This program computes persistent homology, by using the Bitmap_cubical_complex_base class, of cubical " << + "complexes provided in text files in Perseus style. The only number in the first line is a dimension D of a" << "bitmap. In the lines I between 2 and D+1 there are numbers of top dimensional cells in the direction I. Let " << "N denote product of the numbers in the lines between 2 and D. In the lines D+2 to D+2+N there are " << "filtrations of top dimensional cells. We assume that the cells are in the lexicographical order. See " << diff --git a/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex_periodic_boundary_conditions.cpp b/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex_periodic_boundary_conditions.cpp index 122160a2..7f9296a6 100644 --- a/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex_periodic_boundary_conditions.cpp +++ b/src/Bitmap_cubical_complex/utilities/Bitmap_cubical_complex_periodic_boundary_conditions.cpp @@ -33,9 +33,9 @@ #include int main(int argc, char** argv) { - std::cout << "This program computes persistent homology, by using " << + std::cout << "This program computes persistent homology, by using the " << "Bitmap_cubical_complex_periodic_boundary_conditions class, of cubical complexes provided in text files in " << - "Perseus style (the only numbered in the first line is a dimension D of a bitmap. In the lines I between 2 " << + "Perseus style. The only number in the first line is a dimension D of a bitmap. In the lines I between 2 " << "and D+1 there are numbers of top dimensional cells in the direction I. Let N denote product of the numbers " << "in the lines between 2 and D. In the lines D+2 to D+2+N there are filtrations of top dimensional cells. We " << "assume that the cells are in the lexicographical order. See CubicalOneSphere.txt or CubicalTwoSphere.txt for" << diff --git a/src/Bitmap_cubical_complex/utilities/README b/src/Bitmap_cubical_complex/utilities/README new file mode 100644 index 00000000..d9085635 --- /dev/null +++ b/src/Bitmap_cubical_complex/utilities/README @@ -0,0 +1,24 @@ +# Bitmap_cubical_complex # + +## `Bitmap_cubical_complex` ## +This program computes persistent homology, by using the Bitmap_cubical_complex class, of cubical complexes provided in text files in Perseus style. The only number in the first line is a dimension D of a bitmap. In the lines I between 2 and D+1 there are numbers of top dimensional cells in the direction I. Let N denote product of the numbers in the lines between 2 and D. In the lines D+2 to D+2+N there are filtrations of top dimensional cells. We assume that the cells are in the lexicographical order. + +Examples: + +* Create a Cubical Complex from the Perseus style file CubicalOneSphere.txt, computes Persistence cohomology from it and writes the results in a persistence file: +`Bitmap_cubical_complex data/bitmap/CubicalOneSphere.txt` + +* Create a Cubical Complex from the Perseus style file CubicalTwoSphere.txt, computes Persistence cohomology from it and writes the results in a persistence file: +`Bitmap_cubical_complex data/bitmap/CubicalTwoSphere.txt` + +## `Bitmap_cubical_complex_periodic_boundary_conditions` ## + +Same as above, but with periodic boundary conditions. + +Examples: + +* Create a Periodical Cubical Complex from the Perseus style file 2d_torus.txt, computes Persistence cohomology from it and writes the results in a persistence file: +`Bitmap_cubical_complex_periodic_boundary_conditions.exe data/bitmap/2d_torus.txt` + +* Create a Periodical Cubical Complex from the Perseus style file 3d_torus.txt, computes Persistence cohomology from it and writes the results in a persistence file: +`Bitmap_cubical_complex_periodic_boundary_conditions.exe data/bitmap/3d_torus.txt` diff --git a/src/Bottleneck_distance/utilities/README b/src/Bottleneck_distance/utilities/README new file mode 100644 index 00000000..4c9b0735 --- /dev/null +++ b/src/Bottleneck_distance/utilities/README @@ -0,0 +1,19 @@ +# Bottleneck_distance # + +## `alpha_rips_persistence_bottleneck_distance` ## +This program computes the persistent homology with coefficient field Z/pZ of a Rips complex defined on a set of input points. The output diagram contains one bar per line, written with the convention: + +`p dim b d` + +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients. + +Usage: +`alpha_rips_persistence_bottleneck_distance [options] ` + +Allowed options: + +* `-h [ --help ]` Produce help message +* `-r [ --max-edge-length ]` (default = inf) Maximal length of an edge for the Rips complex construction.` +* `-d [ --cpx-dimension ]` (default = 1) Maximal dimension of the Rips complex we want to compute.` +* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. \ No newline at end of file diff --git a/src/Persistent_cohomology/utilities/CMakeLists.txt b/src/Persistent_cohomology/utilities/CMakeLists.txt index c2f00da2..5b315801 100644 --- a/src/Persistent_cohomology/utilities/CMakeLists.txt +++ b/src/Persistent_cohomology/utilities/CMakeLists.txt @@ -20,37 +20,4 @@ add_test(NAME Persistent_cohomology_example_from_rips_on_tore_3D COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") - - install(TARGETS alpha_complex_3d_persistence DESTINATION bin) - - if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) - add_executable (alpha_complex_persistence alpha_complex_persistence.cpp) - target_link_libraries(alpha_complex_persistence - ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - - add_executable(periodic_alpha_complex_3d_persistence periodic_alpha_complex_3d_persistence.cpp) - target_link_libraries(periodic_alpha_complex_3d_persistence ${CGAL_LIBRARY}) - - if (TBB_FOUND) - target_link_libraries(alpha_complex_persistence ${TBB_LIBRARIES}) - target_link_libraries(periodic_alpha_complex_3d_persistence ${TBB_LIBRARIES}) - endif(TBB_FOUND) - add_test(NAME Persistent_cohomology_example_alpha_complex COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "-p" "2" "-m" "0.45") - add_test(NAME Persistent_cohomology_example_periodic_alpha_complex_3d COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off" "${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt" "2" "0") - - install(TARGETS alpha_complex_persistence DESTINATION bin) - install(TARGETS periodic_alpha_complex_3d_persistence DESTINATION bin) - - endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) endif(CGAL_FOUND) diff --git a/src/Persistent_cohomology/utilities/README b/src/Persistent_cohomology/utilities/README index 76e960da..eecee7ee 100644 --- a/src/Persistent_cohomology/utilities/README +++ b/src/Persistent_cohomology/utilities/README @@ -1,114 +1,66 @@ -To build the utilities, run in a Terminal: +# Persistent_cohomology # -cd /path-to-utilities/ -cmake . -make +## `rips_persistence` ## +This program computes the persistent homology with coefficient field *Z/pZ* of a Rips complex defined on a set of input points. The output diagram contains one bar per line, written with the convention: -*********************************************************************************************************************** -Example of use of RIPS: +`p dim b d` -Computation of the persistent homology with Z/2Z coefficients of the Rips complex on points -sampling a 3D torus: +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers *pi* such that the homology feature exists in homology with *Z/piZ* coefficients). -./rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 2 +**Usage** +`rips_persistence [options] ` -output: -2 0 0 inf +**Allowed options** + +* `-h [ --help ]` Produce help message +* `-r [ --max-edge-length ]` (default = inf) Maximal length of an edge for the Rips complex construction. +* `-d [ --cpx-dimension ]` (default = 1) Maximal dimension of the Rips complex we want to compute. +* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. + +**Example 1 with Z/2Z coefficients** +`rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 2` + +outputs: +``` +2 0 0 inf 2 1 0.0983494 inf 2 1 0.104347 inf 2 2 0.138335 inf +``` +**Example 2 with Z/3Z coefficients** -Every line is of this format: p1*...*pr dim b d -where - p1*...*pr is the product of prime numbers pi such that the homology feature exists in homology with Z/piZ coefficients. - dim is the dimension of the homological feature, - b and d are respectively the birth and death of the feature and - +rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 3 +outputs: +``` +3 0 0 inf +3 1 0.0983494 inf +3 1 0.104347 inf +3 2 0.138335 inf +``` -with Z/3Z coefficients: -./rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 3 -output: -3 0 0 inf -3 1 0.0983494 inf -3 1 0.104347 inf -3 2 0.138335 inf - -*********************************************************************************************************************** -Example of use of ALPHA: - -For a more verbose mode, please run cmake with option "DEBUG_TRACES=TRUE" and recompile the programs. - -1) 3D special case ------------------- -Computation of the persistent homology with Z/2Z coefficients of the alpha complex on points -sampling a torus 3D: - -./alpha_complex_3d_persistence ../../data/points/tore3D_300.off 2 0.45 - -output: -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 - -Here we retrieve expected Betti numbers on a tore 3D: -Betti numbers[0] = 1 -Betti numbers[1] = 2 -Betti numbers[2] = 1 - -N.B.: - alpha_complex_3d_persistence accepts only OFF files in 3D dimension. - - filtration values are alpha square values - -2) d-Dimension case -------------------- -Computation of the persistent homology with Z/2Z coefficients of the alpha complex on points -sampling a torus 3D: - -./alpha_complex_persistence -r 32 -p 2 -m 0.45 ../../data/points/tore3D_300.off - -output: -Alpha complex is of dimension 3 - 9273 simplices - 300 vertices. -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 - -Here we retrieve expected Betti numbers on a tore 3D: -Betti numbers[0] = 1 -Betti numbers[1] = 2 -Betti numbers[2] = 1 - -N.B.: - alpha_complex_persistence accepts OFF files in d-Dimension. - - filtration values are alpha square values - -3) 3D periodic special case ---------------------------- -./periodic_alpha_complex_3d_persistence ../../data/points/grid_10_10_10_in_0_1.off ../../data/points/iso_cuboid_3_in_0_1.txt 3 1.0 - -output: -Periodic Delaunay computed. -Simplex_tree dim: 3 + +## `rips_distance_matrix_persistence` ## +Same as `rips_persistence` but taking an distance matrix as input. + +**Example** +`rips_distance_matrix_persistence data/distance_matrix/full_square_distance_matrix.csv -r 15 -d 3 -p 3 -m 0` + +outputs: +``` +The complex contains 46 simplices + and has dimension 3 3 0 0 inf -3 1 0.0025 inf -3 1 0.0025 inf -3 1 0.0025 inf -3 2 0.005 inf -3 2 0.005 inf -3 2 0.005 inf -3 3 0.0075 inf - -Here we retrieve expected Betti numbers on a tore 3D: -Betti numbers[0] = 1 -Betti numbers[1] = 3 -Betti numbers[2] = 3 -Betti numbers[3] = 1 - -N.B.: - periodic_alpha_complex_3d_persistence accepts only OFF files in 3D dimension. In this example, the periodic cube -is hard coded to { x = [0,1]; y = [0,1]; z = [0,1] } - - filtration values are alpha square values +3 0 0 8.94427 +3 0 0 7.28011 +3 0 0 6.08276 +3 0 0 5.83095 +3 0 0 5.38516 +3 0 0 5 +3 1 11 12.0416 +3 1 6.32456 6.7082 +``` diff --git a/src/Persistent_cohomology/utilities/alpha_complex_3d_helper.h b/src/Persistent_cohomology/utilities/alpha_complex_3d_helper.h deleted file mode 100644 index 7865e4ec..00000000 --- a/src/Persistent_cohomology/utilities/alpha_complex_3d_helper.h +++ /dev/null @@ -1,76 +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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (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 . - */ - -#ifndef ALPHA_COMPLEX_3D_HELPER_H_ -#define ALPHA_COMPLEX_3D_HELPER_H_ - -template -Vertex_list from_cell(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; -} - -template -Vertex_list from_facet(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; -} - -template -Vertex_list from_edge(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; -} - -template -Vertex_list from_vertex(const 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; -} - -#endif // ALPHA_COMPLEX_3D_HELPER_H_ diff --git a/src/Persistent_cohomology/utilities/alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/utilities/alpha_complex_3d_persistence.cpp deleted file mode 100644 index f63ff0f6..00000000 --- a/src/Persistent_cohomology/utilities/alpha_complex_3d_persistence.cpp +++ /dev/null @@ -1,242 +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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA - * - * 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 -#include -#include -#include -#include - -#include "alpha_complex_3d_helper.h" - -// Alpha_shape_3 templates type definitions -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 -using Point_3 = Kernel::Point_3; - -// filtration with alpha values needed type definition -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 -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:\n" << progName << " path_to_OFF_file coeff_field_characteristic[integer " << - "> 0] min_persistence[float >= -1.0]\n"; - std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; - exit(-1); -} - -int main(int argc, char * const argv[]) { - // program args management - if (argc != 4) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - - int coeff_field_characteristic = atoi(argv[2]); - - Filtration_value min_persistence = 0.0; - 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]); - } - - // Read points from file - std::string offInputFile(argv[1]); - // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); - // Check the read operation was correct - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); - } - - // Retrieve the triangulation - std::vector lp = off_reader.get_point_cloud(); - - // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. - Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); -#ifdef DEBUG_TRACES - std::cout << "Alpha shape computed in GENERAL mode" << std::endl; -#endif // DEBUG_TRACES - - // filtration with alpha values from alpha shape - std::vector the_objects; - std::vector the_alpha_values; - - Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), - std::back_inserter(the_alpha_values)); - - as.filtration_with_alpha_values(disp); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - - Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; - - // Loop on objects vector - Vertex_list vertex_list; - ST simplex_tree; - Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max = 0; - Filtration_value filtration_max = 0.0; - 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(*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(*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(*edge); - count_edges++; - if (dim_max < 1) { - // Edge_3 is of dim 1 - dim_max = 1; - } - } else if (const Vertex_handle * vertex = CGAL::object_cast(&object_iterator)) { - count_vertices++; - 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; - for (auto the_alpha_shape_vertex : vertex_list) { - Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) { - // alpha shape not found - Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); - } else { - // alpha shape found - Simplex_tree_vertex vertex = the_map_iterator->second; -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - } - } - // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); -#ifdef DEBUG_TRACES - std::cout << "filtration = " << filtr << std::endl; -#endif // DEBUG_TRACES - if (filtr > filtration_max) { - filtration_max = filtr; - } - simplex_tree.insert_simplex(the_simplex_tree, filtr); - if (the_alpha_value_iterator != the_alpha_values.end()) - ++the_alpha_value_iterator; - else - std::cout << "This shall not happen" << std::endl; - } - simplex_tree.set_dimension(dim_max); - -#ifdef DEBUG_TRACES - std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; - - - std::cout << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; - std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; - std::cout << " Dimension = " << simplex_tree.dimension() << " "; -#endif // DEBUG_TRACES - -#ifdef DEBUG_TRACES - std::cout << "Iterator on vertices: " << std::endl; - for (auto vertex : simplex_tree.complex_vertex_range()) { - std::cout << vertex << " "; - } -#endif // DEBUG_TRACES - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; - // Compute the persistence diagram of the complex - PCOH pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - pcoh.output_diagram(); - - return 0; -} diff --git a/src/Persistent_cohomology/utilities/alpha_complex_persistence.cpp b/src/Persistent_cohomology/utilities/alpha_complex_persistence.cpp deleted file mode 100644 index 9e84e91f..00000000 --- a/src/Persistent_cohomology/utilities/alpha_complex_persistence.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include - -#include - -#include -#include -// to construct a simplex_tree from alpha complex -#include - -#include -#include -#include // for numeric_limits - -using Simplex_tree = Gudhi::Simplex_tree<>; -using Filtration_value = Simplex_tree::Filtration_value; - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & output_file_diag - , Filtration_value & alpha_square_max_value - , int & coeff_field_characteristic - , Filtration_value & min_persistence); - -int main(int argc, char **argv) { - std::string off_file_points; - std::string output_file_diag; - Filtration_value alpha_square_max_value; - int coeff_field_characteristic; - Filtration_value min_persistence; - - program_options(argc, argv, off_file_points, output_file_diag, alpha_square_max_value, - coeff_field_characteristic, min_persistence); - - // ---------------------------------------------------------------------------- - // Init of an alpha complex from an OFF file - // ---------------------------------------------------------------------------- - using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; - Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); - - Simplex_tree simplex; - if (alpha_complex_from_file.create_complex(simplex, alpha_square_max_value)) { - // ---------------------------------------------------------------------------- - // Display information about the alpha complex - // ---------------------------------------------------------------------------- - std::cout << "Simplicial complex is of dimension " << simplex.dimension() << - " - " << simplex.num_simplices() << " simplices - " << - simplex.num_vertices() << " vertices." << std::endl; - - // Sort the simplices in the order of the filtration - simplex.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; - // Compute the persistence diagram of the complex - Gudhi::persistent_cohomology::Persistent_cohomology< Simplex_tree, - Gudhi::persistent_cohomology::Field_Zp > pcoh(simplex); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (output_file_diag.empty()) { - pcoh.output_diagram(); - } else { - std::cout << "Result in file: " << output_file_diag << std::endl; - std::ofstream out(output_file_diag); - pcoh.output_diagram(out); - out.close(); - } - } - - return 0; -} - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & output_file_diag - , Filtration_value & alpha_square_max_value - , int & coeff_field_characteristic - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of file containing a point set. Format is one point per line: X1 ... Xd "); - - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&output_file_diag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-alpha-square-value,r", - po::value(&alpha_square_max_value)->default_value(std::numeric_limits::infinity()), - "Maximal alpha square value for the Alpha complex construction.") - ("field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of an Alpha complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} diff --git a/src/Persistent_cohomology/utilities/periodic_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/utilities/periodic_alpha_complex_3d_persistence.cpp deleted file mode 100644 index 8140a3c5..00000000 --- a/src/Persistent_cohomology/utilities/periodic_alpha_complex_3d_persistence.cpp +++ /dev/null @@ -1,268 +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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA - * - * 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 -#include -#include -#include -#include -#include -#include - -#include "alpha_complex_3d_helper.h" - -// Traits -using K = CGAL::Exact_predicates_inexact_constructions_kernel; -using PK = CGAL::Periodic_3_Delaunay_triangulation_traits_3; -// Vertex type -using DsVb = CGAL::Periodic_3_triangulation_ds_vertex_base_3<>; -using Vb = CGAL::Triangulation_vertex_base_3; -using AsVb = CGAL::Alpha_shape_vertex_base_3; -// Cell type -using DsCb = CGAL::Periodic_3_triangulation_ds_cell_base_3<>; -using Cb = CGAL::Triangulation_cell_base_3; -using AsCb = CGAL::Alpha_shape_cell_base_3; -using Tds = CGAL::Triangulation_data_structure_3; -using P3DT3 = CGAL::Periodic_3_Delaunay_triangulation_3; -using Alpha_shape_3 = CGAL::Alpha_shape_3; -using Point_3 = PK::Point_3; - -// filtration with alpha values needed type definition -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 -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 Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< - ST, Gudhi::persistent_cohomology::Field_Zp >; - -void usage(char * const progName) { - std::cerr << "Usage:\n" << progName << " path_to_OFF_file path_to_iso_cuboid_3_file coeff_field_characteristic[" << - "integer > 0] min_persistence[float >= -1.0]\n" << - " path_to_OFF_file is the path to your points cloud in OFF format.\n" << - " path_to_iso_cuboid_3_file is the path to the iso cuboid file with the following format :\n" << - " x_min y_min z_min x_max y_max z_max\n" << - " In this example, the periodic cube will be " << - "{ x = [x_min,x_max]; y = [y_min,y_max]; z = [z_min,z_max] }.\n" << - " For more information, please refer to\n" << - " https://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Iso__cuboid__3.html\n"; - - exit(-1); -} - -int main(int argc, char * const argv[]) { - // program args management - if (argc != 5) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - - int coeff_field_characteristic = atoi(argv[3]); - Filtration_value min_persistence = strtof(argv[4], nullptr); - - // Read points from file - std::string offInputFile(argv[1]); - // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); - // Check the read operation was correct - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); - } - - // Read iso_cuboid_3 information from file - std::ifstream iso_cuboid_str(argv[2]); - double x_min, y_min, z_min, x_max, y_max, z_max; - if (iso_cuboid_str.good()) { - iso_cuboid_str >> x_min >> y_min >> z_min >> x_max >> y_max >> z_max; - } else { - std::cerr << "Unable to read file " << argv[2] << std::endl; - usage(argv[0]); - } - - // Retrieve the triangulation - std::vector lp = off_reader.get_point_cloud(); - - // Define the periodic cube - P3DT3 pdt(PK::Iso_cuboid_3(x_min, y_min, z_min, x_max, y_max, z_max)); - // Heuristic for inserting large point sets (if pts is reasonably large) - pdt.insert(lp.begin(), lp.end(), true); - // As pdt won't be modified anymore switch to 1-sheeted cover if possible - if (pdt.is_triangulation_in_1_sheet()) pdt.convert_to_1_sheeted_covering(); - std::cout << "Periodic Delaunay computed." << std::endl; - - // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. This is the default mode - // Maybe need to set it to GENERAL mode - Alpha_shape_3 as(pdt, 0, Alpha_shape_3::GENERAL); - - // filtration with alpha values from alpha shape - std::vector the_objects; - std::vector the_alpha_values; - - Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), - std::back_inserter(the_alpha_values)); - - as.filtration_with_alpha_values(disp); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - - Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; - - // Loop on objects vector - Vertex_list vertex_list; - ST simplex_tree; - Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max = 0; - Filtration_value filtration_max = 0.0; - 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(*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(*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(*edge); - count_edges++; - if (dim_max < 1) { - // Edge_3 is of dim 1 - dim_max = 1; - } - } else if (const Alpha_shape_3::Vertex_handle * vertex = - CGAL::object_cast(&object_iterator)) { - count_vertices++; - 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; - for (auto the_alpha_shape_vertex : vertex_list) { - Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) { - // alpha shape not found - Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); - } else { - // alpha shape found - Simplex_tree_vertex vertex = the_map_iterator->second; -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - } - } - // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); -#ifdef DEBUG_TRACES - std::cout << "filtration = " << filtr << std::endl; -#endif // DEBUG_TRACES - if (filtr > filtration_max) { - filtration_max = filtr; - } - simplex_tree.insert_simplex(the_simplex_tree, filtr); - if (the_alpha_value_iterator != the_alpha_values.end()) - ++the_alpha_value_iterator; - else - std::cout << "This shall not happen" << std::endl; - } - simplex_tree.set_dimension(dim_max); - -#ifdef DEBUG_TRACES - std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; - - - std::cout << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; - std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; - std::cout << " Dimension = " << simplex_tree.dimension() << " "; -#endif // DEBUG_TRACES - -#ifdef DEBUG_TRACES - std::cout << "Iterator on vertices: " << std::endl; - for (auto vertex : simplex_tree.complex_vertex_range()) { - std::cout << vertex << " "; - } -#endif // DEBUG_TRACES - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree, true); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - pcoh.output_diagram(); - - return 0; -} diff --git a/src/Witness_complex/example/CMakeLists.txt b/src/Witness_complex/example/CMakeLists.txt index f8527e0f..a8231392 100644 --- a/src/Witness_complex/example/CMakeLists.txt +++ b/src/Witness_complex/example/CMakeLists.txt @@ -14,25 +14,22 @@ install(TARGETS Witness_complex_example_nearest_landmark_table DESTINATION bin) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) add_executable( Witness_complex_example_off example_witness_complex_off.cpp ) add_executable ( Witness_complex_example_sphere example_witness_complex_sphere.cpp ) - - add_executable ( Witness_complex_example_witness_persistence example_witness_complex_persistence.cpp ) - target_link_libraries(Witness_complex_example_witness_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) - - if (TBB_FOUND) - target_link_libraries(Witness_complex_example_witness_persistence ${TBB_LIBRARIES}) - endif() + + add_executable( Witness_complex_example_strong_off example_strong_witness_complex_off.cpp ) + target_link_libraries(Witness_complex_example_strong_off) add_test(NAME Witness_complex_example_off_test_torus COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "20" "1.0" "3") add_test(NAME Witness_complex_example_test_sphere_10 COMMAND $ "10") - add_test(NAME Witness_complex_example_test_torus_persistence - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-l" "20" "-a" "0.5") - + add_test(NAME Witness_complex_example_strong_off_test_torus + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "20" "1.0" "3") + install(TARGETS Witness_complex_example_off DESTINATION bin) install(TARGETS Witness_complex_example_sphere DESTINATION bin) - install(TARGETS Witness_complex_example_witness_persistence DESTINATION bin) + install(TARGETS Witness_complex_example_strong_off DESTINATION bin) + endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) diff --git a/src/Witness_complex/example/example_strong_witness_complex_off.cpp b/src/Witness_complex/example/example_strong_witness_complex_off.cpp new file mode 100644 index 00000000..0ee9ee90 --- /dev/null +++ b/src/Witness_complex/example/example_strong_witness_complex_off.cpp @@ -0,0 +1,79 @@ +/* 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 (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 + +using K = CGAL::Epick_d; +using Point_d = typename K::Point_d; +using Witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; +using Point_vector = std::vector; + +int main(int argc, char * const argv[]) { + if (argc != 5) { + std::cerr << "Usage: " << argv[0] + << " path_to_point_file number_of_landmarks max_squared_alpha limit_dimension\n"; + return 0; + } + + std::string file_name = argv[1]; + int nbL = atoi(argv[2]), lim_dim = atoi(argv[4]); + double alpha2 = atof(argv[3]); + clock_t start, end; + 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 << "Strong 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, + point_vector); + + witness_complex.create_complex(simplex_tree, alpha2, lim_dim); + end = clock(); + std::cout << "Strong 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_persistence.cpp b/src/Witness_complex/example/example_witness_complex_persistence.cpp deleted file mode 100644 index a1146922..00000000 --- a/src/Witness_complex/example/example_witness_complex_persistence.cpp +++ /dev/null @@ -1,171 +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 (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 // infinity - -using K = CGAL::Epick_d; -using Point_d = K::Point_d; - -using Point_vector = std::vector; -using Witness_complex = Gudhi::witness_complex::Euclidean_witness_complex; -using SimplexTree = Gudhi::Simplex_tree<>; - -using Filtration_value = SimplexTree::Filtration_value; - -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; - -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { - std::string file_name; - std::string filediag; - Filtration_value max_squared_alpha; - int p, nbL, lim_d; - Filtration_value min_persistence; - SimplexTree simplex_tree; - - program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, lim_d, min_persistence); - - // Extract the points from the file file_name - Point_vector witnesses, 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); // ----- >> - } - witnesses = Point_vector(off_reader.get_point_cloud()); - std::cout << "Successfully read " << witnesses.size() << " points.\n"; - std::cout << "Ambient dimension is " << witnesses[0].dimension() << ".\n"; - - // Choose landmarks from witnesses - Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); - - // Compute witness complex - Witness_complex witness_complex(landmarks, - witnesses); - - witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); - - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; - std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(p); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (filediag.empty()) { - pcoh.output_diagram(); - } else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); - } - - return 0; -} - - -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&file_name), - "Name of file containing a point set in off format."); - - Filtration_value default_alpha = std::numeric_limits::infinity(); - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("landmarks,l", po::value(&nbL), - "Number of landmarks to choose from the point cloud.") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), - "Maximal squared relaxation parameter.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence)->default_value(0), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") - ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), - "Maximal dimension of the weak witness complex we want to compute."); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - po::variables_map vm; - - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Weak witness complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} diff --git a/src/Witness_complex/utilities/CMakeLists.txt b/src/Witness_complex/utilities/CMakeLists.txt index 918ab864..125a41ff 100644 --- a/src/Witness_complex/utilities/CMakeLists.txt +++ b/src/Witness_complex/utilities/CMakeLists.txt @@ -3,24 +3,26 @@ project(Witness_complex_utilities) # CGAL and Eigen3 are required for Euclidean version of Witness if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) - add_executable( Witness_complex_example_strong_off example_strong_witness_complex_off.cpp ) - target_link_libraries(Witness_complex_example_strong_off) + + add_executable ( Witness_complex_strong_witness_persistence strong_witness_persistence.cpp ) + target_link_libraries(Witness_complex_strong_witness_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) - add_executable ( Witness_complex_example_strong_witness_persistence example_strong_witness_persistence.cpp ) - target_link_libraries(Witness_complex_example_strong_witness_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) + add_executable ( Witness_complex_weak_witness_persistence weak_witness_persistence.cpp ) + target_link_libraries(Witness_complex_weak_witness_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) if (TBB_FOUND) - target_link_libraries(Witness_complex_example_strong_witness_persistence ${TBB_LIBRARIES}) + target_link_libraries(Witness_complex_strong_witness_persistence ${TBB_LIBRARIES}) + target_link_libraries(Witness_complex_weak_witness_persistence ${TBB_LIBRARIES}) endif() - add_test(NAME Witness_complex_example_strong_off_test_torus - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "20" "1.0" "3") - add_test(NAME Witness_complex_example_strong_test_torus_persistence - COMMAND $ + add_test(NAME Witness_complex_strong_test_torus_persistence + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-l" "20" "-a" "0.5") + add_test(NAME Witness_complex_weak_test_torus_persistence + COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-l" "20" "-a" "0.5") - install(TARGETS Witness_complex_example_strong_off DESTINATION bin) - install(TARGETS Witness_complex_example_strong_witness_persistence DESTINATION bin) + install(TARGETS Witness_complex_strong_witness_persistence DESTINATION bin) + install(TARGETS Witness_complex_weak_witness_persistence DESTINATION bin) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.6.0) diff --git a/src/Witness_complex/utilities/README b/src/Witness_complex/utilities/README new file mode 100644 index 00000000..d8dc9ca7 --- /dev/null +++ b/src/Witness_complex/utilities/README @@ -0,0 +1,72 @@ +# Witness_complex # + +## `weak_witness_persistence` ## +This program computes the persistent homology with coefficient field *Z/pZ* of a Weak witness complex defined on a set of input points. The output diagram contains one bar per line, written with the convention: + +`p dim b d` + +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients. + +*Usage* +`weak_witness_persistence [options] ` + +*Allowed options* + +* `-h [ --help ]` Produce help message +* `-l [ --landmarks ]` Number of landmarks to choose from the point cloud. +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. By default, print in std::cout. +* `-a [ --max-sq-alpha ]` (default = inf) Maximal squared relaxation parameter. +* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. +* `-d [ --cpx-dimension ]` (default = 2147483647) Maximal dimension of the weak witness complex we want to compute. + +*Example* +`weak_witness_persistence data/points/tore3D_1307.off -l 20 -a 0.5 -m 0.006` + +outputs: +``` +Successfully read 1307 points. +Ambient dimension is 3. +The complex contains 732 simplices and has dimension 8 +11 0 0 inf +11 1 0 inf +11 2 0.0275251 0.0534586 +11 1 0 0.0239952 +``` + +N.B.: output is random as the 20 landmarks are chosen randomly. + +## `strong_witness_persistence` ## +This program computes the persistent homology with coefficient field *Z/pZ* of a Strong witness complex defined on a set of input points. The output diagram contains one bar per line, written with the convention: + +`p dim b d` + +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients. + +*Usage* +`strong_witness_persistence [options] ` + +*Allowed options* + +* `-h [ --help ]` Produce help message +* `-l [ --landmarks ]` Number of landmarks to choose from the point cloud. +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. By default, print in std::cout. +* `-a [ --max-sq-alpha ]` (default = inf) Maximal squared relaxation parameter. +* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. +* `-d [ --cpx-dimension ]` (default = 2147483647) Maximal dimension of the weak witness complex we want to compute. + +*Example* +`strong_witness_persistence data/points/tore3D_1307.off -l 20 -a 0.5 -m 0.06` + +outputs: +``` +Successfully read 1307 points. +Ambient dimension is 3. +The complex contains 1836 simplices and has dimension 8 +11 0 0 inf +11 1 0.00674748 inf +11 2 0.0937751 0.235354 +``` + +N.B.: output is random as the 20 landmarks are chosen randomly. diff --git a/src/Witness_complex/utilities/example_strong_witness_complex_off.cpp b/src/Witness_complex/utilities/example_strong_witness_complex_off.cpp deleted file mode 100644 index 0ee9ee90..00000000 --- a/src/Witness_complex/utilities/example_strong_witness_complex_off.cpp +++ /dev/null @@ -1,79 +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 (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 - -using K = CGAL::Epick_d; -using Point_d = typename K::Point_d; -using Witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; -using Point_vector = std::vector; - -int main(int argc, char * const argv[]) { - if (argc != 5) { - std::cerr << "Usage: " << argv[0] - << " path_to_point_file number_of_landmarks max_squared_alpha limit_dimension\n"; - return 0; - } - - std::string file_name = argv[1]; - int nbL = atoi(argv[2]), lim_dim = atoi(argv[4]); - double alpha2 = atof(argv[3]); - clock_t start, end; - 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 << "Strong 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, - point_vector); - - witness_complex.create_complex(simplex_tree, alpha2, lim_dim); - end = clock(); - std::cout << "Strong 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/utilities/example_strong_witness_persistence.cpp b/src/Witness_complex/utilities/example_strong_witness_persistence.cpp deleted file mode 100644 index f786fe7b..00000000 --- a/src/Witness_complex/utilities/example_strong_witness_persistence.cpp +++ /dev/null @@ -1,171 +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 (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 // infinity - -using K = CGAL::Epick_d; -using Point_d = K::Point_d; - -using Point_vector = std::vector; -using Strong_witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; -using SimplexTree = Gudhi::Simplex_tree<>; - -using Filtration_value = SimplexTree::Filtration_value; - -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; - -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { - std::string file_name; - std::string filediag; - Filtration_value max_squared_alpha; - int p, nbL, lim_d; - Filtration_value min_persistence; - SimplexTree simplex_tree; - - program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, lim_d, min_persistence); - - // Extract the points from the file file_name - Point_vector witnesses, 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); // ----- >> - } - witnesses = Point_vector(off_reader.get_point_cloud()); - std::cout << "Successfully read " << witnesses.size() << " points.\n"; - std::cout << "Ambient dimension is " << witnesses[0].dimension() << ".\n"; - - // Choose landmarks from witnesses - Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); - - // Compute witness complex - Strong_witness_complex strong_witness_complex(landmarks, - witnesses); - - strong_witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); - - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; - std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(p); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (filediag.empty()) { - pcoh.output_diagram(); - } else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); - } - - return 0; -} - -void program_options(int argc, char * argv[] - , int & nbL - , std::string & file_name - , std::string & filediag - , Filtration_value & max_squared_alpha - , int & p - , int & dim_max - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&file_name), - "Name of file containing a point set in off format."); - - po::options_description visible("Allowed options", 100); - Filtration_value default_alpha = std::numeric_limits::infinity(); - visible.add_options() - ("help,h", "produce help message") - ("landmarks,l", po::value(&nbL), - "Number of landmarks to choose from the point cloud.") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), - "Maximal squared relaxation parameter.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence)->default_value(0), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") - ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), - "Maximal dimension of the strong witness complex we want to compute."); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - po::variables_map vm; - - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Strong witness complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} - diff --git a/src/Witness_complex/utilities/strong_witness_persistence.cpp b/src/Witness_complex/utilities/strong_witness_persistence.cpp new file mode 100644 index 00000000..f786fe7b --- /dev/null +++ b/src/Witness_complex/utilities/strong_witness_persistence.cpp @@ -0,0 +1,171 @@ +/* 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 (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 // infinity + +using K = CGAL::Epick_d; +using Point_d = K::Point_d; + +using Point_vector = std::vector; +using Strong_witness_complex = Gudhi::witness_complex::Euclidean_strong_witness_complex; +using SimplexTree = Gudhi::Simplex_tree<>; + +using Filtration_value = SimplexTree::Filtration_value; + +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , int & dim_max + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string file_name; + std::string filediag; + Filtration_value max_squared_alpha; + int p, nbL, lim_d; + Filtration_value min_persistence; + SimplexTree simplex_tree; + + program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, lim_d, min_persistence); + + // Extract the points from the file file_name + Point_vector witnesses, 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); // ----- >> + } + witnesses = Point_vector(off_reader.get_point_cloud()); + std::cout << "Successfully read " << witnesses.size() << " points.\n"; + std::cout << "Ambient dimension is " << witnesses[0].dimension() << ".\n"; + + // Choose landmarks from witnesses + Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); + + // Compute witness complex + Strong_witness_complex strong_witness_complex(landmarks, + witnesses); + + strong_witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); + + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + + return 0; +} + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , int & dim_max + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&file_name), + "Name of file containing a point set in off format."); + + po::options_description visible("Allowed options", 100); + Filtration_value default_alpha = std::numeric_limits::infinity(); + visible.add_options() + ("help,h", "produce help message") + ("landmarks,l", po::value(&nbL), + "Number of landmarks to choose from the point cloud.") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), + "Maximal squared relaxation parameter.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence)->default_value(0), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") + ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), + "Maximal dimension of the strong witness complex we want to compute."); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + po::variables_map vm; + + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Strong witness complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} + diff --git a/src/Witness_complex/utilities/weak_witness_persistence.cpp b/src/Witness_complex/utilities/weak_witness_persistence.cpp new file mode 100644 index 00000000..a1146922 --- /dev/null +++ b/src/Witness_complex/utilities/weak_witness_persistence.cpp @@ -0,0 +1,171 @@ +/* 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 (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 // infinity + +using K = CGAL::Epick_d; +using Point_d = K::Point_d; + +using Point_vector = std::vector; +using Witness_complex = Gudhi::witness_complex::Euclidean_witness_complex; +using SimplexTree = Gudhi::Simplex_tree<>; + +using Filtration_value = SimplexTree::Filtration_value; + +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , int & dim_max + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string file_name; + std::string filediag; + Filtration_value max_squared_alpha; + int p, nbL, lim_d; + Filtration_value min_persistence; + SimplexTree simplex_tree; + + program_options(argc, argv, nbL, file_name, filediag, max_squared_alpha, p, lim_d, min_persistence); + + // Extract the points from the file file_name + Point_vector witnesses, 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); // ----- >> + } + witnesses = Point_vector(off_reader.get_point_cloud()); + std::cout << "Successfully read " << witnesses.size() << " points.\n"; + std::cout << "Ambient dimension is " << witnesses[0].dimension() << ".\n"; + + // Choose landmarks from witnesses + Gudhi::subsampling::pick_n_random_points(witnesses, nbL, std::back_inserter(landmarks)); + + // Compute witness complex + Witness_complex witness_complex(landmarks, + witnesses); + + witness_complex.create_complex(simplex_tree, max_squared_alpha, lim_d); + + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + + return 0; +} + + +void program_options(int argc, char * argv[] + , int & nbL + , std::string & file_name + , std::string & filediag + , Filtration_value & max_squared_alpha + , int & p + , int & dim_max + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&file_name), + "Name of file containing a point set in off format."); + + Filtration_value default_alpha = std::numeric_limits::infinity(); + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("landmarks,l", po::value(&nbL), + "Number of landmarks to choose from the point cloud.") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-sq-alpha,a", po::value(&max_squared_alpha)->default_value(default_alpha), + "Maximal squared relaxation parameter.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence)->default_value(0), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals") + ("cpx-dimension,d", po::value(&dim_max)->default_value(std::numeric_limits::max()), + "Maximal dimension of the weak witness complex we want to compute."); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + po::variables_map vm; + + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Weak witness complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/common/utilities/README b/src/common/utilities/README index dc841521..18fa8cc4 100644 --- a/src/common/utilities/README +++ b/src/common/utilities/README @@ -1,19 +1,19 @@ -======================= off_file_from_shape_generator ================================== +# Pointset generator # -Example of use : +## `off_file_from_shape_generator` ## -*** on|in sphere|cube|curve|torus|klein generator +Generates a pointset and save it in an OFF file. Command-line is: +`off_file_from_shape_generator on|in sphere|cube|curve|torus|klein ...` -./off_file_from_shape_generator on sphere onSphere.off 1000 3 15.2 +Warning: "on cube" generator is not available! - => generates a onSphere.off file with 1000 points randomized on a sphere of dimension 3 and radius 15.2 +Examples: -./off_file_from_shape_generator in sphere inSphere.off 100 2 +* Generate an onSphere.off file with 1000 points randomized on a sphere of dimension 3 and radius 15.2: +`off_file_from_shape_generator on sphere onSphere.off 1000 3 15.2` + +* Generate an inSphere.off file with 100 points randomized in a sphere of dimension 2 (circle) and radius 1.0 (default): +`off_file_from_shape_generator in sphere inSphere.off 100 2` - => generates a inSphere.off file with 100 points randomized in a sphere of dimension 2 (circle) and radius 1.0 (default) - -./off_file_from_shape_generator in cube inCube.off 10000 3 5.8 - - => generates a inCube.off file with 10000 points randomized in a cube of dimension 3 and side 5.8 - -!! Warning: hypegenerator on cube is not available !! +* Generates a inCube.off file with 10000 points randomized in a cube of dimension 3 and side 5.8: +`off_file_from_shape_generator in cube inCube.off 10000 3 5.8` -- cgit v1.2.3 From e678542b5578e32bb931605b2ea0f8ae763ec6b8 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 4 Oct 2017 13:12:13 +0000 Subject: Fix some CMakeLists.txt files git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2753 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f895fab289a0c508ded97fcc5d9c8f5dd3670224 --- src/Bottleneck_distance/example/CMakeLists.txt | 12 +++++++----- src/Contraction/utilities/CMakeLists.txt | 1 + src/Persistent_cohomology/utilities/CMakeLists.txt | 2 -- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Bottleneck_distance/example/CMakeLists.txt b/src/Bottleneck_distance/example/CMakeLists.txt index b37555f9..6a602dbb 100644 --- a/src/Bottleneck_distance/example/CMakeLists.txt +++ b/src/Bottleneck_distance/example/CMakeLists.txt @@ -2,14 +2,16 @@ cmake_minimum_required(VERSION 2.6) project(Bottleneck_distance_examples) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) - add_executable (bottleneck_read_file_example bottleneck_read_file_example.cpp) add_executable (bottleneck_basic_example bottleneck_basic_example.cpp) + add_executable (bottleneck_read_file_example bottleneck_read_file_example.cpp) add_test(NAME Bottleneck_distance_example_basic COMMAND $) + add_test(NAME Bottleneck_read_file_example + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers") + install(TARGETS bottleneck_read_file_example DESTINATION bin) install(TARGETS bottleneck_basic_example DESTINATION bin) - if (TBB_FOUND) - target_link_libraries(alpha_rips_persistence_bottleneck_distance ${TBB_LIBRARIES}) - endif(TBB_FOUND) -endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) + +endif (NOT CGAL_VERSION VERSION_LESS 4.8.1) diff --git a/src/Contraction/utilities/CMakeLists.txt b/src/Contraction/utilities/CMakeLists.txt index a18783ef..36efd99a 100644 --- a/src/Contraction/utilities/CMakeLists.txt +++ b/src/Contraction/utilities/CMakeLists.txt @@ -2,5 +2,6 @@ cmake_minimum_required(VERSION 2.6) project(Contraction_utilities) add_executable(GarlandHeckbert Garland_heckbert.cpp) +target_link_libraries(GarlandHeckbert ${Boost_TIMER_LIBRARY}) install(TARGETS GarlandHeckbert DESTINATION bin) diff --git a/src/Persistent_cohomology/utilities/CMakeLists.txt b/src/Persistent_cohomology/utilities/CMakeLists.txt index 5b315801..9a506b3f 100644 --- a/src/Persistent_cohomology/utilities/CMakeLists.txt +++ b/src/Persistent_cohomology/utilities/CMakeLists.txt @@ -19,5 +19,3 @@ add_test(NAME Persistent_cohomology_example_from_rips_on_tore_3D COMMAND $ Date: Wed, 4 Oct 2017 13:12:33 +0000 Subject: Remove timer (compilation problems on Windows) git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2754 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9af1b232021b765d4180695af2a08313f9d51965 --- src/Contraction/utilities/Garland_heckbert.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Contraction/utilities/Garland_heckbert.cpp b/src/Contraction/utilities/Garland_heckbert.cpp index 8b5a6a6c..2b0dc973 100644 --- a/src/Contraction/utilities/Garland_heckbert.cpp +++ b/src/Contraction/utilities/Garland_heckbert.cpp @@ -30,7 +30,6 @@ #include #include -#include #include #include "Garland_heckbert/Error_quadric.h" @@ -165,8 +164,6 @@ int main(int argc, char *argv[]) { int num_contractions = atoi(argv[3]); - boost::timer::auto_cpu_timer t; - // constructs the contractor object with Garland Heckbert policies. Complex_contractor contractor(complex, new GH_cost(complex), -- cgit v1.2.3 From 300914816e3e5d347efd9eaa5d06c236ad81511e Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 5 Oct 2017 08:26:50 +0000 Subject: Move some utils + update doc so that utilities are shown as examples git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2756 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a707d174a382da7efad3d12a73bb66d2c90da599 --- src/Doxyfile | 3 +- .../doc/Intro_persistent_cohomology.h | 20 +-- src/Persistent_cohomology/utilities/CMakeLists.txt | 21 --- src/Persistent_cohomology/utilities/README | 66 --------- .../utilities/rips_distance_matrix_persistence.cpp | 144 -------------------- .../utilities/rips_persistence.cpp | 147 --------------------- src/Rips_complex/utilities/CMakeLists.txt | 21 +++ src/Rips_complex/utilities/README | 66 +++++++++ .../utilities/rips_distance_matrix_persistence.cpp | 144 ++++++++++++++++++++ src/Rips_complex/utilities/rips_persistence.cpp | 147 +++++++++++++++++++++ src/common/doc/main_page.h | 54 ++++---- 11 files changed, 415 insertions(+), 418 deletions(-) delete mode 100644 src/Persistent_cohomology/utilities/CMakeLists.txt delete mode 100644 src/Persistent_cohomology/utilities/README delete mode 100644 src/Persistent_cohomology/utilities/rips_distance_matrix_persistence.cpp delete mode 100644 src/Persistent_cohomology/utilities/rips_persistence.cpp create mode 100644 src/Rips_complex/utilities/CMakeLists.txt create mode 100644 src/Rips_complex/utilities/README create mode 100644 src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp create mode 100644 src/Rips_complex/utilities/rips_persistence.cpp diff --git a/src/Doxyfile b/src/Doxyfile index 7f5975eb..7b506e42 100644 --- a/src/Doxyfile +++ b/src/Doxyfile @@ -819,7 +819,8 @@ EXCLUDE_SYMBOLS = # command). EXAMPLE_PATH = biblio/ \ - example/ + example/ \ + utilities/ # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and diff --git a/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h b/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h index e17e5926..576a1af8 100644 --- a/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h +++ b/src/Persistent_cohomology/doc/Intro_persistent_cohomology.h @@ -143,8 +143,8 @@ namespace persistent_cohomology { We provide several example files: run these examples with -h for details on their use, and read the README file. -\li -Persistent_cohomology/rips_persistence.cpp computes the Rips complex of a point cloud and outputs its persistence +\li +Rips_complex/rips_persistence.cpp computes the Rips complex of a point cloud and outputs its persistence diagram. \code $> ./rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 3 \endcode \code The complex contains 177838 simplices @@ -158,12 +158,12 @@ diagram. Persistent_cohomology/rips_multifield_persistence.cpp computes the Rips complex of a point cloud and outputs its persistence diagram with a family of field coefficients. -\li -Persistent_cohomology/rips_distance_matrix_persistence.cpp computes the Rips complex of a distance matrix and +\li +Rips_complex/rips_distance_matrix_persistence.cpp computes the Rips complex of a distance matrix and outputs its persistence diagram. -\li -Persistent_cohomology/alpha_complex_3d_persistence.cpp computes the persistent homology with +\li +Alpha_complex/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. \code $> ./alpha_complex_3d_persistence ../../data/points/tore3D_300.off 2 0.45 \endcode \code Simplex_tree dim: 3 @@ -194,8 +194,8 @@ and a weights file. 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 +\li +Alpha_complex/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. \code $> ./alpha_complex_persistence -r 32 -p 2 -m 0.45 ../../data/points/tore3D_300.off \endcode \code Alpha complex is of dimension 3 - 9273 simplices - 300 vertices. @@ -205,8 +205,8 @@ Simplex_tree dim: 3 2 1 0.0934117 1.00003 2 2 0.56444 1.03938 \endcode -\li -Persistent_cohomology/periodic_alpha_complex_3d_persistence.cpp computes the persistent homology with +\li +Alpha_complex/periodic_alpha_complex_3d_persistence.cpp computes the persistent homology with \f$\mathbb{Z}/2\mathbb{Z}\f$ coefficients of the periodic alpha complex on points sampling from an OFF file. \code $> ./periodic_alpha_complex_3d_persistence ../../data/points/grid_10_10_10_in_0_1.off 3 1.0 \endcode \code Periodic Delaunay computed. diff --git a/src/Persistent_cohomology/utilities/CMakeLists.txt b/src/Persistent_cohomology/utilities/CMakeLists.txt deleted file mode 100644 index 9a506b3f..00000000 --- a/src/Persistent_cohomology/utilities/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -project(Persistent_cohomology_utilities) - -add_executable(rips_distance_matrix_persistence rips_distance_matrix_persistence.cpp) -target_link_libraries(rips_distance_matrix_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) - -add_executable(rips_persistence rips_persistence.cpp) -target_link_libraries(rips_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) - -if (TBB_FOUND) - target_link_libraries(rips_distance_matrix_persistence ${TBB_LIBRARIES}) - target_link_libraries(rips_persistence ${TBB_LIBRARIES}) -endif() - -add_test(NAME Persistent_cohomology_example_from_rips_distance_matrix COMMAND $ - "${CMAKE_SOURCE_DIR}/data/distance_matrix/full_square_distance_matrix.csv" "-r" "1.0" "-d" "3" "-p" "3" "-m" "0") -add_test(NAME Persistent_cohomology_example_from_rips_on_tore_3D COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "3") - -install(TARGETS rips_distance_matrix_persistence DESTINATION bin) -install(TARGETS rips_persistence DESTINATION bin) diff --git a/src/Persistent_cohomology/utilities/README b/src/Persistent_cohomology/utilities/README deleted file mode 100644 index eecee7ee..00000000 --- a/src/Persistent_cohomology/utilities/README +++ /dev/null @@ -1,66 +0,0 @@ -# Persistent_cohomology # - -## `rips_persistence` ## -This program computes the persistent homology with coefficient field *Z/pZ* of a Rips complex defined on a set of input points. The output diagram contains one bar per line, written with the convention: - -`p dim b d` - -where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers *pi* such that the homology feature exists in homology with *Z/piZ* coefficients). - -**Usage** -`rips_persistence [options] ` - -**Allowed options** - -* `-h [ --help ]` Produce help message -* `-r [ --max-edge-length ]` (default = inf) Maximal length of an edge for the Rips complex construction. -* `-d [ --cpx-dimension ]` (default = 1) Maximal dimension of the Rips complex we want to compute. -* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. -* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. - -**Example 1 with Z/2Z coefficients** -`rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 2` - -outputs: -``` -2 0 0 inf -2 1 0.0983494 inf -2 1 0.104347 inf -2 2 0.138335 inf -``` - -**Example 2 with Z/3Z coefficients** - -rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 3 - -outputs: -``` -3 0 0 inf -3 1 0.0983494 inf -3 1 0.104347 inf -3 2 0.138335 inf -``` - - - - -## `rips_distance_matrix_persistence` ## -Same as `rips_persistence` but taking an distance matrix as input. - -**Example** -`rips_distance_matrix_persistence data/distance_matrix/full_square_distance_matrix.csv -r 15 -d 3 -p 3 -m 0` - -outputs: -``` -The complex contains 46 simplices - and has dimension 3 -3 0 0 inf -3 0 0 8.94427 -3 0 0 7.28011 -3 0 0 6.08276 -3 0 0 5.83095 -3 0 0 5.38516 -3 0 0 5 -3 1 11 12.0416 -3 1 6.32456 6.7082 -``` diff --git a/src/Persistent_cohomology/utilities/rips_distance_matrix_persistence.cpp b/src/Persistent_cohomology/utilities/rips_distance_matrix_persistence.cpp deleted file mode 100644 index d38808c7..00000000 --- a/src/Persistent_cohomology/utilities/rips_distance_matrix_persistence.cpp +++ /dev/null @@ -1,144 +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): Pawel Dlotko, Vincent Rouvreau - * - * Copyright (C) 2016 INRIA - * - * 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 // infinity - -// Types definition -using Simplex_tree = Gudhi::Simplex_tree; -using Filtration_value = Simplex_tree::Filtration_value; -using Rips_complex = Gudhi::rips_complex::Rips_complex; -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -using Distance_matrix = std::vector>; - -void program_options(int argc, char * argv[] - , std::string & csv_matrix_file - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { - std::string csv_matrix_file; - std::string filediag; - Filtration_value threshold; - int dim_max; - int p; - Filtration_value min_persistence; - - program_options(argc, argv, csv_matrix_file, filediag, threshold, dim_max, p, min_persistence); - - Distance_matrix distances = Gudhi::read_lower_triangular_matrix_from_csv_file(csv_matrix_file); - Rips_complex rips_complex_from_file(distances, threshold); - - // Construct the Rips complex in a Simplex Tree - Simplex_tree simplex_tree; - - rips_complex_from_file.create_complex(simplex_tree, dim_max); - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; - std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(p); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (filediag.empty()) { - pcoh.output_diagram(); - } else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); - } - return 0; -} - -void program_options(int argc, char * argv[] - , std::string & csv_matrix_file - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&csv_matrix_file), - "Name of file containing a distance matrix. Can be square or lower triangular matrix. Separator is ';'."); - - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of distance matrix.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} diff --git a/src/Persistent_cohomology/utilities/rips_persistence.cpp b/src/Persistent_cohomology/utilities/rips_persistence.cpp deleted file mode 100644 index d504798b..00000000 --- a/src/Persistent_cohomology/utilities/rips_persistence.cpp +++ /dev/null @@ -1,147 +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): Clément Maria - * - * Copyright (C) 2014 INRIA - * - * 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 // infinity - -// Types definition -using Simplex_tree = Gudhi::Simplex_tree; -using Filtration_value = Simplex_tree::Filtration_value; -using Rips_complex = Gudhi::rips_complex::Rips_complex; -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -using Point = std::vector; -using Points_off_reader = Gudhi::Points_off_reader; - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence); - -int main(int argc, char * argv[]) { - std::string off_file_points; - std::string filediag; - Filtration_value threshold; - int dim_max; - int p; - Filtration_value min_persistence; - - program_options(argc, argv, off_file_points, filediag, threshold, dim_max, p, min_persistence); - - Points_off_reader off_reader(off_file_points); - Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); - - // Construct the Rips complex in a Simplex Tree - Simplex_tree simplex_tree; - - rips_complex_from_file.create_complex(simplex_tree, dim_max); - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; - std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(p); - - pcoh.compute_persistent_cohomology(min_persistence); - - // Output the diagram in filediag - if (filediag.empty()) { - pcoh.output_diagram(); - } else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); - } - - return 0; -} - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of an OFF file containing a point set.\n"); - - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} diff --git a/src/Rips_complex/utilities/CMakeLists.txt b/src/Rips_complex/utilities/CMakeLists.txt new file mode 100644 index 00000000..baa571fa --- /dev/null +++ b/src/Rips_complex/utilities/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 2.6) +project(Rips_complex_utilities) + +add_executable(rips_distance_matrix_persistence rips_distance_matrix_persistence.cpp) +target_link_libraries(rips_distance_matrix_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) + +add_executable(rips_persistence rips_persistence.cpp) +target_link_libraries(rips_persistence ${Boost_PROGRAM_OPTIONS_LIBRARY}) + +if (TBB_FOUND) + target_link_libraries(rips_distance_matrix_persistence ${TBB_LIBRARIES}) + target_link_libraries(rips_persistence ${TBB_LIBRARIES}) +endif() + +add_test(NAME Rips_complex_utility_from_rips_distance_matrix COMMAND $ + "${CMAKE_SOURCE_DIR}/data/distance_matrix/full_square_distance_matrix.csv" "-r" "1.0" "-d" "3" "-p" "3" "-m" "0") +add_test(NAME Rips_complex_utility_from_rips_on_tore_3D COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.25" "-m" "0.5" "-d" "3" "-p" "3") + +install(TARGETS rips_distance_matrix_persistence DESTINATION bin) +install(TARGETS rips_persistence DESTINATION bin) diff --git a/src/Rips_complex/utilities/README b/src/Rips_complex/utilities/README new file mode 100644 index 00000000..ddb7860f --- /dev/null +++ b/src/Rips_complex/utilities/README @@ -0,0 +1,66 @@ +# Rips_complex # + +## `rips_persistence` ## +This program computes the persistent homology with coefficient field *Z/pZ* of a Rips complex defined on a set of input points. The output diagram contains one bar per line, written with the convention: + +`p dim b d` + +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers *pi* such that the homology feature exists in homology with *Z/piZ* coefficients). + +**Usage** +`rips_persistence [options] ` + +**Allowed options** + +* `-h [ --help ]` Produce help message +* `-r [ --max-edge-length ]` (default = inf) Maximal length of an edge for the Rips complex construction. +* `-d [ --cpx-dimension ]` (default = 1) Maximal dimension of the Rips complex we want to compute. +* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. + +**Example 1 with Z/2Z coefficients** +`rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 2` + +outputs: +``` +2 0 0 inf +2 1 0.0983494 inf +2 1 0.104347 inf +2 2 0.138335 inf +``` + +**Example 2 with Z/3Z coefficients** + +rips_persistence ../../data/points/tore3D_1307.off -r 0.25 -m 0.5 -d 3 -p 3 + +outputs: +``` +3 0 0 inf +3 1 0.0983494 inf +3 1 0.104347 inf +3 2 0.138335 inf +``` + + + + +## `rips_distance_matrix_persistence` ## +Same as `rips_persistence` but taking an distance matrix as input. + +**Example** +`rips_distance_matrix_persistence data/distance_matrix/full_square_distance_matrix.csv -r 15 -d 3 -p 3 -m 0` + +outputs: +``` +The complex contains 46 simplices + and has dimension 3 +3 0 0 inf +3 0 0 8.94427 +3 0 0 7.28011 +3 0 0 6.08276 +3 0 0 5.83095 +3 0 0 5.38516 +3 0 0 5 +3 1 11 12.0416 +3 1 6.32456 6.7082 +``` diff --git a/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp b/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp new file mode 100644 index 00000000..d38808c7 --- /dev/null +++ b/src/Rips_complex/utilities/rips_distance_matrix_persistence.cpp @@ -0,0 +1,144 @@ +/* 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): Pawel Dlotko, Vincent Rouvreau + * + * Copyright (C) 2016 INRIA + * + * 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 // infinity + +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Distance_matrix = std::vector>; + +void program_options(int argc, char * argv[] + , std::string & csv_matrix_file + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string csv_matrix_file; + std::string filediag; + Filtration_value threshold; + int dim_max; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, csv_matrix_file, filediag, threshold, dim_max, p, min_persistence); + + Distance_matrix distances = Gudhi::read_lower_triangular_matrix_from_csv_file(csv_matrix_file); + Rips_complex rips_complex_from_file(distances, threshold); + + // Construct the Rips complex in a Simplex Tree + Simplex_tree simplex_tree; + + rips_complex_from_file.create_complex(simplex_tree, dim_max); + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & csv_matrix_file + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&csv_matrix_file), + "Name of file containing a distance matrix. Can be square or lower triangular matrix. Separator is ';'."); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of distance matrix.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Rips_complex/utilities/rips_persistence.cpp b/src/Rips_complex/utilities/rips_persistence.cpp new file mode 100644 index 00000000..d504798b --- /dev/null +++ b/src/Rips_complex/utilities/rips_persistence.cpp @@ -0,0 +1,147 @@ +/* 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): Clément Maria + * + * Copyright (C) 2014 INRIA + * + * 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 // infinity + +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Point = std::vector; +using Points_off_reader = Gudhi::Points_off_reader; + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string off_file_points; + std::string filediag; + Filtration_value threshold; + int dim_max; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, off_file_points, filediag, threshold, dim_max, p, min_persistence); + + Points_off_reader off_reader(off_file_points); + Rips_complex rips_complex_from_file(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); + + // Construct the Rips complex in a Simplex Tree + Simplex_tree simplex_tree; + + rips_complex_from_file.create_complex(simplex_tree, dim_max); + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices \n"; + std::cout << " and has dimension " << simplex_tree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } + + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&off_file_points), + "Name of an OFF file containing a point set.\n"); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index cee0c28b..466236ad 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -271,8 +271,8 @@ make doxygen * * The following examples/utilities require the Computational Geometry Algorithms * 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 + * Alpha_complex/alpha_complex_3d_persistence.cpp * \li * Persistent_cohomology/exact_alpha_complex_3d_persistence.cpp * \li @@ -289,10 +289,10 @@ make doxygen * Alpha_complex/Alpha_complex_from_off.cpp * \li * Alpha_complex/Alpha_complex_from_points.cpp - * \li - * Persistent_cohomology/alpha_complex_persistence.cpp - * \li - * Persistent_cohomology/periodic_alpha_complex_3d_persistence.cpp + * \li + * Alpha_complex/alpha_complex_persistence.cpp + * \li + * Alpha_complex/periodic_alpha_complex_3d_persistence.cpp * \li * Persistent_cohomology/custom_persistence_sort.cpp * @@ -329,12 +329,12 @@ make doxygen * Alpha_complex/Alpha_complex_from_off.cpp * \li * Alpha_complex/Alpha_complex_from_points.cpp + * \li + * Alpha_complex/alpha_complex_persistence.cpp + * \li + * Alpha_complex/periodic_alpha_complex_3d_persistence.cpp * \li * Bottleneck_distance/alpha_rips_persistence_bottleneck_distance.cpp.cpp - * \li - * Persistent_cohomology/alpha_complex_persistence.cpp - * \li - * Persistent_cohomology/periodic_alpha_complex_3d_persistence.cpp * \li * Persistent_cohomology/custom_persistence_sort.cpp * \li @@ -364,26 +364,24 @@ make doxygen * Alpha_complex/Alpha_complex_from_off.cpp * \li * Alpha_complex/Alpha_complex_from_points.cpp + * \li + * Alpha_complex/alpha_complex_3d_persistence.cpp + * \li + * Alpha_complex/alpha_complex_persistence.cpp + * \li + * Alpha_complex/periodic_alpha_complex_3d_persistence.cpp * \li * Bitmap_cubical_complex/Bitmap_cubical_complex.cpp * \li * Bitmap_cubical_complex/Bitmap_cubical_complex_periodic_boundary_conditions.cpp * \li * Bitmap_cubical_complex/Random_bitmap_cubical_complex.cpp - * \li - * Persistent_cohomology/alpha_complex_3d_persistence.cpp - * \li - * Persistent_cohomology/alpha_complex_persistence.cpp * \li * Simplex_tree/simple_simplex_tree.cpp * \li * Simplex_tree/example_alpha_shapes_3_simplex_tree_from_off_file.cpp * \li * Simplex_tree/simplex_tree_from_cliques_of_graph.cpp - * \li - * Persistent_cohomology/alpha_complex_3d_persistence.cpp - * \li - * Persistent_cohomology/alpha_complex_persistence.cpp * \li * Persistent_cohomology/rips_persistence_via_boundary_matrix.cpp * \li @@ -392,26 +390,24 @@ make doxygen * Persistent_cohomology/persistence_from_simple_simplex_tree.cpp * \li * Persistent_cohomology/plain_homology.cpp - * \li - * Persistent_cohomology/rips_distance_matrix_persistence.cpp * \li * Persistent_cohomology/rips_multifield_persistence.cpp - * \li - * 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/weighted_alpha_complex_3d_persistence.cpp - * \li - * Persistent_cohomology/periodic_alpha_complex_3d_persistence.cpp * \li * Persistent_cohomology/custom_persistence_sort.cpp * \li * Rips_complex/example_one_skeleton_rips_from_points.cpp * \li * Rips_complex/example_rips_complex_from_off_file.cpp + * \li + * Rips_complex/rips_distance_matrix_persistence.cpp + * \li + * Rips_complex/rips_persistence.cpp * * \section Contributions Bug reports and contributions * Please help us improving the quality of the GUDHI library. You may report bugs or suggestions to: @@ -436,6 +432,9 @@ make doxygen /*! @file Examples * @example Alpha_complex/Alpha_complex_from_off.cpp * @example Alpha_complex/Alpha_complex_from_points.cpp + * @example Alpha_complex/alpha_complex_3d_persistence.cpp + * @example Alpha_complex/alpha_complex_persistence.cpp + * @example Alpha_complex/periodic_alpha_complex_3d_persistence.cpp * @example Bottleneck_distance/alpha_rips_persistence_bottleneck_distance.cpp * @example Bottleneck_distance/bottleneck_basic_example.cpp * @example Bottleneck_distance/bottleneck_read_file_example.cpp @@ -446,22 +445,19 @@ make doxygen * @example common/example_CGAL_points_off_reader.cpp * @example Contraction/Garland_heckbert.cpp * @example Contraction/Rips_contraction.cpp - * @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/weighted_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 * @example Persistent_cohomology/plain_homology.cpp * @example Persistent_cohomology/rips_multifield_persistence.cpp - * @example Persistent_cohomology/rips_distance_matrix_persistence.cpp - * @example Persistent_cohomology/rips_persistence.cpp * @example Persistent_cohomology/custom_persistence_sort.cpp * @example Persistent_cohomology/rips_persistence_step_by_step.cpp * @example Rips_complex/example_one_skeleton_rips_from_points.cpp * @example Rips_complex/example_rips_complex_from_off_file.cpp + * @example Rips_complex/rips_persistence.cpp + * @example Rips_complex/rips_distance_matrix_persistence.cpp * @example Simplex_tree/mini_simplex_tree.cpp * @example Simplex_tree/simple_simplex_tree.cpp * @example Simplex_tree/example_alpha_shapes_3_simplex_tree_from_off_file.cpp -- cgit v1.2.3 From a60c38b4738f8147b0f6fb0f27eaa55cf466e22f Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 26 Oct 2017 15:06:12 +0000 Subject: Cancel the move of Garland_heckbert.cpp & co git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2806 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a3df461085b25b301ea52fcdefecd8d17903e211 --- src/Contraction/example/CMakeLists.txt | 5 +- src/Contraction/example/Garland_heckbert.cpp | 192 +++++++++++++++++++++ .../example/Garland_heckbert/Error_quadric.h | 182 +++++++++++++++++++ src/Contraction/utilities/CMakeLists.txt | 7 - src/Contraction/utilities/Garland_heckbert.cpp | 192 --------------------- .../utilities/Garland_heckbert/Error_quadric.h | 182 ------------------- 6 files changed, 378 insertions(+), 382 deletions(-) create mode 100644 src/Contraction/example/Garland_heckbert.cpp create mode 100644 src/Contraction/example/Garland_heckbert/Error_quadric.h delete mode 100644 src/Contraction/utilities/CMakeLists.txt delete mode 100644 src/Contraction/utilities/Garland_heckbert.cpp delete mode 100644 src/Contraction/utilities/Garland_heckbert/Error_quadric.h diff --git a/src/Contraction/example/CMakeLists.txt b/src/Contraction/example/CMakeLists.txt index f02949e4..a92d1685 100644 --- a/src/Contraction/example/CMakeLists.txt +++ b/src/Contraction/example/CMakeLists.txt @@ -1,9 +1,11 @@ cmake_minimum_required(VERSION 2.6) project(Contraction_examples) - add_executable(RipsContraction Rips_contraction.cpp) +add_executable(GarlandHeckbert Garland_heckbert.cpp) +target_link_libraries(GarlandHeckbert ${Boost_TIMER_LIBRARY}) + add_test(NAME Contraction_example_tore3D_0.2 COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "0.2") # TODO(DS) : These tests are too long under Windows @@ -13,3 +15,4 @@ add_test(NAME Contraction_example_tore3D_0.2 COMMAND $. + * + */ + + +#ifndef GARLAND_HECKBERT_H_ +#define GARLAND_HECKBERT_H_ + +#include +#include +#include +#include + +#include + +#include "Garland_heckbert/Error_quadric.h" + +struct Geometry_trait { + typedef Point_d Point; +}; + +/** + * The vertex stored in the complex contains a quadric. + */ +struct Garland_heckbert_traits + : public Gudhi::skeleton_blocker::Skeleton_blocker_simple_geometric_traits { + public: + struct Garland_heckbert_vertex : public Simple_geometric_vertex { + Error_quadric quadric; + }; + typedef Garland_heckbert_vertex Graph_vertex; +}; + +using Complex = Gudhi::skeleton_blocker::Skeleton_blocker_geometric_complex< Garland_heckbert_traits >; +using EdgeProfile = Gudhi::contraction::Edge_profile; +using Complex_contractor = Gudhi::contraction::Skeleton_blocker_contractor; + +/** + * How the new vertex is placed after an edge collapse : here it is placed at + * the point minimizing the cost of the quadric. + */ +class GH_placement : public Gudhi::contraction::Placement_policy { + Complex& complex_; + + public: + typedef Gudhi::contraction::Placement_policy::Placement_type Placement_type; + + GH_placement(Complex& complex) : complex_(complex) { (void)complex_; } + + Placement_type operator()(const EdgeProfile& profile) const override { + auto sum_quad(profile.v0().quadric); + sum_quad += profile.v1().quadric; + + boost::optional min_quadric_pt(sum_quad.min_cost()); + if (min_quadric_pt) + return Placement_type(*min_quadric_pt); + else + return profile.p0(); + } +}; + +/** + * How much cost an edge collapse : here the costs is given by a quadric + * which expresses a squared distances with triangles planes. + */ +class GH_cost : public Gudhi::contraction::Cost_policy { + Complex& complex_; + + public: + typedef Gudhi::contraction::Cost_policy::Cost_type Cost_type; + + GH_cost(Complex& complex) : complex_(complex) { (void)complex_; } + + Cost_type operator()(EdgeProfile const& profile, boost::optional const& new_point) const override { + Cost_type res; + if (new_point) { + auto sum_quad(profile.v0().quadric); + sum_quad += profile.v1().quadric; + res = sum_quad.cost(*new_point); + } + return res; + } +}; + +/** + * Visitor that is called at several moment. + * Here we initializes the quadrics of every vertex at the on_started call back + * and we update them when contracting an edge (the quadric become the sum of both quadrics). + */ +class GH_visitor : public Gudhi::contraction::Contraction_visitor { + Complex& complex_; + + public: + GH_visitor(Complex& complex) : complex_(complex) { (void)complex_; } + + // Compute quadrics for every vertex v + // The quadric of v consists in the sum of quadric + // of every triangles passing through v weighted by its area + + void on_started(Complex & complex) override { + for (auto v : complex.vertex_range()) { + auto & quadric_v(complex[v].quadric); + for (auto t : complex.triangle_range(v)) { + auto t_it = t.begin(); + const auto& p0(complex.point(*t_it++)); + const auto& p1(complex.point(*t_it++)); + const auto& p2(complex.point(*t_it++)); + quadric_v += Error_quadric(p0, p1, p2); + } + } + } + + /** + * @brief Called when an edge is about to be contracted and replaced by a vertex whose position is *placement. + */ + void on_contracting(EdgeProfile const &profile, boost::optional< Point > placement) + override { + profile.v0().quadric += profile.v1().quadric; + } +}; + +int main(int argc, char *argv[]) { + if (argc != 4) { + std::cerr << "Usage " << argv[0] << + " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; + return EXIT_FAILURE; + } + + Complex complex; + typedef Complex::Vertex_handle Vertex_handle; + + // load the points + Gudhi::skeleton_blocker::Skeleton_blocker_off_reader off_reader(argv[1], complex); + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file:" << argv[1] << std::endl; + return EXIT_FAILURE; + } + + if (!complex.empty() && !(complex.point(Vertex_handle(0)).dimension() == 3)) { + std::cerr << "Only points of dimension 3 are supported." << std::endl; + return EXIT_FAILURE; + } + + std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; + + int num_contractions = atoi(argv[3]); + + // constructs the contractor object with Garland Heckbert policies. + Complex_contractor contractor(complex, + new GH_cost(complex), + new GH_placement(complex), + Gudhi::contraction::make_link_valid_contraction(), + new GH_visitor(complex)); + + std::cout << "Contract " << num_contractions << " edges" << std::endl; + contractor.contract_edges(num_contractions); + + std::cout << "Final complex has " << + complex.num_vertices() << " vertices, " << + complex.num_edges() << " edges and " << + complex.num_triangles() << " triangles." << std::endl; + + // write simplified complex + Gudhi::skeleton_blocker::Skeleton_blocker_off_writer off_writer(argv[2], complex); + + return EXIT_SUCCESS; +} + +#endif // GARLAND_HECKBERT_H_ + + + + diff --git a/src/Contraction/example/Garland_heckbert/Error_quadric.h b/src/Contraction/example/Garland_heckbert/Error_quadric.h new file mode 100644 index 00000000..e7dafaa0 --- /dev/null +++ b/src/Contraction/example/Garland_heckbert/Error_quadric.h @@ -0,0 +1,182 @@ +/* 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-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 . + * + */ + +#ifndef GARLAND_HECKBERT_ERROR_QUADRIC_H_ +#define GARLAND_HECKBERT_ERROR_QUADRIC_H_ + +#include + +#include +#include + +template class Error_quadric { + private: + double coeff[10]; + + public: + Error_quadric() { + clear(); + } + + /** + * Quadric corresponding to the L2 distance to the plane. + * + * According to the notation of Garland Heckbert, they + * denote a quadric symetric matrix as : + * Q = [ q11 q12 q13 q14] + * [ q12 q22 q23 q24] + * [ q13 q23 q33 q34] + * [ q14 q24 q34 q44] + * + * which is represented by a vector with 10 elts that + * are denoted ci for clarity with : + * Q = [ c0 c1 c2 c3 ] + * [ c1 c4 c5 c6 ] + * [ c2 c5 c7 c8 ] + * [ c3 c6 c8 c9 ] + * + * The constructor return the quadrics that represents + * the squared distance to the plane defined by triangle p0,p1,p2 + * times the area of triangle p0,p1,p2. + */ + Error_quadric(const Point & p0, const Point & p1, const Point & p2) { + Point normal(unit_normal(p0, p1, p2)); + double a = normal[0]; + double b = normal[1]; + double c = normal[2]; + double d = -a * p0[0] - b * p0[1] - c * p0[2]; + coeff[0] = a*a; + coeff[1] = a*b; + coeff[2] = a*c; + coeff[3] = a*d; + coeff[4] = b*b; + coeff[5] = b*c; + coeff[6] = b*d; + coeff[7] = c*c; + coeff[8] = c*d; + coeff[9] = d*d; + + double area_p0p1p2 = std::sqrt(squared_area(p0, p1, p2)); + for (auto& x : coeff) + x *= area_p0p1p2; + } + + inline double squared_area(const Point& p0, const Point& p1, const Point& p2) { + // if (x1,x2,x3) = p1-p0 and (y1,y2,y3) = p2-p0 + // then the squared area is = (u^2+v^2+w^2)/4 + // with: u = x2 * y3 - x3 * y2; + // v = x3 * y1 - x1 * y3; + // w = x1 * y2 - x2 * y1; + Point p0p1(p1 - p0); + Point p0p2(p2 - p0); + double A = p0p1[1] * p0p2[2] - p0p1[2] * p0p2[1]; + double B = p0p1[2] * p0p2[0] - p0p1[0] * p0p2[2]; + double C = p0p1[0] * p0p2[1] - p0p1[1] * p0p2[0]; + return 1. / 4. * (A * A + B * B + C * C); + } + + void clear() { + for (auto& x : coeff) + x = 0; + } + + Error_quadric& operator+=(const Error_quadric& other) { + if (this != &other) { + for (int i = 0; i < 10; ++i) + coeff[i] += other.coeff[i]; + } + return *this; + } + + /** + * @return The quadric quost defined by the scalar product v^T Q v where Q is the quadratic form of Garland/Heckbert + */ + inline double cost(const Point& point) const { + double cost = + coeff[0] * point.x() * point.x() + coeff[4] * point.y() * point.y() + coeff[7] * point.z() * point.z() + + 2 * (coeff[1] * point.x() * point.y() + coeff[5] * point.y() * point.z() + coeff[2] * point.z() * point.x()) + + 2 * (coeff[3] * point.x() + coeff[6] * point.y() + coeff[8] * point.z()) + + coeff[9]; + if (cost < 0) { + return 0; + } else { + return cost; + } + } + + inline double grad_determinant() const { + return + coeff[0] * coeff[4] * coeff[7] + - coeff[0] * coeff[5] * coeff[5] + - coeff[1] * coeff[1] * coeff[7] + + 2 * coeff[1] * coeff[5] * coeff[2] + - coeff[4] * coeff[2] * coeff[2]; + } + + /** + * Return the point such that it minimizes the gradient of the quadric. + * Det must be passed with the determinant value of the gradient (should be non zero). + */ + inline Point solve_linear_gradient(double det) const { + return Point({ + (-coeff[1] * coeff[5] * coeff[8] + coeff[1] * coeff[7] * coeff[6] + coeff[2] * coeff[8] * coeff[4] - + coeff[2] * coeff[5] * coeff[6] - coeff[3] * coeff[4] * coeff[7] + coeff[3] * coeff[5] * coeff[5]) + / det, + (coeff[0] * coeff[5] * coeff[8] - coeff[0] * coeff[7] * coeff[6] - coeff[5] * coeff[2] * coeff[3] - + coeff[1] * coeff[2] * coeff[8] + coeff[6] * coeff[2] * coeff[2] + coeff[1] * coeff[3] * coeff[7]) + / det, + (-coeff[8] * coeff[0] * coeff[4] + coeff[8] * coeff[1] * coeff[1] + coeff[2] * coeff[3] * coeff[4] + + coeff[5] * coeff[0] * coeff[6] - coeff[5] * coeff[1] * coeff[3] - coeff[1] * coeff[2] * coeff[6]) + / det + }); + } + + /** + * returns the point that minimizes the quadric. + * It inverses the quadric if its determinant is higher that a given threshold . + * If the determinant is lower than this value the returned value is uninitialized. + */ + boost::optional min_cost(double scale = 1) const { + // const double min_determinant = 1e-4 * scale*scale; + const double min_determinant = 1e-5; + boost::optional pt_res; + double det = grad_determinant(); + if (std::abs(det) > min_determinant) + pt_res = solve_linear_gradient(det); + return pt_res; + } + + friend std::ostream& operator<<(std::ostream& stream, const Error_quadric& quadric) { + stream << "\n[ " << quadric.coeff[0] << "," << quadric.coeff[1] << "," << quadric.coeff[2] << "," << + quadric.coeff[3] << ";\n"; + stream << " " << quadric.coeff[1] << "," << quadric.coeff[4] << "," << quadric.coeff[5] << "," << + quadric.coeff[6] << ";\n"; + stream << " " << quadric.coeff[2] << "," << quadric.coeff[5] << "," << quadric.coeff[7] << "," << + quadric.coeff[8] << ";\n"; + stream << " " << quadric.coeff[3] << "," << quadric.coeff[6] << "," << quadric.coeff[8] << "," << + quadric.coeff[9] << "]"; + return stream; + } +}; + +#endif // GARLAND_HECKBERT_ERROR_QUADRIC_H_ diff --git a/src/Contraction/utilities/CMakeLists.txt b/src/Contraction/utilities/CMakeLists.txt deleted file mode 100644 index 36efd99a..00000000 --- a/src/Contraction/utilities/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -project(Contraction_utilities) - -add_executable(GarlandHeckbert Garland_heckbert.cpp) -target_link_libraries(GarlandHeckbert ${Boost_TIMER_LIBRARY}) - -install(TARGETS GarlandHeckbert DESTINATION bin) diff --git a/src/Contraction/utilities/Garland_heckbert.cpp b/src/Contraction/utilities/Garland_heckbert.cpp deleted file mode 100644 index 2b0dc973..00000000 --- a/src/Contraction/utilities/Garland_heckbert.cpp +++ /dev/null @@ -1,192 +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): David Salinas - * - * Copyright (C) 2014 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 . - * - */ - - -#ifndef GARLAND_HECKBERT_H_ -#define GARLAND_HECKBERT_H_ - -#include -#include -#include -#include - -#include - -#include "Garland_heckbert/Error_quadric.h" - -struct Geometry_trait { - typedef Point_d Point; -}; - -/** - * The vertex stored in the complex contains a quadric. - */ -struct Garland_heckbert_traits - : public Gudhi::skeleton_blocker::Skeleton_blocker_simple_geometric_traits { - public: - struct Garland_heckbert_vertex : public Simple_geometric_vertex { - Error_quadric quadric; - }; - typedef Garland_heckbert_vertex Graph_vertex; -}; - -using Complex = Gudhi::skeleton_blocker::Skeleton_blocker_geometric_complex< Garland_heckbert_traits >; -using EdgeProfile = Gudhi::contraction::Edge_profile; -using Complex_contractor = Gudhi::contraction::Skeleton_blocker_contractor; - -/** - * How the new vertex is placed after an edge collapse : here it is placed at - * the point minimizing the cost of the quadric. - */ -class GH_placement : public Gudhi::contraction::Placement_policy { - Complex& complex_; - - public: - typedef Gudhi::contraction::Placement_policy::Placement_type Placement_type; - - GH_placement(Complex& complex) : complex_(complex) { (void)complex_; } - - Placement_type operator()(const EdgeProfile& profile) const override { - auto sum_quad(profile.v0().quadric); - sum_quad += profile.v1().quadric; - - boost::optional min_quadric_pt(sum_quad.min_cost()); - if (min_quadric_pt) - return Placement_type(*min_quadric_pt); - else - return profile.p0(); - } -}; - -/** - * How much cost an edge collapse : here the costs is given by a quadric - * which expresses a squared distances with triangles planes. - */ -class GH_cost : public Gudhi::contraction::Cost_policy { - Complex& complex_; - - public: - typedef Gudhi::contraction::Cost_policy::Cost_type Cost_type; - - GH_cost(Complex& complex) : complex_(complex) { (void)complex_; } - - Cost_type operator()(EdgeProfile const& profile, boost::optional const& new_point) const override { - Cost_type res; - if (new_point) { - auto sum_quad(profile.v0().quadric); - sum_quad += profile.v1().quadric; - res = sum_quad.cost(*new_point); - } - return res; - } -}; - -/** - * Visitor that is called at several moment. - * Here we initializes the quadrics of every vertex at the on_started call back - * and we update them when contracting an edge (the quadric become the sum of both quadrics). - */ -class GH_visitor : public Gudhi::contraction::Contraction_visitor { - Complex& complex_; - - public: - GH_visitor(Complex& complex) : complex_(complex) { (void)complex_; } - - // Compute quadrics for every vertex v - // The quadric of v consists in the sum of quadric - // of every triangles passing through v weighted by its area - - void on_started(Complex & complex) override { - for (auto v : complex.vertex_range()) { - auto & quadric_v(complex[v].quadric); - for (auto t : complex.triangle_range(v)) { - auto t_it = t.begin(); - const auto& p0(complex.point(*t_it++)); - const auto& p1(complex.point(*t_it++)); - const auto& p2(complex.point(*t_it++)); - quadric_v += Error_quadric(p0, p1, p2); - } - } - } - - /** - * @brief Called when an edge is about to be contracted and replaced by a vertex whose position is *placement. - */ - void on_contracting(EdgeProfile const &profile, boost::optional< Point > placement) - override { - profile.v0().quadric += profile.v1().quadric; - } -}; - -int main(int argc, char *argv[]) { - if (argc != 4) { - std::cerr << "Usage " << argv[0] << - " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; - return EXIT_FAILURE; - } - - Complex complex; - typedef Complex::Vertex_handle Vertex_handle; - - // load the points - Gudhi::skeleton_blocker::Skeleton_blocker_off_reader off_reader(argv[1], complex); - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file:" << argv[1] << std::endl; - return EXIT_FAILURE; - } - - if (!complex.empty() && !(complex.point(Vertex_handle(0)).dimension() == 3)) { - std::cerr << "Only points of dimension 3 are supported." << std::endl; - return EXIT_FAILURE; - } - - std::cout << "Load complex with " << complex.num_vertices() << " vertices" << std::endl; - - int num_contractions = atoi(argv[3]); - - // constructs the contractor object with Garland Heckbert policies. - Complex_contractor contractor(complex, - new GH_cost(complex), - new GH_placement(complex), - Gudhi::contraction::make_link_valid_contraction(), - new GH_visitor(complex)); - - std::cout << "Contract " << num_contractions << " edges" << std::endl; - contractor.contract_edges(num_contractions); - - std::cout << "Final complex has " << - complex.num_vertices() << " vertices, " << - complex.num_edges() << " edges and " << - complex.num_triangles() << " triangles." << std::endl; - - // write simplified complex - Gudhi::skeleton_blocker::Skeleton_blocker_off_writer off_writer(argv[2], complex); - - return EXIT_SUCCESS; -} - -#endif // GARLAND_HECKBERT_H_ - - - - diff --git a/src/Contraction/utilities/Garland_heckbert/Error_quadric.h b/src/Contraction/utilities/Garland_heckbert/Error_quadric.h deleted file mode 100644 index e7dafaa0..00000000 --- a/src/Contraction/utilities/Garland_heckbert/Error_quadric.h +++ /dev/null @@ -1,182 +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): David Salinas - * - * Copyright (C) 2014 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 . - * - */ - -#ifndef GARLAND_HECKBERT_ERROR_QUADRIC_H_ -#define GARLAND_HECKBERT_ERROR_QUADRIC_H_ - -#include - -#include -#include - -template class Error_quadric { - private: - double coeff[10]; - - public: - Error_quadric() { - clear(); - } - - /** - * Quadric corresponding to the L2 distance to the plane. - * - * According to the notation of Garland Heckbert, they - * denote a quadric symetric matrix as : - * Q = [ q11 q12 q13 q14] - * [ q12 q22 q23 q24] - * [ q13 q23 q33 q34] - * [ q14 q24 q34 q44] - * - * which is represented by a vector with 10 elts that - * are denoted ci for clarity with : - * Q = [ c0 c1 c2 c3 ] - * [ c1 c4 c5 c6 ] - * [ c2 c5 c7 c8 ] - * [ c3 c6 c8 c9 ] - * - * The constructor return the quadrics that represents - * the squared distance to the plane defined by triangle p0,p1,p2 - * times the area of triangle p0,p1,p2. - */ - Error_quadric(const Point & p0, const Point & p1, const Point & p2) { - Point normal(unit_normal(p0, p1, p2)); - double a = normal[0]; - double b = normal[1]; - double c = normal[2]; - double d = -a * p0[0] - b * p0[1] - c * p0[2]; - coeff[0] = a*a; - coeff[1] = a*b; - coeff[2] = a*c; - coeff[3] = a*d; - coeff[4] = b*b; - coeff[5] = b*c; - coeff[6] = b*d; - coeff[7] = c*c; - coeff[8] = c*d; - coeff[9] = d*d; - - double area_p0p1p2 = std::sqrt(squared_area(p0, p1, p2)); - for (auto& x : coeff) - x *= area_p0p1p2; - } - - inline double squared_area(const Point& p0, const Point& p1, const Point& p2) { - // if (x1,x2,x3) = p1-p0 and (y1,y2,y3) = p2-p0 - // then the squared area is = (u^2+v^2+w^2)/4 - // with: u = x2 * y3 - x3 * y2; - // v = x3 * y1 - x1 * y3; - // w = x1 * y2 - x2 * y1; - Point p0p1(p1 - p0); - Point p0p2(p2 - p0); - double A = p0p1[1] * p0p2[2] - p0p1[2] * p0p2[1]; - double B = p0p1[2] * p0p2[0] - p0p1[0] * p0p2[2]; - double C = p0p1[0] * p0p2[1] - p0p1[1] * p0p2[0]; - return 1. / 4. * (A * A + B * B + C * C); - } - - void clear() { - for (auto& x : coeff) - x = 0; - } - - Error_quadric& operator+=(const Error_quadric& other) { - if (this != &other) { - for (int i = 0; i < 10; ++i) - coeff[i] += other.coeff[i]; - } - return *this; - } - - /** - * @return The quadric quost defined by the scalar product v^T Q v where Q is the quadratic form of Garland/Heckbert - */ - inline double cost(const Point& point) const { - double cost = - coeff[0] * point.x() * point.x() + coeff[4] * point.y() * point.y() + coeff[7] * point.z() * point.z() - + 2 * (coeff[1] * point.x() * point.y() + coeff[5] * point.y() * point.z() + coeff[2] * point.z() * point.x()) - + 2 * (coeff[3] * point.x() + coeff[6] * point.y() + coeff[8] * point.z()) - + coeff[9]; - if (cost < 0) { - return 0; - } else { - return cost; - } - } - - inline double grad_determinant() const { - return - coeff[0] * coeff[4] * coeff[7] - - coeff[0] * coeff[5] * coeff[5] - - coeff[1] * coeff[1] * coeff[7] - + 2 * coeff[1] * coeff[5] * coeff[2] - - coeff[4] * coeff[2] * coeff[2]; - } - - /** - * Return the point such that it minimizes the gradient of the quadric. - * Det must be passed with the determinant value of the gradient (should be non zero). - */ - inline Point solve_linear_gradient(double det) const { - return Point({ - (-coeff[1] * coeff[5] * coeff[8] + coeff[1] * coeff[7] * coeff[6] + coeff[2] * coeff[8] * coeff[4] - - coeff[2] * coeff[5] * coeff[6] - coeff[3] * coeff[4] * coeff[7] + coeff[3] * coeff[5] * coeff[5]) - / det, - (coeff[0] * coeff[5] * coeff[8] - coeff[0] * coeff[7] * coeff[6] - coeff[5] * coeff[2] * coeff[3] - - coeff[1] * coeff[2] * coeff[8] + coeff[6] * coeff[2] * coeff[2] + coeff[1] * coeff[3] * coeff[7]) - / det, - (-coeff[8] * coeff[0] * coeff[4] + coeff[8] * coeff[1] * coeff[1] + coeff[2] * coeff[3] * coeff[4] + - coeff[5] * coeff[0] * coeff[6] - coeff[5] * coeff[1] * coeff[3] - coeff[1] * coeff[2] * coeff[6]) - / det - }); - } - - /** - * returns the point that minimizes the quadric. - * It inverses the quadric if its determinant is higher that a given threshold . - * If the determinant is lower than this value the returned value is uninitialized. - */ - boost::optional min_cost(double scale = 1) const { - // const double min_determinant = 1e-4 * scale*scale; - const double min_determinant = 1e-5; - boost::optional pt_res; - double det = grad_determinant(); - if (std::abs(det) > min_determinant) - pt_res = solve_linear_gradient(det); - return pt_res; - } - - friend std::ostream& operator<<(std::ostream& stream, const Error_quadric& quadric) { - stream << "\n[ " << quadric.coeff[0] << "," << quadric.coeff[1] << "," << quadric.coeff[2] << "," << - quadric.coeff[3] << ";\n"; - stream << " " << quadric.coeff[1] << "," << quadric.coeff[4] << "," << quadric.coeff[5] << "," << - quadric.coeff[6] << ";\n"; - stream << " " << quadric.coeff[2] << "," << quadric.coeff[5] << "," << quadric.coeff[7] << "," << - quadric.coeff[8] << ";\n"; - stream << " " << quadric.coeff[3] << "," << quadric.coeff[6] << "," << quadric.coeff[8] << "," << - quadric.coeff[9] << "]"; - return stream; - } -}; - -#endif // GARLAND_HECKBERT_ERROR_QUADRIC_H_ -- cgit v1.2.3 From 629542264458d2174ece2c18a490f63d1a231802 Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 26 Oct 2017 15:08:50 +0000 Subject: Fix sentence git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2807 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8d914e747993fc8c1883ee6c0807c3335c816a3e --- src/common/doc/main_page.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h index 466236ad..9071b566 100644 --- a/src/common/doc/main_page.h +++ b/src/common/doc/main_page.h @@ -323,7 +323,7 @@ make doxygen * Eigen3 is a C++ template library for linear algebra: * matrices, vectors, numerical solvers, and related algorithms. * - * The following example requires the Eigen3 and will not be + * The following examples/utilities require the Eigen3 and will not be * built if Eigen3 is not installed: * \li * Alpha_complex/Alpha_complex_from_off.cpp -- cgit v1.2.3 From 8428e315efa22a1b40eb996c98eff671f91a9b27 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 15 Nov 2017 14:20:30 +0000 Subject: Fixes according to Marc's review git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2881 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 84870193cb05cabd8c756a3bbc49083e4d739525 --- src/Alpha_complex/utilities/README | 10 +- src/Bottleneck_distance/example/CMakeLists.txt | 12 +- src/Bottleneck_distance/example/README | 19 +++ .../alpha_rips_persistence_bottleneck_distance.cpp | 190 +++++++++++++++++++++ .../example/bottleneck_read_file_example.cpp | 50 ------ src/Bottleneck_distance/utilities/CMakeLists.txt | 11 +- src/Bottleneck_distance/utilities/README | 19 +-- .../alpha_rips_persistence_bottleneck_distance.cpp | 190 --------------------- .../utilities/bottleneck_read_file_example.cpp | 50 ++++++ src/Rips_complex/utilities/README | 2 +- 10 files changed, 281 insertions(+), 272 deletions(-) create mode 100644 src/Bottleneck_distance/example/README create mode 100644 src/Bottleneck_distance/example/alpha_rips_persistence_bottleneck_distance.cpp delete mode 100644 src/Bottleneck_distance/example/bottleneck_read_file_example.cpp delete mode 100644 src/Bottleneck_distance/utilities/alpha_rips_persistence_bottleneck_distance.cpp create mode 100644 src/Bottleneck_distance/utilities/bottleneck_read_file_example.cpp diff --git a/src/Alpha_complex/utilities/README b/src/Alpha_complex/utilities/README index 30e1b187..abb17bf7 100644 --- a/src/Alpha_complex/utilities/README +++ b/src/Alpha_complex/utilities/README @@ -5,14 +5,14 @@ This program computes the persistent homology with coefficient field Z/pZ of the `p dim b d` -where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers *pi* such that the homology feature exists in homology with *Z/piZ* coefficients). +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p` must be a prime number). **Usage** `alpha_complex_3d_persistence

` where `` is the path to the input point cloud in OFF format. `

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. -`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. It must be a floating-point number >= -1. +`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. **Example** `alpha_complex_3d_persistence ../../data/points/tore3D_300.off 2 0.45` @@ -45,14 +45,14 @@ This program computes the persistent homology with coefficient field Z/pZ of the `p dim b d` -where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers *pi* such that the homology feature exists in homology with *Z/piZ* coefficients). +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p` must be a prime number). **Usage** `periodic_alpha_complex_3d_persistence

` where `` is the path to the input point cloud in OFF format. `

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. -`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. It must be a floating-point number >= -1. +`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. **Example** `periodic_alpha_complex_3d_persistence ../../data/points/grid_10_10_10_in_0_1.off ../../data/points/iso_cuboid_3_in_0_1.txt 3 1.0` @@ -93,7 +93,7 @@ This program computes the persistent homology with coefficient field Z/pZ of the `p dim b d` -where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers pi such that the homology feature exists in homology with Z/piZ coefficients). +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p` must be a prime number). **Usage** `alpha_complex_persistence [options] ` diff --git a/src/Bottleneck_distance/example/CMakeLists.txt b/src/Bottleneck_distance/example/CMakeLists.txt index 6a602dbb..9677f5c5 100644 --- a/src/Bottleneck_distance/example/CMakeLists.txt +++ b/src/Bottleneck_distance/example/CMakeLists.txt @@ -3,15 +3,15 @@ project(Bottleneck_distance_examples) if (NOT CGAL_VERSION VERSION_LESS 4.8.1) add_executable (bottleneck_basic_example bottleneck_basic_example.cpp) - add_executable (bottleneck_read_file_example bottleneck_read_file_example.cpp) + add_executable (alpha_rips_persistence_bottleneck_distance alpha_rips_persistence_bottleneck_distance.cpp) + target_link_libraries(alpha_rips_persistence_bottleneck_distance ${Boost_PROGRAM_OPTIONS_LIBRARY}) add_test(NAME Bottleneck_distance_example_basic COMMAND $) + add_test(NAME Bottleneck_distance_example_alpha_rips_persistence_bottleneck + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.15" "-m" "0.12" "-d" "3" "-p" "3") - add_test(NAME Bottleneck_read_file_example - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers") - - install(TARGETS bottleneck_read_file_example DESTINATION bin) install(TARGETS bottleneck_basic_example DESTINATION bin) + install(TARGETS alpha_rips_persistence_bottleneck_distance DESTINATION bin) endif (NOT CGAL_VERSION VERSION_LESS 4.8.1) diff --git a/src/Bottleneck_distance/example/README b/src/Bottleneck_distance/example/README new file mode 100644 index 00000000..0e314608 --- /dev/null +++ b/src/Bottleneck_distance/example/README @@ -0,0 +1,19 @@ +# Bottleneck_distance # + +## `alpha_rips_persistence_bottleneck_distance` ## +This program computes the persistent homology with coefficient field Z/pZ of a Rips complex defined on a set of input points. The output diagram contains one bar per line, written with the convention: + +`p dim b d` + +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients. + +Usage: +`alpha_rips_persistence_bottleneck_distance [options] ` + +Allowed options: + +* `-h [ --help ]` Produce help message +* `-r [ --max-edge-length ]` (default = inf) Maximal length of an edge for the Rips complex construction.` +* `-d [ --cpx-dimension ]` (default = 1) Maximal dimension of the Rips complex we want to compute.` +* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. diff --git a/src/Bottleneck_distance/example/alpha_rips_persistence_bottleneck_distance.cpp b/src/Bottleneck_distance/example/alpha_rips_persistence_bottleneck_distance.cpp new file mode 100644 index 00000000..fd164b22 --- /dev/null +++ b/src/Bottleneck_distance/example/alpha_rips_persistence_bottleneck_distance.cpp @@ -0,0 +1,190 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2017 INRIA + * + * 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 // infinity +#include // for pair +#include // for transform + + +// Types definition +using Simplex_tree = Gudhi::Simplex_tree; +using Filtration_value = Simplex_tree::Filtration_value; +using Rips_complex = Gudhi::rips_complex::Rips_complex; +using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; +using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; +using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; +using Point_d = Kernel::Point_d; +using Points_off_reader = Gudhi::Points_off_reader; + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +static inline std::pair compute_root_square(std::pair input) { + return std::make_pair(std::sqrt(input.first), std::sqrt(input.second)); +} + +int main(int argc, char * argv[]) { + std::string off_file_points; + Filtration_value threshold; + int dim_max; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, off_file_points, threshold, dim_max, p, min_persistence); + + Points_off_reader off_reader(off_file_points); + + // -------------------------------------------- + // Rips persistence + // -------------------------------------------- + Rips_complex rips_complex(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); + + // Construct the Rips complex in a Simplex Tree + Simplex_tree rips_stree; + + rips_complex.create_complex(rips_stree, dim_max); + std::cout << "The Rips complex contains " << rips_stree.num_simplices() << " simplices and has dimension " + << rips_stree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + rips_stree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology rips_pcoh(rips_stree); + // initializes the coefficient field for homology + rips_pcoh.init_coefficients(p); + rips_pcoh.compute_persistent_cohomology(min_persistence); + + // rips_pcoh.output_diagram(); + + // -------------------------------------------- + // Alpha persistence + // -------------------------------------------- + Gudhi::alpha_complex::Alpha_complex alpha_complex(off_reader.get_point_cloud()); + + Simplex_tree alpha_stree; + alpha_complex.create_complex(alpha_stree, threshold * threshold); + std::cout << "The Alpha complex contains " << alpha_stree.num_simplices() << " simplices and has dimension " + << alpha_stree.dimension() << " \n"; + + // Sort the simplices in the order of the filtration + alpha_stree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology alpha_pcoh(alpha_stree); + // initializes the coefficient field for homology + alpha_pcoh.init_coefficients(p); + alpha_pcoh.compute_persistent_cohomology(min_persistence * min_persistence); + + // alpha_pcoh.output_diagram(); + + // -------------------------------------------- + // Bottleneck distance between both persistence + // -------------------------------------------- + double max_b_distance {}; + for (int dim = 0; dim < dim_max; dim ++) { + std::vector< std::pair< Filtration_value , Filtration_value > > rips_intervals; + std::vector< std::pair< Filtration_value , Filtration_value > > alpha_intervals; + rips_intervals = rips_pcoh.intervals_in_dimension(dim); + alpha_intervals = alpha_pcoh.intervals_in_dimension(dim); + std::transform(alpha_intervals.begin(), alpha_intervals.end(), alpha_intervals.begin(), compute_root_square); + + double bottleneck_distance = Gudhi::persistence_diagram::bottleneck_distance(rips_intervals, alpha_intervals); + std::cout << "In dimension " << dim << ", bottleneck distance = " << bottleneck_distance << std::endl; + if (bottleneck_distance > max_b_distance) + max_b_distance = bottleneck_distance; + } + std::cout << "================================================================================" << std::endl; + std::cout << "Bottleneck distance is " << max_b_distance << std::endl; + + return 0; +} + +void program_options(int argc, char * argv[] + , std::string & off_file_points + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options() + ("input-file", po::value(&off_file_points), + "Name of an OFF file containing a point set.\n"); + + po::options_description visible("Allowed options", 100); + visible.add_options() + ("help,h", "produce help message") + ("max-edge-length,r", + po::value(&threshold)->default_value(std::numeric_limits::infinity()), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv). + options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp deleted file mode 100644 index 24d73c57..00000000 --- a/src/Bottleneck_distance/example/bottleneck_read_file_example.cpp +++ /dev/null @@ -1,50 +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. - * - * Authors: Francois Godi, small modifications by Pawel Dlotko - * - * Copyright (C) 2015 INRIA - * - * 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 // for pair -#include -#include // for numeric_limits - -int main(int argc, char** argv) { - if (argc < 3) { - std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file" << - " should contain a birth-death pair per line. Third, optional parameter is an error bound on a bottleneck" << - " distance (set by default to the smallest positive double value). If you set the error bound to 0, be" << - " aware this version is exact but expensive. The program will now terminate \n"; - return -1; - } - std::vector> diag1 = Gudhi::read_persistence_intervals_in_dimension(argv[1]); - std::vector> diag2 = Gudhi::read_persistence_intervals_in_dimension(argv[2]); - - double tolerance = std::numeric_limits::min(); - if (argc == 4) { - tolerance = atof(argv[3]); - } - double b = Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, tolerance); - std::cout << "The distance between the diagrams is : " << b << ". The tolerance is : " << tolerance << std::endl; - - return 0; -} diff --git a/src/Bottleneck_distance/utilities/CMakeLists.txt b/src/Bottleneck_distance/utilities/CMakeLists.txt index 634b2479..decdc789 100644 --- a/src/Bottleneck_distance/utilities/CMakeLists.txt +++ b/src/Bottleneck_distance/utilities/CMakeLists.txt @@ -2,16 +2,15 @@ cmake_minimum_required(VERSION 2.6) project(Bottleneck_distance_utilities) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) - add_executable (alpha_rips_persistence_bottleneck_distance alpha_rips_persistence_bottleneck_distance.cpp) - target_link_libraries(alpha_rips_persistence_bottleneck_distance ${Boost_PROGRAM_OPTIONS_LIBRARY}) + add_executable (bottleneck_read_file_example bottleneck_read_file_example.cpp) if (TBB_FOUND) target_link_libraries(alpha_rips_persistence_bottleneck_distance ${TBB_LIBRARIES}) endif(TBB_FOUND) - add_test(NAME Bottleneck_distance_example_alpha_rips_persistence_bottleneck - COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_1307.off" "-r" "0.15" "-m" "0.12" "-d" "3" "-p" "3") + add_test(NAME Bottleneck_read_file_example + COMMAND $ + "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers") - install(TARGETS alpha_rips_persistence_bottleneck_distance DESTINATION bin) + install(TARGETS bottleneck_read_file_example DESTINATION bin) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) diff --git a/src/Bottleneck_distance/utilities/README b/src/Bottleneck_distance/utilities/README index 4c9b0735..cfdccf0b 100644 --- a/src/Bottleneck_distance/utilities/README +++ b/src/Bottleneck_distance/utilities/README @@ -1,19 +1,10 @@ # Bottleneck_distance # -## `alpha_rips_persistence_bottleneck_distance` ## -This program computes the persistent homology with coefficient field Z/pZ of a Rips complex defined on a set of input points. The output diagram contains one bar per line, written with the convention: - -`p dim b d` - -where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients. +## `bottleneck_read_file_example` ## +This program computes the Bottleneck distance between two persistence diagram files. Usage: -`alpha_rips_persistence_bottleneck_distance [options] ` - -Allowed options: +`bottleneck_read_file_example []` -* `-h [ --help ]` Produce help message -* `-r [ --max-edge-length ]` (default = inf) Maximal length of an edge for the Rips complex construction.` -* `-d [ --cpx-dimension ]` (default = 1) Maximal dimension of the Rips complex we want to compute.` -* `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. -* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. \ No newline at end of file + and must be in the format described [here](http://gudhi.gforge.inria.fr/doc/latest/fileformats.html#FileFormatsPers). + is an error bound on the bottleneck distance (set by default to the smallest positive double value). diff --git a/src/Bottleneck_distance/utilities/alpha_rips_persistence_bottleneck_distance.cpp b/src/Bottleneck_distance/utilities/alpha_rips_persistence_bottleneck_distance.cpp deleted file mode 100644 index fd164b22..00000000 --- a/src/Bottleneck_distance/utilities/alpha_rips_persistence_bottleneck_distance.cpp +++ /dev/null @@ -1,190 +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): Vincent Rouvreau - * - * Copyright (C) 2017 INRIA - * - * 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 // infinity -#include // for pair -#include // for transform - - -// Types definition -using Simplex_tree = Gudhi::Simplex_tree; -using Filtration_value = Simplex_tree::Filtration_value; -using Rips_complex = Gudhi::rips_complex::Rips_complex; -using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; -using Point_d = Kernel::Point_d; -using Points_off_reader = Gudhi::Points_off_reader; - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence); - -static inline std::pair compute_root_square(std::pair input) { - return std::make_pair(std::sqrt(input.first), std::sqrt(input.second)); -} - -int main(int argc, char * argv[]) { - std::string off_file_points; - Filtration_value threshold; - int dim_max; - int p; - Filtration_value min_persistence; - - program_options(argc, argv, off_file_points, threshold, dim_max, p, min_persistence); - - Points_off_reader off_reader(off_file_points); - - // -------------------------------------------- - // Rips persistence - // -------------------------------------------- - Rips_complex rips_complex(off_reader.get_point_cloud(), threshold, Gudhi::Euclidean_distance()); - - // Construct the Rips complex in a Simplex Tree - Simplex_tree rips_stree; - - rips_complex.create_complex(rips_stree, dim_max); - std::cout << "The Rips complex contains " << rips_stree.num_simplices() << " simplices and has dimension " - << rips_stree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - rips_stree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology rips_pcoh(rips_stree); - // initializes the coefficient field for homology - rips_pcoh.init_coefficients(p); - rips_pcoh.compute_persistent_cohomology(min_persistence); - - // rips_pcoh.output_diagram(); - - // -------------------------------------------- - // Alpha persistence - // -------------------------------------------- - Gudhi::alpha_complex::Alpha_complex alpha_complex(off_reader.get_point_cloud()); - - Simplex_tree alpha_stree; - alpha_complex.create_complex(alpha_stree, threshold * threshold); - std::cout << "The Alpha complex contains " << alpha_stree.num_simplices() << " simplices and has dimension " - << alpha_stree.dimension() << " \n"; - - // Sort the simplices in the order of the filtration - alpha_stree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology alpha_pcoh(alpha_stree); - // initializes the coefficient field for homology - alpha_pcoh.init_coefficients(p); - alpha_pcoh.compute_persistent_cohomology(min_persistence * min_persistence); - - // alpha_pcoh.output_diagram(); - - // -------------------------------------------- - // Bottleneck distance between both persistence - // -------------------------------------------- - double max_b_distance {}; - for (int dim = 0; dim < dim_max; dim ++) { - std::vector< std::pair< Filtration_value , Filtration_value > > rips_intervals; - std::vector< std::pair< Filtration_value , Filtration_value > > alpha_intervals; - rips_intervals = rips_pcoh.intervals_in_dimension(dim); - alpha_intervals = alpha_pcoh.intervals_in_dimension(dim); - std::transform(alpha_intervals.begin(), alpha_intervals.end(), alpha_intervals.begin(), compute_root_square); - - double bottleneck_distance = Gudhi::persistence_diagram::bottleneck_distance(rips_intervals, alpha_intervals); - std::cout << "In dimension " << dim << ", bottleneck distance = " << bottleneck_distance << std::endl; - if (bottleneck_distance > max_b_distance) - max_b_distance = bottleneck_distance; - } - std::cout << "================================================================================" << std::endl; - std::cout << "Bottleneck distance is " << max_b_distance << std::endl; - - return 0; -} - -void program_options(int argc, char * argv[] - , std::string & off_file_points - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence) { - namespace po = boost::program_options; - po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of an OFF file containing a point set.\n"); - - po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("max-edge-length,r", - po::value(&threshold)->default_value(std::numeric_limits::infinity()), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); - - po::positional_options_description pos; - pos.add("input-file", 1); - - po::options_description all; - all.add(visible).add(hidden); - - po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); - po::notify(vm); - - if (vm.count("help") || !vm.count("input-file")) { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); - } -} diff --git a/src/Bottleneck_distance/utilities/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/utilities/bottleneck_read_file_example.cpp new file mode 100644 index 00000000..9dd52b31 --- /dev/null +++ b/src/Bottleneck_distance/utilities/bottleneck_read_file_example.cpp @@ -0,0 +1,50 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Authors: Francois Godi, small modifications by Pawel Dlotko + * + * Copyright (C) 2015 INRIA + * + * 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 // for pair +#include +#include // for numeric_limits + +int main(int argc, char** argv) { + if (argc < 3) { + std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file" << + " should contain a birth-death pair per line. Third, optional parameter is an error bound on the bottleneck" << + " distance (set by default to the smallest positive double value). If you set the error bound to 0, be" << + " aware this version is exact but expensive. The program will now terminate \n"; + return -1; + } + std::vector> diag1 = Gudhi::read_persistence_intervals_in_dimension(argv[1]); + std::vector> diag2 = Gudhi::read_persistence_intervals_in_dimension(argv[2]); + + double tolerance = std::numeric_limits::min(); + if (argc == 4) { + tolerance = atof(argv[3]); + } + double b = Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, tolerance); + std::cout << "The distance between the diagrams is : " << b << ". The tolerance is : " << tolerance << std::endl; + + return 0; +} diff --git a/src/Rips_complex/utilities/README b/src/Rips_complex/utilities/README index ddb7860f..93ec3658 100644 --- a/src/Rips_complex/utilities/README +++ b/src/Rips_complex/utilities/README @@ -5,7 +5,7 @@ This program computes the persistent homology with coefficient field *Z/pZ* of a `p dim b d` -where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p = p1*...*pr` is the product of prime numbers *pi* such that the homology feature exists in homology with *Z/piZ* coefficients). +where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p` must be a prime number). **Usage** `rips_persistence [options] ` -- cgit v1.2.3 From ae41883215cd89e2ca71fd7e2a46b66d5075dc2d Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 15 Nov 2017 14:39:41 +0000 Subject: Add iso-cuboid file format git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2882 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ad82867ef7523c4a03fdb89054e5bd7b8d40f7da --- src/Alpha_complex/utilities/README | 3 ++- src/Bottleneck_distance/utilities/README | 6 +++--- src/common/doc/file_formats.h | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Alpha_complex/utilities/README b/src/Alpha_complex/utilities/README index abb17bf7..67ea1875 100644 --- a/src/Alpha_complex/utilities/README +++ b/src/Alpha_complex/utilities/README @@ -48,9 +48,10 @@ This program computes the persistent homology with coefficient field Z/pZ of the where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p` must be a prime number). **Usage** -`periodic_alpha_complex_3d_persistence

` +`periodic_alpha_complex_3d_persistence

` where `` is the path to the input point cloud in OFF format. +`` is the path to the file describing the periodic domain. It must be in the format described [here](http://gudhi.gforge.inria.fr/doc/latest/fileformats.html#FileFormatsIsoCuboid). `

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. `` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. diff --git a/src/Bottleneck_distance/utilities/README b/src/Bottleneck_distance/utilities/README index cfdccf0b..d9fdd252 100644 --- a/src/Bottleneck_distance/utilities/README +++ b/src/Bottleneck_distance/utilities/README @@ -5,6 +5,6 @@ This program computes the Bottleneck distance between two persistence diagram fi Usage: `bottleneck_read_file_example []` - - and must be in the format described [here](http://gudhi.gforge.inria.fr/doc/latest/fileformats.html#FileFormatsPers). - is an error bound on the bottleneck distance (set by default to the smallest positive double value). +where +`` and `` must be in the format described [here](http://gudhi.gforge.inria.fr/doc/latest/fileformats.html#FileFormatsPers). +`` is an error bound on the bottleneck distance (set by default to the smallest positive double value). diff --git a/src/common/doc/file_formats.h b/src/common/doc/file_formats.h index d715aa4d..3b3d9248 100644 --- a/src/common/doc/file_formats.h +++ b/src/common/doc/file_formats.h @@ -53,6 +53,21 @@ namespace Gudhi { Such files can be generated with `Gudhi::persistent_cohomology::Persistent_cohomology::output_diagram()` and read with `Gudhi::read_persistence_intervals_and_dimension()`, `Gudhi::read_persistence_intervals_grouped_by_dimension()` or `Gudhi::read_persistence_intervals_in_dimension()`. + + + \section FileFormatsIsoCuboid Iso-cuboid + + Such a file describes an iso-oriented cuboid with diagonal opposite vertices (min_hx, min_hy, min_hz,...) and (max_hx, max_hy, max_hz, ...). The format is:
+ \verbatim + min_hx min_hy [min_hz ...] + max_hx max_hy [max_hz ...] + \endverbatim + + Here is a simple sample file in the 3D case: + \verbatim + -1. -1. -1. + 1. 1. 1. + \endverbatim */ } // namespace Gudhi -- cgit v1.2.3 From 048108b77120bf7b607a5093977b1da294bc472b Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 15 Nov 2017 14:50:29 +0000 Subject: Move 2 more examples into utilities git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2883 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b9fd71a4833c84640be2a0f792f1eaea5109874d --- src/Alpha_complex/utilities/CMakeLists.txt | 13 + .../exact_alpha_complex_3d_persistence.cpp | 244 +++++++++++++++++++ .../weighted_alpha_complex_3d_persistence.cpp | 267 +++++++++++++++++++++ src/Persistent_cohomology/example/CMakeLists.txt | 17 -- .../example/exact_alpha_complex_3d_persistence.cpp | 244 ------------------- .../weighted_alpha_complex_3d_persistence.cpp | 267 --------------------- 6 files changed, 524 insertions(+), 528 deletions(-) create mode 100644 src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp create mode 100644 src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp delete mode 100644 src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp delete mode 100644 src/Persistent_cohomology/example/weighted_alpha_complex_3d_persistence.cpp diff --git a/src/Alpha_complex/utilities/CMakeLists.txt b/src/Alpha_complex/utilities/CMakeLists.txt index 69dbc28a..120ca416 100644 --- a/src/Alpha_complex/utilities/CMakeLists.txt +++ b/src/Alpha_complex/utilities/CMakeLists.txt @@ -4,14 +4,27 @@ project(Alpha_complex_utilities) if(CGAL_FOUND) add_executable(alpha_complex_3d_persistence alpha_complex_3d_persistence.cpp) target_link_libraries(alpha_complex_3d_persistence ${CGAL_LIBRARY}) + add_executable(exact_alpha_complex_3d_persistence exact_alpha_complex_3d_persistence.cpp) + target_link_libraries(exact_alpha_complex_3d_persistence ${CGAL_LIBRARY}) + add_executable(weighted_alpha_complex_3d_persistence weighted_alpha_complex_3d_persistence.cpp) + target_link_libraries(weighted_alpha_complex_3d_persistence ${CGAL_LIBRARY}) if (TBB_FOUND) target_link_libraries(alpha_complex_3d_persistence ${TBB_LIBRARIES}) + target_link_libraries(exact_alpha_complex_3d_persistence ${TBB_LIBRARIES}) + target_link_libraries(weighted_alpha_complex_3d_persistence ${TBB_LIBRARIES}) endif(TBB_FOUND) + add_test(NAME Alpha_complex_utilities_alpha_complex_3d_persistence COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") + add_test(NAME Persistent_cohomology_example_exact_alpha_complex_3d COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") + add_test(NAME Persistent_cohomology_example_weighted_alpha_complex_3d COMMAND $ + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.weights" "2" "0.45") install(TARGETS alpha_complex_3d_persistence DESTINATION bin) + install(TARGETS exact_alpha_complex_3d_persistence DESTINATION bin) + install(TARGETS weighted_alpha_complex_3d_persistence DESTINATION bin) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) add_executable (alpha_complex_persistence alpha_complex_persistence.cpp) diff --git a/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp new file mode 100644 index 00000000..8ce68406 --- /dev/null +++ b/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp @@ -0,0 +1,244 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (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 +#include +#include +#include +#include + +#include "../utilities/alpha_complex_3d_helper.h" + +// Alpha_shape_3 templates type definitions +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 +using Point_3 = Kernel::Point_3; + +// filtration with alpha values needed type definition +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 +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:\n" << progName << " path_to_OFF_file coeff_field_characteristic[integer " << + "> 0] min_persistence[float >= -1.0]\n"; + std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; + exit(-1); +} + +int main(int argc, char * const argv[]) { + // program args management + if (argc != 4) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = atoi(argv[2]); + + Filtration_value min_persistence = 0.0; + 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]); + } + + // Read points from file + std::string offInputFile(argv[1]); + // Read the OFF file (input file name given as parameter) and triangulate points + Gudhi::Points_3D_off_reader off_reader(offInputFile); + // Check the read operation was correct + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file " << offInputFile << std::endl; + usage(argv[0]); + } + + // Retrieve the triangulation + std::vector lp = off_reader.get_point_cloud(); + + // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. + Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); +#ifdef DEBUG_TRACES + std::cout << "Alpha shape computed in GENERAL mode" << std::endl; +#endif // DEBUG_TRACES + + // filtration with alpha values from alpha shape + std::vector the_objects; + std::vector the_alpha_values; + + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); + + as.filtration_with_alpha_values(disp); +#ifdef DEBUG_TRACES + std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; +#endif // DEBUG_TRACES + + Alpha_shape_3::size_type count_vertices = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; + + // Loop on objects vector + Vertex_list vertex_list; + ST simplex_tree; + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; + std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); + int dim_max = 0; + Filtration_value filtration_max = 0.0; + 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(*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(*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(*edge); + count_edges++; + if (dim_max < 1) { + // Edge_3 is of dim 1 + dim_max = 1; + } + } else if (const Vertex_handle * vertex = CGAL::object_cast(&object_iterator)) { + count_vertices++; + 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; + for (auto the_alpha_shape_vertex : vertex_list) { + Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); + if (the_map_iterator == map_cgal_simplex_tree.end()) { + // alpha shape not found + Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { + // alpha shape found + Simplex_tree_vertex vertex = the_map_iterator->second; +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + } + } + // Construction of the simplex_tree + // 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 + if (filtr > filtration_max) { + filtration_max = filtr; + } + simplex_tree.insert_simplex(the_simplex_tree, filtr); + if (the_alpha_value_iterator != the_alpha_values.end()) + ++the_alpha_value_iterator; + else + std::cout << "This shall not happen" << std::endl; + } + simplex_tree.set_dimension(dim_max); + +#ifdef DEBUG_TRACES + std::cout << "vertices \t\t" << count_vertices << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; + + + std::cout << "Information of the Simplex Tree: " << std::endl; + std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; + std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; + std::cout << " Dimension = " << simplex_tree.dimension() << " "; +#endif // DEBUG_TRACES + +#ifdef DEBUG_TRACES + std::cout << "Iterator on vertices: " << std::endl; + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; + // Compute the persistence diagram of the complex + PCOH pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + pcoh.output_diagram(); + + return 0; +} diff --git a/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp new file mode 100644 index 00000000..a4ecf9da --- /dev/null +++ b/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp @@ -0,0 +1,267 @@ +/* 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): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "../utilities/alpha_complex_3d_helper.h" + +// Traits +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Gt = CGAL::Regular_triangulation_euclidean_traits_3; +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::Regular_triangulation_3; +using Alpha_shape_3 = CGAL::Alpha_shape_3; + +// From file type definition +using Point_3 = Gt::Bare_point; +using Weighted_point_3 = Gt::Weighted_point; + +// filtration with alpha values needed type definition +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 +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 Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< + ST, Gudhi::persistent_cohomology::Field_Zp >; + +void usage(char * const progName) { + std::cerr << "Usage:\n" << progName << " path_to_OFF_file path_to_weight_file coeff_field_characteristic[integer " << + "> 0] min_persistence[float >= -1.0]\n"; + std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; + std::cerr << " path_to_weight_file is the path to the weights of your points cloud (one value per line.)\n"; + std::cerr << " Weights values are explained on CGAL documentation:\n"; + std::cerr << " https://doc.cgal.org/latest/Alpha_shapes_3/index.html#title0\n"; + std::cerr << " https://doc.cgal.org/latest/Triangulation_3/index.html#Triangulation3secclassRegulartriangulation\n"; + exit(-1); +} + +int main(int argc, char * const argv[]) { + // program args management + if (argc != 5) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = atoi(argv[3]); + Filtration_value min_persistence = strtof(argv[4], nullptr); + + // Read points from file + std::string offInputFile(argv[1]); + // Read the OFF file (input file name given as parameter) and triangulate points + Gudhi::Points_3D_off_reader off_reader(offInputFile); + // Check the read operation was correct + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file " << offInputFile << std::endl; + usage(argv[0]); + } + + // Retrieve the triangulation + std::vector lp = off_reader.get_point_cloud(); + + // Read weights information from file + std::ifstream weights_ifstr(argv[2]); + std::vector wp; + if (weights_ifstr.good()) { + double weight = 0.0; + std::size_t index = 0; + wp.reserve(lp.size()); + // Attempt read the weight in a double format, return false if it fails + while ((weights_ifstr >> weight) && (index < lp.size())) { + wp.push_back(Weighted_point_3(lp[index], weight)); + index++; + } + if (index != lp.size()) { + std::cerr << "Bad number of weights in file " << argv[2] << std::endl; + usage(argv[0]); + } + } else { + std::cerr << "Unable to read file " << argv[2] << std::endl; + usage(argv[0]); + } + + // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. + Alpha_shape_3 as(wp.begin(), wp.end(), 0, Alpha_shape_3::GENERAL); +#ifdef DEBUG_TRACES + std::cout << "Alpha shape computed in GENERAL mode" << std::endl; +#endif // DEBUG_TRACES + + // filtration with alpha values from alpha shape + std::vector the_objects; + std::vector the_alpha_values; + + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); + + as.filtration_with_alpha_values(disp); +#ifdef DEBUG_TRACES + std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; +#endif // DEBUG_TRACES + + Alpha_shape_3::size_type count_vertices = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; + + // Loop on objects vector + Vertex_list vertex_list; + ST simplex_tree; + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; + std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); + int dim_max = 0; + Filtration_value filtration_max = 0.0; + 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(*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(*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(*edge); + count_edges++; + if (dim_max < 1) { + // Edge_3 is of dim 1 + dim_max = 1; + } + } else if (const Alpha_shape_3::Vertex_handle * vertex = + CGAL::object_cast(&object_iterator)) { + count_vertices++; + 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; + for (auto the_alpha_shape_vertex : vertex_list) { + Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); + if (the_map_iterator == map_cgal_simplex_tree.end()) { + // alpha shape not found + Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { + // alpha shape found + Simplex_tree_vertex vertex = the_map_iterator->second; +#ifdef DEBUG_TRACES + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + } + } + // Construction of the simplex_tree + Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); +#ifdef DEBUG_TRACES + std::cout << "filtration = " << filtr << std::endl; +#endif // DEBUG_TRACES + if (filtr > filtration_max) { + filtration_max = filtr; + } + simplex_tree.insert_simplex(the_simplex_tree, filtr); + if (the_alpha_value_iterator != the_alpha_values.end()) + ++the_alpha_value_iterator; + else + std::cout << "This shall not happen" << std::endl; + } + simplex_tree.set_dimension(dim_max); + +#ifdef DEBUG_TRACES + std::cout << "vertices \t\t" << count_vertices << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; + + + std::cout << "Information of the Simplex Tree: " << std::endl; + std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; + std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; + std::cout << " Dimension = " << simplex_tree.dimension() << " "; +#endif // DEBUG_TRACES + +#ifdef DEBUG_TRACES + std::cout << "Iterator on vertices: " << std::endl; + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; + // Compute the persistence diagram of the complex + Persistent_cohomology pcoh(simplex_tree, true); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); + + pcoh.compute_persistent_cohomology(min_persistence); + + pcoh.output_diagram(); + + return 0; +} diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index 98ed753d..18e2913b 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -55,23 +55,6 @@ if(GMP_FOUND) endif(GMP_FOUND) if(CGAL_FOUND) - add_executable(exact_alpha_complex_3d_persistence exact_alpha_complex_3d_persistence.cpp) - target_link_libraries(exact_alpha_complex_3d_persistence ${CGAL_LIBRARY}) - add_executable(weighted_alpha_complex_3d_persistence weighted_alpha_complex_3d_persistence.cpp) - target_link_libraries(weighted_alpha_complex_3d_persistence ${CGAL_LIBRARY}) - - if (TBB_FOUND) - target_link_libraries(exact_alpha_complex_3d_persistence ${TBB_LIBRARIES}) - target_link_libraries(weighted_alpha_complex_3d_persistence ${TBB_LIBRARIES}) - endif(TBB_FOUND) - add_test(NAME Persistent_cohomology_example_exact_alpha_complex_3d COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") - add_test(NAME Persistent_cohomology_example_weighted_alpha_complex_3d COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.weights" "2" "0.45") - - install(TARGETS exact_alpha_complex_3d_persistence DESTINATION bin) - install(TARGETS weighted_alpha_complex_3d_persistence DESTINATION bin) - if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) add_executable(custom_persistence_sort custom_persistence_sort.cpp) target_link_libraries(custom_persistence_sort ${CGAL_LIBRARY}) diff --git a/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp deleted file mode 100644 index 8ce68406..00000000 --- a/src/Persistent_cohomology/example/exact_alpha_complex_3d_persistence.cpp +++ /dev/null @@ -1,244 +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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (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 -#include -#include -#include -#include - -#include "../utilities/alpha_complex_3d_helper.h" - -// Alpha_shape_3 templates type definitions -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 -using Point_3 = Kernel::Point_3; - -// filtration with alpha values needed type definition -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 -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:\n" << progName << " path_to_OFF_file coeff_field_characteristic[integer " << - "> 0] min_persistence[float >= -1.0]\n"; - std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; - exit(-1); -} - -int main(int argc, char * const argv[]) { - // program args management - if (argc != 4) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - - int coeff_field_characteristic = atoi(argv[2]); - - Filtration_value min_persistence = 0.0; - 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]); - } - - // Read points from file - std::string offInputFile(argv[1]); - // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); - // Check the read operation was correct - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); - } - - // Retrieve the triangulation - std::vector lp = off_reader.get_point_cloud(); - - // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. - Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); -#ifdef DEBUG_TRACES - std::cout << "Alpha shape computed in GENERAL mode" << std::endl; -#endif // DEBUG_TRACES - - // filtration with alpha values from alpha shape - std::vector the_objects; - std::vector the_alpha_values; - - Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), - std::back_inserter(the_alpha_values)); - - as.filtration_with_alpha_values(disp); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - - Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; - - // Loop on objects vector - Vertex_list vertex_list; - ST simplex_tree; - Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max = 0; - Filtration_value filtration_max = 0.0; - 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(*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(*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(*edge); - count_edges++; - if (dim_max < 1) { - // Edge_3 is of dim 1 - dim_max = 1; - } - } else if (const Vertex_handle * vertex = CGAL::object_cast(&object_iterator)) { - count_vertices++; - 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; - for (auto the_alpha_shape_vertex : vertex_list) { - Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) { - // alpha shape not found - Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); - } else { - // alpha shape found - Simplex_tree_vertex vertex = the_map_iterator->second; -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - } - } - // Construction of the simplex_tree - // 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 - if (filtr > filtration_max) { - filtration_max = filtr; - } - simplex_tree.insert_simplex(the_simplex_tree, filtr); - if (the_alpha_value_iterator != the_alpha_values.end()) - ++the_alpha_value_iterator; - else - std::cout << "This shall not happen" << std::endl; - } - simplex_tree.set_dimension(dim_max); - -#ifdef DEBUG_TRACES - std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; - - - std::cout << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; - std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; - std::cout << " Dimension = " << simplex_tree.dimension() << " "; -#endif // DEBUG_TRACES - -#ifdef DEBUG_TRACES - std::cout << "Iterator on vertices: " << std::endl; - for (auto vertex : simplex_tree.complex_vertex_range()) { - std::cout << vertex << " "; - } -#endif // DEBUG_TRACES - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; - // Compute the persistence diagram of the complex - PCOH pcoh(simplex_tree); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - pcoh.output_diagram(); - - return 0; -} diff --git a/src/Persistent_cohomology/example/weighted_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/weighted_alpha_complex_3d_persistence.cpp deleted file mode 100644 index a4ecf9da..00000000 --- a/src/Persistent_cohomology/example/weighted_alpha_complex_3d_persistence.cpp +++ /dev/null @@ -1,267 +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): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA - * - * 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 -#include -#include -#include -#include -#include -#include - -#include "../utilities/alpha_complex_3d_helper.h" - -// Traits -using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; -using Gt = CGAL::Regular_triangulation_euclidean_traits_3; -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::Regular_triangulation_3; -using Alpha_shape_3 = CGAL::Alpha_shape_3; - -// From file type definition -using Point_3 = Gt::Bare_point; -using Weighted_point_3 = Gt::Weighted_point; - -// filtration with alpha values needed type definition -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 -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 Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< - ST, Gudhi::persistent_cohomology::Field_Zp >; - -void usage(char * const progName) { - std::cerr << "Usage:\n" << progName << " path_to_OFF_file path_to_weight_file coeff_field_characteristic[integer " << - "> 0] min_persistence[float >= -1.0]\n"; - std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; - std::cerr << " path_to_weight_file is the path to the weights of your points cloud (one value per line.)\n"; - std::cerr << " Weights values are explained on CGAL documentation:\n"; - std::cerr << " https://doc.cgal.org/latest/Alpha_shapes_3/index.html#title0\n"; - std::cerr << " https://doc.cgal.org/latest/Triangulation_3/index.html#Triangulation3secclassRegulartriangulation\n"; - exit(-1); -} - -int main(int argc, char * const argv[]) { - // program args management - if (argc != 5) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - - int coeff_field_characteristic = atoi(argv[3]); - Filtration_value min_persistence = strtof(argv[4], nullptr); - - // Read points from file - std::string offInputFile(argv[1]); - // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); - // Check the read operation was correct - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); - } - - // Retrieve the triangulation - std::vector lp = off_reader.get_point_cloud(); - - // Read weights information from file - std::ifstream weights_ifstr(argv[2]); - std::vector wp; - if (weights_ifstr.good()) { - double weight = 0.0; - std::size_t index = 0; - wp.reserve(lp.size()); - // Attempt read the weight in a double format, return false if it fails - while ((weights_ifstr >> weight) && (index < lp.size())) { - wp.push_back(Weighted_point_3(lp[index], weight)); - index++; - } - if (index != lp.size()) { - std::cerr << "Bad number of weights in file " << argv[2] << std::endl; - usage(argv[0]); - } - } else { - std::cerr << "Unable to read file " << argv[2] << std::endl; - usage(argv[0]); - } - - // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. - Alpha_shape_3 as(wp.begin(), wp.end(), 0, Alpha_shape_3::GENERAL); -#ifdef DEBUG_TRACES - std::cout << "Alpha shape computed in GENERAL mode" << std::endl; -#endif // DEBUG_TRACES - - // filtration with alpha values from alpha shape - std::vector the_objects; - std::vector the_alpha_values; - - Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), - std::back_inserter(the_alpha_values)); - - as.filtration_with_alpha_values(disp); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - - Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; - - // Loop on objects vector - Vertex_list vertex_list; - ST simplex_tree; - Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max = 0; - Filtration_value filtration_max = 0.0; - 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(*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(*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(*edge); - count_edges++; - if (dim_max < 1) { - // Edge_3 is of dim 1 - dim_max = 1; - } - } else if (const Alpha_shape_3::Vertex_handle * vertex = - CGAL::object_cast(&object_iterator)) { - count_vertices++; - 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; - for (auto the_alpha_shape_vertex : vertex_list) { - Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) { - // alpha shape not found - Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); - } else { - // alpha shape found - Simplex_tree_vertex vertex = the_map_iterator->second; -#ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES - the_simplex_tree.push_back(vertex); - } - } - // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); -#ifdef DEBUG_TRACES - std::cout << "filtration = " << filtr << std::endl; -#endif // DEBUG_TRACES - if (filtr > filtration_max) { - filtration_max = filtr; - } - simplex_tree.insert_simplex(the_simplex_tree, filtr); - if (the_alpha_value_iterator != the_alpha_values.end()) - ++the_alpha_value_iterator; - else - std::cout << "This shall not happen" << std::endl; - } - simplex_tree.set_dimension(dim_max); - -#ifdef DEBUG_TRACES - std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; - - - std::cout << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; - std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; - std::cout << " Dimension = " << simplex_tree.dimension() << " "; -#endif // DEBUG_TRACES - -#ifdef DEBUG_TRACES - std::cout << "Iterator on vertices: " << std::endl; - for (auto vertex : simplex_tree.complex_vertex_range()) { - std::cout << vertex << " "; - } -#endif // DEBUG_TRACES - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; - // Compute the persistence diagram of the complex - Persistent_cohomology pcoh(simplex_tree, true); - // initializes the coefficient field for homology - pcoh.init_coefficients(coeff_field_characteristic); - - pcoh.compute_persistent_cohomology(min_persistence); - - pcoh.output_diagram(); - - return 0; -} -- cgit v1.2.3 From 6dbf0ab8f84fd57d4fb80cd3c1bcf0aca6f0bb05 Mon Sep 17 00:00:00 2001 From: cjamin Date: Wed, 15 Nov 2017 15:57:48 +0000 Subject: Doc git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2884 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c5e0a65a484a71d8a9fc1fc2b695dd20a367fd0c --- src/Alpha_complex/utilities/CMakeLists.txt | 4 +- src/Alpha_complex/utilities/README | 17 ++++++++ src/Bottleneck_distance/example/CMakeLists.txt | 4 ++ src/Bottleneck_distance/utilities/CMakeLists.txt | 11 ++--- .../utilities/bottleneck_read_file.cpp | 50 ++++++++++++++++++++++ .../utilities/bottleneck_read_file_example.cpp | 50 ---------------------- 6 files changed, 77 insertions(+), 59 deletions(-) create mode 100644 src/Bottleneck_distance/utilities/bottleneck_read_file.cpp delete mode 100644 src/Bottleneck_distance/utilities/bottleneck_read_file_example.cpp diff --git a/src/Alpha_complex/utilities/CMakeLists.txt b/src/Alpha_complex/utilities/CMakeLists.txt index 120ca416..18699650 100644 --- a/src/Alpha_complex/utilities/CMakeLists.txt +++ b/src/Alpha_complex/utilities/CMakeLists.txt @@ -17,9 +17,9 @@ if(CGAL_FOUND) add_test(NAME Alpha_complex_utilities_alpha_complex_3d_persistence COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") - add_test(NAME Persistent_cohomology_example_exact_alpha_complex_3d COMMAND $ + add_test(NAME Alpha_complex_utilities_exact_alpha_complex_3d COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") - add_test(NAME Persistent_cohomology_example_weighted_alpha_complex_3d COMMAND $ + add_test(NAME Alpha_complex_utilities_weighted_alpha_complex_3d COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.weights" "2" "0.45") install(TARGETS alpha_complex_3d_persistence DESTINATION bin) diff --git a/src/Alpha_complex/utilities/README b/src/Alpha_complex/utilities/README index 67ea1875..6e7d16b7 100644 --- a/src/Alpha_complex/utilities/README +++ b/src/Alpha_complex/utilities/README @@ -39,6 +39,23 @@ N.B.: +## `exact_alpha_complex_3d_persistence` ## +Same as `alpha_complex_3d_persistence`, but using exact computation. It is slower, but it is necessary when points are on a grid for instance. + + + +## `weighted_alpha_complex_3d_persistence` ## +Same as `alpha_complex_3d_persistence`, but using weighted points. + +**Usage** +`weighted_alpha_complex_3d_persistence

` +where +`` is the path to the input point cloud in OFF format. +`` is the path to the file containing the weights of the points (one value per line). +`

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. +`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. + + ## `periodic_alpha_complex_3d_persistence` ## This program computes the persistent homology with coefficient field Z/pZ of the 3D periodic alpha complex built from a 3D point cloud. The output diagram contains one bar per line, written with the convention: diff --git a/src/Bottleneck_distance/example/CMakeLists.txt b/src/Bottleneck_distance/example/CMakeLists.txt index 9677f5c5..2ae45dc5 100644 --- a/src/Bottleneck_distance/example/CMakeLists.txt +++ b/src/Bottleneck_distance/example/CMakeLists.txt @@ -6,6 +6,10 @@ if (NOT CGAL_VERSION VERSION_LESS 4.8.1) add_executable (alpha_rips_persistence_bottleneck_distance alpha_rips_persistence_bottleneck_distance.cpp) target_link_libraries(alpha_rips_persistence_bottleneck_distance ${Boost_PROGRAM_OPTIONS_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(alpha_rips_persistence_bottleneck_distance ${TBB_LIBRARIES}) + endif(TBB_FOUND) + add_test(NAME Bottleneck_distance_example_basic COMMAND $) add_test(NAME Bottleneck_distance_example_alpha_rips_persistence_bottleneck COMMAND $ diff --git a/src/Bottleneck_distance/utilities/CMakeLists.txt b/src/Bottleneck_distance/utilities/CMakeLists.txt index decdc789..cdf76c85 100644 --- a/src/Bottleneck_distance/utilities/CMakeLists.txt +++ b/src/Bottleneck_distance/utilities/CMakeLists.txt @@ -2,15 +2,12 @@ cmake_minimum_required(VERSION 2.6) project(Bottleneck_distance_utilities) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) - add_executable (bottleneck_read_file_example bottleneck_read_file_example.cpp) - if (TBB_FOUND) - target_link_libraries(alpha_rips_persistence_bottleneck_distance ${TBB_LIBRARIES}) - endif(TBB_FOUND) + add_executable (bottleneck_read_file bottleneck_read_file.cpp) - add_test(NAME Bottleneck_read_file_example - COMMAND $ + add_test(NAME Bottleneck_distance_utilities_Bottleneck_read_file + COMMAND $ "${CMAKE_SOURCE_DIR}/data/persistence_diagram/first.pers" "${CMAKE_SOURCE_DIR}/data/persistence_diagram/second.pers") - install(TARGETS bottleneck_read_file_example DESTINATION bin) + install(TARGETS bottleneck_read_file DESTINATION bin) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) diff --git a/src/Bottleneck_distance/utilities/bottleneck_read_file.cpp b/src/Bottleneck_distance/utilities/bottleneck_read_file.cpp new file mode 100644 index 00000000..9dd52b31 --- /dev/null +++ b/src/Bottleneck_distance/utilities/bottleneck_read_file.cpp @@ -0,0 +1,50 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Authors: Francois Godi, small modifications by Pawel Dlotko + * + * Copyright (C) 2015 INRIA + * + * 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 // for pair +#include +#include // for numeric_limits + +int main(int argc, char** argv) { + if (argc < 3) { + std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file" << + " should contain a birth-death pair per line. Third, optional parameter is an error bound on the bottleneck" << + " distance (set by default to the smallest positive double value). If you set the error bound to 0, be" << + " aware this version is exact but expensive. The program will now terminate \n"; + return -1; + } + std::vector> diag1 = Gudhi::read_persistence_intervals_in_dimension(argv[1]); + std::vector> diag2 = Gudhi::read_persistence_intervals_in_dimension(argv[2]); + + double tolerance = std::numeric_limits::min(); + if (argc == 4) { + tolerance = atof(argv[3]); + } + double b = Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, tolerance); + std::cout << "The distance between the diagrams is : " << b << ". The tolerance is : " << tolerance << std::endl; + + return 0; +} diff --git a/src/Bottleneck_distance/utilities/bottleneck_read_file_example.cpp b/src/Bottleneck_distance/utilities/bottleneck_read_file_example.cpp deleted file mode 100644 index 9dd52b31..00000000 --- a/src/Bottleneck_distance/utilities/bottleneck_read_file_example.cpp +++ /dev/null @@ -1,50 +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. - * - * Authors: Francois Godi, small modifications by Pawel Dlotko - * - * Copyright (C) 2015 INRIA - * - * 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 // for pair -#include -#include // for numeric_limits - -int main(int argc, char** argv) { - if (argc < 3) { - std::cout << "To run this program please provide as an input two files with persistence diagrams. Each file" << - " should contain a birth-death pair per line. Third, optional parameter is an error bound on the bottleneck" << - " distance (set by default to the smallest positive double value). If you set the error bound to 0, be" << - " aware this version is exact but expensive. The program will now terminate \n"; - return -1; - } - std::vector> diag1 = Gudhi::read_persistence_intervals_in_dimension(argv[1]); - std::vector> diag2 = Gudhi::read_persistence_intervals_in_dimension(argv[2]); - - double tolerance = std::numeric_limits::min(); - if (argc == 4) { - tolerance = atof(argv[3]); - } - double b = Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, tolerance); - std::cout << "The distance between the diagrams is : " << b << ". The tolerance is : " << tolerance << std::endl; - - return 0; -} -- cgit v1.2.3 From aafe601c247c78a474c6af110ca5b34540a34f44 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 16 Nov 2017 08:31:26 +0000 Subject: Code review : Homogenize alpha shape examples command line git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2887 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8c692434eb48c525047bc34a6fab7d7c1af64d56 --- src/Alpha_complex/utilities/CMakeLists.txt | 19 ++- src/Alpha_complex/utilities/README | 89 +++++++++------ .../utilities/alpha_complex_3d_helper.h | 8 +- .../utilities/alpha_complex_3d_persistence.cpp | 115 ++++++++++++------- .../utilities/alpha_complex_persistence.cpp | 63 +++++----- .../exact_alpha_complex_3d_persistence.cpp | 107 ++++++++++------- .../periodic_alpha_complex_3d_persistence.cpp | 124 ++++++++++++-------- .../weighted_alpha_complex_3d_persistence.cpp | 127 +++++++++++++-------- src/Bottleneck_distance/utilities/CMakeLists.txt | 3 + src/Rips_complex/utilities/README | 3 +- 10 files changed, 406 insertions(+), 252 deletions(-) diff --git a/src/Alpha_complex/utilities/CMakeLists.txt b/src/Alpha_complex/utilities/CMakeLists.txt index 18699650..cefc1ad6 100644 --- a/src/Alpha_complex/utilities/CMakeLists.txt +++ b/src/Alpha_complex/utilities/CMakeLists.txt @@ -3,11 +3,11 @@ project(Alpha_complex_utilities) if(CGAL_FOUND) add_executable(alpha_complex_3d_persistence alpha_complex_3d_persistence.cpp) - target_link_libraries(alpha_complex_3d_persistence ${CGAL_LIBRARY}) + target_link_libraries(alpha_complex_3d_persistence ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) add_executable(exact_alpha_complex_3d_persistence exact_alpha_complex_3d_persistence.cpp) - target_link_libraries(exact_alpha_complex_3d_persistence ${CGAL_LIBRARY}) + target_link_libraries(exact_alpha_complex_3d_persistence ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) add_executable(weighted_alpha_complex_3d_persistence weighted_alpha_complex_3d_persistence.cpp) - target_link_libraries(weighted_alpha_complex_3d_persistence ${CGAL_LIBRARY}) + target_link_libraries(weighted_alpha_complex_3d_persistence ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) if (TBB_FOUND) target_link_libraries(alpha_complex_3d_persistence ${TBB_LIBRARIES}) @@ -16,11 +16,11 @@ if(CGAL_FOUND) endif(TBB_FOUND) add_test(NAME Alpha_complex_utilities_alpha_complex_3d_persistence COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "-p" "2" "-m" "0.45") add_test(NAME Alpha_complex_utilities_exact_alpha_complex_3d COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "2" "0.45") + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "-p" "2" "-m" "0.45") add_test(NAME Alpha_complex_utilities_weighted_alpha_complex_3d COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.weights" "2" "0.45") + "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.weights" "-p" "2" "-m" "0.45") install(TARGETS alpha_complex_3d_persistence DESTINATION bin) install(TARGETS exact_alpha_complex_3d_persistence DESTINATION bin) @@ -28,11 +28,10 @@ if(CGAL_FOUND) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) add_executable (alpha_complex_persistence alpha_complex_persistence.cpp) - target_link_libraries(alpha_complex_persistence - ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) + target_link_libraries(alpha_complex_persistence ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) add_executable(periodic_alpha_complex_3d_persistence periodic_alpha_complex_3d_persistence.cpp) - target_link_libraries(periodic_alpha_complex_3d_persistence ${CGAL_LIBRARY}) + target_link_libraries(periodic_alpha_complex_3d_persistence ${CGAL_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) if (TBB_FOUND) target_link_libraries(alpha_complex_persistence ${TBB_LIBRARIES}) @@ -41,7 +40,7 @@ if(CGAL_FOUND) add_test(NAME Alpha_complex_utilities_alpha_complex_persistence COMMAND $ "${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off" "-p" "2" "-m" "0.45") add_test(NAME Alpha_complex_utilities_periodic_alpha_complex_3d_persistence COMMAND $ - "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off" "${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt" "2" "0") + "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off" "${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt" "-p" "2" "-m" "0") install(TARGETS alpha_complex_persistence DESTINATION bin) install(TARGETS periodic_alpha_complex_3d_persistence DESTINATION bin) diff --git a/src/Alpha_complex/utilities/README b/src/Alpha_complex/utilities/README index 6e7d16b7..c3dd170b 100644 --- a/src/Alpha_complex/utilities/README +++ b/src/Alpha_complex/utilities/README @@ -8,22 +8,24 @@ This program computes the persistent homology with coefficient field Z/pZ of the where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p` must be a prime number). **Usage** -`alpha_complex_3d_persistence

` -where -`` is the path to the input point cloud in OFF format. -`

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. -`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. +`alpha_complex_3d_persistence [options] ` + +**Allowed options** +* `-h [ --help ]` Produce help message +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. Default print in standard output. +* `-p [ --field-charac ]` (default=11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. **Example** -`alpha_complex_3d_persistence ../../data/points/tore3D_300.off 2 0.45` +`alpha_complex_3d_persistence ../../data/points/tore3D_300.off -p 2 -m 0.45` outputs: ``` 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 +2 0 0 inf +2 1 0.0682162 1.0001 +2 1 0.0934117 1.00003 +2 2 0.56444 1.03938 ``` Here we retrieve expected Betti numbers on a tore 3D: @@ -48,21 +50,34 @@ Same as `alpha_complex_3d_persistence`, but using exact computation. It is slowe Same as `alpha_complex_3d_persistence`, but using weighted points. **Usage** -`weighted_alpha_complex_3d_persistence

` -where -`` is the path to the input point cloud in OFF format. -`` is the path to the file containing the weights of the points (one value per line). -`

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. -`` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. +`weighted_alpha_complex_3d_persistence [options] ` +**Allowed options** +* `-h [ --help ]` Produce help message +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. Default print in standard output. +* `-p [ --field-charac ]` (default=11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. +**Example** +`weighted_alpha_complex_3d_persistence ../../data/points/tore3D_300.off ../../data/points/tore3D_300.weights -p 2 -m 0.45` -## `periodic_alpha_complex_3d_persistence` ## -This program computes the persistent homology with coefficient field Z/pZ of the 3D periodic alpha complex built from a 3D point cloud. The output diagram contains one bar per line, written with the convention: +outputs: +``` +Simplex_tree dim: 3 +2 0 -1 inf +2 1 -0.931784 0.000103311 +2 1 -0.906588 2.60165e-05 +2 2 -0.43556 0.0393798 +``` -`p dim b d` +N.B.: +* Weights values are explained on CGAL [Alpha shape](https://doc.cgal.org/latest/Alpha_shapes_3/index.html#title0) +and [Regular triangulation](https://doc.cgal.org/latest/Triangulation_3/index.html#Triangulation3secclassRegulartriangulation) documentation. +* Filtration values are alpha square values. -where `dim` is the dimension of the homological feature, `b` and `d` are respectively the birth and death of the feature, and `p` is the characteristic of the field *Z/pZ* used for homology coefficients (`p` must be a prime number). + +## `periodic_alpha_complex_3d_persistence` ## +Same as `alpha_complex_3d_persistence`, but using periodic alpha shape 3d. **Usage** `periodic_alpha_complex_3d_persistence

` @@ -72,21 +87,31 @@ where `

` is the characteristic p of the coefficient field *Z/pZ* for computing homology. It must be a stricly positive integer. `` is the minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. +**Usage** +`./periodic_alpha_complex_3d_persistence [options] input-file cuboid-file` + +**Allowed options** +* `-h [ --help ]` Produce help message +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. Default print in standard output. +* `-p [ --field-charac ]` (default=11) Characteristic p of the coefficient field Z/pZ for computing homology. +* `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals + + **Example** -`periodic_alpha_complex_3d_persistence ../../data/points/grid_10_10_10_in_0_1.off ../../data/points/iso_cuboid_3_in_0_1.txt 3 1.0` +`periodic_alpha_complex_3d_persistence ../../data/points/grid_10_10_10_in_0_1.off ../../data/points/iso_cuboid_3_in_0_1.txt -p 3 -m 1.0` outputs: ``` Periodic Delaunay computed. Simplex_tree dim: 3 -3 0 0 inf -3 1 0.0025 inf -3 1 0.0025 inf -3 1 0.0025 inf -3 2 0.005 inf -3 2 0.005 inf -3 2 0.005 inf -3 3 0.0075 inf +3 0 0 inf +3 1 0.0025 inf +3 1 0.0025 inf +3 1 0.0025 inf +3 2 0.005 inf +3 2 0.005 inf +3 2 0.005 inf +3 3 0.0075 inf ``` Here we retrieve expected Betti numbers on an 3D iso-oriented cuboids: @@ -98,14 +123,12 @@ Betti numbers[3] = 1 ``` N.B.: -* `periodic_alpha_complex_3d_persistence` only accepts OFF files in dimension 3. -* In this example, the periodic cube is hard coded to { x = [0,1]; y = [0,1]; z = [0,1] } +* Cuboid file must be in the format described [here](http://gudhi.gforge.inria.fr/doc/latest/fileformats.html#FileFormatsIsoCuboid). * Filtration values are alpha square values. - ## `alpha_complex_persistence` ## This program computes the persistent homology with coefficient field Z/pZ of the dD alpha complex built from a dD point cloud. The output diagram contains one bar per line, written with the convention: @@ -119,7 +142,7 @@ where `dim` is the dimension of the homological feature, `b` and `d` are respect **Allowed options** * `-h [ --help ]` Produce help message -* `-o [ --output-file ]` Name of file in which the persistence diagram is written. By default, print in std::cout. +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. Default print in standard output. * `-r [ --max-alpha-square-value ]` (default = inf) Maximal alpha square value for the Alpha complex construction. * `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. * `-m [ --min-persistence ]` (default = 0) Minimal lifetime of homology feature to be recorded. Enter a negative value to see zero length intervals. diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_helper.h b/src/Alpha_complex/utilities/alpha_complex_3d_helper.h index 7865e4ec..6b3b7d5d 100644 --- a/src/Alpha_complex/utilities/alpha_complex_3d_helper.h +++ b/src/Alpha_complex/utilities/alpha_complex_3d_helper.h @@ -23,7 +23,7 @@ #ifndef ALPHA_COMPLEX_3D_HELPER_H_ #define ALPHA_COMPLEX_3D_HELPER_H_ -template +template Vertex_list from_cell(const Cell_handle& ch) { Vertex_list the_list; for (auto i = 0; i < 4; i++) { @@ -35,7 +35,7 @@ Vertex_list from_cell(const Cell_handle& ch) { return the_list; } -template +template Vertex_list from_facet(const Facet& fct) { Vertex_list the_list; for (auto i = 0; i < 4; i++) { @@ -49,7 +49,7 @@ Vertex_list from_facet(const Facet& fct) { return the_list; } -template +template Vertex_list from_edge(const Edge_3& edg) { Vertex_list the_list; for (auto i = 0; i < 4; i++) { @@ -63,7 +63,7 @@ Vertex_list from_edge(const Edge_3& edg) { return the_list; } -template +template Vertex_list from_vertex(const Vertex_handle& vh) { Vertex_list the_list; #ifdef DEBUG_TRACES diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp index f63ff0f6..f2085ab2 100644 --- a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -56,10 +57,10 @@ using Point_3 = Kernel::Point_3; // filtration with alpha values needed type definition 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 Dispatch = + CGAL::Dispatch_output_iterator, + CGAL::cpp11::tuple >, + std::back_insert_iterator > > >; using Cell_handle = Alpha_shape_3::Cell_handle; using Facet = Alpha_shape_3::Facet; using Edge_3 = Alpha_shape_3::Edge; @@ -70,42 +71,28 @@ using Vertex_list = std::list; 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_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:\n" << progName << " path_to_OFF_file coeff_field_characteristic[integer " << - "> 0] min_persistence[float >= -1.0]\n"; - std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; - exit(-1); -} +using Simplex_tree_vector_vertex = std::vector; +using PCOH = Gudhi::persistent_cohomology::Persistent_cohomology; -int main(int argc, char * const argv[]) { - // program args management - if (argc != 4) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &output_file_diag, + int &coeff_field_characteristic, Filtration_value &min_persistence); - int coeff_field_characteristic = atoi(argv[2]); +int main(int argc, char **argv) { + std::string off_file_points; + std::string output_file_diag; + int coeff_field_characteristic; + Filtration_value min_persistence; - Filtration_value min_persistence = 0.0; - 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]); - } + program_options(argc, argv, off_file_points, output_file_diag, coeff_field_characteristic, min_persistence); - // Read points from file - std::string offInputFile(argv[1]); // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); + Gudhi::Points_3D_off_reader off_reader(off_file_points); // Check the read operation was correct if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); + std::cerr << "Unable to read file " << off_file_points << std::endl; + exit(-1); } // Retrieve the triangulation @@ -143,28 +130,28 @@ int main(int argc, char * const argv[]) { Filtration_value filtration_max = 0.0; for (auto object_iterator : the_objects) { // Retrieve Alpha shape vertex list from object - if (const Cell_handle * cell = CGAL::object_cast(&object_iterator)) { + if (const Cell_handle *cell = CGAL::object_cast(&object_iterator)) { 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)) { + } else if (const Facet *facet = CGAL::object_cast(&object_iterator)) { 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)) { + } else if (const Edge_3 *edge = CGAL::object_cast(&object_iterator)) { vertex_list = from_edge(*edge); count_edges++; if (dim_max < 1) { // Edge_3 is of dim 1 dim_max = 1; } - } else if (const 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); } @@ -190,7 +177,7 @@ int main(int argc, char * const argv[]) { } } // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); + Filtration_value filtr = /*std::sqrt*/ (*the_alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; #endif // DEBUG_TRACES @@ -211,7 +198,6 @@ int main(int argc, char * const argv[]) { std::cout << "facets \t\t" << count_facets << std::endl; std::cout << "cells \t\t" << count_cells << std::endl; - std::cout << "Information of the Simplex Tree: " << std::endl; std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; @@ -236,7 +222,58 @@ int main(int argc, char * const argv[]) { pcoh.compute_persistent_cohomology(min_persistence); - pcoh.output_diagram(); + // Output the diagram in filediag + if (output_file_diag.empty()) { + pcoh.output_diagram(); + } else { + std::cout << "Result in file: " << output_file_diag << std::endl; + std::ofstream out(output_file_diag); + pcoh.output_diagram(out); + out.close(); + } return 0; } + +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &output_file_diag, + int &coeff_field_characteristic, Filtration_value &min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options()("input-file", po::value(&off_file_points), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + + po::options_description visible("Allowed options", 100); + visible.add_options()("help,h", "produce help message")( + "output-file,o", po::value(&output_file_diag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a 3D Alpha complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp index 9e84e91f..2105220a 100644 --- a/src/Alpha_complex/utilities/alpha_complex_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_persistence.cpp @@ -14,12 +14,9 @@ using Simplex_tree = Gudhi::Simplex_tree<>; using Filtration_value = Simplex_tree::Filtration_value; -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & output_file_diag - , Filtration_value & alpha_square_max_value - , int & coeff_field_characteristic - , Filtration_value & min_persistence); +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &output_file_diag, + Filtration_value &alpha_square_max_value, int &coeff_field_characteristic, + Filtration_value &min_persistence); int main(int argc, char **argv) { std::string off_file_points; @@ -28,13 +25,13 @@ int main(int argc, char **argv) { int coeff_field_characteristic; Filtration_value min_persistence; - program_options(argc, argv, off_file_points, output_file_diag, alpha_square_max_value, - coeff_field_characteristic, min_persistence); + program_options(argc, argv, off_file_points, output_file_diag, alpha_square_max_value, coeff_field_characteristic, + min_persistence); // ---------------------------------------------------------------------------- // Init of an alpha complex from an OFF file // ---------------------------------------------------------------------------- - using Kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; + using Kernel = CGAL::Epick_d; Gudhi::alpha_complex::Alpha_complex alpha_complex_from_file(off_file_points); Simplex_tree simplex; @@ -42,17 +39,16 @@ int main(int argc, char **argv) { // ---------------------------------------------------------------------------- // Display information about the alpha complex // ---------------------------------------------------------------------------- - std::cout << "Simplicial complex is of dimension " << simplex.dimension() << - " - " << simplex.num_simplices() << " simplices - " << - simplex.num_vertices() << " vertices." << std::endl; + std::cout << "Simplicial complex is of dimension " << simplex.dimension() << " - " << simplex.num_simplices() + << " simplices - " << simplex.num_vertices() << " vertices." << std::endl; // Sort the simplices in the order of the filtration simplex.initialize_filtration(); std::cout << "Simplex_tree dim: " << simplex.dimension() << std::endl; // Compute the persistence diagram of the complex - Gudhi::persistent_cohomology::Persistent_cohomology< Simplex_tree, - Gudhi::persistent_cohomology::Field_Zp > pcoh(simplex); + Gudhi::persistent_cohomology::Persistent_cohomology pcoh( + simplex); // initializes the coefficient field for homology pcoh.init_coefficients(coeff_field_characteristic); @@ -72,30 +68,26 @@ int main(int argc, char **argv) { return 0; } -void program_options(int argc, char * argv[] - , std::string & off_file_points - , std::string & output_file_diag - , Filtration_value & alpha_square_max_value - , int & coeff_field_characteristic - , Filtration_value & min_persistence) { +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &output_file_diag, + Filtration_value &alpha_square_max_value, int &coeff_field_characteristic, + Filtration_value &min_persistence) { namespace po = boost::program_options; po::options_description hidden("Hidden options"); - hidden.add_options() - ("input-file", po::value(&off_file_points), - "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + hidden.add_options()("input-file", po::value(&off_file_points), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); po::options_description visible("Allowed options", 100); - visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&output_file_diag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-alpha-square-value,r", - po::value(&alpha_square_max_value)->default_value(std::numeric_limits::infinity()), - "Maximal alpha square value for the Alpha complex construction.") - ("field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + visible.add_options()("help,h", "produce help message")( + "output-file,o", po::value(&output_file_diag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "max-alpha-square-value,r", po::value(&alpha_square_max_value) + ->default_value(std::numeric_limits::infinity()), + "Maximal alpha square value for the Alpha complex construction.")( + "field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals"); po::positional_options_description pos; pos.add("input-file", 1); @@ -104,8 +96,7 @@ void program_options(int argc, char * argv[] all.add(visible).add(hidden); po::variables_map vm; - po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); po::notify(vm); if (vm.count("help") || !vm.count("input-file")) { diff --git a/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp index 8ce68406..7919c7fd 100644 --- a/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -40,7 +41,7 @@ #include #include -#include "../utilities/alpha_complex_3d_helper.h" +#include "alpha_complex_3d_helper.h" // Alpha_shape_3 templates type definitions using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; @@ -57,10 +58,10 @@ using Point_3 = Kernel::Point_3; // filtration with alpha values needed type definition 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 Dispatch = + CGAL::Dispatch_output_iterator, + CGAL::cpp11::tuple >, + std::back_insert_iterator > > >; using Cell_handle = Alpha_shape_3::Cell_handle; using Facet = Alpha_shape_3::Facet; using Edge_3 = Alpha_shape_3::Edge; @@ -71,42 +72,28 @@ using Vertex_list = std::list; 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_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:\n" << progName << " path_to_OFF_file coeff_field_characteristic[integer " << - "> 0] min_persistence[float >= -1.0]\n"; - std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; - exit(-1); -} +using Simplex_tree_vector_vertex = std::vector; +using PCOH = Gudhi::persistent_cohomology::Persistent_cohomology; -int main(int argc, char * const argv[]) { - // program args management - if (argc != 4) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &output_file_diag, + int &coeff_field_characteristic, Filtration_value &min_persistence); - int coeff_field_characteristic = atoi(argv[2]); +int main(int argc, char **argv) { + std::string off_file_points; + std::string output_file_diag; + int coeff_field_characteristic; + Filtration_value min_persistence; - Filtration_value min_persistence = 0.0; - 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]); - } + program_options(argc, argv, off_file_points, output_file_diag, coeff_field_characteristic, min_persistence); - // Read points from file - std::string offInputFile(argv[1]); // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); + Gudhi::Points_3D_off_reader off_reader(off_file_points); // Check the read operation was correct if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); + std::cerr << "Unable to read file " << off_file_points << std::endl; + exit(-1); } // Retrieve the triangulation @@ -144,28 +131,28 @@ int main(int argc, char * const argv[]) { Filtration_value filtration_max = 0.0; for (auto object_iterator : the_objects) { // Retrieve Alpha shape vertex list from object - if (const Cell_handle * cell = CGAL::object_cast(&object_iterator)) { + if (const Cell_handle *cell = CGAL::object_cast(&object_iterator)) { 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)) { + } else if (const Facet *facet = CGAL::object_cast(&object_iterator)) { 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)) { + } else if (const Edge_3 *edge = CGAL::object_cast(&object_iterator)) { vertex_list = from_edge(*edge); count_edges++; if (dim_max < 1) { // Edge_3 is of dim 1 dim_max = 1; } - } else if (const 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); } @@ -192,7 +179,7 @@ int main(int argc, char * const argv[]) { } // Construction of the simplex_tree // you can also use the_alpha_value_iterator->exact() - Filtration_value filtr = /*std::sqrt*/CGAL::to_double(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 @@ -213,7 +200,6 @@ int main(int argc, char * const argv[]) { std::cout << "facets \t\t" << count_facets << std::endl; std::cout << "cells \t\t" << count_cells << std::endl; - std::cout << "Information of the Simplex Tree: " << std::endl; std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; @@ -242,3 +228,46 @@ int main(int argc, char * const argv[]) { return 0; } + +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &output_file_diag, + int &coeff_field_characteristic, Filtration_value &min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options()("input-file", po::value(&off_file_points), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + + po::options_description visible("Allowed options", 100); + visible.add_options()("help,h", "produce help message")( + "output-file,o", po::value(&output_file_diag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a 3D Alpha complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp index 8140a3c5..10b62f75 100644 --- a/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -63,10 +64,10 @@ using Point_3 = PK::Point_3; // filtration with alpha values needed type definition 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 Dispatch = + CGAL::Dispatch_output_iterator, + CGAL::cpp11::tuple >, + std::back_insert_iterator > > >; using Cell_handle = Alpha_shape_3::Cell_handle; using Facet = Alpha_shape_3::Facet; using Edge_3 = Alpha_shape_3::Edge; @@ -77,54 +78,41 @@ using Vertex_list = std::list; 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_map = std::map; using Alpha_shape_simplex_tree_pair = std::pair; -using Simplex_tree_vector_vertex = std::vector< Simplex_tree_vertex >; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< - ST, Gudhi::persistent_cohomology::Field_Zp >; - -void usage(char * const progName) { - std::cerr << "Usage:\n" << progName << " path_to_OFF_file path_to_iso_cuboid_3_file coeff_field_characteristic[" << - "integer > 0] min_persistence[float >= -1.0]\n" << - " path_to_OFF_file is the path to your points cloud in OFF format.\n" << - " path_to_iso_cuboid_3_file is the path to the iso cuboid file with the following format :\n" << - " x_min y_min z_min x_max y_max z_max\n" << - " In this example, the periodic cube will be " << - "{ x = [x_min,x_max]; y = [y_min,y_max]; z = [z_min,z_max] }.\n" << - " For more information, please refer to\n" << - " https://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Iso__cuboid__3.html\n"; - - exit(-1); -} +using Simplex_tree_vector_vertex = std::vector; +using Persistent_cohomology = + Gudhi::persistent_cohomology::Persistent_cohomology; -int main(int argc, char * const argv[]) { - // program args management - if (argc != 5) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &cuboid_file, + std::string &output_file_diag, int &coeff_field_characteristic, Filtration_value &min_persistence); - int coeff_field_characteristic = atoi(argv[3]); - Filtration_value min_persistence = strtof(argv[4], nullptr); +int main(int argc, char **argv) { + std::string off_file_points; + std::string cuboid_file; + std::string output_file_diag; + int coeff_field_characteristic; + Filtration_value min_persistence; + + program_options(argc, argv, off_file_points, cuboid_file, output_file_diag, coeff_field_characteristic, + min_persistence); - // Read points from file - std::string offInputFile(argv[1]); // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); + Gudhi::Points_3D_off_reader off_reader(off_file_points); // Check the read operation was correct if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); + std::cerr << "Unable to read OFF file " << off_file_points << std::endl; + exit(-1); } // Read iso_cuboid_3 information from file - std::ifstream iso_cuboid_str(argv[2]); + std::ifstream iso_cuboid_str(cuboid_file); double x_min, y_min, z_min, x_max, y_max, z_max; if (iso_cuboid_str.good()) { iso_cuboid_str >> x_min >> y_min >> z_min >> x_max >> y_max >> z_max; } else { - std::cerr << "Unable to read file " << argv[2] << std::endl; - usage(argv[0]); + std::cerr << "Unable to read file " << cuboid_file << std::endl; + exit(-1); } // Retrieve the triangulation @@ -168,29 +156,29 @@ int main(int argc, char * const argv[]) { Filtration_value filtration_max = 0.0; for (auto object_iterator : the_objects) { // Retrieve Alpha shape vertex list from object - if (const Cell_handle * cell = CGAL::object_cast(&object_iterator)) { + if (const Cell_handle *cell = CGAL::object_cast(&object_iterator)) { 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)) { + } else if (const Facet *facet = CGAL::object_cast(&object_iterator)) { 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)) { + } else if (const Edge_3 *edge = CGAL::object_cast(&object_iterator)) { vertex_list = from_edge(*edge); count_edges++; if (dim_max < 1) { // 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 Alpha_shape_3::Vertex_handle *vertex = + CGAL::object_cast(&object_iterator)) { count_vertices++; vertex_list = from_vertex(*vertex); } @@ -216,7 +204,7 @@ int main(int argc, char * const argv[]) { } } // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); + Filtration_value filtr = /*std::sqrt*/ (*the_alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; #endif // DEBUG_TRACES @@ -237,7 +225,6 @@ int main(int argc, char * const argv[]) { std::cout << "facets \t\t" << count_facets << std::endl; std::cout << "cells \t\t" << count_cells << std::endl; - std::cout << "Information of the Simplex Tree: " << std::endl; std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; @@ -266,3 +253,50 @@ int main(int argc, char * const argv[]) { return 0; } + +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &cuboid_file, + std::string &output_file_diag, int &coeff_field_characteristic, + Filtration_value &min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options()("input-file", po::value(&off_file_points), + "Name of file containing a point set. Format is one point per line: X1 ... Xd ")( + "cuboid-file", po::value(&cuboid_file), + "Name of file describing the periodic domain. Format is: min_hx min_hy min_hz\nmax_hx max_hy max_hz"); + + po::options_description visible("Allowed options", 100); + visible.add_options()("help,h", "produce help message")( + "output-file,o", po::value(&output_file_diag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + pos.add("cuboid-file", 2); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file") || !vm.count("cuboid-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a periodic 3D Alpha complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file cuboid-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp index a4ecf9da..293170f7 100644 --- a/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -42,7 +43,7 @@ #include #include -#include "../utilities/alpha_complex_3d_helper.h" +#include "alpha_complex_3d_helper.h" // Traits using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; @@ -60,10 +61,10 @@ using Weighted_point_3 = Gt::Weighted_point; // filtration with alpha values needed type definition 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 Dispatch = + CGAL::Dispatch_output_iterator, + CGAL::cpp11::tuple >, + std::back_insert_iterator > > >; using Cell_handle = Alpha_shape_3::Cell_handle; using Facet = Alpha_shape_3::Facet; using Edge_3 = Alpha_shape_3::Edge; @@ -74,48 +75,38 @@ using Vertex_list = std::list; 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_map = std::map; using Alpha_shape_simplex_tree_pair = std::pair; -using Simplex_tree_vector_vertex = std::vector< Simplex_tree_vertex >; -using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology< - ST, Gudhi::persistent_cohomology::Field_Zp >; - -void usage(char * const progName) { - std::cerr << "Usage:\n" << progName << " path_to_OFF_file path_to_weight_file coeff_field_characteristic[integer " << - "> 0] min_persistence[float >= -1.0]\n"; - std::cerr << " path_to_OFF_file is the path to your points cloud in OFF format.\n"; - std::cerr << " path_to_weight_file is the path to the weights of your points cloud (one value per line.)\n"; - std::cerr << " Weights values are explained on CGAL documentation:\n"; - std::cerr << " https://doc.cgal.org/latest/Alpha_shapes_3/index.html#title0\n"; - std::cerr << " https://doc.cgal.org/latest/Triangulation_3/index.html#Triangulation3secclassRegulartriangulation\n"; - exit(-1); -} +using Simplex_tree_vector_vertex = std::vector; +using Persistent_cohomology = + Gudhi::persistent_cohomology::Persistent_cohomology; -int main(int argc, char * const argv[]) { - // program args management - if (argc != 5) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &weight_file, + std::string &output_file_diag, int &coeff_field_characteristic, Filtration_value &min_persistence); - int coeff_field_characteristic = atoi(argv[3]); - Filtration_value min_persistence = strtof(argv[4], nullptr); +int main(int argc, char **argv) { + std::string off_file_points; + std::string weight_file; + std::string output_file_diag; + int coeff_field_characteristic; + Filtration_value min_persistence; + + program_options(argc, argv, off_file_points, weight_file, output_file_diag, coeff_field_characteristic, + min_persistence); - // Read points from file - std::string offInputFile(argv[1]); // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader off_reader(offInputFile); + Gudhi::Points_3D_off_reader off_reader(off_file_points); // Check the read operation was correct if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << offInputFile << std::endl; - usage(argv[0]); + std::cerr << "Unable to read OFF file " << off_file_points << std::endl; + exit(-1); } // Retrieve the triangulation std::vector lp = off_reader.get_point_cloud(); // Read weights information from file - std::ifstream weights_ifstr(argv[2]); + std::ifstream weights_ifstr(weight_file); std::vector wp; if (weights_ifstr.good()) { double weight = 0.0; @@ -127,12 +118,12 @@ int main(int argc, char * const argv[]) { index++; } if (index != lp.size()) { - std::cerr << "Bad number of weights in file " << argv[2] << std::endl; - usage(argv[0]); + std::cerr << "Bad number of weights in file " << weight_file << std::endl; + exit(-1); } } else { - std::cerr << "Unable to read file " << argv[2] << std::endl; - usage(argv[0]); + std::cerr << "Unable to read weights file " << weight_file << std::endl; + exit(-1); } // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. @@ -167,29 +158,29 @@ int main(int argc, char * const argv[]) { Filtration_value filtration_max = 0.0; for (auto object_iterator : the_objects) { // Retrieve Alpha shape vertex list from object - if (const Cell_handle * cell = CGAL::object_cast(&object_iterator)) { + if (const Cell_handle *cell = CGAL::object_cast(&object_iterator)) { 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)) { + } else if (const Facet *facet = CGAL::object_cast(&object_iterator)) { 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)) { + } else if (const Edge_3 *edge = CGAL::object_cast(&object_iterator)) { vertex_list = from_edge(*edge); count_edges++; if (dim_max < 1) { // 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 Alpha_shape_3::Vertex_handle *vertex = + CGAL::object_cast(&object_iterator)) { count_vertices++; vertex_list = from_vertex(*vertex); } @@ -215,7 +206,7 @@ int main(int argc, char * const argv[]) { } } // Construction of the simplex_tree - Filtration_value filtr = /*std::sqrt*/(*the_alpha_value_iterator); + Filtration_value filtr = /*std::sqrt*/ (*the_alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; #endif // DEBUG_TRACES @@ -236,7 +227,6 @@ int main(int argc, char * const argv[]) { std::cout << "facets \t\t" << count_facets << std::endl; std::cout << "cells \t\t" << count_cells << std::endl; - std::cout << "Information of the Simplex Tree: " << std::endl; std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; @@ -265,3 +255,50 @@ int main(int argc, char * const argv[]) { return 0; } + +void program_options(int argc, char *argv[], std::string &off_file_points, std::string &weight_file, + std::string &output_file_diag, int &coeff_field_characteristic, + Filtration_value &min_persistence) { + namespace po = boost::program_options; + po::options_description hidden("Hidden options"); + hidden.add_options()("input-file", po::value(&off_file_points), + "Name of file containing a point set. Format is one point per line: X1 ... Xd ")( + "weight-file", po::value(&weight_file), + "Name of file containing a point weights. Format is one weigt per line: W1\n...\nWn "); + + po::options_description visible("Allowed options", 100); + visible.add_options()("help,h", "produce help message")( + "output-file,o", po::value(&output_file_diag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout")( + "field-charac,p", po::value(&coeff_field_characteristic)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.")( + "min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length " + "intervals"); + + po::positional_options_description pos; + pos.add("input-file", 1); + pos.add("weight-file", 2); + + po::options_description all; + all.add(visible).add(hidden); + + po::variables_map vm; + po::store(po::command_line_parser(argc, argv).options(all).positional(pos).run(), vm); + po::notify(vm); + + if (vm.count("help") || !vm.count("input-file") || !vm.count("weight-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a weighted 3D Alpha complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file weight-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); + } +} diff --git a/src/Bottleneck_distance/utilities/CMakeLists.txt b/src/Bottleneck_distance/utilities/CMakeLists.txt index cdf76c85..063b6ae3 100644 --- a/src/Bottleneck_distance/utilities/CMakeLists.txt +++ b/src/Bottleneck_distance/utilities/CMakeLists.txt @@ -3,6 +3,9 @@ project(Bottleneck_distance_utilities) if (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.8.1) add_executable (bottleneck_read_file bottleneck_read_file.cpp) + if (TBB_FOUND) + target_link_libraries(bottleneck_read_file ${TBB_LIBRARIES}) + endif(TBB_FOUND) add_test(NAME Bottleneck_distance_utilities_Bottleneck_read_file COMMAND $ diff --git a/src/Rips_complex/utilities/README b/src/Rips_complex/utilities/README index 93ec3658..ca10424d 100644 --- a/src/Rips_complex/utilities/README +++ b/src/Rips_complex/utilities/README @@ -13,6 +13,7 @@ where `dim` is the dimension of the homological feature, `b` and `d` are respect **Allowed options** * `-h [ --help ]` Produce help message +* `-o [ --output-file ]` Name of file in which the persistence diagram is written. Default print in standard output. * `-r [ --max-edge-length ]` (default = inf) Maximal length of an edge for the Rips complex construction. * `-d [ --cpx-dimension ]` (default = 1) Maximal dimension of the Rips complex we want to compute. * `-p [ --field-charac ]` (default = 11) Characteristic p of the coefficient field Z/pZ for computing homology. @@ -45,7 +46,7 @@ outputs: ## `rips_distance_matrix_persistence` ## -Same as `rips_persistence` but taking an distance matrix as input. +Same as `rips_persistence` but taking a distance matrix as input. **Example** `rips_distance_matrix_persistence data/distance_matrix/full_square_distance_matrix.csv -r 15 -d 3 -p 3 -m 0` -- cgit v1.2.3 From 3c1cea405895775ee36e7d978ff8a298bea90122 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 16 Nov 2017 11:41:16 +0000 Subject: Add a script to concatenate utilities/README files git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2889 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 1e79ad60b440d1bb2bd2fb5ede8d541e5970d6aa --- scripts/concatenate_utils_readme.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 scripts/concatenate_utils_readme.sh diff --git a/scripts/concatenate_utils_readme.sh b/scripts/concatenate_utils_readme.sh new file mode 100755 index 00000000..f5390044 --- /dev/null +++ b/scripts/concatenate_utils_readme.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +rm README_FOR_UTILITIES.txt +locate utilities/README | grep `svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$'` | xargs cat -- >> README_FOR_UTILITIES.txt \ No newline at end of file -- cgit v1.2.3 From 1b895dd0d76cbe13b92b68b7198f58631678200f Mon Sep 17 00:00:00 2001 From: cjamin Date: Thu, 16 Nov 2017 11:54:36 +0000 Subject: Add missing includes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2890 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9ddda864abff7b9509984dcbc657225ea1c80b1a --- src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp | 2 ++ src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp | 2 ++ src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp | 2 ++ src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp | 2 ++ .../example/weighted_periodic_alpha_complex_3d_persistence.cpp | 2 ++ .../example/example_alpha_shapes_3_simplex_tree_from_off_file.cpp | 2 ++ 6 files changed, 12 insertions(+) diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp index f2085ab2..28daca5e 100644 --- a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp index 7919c7fd..c69482ab 100644 --- a/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp index 10b62f75..b480a9ec 100644 --- a/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp index 293170f7..91747a8c 100644 --- a/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/Persistent_cohomology/example/weighted_periodic_alpha_complex_3d_persistence.cpp b/src/Persistent_cohomology/example/weighted_periodic_alpha_complex_3d_persistence.cpp index 13634ff7..67d830dc 100644 --- a/src/Persistent_cohomology/example/weighted_periodic_alpha_complex_3d_persistence.cpp +++ b/src/Persistent_cohomology/example/weighted_periodic_alpha_complex_3d_persistence.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/Simplex_tree/example/example_alpha_shapes_3_simplex_tree_from_off_file.cpp b/src/Simplex_tree/example/example_alpha_shapes_3_simplex_tree_from_off_file.cpp index ff2eebcb..d8289ba9 100644 --- a/src/Simplex_tree/example/example_alpha_shapes_3_simplex_tree_from_off_file.cpp +++ b/src/Simplex_tree/example/example_alpha_shapes_3_simplex_tree_from_off_file.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include -- cgit v1.2.3 -- cgit v1.2.3