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