Open3D (C++ API)  0.15.1
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
37namespace open3d {
38namespace t {
39namespace geometry {
40
46public:
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
240private:
241 void AssertInitialized() const;
242
243 float voxel_size_ = -1;
244 int64_t block_resolution_ = -1;
245
246 // Global hash map: 3D coords -> voxel blocks in SoA.
247 std::shared_ptr<core::HashMap> block_hashmap_;
248
249 // Local hash map: 3D coords -> indices in block_hashmap_.
250 std::shared_ptr<core::HashMap> frustum_hashmap_;
251
252 // Map: attribute name -> index to access the attribute in SoA.
253 std::unordered_map<std::string, int> name_attr_map_;
254};
255} // namespace geometry
256} // namespace t
257} // namespace open3d
math::float4 color
Definition: LineSetBuffers.cpp:64
Definition: Device.h:39
Definition: HashMap.h:40
Definition: Tensor.h:51
A point cloud consists of point coordinates, and optionally point colors and point normals.
Definition: PointCloud.h:55
Triangle mesh contains vertices and triangles represented by the indices to the vertices.
Definition: TriangleMesh.h:54
The Image class stores image with customizable rows, cols, channels, dtype and device.
Definition: Image.h:48
A point cloud contains a list of 3D points.
Definition: PointCloud.h:95
Definition: TensorMap.h:49
Definition: VoxelBlockGrid.h:45
static VoxelBlockGrid Load(const std::string &file_name)
Load a voxel block grid from a .npz file.
Definition: VoxelBlockGrid.cpp:548
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
core::Tensor GetAttribute(const std::string &attr_name) const
Definition: VoxelBlockGrid.cpp:138
core::Tensor GetVoxelCoordinates(const core::Tensor &voxel_indices) const
Definition: VoxelBlockGrid.cpp:149
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
TriangleMesh ExtractTriangleMesh(float weight_threshold=3.0f, int estimated_vertex_numer=-1)
Definition: VoxelBlockGrid.cpp:455
void Save(const std::string &file_name) const
Save a voxel block grid to a .npz file.
Definition: VoxelBlockGrid.cpp:493
core::Tensor GetVoxelIndices() const
Get all active voxel indices.
Definition: VoxelBlockGrid.cpp:199
core::HashMap GetHashMap()
Definition: VoxelBlockGrid.h:71
std::pair< core::Tensor, core::Tensor > GetVoxelCoordinatesAndFlattenedIndices()
Definition: VoxelBlockGrid.cpp:205
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
int width
Definition: FilePCD.cpp:71
int height
Definition: FilePCD.cpp:72
HashBackendType
Definition: HashMap.h:38
Definition: PinholeCameraIntrinsic.cpp:35