Point Cloud Library (PCL)  1.9.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 
45 namespace pcl
46 {
47  namespace geometry
48  {
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 vertices of 3.
53  * \tparam MeshTraitsT Please have a look at pcl::geometry::DefaultMeshTraits.
54  * \author Martin Saelzle
55  * \ingroup geometry
56  */
57  template <class MeshTraitsT>
58  class PolygonMesh : public pcl::geometry::MeshBase <PolygonMesh <MeshTraitsT>, MeshTraitsT, PolygonMeshTag>
59  {
60  public:
61 
63 
65  typedef boost::shared_ptr <Self> Ptr;
66  typedef boost::shared_ptr <const Self> ConstPtr;
67 
68  typedef typename Base::VertexData VertexData;
69  typedef typename Base::HalfEdgeData HalfEdgeData;
70  typedef typename Base::EdgeData EdgeData;
71  typedef typename Base::FaceData FaceData;
72  typedef typename Base::IsManifold IsManifold;
73  typedef typename Base::MeshTag MeshTag;
74 
77  typedef typename Base::HasEdgeData HasEdgeData;
78  typedef typename Base::HasFaceData HasFaceData;
79 
84 
85  // Indices
86  typedef typename Base::VertexIndex VertexIndex;
88  typedef typename Base::EdgeIndex EdgeIndex;
89  typedef typename Base::FaceIndex FaceIndex;
90 
93  typedef typename Base::EdgeIndices EdgeIndices;
94  typedef typename Base::FaceIndices FaceIndices;
95 
96  // Circulators
105 
106  /** \brief Constructor. */
108  : Base (),
109  add_triangle_ (3),
110  add_quad_ (4)
111  {
112  }
113 
114  /** \brief The base method of addFace is hidden because of the overloads in this class. */
115  using Base::addFace;
116 
117  /** \brief Add a triangle to the mesh. Data is only added if it is associated with the elements. The last vertex is connected with the first one.
118  * \param[in] idx_v_0 Index to the first vertex.
119  * \param[in] idx_v_1 Index to the second vertex.
120  * \param[in] idx_v_2 Index to the third vertex.
121  * \param[in] face_data Data that is set for the face.
122  * \param[in] half_edge_data Data that is set for all added half-edges.
123  * \param[in] edge_data Data that is set for all added edges.
124  * \return Index to the new face. Failure is signaled by returning an invalid face index.
125  * \warning The vertices must be valid and unique (each vertex may be contained only once). Not complying with this requirement results in undefined behavior!
126  */
127  inline FaceIndex
128  addFace (const VertexIndex& idx_v_0,
129  const VertexIndex& idx_v_1,
130  const VertexIndex& idx_v_2,
131  const FaceData& face_data = FaceData (),
132  const EdgeData& edge_data = EdgeData (),
133  const HalfEdgeData& half_edge_data = HalfEdgeData ())
134  {
135  add_triangle_ [0] = idx_v_0;
136  add_triangle_ [1] = idx_v_1;
137  add_triangle_ [2] = idx_v_2;
138 
139  return (this->addFaceImplBase (add_triangle_, face_data, edge_data, half_edge_data));
140  }
141 
142  /** \brief Add a quad to the mesh. Data is only added if it is associated with the elements. The last vertex is connected with the first one.
143  * \param[in] idx_v_0 Index to the first vertex.
144  * \param[in] idx_v_1 Index to the second vertex.
145  * \param[in] idx_v_2 Index to the third vertex.
146  * \param[in] idx_v_3 Index to the fourth vertex.
147  * \param[in] face_data Data that is set for the face.
148  * \param[in] half_edge_data Data that is set for all added half-edges.
149  * \param[in] edge_data Data that is set for all added edges.
150  * \return Index to the new face. Failure is signaled by returning an invalid face index.
151  * \warning The vertices must be valid and unique (each vertex may be contained only once). Not complying with this requirement results in undefined behavior!
152  */
153  inline FaceIndex
154  addFace (const VertexIndex& idx_v_0,
155  const VertexIndex& idx_v_1,
156  const VertexIndex& idx_v_2,
157  const VertexIndex& idx_v_3,
158  const FaceData& face_data = FaceData (),
159  const EdgeData& edge_data = EdgeData (),
160  const HalfEdgeData& half_edge_data = HalfEdgeData ())
161  {
162  add_quad_ [0] = idx_v_0;
163  add_quad_ [1] = idx_v_1;
164  add_quad_ [2] = idx_v_2;
165  add_quad_ [3] = idx_v_3;
166 
167  return (this->addFaceImplBase (add_quad_, face_data, edge_data, half_edge_data));
168  }
169 
170  private:
171 
172  // NOTE: Can't use the typedef of Base as a friend.
173  friend class pcl::geometry::MeshBase <PolygonMesh <MeshTraitsT>, MeshTraitsT, pcl::geometry::PolygonMeshTag>;
174 
175  /** \brief addFace for the polygon mesh. */
176  inline FaceIndex
177  addFaceImpl (const VertexIndices& vertices,
178  const FaceData& face_data,
179  const EdgeData& edge_data,
180  const HalfEdgeData& half_edge_data)
181  {
182  return (this->addFaceImplBase (vertices, face_data, edge_data, half_edge_data));
183  }
184 
185  ////////////////////////////////////////////////////////////////////////
186  // Members
187  ////////////////////////////////////////////////////////////////////////
188 
189  /** \brief Storage for adding a triangle. */
190  VertexIndices add_triangle_;
191 
192  /** \brief Storage for adding a quad. */
193  VertexIndices add_quad_;
194 
195  public:
196 
197  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
198  };
199  } // End namespace geom
200 } // End namespace pcl
Base::HalfEdgeDataCloud HalfEdgeDataCloud
Definition: polygon_mesh.h:81
boost::shared_ptr< const Self > ConstPtr
Definition: polygon_mesh.h:66
pcl::geometry::MeshBase< PolygonMesh< MeshTraitsT >, MeshTraitsT, PolygonMeshTag > Base
Definition: polygon_mesh.h:62
boost::integral_constant< bool,!boost::is_same< VertexData, pcl::geometry::NoData >::value > HasVertexData
Definition: mesh_base.h:120
Base::VertexIndex VertexIndex
Definition: polygon_mesh.h:86
Base::HasEdgeData HasEdgeData
Definition: polygon_mesh.h:77
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
Circulates clockwise around a face and returns an index to the face of the outer half-edge (the targe...
Circulates counter-clockwise around a vertex and returns an index to the incoming half-edge (the targ...
boost::integral_constant< bool,!boost::is_same< HalfEdgeData, pcl::geometry::NoData >::value > HasHalfEdgeData
Definition: mesh_base.h:121
Base::HasFaceData HasFaceData
Definition: polygon_mesh.h:78
Base::HalfEdgeIndices HalfEdgeIndices
Definition: polygon_mesh.h:92
Base::IsManifold IsManifold
Definition: polygon_mesh.h:72
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:154
Index used to access elements in the half-edge mesh.
Definition: mesh_indices.h:339
Base::HalfEdgeData HalfEdgeData
Definition: polygon_mesh.h:69
boost::shared_ptr< Self > Ptr
Definition: polygon_mesh.h:65
Base::IncomingHalfEdgeAroundVertexCirculator IncomingHalfEdgeAroundVertexCirculator
Definition: polygon_mesh.h:99
Base::OuterHalfEdgeAroundFaceCirculator OuterHalfEdgeAroundFaceCirculator
Definition: polygon_mesh.h:103
Circulates counter-clockwise around a vertex and returns an index to the terminating vertex of the ou...
Base::OutgoingHalfEdgeAroundVertexCirculator OutgoingHalfEdgeAroundVertexCirculator
Definition: polygon_mesh.h:98
Index used to access elements in the half-edge mesh.
Definition: mesh_indices.h:61
Index used to access elements in the half-edge mesh.
Definition: mesh_indices.h:478
Circulates clockwise around a face and returns an index to the terminating vertex of the inner half-e...
Base::VertexDataCloud VertexDataCloud
Definition: polygon_mesh.h:80
Base::VertexAroundVertexCirculator VertexAroundVertexCirculator
Definition: polygon_mesh.h:97
Index used to access elements in the half-edge mesh.
Definition: mesh_indices.h:200
Circulates counter-clockwise around a vertex and returns an index to the outgoing half-edge (the targ...
PolygonMesh< MeshTraitsT > Self
Definition: polygon_mesh.h:64
Base::FaceIndex FaceIndex
Definition: polygon_mesh.h:89
boost::integral_constant< bool,!boost::is_same< FaceData, pcl::geometry::NoData >::value > HasFaceData
Definition: mesh_base.h:123
Base::FaceDataCloud FaceDataCloud
Definition: polygon_mesh.h:83
Base::EdgeIndex EdgeIndex
Definition: polygon_mesh.h:88
Base::FaceAroundVertexCirculator FaceAroundVertexCirculator
Definition: polygon_mesh.h:100
Base::VertexData VertexData
Definition: polygon_mesh.h:68
Tag describing the type of the mesh.
Definition: polygon_mesh.h:50
boost::integral_constant< bool,!boost::is_same< EdgeData, pcl::geometry::NoData >::value > HasEdgeData
Definition: mesh_base.h:122
Base::VertexIndices VertexIndices
Definition: polygon_mesh.h:91
Circulates clockwise around a face and returns an index to the inner half-edge (the target)...
Base::HasHalfEdgeData HasHalfEdgeData
Definition: polygon_mesh.h:76
Base::EdgeIndices EdgeIndices
Definition: polygon_mesh.h:93
Base::VertexAroundFaceCirculator VertexAroundFaceCirculator
Definition: polygon_mesh.h:101
Base::HasVertexData HasVertexData
Definition: polygon_mesh.h:75
Circulates clockwise around a face and returns an index to the outer half-edge (the target)...
Circulates counter-clockwise around a vertex and returns an index to the face of the outgoing half-ed...
Base class for the half-edge mesh.
Definition: mesh_base.h:97
Base::HalfEdgeIndex HalfEdgeIndex
Definition: polygon_mesh.h:87
General half-edge mesh that can store any polygon with a minimum number of vertices of 3...
Definition: polygon_mesh.h:58
Base::FaceIndices FaceIndices
Definition: polygon_mesh.h:94
Base::InnerHalfEdgeAroundFaceCirculator InnerHalfEdgeAroundFaceCirculator
Definition: polygon_mesh.h:102
std::vector< VertexIndex > VertexIndices
Definition: mesh_base.h:136
PolygonMesh()
Constructor.
Definition: polygon_mesh.h:107
Base::FaceAroundFaceCirculator FaceAroundFaceCirculator
Definition: polygon_mesh.h:104
Base::EdgeDataCloud EdgeDataCloud
Definition: polygon_mesh.h:82
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:128