Template Class Block

Class Documentation

template <typename VoxelType>
class Block

An nxnxn container holding VoxelType.

It is aware of its 3D position and contains functions for accessing voxels by position and index

Public Types

typedef std::shared_ptr<Block<VoxelType>> Ptr
typedef std::shared_ptr<const Block<VoxelType>> ConstPtr

Public Functions

Block(size_t voxels_per_side, FloatingPoint voxel_size, const Point &origin)
Block(const BlockProto &proto)
~Block()
size_t computeLinearIndexFromVoxelIndex(const VoxelIndex &index) const
VoxelIndex computeTruncatedVoxelIndexFromCoordinates(const Point &coords) const

NOTE: This function is dangerous, it will truncate the voxel index to an index that is within this block if you pass a coordinate outside the range of this block.

Try not to use this function if there is an alternative to directly address the voxels via precise integer indexing math.

VoxelIndex computeVoxelIndexFromCoordinates(const Point &coords) const

NOTE: This function is also dangerous, use in combination with Block::isValidVoxelIndex function.

This function doesn’t truncate the voxel index to the [0, voxels_per_side] range when the coordinate is outside the range of this block, unlike the function above.

size_t computeLinearIndexFromCoordinates(const Point &coords) const

NOTE: This function is dangerous, it will truncate the voxel index to an index that is within this block if you pass a coordinate outside the range of this block.

Try not to use this function if there is an alternative to directly address the voxels via precise integer indexing math.

Point computeCoordinatesFromLinearIndex(size_t linear_index) const

Returns the CENTER point of the voxel.

Point computeCoordinatesFromVoxelIndex(const VoxelIndex &index) const

Returns the CENTER point of the voxel.

VoxelIndex computeVoxelIndexFromLinearIndex(size_t linear_index) const
const VoxelType &getVoxelByLinearIndex(size_t index) const

Accessors to actual blocks.

const VoxelType &getVoxelByVoxelIndex(const VoxelIndex &index) const
const VoxelType &getVoxelByCoordinates(const Point &coords) const

NOTE: This functions is dangerous, it will truncate the voxel index to an index that is within this block if you pass a coordinate outside the range of this block.

Try not to use this function if there is an alternative to directly address the voxels via precise integer indexing math.

VoxelType &getVoxelByCoordinates(const Point &coords)

NOTE: This functions is dangerous, it will truncate the voxel index to an index that is within this block if you pass a coordinate outside the range of this block.

Try not to use this function if there is an alternative to directly address the voxels via precise integer indexing math.

VoxelType *getVoxelPtrByCoordinates(const Point &coords)

NOTE: This functions is dangerous, it will truncate the voxel index to an index that is within this block if you pass a coordinate outside the range of this block.

Try not to use this function if there is an alternative to directly address the voxels via precise integer indexing math.

const VoxelType *getVoxelPtrByCoordinates(const Point &coords) const
VoxelType &getVoxelByLinearIndex(size_t index)
VoxelType &getVoxelByVoxelIndex(const VoxelIndex &index)
bool isValidVoxelIndex(const VoxelIndex &index) const
bool isValidLinearIndex(size_t index) const
BlockIndex block_index() const
size_t voxels_per_side() const
FloatingPoint voxel_size() const
FloatingPoint voxel_size_inv() const
size_t num_voxels() const
Point origin() const
void setOrigin(const Point &new_origin)
FloatingPoint block_size() const
bool has_data() const
bool updated() const
std::atomic<bool> &updated()
bool &has_data()
void set_updated(bool updated)
void set_has_data(bool has_data)
void getProto(BlockProto *proto) const
void serializeToIntegers(std::vector<uint32_t> *data) const
void deserializeFromIntegers(const std::vector<uint32_t> &data)
void mergeBlock(const Block<VoxelType> &other_block)
size_t getMemorySize() const

Protected Attributes

std::unique_ptr<VoxelType[]> voxels_
size_t num_voxels_
bool has_data_

Is set to true if any one of the voxels in this block received an update.