genericmap.cpp 18 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                                        *
*                                                                              *
*******************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
25 26
#define CGoGN_TOPO_DLL_EXPORT 1

Pierre Kraemer's avatar
Pierre Kraemer committed
27
#include "Topology/generic/genericmap.h"
28
#include "Topology/generic/attributeHandler.h"
29

Pierre Kraemer's avatar
Pierre Kraemer committed
30 31
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
32
#include "Container/registered.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
33

Sylvain Thery's avatar
Sylvain Thery committed
34 35
#include <algorithm>

Pierre Kraemer's avatar
Pierre Kraemer committed
36 37
namespace CGoGN
{
38

39 40 41
namespace Parallel
{
//int NumberOfThreads=1;
Sylvain Thery's avatar
Sylvain Thery committed
42
CGoGN_TOPO_API int NumberOfThreads = getSystemNumberOfCores();
43 44
}

Pierre Kraemer's avatar
Pierre Kraemer committed
45
std::map<std::string, RegisteredBaseAttribute*>* GenericMap::m_attributes_registry_map = NULL;
46

Sylvain Thery's avatar
Sylvain Thery committed
47 48 49
//std::mutex* GenericMap::s_DartBufferMutex = NULL;
//std::mutex* GenericMap::s_IntBufferMutex = NULL;

50
std::vector<GenericMap*>*  GenericMap::s_instances = NULL;
Sylvain Thery's avatar
Sylvain Thery committed
51

52
GenericMap::GenericMap():
Sylvain Thery's avatar
Sylvain Thery committed
53
	m_nextMarkerId(0),
54
	m_authorizeExternalThreads(false),
Sylvain Thery's avatar
Sylvain Thery committed
55
	m_manipulator(NULL)
56 57 58 59 60 61
{
	if(m_attributes_registry_map == NULL)
		initAllStatics(NULL); // no need here to store the pointers

	s_instances->push_back(this);

62 63
	m_thread_ids.reserve(NB_THREADS + 1);
	m_thread_ids.push_back(std::this_thread::get_id());
64 65 66 67 68 69 70

	for(unsigned int i = 0; i < NB_ORBITS; ++i)
	{
		m_attribs[i].setOrbit(i) ;
		m_attribs[i].setRegistry(m_attributes_registry_map) ;
	}

71 72 73 74 75 76 77 78 79
	for(unsigned int i = 0; i < NB_THREADS; ++i)
	{
		s_vdartsBuffers[i].reserve(8);
		s_vintsBuffers[i].reserve(8);

//		for(unsigned int j = 0; j < NB_ORBITS; ++j)
//			m_markVectors_free[i][j].reserve(8);
	}

80 81 82 83 84 85 86 87 88 89
	init();
}

void GenericMap::copyAllStatics(const StaticPointers& sp)
{
	m_attributes_registry_map = sp.att_registry;
	s_instances = sp.instances;
}

void GenericMap::initAllStatics(StaticPointers* sp)
Pierre Kraemer's avatar
Pierre Kraemer committed
90
{
91
	if(m_attributes_registry_map == NULL)
92
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
93
		m_attributes_registry_map = new std::map<std::string, RegisteredBaseAttribute*>;
94

95 96 97
		// register all known types
		registerAttribute<Dart>("Dart");
		registerAttribute<Mark>("Mark");
Pierre Kraemer's avatar
Pierre Kraemer committed
98

99
		registerAttribute<char>("char");
100 101 102
		registerAttribute<short>("short");
		registerAttribute<int>("int");
		registerAttribute<long>("long");
Pierre Kraemer's avatar
Pierre Kraemer committed
103

104
		registerAttribute<unsigned char>("unsigned char");
105 106 107 108 109 110
		registerAttribute<unsigned short>("unsigned short");
		registerAttribute<unsigned int>("unsigned int");
		registerAttribute<unsigned long>("unsigned long");

		registerAttribute<float>("float");
		registerAttribute<double>("double");
Pierre Kraemer's avatar
Pierre Kraemer committed
111

112 113 114
		registerAttribute<Geom::Vec2f>(Geom::Vec2f::CGoGNnameOfType());
		registerAttribute<Geom::Vec3f>(Geom::Vec3f::CGoGNnameOfType());
		registerAttribute<Geom::Vec4f>(Geom::Vec4f::CGoGNnameOfType());
Pierre Kraemer's avatar
Pierre Kraemer committed
115

116 117 118
		registerAttribute<Geom::Vec2d>(Geom::Vec2d::CGoGNnameOfType());
		registerAttribute<Geom::Vec3d>(Geom::Vec3d::CGoGNnameOfType());
		registerAttribute<Geom::Vec4d>(Geom::Vec4d::CGoGNnameOfType());
Pierre Kraemer's avatar
Pierre Kraemer committed
119

120 121
		registerAttribute<Geom::Matrix33f>(Geom::Matrix33f::CGoGNnameOfType());
		registerAttribute<Geom::Matrix44f>(Geom::Matrix44f::CGoGNnameOfType());
Pierre Kraemer's avatar
Pierre Kraemer committed
122

123 124
		registerAttribute<Geom::Matrix33d>(Geom::Matrix33d::CGoGNnameOfType());
		registerAttribute<Geom::Matrix44d>(Geom::Matrix44d::CGoGNnameOfType());
125 126

		registerAttribute<MarkerBool>("MarkerBool");
127 128
	}

129 130
	if (s_instances == NULL)
		s_instances = new std::vector<GenericMap*>;
Pierre Kraemer's avatar
Pierre Kraemer committed
131

132
	if (sp != NULL)
133
	{
134 135
		sp->att_registry = m_attributes_registry_map;
		sp->instances = s_instances;
136
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139 140 141 142 143 144 145
}

GenericMap::~GenericMap()
{
	for(unsigned int i = 0; i < NB_ORBITS; ++i)
	{
		if(isOrbitEmbedded(i))
			m_attribs[i].clear(true) ;
	}
146 147 148 149 150

	for(std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it)
		(*it).second->setInvalid() ;
	attributeHandlers.clear() ;

151 152 153 154
	// remove instance of table
	auto it = std::find(s_instances->begin(), s_instances->end(), this);
	*it = s_instances->back();
	s_instances->pop_back();
155 156

	// clean type registry if necessary
157

158 159 160 161 162 163 164 165
//	if (s_instances->size() == 0)
//	{
//		for (std::map<std::string, RegisteredBaseAttribute*>::iterator it =  m_attributes_registry_map->begin(); it != m_attributes_registry_map->end(); ++it)
//			delete it->second;

//		delete m_attributes_registry_map;
//		m_attributes_registry_map = NULL;

166
//		for(unsigned int i = 0; i < NB_THREADS; ++i)
167 168 169 170 171 172 173
//		{
//			for (auto it =s_vdartsBuffers[i].begin(); it != s_vdartsBuffers[i].end(); ++it)
//				delete *it;
//			for (auto it =s_vintsBuffers[i].begin(); it != s_vintsBuffers[i].end(); ++it)
//				delete *it;
//		}
//	}
Pierre Kraemer's avatar
Pierre Kraemer committed
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
bool GenericMap::askManipulate(MapManipulator* ptr)
{
	if (m_manipulator == NULL)
	{
		CGoGNerr << "Map already manipulated by other manipulator" << CGoGNendl;
		return false;
	}

	m_manipulator = ptr;
	return true;
}

MapManipulator* GenericMap::getManipulator()
{
	return m_manipulator;
}

bool GenericMap::releaseManipulate(MapManipulator* ptr)
{
	if (m_manipulator != ptr)
	{
		CGoGNerr << "Wrong manipulator want to release the map" << CGoGNendl;
		return false;
	}

	m_manipulator = NULL;
	return true;
}

205
void GenericMap::init(bool addBoundaryMarkers)
206
{
Pierre Kraemer's avatar
Pierre Kraemer committed
207
	for(unsigned int i = 0; i < NB_ORBITS; ++i)
208
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
209 210 211 212 213
		m_attribs[i].clear(true) ;
		m_embeddings[i] = NULL ;
		m_quickTraversal[i] = NULL;

		for(unsigned int j = 0; j < NB_ORBITS; ++j)
214
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
215 216
			m_quickLocalIncidentTraversal[i][j] = NULL ;
			m_quickLocalAdjacentTraversal[i][j] = NULL ;
217
		}
218

219
		for(unsigned int j = 0; j < NB_THREADS; ++j)
220
			m_markVectors_free[i][j].clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
221 222
	}

223 224
	if (addBoundaryMarkers)
	{
225 226
		m_boundaryMarkers[0] = m_attribs[DART].addMarkerAttribute("BoundaryMark0") ;
		m_boundaryMarkers[1] = m_attribs[DART].addMarkerAttribute("BoundaryMark1") ;
227 228
	}

229
	for(std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
230 231 232 233 234 235 236
		(*it).second->setInvalid() ;
	attributeHandlers.clear() ;
}

void GenericMap::clear(bool removeAttrib)
{
	if (removeAttrib)
237 238 239 240 241 242
	{
#ifndef NDEBUG
		for(unsigned int i = 0; i < NB_ORBITS; ++i)
			if (m_attribs[i].hasMarkerAttribute())
				CGoGNout << "Warning removing marker attribute on orbit, need update ? "<<orbitName(i)<< CGoGNendl;
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
243
		init();
244
	}
245 246 247 248 249
	else
	{
		for(unsigned int i = 0; i < NB_ORBITS; ++i)
			m_attribs[i].clear(false) ;
	}
untereiner's avatar
untereiner committed
250 251
}

Pierre Kraemer's avatar
Pierre Kraemer committed
252 253 254 255
/****************************************
 *        ATTRIBUTES MANAGEMENT         *
 ****************************************/

256 257 258 259 260 261 262 263 264 265 266 267
void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned int orbit2)
{
	assert(orbit1 != orbit2 || !"Cannot swap a container with itself") ;
	assert((orbit1 != DART && orbit2 != DART) || !"Cannot swap the darts container") ;

	m_attribs[orbit1].swap(m_attribs[orbit2]) ;
	m_attribs[orbit1].setOrbit(orbit1) ;	// to update the orbit information
	m_attribs[orbit2].setOrbit(orbit2) ;	// in the contained AttributeMultiVectors

	m_embeddings[orbit1]->swap(m_embeddings[orbit2]) ;


Sylvain Thery's avatar
Sylvain Thery committed
268
	// NE MARCHE PLUS PAS POSSIBLE DE CHANGER LES CONTAINER
269

270
//	for (unsigned int i = 0; i < NB_THREADS; ++i)
Sylvain Thery's avatar
Sylvain Thery committed
271 272 273 274 275 276 277 278 279
//	{
//		for(std::vector<CellMarkerGen*>::iterator it = cellMarkers[i].begin(); it != cellMarkers[i].end(); ++it)
//		{
//			if((*it)->m_cell == orbit1)
//				(*it)->m_cell = orbit2 ;
//			else if((*it)->m_cell == orbit2)
//				(*it)->m_cell = orbit1 ;
//		}
//	}
280
}
Pierre Kraemer's avatar
Pierre Kraemer committed
281

