Commit 1931a221 authored by David Cazier's avatar David Cazier
Browse files

Merge final avec SA2

parent e8c903af
......@@ -77,8 +77,9 @@ public:
unsigned int mapMemoryCost() ;
float max_for_obstacles;
unsigned int nbSquares;
float sideSize;
float max_for_obstacles;
void scale(float scaleVal);
#ifndef SPATIAL_HASHING
......@@ -100,7 +101,6 @@ public:
void nbAgentsDecrease(Dart d) ;
void pushAgentInCells(Agent* agent, Dart d) ;
void popAgentInCells(Agent* agent, Dart d) ;
// void agentChangeFaceThroughEdge(Agent* agent);
void agentChangeFace(Agent* agent, Dart oldFace) ;
void pushObstacleInCells(Obstacle* o, Dart d) ;
......@@ -181,6 +181,7 @@ public:
return ht_agents[c];
}
const std::vector<Agent*>& getNeighbors(Agent* a) ;
void getOneRingNeighbors(Agent* a, std::vector<Agent*>& neighbors) ;
void addAgentInGrid(Agent* a) ;
......@@ -190,7 +191,6 @@ public:
void removeAgentFromGrid(Agent* a, Geom::Vec2ui c) ;
HashTable2D< std::vector<Agent*> > ht_agents ;
// HashTable2D< std::vector<Agent*> > ht_neighbor_agents ;
HashTable2D< std::vector<Obstacle*> > ht_obstacles ;
#endif
} ;
......@@ -307,7 +307,8 @@ inline void EnvMap::addObstAsNeighbor (Obstacle * o, const std::list<Dart>& bel
CellMarkerStore<FACE> OneRingMark(map);
for(std::list<Dart>::const_iterator it= belonging_cells.begin();it!=belonging_cells.end();++it)
{ assert(!buildingMark.isMarked(d)) ;
{
assert(!buildingMark.isMarked(*it)) ;
MovingObstMark.mark(*it);
}
......
......@@ -6,8 +6,8 @@
class Obstacle
{
public:
Obstacle(VEC3& point1, VEC3& point2, VEC3& prevPoint, VEC3& nextPoint,
MovingObstacle * moving1, int ind) :
Obstacle(const VEC3& point1, const VEC3& point2, const VEC3& prevPoint, const VEC3& nextPoint,
MovingObstacle * moving1, unsigned int ind) :
p1(point1), p2(point2), prevP(prevPoint), nextP(nextPoint),
mo(moving1), index(ind)
{
......@@ -22,7 +22,7 @@ public:
VEC3 prevP ;
VEC3 nextP ;
MovingObstacle * mo ;
int index ;
unsigned int index ;
} ;
#endif
This diff is collapsed.
......@@ -25,18 +25,20 @@ EnvMap::EnvMap() :
refineMark(map),
coarsenMark(map)
#else
ht_agents(1024),
ht_obstacles(1024)
ht_agents(1024),
ht_neighbor_agents(1024),
ht_obstacles(1024)
#endif
{
position = map.addAttribute<PFP::VEC3,VERTEX>("position") ;
normal = map.addAttribute<PFP::VEC3,VERTEX>("normal") ;
position = map.addAttribute<VEC3, VERTEX>("position") ;
normal = map.addAttribute<VEC3, VERTEX>("normal") ;
#ifndef SPATIAL_HASHING
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") ;
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") ;
refineCandidate.reserve(100) ;
coarsenCandidate.reserve(100) ;
......@@ -45,6 +47,10 @@ ht_obstacles(1024)
void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, REAL maxSize)
{
nbSquares = 6;
sideSize = 400.0f;
max_for_obstacles=(sideSize*nbSquares/2)-sideSize/2;
std::cout << "Init EnvMap" << std::endl ;
VEC3 bottomLeft(-width / 2, -height / 2, 0.0f) ;
VEC3 topRight(width / 2, height / 2, 0.0f) ;
......@@ -60,22 +66,19 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
std::cout << " - Table de hachage : " << agentGridSize(0) << " x " << agentGridSize(1) << std::endl ;
#endif
unsigned int nbSquares = 6 ;
switch (config)
{
case 0 :
CityGenerator::generateGrid<PFP>(*this) ;
break ;
case 1 :
CityGenerator::generateGrid<PFP>(*this) ;
break ;
case 2 :
CityGenerator::generateCity<PFP>(*this) ;
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
break ;
case 3 :
{
case 0 :
CityGenerator::generateGrid<PFP>(*this) ;
break ;
case 1 :
CityGenerator::generateGrid<PFP>(*this) ;
break ;
case 2 :
CityGenerator::generateCity<PFP>(*this) ;
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
break ;
case 3 : {
// std::string filename = "/home/jund/Desktop/drawingQuads.svg" ;
// std::string filename = "/home/jund/Desktop/drawingTest.svg" ;
// std::string filename = "/home/jund/Desktop/drawingSimple.svg" ;
......@@ -89,13 +92,13 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
// map.closeMap() ;
// Algo::Modelisation::CatmullClarkSubdivision<PFP>(map, position) ;
// Algo::Modelisation::computeDual<PFP>(map) ;
}
CityGenerator::generateCity<PFP>(*this) ;
break ;
case 4 :
CityGenerator::generatePlanet<PFP>(map, position, obstacleMark, buildingMark, 200.0f,
nbSquares) ;
break ;
}
CityGenerator::generateCity<PFP>(*this) ;
break ;
case 4 :
CityGenerator::generatePlanet<PFP>(map, position, obstacleMark, buildingMark, 200.0f,
nbSquares) ;
break ;
}
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
......@@ -103,14 +106,10 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
// CityGenerator::installGuardRail<PFP>(map, position, obstacleMark, buildingMark, 5.0f);
#ifndef SPATIAL_HASHING
// for (Dart d = map.begin() ; d != map.end(); map.next(d)) {
// Dart d1 = map.phi1(d);
// Dart d11= map.phi1(d1);
// if (map.phi1(d11) != d) map.splitFace(d,d11);
// }
map.init() ;
// registerObstaclesInFaces();
// TODO Check registerWallInFaces();
registerWallInFaces() ;
// subdivideAllToMaxLevel();
for (unsigned int i = subdivisableFace.begin(); i < subdivisableFace.end();
......@@ -181,6 +180,37 @@ unsigned int EnvMap::mapMemoryCost()
+ (map.getAttributeContainer<FACE>()).memorySize() ;
}
// TODO Check void EnvMap::scale(float scaleVal) => compatible avec champ Geometry ?
void EnvMap::scale(float scaleVal)
{
Geom::BoundingBox<PFP::VEC3> bb(position.begin()) ;
for (unsigned int v = position.begin(); v != position.end(); position.next(v))
{
bb.addPoint(position[v]) ;
}
for (unsigned int v = positionScenary.begin(); v != positionScenary.end();
positionScenary.next(v))
{
bb.addPoint(positionScenary[v]) ;
}
VEC3 center = bb.center() ;
for (unsigned int v = position.begin(); v != position.end(); position.next(v))
{
position[v] -= center ;
position[v] *= scaleVal ;
}
for (unsigned int v = positionScenary.begin(); v != positionScenary.end();
positionScenary.next(v))
{
positionScenary[v] -= center ;
positionScenary[v] *= scaleVal ;
}
}
#ifndef SPATIAL_HASHING
void EnvMap::subdivideAllToMaxLevel()
{
......@@ -301,6 +331,52 @@ void EnvMap::foreach_neighborFace(Dart d, FunctorType& f)
} while (dd != d) ;
}
// 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
{
if (obstacleMark.isMarked(dd) && map.isBoundaryMarked(dd))
{
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);
}
}
}
void EnvMap::registerObstaclesInFaces()
{
CellMarker<FACE> m(map) ;
......@@ -324,7 +400,8 @@ void EnvMap::registerObstaclesInFaces()
Dart next = map.phi1(dd2) ;
Dart previous = map.phi_1(dd2) ;
Obstacle* o = new Obstacle(position[dd2], position[next],
position[previous], position[map.phi1(next)]) ;
position[previous], position[map.phi1(next)],
NULL, 0) ;
obstvect[d].push_back(o) ;
}
dd = map.phi1(dd) ;
......@@ -336,6 +413,7 @@ void EnvMap::registerObstaclesInFaces()
Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd)
{
// TODO Check effet de bord
if (!buildingMark.isMarked(ddd)) addNeighborObstacles(
obstvect[d], ddd, ddd == map.alpha_1(dd)) ;
ddd = map.alpha1(ddd) ;
......@@ -374,7 +452,7 @@ void EnvMap::addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbo
Dart next = map.phi1(dd2) ;
Dart previous = map.phi_1(dd2) ;
Obstacle* o = new Obstacle(position[dd2], position[next], position[previous],
position[map.phi1(next)]) ;
position[map.phi1(next)], NULL, 0) ;
obst.push_back(o) ;
// }
}
......@@ -382,84 +460,6 @@ void EnvMap::addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbo
} while (dd != stop) ;
}
//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
// CellMarkerNoUnmark<FACE> f(map);
// 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);
//}
void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
{
Dart newFace = agent->part_.d ;
......@@ -544,14 +544,20 @@ void EnvMap::updateMap()
sf.first = false ;
PFP::AGENTS oldAgents(agentvect[old]) ;
PFP::OBSTACLEVECT oldObst(obstvect[old]) ;
PFP::OBSTACLEVECT oldNeighborObst(neighborObstvect[old]) ;
for (PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
popAgentInCells(*ait, old) ;
for (PFP::OBSTACLEVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
register_pop(*ait, (*ait)->index) ;
for (PFP::OBSTACLEVECT::iterator ait = oldNeighborObst.begin();
ait != oldNeighborObst.end(); ++ait)
register_pop(*ait, (*ait)->index) ;
neighborAgentvect[old].clear() ;
map.setCurrentLevel(fLevel) ;
Algo::IHM::subdivideFace<PFP>(map, old, position) ;
CellMarkerStore newF(map, FACE) ;
CellMarkerStore<FACE> newF(map) ;
unsigned int degree = 0 ;
Dart dd = old ;
do
......@@ -560,6 +566,7 @@ void EnvMap::updateMap()
newF.mark(dd) ;
dd = map.phi1(dd) ;
} while (dd != old) ;
if (degree == 3)
{
Dart centerFace = map.phi2(map.phi1(old)) ;
......@@ -573,6 +580,19 @@ void EnvMap::updateMap()
pushAgentInCells(*ait, (*ait)->part_.d) ;
}
for (PFP::OBSTACLEVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
{
resetObstInFace(*ait) ;
update_registration(*ait) ;
}
for (PFP::OBSTACLEVECT::iterator ait = oldNeighborObst.begin();
ait != oldNeighborObst.end(); ++ait)
{
resetObstInFace(*ait) ;
update_registration(*ait) ;
}
dd = old ;
do
{
......@@ -652,6 +672,20 @@ void EnvMap::updateMap()
nbAgents += agentvect[fit].size() ;
++degree ;
coarsenMark.unmark(fit) ;
// TODO Optimisation déjà faite
// unsigned int start = it + 1;
// unsigned int fEmb = map.getEmbedding<FACE>(fit) ;
// while(start < coarsenCandidate.size())
// {
// if(map.getEmbedding<FACE>(coarsenCandidate[start]) == fEmb)
// {
// coarsenCandidate[start] = coarsenCandidate.back() ;
// coarsenCandidate.pop_back() ;
// }
// else
// ++start ;
// }
fit = map.phi1(fit) ;
} while (fit != old) ;
......@@ -661,6 +695,19 @@ void EnvMap::updateMap()
Dart centerFace = map.phi2(map.phi1(old)) ;
nbAgents += agentvect[centerFace].size() ;
coarsenMark.unmark(centerFace) ;
// TODO Optimisation déjà faite
// unsigned int start = it + 1;
// unsigned int fEmb = map.getEmbedding<FACE>(centerFace) ;
// while(start < coarsenCandidate.size())
// {
// if(map.getEmbedding<FACE>(coarsenCandidate[start]) == fEmb)
// {
// coarsenCandidate[start] = coarsenCandidate.back() ;
// coarsenCandidate.pop_back() ;
// }
// else
// ++start ;
// }
map.setCurrentLevel(fLevel - 1) ;
}
if (nbAgents < nbAgentsToSimplify) checkCoarsenCandidate.push_back(old) ;
......@@ -689,11 +736,19 @@ void EnvMap::updateMap()
} while (fit != old) ;
PFP::AGENTS agents ;
PFP::OBSTACLEVECT obst ;
PFP::OBSTACLEVECT neighborObst ;
fit = old ;
do
{
PFP::AGENTS a(agentvect[fit]) ;
PFP::OBSTACLEVECT ob(obstvect[fit]) ;
PFP::OBSTACLEVECT nob(neighborObstvect[fit]) ;
agents.insert(agents.end(), a.begin(), a.end()) ;
obst.insert(obst.end(), ob.begin(), ob.end()) ;
neighborObst.insert(neighborObst.end(), nob.begin(), nob.end()) ;
map.setCurrentLevel(map.getMaxLevel()) ;
for (PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
popAgentInCells(*ait, fit) ;
......@@ -703,10 +758,19 @@ void EnvMap::updateMap()
{
map.setCurrentLevel(fLevel) ;
PFP::AGENTS& an = agentvect[nf] ;
PFP::OBSTACLEVECT resetob = obstvect[nf] ;
for (PFP::AGENTS::iterator ait = an.begin(); ait != an.end(); ++ait)
{
if ((*ait)->part_.d == map.phi1(nf)) (*ait)->part_.d = nf ;
}
for (PFP::OBSTACLEVECT::iterator ait = resetob.begin(); ait != resetob.end(); ++ait)
{
MovingObstacle* mo = (*ait)->mo ;
if (mo != NULL)
{
resetPart(mo, nf) ;
}
}
map.setCurrentLevel(fLevel - 1) ;
}
fit = map.phi1(fit) ;
......@@ -717,13 +781,25 @@ void EnvMap::updateMap()
map.setCurrentLevel(fLevel) ;
Dart centerFace = map.phi2(map.phi1(old)) ;
PFP::AGENTS a(agentvect[centerFace]) ;
PFP::OBSTACLEVECT ob(obstvect[centerFace]) ;
PFP::OBSTACLEVECT nob(neighborObstvect[centerFace]) ;
agents.insert(agents.end(), a.begin(), a.end()) ;
obst.insert(obst.end(), ob.begin(), ob.end()) ;
neighborObst.insert(neighborObst.end(), nob.begin(), nob.end()) ;
map.setCurrentLevel(map.getMaxLevel()) ;
for (PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
popAgentInCells(*ait, centerFace) ;
map.setCurrentLevel(fLevel - 1) ;
}
neighborAgentvect[old].clear() ;
// TODO Check with optimisation
map.setCurrentLevel(map.getMaxLevel()) ;
for (PFP::OBSTACLEVECT::iterator ait = obst.begin(); ait != obst.end(); ++ait)
register_pop(*ait, (*ait)->index) ;
for (PFP::OBSTACLEVECT::iterator ait = neighborObst.begin(); ait != neighborObst.end();
++ait)
register_pop(*ait, (*ait)->index) ;
map.setCurrentLevel(fLevel - 1) ;
Algo::IHM::coarsenFace<PFP>(map, old, position) ;
......@@ -738,6 +814,16 @@ void EnvMap::updateMap()
(*itA)->part_.d = old ;
pushAgentInCells(*itA, old) ;
}
for (PFP::OBSTACLEVECT::iterator ait = obst.begin(); ait != obst.end(); ++ait)
{
resetObstPartInFace(*ait, old) ;
update_registration(*ait) ;
}
for (PFP::OBSTACLEVECT::iterator ait = neighborObst.begin(); ait != neighborObst.end();
++ait)
{
update_registration(*ait) ;
}
Dart dd = old ;
do
......@@ -745,16 +831,14 @@ void EnvMap::updateMap()
Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd)
{
neighborAgentvect[old].insert(neighborAgentvect[old].end(),
agentvect[ddd].begin(),
agentvect[ddd].end()) ;
neighborAgentvect[old].insert(neighborAgentvect[old].end(), agentvect[ddd].begin(),
agentvect[ddd].end()) ;
ddd = map.alpha1(ddd) ;
}
dd = map.phi1(dd) ;
} while (dd != old) ;
if (fLevel > 1 && !coarsenMark.isMarked(old)
&& agentvect[old].size() < nbAgentsToSimplify)
if (fLevel > 1 && !coarsenMark.isMarked(old) && agentvect[old].size() < nbAgentsToSimplify)
{
coarsenMark.mark(old) ;
coarsenCandidate.push_back(map.faceOldestDart(old)) ;
......@@ -783,12 +867,20 @@ Geom::Vec2ui EnvMap::agentPositionCell(Agent* a)
return Geom::Vec2ui(relativePos[0], relativePos[1]) ;
}
const std::vector<Agent*>& EnvMap::getNeighbors(Agent* a) {
const std::vector<Agent*>& EnvMap::getNeighbors(Agent* a)
{
Geom::Vec2ui c = agentPositionCell(a) ;
return ht_agents[c] ;
}
void EnvMap::getOneRingNeighbors(Agent* a, std::vector<Agent*>& neighbors) {
const std::vector<Agent*>& EnvMap::getNeighborAgents(Agent* a)
{
Geom::Vec2ui c = agentPositionCell(a) ;
return ht_neighbor_agents[c] ;
}
void EnvMap::getOneRingNeighbors(Agent* a, std::vector<Agent*>& neighbors)
{
Geom::Vec2ui c = agentPositionCell(a) ;
for(int ii = -1 ; ii <= 1 ; ++ii)
{
......@@ -804,22 +896,25 @@ void EnvMap::getOneRingNeighbors(Agent* a, std::vector<Agent*>& neighbors) {
}
}
void EnvMap::addAgentInGrid(Agent* a) {
void EnvMap::addAgentInGrid(Agent* a)
{
Geom::Vec2ui c = agentPositionCell(a) ;
addAgentInGrid(a,c) ;
}
void EnvMap::addAgentInGrid(Agent* a, Geom::Vec2ui c) {
void EnvMap::addAgentInGrid(Agent* a, Geom::Vec2ui c)
{
ht_agents[c].push_back(a) ;
}
void EnvMap::removeAgentFromGrid(Agent* a) {
void EnvMap::removeAgentFromGrid(Agent* a)
{
Geom::Vec2ui c = agentPositionCell(a) ;
removeAgentFromGrid(a,c) ;
}
void EnvMap::removeAgentFromGrid(Agent* a, Geom::Vec2ui c) {
void EnvMap::removeAgentFromGrid(Agent* a, Geom::Vec2ui c)
{
removeElementFromVector<Agent*>(ht_agents[c], a) ;
if (ht_agents[c].empty()) ht_agents.erase(c) ;
}
......
......@@ -100,10 +100,10 @@ MovingObstacle::MovingObstacle(int ind, EnvMap* envmap, std::vector<VEC3> pos, V
for (unsigned int i = 0; i < nbVertices; ++i)