env_map.cpp 35.8 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
#include "env_map.h"
#include "utils.h"
#include "agent.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
4
#include "obstacle.h"
5 6
#include "moving_obstacle.h"
#include "simulator.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
7

Pierre Kraemer's avatar
Pierre Kraemer committed
8 9
#include "Geometry/inclusion.h"
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
10
#include "Algo/Modelisation/subdivision.h"
Jund Thomas's avatar
Jund Thomas committed
11
#include "Algo/Modelisation/triangulation.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
12
#include "Algo/Geometry/normal.h"
Thomas's avatar
Thomas committed
13 14
#include "Algo/Import/importSvg.h"
#include "Algo/BooleanOperator/mergeVertices.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
15

Thomas Jund's avatar
Thomas Jund committed
16 17
#include "Topology/generic/mapBrowser.h"

18 19
#include "env_generator.h"

20
using namespace CGoGN ;
Pierre Kraemer's avatar
Pierre Kraemer committed
21

Pierre Kraemer's avatar
Pierre Kraemer committed
22
EnvMap::EnvMap() :
David Cazier's avatar
David Cazier committed
23
	obstacleDistance(Agent::range_),
David Cazier's avatar
David Cazier committed
24 25 26 27 28
	obstacleMarkS(mapScenary),
	buildingMarkS(mapScenary),
	obstacleMark(map),
	buildingMark(map),
	pedWayMark(map),
29

