ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
FillInLinearSystem.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 
12 
13 namespace cloudViewer {
14 namespace t {
15 namespace pipelines {
16 namespace kernel {
17 
19  core::Tensor &Atb,
20  core::Tensor &residual,
21  const core::Tensor &Ti_ps,
22  const core::Tensor &Tj_qs,
23  const core::Tensor &Ri_normal_ps,
24  int i,
25  int j,
26  float threshold) {
33 
34  core::Device device = AtA.GetDevice();
35  if (Atb.GetDevice() != device) {
36  utility::LogError("AtA should have the same device as Atb.");
37  }
38  if (Ti_ps.GetDevice() != device) {
40  "Points i should have the same device as the linear system.");
41  }
42  if (Tj_qs.GetDevice() != device) {
44  "Points j should have the same device as the linear system.");
45  }
46  if (Ri_normal_ps.GetDevice() != device) {
48  "Normals i should have the same device as the linear system.");
49  }
50 
51  if (AtA.IsCPU()) {
52  FillInRigidAlignmentTermCPU(AtA, Atb, residual, Ti_ps, Tj_qs,
53  Ri_normal_ps, i, j, threshold);
54 
55  } else if (AtA.IsCUDA()) {
56 #ifdef BUILD_CUDA_MODULE
57  core::CUDAScopedDevice scoped_device(AtA.GetDevice());
58  FillInRigidAlignmentTermCUDA(AtA, Atb, residual, Ti_ps, Tj_qs,
59  Ri_normal_ps, i, j, threshold);
60 
61 #else
62  utility::LogError("Not compiled with CUDA, but CUDA device is used.");
63 #endif
64  } else {
65  utility::LogError("Unimplemented device");
66  }
67 }
68 
70  core::Tensor &Atb,
71  core::Tensor &residual,
72  const core::Tensor &Ti_ps,
73  const core::Tensor &Tj_qs,
74  const core::Tensor &normal_ps,
75  const core::Tensor &Ri_normal_ps,
76  const core::Tensor &RjT_Ri_normal_ps,
77  const core::Tensor &cgrid_idx_ps,
78  const core::Tensor &cgrid_idx_qs,
79  const core::Tensor &cgrid_ratio_qs,
80  const core::Tensor &cgrid_ratio_ps,
81  int i,
82  int j,
83  int n,
84  float threshold) {
92  core::AssertTensorDtype(RjT_Ri_normal_ps, core::Float32);
93 
94  core::Device device = AtA.GetDevice();
95  if (Atb.GetDevice() != device) {
96  utility::LogError("AtA should have the same device as Atb.");
97  }
98  if (Ti_ps.GetDevice() != device) {
100  "Points i should have the same device as the linear system.");
101  }
102  if (Tj_qs.GetDevice() != device) {
104  "Points j should have the same device as the linear system.");
105  }
106  if (Ri_normal_ps.GetDevice() != device) {
108  "Normals i should have the same device as the linear system.");
109  }
110 
111  if (AtA.IsCPU()) {
112  FillInSLACAlignmentTermCPU(AtA, Atb, residual, Ti_ps, Tj_qs, normal_ps,
113  Ri_normal_ps, RjT_Ri_normal_ps, cgrid_idx_ps,
114  cgrid_idx_qs, cgrid_ratio_ps, cgrid_ratio_qs,
115  i, j, n, threshold);
116 
117  } else if (AtA.IsCUDA()) {
118 #ifdef BUILD_CUDA_MODULE
119  core::CUDAScopedDevice scoped_device(AtA.GetDevice());
120  FillInSLACAlignmentTermCUDA(AtA, Atb, residual, Ti_ps, Tj_qs, normal_ps,
121  Ri_normal_ps, RjT_Ri_normal_ps,
122  cgrid_idx_ps, cgrid_idx_qs, cgrid_ratio_ps,
123  cgrid_ratio_qs, i, j, n, threshold);
124 
125 #else
126  utility::LogError("Not compiled with CUDA, but CUDA device is used.");
127 #endif
128  } else {
129  utility::LogError("Unimplemented device");
130  }
131 }
132 
134  core::Tensor &Atb,
135  core::Tensor &residual,
136  const core::Tensor &grid_idx,
137  const core::Tensor &grid_nbs_idx,
138  const core::Tensor &grid_nbs_mask,
139  const core::Tensor &positions_init,
140  const core::Tensor &positions_curr,
141  float weight,
142  int n,
143  int anchor_idx) {
147 
148  core::Device device = AtA.GetDevice();
149  if (Atb.GetDevice() != device) {
150  utility::LogError("AtA should have the same device as Atb.");
151  }
152 
153  if (AtA.IsCPU()) {
154  FillInSLACRegularizerTermCPU(AtA, Atb, residual, grid_idx, grid_nbs_idx,
155  grid_nbs_mask, positions_init,
156  positions_curr, weight, n, anchor_idx);
157 
158  } else if (AtA.IsCUDA()) {
159 #ifdef BUILD_CUDA_MODULE
160  core::CUDAScopedDevice scoped_device(AtA.GetDevice());
161  FillInSLACRegularizerTermCUDA(
162  AtA, Atb, residual, grid_idx, grid_nbs_idx, grid_nbs_mask,
163  positions_init, positions_curr, weight, n, anchor_idx);
164 #else
165  utility::LogError("Not compiled with CUDA, but CUDA device is used.");
166 #endif
167  } else {
168  utility::LogError("Unimplemented device");
169  }
170 }
171 
172 } // namespace kernel
173 } // namespace pipelines
174 } // namespace t
175 } // namespace cloudViewer
Common CUDA utilities.
#define AssertTensorDtype(tensor,...)
Definition: TensorCheck.h:21
When CUDA is not enabled, this is a dummy class.
Definition: CUDAUtils.h:214
bool IsCUDA() const
Definition: Device.h:99
bool IsCPU() const
Definition: Device.h:95
Device GetDevice() const override
Definition: Tensor.cpp:1435
#define LogError(...)
Definition: Logging.h:60
const Dtype Float32
Definition: Dtype.cpp:42
void FillInRigidAlignmentTerm(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &Ti_ps, const core::Tensor &Tj_qs, const core::Tensor &Ri_normal_ps, int i, int j, float threshold)
void FillInSLACAlignmentTermCPU(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &Ti_qs, const core::Tensor &Tj_qs, const core::Tensor &normal_ps, const core::Tensor &Ri_normal_ps, const core::Tensor &RjT_Ri_normal_ps, const core::Tensor &cgrid_idx_ps, const core::Tensor &cgrid_idx_qs, const core::Tensor &cgrid_ratio_qs, const core::Tensor &cgrid_ratio_ps, int i, int j, int n, float threshold)
void FillInSLACRegularizerTermCPU(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &grid_idx, const core::Tensor &grid_nbs_idx, const core::Tensor &grid_nbs_mask, const core::Tensor &positions_init, const core::Tensor &positions_curr, float weight, int n, int anchor_idx)
void FillInSLACRegularizerTerm(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &grid_idx, const core::Tensor &grid_nbs_idx, const core::Tensor &grid_nbs_mask, const core::Tensor &positions_init, const core::Tensor &positions_curr, float weight, int n, int anchor_idx)
void FillInSLACAlignmentTerm(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &Ti_ps, const core::Tensor &Tj_qs, const core::Tensor &normal_ps, const core::Tensor &Ri_normal_ps, const core::Tensor &RjT_Ri_normal_ps, const core::Tensor &cgrid_idx_ps, const core::Tensor &cgrid_idx_qs, const core::Tensor &cgrid_ratio_qs, const core::Tensor &cgrid_ratio_ps, int i, int j, int n, float threshold)
void FillInRigidAlignmentTermCPU(core::Tensor &AtA, core::Tensor &Atb, core::Tensor &residual, const core::Tensor &Ti_qs, const core::Tensor &Tj_qs, const core::Tensor &Ri_normal_ps, int i, int j, float threshold)
Generic file read and write utility for python interface.