Commit 2858de63 authored by pitiot's avatar pitiot

amelioration structure simulator + envmap.cpp, retrait du cellmarkermemo...

amelioration structure simulator + envmap.cpp, retrait du cellmarkermemo global. remise en fonction de la simplif
parent ff4a4d6a
......@@ -103,6 +103,8 @@ public:
void pushObstacleInCells(Obstacle* o, Dart d) ;
void popObstacleInCells(Obstacle* o, Dart d) ;
void obstacleChangeFace(Obstacle* agent, Dart newFace, Dart oldFace) ;
void refine() ;
void coarse() ;
void updateMap() ;
void resetAgentInFace(Agent* agent) ;
......@@ -119,7 +121,7 @@ public:
CellMarker<EDGE> obstacleMark ;
CellMarker<FACE> buildingMark ;
CellMarker<FACE> pedWayMark ;
CellMarkerMemo<FACE> memo_mark;
// CellMarkerMemo<FACE> memo_mark;
// ajout moving obst
void addObstAsNeighbor (Obstacle * o, const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
// void addMovingObstAsNeighbor (MovingObstacle * mo,std::vector<Dart> belonging_cells, std::vector<Dart> *neighbor_cells);
......@@ -298,8 +300,11 @@ inline void EnvMap::addObstAsNeighbor (Obstacle * o, const std::vector<Dart>& b
assert(map.getCurrentLevel() == map.getMaxLevel());
assert(!belonging_cells.empty());
neighbor_cells->clear();
CellMarkerMemo<FACE> memo_mark(map);
CellMarkerMemo<FACE> OneRingMark(map);
CellMarkerStore<FACE> OneRingMark(map);
for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
memo_mark.mark(*it);
std::vector<Dart>::const_iterator it=belonging_cells.begin();
Dart beg = NIL;
......@@ -341,6 +346,16 @@ inline void EnvMap::addObstAsNeighbor (Obstacle * o, const std::vector<Dart>& b
}
find_next(o,&d, memo_mark);
if(d==NIL)
{
CGoGNout<<"cellule de début : "<<first<<CGoGNendl;
CGoGNout<<"cellules markées OneRing : "<<CGoGNendl;
std::vector<Dart> v=OneRingMark.get_markedCells();
for(std::vector<Dart>::iterator it=v.begin();it<v.end();++it)
{
CGoGNout<<(*it).index<<CGoGNendl;
}
}
// CGoGNout<<"d : "<<d<<CGoGNendl;
}while(!map.sameFace(d,first));
}
......@@ -362,12 +377,30 @@ inline void EnvMap::find_next(Obstacle* o,Dart * ddd, CellMarkerMemo<FACE>& cms)
first = dd;
}
d=map.phi_1(d);
if (rd>10000) {
displayMO(o);
CGoGNout <<(first==NIL)<< " infini find next : "<< *ddd<<CGoGNendl;
break;
if(rd>100)
{
if (rd>10000)
{
displayMO(o);
CGoGNout <<(first==NIL)<< " infini find next d : "<< d<<"phi 2 markée ? : "<<cms.isMarked(map.phi2(d))<<CGoGNendl;
CGoGNout<<"cellules markées : "<<CGoGNendl;
std::vector<Dart> v=cms.get_markedCells();
for(std::vector<Dart>::iterator it=v.begin();it<v.end();++it)
{
CGoGNout<<(*it).index<<CGoGNendl;
}
break;
}
CGoGNout <<(first==NIL)<< " infini find next d : "<< d<<"phi 2 markée ? : "<<cms.isMarked(map.phi2(d))<<CGoGNendl;
CGoGNout<<"cellules markées : "<<CGoGNendl;
std::vector<Dart> v=cms.get_markedCells();
for(std::vector<Dart>::iterator it=v.begin();it<v.end();++it)
{
CGoGNout<<(*it).index<<CGoGNendl;
}
}
d=map.phi_1(d);
}while(first==NIL);
*ddd=first;
}
......
......@@ -101,7 +101,7 @@ public:
void setupCityScenario(int nbLines, int nbRank) ;
void setupScenario(unsigned int nbMaxAgent) ;
void addAgent(const VEC3& start,const VEC3& goal);
void addAgent(const VEC3& start,const std::vector<VEC3>& goal);
void setupMovingObstacle(unsigned int nbObstacles) ;
......@@ -137,7 +137,7 @@ public:
int avoidance;
int nb_dead;
bool multires;
ThreadUpdateInfo* tc1 ;
ThreadUpdateInfo* tc2 ;
ThreadUpdateInfo* tc3 ;
......
......@@ -196,7 +196,7 @@ void Agent::update()
pos = pos + (velocity_ * sim->timeStep_) ;
#else
VEC3 target = part_.getPosition() + (velocity_ * sim_->timeStep_) ;
obstacle_priority(&target);
#endif
meanSpeed_ *= 3.0f ;
......@@ -279,6 +279,7 @@ void Agent::computePrefVelocity()
}
prefVelocity_ = goalVector ;
obstacle_priority(&prefVelocity_);
}
void Agent::computeNewVelocity2()
......
This diff is collapsed.
......@@ -140,7 +140,7 @@ void MovingObstacle::updateFixedObstNeighbors()
for(int k =0;k<2;k++)
{
registering_part->get_memo(vertices[k],sim_->envMap_.memo_mark);
registering_part->get_memo(vertices[k]);
std::vector<Obstacle*>& obst = sim_->envMap_.obstvect[registering_part->d];
//search all obstacles around
......@@ -366,6 +366,10 @@ void MovingObstacle::register_oneRingAdd(Obstacle * o, Dart d, int n)
void register_add(Obstacle* o, int n, const std::vector<Dart>& memo_cross)
{
if(memo_cross.empty())
{
displayMO(o);
}
assert(!memo_cross.empty());
MovingObstacle * mo = o->mo;
......@@ -390,10 +394,10 @@ void register_add(Obstacle* o, int n, const std::vector<Dart>& memo_cross)
std::vector<Dart> MovingObstacle::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1)
{
registering_part->get_memo(pos,sim_->envMap_.memo_mark);
registering_part->get_memo(pos);
d1=registering_part->d;
// CGoGNout<<"d1 : "<< *d1<<"|| d2 : "<< *d2<<"|| start : "<< pos<<"|| stop : "<< dest<<CGoGNendl;
return (registering_part->get_memo(dest,sim_->envMap_.memo_mark));
return (registering_part->get_memo(dest));
}
void MovingObstacle::register_update(Obstacle* o, int n)// maj de l'enregistrement
......@@ -474,7 +478,7 @@ void resetPartSubdiv(Obstacle* o)
VEC3 pos =mo->registering_part->getPosition();
mo->registering_part->ParticleBase<PFP>::move(Algo::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, mo->registering_part->d, mo->sim_->envMap_.position)) ;
mo->registering_part->setState(FACE) ;
mo->registering_part->get_memo(pos,mo->sim_->envMap_.memo_mark) ;
mo->registering_part->get_memo(pos) ;
}
}
......
......@@ -13,6 +13,7 @@ Simulator::Simulator(int minSize) :
avoidance(1),
nb_dead(0)
{
multires=true;
srand(10) ;
nbStepsPerUnit_ = 1 / timeStep_ ;
init(1, minSize, 2.0f) ;
......@@ -27,7 +28,7 @@ Simulator::~Simulator()
void Simulator::init(unsigned int config, int minSize, float dimension, bool enablePathFinding)
{
std::cout << "Setup scenario" << std::endl ;
envMap_.init(config, 1500.0f, 1000.0f, minSize, 50.0f) ;
envMap_.init(config, 1600.0f, 960.0f, minSize, 320.0f) ;
switch (config)
{
......@@ -35,7 +36,7 @@ void Simulator::init(unsigned int config, int minSize, float dimension, bool ena
setupCircleScenario(100) ;
break ;
case 1 :
setupCorridorScenario(500,100) ;
setupCorridorScenario(1000,100) ;
break ;
case 2 :
setupScenario(1000) ;
......@@ -71,7 +72,7 @@ void Simulator::init(unsigned int config, int minSize, float dimension, bool ena
}
#ifndef SPATIAL_HASHING
// envMap_.subdivideToProperLevel() ;
if (multires) envMap_.subdivideToProperLevel() ;
// envMap_.subdivideAllToMaxLevel();
#endif
......@@ -125,7 +126,7 @@ void Simulator::doStep()
}
}
#else
envMap_.map.setCurrentLevel(envMap_.map.getMaxLevel()) ;
if (multires) envMap_.map.setCurrentLevel(envMap_.map.getMaxLevel()) ;
nb_dead = 0 ;
for (unsigned int i = 0 ; i < agents_.size() ; ++i)
{
......@@ -153,7 +154,7 @@ void Simulator::doStep()
nbRefineCandidate += envMap_.refineCandidate.size() ;
nbCoarsenCandidate += envMap_.coarsenCandidate.size() ;
envMap_.updateMap() ;
if (multires) envMap_.updateMap() ;
#endif
globalTime_ += timeStep_ ;
......@@ -170,7 +171,7 @@ bool Simulator::reachedGoal()
return true ;
}
void Simulator::addAgent(const VEC3& start, const VEC3& goal)
void Simulator::addAgent(const VEC3& start, const std::vector<VEC3>& goal)
{
#ifdef SPATIAL_HASHING
Agent* a = new Agent(this, start) ;
......@@ -181,7 +182,7 @@ void Simulator::addAgent(const VEC3& start, const VEC3& goal)
agents_.push_back(new Agent(this, start, dCell)) ;
#endif
agents_.back()->goals_.push_back(goal) ;
agents_.back()->goals_=goal ;
agents_.back()->curGoal_ = 0 ;
}
......@@ -209,8 +210,10 @@ void Simulator::setupCircleScenario(unsigned int nbAgents)
VEC3 v(std::cos(angle) * radius, std::sin(angle) * radius, 0) ;
VEC3 start = center + v ;
VEC3 goal = center - v ;
addAgent(start, goal) ;
std::vector<VEC3> goals;
goals.push_back(start);
goals.push_back(goal);
addAgent(start, goals) ;
}
for (unsigned int i = 0 ; i < movingObstacles_.size() ; ++i)
......@@ -263,8 +266,10 @@ void Simulator::setupCorridorScenario(unsigned int nbAgents, unsigned int nbObst
goal = start ;
start = tmp ;
}
addAgent(start, goal) ;
std::vector<VEC3> goals;
goals.push_back(start);
goals.push_back(goal);
addAgent(start, goals) ;
}
// Départ des obstacles du quart haut sur toute une demi-largeur
......
......@@ -237,10 +237,10 @@ void SocialAgents::cb_redraw()
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
glColor3f(1.0f, 1.0f, 1.0f) ;
glLineWidth(1.0f) ;
if((*it)->index==24)
{
glColor3f(1.0f, 0.0f, 0.5f) ;
}
// if((*it)->index==74)
// {
// glColor3f(1.0f, 0.0f, 0.5f) ;
// }
glBegin(GL_POLYGON) ;
for (unsigned int i = 0 ; i < ((*it)->nbVertices) ; ++i)
......@@ -309,43 +309,43 @@ void SocialAgents::cb_redraw()
// }
// }
CellMarker<FACE> m(sim.envMap_.map) ;
for (Dart d = sim.envMap_.map.begin(); d != sim.envMap_.map.end(); sim.envMap_.map.next(d))
{
if (!m.isMarked(d) && !sim.envMap_.buildingMark.isMarked(d))
{
m.mark(d) ;
Dart dd = d ;
VEC3 cornerLeftBottom = sim.envMap_.position[d] ;
do
{
VEC3 p = sim.envMap_.position[dd] ;
if (cornerLeftBottom[0] > p[0]) cornerLeftBottom[0] = p[0] ;
if (cornerLeftBottom[1] > p[1]) cornerLeftBottom[1] = p[1] ;
if (cornerLeftBottom[2] > p[2]) cornerLeftBottom[2] = p[2] ;
dd = sim.envMap_.map.phi1(dd) ;
} while (dd != d) ;
//draw vectors
//contains
for (unsigned int i = 0; i < sim.envMap_.obstvect[d].size(); ++i)
{
Obstacle* ag = sim.envMap_.obstvect[d][i] ;
if (ag->mo!=NULL)
{
VEC3 col = Utils::color_map_BCGYR(float(ag->mo->index) / float(sim.movingObstacles_.size())) ;
glColor3fv(col.data()) ;
glBegin(GL_POINTS) ;
if (i < 5)
glVertex3f(cornerLeftBottom[0] + 5 + 1 + i * 2, cornerLeftBottom[1] + 7 + 1.5, cornerLeftBottom[2] + 2) ;
else
glVertex3f(cornerLeftBottom[0] + 5 + 1 + (i - 5) * 2, cornerLeftBottom[1] + 7 + 1.5 + 3, cornerLeftBottom[2] + 2) ;
glEnd() ;
}
}
}
}
// CellMarker<FACE> m(sim.envMap_.map) ;
// for (Dart d = sim.envMap_.map.begin(); d != sim.envMap_.map.end(); sim.envMap_.map.next(d))
// {
// if (!m.isMarked(d) && !sim.envMap_.buildingMark.isMarked(d))
// {
// m.mark(d) ;
//
// Dart dd = d ;
// VEC3 cornerLeftBottom = sim.envMap_.position[d] ;
// do
// {
// VEC3 p = sim.envMap_.position[dd] ;
// if (cornerLeftBottom[0] > p[0]) cornerLeftBottom[0] = p[0] ;
// if (cornerLeftBottom[1] > p[1]) cornerLeftBottom[1] = p[1] ;
// if (cornerLeftBottom[2] > p[2]) cornerLeftBottom[2] = p[2] ;
// dd = sim.envMap_.map.phi1(dd) ;
// } while (dd != d) ;
//
// //draw vectors
// //contains
// for (unsigned int i = 0; i < sim.envMap_.obstvect[d].size(); ++i)
// {
// Obstacle* ag = sim.envMap_.obstvect[d][i] ;
// if (ag->mo!=NULL)
// {
// VEC3 col = Utils::color_map_BCGYR(float(ag->mo->index) / float(sim.movingObstacles_.size())) ;
// glColor3fv(col.data()) ;
// glBegin(GL_POINTS) ;
// if (i < 5)
// glVertex3f(cornerLeftBottom[0] + 5 + 1 + i * 2, cornerLeftBottom[1] + 7 + 1.5, cornerLeftBottom[2] + 2) ;
// else
// glVertex3f(cornerLeftBottom[0] + 5 + 1 + (i - 5) * 2, cornerLeftBottom[1] + 7 + 1.5 + 3, cornerLeftBottom[2] + 2) ;
// glEnd() ;
// }
// }
// }
// }
}
......
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