genericmap.hpp 30.8 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25 26
#include "Topology/generic/dartmarker.h"
#include "Topology/generic/traversorCell.h"
27
#include "Topology/generic/traversorFactory.h"
28

Pierre Kraemer's avatar
Pierre Kraemer committed
29 30
namespace CGoGN
{
Pierre Kraemer's avatar
Pierre Kraemer committed
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45
/****************************************
 *           MULTIRES                   *
 ****************************************/

inline unsigned int GenericMap::getCurrentLevel()
{
	return m_mrCurrentLevel ;
}

inline void GenericMap::setCurrentLevel(unsigned int l)
{
	if(l < m_mrDarts.size())
		m_mrCurrentLevel = l ;
	else
Pierre Kraemer's avatar
Pierre Kraemer committed
46
		CGoGNout << "setCurrentLevel : try to access nonexistent resolution level" << CGoGNendl ;
47 48
}

Pierre Kraemer's avatar
Pierre Kraemer committed
49 50
inline void GenericMap::incCurrentLevel()
{
51
	if(m_mrCurrentLevel < m_mrDarts.size() - 1)
Pierre Kraemer's avatar
Pierre Kraemer committed
52 53 54 55 56 57 58 59 60 61 62 63 64
		++m_mrCurrentLevel ;
	else
		CGoGNout << "incCurrentLevel : already at maximum resolution level" << CGoGNendl ;
}

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

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
inline void GenericMap::pushLevel()
{
	m_mrLevelStack.push_back(m_mrCurrentLevel) ;
}

inline void GenericMap::popLevel()
{
	m_mrCurrentLevel = m_mrLevelStack.back() ;
	m_mrLevelStack.pop_back() ;
}

inline unsigned int GenericMap::getMaxLevel()
{
	return m_mrDarts.size() - 1 ;
}

81

Pierre Kraemer's avatar
Pierre Kraemer committed
82 83 84 85 86 87
/****************************************
 *           DARTS MANAGEMENT           *
 ****************************************/

inline Dart GenericMap::newDart()
{
88
	unsigned int di = m_attribs[DART].insertLine();		// insert a new dart line
Pierre Kraemer's avatar
Pierre Kraemer committed
89
	for(unsigned int i = 0; i < NB_ORBITS; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
90
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
91 92
		if (m_embeddings[i])								// set all its embeddings
			(*m_embeddings[i])[di] = EMBNULL ;				// to EMBNULL
Pierre Kraemer's avatar
Pierre Kraemer committed
93
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
94

Pierre Kraemer's avatar
Pierre Kraemer committed
95 96
	if (m_isMultiRes)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
97 98
		unsigned int mrdi = m_mrattribs.insertLine() ;		// insert a new MRdart line
		(*m_mrLevels)[mrdi] = m_mrCurrentLevel ;			// set the introduction level of the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
99
		m_mrNbDarts[m_mrCurrentLevel]++ ;
Pierre Kraemer's avatar
Pierre Kraemer committed
100

Pierre Kraemer's avatar
Pierre Kraemer committed
101
		for(unsigned int i = 0; i < m_mrCurrentLevel; ++i)	// for all previous levels
102
			(*m_mrDarts[i])[mrdi] = MRNULL ;					// this MRdart does not exist
Pierre Kraemer's avatar
Pierre Kraemer committed
103

untereiner's avatar
untereiner committed
104 105
		for(unsigned int i = m_mrCurrentLevel; i < m_mrDarts.size(); ++i)	// for all levels from current to max
  			(*m_mrDarts[i])[mrdi] = di ;									// make this MRdart point to the new dart line
106

Pierre Kraemer's avatar
Pierre Kraemer committed
107 108
		return Dart::create(mrdi) ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
109

Pierre Kraemer's avatar
Pierre Kraemer committed
110
	return Dart::create(di) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112 113 114
}

inline void GenericMap::deleteDart(Dart d)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
115 116
	if(m_isMultiRes)
	{
untereiner's avatar
untereiner committed
117
		unsigned int index = (*m_mrDarts[m_mrCurrentLevel])[d.index] ;
118

119
		if(getDartLevel(d) > m_mrCurrentLevel)
120
		{
121 122 123 124 125 126 127 128
			unsigned int di = (*m_mrDarts[m_mrCurrentLevel + 1])[d.index];
			// si le brin de niveau i pointe sur le meme brin que le niveau i-1
			if(di != index)
			{
				if(isDartValid(d))//index))
					deleteDartLine(index) ;
			}

untereiner's avatar
untereiner committed
129 130
			(*m_mrDarts[m_mrCurrentLevel])[d.index] = MRNULL ;
			return;
131
		}
untereiner's avatar
untereiner committed
132

133 134 135
		// a MRdart can only be deleted on its insertion level
		if(getDartLevel(d) == m_mrCurrentLevel)
		{
136 137
			if(isDartValid(d))
			{
138
				deleteDartLine(index) ;
139 140 141
				m_mrattribs.removeLine(d.index);
				m_mrNbDarts[m_mrCurrentLevel]--;
			}
142
		}
untereiner's avatar
untereiner committed
143 144
		else
		{
145
			unsigned int di = (*m_mrDarts[m_mrCurrentLevel - 1])[d.index];
146
			// si le brin de niveau i pointe sur le meme brin que le niveau i-1
untereiner's avatar
untereiner committed
147 148
			if(di != index)
			{
149
				if(isDartValid(d))//index))
untereiner's avatar
untereiner committed
150 151 152
					deleteDartLine(index) ;
			}

153 154 155 156 157
			for(unsigned int i = m_mrCurrentLevel; i <= getMaxLevel(); ++i) // for all levels from current to max
			{
				(*m_mrDarts[i])[d.index] = di ; //copy the index from previous level
			}
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
158 159 160 161 162 163 164 165 166 167
	}
	else
		deleteDartLine(dartIndex(d)) ;
}

inline void GenericMap::deleteDartLine(unsigned int index)
{
	m_attribs[DART].removeLine(index) ;	// free the dart line

	for (unsigned int t = 0; t < m_nbThreads; ++t)	// clear markers of
168
		(*m_markTables[DART][t])[index].clear() ;		// the removed dart
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
169

Pierre Kraemer's avatar
Pierre Kraemer committed
170 171
	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
172
		if (m_embeddings[orbit])									// for each embedded orbit
Pierre Kraemer's avatar
Pierre Kraemer committed
173
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
174
			unsigned int emb = (*m_embeddings[orbit])[index] ;		// get the embedding of the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
175
			if(emb != EMBNULL)
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
176
			{
Pierre Kraemer's avatar
Pierre Kraemer committed
177
				if(m_attribs[orbit].unrefLine(emb))					// unref the pointed embedding line
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
178
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
179
					for (unsigned int t = 0; t < m_nbThreads; ++t)	// and clear its markers if it was
180
						(*m_markTables[orbit][t])[emb].clear() ;	// its last unref (and was thus freed)
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
181 182
				}
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
183 184
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
185
}
Pierre Kraemer's avatar
Pierre Kraemer committed
186

Pierre Kraemer's avatar
Pierre Kraemer committed
187
inline unsigned int GenericMap::copyDartLine(unsigned int index)
Pierre Kraemer's avatar
Pierre Kraemer committed
188
{
189 190
	unsigned int newindex = m_attribs[DART].insertLine() ;	// create a new dart line
	m_attribs[DART].copyLine(newindex, index) ;				// copy the given dart line
Pierre Kraemer's avatar
Pierre Kraemer committed
191 192
	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
193 194 195 196 197 198
		if (m_embeddings[orbit])
		{
			unsigned int emb = (*m_embeddings[orbit])[newindex] ;	// add a ref to the cells pointed
			if(emb != EMBNULL)										// by the new dart line
				m_attribs[orbit].refLine(emb) ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
199 200
	}
	return newindex ;
Pierre Kraemer's avatar
Pierre Kraemer committed
201 202
}

Pierre Kraemer's avatar
Pierre Kraemer committed
203 204
inline void GenericMap::duplicateDart(Dart d)
{
205
	assert(getDartLevel(d) <= m_mrCurrentLevel || !"duplicateDart : called with a dart inserted after current level") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
206

207
	if(getDartLevel(d) == m_mrCurrentLevel)	// no need to duplicate
Pierre Kraemer's avatar
Pierre Kraemer committed
208 209 210 211
		return ;								// a dart from its insertion level

	unsigned int oldindex = dartIndex(d) ;

212 213 214 215 216
	if(m_mrCurrentLevel > 0)
	{
		if((*m_mrDarts[m_mrCurrentLevel - 1])[d.index] != oldindex)	// no need to duplicate if the dart is already
			return ;												// duplicated with respect to previous level
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
217 218 219

	unsigned int newindex = copyDartLine(oldindex) ;

220
	for(unsigned int i = m_mrCurrentLevel; i <= getMaxLevel(); ++i) // for all levels from current to max
Pierre Kraemer's avatar
Pierre Kraemer committed
221 222 223 224 225 226
	{
		assert((*m_mrDarts[i])[d.index] == oldindex || !"duplicateDart : dart was already duplicated on a greater level") ;
		(*m_mrDarts[i])[d.index] = newindex ;						// make this MRdart points to the new dart line
	}
}

untereiner's avatar
untereiner committed
227
inline void GenericMap::duplicateDartAtOneLevel(Dart d, unsigned int level)
228
{
untereiner's avatar
untereiner committed
229
	(*m_mrDarts[level])[d.index] = copyDartLine(dartIndex(d)) ;
230 231
}

untereiner's avatar
untereiner committed
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 267 268 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 295 296 297 298 299 300 301 302 303 304 305 306 307

inline void GenericMap::propagateDartRelation(Dart d, AttributeMultiVector<Dart>* rel)
{
	Dart dd = (*rel)[dartIndex(d)] ;
	pushLevel() ;
	for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i)
	{
		setCurrentLevel(i) ;
		(*rel)[dartIndex(d)] = dd ;
	}
	popLevel() ;
}

inline void GenericMap::propagateDartRelation(Dart d, Dart e, AttributeMultiVector<Dart>* rel)
{
	Dart dd = (*rel)[dartIndex(d)] ;
	pushLevel() ;
	for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i)
	{
		setCurrentLevel(i) ;

		while( (*rel)[dartIndex(d)] != e )
			d = (*rel)[dartIndex(d)];

		if(d != e)
			duplicateDart(d);

		(*rel)[dartIndex(d)] = dd ;
	}
	popLevel() ;
}

inline void GenericMap::propagateDartRelation(Dart d, Dart e, Dart f, AttributeMultiVector<Dart>* rel, AttributeMultiVector<Dart>* rel2)
{
	Dart dd = f ;
	pushLevel() ;
	for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i)
	{
		setCurrentLevel(i) ;

		while( (*rel)[dartIndex(e)] != dd )
			dd = (*rel2)[dartIndex(dd)];

		(*rel)[dartIndex(d)] = dd ;
	}
	popLevel() ;
}