Pierre Kraemer's avatar
Pierre Kraemer committed
30
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
31 32
	refineMark(map),
	coarsenMark(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
33
#else
David Cazier's avatar
David Cazier committed
34 35 36
	ht_agents(1024),
	ht_neighbor_agents(1024),
	ht_obstacles(1024)
Pierre Kraemer's avatar
Pierre Kraemer committed
37
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
38
{
David Cazier's avatar
David Cazier committed
39 40
	position = map.addAttribute<VEC3, VERTEX>("position") ;
	normal = map.addAttribute<VEC3, VERTEX>("normal") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
41

Jund Thomas's avatar
Jund Thomas committed
42
	positionScenary = mapScenary.addAttribute<VEC3, VERTEX>("position") ;
Jund Thomas's avatar
Jund Thomas committed
43
	normalScenary = mapScenary.addAttribute<VEC3, VERTEX>("normal") ;
Jund Thomas's avatar
Jund Thomas committed
44

Pierre Kraemer's avatar
Pierre Kraemer committed
45
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
46 47 48 49 50
	agentvect = map.addAttribute<PFP::AGENTVECT, FACE>("agents") ;
	neighborAgentvect = map.addAttribute<PFP::AGENTVECT, FACE>("neighborAgents") ;
	obstvect = map.addAttribute<PFP::OBSTACLEVECT, FACE>("obstacles") ;
	neighborObstvect = map.addAttribute<PFP::OBSTACLEVECT, FACE>("neighborObstacles") ;
	subdivisableFace = map.addAttribute<PFP::BOOLATTRIB, FACE>("subdivisableFace") ;
Thomas's avatar
Thomas committed
51

52 53 54 55 56 57 58 59
	refineCandidate.reserve(100) ;
	coarsenCandidate.reserve(100) ;
#endif
}

void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, REAL maxSize)
{
	std::cout << "Init EnvMap" << std::endl ;
David Cazier's avatar
David Cazier committed
60
	VEC3 bottomLeft(-width / 2, -height / 2, 0.0f) ;
61 62 63 64 65 66 67 68
	VEC3 topRight(width / 2, height / 2, 0.0f) ;

	geometry.reset() ;
	geometry.addPoint(bottomLeft) ;
	geometry.addPoint(topRight) ;
	minCellSize = minSize ;
	maxCellSize = maxSize ;
	std::cout << " - Geometry : " << geometry ;
pitiot's avatar
pitiot committed
69
	std::cout << " - Geometry size : " << geometry.size(0)<<" x "<<geometry.size(1) ;
70 71
	std::cout << " - Cell size between : " << minSize << " and " << maxSize << std::endl ;
#ifdef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
72
	std::cout << " - Table de hachage : " << agentGridSize(0) << " x " << agentGridSize(1) << std::endl ;
73 74
#endif

David Cazier's avatar
David Cazier committed
75 76
	switch (config)
	{
David Cazier's avatar
David Cazier committed
77
		case 0 :
pitiot's avatar
merging  
pitiot committed
78
//			CityGenerator::generateGrid<PFP>(*this) ;
79
			CityGenerator::generateCity<PFP>(*this,0) ;
David Cazier's avatar
David Cazier committed
80 81
			break ;
		case 1 :
Thomas Jund's avatar
Thomas Jund committed
82 83
//			CityGenerator::generateGrid<PFP>(*this) ;
			CityGenerator::generateTrianGrid<PFP>(*this,obstacleMark, buildingMark);
David Cazier's avatar
David Cazier committed
84 85
			break ;
		case 2 :
pitiot's avatar
merging  
pitiot committed
86
			CityGenerator::generateGrid<PFP>(*this) ;
David Cazier's avatar
David Cazier committed
87 88
			// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
			break ;
Jund Thomas's avatar
Jund Thomas committed
89
		case 3 :
pitiot's avatar
merging  
pitiot committed
90
			CityGenerator::generateCity<PFP>(*this,10) ;
Jund Thomas's avatar
Jund Thomas committed
91 92 93 94 95 96
			break ;
		case 4 :
			CityGenerator::generatePlanet<PFP>(*this) ;
			break ;
		case 5 :
		{
Jund Thomas's avatar
Jund Thomas committed
97
			std::cout << "?" << std::endl;
Jund Thomas's avatar
Jund Thomas committed
98
//			std::string filename = "./svg/planet.svg" ;
99
			std::string filename = "./svg/mapRoads.svg" ;
Jund Thomas's avatar
Jund Thomas committed
100
//			std::string filename = "./svg/simpleCross.svg" ;
101
			Algo::Surface::Import::importSVG<PFP>(map, filename, position, obstacleMark, buildingMark) ;
Jund Thomas's avatar
Jund Thomas committed
102

Thomas Jund's avatar
Thomas Jund committed
103 104
			std::string filename2 = "./svg/mapBuild.svg" ;
			Algo::Surface::Import::importSVG<PFP>(mapScenary, filename2, positionScenary, obstacleMarkS, buildingMarkS) ;
Jund Thomas's avatar
Jund Thomas committed
105

Arash HABIBI's avatar
Arash HABIBI committed
106
			Geom::BoundingBox<PFP::VEC3> bb1, bb2 ;
Jund Thomas's avatar
Jund Thomas committed
107
			bb1 = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
Thomas Jund's avatar
Thomas Jund committed
108 109 110
			bb2 = Algo::Geometry::computeBoundingBox<PFP>(mapScenary, positionScenary) ;
			bb1.addPoint(bb2.min());
			bb1.addPoint(bb2.max());
Jund Thomas's avatar
Jund Thomas committed
111

112 113
//			CityGenerator::planetify<PFP>(map, position, 100.0f, bb1);
//			CityGenerator::planetify<PFP>(mapScenary, positionScenary, 100.0f, bb1);
Jund Thomas's avatar
Jund Thomas committed
114 115

			std::vector<Dart> v;
Jund Thomas's avatar
Jund Thomas committed
116 117 118
			TraversorF<PFP::MAP> tF(mapScenary);
			for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next())
			{
Jund Thomas's avatar
Jund Thomas committed
119 120 121 122 123 124 125 126 127
				v.push_back(d);
			}

			std::cout << "builds " << v.size() << std::endl;

			for(std::vector<Dart>::iterator it = v.begin() ; it != v.end() ; it++)
			{
				Dart d = *it;

Jund Thomas's avatar
Jund Thomas committed
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
				//test if convex
				bool convex=true;

				Dart dd = mapScenary.phi1(d);
				Dart dN = mapScenary.phi1(dd);
				Dart dNN = mapScenary.phi1(dN);

				VEC3 p1, p2, p3, v1, v2;
				p1 = positionScenary[dd];
				p2 = positionScenary[dN];
				p3 = positionScenary[dNN];

				v1 = VEC3(p2-p1);
				v2 = VEC3(p3-p2);

				float sign = (v1^v2)[2];

				while(convex && dd!=d)
				{
					dd=dN;
					dN = dNN;
					dNN = mapScenary.phi1(dNN);

					p1 = positionScenary[dd];
					p2 = positionScenary[dN];
					p3 = positionScenary[dNN];

					v1 = VEC3(p2-p1);
					v2 = VEC3(p3-p2);

					float sign2 = (v1^v2)[2];
					if((sign<0 && sign2>0) || (sign>0 && sign2<0))
							convex=false;
				}

				//make extrusion/roof/..
				if(convex)
				{
166
					if(Algo::Surface::Geometry::convexFaceArea<PFP>(mapScenary, d, positionScenary)<20.0f) //if big enough create building with "stairs"
Jund Thomas's avatar
Jund Thomas committed
167 168 169 170 171 172 173 174 175 176 177
						CityGenerator::extrudeBuilding<PFP>(mapScenary,positionScenary, d,1+rand()%2,10.0f*(1.0f+rand()/RAND_MAX));
					else //create building with simple roof
						CityGenerator::extrudeBuilding<PFP>(mapScenary,positionScenary, d,3,10.0f*(1.0f+rand()/RAND_MAX));
				}
				else //building with no roof
				{
					CityGenerator::extrudeBuilding<PFP>(mapScenary,positionScenary, d,0,5.0f+5.0f*(1.0f+2.0f*rand()/RAND_MAX));
				}
			}

			//triangulation for rendering
178
			Algo::Surface::Modelisation::EarTriangulation<PFP> et(mapScenary);
Jund Thomas's avatar
Jund Thomas committed
179 180
			et.triangule();

181 182
//			Algo::Modelisation::EarTriangulation<PFP> et2(map);
//			et2.triangule();
Jund Thomas's avatar
Jund Thomas committed
183

Jund Thomas's avatar
Jund Thomas committed
184
			//subdivision to create footpath
Sylvain Thery's avatar
Sylvain Thery committed
185
			MapBrowserSelector mbs(map, SelectorDartNoBoundary<PFP::MAP>(map));
Thomas Jund's avatar
Thomas Jund committed
186
			map.setBrowser(&mbs);
Sylvain Thery's avatar
Sylvain Thery committed
187
			Algo::Surface::Modelisation::TwoNPlusOneSubdivision<PFP,PFP::TVEC3, VEC3>(map,position);
Sylvain Thery's avatar
Sylvain Thery committed
188
			map.setBrowser(NULL);
189 190
			markPedWay();

191
			scale(20.0f);
David Cazier's avatar
David Cazier committed
192
		}
Jund Thomas's avatar
Jund Thomas committed
193
		break;
194 195 196 197 198 199 200 201 202
	}

//	CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
//	CityGenerator::convexifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
//	CityGenerator::installGuardRail<PFP>(map, position, obstacleMark, buildingMark, 5.0f);

#ifndef SPATIAL_HASHING
	map.init() ;
//	registerObstaclesInFaces();
David Cazier's avatar
David Cazier committed
203 204
	// TODO Check registerWallInFaces();
	registerWallInFaces() ;
