diff options
author | Vincent Rouvreau <10407034+VincentRouvreau@users.noreply.github.com> | 2019-11-16 22:58:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-16 22:58:25 +0100 |
commit | 6c341ffd5500f6393467fce3f5e091afc354d25b (patch) | |
tree | f1f33cc70852959c4dbed2266cccd126074b3560 | |
parent | 184587947b18daf57583c7cb111ad315b8d48a43 (diff) | |
parent | 6d2e5d1cbdecd86ad4d56fc8902542caca2cf2bd (diff) |
Merge pull request #123 from VincentRouvreau/alpha_complex_3d_get_point
Add a get_point method for Alpha_complex_3d.
8 files changed, 186 insertions, 79 deletions
diff --git a/src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp b/src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp index 005a712a..99ad94b9 100644 --- a/src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp +++ b/src/Alpha_complex/benchmark/Alpha_complex_3d_benchmark.cpp @@ -115,7 +115,7 @@ void benchmark_weighted_points_on_torus_3D(const std::string& msg) { std::cout << " Alpha complex 3d on torus with " << nb_points << " points." << std::endl; std::vector<K::Point_d> points_on_torus = Gudhi::generate_points_on_torus_3D<K>(nb_points, 1.0, 0.5); - using Point = typename Weighted_alpha_complex_3d::Point_3; + using Point = typename Weighted_alpha_complex_3d::Bare_point_3; using Weighted_point = typename Weighted_alpha_complex_3d::Weighted_point_3; std::vector<Weighted_point> points; @@ -206,7 +206,7 @@ void benchmark_weighted_periodic_points(const std::string& msg) { std::cout << " Weighted periodic alpha complex 3d with " << nb_points * nb_points * nb_points << " points." << std::endl; - using Point = typename Weighted_periodic_alpha_complex_3d::Point_3; + using Point = typename Weighted_periodic_alpha_complex_3d::Bare_point_3; using Weighted_point = typename Weighted_periodic_alpha_complex_3d::Weighted_point_3; std::vector<Weighted_point> points; 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 ac11b68c..fcf80802 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 @@ -10,7 +10,7 @@ // Complexity = FAST, weighted = true, periodic = false using Weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::SAFE, true, false>; -using Point = Weighted_alpha_complex_3d::Point_3; +using Bare_point = Weighted_alpha_complex_3d::Bare_point_3; using Weighted_point = Weighted_alpha_complex_3d::Weighted_point_3; int main(int argc, char **argv) { @@ -18,11 +18,11 @@ int main(int argc, char **argv) { // Init of a list of points and weights from a small molecule // ---------------------------------------------------------------------------- std::vector<Weighted_point> weighted_points; - weighted_points.push_back(Weighted_point(Point(1, -1, -1), 4.)); - weighted_points.push_back(Weighted_point(Point(-1, 1, -1), 4.)); - weighted_points.push_back(Weighted_point(Point(-1, -1, 1), 4.)); - weighted_points.push_back(Weighted_point(Point(1, 1, 1), 4.)); - weighted_points.push_back(Weighted_point(Point(2, 2, 2), 1.)); + weighted_points.push_back(Weighted_point(Bare_point(1, -1, -1), 4.)); + weighted_points.push_back(Weighted_point(Bare_point(-1, 1, -1), 4.)); + weighted_points.push_back(Weighted_point(Bare_point(-1, -1, 1), 4.)); + weighted_points.push_back(Weighted_point(Bare_point(1, 1, 1), 4.)); + weighted_points.push_back(Weighted_point(Bare_point(2, 2, 2), 1.)); // ---------------------------------------------------------------------------- // Init of an alpha complex from the list of points diff --git a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h index 13ebb9c1..7f96c94c 100644 --- a/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h +++ b/src/Alpha_complex/include/gudhi/Alpha_complex_3d.h @@ -43,7 +43,7 @@ #include <vector> #include <unordered_map> #include <stdexcept> -#include <cstddef> +#include <cstddef> // for std::size_t #include <memory> // for std::unique_ptr #include <type_traits> // for std::conditional and std::enable_if #include <limits> // for numeric_limits<> @@ -97,7 +97,7 @@ struct Value_from_iterator<complexity::EXACT> { * \details * The data structure is constructing a <a href="https://doc.cgal.org/latest/Alpha_shapes_3/index.html">CGAL 3D Alpha * Shapes</a> from a range of points (can be read from an OFF file, cf. Points_off_reader). - * Duplicate points are inserted once in the Alpha_complex. This is the reason why the vertices may be not contiguous. + * Duplicate points are inserted once in the Alpha_complex. * * \tparam Complexity shall be `Gudhi::alpha_complex::complexity` type. Default value is * `Gudhi::alpha_complex::complexity::SAFE`. @@ -225,23 +225,23 @@ class Alpha_complex_3d { * Must be compatible with double. */ using FT = typename Alpha_shape_3::FT; - /** \brief Gives public access to the Point_3 type. Here is a Point_3 constructor example: + /** \brief Gives public access to the Bare_point_3 (bare aka. unweighed) type. + * Here is a Bare_point_3 constructor example: \code{.cpp} using Alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::SAFE, false, false>; // x0 = 1., y0 = -1.1, z0 = -1.. -Alpha_complex_3d::Point_3 p0(1., -1.1, -1.); +Alpha_complex_3d::Bare_point_3 p0(1., -1.1, -1.); \endcode * */ - using Point_3 = typename Kernel::Point_3; + using Bare_point_3 = typename Kernel::Point_3; /** \brief Gives public access to the Weighted_point_3 type. A Weighted point can be constructed as follows: \code{.cpp} -using Weighted_alpha_complex_3d = - Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::SAFE, true, false>; +using Weighted_alpha_complex_3d = Gudhi::alpha_complex::Alpha_complex_3d<Gudhi::alpha_complex::complexity::SAFE, true, false>; // x0 = 1., y0 = -1.1, z0 = -1., weight = 4. -Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point_3(1., -1.1, -1.), 4.); +Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Bare_point_3(1., -1.1, -1.), 4.); \endcode * * Note: This type is defined to void if Alpha complex is not weighted. @@ -249,6 +249,11 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point * */ using Weighted_point_3 = typename Triangulation_3<Kernel, Tds, Weighted, Periodic>::Weighted_point_3; + /** \brief `Alpha_complex_3d::Point_3` type is either a `Alpha_complex_3d::Bare_point_3` (Weighted = false) or a + * `Alpha_complex_3d::Weighted_point_3` (Weighted = true). + */ + using Point_3 = typename Alpha_shape_3::Point; + private: using Dispatch = CGAL::Dispatch_output_iterator<CGAL::cpp11::tuple<CGAL::Object, FT>, @@ -264,13 +269,12 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point public: /** \brief Alpha_complex constructor from a list of points. * - * @param[in] points Range of points to triangulate. Points must be in `Alpha_complex_3d::Point_3` or - * `Alpha_complex_3d::Weighted_point_3`. + * @param[in] points Range of points to triangulate. Points must be in `Alpha_complex_3d::Point_3`. * * @pre Available if Alpha_complex_3d is not Periodic. * * The type InputPointRange must be a range for which std::begin and std::end return input iterators on a - * `Alpha_complex_3d::Point_3` or a `Alpha_complex_3d::Weighted_point_3`. + * `Alpha_complex_3d::Point_3`. */ template <typename InputPointRange> Alpha_complex_3d(const InputPointRange& points) { @@ -284,13 +288,13 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point * * @exception std::invalid_argument In debug mode, if points and weights do not have the same size. * - * @param[in] points Range of points to triangulate. Points must be in `Alpha_complex_3d::Point_3`. + * @param[in] points Range of points to triangulate. Points must be in `Alpha_complex_3d::Bare_point_3`. * @param[in] weights Range of weights on points. Weights shall be in double. * * @pre Available if Alpha_complex_3d is Weighted and not Periodic. * * The type InputPointRange must be a range for which std::begin and - * std::end return input iterators on a `Alpha_complex_3d::Point_3`. + * std::end return input iterators on a `Alpha_complex_3d::Bare_point_3`. * The type WeightRange must be a range for which std::begin and * std::end return an input iterator on a double. */ @@ -318,8 +322,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point * * @exception std::invalid_argument In debug mode, if the size of the cuboid in every directions is not the same. * - * @param[in] points Range of points to triangulate. Points must be in `Alpha_complex_3d::Point_3` or - * `Alpha_complex_3d::Weighted_point_3`. + * @param[in] points Range of points to triangulate. Points must be in `Alpha_complex_3d::Point_3`. * @param[in] x_min Iso-oriented cuboid x_min. * @param[in] y_min Iso-oriented cuboid y_min. * @param[in] z_min Iso-oriented cuboid z_min. @@ -330,7 +333,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point * @pre Available if Alpha_complex_3d is Periodic. * * The type InputPointRange must be a range for which std::begin and std::end return input iterators on a - * `Alpha_complex_3d::Point_3` or a `Alpha_complex_3d::Weighted_point_3`. + * `Alpha_complex_3d::Point_3`. * * @note In weighted version, please check weights are greater than zero, and lower than 1/64*cuboid length * squared. @@ -366,7 +369,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point * @exception std::invalid_argument In debug mode, if a weight is negative, zero, or greater than 1/64*cuboid length * squared. * - * @param[in] points Range of points to triangulate. Points must be in `Alpha_complex_3d::Point_3`. + * @param[in] points Range of points to triangulate. Points must be in `Alpha_complex_3d::Bare_point_3`. * @param[in] weights Range of weights on points. Weights shall be in double. * @param[in] x_min Iso-oriented cuboid x_min. * @param[in] y_min Iso-oriented cuboid y_min. @@ -378,7 +381,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point * @pre Available if Alpha_complex_3d is Weighted and Periodic. * * The type InputPointRange must be a range for which std::begin and - * std::end return input iterators on a `Alpha_complex_3d::Point_3`. + * std::end return input iterators on a `Alpha_complex_3d::Bare_point_3`. * The type WeightRange must be a range for which std::begin and * std::end return an input iterator on a double. * The type of x_min, y_min, z_min, x_max, y_max and z_max must be a double. @@ -452,9 +455,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point return false; // ----- >> } - // using Filtration_value = typename SimplicialComplexForAlpha3d::Filtration_value; using Complex_vertex_handle = typename SimplicialComplexForAlpha3d::Vertex_handle; - using Alpha_shape_simplex_tree_map = std::unordered_map<Alpha_vertex_handle, Complex_vertex_handle>; using Simplex_tree_vector_vertex = std::vector<Complex_vertex_handle>; #ifdef DEBUG_TRACES @@ -474,7 +475,6 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point std::cout << "filtration_with_alpha_values returns : " << objects.size() << " objects" << std::endl; #endif // DEBUG_TRACES - Alpha_shape_simplex_tree_map map_cgal_simplex_tree; using Alpha_value_iterator = typename std::vector<FT>::const_iterator; Alpha_value_iterator alpha_value_iterator = alpha_values.begin(); for (auto object_iterator : objects) { @@ -484,7 +484,8 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point if (const Cell_handle* cell = CGAL::object_cast<Cell_handle>(&object_iterator)) { for (auto i = 0; i < 4; i++) { #ifdef DEBUG_TRACES - std::cout << "from cell[" << i << "]=" << (*cell)->vertex(i)->point() << std::endl; + std::cout << "from cell[" << i << "] - Point coordinates (" << (*cell)->vertex(i)->point() << ")" + << std::endl; #endif // DEBUG_TRACES vertex_list.push_back((*cell)->vertex(i)); } @@ -495,7 +496,8 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point for (auto i = 0; i < 4; i++) { if ((*facet).second != i) { #ifdef DEBUG_TRACES - std::cout << "from facet=[" << i << "]" << (*facet).first->vertex(i)->point() << std::endl; + std::cout << "from facet=[" << i << "] - Point coordinates (" << (*facet).first->vertex(i)->point() << ")" + << std::endl; #endif // DEBUG_TRACES vertex_list.push_back((*facet).first->vertex(i)); } @@ -506,7 +508,8 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point } else if (const Edge* edge = CGAL::object_cast<Edge>(&object_iterator)) { for (auto i : {(*edge).second, (*edge).third}) { #ifdef DEBUG_TRACES - std::cout << "from edge[" << i << "]=" << (*edge).first->vertex(i)->point() << std::endl; + std::cout << "from edge[" << i << "] - Point coordinates (" << (*edge).first->vertex(i)->point() << ")" + << std::endl; #endif // DEBUG_TRACES vertex_list.push_back((*edge).first->vertex(i)); } @@ -516,7 +519,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point } else if (const Alpha_vertex_handle* vertex = CGAL::object_cast<Alpha_vertex_handle>(&object_iterator)) { #ifdef DEBUG_TRACES count_vertices++; - std::cout << "from vertex=" << (*vertex)->point() << std::endl; + std::cout << "from vertex - Point coordinates (" << (*vertex)->point() << ")" << std::endl; #endif // DEBUG_TRACES vertex_list.push_back((*vertex)); } @@ -528,7 +531,8 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point // alpha shape not found Complex_vertex_handle vertex = map_cgal_simplex_tree.size(); #ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; + std::cout << "Point (" << the_alpha_shape_vertex->point() << ") not found - insert new vertex id " << vertex + << std::endl; #endif // DEBUG_TRACES the_simplex.push_back(vertex); map_cgal_simplex_tree.emplace(the_alpha_shape_vertex, vertex); @@ -536,7 +540,7 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point // alpha shape found Complex_vertex_handle vertex = the_map_iterator->second; #ifdef DEBUG_TRACES - std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; + std::cout << "Point (" << the_alpha_shape_vertex->point() << ") found as vertex id " << vertex << std::endl; #endif // DEBUG_TRACES the_simplex.push_back(vertex); } @@ -567,9 +571,32 @@ Weighted_alpha_complex_3d::Weighted_point_3 wp0(Weighted_alpha_complex_3d::Point return true; } + /** \brief get_point returns the point corresponding to the vertex given as parameter. + * + * @param[in] vertex Vertex handle of the point to retrieve. + * @return The point found. + * @exception std::out_of_range In case vertex is not found (cf. std::vector::at). + */ + const Point_3& get_point(std::size_t vertex) { + if (map_cgal_simplex_tree.size() != cgal_vertex_iterator_vector.size()) { + cgal_vertex_iterator_vector.resize(map_cgal_simplex_tree.size()); + for (auto map_iterator : map_cgal_simplex_tree) { + cgal_vertex_iterator_vector[map_iterator.second] = map_iterator.first; + } + + } + auto cgal_vertex_iterator = cgal_vertex_iterator_vector.at(vertex); + return cgal_vertex_iterator->point(); + } + private: // 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> alpha_shape_3_ptr_; + + // Map type to switch from CGAL vertex iterator to simplex tree vertex handle. + std::unordered_map<Alpha_vertex_handle, std::size_t> map_cgal_simplex_tree; + // Vector type to switch from simplex tree vertex handle to CGAL vertex iterator. + std::vector<Alpha_vertex_handle> cgal_vertex_iterator_vector; }; } // namespace alpha_complex diff --git a/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp index 1102838a..cd698a27 100644 --- a/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_complex_3d_unit_test.cpp @@ -56,21 +56,52 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_3d_from_points) { // ----------------- std::cout << "Fast alpha complex 3d" << std::endl; - Fast_alpha_complex_3d alpha_complex(get_points<Fast_alpha_complex_3d::Point_3>()); + std::vector<Fast_alpha_complex_3d::Bare_point_3> points = get_points<Fast_alpha_complex_3d::Bare_point_3>(); + Fast_alpha_complex_3d alpha_complex(points); Gudhi::Simplex_tree<> stree; alpha_complex.create_complex(stree); + for (std::size_t index = 0; index < points.size(); index++) { + bool found = false; + for (auto point : points) { + if (point == alpha_complex.get_point(index)) { + found = true; + break; + } + } + // Check all points from alpha complex are found in the input point cloud + BOOST_CHECK(found); + } + // Exception if we go out of range + BOOST_CHECK_THROW(alpha_complex.get_point(points.size()), std::out_of_range); + // ----------------- // Exact version // ----------------- std::cout << "Exact alpha complex 3d" << std::endl; - Exact_alpha_complex_3d exact_alpha_complex(get_points<Exact_alpha_complex_3d::Point_3>()); + std::vector<Exact_alpha_complex_3d::Bare_point_3> exact_points = get_points<Exact_alpha_complex_3d::Bare_point_3>(); + Exact_alpha_complex_3d exact_alpha_complex(exact_points); Gudhi::Simplex_tree<> exact_stree; exact_alpha_complex.create_complex(exact_stree); + for (std::size_t index = 0; index < exact_points.size(); index++) { + bool found = false; + Exact_alpha_complex_3d::Bare_point_3 ap = exact_alpha_complex.get_point(index); + for (auto point : points) { + if ((point.x() == ap.x()) && (point.y() == ap.y()) && (point.z() == ap.z())) { + found = true; + break; + } + } + // Check all points from alpha complex are found in the input point cloud + BOOST_CHECK(found); + } + // Exception if we go out of range + BOOST_CHECK_THROW(exact_alpha_complex.get_point(exact_points.size()), std::out_of_range); + // --------------------- // Compare both versions // --------------------- @@ -110,11 +141,27 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_3d_from_points) { // ----------------- std::cout << "Safe alpha complex 3d" << std::endl; - Safe_alpha_complex_3d safe_alpha_complex(get_points<Safe_alpha_complex_3d::Point_3>()); + std::vector<Safe_alpha_complex_3d::Bare_point_3> safe_points = get_points<Safe_alpha_complex_3d::Bare_point_3>(); + Safe_alpha_complex_3d safe_alpha_complex(safe_points); Gudhi::Simplex_tree<> safe_stree; safe_alpha_complex.create_complex(safe_stree); + for (std::size_t index = 0; index < safe_points.size(); index++) { + bool found = false; + Safe_alpha_complex_3d::Bare_point_3 ap = safe_alpha_complex.get_point(index); + for (auto point : points) { + if ((point.x() == ap.x()) && (point.y() == ap.y()) && (point.z() == ap.z())) { + found = true; + break; + } + } + // Check all points from alpha complex are found in the input point cloud + BOOST_CHECK(found); + } + // Exception if we go out of range + BOOST_CHECK_THROW(safe_alpha_complex.get_point(safe_points.size()), std::out_of_range); + // --------------------- // Compare both versions // --------------------- diff --git a/src/Alpha_complex/test/Periodic_alpha_complex_3d_unit_test.cpp b/src/Alpha_complex/test/Periodic_alpha_complex_3d_unit_test.cpp index ac3791a4..731763fa 100644 --- a/src/Alpha_complex/test/Periodic_alpha_complex_3d_unit_test.cpp +++ b/src/Alpha_complex/test/Periodic_alpha_complex_3d_unit_test.cpp @@ -44,11 +44,11 @@ typedef boost::mpl::list<Fast_periodic_alpha_complex_3d, Safe_periodic_alpha_com BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_periodic_throw, Periodic_alpha_complex_3d, periodic_variants_type_list) { std::cout << "Periodic alpha complex 3d exception throw" << std::endl; - using Point_3 = typename Periodic_alpha_complex_3d::Point_3; - std::vector<Point_3> p_points; + using Bare_point_3 = typename Periodic_alpha_complex_3d::Bare_point_3; + std::vector<Bare_point_3> p_points; // Not important, this is not what we want to check - p_points.push_back(Point_3(0.0, 0.0, 0.0)); + p_points.push_back(Bare_point_3(0.0, 0.0, 0.0)); std::cout << "Check exception throw in debug mode" << std::endl; // Check it throws an exception when the cuboid is not iso @@ -73,13 +73,13 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_periodic) { // --------------------- std::cout << "Fast periodic alpha complex 3d" << std::endl; - using Creator = CGAL::Creator_uniform_3<double, Fast_periodic_alpha_complex_3d::Point_3>; + using Creator = CGAL::Creator_uniform_3<double, Fast_periodic_alpha_complex_3d::Bare_point_3>; CGAL::Random random(7); - CGAL::Random_points_in_cube_3<Fast_periodic_alpha_complex_3d::Point_3, Creator> in_cube(1, random); - std::vector<Fast_periodic_alpha_complex_3d::Point_3> p_points; + CGAL::Random_points_in_cube_3<Fast_periodic_alpha_complex_3d::Bare_point_3, Creator> in_cube(1, random); + std::vector<Fast_periodic_alpha_complex_3d::Bare_point_3> p_points; for (int i = 0; i < 50; i++) { - Fast_periodic_alpha_complex_3d::Point_3 p = *in_cube++; + Fast_periodic_alpha_complex_3d::Bare_point_3 p = *in_cube++; p_points.push_back(p); } @@ -88,15 +88,30 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_periodic) { Gudhi::Simplex_tree<> stree; periodic_alpha_complex.create_complex(stree); + for (std::size_t index = 0; index < p_points.size(); index++) { + bool found = false; + Fast_periodic_alpha_complex_3d::Bare_point_3 ap = periodic_alpha_complex.get_point(index); + for (auto point : p_points) { + if ((point.x() == ap.x()) && (point.y() == ap.y()) && (point.z() == ap.z())) { + found = true; + break; + } + } + // Check all points from alpha complex are found in the input point cloud + BOOST_CHECK(found); + } + // Exception if we go out of range + BOOST_CHECK_THROW(periodic_alpha_complex.get_point(p_points.size()), std::out_of_range); + // ---------------------- // Exact periodic version // ---------------------- std::cout << "Exact periodic alpha complex 3d" << std::endl; - std::vector<Exact_periodic_alpha_complex_3d::Point_3> e_p_points; + std::vector<Exact_periodic_alpha_complex_3d::Bare_point_3> e_p_points; for (auto p : p_points) { - e_p_points.push_back(Exact_periodic_alpha_complex_3d::Point_3(p[0], p[1], p[2])); + e_p_points.push_back(Exact_periodic_alpha_complex_3d::Bare_point_3(p[0], p[1], p[2])); } Exact_periodic_alpha_complex_3d exact_alpha_complex(e_p_points, -1., -1., -1., 1., 1., 1.); @@ -142,10 +157,10 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_periodic) { // ---------------------- std::cout << "Safe periodic alpha complex 3d" << std::endl; - std::vector<Safe_periodic_alpha_complex_3d::Point_3> s_p_points; + std::vector<Safe_periodic_alpha_complex_3d::Bare_point_3> s_p_points; for (auto p : p_points) { - s_p_points.push_back(Safe_periodic_alpha_complex_3d::Point_3(p[0], p[1], p[2])); + s_p_points.push_back(Safe_periodic_alpha_complex_3d::Bare_point_3(p[0], p[1], p[2])); } Safe_periodic_alpha_complex_3d safe_alpha_complex(s_p_points, -1., -1., -1., 1., 1., 1.); diff --git a/src/Alpha_complex/test/Weighted_alpha_complex_3d_unit_test.cpp b/src/Alpha_complex/test/Weighted_alpha_complex_3d_unit_test.cpp index 44deb930..8035f6e8 100644 --- a/src/Alpha_complex/test/Weighted_alpha_complex_3d_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_alpha_complex_3d_unit_test.cpp @@ -43,14 +43,14 @@ typedef boost::mpl::list<Fast_weighted_alpha_complex_3d, Safe_weighted_alpha_com #ifdef GUDHI_DEBUG BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_throw, Weighted_alpha_complex_3d, weighted_variants_type_list) { - using Point_3 = typename Weighted_alpha_complex_3d::Point_3; - std::vector<Point_3> w_points; - w_points.push_back(Point_3(0.0, 0.0, 0.0)); - w_points.push_back(Point_3(0.0, 0.0, 0.2)); - w_points.push_back(Point_3(0.2, 0.0, 0.2)); - // w_points.push_back(Point_3(0.6, 0.6, 0.0)); - // w_points.push_back(Point_3(0.8, 0.8, 0.2)); - // w_points.push_back(Point_3(0.2, 0.8, 0.6)); + using Bare_point_3 = typename Weighted_alpha_complex_3d::Bare_point_3; + std::vector<Bare_point_3> w_points; + w_points.push_back(Bare_point_3(0.0, 0.0, 0.0)); + w_points.push_back(Bare_point_3(0.0, 0.0, 0.2)); + w_points.push_back(Bare_point_3(0.2, 0.0, 0.2)); + // w_points.push_back(Bare_point_3(0.6, 0.6, 0.0)); + // w_points.push_back(Bare_point_3(0.8, 0.8, 0.2)); + // w_points.push_back(Bare_point_3(0.2, 0.8, 0.6)); // weights size is different from w_points size to make weighted Alpha_complex_3d throw in debug mode std::vector<double> weights = {0.01, 0.005, 0.006, 0.01, 0.009, 0.001}; @@ -62,14 +62,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_throw, Weighted_alpha_compl BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted, Weighted_alpha_complex_3d, weighted_variants_type_list) { std::cout << "Weighted alpha complex 3d from points and weights" << std::endl; - using Point_3 = typename Weighted_alpha_complex_3d::Point_3; - std::vector<Point_3> w_points; - w_points.push_back(Point_3(0.0, 0.0, 0.0)); - w_points.push_back(Point_3(0.0, 0.0, 0.2)); - w_points.push_back(Point_3(0.2, 0.0, 0.2)); - w_points.push_back(Point_3(0.6, 0.6, 0.0)); - w_points.push_back(Point_3(0.8, 0.8, 0.2)); - w_points.push_back(Point_3(0.2, 0.8, 0.6)); + using Bare_point_3 = typename Weighted_alpha_complex_3d::Bare_point_3; + std::vector<Bare_point_3> w_points; + w_points.push_back(Bare_point_3(0.0, 0.0, 0.0)); + w_points.push_back(Bare_point_3(0.0, 0.0, 0.2)); + w_points.push_back(Bare_point_3(0.2, 0.0, 0.2)); + w_points.push_back(Bare_point_3(0.6, 0.6, 0.0)); + w_points.push_back(Bare_point_3(0.8, 0.8, 0.2)); + w_points.push_back(Bare_point_3(0.2, 0.8, 0.6)); // weights size is different from w_points size to make weighted Alpha_complex_3d throw in debug mode std::vector<double> weights = {0.01, 0.005, 0.006, 0.01, 0.009, 0.001}; @@ -91,6 +91,24 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted, Weighted_alpha_complex_3d, Gudhi::Simplex_tree<> stree_bis; alpha_complex_w_p.create_complex(stree_bis); + for (std::size_t index = 0; index < weighted_points.size(); index++) { + bool found = false; + Weighted_point_3 awp = alpha_complex_w_p.get_point(index); + for (auto weighted_point : weighted_points) { + if ((weighted_point.weight() == awp.weight()) && + (weighted_point.x() == awp.x()) && + (weighted_point.y() == awp.y()) && + (weighted_point.z() == awp.z())) { + found = true; + break; + } + } + // Check all points from alpha complex are found in the input point cloud + BOOST_CHECK(found); + } + // Exception if we go out of range + BOOST_CHECK_THROW(alpha_complex_w_p.get_point(weighted_points.size()), std::out_of_range); + // --------------------- // Compare both versions // --------------------- diff --git a/src/Alpha_complex/test/Weighted_periodic_alpha_complex_3d_unit_test.cpp b/src/Alpha_complex/test/Weighted_periodic_alpha_complex_3d_unit_test.cpp index 670c7799..b09e92d5 100644 --- a/src/Alpha_complex/test/Weighted_periodic_alpha_complex_3d_unit_test.cpp +++ b/src/Alpha_complex/test/Weighted_periodic_alpha_complex_3d_unit_test.cpp @@ -47,13 +47,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(Alpha_complex_weighted_periodic_throw, Weighted_pe wp_variants_type_list) { std::cout << "Weighted periodic alpha complex 3d exception throw" << std::endl; - using Creator = CGAL::Creator_uniform_3<double, typename Weighted_periodic_alpha_complex_3d::Point_3>; + using Creator = CGAL::Creator_uniform_3<double, typename Weighted_periodic_alpha_complex_3d::Bare_point_3>; CGAL::Random random(7); - CGAL::Random_points_in_cube_3<typename Weighted_periodic_alpha_complex_3d::Point_3, Creator> in_cube(1, random); - std::vector<typename Weighted_periodic_alpha_complex_3d::Point_3> wp_points; + CGAL::Random_points_in_cube_3<typename Weighted_periodic_alpha_complex_3d::Bare_point_3, Creator> in_cube(1, random); + std::vector<typename Weighted_periodic_alpha_complex_3d::Bare_point_3> wp_points; for (int i = 0; i < 50; i++) { - typename Weighted_periodic_alpha_complex_3d::Point_3 p = *in_cube++; + typename Weighted_periodic_alpha_complex_3d::Bare_point_3 p = *in_cube++; wp_points.push_back(p); } std::vector<double> p_weights; @@ -117,13 +117,13 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_weighted_periodic) { // --------------------- std::cout << "Fast weighted periodic alpha complex 3d" << std::endl; - using Creator = CGAL::Creator_uniform_3<double, Fast_weighted_periodic_alpha_complex_3d::Point_3>; + using Creator = CGAL::Creator_uniform_3<double, Fast_weighted_periodic_alpha_complex_3d::Bare_point_3>; CGAL::Random random(7); - CGAL::Random_points_in_cube_3<Fast_weighted_periodic_alpha_complex_3d::Point_3, Creator> in_cube(1, random); - std::vector<Fast_weighted_periodic_alpha_complex_3d::Point_3> p_points; + CGAL::Random_points_in_cube_3<Fast_weighted_periodic_alpha_complex_3d::Bare_point_3, Creator> in_cube(1, random); + std::vector<Fast_weighted_periodic_alpha_complex_3d::Bare_point_3> p_points; for (int i = 0; i < 50; i++) { - Fast_weighted_periodic_alpha_complex_3d::Point_3 p = *in_cube++; + Fast_weighted_periodic_alpha_complex_3d::Bare_point_3 p = *in_cube++; p_points.push_back(p); } std::vector<double> p_weights; @@ -142,10 +142,10 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_weighted_periodic) { // ---------------------- std::cout << "Exact weighted periodic alpha complex 3d" << std::endl; - std::vector<Exact_weighted_periodic_alpha_complex_3d::Point_3> e_p_points; + std::vector<Exact_weighted_periodic_alpha_complex_3d::Bare_point_3> e_p_points; for (auto p : p_points) { - e_p_points.push_back(Exact_weighted_periodic_alpha_complex_3d::Point_3(p[0], p[1], p[2])); + e_p_points.push_back(Exact_weighted_periodic_alpha_complex_3d::Bare_point_3(p[0], p[1], p[2])); } Exact_weighted_periodic_alpha_complex_3d exact_alpha_complex(e_p_points, p_weights, -1., -1., -1., 1., 1., 1.); @@ -191,10 +191,10 @@ BOOST_AUTO_TEST_CASE(Alpha_complex_weighted_periodic) { // ---------------------- std::cout << "Safe weighted periodic alpha complex 3d" << std::endl; - std::vector<Safe_weighted_periodic_alpha_complex_3d::Point_3> s_p_points; + std::vector<Safe_weighted_periodic_alpha_complex_3d::Bare_point_3> s_p_points; for (auto p : p_points) { - s_p_points.push_back(Safe_weighted_periodic_alpha_complex_3d::Point_3(p[0], p[1], p[2])); + s_p_points.push_back(Safe_weighted_periodic_alpha_complex_3d::Bare_point_3(p[0], p[1], p[2])); } Safe_weighted_periodic_alpha_complex_3d safe_alpha_complex(s_p_points, p_weights, -1., -1., -1., 1., 1., 1.); diff --git a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp index 2272576e..929fc2e8 100644 --- a/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp +++ b/src/Alpha_complex/utilities/alpha_complex_3d_persistence.cpp @@ -62,9 +62,9 @@ bool read_cuboid_file(const std::string &cuboid_file, double &x_min, double &y_m } template <typename AlphaComplex3d> -std::vector<typename AlphaComplex3d::Point_3> read_off(const std::string &off_file_points) { +std::vector<typename AlphaComplex3d::Bare_point_3> read_off(const std::string &off_file_points) { // Read the OFF file (input file name given as parameter) and triangulate points - Gudhi::Points_3D_off_reader<typename AlphaComplex3d::Point_3> off_reader(off_file_points); + Gudhi::Points_3D_off_reader<typename AlphaComplex3d::Bare_point_3> off_reader(off_file_points); // Check the read operation was correct if (!off_reader.is_valid()) { std::cerr << "Unable to read OFF file " << off_file_points << std::endl; |