ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::t::geometry::VoxelBlockGrid Class Reference

#include <VoxelBlockGrid.h>

Public Member Functions

 VoxelBlockGrid ()=default
 
 VoxelBlockGrid (const std::vector< std::string > &attr_names, const std::vector< core::Dtype > &attr_dtypes, const std::vector< core::SizeVector > &attr_channels, float voxel_size=0.0058, int64_t block_resolution=16, int64_t block_count=10000, const core::Device &device=core::Device("CPU:0"), const core::HashBackendType &backend=core::HashBackendType::Default)
 Default Constructor. Example: VoxelBlockGrid({"tsdf", "weight", "color"}, {core::Float32, core::UInt16, core::UInt16}, {{1}, {1}, {3}}, 0.005, 16, 10000, core::Device("CUDA:0"), core::HashBackendType::Default);. More...
 
core::HashMap GetHashMap ()
 
core::Tensor GetAttribute (const std::string &attr_name) const
 
core::Tensor GetVoxelIndices (const core::Tensor &buf_indices) const
 
core::Tensor GetVoxelIndices () const
 Get all active voxel indices. More...
 
core::Tensor GetVoxelCoordinates (const core::Tensor &voxel_indices) const
 
std::pair< core::Tensor, core::TensorGetVoxelCoordinatesAndFlattenedIndices (const core::Tensor &buf_indices)
 
std::pair< core::Tensor, core::TensorGetVoxelCoordinatesAndFlattenedIndices ()
 
core::Tensor GetUniqueBlockCoordinates (const Image &depth, const core::Tensor &intrinsic, const core::Tensor &extrinsic, float depth_scale=1000.0f, float depth_max=3.0f, float trunc_voxel_multiplier=8.0)
 
core::Tensor GetUniqueBlockCoordinates (const PointCloud &pcd, float trunc_voxel_multiplier=8.0)
 Obtain active block coordinates from a point cloud. More...
 
void Integrate (const core::Tensor &block_coords, const Image &depth, const Image &color, const core::Tensor &depth_intrinsic, const core::Tensor &color_intrinsic, const core::Tensor &extrinsic, float depth_scale=1000.0f, float depth_max=3.0f, float trunc_voxel_multiplier=8.0f)
 
void Integrate (const core::Tensor &block_coords, const Image &depth, const Image &color, const core::Tensor &intrinsic, const core::Tensor &extrinsic, float depth_scale=1000.0f, float depth_max=3.0f, float trunc_voxel_multiplier=8.0f)
 
void Integrate (const core::Tensor &block_coords, const Image &depth, const core::Tensor &intrinsic, const core::Tensor &extrinsic, float depth_scale=1000.0f, float depth_max=3.0f, float trunc_voxel_multiplier=8.0f)
 
TensorMap RayCast (const core::Tensor &block_coords, const core::Tensor &intrinsic, const core::Tensor &extrinsic, int width, int height, const std::vector< std::string > attrs={"depth", "color"}, float depth_scale=1000.0f, float depth_min=0.1f, float depth_max=3.0f, float weight_threshold=3.0f, float trunc_voxel_multiplier=8.0f, int range_map_down_factor=8)
 
PointCloud ExtractPointCloud (float weight_threshold=3.0f, int estimated_point_number=-1)
 
TriangleMesh ExtractTriangleMesh (float weight_threshold=3.0f, int estimated_vertex_numer=-1)
 
void Save (const std::string &file_name) const
 Save a voxel block grid to a .npz file. More...
 
VoxelBlockGrid To (const core::Device &device, bool copy=false) const
 Convert the hash map to another device. More...
 

Static Public Member Functions

static VoxelBlockGrid Load (const std::string &file_name)
 Load a voxel block grid from a .npz file. More...
 

Detailed Description

A voxel block grid is a sparse grid of voxel blocks. Each voxel block is a dense 3D array, preserving local data distribution. If the block_resolution is set to 1, then the VoxelBlockGrid degenerates to a sparse voxel grid.

Definition at line 26 of file VoxelBlockGrid.h.

Constructor & Destructor Documentation

◆ VoxelBlockGrid() [1/2]

cloudViewer::t::geometry::VoxelBlockGrid::VoxelBlockGrid ( )
default

Referenced by To().

◆ VoxelBlockGrid() [2/2]

cloudViewer::t::geometry::VoxelBlockGrid::VoxelBlockGrid ( const std::vector< std::string > &  attr_names,
const std::vector< core::Dtype > &  attr_dtypes,
const std::vector< core::SizeVector > &  attr_channels,
float  voxel_size = 0.0058,
int64_t  block_resolution = 16,
int64_t  block_count = 10000,
const core::Device device = core::Device("CPU:0"),
const core::HashBackendType backend = core::HashBackendType::Default 
)

Member Function Documentation

◆ ExtractPointCloud()

PointCloud cloudViewer::t::geometry::VoxelBlockGrid::ExtractPointCloud ( float  weight_threshold = 3.0f,
int  estimated_point_number = -1 
)

Specific operation for TSDF volumes. Extract point cloud at isosurface points. Weight threshold is used to filter outliers. By default we use 3.0, where we assume a reliable surface point comes from the fusion of at least 3 viewpoints. Use as low as 0.0 to accept all the possible observations. Estimated point numbers optionally speeds up the process by a one-pass extraction with pre-allocated buffers. Use -1 when no estimate is available.

Definition at line 405 of file VoxelBlockGrid.cpp.

References cloudViewer::t::geometry::BufferRadiusNeighbors(), colors, cloudViewer::t::geometry::ConstructTensorMap(), cloudViewer::t::geometry::kernel::voxel_grid::ExtractPointCloud(), normals, and points.

Referenced by cloudViewer::t::pipelines::slam::Model::ExtractPointCloud().

◆ ExtractTriangleMesh()

TriangleMesh cloudViewer::t::geometry::VoxelBlockGrid::ExtractTriangleMesh ( float  weight_threshold = 3.0f,
int  estimated_vertex_numer = -1 
)

Specific operation for TSDF volumes. Extract mesh near iso-surfaces with Marching Cubes. Weight threshold is used to filter outliers. By default we use 3.0, where we assume a reliable surface point comes from the fusion of at least 3 viewpoints. Use as low as 0.0 to accept all the possible observations. Estimated point numbers optionally speeds up the process by a one-pass extraction with pre-allocated buffers. Use -1 when no estimate is available.

Definition at line 437 of file VoxelBlockGrid.cpp.

References cloudViewer::core::Tensor::Arange(), cloudViewer::t::geometry::BufferRadiusNeighbors(), cloudViewer::t::geometry::ConstructTensorMap(), cloudViewer::t::geometry::kernel::voxel_grid::ExtractTriangleMesh(), cloudViewer::core::Tensor::GetLength(), cloudViewer::core::Int32, cloudViewer::core::Int64, cloudViewer::t::geometry::TriangleMesh::SetVertexColors(), cloudViewer::t::geometry::TriangleMesh::SetVertexNormals(), and cloudViewer::core::Tensor::To().

Referenced by cloudViewer::t::pipelines::slam::Model::ExtractTriangleMesh().

◆ GetAttribute()

core::Tensor cloudViewer::t::geometry::VoxelBlockGrid::GetAttribute ( const std::string &  attr_name) const

Get the attribute tensor corresponding to the attribute name. A sugar for hashmap.GetValueTensor(i)

Definition at line 120 of file VoxelBlockGrid.cpp.

References LogWarning.

◆ GetHashMap()

core::HashMap cloudViewer::t::geometry::VoxelBlockGrid::GetHashMap ( )
inline

Get the underlying hash map that stores values in structure of arrays (SoA).

Definition at line 52 of file VoxelBlockGrid.h.

Referenced by cloudViewer::t::pipelines::slam::Model::GetHashMap().

◆ GetUniqueBlockCoordinates() [1/2]

core::Tensor cloudViewer::t::geometry::VoxelBlockGrid::GetUniqueBlockCoordinates ( const Image depth,
const core::Tensor intrinsic,
const core::Tensor extrinsic,
float  depth_scale = 1000.0f,
float  depth_max = 3.0f,
float  trunc_voxel_multiplier = 8.0 
)

Get a (3, M) active block coordinates from a depth image, with potential duplicates removed. Note: these coordinates are not activated in the internal sparse voxel block. They need to be inserted in the hash map.

Definition at line 213 of file VoxelBlockGrid.cpp.

References cloudViewer::t::geometry::Image::AsTensor(), cloudViewer::t::geometry::CheckDepthTensor(), cloudViewer::t::geometry::CheckExtrinsicTensor(), cloudViewer::t::geometry::CheckIntrinsicTensor(), cloudViewer::t::geometry::kernel::voxel_grid::DepthTouch(), cloudViewer::t::geometry::Image::GetCols(), cloudViewer::t::geometry::Image::GetRows(), and cloudViewer::core::Int32.

Referenced by cloudViewer::t::pipelines::slam::Model::Integrate().

◆ GetUniqueBlockCoordinates() [2/2]

core::Tensor cloudViewer::t::geometry::VoxelBlockGrid::GetUniqueBlockCoordinates ( const PointCloud pcd,
float  trunc_voxel_multiplier = 8.0 
)

◆ GetVoxelCoordinates()

core::Tensor cloudViewer::t::geometry::VoxelBlockGrid::GetVoxelCoordinates ( const core::Tensor voxel_indices) const

Get a (3, hashmap.Size() * resolution^3) coordinate tensor of active voxels per block, used for geometry transformation jointly with indices from GetVoxelIndices.

Example: For a voxel block grid with (2, 2, 2) block resolution, if the active block coordinates are {(-1, 3, 2), (0, 2, 4)}, the returned result will be a (3, 2 x 8) tensor given by: { key_tensor[voxel_indices[0]] * block_resolution_ + voxel_indices[1] key_tensor[voxel_indices[0]] * block_resolution_ + voxel_indices[2] key_tensor[voxel_indices[0]] * block_resolution_ + voxel_indices[3] } Note: the coordinates are VOXEL COORDINATES in Int64. To access metric coordinates, multiply by voxel size.

Definition at line 131 of file VoxelBlockGrid.cpp.

References cloudViewer::core::Tensor::IndexGet(), cloudViewer::core::Int64, and cloudViewer::core::Tensor::To().

◆ GetVoxelCoordinatesAndFlattenedIndices() [1/2]

std::pair< core::Tensor, core::Tensor > cloudViewer::t::geometry::VoxelBlockGrid::GetVoxelCoordinatesAndFlattenedIndices ( )

Same as above, but N is the number of all the active voxels with blocks stored in the hash map.

Definition at line 187 of file VoxelBlockGrid.cpp.

◆ GetVoxelCoordinatesAndFlattenedIndices() [2/2]

std::pair< core::Tensor, core::Tensor > cloudViewer::t::geometry::VoxelBlockGrid::GetVoxelCoordinatesAndFlattenedIndices ( const core::Tensor buf_indices)

Accelerated combination of GetVoxelIndices and GetVoxelCoordinates. Returns a (N, 3) coordinate in float, and a (N, ) flattened index tensor, where N is the number of active voxels located at buf_indices.

Definition at line 194 of file VoxelBlockGrid.cpp.

References cloudViewer::core::Float32, cloudViewer::core::Tensor::GetLength(), cloudViewer::t::geometry::kernel::voxel_grid::GetVoxelCoordinatesAndFlattenedIndices(), cloudViewer::core::Int64, and cloudViewer::core::make_pair().

◆ GetVoxelIndices() [1/2]

core::Tensor cloudViewer::t::geometry::VoxelBlockGrid::GetVoxelIndices ( ) const

Get all active voxel indices.

Definition at line 181 of file VoxelBlockGrid.cpp.

◆ GetVoxelIndices() [2/2]

core::Tensor cloudViewer::t::geometry::VoxelBlockGrid::GetVoxelIndices ( const core::Tensor buf_indices) const

Get a (4, N), Int64 index tensor for active voxels, used for advanced indexing. Returned index tensor can access selected value buffers in order of (buf_index, index_voxel_x, index_voxel_y, index_voxel_z).

Example: For a voxel block grid with (2, 2, 2) block resolution, if the active block coordinates are at buffer index {(2, 4)} given by GetActiveIndices() from the underlying hash map, the returned result will be a (4, 2 x 8) tensor: { (2, 0, 0, 0), (2, 1, 0, 0), (2, 0, 1, 0), (2, 1, 1, 0), (2, 0, 0, 1), (2, 1, 0, 1), (2, 0, 1, 1), (2, 1, 1, 1), (4, 0, 0, 0), (4, 1, 0, 0), (4, 0, 1, 0), (4, 1, 1, 0), (4, 0, 0, 1), (4, 1, 0, 1), (4, 0, 1, 1), (4, 1, 1, 1), } Note: the slicing order is z-y-x.

TODO: Check if kernel version is necessary.

operator % is not supported now

Definition at line 146 of file VoxelBlockGrid.cpp.

References cloudViewer::core::Tensor::Arange(), cloudViewer::core::Tensor::GetLength(), cloudViewer::core::Tensor::IndexGet(), cloudViewer::core::Int64, cloudViewer::core::Dtype::Int64, and To().

◆ Integrate() [1/3]

void cloudViewer::t::geometry::VoxelBlockGrid::Integrate ( const core::Tensor block_coords,
const Image depth,
const core::Tensor intrinsic,
const core::Tensor extrinsic,
float  depth_scale = 1000.0f,
float  depth_max = 3.0f,
float  trunc_voxel_multiplier = 8.0f 
)

