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