From ef84bab542eb07d83515293652841969dd462b1c Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 28 Aug 2018 21:11:26 +0000 Subject: Make fast/safe/exact, weighted/non-weighted, periodic/non-periodic more orthogonal choices Only examples work for the moment. Periodic to be tested. Add Alpha_complex_3d_from_points.cpp example. Maybe to be removed. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_3d_module_vincent@3840 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f5621df603bdb149c52400a6095271ea0f54b84c --- .../example/Alpha_complex_3d_from_points.cpp | 56 +++++++++++ src/Alpha_complex/example/CMakeLists.txt | 8 ++ .../Weighted_alpha_complex_3d_from_points.cpp | 13 +-- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 102 ++++++++++++++++----- 4 files changed, 147 insertions(+), 32 deletions(-) create mode 100644 src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp (limited to 'src') diff --git a/src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp new file mode 100644 index 00000000..e96385c0 --- /dev/null +++ b/src/Alpha_complex/example/Alpha_complex_3d_from_points.cpp @@ -0,0 +1,56 @@ +#include +// to construct a simplex_tree from alpha complex +#include + +#include +#include +#include +#include // for numeric limits + +using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; +using Point = Alpha_complex_3d::Point_3 ; +using Vector_of_points = std::vector; + +int main(int argc, char **argv) { + if (argc != 1) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + std::cerr << "Usage: " << (argv[0] - 1) << " \n"; + exit(-1); // ----- >> + } + + // ---------------------------------------------------------------------------- + // Init of a list of points from a small molecule + // ---------------------------------------------------------------------------- + Vector_of_points points; + points.push_back(Point(1, -1, -1)); + points.push_back(Point(-1, 1, -1)); + points.push_back(Point(-1, -1, 1)); + points.push_back(Point(1, 1, 1)); + points.push_back(Point(2, 2, 2)); + + // ---------------------------------------------------------------------------- + // Init of an alpha complex from the list of points + // ---------------------------------------------------------------------------- + Alpha_complex_3d alpha_complex_from_points(points); + + Gudhi::Simplex_tree<> simplex; + if (alpha_complex_from_points.create_complex(simplex)) { + // ---------------------------------------------------------------------------- + // Display information about the alpha complex + // ---------------------------------------------------------------------------- + std::cout << "Alpha complex is of dimension " << simplex.dimension() << + " - " << simplex.num_simplices() << " simplices - " << + simplex.num_vertices() << " vertices." << std::endl; + + std::cout << "Iterator on alpha complex simplices in the filtration order, with [filtration value]:" << std::endl; + for (auto f_simplex : simplex.filtration_simplex_range()) { + std::cout << " ( "; + for (auto vertex : simplex.simplex_vertex_range(f_simplex)) { + std::cout << vertex << " "; + } + std::cout << ") -> " << "[" << simplex.filtration(f_simplex) << "] "; + std::cout << std::endl; + } + } + return 0; +} diff --git a/src/Alpha_complex/example/CMakeLists.txt b/src/Alpha_complex/example/CMakeLists.txt index 4a1cd26d..1f127972 100644 --- a/src/Alpha_complex/example/CMakeLists.txt +++ b/src/Alpha_complex/example/CMakeLists.txt @@ -39,5 +39,13 @@ if(CGAL_FOUND) add_test(NAME Alpha_complex_example_weighted_3d_from_points COMMAND $) + add_executable ( Alpha_complex_example_3d_from_points Alpha_complex_3d_from_points.cpp ) + target_link_libraries(Alpha_complex_example_3d_from_points ${CGAL_LIBRARY}) + if (TBB_FOUND) + target_link_libraries(Alpha_complex_example_3d_from_points ${TBB_LIBRARIES}) + endif() + add_test(NAME Alpha_complex_example_3d_from_points + COMMAND $) + endif(NOT CGAL_WITH_EIGEN3_VERSION VERSION_LESS 4.11.0) endif() \ No newline at end of file diff --git a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp index abb73427..1b60ccd8 100644 --- a/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp +++ b/src/Alpha_complex/example/Weighted_alpha_complex_3d_from_points.cpp @@ -8,17 +8,10 @@ #include #include // for numeric limits -using Weighted_alpha_shapes_3d = Gudhi::alpha_complex::Weighted_alpha_shapes_3d; -using Weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; -using Point = Gudhi::alpha_complex::Weighted_alpha_shapes_3d::Point_3 ; +using Weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d; +using Point = Weighted_alpha_complex_3d::Point_3 ; using Vector_of_points = std::vector; -using Vector_of_weights = std::vector; - -void usage(int nbArgs, char * const progName) { - std::cerr << "Error: Number of arguments (" << nbArgs << ") is not correct\n"; - std::cerr << "Usage: " << progName << " \n"; - exit(-1); // ----- >> -} +using Vector_of_weights = std::vector; int main(int argc, char **argv) { if (argc != 1) { diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 15acd7bd..ed58c1c0 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -44,6 +44,8 @@ #include #include #include // for std::unique_ptr +#include // for std::conditional and std::enable_if + #if CGAL_VERSION_NR < 1041101000 // Make compilation fail - required for external projects - https://gitlab.inria.fr/GUDHI/gudhi-devel/issues/10 @@ -55,6 +57,13 @@ namespace Gudhi { namespace alpha_complex { +enum class complexity: char +{ + fast='f', + safe='s', + exact='e', +}; + /** * \class Alpha_complex_3d * \brief Alpha complex data structure for 3d specific case. @@ -75,9 +84,51 @@ namespace alpha_complex { * Delaunay complex. * */ -template +template class Alpha_complex_3d { - using Alpha_shape_3 = typename AlphaComplex3dOptions::Alpha_shape_3; + using Predicates = typename std::conditional<((!Weighted && !Periodic) || (Complexity == complexity::fast)), + CGAL::Exact_predicates_inexact_constructions_kernel, + CGAL::Exact_predicates_exact_constructions_kernel>::type; + + using Kernel = typename std::conditional, + Predicates>::type; + + using Exact_tag = typename std::conditional<(Complexity == complexity::fast), + CGAL::Tag_false, + CGAL::Tag_true>::type; + + using TdsVb = typename std::conditional, + CGAL::Triangulation_ds_vertex_base_3<>>::type; + + using Tvb = typename std::conditional, + CGAL::Triangulation_vertex_base_3>::type; + + using Vb = CGAL::Alpha_shape_vertex_base_3; + + using Tcb = typename std::conditional, + CGAL::Triangulation_cell_base_3>::type; + + using Cb = CGAL::Alpha_shape_cell_base_3; + using Tds = CGAL::Triangulation_data_structure_3; + + using Pre_triangulation_3 = typename std::conditional, + CGAL::Delaunay_triangulation_3>::type; + + using Triangulation_3 = typename std::conditional<(Weighted && Periodic), + CGAL::Periodic_3_regular_triangulation_3, + Pre_triangulation_3>::type; + +public: + using Alpha_shape_3 = CGAL::Alpha_shape_3; + + using Point_3 = typename Kernel::Point_3; + +private: using Alpha_value_type = typename Alpha_shape_3::FT; using Dispatch = CGAL::Dispatch_output_iterator, @@ -94,9 +145,6 @@ class Alpha_complex_3d { using Vertex_list = std::vector; #endif -public: - using Point_3 = typename AlphaComplex3dOptions::Point_3; - public: /** \brief Alpha_complex constructor from a list of points. * @@ -112,9 +160,9 @@ public: */ template Alpha_complex_3d(const InputPointRange& points) { - static_assert(!AlphaComplex3dOptions::weighted, + static_assert(!Weighted, "This constructor is not available for weighted versions of Alpha_complex_3d"); - static_assert(!AlphaComplex3dOptions::periodic, + static_assert(!Periodic, "This constructor is not available for periodic versions of Alpha_complex_3d"); alpha_shape_3_ptr_ = std::unique_ptr(new Alpha_shape_3(std::begin(points), std::end(points), 0, @@ -151,14 +199,14 @@ public: */ template Alpha_complex_3d(const InputPointRange& points, WeightRange weights) { - static_assert(AlphaComplex3dOptions::weighted, + static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex_3d"); - static_assert(!AlphaComplex3dOptions::periodic, + static_assert(!Periodic, "This constructor is not available for periodic versions of Alpha_complex_3d"); GUDHI_CHECK((weights.size() == points.size()), std::invalid_argument("Points number in range different from weights range number")); - using Weighted_point_3 = typename AlphaComplex3dOptions::Weighted_point_3; + using Weighted_point_3 = typename Triangulation_3::Weighted_point; std::vector weighted_points_3; std::size_t index = 0; @@ -207,13 +255,13 @@ public: * std::end return input iterators on a AlphaComplex3dOptions::Point_3. * The type of x_min, y_min, z_min, x_max, y_max and z_max is AlphaComplex3dOptions::Alpha_shape_3::FT. */ - template + /*template Alpha_complex_3d(const InputPointRange& points, Alpha_value_type x_min, Alpha_value_type y_min, Alpha_value_type z_min, Alpha_value_type x_max, Alpha_value_type y_max, Alpha_value_type z_max) { - static_assert(!AlphaComplex3dOptions::weighted, + static_assert(!Weighted, "This constructor is not available for weighted versions of Alpha_complex_3d"); - static_assert(AlphaComplex3dOptions::periodic, + static_assert(Periodic, "This constructor is not available for non-periodic versions of Alpha_complex_3d"); // Checking if the cuboid is the same in x,y and z direction. If not, CGAL will not process it. GUDHI_CHECK((x_max - x_min == y_max - y_min) && @@ -246,7 +294,7 @@ public: std::cout << "filtration_with_alpha_values returns : " << objects_.size() << " objects" << std::endl; #endif // DEBUG_TRACES - } + }*/ /** \brief Alpha_complex constructor from a list of points, associated weights and an iso-cuboid coordinates. * @@ -284,13 +332,13 @@ public: * std::end return an input iterator on a AlphaComplex3dOptions::Alpha_shape_3::FT. * The type of x_min, y_min, z_min, x_max, y_max and z_max is AlphaComplex3dOptions::Alpha_shape_3::FT. */ - template + /*template Alpha_complex_3d(const InputPointRange& points, WeightRange weights, Alpha_value_type x_min, Alpha_value_type y_min, Alpha_value_type z_min, Alpha_value_type x_max, Alpha_value_type y_max, Alpha_value_type z_max) { - static_assert(AlphaComplex3dOptions::weighted, + static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex_3d"); - static_assert(AlphaComplex3dOptions::periodic, + static_assert(Periodic, "This constructor is not available for non-periodic versions of Alpha_complex_3d"); GUDHI_CHECK((weights.size() == points.size()), std::invalid_argument("Points number in range different from weights range number")); @@ -344,6 +392,19 @@ public: #ifdef DEBUG_TRACES std::cout << "filtration_with_alpha_values returns : " << objects_.size() << " objects" << std::endl; #endif // DEBUG_TRACES + }*/ + template + typename std::enable_if::value, Filtration_value>::type + value_from_iterator(Alpha_value_iterator the_alpha_value_iterator) + { + return *(the_alpha_value_iterator); + } + + template + typename std::enable_if::value, Filtration_value>::type + value_from_iterator(Alpha_value_iterator the_alpha_value_iterator) + { + return CGAL::to_double(the_alpha_value_iterator->exact()); } @@ -455,11 +516,8 @@ public: } } // Construction of the simplex_tree - //Alpha_value_type filtr; - Filtration_value filtr = - AlphaComplex3dOptions::template value_from_iterator::iterator> - (the_alpha_value_iterator); + Filtration_value filtr = value_from_iterator(the_alpha_value_iterator); + #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; #endif // DEBUG_TRACES -- cgit v1.2.3