diff options
author | Hind-M <hind.montassif@gmail.com> | 2022-02-11 15:00:27 +0100 |
---|---|---|
committer | Hind-M <hind.montassif@gmail.com> | 2022-02-11 15:00:27 +0100 |
commit | 2d1fb6b63f0ca0c7e027cc298fc16198a6283df1 (patch) | |
tree | 5e25c1700a914eb2b180f49777a03503e34644aa | |
parent | 307f5f50a806168deb236e263c58dbed3f776ad0 (diff) |
Do some code clean up/renaming
9 files changed, 106 insertions, 161 deletions
diff --git a/src/Cech_complex/benchmark/cech_complex_benchmark.cpp b/src/Cech_complex/benchmark/cech_complex_benchmark.cpp index 94c5fa4f..b283e1a8 100644 --- a/src/Cech_complex/benchmark/cech_complex_benchmark.cpp +++ b/src/Cech_complex/benchmark/cech_complex_benchmark.cpp @@ -34,9 +34,8 @@ using Proximity_graph = Gudhi::Proximity_graph<Simplex_tree>; using Rips_complex = Gudhi::rips_complex::Rips_complex<Filtration_value>; using Kernel = CGAL::Epick_d<CGAL::Dimension_tag<3>>; using Point_cgal = typename Kernel::Point_d; -using Point_cloud_cgal = std::vector<Point_cgal>; using Points_off_reader_cgal = Gudhi::Points_off_reader<Point_cgal>; -using Cech_complex = Gudhi::cech_complex::Cech_complex<Simplex_tree, Point_cloud_cgal, Kernel, Simplex_tree>; +using Cech_complex = Gudhi::cech_complex::Cech_complex<Kernel, Simplex_tree>; class Minimal_enclosing_ball_radius { public: @@ -83,11 +82,11 @@ int main(int argc, char* argv[]) { off_reader.get_point_cloud(), threshold, Minimal_enclosing_ball_radius()); std::clog << miniball_clock << std::endl; - Gudhi::Clock cgal_miniball_clock("Gudhi::Minimal_enclosing_ball_radius_cgal()"); + Gudhi::Clock cgal_circumsphere_clock("Gudhi::cech_complex::Sphere_circumradius_cgal()"); // Compute the proximity graph of the points - Proximity_graph cgal_miniball_prox_graph = Gudhi::compute_proximity_graph<Simplex_tree>( - off_reader_cgal.get_point_cloud(), threshold, Gudhi::Minimal_enclosing_ball_radius<Kernel>()); - std::clog << cgal_miniball_clock << std::endl; + Proximity_graph cgal_circumsphere_prox_graph = Gudhi::compute_proximity_graph<Simplex_tree>( + off_reader_cgal.get_point_cloud(), threshold, Gudhi::cech_complex::Sphere_circumradius<Kernel>()); + std::clog << cgal_circumsphere_clock << std::endl; boost::filesystem::path full_path(boost::filesystem::current_path()); std::clog << "Current path is : " << full_path << std::endl; @@ -109,7 +108,7 @@ int main(int argc, char* argv[]) { std::clog << radius << ";"; Gudhi::Clock rips_clock("Rips computation"); Rips_complex rips_complex_from_points(off_reader_cgal.get_point_cloud(), radius, - Gudhi::Minimal_enclosing_ball_radius<Kernel>()); + Gudhi::cech_complex::Sphere_circumradius<Kernel>()); Simplex_tree rips_stree; rips_complex_from_points.create_complex(rips_stree, p0.size() - 1); // ------------------------------------------ diff --git a/src/Cech_complex/example/cech_complex_example_from_points.cpp b/src/Cech_complex/example/cech_complex_example_from_points.cpp index 78861951..38021e4a 100644 --- a/src/Cech_complex/example/cech_complex_example_from_points.cpp +++ b/src/Cech_complex/example/cech_complex_example_from_points.cpp @@ -16,7 +16,7 @@ int main() { using FT = typename Kernel::FT; using Point = typename Kernel::Point_d; using Point_cloud = std::vector<Point>; - using Cech_complex = Gudhi::cech_complex::Cech_complex<Simplex_tree, Point_cloud, Kernel, Simplex_tree>; + using Cech_complex = Gudhi::cech_complex::Cech_complex<Kernel, Simplex_tree>; Point_cloud points; diff --git a/src/Cech_complex/example/cech_complex_step_by_step.cpp b/src/Cech_complex/example/cech_complex_step_by_step.cpp index c8dd1585..4401f6af 100644 --- a/src/Cech_complex/example/cech_complex_step_by_step.cpp +++ b/src/Cech_complex/example/cech_complex_step_by_step.cpp @@ -9,7 +9,7 @@ */ #include <gudhi/graph_simplicial_complex.h> -#include <gudhi/Cech_complex/Cech_kernel.h> +#include <gudhi/sphere_circumradius.h> #include <gudhi/Simplex_tree.h> #include <gudhi/Points_off_io.h> @@ -52,7 +52,7 @@ class Cech_blocker { std::clog << "#(" << vertex << ")#"; #endif // DEBUG_TRACES } - Filtration_value radius = Gudhi::Minimal_enclosing_ball_radius<Kernel>()(points); + Filtration_value radius = Gudhi::cech_complex::Sphere_circumradius<Kernel>()(points); #ifdef DEBUG_TRACES std::clog << "radius = " << radius << " - " << (radius > max_radius_) << std::endl; #endif // DEBUG_TRACES @@ -83,7 +83,7 @@ int main(int argc, char* argv[]) { // Compute the proximity graph of the points Proximity_graph prox_graph = Gudhi::compute_proximity_graph<Simplex_tree>(off_reader.get_point_cloud(), max_radius, - Gudhi::Minimal_enclosing_ball_radius<Kernel>()); + Gudhi::cech_complex::Sphere_circumradius<Kernel>()); // Construct the Cech complex in a Simplex Tree Simplex_tree st; diff --git a/src/Cech_complex/include/gudhi/Cech_complex.h b/src/Cech_complex/include/gudhi/Cech_complex.h index 0031d861..375be1d2 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex.h +++ b/src/Cech_complex/include/gudhi/Cech_complex.h @@ -11,7 +11,7 @@ #ifndef CECH_COMPLEX_H_ #define CECH_COMPLEX_H_ -#include <gudhi/Cech_complex/Cech_kernel.h> // for Gudhi::Minimal_enclosing_ball_radius +#include <gudhi/sphere_circumradius.h> // for Gudhi::cech_complex::Sphere_circumradius #include <gudhi/graph_simplicial_complex.h> // for Gudhi::Proximity_graph #include <gudhi/Debug_utils.h> // for GUDHI_CHECK #include <gudhi/Cech_complex_blocker.h> // for Gudhi::cech_complex::Cech_blocker @@ -31,23 +31,21 @@ namespace cech_complex { * * \details * The data structure is a proximity graph, containing edges when the edge length is less or equal - * to a given max_radius. Edge length is computed from `Gudhi::Minimal_enclosing_ball_radius` distance function. + * to a given max_radius. Edge length is computed from `Gudhi::cech_complex::Sphere_circumradius` distance function. * - * \tparam SimplicialComplexForProximityGraph furnishes `Vertex_handle` and `Filtration_value` type definition required - * by `Gudhi::Proximity_graph`. + * \tparam Kernel CGAL kernel. + * + * \tparam SimplicialComplexForCechComplex furnishes `Vertex_handle` and `Filtration_value` type definition required + * by `Gudhi::Proximity_graph` and Cech blocker. * - * \tparam ForwardPointRange must be a range for which `std::begin()` and `std::end()` methods return input - * iterators on a point. `std::begin()` and `std::end()` methods are also required for a point. */ -template <typename SimplicialComplexForProximityGraph, typename ForwardPointRange, typename Kernel, typename SimplicialComplexForCechComplex> +template <typename Kernel, typename SimplicialComplexForCechComplex> class Cech_complex { private: // Required by compute_proximity_graph - using Vertex_handle = typename SimplicialComplexForProximityGraph::Vertex_handle; - using Filtration_value = typename SimplicialComplexForProximityGraph::Filtration_value; - using Proximity_graph = Gudhi::Proximity_graph<SimplicialComplexForProximityGraph>; - - public: + using Vertex_handle = typename SimplicialComplexForCechComplex::Vertex_handle; + using Filtration_value = typename SimplicialComplexForCechComplex::Filtration_value; + using Proximity_graph = Gudhi::Proximity_graph<SimplicialComplexForCechComplex>; using cech_blocker = Cech_blocker<SimplicialComplexForCechComplex, Cech_complex, Kernel>; @@ -57,27 +55,21 @@ class Cech_complex { // Numeric type of coordinates in the kernel using FT = typename cech_blocker::FT; // Sphere is a pair of point and squared radius. - using Sphere = typename std::pair<Point_d, FT>; + using Sphere = typename cech_blocker::Sphere; - public: + public: /** \brief Cech_complex constructor from a list of points. * - * @param[in] points Range of points. + * @param[in] points Vector of points where each point is defined as `kernel::Point_d`. * @param[in] max_radius Maximal radius value. * - * \tparam ForwardPointRange must be a range of Point. Point must be a range of <b>copyable</b> Cartesian coordinates. - * */ - Cech_complex(const ForwardPointRange& points, Filtration_value max_radius) : max_radius_(max_radius) { - // Point cloud deep copy - -// point_cloud_.reserve(boost::size(points)); -// for (auto&& point : points) point_cloud_.emplace_back(point.cartesian_begin(), point.cartesian_end()); + Cech_complex(const Point_cloud & points, Filtration_value max_radius) : max_radius_(max_radius) { point_cloud_.assign(points.begin(), points.end()); - cech_skeleton_graph_ = Gudhi::compute_proximity_graph<SimplicialComplexForProximityGraph>( - point_cloud_, max_radius_, Gudhi::Minimal_enclosing_ball_radius<Kernel>()); + cech_skeleton_graph_ = Gudhi::compute_proximity_graph<SimplicialComplexForCechComplex>( + point_cloud_, max_radius_, Sphere_circumradius<Kernel>()); } /** \brief Initializes the simplicial complex from the proximity graph and expands it until a given maximal diff --git a/src/Cech_complex/include/gudhi/Cech_complex/Cech_kernel.h b/src/Cech_complex/include/gudhi/Cech_complex/Cech_kernel.h deleted file mode 100644 index 89012206..00000000 --- a/src/Cech_complex/include/gudhi/Cech_complex/Cech_kernel.h +++ /dev/null @@ -1,107 +0,0 @@ -/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. - * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. - * Author(s): Hind Montassif - * - * Copyright (C) 2021 Inria - * - * Modification(s): - * - YYYY/MM Author: Description of the modification - */ - -#ifndef CECH_KERNEL_H_ -#define CECH_KERNEL_H_ - -#include <CGAL/Epeck_d.h> // for #include <CGAL/NewKernel_d/KernelD_converter.h> - -#include <cmath> // for std::sqrt -#include <vector> - -namespace Gudhi { - -// namespace cech_complex { - -/** @brief Compute the radius of the minimal enclosing ball between Points given by a range of coordinates. - * The points are assumed to have the same dimension. */ -template<typename Kernel> -class Minimal_enclosing_ball_radius { - private: - Kernel kernel_; - public: - using Point = typename Kernel::Point_d; - using Point_cloud = typename std::vector<Point>; - - /** \brief Enclosing ball radius from two points using CGAL. - * - * @param[in] point_1 - * @param[in] point_2 - * @return Enclosing ball radius for the two points. - * \tparam Point must be a Kernel::Point_d from CGAL. - * - */ - double operator()(const Point& point_1, const Point& point_2) const { - return std::sqrt(CGAL::to_double(kernel_.squared_distance_d_object()(point_1, point_2))) / 2.; - } - - - /** \brief Enclosing ball radius from a point cloud using CGAL. - * - * @param[in] point_cloud The points. - * @return Enclosing ball radius for the points. - * \tparam Point_cloud must be a range of Kernel::Point_d points from CGAL. - * - */ - double operator()(const Point_cloud& point_cloud) const { - return std::sqrt(CGAL::to_double(kernel_.compute_squared_radius_d_object()(point_cloud.begin(), point_cloud.end()))); - } - -}; - -/** - * \class Cech_kernel - * \brief Cech complex kernel container. - * - * \details - * The Cech complex kernel container stores CGAL Kernel and dispatch basic computations. - */ - -// template < typename Kernel > -// class Cech_kernel<Kernel> { -// private: -// // Kernel for functions access. -// Kernel kernel_; -// public: -// using Point_d = typename Kernel::Point_d; -// // Numeric type of coordinates in the kernel -// using FT = typename Kernel::FT; -// // Sphere is a pair of point and squared radius. -// using Sphere = typename std::pair<Point_d, FT>; -// -// int get_dimension(const Point_d& p0) const { -// return kernel_.point_dimension_d_object()(p0); -// } -// -// template<class PointIterator> -// Sphere get_sphere(PointIterator begin, PointIterator end) const { -// Point_d c = kernel_.construct_circumcenter_d_object()(begin, end); -// FT r = kernel_.squared_distance_d_object()(c, *begin); -// return std::make_pair(std::move(c), std::move(r)); -// } -// -// template<class PointIterator> -// FT get_squared_radius(PointIterator begin, PointIterator end) const { -// return kernel_.compute_squared_radius_d_object()(begin, end); -// } -// -// FT get_squared_radius(const Sphere& sph) const { -// return sph.second; -// } -// }; - - -//} // namespace cech_complex - -// namespace cechcomplex = cech_complex; - -} // namespace Gudhi - -#endif // CECH_KERNEL_H_ diff --git a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h index f7f86534..1a696422 100644 --- a/src/Cech_complex/include/gudhi/Cech_complex_blocker.h +++ b/src/Cech_complex/include/gudhi/Cech_complex_blocker.h @@ -31,17 +31,15 @@ namespace cech_complex { * \details * Čech blocker is an oracle constructed from a Cech_complex and a simplicial complex. * - * \tparam SimplicialComplexForProximityGraph furnishes `Simplex_handle` and `Filtration_value` type definition, + * \tparam SimplicialComplexForCech furnishes `Simplex_handle` and `Filtration_value` type definition, * `simplex_vertex_range(Simplex_handle sh)`and `assign_filtration(Simplex_handle sh, Filtration_value filt)` methods. * - * \tparam Chech_complex is required by the blocker. + * \tparam Cech_complex is required by the blocker. + * + * \tparam Kernel CGAL kernel. */ template <typename SimplicialComplexForCech, typename Cech_complex, typename Kernel> class Cech_blocker { - private: - - using Simplex_handle = typename SimplicialComplexForCech::Simplex_handle; - using Filtration_value = typename SimplicialComplexForCech::Filtration_value; public: @@ -51,10 +49,10 @@ class Cech_blocker { // Sphere is a pair of point and squared radius. using Sphere = typename std::pair<Point_d, FT>; - template<class PointIterator> - FT get_squared_radius(PointIterator begin, PointIterator end) const { - return kernel_.compute_squared_radius_d_object()(begin, end); - } + private: + + using Simplex_handle = typename SimplicialComplexForCech::Simplex_handle; + using Filtration_value = typename SimplicialComplexForCech::Filtration_value; template<class PointIterator> Sphere get_sphere(PointIterator begin, PointIterator end) const { @@ -63,6 +61,7 @@ class Cech_blocker { return std::make_pair(std::move(c), std::move(r)); } + public: /** \internal \brief Čech complex blocker operator() - the oracle - assigns the filtration value from the simplex * radius and returns if the simplex expansion must be blocked. @@ -108,10 +107,11 @@ class Cech_blocker { if (kernel_.squared_distance_d_object()(sph.first, cc_ptr_->get_point(extra)) <= sph.second) { radius = std::sqrt(cast_to_double(sph.second)); #ifdef DEBUG_TRACES - std::clog << "circumcenter: " << sph.first << ", radius: " << radius << std::endl; + std::clog << "center: " << sph.first << ", radius: " << radius << std::endl; #endif // DEBUG_TRACES if (cast_to_double(sph.second) < cast_to_double(min_enclos_ball.second)) min_enclos_ball = sph; + break; } } // Get the minimal radius of all faces enclosing balls if exists diff --git a/src/Cech_complex/include/gudhi/sphere_circumradius.h b/src/Cech_complex/include/gudhi/sphere_circumradius.h new file mode 100644 index 00000000..a6dec3dc --- /dev/null +++ b/src/Cech_complex/include/gudhi/sphere_circumradius.h @@ -0,0 +1,62 @@ +/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + * Author(s): Hind Montassif + * + * Copyright (C) 2021 Inria + * + * Modification(s): + * - YYYY/MM Author: Description of the modification + */ + +#ifndef SPHERE_CIRCUMRADIUS_H_ +#define SPHERE_CIRCUMRADIUS_H_ + +#include <CGAL/Epeck_d.h> // for #include <CGAL/NewKernel_d/KernelD_converter.h> + +#include <cmath> // for std::sqrt +#include <vector> + +namespace Gudhi { + +namespace cech_complex { + +/** @brief Compute the circumradius of the sphere passing through points given by a range of coordinates. + * The points are assumed to have the same dimension. */ +template<typename Kernel> +class Sphere_circumradius { + private: + Kernel kernel_; + public: + using Point = typename Kernel::Point_d; + using Point_cloud = typename std::vector<Point>; + + /** \brief Circumradius of sphere passing through two points using CGAL. + * + * @param[in] point_1 + * @param[in] point_2 + * @return Sphere circumradius passing through two points. + * \tparam Point must be a Kernel::Point_d from CGAL. + * + */ + double operator()(const Point& point_1, const Point& point_2) const { + return std::sqrt(CGAL::to_double(kernel_.squared_distance_d_object()(point_1, point_2))) / 2.; + } + + /** \brief Circumradius of sphere passing through point cloud using CGAL. + * + * @param[in] point_cloud The points. + * @return Sphere circumradius passing through the points. + * \tparam Point_cloud must be a range of Kernel::Point_d points from CGAL. + * + */ + double operator()(const Point_cloud& point_cloud) const { + return std::sqrt(CGAL::to_double(kernel_.compute_squared_radius_d_object()(point_cloud.begin(), point_cloud.end()))); + } + +}; + +} // namespace cech_complex + +} // namespace Gudhi + +#endif // SPHERE_CIRCUMRADIUS_H_ diff --git a/src/Cech_complex/test/test_cech_complex.cpp b/src/Cech_complex/test/test_cech_complex.cpp index ca7a9778..4cf8b68f 100644 --- a/src/Cech_complex/test/test_cech_complex.cpp +++ b/src/Cech_complex/test/test_cech_complex.cpp @@ -22,7 +22,7 @@ // to construct Cech_complex from a OFF file of points #include <gudhi/Points_off_io.h> #include <gudhi/Simplex_tree.h> -#include <gudhi/Cech_complex/Cech_kernel.h> +#include <gudhi/sphere_circumradius.h> #include <gudhi/Unitary_tests_utils.h> #include <CGAL/Epeck_d.h> // For EXACT or SAFE version @@ -36,7 +36,7 @@ using Point = typename Kernel::Point_d; using Point_cloud = std::vector<Point>; using Points_off_reader = Gudhi::Points_off_reader<Point>; -using Cech_complex = Gudhi::cech_complex::Cech_complex<Simplex_tree, Point_cloud, Kernel, Simplex_tree>; +using Cech_complex = Gudhi::cech_complex::Cech_complex<Kernel, Simplex_tree>; BOOST_AUTO_TEST_CASE(Cech_complex_for_documentation) { // ---------------------------------------------------------------------------- @@ -108,11 +108,11 @@ BOOST_AUTO_TEST_CASE(Cech_complex_for_documentation) { std::clog << vertex << ","; vp.push_back(points.at(vertex)); } - std::clog << ") - distance =" << Gudhi::Minimal_enclosing_ball_radius<Kernel>()(vp.at(0), vp.at(1)) + std::clog << ") - distance =" << Gudhi::cech_complex::Sphere_circumradius<Kernel>()(vp.at(0), vp.at(1)) << " - filtration =" << st.filtration(f_simplex) << std::endl; BOOST_CHECK(vp.size() == 2); GUDHI_TEST_FLOAT_EQUALITY_CHECK(st.filtration(f_simplex), - Gudhi::Minimal_enclosing_ball_radius<Kernel>()(vp.at(0), vp.at(1))); + Gudhi::cech_complex::Sphere_circumradius<Kernel>()(vp.at(0), vp.at(1))); } } @@ -153,7 +153,7 @@ BOOST_AUTO_TEST_CASE(Cech_complex_for_documentation) { Simplex_tree::Filtration_value f1410 = st2.filtration(st2.find({1, 4, 10})); std::clog << "f1410= " << f1410 << std::endl; - // In this case, the computed sphere using CGAL kernel does not match the minimal enclosing ball; the filtration value check is therefore done against a hardcoded value + // In this case, the computed circumsphere using CGAL kernel does not match the minimal enclosing ball; the filtration value check is therefore done against a hardcoded value GUDHI_TEST_FLOAT_EQUALITY_CHECK(f1410, 1.); Point_cloud points469; diff --git a/src/Cech_complex/utilities/cech_persistence.cpp b/src/Cech_complex/utilities/cech_persistence.cpp index ccf63e3e..82992f2d 100644 --- a/src/Cech_complex/utilities/cech_persistence.cpp +++ b/src/Cech_complex/utilities/cech_persistence.cpp @@ -9,7 +9,7 @@ */ #include <gudhi/Cech_complex.h> -#include <gudhi/Cech_complex/Cech_kernel.h> +#include <gudhi/sphere_circumradius.h> #include <gudhi/Simplex_tree.h> #include <gudhi/Persistent_cohomology.h> #include <gudhi/Points_off_io.h> @@ -28,9 +28,8 @@ using Filtration_value = Simplex_tree::Filtration_value; using Kernel = CGAL::Epeck_d<CGAL::Dynamic_dimension_tag>; using Point = typename Kernel::Point_d; -using Point_cloud = std::vector<Point>; using Points_off_reader = Gudhi::Points_off_reader<Point>; -using Cech_complex = Gudhi::cech_complex::Cech_complex<Simplex_tree, Point_cloud, Kernel, Simplex_tree>; +using Cech_complex = Gudhi::cech_complex::Cech_complex<Kernel, Simplex_tree>; using Field_Zp = Gudhi::persistent_cohomology::Field_Zp; using Persistent_cohomology = Gudhi::persistent_cohomology::Persistent_cohomology<Simplex_tree, Field_Zp>; |