bertram.h 20.8 KB
Newer Older
untereiner's avatar
untereiner committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#ifndef __3MR_BERTRAM_FILTER__
#define __3MR_BERTRAM_FILTER__

#include <cmath>
#include "Algo/Geometry/centroid.h"
#include "Algo/Modelisation/tetrahedralization.h"
#include "Algo/Multiresolution/filter.h"
32
#include "Topology/generic/traversor2_closed.h"
untereiner's avatar
untereiner committed
33
34
35
36
37
38
39

namespace CGoGN
{

namespace Algo
{

40
41
42
namespace Volume
{

untereiner's avatar
untereiner committed
43
44
45
46
47
48
49
50
51
namespace MR
{

namespace Primal
{

namespace Filters
{

52
53
54
55
56
57
58
59
/*******************************************************************************
 *							Without features preserving
 *******************************************************************************/

//
// Synthesis
//

untereiner's avatar
untereiner committed
60
61
//w-lift(a)
template <typename PFP>
62
class Ber02OddSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
63
64
65
66
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
67
	typename PFP::VEC3::DATA_TYPE m_a;
untereiner's avatar
untereiner committed
68
69

public:
70
	Ber02OddSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
untereiner's avatar
untereiner committed
71
72
73
74
75
76
77
	{}

	void operator() ()
	{
		TraversorW<typename PFP::MAP> travW(m_map) ;
		for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
		{
78
			typename PFP::VEC3 vc = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
79
			vc *= 8 * m_a * m_a * m_a;
untereiner's avatar
untereiner committed
80
81

			unsigned int count = 0;
82
			typename PFP::VEC3 ec(0.0);
untereiner's avatar
untereiner committed
83
84
85
86
			Traversor3WE<typename PFP::MAP> travWE(m_map, d);
			for (Dart dit = travWE.begin(); dit != travWE.end(); dit = travWE.next())
			{
				m_map.incCurrentLevel();
87
				ec += m_position[m_map.phi1(dit)];
untereiner's avatar
untereiner committed
88
89
90
91
				m_map.decCurrentLevel();
				++count;
			}
			ec /= count;
92
			ec *= 12 * m_a * m_a;
untereiner's avatar
untereiner committed
93
94

			count = 0;
95
			typename PFP::VEC3 fc(0.0);
untereiner's avatar
untereiner committed
96
97
98
99
			Traversor3WF<typename PFP::MAP> travWF(m_map, d);
			for (Dart dit = travWF.begin(); dit != travWF.end(); dit = travWF.next())
			{
				m_map.incCurrentLevel();
100
				fc += m_position[m_map.phi1(m_map.phi1(dit))];
untereiner's avatar
untereiner committed
101
102
103
104
				m_map.decCurrentLevel();
				++count;
			}
			fc /= count;
105
			fc *= 6 * m_a;
untereiner's avatar
untereiner committed
106
107
108

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
109
			m_position[midV] += vc + ec + fc;
untereiner's avatar
untereiner committed
110
111
112
113
114
115
			m_map.decCurrentLevel() ;
		}

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
116
117
			typename PFP::VEC3 vf(0.0);
			typename PFP::VEC3 ef(0.0);
untereiner's avatar
untereiner committed
118
119
120
121
122

			unsigned int count = 0;
			Traversor3FE<typename PFP::MAP> travFE(m_map, d);
			for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
			{
123
				vf += m_position[dit];
untereiner's avatar
untereiner committed
124
				m_map.incCurrentLevel();
125
				ef += m_position[m_map.phi1(dit)];
untereiner's avatar
untereiner committed
126
127
128
129
				m_map.decCurrentLevel();
				++count;
			}
			ef /= count;
130
131
132
133
			ef *= 4.0 * m_a;

			vf /= count;
			vf *= 4.0 * m_a * m_a;
untereiner's avatar
untereiner committed
134
135

			m_map.incCurrentLevel() ;
136
137
			Dart midF = m_map.phi1(m_map.phi1(d));
			m_position[midF] += vf + ef ;
untereiner's avatar
untereiner committed
138
139
140
141
142
143
			m_map.decCurrentLevel() ;
		}

