Point Cloud Library (PCL)  1.10.1-dev
point_cloud.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, 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 #pragma once
40 
41 #ifdef __GNUC__
42 #pragma GCC system_header
43 #endif
44 
45 #include <Eigen/StdVector>
46 #include <Eigen/Geometry>
47 #include <pcl/PCLHeader.h>
48 #include <pcl/exceptions.h>
49 #include <pcl/memory.h>
50 #include <pcl/pcl_macros.h>
51 #include <pcl/type_traits.h>
52 
53 #include <algorithm>
54 #include <utility>
55 #include <vector>
56 
57 namespace pcl
58 {
59  namespace detail
60  {
61  struct FieldMapping
62  {
63  std::size_t serialized_offset;
64  std::size_t struct_offset;
65  std::size_t size;
66  };
67  } // namespace detail
68 
69  // Forward declarations
70  template <typename PointT> class PointCloud;
71  using MsgFieldMap = std::vector<detail::FieldMapping>;
72 
73  /** \brief Helper functor structure for copying data between an Eigen type and a PointT. */
74  template <typename PointOutT>
76  {
78 
79  /** \brief Constructor
80  * \param[in] p1 the input Eigen type
81  * \param[out] p2 the output Point type
82  */
83  NdCopyEigenPointFunctor (const Eigen::VectorXf &p1, PointOutT &p2)
84  : p1_ (p1),
85  p2_ (reinterpret_cast<Pod&>(p2)),
86  f_idx_ (0) { }
87 
88  /** \brief Operator. Data copy happens here. */
89  template<typename Key> inline void
90  operator() ()
91  {
92  //boost::fusion::at_key<Key> (p2_) = p1_[f_idx_++];
94  std::uint8_t* data_ptr = reinterpret_cast<std::uint8_t*>(&p2_) + pcl::traits::offset<PointOutT, Key>::value;
95  *reinterpret_cast<T*>(data_ptr) = static_cast<T> (p1_[f_idx_++]);
96  }
97 
98  private:
99  const Eigen::VectorXf &p1_;
100  Pod &p2_;
101  int f_idx_;
102  public:
104  };
105 
106  /** \brief Helper functor structure for copying data between an Eigen type and a PointT. */
107  template <typename PointInT>
109  {
111 
112  /** \brief Constructor
113  * \param[in] p1 the input Point type
114  * \param[out] p2 the output Eigen type
115  */
116  NdCopyPointEigenFunctor (const PointInT &p1, Eigen::VectorXf &p2)
117  : p1_ (reinterpret_cast<const Pod&>(p1)), p2_ (p2), f_idx_ (0) { }
118 
119  /** \brief Operator. Data copy happens here. */
120  template<typename Key> inline void
121  operator() ()
122  {
123  //p2_[f_idx_++] = boost::fusion::at_key<Key> (p1_);
125  const std::uint8_t* data_ptr = reinterpret_cast<const std::uint8_t*>(&p1_) + pcl::traits::offset<PointInT, Key>::value;
126  p2_[f_idx_++] = static_cast<float> (*reinterpret_cast<const T*>(data_ptr));
127  }
128 
129  private:
130  const Pod &p1_;
131  Eigen::VectorXf &p2_;
132  int f_idx_;
133  public:
135  };
136 
137  namespace detail
138  {
139  template <typename PointT>
140  PCL_DEPRECATED(1, 12, "use createMapping() instead")
143  } // namespace detail
144 
145  /** \brief PointCloud represents the base class in PCL for storing collections of 3D points.
146  *
147  * The class is templated, which means you need to specify the type of data
148  * that it should contain. For example, to create a point cloud that holds 4
149  * random XYZ data points, use:
150  *
151  * \code
152  * pcl::PointCloud<pcl::PointXYZ> cloud;
153  * cloud.push_back (pcl::PointXYZ (rand (), rand (), rand ()));
154  * cloud.push_back (pcl::PointXYZ (rand (), rand (), rand ()));
155  * cloud.push_back (pcl::PointXYZ (rand (), rand (), rand ()));
156  * cloud.push_back (pcl::PointXYZ (rand (), rand (), rand ()));
157  * \endcode
158  *
159  * The PointCloud class contains the following elements:
160  * - \b width - specifies the width of the point cloud dataset in the number of points. WIDTH has two meanings:
161  * - it can specify the total number of points in the cloud (equal with POINTS see below) for unorganized datasets;
162  * - it can specify the width (total number of points in a row) of an organized point cloud dataset.
163  * \a Mandatory.
164  * - \b height - specifies the height of the point cloud dataset in the number of points. HEIGHT has two meanings:
165  * - it can specify the height (total number of rows) of an organized point cloud dataset;
166  * - it is set to 1 for unorganized datasets (thus used to check whether a dataset is organized or not).
167  * \a Mandatory.
168  * - \b points - the data array where all points of type <b>PointT</b> are stored. \a Mandatory.
169  *
170  * - \b is_dense - specifies if all the data in <b>points</b> is finite (true), or whether it might contain Inf/NaN values
171  * (false). \a Mandatory.
172  *
173  * - \b sensor_origin_ - specifies the sensor acquisition pose (origin/translation). \a Optional.
174  * - \b sensor_orientation_ - specifies the sensor acquisition pose (rotation). \a Optional.
175  *
176  * \author Patrick Mihelich, Radu B. Rusu
177  */
178  template <typename PointT>
179  class PCL_EXPORTS PointCloud
180  {
181  public:
182  /** \brief Default constructor. Sets \ref is_dense to true, \ref width
183  * and \ref height to 0, and the \ref sensor_origin_ and \ref
184  * sensor_orientation_ to identity.
185  */
186  PointCloud () = default;
187 
188  /** \brief Copy constructor from point cloud subset
189  * \param[in] pc the cloud to copy into this
190  * \param[in] indices the subset to copy
191  */
193  const std::vector<int> &indices) :
194  header (pc.header), points (indices.size ()), width (indices.size ()), height (1), is_dense (pc.is_dense),
195  sensor_origin_ (pc.sensor_origin_), sensor_orientation_ (pc.sensor_orientation_)
196  {
197  // Copy the obvious
198  assert (indices.size () <= pc.size ());
199  for (std::size_t i = 0; i < indices.size (); i++)
200  points[i] = pc.points[indices[i]];
201  }
202 
203  /** \brief Allocate constructor from point cloud subset
204  * \param[in] width_ the cloud width
205  * \param[in] height_ the cloud height
206  * \param[in] value_ default value
207  */
208  PointCloud (std::uint32_t width_, std::uint32_t height_, const PointT& value_ = PointT ())
209  : points (width_ * height_, value_)
210  , width (width_)
211  , height (height_)
212  {}
213 
214  //TODO: check if copy/move contructors/assignment operators are needed
215 
216  /** \brief Add a point cloud to the current cloud.
217  * \param[in] rhs the cloud to add to the current cloud
218  * \return the new cloud as a concatenation of the current cloud and the new given cloud
219  */
220  inline PointCloud&
221  operator += (const PointCloud& rhs)
222  {
223  concatenate((*this), rhs);
224  return (*this);
225  }
226 
227  /** \brief Add a point cloud to another cloud.
228  * \param[in] rhs the cloud to add to the current cloud
229  * \return the new cloud as a concatenation of the current cloud and the new given cloud
230  */
231  inline PointCloud
232  operator + (const PointCloud& rhs)
233  {
234  return (PointCloud (*this) += rhs);
235  }
236 
237  inline static bool
239  const pcl::PointCloud<PointT> &cloud2)
240  {
241  // Make the resultant point cloud take the newest stamp
242  cloud1.header.stamp = std::max (cloud1.header.stamp, cloud2.header.stamp);
243 
244  // libstdc++ (GCC) on calling reserve allocates new memory, copies and deallocates old vector
245  // This causes a drastic performance hit. Prefer not to use reserve with libstdc++ (default on clang)
246  cloud1.points.insert (cloud1.points.end (), cloud2.points.begin (), cloud2.points.end ());
247 
248  cloud1.width = static_cast<std::uint32_t>(cloud1.points.size ());
249  cloud1.height = 1;
250  cloud1.is_dense = cloud1.is_dense && cloud2.is_dense;
251  return true;
252  }
253 
254  inline static bool
256  const pcl::PointCloud<PointT> &cloud2,
257  pcl::PointCloud<PointT> &cloud_out)
258  {
259  cloud_out = cloud1;
260  return concatenate(cloud_out, cloud2);
261  }
262 
263  /** \brief Obtain the point given by the (column, row) coordinates. Only works on organized
264  * datasets (those that have height != 1).
265  * \param[in] column the column coordinate
266  * \param[in] row the row coordinate
267  */
268  inline const PointT&
269  at (int column, int row) const
270  {
271  if (this->height > 1)
272  return (points.at (row * this->width + column));
273  else
274  throw UnorganizedPointCloudException ("Can't use 2D indexing with an unorganized point cloud");
275  }
276 
277  /** \brief Obtain the point given by the (column, row) coordinates. Only works on organized
278  * datasets (those that have height != 1).
279  * \param[in] column the column coordinate
280  * \param[in] row the row coordinate
281  */
282  inline PointT&
283  at (int column, int row)
284  {
285  if (this->height > 1)
286  return (points.at (row * this->width + column));
287  else
288  throw UnorganizedPointCloudException ("Can't use 2D indexing with an unorganized point cloud");
289  }
290 
291  /** \brief Obtain the point given by the (column, row) coordinates. Only works on organized
292  * datasets (those that have height != 1).
293  * \param[in] column the column coordinate
294  * \param[in] row the row coordinate
295  */
296  inline const PointT&
297  operator () (std::size_t column, std::size_t row) const
298  {
299  return (points[row * this->width + column]);
300  }
301 
302  /** \brief Obtain the point given by the (column, row) coordinates. Only works on organized
303  * datasets (those that have height != 1).
304  * \param[in] column the column coordinate
305  * \param[in] row the row coordinate
306  */
307  inline PointT&
308  operator () (std::size_t column, std::size_t row)
309  {
310  return (points[row * this->width + column]);
311  }
312 
313  /** \brief Return whether a dataset is organized (e.g., arranged in a structured grid).
314  * \note The height value must be different than 1 for a dataset to be organized.
315  */
316  inline bool
317  isOrganized () const
318  {
319  return (height > 1);
320  }
321 
322  /** \brief Return an Eigen MatrixXf (assumes float values) mapped to the specified dimensions of the PointCloud.
323  * \note This method is for advanced users only! Use with care!
324  *
325  * \attention Since 1.4.0, Eigen matrices are forced to Row Major to increase the efficiency of the algorithms in PCL
326  * This means that the behavior of getMatrixXfMap changed, and is now correctly mapping 1-1 with a PointCloud structure,
327  * that is: number of points in a cloud = rows in a matrix, number of point dimensions = columns in a matrix
328  *
329  * \param[in] dim the number of dimensions to consider for each point
330  * \param[in] stride the number of values in each point (will be the number of values that separate two of the columns)
331  * \param[in] offset the number of dimensions to skip from the beginning of each point
332  * (stride = offset + dim + x, where x is the number of dimensions to skip from the end of each point)
333  * \note for getting only XYZ coordinates out of PointXYZ use dim=3, stride=4 and offset=0 due to the alignment.
334  * \attention PointT types are most of the time aligned, so the offsets are not continuous!
335  */
336  inline Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >
337  getMatrixXfMap (int dim, int stride, int offset)
338  {
339  if (Eigen::MatrixXf::Flags & Eigen::RowMajorBit)
340  return (Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >(reinterpret_cast<float*>(&points[0])+offset, points.size (), dim, Eigen::OuterStride<> (stride)));
341  else
342  return (Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >(reinterpret_cast<float*>(&points[0])+offset, dim, points.size (), Eigen::OuterStride<> (stride)));
343  }
344 
345  /** \brief Return an Eigen MatrixXf (assumes float values) mapped to the specified dimensions of the PointCloud.
346  * \note This method is for advanced users only! Use with care!
347  *
348  * \attention Since 1.4.0, Eigen matrices are forced to Row Major to increase the efficiency of the algorithms in PCL
349  * This means that the behavior of getMatrixXfMap changed, and is now correctly mapping 1-1 with a PointCloud structure,
350  * that is: number of points in a cloud = rows in a matrix, number of point dimensions = columns in a matrix
351  *
352  * \param[in] dim the number of dimensions to consider for each point
353  * \param[in] stride the number of values in each point (will be the number of values that separate two of the columns)
354  * \param[in] offset the number of dimensions to skip from the beginning of each point
355  * (stride = offset + dim + x, where x is the number of dimensions to skip from the end of each point)
356  * \note for getting only XYZ coordinates out of PointXYZ use dim=3, stride=4 and offset=0 due to the alignment.
357  * \attention PointT types are most of the time aligned, so the offsets are not continuous!
358  */
359  inline const Eigen::Map<const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >
360  getMatrixXfMap (int dim, int stride, int offset) const
361  {
362  if (Eigen::MatrixXf::Flags & Eigen::RowMajorBit)
363  return (Eigen::Map<const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >(reinterpret_cast<float*>(const_cast<PointT*>(&points[0]))+offset, points.size (), dim, Eigen::OuterStride<> (stride)));
364  else
365  return (Eigen::Map<const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >(reinterpret_cast<float*>(const_cast<PointT*>(&points[0]))+offset, dim, points.size (), Eigen::OuterStride<> (stride)));
366  }
367 
368  /**
369  * \brief Return an Eigen MatrixXf (assumes float values) mapped to the PointCloud.
370  * \note This method is for advanced users only! Use with care!
371  * \attention PointT types are most of the time aligned, so the offsets are not continuous!
372  * \overload Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> > pcl::PointCloud::getMatrixXfMap ()
373  */
374  inline Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >
376  {
377  return (getMatrixXfMap (sizeof (PointT) / sizeof (float), sizeof (PointT) / sizeof (float), 0));
378  }
379 
380  /**
381  * \brief Return an Eigen MatrixXf (assumes float values) mapped to the PointCloud.
382  * \note This method is for advanced users only! Use with care!
383  * \attention PointT types are most of the time aligned, so the offsets are not continuous!
384  * \overload const Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> > pcl::PointCloud::getMatrixXfMap () const
385  */
386  inline const Eigen::Map<const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >
387  getMatrixXfMap () const
388  {
389  return (getMatrixXfMap (sizeof (PointT) / sizeof (float), sizeof (PointT) / sizeof (float), 0));
390  }
391 
392  /** \brief The point cloud header. It contains information about the acquisition time. */
394 
395  /** \brief The point data. */
396  std::vector<PointT, Eigen::aligned_allocator<PointT> > points;
397 
398  /** \brief The point cloud width (if organized as an image-structure). */
399  std::uint32_t width = 0;
400  /** \brief The point cloud height (if organized as an image-structure). */
401  std::uint32_t height = 0;
402 
403  /** \brief True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields). */
404  bool is_dense = true;
405 
406  /** \brief Sensor acquisition pose (origin/translation). */
407  Eigen::Vector4f sensor_origin_ = Eigen::Vector4f::Zero ();
408  /** \brief Sensor acquisition pose (rotation). */
409  Eigen::Quaternionf sensor_orientation_ = Eigen::Quaternionf::Identity ();
410 
411  using PointType = PointT; // Make the template class available from the outside
412  using VectorType = std::vector<PointT, Eigen::aligned_allocator<PointT> >;
413  using CloudVectorType = std::vector<PointCloud<PointT>, Eigen::aligned_allocator<PointCloud<PointT> > >;
416 
417  // std container compatibility typedefs according to
418  // http://en.cppreference.com/w/cpp/concept/Container
420  using reference = PointT&;
421  using const_reference = const PointT&;
422  using difference_type = typename VectorType::difference_type;
423  using size_type = typename VectorType::size_type;
424 
425  // iterators
426  using iterator = typename VectorType::iterator;
427  using const_iterator = typename VectorType::const_iterator;
428  inline iterator begin () { return (points.begin ()); }
429  inline iterator end () { return (points.end ()); }
430  inline const_iterator begin () const { return (points.begin ()); }
431  inline const_iterator end () const { return (points.end ()); }
432 
433  //capacity
434  inline std::size_t size () const { return (points.size ()); }
435  inline void reserve (std::size_t n) { points.reserve (n); }
436  inline bool empty () const { return points.empty (); }
437 
438  /** \brief Resize the cloud
439  * \param[in] n the new cloud size
440  */
441  inline void resize (std::size_t n)
442  {
443  points.resize (n);
444  if (width * height != n)
445  {
446  width = static_cast<std::uint32_t> (n);
447  height = 1;
448  }
449  }
450 
451  //element access
452  inline const PointT& operator[] (std::size_t n) const { return (points[n]); }
453  inline PointT& operator[] (std::size_t n) { return (points[n]); }
454  inline const PointT& at (std::size_t n) const { return (points.at (n)); }
455  inline PointT& at (std::size_t n) { return (points.at (n)); }
456  inline const PointT& front () const { return (points.front ()); }
457  inline PointT& front () { return (points.front ()); }
458  inline const PointT& back () const { return (points.back ()); }
459  inline PointT& back () { return (points.back ()); }
460 
461  /** \brief Insert a new point in the cloud, at the end of the container.
462  * \note This breaks the organized structure of the cloud by setting the height to 1!
463  * \param[in] pt the point to insert
464  */
465  inline void
466  push_back (const PointT& pt)
467  {
468  points.push_back (pt);
469  width = static_cast<std::uint32_t> (points.size ());
470  height = 1;
471  }
472 
473  /** \brief Emplace a new point in the cloud, at the end of the container.
474  * \note This breaks the organized structure of the cloud by setting the height to 1!
475  * \param[in] args the parameters to forward to the point to construct
476  * \return reference to the emplaced point
477  */
478  template <class... Args> inline reference
479  emplace_back (Args&& ...args)
480  {
481  points.emplace_back (std::forward<Args> (args)...);
482  width = static_cast<std::uint32_t> (points.size ());
483  height = 1;
484  return points.back();
485  }
486 
487  /** \brief Insert a new point in the cloud, given an iterator.
488  * \note This breaks the organized structure of the cloud by setting the height to 1!
489  * \param[in] position where to insert the point
490  * \param[in] pt the point to insert
491  * \return returns the new position iterator
492  */
493  inline iterator
494  insert (iterator position, const PointT& pt)
495  {
496  iterator it = points.insert (position, pt);
497  width = static_cast<std::uint32_t> (points.size ());
498  height = 1;
499  return (it);
500  }
501 
502  /** \brief Insert a new point in the cloud N times, given an iterator.
503  * \note This breaks the organized structure of the cloud by setting the height to 1!
504  * \param[in] position where to insert the point
505  * \param[in] n the number of times to insert the point
506  * \param[in] pt the point to insert
507  */
508  inline void
509  insert (iterator position, std::size_t n, const PointT& pt)
510  {
511  points.insert (position, n, pt);
512  width = static_cast<std::uint32_t> (points.size ());
513  height = 1;
514  }
515 
516  /** \brief Insert a new range of points in the cloud, at a certain position.
517  * \note This breaks the organized structure of the cloud by setting the height to 1!
518  * \param[in] position where to insert the data
519  * \param[in] first where to start inserting the points from
520  * \param[in] last where to stop inserting the points from
521  */
522  template <class InputIterator> inline void
523  insert (iterator position, InputIterator first, InputIterator last)
524  {
525  points.insert (position, first, last);
526  width = static_cast<std::uint32_t> (points.size ());
527  height = 1;
528  }
529 
530  /** \brief Emplace a new point in the cloud, given an iterator.
531  * \note This breaks the organized structure of the cloud by setting the height to 1!
532  * \param[in] position iterator before which the point will be emplaced
533  * \param[in] args the parameters to forward to the point to construct
534  * \return returns the new position iterator
535  */
536  template <class... Args> inline iterator
537  emplace (iterator position, Args&& ...args)
538  {
539  iterator it = points.emplace (position, std::forward<Args> (args)...);
540  width = static_cast<std::uint32_t> (points.size ());
541  height = 1;
542  return (it);
543  }
544 
545  /** \brief Erase a point in the cloud.
546  * \note This breaks the organized structure of the cloud by setting the height to 1!
547  * \param[in] position what data point to erase
548  * \return returns the new position iterator
549  */
550  inline iterator
551  erase (iterator position)
552  {
553  iterator it = points.erase (position);
554  width = static_cast<std::uint32_t> (points.size ());
555  height = 1;
556  return (it);
557  }
558 
559  /** \brief Erase a set of points given by a (first, last) iterator pair
560  * \note This breaks the organized structure of the cloud by setting the height to 1!
561  * \param[in] first where to start erasing points from
562  * \param[in] last where to stop erasing points from
563  * \return returns the new position iterator
564  */
565  inline iterator
566  erase (iterator first, iterator last)
567  {
568  iterator it = points.erase (first, last);
569  width = static_cast<std::uint32_t> (points.size ());
570  height = 1;
571  return (it);
572  }
573 
574  /** \brief Swap a point cloud with another cloud.
575  * \param[in,out] rhs point cloud to swap this with
576  */
577  inline void
579  {
580  std::swap (header, rhs.header);
581  this->points.swap (rhs.points);
582  std::swap (width, rhs.width);
583  std::swap (height, rhs.height);
584  std::swap (is_dense, rhs.is_dense);
585  std::swap (sensor_origin_, rhs.sensor_origin_);
586  std::swap (sensor_orientation_, rhs.sensor_orientation_);
587  }
588 
589  /** \brief Removes all points in a cloud and sets the width and height to 0. */
590  inline void
591  clear ()
592  {
593  points.clear ();
594  width = 0;
595  height = 0;
596  }
597 
598  /** \brief Copy the cloud to the heap and return a smart pointer
599  * Note that deep copy is performed, so avoid using this function on non-empty clouds.
600  * The changes of the returned cloud are not mirrored back to this one.
601  * \return shared pointer to the copy of the cloud
602  */
603  inline Ptr
604  makeShared () const { return Ptr (new PointCloud<PointT> (*this)); }
605 
606  protected:
607  // This is motivated by ROS integration. Users should not need to access mapping_.
608  PCL_DEPRECATED(1, 12, "rewrite your code to avoid using this protected field") shared_ptr<MsgFieldMap> mapping_;
609 
610  friend shared_ptr<MsgFieldMap>& detail::getMapping<PointT>(pcl::PointCloud<PointT> &p);
611 
612  public:
614  };
615 
616  namespace detail
617  {
618  template <typename PointT> shared_ptr<pcl::MsgFieldMap>&
620  {
621  return (p.mapping_);
622  }
623  } // namespace detail
624 
625  template <typename PointT> std::ostream&
626  operator << (std::ostream& s, const pcl::PointCloud<PointT> &p)
627  {
628  s << "header: " << p.header << std::endl;
629  s << "points[]: " << p.points.size () << std::endl;
630  s << "width: " << p.width << std::endl;
631  s << "height: " << p.height << std::endl;
632  s << "is_dense: " << p.is_dense << std::endl;
633  s << "sensor origin (xyz): [" <<
634  p.sensor_origin_.x () << ", " <<
635  p.sensor_origin_.y () << ", " <<
636  p.sensor_origin_.z () << "] / orientation (xyzw): [" <<
637  p.sensor_orientation_.x () << ", " <<
638  p.sensor_orientation_.y () << ", " <<
639  p.sensor_orientation_.z () << ", " <<
640  p.sensor_orientation_.w () << "]" <<
641  std::endl;
642  return (s);
643  }
644 }
645 
646 #define PCL_INSTANTIATE_PointCloud(T) template class PCL_EXPORTS pcl::PointCloud<T>;
Helper functor structure for copying data between an Eigen type and a PointT.
Definition: point_cloud.h:108
iterator erase(iterator position)
Erase a point in the cloud.
Definition: point_cloud.h:551
NdCopyPointEigenFunctor(const PointInT &p1, Eigen::VectorXf &p2)
Constructor.
Definition: point_cloud.h:116
std::vector< detail::FieldMapping > MsgFieldMap
Definition: point_cloud.h:71
shared_ptr< PointCloud< pcl::RGB > > Ptr
Definition: point_cloud.h:414
Defines functions, macros and traits for allocating and using memory.
reference emplace_back(Args &&...args)
Emplace a new point in the cloud, at the end of the container.
Definition: point_cloud.h:479
PointT & at(int column, int row)
Obtain the point given by the (column, row) coordinates.
Definition: point_cloud.h:283
std::uint64_t stamp
A timestamp associated with the time when the data was acquired.
Definition: PCLHeader.h:18
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:396
const_iterator begin() const
Definition: point_cloud.h:430
Helper functor structure for copying data between an Eigen type and a PointT.
Definition: point_cloud.h:75
typename VectorType::const_iterator const_iterator
Definition: point_cloud.h:427
PointT & at(std::size_t n)
Definition: point_cloud.h:455
NdCopyEigenPointFunctor(const Eigen::VectorXf &p1, PointOutT &p2)
Constructor.
Definition: point_cloud.h:83
PointT & back()
Definition: point_cloud.h:459
void resize(std::size_t n)
Resize the cloud.
Definition: point_cloud.h:441
iterator end()
Definition: point_cloud.h:429
const Eigen::Map< const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> > getMatrixXfMap(int dim, int stride, int offset) const
Return an Eigen MatrixXf (assumes float values) mapped to the specified dimensions of the PointCloud...
Definition: point_cloud.h:360
iterator emplace(iterator position, Args &&...args)
Emplace a new point in the cloud, given an iterator.
Definition: point_cloud.h:537
std::size_t size() const
Definition: point_cloud.h:434
void push_back(const PointT &pt)
Insert a new point in the cloud, at the end of the container.
Definition: point_cloud.h:466
PointCloud(const PointCloud< PointT > &pc, const std::vector< int > &indices)
Copy constructor from point cloud subset.
Definition: point_cloud.h:192
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:65
std::vector< pcl::RGB, Eigen::aligned_allocator< pcl::RGB > > VectorType
Definition: point_cloud.h:412
const PointT & at(int column, int row) const
Obtain the point given by the (column, row) coordinates.
Definition: point_cloud.h:269
std::size_t serialized_offset
Definition: point_cloud.h:63
bool isOrganized() const
Return whether a dataset is organized (e.g., arranged in a structured grid).
Definition: point_cloud.h:317
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:399
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
Definition: point_cloud.h:407
A structure representing RGB color information.
Eigen::Map< Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> > getMatrixXfMap()
Definition: point_cloud.h:375
static bool concatenate(const pcl::PointCloud< PointT > &cloud1, const pcl::PointCloud< PointT > &cloud2, pcl::PointCloud< PointT > &cloud_out)
Definition: point_cloud.h:255
void swap(PointCloud< PointT > &rhs)
Swap a point cloud with another cloud.
Definition: point_cloud.h:578
const PointT & front() const
Definition: point_cloud.h:456
std::vector< PointCloud< pcl::RGB >, Eigen::aligned_allocator< PointCloud< pcl::RGB > > > CloudVectorType
Definition: point_cloud.h:413
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
Definition: point_cloud.h:409
PointT & front()
Definition: point_cloud.h:457
void clear()
Removes all points in a cloud and sets the width and height to 0.
Definition: point_cloud.h:591
PCL_EXPORTS bool concatenate(const pcl::PointCloud< PointT > &cloud1, const pcl::PointCloud< PointT > &cloud2, pcl::PointCloud< PointT > &cloud_out)
Concatenate two pcl::PointCloud<PointT>
Definition: io.h:282
Eigen::Map< Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> > getMatrixXfMap(int dim, int stride, int offset)
Return an Eigen MatrixXf (assumes float values) mapped to the specified dimensions of the PointCloud...
Definition: point_cloud.h:337
iterator erase(iterator first, iterator last)
Erase a set of points given by a (first, last) iterator pair.
Definition: point_cloud.h:566
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:401
PointCloud(std::uint32_t width_, std::uint32_t height_, const PointT &value_=PointT())
Allocate constructor from point cloud subset.
Definition: point_cloud.h:208
PointCloud represents the base class in PCL for storing collections of 3D points. ...
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:393
const_iterator end() const
Definition: point_cloud.h:431
static bool concatenate(pcl::PointCloud< PointT > &cloud1, const pcl::PointCloud< PointT > &cloud2)
Definition: point_cloud.h:238
typename VectorType::iterator iterator
Definition: point_cloud.h:426
const Eigen::Map< const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> > getMatrixXfMap() const
Definition: point_cloud.h:387
typename traits::POD< PointOutT >::type Pod
Definition: point_cloud.h:77
An exception that is thrown when an organized point cloud is needed but not provided.
Definition: exceptions.h:208
void insert(iterator position, InputIterator first, InputIterator last)
Insert a new range of points in the cloud, at a certain position.
Definition: point_cloud.h:523
void insert(iterator position, std::size_t n, const PointT &pt)
Insert a new point in the cloud N times, given an iterator.
Definition: point_cloud.h:509
const PointT & back() const
Definition: point_cloud.h:458
typename VectorType::difference_type difference_type
Definition: point_cloud.h:422
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields)...
Definition: point_cloud.h:404
void reserve(std::size_t n)
Definition: point_cloud.h:435
shared_ptr< pcl::MsgFieldMap > & getMapping(pcl::PointCloud< PointT > &p)
Definition: point_cloud.h:619
shared_ptr< const PointCloud< pcl::RGB > > ConstPtr
Definition: point_cloud.h:415
iterator begin()
Definition: point_cloud.h:428
Ptr makeShared() const
Copy the cloud to the heap and return a smart pointer Note that deep copy is performed, so avoid using this function on non-empty clouds.
Definition: point_cloud.h:604
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major...
Definition: pcl_macros.h:120
A point structure representing Euclidean xyz coordinates, and the RGB color.
typename VectorType::size_type size_type
Definition: point_cloud.h:423
iterator insert(iterator position, const PointT &pt)
Insert a new point in the cloud, given an iterator.
Definition: point_cloud.h:494
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: memory.h:81
#define PCL_EXPORTS
Definition: pcl_macros.h:276
Defines all the PCL and non-PCL macros used.
typename traits::POD< PointInT >::type Pod
Definition: point_cloud.h:110
const PointT & at(std::size_t n) const
Definition: point_cloud.h:454
bool empty() const
Definition: point_cloud.h:436