esp::geo::VoxelGrid class

Constructors, destructors, conversion operators

VoxelGrid(const Magnum::Vector3& voxelSize, const Magnum::Vector3i& voxelGridDimensions)
Generates an empty voxel grid given some voxel size and voxel dimensions..

Public functions

template<typename T>
auto voxelGridTypeFor() -> VoxelGridType
Gets the enumerated type of a particular voxel grid type.
auto getGridType(const std::string& gridName) -> VoxelGridType
Returns the type of the specified voxel grid.
template<typename T>
void addGrid(const std::string& gridName)
Generates a new empty voxel grid of a specified type.
auto getExistingGrids() -> std::vector<std::pair<std::string, VoxelGridType>>
Returns a list of existing voxel grids and their types.
auto gridExists(const std::string& gridName) -> bool
Returns a bool true if a grid exists, false otherwise.
void removeGrid(const std::string& gridName)
Removes a grid and frees up memory.
template<typename T>
auto getGrid(const std::string& gridName) -> Corrade::Containers::StridedArrayView3D<T>
Returns a StridedArrayView3D of a grid for easy index access and manipulation.
auto isValidIndex(const Mn::Vector3i& coords) const -> bool
Checks to see if a given 3D voxel index is valid and does not go out of bounds.
template<typename T>
void setVoxel(const Magnum::Vector3i& index, const std::string& gridName, const T& value)
Sets a voxel at a specified index for a specified grid to a value.
template<typename T>
auto getVoxel(const Magnum::Vector3i& index, const std::string& gridName) -> T
Retrieves the voxel value from a grid of a specified type (bool, int, float, Magnum::Vector3).
auto getVoxelGridDimensions() -> Magnum::Vector3i
Returns the dimensions of the voxel grid.
auto getVoxelSize() -> Magnum::Vector3
Returns the size of a voxel.
auto gridSize() -> int
Gets the length of the voxel grid.
auto getOffset() -> Magnum::Vector3
Returns the bounding box minimum offset used for generating an aligned mesh.
auto getMaxOffset() -> Magnum::Vector3
Returns the bounding box maximum offset used for generating an aligned mesh.
auto getMeshData(const std::string& gridName = "Boundary") -> std::shared_ptr<Magnum::Trade::MeshData>
Retrieves the MeshData for a particular voxelGrid. If it does not exist, it will generate the mesh for that grid.
auto getMeshGL(const std::string& gridName = "Boundary") -> Magnum::GL::Mesh&
Retrieves the MeshGL used for rendering for a particular voxelGrid. If it does not exist, it will generate the mesh for that grid.
auto getGlobalCoords(const Magnum::Vector3i& coords) -> Magnum::Vector3
Converts a voxel index into global coords by applying the offset and multiplying by the real voxel size. Does not apply any transformation made to the object the voxle grid is a part of.
void setOffset(const Magnum::Vector3& coords)
Sets the offset of the voxel grid.
void generateMesh(const std::string& gridName = "Boundary")
Generates both a MeshData and MeshGL for a particular voxelGrid.
template<typename T>
void generateSliceMesh(const std::string& gridName = "Boundary", int ind = 0, T minVal = 0, T maxVal = 1)
Generates a colored slice of a mesh.

Protected functions

void fillBoolGridNeighborhood(std::vector<bool>& neighbors, const std::string& gridName, const Magnum::Vector3i& index)
Fills vector neighbors with 6 booleans representing the top (y+1), bottom (x+1), right (y+1), left (y-1), back (z-1) and front (x-1) neighboring voxel's status.
void generateMeshDataAndMeshGL(const std::string& gridName, Corrade::Containers::Array<VoxelVertex>& vertexData, Corrade::Containers::Array<Mn::UnsignedInt>& indexData)
Generates the Magnum MeshData and MeshGL given indices, positions, normals, and colors.
void addVoxelToMeshPrimitives(Corrade::Containers::Array<VoxelVertex>& vertexData, Corrade::Containers::Array<Mn::UnsignedInt>& indexData, const Magnum::Vector3i& localCoords, const std::vector<bool>& neighbors, const Magnum::Color3& color = Magnum::Color3(.4,.8, 1))
Helper function for generate mesh. Adds a cube voxel to a mesh.
void addVectorToMeshPrimitives(Corrade::Containers::Array<VoxelVertex>& vertexData, Corrade::Containers::Array<Mn::UnsignedInt>& indexData, const Magnum::Vector3i& localCoords, const Magnum::Vector3& vec)
Helper function for generate mesh. Adds a vector voxel to a mesh which points in a specified direction.