		TraversorE<typename PFP::MAP> travE(m_map) ;
		for (Dart d = travE.begin(); d != travE.end(); d = travE.next())
		{
144
145
			typename PFP::VEC3 ve = (m_position[d] + m_position[m_map.phi1(d)]) * typename PFP::REAL(0.5);
			ve *= 2.0 * m_a;
untereiner's avatar
untereiner committed
146
147

			m_map.incCurrentLevel() ;
148
149
			Dart midV = m_map.phi1(d) ;
			m_position[midV] += ve;
untereiner's avatar
untereiner committed
150
151
152
153
154
155
156
			m_map.decCurrentLevel() ;
		}
	}
} ;

// s-lift(a)
template <typename PFP>
157
class Ber02EvenSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
158
159
160
161
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
162
	typename PFP::VEC3::DATA_TYPE m_a;
untereiner's avatar
untereiner committed
163
164

public:
165
	Ber02EvenSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
untereiner's avatar
untereiner committed
166
167
168
169
170
171
172
	{}

	void operator() ()
	{
		TraversorV<typename PFP::MAP> travV(m_map);
		for(Dart d = travV.begin() ; d != travV.end() ; d = travV.next())
		{
173
174
175
176
177
178
179
180
			if(m_map.isBoundaryVertex(d))
			{
				Dart db = m_map.findBoundaryFaceOfVertex(d);

				unsigned int count = 0;
				typename PFP::VEC3 ev(0.0);
				typename PFP::VEC3 fv(0.0);

181
182
//				Dart dit = db;
//				do
183
184
185
186
187
188
189
190
191
192
//				{
//					std::cout << "dit = " << dit << std::endl;
//					m_map.incCurrentLevel() ;
//
//					Dart midEdgeV = m_map.phi1(dit);
//					ev += m_position[midEdgeV];
//					fv += m_position[m_map.phi1(midEdgeV)];
//
//					m_map.decCurrentLevel() ;
//					++count;
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
//					dit = m_map.phi2(m_map.phi_1(dit));
//
//				}while(dit != db);

				//TODO Replace do--while with a Traversor2 on Boundary
				ClosedMap::Traversor2VF<typename PFP::MAP> travVF(m_map,db);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					m_map.incCurrentLevel() ;

					Dart midEdgeV = m_map.phi1(dit);
					ev += m_position[midEdgeV];
					fv += m_position[m_map.phi1(midEdgeV)];
207

208
209
210
					m_map.decCurrentLevel() ;
					++count;
				}
211
212
213
214
215
216
217
218
219
220
221

				fv /= count;
				fv *= 4 * m_a * m_a;

				ev /= count;
				ev *= 4 * m_a;

				m_position[d] += fv + ev;

			}
			else
untereiner's avatar
untereiner committed
222
223
			{
				unsigned int count = 0;
224
225

				typename PFP::VEC3 cv(0.0);
untereiner's avatar
untereiner committed
226
227
228
229
230
231
232
233
234
235
				Traversor3VW<typename PFP::MAP> travVW(m_map,d);
				for(Dart dit = travVW.begin(); dit != travVW.end() ; dit = travVW.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					cv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				cv /= count;
236
				cv *= 8 * m_a * m_a * m_a;
untereiner's avatar
untereiner committed
237

238
				typename PFP::VEC3 fv(0.0);
untereiner's avatar
untereiner committed
239
240
241
242
243
				count = 0;
				Traversor3VF<typename PFP::MAP> travVF(m_map,d);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					m_map.incCurrentLevel() ;
244
					Dart midV = m_map.phi1(m_map.phi1(dit));
untereiner's avatar
untereiner committed
245
246
247
248
249
					fv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				fv /= count;
250
				fv *= 12 * m_a * m_a;
untereiner's avatar
untereiner committed
251

252
				typename PFP::VEC3 ev(0.0);
untereiner's avatar
untereiner committed
253
254
255
256
257
				count = 0;
				Traversor3VE<typename PFP::MAP> travVE(m_map,d);
				for(Dart dit = travVE.begin(); dit != travVE.end() ; dit = travVE.next())
				{
					m_map.incCurrentLevel() ;
258
					Dart midV = m_map.phi1(dit);
untereiner's avatar
untereiner committed
259
260
261
262
263
					ev += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ev /= count;
264
				ev *= 6 * m_a;
untereiner's avatar
untereiner committed
265

266
				m_position[d] += cv + fv + ev;
untereiner's avatar
untereiner committed
267
268
269
270
271
272
273
274
275
			}
		}

		TraversorE<typename PFP::MAP> travE(m_map);
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
		{
			if(m_map.isBoundaryEdge(d))
			{
				Dart db = m_map.findBoundaryFaceOfEdge(d);
276
				typename PFP::VEC3 fe(0.0);
untereiner's avatar
untereiner committed
277

278
279
280
281
282
283
//				m_map.incCurrentLevel() ;
//				Dart midV = m_map.phi1(m_map.phi1(db));
//				fe += m_position[midV];
//				midV = m_map.phi_1(m_map.phi2(db));
//				fe += m_position[midV];
//				m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
284

285
286
287
288
289
290
291
292
293
294
295
				//TODO Replace do--while with a Traversor2 on Boundary
				unsigned int count = 0;
				ClosedMap::Traversor2EF<typename PFP::MAP> travEF(m_map, db);
				for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(m_map.phi1(dit));
					fe += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
296

297
				fe /= count;
298
				fe *= 2 * m_a;
untereiner's avatar
untereiner committed
299
300

				m_map.incCurrentLevel() ;
301
302
				Dart midE = m_map.phi1(db);
				m_position[midE] += fe;
untereiner's avatar
untereiner committed
303
304
305
306
307
				m_map.decCurrentLevel() ;
			}
			else
			{
				unsigned int count = 0;
308
309

				typename PFP::VEC3 ce(0.0);
untereiner's avatar
untereiner committed
310
311
312
313
314
315
316
317
318
319
				Traversor3EW<typename PFP::MAP> travEW(m_map, d);
				for(Dart dit = travEW.begin() ; dit != travEW.end() ; dit = travEW.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					ce += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ce /= count;
320
				ce *= 4 * m_a * m_a;
untereiner's avatar
untereiner committed
321

322
				typename PFP::VEC3 fe(0.0);
untereiner's avatar
untereiner committed
323
				count = 0;
324
325
				Traversor3EF<typename PFP::MAP> travEF(m_map, d);
				for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
untereiner's avatar
untereiner committed
326
327
				{
					m_map.incCurrentLevel() ;
328
					Dart midV = m_map.phi1(m_map.phi1(dit));
untereiner's avatar
untereiner committed
329
330
331
332
333
					fe += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				fe /= count;
334
				fe *= 4 * m_a;
untereiner's avatar
untereiner committed
335
336

				m_map.incCurrentLevel() ;
337
338
				Dart midE = m_map.phi1(d);
				m_position[midE] += ce + fe;
untereiner's avatar
untereiner committed
339
340
341
342
343
344
345
346
347
				m_map.decCurrentLevel() ;
			}
		}

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
			if(!m_map.isBoundaryFace(d))
			{
348
				unsigned int count = 0;
untereiner's avatar
untereiner committed
349

350
351
352
353
354
355
356
357
358
359
360
361
				typename PFP::VEC3 cf(0.0);
				Traversor3FW<typename PFP::MAP> travFW(m_map, d);
				for(Dart dit = travFW.begin() ; dit != travFW.end() ; dit = travFW.next())
				{
					m_map.incCurrentLevel();
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					cf += m_position[midV];
					m_map.decCurrentLevel();
					++count;
				}
				cf /= count;
				cf *= 2 * m_a;
untereiner's avatar
untereiner committed
362

363
364
365
366
367
				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(m_map.phi1(d));
				m_position[midF] += cf;
				m_map.decCurrentLevel() ;
			}
untereiner's avatar
untereiner committed
368
369
370
371
372
373
		}
	}
} ;

// s-scale(a)
template <typename PFP>
374
class Ber02ScaleSynthesisFilter : public Algo::MR::Filter
untereiner's avatar
untereiner committed
375
376
377
378
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
379
	typename PFP::VEC3::DATA_TYPE m_a;
untereiner's avatar
untereiner committed
380
381

public:
382
	Ber02ScaleSynthesisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
untereiner's avatar
untereiner committed
383
384
385
386
387
388
389
390
	{}

	void operator() ()
	{
		TraversorV<typename PFP::MAP> travV(m_map) ;
		for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
		{
			if(m_map.isBoundaryVertex(d))
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
				m_position[d] *= m_a * m_a;
			else
				m_position[d] *= m_a *m_a * m_a;
		}

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

			m_map.incCurrentLevel() ;
			Dart midE = m_map.phi1(d);
			if(m_map.isBoundaryVertex(midE))
				m_position[midE] *= m_a;
			else
				m_position[midE] *= m_a * m_a;
			m_map.decCurrentLevel() ;

		}

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
				m_map.incCurrentLevel() ;
				Dart midF = m_map.phi1(m_map.phi1(d));
				if(!m_map.isBoundaryVertex(midF))
					m_position[midF] *= m_a ;
				m_map.decCurrentLevel() ;

		}
	}
} ;

//
// Analysis
//

//w-lift(a)
template <typename PFP>
429
class Ber02OddAnalysisFilter : public Algo::MR::Filter
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
	Ber02OddAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
	{}

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

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

		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
			typename PFP::VEC3 vf(0.0);
			typename PFP::VEC3 ef(0.0);

