class cogs::Octree

Overview

Space-partitioning data structure for point clouds. More…

#include <Octree.h>

class Octree {
public:
    // fields

    static const uint8_t POINTS_THRESHOLD = 64;

    // construction

    Octree();
    Octree(const cogs::PointCloud& cloud);
    Octree(const std::vector<glm::vec3>& positions);
    ~Octree();

    // methods

    void Include(const cogs::PointCloud& cloud);
    void Include(const std::vector<const cogs::PointCloud*>& clouds);
    std::string ToString() const;
    size_t GetNodeCount() const;
    std::vector<geom::Aabb3> GetNodeCubes() const;
    bool HasPointIn(const glm::vec3& location, float_t radius) const;
    bool HasPointIn(const geom::Aabb3& search_range) const;
    std::vector<uint32_t> Find(const glm::vec3& location, float_t radius) const;
    std::vector<uint32_t> Find(const geom::Aabb3& search_range) const;
    int32_t GetIntersectedPoint(const geom::Ray3& ray, std::optional<float> tolerance = std::nullopt) const;
};

Detailed Documentation

Space-partitioning data structure for point clouds.

Fields

static const uint8_t POINTS_THRESHOLD = 64

When an octree node contains this number of points or less, it does not subdivide further.

Construction

Octree()

Default constructor.

Octree(const cogs::PointCloud& cloud)

Constructs Octree over the given cloud.

Parameters:

cloud

Octree will be constructed over points of this cloud.

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

Constructs Octree over the given vector of points.

Parameters:

positions

Octree will be constructed over these points.

~Octree()

Octree destructor.

Methods

void Include(const cogs::PointCloud& cloud)

Adds points of the input cloud into the Octree.

Parameters:

positions

Points of this cloud will be included in the octree.

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

Adds points of input clouds into the Octree.

Parameters:

positions

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

std::string ToString() const

Get the string representation of this octree.

Returns:

String representation of this octree.

size_t GetNodeCount() const

Get the number of nodes in the octree.

Returns:

Node count.

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

Returns the vector of bounding boxes of all internal nodes.

Returns:

Vector of bounding boxes.

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

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

Parameters:

location

Location in the world around which will be searched.

radius

Radius range of the search area.

Returns:

True if any point is in range, false otherwise.

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

Whether any of the points exist inside the input AABB.

Parameters:

search_range

Area of this axis aligned box will be searched for points.

Returns:

True if any point is included in the input AABB, false otherwise.

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

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

Parameters:

location

Location in the world around which will be searched.

radius

Radius range of the search area.

Returns:

Vector of point indices in the area.

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

Get indices of points that are inside the input AABB.

Parameters:

search_range

Area of this axis aligned box will be searched for points.

Returns:

Vector of point indices inside the input AABB.

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.

Parameters:

ray

Ray casted in the world.

tolerance

Maximal 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.