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>
inline void 48 Matrix4 &transformation_matrix)
const 50 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>
void 68 const std::vector<int> &indices_src,
70 Matrix4 &transformation_matrix)
const 72 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>
inline void 91 const std::vector<int> &indices_src,
93 const std::vector<int> &indices_tgt,
94 Matrix4 &transformation_matrix)
const 96 if (indices_src.size () != 3 || indices_tgt.size () != 3)
98 PCL_ERROR (
"[pcl::TransformationEstimation3Point::estimateRigidTransformation] Number of indices in source (%lu) and target (%lu) must be 3!\n",
99 indices_src.size (), indices_tgt.size ());
105 estimateRigidTransformation (source_it, target_it, transformation_matrix);
109 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void 114 Matrix4 &transformation_matrix)
const 116 if (correspondences.size () != 3)
118 PCL_ERROR (
"[pcl::TransformationEstimation3Point::estimateRigidTransformation] Number of correspondences (%lu) must be 3!\n",
119 correspondences.size ());
125 estimateRigidTransformation (source_it, target_it, transformation_matrix);
129 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void 133 Matrix4 &transformation_matrix)
const 135 transformation_matrix.setIdentity ();
139 Eigen::Matrix <Scalar, 4, 1> source_mean, target_mean;
146 Eigen::Matrix <Scalar, Eigen::Dynamic, Eigen::Dynamic> source_demean, target_demean;
153 Eigen::Matrix <Scalar, 3, 1> s1 = source_demean.col (1).head (3) - source_demean.col (0).head (3);
156 Eigen::Matrix <Scalar, 3, 1> s2 = source_demean.col (2).head (3) - source_demean.col (0).head (3);
157 s2 -= s2.dot (s1) * s1;
160 Eigen::Matrix <Scalar, 3, 3> source_rot;
161 source_rot.col (0) = s1;
162 source_rot.col (1) = s2;
163 source_rot.col (2) = s1.cross (s2);
165 Eigen::Matrix <Scalar, 3, 1> t1 = target_demean.col (1).head (3) - target_demean.col (0).head (3);
168 Eigen::Matrix <Scalar, 3, 1> t2 = target_demean.col (2).head (3) - target_demean.col (0).head (3);
169 t2 -= t2.dot (t1) * t1;
172 Eigen::Matrix <Scalar, 3, 3> target_rot;
173 target_rot.col (0) = t1;
174 target_rot.col (1) = t2;
175 target_rot.col (2) = t1.cross (t2);
178 Eigen::Matrix <Scalar, 3, 3> R = target_rot * source_rot.transpose ();
179 transformation_matrix.topLeftCorner (3, 3) = R;
181 transformation_matrix.block (0, 3, 3, 1) = target_mean.head (3) - R * source_mean.head (3);
186 #endif // PCL_REGISTRATION_IMPL_TRANSFORMATION_ESTIMATION_3POINT_H_ 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.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
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.