map3.cpp 15 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "Topology/map/map3.h"

namespace CGoGN
{

/*! @name Generator and Deletor
 *  To generate or delete volumes in a 3-map
 *************************************************************************/
33 34

void Map3::deleteVolume(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
35 36 37 38
{
	DartMarkerStore mark(*this);		// Lock a marker

	std::vector<Dart> visitedFaces;		// Faces that are traversed
39
	visitedFaces.reserve(512);
Pierre Kraemer's avatar
Pierre Kraemer committed
40 41
	visitedFaces.push_back(d);			// Start with the face of d

42
	mark.markOrbit(FACE, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
43

44
	for(std::vector<Dart>::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47 48 49 50 51 52 53 54 55
	{
		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) ;
56
				mark.markOrbit(FACE, ee) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
57 58 59 60 61 62 63
			}
			e = phi1(e) ;
		} while(e != *face) ;
	}


	// delete every visited face
64
	for (std::vector<Dart>::iterator face = visitedFaces.begin(); face != visitedFaces.end(); ++face)
65
		Map2::deleteOrientedFace(*face);
Pierre Kraemer's avatar
Pierre Kraemer committed
66 67 68 69 70 71
}

/*! @name Topological Operators
 *  Topological operations on 3-maps
 *************************************************************************/

David Cazier's avatar
David Cazier committed
72
Dart Map3::deleteVertex(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
73
{
untereiner's avatar
untereiner committed
74 75 76 77 78 79 80 81 82 83 84 85
	//Save the darts around the vertex
	//(one dart per face should be enough)
	std::vector<Dart> fstoretmp;
	fstoretmp.reserve(100);
	FunctorStore fs(fstoretmp);
	foreach_dart_of_vertex(d, fs);

	//just one dart per face
	std::vector<Dart> fstore;
	fstore.reserve(100);
	DartMarker mf(*this);
	for(std::vector<Dart>::iterator it = fstoretmp.begin() ; it != fstoretmp.end() ; ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
86
	{
untereiner's avatar
untereiner committed
87
		if(!mf.isMarked(*it))
88
		{
untereiner's avatar
untereiner committed
89 90 91
			mf.markOrbit(FACE, *it);
			fstore.push_back(*it);
		}
92
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
93

untereiner's avatar
untereiner committed
94 95 96 97 98
	for(std::vector<Dart>::iterator it = fstore.begin() ; it != fstore.end() ; ++it)
	{
		if(!mergeVolumes(*it))
			return false;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
99

100
	return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
101 102
}

David Cazier's avatar
David Cazier committed
103
Dart Map3::cutEdge(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
104
{
untereiner's avatar
untereiner committed
105
	if(isBoundaryFace(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107 108 109
		d = phi2(d);

	Dart prev = d;
	Dart dd = alpha2(d);
David Cazier's avatar
David Cazier committed
110
	Dart nd = Map2::cutEdge(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

	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));
		}
	}

untereiner's avatar
untereiner committed
128
	if(!isBoundaryFace(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
129 130 131 132 133 134
	{
		Dart d3 = phi3(d);
		phi3unsew(d);
		phi3sew(d, phi1(d3));
		phi3sew(d3, phi1(d));
	}
David Cazier's avatar
David Cazier committed
135
	return nd;
Pierre Kraemer's avatar
Pierre Kraemer committed
136 137
}

untereiner's avatar
untereiner committed
138
void Map3::uncutEdge(Dart d)
untereiner's avatar
untereiner committed
139
{
untereiner's avatar
untereiner committed
140
	if(isBoundaryFace(d))
untereiner's avatar
untereiner committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
		d = phi_1(phi2(d));

	Dart prev = d;
	Dart dd = alpha2(d);

	Map2::uncutEdge(prev);

	if(phi3(dd) != dd)
		phi3sew(dd,phi2(prev));

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

		Map2::uncutEdge(prev);

		phi3sew(dd, phi2(prev));
	}
untereiner's avatar
untereiner committed
160 161 162

}

163
void Map3::splitFace(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
164
{
165
	Map2::splitFace(d,e);
Pierre Kraemer's avatar
Pierre Kraemer committed
166

untereiner's avatar
untereiner committed
167
	if(!isBoundaryFace(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
168
	{
169 170
		Dart dd = phi1(phi3(d));
		Dart ee = phi1(phi3(e));
Pierre Kraemer's avatar
Pierre Kraemer committed
171

172
		Map2::splitFace(dd,ee);
Pierre Kraemer's avatar
Pierre Kraemer committed
173

174 175
		phi3sew(phi_1(d), phi_1(ee));
		phi3sew(phi_1(e), phi_1(dd));
Pierre Kraemer's avatar
Pierre Kraemer committed
176 177 178
	}
}

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
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)
{
untereiner's avatar
untereiner committed
205
	if(!isBoundaryFace(d))
206
	{
untereiner's avatar
untereiner committed
207 208
		Dart e = phi3(d);
		Map3::unsewVolumes(d);
209 210 211 212 213 214
		Map2::mergeVolumes(d, e); // merge the two volumes along common face
		return true ;
	}
	return false ;
}

untereiner's avatar
untereiner committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
void Map3::splitVolume(std::vector<Dart>& vd)
{
	Dart e = vd.front();
	Dart e2 = phi2(e);

	//unsew the edge path
	for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
		Map2::unsewFaces(*it);

	//close the two holes
	Map2::closeHole(e);
	Map2::closeHole(e2);

	//sew the two connexe componnents
	Map3::sewVolumes(phi2(e), phi2(e2));
}

232 233 234 235 236
/*! @name Topological Queries
 *  Return or set various topological information
 *************************************************************************/

bool Map3::sameOrientedVertex(Dart d, Dart e)
237
{
untereiner's avatar
untereiner committed
238
	return sameVertex(d,e);
239 240 241
}

bool Map3::sameVertex(Dart d, Dart e)
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
{
	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;
}

untereiner's avatar
untereiner committed
280 281
unsigned int Map3::vertexDegree(Dart d)
{
untereiner's avatar
untereiner committed
282
	unsigned int count = 0;
untereiner's avatar
untereiner committed
283 284
	DartMarkerStore mv(*this);	// Lock a marker

285 286 287
	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
288 289 290

	mv.mark(d);

291
	for(darts = darts_list.begin(); darts != darts_list.end() ; ++darts)
untereiner's avatar
untereiner committed
292
	{
293
		Dart dc = *darts;
untereiner's avatar
untereiner committed
294 295 296 297 298 299 300 301

		//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))
		{
302
			darts_list.push_back(d21);
untereiner's avatar
untereiner committed
303 304 305 306 307
			mv.mark(d21);
		}

		if((d23!=d2) && !mv.isMarked(d23))
		{
308
			darts_list.push_back(d23);
untereiner's avatar
untereiner committed
309 310 311 312 313 314
			mv.mark(d23);
		}
	}

	DartMarkerStore me(*this);

315
	for(darts = darts_list.begin(); darts != darts_list.end() ; ++darts)
untereiner's avatar
untereiner committed
316
	{
317
		if(!me.isMarked(*darts))
untereiner's avatar
untereiner committed
318 319
		{
			++count;
320
			me.markOrbit(EDGE, *darts);
untereiner's avatar
untereiner committed
321 322 323 324 325 326
		}
	}

	return count;
}

327 328 329 330 331 332 333 334 335 336 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 364 365 366
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;
}

bool Map3::sameOrientedEdge(Dart d, Dart e)
{
untereiner's avatar
untereiner committed
367
	return sameEdge(d,e);
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
}

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

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

	return false;
}

untereiner's avatar
untereiner committed
384
unsigned int Map3::edgeDegree(Dart d)
385
{
untereiner's avatar
untereiner committed
386
	unsigned int deg = 0;
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
	Dart e = d;

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

	return deg;
}

bool Map3::sameFace(Dart d, Dart e)
{
	if(phi3(d) != d)
		if(Map2::sameOrientedFace(phi3(d), e))
			return true;

	return Map2::sameOrientedFace(d,e);
}

bool Map3::isBoundaryFace(Dart d)
{
	return (phi3(d) == d);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
412 413 414 415 416 417 418 419
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) ;
420
	mark.markOrbit(FACE, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438

	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) ;
439
					mark.markOrbit(FACE, ee) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
440 441 442 443 444 445 446 447 448
				}
				e = phi1(e) ;
			} while(e != *face) ;
		}
	}

	return isBoundary;
}

449
bool Map3::check()
450
{
451 452 453 454 455 456 457 458 459 460
    std::cout << "Check: topology begin" << std::endl;
    DartMarker m(*this);
    for(Dart d = Map3::begin(); d != Map3::end(); Map3::next(d))
    {
        Dart d3 = phi3(d);
        if (phi3(d3) != d) // phi3 involution ?
		{
            std::cout << "Check: phi3 is not an involution" << std::endl;
            return false;
        }
461

462 463 464 465 466 467 468 469
        if(d3 != d)
        {
        	if(phi1(d3) != phi3(phi_1(d)))
        	{
        		std::cout << "Check: phi3 , faces are not entirely sewn" << std::endl;
        		return false;
        	}
        }
470

471 472 473 474 475 476
        Dart d2 = phi2(d);
        if (phi2(d2) != d) // phi2 involution ?
		{
            std::cout << "Check: phi2 is not an involution" << std::endl;
            return false;
        }
477

478 479 480 481 482 483
        Dart d1 = phi1(d);
        if (phi_1(d1) != d) // phi1 a une image correcte ?
		{
            std::cout << "Check: unconsistent phi_1 link" << std::endl;
            return false;
        }
484

485
        if (m.isMarked(d1)) // phi1 a un seul antécédent ?
486
		{
487 488 489 490
            std::cout << "Check: dart with two phi1 predecessors" << std::endl;
            return false;
        }
        m.mark(d1);
491

492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
        if (d1 == d)
            std::cout << "Check: (warning) face loop (one edge)" << std::endl;

        if (phi1(d1) == d)
            std::cout << "Check: (warning) face with only two edges" << std::endl;

        if (phi2(d1) == d)
            std::cout << "Check: (warning) dandling edge (phi2)" << std::endl;

        if (phi3(d1) == d)
            std::cout << "Check: (warning) dandling edge (phi3)" << std::endl;
    }

    for(Dart d = this->begin(); d != this->end(); this->next(d))
    {
        if (!m.isMarked(d)) // phi1 a au moins un antécédent ?
508
		{
509 510 511 512 513
        	//std::cout << "dart = " << d << std::endl;
            std::cout << "Check: dart with no phi1 predecessor" << std::endl;
            return false;
        }
    }
514

515
    std::cout << "Check: topology ok" << std::endl;
516

517 518 519 520

    std::cout << "nb vertex orbits" << getNbOrbits(VERTEX) << std::endl ;
    std::cout << "nb vertex cells" << m_attribs[VERTEX].size() << std::endl ;

untereiner's avatar
untereiner committed
521 522 523 524 525 526 527 528 529 530
    std::cout << "nb edge orbits" << getNbOrbits(EDGE) << std::endl ;
    std::cout << "nb edge cells" << m_attribs[EDGE].size() << std::endl ;

    std::cout << "nb face orbits" << getNbOrbits(FACE) << std::endl ;
    std::cout << "nb face cells" << m_attribs[FACE].size() << std::endl ;

    std::cout << "nb volume orbits" << getNbOrbits(VOLUME) << std::endl ;
    std::cout << "nb volume cells" << m_attribs[VOLUME].size() << std::endl ;


531 532

    return true;
533 534
}

Pierre Kraemer's avatar
Pierre Kraemer committed
535 536 537 538
/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

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

untereiner's avatar
untereiner committed
544 545
	std::vector<Dart> darts_list;			//Darts that are traversed
	darts_list.reserve(512);
untereiner's avatar
untereiner committed
546
	darts_list.push_back(d);			//Start with the dart d
Pierre Kraemer's avatar
Pierre Kraemer committed
547 548
	mv.mark(d);

untereiner's avatar
untereiner committed
549
	for(std::vector<Dart>::iterator darts = darts_list.begin(); !found && darts != darts_list.end() ; ++darts)
Pierre Kraemer's avatar
Pierre Kraemer committed
550 551 552 553 554
	{
		Dart dc = *darts;

		//add phi21 and phi23 successor if they are not marked yet
		Dart d2 = phi2(dc);
untereiner's avatar
untereiner committed
555
		if(d2 != dc)
Pierre Kraemer's avatar
Pierre Kraemer committed
556
		{
untereiner's avatar
untereiner committed
557 558
			Dart d21 = phi1(d2); // turn in volume
			Dart d23 = phi3(d2); // change volume
Pierre Kraemer's avatar
Pierre Kraemer committed
559

untereiner's avatar
untereiner committed
560 561 562 563 564 565 566 567 568 569 570
			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
571 572 573 574 575 576 577 578
		}

		found = f(dc);
	}

