ihm3.cpp 27.2 KB
Newer Older
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
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.unistra.fr/                                           *
21 22 23 24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
25 26
#define CGoGN_ALGO_DLL_EXPORT 1

27
#include "Algo/ImplicitHierarchicalMesh/ihm3.h"
28
#include "Topology/generic/traversor/traversor3.h"
29 30

#include <cmath>
31
#include <limits>
32 33 34 35 36 37 38

namespace CGoGN
{

namespace Algo
{

39 40 41
namespace Volume
{

untereiner's avatar
untereiner committed
42
namespace IHM
43 44 45 46
{

ImplicitHierarchicalMap3::ImplicitHierarchicalMap3() : m_curLevel(0), m_maxLevel(0), m_edgeIdCount(0), m_faceIdCount(0)
{
47 48 49
	m_dartLevel = Map3::addAttribute<unsigned int, DART, EmbeddedMap3>("dartLevel") ;
	m_edgeId = Map3::addAttribute<unsigned int, DART, EmbeddedMap3>("edgeId") ;
	m_faceId = Map3::addAttribute<unsigned int, DART, EmbeddedMap3>("faceId") ;
50 51 52 53 54 55 56

	for(unsigned int i = 0; i < NB_ORBITS; ++i)
		m_nextLevelCell[i] = NULL ;
}

ImplicitHierarchicalMap3::~ImplicitHierarchicalMap3()
{
untereiner's avatar
untereiner committed
57 58 59
	removeAttribute(m_edgeId) ;
	removeAttribute(m_faceId) ;
	removeAttribute(m_dartLevel) ;
60 61
}

62 63 64 65 66
void ImplicitHierarchicalMap3::clear(bool removeAttrib)
{
	Map3::clear(removeAttrib) ;
	if (removeAttrib)
	{
67 68 69
		m_dartLevel = Map3::addAttribute<unsigned int, DART, EmbeddedMap3>("dartLevel") ;
		m_faceId = Map3::addAttribute<unsigned int, DART, EmbeddedMap3>("faceId") ;
		m_edgeId = Map3::addAttribute<unsigned int, DART, EmbeddedMap3>("edgeId") ;
70 71 72 73 74 75

		for(unsigned int i = 0; i < NB_ORBITS; ++i)
			m_nextLevelCell[i] = NULL ;
	}
}

76
void ImplicitHierarchicalMap3::initImplicitProperties()
77 78 79 80
{
	initEdgeId() ;
	initFaceId();

81 82 83 84 85
//	for(Dart d = Map3::begin(); d != Map3::end(); Map3::next(d))
//	{
//		m_edgeId[d] = 0;
//		m_faceId[d] = 0;
//	}
86 87 88 89 90

	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
		if(m_nextLevelCell[orbit] != NULL)
		{
91
			AttributeContainer& cellCont = m_attribs[orbit] ;
92 93 94 95 96 97
			for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i))
				m_nextLevelCell[orbit]->operator[](i) = EMBNULL ;
		}
	}
}

untereiner's avatar
untereiner committed
98

99 100 101 102 103 104 105 106 107 108 109 110 111
//void ImplicitHierarchicalMap3::deleteVolume(Dart d)
//{
//	unsigned int emb = getEmbedding<VERTEX>(d);
//	Dart dr = phi1(phi1(d));

//	EmbeddedMap3::deleteVolume(d);

//	if(isOrbitEmbedded<VERTEX>())
//	{
//		setOrbitEmbedding<VERTEX>(dr,emb);
//	}
//}

112 113
void ImplicitHierarchicalMap3::swapEdges(Dart d, Dart e)
{
114 115
	if(!Map2::isBoundaryEdge(d) && !Map2::isBoundaryEdge(e))
	{
116 117 118 119 120 121 122 123 124
	Dart d2 = phi2(d);
	Dart e2 = phi2(e);

	Map2::unsewFaces(d);
	Map2::unsewFaces(e);

	Map2::sewFaces(d, e);
	Map2::sewFaces(d2, e2);

125
	if(isOrbitEmbedded<VERTEX>())
126
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
127 128 129 130
		copyDartEmbedding<VERTEX>(d, phi2(phi_1(d)));
		copyDartEmbedding<VERTEX>(e, phi2(phi_1(e)));
		copyDartEmbedding<VERTEX>(d2, phi2(phi_1(d2)));
		copyDartEmbedding<VERTEX>(e2, phi2(phi_1(e2)));
131 132
	}

133
	if(isOrbitEmbedded<EDGE>())
134 135 136 137
	{

	}

138
	if(isOrbitEmbedded<VOLUME>())
139
		Algo::Topo::setOrbitEmbeddingOnNewCell<VOLUME>(*this, d);
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
void ImplicitHierarchicalMap3::saveRelationsAroundVertex(Dart d, std::vector<std::pair<Dart, Dart> >& vd)
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

	//le brin est forcement du niveau cur
	Dart dit = d;

	do
	{
		vd.push_back(std::pair<Dart,Dart>(dit,phi2(dit)));

		dit = phi2(phi_1(dit));

	}while(dit != d);
}

void ImplicitHierarchicalMap3::unsewAroundVertex(std::vector<std::pair<Dart, Dart> >& vd)
{
	//unsew the edge path
	for(std::vector<std::pair<Dart, Dart> >::iterator it = vd.begin() ; it != vd.end() ; ++it)
	{
		Dart dit = (*it).first;
		Dart dit2 = (*it).second;

		Map2::unsewFaces(dit);

169
		if(isOrbitEmbedded<VERTEX>())
170
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
171 172
			copyDartEmbedding<VERTEX>(phi2(dit2), dit);
			copyDartEmbedding<VERTEX>(phi2(dit), dit2);
173 174
		}

175
		if(isOrbitEmbedded<EDGE>())
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
		{

		}
	}
}

Dart ImplicitHierarchicalMap3::quadranguleFace(Dart d)
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

	Dart centralDart = NIL;
	Map2::fillHole(phi1(d));

	Dart old = phi2(phi1(d));
	Dart bc = newBoundaryCycle(faceDegree(old));
	sewVolumes(old, bc, false);

193
	if (isOrbitEmbedded<VERTEX>())
194 195 196 197
	{
		Dart it = bc;
		do
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
198
			//copyDartEmbedding<VERTEX>(it, phi1(phi3(it)));
199
			Algo::Topo::setOrbitEmbedding<VERTEX>(*this, it, getEmbedding<VERTEX>(phi1(phi3(it))));
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
			it = phi1(it) ;
		} while(it != bc) ;
	}


	Dart dd = phi1(phi1(old)) ;
	splitFace(old,dd) ;

	unsigned int idface = getNewFaceId();
	setFaceId(dd,idface, FACE);

	Dart ne = phi1(phi1(old)) ;

	cutEdge(ne);
	centralDart = phi1(ne);

	//newEdges.push_back(ne);
	//newEdges.push_back(map.phi1(ne));

	unsigned int id = getNewEdgeId() ;
	setEdgeId(ne, id, EDGE) ;

	Dart stop = phi2(phi1(ne));
	ne = phi2(ne);
	do
	{
		dd = phi1(phi1(phi1(ne)));

		splitFace(ne, dd) ;

		unsigned int idface = getNewFaceId();
		setFaceId(dd,idface, FACE);

		//newEdges.push_back(map.phi1(dd));

		ne = phi2(phi_1(ne));
		dd = phi1(phi1(dd));
	}
	while(dd != stop);

	return centralDart;
}
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

void ImplicitHierarchicalMap3::deleteVertexSubdividedFace(Dart d)
{
	Dart centralV = phi1(phi1(d));
	Dart res = NIL;
	Dart vit = centralV ;
	do
	{
		if(res == NIL && phi1(phi1(centralV)) != centralV)
			res = phi1(centralV) ;

		Dart f = phi_1(phi2(vit)) ;
		phi1sew(vit, f) ;

		vit = phi2(phi_1(vit)) ;
	} while(vit != centralV) ;
	Map1::deleteCycle(centralV) ;

	Dart d3 = phi1(phi3(centralV));
	res = NIL;
	vit = d3 ;
	do
	{
		if(res == NIL && phi1(phi1(d3)) != d3)
			res = phi1(d3) ;

		Dart f = phi_1(phi2(vit)) ;
		phi1sew(vit, f) ;

		vit = phi2(phi_1(vit)) ;
	} while(vit != d3) ;
	Map1::deleteCycle(d3) ;

}

278 279
void ImplicitHierarchicalMap3::initEdgeId()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
280
	DartMarkerStore<Map3> edgeMark(*this) ;
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
	for(Dart d = Map3::begin(); d != Map3::end(); Map3::next(d))
	{
		if(!edgeMark.isMarked(d))
		{
			Dart e = d;
			do
			{
				m_edgeId[e] = m_edgeIdCount;
				edgeMark.mark(e);

				m_edgeId[Map3::phi2(e)] = m_edgeIdCount ;
				edgeMark.mark(Map3::phi2(e));

				e = Map3::alpha2(e);
			} while(e != d);

			m_edgeIdCount++;
		}
	}
}

void ImplicitHierarchicalMap3::initFaceId()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
304
	DartMarkerStore<Map3> faceMark(*this) ;