			unsigned int count = 0;
			Traversor3FE<typename PFP::MAP> travFE(m_map, d);
			for (Dart dit = travFE.begin(); dit != travFE.end(); dit = travFE.next())
untereiner's avatar
untereiner committed
463
			{
464
465
466
467
468
				vf += m_position[dit];
				m_map.incCurrentLevel();
				ef += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
untereiner's avatar
untereiner committed
469
			}
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
			ef /= count;
			ef *= 4.0 * m_a;

			vf /= count;
			vf *= 4.0 * m_a * m_a;

			m_map.incCurrentLevel() ;
			Dart midF = m_map.phi1(m_map.phi1(d));
			m_position[midF] -= vf + ef ;
			m_map.decCurrentLevel() ;
		}

		TraversorW<typename PFP::MAP> travW(m_map) ;
		for (Dart d = travW.begin(); d != travW.end(); d = travW.next())
		{
485
			typename PFP::VEC3 vc = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, d, m_position);
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
			vc *= 8 * m_a * m_a * m_a;

			unsigned int count = 0;
			typename PFP::VEC3 ec(0.0);
			Traversor3WE<typename PFP::MAP> travWE(m_map, d);
			for (Dart dit = travWE.begin(); dit != travWE.end(); dit = travWE.next())
			{
				m_map.incCurrentLevel();
				ec += m_position[m_map.phi1(dit)];
				m_map.decCurrentLevel();
				++count;
			}
			ec /= count;
			ec *= 12 * m_a * m_a;

			count = 0;
			typename PFP::VEC3 fc(0.0);
			Traversor3WF<typename PFP::MAP> travWF(m_map, d);
			for (Dart dit = travWF.begin(); dit != travWF.end(); dit = travWF.next())
untereiner's avatar
untereiner committed
505
			{
506
507
508
509
				m_map.incCurrentLevel();
				fc += m_position[m_map.phi1(m_map.phi1(dit))];
				m_map.decCurrentLevel();
				++count;
untereiner's avatar
untereiner committed
510
			}
511
512
513
514
515
516
517
			fc /= count;
			fc *= 6 * m_a;

			m_map.incCurrentLevel() ;
			Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(d)));
			m_position[midV] -= vc + ec + fc;
			m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
518
		}
519
520
	}
} ;
untereiner's avatar
untereiner committed
521

522
523
// s-lift(a)
template <typename PFP>
524
class Ber02EvenAnalysisFilter : public Algo::MR::Filter
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
	Ber02EvenAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
	{}

	void operator() ()
	{
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
			if(!m_map.isBoundaryFace(d))
			{
				unsigned int count = 0;

				typename PFP::VEC3 cf(0.0);
				Traversor3FW<typename PFP::MAP> travFW(m_map, d);
				for(Dart dit = travFW.begin() ; dit != travFW.end() ; dit = travFW.next())
				{
					m_map.incCurrentLevel();
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					cf += m_position[midV];
					m_map.decCurrentLevel();
					++count;
				}
				cf /= count;
				cf *= 2 * m_a;

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

		TraversorE<typename PFP::MAP> travE(m_map);
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
untereiner's avatar
untereiner committed
566
567
568
569
		{
			if(m_map.isBoundaryEdge(d))
			{
				Dart db = m_map.findBoundaryFaceOfEdge(d);
570
571
				typename PFP::VEC3 fe(0.0);

572
573
574
575
576
577
//				m_map.incCurrentLevel() ;
//				Dart midV = m_map.phi1(m_map.phi1(db));
//				fe += m_position[midV];
//				midV = m_map.phi_1(m_map.phi2(db));
//				fe += m_position[midV];
//				m_map.decCurrentLevel() ;
578

579
580
581
582
583
584
585
586
587
588
589
				//TODO Replace do--while with a Traversor2 on Boundary
				unsigned int count = 0;
				ClosedMap::Traversor2EF<typename PFP::MAP> travEF(m_map, db);
				for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(m_map.phi1(dit));
					fe += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
590

591
				fe /= count;
592
593
				fe *= 2 * m_a;

untereiner's avatar
untereiner committed
594
				m_map.incCurrentLevel() ;
595
596
				Dart midE = m_map.phi1(db);
				m_position[midE] -= fe;
untereiner's avatar
untereiner committed
597
598
599
600
				m_map.decCurrentLevel() ;
			}
			else
			{
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
				unsigned int count = 0;

				typename PFP::VEC3 ce(0.0);
				Traversor3EW<typename PFP::MAP> travEW(m_map, d);
				for(Dart dit = travEW.begin() ; dit != travEW.end() ; dit = travEW.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					ce += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ce /= count;
				ce *= 4 * m_a * m_a;

				typename PFP::VEC3 fe(0.0);
				count = 0;
				Traversor3EF<typename PFP::MAP> travEF(m_map, d);
				for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(m_map.phi1(dit));
					fe += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				fe /= count;
				fe *= 4 * m_a;

untereiner's avatar
untereiner committed
630
				m_map.incCurrentLevel() ;
631
632
				Dart midE = m_map.phi1(d);
				m_position[midE] -= ce + fe;
untereiner's avatar
untereiner committed
633
634
635
636
				m_map.decCurrentLevel() ;
			}
		}

637
638
639
640
641
642
643
644
645
646
647
		TraversorV<typename PFP::MAP> travV(m_map);
		for(Dart d = travV.begin() ; d != travV.end() ; d = travV.next())
		{
			if(m_map.isBoundaryVertex(d))
			{
				Dart db = m_map.findBoundaryFaceOfVertex(d);

				unsigned int count = 0;
				typename PFP::VEC3 ev(0.0);
				typename PFP::VEC3 fv(0.0);

648
649
//				Dart dit = db;
//				do
650
651
652
653
654
655
656
657
658
659
//				{
//					std::cout << "dit = " << dit << std::endl;
//					m_map.incCurrentLevel() ;
//
//					Dart midEdgeV = m_map.phi1(dit);
//					ev += m_position[midEdgeV];
//					fv += m_position[m_map.phi1(midEdgeV)];
//
//					m_map.decCurrentLevel() ;
//					++count;
660
661
662
663
//
//					dit = m_map.phi2(m_map.phi_1(dit));
//
//				}while(dit != db);
664

665
666
667
668
669
670
671
672
673
674
675
676
677
				ClosedMap::Traversor2VF<typename PFP::MAP> travVF(m_map,db);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					std::cout << "dit = " << dit << std::endl;
					m_map.incCurrentLevel() ;

					Dart midEdgeV = m_map.phi1(dit);
					ev += m_position[midEdgeV];
					fv += m_position[m_map.phi1(midEdgeV)];

					m_map.decCurrentLevel() ;
					++count;
				}
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740

				fv /= count;
				fv *= 4 * m_a * m_a;

				ev /= count;
				ev *= 4 * m_a;

				m_position[d] -= fv + ev;

			}
			else
			{
				unsigned int count = 0;

				typename PFP::VEC3 cv(0.0);
				Traversor3VW<typename PFP::MAP> travVW(m_map,d);
				for(Dart dit = travVW.begin(); dit != travVW.end() ; dit = travVW.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi_1(m_map.phi2(m_map.phi1(dit)));
					cv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				cv /= count;
				cv *= 8 * m_a * m_a * m_a;

				typename PFP::VEC3 fv(0.0);
				count = 0;
				Traversor3VF<typename PFP::MAP> travVF(m_map,d);
				for(Dart dit = travVF.begin(); dit != travVF.end() ; dit = travVF.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(m_map.phi1(dit));
					fv += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				fv /= count;
				fv *= 12 * m_a * m_a;

				typename PFP::VEC3 ev(0.0);
				count = 0;
				Traversor3VE<typename PFP::MAP> travVE(m_map,d);
				for(Dart dit = travVE.begin(); dit != travVE.end() ; dit = travVE.next())
				{
					m_map.incCurrentLevel() ;
					Dart midV = m_map.phi1(dit);
					ev += m_position[midV];
					m_map.decCurrentLevel() ;
					++count;
				}
				ev /= count;
				ev *= 6 * m_a;

				m_position[d] -= cv + fv + ev;
			}
		}
	}
} ;

// s-scale(a)
template <typename PFP>
741
class Ber02ScaleAnalysisFilter : public Algo::MR::Filter
742
743
744
745
746
747
748
749
750
751
752
753
{
protected:
	typename PFP::MAP& m_map ;
	VertexAttribute<typename PFP::VEC3>& m_position ;
	typename PFP::VEC3::DATA_TYPE m_a;

public:
	Ber02ScaleAnalysisFilter(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3>& p, typename PFP::VEC3::DATA_TYPE a) : m_map(m), m_position(p), m_a(a)
	{}

	void operator() ()
	{
untereiner's avatar
untereiner committed
754
755
756
757
		TraversorF<typename PFP::MAP> travF(m_map) ;
		for (Dart d = travF.begin(); d != travF.end(); d = travF.next())
		{
				m_map.incCurrentLevel() ;
758
759
760
				Dart midF = m_map.phi1(m_map.phi1(d));
				if(!m_map.isBoundaryVertex(midF))
					m_position[midF] /= m_a ;
untereiner's avatar
untereiner committed
761
				m_map.decCurrentLevel() ;
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785

		}

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

			m_map.incCurrentLevel() ;
			Dart midE = m_map.phi1(d);
			if(m_map.isBoundaryVertex(midE))
				m_position[midE] /= m_a;
			else
				m_position[midE] /= m_a * m_a;
			m_map.decCurrentLevel() ;

		}

		TraversorV<typename PFP::MAP> travV(m_map) ;
		for (Dart d = travV.begin(); d != travV.end(); d = travV.next())
		{
			if(m_map.isBoundaryVertex(d))
				m_position[d] /= m_a * m_a;
			else
				m_position[d] /= m_a *m_a * m_a;
untereiner's avatar
untereiner committed
786
787
788
789
790
791
792
793
794
795
		}
	}
} ;

} // namespace Filters

} // namespace Primal

} // namespace MR

796
797
} // namespace Volume

untereiner's avatar
untereiner committed
798
799
800
801
802
803
} // namespace Algo

} // namespace CGoGN


#endif /* __3MR_FILTERS_PRIMAL__ */