VoxelGrid Class Reference

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

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

+ Inheritance diagram for VoxelGrid:

Public Member Functions

std::set< LabelgetUniqueLabels () const
 Get the set of unique labels in the grid. More...
 
void readJson (const std::filesystem::path &file)
 
void readJson (std::istream &is)
 Read this voxel grid from JSON. More...
 
void setByLabelDensity (const LabelDensity::VoxelGrid &density, bool adoptStructure=false)
 Set the voxels by selecting the label with most points for each voxel. 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...
 

Static Public Member Functions

static VoxelGrid fromLabelDensity (const LabelDensity::VoxelGrid &density)
 Make a label occupancy grid from the given density grid. More...
 

Static Public Attributes

static const std::string JSON_VOXEL_ARRAY_NAME = "labels"
 Name of the single voxel array in JSON. 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

◆ fromLabelDensity()

VoxelGrid fromLabelDensity ( const LabelDensity::VoxelGrid density)
static

Make a label occupancy grid from the given density grid.

See also
setByLabelDensity()

Definition at line 80 of file VoxelGrid.cpp.

+ Here is the call graph for this function:

◆ getUniqueLabels()

std::set< Label > getUniqueLabels ( ) const

Get the set of unique labels in the grid.

Definition at line 87 of file VoxelGrid.cpp.

+ Here is the call graph for this function:

◆ readJson() [1/2]

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

Definition at line 147 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 142 of file VoxelGrid.cpp.

+ Here is the call graph for this function:

◆ setByLabelDensity()

void setByLabelDensity ( const LabelDensity::VoxelGrid density,
bool  adoptStructure = false 
)

Set the voxels by selecting the label with most points for each voxel.

This overwrites any information previously stored in this grid.

Parameters
densityThe label density grid.
adoptStructureIf false, throws an exception if density's structure is not equal to the structure of *this. If you wish to adopt densitys structure, pass true.
Exceptions
<tt>voxelgrid::error::InvalidStructure</tt>If density's structure is different to getStructure() and adoptStructure is false.

Definition at line 100 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 137 of file VoxelGrid.cpp.

+ Here is the call graph for this function:

◆ writeJson() [2/2]

void writeJson ( std::ostream &  os) const

Write this voxel grid to JSON.

Definition at line 132 of file VoxelGrid.cpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ JSON_VOXEL_ARRAY_NAME

const std::string JSON_VOXEL_ARRAY_NAME = "labels"
static

Name of the single voxel array in JSON.

Definition at line 124 of file VoxelGrid.h.


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