Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

ihm3.hpp 22 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
{
	bool addNextLevelCell = false ;
45
	if(!isOrbitEmbedded<ORBIT>())
46
47
		addNextLevelCell = true ;

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

	if(addNextLevelCell)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
52
		AttributeContainer& cellCont = m_attribs[ORBIT] ;
53
		AttributeMultiVector<unsigned int>* amv = cellCont.addAttribute<unsigned int>("nextLevelCell") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
54
		m_nextLevelCell[ORBIT] = amv ;
55
56
57
58
		for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i))
			amv->operator[](i) = EMBNULL ;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
59
	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
	AttributeHandler<T, ORBIT, ImplicitHierarchicalMap3> h = Map3::getAttribute<T, ORBIT, ImplicitHierarchicalMap3>(nameAttr) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
66
	return AttributeHandler_IHM<T, ORBIT>(this, h.getDataVector()) ;
67
}
untereiner's avatar
untereiner committed
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, ImplicitHierarchicalMap3>("dartLevel") ;
	m_faceId = Map3::getAttribute<unsigned int, DART, ImplicitHierarchicalMap3>("faceId") ;
	m_edgeId = Map3::getAttribute<unsigned int, DART, ImplicitHierarchicalMap3>("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
87
88
89
90
91
92
93
 ***************************************************/

inline Dart ImplicitHierarchicalMap3::newDart()
{
	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 ;
}

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

	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
		it = Map3::phi1(it) ;
		if(m_dartLevel[it] <= m_curLevel)
			finished = true ;
		else
		{
110
			while(m_edgeId[it] != edgeId)
111
				it = Map3::phi1(phi2bis(it));
untereiner's avatar
untereiner committed
112

113
114
115
116
117
118
		}
	} while(!finished) ;

	return it ;
}

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
{
	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) ;
133
			while(m_edgeId[it] != edgeId)
untereiner's avatar
untereiner committed
134
				it = Map3::phi_1(phi2bis(it));
