Point Cloud Library (PCL)  1.14.1-dev
polygon_mesh.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2012, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  *
39  */
40 
41 #pragma once
42 
43 #include <pcl/geometry/mesh_base.h>
44 #include <pcl/memory.h>
45 #include <pcl/pcl_macros.h>
46 
47 namespace pcl {
48 namespace geometry {
49 /** \brief Tag describing the type of the mesh. */
50 struct PolygonMeshTag {};
51 
52 /** \brief General half-edge mesh that can store any polygon with a minimum number of
53  * vertices of 3.
54  * \tparam MeshTraitsT Please have a look at
55  * pcl::geometry::DefaultMeshTraits.
56  * \author Martin Saelzle
57  * \ingroup geometry
58  */
59 template <class MeshTraitsT>
60 class PolygonMesh : public pcl::geometry::MeshBase<PolygonMesh<MeshTraitsT>,
61  MeshTraitsT,
62  PolygonMeshTag> {
63 public:
64  using Base =
66 
68  using Ptr = shared_ptr<Self>;
69  using ConstPtr = shared_ptr<const Self>;
70 
71  using VertexData = typename Base::VertexData;
72  using HalfEdgeData = typename Base::HalfEdgeData;
73  using EdgeData = typename Base::EdgeData;
74  using FaceData = typename Base::FaceData;
75  using IsManifold = typename Base::IsManifold;
76  using MeshTag = typename Base::MeshTag;
77 
80  using HasEdgeData = typename Base::HasEdgeData;
81  using HasFaceData = typename Base::HasFaceData;
82 
87 
88  // Indices
89  using VertexIndex = typename Base::VertexIndex;
91  using EdgeIndex = typename Base::EdgeIndex;
92  using FaceIndex = typename Base::FaceIndex;
93 
96  using EdgeIndices = typename Base::EdgeIndices;
97  using FaceIndices = typename Base::FaceIndices;
98 
99  // Circulators
112 
113  /** \brief Constructor. */
114  PolygonMesh() : Base(), add_triangle_(3), add_quad_(4) {}
115 
116  /** \brief The base method of addFace is hidden because of the overloads in this
117  * class. */
118  using Base::addFace;
119 
120  /** \brief Add a triangle to the mesh. Data is only added if it is associated with the
121  * elements. The last vertex is connected with the first one.
122  * \param[in] idx_v_0 Index
123  * to the first vertex.
124  * \param[in] idx_v_1 Index to the second vertex.
125  * \param[in] idx_v_2 Index to the third vertex.
126  * \param[in] face_data Data that is set for the face.
127  * \param[in] half_edge_data Data that is set for all added half-edges.
128  * \param[in] edge_data Data that is set for all added edges.
129  * \return Index to the new face. Failure is signaled by returning an invalid face
130  * index.
131  * \warning The vertices must be valid and unique (each vertex may be contained
132  * only once). Not complying with this requirement results in undefined behavior!
133  */
134  inline FaceIndex
135  addFace(const VertexIndex& idx_v_0,
136  const VertexIndex& idx_v_1,
137  const VertexIndex& idx_v_2,
138  const FaceData& face_data = FaceData(),
139  const EdgeData& edge_data = EdgeData(),
140  const HalfEdgeData& half_edge_data = HalfEdgeData())
141  {
142  add_triangle_[0] = idx_v_0;
143  add_triangle_[1] = idx_v_1;
144  add_triangle_[2] = idx_v_2;
145 
146  return (this->addFaceImplBase(add_triangle_, face_data, edge_data, half_edge_data));
147  }
148 
149  /** \brief Add a quad to the mesh. Data is only added if it is associated with the
150  * elements. The last vertex is connected with the first one.
151  * \param[in] idx_v_0 Index to the first vertex.
152  * \param[in] idx_v_1 Index to the second vertex.
153  * \param[in] idx_v_2 Index to the third vertex.
154  * \param[in] idx_v_3 Index to the fourth vertex.
155  * \param[in] face_data Data that is set for the face.
156  * \param[in] half_edge_data Data that is set for all added half-edges.
157  * \param[in] edge_data Data that is set for all added edges.
158  * \return Index to the new face. Failure is signaled by returning an invalid face
159  * index.
160  * \warning The vertices must be valid and unique (each vertex may be contained
161  * only once). Not complying with this requirement results in undefined behavior!
162  */
163  inline FaceIndex
164  addFace(const VertexIndex& idx_v_0,
165  const VertexIndex& idx_v_1,
166  const VertexIndex& idx_v_2,
167  const VertexIndex& idx_v_3,
168  const FaceData& face_data = FaceData(),
169  const EdgeData& edge_data = EdgeData(),
170  const HalfEdgeData& half_edge_data = HalfEdgeData())
171  {
172  add_quad_[0] = idx_v_0;
173  add_quad_[1] = idx_v_1;
174  add_quad_[2] = idx_v_2;
175  add_quad_[3] = idx_v_3;
176 
177  return (this->addFaceImplBase(add_quad_, face_data, edge_data, half_edge_data));
178  }
179 
180 private:
181  // NOTE: Can't use the typedef of Base as a friend.
182  friend class pcl::geometry::
183  MeshBase<PolygonMesh<MeshTraitsT>, MeshTraitsT, pcl::geometry::PolygonMeshTag>;
184 
185  /** \brief addFace for the polygon mesh. */
186  inline FaceIndex
187  addFaceImpl(const VertexIndices& vertices,
188  const FaceData& face_data,
189  const EdgeData& edge_data,
190  const HalfEdgeData& half_edge_data)
191  {
192  return (this->addFaceImplBase(vertices, face_data, edge_data, half_edge_data));
193  }
194 
195  ////////////////////////////////////////////////////////////////////////
196  // Members
197  ////////////////////////////////////////////////////////////////////////
198 
199  /** \brief Storage for adding a triangle. */
200  VertexIndices add_triangle_;
201 
202  /** \brief Storage for adding a quad. */
203  VertexIndices add_quad_;
204 
205 public:
207 };
208 } // namespace geometry
209 } // End namespace pcl
Base class for the half-edge mesh.
Definition: mesh_base.h:96
std::integral_constant< bool, !std::is_same< VertexData, pcl::geometry::NoData >::value > HasVertexData
Definition: mesh_base.h:120
pcl::geometry::IncomingHalfEdgeAroundVertexCirculator< const Self > IncomingHalfEdgeAroundVertexCirculator
Definition: mesh_base.h:153
pcl::geometry::OuterHalfEdgeAroundFaceCirculator< const Self > OuterHalfEdgeAroundFaceCirculator
Definition: mesh_base.h:161
pcl::geometry::FaceAroundFaceCirculator< const Self > FaceAroundFaceCirculator
Definition: mesh_base.h:162
FaceIndex addFaceImplBase(const VertexIndices &vertices, const FaceData &face_data, const EdgeData &edge_data, const HalfEdgeData &half_edge_data)
General implementation of addFace.
Definition: mesh_base.h:1162
pcl::geometry::FaceAroundVertexCirculator< const Self > FaceAroundVertexCirculator
Definition: mesh_base.h:155
std::integral_constant< bool, !std::is_same< EdgeData, pcl::geometry::NoData >::value > HasEdgeData
Definition: mesh_base.h:126
std::integral_constant< bool, !std::is_same< FaceData, pcl::geometry::NoData >::value > HasFaceData
Definition: mesh_base.h:129
FaceIndex addFace(const VertexIndices &vertices, const FaceData &face_data=FaceData(), const EdgeData &edge_data=EdgeData(), const HalfEdgeData &half_edge_data=HalfEdgeData())
Add a face to the mesh.
Definition: mesh_base.h:203
pcl::geometry::VertexAroundFaceCirculator< const Self > VertexAroundFaceCirculator
Definition: mesh_base.h:157
pcl::geometry::InnerHalfEdgeAroundFaceCirculator< const Self > InnerHalfEdgeAroundFaceCirculator
Definition: mesh_base.h:159
pcl::geometry::VertexAroundVertexCirculator< const Self > VertexAroundVertexCirculator
Definition: mesh_base.h:149
std::integral_constant< bool, !std::is_same< HalfEdgeData, pcl::geometry::NoData >::value > HasHalfEdgeData
Definition: mesh_base.h:123
pcl::geometry::OutgoingHalfEdgeAroundVertexCirculator< const Self > OutgoingHalfEdgeAroundVertexCirculator
Definition: mesh_base.h:151
General half-edge mesh that can store any polygon with a minimum number of vertices of 3.
Definition: polygon_mesh.h:62
typename Base::FaceIndices FaceIndices
Definition: polygon_mesh.h:97
typename Base::HasFaceData HasFaceData
Definition: polygon_mesh.h:81
FaceIndex addFace(const VertexIndex &idx_v_0, const VertexIndex &idx_v_1, const VertexIndex &idx_v_2, const VertexIndex &idx_v_3, const FaceData &face_data=FaceData(), const EdgeData &edge_data=EdgeData(), const HalfEdgeData &half_edge_data=HalfEdgeData())
Add a quad to the mesh.
Definition: polygon_mesh.h:164
typename Base::HalfEdgeIndex HalfEdgeIndex
Definition: polygon_mesh.h:90
typename Base::VertexIndex VertexIndex
Definition: polygon_mesh.h:89
typename Base::EdgeDataCloud EdgeDataCloud
Definition: polygon_mesh.h:85
typename Base::IsManifold IsManifold
Definition: polygon_mesh.h:75
typename Base::VertexIndices VertexIndices
Definition: polygon_mesh.h:94
typename Base::VertexDataCloud VertexDataCloud
Definition: polygon_mesh.h:83
typename Base::FaceAroundVertexCirculator FaceAroundVertexCirculator
Definition: polygon_mesh.h:105
typename Base::HalfEdgeData HalfEdgeData
Definition: polygon_mesh.h:72
typename Base::InnerHalfEdgeAroundFaceCirculator InnerHalfEdgeAroundFaceCirculator
Definition: polygon_mesh.h:108
typename Base::EdgeData EdgeData
Definition: polygon_mesh.h:73
typename Base::HasVertexData HasVertexData
Definition: polygon_mesh.h:78
typename Base::FaceData FaceData
Definition: polygon_mesh.h:74
typename Base::FaceDataCloud FaceDataCloud
Definition: polygon_mesh.h:86
typename Base::EdgeIndices EdgeIndices
Definition: polygon_mesh.h:96
shared_ptr< const Self > ConstPtr
Definition: polygon_mesh.h:69
typename Base::VertexData VertexData
Definition: polygon_mesh.h:71
typename Base::MeshTag MeshTag
Definition: polygon_mesh.h:76
typename Base::OutgoingHalfEdgeAroundVertexCirculator OutgoingHalfEdgeAroundVertexCirculator
Definition: polygon_mesh.h:102
typename Base::FaceAroundFaceCirculator FaceAroundFaceCirculator
Definition: polygon_mesh.h:111
shared_ptr< Self > Ptr
Definition: polygon_mesh.h:68
typename Base::HasEdgeData HasEdgeData
Definition: polygon_mesh.h:80
typename Base::VertexAroundFaceCirculator VertexAroundFaceCirculator
Definition: polygon_mesh.h:106
typename Base::EdgeIndex EdgeIndex
Definition: polygon_mesh.h:91
typename Base::OuterHalfEdgeAroundFaceCirculator OuterHalfEdgeAroundFaceCirculator
Definition: polygon_mesh.h:110
typename Base::FaceIndex FaceIndex
Definition: polygon_mesh.h:92
typename Base::VertexAroundVertexCirculator VertexAroundVertexCirculator
Definition: polygon_mesh.h:100
typename Base::HalfEdgeIndices HalfEdgeIndices
Definition: polygon_mesh.h:95
typename Base::IncomingHalfEdgeAroundVertexCirculator IncomingHalfEdgeAroundVertexCirculator
Definition: polygon_mesh.h:104
typename Base::HalfEdgeDataCloud HalfEdgeDataCloud
Definition: polygon_mesh.h:84
typename Base::HasHalfEdgeData HasHalfEdgeData
Definition: polygon_mesh.h:79
FaceIndex addFace(const VertexIndex &idx_v_0, const VertexIndex &idx_v_1, const VertexIndex &idx_v_2, const FaceData &face_data=FaceData(), const EdgeData &edge_data=EdgeData(), const HalfEdgeData &half_edge_data=HalfEdgeData())
Add a triangle to the mesh.
Definition: polygon_mesh.h:135
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.
Tag describing the type of the mesh.
Definition: polygon_mesh.h:50