305 306 307 308 309 310 311 312 313 314
	for(Dart d = Map3::begin(); d != Map3::end(); Map3::next(d))
	{
		if(!faceMark.isMarked(d))
		{
			Dart e = d;
			do
			{
				m_faceId[e] = m_faceIdCount ;
				faceMark.mark(e);

315
				Dart e3 = Map3::phi3(e);
316 317
				m_faceId[e3] = m_faceIdCount ;
				faceMark.mark(e3);
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335

				e = Map3::phi1(e);
			} while(e != d);

			m_faceIdCount++;
		}
	}
}

unsigned int ImplicitHierarchicalMap3::faceLevel(Dart d)
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

	if(m_curLevel == 0)
		return 0 ;

	Dart it = d ;
	Dart old = it ;
336
	unsigned int l_old = m_dartLevel[old] ;
337 338 339 340
	unsigned int fLevel = edgeLevel(it) ;
	do
	{
		it = phi1(it) ;
341 342 343 344 345 346 347 348
		unsigned int dl = m_dartLevel[it] ;
		if(dl < l_old)							// compute the oldest dart of the face
		{										// in the same time
			old = it ;
			l_old = dl ;
		}										// in a first time, the level of a face
		unsigned int l = edgeLevel(it) ;		// is the minimum of the levels
		fLevel = l < fLevel ? l : fLevel ;		// of its edges
349 350
	} while(it != d) ;

351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
//	unsigned int cur = m_curLevel ;
//	m_curLevel = fLevel ;

//	unsigned int nbSubd = 0 ;
//	it = old ;
//	unsigned int eId = m_edgeId[old] ;			// the particular case of a face
//	do											// with all neighboring faces regularly subdivided
//	{											// but not the face itself
//		++nbSubd ;								// is treated here
//		it = phi1(it) ;
//	} while(m_edgeId[it] == eId) ;

//	while(nbSubd > 1)
//	{
//		nbSubd /= 2 ;
//		--fLevel ;
//	}
368

369
//	m_curLevel = cur ;
370 371 372 373 374 375

	return fLevel ;
}

unsigned int ImplicitHierarchicalMap3::volumeLevel(Dart d)
{
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
	if(m_curLevel == 0)
		return 0 ;

	unsigned int vLevel = std::numeric_limits<unsigned int>::max(); //hook sioux

	//First : the level of a volume is the minimum of the levels of its faces
	Traversor3WF<ImplicitHierarchicalMap3> travF(*this, d);
	for (Dart dit = travF.begin(); dit != travF.end(); dit = travF.next())
	{
		// in a first time, the level of a face
		//the level of the volume is the minimum of the
		//levels of its faces
		unsigned int fLevel = faceLevel(dit);
		vLevel = fLevel < vLevel ? fLevel : vLevel ;
	}

	//Second : the case of all faces regularly subdivided but not the volume itself

	return vLevel;
}

/*
398 399 400 401 402 403 404 405
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

	if(m_curLevel == 0)
		return 0 ;

	//First : the level of a volume is the
	//minimum of the levels of its faces

Pierre Kraemer's avatar
Pierre Kraemer committed
406
	DartMarkerStore<Map3> mark(*this);		// Lock a marker
407 408

	std::vector<Dart> visitedFaces;		// Faces that are traversed
409
	visitedFaces.reserve(512);
410 411 412 413
	visitedFaces.push_back(d);			// Start with the face of d
	std::vector<Dart>::iterator face;

	Dart oldest = d ;
414
	unsigned int vLevel = std::numeric_limits<unsigned int>::max() ; //hook de ouf
415 416 417 418

	//parcours les faces du volume au niveau courant
	//on cherche le brin de niveau le plus bas de la hierarchie
	//on note le niveau le plus bas de la hierarchie
Pierre Kraemer's avatar
Pierre Kraemer committed
419
	mark.markOrbit<FACE>(d) ;
untereiner's avatar
untereiner committed
420
	for(unsigned int i = 0; i < visitedFaces.size(); ++i)
421
	{
untereiner's avatar
untereiner committed
422
		Dart e = visitedFaces[i] ;
423 424 425 426

		// in a first time, the level of a face
		//the level of the volume is the minimum of the
		//levels of its faces
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449

		//
		// Compute the level of this face
		// and the oldest dart
		//
		Dart it = e ;
		Dart old = it ;
		unsigned int l_old = m_dartLevel[old] ;
		unsigned int fLevel = edgeLevel(it) ;
		do
		{
			it = phi1(it) ;
			unsigned int dl = m_dartLevel[it] ;
			if(dl < l_old)							// compute the oldest dart of the face
			{										// in the same time
				old = it ;
				l_old = dl ;
			}										// in a first time, the level of a face
			unsigned int l = edgeLevel(it) ;		// is the minimum of the levels
			fLevel = l < fLevel ? l : fLevel ;		// of its edges
		} while(it != e) ;


450 451
//		unsigned int cur = m_curLevel ;
//		m_curLevel = fLevel ;
452

453 454 455 456 457 458 459 460 461 462
//		unsigned int nbSubd = 0 ;
//		it = old ;
//		unsigned int eId = m_edgeId[old] ;			// the particular case of a face
//		std::cout << "old edge id = " << eId << std::endl;
//		do											// with all neighboring faces regularly subdivided
//		{											// but not the face itself
//			++nbSubd ;								// is treated here
//			it = phi1(it) ;
//			std::cout << "current edge id = " << m_edgeId[it] << std::endl;
//		} while(m_edgeId[it] == eId) ;
463

464 465 466 467 468 469 470
//		while(nbSubd > 1)
//		{
//			nbSubd /= 2 ;
//			--fLevel ;
//		}

//		m_curLevel = cur ;
471 472 473 474 475

		//
		// compute the minimum level of the volume
		// if the level of this face is lower than the saved volume level
		//
476 477
		vLevel = fLevel < vLevel ? fLevel : vLevel ;

478 479 480 481
		//
		// compute the oldest dart from the volume
		// if the oldest dart from this face is oldest than the oldest saved dart
		//
482
		if(m_dartLevel[old] < m_dartLevel[oldest])
483
				oldest = old ;
484

485 486 487 488
		//
		// add all face neighbours to the table
		//
		do
489 490 491 492 493
		{
			Dart ee = phi2(e) ;
			if(!mark.isMarked(ee)) // not already marked
			{
				visitedFaces.push_back(ee) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
494
				mark.markOrbit<FACE>(ee) ;
495 496
			}
			e = phi1(e) ;
untereiner's avatar
untereiner committed
497
		} while(e != visitedFaces[i]) ;
498 499
	}

untereiner's avatar
untereiner committed
500

501 502 503
//	//Second : the case of all faces regularly subdivided but not the volume itself
//	unsigned int cur = m_curLevel ;
//	m_curLevel = vLevel ;
504

505 506 507
//	unsigned int nbSubd = 0 ;
//	Dart it = oldest ;
//	unsigned int eId = m_edgeId[oldest] ;
508

509 510 511 512 513
//	do
//	{
//		++nbSubd ;
//		it = phi1(it) ;
//	} while(m_edgeId[it] == eId) ;
514 515


516 517 518 519 520 521 522
//	while(nbSubd > 1)
//	{
//		nbSubd /= 2 ;
//	    --vLevel ;
//	}

//	m_curLevel = cur ;
523 524 525 526


	return vLevel;
}
527
*/
528 529 530 531

Dart ImplicitHierarchicalMap3::faceOldestDart(Dart d)
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
532 533 534
	Dart it = d ;
	Dart oldest = it ;
	unsigned int l_old = m_dartLevel[oldest] ;
535 536
	do
	{
537
		unsigned int l = m_dartLevel[it] ;
untereiner's avatar
untereiner committed
538 539
		if(l == 0)
			return it ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
540 541

        if(l < l_old || (l == l_old && it.index < oldest.index))
542 543 544 545 546 547 548
		{
			oldest = it ;
			l_old = l ;
		}
		it = phi1(it) ;
	} while(it != d) ;
	return oldest ;
549 550 551 552 553 554 555
}

Dart ImplicitHierarchicalMap3::volumeOldestDart(Dart d)
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

	Dart oldest = d;
556
	unsigned int l_old = m_dartLevel[oldest];
557

558
	Traversor3WF<ImplicitHierarchicalMap3> trav3WF(*this, oldest);
untereiner's avatar
untereiner committed
559
	for(Dart dit = trav3WF.begin() ; dit != trav3WF.end() ; dit = trav3WF.next())
560
	{
untereiner's avatar
untereiner committed
561
		Dart old = faceOldestDart(dit);
562
		unsigned int l = m_dartLevel[old];
Thomas Pitiot 's avatar
Thomas Pitiot committed
563
        if(l < l_old || (l == l_old && it.index < oldest.index))
564
		{
565
			oldest = old;
566 567
			l_old = l;
		}
568 569 570 571 572 573 574 575 576
	}

	return oldest;
}

bool ImplicitHierarchicalMap3::edgeIsSubdivided(Dart d)
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

577 578
	//Dart d2 = phi2(d) ;
	Dart d1 = phi1(d) ;
579
	++m_curLevel ;
580 581
	//Dart d2_l = phi2(d) ;
	Dart d1_l = phi1(d) ;
582
	--m_curLevel ;
583 584
	//if(d2 != d2_l)
	if(d1 != d1_l)
585 586 587 588 589
		return true ;
	else
		return false ;
}

590
bool ImplicitHierarchicalMap3::edgeCanBeCoarsened(Dart d)
untereiner's avatar
untereiner committed
591 592 593 594 595 596 597 598 599 600 601
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

	bool subd = false ;
	bool subdOnce = true ;
	bool degree2 = false ;

	if(edgeIsSubdivided(d))
	{
		subd = true ;
		++m_curLevel ;
untereiner's avatar
untereiner committed
602

untereiner's avatar
untereiner committed
603 604 605
		if(vertexDegree(phi1(d)) == 2)
		{
			degree2 = true ;
606
			if(edgeIsSubdivided(d))
untereiner's avatar
untereiner committed
607 608 609 610 611 612 613
				subdOnce = false ;
		}
		--m_curLevel ;
	}
	return subd && degree2 && subdOnce ;
}

614
bool ImplicitHierarchicalMap3::faceIsSubdivided(Dart d)
615 616
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
617 618 619
	unsigned int fLevel = faceLevel(d) ;
	if(fLevel < m_curLevel)
		return false ;
620

621 622 623 624 625
	bool subd = false ;
	++m_curLevel ;
	if(m_dartLevel[phi1(d)] == m_curLevel && m_edgeId[phi1(d)] != m_edgeId[d])
		subd = true ;
	--m_curLevel ;
626

627 628 629 630 631 632 633 634 635 636 637 638
	return subd ;
}

bool ImplicitHierarchicalMap3::faceCanBeCoarsened(Dart d)
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

	bool subd = false;
	bool subdOnce = true;
	bool subdNeighborhood = false; //deux volumes voisins de la face ne sont pas subdivise

	if(faceIsSubdivided(d))
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
	{
		subd = true;
		Dart d3 = phi3(d);

		//tester si le volume voisin est subdivise
		if(d3 != d && volumeIsSubdivided(d3))
			subdNeighborhood = true;

		++m_curLevel;
		//tester si la face subdivise a des faces subdivise
		Dart cf = phi1(d);

		do
		{
			if(faceIsSubdivided(cf))
				subdOnce = false;

			cf = phi2(phi1(cf));
		}
		while(subdOnce && cf != phi1(d));

		--m_curLevel;
	}

	return subd && !subdNeighborhood && subdOnce;
}

666 667 668


bool ImplicitHierarchicalMap3::volumeIsSubdivided(Dart d)
untereiner's avatar
untereiner committed
669 670
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
671 672 673
	unsigned int vLevel = volumeLevel(d);
	if(vLevel < m_curLevel)
		return false;
untereiner's avatar
untereiner committed
674

675
	bool subd = false;
untereiner's avatar
untereiner committed
676

677 678 679 680
	++m_curLevel;
	if(m_dartLevel[phi2(phi1(phi1(d)))] == m_curLevel && m_faceId[phi2(phi1(phi1(d)))] != m_faceId[d])
		subd = true;
	--m_curLevel;
untereiner's avatar
untereiner committed
681

682
	return subd;
untereiner's avatar
untereiner committed
683

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
//	//bool facesAreSubdivided = faceIsSubdivided(d) ;
//	bool facesAreSubdivided = true ;
//
//	Traversor3WF<ImplicitHierarchicalMap3> trav3WF(*this, d);
//	for(Dart dit = trav3WF.begin() ; dit != trav3WF.end() ; dit = trav3WF.next())
//	{
//		// in a first time, the level of a face
//		//the level of the volume is the minimum of the
//		//levels of its faces
//
//		facesAreSubdivided &= faceIsSubdivided(dit) ;
//	}
//
//	//but not the volume itself
//	bool subd = false;
//	++m_curLevel;
//	if(facesAreSubdivided && m_dartLevel[phi2(phi1(phi1(d)))] == m_curLevel && m_faceId[phi2(phi1(phi1(d)))] != m_faceId[d])
//		subd = true;
//	--m_curLevel;
//
//	return subd;
untereiner's avatar
untereiner committed
705 706
}

707

708
bool ImplicitHierarchicalMap3::volumeIsSubdividedOnce(Dart d)
untereiner's avatar
untereiner committed
709
{
710
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
711 712 713 714 715 716
	unsigned int vLevel = volumeLevel(d);
	if(vLevel < m_curLevel)
		return false;

	bool subd = false ;
	bool subdOnce = true ;
untereiner's avatar
untereiner committed
717

untereiner's avatar
untereiner committed
718
	++m_curLevel;
719
	if(m_dartLevel[phi2(phi1(phi1(d)))] == m_curLevel && m_faceId[phi2(phi1(phi1(d)))] != m_faceId[d])
untereiner's avatar
untereiner committed
720 721 722 723 724
	{
		subd = true;
		++m_curLevel;
		Dart dcenter = phi_1(phi2(phi1(d)));
		Traversor3VW<ImplicitHierarchicalMap3> trav3(*this, dcenter);
725
		for(Dart dit = trav3.begin() ; subdOnce && dit != trav3.end() && subdOnce; dit = trav3.next())
untereiner's avatar
untereiner committed
726
		{
727
			if(m_dartLevel[phi2(phi1(phi1(dit)))] == m_curLevel && m_faceId[phi2(phi1(phi1(dit)))] != m_faceId[dit])
untereiner's avatar
untereiner committed
728 729 730 731 732 733
				subdOnce = false;
		}
		--m_curLevel;
	}
	--m_curLevel;
	return subd && subdOnce;
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772

//	//si le volume est subdivise
//
//	//test si toutes les faces sont subdivisee
//	DartMarkerStore mark(*this);		// Lock a marker
//
//	std::vector<Dart> visitedFaces;		// Faces that are traversed
//	visitedFaces.reserve(512);
//	visitedFaces.push_back(d);			// Start with the face of d
//	std::vector<Dart>::iterator face;
//
//	bool facesAreSubdivided = faceIsSubdivided(d) ;
//
//	//parcours les faces du volume au niveau courant
//	//on cherche le brin de niveau le plus bas de la hierarchie
//	//on note le niveau le plus bas de la hierarchie
//	mark.markOrbit<FACE>(d) ;
//	for(unsigned int i = 0; i < visitedFaces.size(); ++i)
//	{
//		Dart e = visitedFaces[i] ;
//
//		// in a first time, the level of a face
//		//the level of the volume is the minimum of the
//		//levels of its faces
//
//		facesAreSubdivided &= faceIsSubdivided(e) ;
//
//		do	// add all face neighbours to the table
//		{
//			Dart ee = phi2(e) ;
//			if(!mark.isMarked(ee)) // not already marked
//			{
//				visitedFaces.push_back(ee) ;
//				mark.markOrbit<FACE>(ee) ;
//			}
//			e = phi1(e) ;
//		} while(e != visitedFaces[i]) ;
//	}

untereiner's avatar
untereiner committed
773 774
}

Thomas Pitiot 's avatar
ok  
Thomas Pitiot committed
775 776 777 778 779 780 781 782 783 784 785 786 787 788
bool ImplicitHierarchicalMap3::checkForSurrounded (Dart d)
{
    for(Vol dd : volumesAdjacentByFace3<ImplicitHierarchicalMap3>(*this,d))
    {
        if(!sameVolume(phi3(d),dd))
        {
            if(!volumeIsSubdivided(dd))
            {
                return false;
            }
        }
    }
    return true;
}
789 790

bool ImplicitHierarchicalMap3::neighborhoodLevelDiffersMoreThanOne(Dart d)
791 792 793
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;

untereiner's avatar
untereiner committed
794
	int vLevel = volumeLevel(d);
795
	bool isMoreThanOne = false;
796

untereiner's avatar
untereiner committed
797
//	std::cout << "niveau du courant : " << vLevel << std::endl;
untereiner's avatar
untereiner committed
798
	Traversor3WWaV<ImplicitHierarchicalMap3> trav3WWaV(*this, d);
799
	for(Dart dit = trav3WWaV.begin() ; !isMoreThanOne && dit != trav3WWaV.end() ; dit = trav3WWaV.next())
800
	{
untereiner's avatar
untereiner committed
801
		//Dart oldit = volumeOldestDart(dit);
untereiner's avatar
untereiner committed
802 803
//		std::cout << "niveau du voisin : " << volumeLevel(dit) << std::endl;
//		std::cout << "difference de niveau avec voisin : " << abs((volumeLevel(dit) - vLevel)) << std::endl;
untereiner's avatar
untereiner committed
804
		if(abs((int(volumeLevel(dit)) - vLevel)) > 1)
805
			isMoreThanOne = true;
806 807
	}

808
	return isMoreThanOne;
untereiner's avatar
untereiner committed
809 810 811 812 813 814 815 816 817

//	Traversor3EW<ImplicitHierarchicalMap3> trav3EW(*this, old);
//	for(Dart dit = trav3EW.begin() ; dit != trav3EW.end() ; dit = trav3EW.next())
//	{
//		Dart oldit = volumeOldestDart(dit);
//		if((volumeLevel(oldit) - vLevel) > 1)
//			overOne = false;
//	}

818 819
}

820
bool ImplicitHierarchicalMap3::coarsenNeighborhoodLevelDiffersMoreThanOne(Dart d)
821 822
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
untereiner's avatar
untereiner committed
823
//	assert(m_curLevel > 0 || !"Coarsen a volume at level 0");
824

untereiner's avatar
untereiner committed
825
	int vLevel = volumeLevel(d)-1;
826
	bool isMoreThanOne = false;
827

untereiner's avatar
untereiner committed
828 829 830 831 832 833 834
//	std::cout << "niveau du courant : " << vLevel << std::endl;
	Traversor3WWaV<ImplicitHierarchicalMap3> trav3WWaV(*this, d);
	for(Dart dit = trav3WWaV.begin() ; !isMoreThanOne && dit != trav3WWaV.end() ; dit = trav3WWaV.next())
	{
		//Dart oldit = volumeOldestDart(dit);
//		std::cout << "niveau du voisin : " << volumeLevel(dit) << std::endl;
//		std::cout << "difference de niveau avec voisin : " << abs((volumeLevel(dit) - vLevel)) << std::endl;
untereiner's avatar
untereiner committed
835
		if(abs((int(volumeLevel(dit)) - vLevel)) > 1)
untereiner's avatar
untereiner committed
836 837
			isMoreThanOne = true;
	}
838

839
	return isMoreThanOne;
840

untereiner's avatar
untereiner committed
841 842 843 844 845 846
//	Traversor3EW<ImplicitHierarchicalMap3> trav3EW(*this, old);
//	for(Dart dit = trav3EW.begin() ; dit != trav3EW.end() ; dit = trav3EW.next())
//	{
//		if(!faceIsSubdividedOnce(dit))
//			OverOne = true;
//	}
847

untereiner's avatar
untereiner committed
848
	//unsigned int vLevel = volumeLevel(d);
849

untereiner's avatar
untereiner committed
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
//	DartMarkerStore mf(*this);		// Lock a face marker to save one dart per face
//
//	//Store faces that are traversed and start with the face of d
//	std::vector<Dart> visitedFaces;
//	visitedFaces.reserve(512);
//	visitedFaces.push_back(old);
//
//	mf.markOrbit<FACE>(old) ;
//
//	for(unsigned int i = 0; !found && i < visitedFaces.size(); ++i)
//	{
//		Dart e = visitedFaces[i] ;
//		do
//		{
//			// add all face neighbours to the table
//
//			if(faceIsSubdivided(e))
//			{
//				++m_curLevel;
//
//				if(faceIsSubdividedOnce(e))
//					found = true;
//
//				--m_curLevel;
//			}
//			Dart ee = phi2(e) ;
//			if(!mf.isMarked(ee)) // not already marked
//			{
//				visitedFaces.push_back(ee) ;
//				mf.markOrbit<FACE>(ee) ;
//			}
//
//			e = phi1(e) ;
//		} while(e != visitedFaces[i]) ;
//	}
//
//	return found;
887 888
}

889 890 891 892 893 894 895
} // namespace IHM

} // namespace Volume

} // namespace Algo

} // namespace CGoGN
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 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 963 964 965 966 967 968 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 1021 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 1074 1075 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 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130






//bool ImplicitHierarchicalMap3::faceIsSubdividedOnce(Dart d)
//{
//	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
//	unsigned int fLevel = faceLevel(d) ;
//	if(fLevel < m_curLevel)		// a face whose level in the current level map is lower than
//		return false ;			// the current level can not be subdivided to higher levels
//
//	unsigned int degree = 0 ;
//	bool subd = false ;
//	bool subdOnce = true ;
//	Dart fit = d ;
//	do
//	{
//		++m_curLevel ;
//		if(m_dartLevel[phi1(fit)] == m_curLevel && m_edgeId[phi1(fit)] != m_edgeId[fit])
//		{
//			subd = true ;
//			++m_curLevel ;
//			if(m_dartLevel[phi1(fit)] == m_curLevel && m_edgeId[phi1(fit)] != m_edgeId[fit])
//				subdOnce = false ;
//			--m_curLevel ;
//		}
//		--m_curLevel ;
//		++degree ;
//		fit = phi1(fit) ;
//
//	} while(subd && subdOnce && fit != d) ;
//
//	if(degree == 3 && subd)
//	{
//		++m_curLevel ;
//		Dart cf = phi2(phi1(d)) ;
//		++m_curLevel ;
//		if(m_dartLevel[phi1(cf)] == m_curLevel && m_edgeId[phi1(cf)] != m_edgeId[cf])
//			subdOnce = false ;
//		--m_curLevel ;
//		--m_curLevel ;
//	}
//
//	return subd && subdOnce ;
//}




