23 namespace voxel_grid {
31 if (hashmap->IsCPU()) {
33 voxel_grid_resolution, voxel_size, sdf_trunc);
34 }
else if (hashmap->IsCUDA()) {
36 voxel_grid_resolution, voxel_size, sdf_trunc);
53 if (hashmap->IsCPU()) {
54 DepthTouchCPU(hashmap, depth, intrinsic, extrinsic, voxel_block_coords,
55 voxel_grid_resolution, voxel_size, sdf_trunc, depth_scale,
57 }
else if (hashmap->IsCUDA()) {
58 CUDA_CALL(DepthTouchCUDA, hashmap, depth, intrinsic, extrinsic,
59 voxel_block_coords, voxel_grid_resolution, voxel_size,
60 sdf_trunc, depth_scale, depth_max,
stride);
72 if (block_keys.
IsCPU()) {
74 buf_indices, block_keys, voxel_coords, flattened_indices,
75 block_resolution, voxel_size);
76 }
else if (block_keys.
IsCUDA()) {
77 CUDA_CALL(GetVoxelCoordinatesAndFlattenedIndicesCUDA, buf_indices,
78 block_keys, voxel_coords, flattened_indices, block_resolution,
85 #define DISPATCH_VALUE_DTYPE_TO_TEMPLATE(WEIGHT_DTYPE, COLOR_DTYPE, ...) \
87 if (WEIGHT_DTYPE == cloudViewer::core::Float32 && \
88 COLOR_DTYPE == cloudViewer::core::Float32) { \
89 using weight_t = float; \
90 using color_t = float; \
91 return __VA_ARGS__(); \
92 } else if (WEIGHT_DTYPE == cloudViewer::core::UInt16 && \
93 COLOR_DTYPE == cloudViewer::core::UInt16) { \
94 using weight_t = uint16_t; \
95 using color_t = uint16_t; \
96 return __VA_ARGS__(); \
99 "Unsupported value data type combination. Expected " \
100 "(float, float) or (uint16, uint16), but received ({} " \
102 WEIGHT_DTYPE.ToString(), COLOR_DTYPE.ToString()); \
106 #define DISPATCH_INPUT_DTYPE_TO_TEMPLATE(DEPTH_DTYPE, COLOR_DTYPE, ...) \
108 if (DEPTH_DTYPE == cloudViewer::core::Float32 && \
109 COLOR_DTYPE == cloudViewer::core::Float32) { \
110 using input_depth_t = float; \
111 using input_color_t = float; \
112 return __VA_ARGS__(); \
113 } else if (DEPTH_DTYPE == cloudViewer::core::UInt16 && \
114 COLOR_DTYPE == cloudViewer::core::UInt8) { \
115 using input_depth_t = uint16_t; \
116 using input_color_t = uint8_t; \
117 return __VA_ARGS__(); \
120 "Unsupported input data type combination. Expected " \
121 "(float, float) or (uint16, uint8), but received ({} {})", \
122 DEPTH_DTYPE.ToString(), COLOR_DTYPE.ToString()); \
139 using tsdf_t = float;
142 if (block_value_map.
Contains(
"weight")) {
143 block_weight_dtype = block_value_map.at(
"weight").GetDtype();
145 if (block_value_map.
Contains(
"color")) {
146 block_color_dtype = block_value_map.at(
"color").GetDtype();
153 if (
color.NumElements() > 0) {
154 input_color_dtype =
color.GetDtype();
159 input_depth_dtype, input_color_dtype, [&] {
161 block_weight_dtype, block_color_dtype, [&] {
163 tsdf_t, weight_t, color_t>(
164 depth,
color, block_indices, block_keys,
165 block_value_map, depth_intrinsic,
166 color_intrinsic, extrinsic, resolution,
167 voxel_size, sdf_trunc, depth_scale,
171 }
else if (depth.
IsCUDA()) {
172 #ifdef BUILD_CUDA_MODULE
174 input_depth_dtype, input_color_dtype, [&] {
176 block_weight_dtype, block_color_dtype, [&] {
177 IntegrateCUDA<input_depth_t, input_color_t,
178 tsdf_t, weight_t, color_t>(
179 depth,
color, block_indices, block_keys,
180 block_value_map, depth_intrinsic,
181 color_intrinsic, extrinsic, resolution,
182 voxel_size, sdf_trunc, depth_scale,
201 int64_t block_resolution,
210 if (block_keys.
IsCPU()) {
212 extrinsics_d, h, w, down_factor, block_resolution,
213 voxel_size, depth_min, depth_max, fragment_buffer);
214 }
else if (block_keys.
IsCUDA()) {
215 #ifdef BUILD_CUDA_MODULE
216 EstimateRangeCUDA(block_keys, range_minmax_map, intrinsics_d,
217 extrinsics_d, h, w, down_factor, block_resolution,
218 voxel_size, depth_min, depth_max, fragment_buffer);
227 void RayCast(std::shared_ptr<core::HashMap>& hashmap,
240 float weight_threshold,
241 float trunc_voxel_multiplier,
242 int range_map_down_factor) {
243 using tsdf_t = float;
246 if (block_value_map.
Contains(
"weight")) {
247 block_weight_dtype = block_value_map.at(
"weight").GetDtype();
249 if (block_value_map.
Contains(
"color")) {
250 block_color_dtype = block_value_map.at(
"color").GetDtype();
255 block_weight_dtype, block_color_dtype, [&] {
256 RayCastCPU<tsdf_t, weight_t, color_t>(
257 hashmap, block_value_map, range_map, renderings_map,
258 intrinsic, extrinsic, h, w, block_resolution,
259 voxel_size, depth_scale, depth_min, depth_max,
260 weight_threshold, trunc_voxel_multiplier,
261 range_map_down_factor);
264 }
else if (hashmap->GetDevice().GetType() ==
266 #ifdef BUILD_CUDA_MODULE
268 block_weight_dtype, block_color_dtype, [&] {
269 RayCastCUDA<tsdf_t, weight_t, color_t>(
270 hashmap, block_value_map, range_map, renderings_map,
271 intrinsic, extrinsic, h, w, block_resolution,
272 voxel_size, depth_scale, depth_min, depth_max,
273 weight_threshold, trunc_voxel_multiplier,
274 range_map_down_factor);
294 float weight_threshold,
296 using tsdf_t = float;
299 if (block_value_map.
Contains(
"weight")) {
300 block_weight_dtype = block_value_map.at(
"weight").GetDtype();
302 if (block_value_map.
Contains(
"color")) {
303 block_color_dtype = block_value_map.at(
"color").GetDtype();
306 if (block_indices.
IsCPU()) {
308 block_weight_dtype, block_color_dtype, [&] {
309 ExtractPointCloudCPU<tsdf_t, weight_t, color_t>(
310 block_indices, nb_block_indices, nb_block_masks,
312 colors, block_resolution, voxel_size,
313 weight_threshold, valid_size);
316 }
else if (block_indices.
IsCUDA()) {
317 #ifdef BUILD_CUDA_MODULE
319 block_weight_dtype, block_color_dtype, [&] {
320 ExtractPointCloudCUDA<tsdf_t, weight_t, color_t>(
321 block_indices, nb_block_indices, nb_block_masks,
323 colors, block_resolution, voxel_size,
324 weight_threshold, valid_size);
346 float weight_threshold,
348 using tsdf_t = float;
351 if (block_value_map.
Contains(
"weight")) {
352 block_weight_dtype = block_value_map.at(
"weight").GetDtype();
354 if (block_value_map.
Contains(
"color")) {
355 block_color_dtype = block_value_map.at(
"color").GetDtype();
358 if (block_indices.
IsCPU()) {
360 block_weight_dtype, block_color_dtype, [&] {
361 ExtractTriangleMeshCPU<tsdf_t, weight_t, color_t>(
362 block_indices, inv_block_indices, nb_block_indices,
363 nb_block_masks, block_keys, block_value_map,
364 vertices, triangles, vertex_normals, vertex_colors,
365 block_resolution, voxel_size, weight_threshold,
368 }
else if (block_indices.
IsCUDA()) {
369 #ifdef BUILD_CUDA_MODULE
371 block_weight_dtype, block_color_dtype, [&] {
372 ExtractTriangleMeshCUDA<tsdf_t, weight_t, color_t>(
373 block_indices, inv_block_indices, nb_block_indices,
374 nb_block_masks, block_keys, block_value_map,
375 vertices, triangles, vertex_normals, vertex_colors,
376 block_resolution, voxel_size, weight_threshold,
#define CUDA_CALL(cuda_function,...)
static const Dtype Float32
Tensor Contiguous() const
Tensor To(Dtype dtype, bool copy=false) const
bool Contains(const std::string &key) const
#define DISPATCH_INPUT_DTYPE_TO_TEMPLATE(DEPTH_DTYPE, COLOR_DTYPE,...)
#define DISPATCH_VALUE_DTYPE_TO_TEMPLATE(WEIGHT_DTYPE, COLOR_DTYPE,...)
void Integrate(const core::Tensor &depth, const core::Tensor &color, const core::Tensor &block_indices, const core::Tensor &block_keys, TensorMap &block_value_map, const core::Tensor &depth_intrinsic, const core::Tensor &color_intrinsic, const core::Tensor &extrinsic, index_t resolution, float voxel_size, float sdf_trunc, float depth_scale, float depth_max)
void DepthTouchCPU(std::shared_ptr< core::HashMap > &hashmap, const core::Tensor &depth, const core::Tensor &intrinsic, const core::Tensor &extrinsic, core::Tensor &voxel_block_coords, index_t voxel_grid_resolution, float voxel_size, float sdf_trunc, float depth_scale, float depth_max, index_t stride)
void PointCloudTouchCPU(std::shared_ptr< core::HashMap > &hashmap, const core::Tensor &points, core::Tensor &voxel_block_coords, index_t voxel_grid_resolution, float voxel_size, float sdf_trunc)
CPU.
void GetVoxelCoordinatesAndFlattenedIndices(const core::Tensor &buf_indices, const core::Tensor &block_keys, core::Tensor &voxel_coords, core::Tensor &flattened_indices, index_t block_resolution, float voxel_size)
void EstimateRangeCPU(const core::Tensor &block_keys, core::Tensor &range_minmax_map, const core::Tensor &intrinsics, const core::Tensor &extrinsics, int h, int w, int down_factor, int64_t block_resolution, float voxel_size, float depth_min, float depth_max, core::Tensor &fragment_buffer)
void PointCloudTouch(std::shared_ptr< core::HashMap > &hashmap, const core::Tensor &points, core::Tensor &voxel_block_coords, index_t voxel_grid_resolution, float voxel_size, float sdf_trunc)
void ExtractPointCloud(const core::Tensor &block_indices, const core::Tensor &nb_block_indices, const core::Tensor &nb_block_masks, const core::Tensor &block_keys, const TensorMap &block_value_map, core::Tensor &points, core::Tensor &normals, core::Tensor &colors, index_t block_resolution, float voxel_size, float weight_threshold, int &valid_size)
void RayCast(std::shared_ptr< core::HashMap > &hashmap, const TensorMap &block_value_map, const core::Tensor &range_map, TensorMap &renderings_map, const core::Tensor &intrinsic, const core::Tensor &extrinsic, index_t h, index_t w, index_t block_resolution, float voxel_size, float depth_scale, float depth_min, float depth_max, float weight_threshold, float trunc_voxel_multiplier, int range_map_down_factor)
void DepthTouch(std::shared_ptr< core::HashMap > &hashmap, const core::Tensor &depth, const core::Tensor &intrinsic, const core::Tensor &extrinsic, core::Tensor &voxel_block_coords, index_t voxel_grid_resolution, float voxel_size, float sdf_trunc, float depth_scale, float depth_max, index_t stride)
void IntegrateCPU(const core::Tensor &depth, const core::Tensor &color, const core::Tensor &block_indices, const core::Tensor &block_keys, TensorMap &block_value_map, const core::Tensor &depth_intrinsic, const core::Tensor &color_intrinsic, const core::Tensor &extrinsic, index_t resolution, float voxel_size, float sdf_trunc, float depth_scale, float depth_max)
void GetVoxelCoordinatesAndFlattenedIndicesCPU(const core::Tensor &buf_indices, const core::Tensor &block_keys, core::Tensor &voxel_coords, core::Tensor &flattened_indices, index_t block_resolution, float voxel_size)
void ExtractTriangleMesh(const core::Tensor &block_indices, const core::Tensor &inv_block_indices, const core::Tensor &nb_block_indices, const core::Tensor &nb_block_masks, const core::Tensor &block_keys, const TensorMap &block_value_map, core::Tensor &vertices, core::Tensor &triangles, core::Tensor &vertex_normals, core::Tensor &vertex_colors, index_t block_resolution, float voxel_size, float weight_threshold, int &vertex_count)
void EstimateRange(const core::Tensor &block_keys, core::Tensor &range_minmax_map, const core::Tensor &intrinsics, const core::Tensor &extrinsics, int h, int w, int down_factor, int64_t block_resolution, float voxel_size, float depth_min, float depth_max, core::Tensor &fragment_buffer)
Generic file read and write utility for python interface.