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

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .