Voxomap
A C++11 voxel container.
voxomap::SparseContainer< T_Voxel, T_Container > Class Template Reference

Voxel container used in leaves of the VoxelOctree. Mix between a fixed size 3D array (like in ArrayContainer) and a dynamic array. Useful for little density of voxels. More...

#include <SparseContainer.hpp>

Public Types

using VoxelData = T_Voxel
 
using VoxelContainer = SparseContainer< T_Voxel, T_Container >
 
using iterator = container_iterator< VoxelContainer >
 

Public Member Functions

 SparseContainer ()=default
 Default constructor. More...
 
 SparseContainer (SparseContainer const &other)=default
 Default copy constructor. More...
 
void init (VoxelNode< VoxelContainer > const &)
 Initialization method, do nothing. More...
 
uint16_t getNbVoxel () const
 Returns number of voxels. More...
 
bool hasVoxel (uint8_t x) const
 Check if there is voxel inside. More...
 
bool hasVoxel (uint8_t x, uint8_t y) const
 Check if there is voxel inside. More...
 
bool hasVoxel (uint8_t x, uint8_t y, uint8_t z) const
 Check if voxel exist. More...
 
VoxelDatafindVoxel (uint8_t x, uint8_t y, uint8_t z)
 Find voxel. More...
 
VoxelData const * findVoxel (uint8_t x, uint8_t y, uint8_t z) const
 Find voxel. More...
 
template<typename Iterator >
VoxelDatafindVoxel (Iterator &it)
 Find voxel. More...
 
template<typename Iterator >
VoxelData const * findVoxel (Iterator &it) const
 Find voxel. More...
 
template<typename Iterator , typename... Args>
bool addVoxel (Iterator &it, Args &&... args)
 Add a voxel, don't update an existing voxel. More...
 
template<typename Iterator , typename... Args>
bool updateVoxel (Iterator &it, Args &&... args)
 Update an existing voxel, don't create a new one. More...
 
template<typename Iterator , typename... Args>
void putVoxel (Iterator &it, Args &&... args)
 Add or update a voxel. More...
 
template<typename Iterator >
bool removeVoxel (Iterator const &it, VoxelData *voxel=nullptr)
 Remove an existing voxel. More...
 
template<typename Iterator >
void exploreVoxel (Iterator &it, std::function< void(Iterator const &)> const &predicate) const
 Go through all voxels of the container and call the predicate for each. More...
 
void exploreVoxelContainer (std::function< void(SparseContainer const &)> const &predicate) const
 
void serialize (std::string &str) const
 Serialize the structure. More...
 
size_t unserialize (char const *str, size_t size)
 Unserialize str inside this. More...
 

Static Public Attributes

static const uint32_t NB_VOXELS = 8
 
static const uint32_t COORD_MASK = ~(NB_VOXELS - 1)
 
static const uint32_t VOXEL_MASK = NB_VOXELS - 1
 
static const uint32_t NB_SUPERCONTAINER = 0
 

Private Attributes

SparseIDArray< T_Voxel, NB_VOXELS, T_Container > _sparseArray
 

Detailed Description

template<class T_Voxel, template< class... > class T_Container = std::vector>
class voxomap::SparseContainer< T_Voxel, T_Container >

Voxel container used in leaves of the VoxelOctree. Mix between a fixed size 3D array (like in ArrayContainer) and a dynamic array. Useful for little density of voxels.

  • Advantages:
    • Good access/update performance (~= ArrayContainer)
    • Small memory footprint
  • Disadvantages:

The container uses 3 arrays:

  • A dynamic vector that contains the voxels
  • A fixed size array (like ArrayContainer) that contains the voxel id inside the above vector, 0 if there is no voxel
  • A dynamic vector that contains the unused voxel inside the first vector. Due to performance issue, the removed voxel are not removed from the first vector.

Definition at line 32 of file SparseContainer.hpp.

Member Typedef Documentation

◆ VoxelData

template<class T_Voxel , template< class... > class T_Container = std::vector>
using voxomap::SparseContainer< T_Voxel, T_Container >::VoxelData = T_Voxel

Definition at line 35 of file SparseContainer.hpp.

◆ VoxelContainer

