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.

functors_Primal.h 17.5 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*******************************************************************************
* 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_FUNCTORS_PRIMAL__
#define __3MR_FUNCTORS_PRIMAL__

#include <cmath>
#include "Algo/Geometry/centroid.h"

namespace CGoGN
{

namespace Multiresolution
{

/*********************************************************************************
 *                           LOOP BASIC FUNCTIONS
 *********************************************************************************/
template <typename PFP>
untereiner's avatar
untereiner committed
41
typename PFP::VEC3 loopOddVertex(typename PFP::MAP& map, const AttributeHandler<typename PFP::VEC3, VERTEX>& position, Dart d1)
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{
	Dart d2 = map.phi2(d1) ;
	Dart d3 = map.phi_1(d1) ;
	Dart d4 = map.phi_1(d2) ;

	typename PFP::VEC3 p1 = position[d1] ;
	typename PFP::VEC3 p2 = position[d2] ;
	typename PFP::VEC3 p3 = position[d3] ;
	typename PFP::VEC3 p4 = position[d4] ;

	p1 *= 3.0 / 8.0 ;
	p2 *= 3.0 / 8.0 ;
	p3 *= 1.0 / 8.0 ;
	p4 *= 1.0 / 8.0 ;

	return p1 + p2 + p3 + p4 ;
}

template <typename PFP>
untereiner's avatar
untereiner committed
61
typename PFP::VEC3 loopEvenVertex(typename PFP::MAP& map, const AttributeHandler<typename PFP::VEC3, VERTEX>& position, Dart d)
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
	map.incCurrentLevel() ;

	typename PFP::VEC3 np(0) ;
	unsigned int degree = 0 ;
	Traversor2VVaE<typename PFP::MAP> trav(map, d) ;
	for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
	{
		++degree ;
		np += position[it] ;
	}

	map.decCurrentLevel() ;

	float mu = 3.0/8.0 + 1.0/4.0 * cos(2.0 * M_PI / degree) ;
	mu = (5.0/8.0 - (mu * mu)) / degree ;
	np *= 8.0/5.0 * mu ;

	return np ;
}

/*********************************************************************************
 *          SHW04 BASIC FUNCTIONS : tetrahedral/octahedral meshes
 *********************************************************************************/
template <typename PFP>
untereiner's avatar
untereiner committed
87
typename PFP::VEC3 SHW04Vertex(typename PFP::MAP& map, const AttributeHandler<typename PFP::VEC3, VERTEX>& position, Dart d)
88
89
90
91
92
93
94
95
96
97
98
99
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
{
	typename PFP::VEC3 res(0);

	if(map.isTetrahedron(d))
	{
		Dart d1 = map.phi1(d) ;
		Dart d2 = map.phi_1(d);
		Dart d3 = map.phi_1(map.phi2(d));

		typename PFP::VEC3 p = position[d];
		typename PFP::VEC3 p1 = position[d1] ;
		typename PFP::VEC3 p2 = position[d2] ;
		typename PFP::VEC3 p3 = position[d3] ;

		p *= -1;
		p1 *= 17.0 / 3.0;
		p2 *= 17.0 / 3.0;
		p3 *= 17.0 / 3.0;

		res += p + p1 + p2 + p3;
		res *= 1.0 / 16.0;
	}
	else
	{
		Dart d1 = map.phi1(d);
		Dart d2 = map.phi_1(d);
		Dart d3 = map.phi_1(map.phi2(d));
		Dart d4 = map.phi_1(map.phi2(d3));
		Dart d5 = map.phi_1(map.phi2(map.phi_1(d)));

		typename PFP::VEC3 p = position[d];
		typename PFP::VEC3 p1 = position[d1] ;
		typename PFP::VEC3 p2 = position[d2] ;
		typename PFP::VEC3 p3 = position[d3] ;
		typename PFP::VEC3 p4 = position[d4] ;
		typename PFP::VEC3 p5 = position[d5] ;

		p *= 3.0 / 4.0;
		p1 *= 1.0 / 6.0;
		p2 *= 1.0 / 6.0;
		p3 *= 1.0 / 6.0;
		p4 *= 7.0 / 12.0;
		p5 *= 1.0 / 6.0;

		res += p + p1 + p2 + p3 + p4 + p5;
		res *= 1.0 / 2.0;
	}

	return res;
}

/*********************************************************************************
 *          BSXW02 BASIC FUNCTIONS : polyhedral meshes
 *********************************************************************************/




untereiner's avatar
untereiner committed
146
/*******************************MJ96EdgeVertexFunctor**************************************************
147
148
149
150
151
152
153
154
155
156
 *                           FUNCTORS
 *********************************************************************************/

/* Linear Interpolation
 *********************************************************************************/
template <typename PFP>
class LerpVertexVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
157
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
158
159

public:
untereiner's avatar
untereiner committed
160
	LerpVertexVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
	{}

	bool operator() (Dart d)
	{
		m_map.decCurrentLevel() ;
		typename PFP::VEC3 p = m_position[d] ;
		m_map.incCurrentLevel() ;

		m_position[d] = p ;

		return false ;
	}
};

template <typename PFP>
class LerpEdgeVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
180
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
181
182

public:
untereiner's avatar
untereiner committed
183
	LerpEdgeVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
	{}

	bool operator() (Dart d)
	{
		Dart d1 = m_map.phi2(d);

		m_map.decCurrentLevel();
		Dart d2 = m_map.phi2(d1);
		typename PFP::VEC3 p = (m_position[d1] + m_position[d2]) * typename PFP::REAL(0.5);
		m_map.incCurrentLevel();

		m_position[d] = p;

		return false;
	}
} ;

template <typename PFP>
class LerpFaceVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
206
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
207
208

public:
untereiner's avatar
untereiner committed
209
	LerpFaceVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
	{}

	bool operator() (Dart d)
	{
		Dart df = m_map.phi1(m_map.phi1(d)) ;

		m_map.decCurrentLevel() ;
		typename PFP::VEC3 p =  Algo::Geometry::faceCentroid<PFP>(m_map, df, m_position);
		m_map.incCurrentLevel() ;

		m_position[d] = p ;

		return false ;
	}
} ;

template <typename PFP>
class LerpVolumeVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
231
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
232
233

public:
untereiner's avatar
untereiner committed
234
	LerpVolumeVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
	{}

	bool operator() (Dart d)
	{
		Dart df = m_map.phi_1(m_map.phi2(m_map.phi1(d))) ;

		m_map.decCurrentLevel() ;
		typename PFP::VEC3 p =  Algo::Geometry::volumeCentroid<PFP>(m_map, df, m_position);
		m_map.incCurrentLevel() ;

		m_position[d] = p ;

		return false ;
	}
} ;


/* SHW04 basic functions : tetrahedral/octahedral meshes
 *********************************************************************************/
template <typename PFP>
class SHW04VertexVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
259
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
260
261

public:
untereiner's avatar
untereiner committed
262
	SHW04VertexVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
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
319
320
321
	{}

	bool operator() (Dart d)
	{

		if(m_map.isBoundaryVertex(d))
		{
			Dart db = m_map.findBoundaryFaceOfVertex(d);

			m_map.decCurrentLevel() ;

			typename PFP::VEC3 np(0) ;
			unsigned int degree = 0 ;
			Traversor2VVaE<typename PFP::MAP> trav(m_map, db) ;
			for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
			{
				++degree ;
				np += m_position[it] ;
			}
			float tmp = 3.0 + 2.0 * cos(2.0 * M_PI / degree) ;
			float beta = (5.0 / 8.0) - ( tmp * tmp / 64.0 ) ;
			np *= beta / degree ;

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

			m_map.incCurrentLevel() ;

			m_position[d] = np + vp ;
		}
		else
		{
			typename PFP::VEC3 p = typename PFP::VEC3(0);
			unsigned int degree = 0;

			m_map.decCurrentLevel() ;

			Traversor3VW<typename PFP::MAP> travVW(m_map, d);
			for(Dart dit = travVW.begin() ; dit != travVW.end() ; dit = travVW.next())
			{
				p += SHW04Vertex<PFP>(m_map, m_position, dit);
				++degree;
			}

			p /= degree;

			m_map.incCurrentLevel() ;

			m_position[d] = p ;
		}
		return false ;
	}
} ;

