Developer Documentation

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 #ifndef OPENMESH_HANDLES_HH
45 #define OPENMESH_HANDLES_HH
46
47
48 //== INCLUDES =================================================================
49
50 #include <OpenMesh/Core/System/config.h>
51 #include <ostream>
52
53
54 //== NAMESPACES ===============================================================
55
56 namespace OpenMesh {
57
58 //== CLASS DEFINITION =========================================================
59
60
62 class BaseHandle
63 {
64 public:
65
66 explicit BaseHandle(int _idx=-1) : idx_(_idx) {}
67
69 int idx() const { return idx_; }
70
72 bool is_valid() const { return idx_ >= 0; }
73
75 void reset() { idx_=-1; }
77 void invalidate() { idx_ = -1; }
78
79 bool operator==(const BaseHandle& _rhs) const {
80 return (this->idx_ == _rhs.idx_);
81 }
82
83 bool operator!=(const BaseHandle& _rhs) const {
84 return (this->idx_ != _rhs.idx_);
85 }
86
87 bool operator<(const BaseHandle& _rhs) const {
88 return (this->idx_ < _rhs.idx_);
89 }
90
91
92 // this is to be used only by the iterators
93 void __increment() { ++idx_; }
94 void __decrement() { --idx_; }
95
96 void __increment(int amount) { idx_ += amount; }
97 void __decrement(int amount) { idx_ -= amount; }
98
99 private:
100
101 int idx_;
102 };
103
104 // this is used by boost::unordered_set/map
105 inline size_t hash_value(const BaseHandle& h) { return h.idx(); }
106
107 //-----------------------------------------------------------------------------
108
110 inline std::ostream& operator<<(std::ostream& _os, const BaseHandle& _hnd)
111 {
112 return (_os << _hnd.idx());
113 }
114
115
116 //-----------------------------------------------------------------------------
117
118
120 struct VertexHandle : public BaseHandle
121 {
122 explicit VertexHandle(int _idx=-1) : BaseHandle(_idx) {}
123 };
124
125
127 struct HalfedgeHandle : public BaseHandle
128 {
129 explicit HalfedgeHandle(int _idx=-1) : BaseHandle(_idx) {}
130 };
131
132
134 struct EdgeHandle : public BaseHandle
135 {
136 explicit EdgeHandle(int _idx=-1) : BaseHandle(_idx) {}
137 };
138
139
141 struct FaceHandle : public BaseHandle
142 {
143 explicit FaceHandle(int _idx=-1) : BaseHandle(_idx) {}
144 };
145
146
147 //=============================================================================
148 } // namespace OpenMesh
149 //=============================================================================
150
151 #ifdef OM_HAS_HASH
152 #include <functional>
153 namespace std {
154
155 #if defined(_MSVC_VER)
156 # pragma warning(push)
157 # pragma warning(disable:4099) // For VC++ it is class hash
158 #endif
159
160
161 template <>
162 struct hash<OpenMesh::BaseHandle >
163 {
164 typedef OpenMesh::BaseHandle argument_type;
165 typedef std::size_t result_type;
166
167 std::size_t operator()(const OpenMesh::BaseHandle& h) const
168 {
169 return h.idx();
170 }
171 };
172
173 template <>
174 struct hash<OpenMesh::VertexHandle >
175 {
176 typedef OpenMesh::VertexHandle argument_type;
177 typedef std::size_t result_type;
178
179 std::size_t operator()(const OpenMesh::VertexHandle& h) const
180 {
181 return h.idx();
182 }
183 };
184
185 template <>
186 struct hash<OpenMesh::HalfedgeHandle >
187 {
188
189 typedef OpenMesh::HalfedgeHandle argument_type;
190 typedef std::size_t result_type;
191
192 std::size_t operator()(const OpenMesh::HalfedgeHandle& h) const
193 {
194 return h.idx();
195 }
196 };
197
198 template <>
199 struct hash<OpenMesh::EdgeHandle >
200 {
201
202 typedef OpenMesh::EdgeHandle argument_type;
203 typedef std::size_t result_type;
204
205 std::size_t operator()(const OpenMesh::EdgeHandle& h) const
206 {
207 return h.idx();
208 }
209 };
210
211 template <>
212 struct hash<OpenMesh::FaceHandle >
213 {
214
215 typedef OpenMesh::FaceHandle argument_type;
216 typedef std::size_t result_type;
217
218 std::size_t operator()(const OpenMesh::FaceHandle& h) const
219 {
220 return h.idx();
221 }
222 };
223
224 #if defined(_MSVC_VER)
225 # pragma warning(pop)
226 #endif
227
228 }
229 #endif // OM_HAS_HASH
230
231
232 #endif // OPENMESH_HANDLES_HH
233 //=============================================================================
OpenMesh::operator<<
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
Definition: VectorT.hh:647
OpenMesh::VertexHandle
Handle for a vertex entity.
Definition: Handles.hh:120
OpenMesh::HalfedgeHandle
Handle for a halfedge entity.
Definition: Handles.hh:127
OpenMesh::BaseHandle::invalidate
void invalidate()
reset handle to be invalid
Definition: Handles.hh:77
config.h
OpenMesh::FaceHandle
Handle for a face entity.
Definition: Handles.hh:141
std
STL namespace.
OpenMesh::BaseHandle
Base class for all handle types.
Definition: Handles.hh:62
OpenMesh::EdgeHandle
Handle for a edge entity.
Definition: Handles.hh:134
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:69
OpenMesh::BaseHandle::is_valid
bool is_valid() const
The handle is valid iff the index is not negative.
Definition: Handles.hh:72
OpenMesh
Definition: MeshItems.hh:59
OpenMesh::BaseHandle::reset
void reset()
reset handle to be invalid
Definition: Handles.hh:75