Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

map2.hpp 29 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
25
26
27
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

Pierre Kraemer's avatar
Pierre Kraemer committed
28
29
template <typename MAP_IMPL>
inline void Map2<MAP_IMPL>::init()
Pierre Kraemer's avatar
Pierre Kraemer committed
30
{
Pierre Kraemer's avatar
Pierre Kraemer committed
31
	MAP_IMPL::addInvolution() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
32
33
}

Pierre Kraemer's avatar
Pierre Kraemer committed
34
35
template <typename MAP_IMPL>
inline Map2<MAP_IMPL>::Map2() : Map1<MAP_IMPL>()
36
37
38
39
{
	init() ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
40
41
template <typename MAP_IMPL>
inline std::string Map2<MAP_IMPL>::mapTypeName() const
Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
44
45
{
	return "Map2" ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
template <typename MAP_IMPL>
inline unsigned int Map2<MAP_IMPL>::dimension() const
Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
50
51
{
	return 2 ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
template <typename MAP_IMPL>
inline void Map2<MAP_IMPL>::clear(bool removeAttrib)
54
{
55
	ParentMap::clear(removeAttrib) ;
Sylvain Thery's avatar
Sylvain Thery committed
56
57
	if (removeAttrib)
		init() ;
58
59
}

Pierre Kraemer's avatar
Pierre Kraemer committed
60
61
template <typename MAP_IMPL>
inline void Map2<MAP_IMPL>::update_topo_shortcuts()
Sylvain Thery's avatar
Sylvain Thery committed
62
{
63
	ParentMap::update_topo_shortcuts();
64
//	m_phi2 = getRelation("phi2");
Sylvain Thery's avatar
Sylvain Thery committed
65
66
}

Pierre Kraemer's avatar
Pierre Kraemer committed
67
68
69
70
/*! @name Basic Topological Operators
 * Access and Modification
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
71
72
template <typename MAP_IMPL>
inline Dart Map2<MAP_IMPL>::phi2(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
73
{
Pierre Kraemer's avatar
Pierre Kraemer committed
74
	return MAP_IMPL::template getInvolution<0>(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
75
76
}

Pierre Kraemer's avatar
Pierre Kraemer committed
77
template <typename MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
78
template <int N>
Pierre Kraemer's avatar
Pierre Kraemer committed
79
inline Dart Map2<MAP_IMPL>::phi(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
80
81
82
83
84
85
{
	assert( (N > 0) || !"negative parameters not allowed in template multi-phi");
	if (N < 10)
	{
		switch(N)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
86
			case 1 : return this->phi1(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
87
88
89
90
91
92
93
94
95
96
97
98
			case 2 : return phi2(d) ;
			default : assert(!"Wrong multi-phi relation value") ; return d ;
		}
	}
	switch(N%10)
	{
		case 1 : return phi1(phi<N/10>(d)) ;
		case 2 : return phi2(phi<N/10>(d)) ;
		default : assert(!"Wrong multi-phi relation value") ; return d ;
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
99
100
template <typename MAP_IMPL>
inline Dart Map2<MAP_IMPL>::alpha0(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
101
102
103
104
{
	return phi2(d) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
105
106
template <typename MAP_IMPL>
inline Dart Map2<MAP_IMPL>::alpha1(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
107
{
108
	return phi2(this->phi_1(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
109
110
}

Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
template <typename MAP_IMPL>
inline Dart Map2<MAP_IMPL>::alpha_1(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
113
{
114
	return this->phi1(phi2(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
115
116
}

Pierre Kraemer's avatar
Pierre Kraemer committed
117
118
template <typename MAP_IMPL>
inline Dart Map2<MAP_IMPL>::phi2_1(Dart d) const
119
{
120
	return phi2(this->phi_1(d)) ;
121
122
}

Pierre Kraemer's avatar
Pierre Kraemer committed
123
124
template <typename MAP_IMPL>
inline Dart Map2<MAP_IMPL>::phi12(Dart d) const
125
126
127
128
{
	return phi1(phi2(d)) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
129
130
template <typename MAP_IMPL>
inline void Map2<MAP_IMPL>::phi2sew(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
131
{
Pierre Kraemer's avatar
Pierre Kraemer committed
132
	MAP_IMPL::template involutionSew<0>(d,e);
Pierre Kraemer's avatar
Pierre Kraemer committed
133
134
}

Pierre Kraemer's avatar
Pierre Kraemer committed
135
136
template <typename MAP_IMPL>
inline void Map2<MAP_IMPL>::phi2unsew(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
137
{
Pierre Kraemer's avatar
Pierre Kraemer committed
138
	MAP_IMPL::template involutionUnsew<0>(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
139
140
}

141
142
143
144
/*! @name Generator and Deletor
 *  To generate or delete faces in a 2-map
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
145
146
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::newPolyLine(unsigned int nbEdges)
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
{
	Dart d = ParentMap::newCycle(2*nbEdges);
	{
		Dart it1 = d;
		Dart it2 = this->phi_1(d);
		for(unsigned int i = 0; i < nbEdges ; ++i)
		{
			phi2sew(it1, it2);
			it1 = this->phi1(it1);
			it2 = this->phi_1(it2);
		}
	}
	return d;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
162
163
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::newFace(unsigned int nbEdges, bool withBoundary)
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{
	Dart d = ParentMap::newCycle(nbEdges);
	if (withBoundary)
	{
		Dart e = newBoundaryCycle(nbEdges);

		Dart it = d;
		do
		{
			phi2sew(it, e);
			it = this->phi1(it);
			e = this->phi_1(e);
		} while (it != d);
	}
	return d;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
181
182
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::deleteFace(Dart d, bool withBoundary)
183
{
Pierre Kraemer's avatar
Pierre Kraemer committed
184
	assert(!this->template isBoundaryMarked<2>(d)) ;
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
	if (withBoundary)
	{
		Dart it = d ;
		do
		{
			if(!isBoundaryEdge(it))
				unsewFaces(it) ;
			it = this->phi1(it) ;
		} while(it != d) ;
		Dart dd = phi2(d) ;
		ParentMap::deleteCycle(d) ;
		ParentMap::deleteCycle(dd) ;
		return;
	}
	//else with remove the face and create fixed points
	Dart it = d ;
	do
	{
		phi2unsew(it);
		it = this->phi1(it) ;
	} while(it != d) ;
	ParentMap::deleteCycle(d);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
209
210
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::deleteCC(Dart d)
211
{
Pierre Kraemer's avatar
Pierre Kraemer committed
212
	DartMarkerStore<MAP_IMPL> mark(*this);
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

	std::vector<Dart> visited;
	visited.reserve(1024) ;
	visited.push_back(d);
	mark.mark(d) ;

	for(unsigned int i = 0; i < visited.size(); ++i)
	{
		Dart d1 = this->phi1(visited[i]) ;
		if(!mark.isMarked(d1))
		{
			visited.push_back(d1) ;
			mark.mark(d1);
		}
		Dart d2 = phi2(visited[i]) ;
		if(!mark.isMarked(d2))
		{
			visited.push_back(d2) ;
			mark.mark(d2);
		}
	}

	for(std::vector<Dart>::iterator it = visited.begin(); it != visited.end(); ++it)
		this->deleteDart(*it) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
239
240
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::fillHole(Dart d)
241
242
243
{
	assert(isBoundaryEdge(d)) ;
	Dart dd = d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
244
	if(!this->template isBoundaryMarked<2>(dd))
245
246
247
248
		dd = phi2(dd) ;
	this->template boundaryUnmarkOrbit<FACE,2>(dd) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
249
250
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::createHole(Dart d)
251
252
253
254
255
256
257
258
259
{
	assert(!isBoundaryEdge(d)) ;
	this->template boundaryMarkOrbit<FACE,2>(d) ;
}

/*! @name Topological Operators
 *  Topological operations on 2-maps
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
260
261
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::splitVertex(Dart d, Dart e)
262
263
264
265
266
267
268
269
270
{
	assert(sameVertex(d, e)) ;
	Dart d2 = phi2(d) ; assert(d != d2) ;
	Dart e2 = phi2(e) ; assert(e != e2) ;
	Dart nd = ParentMap::cutEdge(d2) ;	// Cut the edge of dd (make a new half edge)
	Dart ne = ParentMap::cutEdge(e2) ;	// Cut the edge of ee (make a new half edge)
	phi2sew(nd, ne) ;					// Sew the two faces along the new edge
}

Pierre Kraemer's avatar
Pierre Kraemer committed
271
272
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::deleteVertex(Dart d)
273
274
275
276
277
278
279
280
281
282
283
284
{
	//TODO utile ?
	if(isBoundaryVertex(d))
		return NIL ;

	Dart res = NIL ;
	Dart vit = d ;
	do
	{
		if(res == NIL && this->phi1(this->phi1(d)) != d)
			res = this->phi1(d) ;

285
		Dart f = this->phi_1(phi2(vit)) ;
286
287
288
289
290
291
292
293
		this->phi1sew(vit, f) ;

		vit = phi2(this->phi_1(vit)) ;
	} while(vit != d) ;
	ParentMap::deleteCycle(d) ;
	return res ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
294
295
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::cutEdge(Dart d)
296
297
298
299
300
301
302
303
304
305
{
	Dart e = phi2(d);
	phi2unsew(d);						// remove old phi2 links
	Dart nd = ParentMap::cutEdge(d);	// Cut the 1-edge of d
	Dart ne = ParentMap::cutEdge(e);	// Cut the 1-edge of phi2(d)
	phi2sew(d, ne);						// Correct the phi2 links
	phi2sew(e, nd);
	return nd;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
306
307
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::uncutEdge(Dart d)
308
309
310
311
312
313
314
315
316
317
318
319
320
321
{
	if(vertexDegree(this->phi1(d)) == 2)
	{
		Dart e = phi2(this->phi1(d)) ;
		phi2unsew(e) ;
		phi2unsew(d) ;
		ParentMap::uncutEdge(d) ;
		ParentMap::uncutEdge(e) ;
		phi2sew(d, e) ;
		return true ;
	}
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
322
323
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::collapseEdge(Dart d, bool delDegenerateFaces)
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
{
	Dart resV = NIL ;

	Dart e = phi2(d);
	phi2unsew(d);	// Unlink the opposite edges

	Dart f = this->phi1(e) ;
	Dart h = phi2(this->phi_1(e));

	if (h != e)
		resV = h;

	if (f != e && delDegenerateFaces)
	{
		ParentMap::collapseEdge(e) ;	// Collapse edge e
		collapseDegeneratedFace(f) ;	// and collapse its face if degenerated
	}
	else
		ParentMap::collapseEdge(e) ;	// Just collapse edge e

	f = this->phi1(d) ;
	if(resV == NIL)
	{
		h = phi2(this->phi_1(d));
		if (h != d)
			resV = h;
	}

	if (f != d && delDegenerateFaces)
	{
		ParentMap::collapseEdge(d) ;	// Collapse edge d
		collapseDegeneratedFace(f) ;	// and collapse its face if degenerated
	}
	else
		ParentMap::collapseEdge(d) ;	// Just collapse edge d

	return resV ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
363
364
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::flipEdge(Dart d)
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
{
	if (!isBoundaryEdge(d))
	{
		Dart e = phi2(d);
		Dart dNext = this->phi1(d);
		Dart eNext = this->phi1(e);
		Dart dPrev = this->phi_1(d);
		Dart ePrev = this->phi_1(e);
		this->phi1sew(d, ePrev);	// Detach the two
		this->phi1sew(e, dPrev);	// vertices of the edge
		this->phi1sew(d, dNext);	// Insert the edge in its
		this->phi1sew(e, eNext);	// new vertices after flip
		return true ;
	}
	return false ; // cannot flip a border edge
}

Pierre Kraemer's avatar
Pierre Kraemer committed
382
383
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::flipBackEdge(Dart d)
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
{
	if (!isBoundaryEdge(d))
	{
		Dart e = phi2(d);
		Dart dPrev = this->phi_1(d);
		Dart ePrev = this->phi_1(e);
		this->phi1sew(d, ePrev);		// Detach the two
		this->phi1sew(e, dPrev);		// vertices of the edge
		this->phi1sew(e, this->phi_1(dPrev));	// Insert the edge in its
		this->phi1sew(d, this->phi_1(ePrev));	// new vertices after flip
		return true ;
	}
	return false ; // cannot flip a border edge
}

Pierre Kraemer's avatar
Pierre Kraemer committed
399
400
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::swapEdges(Dart d, Dart e)
401
402
403
404
405
406
407
408
409
410
411
412
413
{
	assert(!Map2::isBoundaryEdge(d) && !Map2::isBoundaryEdge(e));

	Dart d2 = phi2(d);
	Dart e2 = phi2(e);

	phi2unsew(d);
	phi2unsew(e) ;

	phi2sew(d, e);
	phi2sew(d2, e2);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
414
415
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::insertEdgeInVertex(Dart d, Dart e)
416
417
418
{
	assert(!sameVertex(d,e));
	assert(phi2(e) == this->phi_1(e));
419
	this->phi1sew(this->phi_1(d), this->phi_1(e));
420
421
}

Pierre Kraemer's avatar
Pierre Kraemer committed
422
423
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::removeEdgeFromVertex(Dart d)
424
425
426
427
428
429
430
431
432
{
	if (!isBoundaryEdge(d))
	{
		this->phi1sew(this->phi_1(d), phi2(d)) ;
		return true ;
	}
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
433
434
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::sewFaces(Dart d, Dart e, bool withBoundary)
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
{
	// if sewing with fixed points
	if (!withBoundary)
	{
		assert(phi2(d) == d && phi2(e) == e) ;
		phi2sew(d, e) ;
		return ;
	}

	assert(isBoundaryEdge(d) && isBoundaryEdge(e)) ;

	Dart dd = phi2(d) ;
	Dart ee = phi2(e) ;

	phi2unsew(d) ;	// unsew faces from boundary
	phi2unsew(e) ;

	if (ee != this->phi_1(dd))
		this->phi1sew(ee, this->phi_1(dd)) ;	// remove the boundary edge
	if (dd != this->phi_1(ee))
		this->phi1sew(dd, this->phi_1(ee)) ;	// and properly close incident boundaries
	ParentMap::deleteCycle(dd) ;

	phi2sew(d, e) ; // sew the faces
}

Pierre Kraemer's avatar
Pierre Kraemer committed
461
462
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::unsewFaces(Dart d, bool withBoundary)
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
{
	if (!withBoundary)
	{
		phi2unsew(d) ;
		return ;
	}

	assert(!Map2::isBoundaryEdge(d)) ;

	Dart dd = phi2(d) ;

	Dart e = newBoundaryCycle(2) ;
	Dart ee = this->phi1(e) ;

	Dart f = findBoundaryEdgeOfVertex(d) ;
	Dart ff = findBoundaryEdgeOfVertex(dd) ;

	if(f != NIL)
		this->phi1sew(e, this->phi_1(f)) ;

	if(ff != NIL)
		this->phi1sew(ee, this->phi_1(ff)) ;

	phi2unsew(d) ;

	phi2sew(d, e) ;		// sew faces
	phi2sew(dd, ee) ;	// to the boundary
}

Pierre Kraemer's avatar
Pierre Kraemer committed
492
493
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::collapseDegeneratedFace(Dart d)
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
{
	Dart e = this->phi1(d) ;		// Check if the face is degenerated
	if (this->phi1(e) == d)			// Yes: it contains one or two edge(s)
	{
		Dart d2 = phi2(d) ;			// Check opposite edges
		Dart e2 = phi2(e) ;
		phi2unsew(d) ;
		if(d != e)
		{
			phi2unsew(e) ;
			phi2sew(d2, e2) ;
		}
		else
		{
			this->phi1sew(d2, this->phi_1(d2)) ;
			ParentMap::deleteCycle(d2) ;
		}
		ParentMap::deleteCycle(d) ;
		return true ;
	}
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
517
518
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::splitFace(Dart d, Dart e)
519
{
Pierre Kraemer's avatar
Pierre Kraemer committed
520
	assert(d != e && Map2<MAP_IMPL>::sameFace(d, e)) ;
521
522
523
524
525
526
	Dart dd = ParentMap::cutEdge(this->phi_1(d)) ;
	Dart ee = ParentMap::cutEdge(this->phi_1(e)) ;
	ParentMap::splitCycle(dd, ee) ;
	phi2sew(dd, ee);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
527
528
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::mergeFaces(Dart d)
529
530
531
532
533
534
535
536
537
538
539
540
541
{
	if (!isBoundaryEdge(d))
	{
		Dart e = phi2(d) ;
		phi2unsew(d) ;
		ParentMap::mergeCycles(d, this->phi1(e)) ;
		ParentMap::splitCycle(e, this->phi1(d)) ;
		ParentMap::deleteCycle(d) ;
		return true ;
	}
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
542
543
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::extractTrianglePair(Dart d)
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
{
	Dart e = phi2(d) ;

	assert(!isBoundaryFace(d) && !isBoundaryFace(e)) ;
	assert(faceDegree(d) == 3 && faceDegree(e) == 3) ;

	Dart d1 = phi2(this->phi1(d)) ;
	Dart d2 = phi2(this->phi_1(d)) ;
	phi2unsew(d1) ;
	phi2unsew(d2) ;
	phi2sew(d1, d2) ;

	Dart e1 = phi2(this->phi1(e)) ;
	Dart e2 = phi2(this->phi_1(e)) ;
	phi2unsew(e1) ;
	phi2unsew(e2) ;
	phi2sew(e1, e2) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
563
564
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::insertTrianglePair(Dart d, Dart v1, Dart v2)
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
{
	Dart e = phi2(d) ;

	assert(v1 != v2 && sameOrientedVertex(v1, v2)) ;
	assert(faceDegree(d) == 3 && faceDegree(phi2(d)) == 3) ;

	Dart vv1 = phi2(v1) ;
	phi2unsew(v1) ;
	phi2sew(this->phi_1(d), v1) ;
	phi2sew(this->phi1(d), vv1) ;

	Dart vv2 = phi2(v2) ;
	phi2unsew(v2) ;
	phi2sew(this->phi_1(e), v2) ;
	phi2sew(this->phi1(e), vv2) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
582
583
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::mergeVolumes(Dart d, Dart e, bool deleteFace)
584
{
Pierre Kraemer's avatar
Pierre Kraemer committed
585
	assert(!this->template isBoundaryMarked<2>(d) && !this->template isBoundaryMarked<2>(e)) ;
586

Pierre Kraemer's avatar
Pierre Kraemer committed
587
	if (Map2<MAP_IMPL>::isBoundaryFace(d) || Map2<MAP_IMPL>::isBoundaryFace(e))
588
589
590
591
592
593
594
595
596
597
598
599
600
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
630
631
632
633
634
635
		return false;

	// First traversal of both faces to check the face sizes
	// and store their edges to efficiently access them further

	std::vector<Dart> dDarts;
	std::vector<Dart> eDarts;
	dDarts.reserve(16);		// usual faces have less than 16 edges
	eDarts.reserve(16);

	Dart dFit = d ;
	Dart eFit = this->phi1(e) ;	// must take phi1 because of the use
	do							// of reverse iterator for sewing loop
	{
		dDarts.push_back(dFit) ;
		dFit = this->phi1(dFit) ;
	} while(dFit != d) ;
	do
	{
		eDarts.push_back(eFit) ;
		eFit = this->phi1(eFit) ;
	} while(eFit != this->phi1(e)) ;

	if(dDarts.size() != eDarts.size())
		return false ;

	// Make the sewing: take darts in initial order (clockwise) in first face
	// and take darts in reverse order (counter-clockwise) in the second face
	std::vector<Dart>::iterator dIt;
	std::vector<Dart>::reverse_iterator eIt;
	for (dIt = dDarts.begin(), eIt = eDarts.rbegin(); dIt != dDarts.end(); ++dIt, ++eIt)
	{
		Dart d2 = phi2(*dIt);	// Search the faces adjacent to dNext and eNext
		Dart e2 = phi2(*eIt);
		phi2unsew(d2);		// Unlink the two adjacent faces from dNext and eNext
		phi2unsew(e2);
		phi2sew(d2, e2);	// Link the two adjacent faces together
	}

	if(deleteFace)
	{
		ParentMap::deleteCycle(d);		// Delete the two alone faces
		ParentMap::deleteCycle(e);
	}

	return true ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
636
637
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::splitSurface(std::vector<Dart>& vd, bool firstSideClosed, bool secondSideClosed)
638
639
640
641
642
643
644
645
646
{
//	assert(checkSimpleOrientedPath(vd)) ;

	Dart e = vd.front() ;
	Dart e2 = phi2(e) ;

	//unsew the edge path
	for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
647
		//if(!Map2<MAP_IMPL>::isBoundaryEdge(*it))
648
649
650
651
			unsewFaces(*it) ;
	}

	if(firstSideClosed)
Pierre Kraemer's avatar
Pierre Kraemer committed
652
		Map2<MAP_IMPL>::fillHole(e) ;
653
654

	if(secondSideClosed)
Pierre Kraemer's avatar
Pierre Kraemer committed
655
		Map2<MAP_IMPL>::fillHole(e2) ;
656
657
}

Pierre Kraemer's avatar
Pierre Kraemer committed
658
659
660
661
/*! @name Topological Queries
 *  Return or set various topological information
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
662
663
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::sameOrientedVertex(Dart d, Dart e) const
664
665
666
667
668
669
670
671
672
673
674
{
	Dart it = d;				// Foreach dart dNext in the vertex of d
	do
	{
		if (it == e)			// Test equality with e
			return true;
		it = phi2(this->phi_1(it));
	} while (it != d);
	return false;				// None is equal to e => vertices are distinct
}

Pierre Kraemer's avatar
Pierre Kraemer committed
675
676
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::sameVertex(Dart d, Dart e) const
Pierre Kraemer's avatar
Pierre Kraemer committed
677
678
679
680
{
	return sameOrientedVertex(d, e) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
681
682
template <typename MAP_IMPL>
unsigned int Map2<MAP_IMPL>::vertexDegree(Dart d) const
683
684
685
686
687
688
689
690
691
692
693
{
	unsigned int count = 0 ;
	Dart it = d ;
	do
	{
		++count ;
		it = phi2(this->phi_1(it)) ;
	} while (it != d) ;
	return count ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
694
695
template <typename MAP_IMPL>
int Map2<MAP_IMPL>::checkVertexDegree(Dart d, unsigned int vd) const
696
697
698
699
700
701
702
703
704
705
706
707
{
	unsigned int count = 0 ;
	Dart it = d ;
	do
	{
		++count ;
		it = phi2(this->phi_1(it)) ;
	} while ((count <= vd) && (it != d)) ;

	return count - vd;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
708
709
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::isBoundaryVertex(Dart d) const
710
711
712
713
{
	Dart it = d ;
	do
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
714
		if (this->template isBoundaryMarked<2>(it))
715
716
717
718
719
720
			return true ;
		it = phi2(this->phi_1(it)) ;
	} while (it != d) ;
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
721
722
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::findBoundaryEdgeOfVertex(Dart d) const
723
724
725
726
{
	Dart it = d ;
	do
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
727
		if (this->template isBoundaryMarked<2>(it))
728
729
730
731
732
733
			return it ;
		it = phi2(this->phi_1(it)) ;
	} while (it != d) ;
	return NIL ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
734
735
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::sameEdge(Dart d, Dart e) const
Pierre Kraemer's avatar
Pierre Kraemer committed
736
737
738
739
{
	return d == e || phi2(d) == e ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
740
741
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::isBoundaryEdge(Dart d) const
untereiner's avatar
untereiner committed
742
{
Pierre Kraemer's avatar
Pierre Kraemer committed
743
	return this->template isBoundaryMarked<2>(d) || this->template isBoundaryMarked<2>(phi2(d));
untereiner's avatar
untereiner committed
744
745
}

Pierre Kraemer's avatar
Pierre Kraemer committed
746
747
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::sameOrientedFace(Dart d, Dart e) const
748
{
749
	return ParentMap::sameCycle(d, e) ;
750
751
}

Pierre Kraemer's avatar
Pierre Kraemer committed
752
753
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::sameFace(Dart d, Dart e) const
754
755
756
757
{
	return sameOrientedFace(d, e) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
758
759
template <typename MAP_IMPL>
inline unsigned int Map2<MAP_IMPL>::faceDegree(Dart d) const
760
{
761
	return ParentMap::cycleDegree(d) ;
762
763
}

Pierre Kraemer's avatar
Pierre Kraemer committed
764
765
template <typename MAP_IMPL>
inline int Map2<MAP_IMPL>::checkFaceDegree(Dart d, unsigned int le) const
766
{
767
	return ParentMap::checkCycleDegree(d,le) ;
768
769
}

Pierre Kraemer's avatar
Pierre Kraemer committed
770
771
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::isBoundaryFace(Dart d) const
772
773
774
775
{
	Dart it = d ;
	do
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
776
		if (this->template isBoundaryMarked<2>(phi2(it)))
777
778
779
780
781
782
			return true ;
		it = this->phi1(it) ;
	} while (it != d) ;
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
783
784
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::findBoundaryEdgeOfFace(Dart d) const
785
786
787
788
789
790
791
792
793
794
795
{
	Dart it = d ;
	do
	{
		if (this->isBoundaryMarked2(phi2(it)))
			return phi2(it) ;
		it = this->phi1(it) ;
	} while (it != d) ;
	return NIL ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
796
797
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::sameOrientedVolume(Dart d, Dart e) const
798
{
Pierre Kraemer's avatar
Pierre Kraemer committed
799
	DartMarkerStore<MAP_IMPL> mark(*this);	// Lock a marker
800
801
802
803
804
805
806
807

	std::list<Dart> visitedFaces;	// Faces that are traversed
	visitedFaces.push_back(d);		// Start with the face of d
	std::list<Dart>::iterator face;

	// For every face added to the list
	for (face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
808
		if (!this->template isBoundaryMarked<2>(*face) && !mark.isMarked(*face))		// Face has not been visited yet
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
		{
			Dart it = *face ;
			do
			{
				if(it == e)
					return true;

				mark.mark(it);						// Mark
				Dart adj = phi2(it);				// Get adjacent face
				if (!this->isBoundaryMarked2(adj) && !mark.isMarked(adj))
					visitedFaces.push_back(adj);	// Add it
				it = this->phi1(it);
			} while(it != *face);
		}
	}
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
827
828
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::sameVolume(Dart d, Dart e) const
829
830
831
832
{
	return sameOrientedVolume(d, e) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
833
834
template <typename MAP_IMPL>
unsigned int Map2<MAP_IMPL>::volumeDegree(Dart d) const
835
836
{
	unsigned int count = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
837
	DartMarkerStore<MAP_IMPL> mark(*this);		// Lock a marker
838
839
840
841
842
843
844
845
846
847

	std::vector<Dart> visitedFaces;		// Faces that are traversed
	visitedFaces.reserve(16);
	visitedFaces.push_back(d);			// Start with the face of d
	std::vector<Dart>::iterator face;

	// For every face added to the list
	for (unsigned int i = 0; i != visitedFaces.size(); ++i)
	{
		Dart df = visitedFaces[i];
Pierre Kraemer's avatar
Pierre Kraemer committed
848
		if (!this->template isBoundaryMarked<2>(df) && !mark.isMarked(df))		// Face has not been visited yet
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
		{
			++count;
			Dart it = df ;
			do
			{
				mark.mark(it);					// Mark
				Dart adj = phi2(it);			// Get adjacent face
				if ( !this->isBoundaryMarked2(adj) && !mark.isMarked(adj) )
					visitedFaces.push_back(adj);// Add it
				it = this->phi1(it);
			} while(it != df);
		}
	}

	return count;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
866
867
template <typename MAP_IMPL>
int Map2<MAP_IMPL>::checkVolumeDegree(Dart d, unsigned int volDeg) const
868
869
{
	unsigned int count = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
870
	DartMarkerStore<MAP_IMPL> mark(*this);		// Lock a marker
871
872
873
874
875
876
877
878
879

	std::vector<Dart> visitedFaces;		// Faces that are traversed
	visitedFaces.reserve(16);
	visitedFaces.push_back(d);			// Start with the face of d

	// For every face added to the list
	for (unsigned int i = 0; i != visitedFaces.size(); ++i)
	{
		Dart df = visitedFaces[i];
Pierre Kraemer's avatar
Pierre Kraemer committed
880
		if (!this->template isBoundaryMarked<2>(df) && !mark.isMarked(df))		// Face has not been visited yet
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
		{
			++count;
			Dart it = df ;
			do
			{
				mark.mark(it);					// Mark
				Dart adj = phi2(it);			// Get adjacent face
				if ( !this->isBoundaryMarked2(adj) && !mark.isMarked(adj) )
					visitedFaces.push_back(adj);// Add it
				it = this->phi1(it);
			} while(it != df);
		}
		if (count > volDeg)
			break;
	}

	return count - volDeg;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
900
901
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::isTriangular() const
902
{
Pierre Kraemer's avatar
Pierre Kraemer committed
903
	TraversorF<Map2<MAP_IMPL> > t(*this) ;
904
905
906
907
908
909
910
911
	for(Dart d = t.begin(); d != t.end(); d = t.next())
	{
		if(faceDegree(d) != 3)
			return false ;
	}
	return true ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
912
913
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::check() const
914
915
{
	CGoGNout << "Check: topology begin" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
916
	DartMarker<MAP_IMPL> m(*this);
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
	for(Dart d = Map2::begin(); d != Map2::end(); Map2::next(d))
	{
		Dart d2 = phi2(d);
		if (phi2(d2) != d)	// phi2 involution ?
		{
			CGoGNout << "Check: phi2 is not an involution" << CGoGNendl;
			return false;
		}
		if(d2 == d)
		{
			CGoGNout << "Check: phi2 fixed point" << CGoGNendl;
			return false;
		}

		Dart d1 = this->phi1(d);
		if (this->phi_1(d1) != d)	// phi1 a une image correcte ?
		{
			CGoGNout << "Check: inconsistent phi_1 link" << CGoGNendl;
			return false;
		}

		if (m.isMarked(d1))	// phi1 a un seul antécédent ?
		{
			CGoGNout << "Check: dart with two phi1 predecessors" << CGoGNendl;
			return false;
		}
		m.mark(d1);

		if (d1 == d)
			CGoGNout << "Check: (warning) face loop (one edge)" << CGoGNendl;
		if (this->phi1(d1) == d)
			CGoGNout << "Check: (warning) face with only two edges" << CGoGNendl;
		if (phi2(d1) == d)
			CGoGNout << "Check: (warning) dangling edge" << CGoGNendl;
	}

	for(Dart d = Map2::begin(); d != Map2::end(); Map2::next(d))
	{
		if (!m.isMarked(d))	// phi1 a au moins un antécédent ?
		{
			CGoGNout << "Check: dart with no phi1 predecessor" << CGoGNendl;
			return false;
		}
	}

	CGoGNout << "Check: topology ok" << CGoGNendl;

	return true;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
967
968
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::checkSimpleOrientedPath(std::vector<Dart>& vd)
969
{
Pierre Kraemer's avatar
Pierre Kraemer committed
970
	DartMarkerStore<MAP_IMPL> dm(*this) ;
971
972
973
974
	for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
	{
		if(dm.isMarked(*it))
			return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
975
		dm.template markOrbit<VERTEX>(*it) ;
976
977
978
979
980
981
982
983
984
985
986
987
988

		std::vector<Dart>::iterator prev ;
		if(it == vd.begin())
			prev = vd.end() - 1 ;
		else
			prev = it - 1 ;

		if(!sameVertex(*it, this->phi1(*prev)))
			return false ;
	}
	return true ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
989
990
991
992
/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
993
994
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const
995
996
997
998
999
1000
1001
1002
1003
1004
1005
{
	Dart dNext = d;
	do
	{
		if (f(dNext))
			return true;
		dNext = phi2(this->phi_1(dNext));
	} while (dNext != d);
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1006
1007
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::foreach_dart_of_edge(Dart d, FunctorType& fonct, unsigned int /*thread*/) const
1008
1009
1010
1011
1012
1013
{
	if (fonct(d))
		return true;
	return fonct(phi2(d));
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1014
1015
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const
Pierre Kraemer's avatar
Pierre Kraemer committed
1016
{
1017
	return ParentMap::foreach_dart_of_cc(d, f, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
1018
1019
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1020
1021
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const
Pierre Kraemer's avatar
Pierre Kraemer committed
1022
1023
1024
{
	return foreach_dart_of_cc(d, f, thread);
}
1025

Pierre Kraemer's avatar
Pierre Kraemer committed
1026
1027
template <typename MAP_IMPL>
bool Map2<MAP_IMPL>::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const
1028
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1029
	DartMarkerStore<MAP_IMPL> mark(*this, thread);	// Lock a marker
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
	bool found = false;				// Last functor return value

	std::vector<Dart> visitedFaces;	// Faces that are traversed
	visitedFaces.reserve(1024) ;
	visitedFaces.push_back(d);		// Start with the face of d

	// For every face added to the list
	for(unsigned int i = 0; !found && i < visitedFaces.size(); ++i)
	{
		if (!mark.isMarked(visitedFaces[i]))	// Face has not been visited yet
		{
			// Apply functor to the darts of the face
			found = Map2::foreach_dart_of_face(visitedFaces[i], f);

			// If functor returns false then mark visited darts (current face)
			// and add non visited adjacent faces to the list of face
			if (!found)
			{
				Dart e = visitedFaces[i] ;
				do
				{
					mark.mark(e);				// Mark
					Dart adj = phi2(e);			// Get adjacent face
					if (!mark.isMarked(adj))
						visitedFaces.push_back(adj);	// Add it
					e = this->phi1(e);
				} while(e != visitedFaces[i]);
			}
		}
	}
	return found;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1063
1064
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::foreach_dart_of_vertex1(Dart d, FunctorType& f, unsigned int thread) const
1065
{
1066
	return ParentMap::foreach_dart_of_vertex(d,f,thread);
1067
1068
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1069
1070
template <typename MAP_IMPL>
inline bool Map2<MAP_IMPL>::foreach_dart_of_edge1(Dart d, FunctorType& f, unsigned int thread) const
Pierre Kraemer's avatar
Pierre Kraemer committed
1071
{
1072
	return ParentMap::foreach_dart_of_edge(d,f,thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
1073
1074
}

1075
1076
1077
1078
/*! @name Close map after import or creation
 *  These functions must be used with care, generally only by import/creation algorithms
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
1079
1080
template <typename MAP_IMPL>
Dart Map2<MAP_IMPL>::newBoundaryCycle(unsigned int nbE)
1081
1082
1083
1084
1085
1086
{
	Dart d = ParentMap::newCycle(nbE);
	this->template boundaryMarkOrbit<FACE,2>(d);
	return d;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1087
1088
template <typename MAP_IMPL>
unsigned int Map2<MAP_IMPL>::closeHole(Dart d, bool forboundary)
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
{
	assert(phi2(d) == d);		// Nothing to close

	Dart first = this->newDart();	// First edge of the face that will fill the hole
	unsigned int countEdges = 1;

	phi2sew(d, first);	// phi2-link the new edge to the hole

	Dart dNext = d;	// Turn around the hole
	Dart dPhi1;		// to complete the face
	do
	{
		do
		{
			dPhi1 = this->phi1(dNext);	// Search and put in dNext
			dNext = phi2(dPhi1);		// the next dart of the hole
		} while (dNext != dPhi1 && dPhi1 != d);

		if (dPhi1 != d)
		{
			Dart next = this->newDart();	// Add a new edge there and link it to the face
			++countEdges;
			this->phi1sew(first, next);	// the edge is linked to the face
			phi2sew(dNext, next);		// the face is linked to the hole
		}
	} while (dPhi1 != d);

	if (forboundary)
		this->template boundaryMarkOrbit<FACE,2>(phi2(d));

	return countEdges ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1122
1123
template <typename MAP_IMPL>
unsigned int Map2<MAP_IMPL>::closeMap(bool forboundary)
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
{
	// Search the map for topological holes (fix points of phi2)
	unsigned int nb = 0 ;
	for (Dart d = this->begin(); d != this->end(); this->next(d))
	{
		if (phi2(d) == d)
		{
			++nb ;
			closeHole(d, forboundary);
		}
	}
	return nb ;
}

/*! @name Compute dual
 * These functions compute the dual mesh
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
1142
1143
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::reverseOrientation()
1144
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1145
	DartAttribute<unsigned int, MAP_IMPL> emb0(this, this->template getEmbeddingAttributeVector<VERTEX>()) ;
1146
1147
	if(emb0.isValid())
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
1148
		DartAttribute<unsigned int, MAP_IMPL> new_emb0 = this->template addAttribute<unsigned int, DART>("new_EMB_0") ;
1149
1150
1151
1152
1153
1154
1155
		for(Dart d = this->begin(); d != this->end(); this->next(d))
			new_emb0[d] = emb0[this->phi1(d)] ;

		this->template swapAttributes<unsigned int>(emb0, new_emb0) ;
		this->removeAttribute(new_emb0) ;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
1156
1157
	DartAttribute<Dart, MAP_IMPL> n_phi1 = this->template getAttribute<Dart, DART>("phi1") ;
	DartAttribute<Dart, MAP_IMPL> n_phi_1 = this->template getAttribute<Dart, DART>("phi_1") ;
1158
1159
1160
	this->template swapAttributes<Dart>(n_phi1, n_phi_1) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1161
1162
template <typename MAP_IMPL>
void Map2<MAP_IMPL>::computeDual()
1163
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1164
1165
1166
1167
	DartAttribute<Dart, MAP_IMPL> old_phi1 = this->template getAttribute<Dart, DART>("phi1");
	DartAttribute<Dart, MAP_IMPL> old_phi_1 = this->template getAttribute<Dart, DART>("phi_1") ;
	DartAttribute<Dart, MAP_IMPL> new_phi1 = this->template addAttribute<Dart, DART>("new_phi1") ;
	DartAttribute<Dart, MAP_IMPL> new_phi_1 = this->template addAttribute<Dart, DART>("new_phi_1") ;
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194

	for(Dart d = this->begin(); d != this->end(); this->next(d))
	{
		Dart dd = this->phi1(phi2(d));

		new_phi1[d] = dd ;
		new_phi_1[dd] = d ;
	}

	this->template swapAttributes<Dart>(old_phi1, new_phi1) ;
	this->template swapAttributes<Dart>(old_phi_1, new_phi_1) ;

	this->removeAttribute(new_phi1) ;
	this->removeAttribute(new_phi_1) ;

	this->swapEmbeddingContainers(VERTEX, FACE) ;

	reverseOrientation() ;

	// boundary management
	for(Dart d = this->begin(); d != this->end(); this->next(d))
	{
		if(this->isBoundaryMarked2(d))
			this->template boundaryMarkOrbit<FACE,2>(deleteVertex(phi2(d)));
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1195
} // namespace CGoGN