template <typename PFP>
class SHW04EdgeVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
322
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
323
324

public:
untereiner's avatar
untereiner committed
325
	SHW04EdgeVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
	{}

	bool operator() (Dart d)
	{
		if(m_map.isBoundaryEdge(d))
		{
			Dart dd = m_map.phi2(d) ;
			m_map.decCurrentLevel() ;

			Dart d1 = m_map.findBoundaryFaceOfEdge(dd);

			Dart d2 = m_map.phi2(d1) ;
			Dart d3 = m_map.phi_1(d1) ;
			Dart d4 = m_map.phi_1(d2) ;

			typename PFP::VEC3 p1 = m_position[d1] ;
			typename PFP::VEC3 p2 = m_position[d2] ;
			typename PFP::VEC3 p3 = m_position[d3] ;
			typename PFP::VEC3 p4 = m_position[d4] ;

			p1 *= 3.0 / 8.0 ;
			p2 *= 3.0 / 8.0 ;
			p3 *= 1.0 / 8.0 ;
			p4 *= 1.0 / 8.0 ;

			m_map.incCurrentLevel() ;

			m_position[d] = p1 + p2 + p3 + p4 ;
		}
		else
		{
			Dart d1 = m_map.phi2(d);

			m_map.decCurrentLevel();
			Dart d2 = m_map.phi2(d1);
			typename PFP::VEC3 mid = (m_position[d1] + m_position[d2]) * typename PFP::REAL(0.5);


			typename PFP::VEC3 p = typename PFP::VEC3(0);
			unsigned int degree = 0;

			Traversor3VW<typename PFP::MAP> travVW(m_map, d);
			for(Dart dit = travVW.begin() ; dit != travVW.end() ; dit = travVW.next())
			{
				p += SHW04Vertex<PFP>(m_map, m_position, dit);
				++degree;
			}

			p /= degree;

			m_map.incCurrentLevel();

			m_position[d] = mid + p ;
		}

		return false ;
	}
} ;

template <typename PFP>
class SHW04VolumeVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
390
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position;
391
392

public:
untereiner's avatar
untereiner committed
393
	SHW04VolumeVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
	{}

	bool operator() (Dart d)
	{
		Dart df = m_map.phi_1(m_map.phi2(m_map.phi1(d))) ;

		m_map.decCurrentLevel() ;
		typename PFP::VEC3 p =  Algo::Geometry::volumeCentroid<PFP>(m_map, df, m_position);
		m_map.incCurrentLevel() ;

		m_position[d] = p ;

		return false;
	}
};


/* MJ96 basic functions : polyhedral meshes
 *********************************************************************************/
template <typename PFP>
class MJ96VertexVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
418
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
419
420

