Open3D (C++ API)  0.18.0+0cf605f
VoxelBlockGrid.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include "open3d/core/Tensor.h"
17 
18 namespace open3d {
19 namespace t {
20 namespace geometry {
21 
27 public:
28  VoxelBlockGrid() = default;
29 
40  VoxelBlockGrid(const std::vector<std::string> &attr_names,
41  const std::vector<core::Dtype> &attr_dtypes,
42  const std::vector<core::SizeVector> &attr_channels,
43  float voxel_size = 0.0058,
44  int64_t block_resolution = 16,
45  int64_t block_count = 10000,
46  const core::Device &device = core::Device("CPU:0"),
47  const core::HashBackendType &backend =
49 
52  core::HashMap GetHashMap() { return *block_hashmap_; }
53 
56  core::Tensor GetAttribute(const std::string &attr_name) const;
57 
75  core::Tensor GetVoxelIndices(const core::Tensor &buf_indices) const;
76 
79 
95  core::Tensor GetVoxelCoordinates(const core::Tensor &voxel_indices) const;
96 
100  std::pair<core::Tensor, core::Tensor>
102 
105  std::pair<core::Tensor, core::Tensor>
107 
113  const core::Tensor &intrinsic,
114  const core::Tensor &extrinsic,
115  float depth_scale = 1000.0f,
116  float depth_max = 3.0f,
117  float trunc_voxel_multiplier = 8.0);
118 
121  float trunc_voxel_multiplier = 8.0);
122 
136  void Integrate(const core::Tensor &block_coords,
137  const Image &depth,
138  const Image &color,
139  const core::Tensor &depth_intrinsic,
140  const core::Tensor &color_intrinsic,
141  const core::Tensor &extrinsic,
142  float depth_scale = 1000.0f,
143  float depth_max = 3.0f,
144  float trunc_voxel_multiplier = 8.0f);
145 
149  void Integrate(const core::Tensor &block_coords,
150  const Image &depth,
151  const Image &color,
152  const core::Tensor &intrinsic,
153  const core::Tensor &extrinsic,
154  float depth_scale = 1000.0f,
155  float depth_max = 3.0f,
156  float trunc_voxel_multiplier = 8.0f);
157 
160  void Integrate(const core::Tensor &block_coords,
161  const Image &depth,
162  const core::Tensor &intrinsic,
163  const core::Tensor &extrinsic,
164  float depth_scale = 1000.0f,
165  float depth_max = 3.0f,
166  float trunc_voxel_multiplier = 8.0f);
167 
178  TensorMap RayCast(const core::Tensor &block_coords,
179  const core::Tensor &intrinsic,
180  const core::Tensor &extrinsic,
181  int width,
182  int height,
183  const std::vector<std::string> attrs = {"depth", "color"},
184  float depth_scale = 1000.0f,
185  float depth_min = 0.1f,
186  float depth_max = 3.0f,
187  float weight_threshold = 3.0f,
188  float trunc_voxel_multiplier = 8.0f,
189  int range_map_down_factor = 8);
190 
200  PointCloud ExtractPointCloud(float weight_threshold = 3.0f,
201  int estimated_point_number = -1);
202 
212  TriangleMesh ExtractTriangleMesh(float weight_threshold = 3.0f,
213  int estimated_vertex_numer = -1);
214 
216  void Save(const std::string &file_name) const;
217 
219  static VoxelBlockGrid Load(const std::string &file_name);
220 
222  VoxelBlockGrid To(const core::Device &device, bool copy = false) const;
223 
224 private:
225  void AssertInitialized() const;
226 
227  VoxelBlockGrid(float voxelSize,
228  int64_t blockResolution,
229  const std::shared_ptr<core::HashMap> &blockHashmap,
230  const std::unordered_map<std::string, int> &nameAttrMap)
231  : voxel_size_(voxelSize),
232  block_resolution_(blockResolution),
233  block_hashmap_(blockHashmap),
234  name_attr_map_(nameAttrMap) {}
235 
236  float voxel_size_ = -1;
237  int64_t block_resolution_ = -1;
238 
239  // Global hash map: 3D coords -> voxel blocks in SoA.
240  std::shared_ptr<core::HashMap> block_hashmap_;
241 
242  // Local hash map: 3D coords -> indices in block_hashmap_.
243  std::shared_ptr<core::HashMap> frustum_hashmap_;
244 
245  // Map: attribute name -> index to access the attribute in SoA.
246  std::unordered_map<std::string, int> name_attr_map_;
247 
248  // Allocated fragment buffer for reuse in depth estimation
249  core::Tensor fragment_buffer_;
250 };
251 } // namespace geometry
252 } // namespace t
253 } // namespace open3d
math::float4 color
Definition: LineSetBuffers.cpp:45
bool copy
Definition: VtkUtils.cpp:73
Definition: Device.h:18
Definition: HashMap.h:22
Definition: Tensor.h:32
A point cloud consists of point coordinates, and optionally point colors and point normals.
Definition: PointCloud.h:36
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:35
The Image class stores image with customizable rows, cols, channels, dtype and device.
Definition: Image.h:29
A point cloud contains a list of 3D points.
Definition: PointCloud.h:80
Definition: TensorMap.h:31
Definition: VoxelBlockGrid.h:26
static VoxelBlockGrid Load(const std::string &file_name)
Load a voxel block grid from a .npz file.
Definition: VoxelBlockGrid.cpp:540
PointCloud ExtractPointCloud(float weight_threshold=3.0f, int estimated_point_number=-1)
Definition: VoxelBlockGrid.cpp:404
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)
Definition: VoxelBlockGrid.cpp:292
core::Tensor GetAttribute(const std::string &attr_name) const
Definition: VoxelBlockGrid.cpp:119
VoxelBlockGrid To(const core::Device &device, bool copy=false) const
Convert the hash map to another device.
Definition: VoxelBlockGrid.cpp:529
core::Tensor GetVoxelCoordinates(const core::Tensor &voxel_indices) const
Definition: VoxelBlockGrid.cpp:130
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)
Definition: VoxelBlockGrid.cpp:328
TriangleMesh ExtractTriangleMesh(float weight_threshold=3.0f, int estimated_vertex_numer=-1)
Definition: VoxelBlockGrid.cpp:436
void Save(const std::string &file_name) const
Save a voxel block grid to a .npz file.
Definition: VoxelBlockGrid.cpp:474
core::Tensor GetVoxelIndices() const
Get all active voxel indices.
Definition: VoxelBlockGrid.cpp:180
core::HashMap GetHashMap()
Definition: VoxelBlockGrid.h:52
std::pair< core::Tensor, core::Tensor > GetVoxelCoordinatesAndFlattenedIndices()
Definition: VoxelBlockGrid.cpp:186
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)
Definition: VoxelBlockGrid.cpp:212
int width
Definition: FilePCD.cpp:52
int height
Definition: FilePCD.cpp:53
HashBackendType
Definition: HashMap.h:20
Definition: PinholeCameraIntrinsic.cpp:16