OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Traits.hh
Go to the documentation of this file.
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2014 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: 990 $ *
38  * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05 Feb 2014) $ *
39  * *
40 \*===========================================================================*/
41 
46 //=============================================================================
47 //
48 // CLASS Traits
49 //
50 //=============================================================================
51 
52 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_TRAITS_HH
53 #define OPENMESH_SUBDIVIDER_ADAPTIVE_TRAITS_HH
54 
55 
56 //== INCLUDES =================================================================
57 
58 #include <map>
59 #include <OpenMesh/Core/Mesh/Types/TriMesh_ArrayKernelT.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 
77 typedef int state_t;
78 typedef bool final_t;
79 
80 struct State
81 {
82  int state : 31;
83  unsigned final : 1;
84 };
85 
87 {
88 
89  // add face normals
90  FaceAttributes( OpenMesh::Attributes::Normal );
91 
92  // add vertex normals
93  VertexAttributes( OpenMesh::Attributes::Normal );
94 
95  // add previous halfedge handle
96  HalfedgeAttributes( OpenMesh::Attributes::PrevHalfedge );
97 
98  FaceTraits
99  {
100 
101  private:
102 
103  typedef typename Refs::Point Point;
104  typedef typename Refs::HalfedgeHandle HalfedgeHandle;
105  typedef std::map<state_t, Point> PositionHistory;
106 
107  State state_;
108  HalfedgeHandle red_halfedge_;
109 
110  PositionHistory pos_map_;
111 
112  public:
113 
114  // face state
115  state_t state() const { return state_t(state_.state); }
116  void set_state(const state_t _s) { state_.state = _s; }
117  void inc_state() { ++state_.state; }
118 
119  // face not final if divided (loop) or edge not flipped (sqrt(3))
120  final_t final() const { return final_t(state_.final); }
121  void set_final() { state_.final = true; }
122  void set_not_final() { state_.final = false; }
123 
124  // halfedge of dividing edge (red-green triangulation)
125  const HalfedgeHandle& red_halfedge() const { return red_halfedge_; }
126  void set_red_halfedge(const HalfedgeHandle& _h) { red_halfedge_ = _h; }
127 
128  // position of face, depending on generation _i.
129  void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
130  const Point position(const int& _i) {
131  if (pos_map_.find(_i) != pos_map_.end())
132  return pos_map_[_i];
133  else {
134 
135  if (_i <= 0) {
136  const Point zero_point(0.0, 0.0, 0.0);
137  return zero_point;
138  }
139 
140  return position(_i - 1);
141  }
142  }
143  }; // end class FaceTraits
144 
145 
146  EdgeTraits
147  {
148 
149  private:
150 
151  typedef typename Refs::Point Point;
152  typedef std::map<state_t, Point> PositionHistory;
153 
154  State state_;
155  PositionHistory pos_map_;
156 
157  public:
158 
159  typedef typename Refs::Scalar Scalar;
160 
161  // Scalar weight_;
162 
163  // state of edge
164  state_t state() const { return state_t(state_.state); }
165  void set_state(const state_t _s) { state_.state = _s; }
166  void inc_state() { ++state_.state; }
167 
168  // edge not final if dividing face (Loop) or edge not flipped (SQRT(3))
169  final_t final() const { return final_t(state_.final); }
170  void set_final() { state_.final = true; }
171  void set_not_final() { state_.final = false; }
172 
173  // position of edge, depending on generation _i.
174  void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
175  const Point position(const int& _i) {
176 
177  if (pos_map_.find(_i) != pos_map_.end())
178  {
179  return pos_map_[_i];
180  }
181  else
182  {
183  if (_i <= 0)
184  {
185  const Point zero_point(0.0, 0.0, 0.0);
186  return zero_point;
187  }
188 
189  return position(_i - 1);
190  }
191  }
192  }; // end class EdgeTraits
193 
194 
195  VertexTraits
196  {
197 
198  private:
199 
200  typedef typename Refs::Point Point;
201  typedef std::map<state_t, Point> PositionHistory;
202 
203  State state_;
204 
205  PositionHistory pos_map_;
206 
207  public:
208 
209  // state of vertex
210  state_t state() const { return state_.state; }
211  void set_state(const state_t _s) { state_.state = _s; }
212  void inc_state() { ++state_.state; }
213 
214 
215  // usually not needed by loop or sqrt(3)
216  final_t final() const { return state_.final; }
217  void set_final() { state_.final = true; }
218  void set_not_final() { state_.final = false; }
219 
220  // position of vertex, depending on generation _i. (not for display)
221  void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
222  const Point position(const int& _i) {
223 
224  if (pos_map_.find(_i) != pos_map_.end())
225 
226  return pos_map_[_i];
227 
228  else {
229 
230  if (_i <= 0) {
231 
232  const Point zero_point(0.0, 0.0, 0.0);
233  return zero_point;
234  }
235 
236  return position(_i - 1);
237  }
238  }
239  }; // end class VertexTraits
240 }; // end class Traits
241 
242 //=============================================================================
243 } // END_NS_ADAPTIVE
244 } // END_NS_SUBDIVIDER
245 } // END_NS_OPENMESH
246 //=============================================================================
247 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_TRAITS_HH defined
248 //=============================================================================
Vec3f Point
The default coordinate type is OpenMesh::Vec3f.
Definition: Traits.hh:122
Base class for all traits.
Definition: Traits.hh:119
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:56
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:82
CompositeTraits::state_t state_t
Adaptive Composite Subdivision framework.
Definition: CompositeTraits.hh:248
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80

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