map3.cpp 25.2 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
		deleteCycle(*face);
Pierre Kraemer's avatar
Pierre Kraemer committed
66 67 68 69 70 71
}

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

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
	for(std::vector<Dart>::iterator it = fstore.begin() ; it != fstore.end() ; ++it)
	{
		if(!mergeVolumes(*it))
97
			return NIL;
untereiner's avatar
untereiner committed
98
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
99

100
	return NIL;
Pierre Kraemer's avatar
Pierre Kraemer committed
101 102 103 104
}

void Map3::cutEdge(Dart d)
{
untereiner's avatar
untereiner committed
105
	if(isBoundaryFace(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
		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));
		}
	}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
137
bool Map3::uncutEdge(Dart d)
untereiner's avatar
untereiner committed
138
{
Pierre Kraemer's avatar
Pierre Kraemer committed
139 140
	if(vertexDegree(phi1(d)) == 2)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
141
		if(isBoundaryFace(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
142
			d = phi_1(phi2(d));
untereiner's avatar
untereiner committed
143

Pierre Kraemer's avatar
Pierre Kraemer committed
144 145
		Dart prev = d;
		Dart dd = alpha2(d);
untereiner's avatar
untereiner committed
146

Pierre Kraemer's avatar
Pierre Kraemer committed
147
		Map2::uncutEdge(prev);
untereiner's avatar
untereiner committed
148

Pierre Kraemer's avatar
Pierre Kraemer committed
149 150
		if(phi3(dd) != dd)
			phi3sew(dd,phi2(prev));
untereiner's avatar
untereiner committed
151

Pierre Kraemer's avatar
Pierre Kraemer committed
152 153 154 155
		while (dd!=d)
		{
			prev = dd;
			dd = alpha2(dd);
untereiner's avatar
untereiner committed
156

Pierre Kraemer's avatar
Pierre Kraemer committed
157
			Map2::uncutEdge(prev);
untereiner's avatar
untereiner committed
158

Pierre Kraemer's avatar
Pierre Kraemer committed
159 160 161
			phi3sew(dd, phi2(prev));
		}
		return true;
untereiner's avatar
untereiner committed
162
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
163
	return false;
untereiner's avatar
untereiner committed
164 165
}

166
void Map3::splitFace(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
167
{
168
	Map2::splitFace(d,e);
Pierre Kraemer's avatar
Pierre Kraemer committed
169

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

175
		Map2::splitFace(dd,ee);
Pierre Kraemer's avatar
Pierre Kraemer committed
176

177 178
		phi3sew(phi_1(d), phi_1(ee));
		phi3sew(phi_1(e), phi_1(dd));
Pierre Kraemer's avatar
Pierre Kraemer committed
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 205 206 207
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
208
	if(!isBoundaryFace(d))
209
	{
untereiner's avatar
untereiner committed
210
		Dart e = phi3(d);
untereiner's avatar
untereiner committed
211
		Map3::unsewVolumes(d); //TODO a enlever ??
212 213 214 215 216 217
		Map2::mergeVolumes(d, e); // merge the two volumes along common face
		return true ;
	}
	return false ;
}

untereiner's avatar
untereiner committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
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));
}

235 236 237 238 239
/*! @name Topological Queries
 *  Return or set various topological information
 *************************************************************************/

bool Map3::sameOrientedVertex(Dart d, Dart e)
240
{
untereiner's avatar
untereiner committed
241
	return sameVertex(d,e);
242 243 244
}

bool Map3::sameVertex(Dart d, Dart e)
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
{
	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
283 284
unsigned int Map3::vertexDegree(Dart d)
{
untereiner's avatar
untereiner committed
285
	unsigned int count = 0;
untereiner's avatar
untereiner committed
286 287
	DartMarkerStore mv(*this);	// Lock a marker

288 289 290
	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
291 292 293

	mv.mark(d);

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

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

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

	DartMarkerStore me(*this);

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

	return count;
}

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 367 368 369
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
370
	return sameEdge(d,e);
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
}

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
387
unsigned int Map3::edgeDegree(Dart d)
388
{
untereiner's avatar
untereiner committed
389
	unsigned int deg = 0;
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
	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
415 416 417 418 419 420 421 422
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) ;
423
	mark.markOrbit(FACE, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441

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

	return isBoundary;
}

452
bool Map3::check()
453
{
454 455 456 457 458 459 460 461 462 463
    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;
        }
464

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

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

481 482 483 484 485 486
        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;
        }
487

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

495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
        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 ?
511
		{
512 513 514 515 516
        	//std::cout << "dart = " << d << std::endl;
            std::cout << "Check: dart with no phi1 predecessor" << std::endl;
            return false;
        }
    }
517

518
    std::cout << "Check: topology ok" << std::endl;
519

520 521 522 523

    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
524 525 526 527 528 529 530 531 532 533
    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 ;


534 535

    return true;
536 537
}

Pierre Kraemer's avatar
Pierre Kraemer committed
538 539 540 541
/*! @name Cell Functors
 *  Apply functors to all darts of a cell
 *************************************************************************/

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

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

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

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

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

		found = f(dc);
	}

	return found;
}

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

