diff --git a/Orthtree/doc/Orthtree/Concepts/CollectionPartitioningOrthtreeTraits.h b/Orthtree/doc/Orthtree/Concepts/CollectionPartitioningOrthtreeTraits.h index 2c2e469f7f2..9dcdb855330 100644 --- a/Orthtree/doc/Orthtree/Concepts/CollectionPartitioningOrthtreeTraits.h +++ b/Orthtree/doc/Orthtree/Concepts/CollectionPartitioningOrthtreeTraits.h @@ -23,7 +23,7 @@ public: /// @{ /*! - * Sphere type used for the shrinking-sphere approach for neighbor queries + * Sphere Type used for the shrinking-sphere approach for neighbor queries; needs to be copy assignable. */ using Sphere_d = unspecified_type; @@ -48,11 +48,50 @@ public: */ using Squared_distance_of_element = unspecified_type; + /*! + * \brief Functor with an operator that constructs a `Sphere_d` from a provided center and squared radius. + * + * Provides the operator: + * `Sphere_d operator()(const Point_d&, const FT&)` + */ + using Construct_sphere_3 = unspecified_type; + + /*! + * \brief Functor with an operator that provides the center of a `Sphere_d`. + * + * Provides the operator: + * `Point_d operator()(const Sphere_d&)` + */ + using Construct_center_3 = unspecified_type; + + /*! + * \brief Functor with an operator that provides the squared radius of a `Sphere_d`. + * + * Provides the operator: + * `FT operator()(const Sphere_d&)` + */ + using Compute_squared_radius_3 = unspecified_type; + /// @} /// \name Operations /// @{ + /*! + * constructs an object of type `ConstructSphere_3`. + */ + Construct_sphere_3 get_construct_sphere_3_object() const; + + /*! + * constructs an object of type `ConstructCenter_3`. + */ + Construct_center_3 get_construct_center_3_object() const; + + /*! + * constructs an object of type `ComputeSquaredRadius_3`. + */ + Compute_squared_radius_3 get_compute_squared_radius_3_object() const; + /*! * constructs an object of type `Squared_distance_of_element`. */ diff --git a/Orthtree/include/CGAL/Orthtree/Nearest_neighbors.h b/Orthtree/include/CGAL/Orthtree/Nearest_neighbors.h index fdcbe33eccb..7a033440fbd 100644 --- a/Orthtree/include/CGAL/Orthtree/Nearest_neighbors.h +++ b/Orthtree/include/CGAL/Orthtree/Nearest_neighbors.h @@ -38,10 +38,10 @@ void nearest_k_neighbors_recursive(const Tree& orthtree, // Pair that element with its distance from the search point Result current_element_with_distance = - {e, orthtree.traits().get_squared_distance_of_element_object()(e, search_bounds.center())}; + {e, orthtree.traits().get_squared_distance_of_element_object()(e, orthtree.traits().get_construct_center_3_object()(search_bounds))}; // Check if the new element is within the bounds - if (current_element_with_distance.distance < search_bounds.squared_radius()) { + if (current_element_with_distance.distance < orthtree.traits().get_compute_squared_radius_3_object()(search_bounds)) { // Check if the results list is full if (results.size() == results.capacity()) { @@ -62,7 +62,7 @@ void nearest_k_neighbors_recursive(const Tree& orthtree, if (results.size() == results.capacity()) { // Set the search radius - search_bounds = typename Tree::Sphere(search_bounds.center(), results.back().distance + epsilon); + search_bounds = orthtree.traits().get_construct_sphere_3_object()(orthtree.traits().get_construct_center_3_object()(search_bounds), results.back().distance + epsilon); } } } @@ -89,7 +89,7 @@ void nearest_k_neighbors_recursive(const Tree& orthtree, // Add a child to the list, with its distance children_with_distances.emplace_back( child_node, - CGAL::squared_distance(search_bounds.center(), orthtree.barycenter(child_node)) + CGAL::squared_distance(orthtree.traits().get_construct_center_3_object()(search_bounds), orthtree.barycenter(child_node)) ); } @@ -182,7 +182,7 @@ template OutputIterator nearest_neighbors(const Tree& orthtree, const typename Tree::Point& query, std::size_t k, OutputIterator output) { - typename Tree::Sphere query_sphere(query, (std::numeric_limits::max)()); + typename Tree::Sphere query_sphere = orthtree.traits().get_construct_sphere_3_object()(query, (std::numeric_limits::max)()); return nearest_k_neighbors_in_radius(orthtree, query_sphere, k, output); } diff --git a/Orthtree/include/CGAL/Orthtree_traits_point.h b/Orthtree/include/CGAL/Orthtree_traits_point.h index e3abafbbd8d..068aa0baeaf 100644 --- a/Orthtree/include/CGAL/Orthtree_traits_point.h +++ b/Orthtree/include/CGAL/Orthtree_traits_point.h @@ -163,6 +163,24 @@ public: }; } + auto get_construct_sphere_3_object() const { + return [](const typename Self::Point_d& center, const typename Self::FT& squared_radius) -> typename Self::Sphere_d { + return typename Self::Sphere_d(center, squared_radius); + }; + } + + auto get_construct_center_3_object() const { + return [](const typename Self::Sphere_d& sphere) -> typename Self::Point_d { + return sphere.center(); + }; + } + + auto get_compute_squared_radius_3_object() const { + return [](const typename Self::Sphere_d& sphere) -> typename Self::FT { + return sphere.squared_radius(); + }; + } + auto get_squared_distance_of_element_object() const { return [&](const Node_data_element& index, const typename Self::Point_d& point) -> typename Self::FT { return CGAL::squared_distance(get(m_point_map, index), point);