205 206
//	subdivideAllToMaxLevel();

207
	for (unsigned int i = subdivisableFace.begin(); i < subdivisableFace.end(); subdivisableFace.next(i))
208
		subdivisableFace[i].first = false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
209
#endif
210

Thomas Jund's avatar
Thomas Jund committed
211 212 213 214 215 216 217 218 219 220 221
	if(!normal.isValid())
		normal = map.addAttribute<PFP::VEC3, VERTEX>("normal") ;

	Algo::Surface::Geometry::computeNormalVertices<PFP>(map, position, normal) ;

	if(config==5 && !normalScenary.isValid())
	{
		normalScenary = mapScenary.addAttribute<PFP::VEC3, VERTEX>("normal") ;

		Algo::Surface::Geometry::computeNormalVertices<PFP>(mapScenary, positionScenary, normalScenary) ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
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 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 308 309 310 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 378 379
void EnvMap::initGL()
{
#ifdef EXPORTING3
	PFP::MAP * nmap = new PFP::MAP();

	std::vector<std::string> attrNames ;
	Algo::Surface::Import::OBJModel<PFP2> * obj = new Algo::Surface::Import::OBJModel<PFP2>(*nmap);
	obj->import("./meshRessources/cityTex/Building11.obj",attrNames);

	VertexAttribute<VEC3> position_Export = nmap->getAttribute<VEC3, VERTEX>(attrNames[0]) ;
	TraversorV<PFP2::MAP> tV(*nmap);
	for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
	{
		position_Export[d] *= 100.0f;
		position_Export[d] += VEC3(2000,0,0);
	}

	Utils::VBO * texcoordVBO = new Utils::VBO();
	Utils::VBO * positionVBO = new Utils::VBO();
	Utils::VBO * normalVBO = new Utils::VBO();

	Utils::Texture<2,Geom::Vec3uc> * texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);

	if (texture->load("./meshRessources/cityTex/AO_Buildings11.png"))
			texture->update();
	else
		std::cout << "problem : loading texture" << std::endl;

	texture->setWrapping(GL_CLAMP_TO_EDGE);

	ShaderCustomTex * shaderTex = new ShaderCustomTex();
	shaderTex->setAttributePosition(positionVBO);
	shaderTex->setAttributeTexCoord(texcoordVBO);
	shaderTex->setTextureUnit(GL_TEXTURE0);
	shaderTex->setTexture(texture);

	glEnable(GL_TEXTURE_2D);

	nmap->setBrowser(NULL);

	if (!obj->hasNormals())
	{
		VertexAttribute<VEC3> normal = nmap->getAttribute<VEC3, VERTEX>("normal") ;
		if(!normal.isValid())
			normal = nmap->addAttribute<VEC3, VERTEX>("normal") ;

		Algo::Surface::Geometry::computeNormalVertices<PFP2>(*nmap, obj->m_positions, normal) ;
		obj->setNormalAttribute(normal);
	}

	unsigned int nbIndices = obj->createSimpleVBO_PTN(positionVBO,texcoordVBO,normalVBO);

	m_map_Export.push_back(nmap);
	m_obj_Export.push_back(obj);

	m_texture_Export.push_back(texture);
	m_texcoordVBO_Export.push_back(texcoordVBO);
	m_positionVBO_Export.push_back(positionVBO);
	m_normalVBO_Export.push_back(normalVBO);
	m_shaderTex_Export.push_back(shaderTex);

	m_nbIndice_Export.push_back(nbIndices);

//	m_map_Export = new PFP2::MAP();
//
//	std::vector<std::string> attrNames ;
//	m_obj_Export = new Algo::Surface::Import::OBJModel<PFP2>(m_map_Export);
//	m_obj_Export->import("./meshRessources/cityTex/Building11.obj",attrNames);
//
//	position_Export = m_map_Export.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
//	TraversorV<PFP2::MAP> tV(m_map_Export);
//
//	VEC3 bary(0);
//	unsigned int count = 0;
//	for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
//	{
//		bary += position_Export[d];
//		count++;
//	}
//	bary /= float(count);
//
//	for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
//	{
////		position_Export[d] -= bary;
//		position_Export[d] *= 100.0f;
//		std::cout << position_Export[d] << std::endl;
//		position_Export[d] += VEC3(2000,0,0);
//		std::cout << position_Export[d] << std::endl;
//	}
//
//	m_texcoordVBO_Export = new Utils::VBO();
//	m_positionVBO_Export = new Utils::VBO();
//	m_normalVBO_Export = new Utils::VBO();
//
//	m_texture_Export = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
//
//	if (m_texture_Export->load("./meshRessources/cityTex/AO_Buildings11.png"))
//		m_texture_Export->update();
//	else
//		std::cout << "problem : loading texture" << std::endl;
//
//	m_texture_Export->setWrapping(GL_CLAMP_TO_EDGE);
//
//	m_shaderTex_Export = new ShaderCustomTex();
//	m_shaderTex_Export->setAttributePosition(m_positionVBO_Export);
//	m_shaderTex_Export->setAttributeTexCoord(m_texcoordVBO_Export);
//	m_shaderTex_Export->setTextureUnit(GL_TEXTURE0);
//	m_shaderTex_Export->setTexture(m_texture_Export);
//
//	glEnable(GL_TEXTURE_2D);
//
//	m_map_Export.setBrowser(NULL);
//
//	if (!m_obj_Export->hasNormals())
//	{
//		normal_Export  = m_map_Export.getAttribute<VEC3, VERTEX>("normal") ;
//		if(!normal_Export.isValid())
//			normal_Export = m_map_Export.addAttribute<VEC3, VERTEX>("normal") ;
//
//		Algo::Surface::Geometry::computeNormalVertices<PFP2>(m_map_Export, m_obj_Export->m_positions, normal_Export) ;
//		m_obj_Export->setNormalAttribute(normal_Export);
//	}
//
//	m_nbIndice_Export = m_obj_Export->createSimpleVBO_PTN(m_positionVBO_Export,m_texcoordVBO_Export,m_normalVBO_Export);
#endif
}

