embeddedMap3.cpp 7.49 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
/*******************************************************************************
* 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 "Topology/map/embeddedMap3.h"

namespace CGoGN
{

Pierre Kraemer's avatar
Pierre Kraemer committed
30
Dart EmbeddedMap3::deleteVertex(Dart d)
31
{
untereiner's avatar
untereiner committed
32
33
	//the merge volumes inside deleteVertex merges the volume embedding

34
35
36
37
38
39
40
41
42
43
44
	return Map3::deleteVertex(d);
}

void EmbeddedMap3::cutEdge(Dart d)
{
	Map3::cutEdge(d);

	if(isOrbitEmbedded(EDGE))
	{
		Dart nd = phi1(d) ;

untereiner's avatar
untereiner committed
45
		//embed the new darts created in the cutted edge
46
47
		unsigned int vEmb = getEmbedding(EDGE, d);
		embedOrbit(EDGE, d, vEmb) ;
untereiner's avatar
untereiner committed
48
49
50
51

		//embed a new cell for the new edge and copy the embedding
		embedNewCell(EDGE, nd) ;
		copyCell(EDGE, nd, d) ;
52
53
54
55
56
57
58
59
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
88
89
	}

	if(isOrbitEmbedded(FACE))
	{
		Dart f = d;
		do
		{
			Dart nd = phi1(f) ;
			copyDartEmbedding(FACE, nd, f);

			Dart f2 = phi2(nd);
			if(f2!=nd)
			{
				Dart nd2 = phi2(f);
				copyDartEmbedding(FACE, nd2, f2);
			}

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

	if(isOrbitEmbedded(VOLUME))
	{
		Dart f = d;
		do
		{
			Dart nd = phi1(f) ;
			copyDartEmbedding(VOLUME, nd, f);

			Dart nd2 = phi2(f);
			if(f!=nd2)
				copyDartEmbedding(VOLUME, nd2, f);

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

90
bool EmbeddedMap3::uncutEdge(Dart d)
91
{
92
	if(Map3::uncutEdge(d))
untereiner's avatar
untereiner committed
93
	{
94
95
96
97
98
99
100
		//embed all darts from the old two edges to one of the two edge embedding
		if(isOrbitEmbedded(EDGE))
		{
			unsigned int vEmb = getEmbedding(EDGE, d);
			embedOrbit(EDGE, d, vEmb) ;
		}
		return true ;
untereiner's avatar
untereiner committed
101
	}
102
	return false ;
103
104
105
106
107
108
}

void EmbeddedMap3::splitFace(Dart d, Dart e)
{
	Map3::splitFace(d,e);

untereiner's avatar
untereiner committed
109
	//copy the vertex embedding to new darts (same vertex embedding for all darts)
110
111
112
113
114
	if(isOrbitEmbedded(VERTEX))
	{
		copyDartEmbedding(VERTEX, phi2(phi_1(d)), d);
		copyDartEmbedding(VERTEX, phi2(phi_1(e)), e);

untereiner's avatar
untereiner committed
115
		if(!isBoundaryFace(d))
116
117
118
119
120
121
122
123
124
		{
			Dart d3 = phi3(d);
			Dart e3 = phi3(e);

			copyDartEmbedding(VERTEX, phi1(d3), phi1(phi2(phi1(d3))));
			copyDartEmbedding(VERTEX, phi1(e3), phi1(phi2(phi1(e3))));
		}
	}

untereiner's avatar
untereiner committed
125
	//add a new face embedding to the created face
126
127
128
129
130
131
	if(isOrbitEmbedded(FACE))
	{
		embedNewCell(FACE, phi2(phi_1(d)));
		copyCell(FACE, phi2(phi_1(d)), d);
	}

untereiner's avatar
untereiner committed
132
	//copy the volume embedding to new darts (same volume embedding for all darts on the faces)
133
134
135
136
137
	if(isOrbitEmbedded(VOLUME))
	{
		copyDartEmbedding(VOLUME, phi_1(d),  d);
		copyDartEmbedding(VOLUME, phi2(phi_1(d)),  d);

untereiner's avatar
untereiner committed
138
		if(!isBoundaryFace(d))
139
140
141
142
143
144
145
		{
			Dart d3 = phi3(d);

			copyDartEmbedding(VOLUME, phi1(d3), d3);
			copyDartEmbedding(VOLUME, phi2(phi1(d3)), d3);
		}
	}
untereiner's avatar
untereiner committed
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
void EmbeddedMap3::sewVolumes(Dart d, Dart e)
{
	//topological sewing
	Map3::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 ;
		do {
			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 ;
		do {
			vEmb1 = getEmbedding(EDGE, d);
			embedOrbit(EDGE, d, vEmb1) ;
			dd = phi1(dd) ;
		} while(dd != d) ;
	}

	//embed the face orbit from the volume sewn
	if (isOrbitEmbedded(FACE))
182
183
184
185
	{
		unsigned int vEmb1 = getEmbedding(FACE, d);
		embedOrbit(FACE, e, vEmb1) ;
	}
186
187
188
189
}

void EmbeddedMap3::unsewVolumes(Dart d)
{
untereiner's avatar
untereiner committed
190
	if(!Map3::isBoundaryFace(d))
Thomas's avatar
Thomas committed
191
	{
untereiner's avatar
untereiner committed
192
		Dart dd = phi1(phi3(d));
Thomas's avatar
Thomas committed
193
194
		Map3::unsewVolumes(d);

untereiner's avatar
untereiner committed
195
		Dart dit = d;
Thomas's avatar
Thomas committed
196
197
		do
		{
untereiner's avatar
untereiner committed
198
			//embed the unsewn vertex orbit with the vertex embedding if it is deconnected
Thomas's avatar
Thomas committed
199
200
			if(isOrbitEmbedded(VERTEX))
			{
untereiner's avatar
untereiner committed
201
				if(!sameVertex(dit,dd))
Thomas's avatar
Thomas committed
202
203
				{
					embedNewCell(VERTEX, dd);
untereiner's avatar
untereiner committed
204
					copyCell(VERTEX, dd, dit);
Thomas's avatar
Thomas committed
205
206
207
208
209
				}
			}

			dd = phi_1(dd);

untereiner's avatar
untereiner committed
210
			//embed the unsewn edge with the edge embedding if it is deconnected
Thomas's avatar
Thomas committed
211
212
			if(isOrbitEmbedded(EDGE))
			{
untereiner's avatar
untereiner committed
213
				if(!sameEdge(dit,dd))
Thomas's avatar
Thomas committed
214
215
				{
					embedNewCell(EDGE, dd);
untereiner's avatar
untereiner committed
216
					copyCell(EDGE, dd, dit);
Thomas's avatar
Thomas committed
217
218
219
				}
			}

untereiner's avatar
untereiner committed
220
221
			dit = phi1(dit);
		} while(dit!=d);
Thomas's avatar
Thomas committed
222

untereiner's avatar
untereiner committed
223
		//embed the unsewn face with the face embedding
Thomas's avatar
Thomas committed
224
225
226
227
228
229
		if (isOrbitEmbedded(FACE))
		{
			embedNewCell(FACE, dd);
			copyCell(FACE, dd, d);
		}
	}
230
231
232
233
234
235
236
237
238
239
240
}

bool EmbeddedMap3::mergeVolumes(Dart d)
{
	Dart d2 = phi2(d);

	if(Map3::mergeVolumes(d))
	{
		if (isOrbitEmbedded(VOLUME))
		{
				unsigned int vEmb = getEmbedding(VOLUME, d2);
untereiner's avatar
untereiner committed
241
				embedOrbit(VOLUME, d2, vEmb) ;
242
243
244
245
246
247
		}
		return true;
	}
	return false;
}

untereiner's avatar
untereiner committed
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
void EmbeddedMap3::splitVolume(std::vector<Dart>& vd)
{
	Map3::splitVolume(vd);

	//follow the edge path a second time to embed the vertex, edge and volume orbits
	for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
	{
		Dart dit = *it;
		Dart dit3 = alpha2(dit);

		//embed the vertex embedded from the origin volume to the new darts
		if(isOrbitEmbedded(VERTEX))
		{
			copyDartEmbedding(VERTEX, dit3, dit);
			copyDartEmbedding(VERTEX, phi2(dit), phi2(dit3));
		}

		//embed the edge embedded from the origin volume to the new darts
		if(isOrbitEmbedded(EDGE))
		{
			copyDartEmbedding(EDGE, dit3, dit);
			copyDartEmbedding(EDGE, phi2(dit), dit);
		}

		//embed the volume embedded from the origin volume to the new darts
		if(isOrbitEmbedded(VOLUME))
		{
untereiner's avatar
untereiner committed
275
276
			copyDartEmbedding(VOLUME, dit3, dit);
			copyDartEmbedding(VOLUME, phi2(dit), dit);
untereiner's avatar
untereiner committed
277
278
279
280
		}
	}
}

281
bool EmbeddedMap3::check()
282
{
283
284
285
	bool topo = Map3::check() ;
	if (!topo)
		return false ;
286

287
288
289
	std::cout << "Check: embedding begin" << std::endl ;
	DartMarker mv(*this);
	for(Dart d = begin(); d != end(); next(d))
290
	{
291
		if(isOrbitEmbedded(VERTEX))
292
		{
293
			if(!mv.isMarked(d))
294
			{
295
296
297
298
299
300
301
				mv.markOrbit(VERTEX, d);
				unsigned int emb = getEmbedding(VERTEX, d);
				FunctorCheckEmbedding<Map3> fce(*this, VERTEX, emb);
				if(foreach_dart_of_orbit(VERTEX, d, fce))
				{
					std::cout << "Embedding Check : different embeddings on vertex" << std::endl;
				}
302
			}
303
		}
304
305

	}
306
307
	std::cout << "Check: embedding ok" << std::endl ;
	return true ;
308
309
310
}

} // namespace CGoGN