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. 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 getExtent () const
 Get extent of the grid along each axis (encompassing the whole voxels). More...
 
Eigen::Vector3f getExtentOfCenters () const
 Get extent of the grid along each axis (encompassing only voxel centers). More...
 
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. More...
 
std::size_t getFlatIndex (const Eigen::Vector3i &indices) const
 Get the flat index for the given grid indices. More...
 
std::size_t getFlatIndex (int x, int y, int z) const
 Get the flat index for the given grid indices. More...
 
Eigen::Vector3i getGridIndex (const Eigen::Vector3f &point, bool local=false) const
 Get the indices of the voxel closest to point. More...
 
Eigen::Vector3i getGridIndex (size_t index) const
 Get the voxel indices of the voxel with the given index. More...
 
Eigen::Vector3i getGridIndexMax () const
 Get the maximal (along each axis) grid index. More...
 
Eigen::Vector3i getGridIndexMin () const
 Get the minimal (along each axis) grid index. More...
 
Eigen::Vector3i getGridSize () 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 contained in the structure. 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...
 
Eigen::Vector3f getVoxelCenter (const Eigen::Vector3i &indices, bool local=false) const
 Get the center of the voxel with the given indices. More...
 
Eigen::Vector3f getVoxelCenter (int x, int y, int z, bool local=false) const
 Get the center of the voxel with the given indices. More...
 
Eigen::Vector3f getVoxelCenter (std::size_t index, bool local=false) const
 Get the center of the voxel with the given indices. More...
 
Eigen::Vector3f getVoxelSize () 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 &indices) const
 Indicate whether the given point is inside the voxel. More...
 
bool operator!= (const VoxelGridStructure &rhs) const
 
bool operator== (const VoxelGridStructure &rhs) const
 Indicates whether rhs is equal to *this. More...
 
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). More...
 
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. More...
 
void setGridSize (const Eigen::Vector3i &gridSize)
 Set the grid size. More...
 
void setGridSize (int gridSize)
 Set the grid size for a cubic grid. 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 &pose)
 Get the grid pose in the world frame. More...
 
void setVoxelSize (const Eigen::Vector3f &voxelSize)
 Set the voxel size. More...
 
void setVoxelSize (float voxelSize)
 Set the voxel size for cubic voxels. More...
 
 VoxelGridStructure ()
 Construct an empty grid structure (0 voxels with size 1.0). More...
 
 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. More...
 
 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. More...
 
 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. More...
 
 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. More...
 

Friends

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

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)

Definition at line 96 of file VoxelGridStructure.h.

Constructor & Destructor Documentation

◆ VoxelGridStructure() [1/5]

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

Definition at line 31 of file VoxelGridStructure.cpp.

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

Definition at line 34 of file VoxelGridStructure.cpp.

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

Definition at line 42 of file VoxelGridStructure.cpp.

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

Definition at line 48 of file VoxelGridStructure.cpp.

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

Definition at line 54 of file VoxelGridStructure.cpp.

Member Function Documentation

◆ checkIsInside()

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

Assert that the given indices are valid grid indices.

Definition at line 300 of file VoxelGridStructure.cpp.

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

◆ getCenter()

Eigen::Vector3f getCenter ( ) const

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

Definition at line 222 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

◆ getCenterPose()

Eigen::Matrix4f getCenterPose ( ) const

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

Definition at line 243 of file VoxelGridStructure.cpp.

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

◆ getExtent()

Eigen::Vector3f getExtent ( ) const

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

Definition at line 254 of file VoxelGridStructure.cpp.

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

◆ getExtentOfCenters()

Eigen::Vector3f getExtentOfCenters ( ) const

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

Definition at line 259 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

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

Definition at line 122 of file VoxelGridStructure.cpp.

+ Here is the call graph for this function:

◆ getFlatIndex() [2/3]

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

Get the flat index for the given grid indices.

Definition at line 107 of file VoxelGridStructure.cpp.

+ Here is the call graph for this function:

◆ getFlatIndex() [3/3]

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

