OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
110 //-----------------------------------------------------------------------------
111 
113 inline std::ostream& operator<<(std::ostream& _os, const BaseHandle& _hnd)
114 {
115  return (_os << _hnd.idx());
116 }
117 
118 
119 //-----------------------------------------------------------------------------
120 
121 
123 struct VertexHandle : public BaseHandle
124 {
125  explicit VertexHandle(int _idx=-1) : BaseHandle(_idx) {}
126 };
127 
128 
130 struct HalfedgeHandle : public BaseHandle
131 {
132  explicit HalfedgeHandle(int _idx=-1) : BaseHandle(_idx) {}
133 };
134 
135 
137 struct EdgeHandle : public BaseHandle
138 {
139  explicit EdgeHandle(int _idx=-1) : BaseHandle(_idx) {}
140 };
141 
142 
144 struct FaceHandle : public BaseHandle
145 {
146  explicit FaceHandle(int _idx=-1) : BaseHandle(_idx) {}
147 };
148 
149 
150 //=============================================================================
151 } // namespace OpenMesh
152 //=============================================================================
153 #endif // OPENMESH_HANDLES_HH
154 //=============================================================================
Base class for all handle types.
Definition: Handles.hh:67
int idx() const
Get the underlying index of this handle.
Definition: Handles.hh:74
Handle for a vertex entity.
Definition: Handles.hh:123
bool is_valid() const
The handle is valid iff the index is not equal to -1.
Definition: Handles.hh:77
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 edge entity.
Definition: Handles.hh:137
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
void invalidate()
reset handle to be invalid
Definition: Handles.hh:82
Handle for a halfedge entity.
Definition: Handles.hh:130
Handle for a face entity.
Definition: Handles.hh:144

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