VoxelGrid< _VoxelT > Class Template Reference

A 3D grid of voxels of type _VoxelT. More...

#include <VisionX/libraries/VoxelGridCore/VoxelGrid.hpp>

Public Types

using VoxelT = _VoxelT
 The voxel type. More...
 

Public Member Functions

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

Protected Attributes

VoxelGridStructure _struct
 The geometric structure. More...
 
std::vector< VoxelT_voxels
 The voxel data. More...
 

Friends

template<class VoxelType >
std::ostream & operator<< (std::ostream &os, const VoxelGrid< VoxelType > &grid)
 Stream a human-readable description of the grid's structure. More...
 

Detailed Description

template<typename _VoxelT>
class visionx::voxelgrid::VoxelGrid< _VoxelT >

A 3D grid of voxels of type _VoxelT.

A VoxelGrid three-dimensional regular grid of cuboids, called voxels. Its geometric structure is defined by a VoxelGridStructure. In addition, it stores voxel data of type _VoxelT (one per voxel).

This is a generic implementation made to hold hold arbitrary data. As such, there is no concept of "free/occupied" voxels".

See also
VoxelGridStructure

Definition at line 50 of file VoxelGrid.hpp.

Member Typedef Documentation

◆ VoxelT

using VoxelT = _VoxelT

The voxel type.

Definition at line 55 of file VoxelGrid.hpp.

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]

VoxelGrid ( const VoxelGridStructure structure,
const VoxelT value = {} 
)

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

Definition at line 460 of file VoxelGrid.hpp.

◆ VoxelGrid() [3/5]

VoxelGrid ( const VoxelGridStructure structure,
const std::vector< VoxelGrid< _VoxelT >::VoxelT > &  voxelData 
)

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 ( const VoxelGrid< OtherVoxelT > &  other)

Construct a voxel grid with the same structure as other.

Definition at line 478 of file VoxelGrid.hpp.

◆ VoxelGrid() [5/5]

VoxelGrid ( const VoxelGrid< VoxelT > &  other)
default

Ordinary copy constructor for voxel grid with same VoxelT.

Member Function Documentation

◆ begin() [1/2]

std::vector<VoxelT>::iterator begin ( )
inline

Get an iterator to the first voxel.

Definition at line 407 of file VoxelGrid.hpp.

◆ begin() [2/2]

std::vector<VoxelT>::const_iterator begin ( ) const
inline

Get an iterator to the first voxel.

Definition at line 412 of file VoxelGrid.hpp.

◆ cbegin()

std::vector<VoxelT>::const_iterator cbegin ( ) const
inline

Get an iterator to the first voxel.

Definition at line 417 of file VoxelGrid.hpp.

◆ cend()

std::vector<VoxelT>::const_iterator cend ( ) const
inline

Get an iterator to the element following the last voxel.

Definition at line 433 of file VoxelGrid.hpp.

◆ checkIsInside()

void checkIsInside ( const Eigen::Vector3i &  index) const
inline

Assert that the given index is a valid grid index.

Definition at line 379 of file VoxelGrid.hpp.

◆ end() [1/2]

std::vector<VoxelT>::iterator end ( )
inline

Get an iterator to the element following the last voxel.

Definition at line 423 of file VoxelGrid.hpp.

◆ end() [2/2]

std::vector<VoxelT>::const_iterator end ( ) const
inline

Get an iterator to the element following the last voxel.

Definition at line 428 of file VoxelGrid.hpp.

◆ getCenter()

Eigen::Vector3f getCenter ( ) const
inline

Get the geometric center of the grid the world frame (which differs from the origin for even grid sizes).

Definition at line 297 of file VoxelGrid.hpp.

◆ getCenterPose()

Eigen::Matrix4f getCenterPose ( ) const
inline

Get the grid pose positioned at the grid center in the world frame.

Definition at line 333 of file VoxelGrid.hpp.

◆ getExtents()

Eigen::Vector3f getExtents ( ) const
inline

Get extent of the grid along each axis (encompassing the whole voxels).

Definition at line 346 of file VoxelGrid.hpp.

◆ getExtentsOfCenters()

Eigen::Vector3f getExtentsOfCenters ( ) const
inline

Get extent of the grid along each axis (encompassing only voxel centers).

Definition at line 351 of file VoxelGrid.hpp.

◆ getGridSizes()

Eigen::Vector3i getGridSizes ( ) const
inline

Get the grid size.

Definition at line 177 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getLocalBoundingBox()

Eigen::Matrix32f getLocalBoundingBox ( ) const
inline

Get the local axis aligned bounding box of the grid (minimal/maximal values in columns).

Definition at line 356 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getLocalBoundingBoxOfCenters()

Eigen::Matrix32f getLocalBoundingBoxOfCenters ( ) const
inline

Get the local axis aligned bounding box of the voxel centers (minimal/maximal values in columns).

