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 --- .../exact_alpha_complex_3d_persistence.cpp | 107 +++++++++++++-------- 1 file changed, 68 insertions(+), 39 deletions(-) (limited to 'src/Alpha_complex/utilities/exact_alpha_complex_3d_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 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(); + } +} -- cgit v1.2.3