	return found;
}

Sylvain Thery's avatar
Sylvain Thery committed
579
bool Map3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
580 581 582
{
	Dart dNext = d;
	do {
Sylvain Thery's avatar
Sylvain Thery committed
583
		if (Map2::foreach_dart_of_edge(dNext,f,thread)) return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
584 585 586 587 588
		dNext = alpha2(dNext);
	} while (dNext != d);
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
589
bool Map3::foreach_dart_of_open_edge(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
590
{
Sylvain Thery's avatar
Sylvain Thery committed
591
	DartMarkerStore mv(*this,thread);	// Lock a marker
Pierre Kraemer's avatar
Pierre Kraemer committed
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
	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
625
bool Map3::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
626
{
Sylvain Thery's avatar
Sylvain Thery committed
627
	if (foreach_dart_of_oriented_face(d,f,thread)) return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
628 629

	Dart d3 = phi3(d);
Sylvain Thery's avatar
Sylvain Thery committed
630
	if (d3 != d) return foreach_dart_of_oriented_face(d3,f,thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
631 632 633
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
634
bool Map3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
635
{
Sylvain Thery's avatar
Sylvain Thery committed
636
	DartMarkerStore mv(*this,thread);			// Lock a marker
Pierre Kraemer's avatar
Pierre Kraemer committed
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
	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;
}


} // namespace CGoGN