From 4e4b190e9f3937f3f136c83e42c3c9322074f16a Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 14 Nov 2018 09:47:52 +0000 Subject: Fix https://github.com/CGAL/cgal/issues/3153 git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alpha_complex_3d_module_vincent@3978 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 41b598d277452a2ebcf9eedc3a7e144d96e46b1d --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 49 ++++++++++++++++++---- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 0333abbd..00a47d5c 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -67,12 +67,20 @@ namespace Gudhi { namespace alpha_complex { +#ifdef GUDHI_CAN_USE_CXX11_THREAD_LOCAL +thread_local +#endif // GUDHI_CAN_USE_CXX11_THREAD_LOCAL + double RELATIVE_PRECISION_OF_TO_DOUBLE = 0.00001; + // Value_from_iterator returns the filtration value from an iterator on alpha shapes values // -// FAST SAFE EXACT -// *iterator CGAL::to_double(*iterator) CGAL::to_double(iterator->exact()) +// FAST SAFE EXACT +// not weighted and *iterator Specific case due to CGAL CGAL::to_double(iterator->exact()) +// not periodic issue # 3153 +// +// otherwise *iterator CGAL::to_double(*iterator) CGAL::to_double(iterator->exact()) -template +template struct Value_from_iterator { template static double perform(Iterator it) { @@ -82,16 +90,43 @@ struct Value_from_iterator { }; template <> -struct Value_from_iterator { +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. + // In SAFE mode, we are with Epick with EXACT value set to CGAL::Tag_true. return CGAL::to_double(*it); } }; template <> -struct Value_from_iterator { +struct Value_from_iterator { + template + static double perform(Iterator it) { + // In SAFE mode, we are with Epeck with EXACT value set to CGAL::Tag_true. + // Specific case due to CGAL issue https://github.com/CGAL/cgal/issues/3153 + auto approx = it->approx(); + double r; + if (CGAL::fit_in_double(approx, r)) return r; + + // If it's precise enough, then OK. + if (CGAL::has_smaller_relative_precision(approx, RELATIVE_PRECISION_OF_TO_DOUBLE)) return CGAL::to_double(approx); + + it->exact(); + return CGAL::to_double(it->approx()); + } +}; + +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()); + } +}; + +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. @@ -524,7 +559,7 @@ class Alpha_complex_3d { } } // Construction of the simplex_tree - Filtration_value filtr = Value_from_iterator::perform(alpha_value_iterator); + Filtration_value filtr = Value_from_iterator::perform(alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; -- cgit v1.2.3