Template Class VoxelGrid

Nested Relationships

Nested Types

Class Documentation

template<typename DataT>
class VoxelGrid

Public Types

using LeafGrid = Grid<DataT>
using InnerGrid = Grid<std::shared_ptr<LeafGrid>>
using RootMap = std::unordered_map<CoordT, InnerGrid>

Public Functions

inline explicit VoxelGrid(double voxel_size, uint8_t inner_bits = 2, uint8_t leaf_bits = 3)

VoxelGrid constructor.

Parameters:

voxel_size – dimension of the voxel. Used to convert between Point3D and CoordT

VoxelGrid(const VoxelGrid&) = delete
VoxelGrid &operator=(const VoxelGrid&) = delete
VoxelGrid(VoxelGrid &&other) = default
VoxelGrid &operator=(VoxelGrid &&other) = default
inline uint32_t innetBits() const
inline uint32_t leafBits() const
inline double voxelSize() const
inline const RootMap &rootMap() const
inline RootMap &rootMap()
inline size_t memUsage() const

getMemoryUsage returns the amount of bytes used by this data structure

inline void releaseUnusedMemory()

Try freeing memory; this will discard grids where all the cells are OFF. Note that the memory release is NOT guaranteed, since we are using a memory pool too. CAREFULL: This will invalidate all the existing Accessors (you need to create new ones).

inline size_t activeCellsCount() const

Return the total number of active cells.

inline CoordT posToCoord(double x, double y, double z) const

posToCoord is used to convert real coordinates to CoordT indices.

inline CoordT posToCoord(const Point3D &pos) const

posToCoord is used to convert real coordinates to CoordT indices.

inline Point3D coordToPos(const CoordT &coord) const

coordToPos converts CoordT indices to Point3D.

template<class VisitorFunction>
inline void forEachCell(VisitorFunction func) const

forEachCell apply a function of type:

void(const DataT&, const CoordT&)
to each active element of the grid.

template<class VisitorFunction>
inline void forEachCell(VisitorFunction func)

forEachCell apply a function of type:

void(DataT&, const CoordT&)
to each active element of the grid.

inline void clear(ClearOption opt)
inline std::shared_ptr<LeafGrid> allocateLeafGrid()
inline Accessor createAccessor()
inline ConstAccessor createConstAccessor() const
inline CoordT getRootKey(const CoordT &coord) const
inline CoordT getInnerKey(const CoordT &coord) const
inline uint32_t getInnerIndex(const CoordT &coord) const
inline uint32_t getLeafIndex(const CoordT &coord) const
class Accessor : public Bonxai::VoxelGrid<DataT>::ConstAccessor

Class to be used to set and get values of a cell of the Grid. It uses caching to speed up computation.

Create an instance of this object with the method VoxelGrid::createAccessor()

Public Functions

inline Accessor(VoxelGrid &grid)
inline bool setValue(const CoordT &coord, const DataT &value)

setValue of a cell. If the cell did not exist, it is created.

Parameters:
  • coord – coordinate of the cell

  • value – value to set.

Returns:

the previous state of the cell (ON = true).

inline DataT *value(const CoordT &coord, bool create_if_missing = false)

value getter.

Parameters:

coord – coordinate of the cell.

Returns:

return the pointer to the value or nullptr if not set.

inline bool setCellOn(const CoordT &coord, const DataT &default_value = DataT())

setCellOn is similar to setValue, but the value is changed only if the cell has been created, otherwise, the previous value is used.

Parameters:
  • coord – coordinate of the cell.

  • default_value – default value of the cell. Use only if the cell did not exist before.

Returns:

the previous state of the cell (ON = true).

inline bool setCellOff(const CoordT &coord)

setCellOff will disable a cell without deleting its content.

Parameters:

coord – coordinate of the cell.

Returns:

the previous state of the cell (ON = true).

inline LeafGrid *getLeafGrid(const CoordT &coord, bool create_if_missing = false)

getLeafGrid gets the pointer to the LeafGrid containing the cell. It is the basic class used by setValue() and value().

Parameters:
  • coord – Coordinate of the cell.

  • create_if_missing – if true, create the Root, Inner and Leaf, if not present.

class ConstAccessor

Subclassed by Bonxai::VoxelGrid< DataT >::Accessor

Public Functions

inline ConstAccessor(const VoxelGrid &grid)
inline const DataT *value(const CoordT &coord) const

value getter.

Parameters:

coord – coordinate of the cell.

Returns:

return the pointer to the value or nullptr if not set.

inline bool isCellOn(const CoordT &coord) const

isCellOn only check if a cell is in “On” state

Parameters:

coordinate – of the cell.

inline const InnerGrid *lastInnerGrid() const

lastInnerGrid returns the pointer to the InnerGrid in the cache.

inline const LeafGrid *lastLeafGrid() const

lastLeafGrid returns the pointer to the LeafGrid in the cache.

inline const LeafGrid *getLeafGrid(const CoordT &coord) const

Protected Attributes

const VoxelGrid &grid_
mutable CoordT prev_root_coord_ = {std::numeric_limits<int32_t>::max(), 0, 0}
mutable CoordT prev_inner_coord_ = {std::numeric_limits<int32_t>::max(), 0, 0}
mutable const InnerGrid *prev_inner_ptr_ = nullptr
mutable const LeafGrid *prev_leaf_ptr_ = nullptr