135
136
137
138
139
140
		}
	} while(!finished) ;

	return it ;
}

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

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

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

		return it;
	}
}

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

	return Map3::phi2(Map3::phi_1(phi1(d))) ;
}

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

	if(Map3::phi3(d) == d)
		return d;

	return Map3::phi3(Map3::phi_1(phi1(d)));
}

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

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

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

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

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

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

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

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

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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
template <unsigned int ORBIT, typename FUNC>
void ImplicitHierarchicalMap3::foreach_dart_of_orbit(Cell<ORBIT> c, FUNC f, unsigned int thread) const
{
	switch(ORBIT)
	{
		case DART:		f(c); break;
		case VERTEX: 	foreach_dart_of_vertex(c, f, thread); break;
		case EDGE: 		foreach_dart_of_edge(c, f, thread); break;
		case FACE: 		foreach_dart_of_face(c, f, thread); break;
		case VOLUME: 	foreach_dart_of_volume(c, f, thread); break;
		case VERTEX1: 	foreach_dart_of_vertex1(c, f, thread); break;
		case EDGE1: 	foreach_dart_of_edge1(c, f, thread); break;
		case VERTEX2: 	foreach_dart_of_vertex2(c, f, thread); break;
		case EDGE2:		foreach_dart_of_edge2(c, f, thread); break;
		case FACE2:		foreach_dart_of_face2(c, f, thread); break;
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
}

template <unsigned int ORBIT, typename FUNC>
void ImplicitHierarchicalMap3::foreach_dart_of_orbit(Cell<ORBIT> c, FUNC& f, unsigned int thread) const
{
	switch(ORBIT)
	{
		case DART:		f(c); break;
		case VERTEX: 	foreach_dart_of_vertex(c, f, thread); break;
		case EDGE: 		foreach_dart_of_edge(c, f, thread); break;
		case FACE: 		foreach_dart_of_face(c, f, thread); break;
		case VOLUME: 	foreach_dart_of_volume(c, f, thread); break;
		case VERTEX1: 	foreach_dart_of_vertex1(c, f, thread); break;
		case EDGE1: 	foreach_dart_of_edge1(c, f, thread); break;
		case VERTEX2: 	foreach_dart_of_vertex2(c, f, thread); break;
		case EDGE2:		foreach_dart_of_edge2(c, f, thread); break;
		case FACE2:		foreach_dart_of_face2(c, f, thread); break;
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
}

template <typename FUNC>
inline void ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FUNC& f, unsigned int thread) const
267
{
Pierre Kraemer's avatar
Pierre Kraemer committed
268
	DartMarkerStore<Map3> mv(*this, thread);	// Lock a marker
269

untereiner's avatar
untereiner committed
270
271
272
	std::vector<Dart> darts;	// Darts that are traversed
	darts.reserve(256);
	darts.push_back(d);			// Start with the dart d
273
274
	mv.mark(d);

275
	for(unsigned int i = 0; i < darts.size(); ++i)
276
	{
untereiner's avatar
untereiner committed
277
278
279
280
		// 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
281

untereiner's avatar
untereiner committed
282
		if(!mv.isMarked(d21))
283
		{
untereiner's avatar
untereiner committed
284
285
286
287
288
289
290
			darts.push_back(d21);
			mv.mark(d21);
		}
		if(!mv.isMarked(d23))
		{
			darts.push_back(d23);
			mv.mark(d23);
291
292
		}

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

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

307
308
template <typename FUNC>
inline void ImplicitHierarchicalMap3::foreach_dart_of_oriented_face(Dart d, FUNC& f, unsigned int /*thread*/) const
309
310
311
312
{
	Dart dNext = d ;
	do
	{
313
		f(dNext);
314
315
316
317
		dNext = phi1(dNext) ;
	} while (dNext != d) ;
}

318
319
template <typename FUNC>
inline void ImplicitHierarchicalMap3::foreach_dart_of_face(Dart d, FUNC& f, unsigned int thread) const
320
{
321
322
	foreach_dart_of_oriented_face(d, f, thread);
	foreach_dart_of_oriented_face(phi3(d), f, thread);
323
324
}

325
326
template <typename FUNC>
inline void ImplicitHierarchicalMap3::foreach_dart_of_oriented_volume(Dart d, FUNC& f, unsigned int thread) const
untereiner's avatar
untereiner committed
327
{
Pierre Kraemer's avatar
Pierre Kraemer committed
328
	DartMarkerStore<Map3> mark(*this, thread);	// Lock a marker
untereiner's avatar
untereiner committed
329
330
331
332
333
334

	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
335
	for(unsigned int i = 0; i < visitedFaces.size(); ++i)
untereiner's avatar
untereiner committed
336
337
338
339
	{
		if (!mark.isMarked(visitedFaces[i]))	// Face has not been visited yet
		{
			// Apply functor to the darts of the face
340
			foreach_dart_of_oriented_face(visitedFaces[i], f);
untereiner's avatar
untereiner committed
341

342
			// mark visited darts (current face)
untereiner's avatar
untereiner committed
343
			// and add non visited adjacent faces to the list of face
344
345
			Dart e = visitedFaces[i] ;
			do
untereiner's avatar
untereiner committed
346
			{
347
348
349
350
351
352
				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
353
354
355
356
		}
	}
}

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

363
template <typename FUNC>
364
inline void ImplicitHierarchicalMap3::foreach_dart_of_vertex1(Dart d, FUNC& f, unsigned int /*thread*/) const
365
366
367
368
369
{
	f(d);
}

template <typename FUNC>
370
inline void ImplicitHierarchicalMap3::foreach_dart_of_edge1(Dart d, FUNC& f, unsigned int /*thread*/) const
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
{
	f(d);
}

template <typename FUNC>
inline void ImplicitHierarchicalMap3::foreach_dart_of_vertex2(Dart d, FUNC& f, unsigned int /*thread*/) const
{
	Dart dNext = d;
	do
	{
		f(dNext);
		dNext = phi2(phi_1(dNext));
	} while (dNext != d);
}

template <typename FUNC>
inline void ImplicitHierarchicalMap3::foreach_dart_of_edge2(Dart d, FUNC& f, unsigned int /*thread*/) const
{
	f(d);
	f(phi2(d));
}

template <typename FUNC>
inline void ImplicitHierarchicalMap3::foreach_dart_of_face2(Dart d, FUNC& f, unsigned int thread) const
{
	foreach_dart_of_oriented_face(d, f, thread);
}

template <typename FUNC>
inline void ImplicitHierarchicalMap3::foreach_dart_of_cc(Dart d, FUNC& f, unsigned int thread) const
401
{
Pierre Kraemer's avatar
Pierre Kraemer committed
402
	DartMarkerStore<Map3> mark(*this, thread);	// Lock a marker
403

404
	std::vector<Dart> visitedFaces;	// Faces that are traversed
untereiner's avatar
untereiner committed
405
	visitedFaces.reserve(1024) ;
406
407
408
	visitedFaces.push_back(d);		// Start with the face of d

	// For every face added to the list
409
	for(unsigned int i = 0; i < visitedFaces.size(); ++i)
410
	{
untereiner's avatar
untereiner committed
411
		if (!mark.isMarked(visitedFaces[i]))	// Face has not been visited yet
412
413
		{
			// Apply functor to the darts of the face
414
			foreach_dart_of_face(visitedFaces[i], f);
415

416
			// mark visited darts (current face)
417
			// and add non visited adjacent faces to the list of face
418
419
			Dart e = visitedFaces[i] ;
			do
420
			{
421
422
423
424
425
426
				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]);
427
428
429
		}
	}

430
//	// foreach_dart_of_oriented_volume(d, f) ;
untereiner's avatar
untereiner committed
431
432
433
434
435
436
437
//	DartMarkerStore mv(*this,thread);	// Lock a marker
//
//	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
template <unsigned int ORBIT>
642
inline unsigned int ImplicitHierarchicalMap3::getEmbedding(Cell<ORBIT> c) const
643
{
644
645
	unsigned int nbSteps = m_curLevel - vertexInsertionLevel(c.dart);
	unsigned int index = EmbeddedMap3::getEmbedding(c);
646

647
648
649
650
651
652
653
654
655
    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;
    }
656

657
    return index;
658
659
}

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

665
	for(Vertex dv = tv.begin() ; dv.dart != tv.end() ; dv = tv.next())
666
	{
667
		unsigned int curem = this->getEmbedding(dv);
668
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
		//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;
}

694

695
696
697
698
699
700
701
702
703
704










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

709
//   decCurrentLevel() ;
710

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

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

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

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

725
726
727
728
/***************************************************
 *               ATTRIBUTE HANDLER                 *
 ***************************************************/

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

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

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

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

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

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

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

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

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

//	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;
793
794
795
796
797

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

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

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

809

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