282 283 284 285 286 287 288 289 290 291 292 293
void GenericMap::viewAttributesTables()
{
	std::cout << "======================="<< std::endl ;
	for (unsigned int i = 0; i < NB_ORBITS; ++i)
	{
		std::cout << "ATTRIBUTE_CONTAINER " << i << std::endl ;
		AttributeContainer& cont = m_attribs[i] ;

		// get the list of attributes
		std::vector<std::string> listeNames ;
		cont.getAttributesNames(listeNames) ;
		for (std::vector<std::string>::iterator it = listeNames.begin(); it != listeNames.end(); ++it)
294 295 296 297 298
		{
			unsigned int id = cont.getAttributeIndex(*it);
			std::cout << "    " << *it << " ("<<id<<")"<<std::endl ;
		}

299 300 301 302 303 304 305
		std::cout << "-------------------------" << std::endl ;
	}
	std::cout << "m_embeddings: " << std::hex ;
	for (unsigned int i = 0; i < NB_ORBITS; ++i)
		std::cout << (long)(m_embeddings[i]) << " / " ;
	std::cout << std::endl << "-------------------------" << std::endl ;

Sylvain Thery's avatar
Sylvain Thery committed
306 307 308 309
//	std::cout << "m_markTables: " ;
//	for (unsigned int i = 0; i < NB_ORBITS; ++i)
//		std::cout << (long)(m_markTables[i][0]) << " / " ;
//	std::cout << std::endl << "-------------------------" << std::endl << std::dec ;
310 311
}

