From 9ded4522e4be2b018172c0563b2acf9d5cdc5b44 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 17 Sep 2018 20:58:41 +0000 Subject: Add benchmark Safe version for Alpha complex 3d (missing part if not weighted and not periodic) Need to fix Alpha_complex_3d_unit_test git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_3d_module_vincent@3893 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 304c9f89826008eab67a72f3742caa8d6d80f36b --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 119 +++++++++++---------- .../include/gudhi/Alpha_complex_options.h | 13 --- 2 files changed, 63 insertions(+), 69 deletions(-) (limited to 'src/Alpha_complex/include') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 6e25814f..3f145272 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -33,6 +33,18 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -57,6 +69,40 @@ namespace Gudhi { namespace alpha_complex { +template +struct Value_from_iterator +{ + template + static double perform(Iterator it) + { + // Default behaviour is to return the value pointed by the given iterator + return *it; + } +}; + +template <> +struct Value_from_iterator +{ + template + static double perform(Iterator it) + { + // In safe mode, we are with Epeck or Epick with exact value set to CGAL::Tag_true. + return CGAL::to_double(*it); + } +}; + +template <> +struct Value_from_iterator +{ + template + static double perform(Iterator it) + { + // In exact mode, we are with Epeck or Epick with exact value set to CGAL::Tag_true. + return CGAL::to_double(it->exact()); + } +}; + + /** * \class Alpha_complex_3d * \brief Alpha complex data structure for 3d specific case. @@ -207,14 +253,6 @@ public: alpha_shape_3_ptr_ = std::unique_ptr(new Alpha_shape_3(std::begin(points), std::end(points), 0, Alpha_shape_3::GENERAL)); - Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects_), - std::back_inserter(alpha_values_)); - - alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << objects_.size() << " objects" << std::endl; -#endif // DEBUG_TRACES - } /** \brief Alpha_complex constructor from a list of points and associated weights. @@ -254,14 +292,6 @@ public: std::end(weighted_points_3), 0, Alpha_shape_3::GENERAL)); - - Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects_), - std::back_inserter(alpha_values_)); - - alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); -#ifdef DEBUG_TRACES - std::cout << "filtration_with_alpha_values returns : " << objects_.size() << " objects" << std::endl; -#endif // DEBUG_TRACES } /** \brief Alpha_complex constructor from a list of points and an iso-cuboid coordinates. @@ -311,15 +341,6 @@ public: // Maybe need to set it to GENERAL mode alpha_shape_3_ptr_ = std::unique_ptr(new Alpha_shape_3(pdt, 0, Alpha_shape_3::GENERAL)); - - Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects_), - std::back_inserter(alpha_values_)); - - alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); -#ifdef DEBUG_TRACES - 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. @@ -396,31 +417,8 @@ public: // Maybe need to set it to GENERAL mode alpha_shape_3_ptr_ = std::unique_ptr(new Alpha_shape_3(pdt, 0, Alpha_shape_3::GENERAL)); - - Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects_), - std::back_inserter(alpha_values_)); - - alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); -#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()); - } - - /** \brief Inserts all Delaunay triangulation into the simplicial complex. * It also computes the filtration values accordingly to the \ref createcomplexalgorithm * @@ -457,10 +455,21 @@ public: std::size_t count_facets = 0; std::size_t count_cells = 0; #endif // DEBUG_TRACES + std::vector objects; + std::vector alpha_values; + + Dispatch dispatcher = CGAL::dispatch_output(std::back_inserter(objects), + std::back_inserter(alpha_values)); + alpha_shape_3_ptr_->filtration_with_alpha_values(dispatcher); +#ifdef DEBUG_TRACES + std::cout << "filtration_with_alpha_values returns : " << objects.size() << " objects" << std::endl; +#endif // DEBUG_TRACES + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - auto the_alpha_value_iterator = alpha_values_.begin(); - for (auto object_iterator : objects_) { + using Alpha_value_iterator = typename std::vector::const_iterator; + Alpha_value_iterator alpha_value_iterator = alpha_values.begin(); + for (auto object_iterator : objects) { Vertex_list vertex_list; // Retrieve Alpha shape vertex list from object @@ -525,14 +534,14 @@ public: } } // Construction of the simplex_tree - Filtration_value filtr = value_from_iterator(the_alpha_value_iterator); + Filtration_value filtr = Value_from_iterator::perform(alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; #endif // DEBUG_TRACES complex.insert_simplex(the_simplex, static_cast(filtr)); - GUDHI_CHECK(the_alpha_value_iterator != alpha_values_.end(), "CGAL provided more simplices than values"); - ++the_alpha_value_iterator; + GUDHI_CHECK(alpha_value_iterator != alpha_values.end(), "CGAL provided more simplices than values"); + ++alpha_value_iterator; } #ifdef DEBUG_TRACES @@ -551,10 +560,8 @@ public: } private: - // Needs to store alpha_shape_3_ptr_ as objects_ are freed with alpha_shape_3_ptr_ + // use of a unique_ptr on cgal Alpha_shape_3, as copy and default constructor is not available - no need to be freed std::unique_ptr alpha_shape_3_ptr_; - std::vector objects_; - std::vector alpha_values_; }; diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_options.h b/src/Alpha_complex/include/gudhi/Alpha_complex_options.h index 32980fa7..cd9fe799 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_options.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_options.h @@ -24,23 +24,10 @@ #define ALPHA_COMPLEX_OPTIONS_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - namespace Gudhi { namespace alpha_complex { - /** * \class complexity * \brief Alpha complex complexity template parameter possible values. -- cgit v1.2.3