public:
untereiner's avatar
untereiner committed
421
	MJ96VertexVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
	{}

	bool operator() (Dart d)
	{
		if(m_map.isBoundaryVertex(d))
		{
			Dart db = m_map.findBoundaryFaceOfVertex(d);

			m_map.decCurrentLevel() ;

			typename PFP::VEC3 np1(0) ;
			typename PFP::VEC3 np2(0) ;
			unsigned int degree1 = 0 ;
			unsigned int degree2 = 0 ;
			Dart it = db ;
			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.phi2(m_map.phi_1(it)) ;
			} while(it != db) ;

			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[db] ;
			vp *= 1.0 - beta - gamma ;

			m_map.incCurrentLevel() ;

			m_position[d] = np1 + np2 + vp ;

		}
		else
		{
			typename PFP::VEC3 P = m_position[d];

			m_map.decCurrentLevel() ;
			//vertex points
			typename PFP::VEC3 Cavg = typename PFP::VEC3(0);
			unsigned int degree = 0;
			Traversor3VW<typename PFP::MAP> travVW(m_map, d);
			for(Dart dit = travVW.begin() ; dit != travVW.end() ; dit = travVW.next())
			{
				Cavg += Algo::Geometry::volumeCentroid<PFP>(m_map, dit, m_position);
				++degree;
			}
			Cavg /= degree;

			typename PFP::VEC3 Aavg = typename PFP::VEC3(0);
			degree = 0;
			Traversor3VF<typename PFP::MAP> travVF(m_map, d);
			for(Dart dit = travVF.begin() ; dit != travVF.end() ; dit = travVF.next())
			{
				Aavg += Algo::Geometry::faceCentroid<PFP>(m_map, dit, m_position);
				++degree;
			}
			Aavg /= degree;

			typename PFP::VEC3 Mavg = typename PFP::VEC3(0);
			degree = 0;
			Traversor3VE<typename PFP::MAP> travVE(m_map, d);
			for(Dart dit = travVE.begin() ; dit != travVE.end() ; dit = travVE.next())
			{
				Dart d2 = m_map.phi2(dit);
				Aavg += (m_position[dit] + m_position[d2]) * typename PFP::REAL(0.5);
				++degree;
			}
			Aavg /= degree;

			typename PFP::VEC3 vp = Cavg + Aavg * 3 + Mavg * 3 + P;
			vp /= 8;

			m_map.incCurrentLevel() ;

			m_position[d] = vp;
		}

		return false;
	}
};

template <typename PFP>
class MJ96EdgeVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
520
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
521
522

public:
untereiner's avatar
untereiner committed
523
	MJ96EdgeVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
524
525
526
527
528
529
530
531
532
533
	{}

	bool operator() (Dart d)
	{
		if(m_map.isBoundaryEdge(d))
		{
			Dart db = m_map.findBoundaryFaceOfEdge(d);

			Dart d1 = m_map.phi2(db) ;

untereiner's avatar
untereiner committed
534
			//m_map.decCurrentLevel() ;
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555

			Dart d2 = m_map.phi2(d1) ;
			Dart d3 = m_map.phi_1(d1) ;
			Dart d4 = m_map.phi_1(d2) ;
			Dart d5 = m_map.phi1(m_map.phi1(d1)) ;
			Dart d6 = m_map.phi1(m_map.phi1(d2)) ;

			typename PFP::VEC3 p1 = m_position[d1] ;
			typename PFP::VEC3 p2 = m_position[d2] ;
			typename PFP::VEC3 p3 = m_position[d3] ;
			typename PFP::VEC3 p4 = m_position[d4] ;
			typename PFP::VEC3 p5 = m_position[d5] ;
			typename PFP::VEC3 p6 = m_position[d6] ;

			p1 *= 3.0 / 8.0 ;
			p2 *= 3.0 / 8.0 ;
			p3 *= 1.0 / 16.0 ;
			p4 *= 1.0 / 16.0 ;
			p5 *= 1.0 / 16.0 ;
			p6 *= 1.0 / 16.0 ;

untereiner's avatar
untereiner committed
556
			//m_map.incCurrentLevel() ;
557
558
559
560
561
562
563

			m_position[d] = p1 + p2 + p3 + p4 + p5 + p6 ;
		}
		else
		{
			Dart d2 = m_map.phi2(d);

untereiner's avatar
untereiner committed
564
			//m_map.decCurrentLevel() ;
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
			//edge points
			typename PFP::VEC3 Cavg = typename PFP::VEC3(0);
			unsigned int degree = 0;
			Traversor3EW<typename PFP::MAP> travEW(m_map, d2);
			for(Dart dit = travEW.begin() ; dit != travEW.end() ; dit = travEW.next())
			{
				Cavg += Algo::Geometry::volumeCentroid<PFP>(m_map, dit, m_position);
				++degree;
			}
			Cavg /= degree;

			typename PFP::VEC3 Aavg = typename PFP::VEC3(0);
			degree = 0;
			Traversor3EF<typename PFP::MAP> travEF(m_map, d2);
			for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
			{
				Aavg += Algo::Geometry::faceCentroid<PFP>(m_map, dit, m_position);
				++degree;
			}
			Aavg /= degree;

			Dart d22 = m_map.phi2(d2);
			typename PFP::VEC3 M = (m_position[d2] + m_position[d22]) * typename PFP::REAL(0.5);

			typename PFP::VEC3 ep = Cavg + Aavg * 2 + M * (degree - 3);
			ep /= degree;

untereiner's avatar
untereiner committed
592
			//m_map.incCurrentLevel() ;
593
594
595
596
597
598
599
600
601
602
603
604
605

			m_position[d] = ep;
		}

		return false;
	}
};

