Point Cloud Library (PCL) 1.13.0
Loading...
Searching...
No Matches
PCLPointCloud2.h
1#pragma once
2
3#include <ostream>
4#include <vector>
5
6#include <boost/predef/other/endian.h>
7
8#include <pcl/pcl_macros.h> // for PCL_EXPORTS
9#include <pcl/PCLHeader.h>
10#include <pcl/PCLPointField.h>
11#include <pcl/types.h>
12
13namespace pcl
14{
15
16 struct PCL_EXPORTS PCLPointCloud2
17 {
19
20 uindex_t height = 0;
21 uindex_t width = 0;
22
23 std::vector<::pcl::PCLPointField> fields;
24
25 static_assert(BOOST_ENDIAN_BIG_BYTE || BOOST_ENDIAN_LITTLE_BYTE, "unable to determine system endianness");
26 std::uint8_t is_bigendian = BOOST_ENDIAN_BIG_BYTE;
27 uindex_t point_step = 0;
28 uindex_t row_step = 0;
29
30 std::vector<std::uint8_t> data;
31
32 std::uint8_t is_dense = 0;
33
34 public:
35 using Ptr = shared_ptr< ::pcl::PCLPointCloud2>;
36 using ConstPtr = shared_ptr<const ::pcl::PCLPointCloud2>;
37
38 //////////////////////////////////////////////////////////////////////////
39 /** \brief Inplace concatenate two pcl::PCLPointCloud2
40 *
41 * IFF the layout of all the fields in both the clouds is the same, this command
42 * doesn't remove any fields named "_" (aka marked as skip). For comparison of field
43 * names, "rgb" and "rgba" are considered equivalent
44 * However, if the order and/or number of non-skip fields is different, the skip fields
45 * are dropped and non-skip fields copied selectively.
46 * This function returns an error if
47 * * the total number of non-skip fields is different
48 * * the non-skip field names are named differently (excluding "rbg{a}") in serial order
49 * * the endian-ness of both clouds is different
50 * \param[in,out] cloud1 the first input and output point cloud dataset
51 * \param[in] cloud2 the second input point cloud dataset
52 * \return true if successful, false if failed (e.g., name/number of fields differs)
53 */
54 static bool
56
57 /** \brief Concatenate two pcl::PCLPointCloud2
58 * \param[in] cloud1 the first input point cloud dataset
59 * \param[in] cloud2 the second input point cloud dataset
60 * \param[out] cloud_out the resultant output point cloud dataset
61 * \return true if successful, false if failed (e.g., name/number of fields differs)
62 */
63 static bool
65 const PCLPointCloud2 &cloud2,
66 PCLPointCloud2 &cloud_out)
67 {
68 cloud_out = cloud1;
69 return concatenate(cloud_out, cloud2);
70 }
71
72 /** \brief Add a point cloud to the current cloud.
73 * \param[in] rhs the cloud to add to the current cloud
74 * \return the new cloud as a concatenation of the current cloud and the new given cloud
75 */
77 operator += (const PCLPointCloud2& rhs);
78
79 /** \brief Add a point cloud to another cloud.
80 * \param[in] rhs the cloud to add to the current cloud
81 * \return the new cloud as a concatenation of the current cloud and the new given cloud
82 */
83 inline PCLPointCloud2
84 operator + (const PCLPointCloud2& rhs)
85 {
86 return (PCLPointCloud2 (*this) += rhs);
87 }
88
89 /** \brief Get value at specified offset.
90 * \param[in] point_index point index.
91 * \param[in] field_offset offset.
92 * \return value at the given offset.
93 */
94 template<typename T> inline
95 const T& at(const pcl::uindex_t& point_index, const pcl::uindex_t& field_offset) const {
96 const auto position = point_index * point_step + field_offset;
97 if (data.size () >= (position + sizeof(T)))
98 return reinterpret_cast<const T&>(data[position]);
99 else
100 throw std::out_of_range("PCLPointCloud2::at");
101 }
102
103 /** \brief Get value at specified offset.
104 * \param[in] point_index point index.
105 * \param[in] field_offset offset.
106 * \return value at the given offset.
107 */
108 template<typename T> inline
109 T& at(const pcl::uindex_t& point_index, const pcl::uindex_t& field_offset) {
110 const auto position = point_index * point_step + field_offset;
111 if (data.size () >= (position + sizeof(T)))
112 return reinterpret_cast<T&>(data[position]);
113 else
114 throw std::out_of_range("PCLPointCloud2::at");
115 }
116 }; // struct PCLPointCloud2
117
120
121 inline std::ostream& operator<<(std::ostream& s, const ::pcl::PCLPointCloud2 &v)
122 {
123 s << "header: " << std::endl;
124 s << v.header;
125 s << "height: ";
126 s << " " << v.height << std::endl;
127 s << "width: ";
128 s << " " << v.width << std::endl;
129 s << "fields[]" << std::endl;
130 for (std::size_t i = 0; i < v.fields.size (); ++i)
131 {
132 s << " fields[" << i << "]: ";
133 s << std::endl;
134 s << " " << v.fields[i] << std::endl;
135 }
136 s << "is_bigendian: ";
137 s << " " << v.is_bigendian << std::endl;
138 s << "point_step: ";
139 s << " " << v.point_step << std::endl;
140 s << "row_step: ";
141 s << " " << v.row_step << std::endl;
142 s << "data[]" << std::endl;
143 for (std::size_t i = 0; i < v.data.size (); ++i)
144 {
145 s << " data[" << i << "]: ";
146 s << " " << v.data[i] << std::endl;
147 }
148 s << "is_dense: ";
149 s << " " << v.is_dense << std::endl;
150
151 return (s);
152 }
153
154} // namespace pcl
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:273
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
Definition types.h:120
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
PCLPointCloud2::Ptr PCLPointCloud2Ptr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Defines all the PCL and non-PCL macros used.
std::vector<::pcl::PCLPointField > fields
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
static bool concatenate(const PCLPointCloud2 &cloud1, const PCLPointCloud2 &cloud2, PCLPointCloud2 &cloud_out)
Concatenate two pcl::PCLPointCloud2.
const T & at(const pcl::uindex_t &point_index, const pcl::uindex_t &field_offset) const
Get value at specified offset.
::pcl::PCLHeader header
static bool concatenate(pcl::PCLPointCloud2 &cloud1, const pcl::PCLPointCloud2 &cloud2)
Inplace concatenate two pcl::PCLPointCloud2.
T & at(const pcl::uindex_t &point_index, const pcl::uindex_t &field_offset)
Get value at specified offset.
std::vector< std::uint8_t > data
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Defines basic non-point types used by PCL.