diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-08-28 21:11:26 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-08-28 21:11:26 +0000 |
commit | ef84bab542eb07d83515293652841969dd462b1c (patch) | |
tree | b250a609623f919fd4f8730976b065bdacf1ef96 /src/Alpha_complex | |
parent | 1b65f580392d33ac3d8516acced98de6906e6ed6 (diff) |
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
Diffstat (limited to 'src/Alpha_complex')
4 files changed, 147 insertions, 32 deletions
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 <gudhi/Alpha_complex_3d.h> +// to construct a simplex_tree from alpha complex +#include <gudhi/Simplex_tree.h> + +#include <iostream> +#include <string> +#include <vector> +#include <limits> // for numeric limits + +using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact, false, false>; +using Point = Alpha_complex_3d::Point_3 ; +using Vector_of_points = std::vector<Point>; + +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 $<TARGET_FILE:Alpha_complex_example_weighted_3d_from_points>) + 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 $<TARGET_FILE:Alpha_complex_example_3d_from_points>) + 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 <vector> #include <limits> // 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<Weighted_alpha_shapes_3d>; -using Point = Gudhi::alpha_complex::Weighted_alpha_shapes_3d::Point_3 ; +using Weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::exact, true, false>; +using Point = Weighted_alpha_complex_3d::Point_3 ; using Vector_of_points = std::vector<Point>; -using Vector_of_weights = std::vector<Gudhi::alpha_complex::Weighted_alpha_shapes_3d::Alpha_shape_3::FT>; - -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<Weighted_alpha_complex_3d::Alpha_shape_3::FT>; 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 <stdexcept> #include <cstddef> #include <memory> // for std::unique_ptr +#include <type_traits> // 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<typename AlphaComplex3dOptions> +template<complexity Complexity = complexity::fast, bool Weighted = false, bool Periodic = false> 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<Periodic, + CGAL::Periodic_3_Delaunay_triangulation_traits_3<Predicates>, + Predicates>::type; + + using Exact_tag = typename std::conditional<(Complexity == complexity::fast), + CGAL::Tag_false, + CGAL::Tag_true>::type; + + using TdsVb = typename std::conditional<Periodic, + CGAL::Periodic_3_triangulation_ds_vertex_base_3<>, + CGAL::Triangulation_ds_vertex_base_3<>>::type; + + using Tvb = typename std::conditional<Weighted, + CGAL::Regular_triangulation_vertex_base_3<Kernel, TdsVb>, + CGAL::Triangulation_vertex_base_3<Kernel, TdsVb>>::type; + + using Vb = CGAL::Alpha_shape_vertex_base_3<Kernel, Tvb, Exact_tag>; + + using Tcb = typename std::conditional<Weighted, + CGAL::Regular_triangulation_cell_base_3<Kernel>, + CGAL::Triangulation_cell_base_3<Kernel>>::type; + + using Cb = CGAL::Alpha_shape_cell_base_3<Kernel, Tcb, Exact_tag>; + using Tds = CGAL::Triangulation_data_structure_3<Vb, Cb>; + + using Pre_triangulation_3 = typename std::conditional<Weighted, + CGAL::Regular_triangulation_3<Kernel, Tds>, + CGAL::Delaunay_triangulation_3<Kernel, Tds>>::type; + + using Triangulation_3 = typename std::conditional<(Weighted && Periodic), + CGAL::Periodic_3_regular_triangulation_3<Kernel, Tds>, + Pre_triangulation_3>::type; + +public: + using Alpha_shape_3 = CGAL::Alpha_shape_3<Triangulation_3, Exact_tag>; + + using Point_3 = typename Kernel::Point_3; + +private: using Alpha_value_type = typename Alpha_shape_3::FT; using Dispatch = CGAL::Dispatch_output_iterator<CGAL::cpp11::tuple<CGAL::Object, Alpha_value_type>, @@ -95,9 +146,6 @@ class Alpha_complex_3d { #endif public: - using Point_3 = typename AlphaComplex3dOptions::Point_3; - -public: /** \brief Alpha_complex constructor from a list of points. * * Duplicate points are inserted once in the Alpha_complex. This is the reason why the vertices may be not contiguous. @@ -112,9 +160,9 @@ public: */ template<typename InputPointRange > 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<Alpha_shape_3>(new Alpha_shape_3(std::begin(points), std::end(points), 0, @@ -151,14 +199,14 @@ public: */ template<typename InputPointRange , typename WeightRange> 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_point_3> 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<typename InputPointRange> + /*template<typename InputPointRange> 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<typename InputPointRange , typename WeightRange> + /*template<typename InputPointRange , typename WeightRange> 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 <class Filtration_value, class Alpha_value_iterator> + typename std::enable_if<std::is_same<Exact_tag, CGAL::Tag_false>::value, Filtration_value>::type + value_from_iterator(Alpha_value_iterator the_alpha_value_iterator) + { + return *(the_alpha_value_iterator); + } + + template <class Filtration_value, class Alpha_value_iterator> + typename std::enable_if<std::is_same<Exact_tag, CGAL::Tag_true>::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<Filtration_value, - typename std::vector<Alpha_value_type>::iterator> - (the_alpha_value_iterator); + Filtration_value filtr = value_from_iterator<Filtration_value>(the_alpha_value_iterator); + #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; #endif // DEBUG_TRACES |