From dc9fc58500cc9f1be70e0d34a24cb634d4fc6c34 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Fri, 19 Jun 2020 20:29:46 +0200 Subject: When 3d points are on a 2d plane case - Fixes also default_filtration_value=True in 3d --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Alpha_complex/include/gudhi/Alpha_complex_3d.h') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index c19ebb79..c29905f4 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -471,6 +471,10 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ #ifdef DEBUG_TRACES std::clog << "filtration_with_alpha_values returns : " << objects.size() << " objects" << std::endl; #endif // DEBUG_TRACES + if (objects.size() == 0) { + std::cerr << "Alpha_complex_3d create_complex - no triangulation as points are on a 2d plane\n"; + return false; // ----- >> + } using Alpha_value_iterator = typename std::vector::const_iterator; Alpha_value_iterator alpha_value_iterator = alpha_values.begin(); -- cgit v1.2.3 From 88f7806d69115c1626c4abfb821b598a3078e18d Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sun, 28 Jun 2020 09:52:39 +0200 Subject: Use boost::size for unknown incoming ranges --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/Alpha_complex/include/gudhi/Alpha_complex_3d.h') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index c29905f4..231b1ea9 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -299,14 +300,14 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ Alpha_complex_3d(const InputPointRange& points, WeightRange weights) { static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex_3d"); static_assert(!Periodic, "This constructor is not available for periodic versions of Alpha_complex_3d"); - GUDHI_CHECK((weights.size() == points.size()), + GUDHI_CHECK(boost::size(weights) == boost::size(points), std::invalid_argument("Points number in range different from weights range number")); std::vector weighted_points_3; std::size_t index = 0; - weighted_points_3.reserve(points.size()); - while ((index < weights.size()) && (index < points.size())) { + weighted_points_3.reserve(boost::size(points)); + while ((index < boost::size(weights)) && (index < boost::size(points))) { weighted_points_3.push_back(Weighted_point_3(points[index], weights[index])); index++; } @@ -388,7 +389,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ FT z_min, FT x_max, FT y_max, FT z_max) { static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex_3d"); static_assert(Periodic, "This constructor is not available for non-periodic versions of Alpha_complex_3d"); - GUDHI_CHECK((weights.size() == points.size()), + GUDHI_CHECK(boost::size(weights) == boost::size(points), std::invalid_argument("Points number in range different from weights range number")); // Checking if the cuboid is the same in x,y and z direction. If not, CGAL will not process it. GUDHI_CHECK( @@ -398,14 +399,14 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ std::vector weighted_points_3; std::size_t index = 0; - weighted_points_3.reserve(points.size()); + weighted_points_3.reserve(boost::size(points)); #ifdef GUDHI_DEBUG // Defined in GUDHI_DEBUG to avoid unused variable warning for GUDHI_CHECK FT maximal_possible_weight = 0.015625 * (x_max - x_min) * (x_max - x_min); #endif - while ((index < weights.size()) && (index < points.size())) { + while ((index < boost::size(weights)) && (index < boost::size(points))) { GUDHI_CHECK((weights[index] < maximal_possible_weight) && (weights[index] >= 0), std::invalid_argument("Invalid weight at index " + std::to_string(index + 1) + ". Must be positive and less than maximal possible weight = 1/64*cuboid length " -- cgit v1.2.3 From d4b2ff6855f5ba0c6c18a697c3ee2be1973d388e Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sun, 28 Jun 2020 09:57:13 +0200 Subject: Use make_unique to construct a unique_ptr --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Alpha_complex/include/gudhi/Alpha_complex_3d.h') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 231b1ea9..9275946a 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -278,8 +278,8 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ Alpha_complex_3d(const InputPointRange& points) { 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, Alpha_shape_3::GENERAL)); + alpha_shape_3_ptr_ = std::make_unique( + std::begin(points), std::end(points), 0, Alpha_shape_3::GENERAL); } /** \brief Alpha_complex constructor from a list of points and associated weights. @@ -312,8 +312,8 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ index++; } - alpha_shape_3_ptr_ = std::unique_ptr( - new Alpha_shape_3(std::begin(weighted_points_3), std::end(weighted_points_3), 0, Alpha_shape_3::GENERAL)); + alpha_shape_3_ptr_ = std::make_unique( + std::begin(weighted_points_3), std::end(weighted_points_3), 0, Alpha_shape_3::GENERAL); } /** \brief Alpha_complex constructor from a list of points and an iso-cuboid coordinates. @@ -357,7 +357,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. This is the default mode // 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)); + alpha_shape_3_ptr_ = std::make_unique(pdt, 0, Alpha_shape_3::GENERAL); } /** \brief Alpha_complex constructor from a list of points, associated weights and an iso-cuboid coordinates. @@ -427,7 +427,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. This is the default mode // 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)); + alpha_shape_3_ptr_ = std::make_unique(pdt, 0, Alpha_shape_3::GENERAL); } /** \brief Inserts all Delaunay triangulation into the simplicial complex. -- cgit v1.2.3 From 3dca3a018edd271abf4d7c395801b777c725e2ad Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sun, 28 Jun 2020 09:58:51 +0200 Subject: Replace push_back(T(args...)) with emplace_back(args...) --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Alpha_complex/include/gudhi/Alpha_complex_3d.h') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 9275946a..17a3c6bd 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -308,7 +308,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ std::size_t index = 0; weighted_points_3.reserve(boost::size(points)); while ((index < boost::size(weights)) && (index < boost::size(points))) { - weighted_points_3.push_back(Weighted_point_3(points[index], weights[index])); + weighted_points_3.emplace_back(points[index], weights[index]); index++; } @@ -411,7 +411,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ std::invalid_argument("Invalid weight at index " + std::to_string(index + 1) + ". Must be positive and less than maximal possible weight = 1/64*cuboid length " "squared, which is not an acceptable input.")); - weighted_points_3.push_back(Weighted_point_3(points[index], weights[index])); + weighted_points_3.emplace_back(points[index], weights[index]); index++; } -- cgit v1.2.3 From feb70ad2c47cb0de3cfa1ca83a7773a91c8a99b9 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sun, 28 Jun 2020 10:22:19 +0200 Subject: Don't use input ranges as random access --- src/Alpha_complex/include/gudhi/Alpha_complex_3d.h | 35 +++++++++------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'src/Alpha_complex/include/gudhi/Alpha_complex_3d.h') diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 17a3c6bd..f56e12d0 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include @@ -300,17 +302,12 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ Alpha_complex_3d(const InputPointRange& points, WeightRange weights) { static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex_3d"); static_assert(!Periodic, "This constructor is not available for periodic versions of Alpha_complex_3d"); + // FIXME: this test is only valid if we have a forward range GUDHI_CHECK(boost::size(weights) == boost::size(points), std::invalid_argument("Points number in range different from weights range number")); - std::vector weighted_points_3; - - std::size_t index = 0; - weighted_points_3.reserve(boost::size(points)); - while ((index < boost::size(weights)) && (index < boost::size(points))) { - weighted_points_3.emplace_back(points[index], weights[index]); - index++; - } + auto weighted_points_3 = boost::range::combine(points, weights) + | boost::adaptors::transformed([](auto const&t){return Weighted_point_3(boost::get<0>(t), boost::get<1>(t));}); alpha_shape_3_ptr_ = std::make_unique( std::begin(weighted_points_3), std::end(weighted_points_3), 0, Alpha_shape_3::GENERAL); @@ -389,6 +386,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ FT z_min, FT x_max, FT y_max, FT z_max) { static_assert(Weighted, "This constructor is not available for non-weighted versions of Alpha_complex_3d"); static_assert(Periodic, "This constructor is not available for non-periodic versions of Alpha_complex_3d"); + // FIXME: this test is only valid if we have a forward range GUDHI_CHECK(boost::size(weights) == boost::size(points), std::invalid_argument("Points number in range different from weights range number")); // Checking if the cuboid is the same in x,y and z direction. If not, CGAL will not process it. @@ -396,24 +394,19 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_ (x_max - x_min == y_max - y_min) && (x_max - x_min == z_max - z_min) && (z_max - z_min == y_max - y_min), std::invalid_argument("The size of the cuboid in every directions is not the same.")); - std::vector weighted_points_3; - - std::size_t index = 0; - weighted_points_3.reserve(boost::size(points)); - #ifdef GUDHI_DEBUG // Defined in GUDHI_DEBUG to avoid unused variable warning for GUDHI_CHECK FT maximal_possible_weight = 0.015625 * (x_max - x_min) * (x_max - x_min); #endif - while ((index < boost::size(weights)) && (index < boost::size(points))) { - GUDHI_CHECK((weights[index] < maximal_possible_weight) && (weights[index] >= 0), - std::invalid_argument("Invalid weight at index " + std::to_string(index + 1) + - ". Must be positive and less than maximal possible weight = 1/64*cuboid length " - "squared, which is not an acceptable input.")); - weighted_points_3.emplace_back(points[index], weights[index]); - index++; - } + auto weighted_points_3 = boost::range::combine(points, weights) + | boost::adaptors::transformed([=](auto const&t){ + auto w = boost::get<1>(t); + GUDHI_CHECK((w < maximal_possible_weight) && (w >= 0), + std::invalid_argument("Invalid weight " + std::to_string(w) + + ". Must be non-negative and less than maximal possible weight = 1/64*cuboid length squared.")); + return Weighted_point_3(boost::get<0>(t), w); + }); // Define the periodic cube Dt pdt(typename Kernel::Iso_cuboid_3(x_min, y_min, z_min, x_max, y_max, z_max)); -- cgit v1.2.3