TinyRobotics
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
PointCloud< T > Class Template Reference

Represents a 3D point cloud for robotics and mapping applications. More...

#include <PointCloud.h>

Inheritance diagram for PointCloud< T >:
Inheritance graph
[legend]
Collaboration diagram for PointCloud< T >:
Collaboration graph
[legend]

Public Types

using VectorT = std::vector< Point3D< T >, AllocatorPSRAM< Point3D< T > > >
 
using value_type = T
 

Public Member Functions

 PointCloud (T voxalSize, bool isliveVoxel=false)
 
void setLiveVoxelGrid (bool live)
 
void setVoxalSize (T size)
 Set the size of each voxel in the grid (e.g., 0.1 m for 10cm voxels).
 
void add (T x, T y, T z=0.0f)
 Add a single point.
 
void add (const Point3D< T > *pts, size_t count)
 Add from array.
 
void add (const Coordinate< T > &coord)
 Add from Coordinate.
 
const VectorT & points () const
 Provides access to the points in the point cloud.
 
VectorT & points ()
 Provides access to the points in the point cloud.
 
size_t size () const
 Provide the number of points in the point cloud.
 
bool isEmpty () const
 Checks if the point cloud is empty (i.e., contains no points).
 
Bounds bounds () const
 Returns the bounding box of the point cloud, which is defined by the minimum and maximum coordinates along each axis (x, y, z). The bounding box is updated whenever new points are added to the cloud, allowing for efficient retrieval of the spatial extent of the point cloud.
 
void buildVoxelGrid ()
 Builds a voxel grid for fast occupancy queries: A voxel is a grid cell.
 
std::vector< Coordinate< T > > getNeighbors (Coordinate< T > from) const override
 Returns the free (unoccupied) neighboring coordinates of a given point in the voxel grid.
 
void set3D (bool is3d)
 
void setBounds (float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
 
bool isOccupied (float x, float y, float z) const
 Checks if a given point is occupied based on the voxel grid.
 
bool isValid (const Coordinate< T > &coord) const override
 Checks if a coordinate is valid (within bounds and not occupied)
 
auto beginVoxels ()
 Provides sequential (iterator) access to all occupied voxels.
 
auto endVoxels ()
 Provides sequential (iterator) access to all occupied voxels.
 
auto beginVoxels () const
 Provides sequential (iterator) access to all occupied voxels.
 
auto endVoxels () const
 Provides sequential (iterator) access to all occupied voxels.
 
size_t writeTo (Print &out)
 Write map to output.
 
size_t readFrom (Stream &in)
 Read map from input.
 
void clear ()
 Clear all data.
 
virtual std::vector< Coordinate< T > > getNeighbors (Coordinate< T > from) const =0
 Get world coordinates of neighboring cells (for pathfinding or navigation).
 
virtual bool isValid (const Coordinate< T > &coord) const =0
 Check if a coordinate is inside the map bounds.
 

Protected Types

using PSRAMKeyAllocator = AllocatorPSRAM< Key >
 

Protected Member Functions

void resetBounds ()
 
void updateBounds (const Point3D< T > &p)
 
void addVoxel (float x, float y, float z)
 Adds a point to the voxel grid if voxelSize_ > 0.
 
Coordinate< T > toVoxel (int cx, int cy) const
 

Protected Attributes

bool is_3d = false
 
VectorT points_
 
Bounds bounds_
 
voxelSize_ = 0.0f
 
bool liveVocelGrid_ = false
 
std::unordered_set< Key, KeyHash, std::equal_to< Key >, PSRAMKeyAllocatorvoxelGrid_
 
PointCloudSerializer< PointCloud< T > > serializer
 

Detailed Description

template<typename T = DistanceM>
class tinyrobotics::PointCloud< T >

Represents a 3D point cloud for robotics and mapping applications.

The PointCloud class manages a collection of 3D points and provides:

Usage scenarios include 3D mapping, obstacle detection, SLAM, and environment representation. The class is designed for embedded and robotics use, balancing efficiency and flexibility.

Key features:

Example:

PointCloud cloud(0.1f);
cloud.add(1.0, 2.0, 0.5);
cloud.buildVoxelGrid(); // 10cm voxels
bool occ = cloud.isOccupied(1.0, 2.0, 0.5);
Represents a 3D point cloud for robotics and mapping applications.
Definition: PointCloud.h:64

Member Function Documentation

◆ getNeighbors()

std::vector< Coordinate< T > > getNeighbors ( Coordinate< T >  from) const
inlineoverridevirtual

Returns the free (unoccupied) neighboring coordinates of a given point in the voxel grid.

If the voxel grid is built (voxelSize_ > 0), this method returns all adjacent unoccupied voxels (6-connectivity in 3D, or 4/8-connectivity in 2D if z=0). Only neighbors that are not present in the voxel grid are returned.

Parameters
fromThe coordinate to find neighbors for.
Returns
std::vector<Coordinate<T>> List of free neighboring coordinates.

Implements IMapNeighbors< T >.

◆ isValid()

bool isValid ( const Coordinate< T > &  coord) const
inlineoverridevirtual

Checks if a coordinate is valid (within bounds and not occupied)

Implements IMapNeighbors< T >.

◆ set3D()

void set3D ( bool  is3d)
inline

Use 3D in findNeighbors (if false, only consider z=0 plane for 2D occupancy)

◆ setBounds()

void setBounds ( float  minX,
float  minY,
float  minZ,
float  maxX,
float  maxY,
float  maxZ 
)
inline

Manually set the bounding box (if known in advance, can save time instead of

◆ setLiveVoxelGrid()

void setLiveVoxelGrid ( bool  live)
inline

Update the voxel grid as points are added (for real-time occupancy updates).

◆ toVoxel()

Coordinate< T > toVoxel ( int  cx,
int  cy 
) const
inlineprotected

Convert voxel grid index (cx, cy) to world coordinate (center of voxel, z=0)


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