embeddedMap3.cpp 11 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 34 35 36 37 38 39 40
	Dart v = Map3::deleteVertex(d) ;
	if(v != NIL)
	{
		if (isOrbitEmbedded(VOLUME))
		{
			embedOrbit(VOLUME, v, getEmbedding(VOLUME, v)) ;
		}
	}
	return v ;
41 42 43 44 45 46 47 48 49 50
}

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

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

untereiner's avatar
untereiner committed
51 52 53
		// embed the new darts created in the cut edge
		embedOrbit(EDGE, d, getEmbedding(EDGE, d)) ;
		// embed a new cell for the new edge and copy the attributes' line (c) Lionel
untereiner's avatar
untereiner committed
54 55
		embedNewCell(EDGE, nd) ;
		copyCell(EDGE, nd, d) ;
56 57
	}

untereiner's avatar
untereiner committed
58
	if(isOrbitEmbedded(ORIENTED_FACE))
59 60 61 62 63
	{
		Dart f = d;
		do
		{
			Dart nd = phi1(f) ;
untereiner's avatar
untereiner committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
			copyDartEmbedding(ORIENTED_FACE, nd, f);
			Dart e = phi3(nd);
			copyDartEmbedding(ORIENTED_FACE, phi1(e), e);
			f = alpha2(f);
		} while(f != d);
	}

	if(isOrbitEmbedded(FACE))
	{
		Dart f = d;
		do
		{
			unsigned int fEmb = getEmbedding(FACE, f) ;
			setDartEmbedding(FACE, phi1(f), fEmb);
			setDartEmbedding(FACE, phi3(f), fEmb);
79 80 81 82 83 84 85 86 87
			f = alpha2(f);
		} while(f != d);
	}

	if(isOrbitEmbedded(VOLUME))
	{
		Dart f = d;
		do
		{
untereiner's avatar
untereiner committed
88 89 90
			unsigned int vEmb = getEmbedding(VOLUME, f) ;
			setDartEmbedding(VOLUME, phi1(f), vEmb);
			setDartEmbedding(VOLUME, phi2(f), vEmb);
91 92 93 94 95
			f = alpha2(f);
		} while(f != d);
	}
}

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

untereiner's avatar
untereiner committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
Dart EmbeddedMap3::deleteEdge(Dart d)
{
	Dart v = Map3::deleteVertex(d) ;
	if(v != NIL)
	{
		if(isOrbitEmbedded(VOLUME))
		{
			embedOrbit(VOLUME, v, getEmbedding(VOLUME, v)) ;
		}
	}
	return v;
}

Dart EmbeddedMap3::collapseEdge(Dart d, bool delDegenerateVolumes)
{
	unsigned int vEmb = getEmbedding(VERTEX, d) ;

	Dart resV = Map3::collapseEdge(d, delDegenerateVolumes);

	if(resV != NIL)
	{
		if(isOrbitEmbedded(VERTEX))
		{
			embedOrbit(VERTEX,resV,vEmb);
		}
	}

	return resV;
}

140 141
void EmbeddedMap3::splitFace(Dart d, Dart e)
{
untereiner's avatar
untereiner committed
142 143 144 145
	Dart dd = phi1(phi3(d));
	Dart ee = phi1(phi3(e));

	Map3::splitFace(d, e);
146

untereiner's avatar
untereiner committed
147
	//copy the vertex embedding to new darts (same vertex embedding for all darts)
148 149
	if(isOrbitEmbedded(VERTEX))
	{
untereiner's avatar
untereiner committed
150 151 152 153 154
		copyDartEmbedding(VERTEX, phi_1(e), d);
		copyDartEmbedding(VERTEX, phi_1(d), e);
		copyDartEmbedding(VERTEX, phi_1(ee), dd);
		copyDartEmbedding(VERTEX, phi_1(dd), ee);
	}
155

untereiner's avatar
untereiner committed
156 157 158 159 160
	if(isOrbitEmbedded(ORIENTED_FACE))
	{
		copyDartEmbedding(ORIENTED_FACE, phi_1(d), d) ;
		embedNewCell(ORIENTED_FACE, e) ;
		copyCell(ORIENTED_FACE, e, d) ;
161

untereiner's avatar
untereiner committed
162 163 164
		copyDartEmbedding(ORIENTED_FACE, phi_1(dd), dd) ;
		embedNewCell(ORIENTED_FACE, ee) ;
		copyCell(ORIENTED_FACE, ee, dd) ;
165 166
	}

untereiner's avatar
untereiner committed
167
	//add a new face embedding to the created face
168 169
	if(isOrbitEmbedded(FACE))
	{
untereiner's avatar
untereiner committed
170 171 172 173 174
		unsigned int fEmb = getEmbedding(FACE, d) ;
		setDartEmbedding(FACE, phi_1(d), fEmb) ;
		setDartEmbedding(FACE, phi3(phi_1(d)), fEmb) ;
		embedNewCell(FACE, e);
		copyCell(FACE, e, d);
175 176
	}

untereiner's avatar
untereiner committed
177
	//copy the volume embedding to new darts (same volume embedding for all darts on the faces)
178 179
	if(isOrbitEmbedded(VOLUME))
	{
untereiner's avatar
untereiner committed
180 181 182
		unsigned int vEmb1 = getEmbedding(VOLUME, d) ;
		setDartEmbedding(VOLUME, phi_1(d),  vEmb1);
		setDartEmbedding(VOLUME, phi_1(e),  vEmb1);
183

untereiner's avatar
untereiner committed
184 185 186
		unsigned int vEmb2 = getEmbedding(VOLUME, dd) ;
		setDartEmbedding(VOLUME, phi_1(dd),  vEmb2);
		setDartEmbedding(VOLUME, phi_1(ee),  vEmb2);
187 188 189
	}
}

untereiner's avatar
untereiner committed
190
void EmbeddedMap3::sewVolumes(Dart d, Dart e, bool withBoundary)
191 192
{
	//topological sewing
untereiner's avatar
untereiner committed
193
	Map3::sewVolumes(d, e, withBoundary);
194 195 196 197 198 199

	//embed the vertex orbits from the oriented face with dart e
	//with vertex orbits value from oriented face with dart d
	if (isOrbitEmbedded(VERTEX))
	{
		Dart dd = d ;
untereiner's avatar
untereiner committed
200 201 202
		do
		{
			embedOrbit(VERTEX, dd, getEmbedding(VERTEX, dd)) ;
203 204 205 206 207 208 209 210 211
			dd = phi1(dd) ;
		} while(dd != d) ;
	}

	//embed the new edge orbit with the old edge orbit value
	//for all the face
	if (isOrbitEmbedded(EDGE))
	{
		Dart dd = d ;
untereiner's avatar
untereiner committed
212 213 214
		do
		{
			embedOrbit(EDGE, d, getEmbedding(EDGE, d)) ;
215 216 217 218 219 220
			dd = phi1(dd) ;
		} while(dd != d) ;
	}

	//embed the face orbit from the volume sewn
	if (isOrbitEmbedded(FACE))
221
	{
untereiner's avatar
untereiner committed
222
		embedOrbit(FACE, e, getEmbedding(FACE, d)) ;
223
	}
224 225 226 227
}

void EmbeddedMap3::unsewVolumes(Dart d)
{
228 229
	Dart dd = alpha1(d);

untereiner's avatar
untereiner committed
230
	Map3::unsewVolumes(d);
Thomas's avatar
Thomas committed
231

untereiner's avatar
untereiner committed
232 233 234 235 236 237 238 239 240
	unsigned int fEmb = EMBNULL ;
	if(isOrbitEmbedded(FACE))
		fEmb = getEmbedding(FACE, d) ;

	Dart dit = d;
	do
	{
		// embed the unsewn vertex orbit with the vertex embedding if it is deconnected
		if(isOrbitEmbedded(VERTEX))
Thomas's avatar
Thomas committed
241
		{
untereiner's avatar
untereiner committed
242
			if(!sameVertex(dit, dd))
Thomas's avatar
Thomas committed
243
			{
untereiner's avatar
untereiner committed
244 245
				embedNewCell(VERTEX, dd);
				copyCell(VERTEX, dd, dit);
246 247 248 249 250 251 252
				copyDartEmbedding(VERTEX, alpha1(dit), dit) ;
			}
			else
			{
				unsigned int vEmb = getEmbedding(VERTEX, dit) ;
				setDartEmbedding(VERTEX, alpha_2(dit), vEmb) ;
				setDartEmbedding(VERTEX, alpha_2(dd), vEmb) ;
Thomas's avatar
Thomas committed
253
			}
untereiner's avatar
untereiner committed
254
		}
Thomas's avatar
Thomas committed
255

untereiner's avatar
untereiner committed
256
		dd = phi_1(dd);
Thomas's avatar
Thomas committed
257

untereiner's avatar
untereiner committed
258 259 260 261
		// embed the unsewn edge with the edge embedding if it is deconnected
		if(isOrbitEmbedded(EDGE))
		{
			if(!sameEdge(dit, dd))
Thomas's avatar
Thomas committed
262
			{
untereiner's avatar
untereiner committed
263 264
				embedNewCell(EDGE, dd);
				copyCell(EDGE, dd, dit);
265 266 267 268 269 270 271
				copyDartEmbedding(EDGE, phi3(dit), dit) ;
			}
			else
			{
				unsigned int eEmb = getEmbedding(EDGE, dit) ;
				setDartEmbedding(EDGE, phi3(dit), eEmb) ;
				setDartEmbedding(EDGE, alpha_2(dit), eEmb) ;
Thomas's avatar
Thomas committed
272
			}
untereiner's avatar
untereiner committed
273
		}
Thomas's avatar
Thomas committed
274

untereiner's avatar
untereiner committed
275
		if(isOrbitEmbedded(FACE))
Thomas's avatar
Thomas committed
276
		{
untereiner's avatar
untereiner committed
277
			setDartEmbedding(FACE, phi3(dit), fEmb) ;
Thomas's avatar
Thomas committed
278
		}
untereiner's avatar
untereiner committed
279 280 281 282 283 284 285 286 287

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

	// embed the unsewn face with the face embedding
	if (isOrbitEmbedded(FACE))
	{
		embedNewCell(FACE, dd);
		copyCell(FACE, dd, d);
Thomas's avatar
Thomas committed
288
	}
289 290 291 292 293 294 295 296 297 298
}

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

	if(Map3::mergeVolumes(d))
	{
		if (isOrbitEmbedded(VOLUME))
		{
untereiner's avatar
untereiner committed
299
			embedOrbit(VOLUME, d2, getEmbedding(VOLUME, d2)) ;
300 301 302 303 304 305
		}
		return true;
	}
	return false;
}

untereiner's avatar
untereiner committed
306 307 308 309
void EmbeddedMap3::splitVolume(std::vector<Dart>& vd)
{
	Map3::splitVolume(vd);

untereiner's avatar
untereiner committed
310
	// follow the edge path a second time to embed the vertex, edge and volume orbits
untereiner's avatar
untereiner committed
311 312 313
	for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
	{
		Dart dit = *it;
untereiner's avatar
untereiner committed
314
		Dart dit23 = alpha2(dit);
untereiner's avatar
untereiner committed
315

untereiner's avatar
untereiner committed
316
		// embed the vertex embedded from the origin volume to the new darts
untereiner's avatar
untereiner committed
317 318
		if(isOrbitEmbedded(VERTEX))
		{
untereiner's avatar
untereiner committed
319 320
			copyDartEmbedding(VERTEX, dit23, dit);
			copyDartEmbedding(VERTEX, phi2(dit), phi1(dit));
untereiner's avatar
untereiner committed
321 322
		}

untereiner's avatar
untereiner committed
323
		// embed the edge embedded from the origin volume to the new darts
untereiner's avatar
untereiner committed
324 325
		if(isOrbitEmbedded(EDGE))
		{
untereiner's avatar
untereiner committed
326 327 328
			unsigned int eEmb = getEmbedding(EDGE, dit) ;
			setDartEmbedding(EDGE, dit23, eEmb);
			setDartEmbedding(EDGE, phi2(dit), eEmb);
untereiner's avatar
untereiner committed
329 330
		}

untereiner's avatar
untereiner committed
331
		// embed the volume embedded from the origin volume to the new darts
untereiner's avatar
untereiner committed
332 333
		if(isOrbitEmbedded(VOLUME))
		{
untereiner's avatar
untereiner committed
334
			copyDartEmbedding(VOLUME, phi2(dit), dit);
untereiner's avatar
untereiner committed
335 336
		}
	}
untereiner's avatar
untereiner committed
337 338 339

	if(isOrbitEmbedded(VOLUME))
	{
340
		Dart v = vd.front() ;
untereiner's avatar
untereiner committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354
		Dart v23 = alpha2(v) ;
		embedNewCell(VOLUME, v23) ;
		copyCell(VOLUME, v23, v) ;
	}
}

unsigned int EmbeddedMap3::closeHole(Dart d, bool forboundary)
{
	unsigned int nbF = Map3::closeHole(d, forboundary) ;

	DartMarkerStore mark(*this);	// Lock a marker

	std::vector<Dart> visitedFaces;	// Faces that are traversed
	visitedFaces.reserve(1024) ;
355 356
	visitedFaces.push_back(phi3(d));// Start with the face of d
	mark.markOrbit(ORIENTED_FACE, phi3(d)) ;
untereiner's avatar
untereiner committed
357 358 359 360

	// For every face added to the list
	for (std::vector<Dart>::iterator it = visitedFaces.begin(); it != visitedFaces.end(); ++it)
	{
361 362
		Dart f = *it ;
		do
untereiner's avatar
untereiner committed
363
		{
364
			if(isOrbitEmbedded(VERTEX))
untereiner's avatar
untereiner committed
365
			{
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
				copyDartEmbedding(VERTEX, f, alpha1(f)) ;
			}
			if(isOrbitEmbedded(EDGE))
			{
				copyDartEmbedding(EDGE, f, phi3(f)) ;
			}
			if(isOrbitEmbedded(FACE))
			{
				copyDartEmbedding(FACE, f, phi3(f)) ;
			}

			Dart adj = phi2(f);	// Get adjacent face
			if (!mark.isMarked(adj))
			{
				visitedFaces.push_back(adj);	// Add it
				mark.markOrbit(ORIENTED_FACE, adj) ;
			}

			f = phi1(f) ;
		} while(f != *it) ;
untereiner's avatar
untereiner committed
386 387 388
	}

	return nbF ;
untereiner's avatar
untereiner committed
389 390
}

391
bool EmbeddedMap3::check()
392
{
393 394 395
	bool topo = Map3::check() ;
	if (!topo)
		return false ;
396

397 398
	std::cout << "Check: embedding begin" << std::endl ;
	for(Dart d = begin(); d != end(); next(d))
399
	{
400
		if(isOrbitEmbedded(VERTEX))
401
		{
untereiner's avatar
untereiner committed
402 403
			if( getEmbedding(VERTEX, d) != getEmbedding(VERTEX, alpha1(d)) ||
					getEmbedding(VERTEX, d) != getEmbedding(VERTEX, alpha2(d)) )
404
			{
untereiner's avatar
untereiner committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
				std::cout << "Embedding Check : different embeddings on vertex" << std::endl ;
				return false ;
			}
		}

		if(isOrbitEmbedded(EDGE))
		{
			if( getEmbedding(EDGE, d) != getEmbedding(EDGE, phi2(d)) ||
					getEmbedding(EDGE, d) != getEmbedding(EDGE, phi3(d)) )
			{
				std::cout << "Embedding Check : different embeddings on edge" << std::endl ;
				return false ;
			}
		}

		if (isOrbitEmbedded(ORIENTED_FACE))
		{
			if (getEmbedding(ORIENTED_FACE, d) != getEmbedding(ORIENTED_FACE, phi1(d)))
			{
				CGoGNout << "Check: different embeddings on oriented face" << CGoGNendl ;
				return false ;
426
			}
427
		}
428

untereiner's avatar
untereiner committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
		if (isOrbitEmbedded(FACE))
		{
			if( getEmbedding(FACE, d) != getEmbedding(FACE, phi1(d)) ||
					getEmbedding(FACE, d) != getEmbedding(FACE, phi3(d)) )
			{
				CGoGNout << "Check: different embeddings on face" << CGoGNendl ;
				return false ;
			}
		}

		if (isOrbitEmbedded(VOLUME))
		{
			if( getEmbedding(VOLUME, d) != getEmbedding(VOLUME, phi1(d)) ||
					getEmbedding(VOLUME, d) != getEmbedding(VOLUME, phi2(d)) )
			{
				CGoGNout << "Check: different embeddings on volume" << CGoGNendl ;
				return false ;
			}
		}
448
	}
449 450
	std::cout << "Check: embedding ok" << std::endl ;
	return true ;
451 452 453
}

} // namespace CGoGN