ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Transform.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 
13 
14 namespace cloudViewer {
15 namespace t {
16 namespace geometry {
17 namespace kernel {
18 namespace transform {
19 
20 void TransformPoints(const core::Tensor& transformation, core::Tensor& points) {
22  core::AssertTensorShape(transformation, {4, 4});
23 
24  core::Tensor points_contiguous = points.Contiguous();
25  core::Tensor transformation_contiguous =
26  transformation.To(points.GetDevice(), points.GetDtype())
27  .Contiguous();
28 
29  if (points.IsCPU()) {
30  TransformPointsCPU(transformation_contiguous, points_contiguous);
31  } else if (points.IsCUDA()) {
32  CUDA_CALL(TransformPointsCUDA, transformation_contiguous,
33  points_contiguous);
34  } else {
35  utility::LogError("Unimplemented device");
36  }
37 
38  points = points_contiguous;
39 }
40 
41 void TransformNormals(const core::Tensor& transformation,
44  core::AssertTensorShape(transformation, {4, 4});
45 
46  core::Tensor normals_contiguous = normals.Contiguous();
47  core::Tensor transformation_contiguous =
48  transformation.To(normals.GetDevice(), normals.GetDtype())
49  .Contiguous();
50 
51  if (normals.IsCPU()) {
52  TransformNormalsCPU(transformation_contiguous, normals_contiguous);
53  } else if (normals.IsCUDA()) {
54  CUDA_CALL(TransformNormalsCUDA, transformation_contiguous,
55  normals_contiguous);
56  } else {
57  utility::LogError("Unimplemented device");
58  }
59 
60  normals = normals_contiguous;
61 }
62 
63 void RotatePoints(const core::Tensor& R,
65  const core::Tensor& center) {
67  core::AssertTensorShape(R, {3, 3});
68  core::AssertTensorShape(center, {3});
69 
70  core::Tensor points_contiguous = points.Contiguous();
71  core::Tensor R_contiguous =
72  R.To(points.GetDevice(), points.GetDtype()).Contiguous();
73  core::Tensor center_contiguous =
74  center.To(points.GetDevice(), points.GetDtype()).Contiguous();
75 
76  if (points.IsCPU()) {
77  RotatePointsCPU(R_contiguous, points_contiguous, center_contiguous);
78  } else if (points.IsCUDA()) {
79  CUDA_CALL(RotatePointsCUDA, R_contiguous, points_contiguous,
80  center_contiguous);
81  } else {
82  utility::LogError("Unimplemented device");
83  }
84 
85  points = points_contiguous;
86 }
87 
90  core::AssertTensorShape(R, {3, 3});
91 
92  core::Tensor normals_contiguous = normals.Contiguous();
93  core::Tensor R_contiguous =
94  R.To(normals.GetDevice(), normals.GetDtype()).Contiguous();
95 
96  if (normals.IsCPU()) {
97  RotateNormalsCPU(R_contiguous, normals_contiguous);
98  } else if (normals.IsCUDA()) {
99  CUDA_CALL(RotateNormalsCUDA, R_contiguous, normals_contiguous);
100  } else {
101  utility::LogError("Unimplemented device");
102  }
103 
104  normals = normals_contiguous;
105 }
106 
107 } // namespace transform
108 } // namespace kernel
109 } // namespace geometry
110 } // namespace t
111 } // namespace cloudViewer
Common CUDA utilities.
#define CUDA_CALL(cuda_function,...)
Definition: CUDAUtils.h:49
int points
#define AssertTensorShape(tensor,...)
Definition: TensorCheck.h:61
Tensor Contiguous() const
Definition: Tensor.cpp:772
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:739
double normals[3]
#define LogError(...)
Definition: Logging.h:60
void RotatePointsCPU(const core::Tensor &R, core::Tensor &points, const core::Tensor &center)
void TransformNormals(const core::Tensor &transformation, core::Tensor &normals)
Definition: Transform.cpp:41
void TransformPoints(const core::Tensor &transformation, core::Tensor &points)
Definition: Transform.cpp:20
void RotatePoints(const core::Tensor &R, core::Tensor &points, const core::Tensor &center)
Definition: Transform.cpp:63
void RotateNormals(const core::Tensor &R, core::Tensor &normals)
Definition: Transform.cpp:88
void RotateNormalsCPU(const core::Tensor &R, core::Tensor &normals)
void TransformNormalsCPU(const core::Tensor &transformation, core::Tensor &normals)
void TransformPointsCPU(const core::Tensor &transformation, core::Tensor &points)
Definition: TransformImpl.h:95
constexpr nullopt_t nullopt
Definition: Optional.h:136
Generic file read and write utility for python interface.