Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
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 = 4.0);
137 
140  float trunc_voxel_multiplier = 4.0);
141 
155  void Integrate(const core::Tensor &block_coords,
156  const Image &depth,
157  const Image &color,
158  const core::Tensor &intrinsic,
159  const core::Tensor &extrinsic,
160  float depth_scale = 1000.0f,
161  float depth_max = 3.0f);
162 
165  void Integrate(const core::Tensor &block_coords,
166  const Image &depth,
167  const core::Tensor &intrinsic,
168  const core::Tensor &extrinsic,
169  float depth_scale = 1000.0f,
170  float depth_max = 3.0f);
171 
182  TensorMap RayCast(const core::Tensor &block_coords,
183  const core::Tensor &intrinsic,
184  const core::Tensor &extrinsic,
185  int width,
186  int height,
187  const std::vector<std::string> attrs = {"depth", "color"},
188  float depth_scale = 1000.0f,
189  float depth_min = 0.1f,
190  float depth_max = 3.0f,
191  float weight_threshold = 3.0f);
192 
199  PointCloud ExtractPointCloud(int estimate_number = -1,
200  float weight_threshold = 3.0f);
201 
208  TriangleMesh ExtractTriangleMesh(int estimate_number = -1,
209  float weight_threshold = 3.0f);
210 
212  void Save(const std::string &file_name) const;
213 
215  static VoxelBlockGrid Load(const std::string &file_name);
216 
217 private:
218  void AssertInitialized() const;
219 
220  float voxel_size_ = -1;
221  int64_t block_resolution_ = -1;
222 
223  // Global hash map: 3D coords -> voxel blocks in SoA.
224  std::shared_ptr<core::HashMap> block_hashmap_;
225 
226  // Local hash map: 3D coords -> indices in block_hashmap_.
227  std::shared_ptr<core::HashMap> frustum_hashmap_;
228 
229  // Map: attribute name -> index to access the attribute in SoA.
230  std::unordered_map<std::string, int> name_attr_map_;
231 };
232 } // namespace geometry
233 } // namespace t
234 } // namespace open3d
int height
Definition: FilePCD.cpp:72
PointCloud ExtractPointCloud(int estimate_number=-1, float weight_threshold=3.0f)
Definition: VoxelBlockGrid.cpp:408
HashBackendType
Definition: HashMap.h:38
core::HashMap GetHashMap()
Definition: VoxelBlockGrid.h:71
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)
Definition: VoxelBlockGrid.cpp:299
core::Tensor GetVoxelIndices() const
Get all active voxel indices.
Definition: VoxelBlockGrid.cpp:200
core::Tensor GetAttribute(const std::string &attr_name) const
Definition: VoxelBlockGrid.cpp:139
A triangle mesh contains vertices and triangles.
Definition: TriangleMesh.h:106
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=4.0)
Definition: VoxelBlockGrid.cpp:232
void Save(const std::string &file_name) const
Save a voxel block grid to a .npz file.
Definition: VoxelBlockGrid.cpp:478
static VoxelBlockGrid Load(const std::string &file_name)
Load a voxel block grid from a .npz file.
Definition: VoxelBlockGrid.cpp:533
core::Tensor GetVoxelCoordinates(const core::Tensor &voxel_indices) const
Definition: VoxelBlockGrid.cpp:150
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:39
A point cloud contains a list of 3D points.
Definition: PointCloud.h:95
Definition: HashMap.h:40
Definition: PinholeCameraIntrinsic.cpp:35
TriangleMesh ExtractTriangleMesh(int estimate_number=-1, float weight_threshold=3.0f)
Definition: VoxelBlockGrid.cpp:439
Definition: VoxelBlockGrid.h:45
std::pair< core::Tensor, core::Tensor > GetVoxelCoordinatesAndFlattenedIndices()
Definition: VoxelBlockGrid.cpp:206
int width
Definition: FilePCD.cpp:71
Definition: TensorMap.h:49
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)
Definition: VoxelBlockGrid.cpp:333