OpenMesh
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>
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 
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
103 
104  // add vertex normals
106 
107  // add previous halfedge handle
109 
110  // ---------------------------------------- items
111 
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 
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 
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
258 
259 //=============================================================================
260 } // END_NS_ADAPTIVE
261 } // END_NS_SUBDIVIDER
262 } // END_NS_OPENMESH
263 //=============================================================================
264 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITETRAITS_HH defined
265 //=============================================================================
#define HalfedgeAttributes(_i)
Macro for defining the halfedge attributes. See Specifying your MyMesh.
Definition: Traits.hh:87
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
#define VertexTraits
Macro for defining the vertex traits. See Specifying your MyMesh.
Definition: Traits.hh:96
#define EdgeTraits
Macro for defining the edge traits. See Specifying your MyMesh.
Definition: Traits.hh:104
#define FaceTraits
Macro for defining the face traits. See Specifying your MyMesh.
Definition: Traits.hh:108
#define VertexAttributes(_i)
Macro for defining the vertex attributes. See Specifying your MyMesh.
Definition: Traits.hh:84
bool final_t
External representation for final flag.
Definition: CompositeTraits.hh:89
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
Storage type for intermediate states and the final flag of a mesh entity.
Definition: CompositeTraits.hh:93
Base class for all traits.
Definition: Traits.hh:126
This file defines the default traits and some convenience macros.
int state_t
External representation for intermediate state.
Definition: CompositeTraits.hh:88
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:89
Adaptive Composite Subdivision framework.
Definition: CompositeTraits.hh:86
Vec3f Point
The default coordinate type is OpenMesh::Vec3f.
Definition: Traits.hh:129
#define FaceAttributes(_i)
Macro for defining the face attributes. See Specifying your MyMesh.
Definition: Traits.hh:93

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