env_map.cpp 12.5 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4
#include "env_map.h"
#include "utils.h"
#include "agent.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
5 6
#include "Geometry/inclusion.h"
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
7 8 9 10 11
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Geometry/normal.h"

using namespace CGoGN;

Pierre Kraemer's avatar
Pierre Kraemer committed
12
EnvMap::EnvMap() :
Pierre Kraemer's avatar
Pierre Kraemer committed
13 14 15 16
	obstacleMark(map, EDGE),
	buildingMark(map, FACE),
	refineMark(map, FACE),
	coarsenMark(map, FACE)
Pierre Kraemer's avatar
Pierre Kraemer committed
17
{
Pierre Kraemer's avatar
Pierre Kraemer committed
18 19 20 21 22 23
	position = map.addAttribute<PFP::VEC3>(VERTEX, "position");
	normal = map.addAttribute<PFP::VEC3>(VERTEX, "normal");
	agentvect = map.addAttribute<PFP::AGENTVECT>(FACE, "agents");
	neighborAgentvect = map.addAttribute<PFP::AGENTVECT>(FACE, "neighborAgents");
	obstvect = map.addAttribute<PFP::OBSTACLEVECT>(FACE, "obstacles");
	subdivisableFace = map.addAttribute<PFP::BOOLATTRIB>(FACE, "subdivisableFace");
Pierre Kraemer's avatar
Pierre Kraemer committed
24 25 26 27
}

unsigned int EnvMap::mapMemoryCost()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
28 29 30 31
	return (map.getAttributeContainer(DART)).memorySize()
			+ (map.getAttributeContainer(VERTEX)).memorySize()
			+ (map.getAttributeContainer(EDGE)).memorySize()
			+ (map.getAttributeContainer(FACE)).memorySize();
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33 34 35
}

Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
36
	CellMarkerStore m(map, FACE);
Pierre Kraemer's avatar
Pierre Kraemer committed
37 38
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
39 40
		if(!m.isMarked(d))
		{
41 42 43 44
			m.mark(d);
			if(!buildingMark.isMarked(d) && Algo::Geometry::isPointInConvexFace2D<PFP>(map, d, position, pos, true))
				return d;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47 48 49 50 51 52 53
	}

	std::cout << "ERROR : pos not in map" << std::endl;
	return map.begin();
}

void EnvMap::init()
{
	float sideSize = 70.0f;
Pierre Kraemer's avatar
Pierre Kraemer committed
54
	unsigned int nbSquares = 14;
Pierre Kraemer's avatar
Pierre Kraemer committed
55
	CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
56
//	CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
Pierre Kraemer's avatar
Pierre Kraemer committed
57
//	CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
Pierre Kraemer's avatar
Pierre Kraemer committed
58 59
	map.init();
	registerObstaclesInFaces();
60 61
	for(unsigned int i = subdivisableFace.begin(); i < subdivisableFace.end(); subdivisableFace.next(i))
		subdivisableFace[i].first = false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
62 63
}

Pierre Kraemer's avatar
Pierre Kraemer committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
void EnvMap::foreach_neighborFace(Dart d, FunctorType& f)
{
	Dart dd = d;
	do
	{
		Dart ddd = map.alpha1(map.alpha1(dd));
		while(ddd != dd)
		{
			f(ddd);
			ddd = map.alpha1(ddd);
		}
		dd = map.phi1(dd);
	} while(dd != d);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
79 80
void EnvMap::registerObstaclesInFaces()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
81
	CellMarker m(map, FACE);
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83 84 85 86
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(!m.isMarked(d))
		{
			m.mark(d);
87
			if(!buildingMark.isMarked(d))
Pierre Kraemer's avatar
Pierre Kraemer committed
88
			{
89 90 91 92 93 94 95
				Dart dd = d;
				do
				{
					if(obstacleMark.isMarked(dd))
						obstvect[d].push_back(map.phi2(dd));
					dd = map.phi1(dd);
				} while(dd != d);
Pierre Kraemer's avatar
Pierre Kraemer committed
96

97
				do
Pierre Kraemer's avatar
Pierre Kraemer committed
98
				{
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
					Dart ddd = map.alpha1(map.alpha1(dd));
					while(ddd != dd)
					{
						if(!buildingMark.isMarked(ddd))
							addNeighborObstacles(obstvect[d], ddd, ddd == map.alpha_1(dd));
						ddd = map.alpha1(ddd);
					}
					dd = map.phi1(dd);
				} while(dd != d);
			}
		}
	}

	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
