42 #pragma GCC system_header
45 #include <Eigen/StdVector>
46 #include <Eigen/Geometry>
47 #include <pcl/PCLHeader.h>
48 #include <pcl/exceptions.h>
51 #include <pcl/type_traits.h>
53 #include <pcl/console/print.h>
75 template <
typename Po
intOutT>
78 using Pod =
typename traits::POD<PointOutT>::type;
86 p2_ (reinterpret_cast<
Pod&>(p2)),
90 template<
typename Key>
inline void
94 using T =
typename pcl::traits::datatype<PointOutT, Key>::type;
95 std::uint8_t* data_ptr =
reinterpret_cast<std::uint8_t*
>(&p2_) + pcl::traits::offset<PointOutT, Key>::value;
96 *
reinterpret_cast<T*
>(data_ptr) =
static_cast<T
> (p1_[f_idx_++]);
100 const Eigen::VectorXf &p1_;
108 template <
typename Po
intInT>
111 using Pod =
typename traits::POD<PointInT>::type;
118 : p1_ (reinterpret_cast<const
Pod&>(p1)), p2_ (p2), f_idx_ (0) { }
121 template<
typename Key>
inline void
125 using T =
typename pcl::traits::datatype<PointInT, Key>::type;
126 const std::uint8_t* data_ptr =
reinterpret_cast<const std::uint8_t*
>(&p1_) + pcl::traits::offset<PointInT, Key>::value;
127 p2_[f_idx_++] =
static_cast<float> (*
reinterpret_cast<const T*
>(data_ptr));
132 Eigen::VectorXf &p2_;
171 template <
typename Po
intT>
191 assert (indices.size () <= pc.
size ());
192 for (std::size_t i = 0; i < indices.size (); i++)
193 points[i] = pc[indices[i]];
202 :
points (width_ * height_, value_)
262 at (
int column,
int row)
const
265 return (
points.at (row * this->width + column));
276 at (
int column,
int row)
279 return (
points.at (row * this->width + column));
332 inline Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >
335 if (Eigen::MatrixXf::Flags & Eigen::RowMajorBit)
336 return (Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >(
reinterpret_cast<float*
>(&
points[0])+offset,
size (), dim, Eigen::OuterStride<> (stride)));
338 return (Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >(
reinterpret_cast<float*
>(&
points[0])+offset, dim,
size (), Eigen::OuterStride<> (stride)));
358 inline const Eigen::Map<const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >
361 if (Eigen::MatrixXf::Flags & Eigen::RowMajorBit)
362 return (Eigen::Map<
const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >(
reinterpret_cast<float*
>(
const_cast<PointT*
>(&
points[0]))+offset,
size (), dim, Eigen::OuterStride<> (stride)));
364 return (Eigen::Map<
const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >(
reinterpret_cast<float*
>(
const_cast<PointT*
>(&
points[0]))+offset, dim,
size (), Eigen::OuterStride<> (stride)));
373 inline Eigen::Map<Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >
385 inline const Eigen::Map<const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> >
395 std::vector<PointT, Eigen::aligned_allocator<PointT> >
points;
411 using VectorType = std::vector<PointT, Eigen::aligned_allocator<PointT> >;
412 using CloudVectorType = std::vector<PointCloud<PointT>, Eigen::aligned_allocator<PointCloud<PointT> > >;
413 using Ptr = shared_ptr<PointCloud<PointT> >;
414 using ConstPtr = shared_ptr<const PointCloud<PointT> >;
466 width =
static_cast<std::uint32_t
>(count);
484 points.resize(new_width * new_height);
504 points.resize(count, value);
525 points.resize(new_width * new_height, value);
550 points.assign(count, value);
551 width =
static_cast<std::uint32_t
>(
size());
564 points.assign(new_width * new_height, value);
576 template <
class InputIterator>
578 assign(InputIterator first, InputIterator last)
580 points.assign(std::move(first), std::move(last));
581 width =
static_cast<std::uint32_t
>(
size());
594 template <
class InputIterator>
598 if (new_width == 0) {
599 PCL_WARN(
"Assignment with new_width equal to 0,"
600 "setting width to size of the cloud and height to 1\n");
601 return assign(std::move(first), std::move(last));
604 points.assign(std::move(first), std::move(last));
608 PCL_WARN(
"Mismatch in assignment. Requested width (%zu) doesn't divide "
609 "provided size (%zu) cleanly. Setting height to 1\n",
610 static_cast<std::size_t
>(
width),
611 static_cast<std::size_t
>(
size()));
623 inline assign(std::initializer_list<PointT> ilist)
625 points.assign(std::move(ilist));
626 width =
static_cast<std::uint32_t
>(
size());
640 if (new_width == 0) {
641 PCL_WARN(
"Assignment with new_width equal to 0,"
642 "setting width to size of the cloud and height to 1\n");
643 return assign(std::move(ilist));
645 points.assign(std::move(ilist));
649 PCL_WARN(
"Mismatch in assignment. Requested width (%zu) doesn't divide "
650 "provided size (%zu) cleanly. Setting height to 1\n",
651 static_cast<std::size_t
>(
width),
652 static_cast<std::size_t
>(
size()));
685 template <
class... Args>
inline reference
688 points.emplace_back (std::forward<Args> (args)...);
699 template <
class... Args>
inline reference
702 points.emplace_back (std::forward<Args> (args)...);
743 points.insert (std::move(position), n, pt);
757 points.insert (std::move(position), n, pt);
766 template <
class InputIterator>
inline void
769 points.insert (std::move(position), std::move(first), std::move(last));
780 template <
class InputIterator>
inline void
783 points.insert (std::move(position), std::move(first), std::move(last));
792 template <
class... Args>
inline iterator
795 iterator it =
points.emplace (std::move(position), std::forward<Args> (args)...);
807 template <
class... Args>
inline iterator
810 iterator it =
points.emplace (std::move(position), std::forward<Args> (args)...);
875 this->points.swap (rhs.
points);
904 template <
typename Po
intT> std::ostream&
907 s <<
"header: " << p.
header << std::endl;
908 s <<
"points[]: " << p.
size () << std::endl;
909 s <<
"width: " << p.
width << std::endl;
910 s <<
"height: " << p.
height << std::endl;
911 s <<
"is_dense: " << p.
is_dense << std::endl;
912 s <<
"sensor origin (xyz): [" <<
PointCloud represents the base class in PCL for storing collections of 3D points.
typename VectorType::size_type size_type
iterator erase(iterator position)
Erase a point in the cloud.
const_reverse_iterator rend() const noexcept
void resize(uindex_t new_width, uindex_t new_height)
Resizes the container to contain new_width * new_height elements.
const_iterator cbegin() const noexcept
void push_back(const PointT &pt)
Insert a new point in the cloud, at the end of the container.
reference transient_emplace_back(Args &&...args)
Emplace a new point in the cloud, at the end of the container.
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.
const PointT & at(int column, int row) const
Obtain the point given by the (column, row) coordinates.
reverse_iterator rbegin() noexcept
const_iterator begin() const noexcept
const_iterator cend() const noexcept
const PointT & operator[](std::size_t n) const
void insert(iterator position, std::size_t n, const PointT &pt)
Insert a new point in the cloud N times, given an iterator.
void transient_insert(iterator position, std::size_t n, const PointT &pt)
Insert a new point in the cloud N times, given an iterator.
iterator erase(iterator first, iterator last)
Erase a set of points given by a (first, last) iterator pair.
const_reverse_iterator crend() const noexcept
PointCloud & operator+=(const PointCloud &rhs)
Add a point cloud to the current cloud.
Eigen::Map< Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> > getMatrixXfMap()
PointCloud(std::uint32_t width_, std::uint32_t height_, const PointT &value_=PointT())
Allocate constructor from point cloud subset.
void resize(index_t count, const PointT &value)
Resizes the container to contain count elements.
PointT & at(std::size_t n)
const_reverse_iterator crbegin() const noexcept
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
void insert(iterator position, InputIterator first, InputIterator last)
Insert a new range of points in the cloud, at a certain position.
iterator transient_erase(iterator first, iterator last)
Erase a set of points given by a (first, last) iterator pair.
PointCloud operator+(const PointCloud &rhs)
Add a point cloud to another cloud.
typename VectorType::reverse_iterator reverse_iterator
const PointT & at(std::size_t n) const
const PointT & front() const
iterator transient_erase(iterator position)
Erase a point in the cloud.
void resize(std::size_t count)
Resizes the container to contain count elements.
void assign(InputIterator first, InputIterator last, index_t new_width)
Replaces the points with copies of those in the range [first, last)
typename VectorType::iterator iterator
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
void transient_push_back(const PointT &pt)
Insert a new point in the cloud, at the end of the container.
const PointT & back() const
std::uint32_t width
The point cloud width (if organized as an image-structure).
void assign(std::initializer_list< PointT > ilist)
Replaces the points with the elements from the initializer list ilist
reference emplace_back(Args &&...args)
Emplace a new point in the cloud, at the end of the container.
iterator insert(iterator position, const PointT &pt)
Insert a new point in the cloud, given an iterator.
PointCloud(const PointCloud< PointT > &pc, const Indices &indices)
Copy constructor from point cloud subset.
PointCloud()=default
Default constructor.
pcl::PCLHeader header
The point cloud header.
std::vector< PointCloud< PointT >, Eigen::aligned_allocator< PointCloud< PointT > > > CloudVectorType
iterator emplace(iterator position, Args &&...args)
Emplace a new point in the cloud, given an iterator.
static bool concatenate(const pcl::PointCloud< PointT > &cloud1, const pcl::PointCloud< PointT > &cloud2, pcl::PointCloud< PointT > &cloud_out)
void assign(InputIterator first, InputIterator last)
Replaces the points with copies of those in the range [first, last)
typename VectorType::const_iterator const_iterator
bool isOrganized() const
Return whether a dataset is organized (e.g., arranged in a structured grid).
std::uint32_t height
The point cloud height (if organized as an image-structure).
PointT & at(int column, int row)
Obtain the point given by the (column, row) coordinates.
void clear()
Removes all points in a cloud and sets the width and height to 0.
void resize(index_t new_width, index_t new_height, const PointT &value)
Resizes the container to contain count elements.
void transient_insert(iterator position, InputIterator first, InputIterator last)
Insert a new range of points in the cloud, at a certain position.
typename VectorType::const_reverse_iterator const_reverse_iterator
void assign(std::initializer_list< PointT > ilist, index_t new_width)
Replaces the points with the elements from the initializer list ilist
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
void reserve(std::size_t n)
const PointT & operator()(std::size_t column, std::size_t row) const
Obtain the point given by the (column, row) coordinates.
std::vector< PointT, Eigen::aligned_allocator< PointT > > VectorType
void swap(PointCloud< PointT > &rhs)
Swap a point cloud with another cloud.
shared_ptr< PointCloud< PointT > > Ptr
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.
typename VectorType::difference_type difference_type
index_t max_size() const noexcept
const_iterator end() const noexcept
iterator begin() noexcept
void assign(index_t count, const PointT &value)
Replaces the points with count copies of value
const Eigen::Map< const Eigen::MatrixXf, Eigen::Aligned, Eigen::OuterStride<> > getMatrixXfMap() const
const_reverse_iterator rbegin() const noexcept
void assign(index_t new_width, index_t new_height, const PointT &value)
Replaces the points with new_width * new_height copies of value
iterator transient_insert(iterator position, const PointT &pt)
Insert a new point in the cloud, given an iterator.
iterator transient_emplace(iterator position, Args &&...args)
Emplace a new point in the cloud, given an iterator.
static bool concatenate(pcl::PointCloud< PointT > &cloud1, const pcl::PointCloud< PointT > &cloud2)
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
reverse_iterator rend() noexcept
shared_ptr< const PointCloud< PointT > > ConstPtr
const PointT * data() const noexcept
Ptr makeShared() const
Copy the cloud to the heap and return a smart pointer Note that deep copy is performed,...
An exception that is thrown when an organized point cloud is needed but not provided.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Defines functions, macros and traits for allocating and using memory.
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
IndicesAllocator<> Indices
Type used for indices in PCL.
std::vector< detail::FieldMapping > MsgFieldMap
Defines all the PCL and non-PCL macros used.
Helper functor structure for copying data between an Eigen type and a PointT.
NdCopyEigenPointFunctor(const Eigen::VectorXf &p1, PointOutT &p2)
Constructor.
typename traits::POD< PointOutT >::type Pod
void operator()()
Operator.
Helper functor structure for copying data between an Eigen type and a PointT.
typename traits::POD< PointInT >::type Pod
void operator()()
Operator.
NdCopyPointEigenFunctor(const PointInT &p1, Eigen::VectorXf &p2)
Constructor.
A point structure representing Euclidean xyz coordinates, and the RGB color.
std::size_t struct_offset
std::size_t serialized_offset
Defines basic non-point types used by PCL.