OpenMesh
Traits.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_TRAITS_HH
60 #define OPENMESH_SUBDIVIDER_ADAPTIVE_TRAITS_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 #include <map>
66 #include <OpenMesh/Core/Mesh/Types/TriMesh_ArrayKernelT.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 
84 typedef int state_t;
85 typedef bool final_t;
86 
87 struct State
88 {
89  int state : 31;
90  unsigned final : 1;
91 };
92 
94 {
95 
96  // add face normals
98 
99  // add vertex normals
101 
102  // add previous halfedge handle
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  const Point zero_point(0.0, 0.0, 0.0);
144  return zero_point;
145  }
146 
147  return position(_i - 1);
148  }
149  }
150  }; // end class FaceTraits
151 
152 
153  EdgeTraits
154  {
155 
156  private:
157 
158  typedef typename Refs::Point Point;
159  typedef std::map<state_t, Point> PositionHistory;
160 
161  State state_;
162  PositionHistory pos_map_;
163 
164  public:
165 
166  typedef typename Refs::Scalar Scalar;
167 
168  // Scalar weight_;
169 
170  // state of edge
171  state_t state() const { return state_t(state_.state); }
172  void set_state(const state_t _s) { state_.state = _s; }
173  void inc_state() { ++state_.state; }
174 
175  // edge not final if dividing face (Loop) or edge not flipped (SQRT(3))
176  final_t final() const { return final_t(state_.final); }
177  void set_final() { state_.final = true; }
178  void set_not_final() { state_.final = false; }
179 
180  // position of edge, depending on generation _i.
181  void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
182  const Point position(const int& _i) {
183 
184  if (pos_map_.find(_i) != pos_map_.end())
185  {
186  return pos_map_[_i];
187  }
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 
212  PositionHistory pos_map_;
213 
214  public:
215 
216  // state of vertex
217  state_t state() const { return state_.state; }
218  void set_state(const state_t _s) { state_.state = _s; }
219  void inc_state() { ++state_.state; }
220 
221 
222  // usually not needed by loop or sqrt(3)
223  final_t final() const { return state_.final; }
224  void set_final() { state_.final = true; }
225  void set_not_final() { state_.final = false; }
226 
227  // position of vertex, depending on generation _i. (not for display)
228  void set_position(const int& _i, const Point& _p) { pos_map_[_i] = _p; }
229  const Point position(const int& _i) {
230 
231  if (pos_map_.find(_i) != pos_map_.end())
232 
233  return pos_map_[_i];
234 
235  else {
236 
237  if (_i <= 0) {
238 
239  const Point zero_point(0.0, 0.0, 0.0);
240  return zero_point;
241  }
242 
243  return position(_i - 1);
244  }
245  }
246  }; // end class VertexTraits
247 }; // end class Traits
248 
249 //=============================================================================
250 } // END_NS_ADAPTIVE
251 } // END_NS_SUBDIVIDER
252 } // END_NS_OPENMESH
253 //=============================================================================
254 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_TRAITS_HH defined
255 //=============================================================================
#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
CompositeTraits::state_t state_t
Adaptive Composite Subdivision framework.
Definition: CompositeTraits.hh:255
#define VertexAttributes(_i)
Macro for defining the vertex attributes. See Specifying your MyMesh.
Definition: Traits.hh:84
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
Base class for all traits.
Definition: Traits.hh:126
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:89
#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 .