Point Cloud Library (PCL)  1.14.1-dev
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 #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 QuadMeshTag {};
51 
52 /** \brief Half-edge mesh that can only store quads.
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 QuadMesh
59 : public pcl::geometry::MeshBase<QuadMesh<MeshTraitsT>, MeshTraitsT, QuadMeshTag> {
60 public:
62 
64  using Ptr = shared_ptr<Self>;
65  using ConstPtr = shared_ptr<const Self>;
66 
67  using VertexData = typename Base::VertexData;
68  using HalfEdgeData = typename Base::HalfEdgeData;
69  using EdgeData = typename Base::EdgeData;
70  using FaceData = typename Base::FaceData;
71  using IsManifold = typename Base::IsManifold;
72  using MeshTag = typename Base::MeshTag;
73 
76  using HasEdgeData = typename Base::HasEdgeData;
77  using HasFaceData = typename Base::HasFaceData;
78 
83 
84  // Indices
85  using VertexIndex = typename Base::VertexIndex;
87  using EdgeIndex = typename Base::EdgeIndex;
88  using FaceIndex = typename Base::FaceIndex;
89 
92  using EdgeIndices = typename Base::EdgeIndices;
93  using FaceIndices = typename Base::FaceIndices;
94 
95  // Circulators
108 
109  /** \brief Constructor. */
110  QuadMesh() : Base(), add_quad_(4) {}
111 
112  /** \brief The base method of addFace is hidden because of the overloads in this
113  * class. */
114  using Base::addFace;
115 
116  /** \brief Add a quad to the mesh. Data is only added if it is associated with the
117  * 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
126  * index.
127  * \warning The vertices must be valid and unique (each vertex may be contained
128  * only once). Not complying with this requirement results in undefined behavior!
129  */
130  inline FaceIndex
131  addFace(const VertexIndex& idx_v_0,
132  const VertexIndex& idx_v_1,
133  const VertexIndex& idx_v_2,
134  const VertexIndex& idx_v_3,
135  const FaceData& face_data = FaceData(),
136  const EdgeData& edge_data = EdgeData(),
137  const HalfEdgeData& half_edge_data = HalfEdgeData())
138  {
139  add_quad_[0] = idx_v_0;
140  add_quad_[1] = idx_v_1;
141  add_quad_[2] = idx_v_2;
142  add_quad_[3] = idx_v_3;
143 
144  return (this->addFaceImplBase(add_quad_, face_data, edge_data, half_edge_data));
145  }
146 
147 private:
148  // NOTE: Can't use the typedef of Base as a friend.
149  friend class pcl::geometry::
150  MeshBase<QuadMesh<MeshTraitsT>, MeshTraitsT, pcl::geometry::QuadMeshTag>;
151 
152  /** \brief addFace for the quad mesh. */
153  inline FaceIndex
154  addFaceImpl(const VertexIndices& vertices,
155  const FaceData& face_data,
156  const EdgeData& edge_data,
157  const HalfEdgeData& half_edge_data)
158  {
159  if (vertices.size() == 4)
160  return (this->addFaceImplBase(vertices, face_data, edge_data, half_edge_data));
161  return (FaceIndex());
162  }
163 
164  ////////////////////////////////////////////////////////////////////////
165  // Members
166  ////////////////////////////////////////////////////////////////////////
167 
168  /** \brief Storage for adding a quad. */
169  VertexIndices add_quad_;
170 
171 public:
173 };
174 } // namespace geometry
175 } // 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
Half-edge mesh that can only store quads.
Definition: quad_mesh.h:59
typename Base::FaceAroundFaceCirculator FaceAroundFaceCirculator
Definition: quad_mesh.h:107
typename Base::IncomingHalfEdgeAroundVertexCirculator IncomingHalfEdgeAroundVertexCirculator
Definition: quad_mesh.h:100
typename Base::OutgoingHalfEdgeAroundVertexCirculator OutgoingHalfEdgeAroundVertexCirculator
Definition: quad_mesh.h:98
typename Base::VertexAroundVertexCirculator VertexAroundVertexCirculator
Definition: quad_mesh.h:96
typename Base::HasVertexData HasVertexData
Definition: quad_mesh.h:74
typename Base::HasFaceData HasFaceData
Definition: quad_mesh.h:77
typename Base::MeshTag MeshTag
Definition: quad_mesh.h:72
typename Base::IsManifold IsManifold
Definition: quad_mesh.h:71
typename Base::HalfEdgeIndices HalfEdgeIndices
Definition: quad_mesh.h:91
typename Base::FaceData FaceData
Definition: quad_mesh.h:70
typename Base::VertexIndices VertexIndices
Definition: quad_mesh.h:90
typename Base::EdgeIndices EdgeIndices
Definition: quad_mesh.h:92
typename Base::HalfEdgeData HalfEdgeData
Definition: quad_mesh.h:68
typename Base::FaceAroundVertexCirculator FaceAroundVertexCirculator
Definition: quad_mesh.h:101
shared_ptr< const Self > ConstPtr
Definition: quad_mesh.h:65
typename Base::VertexIndex VertexIndex
Definition: quad_mesh.h:85
typename Base::InnerHalfEdgeAroundFaceCirculator InnerHalfEdgeAroundFaceCirculator
Definition: quad_mesh.h:104
typename Base::VertexData VertexData
Definition: quad_mesh.h:67
typename Base::HalfEdgeIndex HalfEdgeIndex
Definition: quad_mesh.h:86
typename Base::HalfEdgeDataCloud HalfEdgeDataCloud
Definition: quad_mesh.h:80
typename Base::FaceIndex FaceIndex
Definition: quad_mesh.h:88
typename Base::EdgeData EdgeData
Definition: quad_mesh.h:69
shared_ptr< Self > Ptr
Definition: quad_mesh.h:64
typename Base::VertexDataCloud VertexDataCloud
Definition: quad_mesh.h:79
typename Base::OuterHalfEdgeAroundFaceCirculator OuterHalfEdgeAroundFaceCirculator
Definition: quad_mesh.h:106
typename Base::VertexAroundFaceCirculator VertexAroundFaceCirculator
Definition: quad_mesh.h:102
typename Base::HasHalfEdgeData HasHalfEdgeData
Definition: quad_mesh.h:75
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: quad_mesh.h:131
typename Base::HasEdgeData HasEdgeData
Definition: quad_mesh.h:76
typename Base::EdgeDataCloud EdgeDataCloud
Definition: quad_mesh.h:81
typename Base::FaceIndices FaceIndices
Definition: quad_mesh.h:93
QuadMesh()
Constructor.
Definition: quad_mesh.h:110
typename Base::EdgeIndex EdgeIndex
Definition: quad_mesh.h:87
typename Base::FaceDataCloud FaceDataCloud
Definition: quad_mesh.h:82
#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: quad_mesh.h:50