VoxelGrid Class Reference

Voxel grid storing the number of points per label in each voxel. More...

#include <VisionX/libraries/VoxelGrids/LabelDensity/VoxelGrid.h>

+ Inheritance diagram for VoxelGrid:

Public Member Functions

void addPointCloud (const pcl::PointCloud< pcl::PointXYZL > &pointCloud, const Eigen::Matrix4f &pointCloudPose=Eigen::Matrix4f::Identity())
 Add the point cloud. More...
 
void addPointCloud (const pcl::PointCloud< pcl::PointXYZRGBL > &pointCloud, const Eigen::Matrix4f &pointCloudPose=Eigen::Matrix4f::Identity())
 
std::set< LabelgetUniqueLabels () const
 Get the set of unique labels. More...
 
void readJson (const std::filesystem::path &file)
 
void readJson (std::istream &is)
 Read this voxel grid from JSON. More...
 
void reduceNoise (std::size_t minNumPoints)
 Remove entries with number of points below minNumPoints. More...
 
void toCsv (const std::filesystem::path &file, bool includeTotal=false) const
 
void toCsv (std::ostream &os, bool includeTotal=false) const
 Write the voxel data to a CSV file. More...
 
 VoxelGrid ()
 Construct a voxel grid with 0 voxels of size 1.0. More...
 
template<typename OtherVoxelT >
 VoxelGrid (const VoxelGrid< OtherVoxelT > &other)
 Construct a voxel grid with the same structure as other. More...
 
 VoxelGrid (const VoxelGrid< VoxelT > &other)=default
 Ordinary copy constructor for voxel grid with same VoxelT. More...
 
 VoxelGrid (const VoxelGridStructure &structure, const std::vector< VoxelGrid::VoxelT > &voxelData)
 Construct a voxel grid with the given structure and data. More...
 
 VoxelGrid (const VoxelGridStructure &structure, const VoxelT &value={})
 Construct a voxel grid with the given structure and voxels with given value. More...
 
void writeJson (const std::filesystem::path &file) const
 
void writeJson (std::ostream &os) const
 Write this voxel grid to JSON. More...
 
- Public Member Functions inherited from VoxelGrid< VoxelT >
std::vector< VoxelT >::iterator begin ()
 Get an iterator to the first voxel. More...
 
std::vector< VoxelT >::const_iterator begin () const
 Get an iterator to the first voxel. More...
 
std::vector< VoxelT >::const_iterator cbegin () const
 Get an iterator to the first voxel. More...
 
std::vector< VoxelT >::const_iterator cend () const
 Get an iterator to the element following the last voxel. More...
 
void checkIsInside (const Eigen::Vector3i &index) const
 Assert that the given index is a valid grid index. More...
 
std::vector< VoxelT >::iterator end ()
 Get an iterator to the element following the last voxel. More...
 
std::vector< VoxelT >::const_iterator end () const
 Get an iterator to the element following the last voxel. More...
 
Eigen::Vector3f getCenter () const
 Get the geometric center of the grid the world frame (which differs from the origin for even grid sizes). More...
 
Eigen::Matrix4f getCenterPose () const
 Get the grid pose positioned at the grid center in the world frame. More...
 
Eigen::Vector3f getExtents () const
 Get extent of the grid along each axis (encompassing the whole voxels). More...
 
Eigen::Vector3f getExtentsOfCenters () const
 Get extent of the grid along each axis (encompassing only voxel centers). More...
 
Eigen::Vector3i getGridSizes () const
 Get the grid size. More...
 
Eigen::Matrix32f getLocalBoundingBox () const
 Get the local axis aligned bounding box of the grid (minimal/maximal values in columns). More...
 
Eigen::Matrix32f getLocalBoundingBoxOfCenters () const
 Get the local axis aligned bounding box of the voxel centers (minimal/maximal values in columns). More...
 
std::size_t getNumVoxels () const
 Get the number of voxels in the grid. More...
 
Eigen::Quaternionf getOrientation () const
 Get the grid orienation in the world frame. More...
 
Eigen::Vector3f getOrigin () const
 Get the grid origin in the world frame (center of voxel [0 0 0]). More...
 
Eigen::Matrix4f getPose () const
 Get the grid pose in the world frame. More...
 
VoxelGridStructure getStructure () const
 Get the voxel grid structure. More...
 
VoxelTgetVoxel (const Eigen::Vector3f &point, bool local=false)
 Get the voxel closest to the given point. More...
 
const VoxelTgetVoxel (const Eigen::Vector3f &point, bool local=false) const
 
VoxelTgetVoxel (const Eigen::Vector3i &index)
 Get the voxel with the given grid index. More...
 
const VoxelTgetVoxel (const Eigen::Vector3i &index) const
 
VoxelTgetVoxel (int x, int y, int z)
 Get the voxel with the given grid index. More...
 
const VoxelTgetVoxel (int x, int y, int z) const
 
VoxelTgetVoxel (std::size_t index)
 Get the voxel with the given index. More...
 
const VoxelTgetVoxel (std::size_t index) const
 
Eigen::Vector3f getVoxelCenter (const Eigen::Vector3i &index, bool local=false) const
 Get the center of the voxel with the given index. More...
 
Eigen::Vector3f getVoxelCenter (int x, int y, int z, bool local=false) const
 Get the center of the voxel with the given index. More...
 
Eigen::Vector3f getVoxelCenter (std::size_t index, bool local=false) const
 Get the center of the voxel with the given index. More...
 
std::size_t getVoxelFlatIndex (const Eigen::Vector3f &point, bool local=false) const
 Get the flat index of the voxel closest to point. More...
 
std::size_t getVoxelFlatIndex (const Eigen::Vector3i &index) const
 Get the flat index of the voxel with given grid index. More...
 
std::size_t getVoxelFlatIndex (int x, int y, int z) const
 Get the flat index of the voxel with given grid index. More...
 
Eigen::Vector3i getVoxelGridIndex (const Eigen::Vector3f &point, bool local=false) const
 Get the grid index of the voxel closest to point. More...
 
Eigen::Vector3i getVoxelGridIndex (size_t index) const
 Get the grid index of the voxel with the given flat index. More...
 
Eigen::Vector3i getVoxelGridIndexMax () const
 Get the maximal (along each axis) voxel grid index. More...
 
Eigen::Vector3i getVoxelGridIndexMin () const
 Get the minimal (along each axis) voxel grid index. More...
 
const std::vector< VoxelT > & getVoxels () const
 Get the voxels. More...
 
Eigen::Vector3f getVoxelSizes () const
 Get the voxel size. More...
 
bool isInside (const Eigen::Vector3f &point, bool local=false) const
 Indicate whether the given point is inside the voxel. More...
 
bool isInside (const Eigen::Vector3i &index) const
 Indicate whether the given point is inside the voxel. More...
 
std::size_t numVoxels () const
 Get the number of voxels in the grid. More...
 
VoxelToperator[] (const Eigen::Vector3i &index)
 Get the voxel with given grid index. More...
 
const VoxelToperator[] (const Eigen::Vector3i &index) const
 
VoxelToperator[] (std::size_t index)
 Get the voxel with given flat index. More...
 
const VoxelToperator[] (std::size_t index) const
 
void reset (const VoxelT &value={})
 Reset the voxel data by numVoxels() voxels with given value. More...
 
void resetStructure (const VoxelGridStructure &structure)
 Set the voxel grid structure and reset voxel data. More...
 
void setCenter (const Eigen::Vector3f &value)
 Set the geometric center of the grid the world frame (which differs from the origin for even grid sizes). More...
 
void setCenterPose (const Eigen::Matrix4f &value)
 Set the grid pose so that the grid center is the position of the given pose under the given orientation. More...
 
void setGridSizes (const Eigen::Vector3i &gridSizes)
 Set the grid size. This resets the grid data. More...
 
void setGridSizes (float gridSizes)
 Set the grid size for a cubic grid. Resets the grid data. More...
 
void setOrientation (const Eigen::Quaternionf &value)
 Set the grid orienation in the world frame. More...
 
void setOrigin (const Eigen::Vector3f &value)
 Set the grid origin the world frame (center of voxel [0 0 0]). More...
 
void setPose (const Eigen::Matrix4f &value)
 Get the grid pose in the world frame. More...
 
void setVoxels (const std::vector< VoxelT > &voxels)
 Set the voxels. More...
 
void setVoxelSizes (const Eigen::Vector3f &voxelSizes)
 Set the voxel size. The grid data is not updated. More...
 
