Point Cloud Library (PCL)  1.11.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  {
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  bool success = pcl::PCLPointCloud2::concatenate(mesh1.cloud, mesh2.cloud);
34  if (success == false) {
35  return false;
36  }
37  // Make the resultant polygon mesh take the newest stamp
38  mesh1.header.stamp = std::max(mesh1.header.stamp, mesh2.header.stamp);
39 
40  const auto point_offset = mesh1.cloud.width * mesh1.cloud.height;
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::PCLPointCloud2
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::PCLHeader::stamp
std::uint64_t stamp
A timestamp associated with the time when the data was acquired.
Definition: PCLHeader.h:18
pcl::PolygonMesh::cloud
::pcl::PCLPointCloud2 cloud
Definition: PolygonMesh.h:21
pcl
Definition: convolution.h:46
pcl::PolygonMesh::ConstPtr
shared_ptr< const ::pcl::PolygonMesh > ConstPtr
Definition: PolygonMesh.h:97
pcl::PolygonMeshPtr
PolygonMesh::Ptr PolygonMeshPtr
Definition: PolygonMesh.h:100
pcl::PCLPointCloud2::height
index_t height
Definition: PCLPointCloud2.h:20
pcl::PolygonMesh::concatenate
static bool concatenate(const PolygonMesh &mesh1, const PolygonMesh &mesh2, PolygonMesh &mesh_out)
Concatenate two pcl::PCLPointCloud2.
Definition: PolygonMesh.h:66
pcl::PolygonMesh::Ptr
shared_ptr< ::pcl::PolygonMesh > Ptr
Definition: PolygonMesh.h:96
pcl::PCLPointCloud2::concatenate
static bool concatenate(pcl::PCLPointCloud2 &cloud1, const pcl::PCLPointCloud2 &cloud2)
Inplace concatenate two pcl::PCLPointCloud2.
pcl::PCLPointCloud2::width
index_t width
Definition: PCLPointCloud2.h:21
pcl::PolygonMesh::PolygonMesh
PolygonMesh()
Definition: PolygonMesh.h:16
pcl::io::ply::io_operators::operator<<
std::ostream & operator<<(std::ostream &ostream, int8 value)
Definition: io_operators.h:86
pcl::PolygonMeshConstPtr
PolygonMesh::ConstPtr PolygonMeshConstPtr
Definition: PolygonMesh.h:101
pcl::PolygonMesh
Definition: PolygonMesh.h:14
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:16
pcl::PolygonMesh::header
::pcl::PCLHeader header
Definition: PolygonMesh.h:19
pcl::concatenate
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
pcl::PolygonMesh::polygons
std::vector< ::pcl::Vertices > polygons
Definition: PolygonMesh.h:23
pcl::PolygonMesh::concatenate
static bool concatenate(pcl::PolygonMesh &mesh1, const pcl::PolygonMesh &mesh2)
Inplace concatenate two pcl::PolygonMesh.
Definition: PolygonMesh.h:31
pcl::PCLHeader
Definition: PCLHeader.h:10