VoxelGridStructure Class Reference

Geometric structure of a 3D voxel grid. More...

#include <VisionX/libraries/VoxelGridCore/VoxelGridStructure.h>

Public Member Functions

void checkIsInside (const Eigen::Vector3i &indices) const
 Assert that the given indices are valid grid indices.
 
Eigen::Vector3f getCenter () const
 Get the geometric center of the grid the world frame (which differs from the origin for even grid sizes).
 
Eigen::Matrix4f getCenterPose () const
 Get the grid pose positioned at the grid center in the world frame.
 
Eigen::Vector3f getExtent () const
 Get extent of the grid along each axis (encompassing the whole voxels).
 
Eigen::Vector3f getExtentOfCenters () const
 Get extent of the grid along each axis (encompassing only voxel centers).
 
std::size_t getFlatIndex (const Eigen::Vector3f &point, bool local=false) const
 Get the flat index into the grid data of the voxel closest to point.
 
std::size_t getFlatIndex (const Eigen::Vector3i &indices) const
 Get the flat index for the given grid indices.
 
std::size_t getFlatIndex (int x, int y, int z) const
 Get the flat index for the given grid indices.
 
Eigen::Vector3i getGridIndex (const Eigen::Vector3f &point, bool local=false) const
 Get the indices of the voxel closest to point.
 
Eigen::Vector3i getGridIndex (size_t index) const
 Get the voxel indices of the voxel with the given index.
 
Eigen::Vector3i getGridIndexMax () const
 Get the maximal (along each axis) grid index.
 
Eigen::Vector3i getGridIndexMin () const
 Get the minimal (along each axis) grid index.
 
Eigen::Vector3i getGridSize () const
 Get the grid size.
 
Eigen::Matrix32f getLocalBoundingBox () const
 Get the local axis aligned bounding box of the grid (minimal/maximal values in columns).
 
Eigen::Matrix32f getLocalBoundingBoxOfCenters () const
 Get the local axis aligned bounding box of the voxel centers (minimal/maximal values in columns).
 
std::size_t getNumVoxels () const
 Get the number of voxels contained in the structure.
 
Eigen::Quaternionf getOrientation () const
 Get the grid orienation in the world frame.
 
Eigen::Vector3f getOrigin () const
 Get the grid origin in the world frame (center of voxel [0 0 0]).
 
Eigen::Matrix4f getPose () const
 Get the grid pose in the world frame.
 
Eigen::Vector3f getVoxelCenter (const Eigen::Vector3i &indices, bool local=false) const
 Get the center of the voxel with the given indices.
 
Eigen::Vector3f getVoxelCenter (int x, int y, int z, bool local=false) const
 Get the center of the voxel with the given indices.
 
Eigen::Vector3f getVoxelCenter (std::size_t index, bool local=false) const
 Get the center of the voxel with the given indices.
 
Eigen::Vector3f getVoxelSize () const
 Get the voxel size.
 
bool isInside (const Eigen::Vector3f &point, bool local=false) const
 Indicate whether the given point is inside the voxel.
 
bool isInside (const Eigen::Vector3i &indices) const
 Indicate whether the given point is inside the voxel.
 
bool operator!= (const VoxelGridStructure &rhs) const
 
bool operator== (const VoxelGridStructure &rhs) const
 Indicates whether rhs is equal to *this.
 
void setCenter (const Eigen::Vector3f &center)
 Set the geometric center of the grid the world frame (which differs from the origin for even grid sizes).
 
void setCenterPose (const Eigen::Matrix4f &pose)
 Set the grid pose so that the grid center is the position of the given pose under the given orientation.
 
void setGridSize (const Eigen::Vector3i &gridSize)
 Set the grid size.
 
void setGridSize (int gridSize)
 Set the grid size for a cubic grid.
 
void setOrientation (const Eigen::Quaternionf &value)
 Set the grid orienation in the world frame.
 
void setOrigin (const Eigen::Vector3f &value)
 Set the grid origin the world frame (center of voxel [0 0 0]).
 
void setPose (const Eigen::Matrix4f &pose)
 Get the grid pose in the world frame.
 
void setVoxelSize (const Eigen::Vector3f &voxelSize)
 Set the voxel size.
 
