diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2017-11-22 07:37:48 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2017-11-22 07:37:48 +0000 |
commit | d8ffa0a560d22b3bb78d87a8f8e3c18811c9dbda (patch) | |
tree | c165cd33bc07e3134ce1473408ed91afb60e6e79 | |
parent | c0c455e0afca340c70c5516ab19e0c44d961211e (diff) | |
parent | 36784120de86410bfbe51c563910df0d8718e2e9 (diff) |
Merge last trunk modifications
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/add_utils_in_gudhi_v2@2928 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: c5b02e64769ac4af51badc9215a433c50f63299f
-rw-r--r-- | src/Alpha_complex/utilities/CMakeLists.txt | 16 | ||||
-rw-r--r-- | src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp | 19 | ||||
-rw-r--r-- | src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp | 31 | ||||
-rw-r--r-- | src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp | 22 | ||||
-rw-r--r-- | src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp | 51 | ||||
-rw-r--r-- | src/Alpha_complex/utilities/weighted_periodic_alpha_complex_3d_persistence.cpp (renamed from src/Persistent_cohomology/example/weighted_periodic_alpha_complex_3d_persistence.cpp) | 2 |
6 files changed, 96 insertions, 45 deletions
diff --git a/src/Alpha_complex/utilities/CMakeLists.txt b/src/Alpha_complex/utilities/CMakeLists.txt index cefc1ad6..79d9e7dd 100644 --- a/src/Alpha_complex/utilities/CMakeLists.txt +++ b/src/Alpha_complex/utilities/CMakeLists.txt @@ -46,4 +46,20 @@ if(CGAL_FOUND) install(TARGETS periodic_alpha_complex_3d_persistence DESTINATION bin) endif (NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.7.0) + + if (NOT CGAL_VERSION VERSION_LESS 4.11.0) + add_executable(weighted_periodic_alpha_complex_3d_persistence weighted_periodic_alpha_complex_3d_persistence.cpp) + target_link_libraries(weighted_periodic_alpha_complex_3d_persistence ${CGAL_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(weighted_periodic_alpha_complex_3d_persistence ${TBB_LIBRARIES}) + endif(TBB_FOUND) + + add_test(NAME Persistent_cohomology_example_weigted_periodic_alpha_complex_3d COMMAND $<TARGET_FILE:weighted_periodic_alpha_complex_3d_persistence> + "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off" "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.weights" + "${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt" "3" "1.0") + + install(TARGETS weighted_periodic_alpha_complex_3d_persistence DESTINATION bin) + + endif (NOT CGAL_VERSION VERSION_LESS 4.11.0) + endif(CGAL_FOUND) diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp index 28daca5e..0a021a0f 100644 --- a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp @@ -30,8 +30,6 @@ #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Delaunay_triangulation_3.h> #include <CGAL/Alpha_shape_3.h> -#include <CGAL/Alpha_shape_vertex_base_3.h> -#include <CGAL/Alpha_shape_cell_base_3.h> #include <CGAL/iterator.h> #include <fstream> @@ -42,6 +40,7 @@ #include <utility> #include <list> #include <vector> +#include <cstdlib> #include "alpha_complex_3d_helper.h" @@ -76,7 +75,8 @@ using Simplex_tree_vertex = ST::Vertex_handle; using Alpha_shape_simplex_tree_map = std::map<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex>; using Alpha_shape_simplex_tree_pair = std::pair<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex>; using Simplex_tree_vector_vertex = std::vector<Simplex_tree_vertex>; -using PCOH = Gudhi::persistent_cohomology::Persistent_cohomology<ST, Gudhi::persistent_cohomology::Field_Zp>; +using Persistent_cohomology = + Gudhi::persistent_cohomology::Persistent_cohomology<ST, Gudhi::persistent_cohomology::Field_Zp>; 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); @@ -132,28 +132,28 @@ int main(int argc, char **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<Cell_handle>(&object_iterator)) { + if (const Cell_handle* cell = CGAL::object_cast<Cell_handle>(&object_iterator)) { vertex_list = from_cell<Vertex_list, Cell_handle>(*cell); count_cells++; if (dim_max < 3) { // Cell is of dim 3 dim_max = 3; } - } else if (const Facet *facet = CGAL::object_cast<Facet>(&object_iterator)) { + } else if (const Facet* facet = CGAL::object_cast<Facet>(&object_iterator)) { vertex_list = from_facet<Vertex_list, 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<Edge_3>(&object_iterator)) { + } else if (const Edge_3* edge = CGAL::object_cast<Edge_3>(&object_iterator)) { vertex_list = from_edge<Vertex_list, Edge_3>(*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<Vertex_handle>(&object_iterator)) { + } else if (const Vertex_handle* vertex = CGAL::object_cast<Vertex_handle>(&object_iterator)) { count_vertices++; vertex_list = from_vertex<Vertex_list, Vertex_handle>(*vertex); } @@ -179,7 +179,7 @@ int main(int argc, char **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 @@ -192,7 +192,6 @@ int main(int argc, char **argv) { 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; @@ -218,7 +217,7 @@ int main(int argc, char **argv) { std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; // Compute the persistence diagram of the complex - PCOH pcoh(simplex_tree); + Persistent_cohomology pcoh(simplex_tree, true); // initializes the coefficient field for homology pcoh.init_coefficients(coeff_field_characteristic); 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 c69482ab..9a266418 100644 --- a/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/exact_alpha_complex_3d_persistence.cpp @@ -4,7 +4,7 @@ * * Author(s): Vincent Rouvreau * - * Copyright (C) 2014 INRIA Saclay (France) + * 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 @@ -30,8 +30,6 @@ #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Delaunay_triangulation_3.h> #include <CGAL/Alpha_shape_3.h> -#include <CGAL/Alpha_shape_vertex_base_3.h> -#include <CGAL/Alpha_shape_cell_base_3.h> #include <CGAL/iterator.h> #include <fstream> @@ -42,6 +40,7 @@ #include <utility> #include <list> #include <vector> +#include <cstdlib> #include "alpha_complex_3d_helper.h" @@ -77,7 +76,8 @@ using Simplex_tree_vertex = ST::Vertex_handle; using Alpha_shape_simplex_tree_map = std::map<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex>; using Alpha_shape_simplex_tree_pair = std::pair<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex>; using Simplex_tree_vector_vertex = std::vector<Simplex_tree_vertex>; -using PCOH = Gudhi::persistent_cohomology::Persistent_cohomology<ST, Gudhi::persistent_cohomology::Field_Zp>; +using Persistent_cohomology = + Gudhi::persistent_cohomology::Persistent_cohomology<ST, Gudhi::persistent_cohomology::Field_Zp>; 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); @@ -133,28 +133,28 @@ int main(int argc, char **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<Cell_handle>(&object_iterator)) { + if (const Cell_handle* cell = CGAL::object_cast<Cell_handle>(&object_iterator)) { vertex_list = from_cell<Vertex_list, Cell_handle>(*cell); count_cells++; if (dim_max < 3) { // Cell is of dim 3 dim_max = 3; } - } else if (const Facet *facet = CGAL::object_cast<Facet>(&object_iterator)) { + } else if (const Facet* facet = CGAL::object_cast<Facet>(&object_iterator)) { vertex_list = from_facet<Vertex_list, 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<Edge_3>(&object_iterator)) { + } else if (const Edge_3* edge = CGAL::object_cast<Edge_3>(&object_iterator)) { vertex_list = from_edge<Vertex_list, Edge_3>(*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<Vertex_handle>(&object_iterator)) { + } else if (const Vertex_handle* vertex = CGAL::object_cast<Vertex_handle>(&object_iterator)) { count_vertices++; vertex_list = from_vertex<Vertex_list, Vertex_handle>(*vertex); } @@ -181,7 +181,7 @@ int main(int argc, char **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 @@ -194,7 +194,6 @@ int main(int argc, char **argv) { 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; @@ -220,13 +219,21 @@ int main(int argc, char **argv) { std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; // Compute the persistence diagram of the complex - PCOH pcoh(simplex_tree); + 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(); + // 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; } 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 b480a9ec..186a58f8 100644 --- a/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/periodic_alpha_complex_3d_persistence.cpp @@ -31,8 +31,6 @@ #include <CGAL/Periodic_3_Delaunay_triangulation_traits_3.h> #include <CGAL/Periodic_3_Delaunay_triangulation_3.h> #include <CGAL/Alpha_shape_3.h> -#include <CGAL/Alpha_shape_vertex_base_3.h> -#include <CGAL/Alpha_shape_cell_base_3.h> #include <CGAL/iterator.h> #include <fstream> @@ -158,29 +156,28 @@ int main(int argc, char **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<Cell_handle>(&object_iterator)) { + if (const Cell_handle* cell = CGAL::object_cast<Cell_handle>(&object_iterator)) { vertex_list = from_cell<Vertex_list, Cell_handle>(*cell); count_cells++; if (dim_max < 3) { // Cell is of dim 3 dim_max = 3; } - } else if (const Facet *facet = CGAL::object_cast<Facet>(&object_iterator)) { + } else if (const Facet* facet = CGAL::object_cast<Facet>(&object_iterator)) { vertex_list = from_facet<Vertex_list, 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<Edge_3>(&object_iterator)) { + } else if (const Edge_3* edge = CGAL::object_cast<Edge_3>(&object_iterator)) { vertex_list = from_edge<Vertex_list, Edge_3>(*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<Alpha_shape_3::Vertex_handle>(&object_iterator)) { + } else if (const Vertex_handle* vertex = CGAL::object_cast<Vertex_handle>(&object_iterator)) { count_vertices++; vertex_list = from_vertex<Vertex_list, Vertex_handle>(*vertex); } @@ -219,7 +216,6 @@ int main(int argc, char **argv) { 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; @@ -251,7 +247,15 @@ int main(int argc, char **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; } 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 91747a8c..0e73a99b 100644 --- a/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/weighted_alpha_complex_3d_persistence.cpp @@ -27,14 +27,17 @@ #include <gudhi/Persistent_cohomology.h> #include <gudhi/Points_3D_off_io.h> +#include <CGAL/config.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> -#include <CGAL/Regular_triangulation_euclidean_traits_3.h> #include <CGAL/Regular_triangulation_3.h> #include <CGAL/Alpha_shape_3.h> -#include <CGAL/Alpha_shape_vertex_base_3.h> -#include <CGAL/Alpha_shape_cell_base_3.h> #include <CGAL/iterator.h> +// For CGAL < 4.11 +#if CGAL_VERSION_NR < 1041100000 +#include <CGAL/Regular_triangulation_euclidean_traits_3.h> +#endif // CGAL_VERSION_NR < 1041100000 + #include <fstream> #include <cmath> #include <string> @@ -47,19 +50,37 @@ #include "alpha_complex_3d_helper.h" -// Traits +// Alpha_shape_3 templates type definitions using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; + +// For CGAL < 4.11 +#if CGAL_VERSION_NR < 1041100000 using Gt = CGAL::Regular_triangulation_euclidean_traits_3<Kernel>; using Vb = CGAL::Alpha_shape_vertex_base_3<Gt>; using Fb = CGAL::Alpha_shape_cell_base_3<Gt>; using Tds = CGAL::Triangulation_data_structure_3<Vb, Fb>; using Triangulation_3 = CGAL::Regular_triangulation_3<Gt, Tds>; -using Alpha_shape_3 = CGAL::Alpha_shape_3<Triangulation_3>; // From file type definition using Point_3 = Gt::Bare_point; using Weighted_point_3 = Gt::Weighted_point; +// For CGAL >= 4.11 +#else // CGAL_VERSION_NR < 1041100000 +using Rvb = CGAL::Regular_triangulation_vertex_base_3<Kernel>; +using Vb = CGAL::Alpha_shape_vertex_base_3<Kernel,Rvb>; +using Rcb = CGAL::Regular_triangulation_cell_base_3<Kernel>; +using Cb = CGAL::Alpha_shape_cell_base_3<Kernel,Rcb>; +using Tds = CGAL::Triangulation_data_structure_3<Vb,Cb>; +using Triangulation_3 = CGAL::Regular_triangulation_3<Kernel,Tds>; + +// From file type definition +using Point_3 = Triangulation_3::Bare_point; +using Weighted_point_3 = Triangulation_3::Weighted_point; +#endif // CGAL_VERSION_NR < 1041100000 + +using Alpha_shape_3 = CGAL::Alpha_shape_3<Triangulation_3>; + // filtration with alpha values needed type definition using Alpha_value_type = Alpha_shape_3::FT; using Object = CGAL::Object; @@ -160,29 +181,28 @@ int main(int argc, char **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<Cell_handle>(&object_iterator)) { + if (const Cell_handle* cell = CGAL::object_cast<Cell_handle>(&object_iterator)) { vertex_list = from_cell<Vertex_list, Cell_handle>(*cell); count_cells++; if (dim_max < 3) { // Cell is of dim 3 dim_max = 3; } - } else if (const Facet *facet = CGAL::object_cast<Facet>(&object_iterator)) { + } else if (const Facet* facet = CGAL::object_cast<Facet>(&object_iterator)) { vertex_list = from_facet<Vertex_list, 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<Edge_3>(&object_iterator)) { + } else if (const Edge_3* edge = CGAL::object_cast<Edge_3>(&object_iterator)) { vertex_list = from_edge<Vertex_list, Edge_3>(*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<Alpha_shape_3::Vertex_handle>(&object_iterator)) { + } else if (const Vertex_handle* vertex = CGAL::object_cast<Vertex_handle>(&object_iterator)) { count_vertices++; vertex_list = from_vertex<Vertex_list, Vertex_handle>(*vertex); } @@ -221,7 +241,6 @@ int main(int argc, char **argv) { 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; @@ -253,7 +272,15 @@ int main(int argc, char **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; } diff --git a/src/Persistent_cohomology/example/weighted_periodic_alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/weighted_periodic_alpha_complex_3d_persistence.cpp index 67d830dc..13634ff7 100644 --- a/src/Persistent_cohomology/example/weighted_periodic_alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/weighted_periodic_alpha_complex_3d_persistence.cpp @@ -30,8 +30,6 @@ #include <CGAL/Periodic_3_regular_triangulation_traits_3.h> #include <CGAL/Periodic_3_regular_triangulation_3.h> #include <CGAL/Alpha_shape_3.h> -#include <CGAL/Alpha_shape_vertex_base_3.h> -#include <CGAL/Alpha_shape_cell_base_3.h> #include <CGAL/iterator.h> #include <fstream> |