From 9bcfe7ed9dabd7ac4688bd4e5ee6f60bf83635b4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 10 Sep 2018 07:37:33 +0000 Subject: Code review : Fix alpha_complex_3d_persistence utility with new alpha_complex_3d design git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_3d_module_vincent@3877 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 59c028ed6d5a3c85efeb99398a6d2e34c3af096a --- src/Alpha_complex/utilities/CMakeLists.txt | 2 +- .../utilities/alpha_complex_3d_persistence.cpp | 142 +++++++++++---------- 2 files changed, 74 insertions(+), 70 deletions(-) (limited to 'src/Alpha_complex/utilities') diff --git a/src/Alpha_complex/utilities/CMakeLists.txt b/src/Alpha_complex/utilities/CMakeLists.txt index 13476ba5..80444de8 100644 --- a/src/Alpha_complex/utilities/CMakeLists.txt +++ b/src/Alpha_complex/utilities/CMakeLists.txt @@ -49,7 +49,7 @@ if(CGAL_FOUND) "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.off" "-w" "${CMAKE_SOURCE_DIR}/data/points/grid_10_10_10_in_0_1.weights" "-c" "${CMAKE_SOURCE_DIR}/data/points/iso_cuboid_3_in_0_1.txt" - "-p" "2" "-m" "0") + "-p" "2" "-m" "0" "-e") install(TARGETS alpha_complex_3d_persistence DESTINATION bin) diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp index 1a152541..fb1418bb 100644 --- a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp @@ -38,29 +38,10 @@ using Filtration_value = Simplex_tree::Filtration_value; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology; -using Fast_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Safe_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Exact_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Fast_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Safe_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Exact_weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Fast_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Safe_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Exact_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Fast_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Safe_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Exact_weighted_periodic_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; - void program_options(int argc, char *argv[], std::string &off_file_points, bool& exact, std::string &weight_file, std::string &cuboid_file, std::string &output_file_diag, Filtration_value &alpha_square_max_value, int &coeff_field_characteristic, Filtration_value &min_persistence); -template -bool create_complex(AlphaComplex3d& alpha_complex, Simplex_tree& simplex_tree, - Filtration_value alpha_square_max_value) { - return alpha_complex.create_complex(simplex_tree, alpha_square_max_value); -} - bool read_weight_file(const std::string& weight_file, std::vector& weights) { // Read weights information from file std::ifstream weights_ifstr(weight_file); @@ -90,6 +71,18 @@ bool read_cuboid_file(const std::string& cuboid_file, double& x_min, double& y_m return true; } +template +std::vector read_off(const std::string& off_file_points) { + // Read the OFF file (input file name given as parameter) and triangulate points + 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 OFF file " << off_file_points << std::endl; + exit(-1); + } + return off_reader.get_point_cloud(); +} + int main(int argc, char **argv) { std::string off_file_points; std::string weight_file; @@ -105,28 +98,61 @@ int main(int argc, char **argv) { program_options(argc, argv, off_file_points, exact_version, weight_file, cuboid_file, output_file_diag, alpha_square_max_value, coeff_field_characteristic, min_persistence); + std::vector weights; + if (weight_file != std::string()) { + if (!read_weight_file(weight_file, weights)) { + std::cerr << "Unable to read weights file " << weight_file << std::endl; + exit(-1); + } + weighted_version = true; + } + + double x_min=0., y_min=0., z_min=0., x_max=0., y_max=0., z_max=0.; + std::ifstream iso_cuboid_str(argv[3]); + if (cuboid_file != std::string()) { + if (!read_cuboid_file(cuboid_file, x_min, y_min, z_min, x_max, y_max, z_max)) { + std::cerr << "Unable to read cuboid file " << cuboid_file << std::endl; + exit(-1); + } + periodic_version = true; + } + Gudhi::alpha_complex::complexity complexity = Gudhi::alpha_complex::complexity::fast; if (exact_version) { complexity = Gudhi::alpha_complex::complexity::exact; } + Simplex_tree simplex_tree; + switch(complexity) { case Gudhi::alpha_complex::complexity::fast: if (weighted_version) { if (periodic_version) { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, weights, x_min, y_min, z_min, x_max, y_max, z_max); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } else { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, weights); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } } else { if (periodic_version) { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, x_min, y_min, z_min, x_max, y_max, z_max); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } else { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } } break; @@ -135,17 +161,29 @@ int main(int argc, char **argv) { if (periodic_version) { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, weights, x_min, y_min, z_min, x_max, y_max, z_max); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } else { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, weights); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } } else { if (periodic_version) { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, x_min, y_min, z_min, x_max, y_max, z_max); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } else { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } } break; @@ -154,72 +192,38 @@ int main(int argc, char **argv) { if (periodic_version) { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, weights, x_min, y_min, z_min, x_max, y_max, z_max); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } else { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, weights); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } } else { if (periodic_version) { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points, x_min, y_min, z_min, x_max, y_max, z_max); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } else { using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; + auto points = read_off(off_file_points); + Alpha_complex_3d alpha_complex(points); + alpha_complex.create_complex(simplex_tree, alpha_square_max_value); } } break; - } - - /*const Gudhi::alpha_complex::complexity complexity_(complexity); - // Read the OFF file (input file name given as parameter) and triangulate points - 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 OFF file " << off_file_points << std::endl; - exit(-1); - } - - std::vector weights; - if (weight_file != std::string()) { - if (!read_weight_file(weight_file, weights)) { - std::cerr << "Unable to read weights file " << weight_file << std::endl; - exit(-1); - } - weighted_version = true; - } - - double x_min=0., y_min=0., z_min=0., x_max=0., y_max=0., z_max=0.; - std::ifstream iso_cuboid_str(argv[3]); - if (cuboid_file != std::string()) { - if (!read_cuboid_file(cuboid_file, x_min, y_min, z_min, x_max, y_max, z_max)) { - std::cerr << "Unable to read cuboid file " << cuboid_file << std::endl; + default: + std::cerr << "Unknown complexity value " << std::endl; exit(-1); - } - periodic_version = true; - } - - Simplex_tree simplex_tree; - - if (weighted_version) { - if (periodic_version) { - Alpha_complex_3d alpha_complex(off_reader.get_point_cloud(), weights, - x_min, y_min, z_min, x_max, y_max, z_max); - create_complex(alpha_complex, simplex_tree, alpha_square_max_value); - } else { - Alpha_complex_3d alpha_complex(off_reader.get_point_cloud(), weights); - create_complex(alpha_complex, simplex_tree, alpha_square_max_value); - } - } else { - if (periodic_version) { - Alpha_complex_3d alpha_complex(off_reader.get_point_cloud(), x_min, y_min, z_min, x_max, y_max, z_max); - create_complex(alpha_complex, simplex_tree, alpha_square_max_value); - } else { - Alpha_complex_3d alpha_complex(off_reader.get_point_cloud()); - create_complex(alpha_complex, simplex_tree, alpha_square_max_value); - } + break; } - // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); @@ -239,7 +243,7 @@ int main(int argc, char **argv) { std::ofstream out(output_file_diag); pcoh.output_diagram(out); out.close(); - }*/ + } return 0; } -- cgit v1.2.3