Commit fe22bd55 authored by Pierre Kraemer's avatar Pierre Kraemer
Browse files

refineCandidate : map -> vector

parent 90d6a95b
......@@ -407,7 +407,7 @@ void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position, Ce
stillSimplif = false;
}
// convexifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
convexifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
map.check();
}
......
......@@ -69,10 +69,7 @@ public :
void pushAgentInCells(Agent* agent, Dart d);
void popAgentInCells(Agent* agent, Dart d);
void addRefineCandidate(Dart d);
void addCoarsenCandidate(Dart d);
void clearUpdateCandidates();
void updateMap();
void resetAgentInFace(Agent* agent);
......@@ -95,8 +92,12 @@ public :
static const unsigned int nbAgentsToSubdivide = 7;
static const unsigned int nbAgentsToSimplify = 7;
std::map<unsigned int, Dart> refineCandidate;
std::map<unsigned int, Dart> coarsenCandidate;
// std::map<unsigned int, Dart> refineCandidate;
// std::map<unsigned int, Dart> coarsenCandidate;
CellMarker refineMark;
std::vector<Dart> refineCandidate;
// std::vector<Dart> coarsenCandidate;
};
/**************************************
......@@ -165,21 +166,6 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
} while(dd != d);
}
inline void EnvMap::addRefineCandidate(Dart 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(FACE_ORBIT, d), d)) ;
}
}
inline void EnvMap::addCoarsenCandidate(Dart d)
{
coarsenCandidate.insert(std::pair<unsigned int, Dart>(map.getEmbedding(FACE_ORBIT, d), d)) ;
}
inline void EnvMap::clearUpdateCandidates()
{
refineCandidate.clear();
......
......@@ -12,6 +12,37 @@
#include <fstream>
#include <sstream>
class ThreadUpdateInfo
{
public :
std::vector<Agent*> ag_;
unsigned int bMin_;
unsigned int bMax_;
// Constructor
ThreadUpdateInfo(std::vector<Agent*> agents, unsigned int bMin, unsigned int bMax) :
bMin_(bMin),
bMax_(bMax)
{
ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax);
}
// Destructor
~ThreadUpdateInfo() { }
void run()
{
// Thread execution stuff goes here
for (unsigned int i = 0; i < ag_.size(); ++i)
{
ag_[i]->updateObstacleNeighbors();
ag_[i]->updateAgentNeighbors();
ag_[i]->computePrefVelocity();
ag_[i]->computeNewVelocity();
}
}
};
class Simulator
{
public:
......@@ -40,6 +71,11 @@ public:
float globalTime_;
float timeStep_;
ThreadUpdateInfo* tc1;
ThreadUpdateInfo* tc2;
ThreadUpdateInfo* tc3;
ThreadUpdateInfo* tc4;
};
#endif
......@@ -45,7 +45,7 @@ void Agent::updateAgentNeighbors()
{
VEC3 pop = part_.m_position - (*it)->part_.m_position;
float distSq = pop.norm2();
if((agentNeighbors_.size() < maxNeighbors_ || distSq < maxDist) && distSq < neighborDistSq_)
if(*it != this && (agentNeighbors_.size() < maxNeighbors_ || distSq < maxDist) && distSq < neighborDistSq_)
{
if(distSq > maxDist)
maxDist = distSq;
......@@ -82,7 +82,7 @@ void Agent::updateObstacleNeighbors()
obstacleNeighbors_.push_back(std::make_pair(distSq, *it));
}
std::sort(obstacleNeighbors_.begin(), obstacleNeighbors_.end(), obstacleSort);
// std::sort(obstacleNeighbors_.begin(), obstacleNeighbors_.end(), obstacleSort);
}
void Agent::update()
......@@ -361,7 +361,7 @@ void Agent::computeNewVelocity()
/* Create agent ORCA lines. */
unsigned int nbA = 0;
for(std::vector<std::pair<float, Agent*> >::iterator it = agentNeighbors_.begin();
it != agentNeighbors_.end() && it->first < neighborDistSq_ && nbA < maxNeighbors_;
it != agentNeighbors_.end() && nbA < maxNeighbors_;
++it, ++nbA)
{
Agent* other = it->second;
......
......@@ -9,7 +9,7 @@
using namespace CGoGN;
EnvMap::EnvMap() : obstacleMark(map, EDGE_CELL), buildingMark(map, FACE_CELL)
EnvMap::EnvMap() : obstacleMark(map, EDGE_CELL), buildingMark(map, FACE_CELL), refineMark(map, FACE_CELL)
{
position = map.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position");
normal = map.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal");
......@@ -46,12 +46,10 @@ Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
void EnvMap::init()
{
float sideSize = 70.0f;
unsigned int nbSquares = 15;
map.check();
unsigned int nbSquares = 25;
CityGenerator::generateCity<PFP>(map, position, obstacleMark, buildingMark, sideSize, nbSquares);
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
map.check();
// 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))
......@@ -218,20 +216,32 @@ void EnvMap::addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbo
void EnvMap::agentChangeFace(Agent* agent, Dart oldFace)
{
Dart newFace = agent->part_.d;
popAgentInCells(agent, oldFace);
// addCoarsenCandidate(oldFace);
pushAgentInCells(agent, newFace);
// coarsenCandidate.insert(std::pair<unsigned int, Dart>(map.getEmbedding(FACE_ORBIT, oldFace), oldFace));
pushAgentInCells(agent, agent->part_.d);
addRefineCandidate(agent->part_.d);
if(!refineMark.isMarked(newFace) && agentvect[newFace].size() > nbAgentsToSubdivide)
{
std::pair<bool,bool>& sf = subdivisableFace[newFace];
if(sf.first == false || (sf.first == true && sf.second))
{
refineMark.mark(newFace);
refineCandidate.push_back(newFace);
}
}
}
void EnvMap::updateMap()
{
assert(map.getCurrentLevel() == map.getMaxLevel()) ;
for(std::map<unsigned int, Dart>::iterator it = refineCandidate.begin(); it != refineCandidate.end(); ++it)
for(std::vector<Dart>::iterator it = refineCandidate.begin(); it != refineCandidate.end(); ++it)
{
Dart d = (*it).second ;
Dart d = (*it) ;
refineMark.unmark(d);
if(agentvect[d].size() > nbAgentsToSubdivide)
{
......
......@@ -8,11 +8,19 @@ Simulator::Simulator() : globalTime_(0.0f), timeStep_(0.2f)
// importAgents("myAgents.pos");
setupScenario(15000);
// addPathsToAgents();
for(unsigned int i = 0; i < agents_.size(); ++i)
unsigned nbAgents = agents_.size();
for(unsigned int i = 0; i < nbAgents; ++i)
{
agents_[i]->updateObstacleNeighbors();
agents_[i]->updateAgentNeighbors();
}
// tc1 = new ThreadUpdateInfo(agents_, 0, nbAgents / 4);
// tc2 = new ThreadUpdateInfo(agents_, nbAgents / 4, nbAgents / 2);
// tc3 = new ThreadUpdateInfo(agents_, nbAgents / 2, nbAgents * 3 / 4);
// tc4 = new ThreadUpdateInfo(agents_, nbAgents * 3 / 4, nbAgents);
}
Simulator::~Simulator()
......@@ -21,65 +29,6 @@ Simulator::~Simulator()
delete agents_[i];
}
class ThreadUpdateInfo
{
public :
std::vector<Agent*> ag_;
unsigned int bMin_;
unsigned int bMax_;
// Constructor
ThreadUpdateInfo(std::vector<Agent*> agents, unsigned int bMin, unsigned int bMax) :
bMin_(bMin),
bMax_(bMax)
{
ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax);
}
// Destructor
~ThreadUpdateInfo() { }
void run()
{
// Thread execution stuff goes here
for (unsigned int i = 0; i < ag_.size(); ++i)
{
ag_[i]->updateObstacleNeighbors();
ag_[i]->updateAgentNeighbors();
ag_[i]->computePrefVelocity();
ag_[i]->computeNewVelocity();
}
}
};
class ThreadUpdatePos
{
public :
std::vector<Agent*> ag_;
unsigned int bMin_;
unsigned int bMax_;
// Constructor
ThreadUpdatePos(std::vector<Agent*> agents, unsigned int bMin, unsigned int bMax) :
bMin_(bMin),
bMax_(bMax)
{
ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax);
}
// Destructor
~ThreadUpdatePos() { }
void run()
{
// Thread execution stuff goes here
for (unsigned int i = 0; i < ag_.size(); ++i)
{
ag_[i]->update();
}
}
};
void Simulator::doStep()
{
envMap_.clearUpdateCandidates();
......@@ -94,23 +43,10 @@ void Simulator::doStep()
agents_[i]->computeNewVelocity();
}
// unsigned nbAgents = agents_.size();
// ThreadUpdateInfo tc1(agents_, 0, nbAgents / 4);
// ThreadUpdateInfo tc2(agents_, nbAgents / 4, nbAgents / 2);
// ThreadUpdateInfo tc3(agents_, nbAgents / 2, nbAgents * 3 / 4);
// ThreadUpdateInfo tc4(agents_, nbAgents * 3 / 4, nbAgents);
// boost::thread thread1(&ThreadUpdateInfo::run, &tc1);
// boost::thread thread2(&ThreadUpdateInfo::run, &tc2);
// boost::thread thread3(&ThreadUpdateInfo::run, &tc3);
// boost::thread thread4(&ThreadUpdateInfo::run, &tc4);
// std::vector<Dart> oldDarts;
// oldDarts.reserve(agents_.size());
// for (unsigned int i = 0; i < agents_.size(); ++i)
// {
// oldDarts.push_back(agents_[i]->part_.d);
// }
// boost::thread thread1(&ThreadUpdateInfo::run, tc1);
// boost::thread thread2(&ThreadUpdateInfo::run, tc2);
// boost::thread thread3(&ThreadUpdateInfo::run, tc3);
// boost::thread thread4(&ThreadUpdateInfo::run, tc4);
// thread1.join();
// thread2.join();
// thread3.join();
......@@ -118,13 +54,6 @@ void Simulator::doStep()
envMap_.map.setCurrentLevel(envMap_.map.getMaxLevel());
// ThreadUpdatePos tc3(agents_,0,agents_.size()/2);
// ThreadUpdatePos tc4(agents_,agents_.size()/2,agents_.size());
// boost::thread thread3(&ThreadUpdatePos::run, &tc3);
// boost::thread thread4(&ThreadUpdatePos::run, &tc4);
// thread3.join();
// thread4.join();
for (unsigned int i = 0; i < agents_.size(); ++i)
{
Dart oldFace = agents_[i]->part_.d;
......@@ -151,9 +80,7 @@ void Simulator::doStep()
globalTime_ += timeStep_;
if(globalTime_ - int(globalTime_) == 0.0f && int(globalTime_) % 500 == 0)
{
swapAgentsGoals();
}
}
void Simulator::setupScenario(unsigned int nbMaxAgent)
......
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