ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Model.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
17 
18 namespace cloudViewer {
19 namespace t {
20 namespace pipelines {
21 namespace slam {
22 
23 Model::Model(float voxel_size,
24  int block_resolution,
25  int est_block_count,
26  const core::Tensor& T_init,
27  const core::Device& device)
28  : voxel_grid_(std::vector<std::string>({"tsdf", "weight", "color"}),
29  std::vector<core::Dtype>(
31  std::vector<core::SizeVector>({{1}, {1}, {3}}),
32  voxel_size,
33  block_resolution,
34  est_block_count,
35  device),
36  T_frame_to_world_(T_init.To(core::Device("CPU:0"))) {}
37 
38 void Model::SynthesizeModelFrame(Frame& raycast_frame,
39  float depth_scale,
40  float depth_min,
41  float depth_max,
42  float trunc_voxel_multiplier,
43  bool enable_color,
44  float weight_threshold) {
45  if (weight_threshold < 0) {
46  weight_threshold = std::min(frame_id_ * 1.0f, 3.0f);
47  }
48 
49  auto result = voxel_grid_.RayCast(
50  frustum_block_coords_, raycast_frame.GetIntrinsics(),
52  raycast_frame.GetWidth(), raycast_frame.GetHeight(),
53  {"depth", "color"}, depth_scale, depth_min, depth_max,
54  weight_threshold, trunc_voxel_multiplier);
55  raycast_frame.SetData("depth", result["depth"]);
56 
57  if (enable_color) {
58  raycast_frame.SetData("color", result["color"]);
59  } else if (raycast_frame.GetData("color").NumElements() == 0) {
60  // Put a dummy RGB frame to enable RGBD odometry in TrackFrameToModel
61  raycast_frame.SetData("color",
62  core::Tensor({raycast_frame.GetHeight(),
63  raycast_frame.GetWidth(), 3},
65  }
66 }
67 
69  const Frame& input_frame,
70  const Frame& raycast_frame,
71  float depth_scale,
72  float depth_max,
73  float depth_diff,
74  const odometry::Method method,
75  const std::vector<odometry::OdometryConvergenceCriteria>& criteria) {
76  // TODO: Expose init_source_to_target as param, and make the input sequence
77  // consistent with RGBDOdometryMultiScale.
78  const static core::Tensor init_source_to_target =
80 
82  t::geometry::RGBDImage(input_frame.GetDataAsImage("color"),
83  input_frame.GetDataAsImage("depth")),
84  t::geometry::RGBDImage(raycast_frame.GetDataAsImage("color"),
85  raycast_frame.GetDataAsImage("depth")),
86  raycast_frame.GetIntrinsics(), init_source_to_target, depth_scale,
87  depth_max, criteria, method,
88  odometry::OdometryLossParams(depth_diff));
89 }
90 
91 void Model::Integrate(const Frame& input_frame,
92  float depth_scale,
93  float depth_max,
94  float trunc_voxel_multiplier) {
95  t::geometry::Image depth = input_frame.GetDataAsImage("depth");
96  t::geometry::Image color = input_frame.GetDataAsImage("color");
97  core::Tensor intrinsic = input_frame.GetIntrinsics();
98  core::Tensor extrinsic =
101  depth, intrinsic, extrinsic, depth_scale, depth_max,
102  trunc_voxel_multiplier);
104  extrinsic, depth_scale, depth_max,
105  trunc_voxel_multiplier);
106 }
107 
109  int estimated_number) {
110  return voxel_grid_.ExtractPointCloud(weight_threshold, estimated_number);
111 }
112 
114  int estimated_number) {
115  return voxel_grid_.ExtractTriangleMesh(weight_threshold, estimated_number);
116 }
117 
119 
120 } // namespace slam
121 } // namespace pipelines
122 } // namespace t
123 } // namespace cloudViewer
math::float4 color
core::Tensor result
Definition: VtkUtils.cpp:76
static Tensor Eye(int64_t n, Dtype dtype, const Device &device)
Create an identity matrix of size n x n.
Definition: Tensor.cpp:418
int64_t NumElements() const
Definition: Tensor.h:1170
The Image class stores image with customizable rows, cols, channels, dtype and device.
Definition: Image.h:29
A point cloud contains a list of 3D points.
Definition: PointCloud.h:82
RGBDImage A pair of color and depth images.
Definition: RGBDImage.h:21
A triangle mesh contains vertices and triangles.
Definition: TriangleMesh.h:98
PointCloud ExtractPointCloud(float weight_threshold=3.0f, int estimated_point_number=-1)
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)
TriangleMesh ExtractTriangleMesh(float weight_threshold=3.0f, int estimated_vertex_numer=-1)
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)
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)
Frame is a container class storing an intrinsic matrix and several 2D tensors, from depth map,...
Definition: Frame.h:21
core::Tensor GetData(const std::string &name) const
Definition: Frame.h:43
core::Tensor GetIntrinsics() const
Definition: Frame.h:38
void SetData(const std::string &name, const core::Tensor &data)
Definition: Frame.h:40
t::geometry::Image GetDataAsImage(const std::string &name) const
Definition: Frame.h:58
void SynthesizeModelFrame(Frame &raycast_frame, float depth_scale=1000.0, float depth_min=0.1, float depth_max=3.0, float trunc_voxel_multiplier=8.0, bool enable_color=true, float weight_threshold=-1.0)
Definition: Model.cpp:38
odometry::OdometryResult TrackFrameToModel(const Frame &input_frame, const Frame &raycast_frame, float depth_scale=1000.0, float depth_max=3.0, float depth_diff=0.07, odometry::Method method=odometry::Method::PointToPlane, const std::vector< odometry::OdometryConvergenceCriteria > &criteria={6, 3, 1})
Definition: Model.cpp:68
core::Tensor GetCurrentFramePose() const
Definition: Model.h:36
t::geometry::TriangleMesh ExtractTriangleMesh(float weight_threshold=3.0f, int estimated_number=-1)
Definition: Model.cpp:113
void Integrate(const Frame &input_frame, float depth_scale=1000.0, float depth_max=3.0, float trunc_voxel_multiplier=8.0f)
Definition: Model.cpp:91
core::HashMap GetHashMap()
Get block hashmap int the VoxelBlockGrid.
Definition: Model.cpp:118
t::geometry::PointCloud ExtractPointCloud(float weight_threshold=3.0f, int estimated_number=-1)
Definition: Model.cpp:108
t::geometry::VoxelBlockGrid voxel_grid_
Maintained volumetric map.
Definition: Model.h:122
core::Tensor frustum_block_coords_
Active block coordinates from prior integration.
Definition: Model.h:125
int min(int a, int b)
Definition: cutil_math.h:53
const Dtype Float64
Definition: Dtype.cpp:43
const Dtype UInt16
Definition: Dtype.cpp:49
const Dtype Float32
Definition: Dtype.cpp:42
core::Tensor InverseTransformation(const core::Tensor &T)
TODO(wei): find a proper place for such functionalities.
Definition: Utility.h:77
OdometryResult RGBDOdometryMultiScale(const RGBDImage &source, const RGBDImage &target, const Tensor &intrinsics, const Tensor &init_source_to_target, const float depth_scale, const float depth_max, const std::vector< OdometryConvergenceCriteria > &criteria, const Method method, const OdometryLossParams &params)
Create an RGBD image pyramid given the original source and target RGBD images, and perform hierarchic...
Generic file read and write utility for python interface.
Definition: Eigen.h:85