Stride Reference Manual  - generated for commit 9643b11
geopop::KdTree< P > Class Template Reference

A k-d tree: a k-dimensional generalization of binary search trees This data structure allows for efficient lookup of points and range queries with an Axis-Aligned Bounding Box (when balanced). More...

#include <KdNode.h>

Inheritance diagram for geopop::KdTree< P >:
Inheritance graph
Collaboration diagram for geopop::KdTree< P >:
Collaboration graph

Public Member Functions

 KdTree ()
 Constructor: builds an empty tree. More...
 
void Apply (std::function< bool(const P &)> f) const
 Calls a function with each of the points in the tree. More...
 
void Apply (std::function< bool(const P &)> f, const AABBox< P > &box) const
 Calls a function with every point contained in box More...
 
bool Contains (const P &point) const
 Test wether a point is contained in the tree. More...
 
bool Empty () const
 Is the tree empty. More...
 
std::size_t GetHeight () const
 Get the height of the tree (mostly for testing purposes). More...
 
void Insert (P point)
 Insert a new point into the tree, using this often may result in an unbalanced tree. More...
 
std::vector< P > Query (const AABBox< P > &box) const
 Get all points in the tree that lie within box. More...
 
std::size_t Size () const
 Get the size of the tree. More...
 

Static Public Member Functions

static KdTree Build (const std::vector< P > &points)
 Build a balanced tree from the given set of points efficiently. More...
 

Static Private Member Functions

template<std::size_t D>
static std::unique_ptr< kd::Node< P, D > > Construct (const std::vector< P > &points)
 

Private Attributes

std::size_t m_size
 The number of points in the tree. More...
 
std::unique_ptr< kd::Node< P, 0 > > m_root
 The root node of the tree. More...
 

Detailed Description

template<typename P>
class geopop::KdTree< P >

A k-d tree: a k-dimensional generalization of binary search trees This data structure allows for efficient lookup of points and range queries with an Axis-Aligned Bounding Box (when balanced).

The template parameter P should have the following attributes and operations:

  • A static constexpr std::size_t dim: the number of dimensions of the point type.
  • A template <std::size_d D> get() const returns the coordinate of the Dth dimension of the point.
  • A nested template <std::size_t D> struct dimension_type has a member type type with return type for Get<D>.
  • A default constructor and a copy constructor
  • The individual dimensions should each have a total order and equality
  • A method bool InBox(const AABB<P>& box) const indicates if a point falls withing the bounding box (only for range queries)

Definition at line 25 of file KdNode.h.

Constructor & Destructor Documentation

template<typename P >
geopop::KdTree< P >::KdTree ( )

Constructor: builds an empty tree.

Definition at line 35 of file KdTree_def.h.

Member Function Documentation

template<typename P>
KdTree< P > geopop::KdTree< P >::Build ( const std::vector< P > &  points)
static

Build a balanced tree from the given set of points efficiently.

Parameters
pointsThe points to insert in the resulting tree.
Returns
A balanced KdTree containing the given points.

Definition at line 40 of file KdTree_def.h.

References geopop::KdTree< P >::m_root, and geopop::KdTree< P >::m_size.

template<typename P>
void geopop::KdTree< P >::Apply ( std::function< bool(const P &)>  f) const

Calls a function with each of the points in the tree.

Parameters
fA function that will be called with each point, if f returns false, traversal stops.

Definition at line 49 of file KdTree_def.h.

References geopop::kd::BaseNode< P >::BorrowLeft(), geopop::kd::BaseNode< P >::BorrowRight(), geopop::kd::BaseNode< P >::GetPoint(), and geopop::KdTree< P >::m_root.

Referenced by geopop::KdTree< P >::Contains(), and geopop::KdTree< P >::Query().

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename P>
void geopop::KdTree< P >::Apply ( std::function< bool(const P &)>  f,
const AABBox< P > &  box 
) const

Calls a function with every point contained in box

Parameters
fA function that will be called with each point within box, if f returns false, traversal stops.
boxThe containing Axis-Aligned Bounding Box to search for points

Definition at line 76 of file KdTree_def.h.

References geopop::kd::BaseNode< P >::BorrowSplitChild(), geopop::kd::BaseNode< P >::GetPoint(), geopop::AABBox< P >::lower, geopop::KdTree< P >::m_root, and geopop::AABBox< P >::upper.

Here is the call graph for this function:

template<typename P>
bool geopop::KdTree< P >::Contains ( const P &  point) const

Test wether a point is contained in the tree.

Parameters
pointThe point to test. P should support bool operator==(const P&) const.
Returns
Whether the point is found in the tree.

Definition at line 100 of file KdTree_def.h.

References geopop::KdTree< P >::Apply().

Here is the call graph for this function:

template<typename P >
bool geopop::KdTree< P >::Empty ( ) const

Is the tree empty.

Definition at line 114 of file KdTree_def.h.

References geopop::KdTree< P >::Size().

Here is the call graph for this function:

template<typename P >
std::size_t geopop::KdTree< P >::GetHeight ( ) const

Get the height of the tree (mostly for testing purposes).

Definition at line 120 of file KdTree_def.h.

References geopop::kd::BaseNode< P >::BorrowLeft(), geopop::kd::BaseNode< P >::BorrowRight(), and geopop::KdTree< P >::m_root.

Here is the call graph for this function:

template<typename P>
void geopop::KdTree< P >::Insert ( point)

Insert a new point into the tree, using this often may result in an unbalanced tree.

Parameters
pointThe point to insert into the tree.

Definition at line 139 of file KdTree_def.h.

References geopop::kd::BaseNode< P >::AddChild(), geopop::kd::BaseNode< P >::BorrowSplitChild(), geopop::KdTree< P >::m_root, and geopop::KdTree< P >::m_size.

Here is the call graph for this function:

template<typename P>
std::vector< P > geopop::KdTree< P >::Query ( const AABBox< P > &  box) const

Get all points in the tree that lie within box.

Parameters
boxThe limiting AABB to search for points.
Returns
A collection of points found within box.

Definition at line 158 of file KdTree_def.h.

References geopop::KdTree< P >::Apply().

Here is the call graph for this function:

template<typename P >
std::size_t geopop::KdTree< P >::Size ( ) const

Get the size of the tree.

Definition at line 171 of file KdTree_def.h.

References geopop::KdTree< P >::m_size.

Referenced by geopop::KdTree< P >::Empty().

Here is the caller graph for this function:

template<typename P>
template<std::size_t D>
std::unique_ptr< kd::Node< P, D > > geopop::KdTree< P >::Construct ( const std::vector< P > &  points)
staticprivate

Definition at line 178 of file KdTree_def.h.

Member Data Documentation

template<typename P>
std::size_t geopop::KdTree< P >::m_size
private

The number of points in the tree.

Definition at line 108 of file KdTree.h.

Referenced by geopop::KdTree< P >::Build(), geopop::KdTree< P >::Insert(), and geopop::KdTree< P >::Size().

template<typename P>
std::unique_ptr<kd::Node<P, 0> > geopop::KdTree< P >::m_root
private

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