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