Developer Documentation

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CompositeTraits.hh
Go to the documentation of this file.
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
53 //=============================================================================
54 //
55 // CLASS Traits
56 //
57 //=============================================================================
58
59 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH
60 #define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH
61
62
63 //== INCLUDES =================================================================
64
65 #include <map>
66 #include <OpenMesh/Core/Mesh/Traits.hh>
67
68 //== NAMESPACE ================================================================
69
70 namespace OpenMesh { // BEGIN_NS_OPENMESH
71 namespace Subdivider { // BEGIN_NS_DECIMATER
72 namespace Adaptive { // BEGIN_NS_ADAPTIVE
73
74
75 //== CLASS DEFINITION =========================================================
76
80 // typedef unsigned short state_t;
81 // const state_t mask_final = 1 << ((sizeof(state_t)*8)-1);
82 // const state_t mask_state = ~mask_final;
83
86 struct CompositeTraits : public OpenMesh::DefaultTraits
87 {
88 typedef int state_t;
89 typedef bool final_t;
90
91
93 struct State
94 {
95 int state : 31;
96 unsigned final : 1;
97 };
98
99 // ---------------------------------------- attributes
100
101 // add face normals
102 FaceAttributes( OpenMesh::Attributes::Normal );
103
104 // add vertex normals
105 VertexAttributes( OpenMesh::Attributes::Normal );
106
107 // add previous halfedge handle
108 HalfedgeAttributes( OpenMesh::Attributes::PrevHalfedge );
109
110 // ---------------------------------------- items
111
112 FaceTraits
113 {
114
115 private:
116
117 typedef typename Refs::Point Point;
118 typedef typename Refs::HalfedgeHandle HalfedgeHandle;
119 typedef std::map<state_t, Point> PositionHistory;
120
121 State state_;
122 HalfedgeHandle red_halfedge_;
123
124 PositionHistory pos_map_;
125
126 public:
127
128 // face state
129 state_t state() const { return state_t(state_.state); }
130 void set_state(const state_t _s) { state_.state = _s; }
131 void inc_state() { ++state_.state; }
132
133 // face not final if divided (loop) or edge not flipped (sqrt(3))
134 final_t final() const { return final_t(state_.final); }
135 void set_final() { state_.final = true; }
136 void set_not_final() { state_.final = false; }
137
138 // halfedge of dividing edge (red-green triangulation)
139 const HalfedgeHandle& red_halfedge() const { return red_halfedge_; }
140 void set_red_halfedge(const HalfedgeHandle& _h) { red_halfedge_ = _h; }
141
142 // position of face, depending on generation _i.
143 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
144 const Point position(const int& _i) {
145 if (pos_map_.find(_i) != pos_map_.end())
146 return pos_map_[_i];
147 else {
148
149 if (_i <= 0) {
150 return Point(0.0, 0.0, 0.0);
151 }
152
153 return position(_i - 1);
154 }
155 }
156 }; // end class FaceTraits
157
158
159 EdgeTraits
160 {
161
162 private:
163
164 typedef typename Refs::Point Point;
165 typedef std::map<state_t, Point> PositionHistory;
166
167 State state_;
168 PositionHistory pos_map_;
169
170 public:
171
172 typedef typename Refs::Scalar Scalar;
173
174 // Scalar weight_;
175
176 // state of edge
177 state_t state() const { return state_t(state_.state); }
178 void set_state(const state_t _s) { state_.state = _s; }
179 void inc_state() { ++state_.state; }
180
181 // edge not final if dividing face (Loop) or edge not flipped (SQRT(3))
182 final_t final() const { return final_t(state_.final); }
183 void set_final() { state_.final = true; }
184 void set_not_final() { state_.final = false; }
185
186 // position of edge, depending on generation _i.
187 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
188
189 const Point position(const int& _i) {
190
191 if (pos_map_.find(_i) != pos_map_.end())
192 return pos_map_[_i];
193 else
194 {
195 if (_i <= 0)
196 {
197 const Point zero_point(0.0, 0.0, 0.0);
198 return zero_point;
199 }
200
201 return position(_i - 1);
202 }
203 }
204 }; // end class EdgeTraits
205
206
207 VertexTraits
208 {
209
210 private:
211
212 typedef typename Refs::Point Point;
213 typedef std::map<state_t, Point> PositionHistory;
214
215 State state_;
216 PositionHistory pos_map_;
217
218 public:
219
220 // state of vertex
221 state_t state() const { return state_.state; }
222 void set_state(const state_t _s) { state_.state = _s; }
223 void inc_state() { ++state_.state; }
224
225
226 // usually not needed by loop or sqrt(3)
227 final_t final() const { return state_.final; }
228 void set_final() { state_.final = true; }
229 void set_not_final() { state_.final = false; }
230
231 // position of vertex, depending on generation _i. (not for display)
232 void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
233 const Point position(const int& _i) {
234
235 if (pos_map_.find(_i) != pos_map_.end())
236
237 return pos_map_[_i];
238
239 else {
240
241 if (_i <= 0) {
242
243 const Point zero_point(0.0, 0.0, 0.0);
244 return zero_point;
245 }
246
247 return position(_i - 1);
248 }
249 }
250 }; // end class VertexTraits
251 }; // end class CompositeTraits
252
253
254 // export items to namespace to maintain compatibility
255 typedef CompositeTraits::state_t state_t;
256 typedef CompositeTraits::final_t final_t;
257 typedef CompositeTraits::State State;
258
259 //=============================================================================
260 } // END_NS_ADAPTIVE
261 } // END_NS_SUBDIVIDER
262 } // END_NS_OPENMESH
263 //=============================================================================
264 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH defined
265 //=============================================================================
OpenMesh
Definition: MeshItems.hh:64
OpenMesh::Subdivider::Adaptive::CompositeTraits
Definition: CompositeTraits.hh:86
Traits.hh
OpenMesh::Subdivider::Adaptive::CompositeTraits::final_t
bool final_t
External representation for final flag.
Definition: CompositeTraits.hh:89
OpenMesh::Attributes::PrevHalfedge
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:89
OpenMesh::Subdivider::Adaptive::State
Definition: Traits.hh:87
OpenMesh::Attributes::Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
OpenMesh::DefaultTraits::Point
Vec3f Point
The default coordinate type is OpenMesh::Vec3f.
Definition: Traits.hh:129
OpenMesh::Subdivider::Adaptive::CompositeTraits::state_t
int state_t
External representation for intermediate state.
Definition: CompositeTraits.hh:88
OpenMesh::DefaultTraits
Definition: Traits.hh:126
OpenMesh::Subdivider::Adaptive::state_t
CompositeTraits::state_t state_t
Definition: CompositeTraits.hh:255
OpenMesh::Subdivider::Adaptive::CompositeTraits::State
Storage type for intermediate states and the final flag of a mesh entity.
Definition: CompositeTraits.hh:93