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_ != -1; }
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  : public std::unary_function<OpenMesh::BaseHandle, std::size_t>
169 {
170 
171  std::size_t operator()(const OpenMesh::BaseHandle& h) const
172  {
173  return h.idx();
174  }
175 };
176 
177 template <>
178 struct hash<OpenMesh::VertexHandle >
179  : public std::unary_function<OpenMesh::VertexHandle, std::size_t>
180 {
181 
182  std::size_t operator()(const OpenMesh::VertexHandle& h) const
183  {
184  return h.idx();
185  }
186 };
187 
188 template <>
189 struct hash<OpenMesh::HalfedgeHandle >
190  : public std::unary_function<OpenMesh::HalfedgeHandle, std::size_t>
191 {
192 
193  std::size_t operator()(const OpenMesh::HalfedgeHandle& h) const
194  {
195  return h.idx();
196  }
197 };
198 
199 template <>
200 struct hash<OpenMesh::EdgeHandle >
201  : public std::unary_function<OpenMesh::EdgeHandle, std::size_t>
202 {
203 
204  std::size_t operator()(const OpenMesh::EdgeHandle& h) const
205  {
206  return h.idx();
207  }
208 };
209 
210 template <>
211 struct hash<OpenMesh::FaceHandle >
212  : public std::unary_function<OpenMesh::FaceHandle, std::size_t>
213 {
214 
215  std::size_t operator()(const OpenMesh::FaceHandle& h) const
216  {
217  return h.idx();
218  }
219 };
220 
221 #if defined(_MSVC_VER)
222 # pragma warning(pop)
223 #endif
224 
225 }
226 #endif // OM_HAS_HASH
227 
228 
229 #endif // OPENMESH_HANDLES_HH
230 //=============================================================================
STL namespace.
void reset()
reset handle to be invalid
Definition: Handles.hh:80
Handle for a vertex entity.
Definition: Handles.hh:125
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
Base class for all handle types.
Definition: Handles.hh:67
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
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
Handle for a edge entity.
Definition: Handles.hh:139
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
Handle for a halfedge entity.
Definition: Handles.hh:132
void invalidate()
reset handle to be invalid
Definition: Handles.hh:82

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