Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OpenVolumeMeshHandle.hh
1 /*===========================================================================*\
2  * *
3  * OpenVolumeMesh *
4  * Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen *
5  * www.openvolumemesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenVolumeMesh. *
9  * *
10  * OpenVolumeMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenVolumeMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenVolumeMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision$ *
38  * $Date$ *
39  * $LastChangedBy$ *
40  * *
41 \*===========================================================================*/
42 
43 #ifndef OPENVOLUMEMESHHANDLE_HH_
44 #define OPENVOLUMEMESHHANDLE_HH_
45 
46 #include <algorithm>
47 #include <iosfwd>
48 #include <vector>
49 
50 #include "../System/FunctionalInclude.hh"
51 
52 namespace OpenVolumeMesh {
53 
54 // Define handle types in order to distinguish different entities by their indices
56 public:
57  // Default constructor
58  explicit OpenVolumeMeshHandle(int _idx) : idx_(_idx) {};
59 
60  OpenVolumeMeshHandle& operator=(int _idx) {
61  idx_ = _idx;
62  return *this;
63  }
64 
65  OpenVolumeMeshHandle& operator=(const OpenVolumeMeshHandle& _idx) {
66  idx_ = _idx.idx_;
67  return *this;
68  }
69 
70  inline bool is_valid() const { return idx_ != -1; }
71 
72  inline bool operator<(const OpenVolumeMeshHandle& _idx) const { return (this->idx_ < _idx.idx_); }
73 
74  inline bool operator<(int _idx) const { return idx_ < _idx; }
75 
76  inline bool operator>(const OpenVolumeMeshHandle& _idx) const { return (this->idx_ > _idx.idx_); }
77 
78  inline bool operator>(int _idx) const { return idx_ > _idx; }
79 
80  inline bool operator==(const OpenVolumeMeshHandle& _h) const { return _h.idx_ == this->idx_; }
81 
82  inline bool operator!=(const OpenVolumeMeshHandle& _h) const { return _h.idx_ != this->idx_; }
83 
84  inline const int& idx() const { return idx_; }
85 
86  void idx(const int& _idx) { idx_ = _idx; }
87 
88  inline operator int() const { return idx_; }
89 
90  void reset() { idx_ = -1; }
91 
92 private:
93  int idx_;
94 };
95 
96 // Default entity handles
97 
98 class VertexHandle : public OpenVolumeMeshHandle { public: VertexHandle(int _idx = -1) : OpenVolumeMeshHandle(_idx) {} };
99 class EdgeHandle : public OpenVolumeMeshHandle { public: EdgeHandle(int _idx = -1) : OpenVolumeMeshHandle(_idx) {} };
100 class FaceHandle : public OpenVolumeMeshHandle { public: FaceHandle(int _idx = -1) : OpenVolumeMeshHandle(_idx) {} };
101 class CellHandle : public OpenVolumeMeshHandle { public: CellHandle(int _idx = -1) : OpenVolumeMeshHandle(_idx) {} };
102 class HalfEdgeHandle : public OpenVolumeMeshHandle { public: HalfEdgeHandle(int _idx = -1) : OpenVolumeMeshHandle(_idx) {} };
103 class HalfFaceHandle : public OpenVolumeMeshHandle { public: HalfFaceHandle(int _idx = -1) : OpenVolumeMeshHandle(_idx) {} };
104 
105 // Helper class that is used to decrease all handles
106 // exceeding a certain threshold
107 
109 public:
110  VHandleCorrection(VertexHandle _thld) : thld_(_thld) {}
111  void correctValue(VertexHandle& _h) {
112  if(_h > thld_) _h.idx(_h.idx() - 1);
113  }
114 private:
115  VertexHandle thld_;
116 };
118 public:
119  HEHandleCorrection(HalfEdgeHandle _thld) : thld_(_thld) {}
120  void correctVecValue(std::vector<HalfEdgeHandle>& _vec) {
121 #if defined(__clang_major__) && (__clang_major__ >= 5)
122  for(std::vector<HalfEdgeHandle>::iterator it = _vec.begin(), end = _vec.end(); it != end; ++it) {
123  correctValue(*it);
124  }
125 #else
126  std::for_each(_vec.begin(), _vec.end(), fun::bind(&HEHandleCorrection::correctValue, this, fun::placeholders::_1));
127 #endif
128  }
129  void correctValue(HalfEdgeHandle& _h) {
130  if(_h > thld_) _h.idx(_h.idx() - 2);
131  }
132 private:
133  HalfEdgeHandle thld_;
134 };
136 public:
137  HFHandleCorrection(HalfFaceHandle _thld) : thld_(_thld) {}
138  void correctVecValue(std::vector<HalfFaceHandle>& _vec) {
139 #if defined(__clang_major__) && (__clang_major__ >= 5)
140  for(std::vector<HalfFaceHandle>::iterator it = _vec.begin(), end = _vec.end(); it != end; ++it) {
141  correctValue(*it);
142  }
143 #else
144  std::for_each(_vec.begin(), _vec.end(), fun::bind(&HFHandleCorrection::correctValue, this, fun::placeholders::_1));
145 #endif
146  }
147  void correctValue(HalfFaceHandle& _h) {
148  if(_h > thld_) _h.idx(_h.idx() - 2);
149  }
150 private:
151  HalfFaceHandle thld_;
152 };
154 public:
155  CHandleCorrection(CellHandle _thld) : thld_(_thld) {}
156  void correctValue(CellHandle& _h) {
157  if(_h > thld_) _h.idx(_h.idx() - 1);
158  }
159 private:
160  CellHandle thld_;
161 };
162 
163 bool operator==(const int& _lhs, const OpenVolumeMeshHandle& _rhs);
164 
165 bool operator==(const unsigned int& _lhs, const OpenVolumeMeshHandle& _rhs);
166 
167 bool operator!=(const int& _lhs, const OpenVolumeMeshHandle& _rhs);
168 
169 bool operator!=(const unsigned int& _lhs, const OpenVolumeMeshHandle& _rhs);
170 
171 std::ostream& operator<<(std::ostream& _ostr, const OpenVolumeMeshHandle& _handle);
172 
173 std::istream& operator>>(std::istream& _istr, OpenVolumeMeshHandle& _handle);
174 
175 } // Namespace OpenVolumeMesh
176 
177 #endif /* OPENVOLUMEMESHHANDLE_HH_ */
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
Definition: bindT.hh:106