OpenMesh
LoopSchemeMaskT.hh
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  * *
45  * $Revision$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 #ifndef LOOPSCHEMEMASKT_HH
51 #define LOOPSCHEMEMASKT_HH
52 
53 #include <cmath>
54 #include <vector>
55 
56 #include <OpenMesh/Core/System/config.h>
57 #include <OpenMesh/Core/Utils/SingletonT.hh>
58 
59 namespace OpenMesh
60 {
61 
70 template <class T_, unsigned int cache_size_ = 100>
72 {
73 public:
74  enum { cache_size = cache_size_ };
75  typedef T_ Scalar;
76 
77 protected:
78 
79  Scalar proj_weights_[cache_size];
80  Scalar limit_weights_[cache_size];
81  Scalar step_weights_[cache_size];
82  std::vector<Scalar> tang0_weights_[cache_size];
83  std::vector<Scalar> tang1_weights_[cache_size];
84 
85 protected:
86 
87  inline static Scalar compute_proj_weight(uint _valence)
88  {
89  //return pow(3.0 / 2.0 + cos(2.0 * M_PI / _valence), 2) / 2.0 - 1.0;
90  double denom = (3.0 + 2.0*cos(2.0*M_PI/(double)_valence));
91  double weight = (64.0*_valence)/(40.0 - denom*denom) - _valence;
92  return (Scalar) weight;
93  }
94 
95  inline static Scalar compute_limit_weight(uint _valence)
96  {
97  double proj_weight = compute_proj_weight(_valence);
98  proj_weight = proj_weight/(proj_weight + _valence);//normalize the proj_weight
99  double weight = (3.0/8.0)/(1.0 - proj_weight + (3.0/8.0));
100  return (Scalar)weight;
101  }
102 
103  inline static Scalar compute_step_weight(uint _valence)
104  {
105  double proj_weight = compute_proj_weight(_valence);
106  proj_weight = proj_weight/(proj_weight + _valence);//normalize the proj_weight
107  double weight = proj_weight - (3.0/8.0);
108  return (Scalar)weight;
109  }
110 
111  inline static Scalar compute_tang0_weight(uint _valence, uint _ver_id)
112  {
113  return (Scalar)cos(2.0*M_PI*(double)_ver_id/(double)_valence);
114  }
115 
116  inline static Scalar compute_tang1_weight(uint _valence, uint _ver_id)
117  {
118  return (Scalar)sin(2.0*M_PI*(double)_ver_id/(double)_valence);
119  }
120 
121  void cache_weights()
122  {
123  proj_weights_[0] = 1;
124  for (uint k = 1; k < cache_size; ++k)
125  {
126  proj_weights_[k] = compute_proj_weight(k);
127  limit_weights_[k] = compute_limit_weight(k);
128  step_weights_[k] = compute_step_weight(k);
129  tang0_weights_[k].resize(k);
130  tang1_weights_[k].resize(k);
131  for (uint i = 0; i < k; ++i)
132  {
133  tang0_weights_[k][i] = compute_tang0_weight(k,i);
134  tang1_weights_[k][i] = compute_tang1_weight(k,i);
135  }
136  }
137  }
138 
139 public:
140 
142  {
143  cache_weights();
144  }
145 
146  inline Scalar proj_weight(uint _valence) const
147  {
148  assert(_valence < cache_size );
149  return proj_weights_[_valence];
150  }
151 
152  inline Scalar limit_weight(uint _valence) const
153  {
154  assert(_valence < cache_size );
155  return limit_weights_[_valence];
156  }
157 
158  inline Scalar step_weight(uint _valence, uint _step) const
159  {
160  assert(_valence < cache_size);
161  return pow(step_weights_[_valence], (int)_step);//can be precomputed
162  }
163 
164  inline Scalar tang0_weight(uint _valence, uint _ver_id) const
165  {
166  assert(_valence < cache_size );
167  assert(_ver_id < _valence);
168  return tang0_weights_[_valence][_ver_id];
169  }
170 
171  inline Scalar tang1_weight(uint _valence, uint _ver_id) const
172  {
173  assert(_valence < cache_size );
174  assert(_ver_id < _valence);
175  return tang1_weights_[_valence][_ver_id];
176  }
177 
178  void dump(uint _max_valency = cache_size - 1) const
179  {
180  assert(_max_valency <= cache_size - 1);
181  //CConsole::printf("(k : pw_k, lw_k): ");
182  for (uint i = 0; i <= _max_valency; ++i)
183  {
184  //CConsole::stream() << "(" << i << " : " << proj_weight(i) << ", " << limit_weight(i) << ", " << step_weight(i,1) << "), ";
185  }
186  //CConsole::printf("\n");
187  }
188 };
189 
192 
193 }//namespace OpenMesh
194 
195 #endif//LOOPSCHEMEMASKT_HH
196 
implements cache for the weights of the original Loop scheme supported:
Definition: LoopSchemeMaskT.hh:71
A simple singleton template.
Definition: SingletonT.hh:84
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64

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