41 #ifndef PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_POINT_TO_PLANE_LLS_HPP_
42 #define PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_POINT_TO_PLANE_LLS_HPP_
44 #include <pcl/cloud_iterator.h>
50 namespace registration
53 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
57 Matrix4 &transformation_matrix)
const
59 std::size_t nr_points = cloud_src.
points.size ();
60 if (cloud_tgt.
points.size () != nr_points)
62 PCL_ERROR (
"[pcl::TransformationEstimationPointToPlaneLLS::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", nr_points, cloud_tgt.
points.size ());
68 estimateRigidTransformation (source_it, target_it, transformation_matrix);
72 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
75 const std::vector<int> &indices_src,
77 Matrix4 &transformation_matrix)
const
79 std::size_t nr_points = indices_src.size ();
80 if (cloud_tgt.
points.size () != nr_points)
82 PCL_ERROR (
"[pcl::TransformationEstimationPointToPlaneLLS::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", indices_src.size (), cloud_tgt.
points.size ());
88 estimateRigidTransformation (source_it, target_it, transformation_matrix);
92 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
95 const std::vector<int> &indices_src,
97 const std::vector<int> &indices_tgt,
98 Matrix4 &transformation_matrix)
const
100 std::size_t nr_points = indices_src.size ();
101 if (indices_tgt.size () != nr_points)
103 PCL_ERROR (
"[pcl::TransformationEstimationPointToPlaneLLS::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", indices_src.size (), indices_tgt.size ());
109 estimateRigidTransformation (source_it, target_it, transformation_matrix);
113 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
118 Matrix4 &transformation_matrix)
const
122 estimateRigidTransformation (source_it, target_it, transformation_matrix);
126 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
129 const double & tx,
const double & ty,
const double & tz,
130 Matrix4 &transformation_matrix)
const
133 transformation_matrix = Eigen::Matrix<Scalar, 4, 4>::Zero ();
134 transformation_matrix (0, 0) =
static_cast<Scalar
> ( std::cos (gamma) * std::cos (beta));
135 transformation_matrix (0, 1) =
static_cast<Scalar
> (-sin (gamma) * std::cos (alpha) + std::cos (gamma) * sin (beta) * sin (alpha));
136 transformation_matrix (0, 2) =
static_cast<Scalar
> ( sin (gamma) * sin (alpha) + std::cos (gamma) * sin (beta) * std::cos (alpha));
137 transformation_matrix (1, 0) =
static_cast<Scalar
> ( sin (gamma) * std::cos (beta));
138 transformation_matrix (1, 1) =
static_cast<Scalar
> ( std::cos (gamma) * std::cos (alpha) + sin (gamma) * sin (beta) * sin (alpha));
139 transformation_matrix (1, 2) =
static_cast<Scalar
> (-std::cos (gamma) * sin (alpha) + sin (gamma) * sin (beta) * std::cos (alpha));
140 transformation_matrix (2, 0) =
static_cast<Scalar
> (-sin (beta));
141 transformation_matrix (2, 1) =
static_cast<Scalar
> ( std::cos (beta) * sin (alpha));
142 transformation_matrix (2, 2) =
static_cast<Scalar
> ( std::cos (beta) * std::cos (alpha));
144 transformation_matrix (0, 3) =
static_cast<Scalar
> (tx);
145 transformation_matrix (1, 3) =
static_cast<Scalar
> (ty);
146 transformation_matrix (2, 3) =
static_cast<Scalar
> (tz);
147 transformation_matrix (3, 3) =
static_cast<Scalar
> (1);
151 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
155 using Vector6d = Eigen::Matrix<double, 6, 1>;
156 using Matrix6d = Eigen::Matrix<double, 6, 6>;
166 if (!std::isfinite (source_it->x) ||
167 !std::isfinite (source_it->y) ||
168 !std::isfinite (source_it->z) ||
169 !std::isfinite (target_it->x) ||
170 !std::isfinite (target_it->y) ||
171 !std::isfinite (target_it->z) ||
172 !std::isfinite (target_it->normal_x) ||
173 !std::isfinite (target_it->normal_y) ||
174 !std::isfinite (target_it->normal_z))
181 const float & sx = source_it->x;
182 const float & sy = source_it->y;
183 const float & sz = source_it->z;
184 const float & dx = target_it->x;
185 const float & dy = target_it->y;
186 const float & dz = target_it->z;
187 const float & nx = target_it->normal[0];
188 const float & ny = target_it->normal[1];
189 const float & nz = target_it->normal[2];
191 double a = nz*sy - ny*sz;
192 double b = nx*sz - nz*sx;
193 double c = ny*sx - nx*sy;
202 ATA.coeffRef (0) += a * a;
203 ATA.coeffRef (1) += a * b;
204 ATA.coeffRef (2) += a * c;
205 ATA.coeffRef (3) += a * nx;
206 ATA.coeffRef (4) += a * ny;
207 ATA.coeffRef (5) += a * nz;
208 ATA.coeffRef (7) += b * b;
209 ATA.coeffRef (8) += b * c;
210 ATA.coeffRef (9) += b * nx;
211 ATA.coeffRef (10) += b * ny;
212 ATA.coeffRef (11) += b * nz;
213 ATA.coeffRef (14) += c * c;
214 ATA.coeffRef (15) += c * nx;
215 ATA.coeffRef (16) += c * ny;
216 ATA.coeffRef (17) += c * nz;
217 ATA.coeffRef (21) += nx * nx;
218 ATA.coeffRef (22) += nx * ny;
219 ATA.coeffRef (23) += nx * nz;
220 ATA.coeffRef (28) += ny * ny;
221 ATA.coeffRef (29) += ny * nz;
222 ATA.coeffRef (35) += nz * nz;
224 double d = nx*dx + ny*dy + nz*dz - nx*sx - ny*sy - nz*sz;
225 ATb.coeffRef (0) += a * d;
226 ATb.coeffRef (1) += b * d;
227 ATb.coeffRef (2) += c * d;
228 ATb.coeffRef (3) += nx * d;
229 ATb.coeffRef (4) += ny * d;
230 ATb.coeffRef (5) += nz * d;
236 ATA.coeffRef (6) = ATA.coeff (1);
237 ATA.coeffRef (12) = ATA.coeff (2);
238 ATA.coeffRef (13) = ATA.coeff (8);
239 ATA.coeffRef (18) = ATA.coeff (3);
240 ATA.coeffRef (19) = ATA.coeff (9);
241 ATA.coeffRef (20) = ATA.coeff (15);
242 ATA.coeffRef (24) = ATA.coeff (4);
243 ATA.coeffRef (25) = ATA.coeff (10);
244 ATA.coeffRef (26) = ATA.coeff (16);
245 ATA.coeffRef (27) = ATA.coeff (22);
246 ATA.coeffRef (30) = ATA.coeff (5);
247 ATA.coeffRef (31) = ATA.coeff (11);
248 ATA.coeffRef (32) = ATA.coeff (17);
249 ATA.coeffRef (33) = ATA.coeff (23);
250 ATA.coeffRef (34) = ATA.coeff (29);
253 Vector6d x =
static_cast<Vector6d
> (ATA.inverse () * ATb);
256 constructTransformationMatrix (x (0), x (1), x (2), x (3), x (4), x (5), transformation_matrix);
Iterator class for point clouds with or without given indices.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences