COGS
Computer Graphics Structures library
cogs::Octree Class Reference

Space-partitioning data structure for point clouds. More...

Public Member Functions

 ~Octree ()
 Octree destructor.
 
 Octree ()=default
 Default constructor.
 
 Octree (const cogs::PointCloud &cloud)
 Constructs Octree over the given cloud. More...
 
 Octree (const std::vector< glm::vec3 > &positions)
 Constructs Octree over the given vector of points. More...
 
void Include (const cogs::PointCloud &cloud)
 Adds points of the input cloud into the Octree. More...
 
void Include (const std::vector< const cogs::PointCloud *> &clouds)
 Adds points of input clouds into the Octree. More...
 
std::string ToString () const
 Get the string representation of this octree. More...
 
size_t GetNodeCount () const
 Get the number of nodes in the octree. More...
 
std::vector< geom::Aabb3 > GetNodeCubes () const
 Returns the vector of bounding boxes of all internal nodes. More...
 
bool HasPointIn (const glm::vec3 &location, float_t radius) const
 Whether any of the points exist in the range from the given location. More...
 
bool HasPointIn (const geom::Aabb3 &search_range) const
 Whether any of the points exist inside the input AABB. More...
 
std::vector< uint32_t > Find (const glm::vec3 &location, float_t radius) const
 Get indices of points in the radius from the given location. More...
 
std::vector< uint32_t > Find (const geom::Aabb3 &search_range) const
 Get indices of points that are inside the input AABB. More...
 
int32_t GetIntersectedPoint (const geom::Ray3 &ray, std::optional< float > tolerance=std::nullopt) const
 Check whether the input ray hits any of the points and if yes, returns the one closest to the origin. More...
 

Static Public Attributes

static const uint8_t POINTS_THRESHOLD = 64
 When an octree node contains this number of points or less, it does not subdivide further.
 

Detailed Description

Space-partitioning data structure for point clouds.

Constructor & Destructor Documentation

◆ Octree() [1/2]

cogs::Octree::Octree ( const cogs::PointCloud &  cloud)

Constructs Octree over the given cloud.

Parameters
cloudOctree will be constructed over points of this cloud.

◆ Octree() [2/2]

cogs::Octree::Octree ( const std::vector< glm::vec3 > &  positions)

Constructs Octree over the given vector of points.

Parameters
positionsOctree will be constructed over these points.

Member Function Documentation

◆ Find() [1/2]

std::vector<uint32_t> cogs::Octree::Find ( const glm::vec3 &  location,
float_t  radius 
) const

Get indices of points in the radius from the given location.

Parameters
locationLocation in the world around which will be searched.
radiusRadius range of the search area.
Returns
Vector of point indices in the area.

◆ Find() [2/2]

std::vector<uint32_t> cogs::Octree::Find ( const geom::Aabb3 &  search_range) const

Get indices of points that are inside the input AABB.

Parameters
search_rangeArea of this axis aligned box will be searched for points.
Returns
Vector of point indices inside the input AABB.

◆ GetIntersectedPoint()

int32_t cogs::Octree::GetIntersectedPoint ( const geom::Ray3 &  ray,
std::optional< float >  tolerance = std::nullopt 
) const

Check whether the input ray hits any of the points and if yes, returns the one closest to the origin.

Parameters
rayRay casted in the world.
toleranceMaximal distance between point and ray in order to intersect it. When set tu nullopt, automatic value is used.
Returns
Index of the intersected point closest to the origin of the ray, -1 otherwise.

◆ GetNodeCount()

size_t cogs::Octree::GetNodeCount ( ) const

Get the number of nodes in the octree.

Returns
Node count.

◆ GetNodeCubes()

std::vector<geom::Aabb3> cogs::Octree::GetNodeCubes ( ) const

Returns the vector of bounding boxes of all internal nodes.

Returns
Vector of bounding boxes.

◆ HasPointIn() [1/2]

bool cogs::Octree::HasPointIn ( const glm::vec3 &  location,
float_t  radius 
) const

Whether any of the points exist in the range from the given location.

Parameters
locationLocation in the world around which will be searched.
radiusRadius range of the search area.
Returns
True if any point is in range, false otherwise.

◆ HasPointIn() [2/2]

bool cogs::Octree::HasPointIn ( const geom::Aabb3 &  search_range) const

Whether any of the points exist inside the input AABB.

Parameters
search_rangeArea of this axis aligned box will be searched for points.
Returns
True if any point is included in the input AABB, false otherwise.

◆ Include() [1/2]

void cogs::Octree::Include ( const cogs::PointCloud &  cloud)

Adds points of the input cloud into the Octree.

Parameters
positionsPoints of this cloud will be included in the octree.

◆ Include() [2/2]

void cogs::Octree::Include ( const std::vector< const cogs::PointCloud *> &  clouds)

Adds points of input clouds into the Octree.

Parameters
positionsPoints from all the clouds in this vector will be included in the octree.

◆ ToString()

std::string cogs::Octree::ToString ( ) const

Get the string representation of this octree.

Returns
String representation of this octree.