Point Cloud Library (PCL)  1.9.1-dev
PolygonMesh.h
1 #pragma once
2 
3 #include <algorithm>
4 #include <string>
5 #include <vector>
6 #include <ostream>
7 
8 // Include the correct Header path here
9 #include <pcl/PCLHeader.h>
10 #include <pcl/PCLPointCloud2.h>
11 #include <pcl/Vertices.h>
12 
13 namespace pcl
14 {
15  struct PolygonMesh
16  {
18  {}
19 
21 
23 
24  std::vector< ::pcl::Vertices> polygons;
25 
26  /** \brief Inplace concatenate two pcl::PolygonMesh
27  * \param[in,out] mesh1 the first input and output mesh
28  * \param[in] mesh2 the second input mesh
29  * \return true if successful, false otherwise (unexpected error)
30  */
31  static bool
33  {
34  bool success = pcl::PCLPointCloud2::concatenate(mesh1.cloud, mesh2.cloud);
35  if (success == false) {
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  const auto point_offset = mesh1.cloud.width * mesh1.cloud.height;
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&
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
92  {
93  return (PolygonMesh (*this) += rhs);
94  }
95 
96  public:
97  using Ptr = boost::shared_ptr< ::pcl::PolygonMesh>;
98  using ConstPtr = boost::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
std::uint64_t stamp
A timestamp associated with the time when the data was acquired.
Definition: PCLHeader.h:23
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
boost::shared_ptr< ::pcl::PolygonMesh > Ptr
Definition: PolygonMesh.h:97
static bool concatenate(pcl::PCLPointCloud2 &cloud1, const pcl::PCLPointCloud2 &cloud2)
Inplace concatenate two pcl::PCLPointCloud2.
PolygonMesh::Ptr PolygonMeshPtr
Definition: PolygonMesh.h:101
std::ostream & operator<<(std::ostream &os, const BivariatePolynomialT< real > &p)
std::uint32_t height
::pcl::PCLHeader header
Definition: PolygonMesh.h:20
boost::shared_ptr< const ::pcl::PolygonMesh > ConstPtr
Definition: PolygonMesh.h:98
static bool concatenate(const PolygonMesh &mesh1, const PolygonMesh &mesh2, PolygonMesh &mesh_out)
Concatenate two pcl::PCLPointCloud2.
Definition: PolygonMesh.h:67
PolygonMesh::ConstPtr PolygonMeshConstPtr
Definition: PolygonMesh.h:102
std::vector< ::pcl::Vertices > polygons
Definition: PolygonMesh.h:24
std::uint32_t width
PolygonMesh & operator+=(const PolygonMesh &rhs)
Add another polygon mesh to the current mesh.
Definition: PolygonMesh.h:80
::pcl::PCLPointCloud2 cloud
Definition: PolygonMesh.h:22
const PolygonMesh operator+(const PolygonMesh &rhs)
Add a polygon mesh to another mesh.
Definition: PolygonMesh.h:91
static bool concatenate(pcl::PolygonMesh &mesh1, const pcl::PolygonMesh &mesh2)
Inplace concatenate two pcl::PolygonMesh.
Definition: PolygonMesh.h:32