Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

catmullClark.h 11.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

untereiner's avatar
untereiner committed
25
26
#ifndef __2MR_CC_FILTER__
#define __2MR_CC_FILTER__
27
28
29
30
31
32
33
34
35
36

#include <cmath>
#include "Algo/Multiresolution/filter.h"

namespace CGoGN
{

namespace Algo
{

37
38
39
namespace Surface
{

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace MR
{

namespace Primal
{

namespace Filters
{

/*
	@article {springerlink:10.1007/s00371-006-0074-7,
	   author = {Wang, Huawei and Qin, Kaihuai and Tang, Kai},
	   affiliation = {Hong Kong University of Science & Technology Department of Mechanical Engineering Hong Kong China},
	   title = {Efficient wavelet construction with Catmull–Clark subdivision},
	   journal = {The Visual Computer},
	   publisher = {Springer Berlin / Heidelberg},
	   issn = {0178-2789},
	   keyword = {Computer Science},
	   pages = {874-884},
	   volume = {22},
	   issue = {9},
	   url = {http://dx.doi.org/10.1007/s00371-006-0074-7},
	   note = {10.1007/s00371-006-0074-7},
	   year = {2006}
	}
*/

/*********************************************************************************
 *                      	     Lazy Wavelet
 *********************************************************************************/
template <typename PFP>
untereiner's avatar
untereiner committed
71
class CCInitEdgeSynthesisFilter : public Algo::MR::Filter
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	bool first;

public:
	CCInitEdgeSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p), first(true)
	{}

	void operator() ()
	{
		if(first)
		{
			TraversorE<typename PFP::MAP> trav(m_map) ;
			for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
			{
				m_map.incCurrentLevel() ;
				m_position[m_map.phi1(d)] = typename PFP::VEC3(0.0);
				m_map.decCurrentLevel() ;
			}
			first = false;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
99
class CCInitFaceSynthesisFilter : public Algo::MR::Filter
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	bool first;

public:
	CCInitFaceSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p), first(true)
	{}

	void operator() ()
	{
		if(first)
		{
			TraversorF<typename PFP::MAP> trav(m_map) ;
			for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
			{
				m_map.incCurrentLevel() ;
				m_position[m_map.phi2(m_map.phi1(d))] = typename PFP::VEC3(0.0); // ou phi2(d)
				m_map.decCurrentLevel() ;
			}
			first = false;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
127
class CCEdgeSynthesisFilter : public Algo::MR::Filter
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCEdgeSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorE<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			typename PFP::VEC3 ei =  (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
			m_position[midV] += ei ;
			m_map.decCurrentLevel() ;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
153
class CCFaceSynthesisFilter : public Algo::MR::Filter
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCFaceSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorF<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			float u = 1.0/2.0;

			typename PFP::VEC3 v(0.0);
			typename PFP::VEC3 e(0.0);
			unsigned int degree = 0;

			Dart dit = d;
			do
			{
				v += m_position[dit];

				m_map.incCurrentLevel() ;
				e += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel() ;

				++degree;

				dit = m_map.phi1(dit);
			}
			while(dit != d);

			v *= (1.0 - u) / degree;
			e *= u / degree;

			m_map.incCurrentLevel() ;
			m_position[m_map.phi2(m_map.phi1(d))] += v + e ;
			m_map.decCurrentLevel() ;
		}

	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
201
class CCVertexSynthesisFilter : public Algo::MR::Filter
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCVertexSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorV<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			typename PFP::VEC3 np1(0) ;
			typename PFP::VEC3 np2(0) ;
			unsigned int degree1 = 0 ;
			unsigned int degree2 = 0 ;
			Dart it = d ;
			do
			{
				++degree1 ;
				Dart dd = m_map.phi1(it) ;
				np1 += m_position[dd] ;
				Dart end = m_map.phi_1(it) ;
				dd = m_map.phi1(dd) ;
				do
				{
					++degree2 ;
					np2 += m_position[dd] ;
					dd = m_map.phi1(dd) ;
				} while(dd != end) ;
				it = m_map.alpha1(it) ;
			} while(it != d) ;

			float beta = 3.0 / (2.0 * degree1) ;
			float gamma = 1.0 / (4.0 * degree2) ;
			np1 *= beta / degree1 ;
			np2 *= gamma / degree2 ;

			typename PFP::VEC3 vp = m_position[d] ;
			vp *= 1.0 - beta - gamma ;

			m_map.incCurrentLevel() ;
			m_position[d] = np1 + np2 + vp ;
			m_map.decCurrentLevel() ;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
253
class CCScalingSynthesisFilter : public Algo::MR::Filter
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCScalingSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorE<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			m_map.incCurrentLevel() ;

			typename PFP::VEC3 ei = m_position[m_map.phi1(d)];

			typename PFP::VEC3 f = m_position[m_map.phi2(m_map.phi1(d))];
			f += m_position[m_map.phi_1(m_map.phi2(d))];
			f *= 1.0 / 2.0;

			ei += f;
			ei *= 1.0 / 2.0;

			m_position[m_map.phi1(d)] = ei;
			m_map.decCurrentLevel() ;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
286
class CCScalingAnalysisFilter : public Algo::MR::Filter
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCScalingAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorE<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			m_map.incCurrentLevel() ;

			typename PFP::VEC3 ei = m_position[m_map.phi1(d)];

			typename PFP::VEC3 f = m_position[m_map.phi2(m_map.phi1(d))];
			f += m_position[m_map.phi_1(m_map.phi2(d))];
			f *= 1.0 / 2.0;

			ei *= 2.0;
			ei -= f;

			m_position[m_map.phi1(d)] = ei;
			m_map.decCurrentLevel() ;
		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
319
class CCVertexAnalysisFilter : public Algo::MR::Filter
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCVertexAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorV<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			m_map.incCurrentLevel() ;
			typename PFP::VEC3 np1(0) ;
			typename PFP::VEC3 np2(0) ;
			unsigned int degree1 = 0 ;
			unsigned int degree2 = 0 ;
			Dart it = d ;
			do
			{
				++degree1 ;
				Dart dd = m_map.phi1(it) ;
				np1 += m_position[dd] ;
				Dart end = m_map.phi_1(it) ;
				dd = m_map.phi1(dd) ;
				do
				{
					++degree2 ;
					np2 += m_position[dd] ;
					dd = m_map.phi1(dd) ;
				} while(dd != end) ;
				it = m_map.alpha1(it) ;
			} while(it != d) ;

			float beta = 3.0 / (2.0 * degree1) ;
			float gamma = 1.0 / (4.0 * degree2) ;
			np1 *= beta / degree1 ;
			np2 *= gamma / degree2 ;

			typename PFP::VEC3 vd = m_position[d] ;

			m_map.decCurrentLevel() ;

			m_position[d] = vd - np1 - np2;
			m_position[d] /= 1.0 - beta - gamma ;

		}
	}
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
373
class CCFaceAnalysisFilter : public Algo::MR::Filter
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCFaceAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorF<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{

			float u = 1.0/2.0;

			typename PFP::VEC3 v(0.0);
			typename PFP::VEC3 e(0.0);
			unsigned int degree = 0;

			Dart dit = d;
			do
			{
				v += m_position[dit];

				m_map.incCurrentLevel() ;
				e += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel() ;

				++degree;

				dit = m_map.phi1(dit);
			}
			while(dit != d);

			v *= (1.0 - u) / degree;
			e *= u / degree;

			m_map.incCurrentLevel() ;
414
			m_position[m_map.phi2(m_map.phi1(d))] = m_position[m_map.phi2(m_map.phi1(d))] - v - e ;
415
416
			m_map.decCurrentLevel() ;
		}
untereiner's avatar
untereiner committed
417
	}
418
419
420
} ;

template <typename PFP>
untereiner's avatar
untereiner committed
421
class CCEdgeAnalysisFilter : public Algo::MR::Filter
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;

public:
	CCEdgeAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p) : m_map(m), m_position(p)
	{}

	void operator() ()
	{
		TraversorE<typename PFP::MAP> trav(m_map) ;
		for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
		{
			typename PFP::VEC3 ei =  (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi1(d) ;
			m_position[midV] -= ei ;
			m_map.decCurrentLevel() ;
		}
	}
} ;

} // namespace Filters

} // namespace Primal

} // namespace MR

452
453
} // namespace Surface

454
455
456
457
458
459
} // namespace Algo

} // namespace CGoGN

#endif