41 #ifndef PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_SVD_HPP_ 42 #define PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_SVD_HPP_ 44 #include <pcl/common/eigen.h> 50 namespace registration
53 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void 57 Matrix4 &transformation_matrix)
const 59 const auto nr_points = cloud_src.
size ();
60 if (cloud_tgt.
size () != nr_points)
62 PCL_ERROR(
"[pcl::TransformationEstimationSVD::estimateRigidTransformation] Number " 63 "or points in source (%zu) differs than target (%zu)!\n",
64 static_cast<std::size_t>(nr_points),
65 static_cast<std::size_t>(cloud_tgt.
size()));
71 estimateRigidTransformation (source_it, target_it, transformation_matrix);
75 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void 78 const std::vector<int> &indices_src,
80 Matrix4 &transformation_matrix)
const 82 if (indices_src.size () != cloud_tgt.
size ())
84 PCL_ERROR(
"[pcl::TransformationSVD::estimateRigidTransformation] Number or points " 85 "in source (%zu) differs than target (%zu)!\n",
87 static_cast<std::size_t
>(cloud_tgt.
size()));
93 estimateRigidTransformation (source_it, target_it, transformation_matrix);
97 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void 100 const std::vector<int> &indices_src,
102 const std::vector<int> &indices_tgt,
103 Matrix4 &transformation_matrix)
const 105 if (indices_src.size () != indices_tgt.size ())
107 PCL_ERROR(
"[pcl::TransformationEstimationSVD::estimateRigidTransformation] Number " 108 "or points in source (%zu) differs than target (%zu)!\n",
116 estimateRigidTransformation (source_it, target_it, transformation_matrix);
120 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void 125 Matrix4 &transformation_matrix)
const 129 estimateRigidTransformation (source_it, target_it, transformation_matrix);
133 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void 137 Matrix4 &transformation_matrix)
const 140 const int npts = static_cast <
int> (source_it.
size ());
146 Eigen::Matrix<Scalar, 3, Eigen::Dynamic> cloud_src (3, npts);
147 Eigen::Matrix<Scalar, 3, Eigen::Dynamic> cloud_tgt (3, npts);
149 for (
int i = 0; i < npts; ++i)
151 cloud_src (0, i) = source_it->x;
152 cloud_src (1, i) = source_it->y;
153 cloud_src (2, i) = source_it->z;
156 cloud_tgt (0, i) = target_it->x;
157 cloud_tgt (1, i) = target_it->y;
158 cloud_tgt (2, i) = target_it->z;
163 transformation_matrix =
pcl::umeyama (cloud_src, cloud_tgt,
false);
169 transformation_matrix.setIdentity ();
171 Eigen::Matrix<Scalar, 4, 1> centroid_src, centroid_tgt;
178 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> cloud_src_demean, cloud_tgt_demean;
182 getTransformationFromCorrelation (cloud_src_demean, centroid_src, cloud_tgt_demean, centroid_tgt, transformation_matrix);
187 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void 189 const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_src_demean,
190 const Eigen::Matrix<Scalar, 4, 1> ¢roid_src,
191 const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_tgt_demean,
192 const Eigen::Matrix<Scalar, 4, 1> ¢roid_tgt,
193 Matrix4 &transformation_matrix)
const 195 transformation_matrix.setIdentity ();
198 Eigen::Matrix<Scalar, 3, 3> H = (cloud_src_demean * cloud_tgt_demean.transpose ()).topLeftCorner (3, 3);
201 Eigen::JacobiSVD<Eigen::Matrix<Scalar, 3, 3> > svd (H, Eigen::ComputeFullU | Eigen::ComputeFullV);
202 Eigen::Matrix<Scalar, 3, 3> u = svd.matrixU ();
203 Eigen::Matrix<Scalar, 3, 3> v = svd.matrixV ();
206 if (u.determinant () * v.determinant () < 0)
208 for (
int x = 0; x < 3; ++x)
212 Eigen::Matrix<Scalar, 3, 3> R = v * u.transpose ();
215 transformation_matrix.topLeftCorner (3, 3) = R;
216 const Eigen::Matrix<Scalar, 3, 1> Rc (R * centroid_src.head (3));
217 transformation_matrix.block (0, 3, 3, 1) = centroid_tgt.head (3) - Rc;
Iterator class for point clouds with or without given indices.
Eigen::internal::umeyama_transform_matrix_type< Derived, OtherDerived >::type umeyama(const Eigen::MatrixBase< Derived > &src, const Eigen::MatrixBase< OtherDerived > &dst, bool with_scaling=false)
Returns the transformation between two point sets.
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
std::size_t size() const
Size of the range the iterator is going through.
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.