template <typename PFP>
class MJ96FaceVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
606
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
607
608

public:
untereiner's avatar
untereiner committed
609
	MJ96FaceVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
610
611
612
613
614
615
616
617
618
619
	{}

	bool operator() (Dart d)
	{
		if(m_map.isBoundaryVertex(d))
		{
			Dart db = m_map.findBoundaryFaceOfVertex(d);

			Dart df = m_map.phi1(m_map.phi1(db)) ;

untereiner's avatar
untereiner committed
620
			//m_map.decCurrentLevel() ;
621
622
623
624
625
626
627
628
629
630
631

			typename PFP::VEC3 p(0) ;
			unsigned int degree = 0 ;
			Traversor2FV<typename PFP::MAP> trav(m_map, df) ;
			for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
			{
				++degree ;
				p += m_position[it] ;
			}
			p /= degree ;

untereiner's avatar
untereiner committed
632
			//m_map.incCurrentLevel() ;
633
634
635
636
637
638

			m_position[d] = p ;
		}
		else
		{
			Dart df = m_map.phi1(m_map.phi1(d)) ;
untereiner's avatar
untereiner committed
639
			//m_map.decCurrentLevel() ;
640
641
642
643
644
645
646
647
648
			//face points
			typename PFP::VEC3 C0 = Algo::Geometry::volumeCentroid<PFP>(m_map, df, m_position);
			typename PFP::VEC3 C1 = Algo::Geometry::volumeCentroid<PFP>(m_map, m_map.phi3(df), m_position);

			typename PFP::VEC3 A = Algo::Geometry::volumeCentroid<PFP>(m_map, m_map.phi3(df), m_position);

			typename PFP::VEC3 fp = C0 + A * 2 + C1;
			fp /= 4;

untereiner's avatar
untereiner committed
649
			//m_map.incCurrentLevel() ;
650
651
652
653
654
655
656
657
658
659
660
661
662
663

			m_position[d] = fp;
		}

		return false;
	}

};

template <typename PFP>
class MJ96VolumeVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
untereiner's avatar
untereiner committed
664
	AttributeHandler<typename PFP::VEC3, VERTEX>& m_position ;
665
666

public:
untereiner's avatar
untereiner committed
667
	MJ96VolumeVertexFunctor(typename PFP::MAP& m, AttributeHandler<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
	{}

	bool operator() (Dart d)
	{
		Dart df = m_map.phi_1(m_map.phi2(m_map.phi1(d))) ;

		m_map.decCurrentLevel() ;
		//cell points : these points are the average of the
		//vertices of the lattice that bound the cell
		typename PFP::VEC3 p = Algo::Geometry::volumeCentroid<PFP>(m_map,df,m_position);
		m_map.incCurrentLevel() ;

		m_position[d] = p;

		return false;
	}
};


} // namespace Multiresolution

} // namespace CGoGN


#endif /* __3MR_FUNCTORS_PRIMAL__ */