OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
CompositeTraits.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh 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 * OpenMesh 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 OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
46 //=============================================================================
47 //
48 // CLASS Traits
49 //
50 //=============================================================================
51
52 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH
53 #define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH
54
55
56 //== INCLUDES =================================================================
57
58 #include <map>
59 #include <OpenMesh/Core/Mesh/Traits.hh>
60
61 //== NAMESPACE ================================================================
62
63 namespace OpenMesh { // BEGIN_NS_OPENMESH
64 namespace Subdivider { // BEGIN_NS_DECIMATER
65 namespace Adaptive { // BEGIN_NS_ADAPTIVE
66
67
68 //== CLASS DEFINITION =========================================================
69
73 // typedef unsigned short state_t;
74 // const state_t mask_final = 1 << ((sizeof(state_t)*8)-1);
75 // const state_t mask_state = ~mask_final;
76
79 struct CompositeTraits : public OpenMesh::DefaultTraits
80 {
81 typedef int state_t;
82 typedef bool final_t;
83
84
86 struct State
87 {
88 int state : 31;
89 unsigned final : 1;
90 };
91
92 // ---------------------------------------- attributes
93
94 // add face normals
95 FaceAttributes( OpenMesh::Attributes::Normal );
96
97 // add vertex normals
98 VertexAttributes( OpenMesh::Attributes::Normal );
99
100 // add previous halfedge handle
101 HalfedgeAttributes( OpenMesh::Attributes::PrevHalfedge );
102
103 // ---------------------------------------- items
104
105 FaceTraits
106 {
107
108 private:
109
110 typedef typename Refs::Point Point;
111 typedef typename Refs::HalfedgeHandle HalfedgeHandle;
112 typedef std::map<state_t, Point> PositionHistory;
113
114 State state_;
115 HalfedgeHandle red_halfedge_;
116
117 PositionHistory pos_map_;
118
119 public:
120
121 // face state
122 state_t state() const { return state_t(state_.state); }
123 void set_state(const state_t _s) { state_.state = _s; }
124 void inc_state() { ++state_.state; }
125
126 // face not final if divided (loop) or edge not flipped (sqrt(3))
127 final_t final() const { return final_t(state_.final); }
128 void set_final() { state_.final = true; }
129 void set_not_final() { state_.final = false; }
130
131 // halfedge of dividing edge (red-green triangulation)
132 const HalfedgeHandle& red_halfedge() const { return red_halfedge_; }
133 void set_red_halfedge(const HalfedgeHandle& _h) { red_halfedge_ = _h; }
134
135 // position of face, depending on generation _i.
136 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
137 const Point position(const int& _i) {
138 if (pos_map_.find(_i) != pos_map_.end())
139 return pos_map_[_i];
140 else {
141
142 if (_i <= 0) {
143 return Point(0.0, 0.0, 0.0);
144 }
145
146 return position(_i - 1);
147 }
148 }
149 }; // end class FaceTraits
150
151
152 EdgeTraits
153 {
154
155 private:
156
157 typedef typename Refs::Point Point;
158 typedef std::map<state_t, Point> PositionHistory;
159
160 State state_;
161 PositionHistory pos_map_;
162
163 public:
164
165 typedef typename Refs::Scalar Scalar;
166
167 // Scalar weight_;
168
169 // state of edge
170 state_t state() const { return state_t(state_.state); }
171 void set_state(const state_t _s) { state_.state = _s; }
172 void inc_state() { ++state_.state; }
173
174 // edge not final if dividing face (Loop) or edge not flipped (SQRT(3))
175 final_t final() const { return final_t(state_.final); }
176 void set_final() { state_.final = true; }
177 void set_not_final() { state_.final = false; }
178
179 // position of edge, depending on generation _i.
180 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
181
182 const Point position(const int& _i) {
183
184 if (pos_map_.find(_i) != pos_map_.end())
185 return pos_map_[_i];
186 else
187 {
188 if (_i <= 0)
189 {
190 const Point zero_point(0.0, 0.0, 0.0);
191 return zero_point;
192 }
193
194 return position(_i - 1);
195 }
196 }
197 }; // end class EdgeTraits
198
199
200 VertexTraits
201 {
202
203 private:
204
205 typedef typename Refs::Point Point;
206 typedef std::map<state_t, Point> PositionHistory;
207
208 State state_;
209 PositionHistory pos_map_;
210
211 public:
212
213 // state of vertex
214 state_t state() const { return state_.state; }
215 void set_state(const state_t _s) { state_.state = _s; }
216 void inc_state() { ++state_.state; }
217
218
219 // usually not needed by loop or sqrt(3)
220 final_t final() const { return state_.final; }
221 void set_final() { state_.final = true; }
222 void set_not_final() { state_.final = false; }
223
224 // position of vertex, depending on generation _i. (not for display)
225 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
226 const Point position(const int& _i) {
227
228 if (pos_map_.find(_i) != pos_map_.end())
229
230 return pos_map_[_i];
231
232 else {
233
234 if (_i <= 0) {
235
236 const Point zero_point(0.0, 0.0, 0.0);
237 return zero_point;
238 }
239
240 return position(_i - 1);
241 }
242 }
243 }; // end class VertexTraits
244 }; // end class CompositeTraits
245
246
247 // export items to namespace to maintain compatibility
248 typedef CompositeTraits::state_t state_t;
249 typedef CompositeTraits::final_t final_t;
250 typedef CompositeTraits::State State;
251
252 //=============================================================================
253 } // END_NS_ADAPTIVE
254 } // END_NS_SUBDIVIDER
255 } // END_NS_OPENMESH
256 //=============================================================================
257 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH defined
258 //=============================================================================