Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit fd3a323a authored by Jund Thomas's avatar Jund Thomas
Browse files

up

parents ec750a6b eb5c416c
......@@ -49,13 +49,27 @@ struct PFP: public PFP_STANDARD
};
typedef PFP::VEC3 VEC3;
typedef PFP::REAL REAL ;
class EnvMap
{
public :
EnvMap();
void markPedWay();
/* Geometry of the EnvMap : the bounding box of the scene
* The density of cells in the EnvMap is given by two parameters :
* - minCellSize : the size under which no subdivision occurs
* - maxCellSize : the size of the initial cells (before subdivisions occur)
* - obstacleDistance : the minimal goal distance between agents and obstacles
* The number of cells in the initial EnvMap is about (width*height)/(size*size)
*/
Geom::BoundingBox<VEC3> geometry ;
REAL maxCellSize ;
REAL minCellSize ;
REAL obstacleDistance ;
void markPedWay() ;
float max_for_obstacles;
float sideSize;
unsigned int nbSquares;
......@@ -69,7 +83,7 @@ public :
void subdivideToProperLevel();
#endif
void init(unsigned int config);
void init(unsigned int config, REAL width, REAL height, REAL minSize, REAL maxSize) ;
#ifndef SPATIAL_HASHING
void foreach_neighborFace(Dart d, FunctorType& f);
......@@ -255,7 +269,7 @@ inline void EnvMap::addObstAsNeighbor (Obstacle * o, const std::list<Dart>& bel
Dart first =NIL;
Dart d=NIL;
Dart dd=NIL;
// CGoGNout << "debut"<<CGoGNendl;
//boucle pour trouver une face du voisinage de l'obstacle ne contenant pas l'obstacle
do
{
......
......@@ -17,52 +17,54 @@
class ThreadUpdateInfo
{
public :
std::vector<Agent*> ag_;
unsigned int bMin_;
unsigned int bMax_;
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)
bMin_(bMin), bMax_(bMax)
{
ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax);
ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax) ;
}
// Destructor
~ThreadUpdateInfo() { }
~ThreadUpdateInfo()
{
}
void run()
{
// Thread execution stuff goes here
// 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();
ag_[i]->computePrefVelocity() ;
ag_[i]->computeNewVelocity() ;
}
}
};
} ;
class ThreadUpdatePos
{
public :
std::vector<Agent*> ag_;
unsigned int bMin_;
unsigned int bMax_;
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)
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);
ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax) ;
}
// Destructor
~ThreadUpdatePos() { }
~ThreadUpdatePos()
{
}
void run() {
// Thread execution stuff goes here
......@@ -76,7 +78,7 @@ public :
class Simulator
{
public:
Simulator();
Simulator(int minSize);
Simulator(
float timeStep, float neighborDist, unsigned int maxNeighbors,
......@@ -86,13 +88,14 @@ public:
~Simulator();
void init(unsigned int config, float dimension, bool enablePathFinding=false);
void init(unsigned int config, int minSize, float dimension, bool enablePathFinding = false) ;
void doStep();
bool reachedGoal();
void setupCircleScenario(unsigned int nbMaxAgent);
void setupCorridorScenario(unsigned int nbMaxAgent,int nb_obst);
void setupCityScenario(float startX, float startY, int nbLines , int nbRank);
void setupScenario(unsigned int nbMaxAgent);
......
......@@ -23,6 +23,7 @@
*******************************************************************************/
#include <iostream>
#include <sys/time.h>
#include "Utils/Qt/qtSimple.h"
#include "ui_socialAgents.h"
......@@ -50,7 +51,7 @@ class SocialAgents : public Utils::QT::SimpleQT
Q_OBJECT
public:
SocialAgents() ;
SocialAgents(int minSize = Agent::neighborDist_, int iterations = 0) ;
void initGUI() ;
......@@ -68,6 +69,9 @@ public:
QTimer* timer;
int nbIterations ;
// Number of iterations before stopping the animation (0 if interactive animation)
int maxIterations ;
// to count fps
int frames;
clock_t nextUpdate;
......
......@@ -291,23 +291,23 @@ void Agent::computePrefVelocity()
goalVector = goals_[curGoal_] - pos;
#else
VEC3 possiblepos=goals_[curGoal_];
int x =rand() % 2 +1;
/*int x =rand() % 2 +1;
if (x==2){
possiblepos[1]*=-(x-1)*1.0f;
x=rand() % 2 +1;
if (x==2) possiblepos[0]*=-(x-1)*1.0f;
}
else possiblepos[0]*=-1.0f;
else*/ possiblepos[0]*=-1.0f;
Dart d1 =sim_->envMap_.getBelongingCell(possiblepos);
if (sim_->envMap_.buildingMark.isMarked(d1))
{
if (((possiblepos[0]+sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles) && ((possiblepos[1]+sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles)) possiblepos += VEC3(sim_->envMap_.sideSize,sim_->envMap_.sideSize,0);
else if (((possiblepos[0]-sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles) && ((possiblepos[1]-sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles))possiblepos += VEC3(-sim_->envMap_.sideSize,-sim_->envMap_.sideSize,0);
else if (((possiblepos[0]-sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles) && ((possiblepos[1]+sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles))possiblepos += VEC3(-sim_->envMap_.sideSize,sim_->envMap_.sideSize,0);
else possiblepos += VEC3(sim_->envMap_.sideSize,-sim_->envMap_.sideSize,0);
}
// Dart d1 =sim_->envMap_.getBelongingCell(possiblepos);
// if (sim_->envMap_.buildingMark.isMarked(d1))
// {
// if (((possiblepos[0]+sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles) && ((possiblepos[1]+sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles)) possiblepos += VEC3(sim_->envMap_.sideSize,sim_->envMap_.sideSize,0);
// else if (((possiblepos[0]-sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles) && ((possiblepos[1]-sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles))possiblepos += VEC3(-sim_->envMap_.sideSize,-sim_->envMap_.sideSize,0);
// else if (((possiblepos[0]-sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles) && ((possiblepos[1]+sim_->envMap_.sideSize) <sim_->envMap_.max_for_obstacles))possiblepos += VEC3(-sim_->envMap_.sideSize,sim_->envMap_.sideSize,0);
// else possiblepos += VEC3(sim_->envMap_.sideSize,-sim_->envMap_.sideSize,0);
// }
goals_[curGoal_]=possiblepos;
goalVector = goals_[curGoal_] - part_.m_position;
#endif
......
......@@ -59,6 +59,72 @@ EnvMap::EnvMap() :
#endif
}
void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, REAL maxSize)
{
sideSize = maxSize;
nbSquares = width/maxSize;
max_for_obstacles=(sideSize*nbSquares/2)-sideSize/2;
std::cout << "Init EnvMap" << std::endl ;
VEC3 bottomLeft(-width / 2, -height / 2, 0.0f) ;
VEC3 topRight(width / 2, height / 2, 0.0f) ;
geometry.reset() ;
geometry.addPoint(bottomLeft) ;
geometry.addPoint(topRight) ;
minCellSize = minSize ;
maxCellSize = maxSize ;
std::cout << " - Geometry : " << geometry ;
std::cout << " - Cell size between : " << minSize << " and " << maxSize << std::endl ;
#ifdef SPATIAL_HASHING
std::cout << " - Table de hachage : " << agentGridSize(0) << " x " << agentGridSize(1) << std::endl ;
#endif
switch (config)
{
case 0 : CityGenerator::generateGrid<PFP>(map, position, nbSquares, nbSquares, sideSize, obstacleMark, buildingMark);
break;
case 1 :CityGenerator::generateGrid<PFP>(map, position, nbSquares, nbSquares, sideSize, obstacleMark, buildingMark);
break;
case 2 : CityGenerator::generateCity<PFP>(this, sideSize, nbSquares);
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
break;
case 3 :
{
// std::string filename = "/home/jund/Desktop/drawingQuads.svg";
// std::string filename = "/home/jund/Desktop/drawingTest.svg";
// std::string filename = "/home/jund/Desktop/drawingSimple.svg";
// std::string filename = "/home/jund/Desktop/drawingLines.svg";
// std::string filename = "/home/jund/Desktop/mapKrutSimple.svg";
// std::string filename = "/home/jund/Desktop/mapKrut.svg";
// Algo::Import::importSVG<PFP>(map,filename,position, obstacleMark, buildingMark);
// scale(3.2808399f);
//
// Algo::BooleanOperator::mergeVertices<PFP>(map, position);
// map.closeMap();
// Algo::Modelisation::CatmullClarkSubdivision<PFP>(map, position);
// Algo::Modelisation::computeDual<PFP>(map);
}
break;
case 4 : CityGenerator::generatePlanet<PFP>(map, position, obstacleMark, buildingMark, 200.0f, nbSquares);
break;
}
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
// CityGenerator::convexifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
// CityGenerator::installGuardRail<PFP>(map, position, obstacleMark, buildingMark, 5.0f);
#ifndef SPATIAL_HASHING
map.init();
// registerObstaclesInFaces();
registerWallInFaces();
// subdivideAllToMaxLevel();
for(unsigned int i = subdivisableFace.begin(); i < subdivisableFace.end(); subdivisableFace.next(i))
subdivisableFace[i].first = false ;
#endif
}
void EnvMap::markPedWay()
{
CellMarker<FACE> treat(map);
......@@ -250,56 +316,6 @@ Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
}
#endif
void EnvMap::init(unsigned int config)
{
sideSize = 400.0f;
nbSquares = 10;
max_for_obstacles=(sideSize*nbSquares/2)-sideSize/2;
switch(config)
{
case 0 : CityGenerator::generateGrid<PFP>(map, position, nbSquares, nbSquares, sideSize, obstacleMark, buildingMark);
break;
case 1 : CityGenerator::generateCity<PFP>(this, sideSize, nbSquares);
break;
case 2 : CityGenerator::generateCity<PFP>(this, sideSize, nbSquares);
// CityGenerator::generateMall<PFP>(map, position, obstacleMark, buildingMark, sideSize);
break;
case 3 :
{
// std::string filename = "/home/jund/Desktop/drawingQuads.svg";
// std::string filename = "/home/jund/Desktop/drawingTest.svg";
// std::string filename = "/home/jund/Desktop/drawingSimple.svg";
// std::string filename = "/home/jund/Desktop/drawingLines.svg";
// std::string filename = "/home/jund/Desktop/mapKrutSimple.svg";
// std::string filename = "/home/jund/Desktop/mapKrut.svg";
// Algo::Import::importSVG<PFP>(map,filename,position, obstacleMark, buildingMark);
// scale(3.2808399f);
//
// Algo::BooleanOperator::mergeVertices<PFP>(map, position);
// map.closeMap();
// Algo::Modelisation::CatmullClarkSubdivision<PFP>(map, position);
// Algo::Modelisation::computeDual<PFP>(map);
}
break;
case 4 : CityGenerator::generatePlanet<PFP>(map, position, obstacleMark, buildingMark, 200.0f, nbSquares);
break;
}
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
// CityGenerator::convexifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
// CityGenerator::installGuardRail<PFP>(map, position, obstacleMark, buildingMark, 5.0f);
#ifndef SPATIAL_HASHING
map.init();
// registerObstaclesInFaces();
registerWallInFaces();
// subdivideAllToMaxLevel();
for(unsigned int i = subdivisableFace.begin(); i < subdivisableFace.end(); subdivisableFace.next(i))
subdivisableFace[i].first = false ;
#endif
}
#ifndef SPATIAL_HASHING
void EnvMap::foreach_neighborFace(Dart d, FunctorType& f)
{
......
......@@ -34,7 +34,7 @@ bool MovingObstacle::is_inside(VEC3 p)
float get_angle(VEC3 v1, VEC3 v2)
{
float flo;
float flo=0;
float nb = std::sqrt(v1.norm2() * v2.norm2());
if (nb != 0)
......@@ -79,7 +79,7 @@ MovingObstacle::MovingObstacle(int ind, EnvMap* envmap, std::vector<VEC3> pos, V
nb_register_cells = 0;
float pos_max = 0;
velocity_factor = 1.0f;
velocity_factor = 0.8f;
nbVertices = pos.size();
parts_ = new CGoGN::Algo::MovingObjects::ParticleCell2D<PFP>*[nbVertices];
......@@ -188,14 +188,15 @@ void MovingObstacle::updateFixedObstNeighbors()
void MovingObstacle::computePrefVelocity()
{
VEC3 goalVector = finalGoal - center;
int co;
int co=2;
float angle;
float goalDist2 = goalVector.norm2();
// CGoGNout << "finalGoal "<< finalGoal << CGoGNendl;
// CGoGNout << "dist 2 "<< goalDist2 << CGoGNendl;
if(goalDist2 < 2.0f)
{
co=rand() % 2 + 1;
// co=rand() % 2 + 1;
if(co==1)
finalGoal[0]*=-1;
......@@ -313,8 +314,6 @@ void MovingObstacle::register_(Obstacle* o, Dart d, int n)
belonging_cells[n] = part->memo_cross;
// CGoGNout << "coucou je vais rentrer dans addNeighbor" << CGoGNendl;
envMap_->addObstAsNeighbor(o, belonging_cells[n], &(neighbor_cells[n]));
// CGoGNout << "coucou je suis sorti de addNeighbor" << CGoGNendl;
......@@ -466,12 +465,10 @@ void update_registration(Obstacle * o)
// mo->general_belonging.push_back(*it);
// }
// }
// mo->general_belonging.sort();
// unify(&mo->general_belonging, mo->envMap_);
// CGoGNout<<"MAJ Terminée"<<CGoGNendl;
}
}
void resetObstInFace(Obstacle* o)
{
MovingObstacle * mo = o->mo;
......@@ -479,7 +476,8 @@ void resetObstInFace(Obstacle* o)
if (mo != NULL)
{
VEC3 pos = o->p1;
mo->parts_[ind]->m_position = Algo::Geometry::faceCentroid<PFP>(mo->envMap_->map, mo->parts_[ind]->d, mo->envMap_->position);
mo->parts_[ind]->m_position = Algo::Geometry::faceCentroid < PFP
> (mo->envMap_->map, mo->parts_[ind]->d, mo->envMap_->position);
mo->parts_[ind]->state = FACE;
mo->parts_[ind]->move(pos);
}
......@@ -502,6 +500,7 @@ void resetObstPartInFace(Obstacle* o, Dart d1)
void resetPart(MovingObstacle * mo, Dart d1)
{
for (unsigned int i = 0; i < mo->nbVertices; i++) {
if (mo->parts_[i]->d == mo->envMap_->map.phi1(d1))
mo->parts_[i]->d = d1;
......
#include "simulator.h"
Simulator::Simulator() :
Simulator::Simulator(int minSize) :
timeStep_(0.2f),
globalTime_(0.0f),
nbSteps_(0),
avoidance(0),
nb_dead(0)
{
srand(10);
nbStepsPerUnit_ = 1 / timeStep_;
init(2, 2.0f);
srand(10) ;
nbStepsPerUnit_ = 1 / timeStep_ ;
init(1, minSize, 2.0f) ;
}
Simulator::~Simulator()
......@@ -18,27 +18,32 @@ Simulator::~Simulator()
delete agents_[i];
}
void Simulator::init(unsigned int config, float dimension, bool enablePathFinding)
void Simulator::init(unsigned int config, int minSize, float dimension, bool enablePathFinding)
{
envMap_.init(config);
envMap_.init(config, 1000.0f, 1000.0f, minSize, 400.0f);
// setupMovingObstacle(40);
std::cout << "setup scenario" << std::endl;
switch(config)
{
case 0 : setupCircleScenario(200);
break;
case 1 : importAgents("myAgents.pos");
break;
case 2 : setupScenario(1000);
break;
case 3 : setupCityScenario(
-1.0f * (12 * (70.0f / 2.0f) - 10),
-1.0f * (12 * (70.0f / 2.0f) - 10),
20,
20
);
break;
case 0 :
setupCircleScenario(1000) ;
break ;
case 1 :
setupCorridorScenario(500,10) ;
break ;
case 2 :
setupScenario(1000) ;
break ;
case 3 :
// setupCityScenario(20, 20) ;
// setupCityScenario(-1.0f * (12 * (70.0f / 2.0f) - 10),
// -1.0f * (12 * (70.0f / 2.0f) - 10), 20, 20);
break ;
case 4 :
importAgents("myAgents.pos") ;
break ;
}
#ifndef SPATIAL_HASHING
......@@ -68,7 +73,7 @@ void Simulator::init(unsigned int config, float dimension, bool enablePathFindin
// tc3 = new ThreadUpdateInfo(agents_, nbAgents / 2, nbAgents * 3 / 4);
// tc4 = new ThreadUpdateInfo(agents_, nbAgents * 3 / 4, nbAgents);
#ifndef SPATIAL_HASHING
envMap_.subdivideToProperLevel();
// envMap_.subdivideToProperLevel();
#endif
setupMovingObstacle(40);
......@@ -78,7 +83,7 @@ void Simulator::doStep()
{
for (unsigned int i = 0; i < movingObstacles_.size(); ++i)
{
movingObstacles_[i]->updateFixedObstNeighbors();
// movingObstacles_[i]->updateFixedObstNeighbors();
movingObstacles_[i]->computePrefVelocity();
movingObstacles_[i]->update();
// CGoGNout<<"fin update obstacle au temps : "<<nbSteps_<<CGoGNendl;
......@@ -249,6 +254,112 @@ void Simulator::setupCircleScenario(unsigned int nbMaxAgent)
for(unsigned int i = 0; i < agents_.size(); ++i)
envMap_.pushAgentInCells(agents_[i], agents_[i]->part_.d);
#endif
}
void Simulator::setupCorridorScenario(unsigned int nbMaxAgent,int nb_obst)
{
std::cout << " - Setup Corridor Scenario : " << nbMaxAgent << " agents" << std::endl ;
int xBorder = 120 ;
int yBorder= 120;
int variationX = 20 ;
int left = envMap_.geometry.min()[0] + xBorder ;
int right = envMap_.geometry.max()[0] - xBorder - variationX ;
int top= envMap_.geometry.max()[1] - yBorder ;
// int bottom=envMap_.geometry.min()[1] + yBorder;
int variationY = envMap_.geometry.size(1) * 0.4f ;
int middle = -variationY / 2 ;
int variationTopX=10;
int variationTop=envMap_.geometry.size(0) * 0.4f ;
int middleX = -variationTop / 2 ;
// float r = 220.0f;
for (unsigned int i = 0; i < nbMaxAgent; ++i)
{
VEC3 posagent(left + rand() % variationX, middle + rand() % variationY, 0) ;
VEC3 posgoal(right + rand() % variationX, middle + rand() % variationY, 0) ;
VEC3 tmp ;
if (i % 2 == 1)
{
tmp = posgoal ;
posgoal = posagent ;
posagent = tmp ;
}
#ifdef SPATIAL_HASHING
Agent* a = new Agent(this, posagent) ;
agents_.push_back(a) ;
envMap_.addAgentInGrid(a) ;
#else
Dart dCell = envMap_.getBelongingCell(posagent) ;
agents_.push_back(new Agent(this, posagent, dCell)) ;
#endif
agents_.back()->goals_.push_back(posgoal) ;
agents_.back()->curGoal_ = 0 ;
}
std::cout << "nb agents : " << agents_.size() << std::endl ;
#ifndef SPATIAL_HASHING
for (unsigned int i = 0 ; i < agents_.size() ; ++i)
envMap_.pushAgentInCells(agents_[i], agents_[i]->part_.d) ;
#endif
//création obstacles
std::cout << "nb obstacles : " << nb_obst << std::endl ;
float xSize = 10.0f;
float ySize = 45.0f;
VEC3 tmp2 (0,0,0);
VEC3 goal (0,0,0);
VEC3 posInit(0,0,0);
std::vector<VEC3> vPos;
MovingObstacle* mo4;
for (int i =0; i <(nb_obst); i++)
{
goal =PFP::VEC3(middleX + i*(variationTop/nb_obst), top + rand() % variationTopX-(ySize), 0);
posInit=goal;
posInit[1]*=-1;
if (i % 2 == 1)
{
tmp2 = goal ;
goal = posInit ;
posInit = tmp2 ;
}
// std::cout << "obst : " << i<< "| pos : "<<posInit<< "| goal : "<<goal<< std::endl ;
//posInit[0] -= 200.0f;
vPos.clear();
vPos.push_back(posInit);
// posInit[0] -= xSize/2;
// vPos.push_back(posInit);
posInit[0] -= xSize;
posInit[1] -= ySize/2;
vPos.push_back(posInit);
posInit[0] += xSize;
posInit[1] -= ySize/2;
vPos.push_back(posInit);
// posInit[0] += xSize;
// posInit[1] += ySize;
// vPos.push_back(posInit);
posInit[0] += xSize;
posInit[1] += ySize/2;
vPos.push_back(posInit);
// posInit[0] -= xSize;
// posInit[1] += ySize/2;
// vPos.push_back(posInit);
// CGoGNout << "ligne "<< i << vPos[i] << CGoGNendl;
mo4= new MovingObstacle(i,&envMap_, vPos,goal,0);
movingObstacles_.push_back(mo4);
}
}
void Simulator::setupCityScenario(float startX, float startY, int nbLines, int nbRank)
......@@ -693,54 +804,8 @@ void Simulator::setupMovingObstacle( unsigned int nb_obst)
VEC3 goal (50.0f,50.0f,0);
VEC3 posInit(0,0,0);
VEC3 possiblepos(0,0,0);
// //posInit[0] -= 200.0f;
// posInit[1] -= 100.0f;
//
//
std::vector<VEC3> vPos;
// vPos.push_back(posInit);
// posInit[0] -= xSize;
//// vPos.push_back(posInit);