38 #ifndef PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_POINT_TO_PLANE_LLS_HPP_
39 #define PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_POINT_TO_PLANE_LLS_HPP_
42 template <
typename Po
intSource,
typename Po
intTarget>
inline void
46 Eigen::Matrix4f &transformation_matrix)
48 size_t nr_points = cloud_src.
points.size ();
49 if (cloud_tgt.
points.size () != nr_points)
51 PCL_ERROR (
"[pcl::TransformationSVD::estimateRigidTransformation] Number or points in source (%zu) differs than target (%zu)!\n", nr_points, cloud_tgt.
points.size ());
56 Eigen::MatrixXf A (nr_points, 6);
57 Eigen::MatrixXf b (nr_points, 1);
58 for (
size_t i = 0; i < nr_points; ++i)
60 const float & sx = cloud_src.
points[i].x;
61 const float & sy = cloud_src.
points[i].y;
62 const float & sz = cloud_src.
points[i].z;
63 const float & dx = cloud_tgt.
points[i].x;
64 const float & dy = cloud_tgt.
points[i].y;
65 const float & dz = cloud_tgt.
points[i].z;
66 const float & nx = cloud_tgt.
points[i].normal[0];
67 const float & ny = cloud_tgt.
points[i].normal[1];
68 const float & nz = cloud_tgt.
points[i].normal[2];
69 A (i, 0) = nz*sy - ny*sz;
70 A (i, 1) = nx*sz - nz*sx;
71 A (i, 2) = ny*sx - nx*sy;
75 b (i, 0) = nx*dx + ny*dy + nz*dz - nx*sx - ny*sy - nz*sz;
79 Eigen::VectorXf x = A.colPivHouseholderQr ().solve (b);
82 constructTransformationMatrix (x (0), x (1), x (2), x (3), x (4), x (5), transformation_matrix);
87 template <
typename Po
intSource,
typename Po
intTarget>
void
90 const std::vector<int> &indices_src,
92 Eigen::Matrix4f &transformation_matrix)
94 size_t nr_points = indices_src.size ();
95 if (cloud_tgt.
points.size () != nr_points)
97 PCL_ERROR (
"[pcl::TransformationSVD::estimateRigidTransformation] Number or points in source (%zu) differs than target (%zu)!\n", indices_src.size (), cloud_tgt.
points.size ());
102 Eigen::MatrixXf A (nr_points, 6);
103 Eigen::MatrixXf b (nr_points, 1);
104 for (
size_t i = 0; i < nr_points; ++i)
106 const float & sx = cloud_src.
points[indices_src[i]].x;
107 const float & sy = cloud_src.
points[indices_src[i]].y;
108 const float & sz = cloud_src.
points[indices_src[i]].z;
109 const float & dx = cloud_tgt.
points[i].x;
110 const float & dy = cloud_tgt.
points[i].y;
111 const float & dz = cloud_tgt.
points[i].z;
112 const float & nx = cloud_tgt.
points[i].normal[0];
113 const float & ny = cloud_tgt.
points[i].normal[1];
114 const float & nz = cloud_tgt.
points[i].normal[2];
115 A (i, 0) = nz*sy - ny*sz;
116 A (i, 1) = nx*sz - nz*sx;
117 A (i, 2) = ny*sx - nx*sy;
121 b (i, 0) = nx*dx + ny*dy + nz*dz - nx*sx - ny*sy - nz*sz;
125 Eigen::VectorXf x = A.colPivHouseholderQr ().solve (b);
128 constructTransformationMatrix (x (0), x (1), x (2), x (3), x (4), x (5), transformation_matrix);
133 template <
typename Po
intSource,
typename Po
intTarget>
inline void
136 const std::vector<int> &indices_src,
138 const std::vector<int> &indices_tgt,
139 Eigen::Matrix4f &transformation_matrix)
141 size_t nr_points = indices_src.size ();
142 if (indices_tgt.size () != nr_points)
144 PCL_ERROR (
"[pcl::TransformationEstimationPointToPlaneLLS::estimateRigidTransformation] Number or points in source (%zu) differs than target (%zu)!\n", indices_src.size (), indices_tgt.size ());
149 Eigen::MatrixXf A (nr_points, 6);
150 Eigen::MatrixXf b (nr_points, 1);
151 for (
size_t i = 0; i < nr_points; ++i)
153 const float & sx = cloud_src.
points[indices_src[i]].x;
154 const float & sy = cloud_src.
points[indices_src[i]].y;
155 const float & sz = cloud_src.
points[indices_src[i]].z;
156 const float & dx = cloud_tgt.
points[indices_tgt[i]].x;
157 const float & dy = cloud_tgt.
points[indices_tgt[i]].y;
158 const float & dz = cloud_tgt.
points[indices_tgt[i]].z;
159 const float & nx = cloud_tgt.
points[indices_tgt[i]].normal[0];
160 const float & ny = cloud_tgt.
points[indices_tgt[i]].normal[1];
161 const float & nz = cloud_tgt.
points[indices_tgt[i]].normal[2];
162 A (i, 0) = nz*sy - ny*sz;
163 A (i, 1) = nx*sz - nz*sx;
164 A (i, 2) = ny*sx - nx*sy;
168 b (i, 0) = nx*dx + ny*dy + nz*dz - nx*sx - ny*sy - nz*sz;
172 Eigen::VectorXf x = A.colPivHouseholderQr ().solve (b);
175 constructTransformationMatrix (x (0), x (1), x (2), x (3), x (4), x (5), transformation_matrix);
179 template <
typename Po
intSource,
typename Po
intTarget>
inline void
184 Eigen::Matrix4f &transformation_matrix)
186 size_t nr_points = correspondences.size ();
189 Eigen::MatrixXf A (nr_points, 6);
190 Eigen::MatrixXf b (nr_points, 1);
191 for (
size_t i = 0; i < nr_points; ++i)
193 const int & src_idx = correspondences[i].index_query;
194 const int & tgt_idx = correspondences[i].index_match;
195 const float & sx = cloud_src.
points[src_idx].x;
196 const float & sy = cloud_src.
points[src_idx].y;
197 const float & sz = cloud_src.
points[src_idx].z;
198 const float & dx = cloud_tgt.
points[tgt_idx].x;
199 const float & dy = cloud_tgt.
points[tgt_idx].y;
200 const float & dz = cloud_tgt.
points[tgt_idx].z;
201 const float & nx = cloud_tgt.
points[tgt_idx].normal[0];
202 const float & ny = cloud_tgt.
points[tgt_idx].normal[1];
203 const float & nz = cloud_tgt.
points[tgt_idx].normal[2];
204 A (i, 0) = nz*sy - ny*sz;
205 A (i, 1) = nx*sz - nz*sx;
206 A (i, 2) = ny*sx - nx*sy;
210 b (i, 0) = nx*dx + ny*dy + nz*dz - nx*sx - ny*sy - nz*sz;
214 Eigen::VectorXf x = A.colPivHouseholderQr ().solve (b);
217 constructTransformationMatrix (x (0), x (1), x (2), x (3), x (4), x (5), transformation_matrix);
220 template <
typename Po
intSource,
typename Po
intTarget>
inline void
223 const float & tx,
const float & ty,
const float & tz,
224 Eigen::Matrix4f &transformation_matrix)
228 transformation_matrix = Eigen::Matrix4f::Zero ();
229 transformation_matrix (0, 0) = cosf (gamma) * cosf (beta);
230 transformation_matrix (0, 1) = -sinf (gamma) * cosf (alpha) + cosf (gamma) * sinf (beta) * sinf (alpha);
231 transformation_matrix (0, 2) = sinf (gamma) * sinf (alpha) + cosf (gamma) * sinf (beta) * cosf (alpha);
232 transformation_matrix (1, 0) = sinf (gamma) * cosf (beta);
233 transformation_matrix (1, 1) = cosf (gamma) * cosf (alpha) + sinf (gamma) * sinf (beta) * sinf (alpha);
234 transformation_matrix (1, 2) = -cosf (gamma) * sinf (alpha) + sinf (gamma) * sinf (beta) * cosf (alpha);
235 transformation_matrix (2, 0) = -sinf (beta);
236 transformation_matrix (2, 1) = cosf (beta) * sinf (alpha);
237 transformation_matrix (2, 2) = cosf (beta) * cosf (alpha);
239 transformation_matrix (0, 3) = tx;
240 transformation_matrix (1, 3) = ty;
241 transformation_matrix (2, 3) = tz;
242 transformation_matrix (3, 3) = 1;