Commit 211fc6e6 authored by Pierre Kraemer's avatar Pierre Kraemer

des trucs

parent 704df519
......@@ -128,14 +128,15 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
assert(map.getCurrentLevel() == map.getMaxLevel());
assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end());
PFP::AGENTS& a = agentvect[d];
PFP::AGENTS::iterator end = a.end();
bool found = false;
PFP::AGENTS::iterator end = agentvect[d].end();
for(PFP::AGENTS::iterator it = agentvect[d].begin(); it != end && !found; ++it)
for(PFP::AGENTS::iterator it = a.begin(); it != end && !found; ++it)
{
if(*it == agent)
{
*it = agentvect[d].back();
agentvect[d].pop_back();
*it = a.back();
a.pop_back();
found = true;
}
}
......@@ -147,13 +148,14 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
while(ddd != dd)
{
bool found = false;
PFP::AGENTS::iterator end = neighborAgentvect[ddd].end();
for(PFP::AGENTS::iterator it = neighborAgentvect[ddd].begin(); it != end && !found; ++it)
PFP::AGENTS& na = neighborAgentvect[ddd];
PFP::AGENTS::iterator end = na.end();
for(PFP::AGENTS::iterator it = na.begin(); it != end && !found; ++it)
{
if(*it == agent)
{
*it = neighborAgentvect[ddd].back();
neighborAgentvect[ddd].pop_back();
*it = na.back();
na.pop_back();
found = true;
}
}
......@@ -165,7 +167,12 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
inline void EnvMap::addRefineCandidate(Dart d)
{
refineCandidate.insert(std::pair<unsigned int, Dart>(map.getEmbedding(d, FACE_ORBIT), d)) ;
if(agentvect[d].size() > nbAgentsToSubdivide)
{
std::pair<bool,bool>& sf = subdivisableFace[d] ;
if(sf.first == false || (sf.first == true && sf.second))
refineCandidate.insert(std::pair<unsigned int, Dart>(map.getEmbedding(d, FACE_ORBIT), d)) ;
}
}
inline void EnvMap::addCoarsenCandidate(Dart d)
......@@ -176,7 +183,7 @@ inline void EnvMap::addCoarsenCandidate(Dart d)
inline void EnvMap::clearUpdateCandidates()
{
refineCandidate.clear();
coarsenCandidate.clear();
// coarsenCandidate.clear();
}
#endif
......@@ -45,7 +45,7 @@ void EnvMap::init()
unsigned int nbSquares = 25;
CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
map.init();
registerObstaclesInFaces();
for(unsigned int i = subdivisableFace.begin(); i < subdivisableFace.end(); subdivisableFace.next(i))
......@@ -212,7 +212,10 @@ void EnvMap::addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbo
void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
{
popAgentInCells(agent, oldFace);
// addCoarsenCandidate(oldFace);
pushAgentInCells(agent, agent->part_.d);
addRefineCandidate(agent->part_.d);
}
void EnvMap::updateMap()
......@@ -223,27 +226,29 @@ void EnvMap::updateMap()
{
Dart d = (*it).second ;
unsigned int fLevel = map.faceLevel(d) ;
Dart old = map.faceOldestDart(d) ;
if(agentvect[old].size() > nbAgentsToSubdivide)
if(agentvect[d].size() > nbAgentsToSubdivide)
{
unsigned int fLevel = -1 ;
Dart old = map.faceOldestDart(d) ;
bool subdivisable = true ;
if(subdivisableFace[old].first == true)
{
subdivisable = subdivisableFace[old].second ;
}
std::pair<bool,bool>& sf = subdivisableFace[d] ;
if(sf.first == true)
subdivisable = sf.second ;
else
{
float maxEdgeSize = Agent::neighborDistSq_ ; // diametre de vision de l'agent au carré
fLevel = map.faceLevel(d) ;
map.setCurrentLevel(fLevel) ;
PFP::VEC3 fCenter = Algo::Geometry::faceCentroid<PFP>(map, old, position) ;
Dart fd = old ;
do
{
PFP::VEC3& p = position[fd] ;
PFP::VEC3 edge = Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position) ;
PFP::VEC3 proj = fCenter - (position[fd] + (edge * (fCenter - position[fd]) / edge.norm2()) * edge) ;
PFP::VEC3 proj = fCenter - (p + (edge * (fCenter - p) / edge.norm2()) * edge) ;
if(proj.norm2() < maxEdgeSize)
// if(Algo::Geometry::vectorOutOfDart<PFP>(map, fd, position).norm2() < maxEdgeSize)
{
......@@ -254,13 +259,16 @@ void EnvMap::updateMap()
} while(fd != old) ;
map.setCurrentLevel(map.getMaxLevel()) ;
subdivisableFace[old].first = true ;
subdivisableFace[old].second = subdivisable ;
sf.first = true ;
sf.second = subdivisable ;
}
if(subdivisable)
{
subdivisableFace[old].first = false ;
if(fLevel == -1)
fLevel = map.faceLevel(d) ;
sf.first = false ;
PFP::AGENTS oldAgents(agentvect[old]);
for(PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
......@@ -280,44 +288,52 @@ void EnvMap::updateMap()
pushAgentInCells(*ait, (*ait)->part_.d) ;
}
unsigned int degree = 0;
Dart dd = old;
unsigned int degree = 0 ;
Dart dd = old ;
do
{
++degree;
Dart d3 = dd;
++degree ;
Dart d3 = dd ;
do
{
Dart d4 = map.alpha1(map.alpha1(d3));
Dart d4 = map.alpha1(map.alpha1(d3)) ;
PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
while(d4 != d3)
{
if(!newF.isMarked(d4))
neighborAgentvect[d3].insert(neighborAgentvect[d3].end(), agentvect[d4].begin(), agentvect[d4].end());
d4 = map.alpha1(d4);
{
PFP::AGENTS& ad4 = agentvect[d4] ;
nad3.insert(nad3.end(), ad4.begin(), ad4.end()) ;
}
d4 = map.alpha1(d4) ;
}
d3 = map.phi1(d3);
} while(d3 != dd);
d3 = map.phi1(d3) ;
} while(d3 != dd) ;
map.setCurrentLevel(fLevel) ;
dd = map.phi1(dd);
dd = map.phi1(dd) ;
map.setCurrentLevel(map.getMaxLevel()) ;
} while(dd != old);
if(degree == 3)
{
Dart centerFace = map.phi2(map.phi1(old));
Dart d3 = centerFace;
Dart centerFace = map.phi2(map.phi1(old)) ;
Dart d3 = centerFace ;
do
{
Dart d4 = map.alpha1(map.alpha1(d3));
Dart d4 = map.alpha1(map.alpha1(d3)) ;
PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
while(d4 != d3)
{
if(!newF.isMarked(d4))
neighborAgentvect[d3].insert(neighborAgentvect[d3].end(), agentvect[d4].begin(), agentvect[d4].end());
d4 = map.alpha1(d4);
{
PFP::AGENTS& ad4 = agentvect[d4] ;
nad3.insert(neighborAgentvect[d3].end(), ad4.begin(), ad4.end()) ;
}
d4 = map.alpha1(d4) ;
}
d3 = map.phi1(d3);
} while(d3 != centerFace);
d3 = map.phi1(d3) ;
} while(d3 != centerFace) ;
}
}
}
......
#include "simulator.h"
Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.25f)
Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.5f)
{
srand(10);
envMap_.init();
std::cout << "setup scenario" << std::endl;
importAgents("myAgents.pos");
// setupScenario();
// importAgents("myAgents.pos");
setupScenario();
// addPathsToAgents();
for(unsigned int i = 0; i < agents_.size(); ++i)
{
......@@ -48,8 +48,6 @@ void Simulator::doStep()
// break;
// case CGoGN::Algo::MovingObjects::CROSS_OTHER :
envMap_.agentChangeFace(agents_[i], oldFace);
envMap_.addCoarsenCandidate(oldFace);
envMap_.addRefineCandidate(agents_[i]->part_.d);
// break;
}
......@@ -63,6 +61,11 @@ void Simulator::doStep()
envMap_.updateMap();
globalTime_ += timeStep_;
if(globalTime_ - int(globalTime_) == 0.0f && int(globalTime_) % 500 == 0)
{
swapAgentsGoals();
}
}
void Simulator::setupScenario()
......@@ -227,7 +230,8 @@ void Simulator::swapAgentsGoals()
{
unsigned int r = rand() % nbAgents;
if(agents_[i]->goals_[1][0]!=agents_[r]->goals_[1][0] || agents_[i]->goals_[1][1]!=agents_[r]->goals_[1][1]) {
if(agents_[i]->goals_[1][0] != agents_[r]->goals_[1][0] || agents_[i]->goals_[1][1] != agents_[r]->goals_[1][1])
{
VEC3 g = agents_[i]->goals_[1];
agents_[i]->goals_[1] = agents_[r]->goals_[1];
agents_[r]->goals_[1] = g;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment