map3.hpp 40.6 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
26
#include "Topology/generic/traversor3.h"

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
63
template <typename MAP_IMPL>
inline void Map3<MAP_IMPL>::update_topo_shortcuts()
Sylvain Thery's avatar
Sylvain Thery committed
64
{
Pierre Kraemer's avatar
Pierre Kraemer committed
65
66
	ParentMap::update_topo_shortcuts();
//	m_phi3 = getRelation("phi3");
Sylvain Thery's avatar
Sylvain Thery committed
67
68
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
73
74
template <typename MAP_IMPL>
inline Dart Map3<MAP_IMPL>::phi3(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
75
{
Pierre Kraemer's avatar
Pierre Kraemer committed
76
	return MAP_IMPL::template getInvolution<1>(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
77
78
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
103
104
template <typename MAP_IMPL>
inline Dart Map3<MAP_IMPL>::alpha0(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
105
106
107
108
{
	return phi3(d) ;
}

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
127
128
template <typename MAP_IMPL>
inline void Map3<MAP_IMPL>::phi3sew(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
129
{
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	MAP_IMPL::template involutionSew<1>(d,e);
Pierre Kraemer's avatar
Pierre Kraemer committed
131
132
}

Pierre Kraemer's avatar
Pierre Kraemer committed
133
134
template <typename MAP_IMPL>
inline void Map3<MAP_IMPL>::phi3unsew(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
135
{
Pierre Kraemer's avatar
Pierre Kraemer committed
136
	MAP_IMPL::template involutionUnsew<1>(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
137
138
}

139
140
/*! @name Generator and Deletor
 *  To generate or delete volumes in a 3-map
untereiner's avatar
untereiner committed
141
 *************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
142

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

		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
154
		mark.template markOrbit<FACE2>(d) ;
155
156
157
158
159
160
161
162
163
164
165
166
167
168

		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
169
					mark.template markOrbit<FACE2>(ee) ;
170
171
172
173
174
175
176
177
178
179
180
181
182
				}
				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
Pierre Kraemer's avatar
Pierre Kraemer committed
183
	DartMarkerStore<MAP_IMPL> mark(*this);		// Lock a marker
184
185
186
187
188

	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
189
	mark.template markOrbit<FACE2>(d) ;
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

	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
208
				mark.template markOrbit<FACE2>(ee) ;
209
210
211
212
213
214
			}
			e = this->phi1(e) ;
		} while(e != visitedFaces[i]) ;
	}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
217
218
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::fillHole(Dart d)
untereiner's avatar
untereiner committed
219
{
220
221
	assert(isBoundaryFace(d)) ;
	Dart dd = d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
222
	if(!this->template isBoundaryMarked<3>(dd))
223
224
		dd = phi3(dd) ;
	this->template boundaryUnmarkOrbit<VOLUME,3>(dd) ;
untereiner's avatar
untereiner committed
225
}
Pierre Kraemer's avatar
Pierre Kraemer committed
226

Pierre Kraemer's avatar
Pierre Kraemer committed
227
228
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::createHole(Dart d)
untereiner's avatar
untereiner committed
229
{
230
231
	assert(!isBoundaryFace(d)) ;
	this->template boundaryMarkOrbit<VOLUME,3>(d) ;
untereiner's avatar
untereiner committed
232
233
}

234
235
/*! @name Topological Operators
 *  Topological operations on 3-maps
untereiner's avatar
untereiner committed
236
237
 *************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
238
239
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::splitVertex(std::vector<Dart>& vd)
untereiner's avatar
untereiner committed
240
{
241
242
243
244
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
	//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)));
287
288
}

Pierre Kraemer's avatar
Pierre Kraemer committed
289
290
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::deleteVertex(Dart d)
291
{
292
293
294
295
296
297
298
299
300
301
302
303
304
	//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);
	FunctorStore fs(fstoretmp);
	foreach_dart_of_vertex(d, fs);

	 // just one dart per face
	std::vector<Dart> fstore;
	fstore.reserve(128);
Pierre Kraemer's avatar
Pierre Kraemer committed
305
	DartMarker<MAP_IMPL> mf(*this);
306
307
308
309
	for(unsigned int i = 0; i < fstoretmp.size(); ++i)
	{
		if(!mf.isMarked(fstoretmp[i]))
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
310
			mf.template markOrbit<FACE>(fstoretmp[i]);
311
312
313
314
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
			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 ;
370
371
}

Pierre Kraemer's avatar
Pierre Kraemer committed
372
373
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::cutEdge(Dart d)
374
{
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
	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;
398
399
}

Pierre Kraemer's avatar
Pierre Kraemer committed
400
401
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::uncutEdge(Dart d)
402
{
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
	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;
423
424
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
433
434
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::deleteEdge(Dart d)
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
{
	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
472
473
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::collapseEdge(Dart d, bool delDegenerateVolumes)
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
{
	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
506
507
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::splitFacePreCond(Dart d, Dart e)
508
509
510
511
{
	return (d != e && this->sameOrientedFace(d, e)) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
512
513
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::splitFace(Dart d, Dart e)
514
515
516
517
518
519
520
521
522
523
524
525
526
527
{
//	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
528
529
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::mergeFaces(Dart d)
530
531
532
533
534
535
536
537
538
539
540
541
542
{
	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
543
544
545
	Map1<MAP_IMPL>::mergeCycles(d, this->phi1(e)) ;
	Map1<MAP_IMPL>::splitCycle(e, this->phi1(d)) ;
	Map1<MAP_IMPL>::deleteCycle(d) ;
546
547
548
//	ParentMap::mergeFaces(dd);
	e = this->phi2(dd) ;
	this->phi2unsew(dd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
549
550
551
	Map1<MAP_IMPL>::mergeCycles(dd, this->phi1(e)) ;
	Map1<MAP_IMPL>::splitCycle(e, this->phi1(dd)) ;
	Map1<MAP_IMPL>::deleteCycle(dd);
552
553
554
555

	return true;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
556
557
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::collapseFace(Dart d, bool delDegenerateVolumes)
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
{
	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
578
579
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::collapseDegeneretedVolume(Dart d)
580
581
582
583
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
{
	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
611
612
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::sewVolumesPreCond(Dart d, Dart e)
613
614
615
616
{
	return (this->faceDegree(d) == this->faceDegree(e));
}

Pierre Kraemer's avatar
Pierre Kraemer committed
617
618
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::sewVolumes(Dart d, Dart e, bool withBoundary)
619
620
621
622
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
{
	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
670
671
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::unsewVolumesPreCond(Dart d)
672
673
674
675
{
	return (!this->isBoundaryFace(d)) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
676
677
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::unsewVolumes(Dart d, bool withBoundary)
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
{
	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
726
727
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::mergeVolumes(Dart d, bool deleteFace)
728
{
Pierre Kraemer's avatar
Pierre Kraemer committed
729
	if(!Map3<MAP_IMPL>::isBoundaryFace(d))
730
731
732
733
734
735
736
	{
		ParentMap::mergeVolumes(d, phi3(d), deleteFace); // merge the two volumes along common face
		return true ;
	}
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
737
738
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::splitVolume(std::vector<Dart>& vd)
739
740
741
742
743
744
745
746
747
{
	//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
748
	Map3<MAP_IMPL>::sewVolumes(this->phi2(e), this->phi2(e2), false);
749
750
}

Pierre Kraemer's avatar
Pierre Kraemer committed
751
752
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::splitVolumeWithFace(std::vector<Dart>& vd, Dart d)
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
{
	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
771
772
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::collapseVolume(Dart d, bool delDegenerateVolumes)
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
{
	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
790
		resV = Map3<MAP_IMPL>::collapseEdge(*it, delDegenerateVolumes);
791
792
793
794

	return resV;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
795
796
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::faceToEdge(Dart d)
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
{
	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
817
818
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::sameVertex(Dart d, Dart e) const
819
{
Pierre Kraemer's avatar
Pierre Kraemer committed
820
	DartMarkerStore<MAP_IMPL> mv(*this);	// Lock a marker
821
822
823
824
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

	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
851
852
template <typename MAP_IMPL>
unsigned int Map3<MAP_IMPL>::vertexDegree(Dart d) const
853
854
855
{
	unsigned int count = 0;

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

	return count;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
863
864
template <typename MAP_IMPL>
int Map3<MAP_IMPL>::checkVertexDegree(Dart d, unsigned int vd) const
865
866
867
{
	unsigned int count = 0;

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

	return count - vd;
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
883
884
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::isBoundaryVertex(Dart d) const
885
{
Pierre Kraemer's avatar
Pierre Kraemer committed
886
	DartMarkerStore<MAP_IMPL> mv(*this);	// Lock a marker
887
888
889
890
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

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

	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
951
952
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::sameOrientedEdge(Dart d, Dart e) const
953
954
955
956
957
958
959
960
961
962
963
{
	Dart it = d;
	do
	{
		if(it == e)
			return true;
		it = alpha2(it);
	} while (it != d);
	return false;
}

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

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

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

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
1022
1023
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::isBoundaryVolume(Dart d) const
1024
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1025
	Traversor3WF<Map3<MAP_IMPL> > tra(*this, d);
1026
1027
1028
1029
1030
1031
1032
1033
	for(Dart dit = tra.begin() ; dit != tra.end() ; dit = tra.next())
	{
		if(isBoundaryMarked3(phi3(dit)))
			return true ;
	}
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1034
1035
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::hasBoundaryEdge(Dart d) const
1036
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1037
	Traversor3WE<Map3<MAP_IMPL> > tra(*this, d);
1038
1039
1040
1041
1042
1043
1044
1045
1046
	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
1047
1048
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::check() const
1049
1050
{
	std::cout << "Check: topology begin" << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
1051
	DartMarkerStore<MAP_IMPL> m(*this);
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
	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
1063
			if(this->template isBoundaryMarked<3>(d))
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
				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
1074
			if(this->template isBoundaryMarked<3>(d))
1075
1076
1077
1078
1079
1080
1081
1082
				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
1083
			if(this->template isBoundaryMarked<3>(d))
1084
1085
1086
1087
1088
1089
1090
				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
1091
			if(this->template isBoundaryMarked<3>(d))
1092
1093
1094
1095
1096
1097
1098
1099
				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
1100
			if(this->template isBoundaryMarked<3>(d))
1101
1102
1103
1104
1105
1106
				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
1107
			if(this->template isBoundaryMarked<3>(d))
1108
1109
1110
1111
1112
1113
				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
1114
			if(this->template isBoundaryMarked<3>(d))
1115
1116
1117
1118
1119
1120
				std::cout << "Boundary case - ";
			std::cout << "Check: (warning) dandling edge (phi2)" << std::endl;
		}

		if (phi3(d1) == d)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
1121
			if(this->template isBoundaryMarked<3>(d))
1122
1123
1124
1125
1126
1127
1128
1129
1130
				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
1131
			if(this->template isBoundaryMarked<3>(d))
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
				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
1147
1148
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) const
1149
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1150
	DartMarkerStore<MAP_IMPL> mv(*this, thread);	// Lock a marker
1151
1152
1153
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
	bool found = false;					// Last functor return value

	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; !found && i < darts.size(); ++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);
		}

		found = f(darts[i]);
	}
	return found;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1181
1182
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread) const
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
{
	Dart it = d;
	do
	{
		if (ParentMap::foreach_dart_of_edge(it, f, thread))
			return true;
		it = alpha2(it);
	} while (it != d);
	return false;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1194
1195
template <typename MAP_IMPL>
inline bool Map3<MAP_IMPL>::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const
1196
1197
1198
1199
{
	return ParentMap::foreach_dart_of_face(d, f, thread) || ParentMap::foreach_dart_of_face(phi3(d), f, thread);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1200
1201
template <typename MAP_IMPL>
inline bool Map3<MAP_IMPL>::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const
1202
1203
1204
1205
{
	return ParentMap::foreach_dart_of_cc(d, f, thread);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1206
1207
template <typename MAP_IMPL>
bool Map3<MAP_IMPL>::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const
1208
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1209
	DartMarkerStore<MAP_IMPL> mv(*this,thread);	// Lock a marker
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
	bool found = false;					// Last functor return value

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

	for(unsigned int i = 0; !found && i < darts.size(); ++i)
	{
		// 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);
		}

		found = f(darts[i]);
	}
	return found;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1245
1246
template <typename MAP_IMPL>
inline bool Map3<MAP_IMPL>::foreach_dart_of_vertex2(Dart d, FunctorType& f, unsigned int thread) const
1247
1248
1249
1250
{
	return ParentMap::foreach_dart_of_vertex(d, f, thread);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1251
1252
template <typename MAP_IMPL>
inline bool Map3<MAP_IMPL>::foreach_dart_of_edge2(Dart d, FunctorType& f, unsigned int thread) const
1253
1254
1255
1256
{
	return ParentMap::foreach_dart_of_edge(d, f, thread);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1257
1258
template <typename MAP_IMPL>
inline bool Map3<MAP_IMPL>::foreach_dart_of_face2(Dart d, FunctorType& f, unsigned int thread) const
1259
1260
1261
1262
1263
1264
1265
1266
{
	return ParentMap::foreach_dart_of_face(d, f, thread);
}

/*! @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
1267
1268
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::newBoundaryCycle(unsigned int nbE)
1269
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1270
	Dart d = Map1<MAP_IMPL>::newCycle(nbE);
1271
1272
1273
1274
	this->template boundaryMarkOrbit<FACE,3>(d);
	return d;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1275
1276
template <typename MAP_IMPL>
unsigned int Map3<MAP_IMPL>::closeHole(Dart d, bool forboundary)
1277
1278
{
	assert(phi3(d) == d);		// Nothing to close
Pierre Kraemer's avatar
Pierre Kraemer committed
1279
	DartMarkerStore<MAP_IMPL> m(*this) ;
1280
1281
1282
1283

	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
1284
	m.template markOrbit<FACE2>(d) ;
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310

	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
1311
						m.template markOrbit<FACE2>(e) ;
1312
1313
					}
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
1314
				else if(this->template isBoundaryMarked<3>(e))
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
				{
					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
1332
1333
template <typename MAP_IMPL>
unsigned int Map3<MAP_IMPL>::closeMap()
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
{
	// 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
1352
1353
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::reverseOrientation()
1354
1355
1356
1357
{

}

Pierre Kraemer's avatar
Pierre Kraemer committed
1358
1359
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::computeDual()
1360
{
Pierre Kraemer's avatar
Pierre Kraemer committed
1361
1362
1363
1364
	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") ;
1365

Pierre Kraemer's avatar
Pierre Kraemer committed
1366
1367
	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") ;
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
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

	for(Dart d = this->begin(); d != this->end(); this->next(d))
	{
		Dart dd = this->phi2(phi3(d)) ;
		new_phi1[d] = dd ;
		new_phi_1[dd] = d ;

		Dart ddd = this->phi1(phi3(d));
		new_phi2[d] = ddd;
		new_phi2[ddd] = d;
	}

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

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

	this->swapEmbeddingContainers(VERTEX, VOLUME) ;

//	unsigned int count = 0;

//	std::vector<Dart> vbound;

//	//std::cout << "nb faces : " << closeMap() << std::endl;

//	for(Dart d = begin(); d != end(); next(d))
//	{
//		if(isBoundaryMarked3(d) && !isBoundaryMarked3(phi3(d)))
//		{
//			vbound.push_back(d);
//		}
//	}
//
//	std::cout << "vbound size = " << vbound.size() << std::endl;
//
//	for(std::vector<Dart>::iterator it = vbound.begin() ; it != vbound.end() ; ++it)
//	{
//		Dart d = *it;
//		//Dart d3 = phi3(d);
//		phi3unsew(d);
//		//phi3unsew(d3);
//	}
//
//	//std::cout << "nb faces : " << closeMap() << std::endl;
//
//			if(d == 14208)
//			{
//				std::cout << "yeahhhhhhhh" << std::endl;
//				std::cout << "isBoundaryMarked ? " << isBoundaryMarked3(phi3(phi2(14208))) << std::endl;
//
//			}
//
//			//boundaryUnmark<3>(d);
//
//		}
//			if(d == 1569)
//			{
//				std::cout << "d " << std::endl;
//
//				Traversor3WE<Map3> t(*this,d);
//				for(Dart dit = t.begin() ; dit != t.end() ; dit = t.next())
//				{
//					Dart temp = dit;
//					do
//					{
//						if(isBoundaryMarked3(d))
//							std::cout << "d boundary " << std::endl;
//
//						temp = alpha2(temp);
//					}while(temp != dit);
//				}
//
//				if(isBoundaryMarked3(d))
//					std::cout << "d boundary " << std::endl;
//
//				if(isBoundaryMarked3(phi1(d)))
//					std::cout << "phi1(d) boundary " << std::endl;
//
//				if(isBoundaryMarked3(phi_1(d)))
//					std::cout << "phi_1(d) boundary " << std::endl;
//
//				if(isBoundaryMarked3(phi2(d)))
//					std::cout << "phi2(d) boundary " << std::endl;
//
//				if(isBoundaryMarked3(phi3(d)))
//					std::cout << "phi3(d) boundary " << std::endl;
//
//				if(isBoundaryMarked3(phi2(phi3(d))))
//					std::cout << "phi2(phi3(d)) boundary " << std::endl;
//
//				if(isBoundaryMarked3(phi3(phi2(d))))
//					std::cout << "phi3(phi2(d)) boundary " << std::endl;
//
//				if(isBoundaryMarked3(phi1(phi3(d))))
//					std::cout << "phi1(phi3(d)) boundary " << std::endl;
//
//				if(isBoundaryMarked3(phi3(phi1(d))))
//					std::cout << "phi3(phi1(d)) boundary " << std::endl;
//			}
//
//			if(isBoundaryMarked3(d))
//			{
//
//			if(isBoundaryMarked3(d))
//				std::cout << "d = " << d << std::endl;
//
//			if(isBoundaryMarked3(phi3(d)))
//				std::cout << "phi3(d) = " << phi3(d) << std::endl;
//
//			if(isBoundaryMarked3(phi2(d)))
//				std::cout << "phi2(d) = " << phi2(d) << std::endl;
//
//			Dart dit = deleteVertex(phi3(d));
//
//			if(dit == NIL)
//				std::cout << "NILLLLLLLLLLLLLLL" << std::endl;
//
//			++count;
//
//			if(count == 5)
//				return;
//		}
//	}


//	TraversorW<Map3> tW(*this);
//	for(Dart d = tW.begin(); d != tW.end(); d = tW.next())
//	{
//		if(isBoundaryMarked3(d))
//		{
//			boundaryMarkOrbit<VOLUME,3>(d);
//		}
//	}

//	unsigned int count = 0;
//	for(Dart d = begin(); d != end(); next(d))
//	{
//		if(isBoundaryMarked3(d))
//		{
//			++count;
//		}
//	}
//	std::cout << "nb boundar marked = " << count << std::endl;
//
//	count = 0;
//	for(Dart d = begin(); d != end(); next(d))
//	{
//		if(isBoundaryMarked3(d))
//		{
//			++count;
//			std::cout << count << std::endl;
//			//Map3::deleteVolume(d,false);
//			//deleteVolume(d,false);
//		}
//	}


	//std::cout << "Map closed (" << closeMap() <<" boundary faces)" << std::endl;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1531
1532
template <typename MAP_IMPL>
Dart Map3<MAP_IMPL>::explodBorderTopo(Dart d)
1533
1534
1535
1536
1537
{
	std::vector<std::pair<Dart,Dart> > ve;
	ve.reserve(1024);

	//stocke un brin par face du bord
Pierre Kraemer's avatar
Pierre Kraemer committed
1538
	DartMarker<MAP_IMPL> me(*this);
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
	for(Dart dit = this->begin() ; dit != this->end() ; this->next(dit))
	{
		if(this->isBoundaryMarked3(dit) && !me.isMarked(dit))
		{
			ve.push_back(std::make_pair(dit, this->phi2(dit)));
			me.markOrbit<EDGE>(dit);
		}
	}

	//decoud chaque face
	for(std::vector<std::pair<Dart,Dart> >::iterator it = ve.begin() ; it != ve.end() ; ++it)
	{
		ParentMap::unsewFaces((*it).first, false);
	}

	//triangule chaque face
Pierre Kraemer's avatar
Pierre Kraemer committed
1555
	DartMarker<MAP_IMPL> mf(*this);
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
	for(std::vector<std::pair<Dart,Dart> >::iterator it = ve.begin() ; it != ve.end() ; ++it)
	{
		Dart first = (*it).first;
		Dart second = (*it).second;

		if(!mf.isMarked(first))
		{
			unsigned int degf = ParentMap::faceDegree(first);

			Dart dnf = ParentMap::newFace(degf, false);
			Dart dit = first;
			do
			{
				ParentMap::sewFaces(dit, dnf, false);
				this->template copyDartEmbedding<VERTEX>(dnf, this->phi1(dit)) ;
				dit = this->phi1(dit);
				dnf = this->phi_1(dnf);
			} while(dit != first);

			mf.markOrbit<FACE>(first);

			Dart db = dnf;
			Dart d1 = this->phi1(db);
			ParentMap::splitFace(db, d1) ;
			ParentMap::cutEdge(this->phi_1(db)) ;

			Dart x = phi2(this->phi_1(db)) ;
			Dart dd = this->phi1(this->phi1(this->phi1(x)));
			while(dd != x)
			{
				Dart next = this->phi1(dd) ;
				ParentMap::splitFace(dd, this->phi1(x)) ;
				dd = next ;
			}

			Dart cd = this->phi_1(db);
			do
			{
				this->template setDartEmbedding<VERTEX>(this->phi2(cd), this->template getEmbedding<VERTEX>(this->phi1(cd))) ;
				cd = this->phi2(this->phi_1(cd));
			} while(cd != this->phi_1(db));
		}

		if(!mf.isMarked(second))
		{
			mf.markOrbit<FACE>(second);
			unsigned int degf = ParentMap::faceDegree(second);

			Dart dnf = ParentMap::newFace(degf, false);
			Dart dit = second;
			do
			{
				ParentMap::sewFaces(dit, dnf, false);
				this->template copyDartEmbedding<VERTEX>(dnf, this->phi1(dit));
				dit = this->phi1(dit);
				dnf = this->phi_1(dnf);
			} while(dit != second);

			mf.markOrbit<FACE>(second);

			Dart db = dnf;
			Dart d1 = this->phi1(db);
			ParentMap::splitFace(db, d1);
			ParentMap::cutEdge(this->phi_1(db));

			Dart x = this->phi2(this->phi_1(db)) ;
			Dart dd = this->phi1(this->phi1(this->phi1(x)));
			while(dd != x)
			{
				Dart next = this->phi1(dd) ;
				ParentMap::splitFace(dd, this->phi1(x)) ;
				dd = next ;
			}

			Dart cd = this->phi_1(db);
			do
			{
				this->template setDartEmbedding<VERTEX>(this->phi2(cd), this->template getEmbedding<VERTEX>(this->phi1(cd))) ;
				cd = this->phi2(this->phi_1(cd));
			} while(cd != this->phi_1(db));
		}
	}

	//close de chaque nouveau volume
	for(std::vector<std::pair<Dart,Dart> >::iterator it = ve.begin() ; it != ve.end() ; ++it)
	{
		Dart dit1 = this->phi2((*it).first);
		Dart dit2 = this->phi2((*it).second);
Pierre Kraemer's avatar
Pierre Kraemer committed
1644
		Map3<MAP_IMPL>::sewVolumes(dit1, dit2, false);
1645
1646
1647
1648
1649
1650
1651
	}

	this->template setOrbitEmbeddingOnNewCell<VERTEX>(this->phi_1(this->phi2(ve.front().first)));

	return this->phi_1(this->phi2(ve.front().first));
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1652
1653
template <typename MAP_IMPL>
void Map3<MAP_IMPL>::computeDualTest()
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
{
//		unsigned int count = 0;
//		CellMarkerNoUnmark<VERTEX> cv(*this);
//		std::vector<Dart> v;
//		for(Dart d = begin(); d != end(); next(d))
//		{
//			if(!cv.isMarked(d) && isBoundaryMarked3(d))
//			{
//				++count;
//				v.push_back(d);
//				cv.mark(d);
//			}
//		}
//
//		cv.unmarkAll();

//		std::cout << "boundary vertices : " << count << std::endl;

Pierre Kraemer's avatar
Pierre Kraemer committed
1672
1673
1674
1675
	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") ;
1676

Pierre Kraemer's avatar
Pierre Kraemer committed
1677
1678
	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") ;
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700