OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
LoopSchemeMaskT.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5  * www.openmesh.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenMesh. *
9  * *
10  * OpenMesh is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenMesh is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenMesh. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 736 $ *
38  * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 2012) $ *
39  * *
40 \*===========================================================================*/
41 
42 #ifndef LOOPSCHEMEMASKT_HH
43 #define LOOPSCHEMEMASKT_HH
44 
45 #include <math.h>
46 #include <vector>
47 
48 #include <OpenMesh/Core/System/config.h>
49 #include <OpenMesh/Core/Utils/SingletonT.hh>
50 
51 namespace OpenMesh
52 {
53 
62 template <class T_, unsigned int cache_size_ = 100>
64 {
65 public:
66  enum { cache_size = cache_size_ };
67  typedef T_ Scalar;
68 
69 protected:
70 
71  Scalar proj_weights_[cache_size];
72  Scalar limit_weights_[cache_size];
73  Scalar step_weights_[cache_size];
74  std::vector<Scalar> tang0_weights_[cache_size];
75  std::vector<Scalar> tang1_weights_[cache_size];
76 
77 protected:
78 
79  inline static Scalar compute_proj_weight(uint _valence)
80  {
81  //return pow(3.0 / 2.0 + cos(2.0 * M_PI / _valence), 2) / 2.0 - 1.0;
82  double denom = (3.0 + 2.0*cos(2.0*M_PI/(double)_valence));
83  double weight = (64.0*_valence)/(40.0 - denom*denom) - _valence;
84  return (Scalar) weight;
85  }
86 
87  inline static Scalar compute_limit_weight(uint _valence)
88  {
89  double proj_weight = compute_proj_weight(_valence);
90  proj_weight = proj_weight/(proj_weight + _valence);//normalize the proj_weight
91  double weight = (3.0/8.0)/(1.0 - proj_weight + (3.0/8.0));
92  return (Scalar)weight;
93  }
94 
95  inline static Scalar compute_step_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 = proj_weight - (3.0/8.0);
100  return (Scalar)weight;
101  }
102 
103  inline static Scalar compute_tang0_weight(uint _valence, uint _ver_id)
104  {
105  return (Scalar)cos(2.0*M_PI*(double)_ver_id/(double)_valence);
106  }
107 
108  inline static Scalar compute_tang1_weight(uint _valence, uint _ver_id)
109  {
110  return (Scalar)sin(2.0*M_PI*(double)_ver_id/(double)_valence);
111  }
112 
113  void cache_weights()
114  {
115  proj_weights_[0] = 1;
116  for (uint k = 1; k < cache_size; ++k)
117  {
118  proj_weights_[k] = compute_proj_weight(k);
119  limit_weights_[k] = compute_limit_weight(k);
120  step_weights_[k] = compute_step_weight(k);
121  tang0_weights_[k].resize(k);
122  tang1_weights_[k].resize(k);
123  for (uint i = 0; i < k; ++i)
124  {
125  tang0_weights_[k][i] = compute_tang0_weight(k,i);
126  tang1_weights_[k][i] = compute_tang1_weight(k,i);
127  }
128  }
129  }
130 
131 public:
132 
134  {
135  cache_weights();
136  }
137 
138  inline Scalar proj_weight(uint _valence) const
139  {
140  assert(_valence < cache_size );
141  return proj_weights_[_valence];
142  }
143 
144  inline Scalar limit_weight(uint _valence) const
145  {
146  assert(_valence < cache_size );
147  return limit_weights_[_valence];
148  }
149 
150  inline Scalar step_weight(uint _valence, uint _step) const
151  {
152  assert(_valence < cache_size);
153  return pow(step_weights_[_valence], (int)_step);//can be precomputed
154  }
155 
156  inline Scalar tang0_weight(uint _valence, uint _ver_id) const
157  {
158  assert(_valence < cache_size );
159  assert(_ver_id < _valence);
160  return tang0_weights_[_valence][_ver_id];
161  }
162 
163  inline Scalar tang1_weight(uint _valence, uint _ver_id) const
164  {
165  assert(_valence < cache_size );
166  assert(_ver_id < _valence);
167  return tang1_weights_[_valence][_ver_id];
168  }
169 
170  void dump(uint _max_valency = cache_size - 1) const
171  {
172  assert(_max_valency <= cache_size - 1);
173  //CConsole::printf("(k : pw_k, lw_k): ");
174  for (uint i = 0; i <= _max_valency; ++i)
175  {
176  //CConsole::stream() << "(" << i << " : " << proj_weight(i) << ", " << limit_weight(i) << ", " << step_weight(i,1) << "), ";
177  }
178  //CConsole::printf("\n");
179  }
180 };
181 
184 
185 }//namespace OpenMesh
186 
187 #endif//LOOPSCHEMEMASKT_HH
188 

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