void EnvMap::draw()
{
#ifdef EXPORTING3
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	for(unsigned int i = 0 ; i < m_obj_Export.size() ; ++i)
	{
		unsigned int nbIndices = m_obj_Export[i]->createSimpleVBO_PTN( m_positionVBO_Export[i], m_texcoordVBO_Export[i], m_normalVBO_Export[i]);

		m_shaderTex_Export[i]->activeTexture();
		m_shaderTex_Export[i]->enableVertexAttribs();
//		glDrawArrays(GL_TRIANGLES, 0, m_nbIndice_Export[i]);
		glDrawArrays(GL_TRIANGLES, 0, nbIndices);
		m_shaderTex_Export[i]->disableVertexAttribs();
	}
//glDisable(GL_LIGHTING);
//	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//
//	unsigned int nbIndices = m_obj_Export->createSimpleVBO_PTN( m_positionVBO_Export, m_texcoordVBO_Export, m_normalVBO_Export);
//
//	m_shaderTex_Export->activeTexture();
//	m_shaderTex_Export->enableVertexAttribs();
//	glDrawArrays(GL_TRIANGLES, 0, m_nbIndice_Export);
//	m_shaderTex_Export->disableVertexAttribs();
//
//glEnable(GL_LIGHTING);
#endif
}

380 381 382 383 384 385 386 387 388 389 390 391
void EnvMap::scale(float val)
{
	TraversorV<PFP::MAP> tV(map);
	for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
		position[d] *= val;

	TraversorV<PFP::MAP> tV2(mapScenary);
	for(Dart d = tV2.begin() ; d != tV2.end() ; d = tV2.next())
		positionScenary[d] *= val;

}

392 393
void EnvMap::markPedWay()
{
David Cazier's avatar
David Cazier committed
394
	CellMarker<FACE> treat(map) ;
David Cazier's avatar
David Cazier committed
395 396 397 398
	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (!treat.isMarked(d))
		{
399 400 401
			treat.mark(d) ;

			Dart dd = d ;
David Cazier's avatar
David Cazier committed
402 403
			do
			{
404
				Dart ddd = dd ;
David Cazier's avatar
David Cazier committed
405 406 407 408
				do
				{
					if (obstacleMark.isMarked(dd))
					{
409 410
						pedWayMark.mark(d) ;
						break ;
411
					}
412 413
					ddd = map.alpha1(ddd) ;
				} while (ddd != dd) ;
414

415
				dd = map.phi1(dd) ;
416

417
			} while (dd != d) ;
418 419 420
		}
	}

421
	treat.unmarkAll() ;
David Cazier's avatar
David Cazier committed
422 423 424 425
	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (!treat.isMarked(d))
		{
426 427 428
			treat.mark(d) ;

			Dart dd = d ;
David Cazier's avatar
David Cazier committed
429 430 431 432 433 434
			do
			{
				if (pedWayMark.isMarked(map.phi2(dd)) && pedWayMark.isMarked(map.phi2(map.phi1(dd)))
				    && !pedWayMark.isMarked(map.phi2(map.phi1(map.phi1(dd))))
				    && !pedWayMark.isMarked(map.phi2(map.phi1(map.phi1(map.phi1(dd))))))
				{
435 436 437
					pedWayMark.mark(d) ;
					break ;
				}
438

439
				dd = map.phi1(dd) ;
440

441
			} while (dd != d) ;
442 443 444 445
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
446 447
unsigned int EnvMap::mapMemoryCost()
{
David Cazier's avatar
David Cazier committed
448 449 450 451
	return (map.getAttributeContainer<DART>()).memorySize()
	    + (map.getAttributeContainer<VERTEX>()).memorySize()
	    + (map.getAttributeContainer<EDGE>()).memorySize()
	    + (map.getAttributeContainer<FACE>()).memorySize() ;
Thomas's avatar
Thomas committed
452 453
}

Pierre Kraemer's avatar
Pierre Kraemer committed
454
#ifndef SPATIAL_HASHING
Thomas's avatar
Thomas committed
455 456
void EnvMap::subdivideAllToMaxLevel()
{
457
	bool subdiv ;
David Cazier's avatar
David Cazier committed
458 459
	do
	{
460
		subdiv = false ;
Thomas's avatar
Thomas committed
461
		{
David Cazier's avatar
David Cazier committed
462
			CellMarker<FACE> subd(map) ;
David Cazier's avatar
David Cazier committed
463 464 465 466
			for (Dart d = map.begin(); d != map.end(); map.next(d))
			{
				if (!subd.isMarked(d))
				{
467
					subd.mark(d) ;
David Cazier's avatar
David Cazier committed
468 469
					if (!buildingMark.isMarked(d))
					{
Thomas's avatar
Thomas committed
470 471
						//check if subdivision is authorized
						float minDistSq = Agent::neighborDistSq_ ;
472
						bool subdivisable = true ;
Thomas's avatar
Thomas committed
473 474 475
						Dart old = map.faceOldestDart(d) ;
						unsigned int fLevel = map.faceLevel(old) ;
						map.setCurrentLevel(fLevel) ;
476
						PFP::VEC3 fCenter = Algo::Surface::Geometry::faceCentroid<PFP>(map, old, position) ;
Thomas's avatar
Thomas committed
477
						Dart fd = old ;
David Cazier's avatar
David Cazier committed
478 479
						do
						{
Thomas's avatar
Thomas committed
480
							PFP::VEC3& p = position[fd] ;
481
							PFP::VEC3 edge = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map, fd,
David Cazier's avatar
David Cazier committed
482
							                                                      position) ;
483
							PFP::VEC3 proj = fCenter
David Cazier's avatar
David Cazier committed
484 485 486
							    - (p + (edge * (fCenter - p) / edge.norm2()) * edge) ;
							if (proj.norm2() < minDistSq)
							{
Thomas's avatar
Thomas committed
487 488 489 490
								subdivisable = false ;
								break ;
							}
							fd = map.phi1(fd) ;
491
						} while (fd != old) ;
Thomas's avatar
Thomas committed
492

David Cazier's avatar
David Cazier committed
493 494
						if (subdivisable)
						{
Thomas's avatar
Thomas committed
495
							map.setCurrentLevel(fLevel) ;
496
							Algo::Surface::IHM::subdivideFace<PFP>(map, old, position) ;
497
							subdiv = true ;
Thomas's avatar
Thomas committed
498 499 500 501 502 503
						}
						map.setCurrentLevel(map.getMaxLevel()) ;
					}
				}
			}
		}
504
	} while (subdiv) ;
Thomas's avatar
Thomas committed
505 506 507 508
}