template<class T_Voxel , template< class... > class T_Container = std::vector>
using voxomap::SparseContainer< T_Voxel, T_Container >::VoxelContainer = SparseContainer<T_Voxel, T_Container>

Definition at line 36 of file SparseContainer.hpp.

◆ iterator

template<class T_Voxel , template< class... > class T_Container = std::vector>
using voxomap::SparseContainer< T_Voxel, T_Container >::iterator = container_iterator<VoxelContainer>

Definition at line 37 of file SparseContainer.hpp.

Constructor & Destructor Documentation

◆ SparseContainer() [1/2]

template<class T_Voxel , template< class... > class T_Container = std::vector>
voxomap::SparseContainer< T_Voxel, T_Container >::SparseContainer ( )
default

Default constructor.

◆ SparseContainer() [2/2]

template<class T_Voxel , template< class... > class T_Container = std::vector>
voxomap::SparseContainer< T_Voxel, T_Container >::SparseContainer ( SparseContainer< T_Voxel, T_Container > const &  other)
default

Default copy constructor.

Member Function Documentation

◆ init()

template<class T_Voxel , template< class... > class T_Container = std::vector>
void voxomap::SparseContainer< T_Voxel, T_Container >::init ( VoxelNode< VoxelContainer > const &  )

Initialization method, do nothing.

Definition at line 56 of file SparseContainer.hpp.

◆ getNbVoxel()

template<class T_Voxel , template< class... > class T_Container = std::vector>
uint16_t voxomap::SparseContainer< T_Voxel, T_Container >::getNbVoxel ( ) const

Returns number of voxels.

◆ hasVoxel() [1/3]

template<class T_Voxel , template< class... > class T_Container = std::vector>
bool voxomap::SparseContainer< T_Voxel, T_Container >::hasVoxel ( uint8_t  x) const

Check if there is voxel inside.

Parameters
xX index
Returns
True if there is a voxel

◆ hasVoxel() [2/3]

template<class T_Voxel , template< class... > class T_Container = std::vector>
bool voxomap::SparseContainer< T_Voxel, T_Container >::hasVoxel ( uint8_t  x,
uint8_t  y 
) const

Check if there is voxel inside.

Parameters
xX index
yY index
Returns
True if there is a voxel

◆ hasVoxel() [3/3]

template<class T_Voxel , template< class... > class T_Container = std::vector>
bool voxomap::SparseContainer< T_Voxel, T_Container >::hasVoxel ( uint8_t  x,
uint8_t  y,
uint8_t  z 
) const

Check if voxel exist.

Parameters
xX index
yY index
zZ index
Returns
True if voxel exist

◆ findVoxel() [1/4]

template<class T_Voxel , template< class... > class T_Container = std::vector>
VoxelData* voxomap::SparseContainer< T_Voxel, T_Container >::findVoxel ( uint8_t  x,
uint8_t  y,
uint8_t  z 
)

Find voxel.

Parameters
xX index
yY index
zZ index
Returns
The voxel if exists, otherwise nullptr

◆ findVoxel() [2/4]

template<class T_Voxel , template< class... > class T_Container = std::vector>
VoxelData const* voxomap::SparseContainer< T_Voxel, T_Container >::findVoxel ( uint8_t  x,
uint8_t  y,
uint8_t  z 
) const

Find voxel.

Parameters
xX index
yY index
zZ index
Returns
The voxel if exists, otherwise nullptr

◆ findVoxel() [3/4]

template<class T_Voxel , template< class... > class T_Container = std::vector>
template<typename Iterator >
VoxelData* voxomap::SparseContainer< T_Voxel, T_Container >::findVoxel ( Iterator &  it)

Find voxel.

Parameters
itThe iterator
Returns
The voxel if exists, otherwise nullptr

◆ findVoxel() [4/4]

template<class T_Voxel , template< class... > class T_Container = std::vector>
template<typename Iterator >
VoxelData const* voxomap::SparseContainer< T_Voxel, T_Container >::findVoxel ( Iterator &  it) const

Find voxel.

Parameters
itThe iterator
Returns
The voxel if exists, otherwise nullptr

◆ addVoxel()

template<class T_Voxel , template< class... > class T_Container = std::vector>
template<typename Iterator , typename... Args>
bool voxomap::SparseContainer< T_Voxel, T_Container >::addVoxel ( Iterator &  it,
Args &&...  args 
)

