Point Cloud Library (PCL)  1.7.1
quad_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 #ifndef PCL_GEOMETRY_QUAD_MESH_H
42 #define PCL_GEOMETRY_QUAD_MESH_H
43 
44 #include <pcl/geometry/mesh_base.h>
45 
46 namespace pcl
47 {
48  namespace geometry
49  {
50  /** \brief Tag describing the type of the mesh. */
51  struct QuadMeshTag {};
52 
53  /** \brief Half-edge mesh that can only store quads.
54  * \tparam MeshTraitsT Please have a look at pcl::geometry::DefaultMeshTraits.
55  * \author Martin Saelzle
56  * \ingroup geometry
57  */
58  template <class MeshTraitsT>
59  class QuadMesh : public pcl::geometry::MeshBase <QuadMesh <MeshTraitsT>, MeshTraitsT, QuadMeshTag>
60  {
61  public:
62 
64 
66  typedef boost::shared_ptr <Self> Ptr;
67  typedef boost::shared_ptr <const Self> ConstPtr;
68 
69  typedef typename Base::VertexData VertexData;
70  typedef typename Base::HalfEdgeData HalfEdgeData;
71  typedef typename Base::EdgeData EdgeData;
72  typedef typename Base::FaceData FaceData;
73  typedef typename Base::IsManifold IsManifold;
74  typedef typename Base::MeshTag MeshTag;
75 
78  typedef typename Base::HasEdgeData HasEdgeData;
79  typedef typename Base::HasFaceData HasFaceData;
80 
85 
86  // Indices
87  typedef typename Base::VertexIndex VertexIndex;
89  typedef typename Base::EdgeIndex EdgeIndex;
90  typedef typename Base::FaceIndex FaceIndex;
91 
94  typedef typename Base::EdgeIndices EdgeIndices;
95  typedef typename Base::FaceIndices FaceIndices;
96 
97  // Circulators
106 
107  /** \brief Constructor. */
109  : Base (),
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 quad 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] idx_v_3 Index to the fourth vertex.
122  * \param[in] face_data Data that is set for the face.
123  * \param[in] half_edge_data Data that is set for all added half-edges.
124  * \param[in] edge_data Data that is set for all added edges.
125  * \return Index to the new face. Failure is signaled by returning an invalid face index.
126  * \warning The vertices must be valid and unique (each vertex may be contained only once). Not complying with this requirement results in undefined behavior!
127  */
128  inline FaceIndex
129  addFace (const VertexIndex& idx_v_0,
130  const VertexIndex& idx_v_1,
131  const VertexIndex& idx_v_2,
132  const VertexIndex& idx_v_3,
133  const FaceData& face_data = FaceData (),
134  const EdgeData& edge_data = EdgeData (),
135  const HalfEdgeData& half_edge_data = HalfEdgeData ())
136  {
137  add_quad_ [0] = idx_v_0;
138  add_quad_ [1] = idx_v_1;
139  add_quad_ [2] = idx_v_2;
140  add_quad_ [3] = idx_v_3;
141 
142  return (this->addFaceImplBase (add_quad_, face_data, edge_data, half_edge_data));
143  }
144 
145  private:
146 
147  // NOTE: Can't use the typedef of Base as a friend.
148  friend class pcl::geometry::MeshBase <QuadMesh <MeshTraitsT>, MeshTraitsT, pcl::geometry::QuadMeshTag>;
149 
150  /** \brief addFace for the quad mesh. */
151  inline FaceIndex
152  addFaceImpl (const VertexIndices& vertices,
153  const FaceData& face_data,
154  const EdgeData& edge_data,
155  const HalfEdgeData& half_edge_data)
156  {
157  if (vertices.size () == 4)
158  return (this->addFaceImplBase (vertices, face_data, edge_data, half_edge_data));
159  else
160  return (FaceIndex ());
161  }
162 
163  ////////////////////////////////////////////////////////////////////////
164  // Members
165  ////////////////////////////////////////////////////////////////////////
166 
167  /** \brief Storage for adding a quad. */
168  VertexIndices add_quad_;
169 
170  public:
171 
172  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
173  };
174  } // End namespace geom
175 } // End namespace pcl
176 
177 #endif // PCL_GEOMETRY_QUAD_MESH_H