mapCommon.hpp 21.1 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

/****************************************
 *           DARTS TRAVERSALS           *
 ****************************************/

template <typename MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
33
template <unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
34 35
bool MapCommon<MAP_IMPL>::foreach_orbit(FunctorType& fonct, unsigned int thread)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
36
	TraversorCell<MapCommon<MAP_IMPL>, ORBIT> trav(*this, true, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
37 38 39 40 41 42 43 44 45 46 47
	bool found = false;

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

template <typename MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
template <unsigned int ORBIT>
unsigned int MapCommon<MAP_IMPL>::getNbOrbits() const
{
	unsigned int cpt = 0;
	TraversorCell<MapCommon<MAP_IMPL>, ORBIT> trav(*this, true);
	for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
	{
		++cpt;
	}
	return cpt;
}

template <typename MAP_IMPL>
unsigned int MapCommon<MAP_IMPL>::getNbOrbits(unsigned int orbit) const
Pierre Kraemer's avatar
Pierre Kraemer committed
62
{
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
	switch(orbit)
	{
		case DART:		return getNbOrbits<DART>();
		case VERTEX: 	return getNbOrbits<VERTEX>();
		case EDGE: 		return getNbOrbits<EDGE>();
		case FACE: 		return getNbOrbits<FACE>();
		case VOLUME: 	return getNbOrbits<VOLUME>();
		case VERTEX1: 	return getNbOrbits<VERTEX1>();
		case EDGE1: 	return getNbOrbits<EDGE1>();
		case VERTEX2: 	return getNbOrbits<VERTEX2>();
		case EDGE2:		return getNbOrbits<EDGE2>();
		case FACE2:		return getNbOrbits<FACE2>();
		default: 		assert(!"Cells of this dimension are not handled"); break;
	}
	return 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
78 79 80 81 82 83 84
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int INCIDENT>
unsigned int MapCommon<MAP_IMPL>::degree(Dart d) const
{
	assert(ORBIT != INCIDENT || !"degree does not manage adjacency counting") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
85
	Traversor* t = TraversorFactory<MapCommon<MAP_IMPL> >::createIncident(*this, d, this->dimension(), ORBIT, INCIDENT) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
	FunctorCount fcount ;
	t->applyFunctor(fcount) ;
	delete t ;
	return fcount.getNb() ;
}

/****************************************
 *         EMBEDDING MANAGEMENT         *
 ****************************************/

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline unsigned int MapCommon<MAP_IMPL>::getEmbedding(Dart d) const
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");

	unsigned int d_index = this->dartIndex(d);

	if (ORBIT == DART)
		return d_index;

	return (*this->m_embeddings[ORBIT])[d_index] ;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
void MapCommon<MAP_IMPL>::setDartEmbedding(Dart d, unsigned int emb)
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");

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

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

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

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

	(*this->m_embeddings[ORBIT])[this->dartIndex(d)] = emb ; // finally affect the embedding to the dart
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
void MapCommon<MAP_IMPL>::initDartEmbedding(Dart d, unsigned int emb)
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
	assert(getEmbedding<ORBIT>(d) == EMBNULL || !"initDartEmbedding called on already embedded dart");

	if(emb != EMBNULL)
		this->m_attribs[ORBIT].refLine(emb);	// ref the new emb
	(*this->m_embeddings[ORBIT])[this->dartIndex(d)] = emb ; // affect the embedding to the dart
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline void MapCommon<MAP_IMPL>::copyDartEmbedding(Dart dest, Dart src)
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");

	setDartEmbedding<ORBIT>(dest, getEmbedding<ORBIT>(src));
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline void MapCommon<MAP_IMPL>::setOrbitEmbedding(Dart d, unsigned int em)
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");

	FunctorSetEmb<MapCommon<MAP_IMPL>, ORBIT> fsetemb(*this, em);
	this->template foreach_dart_of_orbit<ORBIT>(d, fsetemb);
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline void MapCommon<MAP_IMPL>::initOrbitEmbedding(Dart d, unsigned int em)
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");

	FunctorInitEmb<MapCommon<MAP_IMPL>, ORBIT> fsetemb(*this, em);
	this->template foreach_dart_of_orbit<ORBIT>(d, fsetemb);
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline unsigned int MapCommon<MAP_IMPL>::setOrbitEmbeddingOnNewCell(Dart d)
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");

	unsigned int em = this->template newCell<ORBIT>();
	setOrbitEmbedding<ORBIT>(d, em);
	return em;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline unsigned int MapCommon<MAP_IMPL>::initOrbitEmbeddingOnNewCell(Dart d)
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");

	unsigned int em = this->template newCell<ORBIT>();
	initOrbitEmbedding<ORBIT>(d, em);
	return em;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline void MapCommon<MAP_IMPL>::copyCell(Dart d, Dart e)
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
	unsigned int dE = getEmbedding<ORBIT>(d) ;
	unsigned int eE = getEmbedding<ORBIT>(e) ;
	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) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
210 211
		this->m_attribs[ORBIT].copyLine(dE, eE) ;	// copy the data
//		copyCell<ORBIT>(dE, eE);
Pierre Kraemer's avatar
Pierre Kraemer committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 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
	}
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
void MapCommon<MAP_IMPL>::initAllOrbitsEmbedding(bool realloc)
{
	if(!this->template isOrbitEmbedded<ORBIT>())
		this->template addEmbedding<ORBIT>() ;
	DartMarker<MapCommon<MAP_IMPL> > mark(*this) ;
	for(Dart d = this->begin(); d != this->end(); this->next(d))
	{
		if(!mark.isMarked(d))
		{
			mark.markOrbit<ORBIT>(d) ;
			if(realloc || getEmbedding<ORBIT>(d) == EMBNULL)
				setOrbitEmbeddingOnNewCell<ORBIT>(d) ;
		}
	}
}

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

template <typename MAP_IMPL>
template <unsigned int DIM>
inline void MapCommon<MAP_IMPL>::boundaryMark(Dart d)
{
	this->m_markTables[DART][0]->operator[](this->dartIndex(d)).setMark(this->m_boundaryMarkers[DIM-2]);
}

template <typename MAP_IMPL>
template <unsigned int DIM>
inline void MapCommon<MAP_IMPL>::boundaryUnmark(Dart d)
{
	this->m_markTables[DART][0]->operator[](this->dartIndex(d)).unsetMark(this->m_boundaryMarkers[DIM-2]);
}

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

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

template <typename MAP_IMPL>
template <unsigned int DIM>
inline bool MapCommon<MAP_IMPL>::isBoundaryMarked(Dart d) const
{
	return this->m_markTables[DART][0]->operator[](this->dartIndex(d)).testMark(this->m_boundaryMarkers[DIM-2]);
}

template <typename MAP_IMPL>
inline bool MapCommon<MAP_IMPL>::isBoundaryMarkedCurrent(Dart d) const
{
	return this->m_markTables[DART][0]->operator[](this->dartIndex(d)).testMark(this->m_boundaryMarkers[this->dimension()-2]);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
280 281 282 283 284 285 286 287 288 289 290
template <typename MAP_IMPL>
inline bool MapCommon<MAP_IMPL>::isBoundaryMarked(unsigned int dim, Dart d) const
{
	switch(dim)
	{
		case 2 : return isBoundaryMarked<2>(d) ; break ;
		case 3 : return isBoundaryMarked<3>(d) ; break ;
		default : return false ; break ;
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
291 292 293 294 295 296 297 298 299
template <typename MAP_IMPL>
template <unsigned int DIM>
void MapCommon<MAP_IMPL>::boundaryUnmarkAll()
{
	AttributeContainer& cont = this->m_attribs[DART] ;
	for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
		this->m_markTables[DART][0]->operator[](i).unsetMark(this->m_boundaryMarkers[DIM-2]);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
300 301 302 303 304 305 306 307 308 309
/****************************************
 *        ATTRIBUTES MANAGEMENT         *
 ****************************************/

template <typename MAP_IMPL>
template <typename T, unsigned int ORBIT>
inline AttributeHandler<T, ORBIT, MAP_IMPL> MapCommon<MAP_IMPL>::addAttribute(const std::string& nameAttr)
{
	if(!this->template isOrbitEmbedded<ORBIT>())
		this->template addEmbedding<ORBIT>() ;
310
	AttributeMultiVector<T>* amv = this->m_attribs[ORBIT].template addAttribute<T>(nameAttr) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
	return AttributeHandler<T, ORBIT, MAP_IMPL>(this, amv) ;
}

template <typename MAP_IMPL>
template <typename T, unsigned int ORBIT>
inline bool MapCommon<MAP_IMPL>::removeAttribute(AttributeHandler<T, ORBIT, MAP_IMPL>& attr)
{
	assert(attr.isValid() || !"Invalid attribute handler") ;
	if(this->m_attribs[attr.getOrbit()].template removeAttribute<T>(attr.getIndex()))
	{
		AttributeMultiVectorGen* amv = attr.getDataVector();
		typedef std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator IT ;
		std::pair<IT, IT> bounds = this->attributeHandlers.equal_range(amv) ;
		for(IT i = bounds.first; i != bounds.second; ++i)
			(*i).second->setInvalid() ;
		this->attributeHandlers.erase(bounds.first, bounds.second) ;
		return true ;
	}
	return false ;
}

template <typename MAP_IMPL>
template <typename T, unsigned int ORBIT>
inline AttributeHandler<T ,ORBIT, MAP_IMPL> MapCommon<MAP_IMPL>::getAttribute(const std::string& nameAttr)
{
	AttributeMultiVector<T>* amv = this->m_attribs[ORBIT].template getDataVector<T>(nameAttr) ;
	return AttributeHandler<T, ORBIT, MAP_IMPL>(this, amv) ;
}

template <typename MAP_IMPL>
template <typename T, unsigned int ORBIT>
inline AttributeHandler<T ,ORBIT, MAP_IMPL> MapCommon<MAP_IMPL>::checkAttribute(const std::string& nameAttr)
{
	AttributeHandler<T, ORBIT, MAP_IMPL> att = this->getAttribute<T,ORBIT>(nameAttr);
	if (!att.isValid())
		att = this->addAttribute<T, ORBIT>(nameAttr);
	return att;
}

template <typename MAP_IMPL>
template <typename T, unsigned int ORBIT>
inline bool MapCommon<MAP_IMPL>::swapAttributes(AttributeHandler<T, ORBIT, MAP_IMPL>& attr1, AttributeHandler<T, ORBIT, MAP_IMPL>& attr2)
{
	assert((attr1.isValid() && attr2.isValid()) || !"Invalid attribute handler") ;
//	assert(attr1.getOrbit() == attr2.getOrbit() || !"Cannot swap attributes of different orbits") ;
//	unsigned int orbit = attr1.getOrbit() ;
	unsigned int index1 = attr1.getIndex() ;
	unsigned int index2 = attr2.getIndex() ;
	if(index1 != index2)
		return this->m_attribs[ORBIT].swapAttributes(index1, index2) ;
	return false ;
}

template <typename MAP_IMPL>
template <typename T, unsigned int ORBIT>
inline bool MapCommon<MAP_IMPL>::copyAttribute(AttributeHandler<T, ORBIT, MAP_IMPL>& dst, AttributeHandler<T, ORBIT, MAP_IMPL>& src)
{
	assert((dst.isValid() && src.isValid()) || !"Invalid attribute handler") ;
//	unsigned int orbit = dst.getOrbit() ;
//	assert(orbit == src.getOrbit() || !"Cannot copy attributes of different orbits") ;
	unsigned int index_dst = dst.getIndex() ;
	unsigned int index_src = src.getIndex() ;
	if(index_dst != index_src)
		return this->m_attribs[ORBIT].copyAttribute(index_dst, index_src) ;
	return false ;
}

Pierre Kraemer's avatar
Pierre Kraemer committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
template <typename MAP_IMPL>
inline DartAttribute<Dart, MAP_IMPL> MapCommon<MAP_IMPL>::getInvolution(unsigned int i)
{
	return DartAttribute<Dart, MAP_IMPL>(this, this->getInvolutionAttribute(i));
}

template <typename MAP_IMPL>
inline DartAttribute<Dart, MAP_IMPL> MapCommon<MAP_IMPL>::getPermutation(unsigned int i)
{
	return DartAttribute<Dart, MAP_IMPL>(this, this->getPermutationAttribute(i));
}

template <typename MAP_IMPL>
inline DartAttribute<Dart, MAP_IMPL> MapCommon<MAP_IMPL>::getPermutationInv(unsigned int i)
{
	return DartAttribute<Dart, MAP_IMPL>(this, this->getPermutationInvAttribute(i));
}

/****************************************
 *     QUICK TRAVERSAL MANAGEMENT       *
 ****************************************/

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline void MapCommon<MAP_IMPL>::enableQuickTraversal()
{
	if(this->m_quickTraversal[ORBIT] == NULL)
	{
		if(!this->template isOrbitEmbedded<ORBIT>())
			this->template addEmbedding<ORBIT>() ;
408
		this->m_quickTraversal[ORBIT] = this->m_attribs[ORBIT].template addAttribute<Dart>("quick_traversal") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
	}
	updateQuickTraversal<ORBIT>() ;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline void MapCommon<MAP_IMPL>::updateQuickTraversal()
{
	assert(this->m_quickTraversal[ORBIT] != NULL || !"updateQuickTraversal on a disabled orbit") ;

	CellMarker<MapCommon<MAP_IMPL>, ORBIT> cm(*this) ;
	for(Dart d = this->begin(); d != this->end(); this->next(d))
	{
		if(!cm.isMarked(d))
		{
			cm.mark(d) ;
			(*this->m_quickTraversal[ORBIT])[getEmbedding<ORBIT>(d)] = d ;
		}
	}
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline const AttributeMultiVector<Dart>* MapCommon<MAP_IMPL>::getQuickTraversal() const
{
	return this->m_quickTraversal[ORBIT] ;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline void MapCommon<MAP_IMPL>::disableQuickTraversal()
{
	if(this->m_quickTraversal[ORBIT] != NULL)
	{
443
		this->m_attribs[ORBIT].template removeAttribute<Dart>(this->m_quickTraversal[ORBIT]->getIndex()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
444 445 446 447 448 449 450 451 452 453 454 455 456 457
		this->m_quickTraversal[ORBIT] = NULL ;
	}
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int INCI>
inline void MapCommon<MAP_IMPL>::enableQuickIncidentTraversal()
{
	if(this->m_quickLocalIncidentTraversal[ORBIT][INCI] == NULL)
	{
		if(!this->template isOrbitEmbedded<ORBIT>())
			this->template addEmbedding<ORBIT>() ;
		std::stringstream ss;
		ss << "quickLocalIncidentTraversal_" << INCI;
458
		this->m_quickLocalIncidentTraversal[ORBIT][INCI] = this->m_attribs[ORBIT].template addAttribute<NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
	}
	updateQuickIncidentTraversal<ORBIT,INCI>() ;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int INCI>
inline void MapCommon<MAP_IMPL>::updateQuickIncidentTraversal()
{
	assert(this->m_quickLocalIncidentTraversal[ORBIT][INCI] != NULL || !"updateQuickTraversal on a disabled orbit") ;

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

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

	TraversorCell<MapCommon<MAP_IMPL>, ORBIT> tra_glob(*this);
	for (Dart d = tra_glob.begin(); d != tra_glob.end(); d = tra_glob.next())
	{
		buffer.clear();
		Traversor* tra_loc = TraversorFactory<MapCommon<MAP_IMPL> >::createIncident(*this, d, this->dimension(), ORBIT, INCI);
		for (Dart e = tra_loc->begin(); e != tra_loc->end(); e = tra_loc->next())
			buffer.push_back(e);
		delete tra_loc;
		buffer.push_back(NIL);
		std::vector<Dart>& vd = (*ptrVD)[getEmbedding<ORBIT>(d)];
		vd.reserve(buffer.size());
		vd.assign(buffer.begin(), buffer.end());
	}

	this->m_quickLocalIncidentTraversal[ORBIT][INCI] = ptrVD;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int INCI>
inline const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* MapCommon<MAP_IMPL>::getQuickIncidentTraversal() const
{
	return this->m_quickLocalIncidentTraversal[ORBIT][INCI] ;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int INCI>
inline void MapCommon<MAP_IMPL>::disableQuickIncidentTraversal()
{
	if(this->m_quickLocalIncidentTraversal[ORBIT][INCI] != NULL)
	{
		this->m_attribs[ORBIT].removeAttribute(this->m_quickLocalIncidentTraversal[ORBIT][INCI]->getIndex()) ;
		this->m_quickLocalIncidentTraversal[ORBIT][INCI] = NULL ;
	}
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int ADJ>
inline void MapCommon<MAP_IMPL>::enableQuickAdjacentTraversal()
{
	if(this->m_quickLocalAdjacentTraversal[ORBIT][ADJ] == NULL)
	{
		if(!this->template isOrbitEmbedded<ORBIT>())
			this->template addEmbedding<ORBIT>() ;
		std::stringstream ss;
		ss << "quickLocalAdjacentTraversal" << ADJ;
520
		this->m_quickLocalAdjacentTraversal[ORBIT][ADJ] = this->m_attribs[ORBIT].template addAttribute<NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
	}
	updateQuickAdjacentTraversal<ORBIT, ADJ>() ;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int ADJ>
inline void MapCommon<MAP_IMPL>::updateQuickAdjacentTraversal()
{
	assert(this->m_quickLocalAdjacentTraversal[ORBIT][ADJ] != NULL || !"updateQuickTraversal on a disabled orbit") ;

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

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

	TraversorCell<MapCommon<MAP_IMPL>, ORBIT> tra_glob(*this);
	for (Dart d = tra_glob.begin(); d != tra_glob.end(); d = tra_glob.next())
	{
		buffer.clear();
		Traversor* tra_loc = TraversorFactory<MapCommon<MAP_IMPL> >::createAdjacent(*this, d, this->dimension(), ORBIT, ADJ);
		for (Dart e = tra_loc->begin(); e != tra_loc->end(); e = tra_loc->next())
			buffer.push_back(e);
		buffer.push_back(NIL);
		delete tra_loc;
		std::vector<Dart>& vd = (*ptrVD)[getEmbedding<ORBIT>(d)];
		vd.reserve(buffer.size());
		vd.assign(buffer.begin(),buffer.end());
	}

	this->m_quickLocalAdjacentTraversal[ORBIT][ADJ] = ptrVD;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int ADJ>
inline const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* MapCommon<MAP_IMPL>::getQuickAdjacentTraversal() const
{
	return this->m_quickLocalAdjacentTraversal[ORBIT][ADJ] ;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT, unsigned int ADJ>
inline void MapCommon<MAP_IMPL>::disableQuickAdjacentTraversal()
{
	if(this->m_quickLocalAdjacentTraversal[ORBIT][ADJ] != NULL)
	{
567
		this->m_attribs[ORBIT].template removeAttribute<Dart>(this->m_quickLocalAdjacentTraversal[ORBIT][ADJ]->getIndex()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
568 569 570 571
		this->m_quickLocalAdjacentTraversal[ORBIT][ADJ] = NULL ;
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
/****************************************
 *               UTILITIES              *
 ****************************************/

template <typename MAP_IMPL>
template <unsigned int ORBIT>
unsigned int MapCommon<MAP_IMPL>::computeIndexCells(AttributeHandler<unsigned int, ORBIT, MAP_IMPL>& idx)
{
	AttributeContainer& cont = this->m_attribs[ORBIT] ;
	unsigned int cpt = 0 ;
	for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
		idx[i] = cpt++ ;
	return cpt ;
}

template <typename MAP_IMPL>
template <unsigned int ORBIT>
void MapCommon<MAP_IMPL>::bijectiveOrbitEmbedding()
{
	assert(this->template isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded") ;

	AttributeHandler<int, ORBIT, MAP_IMPL> counter = addAttribute<int, ORBIT>("tmpCounter") ;
	counter.setAllValues(int(0)) ;

	DartMarker<MAP_IMPL> mark(*this) ;
	for(Dart d = this->begin(); d != this->end(); this->next(d))
	{
		if(!mark.isMarked(d))
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
601
			mark.template markOrbit<ORBIT>(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
			unsigned int emb = getEmbedding<ORBIT>(d) ;
			if (emb != EMBNULL)
			{
				if (counter[d] > 0)
				{
					unsigned int newEmb = setOrbitEmbeddingOnNewCell<ORBIT>(d) ;
					copyCell<ORBIT>(newEmb, emb) ;
				}
				counter[d]++ ;
			}
		}
	}

	removeAttribute(counter) ;
}

} // namespace CGoGN