embeddedMap3.hpp 8.94 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-2011, 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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <vector>
#include <algorithm>

namespace CGoGN
{

template <typename MAP3>
void EmbeddedMap3<MAP3>::sewVolumes(Dart d, Dart e)
{
	//topological sewing
	MAP3::sewVolumes(d,e);

untereiner's avatar
untereiner committed
37
38
	//embed the vertex orbits from the oriented face with dart e
	//with vertex orbits value from oriented face with dart d
39
	if (MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
40
	{
untereiner's avatar
untereiner committed
41
		unsigned int vEmb1 = EMBNULL ;
Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
		Dart dd = d ;
		do {
untereiner's avatar
untereiner committed
44
45
			vEmb1 = MAP3::getEmbedding(VERTEX, dd);
			MAP3::embedOrbit(VERTEX, dd, vEmb1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
48
49
50
			dd = MAP3::phi1(dd) ;
		} while(dd != d) ;
	}

	//embed the new edge orbit with the old edge orbit value
untereiner's avatar
untereiner committed
51
	//for all the face
52
	if (MAP3::isOrbitEmbedded(EDGE))
Pierre Kraemer's avatar
Pierre Kraemer committed
53
	{
untereiner's avatar
untereiner committed
54
		unsigned int vEmb1 = EMBNULL ;
Pierre Kraemer's avatar
Pierre Kraemer committed
55
56
		Dart dd = d ;
		do {
57
58
			vEmb1 = MAP3::getEmbedding(EDGE, d);
			MAP3::embedOrbit(EDGE, d, vEmb1) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59
60
61
			dd = MAP3::phi1(dd) ;
		} while(dd != d) ;
	}
untereiner's avatar
untereiner committed
62

untereiner's avatar
untereiner committed
63
	//embed the face orbit from the volume sewn
64
65
	if (MAP3::isOrbitEmbedded(FACE))
		MAP3::copyDartEmbedding(FACE, e, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
66
67
68
69
70
}

template <typename MAP3>
void EmbeddedMap3<MAP3>::unsewVolumes(Dart d)
{
untereiner's avatar
untereiner committed
71
	Dart d3 = MAP3::phi3(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
72

untereiner's avatar
untereiner committed
73
74
	bool boundaryD = false;
	bool boundaryE = false;
Pierre Kraemer's avatar
Pierre Kraemer committed
75

76
	if(MAP3::isOrbitEmbedded(VERTEX))
untereiner's avatar
untereiner committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
	{
		if(MAP3::isBoundaryVertex(d))
			boundaryD = true;
		if(MAP3::isBoundaryVertex(MAP3::phi1(d)))
			boundaryE = true;
	}

	MAP3::unsewVolumes(d);

	Dart dd = d;
	Dart dd3 = d3;

	do
	{
91
92
		if(MAP3::isOrbitEmbedded(VERTEX))
			MAP3::copyCell(VERTEX, dd3, MAP3::phi1(dd));
Pierre Kraemer's avatar
Pierre Kraemer committed
93

94
		if(MAP3::isOrbitEmbedded(EDGE))
Pierre Kraemer's avatar
Pierre Kraemer committed
95
96


97
		if(MAP3::isOrbitEmbedded(FACE))
Pierre Kraemer's avatar
Pierre Kraemer committed
98
99
100


		dd = MAP3::phi1(dd) ;
untereiner's avatar
untereiner committed
101
102
	}while( dd != d );

Pierre Kraemer's avatar
Pierre Kraemer committed
103
104
105
106
107
108
109

}

template <typename MAP3>
bool EmbeddedMap3<MAP3>::mergeVolumes(Dart d)
{
	Dart d2 = MAP3::phi2(d);
untereiner's avatar
untereiner committed
110
	Dart a_2 = MAP3::phi3(MAP3::phi2(d));
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
113

	if(MAP3::mergeVolumes(d))
	{
114
		if (MAP3::isOrbitEmbedded(VOLUME))
Pierre Kraemer's avatar
Pierre Kraemer committed
115
		{
116
117
				unsigned int vEmb = MAP3::getEmbedding(VOLUME, d2);
				MAP3::embedOrbit(VOLUME, a_2, vEmb) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
118
119
120
121
122
123
124
125
126
127
		}
		return true;
	}
	return false;
}

template <typename MAP3>
void EmbeddedMap3<MAP3>::splitFace(Dart d, Dart e)
{
	MAP3::splitFace(d,e);
untereiner's avatar
untereiner committed
128

129
	if(MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	{
untereiner's avatar
ihm3    
untereiner committed
131
132
		MAP3::copyDartEmbedding(VERTEX, MAP3::phi2(MAP3::phi_1(d)), d);
		MAP3::copyDartEmbedding(VERTEX, MAP3::phi2(MAP3::phi_1(e)), e);
untereiner's avatar
untereiner committed
133
134
135
136
137
138

		if(MAP3::phi3(d) != d)
		{
			Dart d3 = MAP3::phi3(d);
			Dart e3 = MAP3::phi3(e);

139
140
			MAP3::copyDartEmbedding(VERTEX, MAP3::phi1(d3), MAP3::phi1(MAP3::phi2(MAP3::phi1(d3))));
			MAP3::copyDartEmbedding(VERTEX, MAP3::phi1(e3), MAP3::phi1(MAP3::phi2(MAP3::phi1(e3))));
untereiner's avatar
untereiner committed
141
142
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
143
144
	}

145
	if(MAP3::isOrbitEmbedded(FACE))
untereiner's avatar
untereiner committed
146
	{
147
148
		MAP3::embedNewCell(FACE, MAP3::phi2(MAP3::phi_1(d)));
		MAP3::copyCell(FACE, MAP3::phi2(MAP3::phi_1(d)), d);
untereiner's avatar
untereiner committed
149
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
150

151
	if(MAP3::isOrbitEmbedded(VOLUME))
Pierre Kraemer's avatar
Pierre Kraemer committed
152
	{
153
154
		MAP3::copyDartEmbedding(VOLUME, MAP3::phi_1(d),  d);
		MAP3::copyDartEmbedding(VOLUME, MAP3::phi2(MAP3::phi_1(d)),  d);
Pierre Kraemer's avatar
Pierre Kraemer committed
155

untereiner's avatar
untereiner committed
156
		if(MAP3::phi3(d) != d)
Pierre Kraemer's avatar
Pierre Kraemer committed
157
		{
untereiner's avatar
untereiner committed
158
159
			Dart d3 = MAP3::phi3(d);

160
161
			MAP3::copyDartEmbedding(VOLUME, MAP3::phi1(d3), d3);
			MAP3::copyDartEmbedding(VOLUME, MAP3::phi2(MAP3::phi1(d3)), d3);
Pierre Kraemer's avatar
Pierre Kraemer committed
162
163
164
165
166
167
168
169
170
		}

	}

}

template <typename MAP3>
void EmbeddedMap3<MAP3>::cutEdge(Dart d)
{
untereiner's avatar
untereiner committed
171

Pierre Kraemer's avatar
Pierre Kraemer committed
172
	MAP3::cutEdge(d);
untereiner's avatar
untereiner committed
173

174
	if(MAP3::isOrbitEmbedded(EDGE))
untereiner's avatar
untereiner committed
175
176
177
178
	{

	}

179
	if(MAP3::isOrbitEmbedded(FACE))
untereiner's avatar
untereiner committed
180
181
182
183
	{

	}

184
	if(MAP3::isOrbitEmbedded(VOLUME))
untereiner's avatar
untereiner committed
185
186
187
188
189
190
191
192
	{
		Dart demb = d;
		if(MAP3::phi3(demb) == demb)
			demb = MAP3::phi2(demb);

		Dart f = demb;
		do
		{
193
194
			MAP3::copyDartEmbedding(VOLUME, MAP3::phi1(f), f);
			MAP3::copyDartEmbedding(VOLUME, MAP3::phi2(f), MAP3::phi2(MAP3::phi1(f)));
untereiner's avatar
untereiner committed
195
196
197
198
199

			f = MAP3::alpha2(f);
		}
		while(f != demb);
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
200
201
202
203
204
205
206
207
208
}


template <typename MAP3>
int EmbeddedMap3<MAP3>::collapseEdge(Dart d, bool delDegenerateFaces,
		bool delDegenerateVolumes)
{

	unsigned int vEmb = EMBNULL ;
209
	if(MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
210
	{
211
212
213
		vEmb = MAP3::getEmbedding(VERTEX, d) ;
		MAP3::embedOrbit(VERTEX,d,vEmb);
		MAP3::embedOrbit(VERTEX,MAP3::phi2(d),vEmb);
Pierre Kraemer's avatar
Pierre Kraemer committed
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
	}

	int nbCol = MAP3::collapseEdge(d,delDegenerateFaces,delDegenerateVolumes);

	return nbCol;
}

template <typename MAP3>
void EmbeddedMap3<MAP3>::collapseFace(Dart d, bool delDegenerateFaces,
		bool delDegenerateVolumes)
{
	//unsigned int degree = MAP3::faceDegree(d);
	//Dart dsave;

//	//si degree face = 3
//	if(degree == 3)
//	{
//		dsave = MAP3::phi3(MAP3::phi2(MAP3::phi1(d)));
//		dsave = MAP3::phi3(MAP3::phi2(MAP3::phi1(dsave)));
//		//ATTENTION : il faut trouver un brin de l'orbite sommet de d non modifie par l'operation !!
//	}
//	else if(degree > 3)
//	{
//		dsave = MAP3::phi1(MAP3::phi2(MAP3::phi1(d)));
//		dsave = MAP3::phi1(MAP3::phi2(MAP3::phi1(dsave)));
//	}
//	else
//		return;


//	unsigned int vEmb = EMBNULL ;
245
//	if(MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
246
//	{
247
//		vEmb = MAP3::getEmbedding(d, VERTEX) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
248
249
250
251
//	}

	MAP3::collapseFace(d,delDegenerateFaces,delDegenerateVolumes);

252
//	if(MAP3::isOrbitEmbedded(VERTEX))
Pierre Kraemer's avatar
Pierre Kraemer committed
253
//	{
254
//		MAP3::embedOrbit(VERTEX,dsave,vEmb);
Pierre Kraemer's avatar
Pierre Kraemer committed
255
256
257
258
//	}

}

untereiner's avatar
untereiner committed
259
260
//TODO collapseVolume

Pierre Kraemer's avatar
Pierre Kraemer committed
261
262
263
264
265
266
267
268
269
270
template <typename MAP3>
Dart EmbeddedMap3<MAP3>::cutSpike(Dart d)
{

	Dart e = MAP3::cutSpike(d);

	return e;
}


untereiner's avatar
untereiner committed
271
272
273
274
275
276
277
278
279
template <typename MAP3>
unsigned int EmbeddedMap3<MAP3>::closeHole(Dart d)
{
	unsigned int nbE = MAP3::closeHole(d);
	Dart dd = MAP3::phi2(d);
	Dart f = dd;

	do
	{
280
281
282
283
284
285
		if(MAP3::isOrbitEmbedded(VERTEX))
			MAP3::copyDartEmbedding(VERTEX,f, MAP3::phi1(MAP3::phi2(f)));
		if(MAP3::isOrbitEmbedded(EDGE))
			MAP3::copyDartEmbedding(EDGE, f, MAP3::phi2(f));
		if(MAP3::isOrbitEmbedded(VOLUME))
			MAP3::copyDartEmbedding(VOLUME, f, MAP3::phi2(f));
untereiner's avatar
untereiner committed
286
287
288
289
290
291
292

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

	return nbE;
}
Pierre Kraemer's avatar
Pierre Kraemer committed
293
294


untereiner's avatar
untereiner committed
295
296
297
298
299
300
301
302
303
template <typename MAP3>
void EmbeddedMap3<MAP3>::closeMap(DartMarker &marker)
{
	MAP3::closeMap(marker);

	for(Dart d = MAP3::begin() ; d != MAP3::end() ; MAP3::next(d))
	{
		if(marker.isMarked(d))
		{
304
			if(MAP3::isOrbitEmbedded(VERTEX))
untereiner's avatar
untereiner committed
305
			{
306
				MAP3::copyDartEmbedding(VERTEX, d, MAP3::phi1(MAP3::phi3(d)));
untereiner's avatar
untereiner committed
307
308
309
			}
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
310

untereiner's avatar
untereiner committed
311
}
Pierre Kraemer's avatar
Pierre Kraemer committed
312

untereiner's avatar
ihm3    
untereiner committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
template <typename MAP3>
bool EmbeddedMap3<MAP3>::check()
{
	bool topo = MAP3::check() ;
	if (!topo)
		return false ;

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

untereiner's avatar
untereiner committed
331
			 if(MAP3::phi3(d) != d && MAP3::getEmbedding(VERTEX, d) != MAP3::getEmbedding(VERTEX, MAP3::phi1(MAP3::phi3(d))))
untereiner's avatar
ihm3    
untereiner committed
332
333
			 {
					CGoGNout << "Check: different embeddings on vertex in the 2 oriented faces" << CGoGNendl ;
untereiner's avatar
untereiner committed
334
335
336
					std::cout << "Dart #" << d << std::endl;
					std::cout << "Emb(d) = " << MAP3::getEmbedding(VERTEX, d) << std::endl;
					std::cout << "Emb(phi32(d)) = " << MAP3::getEmbedding(VERTEX, MAP3::phi3(MAP3::phi2(d))) << std::endl;
untereiner's avatar
ihm3    
untereiner committed
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
					return false ;
			 }

		}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
364
} // namespace CGoGN