Commit 7f90ed0e authored by pitiot's avatar pitiot

multiple particules optimisées

parent b5f9230a
......@@ -56,9 +56,6 @@ public:
Dart finalDart ;
MovingObstacle **movingObstacles_;
int nb_mos;
MovingObstacle **movingObstacles_;
int nb_mos;
......
......@@ -405,7 +405,7 @@ Dart generateBuilding(EnvMap& envMap, Dart d, float height, unsigned int buildin
Dart x =map.phi2(dd);
if(!map.isBoundaryMarked(x))
{
addElementToVector<Obstacle*>(envMap.obstvect[d],o);
addElementToVector<Obstacle*>(envMap.obstvect[x],o);
if(!map.isBoundaryMarked(map.phi2(map.phi1(x))))
addElementToVector<Obstacle*>(envMap.obstvect[map.phi2(map.phi1(x))],o);
......
......@@ -181,7 +181,7 @@ void update_registration(Obstacle * o);
void register_pop(Obstacle* o, int n);
void resetPartSubdiv(Obstacle* o);
void resetObstPartInFace(Obstacle* o, Dart d);// empeche de viser une dart ayant disparu
void resetPart(MovingObstacle * mo, Dart d); // empeche de viser une dart ayant disparu pour les voisins
void resetPart(Obstacle * mo, Dart d); // empeche de viser une dart ayant disparu pour les voisins
void displayMO(Obstacle * o);
/**************************************
......
......@@ -50,7 +50,7 @@ inline void renderObstacle(EnvMap& m, MovingObstacle * obst, bool showBelonging=
for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
{
const VEC3& p = obst->vertices[i] ;
const VEC3& p = obst->parts_[i]->getPosition() ;
glVertex3fv(p.data()) ;
}
glEnd() ;
......
......@@ -24,13 +24,13 @@ public:
bool is_inside (VEC3 p);
void computePrefVelocity();
void computeNewVelocity();
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1, CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP> * registering_part);
void update();
unsigned int nbVertices;
CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP> *registering_part;
std::vector<PFP::VEC3> vertices;
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP>* * parts_;
float gravity_dist;
VEC3 center;
int nb_agents_voisins;
......
......@@ -202,19 +202,23 @@ void Agent::updateObstacleNeighbors()
{
if ((*it)->mo==NULL)
{
float distSq = distSqPointLineSegment((*it)->p1, (*it)->p2, part_.getPosition()) ;
// CGoGNout<<"obst trouvé : " << distSq;
if ((obstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistObst)
&&distSq < rangeSq_)
{
// CGoGNout<<"obst assez pres :";
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
// CGoGNout<<"obst bien orienté";
if (distSq > maxDistObst) maxDistObst = distSq ;
obstacleNeighbors_.push_back(std::make_pair(distSq, *it)) ;
}
}
// CGoGNout<<CGoGNendl;
}
else
{
......
......@@ -100,7 +100,7 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
std::string filename2 = "./svg/mapBuild.svg" ;
Algo::Import::importSVG<PFP>(mapScenary, filename2, positionScenary, obstacleMarkS, buildingMarkS) ;
Geom::BoundingBox<typename PFP::VEC3> bb1, bb2 ;
Geom::BoundingBox<PFP::VEC3> bb1, bb2 ;
bb1 = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
bb2 = Algo::Geometry::computeBoundingBox<PFP>(mapScenary, positionScenary) ;
bb1.addPoint(bb2.min());
......@@ -536,14 +536,16 @@ void EnvMap::pushObstacleInCells(Obstacle * o)// réenregistre l'obstacle en que
if (mo != NULL)
{
int n = o->index;
VEC3 p1 = mo->vertices[n];
VEC3 p2 = mo->vertices[(n+1)%(mo->nbVertices)];
VEC3 p1 = mo->parts_[n]->getPosition();
VEC3 p2 = mo->parts_[(n+1)%mo->nbVertices]->getPosition();
Dart d1=NIL;
Dart d2=NIL;
std::vector<Dart> memo;
memo = mo->getMemoCross(p1,p2,d1);
d2=mo->registering_part->d;
CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP> * registering_part = new CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP>(map, mo->parts_[n]->d,mo->parts_[n]->getPosition(),position);
memo = mo->getMemoCross(p1,p2,d1,registering_part);
d2=registering_part->d;
if(map.sameFace(d1,d2))
{
......@@ -559,20 +561,20 @@ void EnvMap::pushObstacleInCells(Obstacle * o)// réenregistre l'obstacle en que
void EnvMap::popAndPushObstacleInCells(Obstacle* o, int n)// maj de l'enregistrement
{
MovingObstacle * mo = o->mo;
VEC3 p1 = mo->vertices[n];
VEC3 p2 = mo->vertices[(n+1)%mo->nbVertices];
VEC3 p1 = mo->parts_[n]->getPosition();
VEC3 p2 = mo->parts_[(n+1)%mo->nbVertices]->getPosition();
Dart d1=NIL;
Dart d2=NIL;
std::vector<Dart> memo;
CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP> * registering_part = new CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP>(map, mo->parts_[n]->d,mo->parts_[n]->getPosition(),position);
// bool modif=false;
// if(p1->crossCell != CGoGN::Algo::MovingObjects::NO_CROSS
// || p2->crossCell != CGoGN::Algo::MovingObjects::NO_CROSS)
// {
memo = mo->getMemoCross(p1,p2,d1);
d2=mo->registering_part->d;
memo = mo->getMemoCross(p1,p2,d1,registering_part);
d2=registering_part->d;
// memo.sort();
// modif=true;
// }
......@@ -990,11 +992,9 @@ void EnvMap::coarse()
}
for (PFP::OBSTACLEVECT::iterator ait = resetob.begin(); ait != resetob.end(); ++ait)
{
MovingObstacle* mo = (*ait)->mo ;
if (mo != NULL)
{
resetPart(mo,nf) ;
}
resetPart(*ait,nf) ;
}
map.setCurrentLevel(fLevel - 1) ;
}
......
......@@ -77,6 +77,7 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
parent(art),
index_parent(ind2)
{
seen = false;
color1=1.0f;
color2=1.0f;
......@@ -94,10 +95,9 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
velocity_factor = 0.8f;
nbVertices = pos.size();
Dart d = sim_->envMap_.getBelongingCell(pos[0]);
registering_part = new CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP>(sim_->envMap_.map, d, pos[0], sim_->envMap_.position);
vertices.reserve(nbVertices);
parts_ = new CGoGN::Algo::MovingObjects::ParticleCell2D<PFP>*[nbVertices];
obstacles_ = new Obstacle*[nbVertices];
belonging_cells = new std::vector<Dart>[nbVertices];
neighbor_cells = new std::vector<Dart>[nbVertices];
......@@ -132,14 +132,22 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
}
for (unsigned int i = 0; i < nbVertices; ++i)
{
Dart d = sim_->envMap_.getBelongingCell(pos[i]);
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP>* part = new CGoGN::Algo::MovingObjects::ParticleCell2D<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
parts_[i] = part;
}
for (unsigned int i = 0; i < nbVertices; ++i)
{
Obstacle* o = new Obstacle(vertices[i],
vertices[(i + 1) % nbVertices],
vertices[(i - 1 + nbVertices) % nbVertices],
vertices[(i + 2) % nbVertices], this, i);
obstacles_[i] = o;
sim_->envMap_.pushObstacleInCells(o);
}
......@@ -363,15 +371,16 @@ void MovingObstacle::update()
for (unsigned int i = 0; i < nbVertices; ++i)
{
VEC3 target =vertices[i];
VEC3 target =parts_[i]->getPosition();
target += rotate(vertices[i], center, abs_angle*rotor);
target += rotate(parts_[i]->getPosition(), center, abs_angle*rotor);
target += (velocity_ * sim_->timeStep_);
vertices[i]=target;
parts_[i]->move(target);
bary += target;
vertices[i]=parts_[i]->getPosition();
}
front=(vertices[1] + vertices[2]) / 2;
front=(parts_[1]->getPosition() + parts_[2]->getPosition()) / 2;
if(angle >0)
{
angle -= rotor;
......@@ -385,7 +394,7 @@ void MovingObstacle::update()
//-------- code ajoute par Arash pour les obstacles rectangulaires --------------
VEC3 P0_P1 = vertices[1] - vertices[0];
VEC3 P0_P1 = parts_[1]->getPosition() - parts_[0]->getPosition();
float velocity_coef = 10.0;
if(P0_P1 * velocity_ > 0) // P0_P1 est dans le sens de la vitesse
......@@ -411,7 +420,12 @@ void MovingObstacle::update()
// o->p2 = parts_[(i + 1) % nbVertices]->getPosition();
// o->prevP = parts_[(i - 1 + nbVertices) % nbVertices]->getPosition();
// o->nextP = parts_[(i + 2) % nbVertices]->getPosition();
sim_->envMap_.popAndPushObstacleInCells(o,i);
Dart d1 = parts_[i]->d;
Dart d2 = parts_[(i+1)%nbVertices]->d;
if(!((sim_->envMap_.map.sameFace(d1,d2))&& (parts_[i]->crossCell==CGoGN::Algo::MovingObjects::NO_CROSS && parts_[(i+1)%nbVertices]->crossCell==CGoGN::Algo::MovingObjects::NO_CROSS)))
{
sim_->envMap_.popAndPushObstacleInCells(o,i);
}
if(sim_->detect_agent_collision)
......@@ -450,7 +464,7 @@ void MovingObstacle::update()
}
std::vector<Dart> MovingObstacle::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1)
std::vector<Dart> MovingObstacle::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1, CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP> * registering_part)
{
registering_part->move(pos);
......@@ -465,33 +479,42 @@ void resetPartSubdiv(Obstacle* o)
if (mo != NULL)
{
VEC3 pos =mo->registering_part->getPosition();
mo->registering_part->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, mo->registering_part->d, mo->sim_->envMap_.position)) ;
int n =o->index;
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> * registering_part=mo->parts_[n];
VEC3 pos =registering_part->getPosition();
registering_part->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, registering_part->d, mo->sim_->envMap_.position)) ;
mo->registering_part->setState(FACE) ;
mo->registering_part->move(pos) ;
registering_part->setState(FACE) ;
registering_part->move(pos) ;
}
}
void resetObstPartInFace(Obstacle* o, Dart d1)
{
MovingObstacle * mo = o->mo;
if (mo != NULL) {
VEC3 pos1 = mo->registering_part->getPosition();
int n =o->index;
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> * registering_part=mo->parts_[n];
VEC3 pos1 = registering_part->getPosition();
if (Algo::Geometry::isPointInConvexFace2D < PFP
> (mo->sim_->envMap_.map, d1, mo->sim_->envMap_.position, pos1, true)) {
mo->registering_part->d = d1;
registering_part->d = d1;
}
}
}
void resetPart(MovingObstacle * mo, Dart d1)
void resetPart(Obstacle * o, Dart d1)
{
if (mo->registering_part->d == mo->sim_->envMap_.map.phi1(d1))
mo->registering_part->d = d1;
MovingObstacle * mo = o->mo;
if(mo!=NULL)
{
int n =o->index;
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> * registering_part=mo->parts_[n];
if (registering_part->d == mo->sim_->envMap_.map.phi1(d1))
registering_part->d = d1;
}
}
......
......@@ -15,7 +15,7 @@ Simulator::Simulator(unsigned int config, unsigned int minS) :
{
minSize=minS;
multires=true;
detect_agent_collision=true;
detect_agent_collision=false;
srand(10) ;
nbStepsPerUnit_ = 1 / timeStep_ ;
......@@ -40,7 +40,7 @@ void Simulator::init( float dimension, bool enablePathFinding)
setupCircleScenario(1000,20) ;
break ;
case 1 :
setupCorridorScenario(1000,40) ;
setupCorridorScenario(1000,500) ;
break ;
case 2 :
setupSnakeCorridorScenario(1000,5,10) ;
......@@ -676,7 +676,7 @@ void Simulator::addPathToObstacles()
for (std::vector<MovingObstacle*>::iterator it = movingObstacles_.begin() ; it != movingObstacles_.end() ; ++it)
{
Dart dStart = (*it)->registering_part->d;
Dart dStart = (*it)->parts_[0]->d;
Dart dStop = dStart;
for (unsigned int j = 0 ; envMap_.buildingMark.isMarked(dStop)
......
......@@ -212,12 +212,17 @@ void SocialAgents::cb_redraw()
renderAgent(simulator.envMap_, *it, drawAgentsNeighborDist, drawAgentsObstacleDist, drawAgentsPath,
(*it)->color1, (*it)->color2, (*it)->color3) ;
// for (std::vector<std::pair<float, Dart> >::iterator obst = (*it)->obstacleNeighbors_.begin();
// for (std::vector<std::pair<float, Obstacle *> >::iterator obst = (*it)->obstacleNeighbors_.begin();
// obst != (*it)->obstacleNeighbors_.end() && obst->first < (*it)->rangeSq_; ++obst)
// {
// glColor3f(0.0f, 1.0f, 1.0f) ;
// CGoGNout<<"et de un"<<CGoGNendl;
// glColor3f(1.0f, 0.0f, 0.0f) ;
// glLineWidth(10.0f) ;
// renderDart(sim.envMap_, obst->second) ;
// Obstacle * ob = obst->second;
// glBegin(GL_LINES) ;
// glVertex3fv(ob->p1.data());
// glVertex3fv(ob->p2.data());
// glEnd();
// }
}
......@@ -500,8 +505,8 @@ void SocialAgents::cb_redraw()
if (drawObstacles)
{
glColor3f(0.0f, 0.0f, 1.0f) ;
glLineWidth(3.0f) ;
glColor3f(1.0f, 0.0f, 0.0f) ;
glLineWidth(10.0f) ;
TraversorE<PFP::MAP> tE(simulator.envMap_.map);
for (Dart d = tE.begin() ; d != tE.end() ; d = tE.next())
......@@ -513,20 +518,20 @@ void SocialAgents::cb_redraw()
// renderFace(simulator.envMap_,d);
// }
// if ((simulator.envMap_.obstvect[d].size()) != 0)
// {
// renderFace(simulator.envMap_, d) ;
// }
if ((simulator.envMap_.obstvect[d].size()) != 0 )
{
renderFace(simulator.envMap_, d) ;
}
// if(simulator.envMap_.obstacleMark.isMarked(d))
// {
// renderDart(simulator.envMap_,d);
// }
if(simulator.envMap_.map.isBoundaryEdge(d))
{
renderDart(simulator.envMap_,d);
}
// if(simulator.envMap_.map.isBoundaryEdge(d))
// {
// renderDart(simulator.envMap_,d);
// }
}
#ifdef SPATIAL_HASHING
......@@ -635,7 +640,7 @@ void SocialAgents::cb_redraw()
struct timespec realTime ;
clock_gettime(CLOCK_MONOTONIC, &realTime) ;
time_t elapsedTime = realTime.tv_sec - startTime.tv_sec ;
if(nbIterations == maxIterations -1) CGoGNout << "temps mis pour "<<maxIterations<< " : "<< elapsedTime<<CGoGNendl;
if (elapsedTime >= nextUpdate)
{
// Sortie des stats pour analyse externe
......@@ -1396,8 +1401,8 @@ int main(int argc, char** argv)
sa.setGeometry(0, 0, 1800, 1200) ;
sa.initGUI() ;
sa.show() ;
// if (argc > 1)
// sa.timer->start() ;
if (argc > 1)
sa.timer->start() ;
return app.exec() ;
}
......@@ -12,7 +12,7 @@
viewBox="0 0 1310 1173"
version="1.1"
id="svg2"
inkscape:version="0.48.1 r9760"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="mapCleaned.svg">
<metadata
id="metadata20589">
......@@ -36,16 +36,17 @@
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1680"
inkscape:window-height="1021"
inkscape:window-height="991"
id="namedview20587"
showgrid="false"
inkscape:zoom="2.5600001"
inkscape:cx="1270.5016"
inkscape:cy="245.44341"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:zoom="1.8101934"
inkscape:cx="531.37166"
inkscape:cy="904.14257"
inkscape:window-x="1920"
inkscape:window-y="27"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
inkscape:current-layer="svg2"
inkscape:object-nodes="true" />
<defs
id="defs4">
<g
......@@ -14935,10 +14936,11 @@
id="path6187"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#bababa;stroke-width:5.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;color:#000000;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 164.61719,501.41016 183.33594,518.38281 273.75,433.17187"
style="color:#000000;fill:none;stroke:#bababa;stroke-width:5.5999999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 164.61719,501.41016 18.71875,16.97265 87.04687,-88.47265"
id="path6189"
inkscape:connector-curvature="0" />
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
<path
style="fill:none;stroke:#bababa;stroke-width:5.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;color:#000000;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 1268.3555,154.52344 1304.9531,51.203125"
......@@ -14980,10 +14982,11 @@
id="path6241"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#bababa;stroke-width:5.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;color:#000000;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
style="color:#000000;fill:none;stroke:#bababa;stroke-width:5.5999999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 87.691406,194.32031 9.246094,11.60938 31.62109,40.65625 6.6211,8.83984 73.02343,98.10156 13.625,20.03125 30.5586,37.90625 17.99609,18.44532 3.36719,3.26171"
id="path6243"
inkscape:connector-curvature="0" />
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccc" />
<path
style="fill:none;stroke:#bababa;stroke-width:5.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;color:#000000;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 101.39063,554.23437 63.22656,-52.82421"
......@@ -12,7 +12,7 @@
viewBox="0 0 1310 1173"
version="1.1"
id="svg2"
inkscape:version="0.48.1 r9760"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="mapRoads.svg">
<metadata
id="metadata20589">
......@@ -36,14 +36,14 @@
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1680"
inkscape:window-height="1021"
inkscape:window-height="991"
id="namedview20587"
showgrid="false"
inkscape:zoom="0.45254835"
inkscape:cx="444.14566"
inkscape:cy="746.80007"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:zoom="7.2407736"
inkscape:cx="340.96034"
inkscape:cy="899.38878"
inkscape:window-x="1920"
inkscape:window-y="27"
inkscape:window-maximized="1"
inkscape:current-layer="svg2"
inkscape:object-nodes="true"
......@@ -18639,9 +18639,10 @@
inkscape:connector-curvature="0" />
<path
style="color:#000000;fill:none;stroke:#bababa;stroke-width:5.5999999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 164.61719,501.41007 18.71875,16.9726 90.41406,-85.2109"
d="m 164.61719,501.41007 18.71875,16.9726 87.04687,-88.4726"
id="path6189"
inkscape:connector-curvature="0" />
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
<path
style="color:#000000;fill:none;stroke:#bababa;stroke-width:5.5999999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 181.64453,906.33588 -7.44141,7.3593 -19.21093,18.2969 -23.32813,19.41019 -23.76562,6.9609 -24.480471,7.6094 -15.117188,4.2226"
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