Sylvain Thery's avatar
Sylvain Thery committed
594
bool Map3::foreach_dart_of_open_edge(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
595
{
Sylvain Thery's avatar
Sylvain Thery committed
596
	DartMarkerStore mv(*this,thread);	// Lock a marker
Pierre Kraemer's avatar
Pierre Kraemer committed
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 625 626 627 628 629
	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
630
bool Map3::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
631
{
Pierre Kraemer's avatar
Pierre Kraemer committed
632 633
	if (foreach_dart_of_oriented_face(d, f, thread))
		return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
634 635

	Dart d3 = phi3(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
636 637
	if (d3 != d)
		return foreach_dart_of_oriented_face(d3, f, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
638 639 640
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
641
bool Map3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
642
{
Sylvain Thery's avatar
Sylvain Thery committed
643
	DartMarkerStore mv(*this,thread);			// Lock a marker
Pierre Kraemer's avatar
Pierre Kraemer committed
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 680 681 682 683 684 685 686 687 688 689 690
	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);
691
//	this->markOrbit(DART,d,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
692 693 694 695 696 697 698 699 700 701 702 703
//
//	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);
704
//					this->markOrbit(DART,dd,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718
//					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);
719
//							markOrbit(DART,d2,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
720 721 722 723
//						}
//
//						if(!this->isMarkedDart(d4,m)) {
//							darts_list2.push_back(d4);
724
//							markOrbit(DART,d4,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
725 726 727 728 729 730 731 732 733 734 735
//						}
//
//						++prem2;
//					}
//				}
//				break;
//			case 1 : //edge connexity
//				dd=d1;
//				neighbours_list.push_back(dd);
//				do {
//					if(!this->isMarkedDart(dd,m)) {
736
//						markOrbit(DART,dd,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
//						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);
761
//			this->markOrbit(DART,d2,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
762 763 764
//		}
//		if (!this->isMarkedDart(d3,m)) {
//			darts_list.push_back(d3);
765
//			this->markOrbit(DART,d3,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
766 767 768 769 770 771 772
//		}
//
//		++prem;
//	}
//
//	//unmark current volume
//	for (std::list<Dart>::iterator it = darts_list.begin(); it != darts_list.end(); ++it) {
773
//		this->unmarkOrbit(DART,(*it),m);
Pierre Kraemer's avatar
Pierre Kraemer committed
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
//	}
//
//	//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);
//		}
//	}
790
//	this->releaseMarker(DART,m);
Pierre Kraemer's avatar
Pierre Kraemer committed
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
//	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
//// 		}
//// 	}
807
//// 	this->releaseMarker(DART,markOV);
Pierre Kraemer's avatar
Pierre Kraemer committed
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
//// }



//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
//			{
827 828
//				markOrbit(DART,e,mf2);
//				markOrbit(DART,e,mf3);
Pierre Kraemer's avatar
Pierre Kraemer committed
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
//				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))
//		{
855 856
//			unmarkOrbit(DART,d,mf2); // unmark the two darts
//			unmarkOrbit(DART,*id2,mf2);
Pierre Kraemer's avatar
Pierre Kraemer committed
857 858 859 860 861 862 863 864 865 866
//
//			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))
//		{
867 868
//			unmarkOrbit(DART,d,mf3); // unmark the two darts
//			unmarkOrbit(DART,*id3,mf3);
Pierre Kraemer's avatar
Pierre Kraemer committed
869 870 871 872 873 874 875 876 877 878
//
//			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
879 880
//	this->releaseMarker(DART,mf2);
//	this->releaseMarker(DART,mf3);
Pierre Kraemer's avatar
Pierre Kraemer committed
881 882
//}
//
untereiner's avatar
untereiner committed
883 884


Pierre Kraemer's avatar
Pierre Kraemer committed
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935

//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))
//		{
936
//			this->markOrbit(DART,this->phi3(this->phi_1(*it)),toMerge);
Pierre Kraemer's avatar
Pierre Kraemer committed
937 938 939 940 941 942
//		}
//		else
//		{
//			this->removeFace(*it);
//		}
//	}
943
//	this->releaseMarker(DART,toMerge);
Pierre Kraemer's avatar
Pierre Kraemer committed
944 945 946 947 948 949 950 951 952 953 954 955 956
//}
//
//
//
//

//
//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)
957
//		CGoGNout << "Warning: triangulation of a face with only one edge" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
958 959
//
//	if (phi1(d1) == d0)
960
//		CGoGNout << "Warning: triangulation of a face with only two edges" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
961 962 963 964 965 966 967
//
//	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)
//
968
//	AttributeHandler<Marker> dmarkers( VERTEX<<24 ,*this); // a modifier pour virer <<24
Pierre Kraemer's avatar
Pierre Kraemer committed
969 970 971 972 973 974 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
//
//	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)
//  {
1021
//	CGoGNout << "Warning : cannot cut 2 volumes without creating a degenerated face " << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
//	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
1074 1075
//			markOrbit(DART,dc,traite);
//			markOrbit(DART,dc2,traite);
Pierre Kraemer's avatar
Pierre Kraemer committed
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
//
//			//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
1103
//			unmarkOrbit(DART,dc,traite);
Pierre Kraemer's avatar
Pierre Kraemer committed
1104 1105 1106 1107 1108 1109
//
//			//and sew them to create the tetra
//			phi2sew(phi1(phi2(dc)),phi_1(phi2(dc2)));
//		}
//	}
//
1110 1111
//	this->unmarkAll(DART,traite);
//	this->releaseMarker(DART,traite);
Pierre Kraemer's avatar
Pierre Kraemer committed
1112 1113 1114 1115 1116 1117 1118 1119
//
//	return ret;
//
//}
//
//

} // namespace CGoGN