41 template <
typename Po
intT,
typename Scalar>
void
44 const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform,
47 if (&cloud_in != &cloud_out)
65 for (
size_t i = 0; i < cloud_out.
points.size (); ++i)
68 Eigen::Matrix<Scalar, 3, 1> pt (cloud_in[i].x, cloud_in[i].y, cloud_in[i].z);
69 cloud_out[i].x =
static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
70 cloud_out[i].y =
static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
71 cloud_out[i].z =
static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
78 for (
size_t i = 0; i < cloud_out.
points.size (); ++i)
80 if (!pcl_isfinite (cloud_in.
points[i].x) ||
81 !pcl_isfinite (cloud_in.
points[i].y) ||
82 !pcl_isfinite (cloud_in.
points[i].z))
85 Eigen::Matrix<Scalar, 3, 1> pt (cloud_in[i].x, cloud_in[i].y, cloud_in[i].z);
86 cloud_out[i].x =
static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
87 cloud_out[i].y =
static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
88 cloud_out[i].z =
static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
94 template <
typename Po
intT,
typename Scalar>
void
96 const std::vector<int> &indices,
98 const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform,
101 size_t npts = indices.size ();
105 cloud_out.
width =
static_cast<int> (npts);
107 cloud_out.
points.resize (npts);
114 for (
size_t i = 0; i < npts; ++i)
120 Eigen::Matrix<Scalar, 3, 1> pt (cloud_in[indices[i]].x, cloud_in[indices[i]].y, cloud_in[indices[i]].z);
121 cloud_out[i].x =
static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
122 cloud_out[i].y =
static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
123 cloud_out[i].z =
static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
130 for (
size_t i = 0; i < npts; ++i)
134 if (!pcl_isfinite (cloud_in.
points[indices[i]].x) ||
135 !pcl_isfinite (cloud_in.
points[indices[i]].y) ||
136 !pcl_isfinite (cloud_in.
points[indices[i]].z))
139 Eigen::Matrix<Scalar, 3, 1> pt (cloud_in[indices[i]].x, cloud_in[indices[i]].y, cloud_in[indices[i]].z);
140 cloud_out[i].x =
static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
141 cloud_out[i].y =
static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
142 cloud_out[i].z =
static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
148 template <
typename Po
intT,
typename Scalar>
void
151 const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform,
152 bool copy_all_fields)
154 if (&cloud_in != &cloud_out)
173 for (
size_t i = 0; i < cloud_out.
points.size (); ++i)
176 Eigen::Matrix<Scalar, 3, 1> pt (cloud_in[i].x, cloud_in[i].y, cloud_in[i].z);
177 cloud_out[i].x =
static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
178 cloud_out[i].y =
static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
179 cloud_out[i].z =
static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
183 Eigen::Matrix<Scalar, 3, 1> nt (cloud_in[i].normal_x, cloud_in[i].normal_y, cloud_in[i].normal_z);
184 cloud_out[i].normal_x =
static_cast<float> (transform (0, 0) * nt.coeffRef (0) + transform (0, 1) * nt.coeffRef (1) + transform (0, 2) * nt.coeffRef (2));
185 cloud_out[i].normal_y =
static_cast<float> (transform (1, 0) * nt.coeffRef (0) + transform (1, 1) * nt.coeffRef (1) + transform (1, 2) * nt.coeffRef (2));
186 cloud_out[i].normal_z =
static_cast<float> (transform (2, 0) * nt.coeffRef (0) + transform (2, 1) * nt.coeffRef (1) + transform (2, 2) * nt.coeffRef (2));
192 for (
size_t i = 0; i < cloud_out.
points.size (); ++i)
194 if (!pcl_isfinite (cloud_in.
points[i].x) ||
195 !pcl_isfinite (cloud_in.
points[i].y) ||
196 !pcl_isfinite (cloud_in.
points[i].z))
200 Eigen::Matrix<Scalar, 3, 1> pt (cloud_in[i].x, cloud_in[i].y, cloud_in[i].z);
201 cloud_out[i].x =
static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
202 cloud_out[i].y =
static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
203 cloud_out[i].z =
static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
207 Eigen::Matrix<Scalar, 3, 1> nt (cloud_in[i].normal_x, cloud_in[i].normal_y, cloud_in[i].normal_z);
208 cloud_out[i].normal_x =
static_cast<float> (transform (0, 0) * nt.coeffRef (0) + transform (0, 1) * nt.coeffRef (1) + transform (0, 2) * nt.coeffRef (2));
209 cloud_out[i].normal_y =
static_cast<float> (transform (1, 0) * nt.coeffRef (0) + transform (1, 1) * nt.coeffRef (1) + transform (1, 2) * nt.coeffRef (2));
210 cloud_out[i].normal_z =
static_cast<float> (transform (2, 0) * nt.coeffRef (0) + transform (2, 1) * nt.coeffRef (1) + transform (2, 2) * nt.coeffRef (2));
216 template <
typename Po
intT,
typename Scalar>
void
218 const std::vector<int> &indices,
220 const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform,
221 bool copy_all_fields)
223 size_t npts = indices.size ();
227 cloud_out.
width =
static_cast<int> (npts);
229 cloud_out.
points.resize (npts);
236 for (
size_t i = 0; i < cloud_out.
points.size (); ++i)
242 Eigen::Matrix<Scalar, 3, 1> pt (cloud_in[indices[i]].x, cloud_in[indices[i]].y, cloud_in[indices[i]].z);
243 cloud_out[i].x =
static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
244 cloud_out[i].y =
static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
245 cloud_out[i].z =
static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
249 Eigen::Matrix<Scalar, 3, 1> nt (cloud_in[indices[i]].normal_x, cloud_in[indices[i]].normal_y, cloud_in[indices[i]].normal_z);
250 cloud_out[i].normal_x =
static_cast<float> (transform (0, 0) * nt.coeffRef (0) + transform (0, 1) * nt.coeffRef (1) + transform (0, 2) * nt.coeffRef (2));
251 cloud_out[i].normal_y =
static_cast<float> (transform (1, 0) * nt.coeffRef (0) + transform (1, 1) * nt.coeffRef (1) + transform (1, 2) * nt.coeffRef (2));
252 cloud_out[i].normal_z =
static_cast<float> (transform (2, 0) * nt.coeffRef (0) + transform (2, 1) * nt.coeffRef (1) + transform (2, 2) * nt.coeffRef (2));
258 for (
size_t i = 0; i < cloud_out.
points.size (); ++i)
264 if (!pcl_isfinite (cloud_in.
points[indices[i]].x) ||
265 !pcl_isfinite (cloud_in.
points[indices[i]].y) ||
266 !pcl_isfinite (cloud_in.
points[indices[i]].z))
270 Eigen::Matrix<Scalar, 3, 1> pt (cloud_in[indices[i]].x, cloud_in[indices[i]].y, cloud_in[indices[i]].z);
271 cloud_out[i].x =
static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
272 cloud_out[i].y =
static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
273 cloud_out[i].z =
static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
277 Eigen::Matrix<Scalar, 3, 1> nt (cloud_in[indices[i]].normal_x, cloud_in[indices[i]].normal_y, cloud_in[indices[i]].normal_z);
278 cloud_out[i].normal_x =
static_cast<float> (transform (0, 0) * nt.coeffRef (0) + transform (0, 1) * nt.coeffRef (1) + transform (0, 2) * nt.coeffRef (2));
279 cloud_out[i].normal_y =
static_cast<float> (transform (1, 0) * nt.coeffRef (0) + transform (1, 1) * nt.coeffRef (1) + transform (1, 2) * nt.coeffRef (2));
280 cloud_out[i].normal_z =
static_cast<float> (transform (2, 0) * nt.coeffRef (0) + transform (2, 1) * nt.coeffRef (1) + transform (2, 2) * nt.coeffRef (2));
286 template <
typename Po
intT,
typename Scalar>
inline void
289 const Eigen::Matrix<Scalar, 3, 1> &offset,
290 const Eigen::Quaternion<Scalar> &rotation,
291 bool copy_all_fields)
293 Eigen::Translation<Scalar, 3> translation (offset);
295 Eigen::Transform<Scalar, 3, Eigen::Affine> t (translation * rotation);
300 template <
typename Po
intT,
typename Scalar>
inline void
303 const Eigen::Matrix<Scalar, 3, 1> &offset,
304 const Eigen::Quaternion<Scalar> &rotation,
305 bool copy_all_fields)
307 Eigen::Translation<Scalar, 3> translation (offset);
309 Eigen::Transform<Scalar, 3, Eigen::Affine> t (translation * rotation);
314 template <
typename Po
intT,
typename Scalar>
inline PointT
316 const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform)
319 ret.getVector3fMap () = transform * point.getVector3fMap ();
325 template <
typename Po
intT,
typename Scalar>
inline PointT
327 const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform)
330 ret.getVector3fMap () = transform * point.getVector3fMap ();
331 ret.getNormalVector3fMap () = transform.rotation () * point.getNormalVector3fMap ();
337 template <
typename Po
intT,
typename Scalar>
double
339 Eigen::Transform<Scalar, 3, Eigen::Affine> &transform)
342 Eigen::Matrix<Scalar, 4, 1> centroid;
347 Eigen::Matrix<Scalar, 3, 1> eigen_vals;
348 pcl::eigen33 (covariance_matrix, eigen_vects, eigen_vals);
350 double rel1 = eigen_vals.coeff (0) / eigen_vals.coeff (1);
351 double rel2 = eigen_vals.coeff (1) / eigen_vals.coeff (2);
353 transform.translation () = centroid.head (3);
354 transform.linear () = eigen_vects;
356 return (std::min (rel1, rel2));
void transformPoint(const Eigen::Matrix< Scalar, 3, 1 > &point_in, Eigen::Matrix< Scalar, 3, 1 > &point_out, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transformation)
Transform a point using an affine matrix.
double getPrincipalTransformation(const pcl::PointCloud< PointT > &cloud, Eigen::Transform< Scalar, 3, Eigen::Affine > &transform)
Calculates the principal (PCA-based) alignment of the point cloud.
uint32_t width
The point cloud width (if organized as an image-structure).
struct pcl::PointXYZIEdge EIGEN_ALIGN16
unsigned int computeMeanAndCovarianceMatrix(const pcl::PointCloud< PointT > &cloud, Eigen::Matrix< Scalar, 3, 3 > &covariance_matrix, Eigen::Matrix< Scalar, 4, 1 > ¢roid)
Compute the normalized 3x3 covariance matrix and the centroid of a given set of points in a single lo...
void transformPointCloudWithNormals(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform, bool copy_all_fields=true)
Transform a point cloud and rotate its normals using an Eigen transform.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform, bool copy_all_fields=true)
Apply an affine transform defined by an Eigen Transform.
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
uint32_t height
The point cloud height (if organized as an image-structure).
void eigen33(const Matrix &mat, typename Matrix::Scalar &eigenvalue, Vector &eigenvector)
determines the eigenvector and eigenvalue of the smallest eigenvalue of the symmetric positive semi d...
PointCloud represents the base class in PCL for storing collections of 3D points. ...
PointT transformPointWithNormal(const PointT &point, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform)
Transform a point with members x,y,z,normal_x,normal_y,normal_z.
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
void transformPointCloudWithNormals(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Matrix< Scalar, 4, 4 > &transform, bool copy_all_fields=true)
Transform a point cloud and rotate its normals using an Eigen transform.
A point structure representing Euclidean xyz coordinates, and the RGB color.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values).
pcl::PCLHeader header
The point cloud header.