37 #ifndef PCL_REGISTRATION_IMPL_TRANSFORMATION_ESTIMATION_3POINT_H_
38 #define PCL_REGISTRATION_IMPL_TRANSFORMATION_ESTIMATION_3POINT_H_
40 #include <pcl/common/eigen.h>
41 #include <pcl/registration/transformation_estimation_3point.h>
44 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
49 Matrix4& transformation_matrix)
const
51 if (cloud_src.
size() != 3 || cloud_tgt.
size() != 3) {
52 PCL_ERROR(
"[pcl::TransformationEstimation3Point::estimateRigidTransformation] "
53 "Number of points in source (%zu) and target (%zu) must be 3!\n",
54 static_cast<std::size_t
>(cloud_src.
size()),
55 static_cast<std::size_t
>(cloud_tgt.
size()));
61 estimateRigidTransformation(source_it, target_it, transformation_matrix);
65 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
71 Matrix4& transformation_matrix)
const
73 if (indices_src.size() != 3 || cloud_tgt.
size() != 3) {
75 "[pcl::TransformationEstimation3Point::estimateRigidTransformation] Number of "
76 "indices in source (%zu) and points in target (%zu) must be 3!\n",
78 static_cast<std::size_t
>(cloud_tgt.
size()));
84 estimateRigidTransformation(source_it, target_it, transformation_matrix);
88 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
95 Matrix4& transformation_matrix)
const
97 if (indices_src.size() != 3 || indices_tgt.size() != 3) {
98 PCL_ERROR(
"[pcl::TransformationEstimation3Point::estimateRigidTransformation] "
99 "Number of indices in source (%lu) and target (%lu) must be 3!\n",
111 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
117 Matrix4& transformation_matrix)
const
119 if (correspondences.size() != 3) {
120 PCL_ERROR(
"[pcl::TransformationEstimation3Point::estimateRigidTransformation] "
121 "Number of correspondences (%lu) must be 3!\n",
122 correspondences.size());
128 estimateRigidTransformation(source_it, target_it, transformation_matrix);
132 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
137 Matrix4& transformation_matrix)
const
139 transformation_matrix.setIdentity();
143 Eigen::Matrix<Scalar, 4, 1> source_mean, target_mean;
150 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> source_demean, target_demean;
157 Eigen::Matrix<Scalar, 3, 1> s1 =
158 source_demean.col(1).template head<3>() - source_demean.col(0).template head<3>();
161 Eigen::Matrix<Scalar, 3, 1> s2 =
162 source_demean.col(2).template head<3>() - source_demean.col(0).template head<3>();
163 s2 -= s2.dot(s1) * s1;
166 Eigen::Matrix<Scalar, 3, 3> source_rot;
167 source_rot.col(0) = s1;
168 source_rot.col(1) = s2;
169 source_rot.col(2) = s1.cross(s2);
171 Eigen::Matrix<Scalar, 3, 1> t1 =
172 target_demean.col(1).template head<3>() - target_demean.col(0).template head<3>();
175 Eigen::Matrix<Scalar, 3, 1> t2 =
176 target_demean.col(2).template head<3>() - target_demean.col(0).template head<3>();
177 t2 -= t2.dot(t1) * t1;
180 Eigen::Matrix<Scalar, 3, 3> target_rot;
181 target_rot.col(0) = t1;
182 target_rot.col(1) = t2;
183 target_rot.col(2) = t1.cross(t2);
186 Eigen::Matrix<Scalar, 3, 3> R = target_rot * source_rot.transpose();
187 transformation_matrix.template topLeftCorner<3, 3>() = R;
190 transformation_matrix.template block<3, 1>(0, 3) =
191 target_mean.template head<3>() - R * source_mean.template head<3>();
Iterator class for point clouds with or without given indices.
void demeanPointCloud(ConstCloudIterator< PointT > &cloud_iterator, const Eigen::Matrix< Scalar, 4, 1 > ¢roid, pcl::PointCloud< PointT > &cloud_out, int npts=0)
Subtract a centroid from a point cloud and return the de-meaned representation.
unsigned int compute3DCentroid(ConstCloudIterator< PointT > &cloud_iterator, Eigen::Matrix< Scalar, 4, 1 > ¢roid)
Compute the 3D (X-Y-Z) centroid of a set of points and return it as a 3D vector.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
IndicesAllocator<> Indices
Type used for indices in PCL.