pure-cpp 1.0.0
A C++ physics simulation benchmark comparing performance with Python implementations
Model::KDTree Class Reference

A k-d tree for fast nearest neighbour searches, specialized for our Bodies container. More...

#include <kdtree.hpp>

Collaboration diagram for Model::KDTree:
Collaboration graph

Public Types

using TreeType = nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< double, BodiesAdaptor >, BodiesAdaptor, 3, std::size_t >
 The specific KD-Tree type using our adapter. More...
 

Public Member Functions

 KDTree (const Bodies &in_bodies)
 Construct a new KDTree object and build the index. More...
 
template<typename VectorOfPairs >
std::size_t radiusSearch (const double *query_point, const double search_radius, VectorOfPairs &out_results)
 Finds all bodies within a given radius of a query point. More...
 

Private Attributes

BodiesAdaptor adaptor_
 The adapter that lets nanoflann access our data. More...
 
TreeType tree_
 The underlying nanoflann k-d tree index. More...
 

Detailed Description

A k-d tree for fast nearest neighbour searches, specialized for our Bodies container.

Definition at line 75 of file kdtree.hpp.

Member Typedef Documentation

◆ TreeType

using Model::KDTree::TreeType = nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor<double, BodiesAdaptor>, BodiesAdaptor, 3 , std::size_t >

The specific KD-Tree type using our adapter.

Definition at line 78 of file kdtree.hpp.

Constructor & Destructor Documentation

◆ KDTree()

Model::KDTree::KDTree ( const Bodies in_bodies)
inlineexplicit

Construct a new KDTree object and build the index.

Parameters
in_bodiesThe Bodies container to build the tree from.

Definition at line 87 of file kdtree.hpp.

Member Function Documentation

◆ radiusSearch()

template<typename VectorOfPairs >
std::size_t Model::KDTree::radiusSearch ( const double *  query_point,
const double  search_radius,
VectorOfPairs &  out_results 
)
inline

Finds all bodies within a given radius of a query point.

Parameters
query_pointThe centre point of the search.
search_radiusThe radius of the search sphere.
out_resultsA vector to store the results (pairs of index and squared distance).
Returns
The number of neighbours found.

Definition at line 106 of file kdtree.hpp.

Member Data Documentation

◆ adaptor_

BodiesAdaptor Model::KDTree::adaptor_
private

The adapter that lets nanoflann access our data.

Definition at line 126 of file kdtree.hpp.

◆ tree_

TreeType Model::KDTree::tree_
private

The underlying nanoflann k-d tree index.

Definition at line 128 of file kdtree.hpp.


The documentation for this class was generated from the following file: