map3.hpp 43.2 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/generic/traversor/traversor3.h"
26

Pierre Kraemer's avatar
Pierre Kraemer committed
27
28
29
namespace CGoGN
{

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
template <typename MAP_IMPL>
inline unsigned int Map3<MAP_IMPL>::dimension() const
Pierre Kraemer's avatar
Pierre Kraemer committed
50
51
52
53
{
	return 3;
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
62
template <typename MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
63
inline unsigned int Map3<MAP_IMPL>::getNbInvolutions() const
Sylvain Thery's avatar
Sylvain Thery committed
64
{
Pierre Kraemer's avatar
Pierre Kraemer committed
65
66
67
68
69
70
71
	return 1 + ParentMap::getNbInvolutions();
}

template <typename MAP_IMPL>
inline unsigned int Map3<MAP_IMPL>::getNbPermutations() const
{
	return ParentMap::getNbPermutations();
Sylvain Thery's avatar
Sylvain Thery committed
72
73
}

Pierre Kraemer's avatar
Pierre Kraemer committed
74
75
76
77
/*! @name Basic Topological Operators
 * Access and Modification
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
78
79
template <typename MAP_IMPL>
inline Dart Map3<MAP_IMPL>::phi3(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
80
{
Pierre Kraemer's avatar
Pierre Kraemer committed
81
	return MAP_IMPL::template getInvolution<1>(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
82
83
}

Pierre Kraemer's avatar
Pierre Kraemer committed
84
template <typename MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
85
template <int N>
Pierre Kraemer's avatar
Pierre Kraemer committed
86
inline Dart Map3<MAP_IMPL>::phi(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
87
88
89
90
91
92
{
	assert( (N >0) || !"negative parameters not allowed in template multi-phi");
	if (N<10)
	{
		switch(N)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
93
94
95
96
			case 1 : return this->phi1(d) ;
			case 2 : return this->phi2(d) ;
			case 3 : return phi3(d) ;
			default : assert(!"Wrong multi-phi relation value") ; return d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
99
100
		}
	}
	switch(N%10)
	{
101
102
		case 1 : return this->phi1(phi<N/10>(d)) ;
		case 2 : return this->phi2(phi<N/10>(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
103
104
		case 3 : return phi3(phi<N/10>(d)) ;
		default : assert(!"Wrong multi-phi relation value") ; return d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
105
106
107
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
108
109
template <typename MAP_IMPL>
inline Dart Map3<MAP_IMPL>::alpha0(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
110
111
112
113
{
	return phi3(d) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
114
115
template <typename MAP_IMPL>
inline Dart Map3<MAP_IMPL>::alpha1(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
116
{
Pierre Kraemer's avatar
Pierre Kraemer committed
117
	return phi3(this->phi_1(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
118
119
}

Pierre Kraemer's avatar
Pierre Kraemer committed
120
121
template <typename MAP_IMPL>
inline Dart Map3<MAP_IMPL>::alpha2(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
122
{
Pierre Kraemer's avatar
Pierre Kraemer committed
123
	return phi3(this->phi2(d));
Pierre Kraemer's avatar
Pierre Kraemer committed
124
125
}

Pierre Kraemer's avatar
Pierre Kraemer committed
126
127
template <typename MAP_IMPL>
inline Dart Map3<MAP_IMPL>::alpha_2(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
128
{
129
	return this->phi2(phi3(d));
Pierre Kraemer's avatar
Pierre Kraemer committed
130
131
}

Pierre Kraemer's avatar
Pierre Kraemer committed
132
133
template <typename MAP_IMPL>
inline void Map3<MAP_IMPL>::phi3sew(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
134
{
Pierre Kraemer's avatar
Pierre Kraemer committed
135
	MAP_IMPL::template involutionSew<1>(d,e);
Pierre Kraemer's avatar
Pierre Kraemer committed
136
137
}

Pierre Kraemer's avatar
Pierre Kraemer committed
138
139
template <typename MAP_IMPL>
inline void Map3<MAP_IMPL>::phi3unsew(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
140
{
Pierre Kraemer's avatar
Pierre Kraemer committed
141
	MAP_IMPL::template involutionUnsew<1>(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
142
143
}

144
145
/*! @name Generator and Deletor
 *  To generate or delete volumes in a 3-map
untereiner's avatar
untereiner committed
146
 *************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
147

Pierre Kraemer's avatar
Pierre Kraemer committed
148
149
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::deleteVolume(Dart d, bool withBoundary)
untereiner's avatar
untereiner committed
150
{
151
152
	if(withBoundary)
	{
153
		DartMarkerStore< Map3<MAP_IMPL> > mark(*this);		// Lock a marker
154
155
156
157
158

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

Pierre Kraemer's avatar
Pierre Kraemer committed
159
		mark.template markOrbit<FACE2>(d) ;
160
161
162
163
164
165
166
167
168
169
170
171
172
173

		for(unsigned int i = 0; i < visitedFaces.size(); ++i)
		{
			Dart e = visitedFaces[i] ;

			if(!isBoundaryFace(e))
				unsewVolumes(e) ;

			do	// add all face neighbours to the table
			{
				Dart ee = this->phi2(e) ;
				if(!mark.isMarked(ee)) // not already marked
				{
					visitedFaces.push_back(ee) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
174
					mark.template markOrbit<FACE2>(ee) ;
175
176
177
178
179
180
181
182
183
184
185
186
187
				}
				e = this->phi1(e) ;
			} while(e != visitedFaces[i]) ;
		}

		Dart dd = phi3(d) ;
		ParentMap::deleteCC(d) ; //deleting the volume
		ParentMap::deleteCC(dd) ; //deleting its border (created from the unsew operation)

		return;
	}

	//else remove the CC and create fixed points
188
	DartMarkerStore< Map3<MAP_IMPL> > mark(*this);		// Lock a marker
189
190
191
192
193

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

Pierre Kraemer's avatar
Pierre Kraemer committed
194
	mark.template markOrbit<FACE2>(d) ;
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

	for(unsigned int i = 0; i < visitedFaces.size(); ++i)
	{
		Dart e = visitedFaces[i] ;

		Dart it = e ;
		do
		{
			phi3unsew(it);
			it = this->phi1(it) ;
		} while(it != e) ;

		do	// add all face neighbours to the table
		{
			Dart ee = this->phi2(e) ;
			if(!mark.isMarked(ee)) // not already marked
			{
				visitedFaces.push_back(ee) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
213
				mark.template markOrbit<FACE2>(ee) ;
214
215
216
217
218
219
			}
			e = this->phi1(e) ;
		} while(e != visitedFaces[i]) ;
	}

	ParentMap::deleteCC(d) ; //deleting the volume
untereiner's avatar
untereiner committed
220
221
}

Pierre Kraemer's avatar
Pierre Kraemer committed
222
223
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::fillHole(Dart d)
untereiner's avatar
untereiner committed
224
{
225
226
	assert(isBoundaryFace(d)) ;
	Dart dd = d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
227
	if(!this->template isBoundaryMarked<3>(dd))
228
		dd = phi3(dd) ;
229
	Algo::Topo::boundaryUnmarkOrbit<3,VOLUME>(*this, dd) ;
untereiner's avatar
untereiner committed
230
}
Pierre Kraemer's avatar
Pierre Kraemer committed
231

Pierre Kraemer's avatar
Pierre Kraemer committed
232
233
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::createHole(Dart d)
untereiner's avatar
untereiner committed
234
{
235
	assert(!isBoundaryFace(d)) ;
236
	Algo::Topo::boundaryMarkOrbit<3,VOLUME>(*this, d) ;
untereiner's avatar
untereiner committed
237
238
}

239
240
/*! @name Topological Operators
 *  Topological operations on 3-maps
untereiner's avatar
untereiner committed
241
242
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
243
244
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::splitVertex(std::vector<Dart>& vd)
untereiner's avatar
untereiner committed
245
{
246
247
248
249
250
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
	//assert(checkPathAroundVertex(vd)) ;

	//bool boundE = false;

	Dart prev = vd.front();	//elt 0

	Dart db1 = NIL;
	if(isBoundaryFace(this->phi2(prev)))
		db1 = this->phi2(phi3(this->phi1(this->phi2(prev))));

	Dart fs = this->phi_1(this->phi2(this->phi_1(prev)));	//first side

	ParentMap::splitVertex(prev, this->phi2(fs));

	for(unsigned int i = 1; i < vd.size(); ++i)
	{
		prev = vd[i];

		Dart fs = this->phi_1(this->phi2(this->phi_1(prev)));	//first side

		ParentMap::splitVertex(prev, this->phi2(fs));

		Dart d1 = this->phi_1(this->phi2(this->phi_1(vd[i-1])));
		Dart d2 = this->phi1(this->phi2(vd[i]));

		phi3sew(d1, d2);
	}

	Dart db2 = NIL;
	if(isBoundaryFace(this->phi2(this->phi_1(prev))))
		db2 = this->phi2(phi3(this->phi2(this->phi_1(prev))));

	if(db1 != NIL && db2 != NIL)
	{
		ParentMap::splitVertex(db1, db2);
		phi3sew(this->phi1(this->phi2(db2)), this->phi_1(phi3(this->phi2(db2))));
		phi3sew(this->phi1(this->phi2(db1)), this->phi_1(phi3(this->phi2(db1))));
	}
	else
	{
		Dart dbegin = this->phi1(this->phi2(vd.front()));
		Dart dend = this->phi_1(this->phi2(this->phi_1(vd.back())));
		phi3sew(dbegin, dend);
	}

	return this->phi_1(this->phi2(this->phi_1(prev)));
292
293
}

Pierre Kraemer's avatar
Pierre Kraemer committed
294
295
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::deleteVertex(Dart d)
296
{
297
298
299
300
301
302
303
	//if(isBoundaryVertex(d))
	//	return NIL ;

	// Save the darts around the vertex
	// (one dart per face should be enough)
	std::vector<Dart> fstoretmp;
	fstoretmp.reserve(128);
304
	this->template foreach_dart_of_orbit<VERTEX>(d, [&] (Dart it) { fstoretmp.push_back(it); });
305
306
307
308

	 // just one dart per face
	std::vector<Dart> fstore;
	fstore.reserve(128);
309
	DartMarker<Map3<MAP_IMPL> > mf(*this);
310
311
312
313
	for(unsigned int i = 0; i < fstoretmp.size(); ++i)
	{
		if(!mf.isMarked(fstoretmp[i]))
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
314
			mf.template markOrbit<FACE>(fstoretmp[i]);
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
			fstore.push_back(fstoretmp[i]);
		}
	}

	std::cout << "nb faces " << fstore.size() << std::endl;

	Dart res = NIL ;
	for(std::vector<Dart>::iterator it = fstore.begin() ; it != fstore.end() ; ++it)
	{
		Dart fit = *it ;
		Dart end = this->phi_1(fit) ;
		fit = this->phi1(fit) ;

		if(fit == end)
		{
			std::cout << " mmmmmmmmmmmmmmmmmmmmmerrrrrrrrrrrrrrrrrde !!!!!!!!!!!! " << std::endl;

//			Dart d2 = phi2(fit) ;
//			Dart d23 = phi3(d2) ;
//			Dart d3 = phi3(fit) ;
//			Dart d32 = phi2(d3) ;
//
//			//phi3unsew()
//			phi3sew(d3,23);
//
//			fit = phi_1(fit);
//
//			d2 = phi2(fit) ;
//			d23 = phi3(d2) ;
//			d3 = phi3(fit) ;
//			d32 = phi2(d3) ;
//			phi3sew(d3,23);

//			Map2::deleteCC(fit);
		}
		else
		{
			while(fit != end)
			{
				Dart d2 = this->phi2(fit) ;
				Dart d3 = phi3(fit) ;
				Dart d32 = this->phi2(d3) ;

				if(res == NIL)
					res = d2 ;

				this->phi2unsew(d2) ;
				this->phi2unsew(d32) ;
				this->phi2sew(d2, d32) ;
				this->phi2sew(fit, d3) ;

				fit = this->phi1(fit) ;
			}
		}
	}

	ParentMap::deleteCC(d) ;

	return res ;
374
375
}

Pierre Kraemer's avatar
Pierre Kraemer committed
376
377
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::cutEdge(Dart d)
378
{
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
	Dart prev = d;
	Dart dd = this->alpha2(d);
	Dart nd = ParentMap::cutEdge(d);

	while (dd != d)
	{
		prev = dd;
		dd = alpha2(dd);

		ParentMap::cutEdge(prev);

		Dart d3 = phi3(prev);
		phi3unsew(prev);
		phi3sew(prev, this->phi1(d3));
		phi3sew(d3, this->phi1(prev));
	}

	Dart d3 = phi3(d);
	phi3unsew(d);
	phi3sew(d, this->phi1(d3));
	phi3sew(d3, this->phi1(d));

	return nd;
402
403
}

Pierre Kraemer's avatar
Pierre Kraemer committed
404
405
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::uncutEdge(Dart d)
406
{
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
	if(vertexDegree(this->phi1(d)) == 2)
	{
		Dart prev = d ;
		phi3unsew(this->phi1(prev)) ;

		Dart dd = d;
		do
		{
			prev = dd;
			dd = this->alpha2(dd);

			phi3unsew(this->phi2(prev)) ;
			phi3unsew(this->phi2(this->phi1(prev))) ;
			ParentMap::uncutEdge(prev);
			phi3sew(dd, this->phi2(prev));
		} while (dd != d) ;

		return true;
	}
	return false;
427
428
}

Pierre Kraemer's avatar
Pierre Kraemer committed
429
430
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::deleteEdgePreCond(Dart d)
431
{
432
433
434
435
436
	unsigned int nb1 = vertexDegree(d);
	unsigned int nb2 = vertexDegree(this->phi1(d));
	return (nb1!=2) && (nb2!=2);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
437
438
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::deleteEdge(Dart d)
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
{
	assert(deleteEdgePreCond(d));

	if(isBoundaryEdge(d))
		return NIL ;

	Dart res = NIL ;
	Dart dit = d ;
	do
	{
		Dart fit = dit ;
		Dart end = fit ;
		fit = this->phi1(fit) ;
		while(fit != end)
		{
			Dart d2 = this->phi2(fit) ;
			Dart d3 = phi3(fit) ;
			Dart d32 = this->phi2(d3) ;

			if(res == NIL)
				res = d2 ;

			this->phi2unsew(d2) ;
			this->phi2unsew(d32) ;
			this->phi2sew(d2, d32) ;
			this->phi2sew(fit, d3) ;

			fit = this->phi1(fit) ;
		}
		dit = this->alpha2(dit) ;
	} while(dit != d) ;

	ParentMap::deleteCC(d) ;

	return res ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
476
477
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::collapseEdge(Dart d, bool delDegenerateVolumes)
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
{
	Dart resV = NIL;
	Dart dit = d;

	std::vector<Dart> darts;
	do
	{
		darts.push_back(dit);
		dit = this->alpha2(dit);
	} while(dit != d);

	for (std::vector<Dart>::iterator it = darts.begin(); it != darts.end(); ++it)
	{
		Dart x = this->phi2(this->phi_1(*it));

		Dart resCV = NIL;

		if(!isBoundaryFace(this->phi2(this->phi1(*it))))
			resCV = phi3(this->phi2(this->phi1(*it)));
		else if(!isBoundaryFace(this->phi2(this->phi_1(*it))))
			resCV = phi3(this->phi2(this->phi_1(*it)));

		resV = ParentMap::collapseEdge(*it, true);
		if (delDegenerateVolumes)
			if(collapseDegeneretedVolume(x) && resCV != NIL)
				resV = resCV;
	}

	return resV;
}


Pierre Kraemer's avatar
Pierre Kraemer committed
510
511
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::splitFacePreCond(Dart d, Dart e)
512
513
514
515
{
	return (d != e && this->sameOrientedFace(d, e)) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
516
517
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::splitFace(Dart d, Dart e)
518
519
520
521
522
523
524
525
526
527
528
529
530
531
{
//	assert(d != e && sameOrientedFace(d, e)) ;
	assert(splitFacePreCond(d,e));

	Dart dd = this->phi1(phi3(d));
	Dart ee = this->phi1(phi3(e));

	ParentMap::splitFace(d, e);
	ParentMap::splitFace(dd, ee);

	phi3sew(this->phi_1(d), this->phi_1(ee));
	phi3sew(this->phi_1(e), this->phi_1(dd));
}

Pierre Kraemer's avatar
Pierre Kraemer committed
532
533
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::mergeFaces(Dart d)
534
535
536
537
538
539
540
541
542
543
544
545
546
{
	assert(edgeDegree(d)==2);

	Dart dd = phi3(d);

	phi3unsew(d);
	phi3unsew(dd);

	//use code of mergesFaces to override the if(isBoundaryEdge)
	//we have to merge the faces if the face is linked to a border also
//	Map2::mergeFaces(d);
	Dart e = this->phi2(d) ;
	this->phi2unsew(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
547
548
549
	Map1<MAP_IMPL>::mergeCycles(d, this->phi1(e)) ;
	Map1<MAP_IMPL>::splitCycle(e, this->phi1(d)) ;
	Map1<MAP_IMPL>::deleteCycle(d) ;
550
551
552
//	ParentMap::mergeFaces(dd);
	e = this->phi2(dd) ;
	this->phi2unsew(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
553
554
555
	Map1<MAP_IMPL>::mergeCycles(dd, this->phi1(e)) ;
	Map1<MAP_IMPL>::splitCycle(e, this->phi1(dd)) ;
	Map1<MAP_IMPL>::deleteCycle(dd);
556
557
558
559

	return true;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
560
561
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::collapseFace(Dart d, bool delDegenerateVolumes)
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
{
	Dart resV = NIL;
	Dart stop = this->phi_1(d);
	Dart dit = d;
	std::vector<Dart> vd;
	vd.reserve(32);

	do
	{
		vd.push_back(this->alpha2(dit));
		dit = this->phi1(dit);
	}
	while(dit != stop);

	for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
		resV = Map3::collapseEdge(*it, delDegenerateVolumes);

	return resV;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
582
583
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::collapseDegeneretedVolume(Dart d)
584
585
586
587
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
{
	Dart e1 = d;
	Dart e2 = this->phi2(d);

	do
	{
		if (e1 != this->phi2(e2))
			return false;
		e1 = this->phi1(e1);
		e2 = this->phi_1(e2);
	}while (e1 != d);

	if (e2 != this->phi2(d))
		return false;

	// degenerated:
	do
	{
		Dart f1 = phi3(e1);
		Dart f2 = phi3(e2);
		phi3unsew(e1);
		phi3unsew(e2);
		phi3sew(f1,f2);
		e1 = this->phi1(e1);
		e2 = this->phi_1(e2);
	}while (e1 != d);

	ParentMap::deleteCC(d) ;
	return true;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
615
616
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::sewVolumesPreCond(Dart d, Dart e)
617
618
619
620
{
	return (this->faceDegree(d) == this->faceDegree(e));
}

Pierre Kraemer's avatar
Pierre Kraemer committed
621
622
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::sewVolumes(Dart d, Dart e, bool withBoundary)
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
{
	assert(sewVolumesPreCond(d,e));

	// if sewing with fixed points
	if (!withBoundary)
	{
		assert(phi3(d) == d && phi3(e) == e) ;
		Dart fitD = d ;
		Dart fitE = e ;
		do
		{
			phi3sew(fitD, fitE) ;
			fitD = this->phi1(fitD) ;
			fitE = this->phi_1(fitE) ;
		} while(fitD != d) ;
		return ;
	}

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

	Dart fitD = dd ;
	Dart fitE = ee ;
	do
	{
		Dart fitD2 = this->phi2(fitD) ;
		Dart fitE2 = this->phi2(fitE) ;
		if(fitD2 != fitE)
		{
			this->phi2unsew(fitD) ;
			this->phi2unsew(fitE) ;
			this->phi2sew(fitD2, fitE2) ;
			this->phi2sew(fitD, fitE) ;
		}
		phi3unsew(fitD) ;
		phi3unsew(fitE) ;
		fitD = this->phi1(fitD) ;
		fitE = this->phi_1(fitE) ;
	} while(fitD != dd) ;
	ParentMap::deleteCC(dd) ;

	fitD = d ;
	fitE = e ;
	do
	{
		phi3sew(fitD, fitE) ;
		fitD = this->phi1(fitD) ;
		fitE = this->phi_1(fitE) ;
	} while(fitD != d) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
674
675
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::unsewVolumesPreCond(Dart d)
676
677
678
679
{
	return (!this->isBoundaryFace(d)) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
680
681
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::unsewVolumes(Dart d, bool withBoundary)
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
{
	assert(unsewVolumesPreCond(d)) ;

	if (!withBoundary)
	{
		Dart fitD = d ;
		do
		{
			phi3unsew(fitD) ;
			fitD = this->phi1(fitD) ;
		} while(fitD != d) ;
		return ;
	}

	unsigned int nbE = this->faceDegree(d) ;
	Dart d3 = phi3(d);

	Dart b1 = newBoundaryCycle(nbE) ;
	Dart b2 = newBoundaryCycle(nbE) ;

	Dart fit1 = d ;
	Dart fit2 = d3 ;
	Dart fitB1 = b1 ;
	Dart fitB2 = b2 ;
	do
	{
		Dart f = findBoundaryFaceOfEdge(fit1) ;
		if(f != NIL)
		{
			Dart f2 = this->phi2(f) ;
			this->phi2unsew(f) ;
			this->phi2sew(fitB1, f) ;
			this->phi2sew(fitB2, f2) ;
		}
		else
			this->phi2sew(fitB1, fitB2) ;

		phi3unsew(fit1) ;
		phi3sew(fit1, fitB1) ;
		phi3sew(fit2, fitB2) ;

		fit1 = this->phi1(fit1) ;
		fit2 = this->phi_1(fit2) ;
		fitB1 = this->phi_1(fitB1) ;
		fitB2 = this->phi1(fitB2) ;
	} while(fitB1 != b1) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
730
731
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::mergeVolumes(Dart d, bool deleteFace)
732
{
Pierre Kraemer's avatar
Pierre Kraemer committed
733
	if(!Map3<MAP_IMPL>::isBoundaryFace(d))
734
735
736
737
738
739
740
	{
		ParentMap::mergeVolumes(d, phi3(d), deleteFace); // merge the two volumes along common face
		return true ;
	}
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
741
742
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::splitVolume(std::vector<Dart>& vd)
743
744
745
746
747
748
749
750
751
{
	//assert(checkSimpleOrientedPath(vd)) ;

	Dart e = vd.front();
	Dart e2 = this->phi2(e);

	ParentMap::splitSurface(vd, true, true);

	//sew the two connected components
Pierre Kraemer's avatar
Pierre Kraemer committed
752
	Map3<MAP_IMPL>::sewVolumes(this->phi2(e), this->phi2(e2), false);
753
754
}

Pierre Kraemer's avatar
Pierre Kraemer committed
755
756
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::splitVolumeWithFace(std::vector<Dart>& vd, Dart d)
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
{
	assert(vd.size() == this->faceDegree(d));

	// deconnect edges around the path
	// sew the given face into the paths
	Dart dit = d;
	for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
	{
		Dart it2 = this->phi2(*it);
		ParentMap::unsewFaces(*it, false) ;

		ParentMap::sewFaces(*it, dit, false);
		ParentMap::sewFaces(it2, phi3(dit), false);

		dit = this->phi_1(dit);
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
775
776
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::collapseVolume(Dart d, bool delDegenerateVolumes)
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
{
	Dart resV = NIL;
	std::vector<Dart> vd;
	vd.reserve(32);

	vd.push_back(d);
	vd.push_back(this->alpha2(this->phi1(d)));
	vd.push_back(this->alpha2(this->phi_1(this->phi2(this->phi1(d)))));

//	Traversor3WF<Map3> tra(*this, phi1(d));
//	for(Dart dit = tra.begin() ; dit != tra.end() ; dit = tra.next())
//	{
//		vd.push_back(alpha2(dit));
//	}
//	vd.pop_back();

	for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
794
		resV = Map3<MAP_IMPL>::collapseEdge(*it, delDegenerateVolumes);
795
796
797
798

	return resV;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
799
800
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::faceToEdge(Dart d)
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
{
	Dart dc = this->phi2(this->phi1(d));
	Dart dc1 = this->phi_1(d);
	Dart dc2 = this->phi1(this->phi2(dc));

	ParentMap::unsewFaces(dc, false);
	ParentMap::unsewFaces(dc1, false);
	ParentMap::unsewFaces(dc2, false);

	unsewFaces(phi3(dc), false);
	unsewFaces(phi3(dc1), false);
	unsewFaces(phi3(dc2), false);

	return dc;
}

/*! @name Topological Queries
 *  Return or set various topological information
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
821
822
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::sameVertex(Dart d, Dart e) const
823
{
824
	DartMarkerStore< Map3<MAP_IMPL> > mv(*this);	// Lock a marker
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854

	std::vector<Dart> darts;	// Darts that are traversed
	darts.reserve(256);
	darts.push_back(d);			// Start with the dart d
	mv.mark(d);

	for(unsigned int i = 0; i < darts.size(); ++i)
	{
		if(darts[i] == e)
			return true;

		// add phi21 and phi23 successor if they are not marked yet
		Dart d2 = this->phi2(darts[i]);
		Dart d21 = this->phi1(d2); // turn in volume
		Dart d23 = phi3(d2); // change volume

		if(!mv.isMarked(d21))
		{
			darts.push_back(d21);
			mv.mark(d21);
		}
		if(!mv.isMarked(d23))
		{
			darts.push_back(d23);
			mv.mark(d23);
		}
	}
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
855
856
template <typename MAP_IMPL>
unsigned int Map3<MAP_IMPL>::vertexDegree(Dart d) const
857
858
859
{
	unsigned int count = 0;

Pierre Kraemer's avatar
Pierre Kraemer committed
860
	Traversor3VE<Map3<MAP_IMPL> > trav3VE(*this, d);
861
862
863
864
865
866
	for(Dart dit = trav3VE.begin() ; dit != trav3VE.end() ; dit = trav3VE.next())
		++count;

	return count;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
867
868
template <typename MAP_IMPL>
int Map3<MAP_IMPL>::checkVertexDegree(Dart d, unsigned int vd) const
869
870
871
{
	unsigned int count = 0;

Pierre Kraemer's avatar
Pierre Kraemer committed
872
	Traversor3VE<Map3<MAP_IMPL> > trav3VE(*this, d);
873
874
875
876
877
878
879
	Dart dit = trav3VE.begin();
	for( ; (count <= vd) && (dit != trav3VE.end()) ; dit = trav3VE.next())
		++count;

	return count - vd;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
880
881
template <typename MAP_IMPL>
unsigned int Map3<MAP_IMPL>::vertexDegreeOnBoundary(Dart d) const
882
883
884
885
886
{
	assert(Map3::isBoundaryVertex(d));
	return ParentMap::vertexDegree(d);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
887
888
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::isBoundaryVertex(Dart d) const
889
{
890
	DartMarkerStore< Map3<MAP_IMPL> > mv(*this);	// Lock a marker
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920

	std::vector<Dart> darts;	// Darts that are traversed
	darts.reserve(256);
	darts.push_back(d);			// Start with the dart d
	mv.mark(d);

	for(unsigned int i = 0; i < darts.size(); ++i)
	{
		if(this->isBoundaryMarked3(darts[i]))
			return true ;

		//add phi21 and phi23 successor if they are not marked yet
		Dart d2 = this->phi2(darts[i]);
		Dart d21 = this->phi1(d2); // turn in volume
		Dart d23 = phi3(d2); // change volume

		if(!mv.isMarked(d21))
		{
			darts.push_back(d21);
			mv.mark(d21);
		}
		if(!mv.isMarked(d23))
		{
			darts.push_back(d23);
			mv.mark(d23);
		}
	}
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
921
922
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::findBoundaryFaceOfVertex(Dart d) const
923
{
924
	DartMarkerStore< Map3<MAP_IMPL> > mv(*this);	// Lock a marker
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

	std::vector<Dart> darts;	// Darts that are traversed
	darts.reserve(256);
	darts.push_back(d);			// Start with the dart d
	mv.mark(d);

	for(unsigned int i = 0; i < darts.size(); ++i)
	{
		if(this->isBoundaryMarked3(darts[i]))
			return darts[i];

		//add phi21 and phi23 successor if they are not marked yet
		Dart d2 = this->phi2(darts[i]);
		Dart d21 = this->phi1(d2); // turn in volume
		Dart d23 = phi3(d2); // change volume

		if(!mv.isMarked(d21))
		{
			darts.push_back(d21);
			mv.mark(d21);
		}
		if(!mv.isMarked(d23))
		{
			darts.push_back(d23);
			mv.mark(d23);
		}
	}
	return NIL ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
955
956
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::sameOrientedEdge(Dart d, Dart e) const
957
958
959
960
961
962
963
964
965
966
967
{
	Dart it = d;
	do
	{
		if(it == e)
			return true;
		it = alpha2(it);
	} while (it != d);
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
968
969
template <typename MAP_IMPL>
inline bool Map3<MAP_IMPL>::sameEdge(Dart d, Dart e) const
970
971
972
973
{
	return sameOrientedEdge(d, e) || sameOrientedEdge(this->phi2(d), e) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
974
975
template <typename MAP_IMPL>
unsigned int Map3<MAP_IMPL>::edgeDegree(Dart d) const
976
977
978
979
980
{
	unsigned int deg = 0;
	Dart it = d;
	do
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
981
		if(!this->template isBoundaryMarked<3>(it))
982
983
984
985
986
987
			++deg;
		it = alpha2(it);
	} while(it != d);
	return deg;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
988
989
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::isBoundaryEdge(Dart d) const
990
991
992
993
{
	Dart it = d;
	do
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
994
		if(this->template isBoundaryMarked<3>(it))
995
996
997
998
999
1000
			return true ;
		it = alpha2(it);
	} while(it != d);
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1001
1002
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::findBoundaryFaceOfEdge(Dart d) const
1003
1004
1005
1006
{
	Dart it = d;
	do
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
1007
		if (this->template isBoundaryMarked<3>(it))
1008
1009
1010
1011
1012
1013
			return it ;
		it = alpha2(it);
	} while(it != d);
	return NIL ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1014
1015
template <typename MAP_IMPL>
inline bool Map3<MAP_IMPL>::sameFace(Dart d, Dart e) const
1016
1017
1018
1019
{
	return ParentMap::sameOrientedFace(d, e) || ParentMap::sameOrientedFace(phi3(d), e) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1020
1021
template <typename MAP_IMPL>
inline bool Map3<MAP_IMPL>::isBoundaryFace(Dart d) const
1022
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1023
	return this->template isBoundaryMarked<3>(d) || this->template isBoundaryMarked<3>(phi3(d));
1024
1025
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1026
template <typename MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
1027
bool Map3<MAP_IMPL>::isVolumeIncidentToBoundary(Dart d) const
1028
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1029
	Traversor3WF<Map3<MAP_IMPL> > tra(*this, d);
1030
1031
	for(Dart dit = tra.begin() ; dit != tra.end() ; dit = tra.next())
	{
untereiner's avatar
untereiner committed
1032
		if(this->template isBoundaryMarked<3>(phi3(dit)))
1033
1034
1035
1036
1037
			return true ;
	}
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1038
1039
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::hasBoundaryEdge(Dart d) const
1040
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1041
	Traversor3WE<Map3<MAP_IMPL> > tra(*this, d);
1042
1043
1044
1045
1046
1047
1048
1049
1050
	for(Dart dit = tra.begin() ; dit != tra.end() ; dit = tra.next())
	{
		if(isBoundaryEdge(dit))
			return true;
	}

	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1051
1052
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::check() const
1053
1054
{
	std::cout << "Check: topology begin" << std::endl;
1055
	DartMarkerStore< Map3<MAP_IMPL> > m(*this);
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
	for(Dart d = Map3::begin(); d != Map3::end(); Map3::next(d))
	{
		Dart d3 = phi3(d);
		if (phi3(d3) != d) // phi3 involution ?
		{
			std::cout << "Check: phi3 is not an involution" << std::endl;
			return false;
		}

		if(this->phi1(d3) != phi3(this->phi_1(d)))
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1067
			if(this->template isBoundaryMarked<3>(d))
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
				std::cout << "Boundary case - Check: phi3 , faces are not entirely sewn" << std::endl;
			else
				std::cout << "Check: phi3 , faces are not entirely sewn" << std::endl;
			std::cout << "face : " << this->phi1(d3) << " and face = " << phi3(this->phi_1(d)) << std::endl;
			return false;
		}

		Dart d2 = this->phi2(d);
		if (this->phi2(d2) != d) // phi2 involution ?
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1078
			if(this->template isBoundaryMarked<3>(d))
1079
1080
1081
1082
1083
1084
1085
1086
				std::cout << "Boundary case - ";
			std::cout << "Check: phi2 is not an involution" << std::endl;
			return false;
		}

		Dart d1 = this->phi1(d);
		if (this->phi_1(d1) != d) // phi1 a une image correcte ?
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1087
			if(this->template isBoundaryMarked<3>(d))
1088
1089
1090
1091
1092
1093
1094
				std::cout << "Boundary case - ";
			std::cout << "Check: unconsistent phi_1 link" << std::endl;
			return false;
		}

		if (m.isMarked(d1)) // phi1 a un seul antécédent ?
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1095
			if(this->template isBoundaryMarked<3>(d))
1096
1097
1098
1099
1100
1101
1102
1103
				std::cout << "Boundary case - ";
			std::cout << "Check: dart with two phi1 predecessors" << std::endl;
			return false;
		}
		m.mark(d1);

		if (d1 == d)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1104
			if(this->template isBoundaryMarked<3>(d))
1105
1106
1107
1108
1109
1110
				std::cout << "Boundary case - ";
			std::cout << "Check: (warning) face loop (one edge)" << std::endl;
		}

		if (this->phi1(d1) == d)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1111
			if(this->template isBoundaryMarked<3>(d))
1112
1113
1114
1115
1116
1117
				std::cout << "Boundary case - ";
			std::cout << "Check: (warning) face with only two edges" << std::endl;
		}

		if (this->phi2(d1) == d)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1118
			if(this->template isBoundaryMarked<3>(d))
1119
1120
1121
1122
1123
1124
				std::cout << "Boundary case - ";
			std::cout << "Check: (warning) dandling edge (phi2)" << std::endl;
		}

		if (phi3(d1) == d)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1125
			if(this->template isBoundaryMarked<3>(d))
1126
1127
1128
1129
1130
1131
1132
1133
1134
				std::cout << "Boundary case - ";
			std::cout << "Check: (warning) dandling edge (phi3)" << std::endl;
		}
	}

	for(Dart d = this->begin(); d != this->end(); this->next(d))
	{
		if (!m.isMarked(d)) // phi1 a au moins un antécédent ?
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1135
			if(this->template isBoundaryMarked<3>(d))
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
				std::cout << "Boundary case - ";
			std::cout << "Check: dart with no phi1 predecessor" << std::endl;
			return false;
		}
	}

	std::cout << "Check: topology ok" << std::endl;

	return true;
}

/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
1151
template <typename MAP_IMPL>
1152
1153
template <unsigned int ORBIT, typename FUNC>
void Map3<MAP_IMPL>::foreach_dart_of_orbit(Cell<ORBIT> c, FUNC f, unsigned int thread) const
1154
{
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
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
1195
	switch(ORBIT)
	{
		case DART:		f(c); break;
		case VERTEX: 	foreach_dart_of_vertex(c, f, thread); break;
		case EDGE: 		foreach_dart_of_edge(c, f, thread); break;
		case FACE: 		foreach_dart_of_face(c, f, thread); break;
		case VOLUME: 	foreach_dart_of_volume(c, f, thread); break;
		case VERTEX1: 	foreach_dart_of_vertex1(c, f, thread); break;
		case EDGE1: 	foreach_dart_of_edge1(c, f, thread); break;
		case VERTEX2: 	foreach_dart_of_vertex2(c, f, thread); break;
		case EDGE2:		foreach_dart_of_edge2(c, f, thread); break;
		case FACE2:		foreach_dart_of_face2(c, f, thread); break;
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, typename FUNC>
void Map3<MAP_IMPL>::foreach_dart_of_orbit(Cell<ORBIT> c, FUNC& f, unsigned int thread) const
{
	switch(ORBIT)
	{
		case DART:		f(c); break;
		case VERTEX: 	foreach_dart_of_vertex(c, f, thread); break;
		case EDGE: 		foreach_dart_of_edge(c, f, thread); break;
		case FACE: 		foreach_dart_of_face(c, f, thread); break;
		case VOLUME: 	foreach_dart_of_volume(c, f, thread); break;
		case VERTEX1: 	foreach_dart_of_vertex1(c, f, thread); break;
		case EDGE1: 	foreach_dart_of_edge1(c, f, thread); break;
		case VERTEX2: 	foreach_dart_of_vertex2(c, f, thread); break;
		case EDGE2:		foreach_dart_of_edge2(c, f, thread); break;
		case FACE2:		foreach_dart_of_face2(c, f, thread); break;
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
}

template <typename MAP_IMPL>
template <typename FUNC>
void Map3<MAP_IMPL>::foreach_dart_of_vertex(Dart d, FUNC& f, unsigned int thread) const
{
	DartMarkerStore< Map3<MAP_IMPL> > mv(*this, thread);	// Lock a marker
1196
1197
1198
1199
1200
1201

	std::vector<Dart> darts;	// Darts that are traversed
	darts.reserve(256);
	darts.push_back(d);			// Start with the dart d
	mv.mark(d);

1202
	for(unsigned int i = 0; i < darts.size(); ++i)
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
	{
		// add phi21 and phi23 successor if they are not marked yet
		Dart d2 = this->phi2(darts[i]);
		Dart d21 = this->phi1(d2); // turn in volume
		Dart d23 = phi3(d2); // change volume

		if(!mv.isMarked(d21))
		{
			darts.push_back(d21);
			mv.mark(d21);
		}
		if(!mv.isMarked(d23))
		{
			darts.push_back(d23);
			mv.mark(d23);
		}

1220
		f(darts[i]);
1221
1222
1223
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1224
template <typename MAP_IMPL>
1225
1226
template <typename FUNC>
inline void Map3<MAP_IMPL>::foreach_dart_of_edge(Dart d, FUNC& f, unsigned int thread) const
1227
1228
1229
1230
{
	Dart it = d;
	do
	{
1231
		ParentMap::foreach_dart_of_edge(it, f, thread);
1232
1233
1234
1235
		it = alpha2(it);
	} while (it != d);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1236
template <typename MAP_IMPL>
1237
1238
template <typename FUNC>
inline void Map3<MAP_IMPL>::foreach_dart_of_face(Dart d, FUNC& f, unsigned int thread) const
1239
{
1240
1241
	ParentMap::foreach_dart_of_face(d, f, thread);
	ParentMap::foreach_dart_of_face(phi3(d), f, thread);
1242
1243
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1244
template <typename MAP_IMPL>
1245
1246
template <typename FUNC>
inline void Map3<MAP_IMPL>::foreach_dart_of_volume(Dart d, FUNC& f, unsigned int thread) const
1247
{
1248
	ParentMap::foreach_dart_of_cc(d, f, thread);
1249
1250
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1251
template <typename MAP_IMPL>
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
template <typename FUNC>
inline void Map3<MAP_IMPL>::foreach_dart_of_vertex1(Dart d, FUNC& f, unsigned int thread) const
{
	ParentMap::ParentMap::foreach_dart_of_vertex(d, f, thread);
}

template <typename MAP_IMPL>
template <typename FUNC>
inline void Map3<MAP_IMPL>::foreach_dart_of_edge1(Dart d, FUNC& f, unsigned int thread) const
{
	ParentMap::ParentMap::foreach_dart_of_edge(d, f, thread);
}

template <typename MAP_IMPL>
template <typename FUNC>
inline void Map3<MAP_IMPL>::foreach_dart_of_vertex2(Dart d, FUNC& f, unsigned int thread) const
{
	ParentMap::foreach_dart_of_vertex(d, f, thread);
}

template <typename MAP_IMPL>
template <typename FUNC>
inline void Map3<MAP_IMPL>::foreach_dart_of_edge2(Dart d, FUNC& f, unsigned int thread) const
1275
{
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
	ParentMap::foreach_dart_of_edge(d, f, thread);
}

template <typename MAP_IMPL>
template <typename FUNC>
inline void Map3<MAP_IMPL>::foreach_dart_of_face2(Dart d, FUNC& f, unsigned int thread) const
{
	ParentMap::foreach_dart_of_face(d, f, thread);
}

template <typename MAP_IMPL>
template <typename FUNC>
void Map3<MAP_IMPL>::foreach_dart_of_cc(Dart d, FUNC& f, unsigned int thread) const
{
	DartMarkerStore< Map3<MAP_IMPL> > mv(*this,thread);	// Lock a marker
1291
1292
1293
1294
1295
1296

	std::vector<Dart> darts;	// Darts that are traversed
	darts.reserve(1024);
	darts.push_back(d);			// Start with the dart d
	mv.mark(d);

1297
	for(unsigned int i = 0; i < darts.size(); ++i)
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
	{
		// add all successors if they are not marked yet
		Dart d2 = this->phi1(darts[i]); // turn in face
		Dart d3 = this->phi2(darts[i]); // change face
		Dart d4 = phi3(darts[i]); // change volume

		if (!mv.isMarked(d2))
		{
			darts.push_back(d2);
			mv.mark(d2);
		}
		if (!mv.isMarked(d3))
		{
			darts.push_back(d2);
			mv.mark(d2);
		}
		if (!mv.isMarked(d4))
		{
			darts.push_back(d4);
			mv.mark(d4);
		}

1320
		f(darts[i]);
1321
1322
1323
1324
1325
1326
1327
	}
}

/*! @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
1328
1329
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::newBoundaryCycle(unsigned int nbE)
1330
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1331
	Dart d = Map1<MAP_IMPL>::newCycle(nbE);
1332
	Algo::Topo::boundaryMarkOrbit<3,FACE>(*this, d);
1333
1334
1335
	return d;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1336
1337
template <typename MAP_IMPL>
unsigned int Map3<MAP_IMPL>::closeHole(Dart d, bool forboundary)
1338
1339
{
	assert(phi3(d) == d);		// Nothing to close
1340
	DartMarkerStore< Map3<MAP_IMPL> > m(*this) ;
1341
1342
1343
1344

	std::vector<Dart> visitedFaces;	// Faces that are traversed
	visitedFaces.reserve(1024) ;
	visitedFaces.push_back(d);		// Start with the face of d
Pierre Kraemer's avatar
Pierre Kraemer committed
1345
	m.template markOrbit<FACE2>(d) ;
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371

	unsigned int count = 0 ;

	// For every face added to the list
	for(unsigned int i = 0; i < visitedFaces.size(); ++i)
	{
		Dart it = visitedFaces[i] ;
		Dart f = it ;

		unsigned int degree = this->faceDegree(f) ;
		Dart b = newBoundaryCycle(degree) ;
		++count ;

		Dart bit = b ;
		do
		{
			Dart e = alpha2(f) ;
			bool found = false ;
			do
			{
				if(phi3(e) == e)
				{
					found = true ;
					if(!m.isMarked(e))
					{
						visitedFaces.push_back(e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1372
						m.template markOrbit<FACE2>(e) ;
1373
1374
					}
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
1375
				else if(this->template isBoundaryMarked<3>(e))
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
				{
					found = true ;
					this->phi2sew(e, bit) ;
				}
				else
					e = alpha2(e) ;
			} while(!found) ;

			phi3sew(f, bit) ;
			bit = this->phi_1(bit) ;
			f = this->phi1(f);
		} while(f != it) ;
	}

	return count ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1393
1394
template <typename MAP_IMPL>
unsigned int Map3<MAP_IMPL>::closeMap()
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
{
	// Search the map for topological holes (fix points of phi3)
	unsigned int nb = 0 ;
	for (Dart d = this->begin(); d != this->end(); this->next(d))
	{
		if (phi3(d) == d)
		{
			++nb ;
			closeHole(d);
		}
	}
	return nb ;
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
1413
1414
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::reverseOrientation()
1415
1416
1417
1418
{

}

Pierre Kraemer's avatar
Pierre Kraemer committed
1419
1420
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::computeDual()
1421
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1422
1423
1424
1425
	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") ;
1426

Pierre Kraemer's avatar
Pierre Kraemer committed
1427
1428
	DartAttribute<Dart, MAP_IMPL> old_phi2 = this->template getAttribute<Dart, DART>("phi2") ;
	DartAttribute<Dart, MAP_IMPL> new_phi2 = this->template addAttribute<Dart, DART>("new_phi2") ;
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538