Point Cloud Library (PCL)  1.12.0
PolygonMesh.h
1 #pragma once
2 
3 #include <algorithm>
4 #include <vector>
5 #include <ostream>
6 
7 // Include the correct Header path here
8 #include <pcl/PCLHeader.h>
9 #include <pcl/PCLPointCloud2.h>
10 #include <pcl/Vertices.h>
11 
12 namespace pcl
13 {
14  struct PolygonMesh
15  {
17  {}
18 
20 
22 
23  std::vector< ::pcl::Vertices> polygons;
24 
25  /** \brief Inplace concatenate two pcl::PolygonMesh
26  * \param[in,out] mesh1 the first input and output mesh
27  * \param[in] mesh2 the second input mesh
28  * \return true if successful, false otherwise (unexpected error)
29  */
30  static bool
32  {
33  const auto point_offset = mesh1.cloud.width * mesh1.cloud.height;
34 
35  bool success = pcl::PCLPointCloud2::concatenate(mesh1.cloud, mesh2.cloud);
36  if (success == false) {
37  return false;
38  }
39  // Make the resultant polygon mesh take the newest stamp
40  mesh1.header.stamp = std::max(mesh1.header.stamp, mesh2.header.stamp);
41 
42  std::transform(mesh2.polygons.begin (),
43  mesh2.polygons.end (),
44  std::back_inserter (mesh1.polygons),
45  [point_offset](auto polygon)
46  {
47  std::transform(polygon.vertices.begin (),
48  polygon.vertices.end (),
49  polygon.vertices.begin (),
50  [point_offset](auto& point_idx)
51  {
52  return point_idx + point_offset;
53  });
54  return polygon;
55  });
56 
57  return true;
58  }
59 
60  /** \brief Concatenate two pcl::PCLPointCloud2
61  * \param[in] mesh1 the first input mesh
62  * \param[in] mesh2 the second input mesh
63  * \param[out] mesh_out the resultant output mesh
64  * \return true if successful, false otherwise (unexpected error)
65  */
66  static bool
67  concatenate (const PolygonMesh &mesh1,
68  const PolygonMesh &mesh2,
69  PolygonMesh &mesh_out)
70  {
71  mesh_out = mesh1;
72  return concatenate(mesh_out, mesh2);
73  }
74 
75  /** \brief Add another polygon mesh to the current mesh.
76  * \param[in] rhs the mesh to add to the current mesh
77  * \return the new mesh as a concatenation of the current mesh and the new given mesh
78  */
79  inline PolygonMesh&
80  operator += (const PolygonMesh& rhs)
81  {
82  concatenate((*this), rhs);
83  return (*this);
84  }
85 
86  /** \brief Add a polygon mesh to another mesh.
87  * \param[in] rhs the mesh to add to the current mesh
88  * \return the new mesh as a concatenation of the current mesh and the new given mesh
89  */
90  inline const PolygonMesh
91  operator + (const PolygonMesh& rhs)
92  {
93  return (PolygonMesh (*this) += rhs);
94  }
95 
96  public:
97  using Ptr = shared_ptr< ::pcl::PolygonMesh>;
98  using ConstPtr = shared_ptr<const ::pcl::PolygonMesh>;
99  }; // struct PolygonMesh
100 
103 
104  inline std::ostream& operator<<(std::ostream& s, const ::pcl::PolygonMesh &v)
105  {
106  s << "header: " << std::endl;
107  s << v.header;
108  s << "cloud: " << std::endl;
109  s << v.cloud;
110  s << "polygons[]" << std::endl;
111  for (std::size_t i = 0; i < v.polygons.size (); ++i)
112  {
113  s << " polygons[" << i << "]: " << std::endl;
114  s << v.polygons[i];
115  }
116  return (s);
117  }
118 
119 } // 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:248
std::ostream & operator<<(std::ostream &ostream, int8 value)
Definition: io_operators.h:86
PolygonMesh::ConstPtr PolygonMeshConstPtr
Definition: PolygonMesh.h:102
PolygonMesh::Ptr PolygonMeshPtr
Definition: PolygonMesh.h:101
std::uint64_t stamp
A timestamp associated with the time when the data was acquired.
Definition: PCLHeader.h:18
static bool concatenate(pcl::PCLPointCloud2 &cloud1, const pcl::PCLPointCloud2 &cloud2)
Inplace concatenate two pcl::PCLPointCloud2.
static bool concatenate(pcl::PolygonMesh &mesh1, const pcl::PolygonMesh &mesh2)
Inplace concatenate two pcl::PolygonMesh.
Definition: PolygonMesh.h:31
::pcl::PCLHeader header
Definition: PolygonMesh.h:19
shared_ptr< ::pcl::PolygonMesh > Ptr
Definition: PolygonMesh.h:97
std::vector< ::pcl::Vertices > polygons
Definition: PolygonMesh.h:23
static bool concatenate(const PolygonMesh &mesh1, const PolygonMesh &mesh2, PolygonMesh &mesh_out)
Concatenate two pcl::PCLPointCloud2.
Definition: PolygonMesh.h:67
::pcl::PCLPointCloud2 cloud
Definition: PolygonMesh.h:21
shared_ptr< const ::pcl::PolygonMesh > ConstPtr
Definition: PolygonMesh.h:98