ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
VoxelBlockGrid.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <unordered_map>
11 
16 
17 namespace cloudViewer {
18 namespace t {
19 namespace geometry {
20 namespace kernel {
21 namespace voxel_grid {
22 
23 using index_t = int;
24 
25 void PointCloudTouch(std::shared_ptr<core::HashMap>& hashmap,
26  const core::Tensor& points,
27  core::Tensor& voxel_block_coords,
28  index_t voxel_grid_resolution,
29  float voxel_size,
30  float sdf_trunc);
31 
32 void DepthTouch(std::shared_ptr<core::HashMap>& hashmap,
33  const core::Tensor& depth,
34  const core::Tensor& intrinsic,
35  const core::Tensor& extrinsic,
36  core::Tensor& voxel_block_coords,
37  index_t voxel_grid_resolution,
38  float voxel_size,
39  float sdf_trunc,
40  float depth_scale,
41  float depth_max,
42  index_t stride);
43 
45  const core::Tensor& block_keys,
46  core::Tensor& voxel_coords,
47  core::Tensor& flattened_indices,
48  index_t block_resolution,
49  float voxel_size);
50 
51 void Integrate(const core::Tensor& depth,
52  const core::Tensor& color,
53  const core::Tensor& block_indices,
54  const core::Tensor& block_keys,
55  TensorMap& block_value_map,
56  const core::Tensor& depth_intrinsic,
57  const core::Tensor& color_intrinsic,
58  const core::Tensor& extrinsic,
59  index_t resolution,
60  float voxel_size,
61  float sdf_trunc,
62  float depth_scale,
63  float depth_max);
64 
65 void EstimateRange(const core::Tensor& block_keys,
66  core::Tensor& range_minmax_map,
67  const core::Tensor& intrinsics,
68  const core::Tensor& extrinsics,
69  int h,
70  int w,
71  int down_factor,
72  int64_t block_resolution,
73  float voxel_size,
74  float depth_min,
75  float depth_max,
76  core::Tensor& fragment_buffer);
77 
78 void RayCast(std::shared_ptr<core::HashMap>& hashmap,
79  const TensorMap& block_value_map,
80  const core::Tensor& range_map,
81  TensorMap& renderings_map,
82  const core::Tensor& intrinsic,
83  const core::Tensor& extrinsic,
84  index_t h,
85  index_t w,
86  index_t block_resolution,
87  float voxel_size,
88  float depth_scale,
89  float depth_min,
90  float depth_max,
91  float weight_threshold,
92  float trunc_voxel_multiplier,
93  int range_map_down_factor);
94 
95 void ExtractPointCloud(const core::Tensor& block_indices,
96  const core::Tensor& nb_block_indices,
97  const core::Tensor& nb_block_masks,
98  const core::Tensor& block_keys,
99  const TensorMap& block_value_map,
103  index_t block_resolution,
104  float voxel_size,
105  float weight_threshold,
106  index_t& valid_size);
107 
108 void ExtractTriangleMesh(const core::Tensor& block_indices,
109  const core::Tensor& inv_block_indices,
110  const core::Tensor& nb_block_indices,
111  const core::Tensor& nb_block_masks,
112  const core::Tensor& block_keys,
113  const TensorMap& block_value_map,
114  core::Tensor& vertices,
115  core::Tensor& triangles,
116  core::Tensor& vertex_normals,
117  core::Tensor& vertex_colors,
118  index_t block_resolution,
119  float voxel_size,
120  float weight_threshold,
121  index_t& vertex_count);
122 
124 void PointCloudTouchCPU(std::shared_ptr<core::HashMap>& hashmap,
125  const core::Tensor& points,
126  core::Tensor& voxel_block_coords,
127  index_t voxel_grid_resolution,
128  float voxel_size,
129  float sdf_trunc);
130 
131 void DepthTouchCPU(std::shared_ptr<core::HashMap>& hashmap,
132  const core::Tensor& depth,
133  const core::Tensor& intrinsic,
134  const core::Tensor& extrinsic,
135  core::Tensor& voxel_block_coords,
136  index_t voxel_grid_resolution,
137  float voxel_size,
138  float sdf_trunc,
139  float depth_scale,
140  float depth_max,
141  index_t stride);
142 
144  const core::Tensor& block_keys,
145  core::Tensor& voxel_coords,
146  core::Tensor& flattened_indices,
147  index_t block_resolution,
148  float voxel_size);
149 
150 template <typename input_depth_t,
151  typename input_color_t,
152  typename tsdf_t,
153  typename weight_t,
154  typename color_t>
155 void IntegrateCPU(const core::Tensor& depth,
156  const core::Tensor& color,
157  const core::Tensor& block_indices,
158  const core::Tensor& block_keys,
159  TensorMap& block_value_map,
160  const core::Tensor& depth_intrinsic,
161  const core::Tensor& color_intrinsic,
162  const core::Tensor& extrinsic,
163  index_t resolution,
164  float voxel_size,
165  float sdf_trunc,
166  float depth_scale,
167  float depth_max);
168 
169 void EstimateRangeCPU(const core::Tensor& block_keys,
170  core::Tensor& range_minmax_map,
171  const core::Tensor& intrinsics,
172  const core::Tensor& extrinsics,
173  int h,
174  int w,
175  int down_factor,
176  int64_t block_resolution,
177  float voxel_size,
178  float depth_min,
179  float depth_max,
180  core::Tensor& fragment_buffer);
181 
182 template <typename tsdf_t, typename weight_t, typename color_t>
183 void RayCastCPU(std::shared_ptr<core::HashMap>& hashmap,
184  const TensorMap& block_value_map,
185  const core::Tensor& range_map,
186  TensorMap& renderings_map,
187  const core::Tensor& intrinsic,
188  const core::Tensor& extrinsic,
189  index_t h,
190  index_t w,
191  index_t block_resolution,
192  float voxel_size,
193  float depth_scale,
194  float depth_min,
195  float depth_max,
196  float weight_threshold,
197  float trunc_voxel_multiplier,
198  int range_map_down_factor);
199 
200 template <typename tsdf_t, typename weight_t, typename color_t>
201 void ExtractPointCloudCPU(const core::Tensor& block_indices,
202  const core::Tensor& nb_block_indices,
203  const core::Tensor& nb_block_masks,
204  const core::Tensor& block_keys,
205  const TensorMap& block_value_map,
209  index_t block_resolution,
210  float voxel_size,
211  float weight_threshold,
212  index_t& valid_size);
213 
214 template <typename tsdf_t, typename weight_t, typename color_t>
215 void ExtractTriangleMeshCPU(const core::Tensor& block_indices,
216  const core::Tensor& inv_block_indices,
217  const core::Tensor& nb_block_indices,
218  const core::Tensor& nb_block_masks,
219  const core::Tensor& block_keys,
220  const TensorMap& block_value_map,
221  core::Tensor& vertices,
222  core::Tensor& triangles,
223  core::Tensor& vertex_normals,
224  core::Tensor& vertex_colors,
225  index_t block_resolution,
226  float voxel_size,
227  float weight_threshold,
228  index_t& vertex_count);
229 
230 #ifdef BUILD_CUDA_MODULE
231 void PointCloudTouchCUDA(std::shared_ptr<core::HashMap>& hashmap,
232  const core::Tensor& points,
233  core::Tensor& voxel_block_coords,
234  index_t voxel_grid_resolution,
235  float voxel_size,
236  float sdf_trunc);
237 
238 void DepthTouchCUDA(std::shared_ptr<core::HashMap>& hashmap,
239  const core::Tensor& depth,
240  const core::Tensor& intrinsic,
241  const core::Tensor& extrinsic,
242  core::Tensor& voxel_block_coords,
243  index_t voxel_grid_resolution,
244  float voxel_size,
245  float sdf_trunc,
246  float depth_scale,
247  float depth_max,
248  index_t stride);
249 
250 void GetVoxelCoordinatesAndFlattenedIndicesCUDA(const core::Tensor& buf_indices,
251  const core::Tensor& block_keys,
252  core::Tensor& voxel_coords,
253  core::Tensor& flattened_indices,
254  index_t block_resolution,
255  float voxel_size);
256 
257 template <typename input_depth_t,
258  typename input_color_t,
259  typename tsdf_t,
260  typename weight_t,
261  typename color_t>
262 void IntegrateCUDA(const core::Tensor& depth,
263  const core::Tensor& color,
264  const core::Tensor& block_indices,
265  const core::Tensor& block_keys,
266  TensorMap& block_value_map,
267  const core::Tensor& depth_intrinsic,
268  const core::Tensor& color_intrinsic,
269  const core::Tensor& extrinsic,
270  index_t resolution,
271  float voxel_size,
272  float sdf_trunc,
273  float depth_scale,
274  float depth_max);
275 
276 void EstimateRangeCUDA(const core::Tensor& block_keys,
277  core::Tensor& range_minmax_map,
278  const core::Tensor& intrinsics,
279  const core::Tensor& extrinsics,
280  int h,
281  int w,
282  int down_factor,
283  int64_t block_resolution,
284  float voxel_size,
285  float depth_min,
286  float depth_max,
287  core::Tensor& fragment_buffer);
288 
289 template <typename tsdf_t, typename weight_t, typename color_t>
290 void RayCastCUDA(std::shared_ptr<core::HashMap>& hashmap,
291  const TensorMap& block_value_map,
292  const core::Tensor& range_map,
293  TensorMap& renderings_map,
294  const core::Tensor& intrinsic,
295  const core::Tensor& extrinsic,
296  index_t h,
297  index_t w,
298  index_t block_resolution,
299  float voxel_size,
300  float depth_scale,
301  float depth_min,
302  float depth_max,
303  float weight_threshold,
304  float trunc_voxel_multiplier,
305  int range_map_down_factor);
306 
307 template <typename tsdf_t, typename weight_t, typename color_t>
308 void ExtractPointCloudCUDA(const core::Tensor& block_indices,
309  const core::Tensor& nb_block_indices,
310  const core::Tensor& nb_block_masks,
311  const core::Tensor& block_keys,
312  const TensorMap& block_value_map,
316  index_t block_resolution,
317  float voxel_size,
318  float weight_threshold,
319  index_t& valid_size);
320 
321 template <typename tsdf_t, typename weight_t, typename color_t>
322 void ExtractTriangleMeshCUDA(const core::Tensor& block_indices,
323  const core::Tensor& inv_block_indices,
324  const core::Tensor& nb_block_indices,
325  const core::Tensor& nb_block_masks,
326  const core::Tensor& block_keys,
327  const TensorMap& block_value_map,
328  core::Tensor& vertices,
329  core::Tensor& triangles,
330  core::Tensor& vertex_normals,
331  core::Tensor& vertex_colors,
332  index_t block_resolution,
333  float voxel_size,
334  float weight_threshold,
335  index_t& vertex_count);
336 
337 #endif
338 } // namespace voxel_grid
339 } // namespace kernel
340 } // namespace geometry
341 } // namespace t
342 } // namespace cloudViewer
int points
math::float4 color
size_t stride
double colors[3]
double normals[3]
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 RayCastCPU(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 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 ExtractPointCloudCPU(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, index_t &valid_size)
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 ExtractTriangleMeshCPU(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, index_t &vertex_count)
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.