Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ComputeTransformImpl.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 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 // Private header. Do not include in Open3d.h.
28 
29 #pragma once
30 
31 #include "open3d/core/CUDAUtils.h"
32 #include "open3d/core/Tensor.h"
33 
34 namespace open3d {
35 namespace t {
36 namespace pipelines {
37 namespace kernel {
38 
39 void ComputePosePointToPlaneCPU(const float *source_points_ptr,
40  const float *target_points_ptr,
41  const float *target_normals_ptr,
42  const int64_t *correspondences_first,
43  const int64_t *correspondences_second,
44  const int n,
45  core::Tensor &pose,
46  const core::Dtype &dtype,
47  const core::Device &device);
48 
49 #ifdef BUILD_CUDA_MODULE
50 void ComputePosePointToPlaneCUDA(const float *source_points_ptr,
51  const float *target_points_ptr,
52  const float *target_normals_ptr,
53  const int64_t *correspondences_first,
54  const int64_t *correspondences_second,
55  const int n,
56  core::Tensor &pose,
57  const core::Dtype &dtype,
58  const core::Device &device);
59 #endif
60 
61 void ComputeRtPointToPointCPU(const float *source_points_ptr,
62  const float *target_points_ptr,
63  const int64_t *correspondences_first,
64  const int64_t *correspondences_second,
65  const int n,
66  core::Tensor &R,
67  core::Tensor &t,
68  const core::Dtype dtype,
69  const core::Device device);
70 
72  int64_t workload_idx,
73  const float *source_points_ptr,
74  const float *target_points_ptr,
75  const float *target_normals_ptr,
76  const int64_t *correspondence_first,
77  const int64_t *correspondence_second,
78  float *J_ij,
79  float &r) {
80  // TODO (@rishabh): Pass correspondence without eliminating -1
81  // in registration::GetRegistationResultAndCorrespondences,
82  // and directly check if valid (index != -1) here.
83  // In that case, only use correspondence_second as index for
84  // target, and workload_idx as index for source pointcloud.
85 
86  const int64_t source_idx = 3 * correspondence_first[workload_idx];
87  const int64_t target_idx = 3 * correspondence_second[workload_idx];
88 
89  const float &sx = source_points_ptr[source_idx + 0];
90  const float &sy = source_points_ptr[source_idx + 1];
91  const float &sz = source_points_ptr[source_idx + 2];
92  const float &tx = target_points_ptr[target_idx + 0];
93  const float &ty = target_points_ptr[target_idx + 1];
94  const float &tz = target_points_ptr[target_idx + 2];
95  const float &nx = target_normals_ptr[target_idx + 0];
96  const float &ny = target_normals_ptr[target_idx + 1];
97  const float &nz = target_normals_ptr[target_idx + 2];
98 
99  r = (sx - tx) * nx + (sy - ty) * ny + (sz - tz) * nz;
100  J_ij[0] = nz * sy - ny * sz;
101  J_ij[1] = nx * sz - nz * sx;
102  J_ij[2] = ny * sx - nx * sy;
103  J_ij[3] = nx;
104  J_ij[4] = ny;
105  J_ij[5] = nz;
106 
107  return true;
108 }
109 
110 } // namespace kernel
111 } // namespace pipelines
112 } // namespace t
113 } // namespace open3d
OPEN3D_HOST_DEVICE bool GetJacobianPointToPlane(int64_t workload_idx, const float *source_points_ptr, const float *target_points_ptr, const float *target_normals_ptr, const int64_t *correspondence_first, const int64_t *correspondence_second, float *J_ij, float &r)
Definition: ComputeTransformImpl.h:71
#define OPEN3D_HOST_DEVICE
Definition: CUDAUtils.h:56
Definition: PinholeCameraIntrinsic.cpp:35
void ComputeRtPointToPointCPU(const float *source_points_ptr, const float *target_points_ptr, const int64_t *correspondences_first, const int64_t *correspondences_second, const int n, core::Tensor &R, core::Tensor &t, const core::Dtype dtype, const core::Device device)
Definition: ComputeTransformCPU.cpp:118
void ComputePosePointToPlaneCPU(const float *source_points_ptr, const float *target_points_ptr, const float *target_normals_ptr, const int64_t *correspondences_first, const int64_t *correspondences_second, const int n, core::Tensor &pose, const core::Dtype &dtype, const core::Device &device)
Definition: ComputeTransformCPU.cpp:44
Common CUDA utilities.