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 const auto nr_points = cloud_src.
size ();
55 if (cloud_tgt.
size () != nr_points)
57 PCL_ERROR(
"[pcl::TransformationEstimation2D::estimateRigidTransformation] Number " 58 "or points in source (%zu) differs than target (%zu)!\n",
59 static_cast<std::size_t>(nr_points),
60 static_cast<std::size_t>(cloud_tgt.
size()));
66 estimateRigidTransformation (source_it, target_it, transformation_matrix);
70 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void 73 const std::vector<int> &indices_src,
75 Matrix4 &transformation_matrix)
const 77 if (indices_src.size () != cloud_tgt.
size ())
79 PCL_ERROR(
"[pcl::Transformation2D::estimateRigidTransformation] Number or points " 80 "in source (%zu) differs than target (%zu)!\n",
82 static_cast<std::size_t
>(cloud_tgt.
size()));
92 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void 95 const std::vector<int> &indices_src,
97 const std::vector<int> &indices_tgt,
98 Matrix4 &transformation_matrix)
const 100 if (indices_src.size () != indices_tgt.size ())
102 PCL_ERROR (
"[pcl::TransformationEstimation2D::estimateRigidTransformation] Number or points in source (%lu) differs than target (%lu)!\n", indices_src.size (), indices_tgt.size ());
108 estimateRigidTransformation (source_it, target_it, transformation_matrix);
112 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void 117 Matrix4 &transformation_matrix)
const 121 estimateRigidTransformation (source_it, target_it, transformation_matrix);
125 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
inline void 129 Matrix4 &transformation_matrix)
const 133 Eigen::Matrix<Scalar, 4, 1> centroid_src, centroid_tgt;
140 centroid_src[2] = 0.0f;
141 centroid_tgt[2] = 0.0f;
143 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> cloud_src_demean, cloud_tgt_demean;
147 getTransformationFromCorrelation (cloud_src_demean, centroid_src, cloud_tgt_demean, centroid_tgt, transformation_matrix);
151 template <
typename Po
intSource,
typename Po
intTarget,
typename Scalar>
void 153 const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_src_demean,
154 const Eigen::Matrix<Scalar, 4, 1> ¢roid_src,
155 const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_tgt_demean,
156 const Eigen::Matrix<Scalar, 4, 1> ¢roid_tgt,
157 Matrix4 &transformation_matrix)
const 159 transformation_matrix.setIdentity ();
162 Eigen::Matrix<Scalar, 3, 3> H = (cloud_src_demean * cloud_tgt_demean.transpose ()).topLeftCorner (3, 3);
164 float angle = std::atan2 ((H (0, 1) - H (1, 0)), (H(0, 0) + H (1, 1)));
166 Eigen::Matrix<Scalar, 3, 3> R (Eigen::Matrix<Scalar, 3, 3>::Identity ());
167 R (0, 0) = R (1, 1) = std::cos (angle);
168 R (0, 1) = -std::sin (angle);
169 R (1, 0) = std::sin (angle);
172 transformation_matrix.topLeftCorner (3, 3).matrix () = R;
173 const Eigen::Matrix<Scalar, 3, 1> Rc (R * centroid_src.head (3).matrix ());
174 transformation_matrix.block (0, 3, 3, 1).matrix () = centroid_tgt.head (3) - Rc;
180 #endif // PCL_REGISTRATION_TRANSFORMATION_ESTIMATION_2D_HPP_ 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.