Function documentation

esp::geo::VoxelGrid::VoxelGrid(const Magnum::Vector3& voxelSize, const Magnum::Vector3i& voxelGridDimensions)

Generates an empty voxel grid given some voxel size and voxel dimensions..

Parameters
voxelSize The size of a single voxel
voxelGridDimensions The dimensions of the voxel grid.

template<typename T>
VoxelGridType esp::geo::VoxelGrid::voxelGridTypeFor()

Gets the enumerated type of a particular voxel grid type.

Returns The enumerated type.

VoxelGridType esp::geo::VoxelGrid::getGridType(const std::string& gridName)

Returns the type of the specified voxel grid.

Parameters
gridName The name of the grid.
Returns The enumerated type.

template<typename T>
void esp::geo::VoxelGrid::addGrid(const std::string& gridName)

Generates a new empty voxel grid of a specified type.

Parameters
gridName The key under which the grid will be registered and accessed.

std::vector<std::pair<std::string, VoxelGridType>> esp::geo::VoxelGrid::getExistingGrids()

Returns a list of existing voxel grids and their types.

Returns A vector of pairs, where the first element is the voxel grid's name, and the second element is the string of the object's type.

bool esp::geo::VoxelGrid::gridExists(const std::string& gridName)

Returns a bool true if a grid exists, false otherwise.

Parameters
gridName The name of the grid.
Returns A bool representing whether or not the specified grid exists.

void esp::geo::VoxelGrid::removeGrid(const std::string& gridName)

Removes a grid and frees up memory.

Parameters
gridName The name of the grid to be removed.

template<typename T>
Corrade::Containers::StridedArrayView3D<T> esp::geo::VoxelGrid::getGrid(const std::string& gridName)

Returns a StridedArrayView3D of a grid for easy index access and manipulation.

Parameters
gridName The name of the grid to be retrieved.
Returns A StridedArrayView3D of the specified grid.

bool esp::geo::VoxelGrid::isValidIndex(const Mn::Vector3i& coords) const

Checks to see if a given 3D voxel index is valid and does not go out of bounds.

Parameters
coords The voxel index.
Returns True if the voxel index is valid, false otherwise.

template<typename T>
void esp::geo::VoxelGrid::setVoxel(const Magnum::Vector3i& index, const std::string& gridName, const T& value)

Sets a voxel at a specified index for a specified grid to a value.

Parameters
index The index of the voxel
gridName The voxel grid.
value The new value.

template<typename T>
T esp::geo::VoxelGrid::getVoxel(const Magnum::Vector3i& index, const std::string& gridName)

Retrieves the voxel value from a grid of a specified type (bool, int, float, Magnum::Vector3).

Parameters
index The index of the voxel
gridName The voxel grid.
Returns The value from the specified voxel grid.

Magnum::Vector3i esp::geo::VoxelGrid::getVoxelGridDimensions()

Returns the dimensions of the voxel grid.

Returns The Vector3i value representing the dimensions.

Magnum::Vector3 esp::geo::VoxelGrid::getVoxelSize()

Returns the size of a voxel.

Returns The Vector3 value representing the size of a voxel.

int esp::geo::VoxelGrid::gridSize()

Gets the length of the voxel grid.

Returns The length of the 1 dimensional array voxel grid.

Magnum::Vector3 esp::geo::VoxelGrid::getOffset()

Returns the bounding box minimum offset used for generating an aligned mesh.

Returns The Vector3 value representing the offset.

Magnum::Vector3 esp::geo::VoxelGrid::getMaxOffset()

Returns the bounding box maximum offset used for generating an aligned mesh.

Returns The Vector3 value representing the offset.

std::shared_ptr<Magnum::Trade::MeshData> esp::geo::VoxelGrid::getMeshData(const std::string& gridName = "Boundary")

Retrieves the MeshData for a particular voxelGrid. If it does not exist, it will generate the mesh for that grid.

