ihm3.hpp 22.4 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 25 26 27 28 29 30
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

namespace Algo
{

31 32 33
namespace Volume
{

untereiner's avatar
untereiner committed
34
namespace IHM
35 36
{

37
/***************************************************
38
 *  	   ATTRIBUTES MANAGEMENT    	           	 *
39
 ***************************************************/
40
/*
Pierre Kraemer's avatar
Pierre Kraemer committed
41 42
template <typename T, unsigned int ORBIT>
AttributeHandler_IHM<T, ORBIT> ImplicitHierarchicalMap3::addAttribute(const std::string& nameAttr)
43
{
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    bool addNextLevelCell = false ;
    if(!isOrbitEmbedded<ORBIT>())
        addNextLevelCell = true ;

    AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3> h = Map3::addAttribute<T, ORBIT, ImplicitHierarchicalMap3>(nameAttr) ;

    if(addNextLevelCell)
    {
        AttributeContainer& cellCont = m_attribs[ORBIT] ;
        AttributeMultiVector<unsigned int>* amv = cellCont.addAttribute<unsigned int>("nextLevelCell") ;
        m_nextLevelCell[ORBIT] = amv ;
        for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i))
            amv->operator[](i) = EMBNULL ;
    }

    return AttributeHandler_IHM<T, ORBIT>(this, h.getDataVector()) ;
60 61
}

Pierre Kraemer's avatar
Pierre Kraemer committed
62 63
template <typename T, unsigned int ORBIT>
AttributeHandler_IHM<T, ORBIT> ImplicitHierarchicalMap3::getAttribute(const std::string& nameAttr)
64
{
65 66
    AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3> h = Map3::getAttribute<T, ORBIT, ImplicitHierarchicalMap3>(nameAttr) ;
    return AttributeHandler_IHM<T, ORBIT>(this, h.getDataVector()) ;
67
}
68
*/
69 70
inline void ImplicitHierarchicalMap3::update_topo_shortcuts()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
71
//	Map3::update_topo_shortcuts();
72 73 74
	m_dartLevel = Map3::getAttribute<unsigned int, DART, EmbeddedMap3>("dartLevel") ;
	m_faceId = Map3::getAttribute<unsigned int, DART, EmbeddedMap3>("faceId") ;
	m_edgeId = Map3::getAttribute<unsigned int, DART, EmbeddedMap3>("edgeId") ;
75

76 77
    //AttributeContainer& cont = m_attribs[DART] ;
    //m_nextLevelCell = cont.getDataVector<unsigned int>(cont.getAttributeIndex("nextLevelCell")) ;
78 79 80
}


81
/***************************************************
untereiner's avatar
untereiner committed
82
 *     		 	    MAP TRAVERSAL         		   *
83 84 85 86
 ***************************************************/

inline Dart ImplicitHierarchicalMap3::newDart()
{
87 88 89 90 91
    Dart d = Map3::newDart() ;
    m_dartLevel[d] = m_curLevel ;
    if(m_curLevel > m_maxLevel)			// update max level
        m_maxLevel = m_curLevel ;		// if needed
    return d ;
92 93
}

Sylvain Thery's avatar
Sylvain Thery committed
94
inline Dart ImplicitHierarchicalMap3::phi1(Dart d) const
95
{
96 97
    assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
    bool finished = false ;
98

99 100
    unsigned int edgeId = m_edgeId[d] ;
    Dart it = d ;
untereiner's avatar
untereiner committed
101

102 103
    do
    {
untereiner's avatar
untereiner committed
104

105 106 107 108 109 110 111
        it = Map3::phi1(it) ;
        if(m_dartLevel[it] <= m_curLevel)
            finished = true ;
        else
        {
            while(m_edgeId[it] != edgeId)
                it = Map3::phi1(phi2bis(it));
untereiner's avatar
untereiner committed
112

113 114
        }
    } while(!finished) ;
115

116
    return it ;
117 118
}

Sylvain Thery's avatar
Sylvain Thery committed
119
inline Dart ImplicitHierarchicalMap3::phi_1(Dart d) const
120
{
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
    bool finished = false ;

    Dart it = Map3::phi_1(d) ;
    unsigned int edgeId = m_edgeId[it] ;
    do
    {
        if(m_dartLevel[it] <= m_curLevel)
            finished = true ;
        else
        {
            it = Map3::phi_1(it) ;
            while(m_edgeId[it] != edgeId)
                it = Map3::phi_1(phi2bis(it));
        }
    } while(!finished) ;

    return it ;
139 140
}

Sylvain Thery's avatar
Sylvain Thery committed
141
inline Dart ImplicitHierarchicalMap3::phi2bis(Dart d) const
142
{
143 144
    unsigned int faceId = m_faceId[d];
    Dart it = d;
145

146
    it = Map3::phi2(it) ;
untereiner's avatar
untereiner committed
147

148 149 150 151 152 153 154 155 156 157
    /* du cote des volumes non subdivise (subdiv adapt) */
    if(m_faceId[it] == faceId)
        return it;
    else
    {
        do
        {
            it = Map3::phi2(Map3::phi3(it));
        }
        while(m_faceId[it] != faceId);
158

159 160
        return it;
    }
161 162
}

Sylvain Thery's avatar
Sylvain Thery committed
163
inline Dart ImplicitHierarchicalMap3::phi2(Dart d) const
164
{
165
    assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
166

167
    return Map3::phi2(Map3::phi_1(phi1(d))) ;
168 169
}

Sylvain Thery's avatar
Sylvain Thery committed
170
inline Dart ImplicitHierarchicalMap3::phi3(Dart d) const
171
{
172
    assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
173

174 175
    if(Map3::phi3(d) == d)
        return d;
176

177
    return Map3::phi3(Map3::phi_1(phi1(d)));
178 179
}

Sylvain Thery's avatar
Sylvain Thery committed
180
inline Dart ImplicitHierarchicalMap3::alpha0(Dart d) const
181
{
182
    return phi3(d) ;
183 184
}

Sylvain Thery's avatar
Sylvain Thery committed
185
inline Dart ImplicitHierarchicalMap3::alpha1(Dart d) const
186
{
187
    //assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
188

189
    return phi3(phi_1(d)) ;
190 191
}

Sylvain Thery's avatar
Sylvain Thery committed
192
inline Dart ImplicitHierarchicalMap3::alpha2(Dart d) const
193
{
194
    assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
untereiner's avatar
untereiner committed
195

196
    return phi3(phi2(d));
197 198
}

Sylvain Thery's avatar
Sylvain Thery committed
199
inline Dart ImplicitHierarchicalMap3::alpha_2(Dart d) const
200
{
201
    assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
untereiner's avatar
untereiner committed
202

203
    return phi2(phi3(d));
204 205
}

206
inline Dart ImplicitHierarchicalMap3::begin() const
207
{
208 209 210 211
    Dart d = Map3::begin() ;
    while(m_dartLevel[d] > m_curLevel)
        Map3::next(d) ;
    return d ;
212 213
}

214
inline Dart ImplicitHierarchicalMap3::end() const
215
{
216
    return Map3::end() ;
217 218
}

219
inline void ImplicitHierarchicalMap3::next(Dart& d) const
220
{
221 222 223 224
    do
    {
        Map3::next(d) ;
    } while(d != Map3::end() && m_dartLevel[d] > m_curLevel) ;
225 226
}

227
template <unsigned int ORBIT, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
228
void ImplicitHierarchicalMap3::foreach_dart_of_orbit(Cell<ORBIT> c, FUNC f) const
229 230 231 232
{
	switch(ORBIT)
	{
		case DART:		f(c); break;
Sylvain Thery's avatar
Sylvain Thery committed
233 234 235 236 237 238 239 240 241
		case VERTEX: 	foreach_dart_of_vertex(c, f); break;
		case EDGE: 		foreach_dart_of_edge(c, f); break;
		case FACE: 		foreach_dart_of_face(c, f); break;
		case VOLUME: 	foreach_dart_of_volume(c, f); break;
		case VERTEX1: 	foreach_dart_of_vertex1(c, f); break;
		case EDGE1: 	foreach_dart_of_edge1(c, f); break;
		case VERTEX2: 	foreach_dart_of_vertex2(c, f); break;
		case EDGE2:		foreach_dart_of_edge2(c, f); break;
		case FACE2:		foreach_dart_of_face2(c, f); break;
242 243 244 245 246
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
}

template <unsigned int ORBIT, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
247
void ImplicitHierarchicalMap3::foreach_dart_of_orbit(Cell<ORBIT> c, FUNC& f) const
248 249 250 251
{
	switch(ORBIT)
	{
		case DART:		f(c); break;
Sylvain Thery's avatar
Sylvain Thery committed
252 253 254 255 256 257 258 259 260
		case VERTEX: 	foreach_dart_of_vertex(c, f); break;
		case EDGE: 		foreach_dart_of_edge(c, f); break;
		case FACE: 		foreach_dart_of_face(c, f); break;
		case VOLUME: 	foreach_dart_of_volume(c, f); break;
		case VERTEX1: 	foreach_dart_of_vertex1(c, f); break;
		case EDGE1: 	foreach_dart_of_edge1(c, f); break;
		case VERTEX2: 	foreach_dart_of_vertex2(c, f); break;
		case EDGE2:		foreach_dart_of_edge2(c, f); break;
		case FACE2:		foreach_dart_of_face2(c, f); break;
261 262 263 264 265
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
}

template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
266
inline void ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FUNC& f) const
267
{
Sylvain Thery's avatar
Sylvain Thery committed
268
	DartMarkerStore<Map3> mv(*this);	// Lock a marker
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

    std::vector<Dart> darts;	// Darts that are traversed
    darts.reserve(256);
    darts.push_back(d);			// Start with the dart d
    mv.mark(d);

    for(unsigned int i = 0; i < darts.size(); ++i)
    {
        // add phi21 and phi23 successor if they are not marked yet
        Dart d2 = phi2(darts[i]);
        Dart d21 = phi1(d2); // turn in volume
        Dart d23 = phi3(d2); // change volume

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

        f(darts[i]);
    }
295 296
}

297
template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
298
inline void ImplicitHierarchicalMap3::foreach_dart_of_edge(Dart d, FUNC& f) const
299 300 301
{
	Dart dNext = d;
	do {
Sylvain Thery's avatar
Sylvain Thery committed
302
		foreach_dart_of_edge2(dNext, f);
303 304 305 306
		dNext = alpha2(dNext);
	} while (dNext != d);
}

307
template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
308
inline void ImplicitHierarchicalMap3::foreach_dart_of_oriented_face(Dart d, FUNC& f) const
309
{
310 311 312 313 314 315
    Dart dNext = d ;
    do
    {
        f(dNext);
        dNext = phi1(dNext) ;
    } while (dNext != d) ;
316 317
}

318
template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
319
inline void ImplicitHierarchicalMap3::foreach_dart_of_face(Dart d, FUNC& f) const
320
{
Sylvain Thery's avatar
Sylvain Thery committed
321 322
	foreach_dart_of_oriented_face(d, f);
	foreach_dart_of_oriented_face(phi3(d), f);
323 324
}

325
template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
326
inline void ImplicitHierarchicalMap3::foreach_dart_of_oriented_volume(Dart d, FUNC& f) const
untereiner's avatar
untereiner committed
327
{
Sylvain Thery's avatar
Sylvain Thery committed
328
	DartMarkerStore<Map3> mark(*this);	// Lock a marker
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

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

    // For every face added to the list
    for(unsigned int i = 0; i < visitedFaces.size(); ++i)
    {
        if (!mark.isMarked(visitedFaces[i]))	// Face has not been visited yet
        {
            // Apply functor to the darts of the face
            foreach_dart_of_oriented_face(visitedFaces[i], f);

            // mark visited darts (current face)
            // and add non visited adjacent faces to the list of face
            Dart e = visitedFaces[i] ;
            do
            {
                mark.mark(e);				// Mark
                Dart adj = phi2(e);			// Get adjacent face
                if (!mark.isMarked(adj))
                    visitedFaces.push_back(adj);	// Add it
                e = phi1(e);
            } while(e != visitedFaces[i]);
        }
    }
untereiner's avatar
untereiner committed
355 356
}

357
template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
358
inline void ImplicitHierarchicalMap3::foreach_dart_of_volume(Dart d, FUNC& f) const
untereiner's avatar
untereiner committed
359
{
Sylvain Thery's avatar
Sylvain Thery committed
360
	foreach_dart_of_oriented_volume(d, f) ;
untereiner's avatar
untereiner committed
361
}
untereiner's avatar
untereiner committed
362

363
template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
364
inline void ImplicitHierarchicalMap3::foreach_dart_of_vertex1(Dart d, FUNC& f) const
365
{
366
    f(d);
367 368 369
}

template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
370
inline void ImplicitHierarchicalMap3::foreach_dart_of_edge1(Dart d, FUNC& f) const
371
{
372
    f(d);
373 374 375
}

template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
376
inline void ImplicitHierarchicalMap3::foreach_dart_of_vertex2(Dart d, FUNC& f) const
377
{
378 379 380 381 382 383
    Dart dNext = d;
    do
    {
        f(dNext);
        dNext = phi2(phi_1(dNext));
    } while (dNext != d);
384 385 386
}

template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
387
inline void ImplicitHierarchicalMap3::foreach_dart_of_edge2(Dart d, FUNC& f) const
388
{
389 390
    f(d);
    f(phi2(d));
391 392 393
}

template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
394
inline void ImplicitHierarchicalMap3::foreach_dart_of_face2(Dart d, FUNC& f) const
395
{
Sylvain Thery's avatar
Sylvain Thery committed
396
	foreach_dart_of_oriented_face(d, f);
397 398 399
}

template <typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
400
inline void ImplicitHierarchicalMap3::foreach_dart_of_cc(Dart d, FUNC& f) const
401
{
Sylvain Thery's avatar
Sylvain Thery committed
402
	DartMarkerStore<Map3> mark(*this);	// Lock a marker
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428

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

    // For every face added to the list
    for(unsigned int i = 0; i < visitedFaces.size(); ++i)
    {
        if (!mark.isMarked(visitedFaces[i]))	// Face has not been visited yet
        {
            // Apply functor to the darts of the face
            foreach_dart_of_face(visitedFaces[i], f);

            // mark visited darts (current face)
            // and add non visited adjacent faces to the list of face
            Dart e = visitedFaces[i] ;
            do
            {
                mark.mark(e);				// Mark
                Dart adj = phi2(e);			// Get adjacent face
                if (!mark.isMarked(adj))
                    visitedFaces.push_back(adj);	// Add it
                e = phi1(e);
            } while(e != visitedFaces[i]);
        }
    }
429

430
//	// foreach_dart_of_oriented_volume(d, f) ;
Sylvain Thery's avatar
Sylvain Thery committed
431
//	DartMarkerStore mv(*this);	// Lock a marker
untereiner's avatar
untereiner committed
432 433 434 435 436 437
//
//	std::vector<Dart> darts;	// Darts that are traversed
//	darts.reserve(1024);
//	darts.push_back(d);			// Start with the dart d
//	mv.mark(d);
//
438
//	for(unsigned int i = 0; i < darts.size(); ++i)
untereiner's avatar
untereiner committed
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
//	{
//		// add all successors if they are not marked yet
//		Dart d2 = phi1(darts[i]); // turn in face
//		Dart d3 = phi2(darts[i]); // change face
//		Dart d4 = phi3(darts[i]); // change volume
//
//		if (!mv.isMarked(d2))
//		{
//			darts.push_back(d2);
//			mv.mark(d2);
//		}
//		if (!mv.isMarked(d3))
//		{
//			darts.push_back(d2);
//			mv.mark(d2);
//		}
//		if (!mv.isMarked(d4))
//		{
//			darts.push_back(d4);
//			mv.mark(d4);
//		}
//
461
//		f(darts[i]);
untereiner's avatar
untereiner committed
462
//	}
463 464 465 466 467 468
}

/***************************************************
 *              LEVELS MANAGEMENT                  *
 ***************************************************/

untereiner's avatar
untereiner committed
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
inline void ImplicitHierarchicalMap3::incCurrentLevel()
{
	if(m_curLevel < m_maxLevel)
		++m_curLevel ;
	else
		CGoGNout << "incCurrentLevel : already at maximum resolution level" << CGoGNendl ;
}

inline void ImplicitHierarchicalMap3::decCurrentLevel()
{
	if(m_curLevel > 0)
		--m_curLevel ;
	else
		CGoGNout << "decCurrentLevel : already at minimum resolution level" << CGoGNendl ;
}



Sylvain Thery's avatar
Sylvain Thery committed
487
inline unsigned int ImplicitHierarchicalMap3::getCurrentLevel() const
488 489 490 491 492 493 494 495 496
{
	return m_curLevel ;
}

inline void ImplicitHierarchicalMap3::setCurrentLevel(unsigned int l)
{
	m_curLevel = l ;
}

Sylvain Thery's avatar
Sylvain Thery committed
497
inline unsigned int ImplicitHierarchicalMap3::getMaxLevel() const
498 499 500 501
{
	return m_maxLevel ;
}

Sylvain Thery's avatar
Sylvain Thery committed
502
inline unsigned int ImplicitHierarchicalMap3::getDartLevel(Dart d) const
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
{
	return m_dartLevel[d] ;
}

inline void ImplicitHierarchicalMap3::setDartLevel(Dart d, unsigned int l)
{
	m_dartLevel[d] = l ;
}

/***************************************************
 *             EDGE ID MANAGEMENT                  *
 ***************************************************/

inline unsigned int ImplicitHierarchicalMap3::getNewEdgeId()
{
	return m_edgeIdCount++ ;
}


inline unsigned int ImplicitHierarchicalMap3::getEdgeId(Dart d)
{
	return m_edgeId[d] ;
}

inline void ImplicitHierarchicalMap3::setEdgeId(Dart d, unsigned int i, unsigned int orbit)
{
529
	if(orbit == EDGE)
530 531 532 533 534 535 536 537 538 539 540
	{
		Dart e = d;

		do
		{
			m_edgeId[e] = i;
			m_edgeId[Map3::phi2(e)] = i;

			e = Map3::alpha2(e);
		} while(e != d);
	}
541
	else if(orbit == DART)
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
	{
		m_edgeId[d] = i;
	}
}

/***************************************************
 *             FACE ID MANAGEMENT                  *
 ***************************************************/

inline unsigned int ImplicitHierarchicalMap3::getNewFaceId()
{
	return m_faceIdCount++;
}

inline unsigned int ImplicitHierarchicalMap3::getFaceId(Dart d)
{
	return m_faceId[d] ;
}

561
inline void ImplicitHierarchicalMap3::setFaceId(unsigned int orbit, Dart d)
562 563
{
	//Mise a jour de l'id de face pour les brins autour d'une arete
564
	if(orbit == EDGE)
565 566 567 568 569
	{
		Dart e = d;

		do
		{
570
			m_faceId[Map3::phi1(e)] = m_faceId[e];
571 572 573 574 575

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

	}
576 577 578 579 580
}

inline void ImplicitHierarchicalMap3::setFaceId(Dart d, unsigned int i, unsigned int orbit)
{

581
	//Mise a jour de l'id de face pour les brins autour de la face
582
	if(orbit == FACE)
583 584 585 586 587 588 589 590 591 592 593 594 595 596
	{
		Dart e = d;

		do
		{
			m_faceId[e] = i;

			Dart e3 = Map3::phi3(e);
			if(e3 != e)
				m_faceId[e3] = i;

			e = Map3::phi1(e);
		} while(e != d);
	}
597
	else if(orbit == DART)
598 599
	{
		m_faceId[d] = i;
600 601 602

		if(Map3::phi3(d) != d)
			m_faceId[Map3::phi3(d)] = i;
603 604 605 606 607 608 609 610
	}
}

/***************************************************
 *               CELLS INFORMATION                 *
 ***************************************************/

//TODO
Sylvain Thery's avatar
Sylvain Thery committed
611
inline unsigned int ImplicitHierarchicalMap3::vertexInsertionLevel(Dart d) const
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
{
	assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
	return m_dartLevel[d] ;
}

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

	// the level of an edge is the maximum of the
	// insertion levels of its darts

	unsigned int r = 0;

	Dart e = d;
	do
	{
		unsigned int ld = m_dartLevel[e] ;
		unsigned int ldd = m_dartLevel[phi2(e)] ;
		unsigned int temp = ld < ldd ? ldd : ld;

		r =  r < temp ? temp : r ;

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

	return r;
}

641
/*
642
template <unsigned int ORBIT>
643
inline unsigned int ImplicitHierarchicalMap3::getEmbedding(Cell<ORBIT> c) const
644
{
645 646
	unsigned int nbSteps = m_curLevel - vertexInsertionLevel(c.dart);
	unsigned int index = EmbeddedMap3::getEmbedding(c);
647

648 649 650 651 652 653 654 655 656
    unsigned int step = 0;
    while(step < nbSteps)
    {
        step++;
        unsigned int next = m_nextLevelCell[ORBIT]->operator[](index);
        //index = next;
        if(next != EMBNULL) index = next;
        else break;
    }
657

658
    return index;
659
}*/
660

661 662 663 664 665
inline bool ImplicitHierarchicalMap3::isWellEmbedded()
{
	//std::cout << "yeahhh ? " << std::endl;
	TraversorV<ImplicitHierarchicalMap3> tv(*this);

666
	for(Vertex dv = tv.begin() ; dv.dart != tv.end() ; dv = tv.next())
667
	{
668
		unsigned int curem = this->getEmbedding(dv);
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
		//std::cout << "current emb = " << curem << std::endl;

		unsigned int count = 0;
		TraversorDartsOfOrbit<ImplicitHierarchicalMap3, VERTEX> to(*this, dv);
		for(Dart dit = to.begin() ; dit != to.end() ; dit = to.next())
		{
			//std::cout << getDartLevel(dit) << std::endl;

			if(curem != this->getEmbedding<VERTEX>(dit))
			{
				std::cout << "erreur dart #" << dit;
				std::cout << " / curem = " << curem;
				std::cout << " / em = " << this->getEmbedding<VERTEX>(dit);
				std::cout << std::endl;
			}

			std::cout << EmbeddedMap3::getEmbedding<VERTEX>(dit) << "(" << this->getEmbedding<VERTEX>(dit) << ")" << " / ";
			++count;
		}
		std::cout << " / vertex degree = " << count << std::endl;

	}

	return true;
}

695

696 697 698 699 700 701 702 703 704 705










706 707 708
//void ImplicitHierarchicalMap3::analysis()
//{
//    assert(getCurrentLevel() > 0 || !"analysis : called on level 0") ;
709

710
//   decCurrentLevel() ;
711

712 713 714
//    for(unsigned int i = 0; i < analysisFilters.size(); ++i)
//        (*analysisFilters[i])() ;
//}
715

716 717 718
//void ImplicitHierarchicalMap3::synthesis()
//{
//    assert(getCurrentLevel() < getMaxLevel() || !"synthesis : called on max level") ;
719

720 721
//    for(unsigned int i = 0; i < synthesisFilters.size(); ++i)
//        (*synthesisFilters[i])() ;
722

723 724
//    incCurrentLevel() ;
//}
725

726 727 728 729
/***************************************************
 *               ATTRIBUTE HANDLER                 *
 ***************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
730 731
template <typename T, unsigned int ORBIT>
T& AttributeHandler_IHM<T, ORBIT>::operator[](Dart d)
732 733 734 735 736
{
	ImplicitHierarchicalMap3* m = reinterpret_cast<ImplicitHierarchicalMap3*>(this->m_map) ;
	assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
	assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;

737
//	std::cout << std::endl << "vertexInsertionLevel[" << d <<"] = " << m->vertexInsertionLevel(d) << "\t";
738

739
	unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
740 741 742 743 744 745
	unsigned int index = m->EmbeddedMap3::getEmbedding<ORBIT>(d) ;

//	std::cout << " m->vertexInsertionLevel(d) = " <<  m->vertexInsertionLevel(d) << std::endl;
//	std::cout << "m_curLevel = " << m->m_curLevel << std::endl;
//	std::cout << " nbSteps = " <<  nbSteps << std::endl;
//	std::cout << "index EmbMap3 = " << index << std::endl;
746 747 748

	if(index == EMBNULL)
	{
749
		index = Algo::Topo::setOrbitEmbeddingOnNewCell<ORBIT>(*m, d) ;
750
		m->m_nextLevelCell[ORBIT]->operator[](index) = EMBNULL ;
751 752
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
753
	AttributeContainer& cont = m->getAttributeContainer<ORBIT>() ;
754 755 756 757
	unsigned int step = 0 ;
	while(step < nbSteps)
	{
		step++ ;
758
		unsigned int nextIdx = m->m_nextLevelCell[ORBIT]->operator[](index) ;
759 760
		if (nextIdx == EMBNULL)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
761 762
			nextIdx = m->newCell<ORBIT>() ;
			m->copyCell<ORBIT>(nextIdx, index) ;
763 764
			m->m_nextLevelCell[ORBIT]->operator[](index) = nextIdx ;
			m->m_nextLevelCell[ORBIT]->operator[](nextIdx) = EMBNULL ;
765 766 767 768
			cont.refLine(index) ;
		}
		index = nextIdx ;
	}
769

770
//	std::cout << "emb = " << index << std::endl;
771 772 773 774 775

//	std::cout << "index IHM = " << index << std::endl;
//	if(index != EMBNULL)
//		std::cout << " emb = " << this->m_attrib->operator[](index) << std::endl << std::endl;

776 777 778
	return this->m_attrib->operator[](index);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
779 780
template <typename T, unsigned int ORBIT>
const T& AttributeHandler_IHM<T, ORBIT>::operator[](Dart d) const
781 782 783 784 785 786
{
	ImplicitHierarchicalMap3* m = reinterpret_cast<ImplicitHierarchicalMap3*>(this->m_map) ;
	assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
	assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;

	unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
787 788
    //unsigned int index = m->EmbeddedMap3::getEmbedding<ORBIT>(d) ;
    unsigned int index = m->EmbeddedMap3::getEmbedding<ORBIT>(d) ;
789 790 791 792 793

//	std::cout << "(const) m->vertexInsertionLevel(d) = " <<  m->vertexInsertionLevel(d) << std::endl;
//	std::cout << "(const) m_curLevel = " << m->m_curLevel << std::endl;
//	std::cout << "(const) nbSteps = " <<  nbSteps << std::endl;
//	std::cout << "(const) index EmbMap3 = " << index << std::endl;
794 795 796 797 798

	unsigned int step = 0 ;
	while(step < nbSteps)
	{
		step++ ;
799 800
		unsigned int nextIdx = m->m_nextLevelCell[ORBIT]->operator[](index) ;
		if(nextIdx != EMBNULL) index = nextIdx ;
801 802
		else break ;
	}
803 804 805 806

//	if(index != EMBNULL)
//		std::cout << "(const) emb = " << this->m_attrib->operator[](index) << std::endl << std::endl;

807 808
	return this->m_attrib->operator[](index);
}
809

810

811
} //namespace IHM
812
} // Volume
813 814
} //namespace Algo
} //namespace CGoGN