Commit 49a41675 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

correction bugs simplif

parent 75f8171b
......@@ -51,10 +51,10 @@ Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
void EnvMap::init()
{
float sideSize = 70.0f;
unsigned int nbSquares = 3;
unsigned int nbSquares = 14;
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))
......@@ -223,13 +223,7 @@ void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
popAgentInCells(agent, oldFace);
pushAgentInCells(agent, newFace);
if(!coarsenMark.isMarked(oldFace) && agentvect[oldFace].size() < nbAgentsToSimplify / 2)
{
coarsenMark.mark(oldFace);
coarsenCandidate.push_back(oldFace);
}
if(!refineMark.isMarked(newFace) && !coarsenMark.isMarked(newFace) && agentvect[newFace].size() > nbAgentsToSubdivide)
if(!refineMark.isMarked(newFace) && agentvect[newFace].size() > nbAgentsToSubdivide)
{
std::pair<bool,bool>& sf = subdivisableFace[newFace];
if(sf.first == false || (sf.first == true && sf.second))
......@@ -238,6 +232,12 @@ void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
refineCandidate.push_back(newFace);
}
}
if(!coarsenMark.isMarked(oldFace) && !refineMark.isMarked(oldFace) && agentvect[oldFace].size() < nbAgentsToSimplify / 2)
{
coarsenMark.mark(oldFace);
coarsenCandidate.push_back(map.faceOldestDart(oldFace));
}
}
void EnvMap::updateMap()
......@@ -247,6 +247,7 @@ void EnvMap::updateMap()
for(std::vector<Dart>::iterator it = refineCandidate.begin(); it != refineCandidate.end(); ++it)
{
Dart d = (*it) ;
refineMark.unmark(d);
if(agentvect[d].size() > nbAgentsToSubdivide)
......@@ -365,6 +366,7 @@ void EnvMap::updateMap()
for(std::vector<Dart>::iterator it = coarsenCandidate.begin(); it != coarsenCandidate.end(); ++it)
{
Dart d = (*it) ;
coarsenMark.unmark(d) ;
unsigned int fLevel = map.faceLevel(d) ;
......@@ -403,19 +405,16 @@ void EnvMap::updateMap()
map.setCurrentLevel(fLevel) ;
coarsenMark.unmark(fit) ;
std::vector<Dart>::iterator start = it + 1 ;
if(start != coarsenCandidate.end())
unsigned int fEmb = map.getEmbedding(FACE_ORBIT, fit) ;
while(start != coarsenCandidate.end())
{
unsigned int fEmb = map.getEmbedding(FACE_ORBIT, fit) ;
while(start != coarsenCandidate.end())
if(map.getEmbedding(FACE_ORBIT, *start) == fEmb)
{
if(map.getEmbedding(FACE_ORBIT, *start) == fEmb)
{
*start = coarsenCandidate.back() ;
coarsenCandidate.pop_back() ;
}
else
++start ;
*start = coarsenCandidate.back() ;
coarsenCandidate.pop_back() ;
}
else
++start ;
}
PFP::AGENTS a(agentvect[fit]) ;
agents.insert(agents.end(), a.begin(), a.end()) ;
......@@ -437,25 +436,23 @@ void EnvMap::updateMap()
}
fit = map.phi1(fit) ;
} while(fit != old) ;
if(degree == 3)
{
map.setCurrentLevel(fLevel) ;
Dart centerFace = map.phi2(map.phi1(old)) ;
coarsenMark.unmark(centerFace) ;
std::vector<Dart>::iterator start = it + 1 ;
if(start != coarsenCandidate.end())
unsigned int fEmb = map.getEmbedding(FACE_ORBIT, centerFace) ;
while(start != coarsenCandidate.end())
{
unsigned int fEmb = map.getEmbedding(FACE_ORBIT, centerFace) ;
while(start != coarsenCandidate.end())
if(map.getEmbedding(FACE_ORBIT, *start) == fEmb)
{
if(map.getEmbedding(FACE_ORBIT, *start) == fEmb)
{
*start = coarsenCandidate.back() ;
coarsenCandidate.pop_back() ;
}
else
++start ;
*start = coarsenCandidate.back() ;
coarsenCandidate.pop_back() ;
}
else
++start ;
}
PFP::AGENTS a(agentvect[centerFace]) ;
agents.insert(agents.end(), a.begin(), a.end()) ;
......
......@@ -6,7 +6,7 @@ Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.2f)
envMap_.init();
std::cout << "setup scenario" << std::endl;
// importAgents("myAgents.pos");
setupScenario(15000);
setupScenario(700);
// addPathsToAgents();
unsigned nbAgents = agents_.size();
......@@ -63,7 +63,13 @@ void Simulator::doStep()
for (unsigned int i = 0; i < agents_.size(); ++i)
{
Dart oldFace = agents_[i]->part_.d;
if(!envMap_.map.isDartValid(agents_[i]->part_.d))
std::cout << " AGENT PART INVALID DART before update" << std::endl ;
agents_[i]->update();
if(!envMap_.map.isDartValid(agents_[i]->part_.d))
std::cout << " AGENT PART INVALID DART after update" << std::endl ;
// if(envMap_.map.getEmbedding(oldFace, FACE_ORBIT) != envMap_.map.getEmbedding(agents_[i]->part_.d, FACE_ORBIT))
if(agents_[i]->part_.crossCell != CGoGN::Algo::MovingObjects::NO_CROSS)
// switch(agents_[i]->part_.crossCell)
......@@ -85,7 +91,7 @@ void Simulator::doStep()
globalTime_ += timeStep_;
if(int(globalTime_ / timeStep_) % 1500 == 0)
if(int(globalTime_ / timeStep_) % 2000 == 0)
{
std::cout << "swap goals (globalTime -> " << globalTime_ << ")" << std::endl ;
swapAgentsGoals();
......@@ -101,8 +107,8 @@ void Simulator::setupScenario(unsigned int nbMaxAgent)
Dart d = envMap_.map.begin();
CellMarker filled(envMap_.map,FACE_ORBIT);
unsigned int nbx = 5;
unsigned int nby = 5;
unsigned int nbx = 10;
unsigned int nby = 10;
unsigned int bMax = nbMaxAgent / (nbx*nby);
......@@ -152,7 +158,7 @@ void Simulator::setupScenario(unsigned int nbMaxAgent)
void Simulator::addPathsToAgents()
{
//city
unsigned int dartDistForPath=50;
unsigned int dartDistForPath = 50;
for(unsigned int i = 0; i < agents_.size(); ++i)
{
agents_[i]->goals_.clear();
......@@ -269,11 +275,11 @@ 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])
for(unsigned int nbg = 0; nbg < agents_[i]->goals_.size(); ++nbg)
{
VEC3 g = agents_[i]->goals_[1];
agents_[i]->goals_[1] = agents_[r]->goals_[1];
agents_[r]->goals_[1] = g;
VEC3 g = agents_[i]->goals_[nbg];
agents_[i]->goals_[nbg] = agents_[r]->goals_[nbg];
agents_[r]->goals_[nbg] = 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