added functors for accessing Sphere_d

This commit is contained in:
Sven Oesau 2024-02-21 12:32:06 +01:00
parent 5ad3d90819
commit 2bbf5b8cbe
3 changed files with 63 additions and 6 deletions

View File

@ -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`.
*/

View File

@ -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 <typename Tree, typename OutputIterator>
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<typename Tree::FT>::max)());
typename Tree::Sphere query_sphere = orthtree.traits().get_construct_sphere_3_object()(query, (std::numeric_limits<typename Tree::FT>::max)());
return nearest_k_neighbors_in_radius(orthtree, query_sphere, k, output);
}

View File

@ -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);