embeddedGMap3.cpp 9.87 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
/*******************************************************************************
* 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/embeddedGMap3.h"

namespace CGoGN
{

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
void EmbeddedGMap3::unsewFaces(Dart d)
{
	Dart e = beta2(d);
	GMap3::unsewFaces(d);

	if (isOrbitEmbedded(VERTEX))
	{
		if(!sameVertex(d,e))
		{
			embedNewCell(VERTEX, e);
			copyCell(VERTEX, e, d);
		}

		d = beta0(d);
		e = beta0(e);

		if(!sameVertex(d,e))
		{
			embedNewCell(VERTEX, e);
			copyCell(VERTEX, e, d);
		}
	}

	if (isOrbitEmbedded(EDGE))
	{
		embedNewCell(EDGE, e);
		copyCell(EDGE, e, d);
	}
}

63 64 65 66 67 68 69 70 71 72 73
void EmbeddedGMap3::sewVolumes(Dart d, Dart e)
{
	//topological sewing
	GMap3::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 ;
74 75
		do
		{
76 77 78 79 80 81 82 83 84 85 86 87
			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 ;
88 89 90 91
		do
		{
			vEmb1 = getEmbedding(EDGE, dd);
			embedOrbit(EDGE, dd, vEmb1) ;
92 93 94 95 96 97
			dd = phi1(dd) ;
		} while(dd != d) ;
	}

	//embed the face orbit from the volume sewn
	if (isOrbitEmbedded(FACE))
Thomas's avatar
Thomas committed
98 99 100 101
	{
		unsigned int vEmb = getEmbedding(FACE, d);
		embedOrbit(FACE, e, vEmb) ;
	}
102 103 104 105
}

void EmbeddedGMap3::unsewVolumes(Dart d)
{
Thomas's avatar
Thomas committed
106 107
	Dart dd = phi1(phi3(d));

Thomas's avatar
Thomas committed
108
	if(beta3(d)!=d)
Thomas's avatar
Thomas committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	{
		GMap3::unsewVolumes(d);

		Dart ddd = d;
		do
		{
			if(isOrbitEmbedded(VERTEX))
			{
				if(!sameVertex(ddd,dd))
				{
					embedNewCell(VERTEX, ddd);
					copyCell(VERTEX, ddd, dd);
				}
			}

			dd = phi_1(dd);

			if(isOrbitEmbedded(EDGE))
			{
				if(!sameEdge(ddd,dd))
				{
					embedNewCell(EDGE, dd);
131
					copyCell(EDGE, dd, ddd);
Thomas's avatar
Thomas committed
132 133 134 135 136 137 138 139 140 141 142 143 144
				}
			}

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


		if (isOrbitEmbedded(FACE))
		{
			embedNewCell(FACE, dd);
			copyCell(FACE, dd, d);
		}
	}
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
}

bool EmbeddedGMap3::mergeVolumes(Dart d)
{
	Dart d2 = phi2(d);
	Dart a_2 = phi3(phi2(d));

	if(GMap3::mergeVolumes(d))
	{
		if (isOrbitEmbedded(VOLUME))
		{
				unsigned int vEmb = getEmbedding(VOLUME, d2);
				embedOrbit(VOLUME, a_2, vEmb) ;
		}
		return true;
	}
	return false;
}

void EmbeddedGMap3::splitFace(Dart d, Dart e)
{
	GMap3::splitFace(d,e);

	if(isOrbitEmbedded(VERTEX))
	{
Thomas's avatar
Thomas committed
170 171
		unsigned int vEmb = getEmbedding(VERTEX, d);
		embedOrbit(VERTEX,phi2(phi_1(d)),vEmb);
172

Thomas's avatar
Thomas committed
173 174
		vEmb = getEmbedding(VERTEX, e);
		embedOrbit(VERTEX,phi2(phi_1(e)),vEmb);
175 176 177 178 179 180
	}

	if(isOrbitEmbedded(FACE))
	{
		embedNewCell(FACE, phi2(phi_1(d)));
		copyCell(FACE, phi2(phi_1(d)), d);
Thomas's avatar
Thomas committed
181 182 183 184 185 186

		copyDartEmbedding(FACE, phi_1(d),  d);
		copyDartEmbedding(FACE, beta0(phi_1(d)),  beta0(d));

		copyDartEmbedding(FACE, beta3(phi_1(d)),  beta3(d));
		copyDartEmbedding(FACE, beta3(beta0(phi_1(d))),  beta3(beta0(d)));
187 188 189 190 191
	}

	if(isOrbitEmbedded(VOLUME))
	{
		copyDartEmbedding(VOLUME, phi_1(d),  d);
Thomas's avatar
Thomas committed
192
		copyDartEmbedding(VOLUME, beta0(phi_1(d)),  beta0(d));
193
		copyDartEmbedding(VOLUME, phi2(phi_1(d)),  d);
Thomas's avatar
Thomas committed
194
		copyDartEmbedding(VOLUME, beta0(phi2(phi_1(d))),  beta0(d));
195 196 197 198 199 200

		if(phi3(d) != d)
		{
			Dart d3 = phi3(d);

			copyDartEmbedding(VOLUME, phi1(d3), d3);
Thomas's avatar
Thomas committed
201
			copyDartEmbedding(VOLUME, beta0(phi1(d3)), beta0(d3));
202
			copyDartEmbedding(VOLUME, phi2(phi1(d3)), d3);
Thomas's avatar
Thomas committed
203
			copyDartEmbedding(VOLUME, beta0(phi2(phi1(d3))), beta0(d3));
204 205 206 207 208 209 210 211 212 213
		}
	}
}

void EmbeddedGMap3::cutEdge(Dart d)
{
	GMap3::cutEdge(d);

	if(isOrbitEmbedded(EDGE))
	{
Thomas's avatar
Thomas committed
214
		Dart nd = phi1(d);
215

Thomas's avatar
Thomas committed
216 217
		embedNewCell(EDGE, nd);
		copyCell(EDGE, nd, d);
218 219

		unsigned int vEmb = getEmbedding(EDGE, d);
Thomas's avatar
Thomas committed
220
		embedOrbit(EDGE, d, vEmb);
221 222 223 224 225 226 227
	}

	if(isOrbitEmbedded(FACE))
	{
		Dart f = d;
		do
		{
Thomas's avatar
Thomas committed
228 229 230
			Dart nd = phi1(f);
			unsigned int fEmb = getEmbedding(FACE, f);
			embedOrbit(FACE, nd, fEmb);
231 232 233 234 235

			Dart f2 = phi2(nd);
			if(f2!=nd)
			{
				Dart nd2 = phi2(f);
Thomas's avatar
Thomas committed
236 237
				unsigned int fEmb2 = getEmbedding(FACE, f2);
				embedOrbit(FACE, nd2, fEmb2);
238 239 240 241 242 243 244 245
			}

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

	if(isOrbitEmbedded(VOLUME))
	{
Thomas's avatar
Thomas committed
246 247 248 249 250 251 252 253
//		Dart f = d;
//		do
//		{
//			unsigned int fEmb2 = getEmbedding(VOLUME, d);
//			embedOrbit(VOLUME, d, fEmb2);
//			f = alpha2(f);
//		} while(f != d);

254 255 256
		Dart f = d;
		do
		{
Thomas's avatar
Thomas committed
257
			Dart nd = phi1(f);
258
			copyDartEmbedding(VOLUME, nd, f);
259
			copyDartEmbedding(VOLUME, beta1(nd), f);
Thomas's avatar
Thomas committed
260
			copyDartEmbedding(VOLUME, beta2(nd), f);
261
			copyDartEmbedding(VOLUME, beta1(beta2(nd)), f);
262

Thomas's avatar
Thomas committed
263 264 265 266 267 268
//			Dart nd2 = beta2(nd);
//			if(f!=nd2)
//			{
//				copyDartEmbedding(VOLUME, nd2, f);
//				copyDartEmbedding(VOLUME, beta0(nd2), f);
//			}
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304

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

//int EmbeddedGMap3::collapseEdge(Dart d, bool delDegenerateFaces,
//		bool delDegenerateVolumes)
//{
//	int nbCol = GMap3::collapseEdge(d,delDegenerateFaces,delDegenerateVolumes);
//
//	return nbCol;
//}

//void EmbeddedGMap3::collapseFace(Dart d, bool delDegenerateFaces,
//		bool delDegenerateVolumes)
//{
//	GMap3::collapseFace(d,delDegenerateFaces,delDegenerateVolumes);
//
////	if(isOrbitEmbedded(VERTEX))
////	{
////		embedOrbit(VERTEX,dsave,vEmb);
////	}
//}

//TODO collapseVolume

unsigned int EmbeddedGMap3::closeHole(Dart d)
{
	unsigned int nbE = GMap3::closeHole(d);
	Dart dd = phi2(d);
	Dart f = dd;

	do
	{
		if(isOrbitEmbedded(VERTEX))
Thomas's avatar
Thomas committed
305
		{
306
			copyDartEmbedding(VERTEX,f, phi1(phi2(f)));
Thomas's avatar
Thomas committed
307 308
			copyDartEmbedding(VERTEX,beta1(f), beta1(phi1(phi2(f))));
		}
309
		if(isOrbitEmbedded(EDGE))
Thomas's avatar
Thomas committed
310
		{
311
			copyDartEmbedding(EDGE, f, phi2(f));
Thomas's avatar
Thomas committed
312 313
			copyDartEmbedding(EDGE, beta0(f), beta0(phi2(f)));
		}
314
		if(isOrbitEmbedded(VOLUME))
Thomas's avatar
Thomas committed
315
		{
316
			copyDartEmbedding(VOLUME, f, phi2(f));
Thomas's avatar
Thomas committed
317 318
			copyDartEmbedding(VOLUME, beta0(f), beta0(phi2(f)));
		}
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337

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

	return nbE;
}

void EmbeddedGMap3::closeMap(DartMarker &marker)
{
	GMap3::closeMap(marker);

	for(Dart d = begin() ; d != end() ; next(d))
	{
		if(marker.isMarked(d))
		{
			if(isOrbitEmbedded(VERTEX))
			{
				copyDartEmbedding(VERTEX, d, phi1(phi3(d)));
Thomas's avatar
Thomas committed
338
				copyDartEmbedding(VERTEX, beta0(d), beta0(phi1(phi3(d))));
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
			}
		}
	}
}

bool EmbeddedGMap3::check()
{
	bool topo = GMap3::check() ;
	if (!topo)
		return false ;

	CGoGNout << "Check: embedding begin" << CGoGNendl ;
	for(Dart d = begin(); d != end(); next(d))
	{
		if (isOrbitEmbedded(VERTEX))
		{
Thomas's avatar
Thomas committed
355
			if (getEmbedding(VERTEX, d) != getEmbedding(VERTEX, beta1(d)))
356
			{
357
				CGoGNout << "Check: different embeddings on vertex (1)" << CGoGNendl ;
358 359 360
				return false ;
			}

Thomas's avatar
Thomas committed
361 362
			if (getEmbedding(VERTEX, d) != getEmbedding(VERTEX, beta2(d)))
			{
363
				CGoGNout << "Check: different embeddings on vertex (2)" << CGoGNendl ;
Thomas's avatar
Thomas committed
364 365
				return false ;
			}
366

Thomas's avatar
Thomas committed
367 368
			if (getEmbedding(VERTEX, d) != getEmbedding(VERTEX, beta3(d)))
			{
369
				CGoGNout << "Check: different embeddings on vertex (3)" << CGoGNendl ;
Thomas's avatar
Thomas committed
370 371
				return false ;
			}
372 373
		}

Thomas's avatar
Thomas committed
374 375 376 377
		if (isOrbitEmbedded(EDGE))
		{
			if (getEmbedding(EDGE, d) != getEmbedding(EDGE, beta0(d)))
			{
378
				CGoGNout << "Check: different embeddings on edge (0)" << CGoGNendl ;
Thomas's avatar
Thomas committed
379 380 381 382 383
				return false ;
			}

			if (getEmbedding(EDGE, d) != getEmbedding(EDGE, beta2(d)))
			{
384
				CGoGNout << "Check: different embeddings on edge (1)" << CGoGNendl ;
Thomas's avatar
Thomas committed
385 386 387 388 389
				return false ;
			}

			if (getEmbedding(EDGE, d) != getEmbedding(EDGE, beta3(d)))
			{
390
				CGoGNout << "Check: different embeddings on edge (2)" << CGoGNendl ;
Thomas's avatar
Thomas committed
391 392 393 394 395 396 397 398
				return false ;
			}
		}

		if (isOrbitEmbedded(FACE))
		{
			if (getEmbedding(FACE, d) != getEmbedding(FACE, beta0(d)))
			{
399
				CGoGNout << "Check: different embeddings on face (0)" << CGoGNendl ;
Thomas's avatar
Thomas committed
400 401 402 403 404
				return false ;
			}

			if (getEmbedding(FACE, d) != getEmbedding(FACE, beta1(d)))
			{
405
				CGoGNout << "Check: different embeddings on face (1)" << CGoGNendl ;
Thomas's avatar
Thomas committed
406 407 408 409 410 411 412 413
				return false ;
			}
		}

		if (isOrbitEmbedded(VOLUME))
		{
			if (getEmbedding(VOLUME, d) != getEmbedding(VOLUME, beta0(d)))
			{
414
				CGoGNout << "Check: different embeddings in volume (0)" << CGoGNendl ;
Thomas's avatar
Thomas committed
415 416 417 418 419
				return false ;
			}

			if (getEmbedding(VOLUME, d) != getEmbedding(VOLUME, beta1(d)))
			{
420
				CGoGNout << "Check: different embeddings in volume (1)" << CGoGNendl ;
Thomas's avatar
Thomas committed
421 422 423 424 425
				return false ;
			}

			if (getEmbedding(VOLUME, d) != getEmbedding(VOLUME, beta2(d)))
			{
426
				CGoGNout << "Check: different embeddings in volume (2)" << CGoGNendl ;
Thomas's avatar
Thomas committed
427 428 429
				return false ;
			}
		}
430 431 432 433 434 435
	}
	CGoGNout << "Check: embedding ok" << CGoGNendl ;
	return true ;
}

} // namespace CGoGN