void setVoxelSizes (float voxelSize)
 Set the voxel size of cubic voxels. The grid data is not updated. More...
 
 VoxelGrid ()
 Construct a voxel grid with 0 voxels of size 1.0. More...
 
 VoxelGrid (const VoxelGrid< OtherVoxelT > &other)
 Construct a voxel grid with the same structure as other. More...
 
 VoxelGrid (const VoxelGrid< VoxelT > &other)=default
 Ordinary copy constructor for voxel grid with same VoxelT. More...
 
 VoxelGrid (const VoxelGridStructure &structure, const std::vector< VoxelGrid::VoxelT > &voxelData)
 Construct a voxel grid with the given structure and data. More...
 
 VoxelGrid (const VoxelGridStructure &structure, const VoxelT &value={})
 Construct a voxel grid with the given structure and voxels with given value. More...
 

Additional Inherited Members

- Public Types inherited from VoxelGrid< VoxelT >
using VoxelT = VoxelT
 The voxel type. More...
 
- Protected Attributes inherited from VoxelGrid< VoxelT >
VoxelGridStructure _struct
 The geometric structure. More...
 
std::vector< VoxelT_voxels
 The voxel data. More...
 

Detailed Description

Voxel grid storing the number of points per label in each voxel.

Definition at line 69 of file VoxelGrid.h.

Constructor & Destructor Documentation

◆ VoxelGrid() [1/5]

Construct a voxel grid with 0 voxels of size 1.0.

Definition at line 456 of file VoxelGrid.hpp.

◆ VoxelGrid() [2/5]

Construct a voxel grid with the given structure and voxels with given value.

Definition at line 460 of file VoxelGrid.hpp.

◆ VoxelGrid() [3/5]

Construct a voxel grid with the given structure and data.

The size of voxelData must match the grid size of structure.

Exceptions
error::InvalidVoxelDataSizeIf the size does not match.

Definition at line 465 of file VoxelGrid.hpp.

◆ VoxelGrid() [4/5]

VoxelGrid ( typename OtherVoxelT  )

Construct a voxel grid with the same structure as other.

Definition at line 478 of file VoxelGrid.hpp.

◆ VoxelGrid() [5/5]

VoxelGrid
default

Ordinary copy constructor for voxel grid with same VoxelT.

Member Function Documentation

◆ addPointCloud() [1/2]

void addPointCloud ( const pcl::PointCloud< pcl::PointXYZL > &  pointCloud,
const Eigen::Matrix4f &  pointCloudPose = Eigen::Matrix4f::Identity() 
)

Add the point cloud.

Parameters
pointCloudThe point cloud.
pointCloudPoseThe point cloud pose (in the same frame as the grid's pose).

Definition at line 128 of file VoxelGrid.cpp.

◆ addPointCloud() [2/2]

void addPointCloud ( const pcl::PointCloud< pcl::PointXYZRGBL > &  pointCloud,
const Eigen::Matrix4f &  pointCloudPose = Eigen::Matrix4f::Identity() 
)

Definition at line 135 of file VoxelGrid.cpp.

◆ getUniqueLabels()

std::set< Label > getUniqueLabels ( ) const

Get the set of unique labels.

Definition at line 143 of file VoxelGrid.cpp.

+ Here is the caller graph for this function:

◆ readJson() [1/2]

void readJson ( const std::filesystem::path &  file)

Definition at line 255 of file VoxelGrid.cpp.

+ Here is the call graph for this function:

◆ readJson() [2/2]

void readJson ( std::istream &  is)

Read this voxel grid from JSON.

Definition at line 247 of file VoxelGrid.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceNoise()

void reduceNoise ( std::size_t  minNumPoints)

Remove entries with number of points below minNumPoints.

Definition at line 156 of file VoxelGrid.cpp.

◆ toCsv() [1/2]

void toCsv ( const std::filesystem::path &  file,
bool  includeTotal = false 
) const

Definition at line 329 of file VoxelGrid.cpp.

+ Here is the call graph for this function:

◆ toCsv() [2/2]

void toCsv ( std::ostream &  os,
bool  includeTotal = false 
) const

Write the voxel data to a CSV file.

(Structure is not stored.)

The first column, "index", specified the flat voxel index. The other columns represent the labels, and each row entry specifies the number of points with that label in the respective voxel.

If includeTotal is true, a final column "total" is added, storing the voxel-wise total number of points.

Definition at line 273 of file VoxelGrid.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeJson() [1/2]

void writeJson ( const std::filesystem::path &  file) const

Definition at line 242 of file VoxelGrid.cpp.

◆ writeJson() [2/2]

void writeJson ( std::ostream &  os) const

Write this voxel grid to JSON.

Definition at line 237 of file VoxelGrid.cpp.


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