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

embeddedGMap3.cpp 11.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: http://cgogn.u-strasbg.fr/                                         *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <vector>
#include <algorithm>

#include "Topology/gmap/embeddedGMap3.h"

namespace CGoGN
{

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
void EmbeddedGMap3::sewFaces(Dart d, Dart e)
{
	GMap3::sewFaces(d,e);

	unsigned int vEmb;
	if (isOrbitEmbedded(VERTEX))
	{
		vEmb = getEmbedding(VERTEX, d);
		embedOrbit(VERTEX, d, vEmb) ;

		vEmb = getEmbedding(VERTEX, beta0(d));
		embedOrbit(VERTEX, beta0(d), vEmb) ;
	}

	if (isOrbitEmbedded(EDGE))
	{
		vEmb = getEmbedding(EDGE, d);
		embedOrbit(EDGE, e, vEmb) ;
	}

	if (isOrbitEmbedded(VOLUME))
	{
		vEmb = getEmbedding(VOLUME, d);
		embedOrbit(VOLUME, e, vEmb) ;
	}
}

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
void EmbeddedGMap3::unsewFaces(Dart d)
{
	Dart e = beta2(d);
	GMap3::unsewFaces(d);

	if (isOrbitEmbedded(VERTEX))
	{
		if(!sameVertex(d,e))
		{
			embedNewCell(VERTEX, e);
			copyCell(VERTEX, e, d);
		}

		d = beta0(d);
		e = beta0(e);

		if(!sameVertex(d,e))
		{
			embedNewCell(VERTEX, e);
			copyCell(VERTEX, e, d);
		}
	}

	if (isOrbitEmbedded(EDGE))
	{
		embedNewCell(EDGE, e);
		copyCell(EDGE, e, d);
	}
88
89
90
91
92
93
94
95
96

	if (isOrbitEmbedded(VOLUME))
	{
		if(!sameVolume(d,e))
		{
			embedNewCell(VOLUME, e);
			copyCell(VOLUME, e, d);
		}
	}
97
98
}

99
100
101
102
103
104
105
106
107
108
109
void EmbeddedGMap3::sewVolumes(Dart d, Dart e)
{
	//topological sewing
	GMap3::sewVolumes(d,e);

	//embed the vertex orbits from the oriented face with dart e
	//with vertex orbits value from oriented face with dart d
	if (isOrbitEmbedded(VERTEX))
	{
		unsigned int vEmb1 = EMBNULL ;
		Dart dd = d ;
110
111
		do
		{
112
113
114
115
116
117
118
119
120
121
122
123
			vEmb1 = getEmbedding(VERTEX, dd);
			embedOrbit(VERTEX, dd, vEmb1) ;
			dd = phi1(dd) ;
		} while(dd != d) ;
	}

	//embed the new edge orbit with the old edge orbit value
	//for all the face
	if (isOrbitEmbedded(EDGE))
	{
		unsigned int vEmb1 = EMBNULL ;
		Dart dd = d ;
124
125
126
127
		do
		{
			vEmb1 = getEmbedding(EDGE, dd);
			embedOrbit(EDGE, dd, vEmb1) ;
128
129
130
131
132
133
			dd = phi1(dd) ;
		} while(dd != d) ;
	}

	//embed the face orbit from the volume sewn
	if (isOrbitEmbedded(FACE))
Thomas's avatar
Thomas committed
134
135
136
137
	{
		unsigned int vEmb = getEmbedding(FACE, d);
		embedOrbit(FACE, e, vEmb) ;
	}
138
139
140
141
}

void EmbeddedGMap3::unsewVolumes(Dart d)
{
Thomas's avatar
Thomas committed
142
143
	Dart dd = phi1(phi3(d));

Thomas's avatar
Thomas committed
144
	if(beta3(d)!=d)
Thomas's avatar
Thomas committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
	{
		GMap3::unsewVolumes(d);

		Dart ddd = d;
		do
		{
			if(isOrbitEmbedded(VERTEX))
			{
				if(!sameVertex(ddd,dd))
				{
					embedNewCell(VERTEX, ddd);
					copyCell(VERTEX, ddd, dd);
				}
			}

			dd = phi_1(dd);

			if(isOrbitEmbedded(EDGE))
			{
				if(!sameEdge(ddd,dd))
				{
					embedNewCell(EDGE, dd);
167
					copyCell(EDGE, dd, ddd);
Thomas's avatar
Thomas committed
168
169
170
171
172
173
174
175
176
177
178
179
180
				}
			}

			ddd = phi1(ddd);
		} while(ddd!=d);


		if (isOrbitEmbedded(FACE))
		{
			embedNewCell(FACE, dd);
			copyCell(FACE, dd, d);
		}
	}
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
}

bool EmbeddedGMap3::mergeVolumes(Dart d)
{
	Dart d2 = phi2(d);
	Dart a_2 = phi3(phi2(d));

	if(GMap3::mergeVolumes(d))
	{
		if (isOrbitEmbedded(VOLUME))
		{
				unsigned int vEmb = getEmbedding(VOLUME, d2);
				embedOrbit(VOLUME, a_2, vEmb) ;
		}
		return true;
	}
	return false;
}

void EmbeddedGMap3::splitFace(Dart d, Dart e)
{
	GMap3::splitFace(d,e);

	if(isOrbitEmbedded(VERTEX))
	{
Thomas's avatar
Thomas committed
206
207
		unsigned int vEmb = getEmbedding(VERTEX, d);
		embedOrbit(VERTEX,phi2(phi_1(d)),vEmb);
208

Thomas's avatar
Thomas committed
209
210
		vEmb = getEmbedding(VERTEX, e);
		embedOrbit(VERTEX,phi2(phi_1(e)),vEmb);
211
212
213
214
215
216
	}

	if(isOrbitEmbedded(FACE))
	{
		embedNewCell(FACE, phi2(phi_1(d)));
		copyCell(FACE, phi2(phi_1(d)), d);
Thomas's avatar
Thomas committed
217
218
219
220
221
222

		copyDartEmbedding(FACE, phi_1(d),  d);
		copyDartEmbedding(FACE, beta0(phi_1(d)),  beta0(d));

		copyDartEmbedding(FACE, beta3(phi_1(d)),  beta3(d));
		copyDartEmbedding(FACE, beta3(beta0(phi_1(d))),  beta3(beta0(d)));
223
224
225
226
227
	}

	if(isOrbitEmbedded(VOLUME))
	{
		copyDartEmbedding(VOLUME, phi_1(d),  d);
Thomas's avatar
Thomas committed
228
		copyDartEmbedding(VOLUME, beta0(phi_1(d)),  beta0(d));
229
		copyDartEmbedding(VOLUME, phi2(phi_1(d)),  d);
Thomas's avatar
Thomas committed
230
		copyDartEmbedding(VOLUME, beta0(phi2(phi_1(d))),  beta0(d));
231
232
233
234
235
236

		if(phi3(d) != d)
		{
			Dart d3 = phi3(d);

			copyDartEmbedding(VOLUME, phi1(d3), d3);
Thomas's avatar
Thomas committed
237
			copyDartEmbedding(VOLUME, beta0(phi1(d3)), beta0(d3));
238
			copyDartEmbedding(VOLUME, phi2(phi1(d3)), d3);
Thomas's avatar
Thomas committed
239
			copyDartEmbedding(VOLUME, beta0(phi2(phi1(d3))), beta0(d3));
240
241
242
243
244
245
246
247
248
249
		}
	}
}

void EmbeddedGMap3::cutEdge(Dart d)
{
	GMap3::cutEdge(d);

	if(isOrbitEmbedded(EDGE))
	{
Thomas's avatar
Thomas committed
250
		Dart nd = phi1(d);
251

Thomas's avatar
Thomas committed
252
253
		embedNewCell(EDGE, nd);
		copyCell(EDGE, nd, d);
254
255

		unsigned int vEmb = getEmbedding(EDGE, d);
Thomas's avatar
Thomas committed
256
		embedOrbit(EDGE, d, vEmb);
257
258
259
260
261
262
263
	}

	if(isOrbitEmbedded(FACE))
	{
		Dart f = d;
		do
		{
Thomas's avatar
Thomas committed
264
265
266
			Dart nd = phi1(f);
			unsigned int fEmb = getEmbedding(FACE, f);
			embedOrbit(FACE, nd, fEmb);
267
268
269
270
271

			Dart f2 = phi2(nd);
			if(f2!=nd)
			{
				Dart nd2 = phi2(f);
Thomas's avatar
Thomas committed
272
273
				unsigned int fEmb2 = getEmbedding(FACE, f2);
				embedOrbit(FACE, nd2, fEmb2);
274
275
276
277
278
279
280
281
			}

			f = alpha2(f);
		} while(f != d);
	}

	if(isOrbitEmbedded(VOLUME))
	{
Thomas's avatar
Thomas committed
282
283
284
285
286
287
288
289
//		Dart f = d;
//		do
//		{
//			unsigned int fEmb2 = getEmbedding(VOLUME, d);
//			embedOrbit(VOLUME, d, fEmb2);
//			f = alpha2(f);
//		} while(f != d);

290
291
292
		Dart f = d;
		do
		{
Thomas's avatar
Thomas committed
293
			Dart nd = phi1(f);
294
			copyDartEmbedding(VOLUME, nd, f);
295
			copyDartEmbedding(VOLUME, beta1(nd), f);
Thomas's avatar
Thomas committed
296
			copyDartEmbedding(VOLUME, beta2(nd), f);
297
			copyDartEmbedding(VOLUME, beta1(beta2(nd)), f);
298

Thomas's avatar
Thomas committed
299
300
301
302
303
304
//			Dart nd2 = beta2(nd);
//			if(f!=nd2)
//			{
//				copyDartEmbedding(VOLUME, nd2, f);
//				copyDartEmbedding(VOLUME, beta0(nd2), f);
//			}
305
306
307
308
309
310
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

			f = alpha2(f);
		} while(f != d);
	}
}

//int EmbeddedGMap3::collapseEdge(Dart d, bool delDegenerateFaces,
//		bool delDegenerateVolumes)
//{
//	int nbCol = GMap3::collapseEdge(d,delDegenerateFaces,delDegenerateVolumes);
//
//	return nbCol;
//}

//void EmbeddedGMap3::collapseFace(Dart d, bool delDegenerateFaces,
//		bool delDegenerateVolumes)
//{
//	GMap3::collapseFace(d,delDegenerateFaces,delDegenerateVolumes);
//
////	if(isOrbitEmbedded(VERTEX))
////	{
////		embedOrbit(VERTEX,dsave,vEmb);
////	}
//}

//TODO collapseVolume

unsigned int EmbeddedGMap3::closeHole(Dart d)
{
	unsigned int nbE = GMap3::closeHole(d);
	Dart dd = phi2(d);
	Dart f = dd;

	do
	{
		if(isOrbitEmbedded(VERTEX))
Thomas's avatar
Thomas committed
341
		{
342
			copyDartEmbedding(VERTEX,f, phi1(phi2(f)));
Thomas's avatar
Thomas committed
343
344
			copyDartEmbedding(VERTEX,beta1(f), beta1(phi1(phi2(f))));
		}
345
		if(isOrbitEmbedded(EDGE))
Thomas's avatar
Thomas committed
346
		{
347
			copyDartEmbedding(EDGE, f, phi2(f));
Thomas's avatar
Thomas committed
348
349
			copyDartEmbedding(EDGE, beta0(f), beta0(phi2(f)));
		}
350
		if(isOrbitEmbedded(VOLUME))
Thomas's avatar
Thomas committed
351
		{
352
			copyDartEmbedding(VOLUME, f, phi2(f));
Thomas's avatar
Thomas committed
353
354
			copyDartEmbedding(VOLUME, beta0(f), beta0(phi2(f)));
		}
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373

		f = phi1(f);
	}
	while(dd != f);

	return nbE;
}

void EmbeddedGMap3::closeMap(DartMarker &marker)
{
	GMap3::closeMap(marker);

	for(Dart d = begin() ; d != end() ; next(d))
	{
		if(marker.isMarked(d))
		{
			if(isOrbitEmbedded(VERTEX))
			{
				copyDartEmbedding(VERTEX, d, phi1(phi3(d)));
Thomas's avatar
Thomas committed
374
				copyDartEmbedding(VERTEX, beta0(d), beta0(phi1(phi3(d))));
375
376
377
378
379
380
381
382
383
384
385
386
			}
		}
	}
}

bool EmbeddedGMap3::check()
{
	bool topo = GMap3::check() ;
	if (!topo)
		return false ;

	CGoGNout << "Check: embedding begin" << CGoGNendl ;
Thomas's avatar
Thomas committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414

	DartMarker * dvMark, * deMark, * dfMark, * dvolMark;
	CellMarker * vMark, * eMark, * fMark, * volMark;

	if (isOrbitEmbedded(VERTEX))
	{
		dvMark = new DartMarker(*this);
		vMark = new CellMarker(*this, VERTEX);
	}

	if (isOrbitEmbedded(EDGE))
	{
		deMark = new DartMarker(*this);
		eMark = new CellMarker(*this, EDGE);
	}

	if (isOrbitEmbedded(FACE))
	{
		dfMark = new DartMarker(*this);
		fMark = new CellMarker(*this, FACE);
	}

	if (isOrbitEmbedded(VOLUME))
	{
		dvolMark = new DartMarker(*this);
		volMark = new CellMarker(*this, VOLUME);
	}

415
416
417
418
	for(Dart d = begin(); d != end(); next(d))
	{
		if (isOrbitEmbedded(VERTEX))
		{
Thomas's avatar
Thomas committed
419
420
421
422
423
			if(dvMark->isMarked(d) != vMark->isMarked(d))
				CGoGNout << "Check: warning different orbits share same vertex attribute" << CGoGNendl ;
			vMark->mark(d);
			dvMark->markOrbit(VERTEX,d);

Thomas's avatar
Thomas committed
424
			if (getEmbedding(VERTEX, d) != getEmbedding(VERTEX, beta1(d)))
425
			{
426
				CGoGNout << "Check: different embeddings on vertex (1)" << CGoGNendl ;
427
428
429
				return false ;
			}

Thomas's avatar
Thomas committed
430
431
			if (getEmbedding(VERTEX, d) != getEmbedding(VERTEX, beta2(d)))
			{
432
				CGoGNout << "Check: different embeddings on vertex (2)" << CGoGNendl ;
Thomas's avatar
Thomas committed
433
434
				return false ;
			}
435

Thomas's avatar
Thomas committed
436
437
			if (getEmbedding(VERTEX, d) != getEmbedding(VERTEX, beta3(d)))
			{
438
				CGoGNout << "Check: different embeddings on vertex (3)" << CGoGNendl ;
Thomas's avatar
Thomas committed
439
440
				return false ;
			}
441
442
		}

Thomas's avatar
Thomas committed
443
444
		if (isOrbitEmbedded(EDGE))
		{
Thomas's avatar
Thomas committed
445
446
447
448
449
			if(deMark->isMarked(d) != eMark->isMarked(d))
				CGoGNout << "Check: warning different orbits share same edge attribute" << CGoGNendl ;
			eMark->mark(d);
			deMark->markOrbit(EDGE,d);

Thomas's avatar
Thomas committed
450
451
			if (getEmbedding(EDGE, d) != getEmbedding(EDGE, beta0(d)))
			{
452
				CGoGNout << "Check: different embeddings on edge (0)" << CGoGNendl ;
Thomas's avatar
Thomas committed
453
454
455
456
457
				return false ;
			}

			if (getEmbedding(EDGE, d) != getEmbedding(EDGE, beta2(d)))
			{
458
				CGoGNout << "Check: different embeddings on edge (1)" << CGoGNendl ;
Thomas's avatar
Thomas committed
459
460
461
462
463
				return false ;
			}

			if (getEmbedding(EDGE, d) != getEmbedding(EDGE, beta3(d)))
			{
464
				CGoGNout << "Check: different embeddings on edge (2)" << CGoGNendl ;
Thomas's avatar
Thomas committed
465
466
467
468
469
470
				return false ;
			}
		}

		if (isOrbitEmbedded(FACE))
		{
Thomas's avatar
Thomas committed
471
472
473
474
475
			if(dfMark->isMarked(d) != fMark->isMarked(d))
				CGoGNout << "Check: warning different orbits share same face attribute" << CGoGNendl ;
			fMark->mark(d);
			dfMark->markOrbit(FACE,d);

Thomas's avatar
Thomas committed
476
477
			if (getEmbedding(FACE, d) != getEmbedding(FACE, beta0(d)))
			{
478
				CGoGNout << "Check: different embeddings on face (0)" << CGoGNendl ;
Thomas's avatar
Thomas committed
479
480
481
482
483
				return false ;
			}

			if (getEmbedding(FACE, d) != getEmbedding(FACE, beta1(d)))
			{
484
				CGoGNout << "Check: different embeddings on face (1)" << CGoGNendl ;
Thomas's avatar
Thomas committed
485
486
487
488
489
490
				return false ;
			}
		}

		if (isOrbitEmbedded(VOLUME))
		{
Thomas's avatar
Thomas committed
491
492
493
494
495
			if(dvolMark->isMarked(d) != volMark->isMarked(d))
				CGoGNout << "Check: warning different orbits share same volume attribute" << CGoGNendl ;
			volMark->mark(d);
			dvolMark->markOrbit(VOLUME,d);

Thomas's avatar
Thomas committed
496
497
			if (getEmbedding(VOLUME, d) != getEmbedding(VOLUME, beta0(d)))
			{
498
				CGoGNout << "Check: different embeddings in volume (0)" << CGoGNendl ;
Thomas's avatar
Thomas committed
499
500
501
502
503
				return false ;
			}

			if (getEmbedding(VOLUME, d) != getEmbedding(VOLUME, beta1(d)))
			{
504
				CGoGNout << "Check: different embeddings in volume (1)" << CGoGNendl ;
Thomas's avatar
Thomas committed
505
506
507
508
509
				return false ;
			}

			if (getEmbedding(VOLUME, d) != getEmbedding(VOLUME, beta2(d)))
			{
510
				CGoGNout << "Check: different embeddings in volume (2)" << CGoGNendl ;
Thomas's avatar
Thomas committed
511
512
513
				return false ;
			}
		}
514
	}
Thomas's avatar
Thomas committed
515

516
517
518
519
520
	CGoGNout << "Check: embedding ok" << CGoGNendl ;
	return true ;
}

} // namespace CGoGN