Get the flat index for the given grid indices.

Definition at line 102 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

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

Definition at line 141 of file VoxelGridStructure.cpp.

+ Here is the call graph for this function:

◆ getGridIndex() [2/2]

Eigen::Vector3i getGridIndex ( size_t  index) const

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

Definition at line 127 of file VoxelGridStructure.cpp.

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

◆ getGridIndexMax()

Eigen::Vector3i getGridIndexMax ( ) const

Get the maximal (along each axis) grid index.

Definition at line 168 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

◆ getGridIndexMin()

Eigen::Vector3i getGridIndexMin ( ) const

Get the minimal (along each axis) grid index.

Definition at line 159 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

◆ getGridSize()

Eigen::Vector3i getGridSize ( ) const

Get the grid size.

Definition at line 67 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

◆ getLocalBoundingBox()

Eigen::Matrix32f getLocalBoundingBox ( ) const

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

Definition at line 264 of file VoxelGridStructure.cpp.

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

◆ getLocalBoundingBoxOfCenters()

Eigen::Matrix32f getLocalBoundingBoxOfCenters ( ) const

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

Definition at line 272 of file VoxelGridStructure.cpp.

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

◆ getNumVoxels()

std::size_t getNumVoxels ( ) const

Get the number of voxels contained in the structure.

Definition at line 97 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

◆ getOrientation()

Eigen::Quaternionf getOrientation ( ) const

Get the grid orienation in the world frame.

Definition at line 212 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

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

Definition at line 202 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

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

Definition at line 232 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

◆ getVoxelCenter() [1/3]

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

Get the center of the voxel with the given indices.

Definition at line 188 of file VoxelGridStructure.cpp.

+ Here is the call graph for this function:

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

Definition at line 183 of file VoxelGridStructure.cpp.

+ Here is the call graph for this function:

◆ getVoxelCenter() [3/3]

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

Get the center of the voxel with the given indices.

Definition at line 178 of file VoxelGridStructure.cpp.

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

◆ getVoxelSize()

Eigen::Vector3f getVoxelSize ( ) const

Get the voxel size.

Definition at line 82 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

◆ isInside() [1/2]

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

Indicate whether the given point is inside the voxel.

Definition at line 295 of file VoxelGridStructure.cpp.

+ Here is the call graph for this function:

◆ isInside() [2/2]

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

Indicate whether the given point is inside the voxel.

Definition at line 280 of file VoxelGridStructure.cpp.

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

◆ operator!=()

bool operator!= ( const VoxelGridStructure rhs) const

Definition at line 317 of file VoxelGridStructure.cpp.

◆ operator==()

bool operator== ( const VoxelGridStructure rhs) const

Indicates whether rhs is equal to *this.

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

Definition at line 309 of file VoxelGridStructure.cpp.

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

Definition at line 227 of file VoxelGridStructure.cpp.

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

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

Definition at line 248 of file VoxelGridStructure.cpp.

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

◆ setGridSize() [1/2]

void setGridSize ( const Eigen::Vector3i &  gridSize)

Set the grid size.

Definition at line 77 of file VoxelGridStructure.cpp.

◆ setGridSize() [2/2]

void setGridSize ( int  gridSize)

Set the grid size for a cubic grid.

Definition at line 72 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

◆ setOrientation()

void setOrientation ( const Eigen::Quaternionf value)

Set the grid orienation in the world frame.

Definition at line 217 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

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

Definition at line 207 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

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

Definition at line 237 of file VoxelGridStructure.cpp.

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

◆ setVoxelSize() [1/2]

void setVoxelSize ( const Eigen::Vector3f &  voxelSize)

Set the voxel size.

Definition at line 92 of file VoxelGridStructure.cpp.

◆ setVoxelSize() [2/2]

void setVoxelSize ( float  voxelSize)

Set the voxel size for cubic voxels.

Definition at line 87 of file VoxelGridStructure.cpp.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

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

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

Definition at line 341 of file VoxelGridStructure.cpp.


The documentation for this class was generated from the following files:
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39