| OpenMesh

SmartHandles.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2019, 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 #pragma once
44
45
46 //== INCLUDES =================================================================
47
48 #include "Handles.hh"
49 #include <OpenMesh/Core/Mesh/PolyConnectivity.hh>
50 #include <OpenMesh/Core/System/OpenMeshDLLMacros.hh>
51
52
53 //== NAMESPACES ===============================================================
54
55 namespace OpenMesh {
56
57 //== FORWARD DECLARATION ======================================================
58
59 struct SmartVertexHandle;
60 struct SmartHalfedgeHandle;
61 struct SmartEdgeHandle;
62 struct SmartFaceHandle;
63
64
65 //== CLASS DEFINITION =========================================================
66
68 class OPENMESHDLLEXPORT SmartBaseHandle
69 {
70 public:
71 explicit SmartBaseHandle(const PolyConnectivity* _mesh = nullptr) : mesh_(_mesh) {}
72
74 const PolyConnectivity* mesh() const { return mesh_; }
75
76 // TODO: should operators ==, !=, < look at mesh_?
77
78 private:
79 const PolyConnectivity* mesh_;
80
81 };
82
84 struct OPENMESHDLLEXPORT SmartVertexHandle : public SmartBaseHandle, VertexHandle
85 {
86 explicit SmartVertexHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), VertexHandle(_idx) {}
87
89 SmartHalfedgeHandle out() const;
91 SmartHalfedgeHandle halfedge() const; // alias for out
93 SmartHalfedgeHandle in() const;
94
96 PolyConnectivity::ConstVertexFaceRange faces() const;
98 PolyConnectivity::ConstVertexEdgeRange edges() const;
100 PolyConnectivity::ConstVertexVertexRange vertices() const;
102 PolyConnectivity::ConstVertexIHalfedgeRange incoming_halfedges() const;
104 PolyConnectivity::ConstVertexOHalfedgeRange outgoing_halfedges() const;
105
107 uint valence() const;
109 bool is_boundary() const;
111 bool is_manifold() const;
112 };
113
114 struct OPENMESHDLLEXPORT SmartHalfedgeHandle : public SmartBaseHandle, HalfedgeHandle
115 {
116 explicit SmartHalfedgeHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), HalfedgeHandle(_idx) {}
117
119 SmartHalfedgeHandle next() const;
121 SmartHalfedgeHandle prev() const;
123 SmartHalfedgeHandle opp() const;
125 SmartVertexHandle to() const;
127 SmartVertexHandle from() const;
129 SmartEdgeHandle edge() const;
131 SmartFaceHandle face() const;
132
134 bool is_boundary() const;
135 };
136
137 struct OPENMESHDLLEXPORT SmartEdgeHandle : public SmartBaseHandle, EdgeHandle
138 {
139 explicit SmartEdgeHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), EdgeHandle(_idx) {}
140
142 SmartHalfedgeHandle halfedge(unsigned int _i) const;
144 SmartHalfedgeHandle h(unsigned int _i) const;
146 SmartHalfedgeHandle h0() const;
148 SmartHalfedgeHandle h1() const;
150 SmartVertexHandle vertex(unsigned int _i) const;
152 SmartVertexHandle v(unsigned int _i) const;
154 SmartVertexHandle v0() const;
156 SmartVertexHandle v1() const;
157
159 bool is_boundary() const;
160 };
161
162 struct OPENMESHDLLEXPORT SmartFaceHandle : public SmartBaseHandle, FaceHandle
163 {
164 explicit SmartFaceHandle(int _idx=-1, const PolyConnectivity* _mesh = nullptr) : SmartBaseHandle(_mesh), FaceHandle(_idx) {}
165
167 SmartHalfedgeHandle halfedge() const;
168
170 PolyConnectivity::ConstFaceVertexRange vertices() const;
172 PolyConnectivity::ConstFaceHalfedgeRange halfedges() const;
174 PolyConnectivity::ConstFaceEdgeRange edges() const;
176 PolyConnectivity::ConstFaceFaceRange faces() const;
177
179 uint valence() const;
181 bool is_boundary() const;
182 };
183
184
186 inline SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity* _mesh) { return SmartVertexHandle (_vh.idx(), _mesh); }
188 inline SmartHalfedgeHandle make_smart(HalfedgeHandle _hh, const PolyConnectivity* _mesh) { return SmartHalfedgeHandle(_hh.idx(), _mesh); }
190 inline SmartEdgeHandle make_smart(EdgeHandle _eh, const PolyConnectivity* _mesh) { return SmartEdgeHandle (_eh.idx(), _mesh); }
192 inline SmartFaceHandle make_smart(FaceHandle _fh, const PolyConnectivity* _mesh) { return SmartFaceHandle (_fh.idx(), _mesh); }
193
195 inline SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity& _mesh) { return SmartVertexHandle (_vh.idx(), &_mesh); }
197 inline SmartHalfedgeHandle make_smart(HalfedgeHandle _hh, const PolyConnectivity& _mesh) { return SmartHalfedgeHandle(_hh.idx(), &_mesh); }
199 inline SmartEdgeHandle make_smart(EdgeHandle _eh, const PolyConnectivity& _mesh) { return SmartEdgeHandle (_eh.idx(), &_mesh); }
201 inline SmartFaceHandle make_smart(FaceHandle _fh, const PolyConnectivity& _mesh) { return SmartFaceHandle (_fh.idx(), &_mesh); }
202
203
204 // helper to convert Handle Types to Smarthandle Types
205 template <typename HandleT>
206 struct SmartHandle;
207
208 template <> struct SmartHandle<VertexHandle> { using type = SmartVertexHandle; };
209 template <> struct SmartHandle<HalfedgeHandle> { using type = SmartHalfedgeHandle; };
210 template <> struct SmartHandle<EdgeHandle> { using type = SmartEdgeHandle; };
211 template <> struct SmartHandle<FaceHandle> { using type = SmartFaceHandle; };
212
213
214 inline SmartHalfedgeHandle SmartVertexHandle::out() const
215 {
216 assert(mesh() != nullptr);
217 return make_smart(mesh()->halfedge_handle(*this), mesh());
218 }
219
220 inline SmartHalfedgeHandle SmartVertexHandle::halfedge() const
221 {
222 return out();
223 }
224
225 inline SmartHalfedgeHandle SmartVertexHandle::in() const
226 {
227 return out().opp();
228 }
229
230 inline uint SmartVertexHandle::valence() const
231 {
232 assert(mesh() != nullptr);
233 return mesh()->valence(*this);
234 }
235
236 inline bool SmartVertexHandle::is_boundary() const
237 {
238 assert(mesh() != nullptr);
239 return mesh()->is_boundary(*this);
240 }
241
242 inline bool SmartVertexHandle::is_manifold() const
243 {
244 assert(mesh() != nullptr);
245 return mesh()->is_manifold(*this);
246 }
247
248 inline SmartHalfedgeHandle SmartHalfedgeHandle::next() const
249 {
250 assert(mesh() != nullptr);
251 return make_smart(mesh()->next_halfedge_handle(*this), mesh());
252 }
253
254 inline SmartHalfedgeHandle SmartHalfedgeHandle::prev() const
255 {
256 assert(mesh() != nullptr);
257 return make_smart(mesh()->prev_halfedge_handle(*this), mesh());
258 }
259
260 inline SmartHalfedgeHandle SmartHalfedgeHandle::opp() const
261 {
262 assert(mesh() != nullptr);
263 return make_smart(mesh()->opposite_halfedge_handle(*this), mesh());
264 }
265
266 inline SmartVertexHandle SmartHalfedgeHandle::to() const
267 {
268 assert(mesh() != nullptr);
269 return make_smart(mesh()->to_vertex_handle(*this), mesh());
270 }
271
272 inline SmartVertexHandle SmartHalfedgeHandle::from() const
273 {
274 assert(mesh() != nullptr);
275 return make_smart(mesh()->from_vertex_handle(*this), mesh());
276 }
277
278 inline SmartEdgeHandle SmartHalfedgeHandle::edge() const
279 {
280 assert(mesh() != nullptr);
281 return make_smart(mesh()->edge_handle(*this), mesh());
282 }
283
284 inline SmartFaceHandle SmartHalfedgeHandle::face() const
285 {
286 assert(mesh() != nullptr);
287 return make_smart(mesh()->face_handle(*this), mesh());
288 }
289
290 inline bool SmartHalfedgeHandle::is_boundary() const
291 {
292 assert(mesh() != nullptr);
293 return mesh()->is_boundary(*this);
294 }
295
296 inline SmartHalfedgeHandle SmartEdgeHandle::halfedge(unsigned int _i) const
297 {
298 assert(mesh() != nullptr);
299 return make_smart(mesh()->halfedge_handle(*this, _i), mesh());
300 }
301
302 inline SmartHalfedgeHandle SmartEdgeHandle::h(unsigned int _i) const
303 {
304 return halfedge(_i);
305 }
306
307 inline SmartHalfedgeHandle SmartEdgeHandle::h0() const
308 {
309 return h(0);
310 }
311
312 inline SmartHalfedgeHandle SmartEdgeHandle::h1() const
313 {
314 return h(1);
315 }
316
317 inline SmartVertexHandle SmartEdgeHandle::vertex(unsigned int _i) const
318 {
319 return halfedge(_i).from();
320 }
321
322 inline SmartVertexHandle SmartEdgeHandle::v(unsigned int _i) const
323 {
324 return vertex(_i);
325 }
326
327 inline SmartVertexHandle SmartEdgeHandle::v0() const
328 {
329 return v(0);
330 }
331
332 inline SmartVertexHandle SmartEdgeHandle::v1() const
333 {
334 return v(1);
335 }
336
337 inline bool SmartEdgeHandle::is_boundary() const
338 {
339 assert(mesh() != nullptr);
340 return mesh()->is_boundary(*this);
341 }
342
343 inline SmartHalfedgeHandle SmartFaceHandle::halfedge() const
344 {
345 assert(mesh() != nullptr);
346 return make_smart(mesh()->halfedge_handle(*this), mesh());
347 }
348
349 inline uint SmartFaceHandle::valence() const
350 {
351 assert(mesh() != nullptr);
352 return mesh()->valence(*this);
353 }
354
355 inline bool SmartFaceHandle::is_boundary() const
356 {
357 assert(mesh() != nullptr);
358 return mesh()->is_boundary(*this);
359 }
360
361
362
363 //=============================================================================
364 } // namespace OpenMesh
365 //=============================================================================
366
367 //=============================================================================
OpenMesh::SmartEdgeHandle::vertex
SmartVertexHandle vertex(unsigned int _i) const
Returns one of the two incident vertices of the edge.
Definition: SmartHandles.hh:317
OpenMesh::FaceHandle
Handle for a face entity.
Definition: Handles.hh:141
OpenMesh::SmartHalfedgeHandle::edge
SmartEdgeHandle edge() const
Returns incident edge of halfedge.
Definition: SmartHandles.hh:278
OpenMesh::SmartFaceHandle::valence
uint valence() const
Returns the valence of the face.
Definition: SmartHandles.hh:349
OpenMesh::SmartEdgeHandle::v
SmartVertexHandle v(unsigned int _i) const
Shorthand for vertex()
Definition: SmartHandles.hh:322
OpenMesh::SmartFaceHandle::is_boundary
bool is_boundary() const
Returns true iff the face lies at the boundary (i.e. one of the edges is boundary) ...
Definition: SmartHandles.hh:355
OpenMesh::SmartFaceHandle::halfedge
SmartHalfedgeHandle halfedge() const
Returns one of the halfedges of the face.
Definition: SmartHandles.hh:343
OpenMesh::SmartEdgeHandle::h
SmartHalfedgeHandle h(unsigned int _i) const
Shorthand for halfedge()
Definition: SmartHandles.hh:302
OpenMesh::SmartVertexHandle::valence
uint valence() const
Returns valence of the vertex.
Definition: SmartHandles.hh:230
OpenMesh::SmartHalfedgeHandle::to
SmartVertexHandle to() const
Returns vertex pointed to by halfedge.
Definition: SmartHandles.hh:266
OpenMesh::SmartEdgeHandle::is_boundary
bool is_boundary() const
Returns true iff the edge lies on the boundary (i.e. one of the halfedges is boundary) ...
Definition: SmartHandles.hh:337
OpenMesh::SmartBaseHandle::mesh
const PolyConnectivity * mesh() const
Get the underlying mesh of this handle.
Definition: SmartHandles.hh:74
OpenMesh::SmartBaseHandle
Base class for all smart handle types.
Definition: SmartHandles.hh:68
OpenMesh::SmartVertexHandle::is_manifold
bool is_manifold() const
Returns true iff (the mesh at) the vertex is two-manifold ?
Definition: SmartHandles.hh:242
OpenMesh::SmartHalfedgeHandle::opp
SmartHalfedgeHandle opp() const
Returns opposite halfedge handle.
Definition: SmartHandles.hh:260
OpenMesh::SmartVertexHandle::is_boundary
bool is_boundary() const
Returns true iff the vertex is incident to a boundary halfedge.
Definition: SmartHandles.hh:236
OpenMesh::SmartHalfedgeHandle::from
SmartVertexHandle from() const
Returns vertex at start of halfedge.
Definition: SmartHandles.hh:272
OpenMesh::SmartHandle
Definition: SmartHandles.hh:206
OpenMesh::SmartEdgeHandle::h1
SmartHalfedgeHandle h1() const
Shorthand for halfedge(1)
Definition: SmartHandles.hh:312
OpenMesh::VertexHandle
Handle for a vertex entity.
Definition: Handles.hh:120
OpenMesh::SmartHalfedgeHandle::next
SmartHalfedgeHandle next() const
Returns next halfedge handle.
Definition: SmartHandles.hh:248
OpenMesh::SmartEdgeHandle::v0
SmartVertexHandle v0() const
Shorthand for vertex(0)
Definition: SmartHandles.hh:327
OpenMesh::SmartHalfedgeHandle
Definition: SmartHandles.hh:114
OpenMesh::SmartVertexHandle::out
SmartHalfedgeHandle out() const
Returns an outgoing halfedge.
Definition: SmartHandles.hh:214
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:69
OpenMesh::SmartEdgeHandle::h0
SmartHalfedgeHandle h0() const
Shorthand for halfedge(0)
Definition: SmartHandles.hh:307
OpenMesh::SmartHalfedgeHandle::prev
SmartHalfedgeHandle prev() const
Returns previous halfedge handle.
Definition: SmartHandles.hh:254
OpenMesh::SmartFaceHandle
Definition: SmartHandles.hh:162
OpenMesh::SmartVertexHandle
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
Definition: SmartHandles.hh:84
OpenMesh::CirculatorRange
Generic class for iterator ranges.
Definition: PolyConnectivity.hh:86
OpenMesh::EdgeHandle
Handle for a edge entity.
Definition: Handles.hh:134
OpenMesh::SmartHalfedgeHandle::face
SmartFaceHandle face() const
Returns incident face of halfedge.
Definition: SmartHandles.hh:284
OpenMesh::SmartEdgeHandle::halfedge
SmartHalfedgeHandle halfedge(unsigned int _i) const
Returns one of the two halfedges of the edge.
Definition: SmartHandles.hh:296
OpenMesh::make_smart
SmartVertexHandle make_smart(VertexHandle _vh, const PolyConnectivity *_mesh)
Creats a SmartVertexHandle from a VertexHandle and a Mesh.
Definition: SmartHandles.hh:186
OpenMesh::SmartEdgeHandle
Definition: SmartHandles.hh:137
OpenMesh::PolyConnectivity
Connectivity Class for polygonal meshes.
Definition: PolyConnectivity.hh:112
OpenMesh::SmartVertexHandle::halfedge
SmartHalfedgeHandle halfedge() const
Returns an outgoing halfedge.
Definition: SmartHandles.hh:220
OpenMesh::SmartHalfedgeHandle::is_boundary
bool is_boundary() const
Returns true iff the halfedge is on the boundary (i.e. it has no corresponding face) ...
Definition: SmartHandles.hh:290
OpenMesh::SmartVertexHandle::in
SmartHalfedgeHandle in() const
Returns an incoming halfedge.
Definition: SmartHandles.hh:225
OpenMesh::SmartEdgeHandle::v1
SmartVertexHandle v1() const
Shorthand for vertex(1)
Definition: SmartHandles.hh:332
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::HalfedgeHandle
Handle for a halfedge entity.
Definition: Handles.hh:127