Point Cloud Library (PCL)  1.7.1
transforms.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  *
38  */
39 #ifndef PCL_TRANSFORMS_H_
40 #define PCL_TRANSFORMS_H_
41 
42 #include <pcl/point_cloud.h>
43 #include <pcl/point_types.h>
44 #include <pcl/common/centroid.h>
45 #include <pcl/common/eigen.h>
46 #include <pcl/PointIndices.h>
47 
48 namespace pcl
49 {
50  /** \brief Apply an affine transform defined by an Eigen Transform
51  * \param[in] cloud_in the input point cloud
52  * \param[out] cloud_out the resultant output point cloud
53  * \param[in] transform an affine transformation (typically a rigid transformation)
54  * \note Can be used with cloud_in equal to cloud_out
55  * \ingroup common
56  */
57  template <typename PointT, typename Scalar> void
59  pcl::PointCloud<PointT> &cloud_out,
60  const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform);
61 
62  template <typename PointT> void
64  pcl::PointCloud<PointT> &cloud_out,
65  const Eigen::Affine3f &transform)
66  {
67  return (transformPointCloud<PointT, float> (cloud_in, cloud_out, transform));
68  }
69 
70  /** \brief Apply an affine transform defined by an Eigen Transform
71  * \param[in] cloud_in the input point cloud
72  * \param[in] indices the set of point indices to use from the input point cloud
73  * \param[out] cloud_out the resultant output point cloud
74  * \param[in] transform an affine transformation (typically a rigid transformation)
75  * \ingroup common
76  */
77  template <typename PointT, typename Scalar> void
79  const std::vector<int> &indices,
80  pcl::PointCloud<PointT> &cloud_out,
81  const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform);
82 
83  template <typename PointT> void
85  const std::vector<int> &indices,
86  pcl::PointCloud<PointT> &cloud_out,
87  const Eigen::Affine3f &transform)
88  {
89  return (transformPointCloud<PointT, float> (cloud_in, indices, cloud_out, transform));
90  }
91 
92  /** \brief Apply an affine transform defined by an Eigen Transform
93  * \param[in] cloud_in the input point cloud
94  * \param[in] indices the set of point indices to use from the input point cloud
95  * \param[out] cloud_out the resultant output point cloud
96  * \param[in] transform an affine transformation (typically a rigid transformation)
97  * \ingroup common
98  */
99  template <typename PointT, typename Scalar> void
101  const pcl::PointIndices &indices,
102  pcl::PointCloud<PointT> &cloud_out,
103  const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform)
104  {
105  return (transformPointCloud<PointT, Scalar> (cloud_in, indices.indices, cloud_out, transform));
106  }
107 
108  template <typename PointT> void
110  const pcl::PointIndices &indices,
111  pcl::PointCloud<PointT> &cloud_out,
112  const Eigen::Affine3f &transform)
113  {
114  return (transformPointCloud<PointT, float> (cloud_in, indices, cloud_out, transform));
115  }
116 
117  /** \brief Transform a point cloud and rotate its normals using an Eigen transform.
118  * \param[in] cloud_in the input point cloud
119  * \param[out] cloud_out the resultant output point cloud
120  * \param[in] transform an affine transformation (typically a rigid transformation)
121  * \note Can be used with cloud_in equal to cloud_out
122  */
123  template <typename PointT, typename Scalar> void
125  pcl::PointCloud<PointT> &cloud_out,
126  const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform);
127 
128  template <typename PointT> void
130  pcl::PointCloud<PointT> &cloud_out,
131  const Eigen::Affine3f &transform)
132  {
133  return (transformPointCloudWithNormals<PointT, float> (cloud_in, cloud_out, transform));
134  }
135 
136  /** \brief Transform a point cloud and rotate its normals using an Eigen transform.
137  * \param[in] cloud_in the input point cloud
138  * \param[in] indices the set of point indices to use from the input point cloud
139  * \param[out] cloud_out the resultant output point cloud
140  * \param[in] transform an affine transformation (typically a rigid transformation)
141  */
142  template <typename PointT, typename Scalar> void
144  const std::vector<int> &indices,
145  pcl::PointCloud<PointT> &cloud_out,
146  const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform);
147 
148  template <typename PointT> void
150  const std::vector<int> &indices,
151  pcl::PointCloud<PointT> &cloud_out,
152  const Eigen::Affine3f &transform)
153  {
154  return (transformPointCloudWithNormals<PointT, float> (cloud_in, indices, cloud_out, transform));
155  }
156 
157  /** \brief Transform a point cloud and rotate its normals using an Eigen transform.
158  * \param[in] cloud_in the input point cloud
159  * \param[in] indices the set of point indices to use from the input point cloud
160  * \param[out] cloud_out the resultant output point cloud
161  * \param[in] transform an affine transformation (typically a rigid transformation)
162  */
163  template <typename PointT, typename Scalar> void
165  const pcl::PointIndices &indices,
166  pcl::PointCloud<PointT> &cloud_out,
167  const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform)
168  {
169  return (transformPointCloudWithNormals<PointT, Scalar> (cloud_in, indices.indices, cloud_out, transform));
170  }
171 
172 
173  template <typename PointT> void
175  const pcl::PointIndices &indices,
176  pcl::PointCloud<PointT> &cloud_out,
177  const Eigen::Affine3f &transform)
178  {
179  return (transformPointCloudWithNormals<PointT, float> (cloud_in, indices, cloud_out, transform));
180  }
181 
182  /** \brief Apply a rigid transform defined by a 4x4 matrix
183  * \param[in] cloud_in the input point cloud
184  * \param[out] cloud_out the resultant output point cloud
185  * \param[in] transform a rigid transformation
186  * \note Can be used with cloud_in equal to cloud_out
187  * \ingroup common
188  */
189  template <typename PointT, typename Scalar> void
191  pcl::PointCloud<PointT> &cloud_out,
192  const Eigen::Matrix<Scalar, 4, 4> &transform)
193  {
194  Eigen::Transform<Scalar, 3, Eigen::Affine> t (transform);
195  return (transformPointCloud<PointT, Scalar> (cloud_in, cloud_out, t));
196  }
197 
198  template <typename PointT> void
200  pcl::PointCloud<PointT> &cloud_out,
201  const Eigen::Matrix4f &transform)
202  {
203  return (transformPointCloud<PointT, float> (cloud_in, cloud_out, transform));
204  }
205 
206  /** \brief Apply a rigid transform defined by a 4x4 matrix
207  * \param[in] cloud_in the input point cloud
208  * \param[in] indices the set of point indices to use from the input point cloud
209  * \param[out] cloud_out the resultant output point cloud
210  * \param[in] transform a rigid transformation
211  * \ingroup common
212  */
213  template <typename PointT, typename Scalar> void
215  const std::vector<int> &indices,
216  pcl::PointCloud<PointT> &cloud_out,
217  const Eigen::Matrix<Scalar, 4, 4> &transform)
218  {
219  Eigen::Transform<Scalar, 3, Eigen::Affine> t (transform);
220  return (transformPointCloud<PointT, Scalar> (cloud_in, indices, cloud_out, t));
221  }
222 
223  template <typename PointT> void
225  const std::vector<int> &indices,
226  pcl::PointCloud<PointT> &cloud_out,
227  const Eigen::Matrix4f &transform)
228  {
229  return (transformPointCloud<PointT, float> (cloud_in, indices, cloud_out, transform));
230  }
231 
232  /** \brief Apply a rigid transform defined by a 4x4 matrix
233  * \param[in] cloud_in the input point cloud
234  * \param[in] indices the set of point indices to use from the input point cloud
235  * \param[out] cloud_out the resultant output point cloud
236  * \param[in] transform a rigid transformation
237  * \ingroup common
238  */
239  template <typename PointT, typename Scalar> void
241  const pcl::PointIndices &indices,
242  pcl::PointCloud<PointT> &cloud_out,
243  const Eigen::Matrix<Scalar, 4, 4> &transform)
244  {
245  return (transformPointCloud<PointT, Scalar> (cloud_in, indices.indices, cloud_out, transform));
246  }
247 
248  template <typename PointT> void
250  const pcl::PointIndices &indices,
251  pcl::PointCloud<PointT> &cloud_out,
252  const Eigen::Matrix4f &transform)
253  {
254  return (transformPointCloud<PointT, float> (cloud_in, indices, cloud_out, transform));
255  }
256 
257  /** \brief Transform a point cloud and rotate its normals using an Eigen transform.
258  * \param[in] cloud_in the input point cloud
259  * \param[out] cloud_out the resultant output point cloud
260  * \param[in] transform an affine transformation (typically a rigid transformation)
261  * \note Can be used with cloud_in equal to cloud_out
262  * \ingroup common
263  */
264  template <typename PointT, typename Scalar> void
266  pcl::PointCloud<PointT> &cloud_out,
267  const Eigen::Matrix<Scalar, 4, 4> &transform)
268  {
269  Eigen::Transform<Scalar, 3, Eigen::Affine> t (transform);
270  return (transformPointCloudWithNormals<PointT, Scalar> (cloud_in, cloud_out, t));
271  }
272 
273 
274  template <typename PointT> void
276  pcl::PointCloud<PointT> &cloud_out,
277  const Eigen::Matrix4f &transform)
278  {
279  return (transformPointCloudWithNormals<PointT, float> (cloud_in, cloud_out, transform));
280  }
281 
282  /** \brief Transform a point cloud and rotate its normals using an Eigen transform.
283  * \param[in] cloud_in the input point cloud
284  * \param[in] indices the set of point indices to use from the input point cloud
285  * \param[out] cloud_out the resultant output point cloud
286  * \param[in] transform an affine transformation (typically a rigid transformation)
287  * \note Can be used with cloud_in equal to cloud_out
288  * \ingroup common
289  */
290  template <typename PointT, typename Scalar> void
292  const std::vector<int> &indices,
293  pcl::PointCloud<PointT> &cloud_out,
294  const Eigen::Matrix<Scalar, 4, 4> &transform)
295  {
296  Eigen::Transform<Scalar, 3, Eigen::Affine> t (transform);
297  return (transformPointCloudWithNormals<PointT, Scalar> (cloud_in, indices, cloud_out, t));
298  }
299 
300 
301  template <typename PointT> void
303  const std::vector<int> &indices,
304  pcl::PointCloud<PointT> &cloud_out,
305  const Eigen::Matrix4f &transform)
306  {
307  return (transformPointCloudWithNormals<PointT, float> (cloud_in, indices, cloud_out, transform));
308  }
309 
310  /** \brief Transform a point cloud and rotate its normals using an Eigen transform.
311  * \param[in] cloud_in the input point cloud
312  * \param[in] indices the set of point indices to use from the input point cloud
313  * \param[out] cloud_out the resultant output point cloud
314  * \param[in] transform an affine transformation (typically a rigid transformation)
315  * \note Can be used with cloud_in equal to cloud_out
316  * \ingroup common
317  */
318  template <typename PointT, typename Scalar> void
320  const pcl::PointIndices &indices,
321  pcl::PointCloud<PointT> &cloud_out,
322  const Eigen::Matrix<Scalar, 4, 4> &transform)
323  {
324  Eigen::Transform<Scalar, 3, Eigen::Affine> t (transform);
325  return (transformPointCloudWithNormals<PointT, Scalar> (cloud_in, indices, cloud_out, t));
326  }
327 
328 
329  template <typename PointT> void
331  const pcl::PointIndices &indices,
332  pcl::PointCloud<PointT> &cloud_out,
333  const Eigen::Matrix4f &transform)
334  {
335  return (transformPointCloudWithNormals<PointT, float> (cloud_in, indices, cloud_out, transform));
336  }
337 
338  /** \brief Apply a rigid transform defined by a 3D offset and a quaternion
339  * \param[in] cloud_in the input point cloud
340  * \param[out] cloud_out the resultant output point cloud
341  * \param[in] offset the translation component of the rigid transformation
342  * \param[in] rotation the rotation component of the rigid transformation
343  * \ingroup common
344  */
345  template <typename PointT, typename Scalar> inline void
347  pcl::PointCloud<PointT> &cloud_out,
348  const Eigen::Matrix<Scalar, 3, 1> &offset,
349  const Eigen::Quaternion<Scalar> &rotation);
350 
351  template <typename PointT> inline void
353  pcl::PointCloud<PointT> &cloud_out,
354  const Eigen::Vector3f &offset,
355  const Eigen::Quaternionf &rotation)
356  {
357  return (transformPointCloud<PointT, float> (cloud_in, cloud_out, offset, rotation));
358  }
359 
360  /** \brief Transform a point cloud and rotate its normals using an Eigen transform.
361  * \param[in] cloud_in the input point cloud
362  * \param[out] cloud_out the resultant output point cloud
363  * \param[in] offset the translation component of the rigid transformation
364  * \param[in] rotation the rotation component of the rigid transformation
365  * \ingroup common
366  */
367  template <typename PointT, typename Scalar> inline void
369  pcl::PointCloud<PointT> &cloud_out,
370  const Eigen::Matrix<Scalar, 3, 1> &offset,
371  const Eigen::Quaternion<Scalar> &rotation);
372 
373  template <typename PointT> void
375  pcl::PointCloud<PointT> &cloud_out,
376  const Eigen::Vector3f &offset,
377  const Eigen::Quaternionf &rotation)
378  {
379  return (transformPointCloudWithNormals<PointT, float> (cloud_in, cloud_out, offset, rotation));
380  }
381 
382  /** \brief Transform a point with members x,y,z
383  * \param[in] point the point to transform
384  * \param[out] transform the transformation to apply
385  * \return the transformed point
386  * \ingroup common
387  */
388  template <typename PointT, typename Scalar> inline PointT
389  transformPoint (const PointT &point,
390  const Eigen::Transform<Scalar, 3, Eigen::Affine> &transform);
391 
392  template <typename PointT> inline PointT
393  transformPoint (const PointT &point,
394  const Eigen::Affine3f &transform)
395  {
396  return (transformPoint<PointT, float> (point, transform));
397  }
398 
399  /** \brief Calculates the principal (PCA-based) alignment of the point cloud
400  * \param[in] cloud the input point cloud
401  * \param[out] transform the resultant transform
402  * \return the ratio lambda1/lambda2 or lambda2/lambda3, whatever is closer to 1.
403  * \note If the return value is close to one then the transformation might be not unique -> two principal directions have
404  * almost same variance (extend)
405  */
406  template <typename PointT, typename Scalar> inline double
408  Eigen::Transform<Scalar, 3, Eigen::Affine> &transform);
409 
410  template <typename PointT> inline double
412  Eigen::Affine3f &transform)
413  {
414  return (getPrincipalTransformation<PointT, float> (cloud, transform));
415  }
416 }
417 
418 #include <pcl/common/impl/transforms.hpp>
419 
420 #endif // PCL_TRANSFORMS_H_