map2MR_PrimalAdapt.cpp 14.8 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25
#include "Topology/map/map2MR/map2MR_PrimalAdapt.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
26
27
28
29

namespace CGoGN
{

Pierre Kraemer's avatar
Pierre Kraemer committed
30
Map2MR_PrimalAdapt::Map2MR_PrimalAdapt() :
31
32
33
34
	shareVertexEmbeddings(true),
	vertexVertexFunctor(NULL),
	edgeVertexFunctor(NULL),
	faceVertexFunctor(NULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
35
36
37
38
39
40
41
42
{
	initMR() ;
}

/***************************************************
 *               CELLS INFORMATION                 *
 ***************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
43
unsigned int Map2MR_PrimalAdapt::edgeLevel(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
44
{
Pierre Kraemer's avatar
Pierre Kraemer committed
45
	assert(getDartLevel(d) <= getCurrentLevel() || !"edgeLevel : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
48
49
50
51

	unsigned int ld = getDartLevel(d) ;
	unsigned int ldd = getDartLevel(phi2(d)) ;	// the level of an edge is the maximum of the
	return ld > ldd ? ld : ldd ;				// insertion levels of its two darts
}

Pierre Kraemer's avatar
Pierre Kraemer committed
52
unsigned int Map2MR_PrimalAdapt::faceLevel(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
53
{
Pierre Kraemer's avatar
Pierre Kraemer committed
54
	assert(getDartLevel(d) <= getCurrentLevel() || !"faceLevel : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
55
56
57
58
59
60
61
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
87
88
89
90

	if(getCurrentLevel() == 0)
		return 0 ;

	Dart it = d ;
	unsigned int min1 = getDartLevel(it) ;		// the level of a face is the second minimum of the
	it = phi1(it) ;
	unsigned int min2 = getDartLevel(it) ;		// insertion levels of its darts

	if(min2 < min1)
	{
		unsigned int tmp = min1 ;
		min1 = min2 ;
		min2 = tmp ;
	}

	it = phi1(it) ;
	while(it != d)
	{
		unsigned int dl = getDartLevel(it) ;
		if(dl < min2)
		{
			if(dl < min1)
			{
				min2 = min1 ;
				min1 = dl ;
			}
			else
				min2 = dl ;
		}
		it = phi1(it) ;
	}

	return min2 ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
91
Dart Map2MR_PrimalAdapt::faceOrigin(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
92
{
Pierre Kraemer's avatar
Pierre Kraemer committed
93
	assert(getDartLevel(d) <= getCurrentLevel() || !"faceOrigin : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107

	pushLevel() ;
	Dart p = d ;
	unsigned int pLevel = getDartLevel(p) ;
	while(pLevel > 0)
	{
		p = faceOldestDart(p) ;
		pLevel = getDartLevel(p) ;
		setCurrentLevel(pLevel) ;
	}
	popLevel() ;
	return p ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
108
Dart Map2MR_PrimalAdapt::faceOldestDart(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
109
{
Pierre Kraemer's avatar
Pierre Kraemer committed
110
	assert(getDartLevel(d) <= getCurrentLevel() || !"faceOldestDart : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

	Dart it = d ;
	Dart oldest = it ;
	unsigned int l_old = getDartLevel(oldest) ;
	do
	{
		unsigned int l = getDartLevel(it) ;
		if(l == 0)
			return it ;
		if(l < l_old)
		{
			oldest = it ;
			l_old = l ;
		}
		it = phi1(it) ;
	} while(it != d) ;
	return oldest ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
130
bool Map2MR_PrimalAdapt::edgeIsSubdivided(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
131
{
Pierre Kraemer's avatar
Pierre Kraemer committed
132
	assert(getDartLevel(d) <= getCurrentLevel() || !"edgeIsSubdivided : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
133
134
135
136
137

	if(getCurrentLevel() == getMaxLevel())
		return false ;

	Dart d2 = phi2(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
138
	incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
139
	Dart d2_l = phi2(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
140
	decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
141
142
143
144
145
146
	if(d2 != d2_l)
		return true ;
	else
		return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
147
bool Map2MR_PrimalAdapt::edgeCanBeCoarsened(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
148
{
Pierre Kraemer's avatar
Pierre Kraemer committed
149
	assert(getDartLevel(d) <= getCurrentLevel() || !"edgeCanBeCoarsened : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
150
151
152
153
154
155
156

	if(edgeIsSubdivided(d))
	{
		bool subdOnce = true ;
		bool degree2 = false ;

		Dart d2 = phi2(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
157
		incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
158
159
160
161
162
163
		if(vertexDegree(phi1(d)) == 2)
		{
			degree2 = true ;
			if(edgeIsSubdivided(d) || edgeIsSubdivided(d2))
				subdOnce = false ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
164
		decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
165
166
167
168
169
170
171

		return degree2 && subdOnce ;
	}

	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
172
bool Map2MR_PrimalAdapt::faceIsSubdivided(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
173
{
Pierre Kraemer's avatar
Pierre Kraemer committed
174
	assert(getDartLevel(d) <= getCurrentLevel() || !"faceIsSubdivided : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
175
176
177
178
179
180
181
182
183

	if(getCurrentLevel() == getMaxLevel())
		return false ;

	unsigned int fLevel = faceLevel(d) ;
	if(fLevel < getCurrentLevel())	// a face whose level in the current level map is lower than
		return false ;				// the current level can not be subdivided to higher levels

	bool subd = false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
184
	incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
185
186
	if(getDartLevel(phi1(phi1(d))) == getCurrentLevel())
		subd = true ;
Pierre Kraemer's avatar
Pierre Kraemer committed
187
	decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
188
189
190
	return subd ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
191
bool Map2MR_PrimalAdapt::faceIsSubdividedOnce(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
192
{
Pierre Kraemer's avatar
Pierre Kraemer committed
193
	assert(getDartLevel(d) <= getCurrentLevel() || !"faceIsSubdividedOnce : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
194
195
196
197
198
199
200
201
202
203
204
205

	if(getCurrentLevel() == getMaxLevel())
		return false ;

	unsigned int fLevel = faceLevel(d) ;
	if(fLevel < getCurrentLevel())	// a face whose level in the current level map is lower than
		return false ;				// the current level can not be subdivided to higher levels

	unsigned int degree = 0 ;
	bool subd = false ;
	bool subdOnce = true ;

Pierre Kraemer's avatar
Pierre Kraemer committed
206
	incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
207
208
	if(getDartLevel(phi1(phi1(d))) == getCurrentLevel())
		subd = true ;
Pierre Kraemer's avatar
Pierre Kraemer committed
209
	decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
210
211
212

	if(subd)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
213
		incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
214
215
216

		if(getCurrentLevel() == getMaxLevel())
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
217
			decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
218
219
220
221
222
223
			return true ;
		}

		Dart fit = d ;
		do
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
224
			incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
225
226
			if(getDartLevel(phi1(phi1(fit))) == getCurrentLevel())
				subdOnce = false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
227
			decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
228
229
230
231
232
233
234
			++degree ;
			fit = phi1(fit) ;
		} while(subdOnce && fit != d) ;

		if(degree == 3 && subdOnce)
		{
			Dart cf = phi2(phi1(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
235
			incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
236
237
			if(getDartLevel(phi1(phi1(cf))) == getCurrentLevel())
				subdOnce = false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
238
			decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
239
240
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
241
		decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
242
243
244
245
246
247
248

		return subdOnce ;
	}

	return false ;
}

249
/***************************************************
250
 *               SUBDIVISION                       *
251
252
 ***************************************************/

253
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
void Map2MR_PrimalAdapt::addNewLevel(bool embedNewVertices)
{
	pushLevel() ;

	addLevel() ;
	setCurrentLevel(getMaxLevel()) ;

//	for(unsigned int i = m_mrattribs.begin(); i != m_mrattribs.end(); m_mrattribs.next(i))
//	{
//		unsigned int newindex = copyDartLine((*m_mrDarts[m_mrCurrentLevel])[i]) ;	// duplicate all darts
//		(*m_mrDarts[m_mrCurrentLevel])[i] = newindex ;								// on the new max level
//		if(!shareVertexEmbeddings)
//			(*m_embeddings[VERTEX])[newindex] = EMBNULL ;	// set vertex embedding to EMBNULL if no sharing
//	}

	popLevel() ;
}

void Map2MR_PrimalAdapt::propagateDartRelation(Dart d, AttributeMultiVector<Dart>* rel)
{
	Dart dd = (*rel)[dartIndex(d)] ;
	pushLevel() ;
	for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i)
	{
		setCurrentLevel(i) ;
		(*rel)[dartIndex(d)] = dd ;
	}
	popLevel() ;
}

void Map2MR_PrimalAdapt::propagateDartEmbedding(Dart d, unsigned int orbit)
{
	unsigned int emb = getEmbedding(orbit, d) ;
	pushLevel() ;
	for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i)
	{
		setCurrentLevel(i) ;
		setDartEmbedding(orbit, d, emb) ;
	}
	popLevel() ;
}