Specific operation for TSDF volumes. Similar to RGB-D integration, but only applied to depth.

Definition at line 270 of file VoxelBlockGrid.cpp.

References Integrate().

◆ Integrate() [2/3]

void cloudViewer::t::geometry::VoxelBlockGrid::Integrate ( const core::Tensor block_coords,
const Image depth,
const Image color,
const core::Tensor depth_intrinsic,
const core::Tensor color_intrinsic,
const core::Tensor extrinsic,
float  depth_scale = 1000.0f,
float  depth_max = 3.0f,
float  trunc_voxel_multiplier = 8.0f 
)

Specific operation for TSDF volumes. Integrate an RGB-D frame in the selected block coordinates using pinhole camera model. For built-in kernels, we support efficient hash map types for SLAM: tsdf: float, weight: uint16_t, color: uint16_t and accurate mode for differentiable rendering: tsdf/weight/color: float We assume input data are either raw: depth: uint16_t, color: uint8_t or depth/color: float. To support other types and properties, users should combine GetUniqueBlockCoordinates, GetVoxelIndices, and GetVoxelCoordinates, with self-defined operations.

Definition at line 293 of file VoxelBlockGrid.cpp.

References cloudViewer::t::geometry::Image::AsTensor(), cloudViewer::t::geometry::CheckBlockCoordinates(), cloudViewer::t::geometry::CheckColorTensor(), cloudViewer::t::geometry::CheckDepthTensor(), cloudViewer::t::geometry::CheckExtrinsicTensor(), cloudViewer::t::geometry::CheckIntrinsicTensor(), color, cloudViewer::t::geometry::ConstructTensorMap(), and cloudViewer::t::geometry::kernel::voxel_grid::Integrate().

Referenced by Integrate(), and cloudViewer::t::pipelines::slam::Model::Integrate().

◆ Integrate() [3/3]

void cloudViewer::t::geometry::VoxelBlockGrid::Integrate ( const core::Tensor block_coords,
const Image depth,
const Image color,
const core::Tensor intrinsic,
const core::Tensor extrinsic,
float  depth_scale = 1000.0f,
float  depth_max = 3.0f,
float  trunc_voxel_multiplier = 8.0f 
)

Specific operation for TSDF volumes. Similar to RGB-D integration, but uses the same intrinsics for depth and color.

Definition at line 281 of file VoxelBlockGrid.cpp.

References color, and Integrate().

◆ Load()

◆ RayCast()

TensorMap cloudViewer::t::geometry::VoxelBlockGrid::RayCast ( const core::Tensor block_coords,
const core::Tensor intrinsic,
const core::Tensor extrinsic,
int  width,
int  height,
const std::vector< std::string >  attrs = {"depth", "color"},
float  depth_scale = 1000.0f,
float  depth_min = 0.1f,
float  depth_max = 3.0f,
float  weight_threshold = 3.0f,
float  trunc_voxel_multiplier = 8.0f,
int  range_map_down_factor = 8 
)

Specific operation for TSDF volumes. Perform volumetric ray casting in the selected block coordinates. Return selected properties from the frame. Supported attributes: Conventional rendering: vertex, depth, color, normal, range Differentiable rendering (voxel-wise): mask, index, (interpolation) ratio. The block coordinates in the frustum can be taken from GetUniqueBlockCoordinates. All the block coordinates can be taken from GetHashMap().GetKeyTensor().

Definition at line 329 of file VoxelBlockGrid.cpp.

References cloudViewer::core::Dtype::Bool, cloudViewer::t::geometry::CheckBlockCoordinates(), cloudViewer::t::geometry::CheckExtrinsicTensor(), cloudViewer::t::geometry::CheckIntrinsicTensor(), cloudViewer::t::geometry::ConstructTensorMap(), cloudViewer::t::geometry::kernel::voxel_grid::EstimateRange(), cloudViewer::core::Dtype::Float32, height, cloudViewer::core::Dtype::Int64, LogError, cloudViewer::t::geometry::kernel::voxel_grid::RayCast(), and width.

Referenced by cloudViewer::t::pipelines::slam::Model::SynthesizeModelFrame().

◆ Save()

◆ To()

VoxelBlockGrid cloudViewer::t::geometry::VoxelBlockGrid::To ( const core::Device device,
bool  copy = false 
) const

Convert the hash map to another device.

Definition at line 530 of file VoxelBlockGrid.cpp.

References copy, and VoxelBlockGrid().

Referenced by GetVoxelIndices(), and Save().


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