template <unsigned int ORBIT>
inline void GenericMap::propagateDartEmbedding(Dart d)
{
	   unsigned int emb = getEmbedding<ORBIT>(d) ;
	   pushLevel() ;
	   for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i)
	   {
			   setCurrentLevel(i) ;
			   setDartEmbedding<ORBIT>(d, emb) ;
	   }
	   popLevel() ;
}

template <unsigned int ORBIT>
inline void GenericMap::propagateOrbitEmbedding(Dart d)
{
	   unsigned int emb = getEmbedding<ORBIT>(d) ;
	   pushLevel() ;
	   for(unsigned int i = getCurrentLevel() + 1; i <= getMaxLevel(); ++i)
	   {
			   setCurrentLevel(i) ;
			   setOrbitEmbedding<ORBIT>(d, emb) ;
	   }
	   popLevel() ;
}



Sylvain Thery's avatar
Sylvain Thery committed
308
inline unsigned int GenericMap::dartIndex(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
309
{
Pierre Kraemer's avatar
Pierre Kraemer committed
310 311 312 313 314
	if (m_isMultiRes)
		return (*m_mrDarts[m_mrCurrentLevel])[d.index] ;
	return d.index;
}

315 316 317 318 319 320 321 322
inline Dart GenericMap::indexDart(unsigned int index) const
{
	if (m_isMultiRes)
		return Dart( (*m_mrDarts[m_mrCurrentLevel])[index]) ;
	return Dart(index);
}


323
inline unsigned int GenericMap::getDartLevel(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
324 325 326 327
{
	return (*m_mrLevels)[d.index] ;
}

328 329
inline void GenericMap::incDartLevel(Dart d) const
{
330
	++((*m_mrLevels)[d.index]) ;
331 332 333
}


Pierre Kraemer's avatar
Pierre Kraemer committed
334 335 336 337 338 339 340 341 342 343 344
inline unsigned int GenericMap::getNbInsertedDarts(unsigned int level)
{
	if(level < m_mrDarts.size())
		return m_mrNbDarts[level] ;
	else
		return 0 ;
}

inline unsigned int GenericMap::getNbDarts(unsigned int level)
{
	if(level < m_mrDarts.size())
Pierre Kraemer's avatar
Pierre Kraemer committed
345
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
346 347 348 349
		unsigned int nb = 0 ;
		for(unsigned int i = 0; i <= level; ++i)
			nb += m_mrNbDarts[i] ;
		return nb ;
Pierre Kraemer's avatar
Pierre Kraemer committed
350
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
351 352 353 354 355 356 357 358 359
	else
		return 0 ;
}

inline unsigned int GenericMap::getNbDarts()
{
	if(m_isMultiRes)
		return getNbDarts(m_mrCurrentLevel) ;

360
	return m_attribs[DART].size() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
361 362
}

Pierre Kraemer's avatar
Pierre Kraemer committed
363 364 365 366 367
inline bool GenericMap::isDartValid(Dart d)
{
	return !d.isNil() && m_attribs[DART].used(dartIndex(d)) ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
368 369 370 371
/****************************************
 *         EMBEDDING MANAGEMENT         *
 ****************************************/

372 373
template <unsigned int ORBIT>
inline bool GenericMap::isOrbitEmbedded() const
Pierre Kraemer's avatar
Pierre Kraemer committed
374
{
375
	return (ORBIT == DART) || (m_embeddings[ORBIT] != NULL) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
376 377
}

378
inline bool GenericMap::isOrbitEmbedded(unsigned int orbit) const
Pierre Kraemer's avatar
Pierre Kraemer committed
379
{
380
	return (orbit == DART) || (m_embeddings[orbit] != NULL) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
381 382
}

383
template <unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
384
inline unsigned int GenericMap::getEmbedding(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
385
{
386
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
Pierre Kraemer's avatar
Pierre Kraemer committed
387

388 389
	unsigned int d_index = dartIndex(d);

390
	if (ORBIT == DART)
391
		return d_index;
Pierre Kraemer's avatar
Pierre Kraemer committed
392

393
	return (*m_embeddings[ORBIT])[d_index] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
394 395
}

396 397 398
template <unsigned int ORBIT>
void GenericMap::setDartEmbedding(Dart d, unsigned int emb)
{
399
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417

	unsigned int old = getEmbedding<ORBIT>(d);

	if (old == emb)	// if same emb
		return;		// nothing to do

	if (old != EMBNULL)	// if different
	{
		if(m_attribs[ORBIT].unrefLine(old))	// then unref the old emb
		{
			for (unsigned int t = 0; t < m_nbThreads; ++t)	// clear the markers if it was the
				(*m_markTables[ORBIT][t])[old].clear();		// last unref of the line
		}
	}

	if (emb != EMBNULL)
		m_attribs[ORBIT].refLine(emb);	// ref the new emb

Pierre Kraemer's avatar
Pierre Kraemer committed
418
	(*m_embeddings[ORBIT])[dartIndex(d)] = emb ; // finally affect the embedding to the dart
419 420
}

421 422 423 424
template <unsigned int ORBIT>
void GenericMap::initDartEmbedding(Dart d, unsigned int emb)
{
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
Pierre Kraemer's avatar
Pierre Kraemer committed
425
	assert(getEmbedding<ORBIT>(d) == EMBNULL || !"initDartEmbedding called on already embedded dart");
426 427
	if(emb != EMBNULL)
		m_attribs[ORBIT].refLine(emb);	// ref the new emb
428 429 430
	(*m_embeddings[ORBIT])[dartIndex(d)] = emb ; // affect the embedding to the dart
}

431 432
template <unsigned int ORBIT>
inline void GenericMap::copyDartEmbedding(Dart dest, Dart src)
Pierre Kraemer's avatar
Pierre Kraemer committed
433
{
434
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
435
	setDartEmbedding<ORBIT>(dest, getEmbedding<ORBIT>(src));
Pierre Kraemer's avatar
Pierre Kraemer committed
436 437
}

438 439
template <unsigned int ORBIT>
inline unsigned int GenericMap::newCell()
Pierre Kraemer's avatar
Pierre Kraemer committed
440
{
441
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
442
	return m_attribs[ORBIT].insertLine();
Pierre Kraemer's avatar
Pierre Kraemer committed
443 444
}

445
template <unsigned int ORBIT>
446
inline void GenericMap::setOrbitEmbedding(Dart d, unsigned int em)
Pierre Kraemer's avatar
Pierre Kraemer committed
447
{
448
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
449 450
	FunctorSetEmb<GenericMap, ORBIT> fsetemb(*this, em);
	foreach_dart_of_orbit<ORBIT>(d, fsetemb);
Pierre Kraemer's avatar
Pierre Kraemer committed
451 452
}

453
template <unsigned int ORBIT>
454 455 456 457 458 459 460 461
inline void GenericMap::initOrbitEmbedding(Dart d, unsigned int em)
{
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
	FunctorInitEmb<GenericMap, ORBIT> fsetemb(*this, em);
	foreach_dart_of_orbit<ORBIT>(d, fsetemb);
}

template <unsigned int ORBIT>
462
inline unsigned int GenericMap::setOrbitEmbeddingOnNewCell(Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
463
{
464
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
465
	unsigned int em = newCell<ORBIT>();
466 467 468 469 470 471 472 473 474 475
	setOrbitEmbedding<ORBIT>(d, em);
	return em;
}

template <unsigned int ORBIT>
inline unsigned int GenericMap::initOrbitEmbeddingNewCell(Dart d)
{
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
	unsigned int em = newCell<ORBIT>();
	initOrbitEmbedding<ORBIT>(d, em);
Pierre Kraemer's avatar
Pierre Kraemer committed
476 477 478
	return em;
}

479 480
template <unsigned int ORBIT>
inline void GenericMap::copyCell(Dart d, Dart e)
Pierre Kraemer's avatar
Pierre Kraemer committed
481
{
482
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
483 484
	unsigned int dE = getEmbedding<ORBIT>(d) ;
	unsigned int eE = getEmbedding<ORBIT>(e) ;
485 486 487 488
	if(eE != EMBNULL)	// if the source is NULL, nothing to copy
	{
		if(dE == EMBNULL)	// if the dest is NULL, create a new cell
			dE = setOrbitEmbeddingOnNewCell<ORBIT>(d) ;
489
		m_attribs[ORBIT].copyLine(dE, eE) ;	// copy the data
490
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
491 492
}

493 494
template <unsigned int ORBIT>
inline void GenericMap::copyCell(unsigned int i, unsigned int j)
Pierre Kraemer's avatar
Pierre Kraemer committed
495
{
496
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
497
	m_attribs[ORBIT].copyLine(i, j) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
498 499
}

500 501
template <unsigned int ORBIT>
inline void GenericMap::initCell(unsigned int i)
Pierre Kraemer's avatar
Pierre Kraemer committed
502
{
503
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
504
	m_attribs[ORBIT].initLine(i) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
505 506
}

507 508 509 510

template <unsigned int ORBIT>
void GenericMap::initAllOrbitsEmbedding(bool realloc)
{
511 512
	if(!isOrbitEmbedded<ORBIT>())
		addEmbedding<ORBIT>() ;
513 514 515 516 517 518 519 520 521 522 523 524
	DartMarker mark(*this) ;
	for(Dart d = begin(); d != end(); next(d))
	{
		if(!mark.isMarked(d))
		{
			mark.markOrbit<ORBIT>(d) ;
			if(realloc || getEmbedding<ORBIT>(d) == EMBNULL)
				setOrbitEmbeddingOnNewCell<ORBIT>(d) ;
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
525 526 527 528 529 530 531
/****************************************
 *     QUICK TRAVERSAL MANAGEMENT       *
 ****************************************/

template <unsigned int ORBIT>
inline void GenericMap::enableQuickTraversal()
{
Sylvain Thery's avatar
Sylvain Thery committed
532

Pierre Kraemer's avatar
Pierre Kraemer committed
533 534 535 536 537 538 539 540 541 542
	if(m_quickTraversal[ORBIT] == NULL)
	{
		if(!isOrbitEmbedded<ORBIT>())
			addEmbedding<ORBIT>() ;
		m_quickTraversal[ORBIT] = m_attribs[ORBIT].addAttribute<Dart>("quick_traversal") ;
	}
	updateQuickTraversal<ORBIT>() ;
}

template <unsigned int ORBIT>
543
inline void GenericMap::updateQuickTraversal()
Pierre Kraemer's avatar
Pierre Kraemer committed
544
{
Pierre Kraemer's avatar
Pierre Kraemer committed
545 546
	assert(m_quickTraversal[ORBIT] != NULL || !"updateQuickTraversal on a disabled orbit") ;

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
//	CellMarker<ORBIT> cm(*this) ;
//	for(Dart d = begin(); d != end(); next(d))
//	{
//		if ((!cm.isMarked(d)) && (!isBoundaryMarkedCurrent(d)))
//		{
//			cm.mark(d) ;
//			(*m_quickTraversal[ORBIT])[getEmbedding<ORBIT>(d)] = d ;
//		}
//	}

	// ensure that we do not try to use quick traversal in Traversors
	AttributeMultiVector<Dart>* qt = m_quickTraversal[ORBIT];
	m_quickTraversal[ORBIT] = NULL;

	// fill the quick travsersal
	TraversorCell<GenericMap,VOLUME> trav(*this);
	for(Dart d = trav.begin(); d != trav.end(); d=trav.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
564
	{
565
		(*qt)[getEmbedding<ORBIT>(d)] = d ;
Pierre Kraemer's avatar
Pierre Kraemer committed
566
	}
567 568 569 570

	// restore ptr
	m_quickTraversal[ORBIT] = qt;

Pierre Kraemer's avatar
Pierre Kraemer committed
571 572 573
}

template <unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
574
inline const AttributeMultiVector<Dart>* GenericMap::getQuickTraversal() const
Pierre Kraemer's avatar
Pierre Kraemer committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588
{
	return m_quickTraversal[ORBIT] ;
}

template <unsigned int ORBIT>
inline void GenericMap::disableQuickTraversal()
{
	if(m_quickTraversal[ORBIT] != NULL)
	{
		m_attribs[ORBIT].removeAttribute<Dart>(m_quickTraversal[ORBIT]->getIndex()) ;
		m_quickTraversal[ORBIT] = NULL ;
	}
}

Sylvain Thery's avatar
Sylvain Thery committed
589 590

template <typename MAP, unsigned int ORBIT, unsigned int INCI>
Sylvain Thery's avatar
Sylvain Thery committed
591
inline void GenericMap::enableQuickIncidentTraversal()
Sylvain Thery's avatar
Sylvain Thery committed
592 593 594 595 596 597 598 599 600
{
	if(m_quickLocalIncidentTraversal[ORBIT][INCI] == NULL)
	{
		if(!isOrbitEmbedded<ORBIT>())
			addEmbedding<ORBIT>() ;
		std::stringstream ss;
		ss << "quickLocalIncidentTraversal_" << INCI;
		m_quickLocalIncidentTraversal[ORBIT][INCI] = m_attribs[ORBIT].addAttribute<NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
	}
Sylvain Thery's avatar
Sylvain Thery committed
601
	updateQuickIncidentTraversal<MAP,ORBIT,INCI>() ;
Sylvain Thery's avatar
Sylvain Thery committed
602 603 604
}

template <typename MAP, unsigned int ORBIT, unsigned int INCI>
Sylvain Thery's avatar
Sylvain Thery committed
605
inline void GenericMap::updateQuickIncidentTraversal()
Sylvain Thery's avatar
Sylvain Thery committed
606 607 608 609 610 611 612 613 614
{
	assert(m_quickLocalIncidentTraversal[ORBIT][INCI] != NULL || !"updateQuickTraversal on a disabled orbit") ;

	AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* ptrVD = m_quickLocalIncidentTraversal[ORBIT][INCI];
	m_quickLocalIncidentTraversal[ORBIT][INCI] = NULL;

	std::vector<Dart> buffer;
	buffer.reserve(100);

Sylvain Thery's avatar
Sylvain Thery committed
615 616
	MAP& map = static_cast<MAP&>(*this);

Sylvain Thery's avatar
Sylvain Thery committed
617 618 619 620
	TraversorCell<MAP,ORBIT> tra_glob(map);
	for (Dart d = tra_glob.begin(); d != tra_glob.end(); d = tra_glob.next())
	{
		buffer.clear();
Sylvain Thery's avatar
Sylvain Thery committed
621
		Traversor* tra_loc = TraversorFactory<MAP>::createIncident(map, d, map.dimension(), ORBIT, INCI);
Sylvain Thery's avatar
Sylvain Thery committed
622
		for (Dart e = tra_loc->begin(); e != tra_loc->end(); e = tra_loc->next())
Sylvain Thery's avatar
Sylvain Thery committed
623
			buffer.push_back(e);
Sylvain Thery's avatar
Sylvain Thery committed
624
		delete tra_loc;
Sylvain Thery's avatar
Sylvain Thery committed
625 626 627 628 629 630 631 632 633
		buffer.push_back(NIL);
		std::vector<Dart>& vd = (*ptrVD)[getEmbedding<ORBIT>(d)];
		vd.reserve(buffer.size());
		vd.assign(buffer.begin(),buffer.end());
	}
	m_quickLocalIncidentTraversal[ORBIT][INCI] = ptrVD;
}

template <unsigned int ORBIT, unsigned int INCI>
Sylvain Thery's avatar
Sylvain Thery committed
634
inline const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* GenericMap::getQuickIncidentTraversal() const
Sylvain Thery's avatar
Sylvain Thery committed
635 636 637 638 639
{
	return m_quickLocalIncidentTraversal[ORBIT][INCI] ;
}

template <unsigned int ORBIT, unsigned int INCI>
Sylvain Thery's avatar
Sylvain Thery committed
640
inline void GenericMap::disableQuickIncidentTraversal()
Sylvain Thery's avatar
Sylvain Thery committed
641 642 643 644 645 646 647 648 649 650 651
{
	if(m_quickLocalIncidentTraversal[ORBIT][INCI] != NULL)
	{
		m_attribs[ORBIT].removeAttribute<Dart>(m_quickLocalIncidentTraversal[ORBIT][INCI]->getIndex()) ;
		m_quickLocalIncidentTraversal[ORBIT][INCI] = NULL ;
	}
}



template <typename MAP, unsigned int ORBIT, unsigned int ADJ>
Sylvain Thery's avatar
Sylvain Thery committed
652
inline void GenericMap::enableQuickAdjacentTraversal()
Sylvain Thery's avatar
Sylvain Thery committed
653 654 655 656 657 658
{
	if(m_quickLocalAdjacentTraversal[ORBIT][ADJ] == NULL)
	{
		if(!isOrbitEmbedded<ORBIT>())
			addEmbedding<ORBIT>() ;
		std::stringstream ss;
Sylvain Thery's avatar
Sylvain Thery committed
659
		ss << "quickLocalAdjacentTraversal" << ADJ;
Sylvain Thery's avatar
Sylvain Thery committed
660 661
		m_quickLocalAdjacentTraversal[ORBIT][ADJ] = m_attribs[ORBIT].addAttribute<NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
	}
Sylvain Thery's avatar
Sylvain Thery committed
662
	updateQuickAdjacentTraversal<MAP,ORBIT,ADJ>() ;
Sylvain Thery's avatar
Sylvain Thery committed
663 664 665
}

template <typename MAP, unsigned int ORBIT, unsigned int ADJ>
Sylvain Thery's avatar
Sylvain Thery committed
666
inline void GenericMap::updateQuickAdjacentTraversal()
Sylvain Thery's avatar
Sylvain Thery committed
667 668 669 670 671 672
{
	assert(m_quickLocalAdjacentTraversal[ORBIT][ADJ] != NULL || !"updateQuickTraversal on a disabled orbit") ;

	AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* ptrVD = m_quickLocalAdjacentTraversal[ORBIT][ADJ];
	m_quickLocalAdjacentTraversal[ORBIT][ADJ] = NULL;

Sylvain Thery's avatar
Sylvain Thery committed
673 674
	MAP& map = static_cast<MAP&>(*this);

Sylvain Thery's avatar
Sylvain Thery committed
675 676 677 678 679 680 681
	std::vector<Dart> buffer;
	buffer.reserve(100);

	TraversorCell<MAP,ORBIT> tra_glob(map);
	for (Dart d = tra_glob.begin(); d != tra_glob.end(); d = tra_glob.next())
	{
		buffer.clear();
Sylvain Thery's avatar
Sylvain Thery committed
682
		Traversor* tra_loc = TraversorFactory<MAP>::createAdjacent(map, d, map.dimension(), ORBIT, ADJ);
Sylvain Thery's avatar
Sylvain Thery committed
683
		for (Dart e = tra_loc->begin(); e != tra_loc->end(); e = tra_loc->next())
Sylvain Thery's avatar
Sylvain Thery committed
684 685
			buffer.push_back(e);
		buffer.push_back(NIL);
Sylvain Thery's avatar
Sylvain Thery committed
686
		delete tra_loc;
Sylvain Thery's avatar
Sylvain Thery committed
687 688 689 690 691 692 693
		std::vector<Dart>& vd = (*ptrVD)[getEmbedding<ORBIT>(d)];
		vd.reserve(buffer.size());
		vd.assign(buffer.begin(),buffer.end());
	}
	m_quickLocalAdjacentTraversal[ORBIT][ADJ] = ptrVD;
}

Sylvain Thery's avatar
Sylvain Thery committed
694
template <unsigned int ORBIT, unsigned int ADJ>
Sylvain Thery's avatar
Sylvain Thery committed
695
inline const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* GenericMap::getQuickAdjacentTraversal() const
Sylvain Thery's avatar
Sylvain Thery committed
696
{
Sylvain Thery's avatar
Sylvain Thery committed
697
	return m_quickLocalAdjacentTraversal[ORBIT][ADJ] ;
Sylvain Thery's avatar
Sylvain Thery committed
698 699 700
}

template <unsigned int ORBIT, unsigned int ADJ>
Sylvain Thery's avatar
Sylvain Thery committed
701
inline void GenericMap::disableQuickAdjacentTraversal()
Sylvain Thery's avatar
Sylvain Thery committed
702 703 704 705 706 707 708 709 710 711 712
{
	if(m_quickLocalAdjacentTraversal[ORBIT][ADJ] != NULL)
	{
		m_attribs[ORBIT].removeAttribute<Dart>(m_quickLocalAdjacentTraversal[ORBIT][ADJ]->getIndex()) ;
		m_quickLocalAdjacentTraversal[ORBIT][ADJ] = NULL ;
	}
}




Pierre Kraemer's avatar
Pierre Kraemer committed
713 714 715 716
/****************************************
 *        ATTRIBUTES MANAGEMENT         *
 ****************************************/

717 718 719 720 721
inline unsigned int GenericMap::getNbCells(unsigned int orbit)
{
	return m_attribs[orbit].size() ;
}

722 723
template <unsigned int ORBIT>
inline AttributeContainer& GenericMap::getAttributeContainer()
Pierre Kraemer's avatar
Pierre Kraemer committed
724
{
725
	return m_attribs[ORBIT] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
726 727
}

Sylvain Thery's avatar
Sylvain Thery committed
728 729 730 731 732 733
template <unsigned int ORBIT>
inline const AttributeContainer& GenericMap::getAttributeContainer() const
{
	return m_attribs[ORBIT] ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
734 735 736 737 738
inline AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit)
{
	return m_attribs[orbit] ;
}

Sylvain Thery's avatar
Sylvain Thery committed
739 740 741 742 743 744
inline const AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit) const
{
	return m_attribs[orbit] ;
}


745 746
template <unsigned int ORBIT>
inline AttributeMultiVector<Mark>* GenericMap::getMarkVector(unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
747
{
748
	assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded") ;
749
	return m_markTables[ORBIT][thread] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
750 751
}

752 753
template <unsigned int ORBIT>
inline AttributeMultiVector<unsigned int>* GenericMap::getEmbeddingAttributeVector()
Pierre Kraemer's avatar
Pierre Kraemer committed
754
{
755
	return m_embeddings[ORBIT] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
756 757
}

758 759 760 761 762 763 764 765 766 767 768
inline AttributeContainer& GenericMap::getMRAttributeContainer()
{
	return m_mrattribs ;
}

inline AttributeMultiVector<unsigned int>* GenericMap::getMRDartAttributeVector(unsigned int level)
{
	assert(level <= getMaxLevel() || !"Invalid parameter: level does not exist");
	return m_mrDarts[level] ;
}

untereiner's avatar
untereiner committed
769 770 771 772 773
inline AttributeMultiVector<unsigned int>* GenericMap::getMRLevelAttributeVector()
{
	return m_mrLevels ;
}

774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
template <typename R>
bool GenericMap::registerAttribute(const std::string &nameType)
{
	RegisteredBaseAttribute* ra = new RegisteredAttribute<R>;
	if (ra == NULL)
	{
		CGoGNerr << "Erreur enregistrement attribut" << CGoGNendl;
		return false;
	}

	ra->setTypeName(nameType);

	m_attributes_registry_map->insert(std::pair<std::string, RegisteredBaseAttribute*>(nameType,ra));
	return true;
}

790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
/****************************************
 *   EMBEDDING ATTRIBUTES MANAGEMENT    *
 ****************************************/

template <unsigned int ORBIT>
void GenericMap::addEmbedding()
{
	assert(!isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit already embedded") ;

	std::ostringstream oss;
	oss << "EMB_" << ORBIT;

	AttributeContainer& dartCont = m_attribs[DART] ;
	AttributeMultiVector<unsigned int>* amv = dartCont.addAttribute<unsigned int>(oss.str()) ;
	m_embeddings[ORBIT] = amv ;

806 807 808
	// set new embedding to EMBNULL for all the darts of the map
	for(unsigned int i = dartCont.begin(); i < dartCont.end(); dartCont.next(i))
		(*amv)[i] = EMBNULL ;
809 810
}

Pierre Kraemer's avatar
Pierre Kraemer committed
811 812 813 814
/****************************************
 *           DARTS TRAVERSALS           *
 ****************************************/

815 816
//inline Dart GenericMap::realBegin() const
inline Dart GenericMap::begin() const
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
{
	if (m_isMultiRes)
	{
		unsigned int d = m_mrattribs.begin() ;
		if(d != m_mrattribs.end())
		{
			while (getDartLevel(d) > m_mrCurrentLevel)
				m_mrattribs.next(d) ;
		}
		return Dart::create(d) ;
	}

	return Dart::create(m_attribs[DART].begin()) ;
}

832 833
//inline Dart GenericMap::realEnd() const
inline Dart GenericMap::end() const
834 835 836 837 838 839 840
{
	if (m_isMultiRes)
		return Dart::create(m_mrattribs.end()) ;

	return Dart::create(m_attribs[DART].end()) ;
}

841 842
//inline void GenericMap::realNext(Dart& d) const
inline void GenericMap::next(Dart& d) const
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
{
	if (m_isMultiRes)
	{
		do
		{
			m_mrattribs.next(d.index) ;
		} while (d.index != m_mrattribs.end() && getDartLevel(d) > m_mrCurrentLevel) ;
	}
	else
	{
		m_attribs[DART].next(d.index) ;
	}
}


858 859 860 861 862 863
//inline Dart GenericMap::begin() const
//{
//	if (m_currentBrowser != NULL)
//		return m_currentBrowser->begin();
//	return GenericMap::realBegin();
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
864

865 866 867 868 869 870
//inline Dart GenericMap::end() const
//{
//	if (m_currentBrowser != NULL)
//		return m_currentBrowser->end();
//	return GenericMap::realEnd();
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
871

872 873 874 875 876 877 878
//inline void GenericMap::next(Dart& d) const
//{
//	if (m_currentBrowser != NULL)
//		m_currentBrowser->next(d);
//	else
//		realNext(d);
//}
Sylvain Thery's avatar
Sylvain Thery committed
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927

//inline Dart GenericMap::begin() const
//{
//	if (m_isMultiRes)
//	{
//		unsigned int d = m_mrattribs.begin() ;
//		if(d != m_mrattribs.end())
//		{
//			while (getDartLevel(d) > m_mrCurrentLevel)
//				m_mrattribs.next(d) ;
//		}
//		return Dart::create(d) ;
//	}


//	if (m_currentBrowser != NULL)
//		return m_currentBrowser->begin();

//	return Dart::create(m_attribs[DART].begin()) ;
//}

//inline Dart GenericMap::end() const
//{
//	if (m_isMultiRes)
//		return Dart::create(m_mrattribs.end()) ;

//	if (m_currentBrowser != NULL)
//		return m_currentBrowser->end();

//	return Dart::create(m_attribs[DART].end()) ;
//}

//inline void GenericMap::next(Dart& d) const
//{
//	if (m_isMultiRes)
//	{
//		do
//		{
//			m_mrattribs.next(d.index) ;
//		} while (d.index != m_mrattribs.end() && getDartLevel(d) > m_mrCurrentLevel) ;
//	}
//	else
//	{
//		if (m_currentBrowser != NULL)
//			return m_currentBrowser->next(d);
//		else
//			m_attribs[DART].next(d.index) ;
//	}
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
928

929
template <unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
930
bool GenericMap::foreach_dart_of_orbit(Dart d, FunctorType& f, unsigned int thread) const
931 932 933 934 935 936 937 938 939 940 941 942 943
{
	switch(ORBIT)
	{
		case DART:		return f(d);
		case VERTEX: 	return foreach_dart_of_vertex(d, f, thread);
		case EDGE: 		return foreach_dart_of_edge(d, f, thread);
		case FACE: 		return foreach_dart_of_face(d, f, thread);
		case VOLUME: 	return foreach_dart_of_volume(d, f, thread);
		case VERTEX1: 	return foreach_dart_of_vertex1(d, f, thread);
		case EDGE1: 	return foreach_dart_of_edge1(d, f, thread);
		case VERTEX2: 	return foreach_dart_of_vertex2(d, f, thread);
		case EDGE2:		return foreach_dart_of_edge2(d, f, thread);
		case FACE2:		return foreach_dart_of_face2(d, f, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
944
		default: 		assert(!"Cells of this dimension are not handled"); break;
945 946 947 948
	}
	return false;
}

Sylvain Thery's avatar
Sylvain Thery committed
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
//template <unsigned int ORBIT>
//bool GenericMap::foreach_dart_of_orbit(Dart d, FunctorConstType& f, unsigned int thread) const
//{
//	switch(ORBIT)
//	{
//		case DART:		return f(d);
//		case VERTEX: 	return foreach_dart_of_vertex(d, f, thread);
//		case EDGE: 		return foreach_dart_of_edge(d, f, thread);
//		case FACE: 		return foreach_dart_of_face(d, f, thread);
//		case VOLUME: 	return foreach_dart_of_volume(d, f, thread);
//		case VERTEX1: 	return foreach_dart_of_vertex1(d, f, thread);
//		case EDGE1: 	return foreach_dart_of_edge1(d, f, thread);
//		case VERTEX2: 	return foreach_dart_of_vertex2(d, f, thread);
//		case EDGE2:		return foreach_dart_of_edge2(d, f, thread);
//		case FACE2:		return foreach_dart_of_face2(d, f, thread);
//		default: 		assert(!"Cells of this dimension are not handled"); break;
//	}
//	return false;
//}

969
template <unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
970
bool GenericMap::foreach_orbit(FunctorType& fonct, unsigned int thread) const
971
{
972
	TraversorCell<GenericMap, ORBIT> trav(*this, true, thread);
973 974 975 976 977 978 979 980 981 982
	bool found = false;

	for (Dart d = trav.begin(); !found && d != trav.end(); d = trav.next())
	{
		if ((fonct)(d))
			found = true;
	}
	return found;
}

Sylvain Thery's avatar
Sylvain Thery committed
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997

//template <unsigned int ORBIT>
//bool GenericMap::foreach_orbit(FunctorConstType& fonct, unsigned int thread) const
//{
//	TraversorCell<GenericMap, ORBIT> trav(*this, true, thread);
//	bool found = false;

//	for (Dart d = trav.begin(); !found && d != trav.end(); d = trav.next())
//	{
//		if ((fonct)(d))
//			found = true;
//	}
//	return found;
//}

998
template <unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
999
unsigned int GenericMap::getNbOrbits() const
1000 1001
{
	FunctorCount fcount;
1002
	foreach_orbit<ORBIT>(fcount);
1003 1004 1005
	return fcount.getNb();
}

1006
template <typename MAP, unsigned int ORBIT, unsigned int INCIDENT>
Sylvain Thery's avatar
Sylvain Thery committed
1007
unsigned int GenericMap::degree(Dart d) const
1008
{
1009
	assert(ORBIT != INCIDENT || !"degree does not manage adjacency counting") ;
Sylvain Thery's avatar
Sylvain Thery committed
1010
	Traversor* t = TraversorFactory<MAP>::createIncident(*(reinterpret_cast<MAP*>(this)), d, dimension(), ORBIT, INCIDENT) ;
1011 1012
	FunctorCount fcount ;
	t->applyFunctor(fcount) ;
1013
	delete t ;
1014 1015 1016
	return fcount.getNb() ;
}

1017

Thery Sylvain's avatar
Thery Sylvain committed
1018

1019

Sylvain Thery's avatar
Sylvain Thery committed
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
/****************************************
 *  TOPOLOGICAL ATTRIBUTES MANAGEMENT   *
 ****************************************/

inline AttributeMultiVector<Dart>* GenericMap::addRelation(const std::string& name)
{
	AttributeContainer& cont = m_attribs[DART] ;
	AttributeMultiVector<Dart>* amv = cont.addAttribute<Dart>(name) ;

	// set new relation to fix point for all the darts of the map
	for(unsigned int i = cont.begin(); i < cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
1031
		(*amv)[i] = i ;
Sylvain Thery's avatar
Sylvain Thery committed
1032 1033 1034 1035

	return amv ;
}

Sylvain Thery's avatar
Sylvain Thery committed
1036 1037 1038 1039 1040 1041 1042
inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& name)
{
	AttributeContainer& cont = m_attribs[DART] ;
	AttributeMultiVector<Dart>* amv = cont.getDataVector<Dart>(cont.getAttributeIndex(name)) ;
	return amv ;
}

Sylvain Thery's avatar
Sylvain Thery committed
1043 1044 1045 1046 1047

/**************************
 *  BOUNDARY MANAGEMENT   *
 **************************/

Thery Sylvain's avatar
Thery Sylvain committed
1048
template <unsigned int D>
Sylvain Thery's avatar
Sylvain Thery committed
1049 1050
inline void GenericMap::boundaryMark(Dart d)
{
Thery Sylvain's avatar
Thery Sylvain committed
1051
	m_markTables[DART][0]->operator[](dartIndex(d)).setMark(m_boundaryMarkers[D-2]);
Sylvain Thery's avatar
Sylvain Thery committed
1052 1053
}

Thery Sylvain's avatar
Thery Sylvain committed
1054
template <unsigned int D>
Sylvain Thery's avatar
Sylvain Thery committed
1055 1056
inline void GenericMap::boundaryUnmark(Dart d)
{
Thery Sylvain's avatar
Thery Sylvain committed
1057
	m_markTables[DART][0]->operator[](dartIndex(d)).unsetMark(m_boundaryMarkers[D-2]);
Sylvain Thery's avatar
Sylvain Thery committed
1058 1059
}

Thery Sylvain's avatar
Thery Sylvain committed
1060
template <unsigned int D>
Sylvain Thery's avatar
Sylvain Thery committed
1061 1062
inline bool GenericMap::isBoundaryMarked(Dart d) const
{
Thery Sylvain's avatar
Thery Sylvain committed
1063 1064 1065 1066
	return m_markTables[DART][0]->operator[](dartIndex(d)).testMark(m_boundaryMarkers[D-2]);
}


1067 1068 1069 1070 1071 1072
inline bool GenericMap::isBoundaryMarkedCurrent(Dart d) const
{
	return m_markTables[DART][0]->operator[](dartIndex(d)).testMark(m_boundaryMarkers[this->dimension()-2]);
}


Thery Sylvain's avatar
Thery Sylvain committed
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
inline void GenericMap::boundaryMark2(Dart d)
{
	boundaryMark<2>(d);
}

inline void GenericMap::boundaryUnmark2(Dart d)
{
	boundaryUnmark<2>(d);
}

inline bool GenericMap::isBoundaryMarked2(Dart d) const
{
	return isBoundaryMarked<2>(d);
}

inline void GenericMap::boundaryMark3(Dart d)
{
	boundaryMark<3>(d);
}

inline void GenericMap::boundaryUnmark3(Dart d)
{
	boundaryUnmark<3>(d);
}

inline bool GenericMap::isBoundaryMarked3(Dart d) const
{
	return isBoundaryMarked<3>(d);
}

template <unsigned int ORBIT, unsigned int  DIM>
void GenericMap::boundaryMarkOrbit(Dart d)
{
	FunctorMark<GenericMap> fm(*this, m_boundaryMarkers[DIM-2], m_markTables[DART][0]) ;
	foreach_dart_of_orbit<ORBIT>(d, fm, 0) ;
}

template <unsigned int ORBIT, unsigned int DIM>
void GenericMap::boundaryUnmarkOrbit(Dart d)
{
	FunctorUnmark<GenericMap> fm(*this, m_boundaryMarkers[DIM-2], m_markTables[DART][0]) ;
	foreach_dart_of_orbit<ORBIT>(d, fm, 0) ;
}

template <unsigned int DIM>
void GenericMap::boundaryUnmarkAll()
{
	AttributeContainer& cont = getAttributeContainer<DART>() ;
	for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Thery Sylvain's avatar
Thery Sylvain committed
1122
		m_markTables[DART][0]->operator[](i).unsetMark(m_boundaryMarkers[DIM-2]);
Sylvain Thery's avatar
Sylvain Thery committed
1123 1124
}

Thery Sylvain's avatar
Thery Sylvain committed
1125

Pierre Kraemer's avatar
Pierre Kraemer committed
1126
} //namespace CGoGN