void Map2MR_PrimalAdapt::propagateOrbitEmbedding(Dart d, unsigned int orbit)
{
	unsigned int emb = getEmbedding(orbit, d) ;
	pushLevel() ;
	for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i)
	{
		setCurrentLevel(i) ;
		embedOrbit(orbit, d, emb) ;
	}
	popLevel() ;
}

//Dart Map2MR_PrimalAdapt::cutEdge(Dart d)
308
//{
309
//	Dart dd = phi2(d) ;
310
//
311
312
//	Dart d1 = newDart() ;
//	Dart dd1 = newDart() ;
313
//
314
315
//	pushLevel() ;
//	for(unsigned int i = getCurrentLevel(); i <= getMaxLevel(); ++i)
316
//	{
317
318
319
320
321
322
323
//		setCurrentLevel(i) ;
//
//		phi2unsew(d) ;
//
//		phi1sew(d, d1) ;
//		if (isBoundaryMarked(d))
//			boundaryMark(d1) ;
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
//		phi1sew(dd, dd1) ;
//		if (isBoundaryMarked(dd))
//			boundaryMark(dd1) ;
//
//		phi2sew(d, dd1) ;
//		phi2sew(dd, d1) ;
//	}
//	popLevel() ;
//
//	return d1 ;
//}

Dart Map2MR_PrimalAdapt::cutEdge(Dart d)
{
	Dart dd = phi2(d) ;
	Dart d1 = EmbeddedMap2::cutEdge(d) ;
	Dart dd1 = phi1(dd) ;
	Dart d11 = phi1(d1) ;
	Dart dd11 = phi1(dd1) ;

	propagateDartRelation(d, m_phi1) ;
	propagateDartRelation(d, m_phi2) ;
	propagateDartRelation(dd, m_phi1) ;
	propagateDartRelation(dd, m_phi2) ;
	propagateDartRelation(d1, m_phi1) ;
	propagateDartRelation(d1, m_phi_1) ;
	propagateDartRelation(d1, m_phi2) ;
	propagateDartRelation(dd1, m_phi1) ;
	propagateDartRelation(dd1, m_phi_1) ;
	propagateDartRelation(dd1, m_phi2) ;
	propagateDartRelation(d11, m_phi_1) ;
	propagateDartRelation(dd11, m_phi_1) ;

	return d1 ;
}

//void Map2MR_PrimalAdapt::splitFace(Dart d, Dart e)
362
//{
363
364
//	Dart dprev = phi_1(d) ;
//	Dart eprev = phi_1(e) ;
365
//
366
367
//	Dart dd = newDart() ;
//	Dart ee = newDart() ;
368
//
369
370
//	pushLevel() ;
//	for(unsigned int i = getCurrentLevel(); i <= getMaxLevel(); ++i)
371
//	{
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
//		setCurrentLevel(i) ;
//
//		phi1sew(dprev, dd) ;
//		if (isBoundaryMarked(dprev))
//			boundaryMark(dd);
//
//		phi1sew(eprev, ee) ;
//		if (isBoundaryMarked(eprev))
//			boundaryMark(ee);
//
//		phi1sew(dprev, eprev) ;
//
//		phi2sew(dd, ee) ;
//
//		copyDartEmbedding(VERTEX, ee, d) ;
//		copyDartEmbedding(VERTEX, dd, e) ;
//	}
//	popLevel() ;
390
391
//}

392
void Map2MR_PrimalAdapt::splitFace(Dart d, Dart e)
393
{
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
	Dart dprev = phi_1(d) ;
	Dart eprev = phi_1(e) ;
	EmbeddedMap2::splitFace(d, e) ;
	Dart dd = phi1(dprev) ;
	Dart ee = phi1(eprev) ;

	propagateDartRelation(d, m_phi_1) ;
	propagateDartRelation(e, m_phi_1) ;
	propagateDartRelation(dd, m_phi1) ;
	propagateDartRelation(dd, m_phi_1) ;
	propagateDartRelation(dd, m_phi2) ;
	propagateDartRelation(ee, m_phi1) ;
	propagateDartRelation(ee, m_phi_1) ;
	propagateDartRelation(ee, m_phi2) ;
	propagateDartRelation(dprev, m_phi1) ;
	propagateDartRelation(eprev, m_phi1) ;

	propagateDartEmbedding(dd, VERTEX) ;
	propagateDartEmbedding(ee, VERTEX) ;
413
414
}

Pierre Kraemer's avatar
Pierre Kraemer committed
415
void Map2MR_PrimalAdapt::subdivideEdge(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
416
{
Pierre Kraemer's avatar
Pierre Kraemer committed
417
	assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideEdge : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
418
419
	assert(!edgeIsSubdivided(d) || !"Trying to subdivide an already subdivided edge") ;

420
	assert(getCurrentLevel() == edgeLevel(d) || !"Trying to subdivide an edge on a bad current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
421

422
423
	incCurrentLevel() ;

424
425
	Dart d1 = cutEdge(d) ;
	Dart dd1 = phi2(d) ;
426

427
428
429
	(*edgeVertexFunctor)(d1) ;
	propagateDartEmbedding(d1, VERTEX) ;
	propagateDartEmbedding(dd1, VERTEX) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
430

431
432
433
	decCurrentLevel() ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
434
void Map2MR_PrimalAdapt::coarsenEdge(Dart d)
435
{
Pierre Kraemer's avatar
Pierre Kraemer committed
436
	assert(getDartLevel(d) <= getCurrentLevel() || !"coarsenEdge : called with a dart inserted after current level") ;
437
438
439
440
441
	assert(edgeCanBeCoarsened(d) || !"Trying to coarsen an edge that can not be coarsened") ;

	incCurrentLevel() ;
	uncutEdge(d) ;
	decCurrentLevel() ;
442

443
444
445
	unsigned int maxL = getMaxLevel() ;
	if(getCurrentLevel() == maxL - 1 && getNbInsertedDarts(maxL) == 0)
		removeLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
446
447
}

Pierre Kraemer's avatar
Pierre Kraemer committed
448
unsigned int Map2MR_PrimalAdapt::subdivideFace(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
449
{
Pierre Kraemer's avatar
Pierre Kraemer committed
450
	assert(getDartLevel(d) <= getCurrentLevel() || !"subdivideFace : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
451
452
453
454
455
456
457
458
	assert(!faceIsSubdivided(d) || !"Trying to subdivide an already subdivided face") ;

	unsigned int fLevel = faceLevel(d) ;
	Dart old = faceOldestDart(d) ;

	pushLevel() ;
	setCurrentLevel(fLevel) ;		// go to the level of the face to subdivide its edges

Pierre Kraemer's avatar
Pierre Kraemer committed
459
460
461
462
	if(getCurrentLevel() == getMaxLevel())
		addNewLevel() ;

	unsigned int degree = 0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
463
464
465
	Dart it = old ;
	do
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
466
		++degree ;						// compute the degree of the face
467
468
469
//		Dart nf = phi2(it) ;
//		if(faceLevel(nf) == fLevel - 1)	// check if neighboring faces have to be subdivided first
//			subdivideFace(nf) ;
470
		if(!edgeIsSubdivided(it))
Pierre Kraemer's avatar
Pierre Kraemer committed
471
			subdivideEdge(it) ;			// and cut the edges (if they are not already)
Pierre Kraemer's avatar
Pierre Kraemer committed
472
473
474
475
476
477
478
479
		it = phi1(it) ;
	} while(it != old) ;

	setCurrentLevel(fLevel + 1) ;	// go to the next level to perform face subdivision

	if(degree == 3)					// if subdividing a triangle
	{
		Dart dd = phi1(old) ;
480
481
		Dart e = phi1(dd) ;
		(*vertexVertexFunctor)(e) ;
482
		propagateOrbitEmbedding(e, VERTEX) ;
483
		e = phi1(e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
484
485
486
		splitFace(dd, e) ;

		dd = e ;
487
488
		e = phi1(dd) ;
		(*vertexVertexFunctor)(e) ;
489
		propagateOrbitEmbedding(e, VERTEX) ;
490
		e = phi1(e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
491
492
493
		splitFace(dd, e) ;

		dd = e ;
494
495
		e = phi1(dd) ;
		(*vertexVertexFunctor)(e) ;
496
		propagateOrbitEmbedding(e, VERTEX) ;
497
		e = phi1(e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
498
499
500
501
502
		splitFace(dd, e) ;
	}
	else							// if subdividing a polygonal face
	{
		Dart dd = phi1(old) ;
503
504
		Dart next = phi1(dd) ;
		(*vertexVertexFunctor)(next) ;
505
		propagateOrbitEmbedding(next, VERTEX) ;
506
507
		next = phi1(next) ;
		splitFace(dd, next) ;			// insert a first edge
Pierre Kraemer's avatar
Pierre Kraemer committed
508
509
510
511
		Dart ne = alpha1(dd) ;

		cutEdge(ne) ;					// cut the new edge to insert the central vertex

512
513
		dd = phi1(next) ;
		(*vertexVertexFunctor)(dd) ;
514
		propagateOrbitEmbedding(dd, VERTEX) ;
515
		dd = phi1(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
516
517
		while(dd != ne)					// turn around the face and insert new edges
		{								// linked to the central vertex
Pierre Kraemer's avatar
Pierre Kraemer committed
518
			splitFace(phi1(ne), dd) ;
519
520
			dd = phi1(dd) ;
			(*vertexVertexFunctor)(dd) ;
521
			propagateOrbitEmbedding(dd, VERTEX) ;
522
			dd = phi1(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
523
		}
524
525

		(*faceVertexFunctor)(phi2(ne)) ;
526
		propagateOrbitEmbedding(phi2(ne), VERTEX) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
527
528
529
	}

	popLevel() ;
530
531

	return fLevel ;
Pierre Kraemer's avatar
Pierre Kraemer committed
532
533
}

Pierre Kraemer's avatar
Pierre Kraemer committed
534
void Map2MR_PrimalAdapt::coarsenFace(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
535
{
Pierre Kraemer's avatar
Pierre Kraemer committed
536
	assert(getDartLevel(d) <= getCurrentLevel() || !"coarsenFace : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
	assert(faceIsSubdividedOnce(d) || !"Trying to coarsen a non-subdivided face or a more than once subdivided face") ;

	unsigned int degree = 0 ;
	Dart fit = d ;
	do
	{
		++degree ;
		fit = phi1(fit) ;
	} while(fit != d) ;

	if(degree == 3)
	{
		fit = d ;
		do
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
552
			incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
553
554
555
			Dart innerEdge = phi1(fit) ;
			setCurrentLevel(getMaxLevel()) ;
			mergeFaces(innerEdge) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
556
			decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
557
558
559
560
561
			fit = phi1(fit) ;
		} while(fit != d) ;
	}
	else
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
562
		incCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
563
564
565
		Dart centralV = phi1(phi1(d)) ;
		setCurrentLevel(getMaxLevel()) ;
		deleteVertex(centralV) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
566
		decCurrentLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
567
568
569
570
571
572
573
574
575
	}

	fit = d ;
	do
	{
		if(edgeCanBeCoarsened(fit))
			coarsenEdge(fit) ;
		fit = phi1(fit) ;
	} while(fit != d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
576
577
578
579

	unsigned int maxL = getMaxLevel() ;
	if(getCurrentLevel() == maxL - 1 && getNbInsertedDarts(maxL) == 0)
		removeLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
580
581
582
}

} // namespace CGoGN