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: 1278 $ *
45  * $Date: 2015-06-09 10:58:41 +0200 (Di, 09 Jun 2015) $ *
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 
102 private:
103 
104  int idx_;
105 };
106 
107 
108 //-----------------------------------------------------------------------------
109 
111 inline std::ostream& operator<<(std::ostream& _os, const BaseHandle& _hnd)
112 {
113  return (_os << _hnd.idx());
114 }
115 
116 
117 //-----------------------------------------------------------------------------
118 
119 
121 struct VertexHandle : public BaseHandle
122 {
123  explicit VertexHandle(int _idx=-1) : BaseHandle(_idx) {}
124 };
125 
126 
128 struct HalfedgeHandle : public BaseHandle
129 {
130  explicit HalfedgeHandle(int _idx=-1) : BaseHandle(_idx) {}
131 };
132 
133 
135 struct EdgeHandle : public BaseHandle
136 {
137  explicit EdgeHandle(int _idx=-1) : BaseHandle(_idx) {}
138 };
139 
140 
142 struct FaceHandle : public BaseHandle
143 {
144  explicit FaceHandle(int _idx=-1) : BaseHandle(_idx) {}
145 };
146 
147 
148 //=============================================================================
149 } // namespace OpenMesh
150 //=============================================================================
151 #endif // OPENMESH_HANDLES_HH
152 //=============================================================================
Handle for a edge entity.
Definition: Handles.hh:135
Base class for all handle types.
Definition: Handles.hh:67
void invalidate()
reset handle to be invalid
Definition: Handles.hh:82
void reset()
reset handle to be invalid
Definition: Handles.hh:80
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:128
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
Handle for a face entity.
Definition: Handles.hh:142
Handle for a vertex entity.
Definition: Handles.hh:121
std::ostream & operator<<(std::ostream &_os, const BaseHandle &_hnd)
Write handle _hnd to stream _os.
Definition: Handles.hh:111

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