312 313 314 315 316 317 318
void GenericMap::printDartsTable()
{
	std::cout << "======================="<< std::endl ;

	//m_attribs[DART]
}

319 320 321 322
/****************************************
 *          THREAD MANAGEMENT           *
 ****************************************/

Sylvain Thery's avatar
Sylvain Thery committed
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
//void GenericMap::addThreadMarker(unsigned int nb)
//{
//	unsigned int th ;

//	for (unsigned int j = 0; j < nb; ++j)
//	{
//		th = m_nbThreadMarkers ;
//		m_nbThreadMarkers++ ;

//		for (unsigned int i = 0; i < NB_ORBITS; ++i)
//		{
//			std::stringstream ss ;
//			ss << "Mark_"<< th ;
//			AttributeContainer& cellCont = m_attribs[i] ;
//			AttributeMultiVector<Mark>* amvMark = cellCont.addAttribute<Mark>(ss.str()) ;
//			m_markTables[i][th] = amvMark ;
//		}
//	}
//}

//unsigned int GenericMap::getNbThreadMarkers() const
//{
//	return m_nbThreadMarkers;
//}

//void GenericMap::removeThreadMarker(unsigned int nb)
//{
//	unsigned int th = 0;
//	while ((m_nbThreadMarkers > 1) && (nb > 0))
//	{
//		th = --m_nbThreadMarkers ;
//		--nb;
//		for (unsigned int i = 0; i < NB_ORBITS; ++i)
//		{
//			std::stringstream ss ;
//			ss << "Mark_"<< th ;
//			AttributeContainer& cellCont = m_attribs[i] ;
//			cellCont.removeAttribute<Mark>(ss.str()) ;
//			m_markTables[i][th] = NULL ;
//		}
//	}
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
365 366 367 368 369