114
		if(m.isMarked(d) && !buildingMark.isMarked(d))
115
			m.unmark(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	}
}

void EnvMap::addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbor)
{
	Dart stop;
	if(edgeNeighbor)
		stop = map.phi_1(map.phi_1(map.phi_1(d)));
	else
		stop = map.phi_1(map.phi_1(d));
	
	Dart dd = d;
	do
	{
		if(obstacleMark.isMarked(dd))
		{
			if(buildingMark.isMarked(dd))
				obst.push_back(dd);
			else
				obst.push_back(map.phi2(dd));
		}
		dd = map.phi1(dd);
	} while(dd != d);
}

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
//void EnvMap::agentChangeFaceThroughEdge(Agent* agent)
//{
//	Dart oldFace = agent->part_.lastCrossed;
//	Dart newFace = agent->part_.d;
//
//	agentvect[newFace].push_back(agent);
//
//	PFP::AGENTS::iterator end = agentvect[oldFace].end();
//	for(PFP::AGENTS::iterator it = agentvect[oldFace].begin(); it != end; ++it)
//	{
//		if(*it == agent)
//		{
//			*it = agentvect[oldFace].back();
//			agentvect[oldFace].pop_back();
//			break;
//		}
//	}
//
//	// mark adjacent cells shared by newFace and oldFace
Pierre Kraemer's avatar
Pierre Kraemer committed
160
//	CellMarkerNoUnmark f(map, FACE);
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 210 211 212 213 214 215 216 217
//	Dart d = oldFace;
//	do
//	{
//		f.mark(d);
//		d = map.alpha1(d);
//	} while(d != oldFace);
//
//	d = map.phi1(oldFace);
//	do
//	{
//		f.mark(d);
//		d = map.alpha1(d);
//	} while(d != map.phi1(oldFace));
//
//	// remove agent from cells adjacent to oldFace but not to newFace
//	Dart dd = oldFace;
//	do
//	{
//		Dart ddd = map.alpha1(map.alpha1(dd));
//		while(ddd != dd)
//		{
//			if(!f.isMarked(ddd))
//			{
//				bool found = false;
//				PFP::AGENTS::iterator end = neighborAgentvect[ddd].end();
//				for(PFP::AGENTS::iterator it = neighborAgentvect[ddd].begin(); it != end && !found; ++it)
//				{
//					if(*it == agent)
//					{
//						*it = neighborAgentvect[ddd].back();
//						neighborAgentvect[ddd].pop_back();
//						found = true;
//					}
//				}
//			}
//			ddd = map.alpha1(ddd);
//		}
//		dd = map.phi1(dd);
//	} while(dd != oldFace);
//
//	// add agent from cells adjacent to oldFace but not to newFace
//	// and unmark shared cells
//	dd = newFace;
//	do
//	{
//		Dart ddd = map.alpha1(map.alpha1(dd));
//		while(ddd != dd)
//		{
//			if(!f.isMarked(ddd))
//				neighborAgentvect[ddd].push_back(agent);
//			else
//				f.unmark(ddd);
//			ddd = map.alpha1(ddd);
//		}
//		dd = map.phi1(dd);
//	} while(dd != newFace);
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
218

Pierre Kraemer's avatar
Pierre Kraemer committed
219 220
void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
{
221 222
	Dart newFace = agent->part_.d;

Pierre Kraemer's avatar
Pierre Kraemer committed
223
	popAgentInCells(agent, oldFace);
224 225
	pushAgentInCells(agent, newFace);

Pierre Kraemer's avatar
Pierre Kraemer committed
226
	if(!refineMark.isMarked(newFace) && agentvect[newFace].size() > nbAgentsToSubdivide)
227 228 229 230 231 232 233 234
	{
		std::pair<bool,bool>& sf = subdivisableFace[newFace];
		if(sf.first == false || (sf.first == true && sf.second))
		{
			refineMark.mark(newFace);
			refineCandidate.push_back(newFace);
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
235

Pierre Kraemer's avatar
Pierre Kraemer committed
236
	if(!coarsenMark.isMarked(oldFace) && !refineMark.isMarked(oldFace) && agentvect[oldFace].size() < nbAgentsToSimplify / 4)
Pierre Kraemer's avatar
Pierre Kraemer committed
237 238 239 240
	{
		coarsenMark.mark(oldFace);
		coarsenCandidate.push_back(map.faceOldestDart(oldFace));
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
241 242 243 244 245 246
}

void EnvMap::updateMap()
{
	assert(map.getCurrentLevel() == map.getMaxLevel()) ;

247
	for(std::vector<Dart>::iterator it = refineCandidate.begin(); it != refineCandidate.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
248
	{
249 250
		Dart d = (*it) ;
		refineMark.unmark(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
251

Pierre Kraemer's avatar
Pierre Kraemer committed
252
		if(agentvect[d].size() > nbAgentsToSubdivide)
Pierre Kraemer's avatar
Pierre Kraemer committed
253
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
254 255 256
			unsigned int fLevel = -1 ;
			Dart old = map.faceOldestDart(d) ;

257
			bool subdivisable = true ;
Pierre Kraemer's avatar
Pierre Kraemer committed
258

Pierre Kraemer's avatar
Pierre Kraemer committed
259
			std::pair<bool,bool>& sf = subdivisableFace[old] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
260 261
			if(sf.first == true)
				subdivisable = sf.second ;
262
			else
Pierre Kraemer's avatar
Pierre Kraemer committed
263
			{
Pierre Kraemer's avatar
Pierre Kraemer committed
264
				float minDistSq = Agent::neighborDistSq_ ; // diametre de vision de l'agent au carré
265

Pierre Kraemer's avatar
Pierre Kraemer committed
266
				fLevel = map.faceLevel(old) ;
267 268 269
				map.setCurrentLevel(fLevel) ;
				PFP::VEC3 fCenter = Algo::Geometry::faceCentroid<PFP>(map, old, position) ;
				Dart fd = old ;
Pierre Kraemer's avatar
Pierre Kraemer committed
270 271
				do
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
272
					PFP::VEC3& p = position[fd] ;
273
					PFP::VEC3 edge = Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
274
					PFP::VEC3 proj = fCenter - (p + (edge * (fCenter - p) / edge.norm2()) * edge) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
275
					if(proj.norm2() < minDistSq)
Pierre Kraemer's avatar
Pierre Kraemer committed
276
					{
277 278
						subdivisable = false ;
						break ;
Pierre Kraemer's avatar
Pierre Kraemer committed
279
					}
280 281 282 283
					fd = map.phi1(fd) ;
				} while(fd != old) ;
				map.setCurrentLevel(map.getMaxLevel()) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
284 285
				sf.first = true ;
				sf.second = subdivisable ;
286 287 288 289
			}

			if(subdivisable)
			{
Pierre Kraemer's avatar
Pierre Kraemer committed
290
				if(fLevel == -1)
Pierre Kraemer's avatar
Pierre Kraemer committed
291
					fLevel = map.faceLevel(old) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
292 293

				sf.first = false ;
294 295 296 297 298 299

				PFP::AGENTS oldAgents(agentvect[old]);
				for(PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
					popAgentInCells(*ait, old);

				neighborAgentvect[old].clear() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
300 301

				map.setCurrentLevel(fLevel) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
302
				CellMarkerStore newF(map, FACE);
303 304 305
				newF.mark(old);
				Algo::IHM::subdivideFace<PFP>(map, old, position) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
306
				map.setCurrentLevel(map.getMaxLevel()) ;
307 308 309 310 311
				for(PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
				{
					resetAgentInFace(*ait) ;
					pushAgentInCells(*ait, (*ait)->part_.d) ;
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
312

Pierre Kraemer's avatar
Pierre Kraemer committed
313 314
				unsigned int degree = 0 ;
				Dart dd = old ;
Pierre Kraemer's avatar
Pierre Kraemer committed
315 316
				do
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
317 318
					++degree ;
					Dart d3 = dd ;
319
					do
Pierre Kraemer's avatar
Pierre Kraemer committed
320
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
321 322
						Dart d4 = map.alpha1(map.alpha1(d3)) ;
						PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
323 324 325
						while(d4 != d3)
						{
							if(!newF.isMarked(d4))
Pierre Kraemer's avatar
Pierre Kraemer committed
326 327 328 329 330
							{
								PFP::AGENTS& ad4 = agentvect[d4] ;
								nad3.insert(nad3.end(), ad4.begin(), ad4.end()) ;
							}
							d4 = map.alpha1(d4) ;
331
						}
Pierre Kraemer's avatar
Pierre Kraemer committed
332 333
						d3 = map.phi1(d3) ;
					} while(d3 != dd) ;
334 335

					map.setCurrentLevel(fLevel) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
336
					dd = map.phi1(dd) ;
337 338 339 340 341
					map.setCurrentLevel(map.getMaxLevel()) ;
				} while(dd != old);

				if(degree == 3)
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
342 343
					Dart centerFace = map.phi2(map.phi1(old)) ;
					Dart d3 = centerFace ;
344 345
					do
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
346 347
						Dart d4 = map.alpha1(map.alpha1(d3)) ;
						PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
348 349 350
						while(d4 != d3)
						{
							if(!newF.isMarked(d4))
Pierre Kraemer's avatar
Pierre Kraemer committed
351 352 353 354 355
							{
								PFP::AGENTS& ad4 = agentvect[d4] ;
								nad3.insert(neighborAgentvect[d3].end(), ad4.begin(), ad4.end()) ;
							}
							d4 = map.alpha1(d4) ;
356
						}
Pierre Kraemer's avatar
Pierre Kraemer committed
357 358
						d3 = map.phi1(d3) ;
					} while(d3 != centerFace) ;
359
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
360 361 362
			}
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
363 364

	for(std::vector<Dart>::iterator it = coarsenCandidate.begin(); it != coarsenCandidate.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
365
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
366 367
		Dart old = (*it) ;
		coarsenMark.unmark(old) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
368

Pierre Kraemer's avatar
Pierre Kraemer committed
369 370
//		Dart old = map.faceOldestDart(d) ;
		unsigned int fLevel = map.faceLevel(old) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
371 372 373 374 375 376 377 378 379 380 381 382 383

		if(fLevel > 0 && map.getDartLevel(old) < fLevel)
		{
			unsigned int cur = map.getCurrentLevel() ;
			map.setCurrentLevel(fLevel - 1) ;

			if(map.faceIsSubdividedOnce(old))
			{
				unsigned int degree = 0 ;
				unsigned int nbAgents = 0 ;
				Dart fit = old ;
				do
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
384
					nbAgents += agentvect[fit].size() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
					++degree ;
					fit = map.phi1(fit) ;
				} while(fit != old) ;
				if(degree == 3)
				{
					map.setCurrentLevel(fLevel) ;
					Dart centerFace = map.phi2(map.phi1(old)) ;
					nbAgents += agentvect[centerFace].size() ;
					map.setCurrentLevel(fLevel - 1) ;
				}

				if(nbAgents < nbAgentsToSimplify)
				{
					PFP::AGENTS agents ;
					Dart fit = old ;
					do
					{
						map.setCurrentLevel(fLevel) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
403
						coarsenMark.unmark(fit) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
404
						std::vector<Dart>::iterator start = it + 1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
405
						unsigned int fEmb = map.getEmbedding(FACE, fit) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
406
						while(start != coarsenCandidate.end())
Pierre Kraemer's avatar
Pierre Kraemer committed
407
						{
Pierre Kraemer's avatar
Pierre Kraemer committed
408
							if(map.getEmbedding(FACE, *start) == fEmb)
Pierre Kraemer's avatar
Pierre Kraemer committed
409
							{
Pierre Kraemer's avatar
Pierre Kraemer committed
410 411
								*start = coarsenCandidate.back() ;
								coarsenCandidate.pop_back() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
412
							}
Pierre Kraemer's avatar
Pierre Kraemer committed
413 414
							else
								++start ;
Pierre Kraemer's avatar
Pierre Kraemer committed
415
						}
Pierre Kraemer's avatar
Pierre Kraemer committed
416 417 418
						PFP::AGENTS a(agentvect[fit]) ;
						agents.insert(agents.end(), a.begin(), a.end()) ;
						map.setCurrentLevel(map.getMaxLevel()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
419 420
						for(PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
							popAgentInCells(*ait, fit);
Pierre Kraemer's avatar
Pierre Kraemer committed
421 422 423 424 425 426 427 428
						map.setCurrentLevel(fLevel - 1) ;
						Dart nf = map.phi2(fit) ;
						if(!map.faceIsSubdivided(nf))
						{
							map.setCurrentLevel(fLevel) ;
							PFP::AGENTS& an = agentvect[nf] ;
							for(PFP::AGENTS::iterator ait = an.begin(); ait != an.end(); ++ait)
							{
Pierre Kraemer's avatar
Pierre Kraemer committed
429 430
								if((*ait)->part_.d == map.phi1(nf))
									(*ait)->part_.d = nf ;
Pierre Kraemer's avatar
Pierre Kraemer committed
431 432 433 434 435
							}
							map.setCurrentLevel(fLevel - 1) ;
						}
						fit = map.phi1(fit) ;
					} while(fit != old) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
436

Pierre Kraemer's avatar
Pierre Kraemer committed
437 438 439 440
					if(degree == 3)
					{
						map.setCurrentLevel(fLevel) ;
						Dart centerFace = map.phi2(map.phi1(old)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
441
						coarsenMark.unmark(centerFace) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
442
						std::vector<Dart>::iterator start = it + 1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
443
						unsigned int fEmb = map.getEmbedding(FACE, centerFace) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
444
						while(start != coarsenCandidate.end())
Pierre Kraemer's avatar
Pierre Kraemer committed
445
						{
Pierre Kraemer's avatar
Pierre Kraemer committed
446
							if(map.getEmbedding(FACE, *start) == fEmb)
Pierre Kraemer's avatar
Pierre Kraemer committed
447
							{
Pierre Kraemer's avatar
Pierre Kraemer committed
448 449
								*start = coarsenCandidate.back() ;
								coarsenCandidate.pop_back() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
450
							}
Pierre Kraemer's avatar
Pierre Kraemer committed
451 452
							else
								++start ;
Pierre Kraemer's avatar
Pierre Kraemer committed
453
						}
Pierre Kraemer's avatar
Pierre Kraemer committed
454 455 456
						PFP::AGENTS a(agentvect[centerFace]) ;
						agents.insert(agents.end(), a.begin(), a.end()) ;
						map.setCurrentLevel(map.getMaxLevel());
Pierre Kraemer's avatar
Pierre Kraemer committed
457 458
						for(PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
							popAgentInCells(*ait, centerFace);
Pierre Kraemer's avatar
Pierre Kraemer committed
459 460 461 462 463
						map.setCurrentLevel(fLevel - 1) ;
					}

					Algo::IHM::coarsenFace<PFP>(map, old, position) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
464 465 466
					std::pair<bool,bool>& sf = subdivisableFace[old] ;
					sf.first = true;
					sf.second = true;
Pierre Kraemer's avatar
Pierre Kraemer committed
467 468 469 470

					map.setCurrentLevel(map.getMaxLevel());

					agentvect[old].clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
471
					for(PFP::AGENTS::iterator it = agents.begin(); it != agents.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
472
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
473
						(*it)->part_.d = old ;
Pierre Kraemer's avatar
Pierre Kraemer committed
474 475
						pushAgentInCells(*it, old);
					}
Pierre Kraemer's avatar
Pierre Kraemer committed
476

Pierre Kraemer's avatar
Pierre Kraemer committed
477 478 479 480 481 482 483 484 485 486 487
					Dart dd = old;
					do
					{
						Dart ddd = map.alpha1(map.alpha1(dd));
						while(ddd != dd)
						{
							neighborAgentvect[old].insert(neighborAgentvect[old].end(), agentvect[ddd].begin(), agentvect[ddd].end());
							ddd = map.alpha1(ddd);
						}
						dd = map.phi1(dd);
					} while(dd != old);
Pierre Kraemer's avatar
Pierre Kraemer committed
488

Pierre Kraemer's avatar
Pierre Kraemer committed
489 490 491 492 493
				}
			}
			map.setCurrentLevel(cur) ;
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
494

Pierre Kraemer's avatar
Pierre Kraemer committed
495 496 497 498 499 500 501
	map.setCurrentLevel(map.getMaxLevel()) ;
}

void EnvMap::resetAgentInFace(Agent* agent)
{
	VEC3 pos = agent->part_.m_position;
	agent->part_.m_position = Algo::Geometry::faceCentroid<PFP>(map, agent->part_.d, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
502
	agent->part_.state = FACE;
Pierre Kraemer's avatar
Pierre Kraemer committed
503 504
	agent->part_.move(pos);
}