Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
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
13
namespace
pcl
14
{
15
16
struct
PCL_EXPORTS
PCLPointCloud2
17
{
18
::pcl::PCLHeader
header
;
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
55
concatenate
(
pcl::PCLPointCloud2
&cloud1,
const
pcl::PCLPointCloud2
&cloud2);
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
64
concatenate
(
const
PCLPointCloud2
&cloud1,
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
*/
76
PCLPointCloud2
&
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
118
using
PCLPointCloud2Ptr
=
PCLPointCloud2::Ptr
;
119
using
PCLPointCloud2ConstPtr
=
PCLPointCloud2::ConstPtr
;
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 <<
" "
<<
static_cast<
int
>
(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
Definition
convolution.h:46
pcl::PCLPointCloud2ConstPtr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition
PCLPointCloud2.h:119
pcl::operator<<
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
Definition
bivariate_polynomial.hpp:238
pcl::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition
PCLPointCloud2.h:118
pcl::uindex_t
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
Definition
types.h:120
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl::PCLHeader
Definition
PCLHeader.h:11
pcl::PCLPointCloud2
Definition
PCLPointCloud2.h:17
pcl::PCLPointCloud2::is_dense
std::uint8_t is_dense
Definition
PCLPointCloud2.h:32
pcl::PCLPointCloud2::width
uindex_t width
Definition
PCLPointCloud2.h:21
pcl::PCLPointCloud2::height
uindex_t height
Definition
PCLPointCloud2.h:20
pcl::PCLPointCloud2::fields
std::vector<::pcl::PCLPointField > fields
Definition
PCLPointCloud2.h:23
pcl::PCLPointCloud2::is_bigendian
std::uint8_t is_bigendian
Definition
PCLPointCloud2.h:26
pcl::PCLPointCloud2::row_step
uindex_t row_step
Definition
PCLPointCloud2.h:28
pcl::PCLPointCloud2::Ptr
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Definition
PCLPointCloud2.h:35
pcl::PCLPointCloud2::concatenate
static bool concatenate(const PCLPointCloud2 &cloud1, const PCLPointCloud2 &cloud2, PCLPointCloud2 &cloud_out)
Concatenate two pcl::PCLPointCloud2.
Definition
PCLPointCloud2.h:64
pcl::PCLPointCloud2::at
const T & at(const pcl::uindex_t &point_index, const pcl::uindex_t &field_offset) const
Get value at specified offset.
Definition
PCLPointCloud2.h:95
pcl::PCLPointCloud2::header
::pcl::PCLHeader header
Definition
PCLPointCloud2.h:18
pcl::PCLPointCloud2::concatenate
static bool concatenate(pcl::PCLPointCloud2 &cloud1, const pcl::PCLPointCloud2 &cloud2)
Inplace concatenate two pcl::PCLPointCloud2.
pcl::PCLPointCloud2::at
T & at(const pcl::uindex_t &point_index, const pcl::uindex_t &field_offset)
Get value at specified offset.
Definition
PCLPointCloud2.h:109
pcl::PCLPointCloud2::point_step
uindex_t point_step
Definition
PCLPointCloud2.h:27
pcl::PCLPointCloud2::data
std::vector< std::uint8_t > data
Definition
PCLPointCloud2.h:30
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition
PCLPointCloud2.h:36
types.h
Defines basic non-point types used by PCL.