embeddedGMap2.cpp 11.6 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
33
34
35
36
37
38
39
40
41
/*******************************************************************************
* 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/embeddedGMap2.h"

namespace CGoGN
{

void EmbeddedGMap2::splitVertex(Dart d, Dart e)
{
	Dart dd = phi2(d) ;
	Dart ee = phi2(e) ;

	GMap2::splitVertex(d, e) ;

	if (isOrbitEmbedded(VERTEX))
	{
42
43
44
45
46
47
		unsigned int v1Emb = getEmbedding(VERTEX, d) ;
		setDartEmbedding(VERTEX, phi1(dd), v1Emb) ;
		setDartEmbedding(VERTEX, beta2(phi1(dd)), v1Emb) ;
		unsigned int v2Emb = getEmbedding(VERTEX, e) ;
		setDartEmbedding(VERTEX, phi1(ee), v2Emb) ;
		setDartEmbedding(VERTEX, beta2(phi1(ee)), v2Emb) ;
48
49
50
51
52
53
		embedNewCell(VERTEX, e) ;
		copyCell(VERTEX, e, d) ;
	}

	if(isOrbitEmbedded(FACE))
	{
54
55
56
57
58
59
		unsigned int f1Emb = getEmbedding(FACE, dd) ;
		copyDartEmbedding(FACE, phi1(dd), f1Emb) ;
		copyDartEmbedding(FACE, beta0(phi1(dd)), f1Emb) ;
		unsigned int f2Emb = getEmbedding(FACE, ee) ;
		copyDartEmbedding(FACE, phi1(ee), f2Emb) ;
		copyDartEmbedding(FACE, beta0(phi1(ee)), f2Emb) ;
60
61
62
	}
}

63
Dart EmbeddedGMap2::deleteVertex(Dart d)
64
{
65
66
	Dart f = GMap2::deleteVertex(d) ;
	if(f != NIL)
67
68
69
70
71
	{
		if (isOrbitEmbedded(FACE))
		{
			embedOrbit(FACE, f, getEmbedding(FACE, f)) ;
		}
72
	}
73
	return f ;
74
}
75
76
77
78
79
80
81
82
83
84

void EmbeddedGMap2::cutEdge(Dart d)
{
	GMap2::cutEdge(d) ;

	Dart nd = phi1(d) ;

	if (isOrbitEmbedded(EDGE))
	{
		embedNewCell(EDGE, nd) ;
85
86
87
		unsigned int eEmb = getEmbedding(EDGE, d) ;
		setDartEmbedding(EDGE, phi2(d), eEmb) ;
		setDartEmbedding(EDGE, beta0(d), eEmb) ;
88
89
		copyCell(EDGE, nd, d) ;
	}
Thomas's avatar
Thomas committed
90

91
92
	if(isOrbitEmbedded(FACE))
	{
93
94
95
		unsigned int f1Emb = getEmbedding(FACE, d) ;
		setDartEmbedding(FACE, phi1(d), f1Emb) ;
		setDartEmbedding(FACE, beta0(d), f1Emb) ;
96
		Dart e = phi2(nd) ;
97
98
99
		unsigned int f2Emb = getEmbedding(FACE, d) ;
		setDartEmbedding(FACE, phi1(e), f2Emb) ;
		setDartEmbedding(FACE, beta0(e), f2Emb) ;
100
101
102
	}
}

103
bool EmbeddedGMap2::uncutEdge(Dart d)
104
{
105
106
	if(GMap2::uncutEdge(d))
	{
107
		if(isOrbitEmbedded(EDGE))
108
109
110
111
112
113
114
115
		{
			unsigned int eEmb = getEmbedding(EDGE, d) ;
			setDartEmbedding(EDGE, phi2(d), eEmb) ;
			setDartEmbedding(EDGE, beta0(d), eEmb) ;
		}
		return true ;
	}
	return false ;
116
}
117
118
119
120
121
122
123
124
125
126
127
128

bool EmbeddedGMap2::edgeCanCollapse(Dart d)
{
	if(isBoundaryVertex(d) || isBoundaryVertex(phi1(d)))
		return false ;

	unsigned int val_v1 = vertexDegree(d) ;
	unsigned int val_v2 = vertexDegree(phi1(d)) ;

	if(val_v1 + val_v2 < 8 || val_v1 + val_v2 > 14)
		return false ;

129
	if(faceDegree(d) == 3)
130
131
132
133
134
135
	{
		if(vertexDegree(phi_1(d)) < 4)
			return false ;
	}

	Dart dd = phi2(d) ;
136
	if(faceDegree(dd) == 3)
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
	{
		if(vertexDegree(phi_1(dd)) < 4)
			return false ;
	}

	// Check vertex sharing condition
	std::vector<unsigned int> vu1 ;
	vu1.reserve(32) ;
	Dart vit1 = alpha1(alpha1(d)) ;
	Dart end = phi1(dd) ;
	do
	{
		unsigned int ve = getEmbedding(VERTEX, phi2(vit1)) ;
		vu1.push_back(ve) ;
		vit1 = alpha1(vit1) ;
	} while(vit1 != end) ;
	end = phi1(d) ;
	Dart vit2 = alpha1(alpha1(dd)) ;
	do
	{
		unsigned int ve = getEmbedding(VERTEX, phi2(vit2)) ;
		std::vector<unsigned int>::iterator it = std::find(vu1.begin(), vu1.end(), ve) ;
		if(it != vu1.end())
			return false ;
		vit2 = alpha1(vit2) ;
	} while(vit2 != end) ;

	return true ;
}

Dart EmbeddedGMap2::collapseEdge(Dart d, bool delDegenerateFaces)
{
	unsigned int vEmb = EMBNULL ;
	if (isOrbitEmbedded(VERTEX))
	{
		vEmb = getEmbedding(VERTEX, d) ;
	}

	Dart dV = GMap2::collapseEdge(d, delDegenerateFaces);

	if (isOrbitEmbedded(VERTEX))
	{
		embedOrbit(VERTEX, dV, vEmb) ;
	}

	return dV ;
}

bool EmbeddedGMap2::flipEdge(Dart d)
{
	if(GMap2::flipEdge(d))
	{
		Dart e = phi2(d) ;

		if (isOrbitEmbedded(VERTEX))
		{
193
194
195
196
197
198
			unsigned int v1Emb = getEmbedding(VERTEX, beta1(d)) ;
			setDartEmbedding(VERTEX, d, v1Emb) ;
			setDartEmbedding(VERTEX, beta2(d), v1Emb) ;
			unsigned int v2Emb = getEmbedding(VERTEX, beta1(e)) ;
			setDartEmbedding(VERTEX, e, v2Emb) ;
			setDartEmbedding(VERTEX, beta2(e), v2Emb) ;
199
200
201
		}
		if (isOrbitEmbedded(FACE))
		{
202
203
204
205
206
207
			unsigned int f1Emb = getEmbedding(FACE, d) ;
			setDartEmbedding(FACE, phi_1(d), f1Emb) ;
			setDartEmbedding(FACE, beta1(d), f1Emb) ;
			unsigned int f2Emb = getEmbedding(FACE, e) ;
			setDartEmbedding(FACE, phi_1(e), f2Emb) ;
			setDartEmbedding(FACE, beta1(e), f2Emb) ;
208
209
210
211
212
213
214
215
216
217
218
219
220
221
		}
		return true ;
	}
	return false ;
}

bool EmbeddedGMap2::flipBackEdge(Dart d)
{
	if(GMap2::flipBackEdge(d))
	{
		Dart e = phi2(d) ;

		if (isOrbitEmbedded(VERTEX))
		{
222
223
224
225
226
227
			unsigned int v1Emb = getEmbedding(VERTEX, beta1(d)) ;
			setDartEmbedding(VERTEX, d, v1Emb) ;
			setDartEmbedding(VERTEX, beta2(d), v1Emb) ;
			unsigned int v2Emb = getEmbedding(VERTEX, beta1(e)) ;
			setDartEmbedding(VERTEX, e, v2Emb) ;
			setDartEmbedding(VERTEX, beta2(e), v2Emb) ;
228
		}
Thomas's avatar
Thomas committed
229

230
231
		if (isOrbitEmbedded(FACE))
		{
232
233
234
235
236
237
			unsigned int f1Emb = getEmbedding(FACE, d) ;
			setDartEmbedding(FACE, phi1(d), f1Emb) ;
			setDartEmbedding(FACE, beta0(phi1(d)), f1Emb) ;
			unsigned int f2Emb = getEmbedding(FACE, e) ;
			setDartEmbedding(FACE, phi1(e), f2Emb) ;
			setDartEmbedding(FACE, beta0(phi1(e)), f2Emb) ;
238
239
240
241
242
243
		}
		return true ;
	}
	return false ;
}

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
287
288
289
290
291
292
//void EmbeddedGMap2::insertEdgeInVertex(Dart d, Dart e)
//{
//	GMap2::insertEdgeInVertex(d, e);
//
//	if (isOrbitEmbedded(VERTEX))
//	{
//		copyDartEmbedding(VERTEX, e, d) ;
//		copyDartEmbedding(VERTEX, beta2(e), d) ;
//	}
//
//	if (isOrbitEmbedded(FACE))
//	{
//		if(!sameFace(d,e))
//		{
//			embedNewCell(FACE, e);
//			copyCell(FACE, e, d) ;
//		}
//		else
//		{
//			embedOrbit(FACE, d, getEmbedding(FACE, d)) ;
//		}
//	}
//}
//
//void EmbeddedGMap2::removeEdgeFromVertex(Dart d)
//{
//	Dart dPrev = alpha_1(d);
//
//	GMap2::removeEdgeFromVertex(d);
//
//	if (isOrbitEmbedded(VERTEX))
//	{
//		embedNewCell(VERTEX, d);
//		copyCell(VERTEX, d, dPrev);
//	}
//
//	if (isOrbitEmbedded(FACE))
//	{
//		if(!sameFace(d, dPrev))
//		{
//			embedNewCell(FACE, d);
//			copyCell(FACE, d, dPrev) ;
//		}
//		else
//		{
//			embedOrbit(FACE, d, getEmbedding(FACE, d)) ;
//		}
//	}
//}
293

294
void EmbeddedGMap2::sewFaces(Dart d, Dart e, bool withBoundary)
295
{
296
297
	// for fixed point construction (import & primitives)
	if (!withBoundary)
298
	{
299
300
		GMap2::sewFaces(d, e, false) ;
		return ;
301
302
	}

303
	GMap2::sewFaces(d, e, true) ;
304
305
306

	if (isOrbitEmbedded(VERTEX))
	{
307
308
		embedOrbit(VERTEX, d, getEmbedding(VERTEX, d)) ;
		embedOrbit(VERTEX, e, getEmbedding(VERTEX, beta0(d))) ;
309
310
311
312
	}

	if (isOrbitEmbedded(EDGE))
	{
313
		embedOrbit(EDGE, e, getEmbedding(EDGE, d)) ;
314
315
316
317
318
	}
}

void EmbeddedGMap2::unsewFaces(Dart d)
{
319
320
	Dart e = beta2(d);
	GMap2::unsewFaces(d);
321
322
323

	if (isOrbitEmbedded(VERTEX))
	{
324
		if(!sameVertex(d,e))
325
		{
326
327
			embedNewCell(VERTEX, e);
			copyCell(VERTEX, e, d);
328
329
		}

330
331
332
333
		d = beta0(d);
		e = beta0(e);

		if(!sameVertex(d,e))
334
		{
335
336
			embedNewCell(VERTEX, e);
			copyCell(VERTEX, e, d);
337
338
		}
	}
339

340
341
	if (isOrbitEmbedded(EDGE))
	{
342
343
		embedNewCell(EDGE, e);
		copyCell(EDGE, e, d);
344
345
346
347
348
	}
}

bool EmbeddedGMap2::collapseDegeneratedFace(Dart d)
{
349
350
351
352
	Dart e = beta2(d) ;
	bool updateEdgeEmb = false ;
	if(phi1(d) != d)
		updateEdgeEmb = true ;
353
354
355

	if(GMap2::collapseDegeneratedFace(d))
	{
356
		if (isOrbitEmbedded(EDGE) && updateEdgeEmb)
357
		{
358
359
360
			unsigned int eEmb = getEmbedding(EDGE, e) ;
			setDartEmbedding(EDGE, beta2(e), eEmb) ;
			setDartEmbedding(EDGE, phi2(e), eEmb) ;
361
362
363
364
365
366
367
368
369
370
371
372
		}
		return true ;
	}
	return false ;
}

void EmbeddedGMap2::splitFace(Dart d, Dart e)
{
	GMap2::splitFace(d, e) ;

	if (isOrbitEmbedded(VERTEX))
	{
373
374
375
376
377
378
		unsigned int v1Emb = getEmbedding(VERTEX, d) ;
		copyDartEmbedding(VERTEX, phi_1(e), v1Emb) ;
		copyDartEmbedding(VERTEX, beta1(d), v1Emb) ;
		unsigned int v2Emb = getEmbedding(VERTEX, e) ;
		copyDartEmbedding(VERTEX, phi_1(d), v2Emb) ;
		copyDartEmbedding(VERTEX, beta1(e), v2Emb) ;
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	}
	if (isOrbitEmbedded(FACE))
	{
		embedNewCell(FACE, e) ;
		copyCell(FACE, e, d) ;
	}
}

bool EmbeddedGMap2::mergeFaces(Dart d)
{
	Dart dNext = phi1(d) ;

	if(GMap2::mergeFaces(d))
	{
		if (isOrbitEmbedded(FACE))
		{
			embedOrbit(FACE, dNext, getEmbedding(FACE, dNext)) ;
		}
		return true ;
	}
	return false ;
}

bool EmbeddedGMap2::mergeVolumes(Dart d, Dart e)
{
	std::vector<Dart> darts ;
	std::vector<unsigned int> vEmb ;
	std::vector<unsigned int> eEmb ;
407
408
409
410
	darts.reserve(32) ;
	vEmb.reserve(32) ;
	eEmb.reserve(32) ;

411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
	Dart fit = d ;
	do
	{
		darts.push_back(phi2(fit)) ;

		if (isOrbitEmbedded(VERTEX))
		{
			vEmb.push_back(getEmbedding(VERTEX, phi2(fit))) ;
		}

		if (isOrbitEmbedded(EDGE))
		{
			eEmb.push_back(getEmbedding(EDGE, fit)) ;
		}

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

	if(GMap2::mergeVolumes(d, e))
	{
		for(unsigned int i = 0; i < darts.size(); ++i)
		{
			if (isOrbitEmbedded(VERTEX))
			{
				embedOrbit(VERTEX, darts[i], vEmb[i]) ;
			}

			if (isOrbitEmbedded(EDGE))
			{
				embedOrbit(EDGE, darts[i], eEmb[i]) ;
			}
		}
		return true ;
	}
	return false ;
}

448
unsigned int EmbeddedGMap2::closeHole(Dart d, bool forboundary)
449
450
451
{
	unsigned int nbE = GMap2::closeHole(d) ;
	Dart dd = phi2(d) ;
452
	Dart it = dd ;
453
454
455
456
	do
	{
		if (isOrbitEmbedded(VERTEX))
		{
457
458
			copyDartEmbedding(VERTEX, it, beta2(it)) ;
			copyDartEmbedding(VERTEX, beta0(it), phi2(it)) ;
459
460
461
		}
		if (isOrbitEmbedded(EDGE))
		{
462
463
464
			unsigned int eEmb = getEmbedding(EDGE, beta2(it)) ;
			setDartEmbedding(EDGE, it, eEmb) ;
			setDartEmbedding(EDGE, beta0(it), eEmb) ;
465
		}
466
467
		it = phi1(it) ;
	} while(it != dd) ;
468
469
470
471
472
473
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
506
507
508
509
510
511
	return nbE ;
}

bool EmbeddedGMap2::check()
{
	bool topo = GMap2::check() ;
	if (!topo)
		return false ;

	CGoGNout << "Check: embedding begin" << CGoGNendl ;
	for(Dart d = begin(); d != end(); next(d))
	{
		if (isOrbitEmbedded(VERTEX))
		{
			if (getEmbedding(VERTEX, d) != getEmbedding(VERTEX, alpha1(d)))
			{
				CGoGNout << "Check: different embeddings on vertex" << CGoGNendl ;
				return false ;
			}
		}

		if (isOrbitEmbedded(EDGE))
		{
			if (getEmbedding(EDGE, d) != getEmbedding(EDGE, phi2(d)))
			{
				CGoGNout << "Check: different embeddings on edge" << CGoGNendl ;
				return false ;
			}
		}

		if (isOrbitEmbedded(FACE))
		{
			if (getEmbedding(FACE, d) != getEmbedding(FACE, phi1(d)))
		{
				CGoGNout << "Check: different embeddings on face" << CGoGNendl ;
				return false ;
			}
		}
	}
	CGoGNout << "Check: embedding ok" << CGoGNendl ;
	return true ;
}

} // namespace CGoGN