map3.cpp 34.4 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 37 38 39 40 41 42 43
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <list>
#include <set>
#include <map>
#include <vector>

#include "Topology/map/map3.h"

namespace CGoGN
{

/*! @name Generator and Deletor
 *  To generate or delete volumes in a 3-map
 *************************************************************************/
//ok
void Map3::deleteOrientedVolume(Dart d)
{
	DartMarkerStore mark(*this);		// Lock a marker

	std::vector<Dart> visitedFaces;		// Faces that are traversed
44
	visitedFaces.reserve(512);
Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
	visitedFaces.push_back(d);			// Start with the face of d

//	// For every face added to the list
//	for (face = visitedFaces.begin(); !found && face != visitedFaces.end(); ++face)
//	{
//		if (!mark.isMarked(*face))		// Face has not been visited yet
//		{
//			unsewVolumes(*face);
//
//			Dart dNext = *face ;
//			do
//			{
//				mark.mark(dNext);					// Mark
//				Dart adj = phi2(dNext);				// Get adjacent face
//				if (adj != dNext && !mark.isMarked(adj))
//					visitedFaces.push_back(adj);	// Add it
//				dNext = phi1(dNext);
//			} while(dNext != *face);
//		}
//	}

66
	mark.markOrbit(FACE, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
67

68
	for(std::vector<Dart>::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70 71 72 73 74 75 76 77 78 79
	{
		Dart e = *face ;

		unsewVolumes(e);

		do	// add all face neighbours to the table
		{
			Dart ee = phi2(e) ;
			if(!mark.isMarked(ee)) // not already marked
			{
				visitedFaces.push_back(ee) ;
80
				mark.markOrbit(FACE, ee) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
81 82 83 84 85 86 87
			}
			e = phi1(e) ;
		} while(e != *face) ;
	}


	// delete every visited face
88
	for (std::vector<Dart>::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
89
		deleteCycle(*face);
Pierre Kraemer's avatar
Pierre Kraemer committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 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 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
}

/*! @name Topological Operators
 *  Topological operations on 3-maps
 *************************************************************************/
void Map3::sewVolumes(Dart d, Dart e)
{
	assert(faceDegree(d) == faceDegree(e));

	Dart fitD = d ;
	Dart fitE = e ;
	do
	{
		phi3sew(fitD,fitE);
		fitD = phi1(fitD) ;
		fitE = phi_1(fitE) ;
	} while(fitD != d) ;
}

void Map3::unsewVolumes(Dart d)
{
	Dart fitD = d;
	do
	{
		phi3unsew(fitD);
		fitD = phi1(fitD);
	} while(fitD != d);
}

bool Map3::mergeVolumes(Dart d)
{
	Dart e = phi3(d) ;
	if(e != d)
	{
		unsewVolumes(d);
		Map2::mergeVolumes(d, e); // merge the two volumes along common face
		return true ;
	}
	return false ;
}

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

	if (phi3(d) != d)
	{
		Dart dd = phi1(phi3(d));
		Dart ee = phi1(phi3(e));

		Map2::splitFace(dd,ee);

		phi3sew(phi_1(d), phi_1(ee));
		phi3sew(phi_1(e), phi_1(dd));
	}
}

void Map3::cutEdge(Dart d)
{
	if(phi3(d) == d)
		d = phi2(d);

	Dart prev = d;
	Dart dd = alpha2(d);
	Map2::cutEdge(d);

	while (dd!=d)
	{
		prev = dd;
		dd = alpha2(dd);

		Map2::cutEdge(prev);

		if (phi3(prev) != prev)
		{
			Dart d3 = phi3(prev);
			phi3unsew(prev);
			phi3sew(prev, phi1(d3));
			phi3sew(d3, phi1(prev));
		}
	}

	if (phi3(d) != d)
	{
		Dart d3 = phi3(d);
		phi3unsew(d);
		phi3sew(d, phi1(d3));
		phi3sew(d3, phi1(d));
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
181
bool Map3::uncutEdge(Dart d)
untereiner's avatar
untereiner committed
182
{
Pierre Kraemer's avatar
Pierre Kraemer committed
183 184 185 186
	if(vertexDegree(phi1(d)) == 2)
	{
		if(phi3(d) == d)
			d = phi_1(phi2(d));
untereiner's avatar
untereiner committed
187

Pierre Kraemer's avatar
Pierre Kraemer committed
188 189
		Dart prev = d;
		Dart dd = alpha2(d);
untereiner's avatar
untereiner committed
190

Pierre Kraemer's avatar
Pierre Kraemer committed
191
		Map2::uncutEdge(prev);
untereiner's avatar
untereiner committed
192

Pierre Kraemer's avatar
Pierre Kraemer committed
193 194
		if(phi3(dd) != dd)
			phi3sew(dd,phi2(prev));
untereiner's avatar
untereiner committed
195

Pierre Kraemer's avatar
Pierre Kraemer committed
196 197 198 199
		while (dd!=d)
		{
			prev = dd;
			dd = alpha2(dd);
untereiner's avatar
untereiner committed
200

Pierre Kraemer's avatar
Pierre Kraemer committed
201
			Map2::uncutEdge(prev);
untereiner's avatar
untereiner committed
202

Pierre Kraemer's avatar
Pierre Kraemer committed
203 204 205
			phi3sew(dd, phi2(prev));
		}
		return true;
untereiner's avatar
untereiner committed
206
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
207
	return false;
untereiner's avatar
untereiner committed
208 209
}

210
//besoin d'un iterator pour chaque face autour d'un sommet
untereiner's avatar
untereiner committed
211 212
bool Map3::deleteVertex(Dart d)
{
213 214
	//is boundary
	if(phi3(d) != d)
untereiner's avatar
untereiner committed
215
	{
216 217
		Dart e = d;
		Dart d3 = phi2(phi3(d));
untereiner's avatar
untereiner committed
218

219
		do
untereiner's avatar
untereiner committed
220
		{
221 222 223
			unsewVolumes(e);
			e = phi2(phi_1(e));
		}while(e != d);
untereiner's avatar
untereiner committed
224

225
		Map2::deleteVertex(d3);
untereiner's avatar
untereiner committed
226 227
	}

228
	Map2::deleteVertex(d);
untereiner's avatar
untereiner committed
229 230

	return true;
231 232 233 234 235 236 237 238 239 240 241 242 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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314

//	std::cout << "map3::deleteVertex" << std::endl;
//
//	DartMarkerStore mv(*this);	// Lock a marker
//
//	std::vector<Dart> darts_list;			//Darts that are traversed
//	darts_list.reserve(512);
//	darts_list.push_back(d);			//Start with the dart d
//	std::vector<Dart>::iterator darts;
//
//	mv.mark(d);
//
//	std::vector<Dart> unique_darts_list;
//	unique_darts_list.reserve(512);
//	unique_darts_list.push_back(d);
//
//
//	bool boundary = false;
//	if(isBoundaryVertex(d))
//		boundary = true;
//
//	std::cout << "isBoundary ? " << boundary << std::endl;
//
//	CellMarker mvolume(*this, VOLUME);
//
//	for(darts = darts_list.begin(); darts != darts_list.end() ; ++darts)
//	{
//		Dart dc = *darts;
//
//		//add phi21 and phi23 successor if they are not marked yet
//		Dart d2 = phi2(dc);
//		Dart d21 = phi1(d2); // turn in volume
//		Dart d23 = phi3(d2); // change volume
//
//		if(!mv.isMarked(d21))
//		{
//			darts_list.push_back(d21);
//			mv.mark(d21);
//		}
//
//		if((d23!=d2) && !mv.isMarked(d23))
//		{
//			darts_list.push_back(d23);
//			//if(!mvolume.isMarked(d23))
//			//{
//				unique_darts_list.push_back(d23);
//			//	mvolume.mark(d23);
//			//}
//			mv.mark(d23);
//		}
//
//		std::cout << "save a dart" << std::endl;
//	}
//
//	std::cout << "unique_darts_list size = " << unique_darts_list.size() << std::endl;
//
//	for(darts = unique_darts_list.begin(); darts != unique_darts_list.end() ; ++darts)
//	{
//		//std::cout << "merged ? " << mergeVolumes(*darts) << std::endl;
//
//		//if(!mergeVolumes(*darts))
//		//	return false;
//
//		std::cout << "mergevolumes" << std::endl;
//	}
//
//	std::cout << "end merging" << std::endl;
//
//	if(boundary)
//	{
//		std::cout << "is Boundary " << std::endl;
//		Dart vit = d ;
//			do
//			{
//				Dart f = phi_1(phi2(vit)) ;
//				phi1sew(vit, f) ;
//				vit = phi2(phi_1((vit))) ;
//			} while(vit != d) ;
//			Map1::deleteFace(d) ;
//	}
//
//	std::cout << "return" << std::endl;
//
//	return true;
untereiner's avatar
untereiner committed
315
}
Pierre Kraemer's avatar
Pierre Kraemer committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349

//TODO
//bool Map3::flipEdge(Dart d)
//{
//	if(phi3(d) == d)
//		d = phi2(d);
//
//	Dart e = alpha2(d);
//	Dart e2 = phi2(e);
//
//	// Test if an opposite
//	if (e != d)
//	{
//		Dart dPrev = phi_1(d);
//		Dart dNext = phi1(d);
//		Dart e2Prev = phi_1(e2);
//		Dart e2Next = phi1(e2);
//
//		phi1sew(d, e2Prev);		// Detach the two
//		phi1sew(e2, dPrev);		// vertices of the edge
//		phi1sew(d, dNext);		// Insert the edge in its
//		phi1sew(e2, e2Next);	// new vertices after flip
//		return true;
//	}
//	else // flip a border edge with Map2 flipEdge
//		return Map2::flipEdge(d);
//}

//TODO
//bool Map3::flipBackEdge(Dart d)
//{
//	return false;
//}

untereiner's avatar
untereiner committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
////TODO
//bool Map3::flipFace(Dart d)
//{
//	//prevoir de refaire un linkFace et de ne pas
//	//faire inserFace si flipEdge renvoie faux
//
//	//save a dart from a non-modifed-face of one tetrahedron
//	Dart r = phi2(d);
//
//	//detach common face from tetrahedron from the rest of the faces
//	//unlinkFace(d);
//	Map3::mergeVolumes(d);
//
//	//flip the common edge
//	Map2::flipEdge(r);
//
//	//insert the old face in the new flipped edge
//	//Map3::insertFace(r,d);
//	Map3::splitFace(r,d);
//
//	return true;
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
372

untereiner's avatar
untereiner committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
//void Map3::insertFace(Dart d, Dart e)
//{
//	assert(faceDegree(d) == faceDegree(e)); //les faces ont la meme longueur
//
//    Dart dd = d;
//    Dart nFd = e;
//
//    do {
//    	//sewFace(dd,nFd);
//
//    	Dart d2 = phi2(dd);
//        unsewFaces(dd);
//        sewFaces(d2,phi3(nFd));
//        sewFaces(dd,nFd);
//
//        dd = phi_1(phi2(phi_1(dd)));
//        nFd = phi1(nFd);
//    } while (nFd != e);
//
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 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


int Map3::collapseEdge(Dart d, bool delDegenerateFaces,
		bool delDegenerateVolumes)
{
	Dart e = d;
	int i = 0;

	//stocke un brin par volume autour de l'arete
	std::list<Dart> tmp;
	do
	{
		tmp.push_back(e);
		e = alpha2(e);
		i++;
	} while (e != d);

	for (std::list<Dart>::iterator it = tmp.begin(); it != tmp.end(); ++it)
	{
		Dart e = phi2(*it);

		cutSpike(e);

		Dart t1=e,t2=e;
		//si les faces opposées ont un tetraedre cousu
		if(phi3(phi2(phi1(e))) != phi2(phi1(e))) {
			t1 = phi3(phi2(phi1(e)));
			unsewVolumes(t1);
		}

		if(phi3(phi2(phi_1(e))) != phi2(phi_1(e))) {
			t2 = phi3(phi2(phi_1(e)));
			unsewVolumes(t2);
		}

		if(t1 != e && t2 != e) {
			sewVolumes(t1,t2);
		}

		//unsewVolumes(e);
		//unsewVolumes(*it);

		deleteOrientedVolume(*it);
	}

	return i;
}

441
//	CGoGNout << "coll topo" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
//	Dart e = d;
//
//	//stocke un brin par volume autour de l'arete
//	std::list<Dart> tmp;
//	do
//	{
//		tmp.push_back(e);
//		e = alpha2(e);
//	} while (e != d);
//
//	//contraction de la 2 carte de chaque 2-arete
//	for (std::list<Dart>::iterator it = tmp.begin(); it != tmp.end(); ++it)
//	{
//		//un brin d'une face adjacente a l'arrete contracte
//		Dart d = phi2(phi_1(*it));
//		Map2::collapseEdge(*it, delDegenerateFaces);
//
//		//test de la degeneresence
//		//impossible d'avoir un volume de moins de 4 faces sans avoir de phi2 en points fixe donc on les vire
//		if(delDegenerateVolumes && Map2::volumeDegree(d) < 4)
//		{
463
//			CGoGNout << "del vol" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
464 465 466 467 468 469 470 471 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
//			Dart e = d;
//			//pour tous les brins de la face adjacente
//
//			do
//			{
//				Dart ee = phi3(e);
//				Dart ff = phi3(phi2(e));
//
//				//si les brins ont un voisin par phi3
//				if(ee != e)
//					phi3unsew(ee);
//
//				if(ff != phi2(e))
//					phi3unsew(ff);
//
//				//si les deux en ont un, il faut les coudres ensemble
//				if(ee != e && ff != phi2(e))
//					phi3sew(ee, ff);
//
//				//on peut supprimer les brins de cette arete
//				deleteDart(e);
//				deleteDart(phi2(e));
//				e = phi1(e);
//
//			} while (e != d);
//		}
//	}

//TODO
void Map3::collapseFace(Dart d, bool delDegenerateFaces,
		bool delDegenerateVolumes)
{
	Dart e = d;
	std::list<Dart> tmp;

	//save a dart from the edge for all neighbors
	do
	{
		//if(phi3(phi2(e)) != phi2(e))
		//		tmp.push_back(phi3(phi2(e)));
		tmp.push_back(phi3(phi2(e)));
		e = phi1(e);
	}while(e != d);

	//del the last one (n-1 edge collapse)
	tmp.pop_back();

511
	//CGoGNout << "#voisin=" << tmp.size() << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
512 513 514 515 516

	//collapse all the edges in the list
	for(std::list<Dart>::iterator it = tmp.begin() ; it != tmp.end() ; ++it)
	{
		Dart d = *it;
517
		//CGoGNout << "collapseEdge" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
		//collapseEdge(*it, delDegenerateFaces, delDegenerateVolumes);
		//stocke un brin par volume autour de l'arete

		Dart e = d;

		//stocke un brin par volume autour de l'arete
		std::list<Dart> tmpedge;
		do
		{
			tmpedge.push_back(e);
			e = alpha2(e);
		} while (e != d);

		for (std::list<Dart>::iterator it = tmpedge.begin(); it != tmpedge.end(); ++it)
		{
			Dart e = phi2(*it);

			cutSpike(e);

			Dart t1=e,t2=e;
			//si les faces opposées ont un tetraedre cousu
			if(phi3(phi2(phi1(e))) != phi2(phi1(e))) {
				t1 = phi3(phi2(phi1(e)));
				unsewVolumes(t1);
			}

			if(phi3(phi2(phi_1(e))) != phi2(phi_1(e))) {
				t2 = phi3(phi2(phi_1(e)));
				unsewVolumes(t2);
			}

			if(t1 != e && t2 != e) {
				sewVolumes(t1,t2);
			}

			//deleteOrientedVolume(*it);
		}
	}
//	for(std::list<Dart>::iterator it = tmp.begin() ; it != tmp.end() ; ++it)
//	{
//		deleteOrientedVolume(*it);
//	}
}

//TODO
void Map3::collapseVolume(Dart d, bool delDegenerateFaces,
		bool delDegenerateVolumes)
{
	//pour toutes les faces du volume
	//sauvegarder un brin du voisin s'il existe
	std::vector<Dart> neighborsVol;
	neighborsVol.reserve(16);

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

	std::vector<Dart> visitedFaces;		// Faces that are traversed
	visitedFaces.reserve(16);
	visitedFaces.push_back(d);			// Start with the face of d
	std::vector<Dart>::iterator face;

	// For every face added to the list
	for (face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
	{
		Dart dsave = *face ;
		if(phi3(dsave) != dsave)
			neighborsVol.push_back(dsave);


	}

	// delete every visited face
	for (face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
590
		deleteCycle(*face);
Pierre Kraemer's avatar
Pierre Kraemer committed
591 592 593 594 595 596 597

	//enlever le dernier (n-1) face collapse


	//contracter toutes les faces de la liste
}

598 599

bool Map3::mergeFaces(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
600 601
{

602
 return false;
Pierre Kraemer's avatar
Pierre Kraemer committed
603 604 605 606 607 608 609 610 611
}

Dart Map3::cutSpike(Dart d)
{
  Dart e=d;
  int nb=0;
  Dart dNew;
  int tet=0;

612
  //CGoGNout << "cut" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
613 614 615 616 617 618 619 620 621

  //count the valence of the vertex
  do {
    nb++;
    e=phi1(phi2(e));
  } while (e!=d);

  if(nb<3)
  {
622
	CGoGNout << "Warning : cannot cut 2 volumes without creating a degenerated face " << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
623 624 625 626 627 628 629 630 631
	return d;
  }
  else
  {
	 //triangulate around the vertex
	do {
		if(phi1(phi1(phi1(e)))!=e)
		{
			splitFace(phi_1(e),phi1(e));
632
			//CGoGNout << "split" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
633 634 635 636 637 638 639
		}
		else
			tet++;

		e=phi1(phi2(e));
	} while (e!=d);

640 641
//	CGoGNout << "#tet= " << tet << CGoGNendl;
//	CGoGNout << "#nb= " << nb << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
642 643 644

	//si toute ces faces ne sont pas triangulaires (on insere une face)
	if(tet != nb) {
645
		//CGoGNout << "new face" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
		dNew=newFace(nb);
		Dart d3 = newFace(nb);
		sewVolumes(dNew,d3);

		//sew a face following the triangles
		Dart dTurn=dNew;
		do {
			Dart d1 = phi1(e);
			Dart dSym = phi2(d1);
			phi2unsew(d1);
			phi2sew(dTurn,d1);
			phi2sew(phi3(dTurn),dSym);
			dTurn = phi1(dTurn);
			e=phi1(phi2(e));
		}while(e!=d);
	}
	else
		dNew = d;
  }

  return dNew;
}

669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
/*! @name Topological Queries
 *  Return or set various topological information
 *************************************************************************/

bool Map3::sameOrientedVertex(Dart d, Dart e)
{
	DartMarkerStore mv(*this);	// Lock a marker

	std::list<Dart> darts_list;			//Darts that are traversed
	darts_list.push_back(d);			//Start with the dart d
	mv.mark(d);

	for(std::list<Dart>::iterator darts = darts_list.begin();darts != darts_list.end() ; ++darts)
	{
		Dart dc = *darts;

		if(dc==e)
			return true;

		//add phi21 and phi23 successor if they are not marked yet
		Dart d2 = phi2(dc);
		if(d2 != dc)
		{
			Dart d21 = phi1(d2); // turn in volume
			Dart d23 = phi3(d2); // change volume

			if(!mv.isMarked(d21))
			{
				darts_list.push_back(d21);
				mv.mark(d21);
			}

			if((d23!=d2) && !mv.isMarked(d23))
			{
				darts_list.push_back(d23);
				mv.mark(d23);
			}
		}
	}

	return false;
}

bool Map3::sameVertex(Dart d, Dart e)
{
	return sameOrientedVertex(d,e);
}

bool Map3::sameOrientedEdge(Dart d, Dart e)
{
	  Dart dd = d;
	  do
	  {
		  if(dd==e || phi2(dd)==e)
			  return true;

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

	  return false;
}

bool Map3::sameEdge(Dart d, Dart e)
{
	return sameOrientedEdge(d,e);
}


Pierre Kraemer's avatar
Pierre Kraemer committed
737 738 739 740 741 742 743 744 745 746 747 748 749 750
int Map3::edgeDegree(Dart d)
{
	int deg = 0;
	Dart e = d;

	do
	{
		deg++;
		e = alpha2(e);
	} while(e != d);

	return deg;
}

untereiner's avatar
untereiner committed
751 752 753 754 755
unsigned int Map3::vertexDegree(Dart d)
{
	int count = 0;
	DartMarkerStore mv(*this);	// Lock a marker

756 757 758
	std::list<Dart> darts_list;			//Darts that are traversed
	darts_list.push_back(d);			//Start with the dart d
	std::list<Dart>::iterator darts;
untereiner's avatar
untereiner committed
759 760 761

	mv.mark(d);

762
	for(darts = darts_list.begin(); darts != darts_list.end() ; ++darts)
untereiner's avatar
untereiner committed
763
	{
764
		Dart dc = *darts;
untereiner's avatar
untereiner committed
765 766 767 768 769 770 771 772

		//add phi21 and phi23 successor if they are not marked yet
		Dart d2 = phi2(dc);
		Dart d21 = phi1(d2); // turn in volume
		Dart d23 = phi3(d2); // change volume

		if(!mv.isMarked(d21))
		{
773
			darts_list.push_back(d21);
untereiner's avatar
untereiner committed
774 775 776 777 778
			mv.mark(d21);
		}

		if((d23!=d2) && !mv.isMarked(d23))
		{
779
			darts_list.push_back(d23);
untereiner's avatar
untereiner committed
780 781 782 783 784 785
			mv.mark(d23);
		}
	}

	DartMarkerStore me(*this);

786
	for(darts = darts_list.begin(); darts != darts_list.end() ; ++darts)
untereiner's avatar
untereiner committed
787
	{
788
		if(!me.isMarked(*darts))
untereiner's avatar
untereiner committed
789 790
		{
			++count;
791
			me.markOrbit(EDGE, *darts);
untereiner's avatar
untereiner committed
792 793 794 795 796 797
		}
	}

	return count;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
798 799 800 801 802 803 804 805
bool Map3::isBoundaryVolume(Dart d)
{
	bool isBoundary = false;
	DartMarkerStore mark(*this);		// Lock a marker

	std::vector<Dart> visitedFaces ;
	visitedFaces.reserve(100) ;
	visitedFaces.push_back(d) ;
806
	mark.markOrbit(FACE, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824

	for(std::vector<Dart>::iterator face = visitedFaces.begin(); !isBoundary && face != visitedFaces.end(); ++face)
	{
		Dart e = *face ;

		//if this dart is not phi3-linked
		if(phi3(e) == e)
			isBoundary = true;

		if(!isBoundary)
		{

			do	// add all face neighbours to the table
			{
				Dart ee = phi2(e) ;
				if(!mark.isMarked(ee)) // not already marked
				{
					visitedFaces.push_back(ee) ;
825
					mark.markOrbit(FACE, ee) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
826 827 828 829 830 831 832 833 834
				}
				e = phi1(e) ;
			} while(e != *face) ;
		}
	}

	return isBoundary;
}

835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
bool Map3::isBoundaryVertex(Dart d)
{
	DartMarkerStore mv(*this);			// Lock a marker
	bool found = false;					// Last functor return value

	std::list<Dart> darts_list;			//Darts that are traversed
	darts_list.push_back(d);			//Start with the dart d
	std::list<Dart>::iterator darts;

	mv.mark(d);

	for(darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
	{
		Dart dc = *darts;

		//add phi21 and phi23 successor if they are not marked yet
		Dart d2 = phi2(dc);
		Dart d21 = phi1(d2); // turn in volume
		Dart d23 = phi3(d2); // change volume

		if(!mv.isMarked(d21))
		{
			darts_list.push_back(d21);
			mv.mark(d21);
		}

		if((d23!=d2) && !mv.isMarked(d23))
		{
			darts_list.push_back(d23);
			mv.mark(d23);
		}

		found = phi3(dc) == dc;
	}

	return found;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
873 874 875 876
/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
877
bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
878
{
Sylvain Thery's avatar
Sylvain Thery committed
879
	DartMarkerStore mv(*this,thread);	// Lock a marker
Pierre Kraemer's avatar
Pierre Kraemer committed
880 881
	bool found = false;					// Last functor return value

Sylvain Thery's avatar
Sylvain Thery committed
882
	std::list<Dart> darts_list;			//Darts that are traversed
untereiner's avatar
untereiner committed
883
	darts_list.push_back(d);			//Start with the dart d
Pierre Kraemer's avatar
Pierre Kraemer committed
884 885
	mv.mark(d);

Sylvain Thery's avatar
Sylvain Thery committed
886
	for(std::list<Dart>::iterator darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
Pierre Kraemer's avatar
Pierre Kraemer committed
887 888 889 890 891
	{
		Dart dc = *darts;

		//add phi21 and phi23 successor if they are not marked yet
		Dart d2 = phi2(dc);
untereiner's avatar
untereiner committed
892
		if(d2 != dc)
Pierre Kraemer's avatar
Pierre Kraemer committed
893
		{
untereiner's avatar
untereiner committed
894 895
			Dart d21 = phi1(d2); // turn in volume
			Dart d23 = phi3(d2); // change volume
Pierre Kraemer's avatar
Pierre Kraemer committed
896

untereiner's avatar
untereiner committed
897 898 899 900 901 902 903 904 905 906 907
			if(!mv.isMarked(d21))
			{
				darts_list.push_back(d21);
				mv.mark(d21);
			}

			if((d23!=d2) && !mv.isMarked(d23))
			{
				darts_list.push_back(d23);
				mv.mark(d23);
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
908 909 910 911 912 913 914 915
		}

		found = f(dc);
	}

	return found;
}

Sylvain Thery's avatar
Sylvain Thery committed
916

Sylvain Thery's avatar
Sylvain Thery committed
917
bool Map3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
918 919 920
{
	Dart dNext = d;
	do {
Sylvain Thery's avatar
Sylvain Thery committed
921
		if (Map2::foreach_dart_of_edge(dNext,f,thread)) return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
922 923 924 925 926
		dNext = alpha2(dNext);
	} while (dNext != d);
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
927
bool Map3::foreach_dart_of_open_edge(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
928
{
Sylvain Thery's avatar
Sylvain Thery committed
929
	DartMarkerStore mv(*this,thread);	// Lock a marker
Pierre Kraemer's avatar
Pierre Kraemer committed
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
	bool found = false;					// Last functor return value

	std::list<Dart> darts_list;			//Darts that are traversed
	darts_list.push_back(d);			//Start with the dart d
	std::list<Dart>::iterator darts;

	mv.mark(d);

	for(darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
	{
		Dart d1 = *darts;

		Dart d3 = phi2(d1); // change face
		Dart d4 = phi3(d1); // change volume

		if (!mv.isMarked(d3))
		{
			darts_list.push_back(d3);
			mv.mark(d3);
		}
		if (!mv.isMarked(d4))
		{
			darts_list.push_back(d4);
			mv.mark(d4);
		}

		found = f(d1);
	}


	return found;
}

Sylvain Thery's avatar
Sylvain Thery committed
963
bool Map3::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
964
{
Sylvain Thery's avatar
Sylvain Thery committed
965
	if (foreach_dart_of_oriented_face(d,f,thread)) return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
966 967

	Dart d3 = phi3(d);
Sylvain Thery's avatar
Sylvain Thery committed
968
	if (d3 != d) return foreach_dart_of_oriented_face(d3,f,thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
969 970 971
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
972
bool Map3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
973
{
Sylvain Thery's avatar
Sylvain Thery committed
974
	DartMarkerStore mv(*this,thread);			// Lock a marker
Pierre Kraemer's avatar
Pierre Kraemer committed
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
	bool found = false;					// Last functor return value

	std::list<Dart> darts_list;			//Darts that are traversed
	darts_list.push_back(d);			//Start with the dart d
	std::list<Dart>::iterator darts;

	mv.mark(d);


	for(darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
	{
		Dart d1 = *darts;

		// add all successors if they are not marked yet
		Dart d2 = phi1(d1); // turn in face
		Dart d3 = phi2(d1); // change volume
		Dart d4 = phi3(d1); // change volume

		if (!mv.isMarked(d2))
		{
			darts_list.push_back(d2);
			mv.mark(d2);
		}
		if (!mv.isMarked(d3))
		{
			darts_list.push_back(d2);
			mv.mark(d2);
		}
		if (!mv.isMarked(d4))
		{
			darts_list.push_back(d4);
			mv.mark(d4);
		}

		found = f(d1);	// functor say finish
	}


	return found;
}

//bool Map3::foreach_connex_volume(Dart d, int degree, FunctorType& f, FunctorSelect<Dart>& s)
//{
//	Marker m = this->getNewMarker();
//	bool found = false;
//	std::list<Dart> darts_list;
//	std::list<Dart> neighbours_list;
//	darts_list.push_back(d);
1023
//	this->markOrbit(DART,d,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
//
//	std::list<Dart>::iterator prem = darts_list.begin();
//
//	while (!found && prem != darts_list.end()) {
//		Dart d1 = *prem;
//		Dart dd;
//		switch(degree) {
//			case 0 : //vertex connexity
//				{
//					dd=d1;
//					std::list<Dart> darts_list2;
//					darts_list2.push_back(dd);
1036
//					this->markOrbit(DART,dd,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
//					neighbours_list.push_back(dd);
//					std::list<Dart>::iterator prem2 = darts_list2.begin();
//
//					while (!found && prem2 != darts_list2.end()) {
//						Dart dd1 = *prem2;
//						Dart d3 = phi2(dd1);
//						Dart d2 = phi1(d3); // turn in volume
//						Dart d4 = phi3(d3); // change volume
//
//						if(s(dd1))
//							found =  f(dd1);
//
//						if(!this->isMarkedDart(d2,m)) {
//							darts_list2.push_back(d2);
1051
//							markOrbit(DART,d2,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1052 1053 1054 1055
//						}
//
//						if(!this->isMarkedDart(d4,m)) {
//							darts_list2.push_back(d4);
1056
//							markOrbit(DART,d4,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
//						}
//
//						++prem2;
//					}
//				}
//				break;
//			case 1 : //edge connexity
//				dd=d1;
//				neighbours_list.push_back(dd);
//				do {
//					if(!this->isMarkedDart(dd,m)) {
1068
//						markOrbit(DART,dd,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
//						if(s(dd))
//							found =  f(dd);
//					}
//					dd = alpha2(dd);
//				} while(!found && dd!=d1);
//				break;
//			default : //face connexity
//				dd = phi3(d1);
//				if(!this->isMarkedDart(dd,m)) {
//					neighbours_list.push_back(dd);
//					markOrbit(2,dd,m);
//					if(s(dd)) {
//						found =  f(dd);
//					}
//				}
//		} //end switch
//
//		//test rest of the volume
//		// add phi1 and phi2 successor of they are not yet marked
//		Dart d2 = phi1(d1); // turn in face
//		Dart d3 = phi2(d1); // change volume
//
//		if (!this->isMarkedDart(d2,m)) {
//			darts_list.push_back(d2);
1093
//			this->markOrbit(DART,d2,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1094 1095 1096
//		}
//		if (!this->isMarkedDart(d3,m)) {
//			darts_list.push_back(d3);
1097
//			this->markOrbit(DART,d3,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1098 1099 1100 1101 1102 1103 1104
//		}
//
//		++prem;
//	}
//
//	//unmark current volume
//	for (std::list<Dart>::iterator it = darts_list.begin(); it != darts_list.end(); ++it) {
1105
//		this->unmarkOrbit(DART,(*it),m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
//	}
//
//	//unmark connex volumes checked
//	FunctorUnmark<Map3 > fum(*this,m);
//	for (std::list<Dart>::iterator it = neighbours_list.begin(); it != neighbours_list.end(); ++it) {
//		switch(degree) {
//			case 0 :
//				foreach_dart_of_vertex((*it),fum);
//				break;
//			case 1 :
//				foreach_dart_of_edge((*it),fum);
//				break;
//			default :
//				foreach_dart_of_face((*it),fum);
//		}
//	}
1122
//	this->releaseMarker(DART,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
//	return found;
//}

//// template <typename DART>
//// void Map3::foreach_volume(FunctorType<Dart>* funct)
//// {
//// 	// lock a marker
//// 	int markOV = this->getMarkerIndex();
//// 	for(Dart d = this->begin(); d != this->end(); this->next(d))
//// 	{
//// 		if (!this->isMarkedDart(d,markOV))  // if not yet treated
//// 		{
//// 			(*funct)(d);			// call the functor and
//// 			this->markVolume(d,markOV);  // mark all dart of the vol
//// 		}
//// 	}
1139
//// 	this->releaseMarker(DART,markOV);
Pierre Kraemer's avatar
Pierre Kraemer committed
1140 1141 1142 1143 1144
//// }




untereiner's avatar
untereiner committed
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
void Map3::closeMap(DartMarker& marker)
{
	std::list<Dart> dartList;

// step 1: double,mark & store darts that have fixed point phi3
	for(Dart d = this->begin(); d != this->end(); this->next(d))
	{
		if (phi3(d) == d)
		{
			Dart e = this->newDart();
1155
			marker.markOrbit(DART,e);
untereiner's avatar
untereiner committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
			phi3sew(d,e);
			dartList.push_back(e);
		}
	}

// step 2: update phi1 of new darts
	for (std::list<Dart>::iterator it=dartList.begin(); it!=dartList.end(); ++it)
	{
		Dart d = *it;		// external dart
		Dart e = phi3(d);	// internal dart

		// update phi1 if not already sewn (the last dart of the dart is automatiquely sewn)
		// test à faire dans sewPhi ?
		//if (phi1(d) != phi3(phi_1(e))) phi1sew(d, phi3(phi_1(e)));
		if (phi1(d) == d) {
			Dart eNext = phi1(e);
			do {
				phi1sew(d, phi3(eNext));
				eNext = phi1(eNext);
			} while (eNext != e);
		}
		// search the dart for phi2:
		e = phi3(phi2(e));
		while (!marker.isMarked(e))
		{
			e = phi3(phi2(e));
		}
		//update phi2 if not already sewn (if e have previously been sewn with d)
		//test à faire dans sewPhi ?
		if (phi2(d) != e) phi2sew(d,e);
	}

}

Pierre Kraemer's avatar
Pierre Kraemer committed
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
//void Map3::reverseOrientation()
//{
//	Marker mf2 = this->getNewMarker();
//	Marker mf3 = this->getNewMarker();
//
//	// reverse all faces (only phi1 is modified)
//	for (Dart d= this->begin(); d != this->end(); this->next(d))
//	{
//		if (!isMarkedDart(d,mf2))
//		{
//			reverseFace(d);
//
//			Dart e=d;
//			do
//			{
1205 1206
//				markOrbit(DART,e,mf2);
//				markOrbit(DART,e,mf3);
Pierre Kraemer's avatar
Pierre Kraemer committed
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
//				e=phi1(e);
//			}
//			while (e!=d);
//		}
//	}
//
//	// store all new phi2 and phi3
//	std::vector<Dart> vdphi2;
//	std::vector<Dart> vdphi3;
//	vdphi2.reserve(this->getNbDarts());
//	vdphi3.reserve(this->getNbDarts());
//	for (Dart d= this->begin(); d != this->end(); this->next(d))
//	{
//		Dart e = phi_1(phi2(phi1(d)));
//		vdphi2.push_back(e);
//		Dart f = phi_1(phi3(phi1(d)));
//		vdphi3.push_back(f);
//	}
//
//	// apply the phi2sew with stored phi2 on all darts
//	std::vector<Dart>::iterator id2 = vdphi2.begin();
//	std::vector<Dart>::iterator id3 = vdphi3.begin();
//	for (Dart d= this->begin(); d != this->end(); this->next(d),++id2,++id3)
//	{
//		if (isMarkedDart(d,mf2))
//		{
1233 1234
//			unmarkOrbit(DART,d,mf2); // unmark the two darts
//			unmarkOrbit(DART,*id2,mf2);
Pierre Kraemer's avatar
Pierre Kraemer committed
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
//
//			if (phi2(d) != d)
//				phi2unsew(d);	// unsew the two darts if necessary
//			if (phi2(*id2) != *id2)
//				phi2unsew(*id2);
//			phi2sew(d,*id2); // sew the darts
//		}
//
//		if (isMarkedDart(d,mf3))
//		{
1245 1246
//			unmarkOrbit(DART,d,mf3); // unmark the two darts
//			unmarkOrbit(DART,*id3,mf3);
Pierre Kraemer's avatar
Pierre Kraemer committed
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
//
//			if (phi3(d) != d)
//				phi3unsew(d);	// unsew the two darts if necessary
//			if (phi3(*id3) != *id3)
//				phi3unsew(*id3);
//			phi3sew(d,*id3); // sew the darts
//		}
//	}
//
//	// no need to clear marker second pass do it
1257 1258
//	this->releaseMarker(DART,mf2);
//	this->releaseMarker(DART,mf3);
Pierre Kraemer's avatar
Pierre Kraemer committed
1259 1260
//}
//
untereiner's avatar
untereiner committed
1261 1262 1263 1264 1265


bool Map3::sameFace(Dart d, Dart e)
{
	if(phi3(d) != d)
1266
		if(Map2::sameFace(phi3(d), e))
untereiner's avatar
untereiner committed
1267 1268
			return true;

1269
	return Map2::sameFace(d,e);
untereiner's avatar
untereiner committed
1270 1271
}

untereiner's avatar
ihm3  
untereiner committed
1272 1273 1274 1275
bool Map3::check()
{
    CGoGNout << "Check: topology begin" << CGoGNendl;
    DartMarker m(*this);
untereiner's avatar
untereiner committed
1276
    m.unmarkAll();
untereiner's avatar
ihm3  
untereiner committed
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
    for(Dart d = this->begin(); d != this->end(); this->next(d))
    {
        Dart d3 = phi3(d);
        if (phi3(d3) != d) // phi3 involution ?
		{
             CGoGNout << "Check: phi3 is not an involution" << CGoGNendl;
            return false;
        }

        if(d3 != d)
        {
        	if(phi1(d3) != phi3(phi_1(d)))
        	{
        		CGoGNout << "Check: phi3 , faces are not entirely sewn" << CGoGNendl;
        		return false;
        	}
        }

        Dart d2 = phi2(d);
        if (phi2(d2) != d) // phi2 involution ?
		{
            CGoGNout << "Check: phi2 is not an involution" << CGoGNendl;
            return false;
        }

        Dart d1 = phi1(d);
        if (phi_1(d1) != d) // phi1 a une image correcte ?
		{
            CGoGNout << "Check: unconsistent phi_1 link" << CGoGNendl;
            return false;
        }

        if (m.isMarked(d1)) // phi1 a un seul antécédent ?
		{
            CGoGNout << "Check: dart with two phi1 predecessors" << CGoGNendl;
            return false;
        }
        m.mark(d1);

        if (d1 == d)
            CGoGNout << "Check: (warning) face loop (one edge)" << CGoGNendl;

        if (phi1(d1) == d)
            CGoGNout << "Check: (warning) face with only two edges" << CGoGNendl;

        if (phi2(d1) == d)
            CGoGNout << "Check: (warning) dandling edge (phi2)" << CGoGNendl;

        if (phi3(d1) == d)
            CGoGNout << "Check: (warning) dandling edge (phi3)" << CGoGNendl;
    }

    for(Dart d = this->begin(); d != this->end(); this->next(d))
    {
        if (!m.isMarked(d)) // phi1 a au moins un antécédent ?
		{
1333
        	std::cout << "dart = " << d << std::endl;
untereiner's avatar
ihm3  
untereiner committed
1334 1335 1336 1337 1338 1339 1340 1341
            CGoGNout << "Check: dart with no phi1 predecessor" << CGoGNendl;
            return false;
        }
    }

    CGoGNout << "Check: topology ok" << CGoGNendl;
    return true;
}
Pierre Kraemer's avatar
Pierre Kraemer committed
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398







//void Map3::deleteEdge(Dart d)
//{
//	Dart e = d;
//	std::list<Dart> tmp;
//	do
//	{
//		tmp.push_back(e);
//		e=phi3(phi2(e));
//	}
//	while (e!=d);
//
//	for (std::list<Dart>::iterator it=tmp.begin();it!=tmp.end();++it)
//	{
//		Map2::deleteEdge(*it);
//	}
//
//}
//
//
//void Map3::removeEdge(Dart d)
//{
//
//	Dart e = d;
//	std::list<Dart> tmp;
//	do
//	{
//		tmp.push_back(e);
//		e=phi3(phi2(e));
//	}
//	while (e!=d);
//
//	for (std::list<Dart>::iterator it=tmp.begin();it!=tmp.end();++it)
//	{
//		removeFace(*it);
//	}
//}
//
//
//void Map3::removeVertex(Dart d)
//{
//	std::vector<Dart> store;
//	FunctorStore<Dart> fs(store);
//	foreach_dart_of_vertex(d,fs);
//
//	Marker toMerge = this->getNewMarker();
//
//	for (std::vector<Dart>::iterator it = store.begin() ; it!=store.end() ; ++it)
//	{
//		if (!this->isMarkedDart(*it,toMerge))
//		{
1399
//			this->markOrbit(DART,this->phi3(this->phi_1(*it)),toMerge);
Pierre Kraemer's avatar
Pierre Kraemer committed
1400 1401 1402 1403 1404 1405
//		}
//		else
//		{
//			this->removeFace(*it);
//		}
//	}
1406
//	this->releaseMarker(DART,toMerge);
Pierre Kraemer's avatar
Pierre Kraemer committed
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419
//}
//
//
//
//

//
//Dart Map3::trianguleFace(Dart d0)
//{
//	Dart d1 = phi1(d0);		// Begin with d1 to avoid looking for the dart before d0
//	Dart d = d1;			// Dart d is used to turn around the face
//
//	if (d1 == d0)
1420
//		CGoGNout << "Warning: triangulation of a face with only one edge" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
1421 1422
//
//	if (phi1(d1) == d0)
1423
//		CGoGNout << "Warning: triangulation of a face with only two edges" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
1424 1425 1426 1427 1428 1429 1430
//
//	Dart n = newEdge(2); 	// Create the first edge with n in the central vertex
//	Dart first = phi2(n); 	// Store the opposite of the first edge
//	Dart prec = phi3(n);
//	Dart next = phi1(d); 	// Get the next edge in the face of d
//	phi1sew(n,d); 			// Insert the edge in the face of d (between d and next)
//
1431
//	AttributeHandler<Marker> dmarkers( VERTEX<<24 ,*this); // a modifier pour virer <<24
Pierre Kraemer's avatar
Pierre Kraemer committed
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
//
//	dmarkers[n] = dmarkers[d]; //	n->setMarkerVal(d->getMarkerVal());
//	dmarkers[phi2(n)] = dmarkers[d]; //	phi2(n)->setMarkerVal(d->getMarkerVal());
//
//	phi1sew(phi1(phi3(n)),phi3(next));
//
//	dmarkers[phi3(n)] = dmarkers[phi3(d)]; //	phi3(n)->setMarkerVal(phi3(d)->getMarkerVal());
//	dmarkers[phi1(phi3(n))] = dmarkers[phi3(d)]; //	phi1(phi3(n))->setMarkerVal(phi3(d)->getMarkerVal());
//
//	d = next; 				// Go to the next edge
//
//	while (d != d1)
//	{
//		n = newEdge(2); 		// Create an edge
//		next = phi1(d); 	// Get the next edge in the face of d
//		phi1sew(n,d); 		// Insert the edge in the face of d (between d and next)
//
//		dmarkers[n] = dmarkers[d];//	n->setMarkerVal(d->getMarkerVal());
//		dmarkers[phi2(n)] = dmarkers[d]; //	phi2(n)->setMarkerVal(d->getMarkerVal());
//
//		phi1sew(phi1(phi3(n)),phi3(next));
//
//		dmarkers[phi3(n)] = dmarkers[phi3(d)]; //	phi3(n)->setMarkerVal(phi3(d)->getMarkerVal());
//		dmarkers[phi1(phi3(n))] = dmarkers[phi3(d)]; //	phi1(phi3(n))->setMarkerVal(phi3(d)->getMarkerVal());
//
//		phi1sew(phi2(n),first); // Sew the edge with the first one around central vertex
//		phi1sew(prec,phi3(n));
//		prec = phi3(n);
//		d = next; 			// Go to next edge
//	}
//
//	return n; // Return the last created edge
//}
//
//
//
//
//
//Dart Map3::cutSpike(Dart d)
//{
//  Dart e=d;
//  int nb=0;
//  Dart dNew;
//
//  //count the valence of the vertex
//  do {
//    nb++;
//    e=phi1(phi2(e));
//  } while (e!=d);
//
//  if(nb<3)
//  {
1484
//	CGoGNout << "Warning : cannot cut 2 volumes without creating a degenerated face " << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536
//	return d;
//  }
//  else
//  {
//	//triangulate around the vertex
//	do {
//		if(phi1(phi1(phi1(e)))!=e)
// 			cutFace(phi_1(e),phi1(e));
//		e=phi1(phi2(e));
//	} while (e!=d);
//
//	dNew=newFace(nb);
//
//	//sew a face following the triangles
//	Dart dTurn=dNew;
//	do {
//		Dart d1 = phi1(e);
//		Dart dSym = phi2(d1);
//		phi2unsew(d1);
//		phi2sew(dTurn,d1);
//		phi2sew(phi3(dTurn),dSym);
//		dTurn = phi1(dTurn);
//		e=phi1(phi2(e));
//	}while(e!=d);
//  }
//
//  return dNew;
//}
//
//
//Dart Map3::tetrahedrizeVolume(Dart d)
//{
//	// store all the dart of the volume
//	std::vector<Dart> vStore;
//	FunctorStore<Dart> fs(vStore);
//	foreach_dart_of_volume(d,fs);
//
//	//get a new marker
//	Marker traite = this->getNewMarker();
//
//	//the dart that will be returned
//	Dart ret;
//	//for each dart of the volume
//	for (std::vector<Dart>::iterator it = vStore.begin() ; it != vStore.end() ; ++it )
//	{
//		Dart dc=*it;
//		//if not processed
//		if (!isMarkedDart(dc,traite))
//		{
//			Dart dc2 = phi2(dc);
//
//			//mark the dart
1537 1538
//			markOrbit(DART,dc,traite);
//			markOrbit(DART,dc2,traite);
Pierre Kraemer's avatar
Pierre Kraemer committed
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565
//
//			//create the new triangles
//			Dart dd=this->newFace(3);
//			Dart ee=phi3(dd);
//
//			//and sew them
//			phi2unsew(dc);
//			phi2unsew(dc2);
//			phi2sew(dc,dd);
//			phi2sew(dc2,ee);
//
//			//prepare the returned dart
//			ret=phi_1(dd);
//		}
//	}
//
//	//for each dart
//	for (std::vector<Dart>::iterator it = vStore.begin() ; it != vStore.end() ; ++it)
//	{
//		Dart dc=*it;
//		//if processed
//		if (isMarkedDart(dc,traite))
//		{
//			//get the previous dart in the face
//			Dart dc2 = phi_1(dc);
//
//			//unmark them
1566
//			unmarkOrbit(DART,dc,traite);
Pierre Kraemer's avatar
Pierre Kraemer committed
1567 1568 1569 1570 1571 1572
//
//			//and sew them to create the tetra
//			phi2sew(phi1(phi2(dc)),phi_1(phi2(dc2)));
//		}
//	}
//
1573 1574
//	this->unmarkAll(DART,traite);
//	this->releaseMarker(DART,traite);
Pierre Kraemer's avatar
Pierre Kraemer committed
1575 1576 1577 1578 1579 1580 1581 1582
//
//	return ret;
//
//}
//
//

} // namespace CGoGN