Parameters
gridName The key underwhich the desired voxel grid is registered.
Returns A shared pointer to the MeshData.

Magnum::GL::Mesh& esp::geo::VoxelGrid::getMeshGL(const std::string& gridName = "Boundary")

Retrieves the MeshGL used for rendering for a particular voxelGrid. If it does not exist, it will generate the mesh for that grid.

Parameters
gridName The key underwhich the desired voxel grid is registered.
Returns A reference to the MeshGL.

Magnum::Vector3 esp::geo::VoxelGrid::getGlobalCoords(const Magnum::Vector3i& coords)

Converts a voxel index into global coords by applying the offset and multiplying by the real voxel size. Does not apply any transformation made to the object the voxle grid is a part of.

Parameters
coords The voxel index to be converted.
Returns A Vector3 value representing the global coordinates of the voxel index.

void esp::geo::VoxelGrid::setOffset(const Magnum::Vector3& coords)

Sets the offset of the voxel grid.

Parameters
coords The new offset.

void esp::geo::VoxelGrid::generateMesh(const std::string& gridName = "Boundary")

Generates both a MeshData and MeshGL for a particular voxelGrid.

Parameters
gridName The name of the voxel grid to be converted into a mesh.

template<typename T>
void esp::geo::VoxelGrid::generateSliceMesh(const std::string& gridName = "Boundary", int ind = 0, T minVal = 0, T maxVal = 1)

Generates a colored slice of a mesh.

Parameters
gridName The name of the voxel grid to be converted into a mesh slice.
ind The index value the x axis for the slicing plane.
minVal The minimum value of the grid. Used for determining heatmap colors.
maxVal The maximum value of the grid. Used for determining heatmap colors.

void esp::geo::VoxelGrid::fillBoolGridNeighborhood(std::vector<bool>& neighbors, const std::string& gridName, const Magnum::Vector3i& index) protected

Fills vector neighbors with 6 booleans representing the top (y+1), bottom (x+1), right (y+1), left (y-1), back (z-1) and front (x-1) neighboring voxel's status.

Parameters
neighbors in The vector of booleans to be filled.
gridName The name of the boolean grid to be checked.
index The index of the voxel.

void esp::geo::VoxelGrid::generateMeshDataAndMeshGL(const std::string& gridName, Corrade::Containers::Array<VoxelVertex>& vertexData, Corrade::Containers::Array<Mn::UnsignedInt>& indexData) protected

Generates the Magnum MeshData and MeshGL given indices, positions, normals, and colors.

Parameters
gridName The grid name corresponding to the mesh's grid.
vertexData A Corrade Array of VoxelVertex which each contain a vertex's position, normal, and color
indexData A Corrade Array of indicies for the faces on the mesh.

void esp::geo::VoxelGrid::addVoxelToMeshPrimitives(Corrade::Containers::Array<VoxelVertex>& vertexData, Corrade::Containers::Array<Mn::UnsignedInt>& indexData, const Magnum::Vector3i& localCoords, const std::vector<bool>& neighbors, const Magnum::Color3& color = Magnum::Color3(.4,.8, 1)) protected

Helper function for generate mesh. Adds a cube voxel to a mesh.

Parameters
vertexData A Corrade Array of VoxelVertex which each contain a vertex's position, normal, and color
indexData A Corrade Array of indicies for the faces on the mesh.
localCoords A voxel index specifying the location of the voxel.
neighbors A boolean with 6 booleans representing whether the voxel on the top (y+1), bottom (x+1), right (y+1), left (y-1), back (z-1) and front (x-1) are filled.
color A Magnum::Color3 object specifying the color for a particular voxel. Used primarily for generating the heatmap slices.

void esp::geo::VoxelGrid::addVectorToMeshPrimitives(Corrade::Containers::Array<VoxelVertex>& vertexData, Corrade::Containers::Array<Mn::UnsignedInt>& indexData, const Magnum::Vector3i& localCoords, const Magnum::Vector3& vec) protected

Helper function for generate mesh. Adds a vector voxel to a mesh which points in a specified direction.

Parameters
vertexData A Corrade Array of VoxelVertex which each contain a vertex's position, normal, and color
indexData A Corrade Array of indicies for the faces on the mesh.
localCoords A voxel index specifying the location of the voxel.
vec The vector to be converted into a mesh.