Definition at line 361 of file VoxelGrid.hpp.

◆ getNumVoxels()

std::size_t getNumVoxels ( ) const
inline

Get the number of voxels in the grid.

Definition at line 170 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getOrientation()

Eigen::Quaternionf getOrientation ( ) const
inline

Get the grid orienation in the world frame.

Definition at line 283 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getOrigin()

Eigen::Vector3f getOrigin ( ) const
inline

Get the grid origin in the world frame (center of voxel [0 0 0]).

Note that this differs from the geometric center for even grid sizes.

See also
getCenter()

Definition at line 270 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getPose()

Eigen::Matrix4f getPose ( ) const
inline

Get the grid pose in the world frame.

Note that this differs from the geometric center for even grid sizes.

See also
getCenterPose()

Definition at line 320 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getStructure()

VoxelGridStructure getStructure ( ) const
inline

Get the voxel grid structure.

Definition at line 91 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getVoxel() [1/8]

VoxelT& getVoxel ( const Eigen::Vector3f &  point,
bool  local = false 
)
inline

Get the voxel closest to the given point.

Parameters
localIf false (default), the point is transformed to local coordinate system.

Definition at line 135 of file VoxelGrid.hpp.

◆ getVoxel() [2/8]

const VoxelT& getVoxel ( const Eigen::Vector3f &  point,
bool  local = false 
) const
inline

Definition at line 139 of file VoxelGrid.hpp.

◆ getVoxel() [3/8]

VoxelT& getVoxel ( const Eigen::Vector3i &  index)
inline

Get the voxel with the given grid index.

See also
operator[]

Definition at line 124 of file VoxelGrid.hpp.

◆ getVoxel() [4/8]

const VoxelT& getVoxel ( const Eigen::Vector3i &  index) const
inline

Definition at line 128 of file VoxelGrid.hpp.

◆ getVoxel() [5/8]

VoxelT& getVoxel ( int  x,
int  y,
int  z 
)
inline

Get the voxel with the given grid index.

See also
operator[]

Definition at line 114 of file VoxelGrid.hpp.

◆ getVoxel() [6/8]

const VoxelT& getVoxel ( int  x,
int  y,
int  z 
) const
inline

Definition at line 118 of file VoxelGrid.hpp.

◆ getVoxel() [7/8]

VoxelT& getVoxel ( std::size_t  index)
inline

Get the voxel with the given index.

See also
operator[]

Definition at line 104 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getVoxel() [8/8]

const VoxelT& getVoxel ( std::size_t  index) const
inline

Definition at line 108 of file VoxelGrid.hpp.

◆ getVoxelCenter() [1/3]

Eigen::Vector3f getVoxelCenter ( const Eigen::Vector3i &  index,
bool  local = false 
) const
inline

Get the center of the voxel with the given index.

Definition at line 261 of file VoxelGrid.hpp.

◆ getVoxelCenter() [2/3]

Eigen::Vector3f getVoxelCenter ( int  x,
int  y,
int  z,
bool  local = false 
) const
inline

Get the center of the voxel with the given index.

Definition at line 256 of file VoxelGrid.hpp.

◆ getVoxelCenter() [3/3]

Eigen::Vector3f getVoxelCenter ( std::size_t  index,
bool  local = false 
) const
inline

Get the center of the voxel with the given index.

Definition at line 251 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getVoxelFlatIndex() [1/3]

std::size_t getVoxelFlatIndex ( const Eigen::Vector3f &  point,
bool  local = false 
) const
inline

Get the flat index of the voxel closest to point.

Definition at line 222 of file VoxelGrid.hpp.

◆ getVoxelFlatIndex() [2/3]

std::size_t getVoxelFlatIndex ( const Eigen::Vector3i &  index) const
inline

Get the flat index of the voxel with given grid index.

Definition at line 217 of file VoxelGrid.hpp.

◆ getVoxelFlatIndex() [3/3]

std::size_t getVoxelFlatIndex ( int  x,
int  y,
int  z 
) const
inline

Get the flat index of the voxel with given grid index.

Definition at line 212 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getVoxelGridIndex() [1/2]

Eigen::Vector3i getVoxelGridIndex ( const Eigen::Vector3f &  point,
bool  local = false 
) const
inline

Get the grid index of the voxel closest to point.

Parameters
localIf false (default), the point is transformed to local coordinate system.

Definition at line 234 of file VoxelGrid.hpp.

◆ getVoxelGridIndex() [2/2]

Eigen::Vector3i getVoxelGridIndex ( size_t  index) const
inline

Get the grid index of the voxel with the given flat index.

Definition at line 228 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getVoxelGridIndexMax()

Eigen::Vector3i getVoxelGridIndexMax ( ) const
inline

Get the maximal (along each axis) voxel grid index.

Definition at line 245 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getVoxelGridIndexMin()

Eigen::Vector3i getVoxelGridIndexMin ( ) const
inline

