38 #ifndef PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_2D_HPP_
39 #define PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_2D_HPP_
45 namespace registration
48 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
52 Matrix4 &transformation_matrix)
const
54 std::size_t nr_points = cloud_src.
points.size ();
55 if (cloud_tgt.
points.size () != nr_points)
57 PCL_ERROR (
"[pcl::TransformationEstimation2D::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", nr_points, cloud_tgt.
points.size ());
63 estimateRigidTransformation (source_it, target_it, transformation_matrix);
67 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
70 const std::vector<int> &indices_src,
72 Matrix4 &transformation_matrix)
const
74 if (indices_src.size () != cloud_tgt.
points.size ())
76 PCL_ERROR (
"[pcl::Transformation2D::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", indices_src.size (), cloud_tgt.
points.size ());
82 estimateRigidTransformation (source_it, target_it, transformation_matrix);
86 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
89 const std::vector<int> &indices_src,
91 const std::vector<int> &indices_tgt,
92 Matrix4 &transformation_matrix)
const
94 if (indices_src.size () != indices_tgt.size ())
96 PCL_ERROR (
"[pcl::TransformationEstimation2D::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", indices_src.size (), indices_tgt.size ());
106 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
111 Matrix4 &transformation_matrix)
const
115 estimateRigidTransformation (source_it, target_it, transformation_matrix);
119 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void
123 Matrix4 &transformation_matrix)
const
127 Eigen::Matrix<Scalar, 4, 1> centroid_src, centroid_tgt;
134 centroid_src[2] = 0.0f;
135 centroid_tgt[2] = 0.0f;
137 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> cloud_src_demean, cloud_tgt_demean;
141 getTransformationFromCorrelation (cloud_src_demean, centroid_src, cloud_tgt_demean, centroid_tgt, transformation_matrix);
145 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void
147 const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_src_demean,
148 const Eigen::Matrix<Scalar, 4, 1> ¢roid_src,
149 const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_tgt_demean,
150 const Eigen::Matrix<Scalar, 4, 1> ¢roid_tgt,
151 Matrix4 &transformation_matrix)
const
153 transformation_matrix.setIdentity ();
156 Eigen::Matrix<Scalar, 3, 3> H = (cloud_src_demean * cloud_tgt_demean.transpose ()).topLeftCorner (3, 3);
158 float angle = std::atan2 ((H (0, 1) - H (1, 0)), (H(0, 0) + H (1, 1)));
160 Eigen::Matrix<Scalar, 3, 3> R (Eigen::Matrix<Scalar, 3, 3>::Identity ());
161 R (0, 0) = R (1, 1) = std::cos (angle);
162 R (0, 1) = -std::sin (angle);
163 R (1, 0) = std::sin (angle);
166 transformation_matrix.topLeftCorner (3, 3).matrix () = R;
167 const Eigen::Matrix<Scalar, 3, 1> Rc (R * centroid_src.head (3).matrix ());
168 transformation_matrix.block (0, 3, 3, 1).matrix () = centroid_tgt.head (3) - Rc;
174 #endif // PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_2D_HPP_
Iterator class for point clouds with or without given indices.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
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.