Open3D (C++ API)  0.14.1+b449b58
TSDFVoxelGrid.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 <string>
30 #include <unordered_map>
31 #include <unordered_set>
32 
33 #include "open3d/core/Tensor.h"
40 
41 namespace open3d {
42 namespace t {
43 
44 namespace io {
46 }
47 
48 namespace geometry {
49 
61 public:
63  TSDFVoxelGrid(std::unordered_map<std::string, core::Dtype> attr_dtype_map =
64  {{"tsdf", core::Float32},
65  {"weight", core::UInt16},
66  {"color", core::UInt16}},
67  float voxel_size = 3.0 / 512.0, /* in meter */
68  float sdf_trunc = 0.04, /* in meter */
69  int64_t block_resolution = 16, /* block Tensor resolution */
70  int64_t block_count = 1000,
71  const core::Device &device = core::Device("CPU:0"),
72  const core::HashBackendType &backend =
74 
76 
78  void Integrate(const Image &depth,
79  const core::Tensor &intrinsics,
80  const core::Tensor &extrinsics,
81  float depth_scale = 1000.0f,
82  float depth_max = 3.0f);
83 
85  void Integrate(const Image &depth,
86  const Image &color,
87  const core::Tensor &intrinsics,
88  const core::Tensor &extrinsics,
89  float depth_scale = 1000.0f,
90  float depth_max = 3.0f);
91 
93  None = 0,
94  VertexMap = (1 << 0),
95  DepthMap = (1 << 1),
96  ColorMap = (1 << 2),
97  NormalMap = (1 << 3),
98  RangeMap = (1 << 4)
99  };
108  std::unordered_map<SurfaceMaskCode, core::Tensor> RayCast(
109  const core::Tensor &intrinsics,
110  const core::Tensor &extrinsics,
111  int width,
112  int height,
113  float depth_scale = 1000.0f,
114  float depth_min = 0.1f,
115  float depth_max = 3.0f,
116  float weight_threshold = 3.0f,
117  int ray_cast_mask = SurfaceMaskCode::DepthMap |
118  SurfaceMaskCode::ColorMap);
119 
126  int estimate_number = -1,
127  float weight_threshold = 3.0f,
128  int surface_mask = SurfaceMaskCode::VertexMap |
129  SurfaceMaskCode::ColorMap);
130 
137  int estimate_vertices = -1,
138  float weight_threshold = 3.0f,
139  int surface_mask = SurfaceMaskCode::VertexMap |
140  SurfaceMaskCode::NormalMap |
141  SurfaceMaskCode::ColorMap);
142 
148  TSDFVoxelGrid To(const core::Device &device, bool copy = false) const;
149 
151  TSDFVoxelGrid Clone() const { return To(GetDevice(), true); }
152 
153  float GetVoxelSize() const { return voxel_size_; }
154 
155  float GetSDFTrunc() const { return sdf_trunc_; }
156 
157  int64_t GetBlockResolution() const { return block_resolution_; }
158 
159  int64_t GetBlockCount() const { return block_count_; }
160 
161  std::unordered_map<std::string, core::Dtype> GetAttrDtypeMap() const {
162  return attr_dtype_map_;
163  }
164 
165  core::Device GetDevice() const { return device_; }
166 
167  std::shared_ptr<core::HashMap> GetBlockHashMap() { return block_hashmap_; }
168 
169  std::shared_ptr<core::HashMap> GetBlockHashMap() const {
170  return block_hashmap_;
171  }
172 
173 private:
174  float voxel_size_;
175 
176  float sdf_trunc_;
177 
178  int64_t block_resolution_;
179 
180  int64_t block_count_;
181 
182  std::unordered_map<std::string, core::Dtype> attr_dtype_map_;
183 
184  core::Device device_ = core::Device("CPU:0");
185 
193  std::pair<core::Tensor, core::Tensor> BufferRadiusNeighbors(
194  const core::Tensor &active_buf_indices);
195 
196  // Global hashmap
197  std::shared_ptr<core::HashMap> block_hashmap_;
198 
199  // Local hashmap for the `unique` operation of input points
200  std::shared_ptr<core::HashMap> point_hashmap_;
201 
202  core::Tensor active_block_coords_;
203 };
204 } // namespace geometry
205 } // namespace t
206 } // namespace open3d
float GetVoxelSize() const
Definition: TSDFVoxelGrid.h:153
int height
Definition: FilePCD.cpp:72
~TSDFVoxelGrid()
Definition: TSDFVoxelGrid.h:75
HashBackendType
Definition: HashMap.h:38
std::unordered_map< std::string, core::Dtype > GetAttrDtypeMap() const
Definition: TSDFVoxelGrid.h:161
int64_t GetBlockResolution() const
Definition: TSDFVoxelGrid.h:157
A triangle mesh contains vertices and triangles.
Definition: TriangleMesh.h:106
SurfaceMaskCode
Definition: TSDFVoxelGrid.h:92
const Dtype Float32
Definition: Dtype.cpp:61
TSDFVoxelGrid Clone() const
Clone TSDFVoxelGrid on the same device.
Definition: TSDFVoxelGrid.h:151
The Image class stores image with customizable rows, cols, channels, dtype and device.
Definition: Image.h:48
math::float4 color
Definition: LineSetBuffers.cpp:64
const Dtype UInt16
Definition: Dtype.cpp:68
core::Device GetDevice() const
Definition: TSDFVoxelGrid.h:165
Definition: Device.h:39
A point cloud contains a list of 3D points.
Definition: PointCloud.h:95
Definition: TSDFVoxelGrid.h:60
void ExtractSurfacePoints(const core::Tensor &block_indices, const core::Tensor &nb_block_indices, const core::Tensor &nb_block_masks, const core::Tensor &block_keys, const core::Tensor &block_values, core::Tensor &points, utility::optional< std::reference_wrapper< core::Tensor >> normals, utility::optional< std::reference_wrapper< core::Tensor >> colors, int64_t block_resolution, float voxel_size, float weight_threshold, int &valid_size)
Definition: TSDFVoxelGrid.cpp:196
Definition: PinholeCameraIntrinsic.cpp:35
void To(const core::Tensor &src_im, core::Tensor &dst_im, double scale, double offset)
Definition: IPPImage.cpp:46
void RayCast(std::shared_ptr< core::DeviceHashBackend > &hashmap, const core::Tensor &block_values, const core::Tensor &range_map, core::Tensor &vertex_map, core::Tensor &depth_map, core::Tensor &color_map, core::Tensor &normal_map, const core::Tensor &intrinsics, const core::Tensor &extrinsics, int h, int w, int64_t block_resolution, float voxel_size, float sdf_trunc, float depth_scale, float depth_min, float depth_max, float weight_threshold)
Definition: TSDFVoxelGrid.cpp:153
std::shared_ptr< core::HashMap > GetBlockHashMap() const
Definition: TSDFVoxelGrid.h:169
void ExtractSurfaceMesh(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 core::Tensor &block_values, core::Tensor &vertices, core::Tensor &triangles, utility::optional< std::reference_wrapper< core::Tensor >> vertex_normals, utility::optional< std::reference_wrapper< core::Tensor >> vertex_colors, int64_t block_resolution, float voxel_size, float weight_threshold, int &vertex_count)
Definition: TSDFVoxelGrid.cpp:231
float GetSDFTrunc() const
Definition: TSDFVoxelGrid.h:155
void Integrate(const core::Tensor &depth, const core::Tensor &color, const core::Tensor &block_indices, const core::Tensor &block_keys, core::Tensor &block_values, const core::Tensor &intrinsics, const core::Tensor &extrinsics, int64_t resolution, float voxel_size, float sdf_trunc, float depth_scale, float depth_max)
Definition: TSDFVoxelGrid.cpp:65
Definition: ColorMap.h:35
int64_t GetBlockCount() const
Definition: TSDFVoxelGrid.h:159
std::shared_ptr< core::HashMap > GetBlockHashMap()
Definition: TSDFVoxelGrid.h:167
int width
Definition: FilePCD.cpp:71
Definition: TSDFVoxelGridIO.cpp:40