void setVoxelSize (float voxelSize)
 Set the voxel size for cubic voxels.
 
 VoxelGridStructure ()
 Construct an empty grid structure (0 voxels with size 1.0).
 
 VoxelGridStructure (const Eigen::Vector3i &gridSize, const Eigen::Vector3f &voxelSize, const Eigen::Vector3f &origin=Eigen::Vector3f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
 Construct a voxel grid structure.
 
 VoxelGridStructure (const Eigen::Vector3i &gridSize, float voxelSize, const Eigen::Vector3f &origin=Eigen::Vector3f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
 Construct a voxel grid structure with cubic voxels.
 
 VoxelGridStructure (int gridSize, const Eigen::Vector3f &voxelSize, const Eigen::Vector3f &origin=Eigen::Vector3f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
 Construct a voxel grid structure with cubic grid.
 
 VoxelGridStructure (int gridSize, float voxelSize, const Eigen::Vector3f &origin=Eigen::Vector3f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
 Construct a voxel grid structure with cubic voxels and cubic grid.
 

Friends

std::ostream & operator<< (std::ostream &os, const VoxelGridStructure &grid)
 Stream a human-readable description of the grid's structure.
 

Detailed Description

Geometric structure of a 3D voxel grid.

The grid structure is defined by the voxel size(s) and grid size(s). The voxel size (R^3) is the extent of a single voxel along each axis (x, y, z). (Cubic voxels have constant extent along all axes). The grid size (N^3) is the number of voxels along each axis. (Cubic grids have constant number of voxels along all axes.)

In addition, the voxel grid can have a pose, i.e. position and orientation.

The total number of voxels to be contained in a structure is the product of the grid size coefficients.

Grid Size and Voxel Index

To indicate a voxel, one can use either of:

  • a grid index i = (i_x i_y i_z) in Z^3 (Eigen::Vector3i)
  • a flat index j in N^1 (std::size_t)

A grid index specifies the voxel index along each axis. A flat index specifies a voxel's running index (from 0 to #voxels - 1).

Each coefficient of a grid index is in the range [ - gridSize/2, gridSize/2 ) More precisely, it is in the set { - floor(gridSize/2), ..., 0, ..., ceil(gridSize/2) - 1 }

In other words,

  • for an ODD grid size: [ - floor(gridSize/2), floor(gridSize/2) ]
  • for an EVEN grid size: [ - gridSize/2 , gridSize/2 - 1 ]

For example (along one axis):

| Grid Size | Valid grid indices | +--------—+-----------------------—+ | 3 | { -1, 0, 1 } | | 4 | { -2, -1, 0, 1 } | | 5 | { -2, -1, 0, 1, 2 } |

Note that grid indices are centered around zero and can be negative. A flat index is always non-negative.

Voxel Grid Origin

The grid origin coincides with the center of voxel (0 0 0) and can be chosen freely upon construction. It differs from the grid center in axes with even grid size.

odd grid size (3) even grid size (4)
+---+---+---+ +---+---+---+---+ ^
| | | | 1 | | | | | 1 | voxel size
+---+---+---+ +---+---+---+---+ v
c | | o | | 0 | | | o | | 0
+---+---+---+ +---+---+---+---+----- c
| | | | -1 | | | | | -1
+---+---+---+ +---+---+---+---+
-1 0 1 | | | | | -2
c +---+---+---+---+
-2 -1 | 0 1
c
(i = origin, c = center)
constexpr T c
Definition UnscentedKalmanFilterTest.cpp:46

Constructor & Destructor Documentation

◆ VoxelGridStructure() [1/5]

Construct an empty grid structure (0 voxels with size 1.0).

◆ VoxelGridStructure() [2/5]

VoxelGridStructure ( int gridSize,
float voxelSize,
const Eigen::Vector3f & origin = Eigen::Vector3f::Zero(),
const Eigen::Quaternionf & orientation = Eigen::Quaternionf::Identity() )

Construct a voxel grid structure with cubic voxels and cubic grid.

◆ VoxelGridStructure() [3/5]

VoxelGridStructure ( const Eigen::Vector3i & gridSize,
float voxelSize,
const Eigen::Vector3f & origin = Eigen::Vector3f::Zero(),
const Eigen::Quaternionf & orientation = Eigen::Quaternionf::Identity() )

Construct a voxel grid structure with cubic voxels.

◆ VoxelGridStructure() [4/5]

VoxelGridStructure ( int gridSize,
const Eigen::Vector3f & voxelSize,
const Eigen::Vector3f & origin = Eigen::Vector3f::Zero(),
const Eigen::Quaternionf & orientation = Eigen::Quaternionf::Identity() )

Construct a voxel grid structure with cubic grid.

◆ VoxelGridStructure() [5/5]

VoxelGridStructure ( const Eigen::Vector3i & gridSize,
const Eigen::Vector3f & voxelSize,
const Eigen::Vector3f & origin = Eigen::Vector3f::Zero(),
const Eigen::Quaternionf & orientation = Eigen::Quaternionf::Identity() )

Construct a voxel grid structure.

Member Function Documentation

◆ checkIsInside()

void checkIsInside ( const Eigen::Vector3i & indices) const

Assert that the given indices are valid grid indices.

◆ getCenter()

Eigen::Vector3f getCenter ( ) const

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

◆ getCenterPose()

Eigen::Matrix4f getCenterPose ( ) const

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

◆ getExtent()

Eigen::Vector3f getExtent ( ) const

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

◆ getExtentOfCenters()

Eigen::Vector3f getExtentOfCenters ( ) const

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

◆ getFlatIndex() [1/3]

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

Get the flat index into the grid data of the voxel closest to point.

◆ getFlatIndex() [2/3]

std::size_t getFlatIndex ( const Eigen::Vector3i & indices) const

Get the flat index for the given grid indices.

◆ getFlatIndex() [3/3]

std::size_t getFlatIndex ( int x,
int y,
int z ) const

Get the flat index for the given grid indices.

◆ getGridIndex() [1/2]

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

Get the indices of the voxel closest to point.

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

◆ getGridIndex() [2/2]

Eigen::Vector3i getGridIndex ( size_t index) const

Get the voxel indices of the voxel with the given index.

◆ getGridIndexMax()

Eigen::Vector3i getGridIndexMax ( ) const

Get the maximal (along each axis) grid index.

◆ getGridIndexMin()

Eigen::Vector3i getGridIndexMin ( ) const

Get the minimal (along each axis) grid index.

◆ getGridSize()

Eigen::Vector3i getGridSize ( ) const

Get the grid size.

◆ getLocalBoundingBox()

Eigen::Matrix32f getLocalBoundingBox ( ) const

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

◆ getLocalBoundingBoxOfCenters()

Eigen::Matrix32f getLocalBoundingBoxOfCenters ( ) const

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

◆ getNumVoxels()

std::size_t getNumVoxels ( ) const

Get the number of voxels contained in the structure.

◆ getOrientation()

Eigen::Quaternionf getOrientation ( ) const

Get the grid orienation in the world frame.

◆ getOrigin()

Eigen::Vector3f getOrigin ( ) const

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()

◆ getPose()

Eigen::Matrix4f getPose ( ) const

Get the grid pose in the world frame.

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

See also
getCenterPose()

◆ getVoxelCenter() [1/3]

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

Get the center of the voxel with the given indices.

◆ getVoxelCenter() [2/3]

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

Get the center of the voxel with the given indices.

◆ getVoxelCenter() [3/3]

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

Get the center of the voxel with the given indices.

◆ getVoxelSize()

Eigen::Vector3f getVoxelSize ( ) const

Get the voxel size.

◆ isInside() [1/2]

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

Indicate whether the given point is inside the voxel.

◆ isInside() [2/2]

bool isInside ( const Eigen::Vector3i & indices) const

Indicate whether the given point is inside the voxel.

◆ operator!=()

bool operator!= ( const VoxelGridStructure & rhs) const

◆ operator==()

bool operator== ( const VoxelGridStructure & rhs) const

Indicates whether rhs is equal to *this.

Uses v.isApprox() to compare voxel size, origin and orientation.

◆ setCenter()

void setCenter ( const Eigen::Vector3f & center)

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 setGridCenterPose().
See also
setPoseGridCenter()

◆ setCenterPose()

void setCenterPose ( const Eigen::Matrix4f & pose)

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

◆ setGridSize() [1/2]

void setGridSize ( const Eigen::Vector3i & gridSize)

Set the grid size.

◆ setGridSize() [2/2]

void setGridSize ( int gridSize)

Set the grid size for a cubic grid.

◆ setOrientation()

void setOrientation ( const Eigen::Quaternionf & value)

Set the grid orienation in the world frame.

◆ setOrigin()

void setOrigin ( const Eigen::Vector3f & value)

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()

◆ setPose()

void setPose ( const Eigen::Matrix4f & pose)

Get the grid pose in the world frame.

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

See also
setCenterPose()

◆ setVoxelSize() [1/2]

void setVoxelSize ( const Eigen::Vector3f & voxelSize)

Set the voxel size.

◆ setVoxelSize() [2/2]

void setVoxelSize ( float voxelSize)

Set the voxel size for cubic voxels.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const VoxelGridStructure & grid )
friend

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


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