OpenMesh
Handles.hh
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 #ifndef OPENMESH_HANDLES_HH
50 #define OPENMESH_HANDLES_HH
51 
52 
53 //== INCLUDES =================================================================
54 
55 #include <OpenMesh/Core/System/config.h>
56 #include <ostream>
57 
58 
59 //== NAMESPACES ===============================================================
60 
61 namespace OpenMesh {
62 
63 //== CLASS DEFINITION =========================================================
64 
65 
68 {
69 public:
70 
71  explicit BaseHandle(int _idx=-1) : idx_(_idx) {}
72 
74  int idx() const { return idx_; }
75 
77  bool is_valid() const { return idx_ >= 0; }
78 
80  void reset() { idx_=-1; }
82  void invalidate() { idx_ = -1; }
83 
84  bool operator==(const BaseHandle& _rhs) const {
85  return (this->idx_ == _rhs.idx_);
86  }
87 
88  bool operator!=(const BaseHandle& _rhs) const {
89  return (this->idx_ != _rhs.idx_);
90  }
91 
92  bool operator<(const BaseHandle& _rhs) const {
93  return (this->idx_ < _rhs.idx_);
94  }
95 
96 
97  // this is to be used only by the iterators
98  void __increment() { ++idx_; }
99  void __decrement() { --idx_; }
100 
101  void __increment(int amount) { idx_ += amount; }
102  void __decrement(int amount) { idx_ -= amount; }
103 
104 private:
105 
106  int idx_;
107 };
108 
109 // this is used by boost::unordered_set/map
110 inline size_t hash_value(const BaseHandle& h) { return h.idx(); }
111 
112 //-----------------------------------------------------------------------------
113 
115 inline std::ostream& operator<<(std::ostream& _os, const BaseHandle& _hnd)
116 {
117  return (_os << _hnd.idx());
118 }
119 
120 
121 //-----------------------------------------------------------------------------
122 
123 
125 struct VertexHandle : public BaseHandle
126 {
127  explicit VertexHandle(int _idx=-1) : BaseHandle(_idx) {}
128 };
129 
130 
132 struct HalfedgeHandle : public BaseHandle
133 {
134  explicit HalfedgeHandle(int _idx=-1) : BaseHandle(_idx) {}
135 };
136 
137 
139 struct EdgeHandle : public BaseHandle
140 {
141  explicit EdgeHandle(int _idx=-1) : BaseHandle(_idx) {}
142 };
143 
144 
146 struct FaceHandle : public BaseHandle
147 {
148  explicit FaceHandle(int _idx=-1) : BaseHandle(_idx) {}
149 };
150 
151 
152 //=============================================================================
153 } // namespace OpenMesh
154 //=============================================================================
155 
156 #ifdef OM_HAS_HASH
157 #include <functional>
158 namespace std {
159 
160 #if defined(_MSVC_VER)
161 # pragma warning(push)
162 # pragma warning(disable:4099) // For VC++ it is class hash
163 #endif
164 
165 
166 template <>
167 struct hash<OpenMesh::BaseHandle >
168 {
169  typedef OpenMesh::BaseHandle argument_type;
170  typedef std::size_t result_type;
171 
172  std::size_t operator()(const OpenMesh::BaseHandle& h) const
173  {
174  return h.idx();
175  }
176 };
177 
178 template <>
179 struct hash<OpenMesh::VertexHandle >
180 {
181  typedef OpenMesh::VertexHandle argument_type;
182  typedef std::size_t result_type;
183 
184  std::size_t operator()(const OpenMesh::VertexHandle& h) const
185  {
186  return h.idx();
187  }
188 };
189 
190 template <>
191 struct hash<OpenMesh::HalfedgeHandle >
192 {
193 
194  typedef OpenMesh::HalfedgeHandle argument_type;
195  typedef std::size_t result_type;
196 
197  std::size_t operator()(const OpenMesh::HalfedgeHandle& h) const
198  {
199  return h.idx();
200  }
201 };
202 
203 template <>
204 struct hash<OpenMesh::EdgeHandle >
205 {
206 
207  typedef OpenMesh::EdgeHandle argument_type;
208  typedef std::size_t result_type;
209 
210  std::size_t operator()(const OpenMesh::EdgeHandle& h) const
211  {
212  return h.idx();
213  }
214 };
215 
216 template <>
217 struct hash<OpenMesh::FaceHandle >
218 {
219 
220  typedef OpenMesh::FaceHandle argument_type;
221  typedef std::size_t result_type;
222 
223  std::size_t operator()(const OpenMesh::FaceHandle& h) const
224  {
225  return h.idx();
226  }
227 };
228 
229 #if defined(_MSVC_VER)
230 # pragma warning(pop)
231 #endif
232 
233 }
234 #endif // OM_HAS_HASH
235 
236 
237 #endif // OPENMESH_HANDLES_HH
238 //=============================================================================
Handle for a halfedge entity.
Definition: Handles.hh:132
auto operator<<(std::ostream &os, const VectorT< Scalar, DIM > &_vec) -> typename std::enable_if< sizeof(decltype(os<< _vec[0])) >=0
output a vector by printing its space-separated compontens
Handle for a face entity.
Definition: Handles.hh:146
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:77
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
void reset()
reset handle to be invalid
Definition: Handles.hh:80
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
STL namespace.
Handle for a vertex entity.
Definition: Handles.hh:125
void invalidate()
reset handle to be invalid
Definition: Handles.hh:82
Handle for a edge entity.
Definition: Handles.hh:139
Base class for all handle types.
Definition: Handles.hh:67

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .