Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

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
    assert(m_dartLevel[d] <= m_curLevel || !"Access to a dart introduced after current level") ;
pitiot's avatar
up  
pitiot committed
97
98


99
    bool finished = false ;
100

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

104
105
    do
    {
untereiner's avatar
untereiner committed
106

107
108
109
110
111
112
113
        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
114

115
116
        }
    } while(!finished) ;
117

118
    return it ;
119
120
}

Sylvain Thery's avatar
Sylvain Thery committed
121
inline Dart ImplicitHierarchicalMap3::phi_1(Dart d) const
122
{
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    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 ;
141
142
}

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

148
    it = Map3::phi2(it) ;
untereiner's avatar
untereiner committed
149

150
151
152
153
154
155
156
157
158
159
    /* 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);
160

161
162
        return it;
    }
163
164
}

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

169
    return Map3::phi2(Map3::phi_1(phi1(d))) ;
170
171
}

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

176
177
    if(Map3::phi3(d) == d)
        return d;
178

179
    return Map3::phi3(Map3::phi_1(phi1(d)));
180
181
}

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

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

191
    return phi3(phi_1(d)) ;
192
193
}

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

198
    return phi3(phi2(d));
199
200
}

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

205
    return phi2(phi3(d));
206
207
}

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

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

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

229
template <unsigned int ORBIT, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
230
void ImplicitHierarchicalMap3::foreach_dart_of_orbit(Cell<ORBIT> c, FUNC f) const
231
232
233
234
{
	switch(ORBIT)
	{
		case DART:		f(c); break;
Sylvain Thery's avatar
Sylvain Thery committed
235
236
237
238
239
240
241
242
243
		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;
244
245
246
247
248
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
}

template <unsigned int ORBIT, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
249
void ImplicitHierarchicalMap3::foreach_dart_of_orbit(Cell<ORBIT> c, FUNC& f) const
250
251
252
253
{
	switch(ORBIT)
	{
		case DART:		f(c); break;
Sylvain Thery's avatar
Sylvain Thery committed
254
255
256
257
258
259
260
261
262
		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;
263
264
265
266
267
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
}

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

    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]);
    }
297
298
}

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

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

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

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

    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
357
358
}

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

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

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

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

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

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

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

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

432
//	// foreach_dart_of_oriented_volume(d, f) ;
Sylvain Thery's avatar
Sylvain Thery committed
433
//	DartMarkerStore mv(*this);	// Lock a marker
untereiner's avatar
untereiner committed
434
435
436
437
438
439
//
//	std::vector<Dart> darts;	// Darts that are traversed
//	darts.reserve(1024);
//	darts.push_back(d);			// Start with the dart d
//	mv.mark(d);
//
440
//	for(unsigned int i = 0; i < darts.size(); ++i)
untereiner's avatar
untereiner committed
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
//	{
//		// 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);
//		}
//
463
//		f(darts[i]);
untereiner's avatar
untereiner committed
464
//	}
465
466
467
468
469
470
}

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

untereiner's avatar
untereiner committed
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
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
489
inline unsigned int ImplicitHierarchicalMap3::getCurrentLevel() const
490
491
492
493
494
495
496
497
498
{
	return m_curLevel ;
}

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

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

Sylvain Thery's avatar
Sylvain Thery committed
504
inline unsigned int ImplicitHierarchicalMap3::getDartLevel(Dart d) const
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
{
	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)
{
531
	if(orbit == EDGE)
532
533
534
535
536
537
538
539
540
541
542
	{
		Dart e = d;

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

			e = Map3::alpha2(e);
		} while(e != d);
	}
543
	else if(orbit == DART)
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
	{
		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] ;
}

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

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

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

	}
578
579
580
581
582
}

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

583
	//Mise a jour de l'id de face pour les brins autour de la face
584
	if(orbit == FACE)
585
586
587
588
589
590
591
592
593
594
595
596
597
598
	{
		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);
	}
599
	else if(orbit == DART)
600
601
	{
		m_faceId[d] = i;
602
603
604

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

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

//TODO
Sylvain Thery's avatar
Sylvain Thery committed
613
inline unsigned int ImplicitHierarchicalMap3::vertexInsertionLevel(Dart d) const
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
641
642
{
	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;
}

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

650
651
652
653
654
655
656
657
658
    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;
    }
659

660
    return index;
661
}*/
662

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

668
	for(Vertex dv = tv.begin() ; dv.dart != tv.end() ; dv = tv.next())
669
	{
670
		unsigned int curem = this->getEmbedding(dv);
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
		//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;
}

697

698
699
700
701
702
703
704
705
706
707










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

712
//   decCurrentLevel() ;
713

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

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

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

725
726
//    incCurrentLevel() ;
//}
727

728
729
730
731
/***************************************************
 *               ATTRIBUTE HANDLER                 *
 ***************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
732
733
template <typename T, unsigned int ORBIT>
T& AttributeHandler_IHM<T, ORBIT>::operator[](Dart d)
734
735
736
737
738
{
	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") ;

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

741
	unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
742
743
744
745
746
747
	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;
748
749
750

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

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

772
//	std::cout << "emb = " << index << std::endl;
773
774
775
776
777

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

778
779
780
	return this->m_attrib->operator[](index);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
781
782
template <typename T, unsigned int ORBIT>
const T& AttributeHandler_IHM<T, ORBIT>::operator[](Dart d) const
783
784
785
786
787
788
{
	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) ;
789
790
    //unsigned int index = m->EmbeddedMap3::getEmbedding<ORBIT>(d) ;
    unsigned int index = m->EmbeddedMap3::getEmbedding<ORBIT>(d) ;
791
792
793
794
795

//	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;
796
797
798
799
800

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

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

809
810
	return this->m_attrib->operator[](index);
}
811

812

813
} //namespace IHM
814
} // Volume
815
816
} //namespace Algo
} //namespace CGoGN