Commit 7d618dcf authored by David Cazier's avatar David Cazier

Ajout de stats et d'un scenario Corridor

parent 0577ee58
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
project(SocialAgents)
add_definitions(-DSPATIAL_HASHING)
#add_definitions(-DSPATIAL_HASHING)
SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/../CGoGN CACHE STRING "CGoGN root dir")
include(${CGoGN_ROOT_DIR}/apps_cmake.txt)
......
......@@ -85,7 +85,7 @@ public:
VEC3 prefVelocity_;
VEC3 meanSpeed_;
VEC3 meanPos_;
// VEC3 meanPos_;
Simulator* sim_;
};
......
......@@ -10,21 +10,25 @@ namespace CGoGN
namespace CityGenerator
{
template <typename PFP>
bool notDiagonalAdjacentToAnObstacle(typename PFP::MAP& map, Dart d, CellMarker& buildingMark);
template<typename PFP>
bool notDiagonalAdjacentToAnObstacle(typename PFP::MAP& map, Dart d, CellMarker& buildingMark) ;
template<typename PFP> Algo::Modelisation::Polyhedron<PFP> generateGrid(EnvMap& envMap) ;
template <typename PFP>
Algo::Modelisation::Polyhedron<PFP> generateGrid(typename PFP::MAP& map, typename PFP::TVEC3& position, unsigned int cX, unsigned int cY, float sideLength, CellMarker& obstacleMark, CellMarker& buildingMark);
template<typename PFP> void generateCity(EnvMap& envMap) ;
template <typename PFP>
Algo::Modelisation::Polyhedron<PFP> generateTrianGrid(typename PFP::MAP& map, typename PFP::TVEC3& position, unsigned int cX, unsigned int cY, float sideLength, CellMarker& obstacleMark, CellMarker& buildingMark);
template<typename PFP>
Algo::Modelisation::Polyhedron<PFP> generateTrianGrid(typename PFP::MAP& map,
typename PFP::TVEC3& position, unsigned int cX, unsigned int cY, float sideLength,
CellMarker& obstacleMark, CellMarker& buildingMark) ;
template <typename PFP>
Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, CellMarker& buildingMark, float height);
template<typename PFP>
Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d,
CellMarker& buildingMark, float height) ;
#ifndef SPATIAL_HASHING
template <typename PFP>
bool animateCity(EnvMap* envMap);
template<typename PFP>
bool animateCity(EnvMap* envMap) ;
#endif
//template <typename PFP>
......@@ -34,24 +38,22 @@ bool animateCity(EnvMap* envMap);
//void generateCity(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, float sideSize, unsigned int nbSquares);
template<typename PFP>
Dart generateBuilding(EnvMap* envMap, Dart d, float height, unsigned int buildingType) ;
template<typename PFP>
void generateCity(EnvMap* envMap, float sideSize, unsigned int nbSquares) ;
Dart generateBuilding(EnvMap& envMap, Dart d, float height, unsigned int buildingType) ;
template<typename PFP>
void generateMall(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark,
CellMarker& buildingMark, float sideSize) ;
void generateMall(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark, float sideSize) ;
template<typename PFP>
void generatePathToUpperStair(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dLower,
Dart dUpper) ;
void generatePathToUpperStair(typename PFP::MAP& map, typename PFP::TVEC3& position,
Dart dLower, Dart dUpper) ;
/*******************************************************************************/
template<typename PFP>
void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark,
CellMarker& buildingMark, float radius, unsigned int nbSquares) ;
void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark, float radius,
unsigned int nbSquares) ;
/*******************************************************************************/
......@@ -63,15 +65,15 @@ bool isAnEar(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dd, flo
template<typename PFP>
bool canRemoveEdgeConvex(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d,
CellMarker& obstacleMark) ;
CellMarker& obstacleMark) ;
template<typename PFP>
void convexifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark) ;
CellMarker& obstacleMark, CellMarker& buildingMark) ;
template<typename PFP>
void installGuardRail(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark, float height) ;
CellMarker& obstacleMark, CellMarker& buildingMark, float height) ;
}
......
This diff is collapsed.
......@@ -23,7 +23,7 @@
#include "spatialHashing.h"
using namespace CGoGN;
using namespace CGoGN ;
class Agent ;
class Obstacle ;
......@@ -45,48 +45,63 @@ struct PFP : public PFP_STANDARD
} ;
typedef PFP::VEC3 VEC3 ;
typedef PFP::REAL REAL ;
class EnvMap
{
public:
public:
PFP::MAP map ;
/* 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 ;
EnvMap() ;
void init(unsigned int config, REAL width, REAL height, REAL minSize, REAL maxSize) ;
void markPedWay() ;
unsigned int mapMemoryCost() ;
void scale(float scaleVal) ;
#ifndef SPATIAL_HASHING
Dart getBelongingCell(const PFP::VEC3& pos);
Dart getBelongingCell(const VEC3& pos) ;
void subdivideAllToMaxLevel();
void subdivideToProperLevel();
void subdivideAllToMaxLevel() ;
void subdivideToProperLevel() ;
#endif
void init(unsigned int config);
#ifndef SPATIAL_HASHING
void foreach_neighborFace(Dart d, FunctorType& f);
void foreach_neighborFace(Dart d, FunctorType& f) ;
void registerObstaclesInFaces();
void addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbor);
void registerObstaclesInFaces() ;
void addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbor) ;
void setAgentNeighborsAndObstacles(Agent* agent);
void setAgentNeighborsAndObstacles(Agent* agent) ;
void pushAgentInCells(Agent* agent, Dart d);
void popAgentInCells(Agent* agent, Dart d);
unsigned int totalNeighborSize(Dart d) ;
void nbAgentsIncrease(Dart d) ;
void nbAgentsDecrease(Dart d) ;
void pushAgentInCells(Agent* agent, Dart d) ;
void popAgentInCells(Agent* agent, Dart d) ;
// void agentChangeFaceThroughEdge(Agent* agent);
void agentChangeFace(Agent* agent, Dart oldFace);
void agentChangeFace(Agent* agent, Dart oldFace) ;
void pushObstacleInCells(Obstacle* o, Dart d);
void popObstacleInCells(Obstacle* o, Dart d);
void obstacleChangeFace(Obstacle* agent, Dart newFace, Dart oldFace);
void pushObstacleInCells(Obstacle* o, Dart d) ;
void popObstacleInCells(Obstacle* o, Dart d) ;
void obstacleChangeFace(Obstacle* agent, Dart newFace, Dart oldFace) ;
void updateMap() ;
void resetAgentInFace(Agent* agent);
void resetAgentInFace(Agent* agent) ;
#endif
PFP::MAP map;
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
......@@ -99,11 +114,10 @@ class EnvMap
std::vector<Dart> newBuildings ;
#ifndef SPATIAL_HASHING
AttributeHandler<PFP::BOOLATTRIB> subdivisableFace;
AttributeHandler<PFP::BOOLATTRIB> subdivisableFace ;
PFP::TAB_AGENTVECT agentvect;
PFP::TAB_AGENTVECT neighborAgentvect;
PFP::TAB_AGENTVECT agentvect ;
PFP::TAB_AGENTVECT neighborAgentvect ;
#endif
PFP::TAB_OBSTACLEVECT obstvect ;
......@@ -113,72 +127,97 @@ class EnvMap
CellMarker pedWayMark ;
#ifndef SPATIAL_HASHING
static const unsigned int nbAgentsToSubdivide = 5;
static const unsigned int nbAgentsToSimplify = 4;
static const unsigned int nbAgentsToSubdivide = 4 ;
static const unsigned int nbAgentsToSimplify = 1 ;
CellMarker refineMark;
CellMarker coarsenMark;
std::vector<Dart> refineCandidate;
std::vector<Dart> coarsenCandidate;
CellMarker refineMark ;
CellMarker coarsenMark ;
std::vector<Dart> refineCandidate ;
std::vector<Dart> coarsenCandidate ;
void clearUpdateCandidates() ;
#endif
#ifdef SPATIAL_HASHING
PFP::VEC3 origin ;
unsigned int a_cell_size_x, a_cell_size_y ;
float a_cell_nb_x, a_cell_nb_y ;
unsigned int o_cell_size_x, o_cell_size_y ;
float o_cell_nb_x, o_cell_nb_y ;
Geom::Vec2ui agentPositionCell(VEC3& pos)
{
return Geom::Vec2ui((origin[0] + pos[0]) / a_cell_size_x, (origin[1] + pos[1]) / a_cell_size_y) ;
VEC3 relativePos = pos - geometry.min();
relativePos /= minCellSize;
return Geom::Vec2ui(relativePos[0], relativePos[1]) ;
}
Geom::Vec2ui obstaclePositionCell(VEC3& pos)
{
return Geom::Vec2ui((origin[0] + pos[0]) / o_cell_size_x, (origin[1] + pos[1]) / o_cell_size_y) ;
VEC3 relativePos = pos - geometry.min();
relativePos /= obstacleDistance;
return Geom::Vec2ui(relativePos[0], relativePos[1]) ;
}
HashTable2D< std::vector<Agent*> > ht_agents ;
HashTable2D< std::vector<Agent*> > ht_neighbor_agents ;
HashTable2D< std::vector<Obstacle*> > ht_obstacles ;
#endif
};
} ;
/**************************************
* INLINE FUNCTIONS *
**************************************/
template <typename T>
template<typename T>
inline void removeElementFromVector(std::vector<T>& a, T ag)
{
typename std::vector<T>::iterator end = a.template end();
for(typename std::vector<T>::iterator it = a.begin(); it != end; ++it)
{
if(*it == ag)
{
*it = a.back();
a.pop_back();
return;
typename std::vector<T>::iterator end = a.template end() ;
for (typename std::vector<T>::iterator it = a.begin() ; it != end ; ++it) {
if ( *it == ag) {
*it = a.back() ;
a.pop_back() ;
return ;
}
}
}
#ifndef SPATIAL_HASHING
inline unsigned int EnvMap::totalNeighborSize(Dart d) {
return agentvect[d].size() + neighborAgentvect[d].size() ;
}
inline void EnvMap::nbAgentsIncrease(Dart d)
{
if (refineMark.isMarked(d)) return ;
if (totalNeighborSize(d) < nbAgentsToSubdivide) return ;
std::pair<bool, bool>& sf = subdivisableFace[d] ;
if (sf.first == false || (sf.first == true && sf.second)) {
refineMark.mark(d) ;
refineCandidate.push_back(d) ;
}
}
inline void EnvMap::nbAgentsDecrease(Dart d)
{
if (coarsenMark.isMarked(d) || refineMark.isMarked(d)) return ;
if (totalNeighborSize(d) > nbAgentsToSimplify) return ;
coarsenMark.mark(d) ;
coarsenCandidate.push_back(map.faceOldestDart(d)) ;
}
inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
{
assert(map.getCurrentLevel() == map.getMaxLevel()) ;
assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) == agentvect[d].end()) ;
agentvect[d].push_back(agent) ;
// nbAgentsIncrease(d);
Dart dd = d ;
do {
Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd) {
neighborAgentvect[ddd].push_back(agent) ;
// nbAgentsIncrease(ddd);
ddd = map.alpha1(ddd) ;
}
dd = map.phi1(dd) ;
......@@ -188,15 +227,16 @@ inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
{
assert(map.getCurrentLevel() == map.getMaxLevel()) ;
assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end()) ;
removeElementFromVector<Agent*>(agentvect[d], agent) ;
// nbAgentsDecrease(d) ;
Dart dd = d ;
do {
Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd) {
removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ;
// nbAgentsDecrease(ddd) ;
ddd = map.alpha1(ddd) ;
}
dd = map.phi1(dd) ;
......@@ -205,10 +245,10 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
inline void EnvMap::pushObstacleInCells(Obstacle* o, Dart d)
{
assert(map.getCurrentLevel() == map.getMaxLevel());
assert(!buildingMark.isMarked(d));
assert(map.getCurrentLevel() == map.getMaxLevel()) ;
assert( !buildingMark.isMarked(d)) ;
obstvect[d].push_back(o);
obstvect[d].push_back(o) ;
// obstvect[map.phi<12>(d)].push_back(o);
// obstvect[map.phi2(map.phi_1(d))].push_back(o);
......@@ -229,10 +269,10 @@ inline void EnvMap::pushObstacleInCells(Obstacle* o, Dart d)
inline void EnvMap::popObstacleInCells(Obstacle* o, Dart d)
{
assert(map.getCurrentLevel() == map.getMaxLevel());
assert(!buildingMark.isMarked(d));
assert(map.getCurrentLevel() == map.getMaxLevel()) ;
assert( !buildingMark.isMarked(d)) ;
removeElementFromVector<Obstacle* >(obstvect[d], o);
removeElementFromVector<Obstacle*>(obstvect[d], o) ;
// removeElementFromVector<Obstacle* >(obstvect[map.phi<12>(d)],o);
// removeElementFromVector<Obstacle* >(obstvect[map.phi2(map.phi_1(d))],o);
......
......@@ -16,113 +16,120 @@
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
for (unsigned int i = 0; i < ag_.size(); ++i)
{
// 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
for (unsigned int i = 0; i < ag_.size(); ++i)
{
ag_[i]->update();
void run()
{
// Thread execution stuff goes here
for (unsigned int i = 0 ; i < ag_.size() ; ++i) {
ag_[i]->update() ;
}
}
};
} ;
class Simulator
{
public:
Simulator();
Simulator(
float timeStep, float neighborDist, unsigned int maxNeighbors,
float timeHorizon, float timeHorizonObst, float radius,
float maxSpeed, const VEC3& velocity = VEC3(0)
);
~Simulator();
void init(unsigned int config, float dimension, bool enablePathFinding=false);
void doStep();
bool reachedGoal();
void setupCircleScenario(unsigned int nbMaxAgent);
void setupCityScenario(float startX, float startY, int nbLines , int nbRank);
void setupScenario(unsigned int nbMaxAgent);
void setupMovingObstacle(unsigned int nbObstacles);
Simulator() ;
Simulator(float timeStep, float neighborDist, unsigned int maxNeighbors, float timeHorizon,
float timeHorizonObst, float radius, float maxSpeed,
const VEC3& velocity = VEC3(0)) ;
~Simulator() ;
void init(unsigned int config, float dimension, bool enablePathFinding = false) ;
void setupCircleScenario(unsigned int nbMaxAgent) ;
void setupCorridorScenario(unsigned int nbMaxAgent) ;
void setupCityScenario(float startX, float startY, int nbLines, int nbRank) ;
void setupScenario(unsigned int nbMaxAgent) ;
void doStep() ;
bool reachedGoal() ;
void setupMovingObstacle(unsigned int nbObstacles) ;
#ifndef SPATIAL_HASHING
void addPathToCorner();
void addPathsToAgents();
void addPathsToAgents_height();
void addPathToCorner() ;
void addPathsToAgents() ;
void addPathsToAgents_height() ;
#endif
bool importAgents(std::string filename);
bool exportAgents(std::string filename);
void swapAgentsGoals();
Geom::BoundingBox<VEC3> getAgentsBB();
EnvMap envMap_;
std::vector<Agent*> agents_;
// std::vector<MovingObstacle*> movingObstacles_;
float timeStep_;
float globalTime_;
unsigned int nbSteps_;
unsigned int nbStepsPerUnit_;
bool importAgents(std::string filename) ;
bool exportAgents(std::string filename) ;
void swapAgentsGoals() ;
Geom::BoundingBox<VEC3> getAgentsBB() ;
EnvMap envMap_ ;
std::vector<Agent*> agents_ ;
// std::vector<MovingObstacle*> movingObstacles_;
ThreadUpdateInfo* tc1;
ThreadUpdateInfo* tc2;
ThreadUpdateInfo* tc3;
ThreadUpdateInfo* tc4;
};
float timeStep_ ;
float globalTime_ ;
unsigned int nbSteps_ ;
unsigned int nbStepsPerUnit_ ;
unsigned int nbUpdates ;
unsigned int nbSorts ;
unsigned int nbRefineCandidate ;
unsigned int nbCoarsenCandidate ;
unsigned long nearNeighbors ;
unsigned long totalNeighbors ;
ThreadUpdateInfo* tc1 ;
ThreadUpdateInfo* tc2 ;
ThreadUpdateInfo* tc3 ;
ThreadUpdateInfo* tc4 ;
} ;
#endif
......@@ -70,7 +70,7 @@ public:
// to count fps
int frames;
clock_t nextUpdate;
float nextUpdate;
bool displayFps;
float fps;
......@@ -81,8 +81,6 @@ public:
int visu;
int nbGenerated;
double elapsedTime;
bool drawEnvLines ;
bool drawEnvFaces ;
bool drawEnvTopo ;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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