//Dart ImplicitHierarchicalMap3::cutEdge(Dart d)
//{
//        Dart resV = EmbeddedMap3::cutEdge(d);
//
//        unsigned int eId = getEdgeId(d);
//        Dart dit = d;
//        do
//        {
//        	//EdgeId
//        	m_edgeId[phi1(dit)] = eId;
//        	m_edgeId[phi3(dit)] = eId;
//
//        	//FaceId
//        	unsigned int fId = getFaceId(dit);
//        	m_faceId[phi1(dit)] = fId;
//        	m_edgeId[phi3(dit)] = fId;
//
//            dit = alpha2(dit);
//        }
//        while(dit != d);
//
//        return resV;
//}
//
//bool ImplicitHierarchicalMap3::uncutEdge(Dart d)
//{
//       return EmbeddedMap3::uncutEdge(d);
//}
//
//void ImplicitHierarchicalMap3::splitFace(Dart d, Dart e)
//{
//        EmbeddedMap3::splitFace(d,e);
//
//        unsigned int eId = getNewEdgeId();
//        unsigned int fId = getFaceId(d);
//
//        Dart ne = phi_1(d);
//        Dart ne3 = phi3(ne);
//
//        m_edgeId[ne] = eId;
//        m_edgeId[phi2(ne)] = eId;
//        m_edgeId[ne3] = eId;
//        m_edgeId[phi2(ne3)] = eId;
//
//        m_faceId[ne] = fId;
//        m_faceId[phi2(ne)] = fId;
//        m_faceId[ne3] = fId;
//        m_faceId[phi2(ne3)] = fId;
//}
//
//void ImplicitHierarchicalMap3::sewVolumes(Dart d, Dart e, bool withBoundary)
//{
//        EmbeddedMap3::sewVolumes(d,e);
//
//        unsigned int fId;
//
//        if(m_faceId[d] < m_faceId[phi3(d)])
//        	fId = m_faceId[d] ;
//        else
//        	fId = m_edgeId[phi3(d)];
//
//        Dart dit = d;
//        do
//        {
//                //EdgeId
////                if(m_edgeId[dit] < m_edgeId[phi3(dit)])
////                	m_edgeId[phi3(dit)] = m_edgeId[dit] ;
////                else
////                	m_edgeId[dit] = m_edgeId[phi3(dit)];
//
//                //FaceId
//                m_faceId[dit] = fId;
//                m_faceId[phi3(dit)] = fId;
//
//                dit = phi1(dit);
//        }
//        while(dit != d);
//}
//
//void ImplicitHierarchicalMap3::splitVolume(std::vector<Dart>& vd)
//{
//        EmbeddedMap3::splitVolume(vd);
//
//        unsigned int fId = getNewFaceId();
//
//        for(std::vector<Dart>::iterator it = vd.begin() ; it != vd.end() ; ++it)
//        {
//                Dart dit = *it;
//
//                //Edge Id
//                m_edgeId[phi2(dit)] = m_edgeId[dit];
//
//                //Face Id
//                m_faceId[phi2(dit)] = fId;
//        }
//}
//
//Dart ImplicitHierarchicalMap3::beginSplittingPath(Dart d, DartMarker& m)
//{
//	Dart dres = NIL;
//	Dart dit = d;
//	bool found = false;
//
//	// Recherche d'un brin de depart du chemin d'arete
//	do
//	{
//		Dart eit = phi1(dit);
//
//		if(!m.isMarked(eit) && getDartLevel(eit) == getCurrentLevel())
//		{
//			found = true;
//			dres = eit;
//		}
//
//		dit = phi2(phi_1(dit));
//	}
//	while(!found && dit != d);
//
//	return dres;
//}
//
//void ImplicitHierarchicalMap3::constructSplittingPath(Dart d, std::vector<Dart>& v, DartMarker& m)
//{
//
//	//Construction du chemin d'arete
//	Dart cit = d;
//
//	v.push_back(cit);
//	m.markOrbit<EDGE>(cit);
//
//	do
//	{
//
//		if(std::min(getDartLevel(phi1(cit)),getDartLevel(phi2(phi1(cit))))  == getDartLevel(d))
//		{
//			if(m.isMarked(phi1(cit)))
//			{
//				cit = phi1(phi2(phi1(cit)));
//				std::cout << "1_1" << std::endl;
//			}
//		}
//		else if(std::min(getDartLevel(phi1(cit)),getDartLevel(phi2(phi1(cit)))) < getDartLevel(d))
//		{
//			cit = phi1(phi2(phi1(cit)));
//			std::cout << "2" << std::endl;
//		}
//		else
//			cit = phi1(cit);
//
//		v.push_back(cit);
//		m.markOrbit<EDGE>(cit);
//
//
//	}
//	while(cit != d);
//
////	do
////	{
////		v.push_back(cit);
////		m.markOrbit<EDGE>(cit);
////
////		cit = phi1(cit);
////
////		//std::cout << "cit = " << cit << std::endl;
////
////		if(std::min(getDartLevel(cit), getDartLevel(phi2(cit))) == getDartLevel(d))
////		{
////			if(m.isMarked(cit))
////			{
////				cit = phi1(phi2(cit));
////				//std::cout << "1_1" << std::endl;
////			}
////		}
////		else if(std::min(getDartLevel(cit),getDartLevel(phi2(cit))) < getDartLevel(d))
////		{
////			cit = phi1(phi2(cit));
////			//std::cout << "2" << std::endl;
////		}
////
////	}while(cit != d);
//
//}