Open3D (C++ API)  0.14.1
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
math::float4 color
Definition: LineSetBuffers.cpp:64
Definition: Device.h:39
Definition: Tensor.h:50
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: TSDFVoxelGrid.h:60
std::shared_ptr< core::HashMap > GetBlockHashMap() const
Definition: TSDFVoxelGrid.h:169
core::Device GetDevice() const
Definition: TSDFVoxelGrid.h:165
~TSDFVoxelGrid()
Definition: TSDFVoxelGrid.h:75
std::shared_ptr< core::HashMap > GetBlockHashMap()
Definition: TSDFVoxelGrid.h:167
SurfaceMaskCode
Definition: TSDFVoxelGrid.h:92
@ RangeMap
Definition: TSDFVoxelGrid.h:98
@ NormalMap
Definition: TSDFVoxelGrid.h:97
@ VertexMap
Definition: TSDFVoxelGrid.h:94
@ DepthMap
Definition: TSDFVoxelGrid.h:95
@ None
Definition: TSDFVoxelGrid.h:93
std::unordered_map< SurfaceMaskCode, core::Tensor > RayCast(const core::Tensor &intrinsics, const core::Tensor &extrinsics, int width, int height, float depth_scale=1000.0f, float depth_min=0.1f, float depth_max=3.0f, float weight_threshold=3.0f, int ray_cast_mask=SurfaceMaskCode::DepthMap|SurfaceMaskCode::ColorMap)
Definition: TSDFVoxelGrid.cpp:212
void Integrate(const Image &depth, const core::Tensor &intrinsics, const core::Tensor &extrinsics, float depth_scale=1000.0f, float depth_max=3.0f)
Depth-only integration.
Definition: TSDFVoxelGrid.cpp:109
int64_t GetBlockCount() const
Definition: TSDFVoxelGrid.h:159
TriangleMesh ExtractSurfaceMesh(int estimate_vertices=-1, float weight_threshold=3.0f, int surface_mask=SurfaceMaskCode::VertexMap|SurfaceMaskCode::NormalMap|SurfaceMaskCode::ColorMap)
Definition: TSDFVoxelGrid.cpp:317
PointCloud ExtractSurfacePoints(int estimate_number=-1, float weight_threshold=3.0f, int surface_mask=SurfaceMaskCode::VertexMap|SurfaceMaskCode::ColorMap)
Definition: TSDFVoxelGrid.cpp:272
int64_t GetBlockResolution() const
Definition: TSDFVoxelGrid.h:157
std::unordered_map< std::string, core::Dtype > GetAttrDtypeMap() const
Definition: TSDFVoxelGrid.h:161
float GetSDFTrunc() const
Definition: TSDFVoxelGrid.h:155
TSDFVoxelGrid(std::unordered_map< std::string, core::Dtype > attr_dtype_map={{"tsdf", core::Float32}, {"weight", core::UInt16}, {"color", core::UInt16}}, float voxel_size=3.0/512.0, float sdf_trunc=0.04, int64_t block_resolution=16, int64_t block_count=1000, const core::Device &device=core::Device("CPU:0"), const core::HashBackendType &backend=core::HashBackendType::Default)
Default Constructor.
Definition: TSDFVoxelGrid.cpp:37
float GetVoxelSize() const
Definition: TSDFVoxelGrid.h:153
TSDFVoxelGrid To(const core::Device &device, bool copy=false) const
Definition: TSDFVoxelGrid.cpp:372
TSDFVoxelGrid Clone() const
Clone TSDFVoxelGrid on the same device.
Definition: TSDFVoxelGrid.h:151
A triangle mesh contains vertices and triangles.
Definition: TriangleMesh.h:106
Definition: TSDFVoxelGridIO.cpp:40
Definition: ColorMap.h:35
int width
Definition: FilePCD.cpp:71
int height
Definition: FilePCD.cpp:72
const Dtype UInt16
Definition: Dtype.cpp:68
HashBackendType
Definition: HashMap.h:38
const Dtype Float32
Definition: Dtype.cpp:61
Definition: PinholeCameraIntrinsic.cpp:35