Get the minimal (along each axis) voxel grid index.

Definition at line 240 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getVoxels()

const std::vector<VoxelT>& getVoxels ( ) const
inline

Get the voxels.

Note
VoxelGrid provides begin()/end() pairs, so it can be iterated over directly.

Definition at line 147 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ getVoxelSizes()

Eigen::Vector3f getVoxelSizes ( ) const
inline

Get the voxel size.

Definition at line 195 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ isInside() [1/2]

bool isInside ( const Eigen::Vector3f &  point,
bool  local = false 
) const
inline

Indicate whether the given point is inside the voxel.

Definition at line 373 of file VoxelGrid.hpp.

◆ isInside() [2/2]

bool isInside ( const Eigen::Vector3i &  index) const
inline

Indicate whether the given point is inside the voxel.

Definition at line 368 of file VoxelGrid.hpp.

◆ numVoxels()

std::size_t numVoxels ( ) const
inline

Get the number of voxels in the grid.

Definition at line 165 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ operator[]() [1/4]

VoxelT& operator[] ( const Eigen::Vector3i &  index)
inline

Get the voxel with given grid index.

See also
getVoxel(const Eigen::Vector3i&)

Definition at line 396 of file VoxelGrid.hpp.

◆ operator[]() [2/4]

const VoxelT& operator[] ( const Eigen::Vector3i &  index) const
inline

Definition at line 400 of file VoxelGrid.hpp.

◆ operator[]() [3/4]

VoxelT& operator[] ( std::size_t  index)
inline

Get the voxel with given flat index.

See also
getVoxel(std::size_t)

Definition at line 386 of file VoxelGrid.hpp.

◆ operator[]() [4/4]

const VoxelT& operator[] ( std::size_t  index) const
inline

Definition at line 390 of file VoxelGrid.hpp.

◆ reset()

void reset ( const VoxelT value = {})
inline

Reset the voxel data by numVoxels() voxels with given value.

Definition at line 84 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ resetStructure()

void resetStructure ( const VoxelGridStructure structure)
inline

Set the voxel grid structure and reset voxel data.

Definition at line 96 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ setCenter()

void setCenter ( const Eigen::Vector3f &  value)
inline

Set the geometric center of the grid the world frame (which differs from the origin for even grid sizes).

Note
This computes the origin from the given center using the current orientation. If you want to set grid center and orientation, set the orientation first, or (equivalently), use setCenterPose().
See also
setPoseGridCenter()

Definition at line 311 of file VoxelGrid.hpp.

◆ setCenterPose()

void setCenterPose ( const Eigen::Matrix4f &  value)
inline

Set the grid pose so that the grid center is the position of the given pose under the given orientation.

Definition at line 339 of file VoxelGrid.hpp.

◆ setGridSizes() [1/2]

void setGridSizes ( const Eigen::Vector3i &  gridSizes)
inline

Set the grid size. This resets the grid data.

Definition at line 187 of file VoxelGrid.hpp.

◆ setGridSizes() [2/2]

void setGridSizes ( float  gridSizes)
inline

Set the grid size for a cubic grid. Resets the grid data.

Definition at line 182 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ setOrientation()

void setOrientation ( const Eigen::Quaternionf value)
inline

Set the grid orienation in the world frame.

Definition at line 288 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ setOrigin()

void setOrigin ( const Eigen::Vector3f &  value)
inline

Set the grid origin the world frame (center of voxel [0 0 0]).

Note that this differs from the geometric center for even grid sizes.

See also
setCenter()

Definition at line 277 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ setPose()

void setPose ( const Eigen::Matrix4f &  value)
inline

Get the grid pose in the world frame.

Note that this differs from the geometric center for even grid sizes.

See also
setCenterPose()

Definition at line 327 of file VoxelGrid.hpp.

◆ setVoxels()

void setVoxels ( const std::vector< VoxelT > &  voxels)
inline

Set the voxels.

(Size must match numVoxels()).

Exceptions
error::InvalidVoxelDataSizeIf the size does not match.

Definition at line 154 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

◆ setVoxelSizes() [1/2]

void setVoxelSizes ( const Eigen::Vector3f &  voxelSizes)
inline

Set the voxel size. The grid data is not updated.

Definition at line 205 of file VoxelGrid.hpp.

◆ setVoxelSizes() [2/2]

void setVoxelSizes ( float  voxelSize)
inline

Set the voxel size of cubic voxels. The grid data is not updated.

Definition at line 200 of file VoxelGrid.hpp.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const VoxelGrid< VoxelType > &  grid 
)
friend

Stream a human-readable description of the grid's structure.

Member Data Documentation

◆ _struct

VoxelGridStructure _struct
protected

The geometric structure.

Definition at line 447 of file VoxelGrid.hpp.

◆ _voxels

std::vector<VoxelT> _voxels
protected

The voxel data.

Definition at line 450 of file VoxelGrid.hpp.


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