40 #ifndef PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_SVD_HPP_
41 #define PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_SVD_HPP_
43 #include <pcl/common/eigen.h>
46 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
50 Matrix4 &transformation_matrix)
const
52 size_t nr_points = cloud_src.
points.size ();
53 if (cloud_tgt.
points.size () != nr_points)
55 PCL_ERROR (
"[pcl::TransformationEstimationSVD::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", nr_points, cloud_tgt.
points.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 () != cloud_tgt.
points.size ())
74 PCL_ERROR (
"[pcl::TransformationSVD::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", indices_src.size (), cloud_tgt.
points.size ());
80 estimateRigidTransformation (source_it, target_it, transformation_matrix);
84 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
87 const std::vector<int> &indices_src,
89 const std::vector<int> &indices_tgt,
90 Matrix4 &transformation_matrix)
const
92 if (indices_src.size () != indices_tgt.size ())
94 PCL_ERROR (
"[pcl::TransformationEstimationSVD::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", indices_src.size (), indices_tgt.size ());
100 estimateRigidTransformation (source_it, target_it, transformation_matrix);
104 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
109 Matrix4 &transformation_matrix)
const
113 estimateRigidTransformation (source_it, target_it, transformation_matrix);
117 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
121 Matrix4 &transformation_matrix)
const
124 const int npts = static_cast <
int> (source_it.
size ());
130 Eigen::Matrix<Scalar, 3, Eigen::Dynamic> cloud_src (3, npts);
131 Eigen::Matrix<Scalar, 3, Eigen::Dynamic> cloud_tgt (3, npts);
133 for (
int i = 0; i < npts; ++i)
135 cloud_src (0, i) = source_it->x;
136 cloud_src (1, i) = source_it->y;
137 cloud_src (2, i) = source_it->z;
140 cloud_tgt (0, i) = target_it->x;
141 cloud_tgt (1, i) = target_it->y;
142 cloud_tgt (2, i) = target_it->z;
147 transformation_matrix =
pcl::umeyama (cloud_src, cloud_tgt,
false);
153 transformation_matrix.setIdentity ();
155 Eigen::Matrix<Scalar, 4, 1> centroid_src, centroid_tgt;
162 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> cloud_src_demean, cloud_tgt_demean;
166 getTransformationFromCorrelation (cloud_src_demean, centroid_src, cloud_tgt_demean, centroid_tgt, transformation_matrix);
171 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
173 const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_src_demean,
174 const Eigen::Matrix<Scalar, 4, 1> ¢roid_src,
175 const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_tgt_demean,
176 const Eigen::Matrix<Scalar, 4, 1> ¢roid_tgt,
177 Matrix4 &transformation_matrix)
const
179 transformation_matrix.setIdentity ();
182 Eigen::Matrix<Scalar, 3, 3> H = (cloud_src_demean * cloud_tgt_demean.transpose ()).topLeftCorner (3, 3);
185 Eigen::JacobiSVD<Eigen::Matrix<Scalar, 3, 3> > svd (H, Eigen::ComputeFullU | Eigen::ComputeFullV);
186 Eigen::Matrix<Scalar, 3, 3> u = svd.matrixU ();
187 Eigen::Matrix<Scalar, 3, 3> v = svd.matrixV ();
190 if (u.determinant () * v.determinant () < 0)
192 for (
int x = 0; x < 3; ++x)
196 Eigen::Matrix<Scalar, 3, 3> R = v * u.transpose ();
199 transformation_matrix.topLeftCorner (3, 3) = R;
200 const Eigen::Matrix<Scalar, 3, 1> Rc (R * centroid_src.head (3));
201 transformation_matrix.block (0, 3, 3, 1) = centroid_tgt.head (3) - Rc;
Iterator class for point clouds with or without given indices.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
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.
size_t size() const
Size of the range the iterator is going through.
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.