embeddedGMap2.cpp 12.2 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))
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
44
45
46
		unsigned int vEmb = getEmbedding(VERTEX, d) ;
		setDartEmbedding(VERTEX, phi1(dd), vEmb) ;
		setDartEmbedding(VERTEX, beta2(phi1(dd)), vEmb) ;
		setDartEmbedding(VERTEX, beta0(dd), vEmb) ;

47
48
49
50
51
52
		embedNewCell(VERTEX, e) ;
		copyCell(VERTEX, e, d) ;
	}

	if(isOrbitEmbedded(FACE))
	{
53
54
55
56
57
58
		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) ;
59
60
61
	}
}

62
Dart EmbeddedGMap2::deleteVertex(Dart d)
63
{
64
65
	Dart f = GMap2::deleteVertex(d) ;
	if(f != NIL)
66
67
68
69
70
	{
		if (isOrbitEmbedded(FACE))
		{
			embedOrbit(FACE, f, getEmbedding(FACE, f)) ;
		}
71
	}
72
	return f ;
73
}
74

75
Dart EmbeddedGMap2::cutEdge(Dart d)
76
{
77
	Dart nd = GMap2::cutEdge(d) ;
78
79
80

	if (isOrbitEmbedded(EDGE))
	{
81
82
83
		unsigned int eEmb = getEmbedding(EDGE, d) ;
		setDartEmbedding(EDGE, phi2(d), eEmb) ;
		setDartEmbedding(EDGE, beta0(d), eEmb) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
84
		embedNewCell(EDGE, nd) ;
85
86
		copyCell(EDGE, nd, d) ;
	}
Thomas's avatar
Thomas committed
87

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

	return nd ;
100
101
}

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

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 ;

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

	Dart dd = phi2(d) ;
135
	if(faceDegree(dd) == 3)
136
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
	{
		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))
		{
192
193
194
195
196
197
			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) ;
198
199
200
		}
		if (isOrbitEmbedded(FACE))
		{
201
202
203
204
205
206
			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) ;
207
208
209
210
211
212
213
214
215
216
217
218
219
220
		}
		return true ;
	}
	return false ;
}

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

		if (isOrbitEmbedded(VERTEX))
		{
221
222
223
224
225
226
			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) ;
227
		}
Thomas's avatar
Thomas committed
228

229
230
		if (isOrbitEmbedded(FACE))
		{
231
232
233
234
235
236
			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) ;
237
238
239
240
241
242
		}
		return true ;
	}
	return false ;
}

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
287
288
289
290
291
//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)) ;
//		}
//	}
//}
292

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

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

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

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

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

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

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

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

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

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

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

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

	if (isOrbitEmbedded(VERTEX))
	{
372
		unsigned int v1Emb = getEmbedding(VERTEX, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
373
374
375
		setDartEmbedding(VERTEX, phi_1(e), v1Emb) ;
		setDartEmbedding(VERTEX, beta1(d), v1Emb) ;
		setDartEmbedding(VERTEX, beta1(phi_1(e)), v1Emb) ;
376
		unsigned int v2Emb = getEmbedding(VERTEX, e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
377
378
379
		setDartEmbedding(VERTEX, phi_1(d), v2Emb) ;
		setDartEmbedding(VERTEX, beta1(e), v2Emb) ;
		setDartEmbedding(VERTEX, beta1(phi_1(d)), v2Emb) ;
380
381
382
	}
	if (isOrbitEmbedded(FACE))
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
383
384
385
		unsigned int fEmb = getEmbedding(FACE, d) ;
		setDartEmbedding(FACE, phi_1(d), fEmb) ;
		setDartEmbedding(FACE, beta1(phi_1(d)), fEmb) ;
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
		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 ;
411
412
413
414
	darts.reserve(32) ;
	vEmb.reserve(32) ;
	eEmb.reserve(32) ;

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
448
449
450
451
	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 ;
}

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

512
	CGoGNout << "Check: embedding ok" << CGoGNendl ;
513
514
515
516
517
518
519
520
521
522

    std::cout << "nb vertex orbits : " << getNbOrbits(VERTEX) << std::endl ;
    std::cout << "nb vertex cells : " << m_attribs[VERTEX].size() << std::endl ;

    std::cout << "nb edge orbits : " << getNbOrbits(EDGE) << std::endl ;
    std::cout << "nb edge cells : " << m_attribs[EDGE].size() << std::endl ;

    std::cout << "nb face orbits : " << getNbOrbits(FACE) << std::endl ;
    std::cout << "nb face cells : " << m_attribs[FACE].size() << std::endl ;

523
524
525
526
	return true ;
}

} // namespace CGoGN