/****************************************
 *             SAVE & LOAD              *
 ****************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
370
void GenericMap::restore_shortcuts()
371
{
Pierre Kraemer's avatar
Pierre Kraemer committed
372 373
	// EMBEDDING

374 375 376 377 378 379 380 381 382 383
	// get container of dart orbit
	AttributeContainer& cont = m_attribs[DART] ;

	// get the list of attributes
	std::vector<std::string> listeNames;
	cont.getAttributesNames(listeNames);

	// check if there are EMB_X attributes
	for (unsigned int i = 0;  i < listeNames.size(); ++i)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
384
		std::string sub = listeNames[i].substr(0, listeNames[i].size() - 1);
385 386 387 388 389 390 391 392
		if (sub == "EMB_")
		{
			unsigned int orb = listeNames[i][4]-'0'; // easy atoi computation for one char;
			AttributeMultiVector<unsigned int>* amv = cont.getDataVector<unsigned int>(i);
			m_embeddings[orb] = amv ;
		}
	}

Sylvain Thery's avatar
Sylvain Thery committed
393
	// MARKERS
394 395
	std::vector<AttributeMultiVector<MarkerBool>*>& amvv = m_attribs[DART].getMarkerAttributes();
	for (auto it=amvv.begin(); it != amvv.end(); ++it)
396
	{
397 398 399 400
		if ((*it)->getName() == "BoundaryMark0")
			m_boundaryMarkers[0] = *it;
		if ((*it)->getName() == "BoundaryMark1")
			m_boundaryMarkers[1] = *it;
Sylvain Thery's avatar
Sylvain Thery committed
401
	}
402

403

Sylvain Thery's avatar
Sylvain Thery committed
404
	// QUICK TRAVERSAL
Pierre Kraemer's avatar
Pierre Kraemer committed
405

Sylvain Thery's avatar
Sylvain Thery committed
406 407 408
	for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
		AttributeContainer& cont = m_attribs[orbit];
Pierre Kraemer's avatar
Pierre Kraemer committed
409 410 411 412 413 414 415
		m_quickTraversal[orbit] = cont.getDataVector<Dart>("quick_traversal") ;
		for(unsigned int j = 0; j < NB_ORBITS; ++j)
		{
			std::stringstream ss;
			ss << "quickLocalIncidentTraversal_" << j;
			m_quickLocalIncidentTraversal[orbit][j] = cont.getDataVector< NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
			std::stringstream ss2;
Pierre Kraemer's avatar
Pierre Kraemer committed
416
			ss2 << "quickLocalAdjacentTraversal_" << j;
Pierre Kraemer's avatar
Pierre Kraemer committed
417 418
			m_quickLocalAdjacentTraversal[orbit][j] = cont.getDataVector< NoTypeNameAttribute<std::vector<Dart> > >(ss2.str()) ;
		}
419
	}
420

421 422 423 424
	// set Attribute handlers invalid
	for(std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*>::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it)
		(*it).second->setInvalid() ;
	attributeHandlers.clear() ;
425 426 427 428
}

void GenericMap::dumpAttributesAndMarkers()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
429
	for (unsigned int i = 0; i < NB_ORBITS; ++i)
430 431
	{
		std::vector<std::string> names;
Pierre Kraemer's avatar
Pierre Kraemer committed
432
		names.reserve(32); 				//just to limit reallocation
433
		m_attribs[i].getAttributesNames(names);
434
		unsigned int nb = uint32(names.size());
Pierre Kraemer's avatar
Pierre Kraemer committed
435
		if (nb > 0)
436
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
437
			CGoGNout << "ORBIT "<< i << CGoGNendl;
438 439 440
			std::vector<std::string> types;
			types.reserve(nb);
			m_attribs[i].getAttributesTypes(types);
Pierre Kraemer's avatar
Pierre Kraemer committed
441 442
			for (unsigned int j = 0; j < nb; ++j)
				CGoGNout << "    " << j << " : " << types[j] << " " << names[j] << CGoGNendl;
443 444
		}
	}
Sylvain Thery's avatar
Sylvain Thery committed
445 446 447
//	CGoGNout << "RESERVED MARKERS "<< CGoGNendl;
//	for (unsigned int i = 0; i < NB_ORBITS; ++i)
//	{
448
//		for (unsigned int j = 0; j < NB_THREADS; ++j)
Sylvain Thery's avatar
Sylvain Thery committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
//		{
//			MarkSet ms = m_marksets[i][j];
//			if (!ms.isClear())
//			{
//				CGoGNout << "Orbit " << i << "  thread " << j << " : ";
//				Mark m(1);
//				for (unsigned i = 0; i < Mark::getNbMarks(); ++i)
//				{
//					if (ms.testMark(m))
//						CGoGNout << m.getMarkVal() << ", ";
//					m.setMarkVal(m.getMarkVal()<<1);
//				}
//				CGoGNout << CGoGNendl;
//			}
//		}
//	}
465 466
}

467 468

void GenericMap::compact(bool topoOnly)
469
{
470 471 472 473 474 475
	compactTopo();

	if (topoOnly)
		return;

	std::vector<unsigned int> oldnew;
Sylvain Thery's avatar
Sylvain Thery committed
476

477 478 479 480
	for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
		if ((orbit != DART) && (isOrbitEmbedded(orbit)))
		{
481 482
			m_attribs[orbit].compact(oldnew);
			for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
483
			{
484
				unsigned int& idx = m_embeddings[orbit]->operator[](i);
485 486
				unsigned int jdx = oldnew[idx];
				if (jdx != 0xffffffff)
487 488 489 490 491 492
					idx = jdx;
			}
		}
	}
}

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 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
void GenericMap::compactOrbitContainer(unsigned int orbit, float frag)
{
	std::vector<unsigned int> oldnew;

	if (isOrbitEmbedded(orbit) && (fragmentation(orbit)< frag))
	{
		m_attribs[orbit].compact(oldnew);
		for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
		{
			unsigned int& idx = m_embeddings[orbit]->operator[](i);
			unsigned int jdx = oldnew[idx];
			if (jdx != 0xffffffff)
				idx = jdx;
		}
	}
}


void GenericMap::compactIfNeeded(float frag, bool topoOnly)
{
	if (fragmentation(DART)< frag)
		compactTopo();

	if (topoOnly)
		return;

	std::vector<unsigned int> oldnew;

	for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
		if ((orbit != DART) && (isOrbitEmbedded(orbit)) && (fragmentation(orbit)< frag))
		{
			m_attribs[orbit].compact(oldnew);
			for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i))
			{
				unsigned int& idx = m_embeddings[orbit]->operator[](i);
				unsigned int jdx = oldnew[idx];
				if (jdx != 0xffffffff)
					idx = jdx;
			}
		}
	}
}

537

538 539 540 541
void GenericMap::dumpCSV() const
{
	for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
	{
542
		CGoGNout << "Container of "<<orbitName(orbit)<< CGoGNendl;
543 544 545 546 547
		m_attribs[orbit].dumpCSV();
	}
	CGoGNout << CGoGNendl;
}

Sylvain Thery's avatar
Sylvain Thery committed
548 549 550 551 552

void GenericMap::moveData(GenericMap &mapf)
{
	GenericMap::init(false);

553
	for (unsigned int i = 0; i < NB_ORBITS; ++i)
Sylvain Thery's avatar
Sylvain Thery committed
554 555 556 557 558 559 560
	{
		this->m_attribs[i].swap(mapf.m_attribs[i]);
		this->m_embeddings[i] = mapf.m_embeddings[i];
		this->m_quickTraversal[i] = mapf.m_quickTraversal[i];
		mapf.m_embeddings[i] = NULL ;
		mapf.m_quickTraversal[i] = NULL;

561
		for (unsigned int j = 0; j < NB_ORBITS; ++j)
Sylvain Thery's avatar
Sylvain Thery committed
562 563 564 565 566 567 568
		{
			this->m_quickLocalIncidentTraversal[i][j] = mapf.m_quickLocalIncidentTraversal[i][j];
			this->m_quickLocalAdjacentTraversal[i][j] = mapf.m_quickLocalAdjacentTraversal[i][j];
			mapf.m_quickLocalIncidentTraversal[i][j] = NULL ;
			mapf.m_quickLocalAdjacentTraversal[i][j] = NULL ;
		}

569
		for (unsigned int j = 0; j < NB_THREADS; ++j)
Sylvain Thery's avatar
Sylvain Thery committed
570 571 572
			this->m_markVectors_free[i][j].swap(mapf.m_markVectors_free[i][j]);
	}

573 574 575 576 577 578
	for (unsigned int i = 0; i < NB_THREADS; ++i)
	{
		this->s_vdartsBuffers[i].swap(mapf.s_vdartsBuffers[i]);
		this->s_vintsBuffers[i].swap(mapf.s_vintsBuffers[i]);
	}

Sylvain Thery's avatar
Sylvain Thery committed
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
	this->m_boundaryMarkers[0] = mapf.m_boundaryMarkers[0];
	this->m_boundaryMarkers[1] = mapf.m_boundaryMarkers[1];

	this->m_nextMarkerId = mapf.m_nextMarkerId;

	for(auto it = mapf.attributeHandlers.begin(); it != mapf.attributeHandlers.end(); ++it)
	   (*it).second->setInvalid() ;
	mapf.attributeHandlers.clear() ;
}

void GenericMap::garbageMarkVectors()
{
	unsigned int maxId=0;

	for (unsigned int orbit=0; orbit<NB_ORBITS;++orbit)
	{
595 596 597
		std::vector<AttributeMultiVector<MarkerBool>*>& amvv = m_attribs[orbit].getMarkerAttributes();

		for (auto it = amvv.begin(); it != amvv.end(); ++it )
Sylvain Thery's avatar
Sylvain Thery committed
598
		{
599 600 601
			AttributeMultiVector<MarkerBool>* amv = *it;
			const std::string& name = amv->getName();
			if (name.substr(0,7) == "marker_")
Sylvain Thery's avatar
Sylvain Thery committed
602
			{
603 604
				// store tne next free index for unique numbering
				std::string num = name.substr(name.length()-3,3);
Sylvain Thery's avatar
Sylvain Thery committed
605 606 607
				unsigned int id = 100*(num[0]-'0')+10*(num[1]-'0')+(num[2]-'0');
				if (id > maxId)
					maxId = id;
608

Sylvain Thery's avatar
Sylvain Thery committed
609 610 611 612 613 614 615 616 617 618
				amv->allFalse();
				m_markVectors_free[orbit][0].push_back(amv);
			}
		}
	}
	m_nextMarkerId = maxId+1;
}

void GenericMap::removeMarkVectors()
{
619
	for (unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit)
Sylvain Thery's avatar
Sylvain Thery committed
620 621 622
	{
		std::vector<std::string> attNames;
		m_attribs[orbit].getAttributesNames(attNames);
623
		for (auto sit = attNames.begin(); sit != attNames.end(); ++sit)
Sylvain Thery's avatar
Sylvain Thery committed
624 625 626 627 628 629 630 631 632 633
		{
			if (sit->substr(0,7) == "marker_")
			{
				m_attribs[orbit].removeAttribute<MarkerBool>(*sit);
			}
		}
	}
	m_nextMarkerId = 0;
}

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