void EnvMap::subdivideToProperLevel()
{
509
	bool subdiv ;
David Cazier's avatar
David Cazier committed
510 511
	do
	{
512
		subdiv = false ;
Thomas's avatar
Thomas committed
513
		{
David Cazier's avatar
David Cazier committed
514
			CellMarker<FACE> subd(map) ;
David Cazier's avatar
David Cazier committed
515 516 517 518
			for (Dart d = map.begin(); d != map.end(); map.next(d))
			{
				if (!subd.isMarked(d))
				{
519
					subd.mark(d) ;
David Cazier's avatar
David Cazier committed
520 521
					if (!refineMark.isMarked(d) && agentvect[d].size() > nbAgentsToSubdivide)
					{
522
						std::pair<bool, bool>& sf = subdivisableFace[d] ;
David Cazier's avatar
David Cazier committed
523 524
						if (sf.first == false || (sf.first == true && sf.second))
						{
525 526 527
							subdiv = true ;
							refineMark.mark(d) ;
							refineCandidate.push_back(d) ;
Thomas's avatar
Thomas committed
528 529 530 531
						}
					}
				}
			}
532
			subd.unmarkAll() ;
Thomas's avatar
Thomas committed
533
		}
534 535 536 537
		updateMap() ;
		refineCandidate.clear() ;
		map.setCurrentLevel(map.getMaxLevel()) ;
	} while (subdiv) ;
Thomas's avatar
Thomas committed
538 539
}

Pierre Kraemer's avatar
Pierre Kraemer committed
540 541
Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
{
pitiot's avatar
...  
pitiot committed
542
//	assert(map.getCurrentLevel() == map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
543

David Cazier's avatar
David Cazier committed
544
	CellMarkerStore<FACE> m(map) ;
David Cazier's avatar
David Cazier committed
545 546 547 548
	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (!m.isMarked(d))
		{
549
			m.mark(d) ;
pitiot's avatar
pitiot committed
550
			if (!buildingMark.isMarked(d)
551
			    && Algo::Surface::Geometry::isPointInConvexFace2D<PFP>(map, d, position, pos, true)) return d ;
552
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
553 554
	}

555
	std::cout << "ERROR : pos not in map for getBelongingCell " << pos << std::endl ;
556
	return map.begin() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
557
}
Pierre Kraemer's avatar
Pierre Kraemer committed
558
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
559

