Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.16.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
VoxelBlockGrid.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include "open3d/core/Tensor.h"
36 
37 namespace open3d {
38 namespace t {
39 namespace geometry {
40 
46 public:
47  VoxelBlockGrid() = default;
48 
59  VoxelBlockGrid(const std::vector<std::string> &attr_names,
60  const std::vector<core::Dtype> &attr_dtypes,
61  const std::vector<core::SizeVector> &attr_channels,
62  float voxel_size = 0.0058,
63  int64_t block_resolution = 16,
64  int64_t block_count = 10000,
65  const core::Device &device = core::Device("CPU:0"),
66  const core::HashBackendType &backend =
68 
71  core::HashMap GetHashMap() { return *block_hashmap_; }
72 
75  core::Tensor GetAttribute(const std::string &attr_name) const;
76 
94  core::Tensor GetVoxelIndices(const core::Tensor &buf_indices) const;
95 
98 
114  core::Tensor GetVoxelCoordinates(const core::Tensor &voxel_indices) const;
115 
119  std::pair<core::Tensor, core::Tensor>
121 
124  std::pair<core::Tensor, core::Tensor>
126 
132  const core::Tensor &intrinsic,
133  const core::Tensor &extrinsic,
134  float depth_scale = 1000.0f,
135  float depth_max = 3.0f,
136  float trunc_voxel_multiplier = 8.0);
137 
140  float trunc_voxel_multiplier = 8.0);
141 
155  void Integrate(const core::Tensor &block_coords,
156  const Image &depth,
157  const Image &color,
158  const core::Tensor &depth_intrinsic,
159  const core::Tensor &color_intrinsic,
160  const core::Tensor &extrinsic,
161  float depth_scale = 1000.0f,
162  float depth_max = 3.0f,
163  float trunc_voxel_multiplier = 8.0f);
164 
168  void Integrate(const core::Tensor &block_coords,
169  const Image &depth,
170  const Image &color,
171  const core::Tensor &intrinsic,
172  const core::Tensor &extrinsic,
173  float depth_scale = 1000.0f,
174  float depth_max = 3.0f,
175  float trunc_voxel_multiplier = 8.0f);
176 
179  void Integrate(const core::Tensor &block_coords,
180  const Image &depth,
181  const core::Tensor &intrinsic,
182  const core::Tensor &extrinsic,
183  float depth_scale = 1000.0f,
184  float depth_max = 3.0f,
185  float trunc_voxel_multiplier = 8.0f);
186 
197  TensorMap RayCast(const core::Tensor &block_coords,
198  const core::Tensor &intrinsic,
199  const core::Tensor &extrinsic,
200  int width,
201  int height,
202  const std::vector<std::string> attrs = {"depth", "color"},
203  float depth_scale = 1000.0f,
204  float depth_min = 0.1f,
205  float depth_max = 3.0f,
206  float weight_threshold = 3.0f,
207  float trunc_voxel_multiplier = 8.0f,
208  int range_map_down_factor = 8);
209 
219  PointCloud ExtractPointCloud(float weight_threshold = 3.0f,
220  int estimated_point_number = -1);
221 
231  TriangleMesh ExtractTriangleMesh(float weight_threshold = 3.0f,
232  int estimated_vertex_numer = -1);
233 
235  void Save(const std::string &file_name) const;
236 
238  static VoxelBlockGrid Load(const std::string &file_name);
239 
241  VoxelBlockGrid To(const core::Device &device, bool copy = false) const;
242 
243 private:
244  void AssertInitialized() const;
245 
246  VoxelBlockGrid(float voxelSize,
247  int64_t blockResolution,
248  const std::shared_ptr<core::HashMap> &blockHashmap,
249  const std::unordered_map<std::string, int> &nameAttrMap)
250  : voxel_size_(voxelSize),
251  block_resolution_(blockResolution),
252  block_hashmap_(blockHashmap),
253  name_attr_map_(nameAttrMap) {}
254 
255  float voxel_size_ = -1;
256  int64_t block_resolution_ = -1;
257 
258  // Global hash map: 3D coords -> voxel blocks in SoA.
259  std::shared_ptr<core::HashMap> block_hashmap_;
260 
261  // Local hash map: 3D coords -> indices in block_hashmap_.
262  std::shared_ptr<core::HashMap> frustum_hashmap_;
263 
264  // Map: attribute name -> index to access the attribute in SoA.
265  std::unordered_map<std::string, int> name_attr_map_;
266 
267  // Allocated fragment buffer for reuse in depth estimation
268  core::Tensor fragment_buffer_;
269 };
270 } // namespace geometry
271 } // namespace t
272 } // namespace open3d
int height
Definition: FilePCD.cpp:72
HashBackendType
Definition: HashMap.h:39
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:347
core::HashMap GetHashMap()
Definition: VoxelBlockGrid.h:71
core::Tensor GetVoxelIndices() const
Get all active voxel indices.
Definition: VoxelBlockGrid.cpp:199
core::Tensor GetAttribute(const std::string &attr_name) const
Definition: VoxelBlockGrid.cpp:138
A triangle mesh contains vertices and triangles.
Definition: TriangleMesh.h:111
void Save(const std::string &file_name) const
Save a voxel block grid to a .npz file.
Definition: VoxelBlockGrid.cpp:493
PointCloud ExtractPointCloud(float weight_threshold=3.0f, int estimated_point_number=-1)
Definition: VoxelBlockGrid.cpp:423
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:311
VoxelBlockGrid To(const core::Device &device, bool copy=false) const
Convert the hash map to another device.
Definition: VoxelBlockGrid.cpp:548
static VoxelBlockGrid Load(const std::string &file_name)
Load a voxel block grid from a .npz file.
Definition: VoxelBlockGrid.cpp:559
core::Tensor GetVoxelCoordinates(const core::Tensor &voxel_indices) const
Definition: VoxelBlockGrid.cpp:149
The Image class stores image with customizable rows, cols, channels, dtype and device.
Definition: Image.h:48
math::float4 color
Definition: LineSetBuffers.cpp:64
Definition: Device.h:37
A point cloud contains a list of 3D points.
Definition: PointCloud.h:99
TriangleMesh ExtractTriangleMesh(float weight_threshold=3.0f, int estimated_vertex_numer=-1)
Definition: VoxelBlockGrid.cpp:455
Definition: HashMap.h:41
Definition: PinholeCameraIntrinsic.cpp:35
Definition: VoxelBlockGrid.h:45
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:231
bool copy
Definition: VtkUtils.cpp:89
std::pair< core::Tensor, core::Tensor > GetVoxelCoordinatesAndFlattenedIndices()
Definition: VoxelBlockGrid.cpp:205
int width
Definition: FilePCD.cpp:71
Definition: TensorMap.h:50