Open3D (C++ API)  0.19.0
Loading...
Searching...
No Matches
TransformImpl.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2024 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
10#include "open3d/core/Tensor.h"
11
12namespace open3d {
13namespace t {
14namespace geometry {
15namespace kernel {
16namespace transform {
17
18template <typename scalar_t>
20 const scalar_t* transformation_ptr, scalar_t* points_ptr) {
21 scalar_t x[4] = {transformation_ptr[0] * points_ptr[0] +
22 transformation_ptr[1] * points_ptr[1] +
23 transformation_ptr[2] * points_ptr[2] +
24 transformation_ptr[3],
25 transformation_ptr[4] * points_ptr[0] +
26 transformation_ptr[5] * points_ptr[1] +
27 transformation_ptr[6] * points_ptr[2] +
28 transformation_ptr[7],
29 transformation_ptr[8] * points_ptr[0] +
30 transformation_ptr[9] * points_ptr[1] +
31 transformation_ptr[10] * points_ptr[2] +
32 transformation_ptr[11],
33 transformation_ptr[12] * points_ptr[0] +
34 transformation_ptr[13] * points_ptr[1] +
35 transformation_ptr[14] * points_ptr[2] +
36 transformation_ptr[15]};
37
38 points_ptr[0] = x[0] / x[3];
39 points_ptr[1] = x[1] / x[3];
40 points_ptr[2] = x[2] / x[3];
41}
42
43template <typename scalar_t>
45 const scalar_t* transformation_ptr, scalar_t* normals_ptr) {
46 scalar_t x[3] = {transformation_ptr[0] * normals_ptr[0] +
47 transformation_ptr[1] * normals_ptr[1] +
48 transformation_ptr[2] * normals_ptr[2],
49 transformation_ptr[4] * normals_ptr[0] +
50 transformation_ptr[5] * normals_ptr[1] +
51 transformation_ptr[6] * normals_ptr[2],
52 transformation_ptr[8] * normals_ptr[0] +
53 transformation_ptr[9] * normals_ptr[1] +
54 transformation_ptr[10] * normals_ptr[2]};
55
56 normals_ptr[0] = x[0];
57 normals_ptr[1] = x[1];
58 normals_ptr[2] = x[2];
59}
60
61template <typename scalar_t>
63 const scalar_t* R_ptr, scalar_t* points_ptr, const scalar_t* center) {
64 scalar_t x[3] = {points_ptr[0] - center[0], points_ptr[1] - center[1],
65 points_ptr[2] - center[2]};
66
67 points_ptr[0] =
68 R_ptr[0] * x[0] + R_ptr[1] * x[1] + R_ptr[2] * x[2] + center[0];
69 points_ptr[1] =
70 R_ptr[3] * x[0] + R_ptr[4] * x[1] + R_ptr[5] * x[2] + center[1];
71 points_ptr[2] =
72 R_ptr[6] * x[0] + R_ptr[7] * x[1] + R_ptr[8] * x[2] + center[2];
73}
74
75template <typename scalar_t>
77 const scalar_t* R_ptr, scalar_t* normals_ptr) {
78 scalar_t x[3] = {R_ptr[0] * normals_ptr[0] + R_ptr[1] * normals_ptr[1] +
79 R_ptr[2] * normals_ptr[2],
80 R_ptr[3] * normals_ptr[0] + R_ptr[4] * normals_ptr[1] +
81 R_ptr[5] * normals_ptr[2],
82 R_ptr[6] * normals_ptr[0] + R_ptr[7] * normals_ptr[1] +
83 R_ptr[8] * normals_ptr[2]};
84
85 normals_ptr[0] = x[0];
86 normals_ptr[1] = x[1];
87 normals_ptr[2] = x[2];
88}
89
90#ifndef OPEN3D_SKIP_TRANSFORM_MAIN
91
92#ifdef __CUDACC__
93void TransformPointsCUDA
94#elif defined(SYCL_LANGUAGE_VERSION)
95void TransformPointsSYCL
96#else
98#endif
99 (const core::Tensor& transformation, core::Tensor& points) {
100 DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(points.GetDtype(), [&]() {
101 scalar_t* points_ptr = points.GetDataPtr<scalar_t>();
102 const scalar_t* transformation_ptr =
103 transformation.GetDataPtr<scalar_t>();
104
105 core::ParallelFor(transformation.GetDevice(), points.GetLength(),
106 [=] OPEN3D_DEVICE(int64_t workload_idx) {
107 TransformPointsKernel(
108 transformation_ptr,
109 points_ptr + 3 * workload_idx);
110 });
111 });
112}
113
114#ifdef __CUDACC__
115void TransformNormalsCUDA
116#elif defined(SYCL_LANGUAGE_VERSION)
117void TransformNormalsSYCL
118#else
120#endif
121 (const core::Tensor& transformation, core::Tensor& normals) {
122 DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(normals.GetDtype(), [&]() {
123 scalar_t* normals_ptr = normals.GetDataPtr<scalar_t>();
124 const scalar_t* transformation_ptr =
125 transformation.GetDataPtr<scalar_t>();
126
127 core::ParallelFor(transformation.GetDevice(), normals.GetLength(),
128 [=] OPEN3D_DEVICE(int64_t workload_idx) {
129 TransformNormalsKernel(
130 transformation_ptr,
131 normals_ptr + 3 * workload_idx);
132 });
133 });
134}
135
136#ifdef __CUDACC__
137void RotatePointsCUDA
138#elif defined(SYCL_LANGUAGE_VERSION)
139void RotatePointsSYCL
140#else
142#endif
143 (const core::Tensor& R,
145 const core::Tensor& center) {
146 DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(points.GetDtype(), [&]() {
147 scalar_t* points_ptr = points.GetDataPtr<scalar_t>();
148 const scalar_t* R_ptr = R.GetDataPtr<scalar_t>();
149 const scalar_t* center_ptr = center.GetDataPtr<scalar_t>();
150
151 core::ParallelFor(R.GetDevice(), points.GetLength(),
152 [=] OPEN3D_DEVICE(int64_t workload_idx) {
153 RotatePointsKernel(R_ptr,
154 points_ptr + 3 * workload_idx,
155 center_ptr);
156 });
157 });
158}
159
160#ifdef __CUDACC__
161void RotateNormalsCUDA
162#elif defined(SYCL_LANGUAGE_VERSION)
163void RotateNormalsSYCL
164#else
166#endif
167 (const core::Tensor& R, core::Tensor& normals) {
168 DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(normals.GetDtype(), [&]() {
169 scalar_t* normals_ptr = normals.GetDataPtr<scalar_t>();
170 const scalar_t* R_ptr = R.GetDataPtr<scalar_t>();
171
172 core::ParallelFor(R.GetDevice(), normals.GetLength(),
173 [=] OPEN3D_DEVICE(int64_t workload_idx) {
174 RotateNormalsKernel(
175 R_ptr, normals_ptr + 3 * workload_idx);
176 });
177 });
178}
179
180#endif // OPEN3D_SKIP_TRANSFORM_MAIN
181
182} // namespace transform
183} // namespace kernel
184} // namespace geometry
185} // namespace t
186} // namespace open3d
Common CUDA utilities.
#define OPEN3D_HOST_DEVICE
Definition CUDAUtils.h:43
#define OPEN3D_FORCE_INLINE
Definition CUDAUtils.h:42
#define DISPATCH_FLOAT_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition Dispatch.h:77
double t
Definition SurfaceReconstructionPoisson.cpp:172
Definition Tensor.h:32
int points
Definition FilePCD.cpp:55
void RotatePointsCPU(const core::Tensor &R, core::Tensor &points, const core::Tensor &center)
Definition TransformImpl.h:143
void TransformPointsCPU(const core::Tensor &transformation, core::Tensor &points)
Definition TransformImpl.h:99
void RotateNormalsCPU(const core::Tensor &R, core::Tensor &normals)
Definition TransformImpl.h:167
void TransformNormalsCPU(const core::Tensor &transformation, core::Tensor &normals)
Definition TransformImpl.h:121
OPEN3D_HOST_DEVICE OPEN3D_FORCE_INLINE void TransformNormalsKernel(const scalar_t *transformation_ptr, scalar_t *normals_ptr)
Definition TransformImpl.h:44
OPEN3D_HOST_DEVICE OPEN3D_FORCE_INLINE void TransformPointsKernel(const scalar_t *transformation_ptr, scalar_t *points_ptr)
Definition TransformImpl.h:19
OPEN3D_HOST_DEVICE OPEN3D_FORCE_INLINE void RotatePointsKernel(const scalar_t *R_ptr, scalar_t *points_ptr, const scalar_t *center)
Definition TransformImpl.h:62
OPEN3D_HOST_DEVICE OPEN3D_FORCE_INLINE void RotateNormalsKernel(const scalar_t *R_ptr, scalar_t *normals_ptr)
Definition TransformImpl.h:76
Definition PinholeCameraIntrinsic.cpp:16
const core::Tensor * normals
Definition TriangleMesh.cpp:2126