Pierre Kraemer's avatar
Pierre Kraemer committed
560
#ifndef SPATIAL_HASHING
Pierre Kraemer's avatar
Pierre Kraemer committed
561 562
void EnvMap::foreach_neighborFace(Dart d, FunctorType& f)
{
563
	Dart dd = d ;
David Cazier's avatar
David Cazier committed
564 565
	do
	{
566
		Dart ddd = map.alpha1(map.alpha1(dd)) ;
David Cazier's avatar
David Cazier committed
567 568
		while (ddd != dd)
		{
569 570
			f(ddd) ;
			ddd = map.alpha1(ddd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
571
		}
572 573
		dd = map.phi1(dd) ;
	} while (dd != d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
574 575
}

David Cazier's avatar
David Cazier committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
// TODO Check void EnvMap::registerWallInFaces() boundary markers ?
void EnvMap::registerWallInFaces()
{
	CellMarker<FACE> m(map) ;
	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (!m.isMarked(d))
		{
			m.mark(d) ;

			Dart dd = d ;

			//retrieve all obstacles within its one-ring

			//first : test all edges of the face of d
			do
			{
593
				if (obstacleMark.isMarked(dd) && map.isBoundaryMarked2(dd))
David Cazier's avatar
David Cazier committed
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
				{
					Dart dd2 = map.phi2(dd) ;
					Dart next = map.phi1(dd2) ;
					Dart previous = map.phi_1(dd2) ;
					Obstacle* o = new Obstacle(position[next], position[dd2], position[previous],
					                           position[map.phi1(next)], NULL, 0) ;
					obstvect[dd2].push_back(o) ;
				}
				dd = map.phi1(dd) ;
			} while (dd != d) ;

//				//second : test all edges of neighboring faces
//				do
//				{
//					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);
		}
	}

}

Pierre Kraemer's avatar
Pierre Kraemer committed
622 623
void EnvMap::registerObstaclesInFaces()
{
David Cazier's avatar
David Cazier committed
624
	CellMarker<FACE> m(map) ;
David Cazier's avatar
David Cazier committed
625 626 627 628
	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (!m.isMarked(d))
		{
629
			m.mark(d) ;
David Cazier's avatar
David Cazier committed
630 631
			if (!buildingMark.isMarked(d))
			{
632
				Dart dd = d ;
633 634 635 636

				//retrieve all obstacles within its one-ring

				//first : test all edges of the face of d
David Cazier's avatar
David Cazier committed
637 638 639 640
				do
				{
					if (obstacleMark.isMarked(dd))
					{
641 642 643 644
						Dart dd2 = map.phi2(dd) ;
						Dart next = map.phi1(dd2) ;
						Dart previous = map.phi_1(dd2) ;
						Obstacle* o = new Obstacle(position[dd2], position[next],
David Cazier's avatar
David Cazier committed
645 646
						                           position[previous], position[map.phi1(next)],
						                           NULL, 0) ;
647
						obstvect[d].push_back(o) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
648
					}
649 650
					dd = map.phi1(dd) ;
				} while (dd != d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
651

652
				//second : test all edges of neighboring faces
David Cazier's avatar
David Cazier committed
653 654
				do
				{
655
					Dart ddd = map.alpha1(map.alpha1(dd)) ;
David Cazier's avatar
David Cazier committed
656 657
					while (ddd != dd)
					{
David Cazier's avatar
David Cazier committed
658
						// TODO Check effet de bord
David Cazier's avatar
David Cazier committed
659 660
						if (!buildingMark.isMarked(ddd)) addNeighborObstacles(
						    obstvect[d], ddd, ddd == map.alpha_1(dd)) ;
661
						ddd = map.alpha1(ddd) ;
662
					}
663 664
					dd = map.phi1(dd) ;
				} while (dd != d) ;
665 666 667
			}
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
668 669 670 671
}

void EnvMap::addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbor)
{
672
	Dart stop ;
David Cazier's avatar
David Cazier committed
673 674 675 676
	if (edgeNeighbor)
		stop = map.phi_1(map.phi_1(map.phi_1(d))) ;
	else
		stop = map.phi_1(map.phi_1(d)) ;
677 678

	Dart dd = d ;
David Cazier's avatar
David Cazier committed
679 680 681 682
	do
	{
		if (obstacleMark.isMarked(dd))
		{
683 684 685 686 687 688 689 690 691 692
//			if(buildingMark.isMarked(dd))
//			{
//				std::cout << "caca prout" << std::endl;
//				Dart next = map.phi1(dd);
//				Dart previous = map.phi_1(dd);
//				Obstacle* o = new Obstacle(position[dd], position[next], position[previous], position[map.phi1(next)]);
//				obst.push_back(o);
//			}
//			else
//			{
693 694 695 696
			Dart dd2 = map.phi2(dd) ;
			Dart next = map.phi1(dd2) ;
			Dart previous = map.phi_1(dd2) ;
			Obstacle* o = new Obstacle(position[dd2], position[next], position[previous],
David Cazier's avatar
David Cazier committed
697
			                           position[map.phi1(next)], NULL, 0) ;
698
			obst.push_back(o) ;
699
//			}
Pierre Kraemer's avatar
Pierre Kraemer committed
700
		}
701 702
		dd = map.phi1(dd) ;
	} while (dd != stop) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
703 704
}

705 706 707 708 709 710 711 712 713 714
void EnvMap::pushObstacleInCells(Obstacle * o)// réenregistre l'obstacle en question
{
	MovingObstacle * mo = o->mo;
	if (mo != NULL)
	{
		int n = o->index;

		Dart d1=NIL;
		Dart d2=NIL;
		std::vector<Dart> memo;
715
		memo = mo->getMemoCross(o->p1,o->p2,d1);
716 717 718 719 720 721 722 723 724 725 726 727 728
		d2=mo->registering_part->d;

		if(map.sameFace(d1,d2))
		{
			pushObstacleInOneRingCells(o , d1 , n);
		}
		else
		{
			pushObstacleInCells(o, n, memo);
		}
	}
}

Thomas Jund's avatar
Thomas Jund committed
729
Dart EnvMap::popAndPushObstacleInCells(Obstacle* o, int n)// maj de l'enregistrement
730 731 732 733 734 735 736 737 738 739 740 741
{
	MovingObstacle * mo = o->mo;

	Dart d1=NIL;
	Dart d2=NIL;
	std::vector<Dart> memo;

//	bool modif=false;

//	if(p1->crossCell != CGoGN::Algo::MovingObjects::NO_CROSS
//		|| p2->crossCell != CGoGN::Algo::MovingObjects::NO_CROSS)
//	{
742
		memo = mo->getMemoCross(o->p1,o->p2,d1);
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
		d2=mo->registering_part->d;
//		memo.sort();
//		modif=true;
//	}
//	else if(!map.sameFace(p1->d,p2->d))
//	{
//		memo = getMemoCross(p1,p2->getPosition());
//		memo.sort();
//	 	if(belonging_cells[n] != memo)
//			modif=true;
//	}
//
//	if(modif)
	{
		popObstacleInCells(o, n);

		if(map.sameFace(d1,d2))
		{
			pushObstacleInOneRingCells(o , d1 , n);
		}
		else
		{
			pushObstacleInCells(o, n, memo);
		}
	}
Thomas Jund's avatar
Thomas Jund committed
768 769

	return d1;
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
}

void EnvMap::pushObstacleInOneRingCells(Obstacle * o, Dart d, int n)
{
	MovingObstacle * mo = o->mo;

	assert(map.getCurrentLevel() == map.getMaxLevel());

	addElementToVector<Obstacle*>(obstvect[d],o);

	mo->belonging_cells[n].clear();
	mo->belonging_cells[n].push_back(d);
	mo->neighbor_cells[n].clear();

	Dart dd = d;
	do
	{
		Dart ddd = map.alpha1(map.alpha1(dd));
		while(ddd != dd)
		{
			pushObstNeighborInCells(o, ddd);

			mo->neighbor_cells[n].push_back(ddd);
			ddd = map.alpha1(ddd);
		}
		dd = map.phi1(dd);
	} while(dd != d);
}

void EnvMap::pushObstacleInCells(Obstacle* o, int n, const std::vector<Dart>& memo_cross)
{
	if(memo_cross.empty())
	{
		displayMO(o);
	}
	assert(!memo_cross.empty());
	MovingObstacle * mo = o->mo;

	mo->belonging_cells[n].clear();
	mo->belonging_cells[n] = memo_cross;

	for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin();	it != mo->belonging_cells[n].end(); ++it)
	{
		//		 CGoGNout <<"obstacle"<< o->p1 << "new cell : "<< *it << CGoGNendl;
		addElementToVector<Obstacle*>(obstvect[*it],o);
	}

	addObstAsNeighbor(o, mo->belonging_cells[n], &(mo->neighbor_cells[n]));

	for (std::vector<Dart>::iterator it = mo->neighbor_cells[n].begin(); it != mo->neighbor_cells[n].end(); ++it)
	{
		//		 CGoGNout <<"obstacle"<< o->p1 << "new cell : "<< *it << CGoGNendl;
Jund Thomas's avatar
Jund Thomas committed
822 823
		addElementToVector<Obstacle*>(neighborObstvect[*it],o);
//		pushObstNeighborInCells(o, *it);
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
	}
}

void EnvMap::popObstacleInCells(Obstacle* o, int n)
{
	MovingObstacle * mo = o->mo;

	assert(map.getCurrentLevel() == map.getMaxLevel()) ;

	if (mo != NULL)
	{
		for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin();	it != mo->belonging_cells[n].end(); ++it)
		{
			removeElementFromVector<Obstacle*>(obstvect[*it], o) ;
		}

		for (std::vector<Dart>::iterator it = mo->neighbor_cells[n].begin(); it != mo->neighbor_cells[n].end(); ++it)
		{
			removeElementFromVector<Obstacle*>(neighborObstvect[*it], o) ;
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
847 848
void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
{
849
	Dart newFace = agent->part_.d ;
850

851 852
	popAgentInCells(agent, oldFace) ;
	pushAgentInCells(agent, newFace) ;
853

David Cazier's avatar
David Cazier committed
854 855
	if (!refineMark.isMarked(newFace) && agentvect[newFace].size() > nbAgentsToSubdivide)
	{
856
		std::pair<bool, bool>& sf = subdivisableFace[newFace] ;
David Cazier's avatar
David Cazier committed
857 858
		if (sf.first == false || (sf.first == true && sf.second))
		{
859 860
			refineMark.mark(newFace) ;
			refineCandidate.push_back(newFace) ;
861 862
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
863

David Cazier's avatar
David Cazier committed
864 865 866
	if (!coarsenMark.isMarked(oldFace) && !refineMark.isMarked(oldFace)
	    && 4 * agentvect[oldFace].size() < nbAgentsToSimplify)
	{
867 868
		coarsenMark.mark(oldFace) ;
		coarsenCandidate.push_back(map.faceOldestDart(oldFace)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
869
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
870 871
}

872
void EnvMap::refine()
Pierre Kraemer's avatar
Pierre Kraemer committed
873
{
874
	for (std::vector<Dart>::iterator it = refineCandidate.begin(); it != refineCandidate.end(); ++it)
David Cazier's avatar
David Cazier committed
875 876
	{
		Dart d = (*it) ;
877
		refineMark.unmark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
878

879
		//if the number of agents is big enough
David Cazier's avatar
David Cazier committed
880 881
		if (agentvect[d].size() > nbAgentsToSubdivide)
		{
Thomas's avatar
Thomas committed
882
			int fLevel = -1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
883 884
			Dart old = map.faceOldestDart(d) ;

885
			bool subdivisable = true ;
Pierre Kraemer's avatar
Pierre Kraemer committed
886

887
			//check if faces resulting from a subdivision are big enough
888
			std::pair<bool, bool>& sf = subdivisableFace[old] ;
David Cazier's avatar
David Cazier committed
889 890 891 892
			if (sf.first == true)
				subdivisable = sf.second ;
			else
			{
893 894
//				float minSizeSq = minCellSize * minCellSize ; // diametre de vision de l'agent au carré
				float minSizeSq = Agent::neighborDistSq_;
895

Pierre Kraemer's avatar
Pierre Kraemer committed
896
				fLevel = map.faceLevel(old) ;
897
				map.setCurrentLevel(fLevel) ;
898
				PFP::VEC3 fCenter = Algo::Surface::Geometry::faceCentroid<PFP>(map, old, position) ;
899
				Dart fd = old ;
David Cazier's avatar
David Cazier committed
900 901
				do
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
902
					PFP::VEC3& p = position[fd] ;
903
					PFP::VEC3 edge = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map, fd, position) ;
David Cazier's avatar
David Cazier committed
904 905 906
					PFP::VEC3 proj = fCenter - (p + (edge * (fCenter - p) / edge.norm2()) * edge) ;
					if (proj.norm2() < minSizeSq)
					{
907 908
						subdivisable = false ;
						break ;
Pierre Kraemer's avatar
Pierre Kraemer committed
909
					}
910
					fd = map.phi1(fd) ;
911
				} while (fd != old) ;
912 913
				map.setCurrentLevel(map.getMaxLevel()) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
914 915
				sf.first = true ;
				sf.second = subdivisable ;
916 917
			}

David Cazier's avatar
David Cazier committed
918 919
			if (subdivisable)
			{
920 921
				if (fLevel == -1)
					fLevel = map.faceLevel(old) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
922 923

				sf.first = false ;
924

925
				PFP::AGENTS oldAgents(agentvect[old]) ;
David Cazier's avatar
David Cazier committed
926 927
				PFP::OBSTACLEVECT oldObst(obstvect[old]) ;
				PFP::OBSTACLEVECT oldNeighborObst(neighborObstvect[old]) ;
Thomas Jund's avatar
Thomas Jund committed
928

David Cazier's avatar
David Cazier committed
929
				for (PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
Thomas Jund's avatar
Thomas Jund committed
930
				{
David Cazier's avatar
David Cazier committed
931
					popAgentInCells(*ait, old) ;
Thomas Jund's avatar
Thomas Jund committed
932
				}
David Cazier's avatar
David Cazier committed
933
				for (PFP::OBSTACLEVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
934 935 936
					this->popObstacleInCells(*ait, (*ait)->index) ;
				for (PFP::OBSTACLEVECT::iterator ait = oldNeighborObst.begin();ait != oldNeighborObst.end(); ++ait)
					this->popObstacleInCells(*ait, (*ait)->index) ;
937
				neighborAgentvect[old].clear() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
938 939

				map.setCurrentLevel(fLevel) ;
940
				Algo::Surface::IHM::subdivideFace<PFP>(map, old, position) ;
David Cazier's avatar
David Cazier committed
941
				CellMarkerStore<FACE> newF(map) ;
942 943
				unsigned int degree = 0 ;
				Dart dd = old ;
David Cazier's avatar
David Cazier committed
944 945
				do
				{
946
					++degree ;
947
					newF.mark(dd) ;
948
					dd = map.phi1(dd) ;
949
				} while (dd != old) ;
David Cazier's avatar
David Cazier committed
950

David Cazier's avatar
David Cazier committed
951 952
				if (degree == 3)
				{
953
					Dart centerFace = map.phi2(map.phi1(old)) ;
954
					newF.mark(centerFace) ;
955
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
956
				map.setCurrentLevel(map.getMaxLevel()) ;
957

958
				//agents contained in the subdivided cell are pushed correctly
David Cazier's avatar
David Cazier committed
959 960 961 962
				for (PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
				{
					resetAgentInFace(*ait) ;
					pushAgentInCells(*ait, (*ait)->part_.d) ;
963
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
964

965
				//same for obstacles contained
David Cazier's avatar
David Cazier committed
966 967
				for (PFP::OBSTACLEVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
				{
968
					resetPartSubdiv(*ait);
969
					pushObstacleInCells(*ait);
pitiot's avatar
maj  
pitiot committed
970

David Cazier's avatar
David Cazier committed
971 972
				}

973
				//same for adjacent obstacles
David Cazier's avatar
David Cazier committed
974
				for (PFP::OBSTACLEVECT::iterator ait = oldNeighborObst.begin();
975
					ait != oldNeighborObst.end(); ++ait)
David Cazier's avatar
David Cazier committed
976
				{
977
					pushObstacleInCells(*ait) ;
David Cazier's avatar
David Cazier committed
978 979
				}

980
				dd = old ;
David Cazier's avatar
David Cazier committed
981 982
				do
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
983
					Dart d3 = dd ;
Thomas Jund's avatar
Thomas Jund committed
984

David Cazier's avatar
David Cazier committed
985 986
					do
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
987 988
						Dart d4 = map.alpha1(map.alpha1(d3)) ;
						PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
David Cazier's avatar
David Cazier committed
989 990 991 992
						while (d4 != d3)
						{
							if (!newF.isMarked(d4))
							{
Pierre Kraemer's avatar
Pierre Kraemer committed
993 994 995 996
								PFP::AGENTS& ad4 = agentvect[d4] ;
								nad3.insert(nad3.end(), ad4.begin(), ad4.end()) ;
							}
							d4 = map.alpha1(d4) ;
997
						}
Pierre Kraemer's avatar
Pierre Kraemer committed
998
						d3 = map.phi1(d3) ;
999
					} while (d3 != dd) ;
1000 1001

					map.setCurrentLevel(fLevel) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1002
					dd = map.phi1(dd) ;
1003
					map.setCurrentLevel(map.getMaxLevel()) ;
1004
				} while (dd != old) ;
1005

Thomas Jund's avatar
Thomas Jund committed
1006 1007


David Cazier's avatar
David Cazier committed
1008 1009
				if (degree == 3)
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
1010 1011
					Dart centerFace = map.phi2(map.phi1(old)) ;
					Dart d3 = centerFace ;
David Cazier's avatar
David Cazier committed
1012 1013
					do
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
1014 1015
						Dart d4 = map.alpha1(map.alpha1(d3)) ;
						PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
David Cazier's avatar
David Cazier committed
1016 1017 1018 1019
						while (d4 != d3)
						{
							if (!newF.isMarked(d4))
							{
Pierre Kraemer's avatar
Pierre Kraemer committed
1020
								PFP::AGENTS& ad4 = agentvect[d4] ;
David Cazier's avatar
David Cazier committed
1021
								nad3.insert(neighborAgentvect[d3].end(), ad4.begin(), ad4.end()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1022 1023
							}
							d4 = map.alpha1(d4) ;
1024
						}
Pierre Kraemer's avatar
Pierre Kraemer committed
1025
						d3 = map.phi1(d3) ;
1026
					} while (d3 != centerFace) ;