Add a voxel, don't update an existing voxel.

Parameters
itIterator that contains the informations
argsArguments to forward to voxel constructor
Returns
True if success and update it

◆ updateVoxel()

template<class T_Voxel , template< class... > class T_Container = std::vector>
template<typename Iterator , typename... Args>
bool voxomap::SparseContainer< T_Voxel, T_Container >::updateVoxel ( Iterator &  it,
Args &&...  args 
)

Update an existing voxel, don't create a new one.

Parameters
itIterator that contains the informations
argsArguments to forward to voxel constructor
Returns
True if success

◆ putVoxel()

template<class T_Voxel , template< class... > class T_Container = std::vector>
template<typename Iterator , typename... Args>
void voxomap::SparseContainer< T_Voxel, T_Container >::putVoxel ( Iterator &  it,
Args &&...  args 
)

Add or update a voxel.

Parameters
itIterator that contains the informations
argsArguments to forward to voxel constructor

◆ removeVoxel()

template<class T_Voxel , template< class... > class T_Container = std::vector>
template<typename Iterator >
bool voxomap::SparseContainer< T_Voxel, T_Container >::removeVoxel ( Iterator const &  it,
VoxelData voxel = nullptr 
)

Remove an existing voxel.

Parameters
itIterator that contains the informations
voxelPointer on a voxel structure, filled with the data of the removed voxel
Returns
True if success

◆ exploreVoxel()

template<class T_Voxel , template< class... > class T_Container = std::vector>
template<typename Iterator >
void voxomap::SparseContainer< T_Voxel, T_Container >::exploreVoxel ( Iterator &  it,
std::function< void(Iterator const &)> const &  predicate 
) const

Go through all voxels of the container and call the predicate for each.

Parameters
itBegin iterator
predicateFunction called for each voxel found

◆ exploreVoxelContainer()

template<class T_Voxel , template< class... > class T_Container = std::vector>
void voxomap::SparseContainer< T_Voxel, T_Container >::exploreVoxelContainer ( std::function< void(SparseContainer< T_Voxel, T_Container > const &)> const &  predicate) const

◆ serialize()

template<class T_Voxel , template< class... > class T_Container = std::vector>
void voxomap::SparseContainer< T_Voxel, T_Container >::serialize ( std::string &  str) const

Serialize the structure.

Parameters
strString use for save the serialization

◆ unserialize()

template<class T_Voxel , template< class... > class T_Container = std::vector>
size_t voxomap::SparseContainer< T_Voxel, T_Container >::unserialize ( char const *  str,
size_t  size 
)

Unserialize str inside this.

Parameters
strString that contains data
sizeSize of the string
Returns
Number of bytes read inside str

Member Data Documentation

◆ NB_VOXELS

template<class T_Voxel , template< class... > class T_Container = std::vector>
const uint32_t voxomap::SparseContainer< T_Voxel, T_Container >::NB_VOXELS = 8
static

Definition at line 39 of file SparseContainer.hpp.

◆ COORD_MASK

template<class T_Voxel , template< class... > class T_Container = std::vector>
const uint32_t voxomap::SparseContainer< T_Voxel, T_Container >::COORD_MASK = ~(NB_VOXELS - 1)
static

Definition at line 40 of file SparseContainer.hpp.

◆ VOXEL_MASK

template<class T_Voxel , template< class... > class T_Container = std::vector>
const uint32_t voxomap::SparseContainer< T_Voxel, T_Container >::VOXEL_MASK = NB_VOXELS - 1
static

Definition at line 41 of file SparseContainer.hpp.

◆ NB_SUPERCONTAINER

template<class T_Voxel , template< class... > class T_Container = std::vector>
const uint32_t voxomap::SparseContainer< T_Voxel, T_Container >::NB_SUPERCONTAINER = 0
static

Definition at line 42 of file SparseContainer.hpp.

◆ _sparseArray

template<class T_Voxel , template< class... > class T_Container = std::vector>
SparseIDArray<T_Voxel, NB_VOXELS, T_Container> voxomap::SparseContainer< T_Voxel, T_Container >::_sparseArray
private

Definition at line 171 of file SparseContainer.hpp.


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