Commit 816beba3 authored by David Cazier's avatar David Cazier

- Stats améliorées.

- Simplification des faces optimisées (en deux passse pour éviter le O(n^2) et les faces oubliées)
- Ajout de paramètres au programme : la taille minimal des cellules, le nombre d'itérarions avant l'arrêt de la simulation
parent 7d618dcf
...@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8) ...@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
project(SocialAgents) project(SocialAgents)
#add_definitions(-DSPATIAL_HASHING) add_definitions(-DSPATIAL_HASHING)
SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/../CGoGN CACHE STRING "CGoGN root dir") SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/../CGoGN CACHE STRING "CGoGN root dir")
include(${CGoGN_ROOT_DIR}/apps_cmake.txt) include(${CGoGN_ROOT_DIR}/apps_cmake.txt)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "spatialHashing.h" #include "spatialHashing.h"
#include "Algo/MovingObjects/particle_cell_2D.h" #include "Algo/MovingObjects/particle_cell_2D.h"
class Simulator; class Simulator ;
class Agent class Agent
{ {
...@@ -16,78 +16,69 @@ public: ...@@ -16,78 +16,69 @@ public:
#ifdef SPATIAL_HASHING #ifdef SPATIAL_HASHING
Agent(Simulator* sim, const VEC3& position) ; Agent(Simulator* sim, const VEC3& position) ;
#else #else
Agent(Simulator* sim, const VEC3& position, Dart d); Agent(Simulator* sim, const VEC3& position, Dart d) ;
#endif #endif
VEC3 getPosition(); VEC3 getPosition() ;
void updateAgentNeighbors(); void updateAgentNeighbors() ;
void updateObstacleNeighbors(); void updateObstacleNeighbors() ;
void update(); void update() ;
void computePrefVelocity();
void computeNewVelocity();
void computeNewVelocity2(); void computePrefVelocity() ;
void computeNewVelocity() ;
bool linearProgram1( void computeNewVelocity2() ;
const std::vector<Line>& lines, unsigned int lineNo,
float radius, const VEC3& optVelocity,
bool directionOpt, VEC3& result
);
unsigned int linearProgram2( bool linearProgram1(const std::vector<Line>& lines, unsigned int lineNo, float radius,
const std::vector<Line>& lines, float radius, const VEC3& optVelocity, bool directionOpt, VEC3& result) ;
const VEC3& optVelocity, bool directionOpt,
VEC3& result
);
void linearProgram3( unsigned int linearProgram2(const std::vector<Line>& lines, float radius,
const std::vector<Line>& lines, unsigned int numObstLines, const VEC3& optVelocity, bool directionOpt, VEC3& result) ;
unsigned int beginLine, float radius,
VEC3& result void linearProgram3(const std::vector<Line>& lines, unsigned int numObstLines,
); unsigned int beginLine, float radius, VEC3& result) ;
std::vector<std::pair<float, Agent*> > agentNeighbors_; std::vector<std::pair<float, Agent*> > agentNeighbors_ ;
std::vector<std::pair<float, Obstacle*> > obstacleNeighbors_; std::vector<std::pair<float, Obstacle*> > obstacleNeighbors_ ;
#ifdef SPATIAL_HASHING #ifdef SPATIAL_HASHING
VEC3 pos ; VEC3 pos ;
#else #else
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> part_; CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> part_ ;
#endif #endif
std::vector<VEC3> goals_; std::vector<VEC3> goals_ ;
VEC3 finalGoal; VEC3 finalGoal ;
Dart finalDart; Dart finalDart ;
unsigned int curGoal_; unsigned int curGoal_ ;
static unsigned int maxNeighbors_; static unsigned int maxNeighbors_ ;
static float maxSpeed_; static float maxSpeed_ ;
static float neighborDist_; static float neighborDist_ ;
static float neighborDistSq_; static float neighborDistSq_ ;
static float radius_; static float radius_ ;
static float timeHorizon_; static float timeHorizon_ ;
static float timeHorizonObst_; static float timeHorizonObst_ ;
static float range_; static float range_ ;
static float rangeSq_; static float rangeSq_ ;
static float timeStep ; static float timeStep ;
static unsigned int cptAgent ; static unsigned int cptAgent ;
unsigned int agentNo ; unsigned int agentNo ;
VEC3 velocity_; VEC3 velocity_ ;
VEC3 newVelocity_; VEC3 newVelocity_ ;
VEC3 prefVelocity_; VEC3 prefVelocity_ ;
VEC3 meanSpeed_; VEC3 meanSpeed_ ;
// VEC3 meanPos_; // VEC3 meanPos_;
Simulator* sim_; Simulator* sim_ ;
}; } ;
#endif #endif
...@@ -10,24 +10,26 @@ namespace CGoGN ...@@ -10,24 +10,26 @@ namespace CGoGN
namespace CityGenerator namespace CityGenerator
{ {
template<typename PFP> template <typename PFP>
bool notDiagonalAdjacentToAnObstacle(typename PFP::MAP& map, Dart d, CellMarker& buildingMark) ; 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(EnvMap& envMap) ;
template<typename PFP> void generateCity(EnvMap& envMap) ; template <typename PFP> void generateCity(EnvMap& envMap) ;
template<typename PFP> template <typename PFP>
Algo::Modelisation::Polyhedron<PFP> generateTrianGrid(typename PFP::MAP& map, Algo::Modelisation::Polyhedron<PFP> generateTrianGrid(typename PFP::MAP& map,
typename PFP::TVEC3& position, unsigned int cX, unsigned int cY, float sideLength, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark) ; unsigned int cX, unsigned int cY,
float sideLength, CellMarker& obstacleMark,
CellMarker& buildingMark) ;
template<typename PFP> template <typename PFP>
Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d,
CellMarker& buildingMark, float height) ; CellMarker& buildingMark, float height) ;
#ifndef SPATIAL_HASHING #ifndef SPATIAL_HASHING
template<typename PFP> template <typename PFP>
bool animateCity(EnvMap* envMap) ; bool animateCity(EnvMap* envMap) ;
#endif #endif
...@@ -37,43 +39,42 @@ bool animateCity(EnvMap* envMap) ; ...@@ -37,43 +39,42 @@ bool animateCity(EnvMap* envMap) ;
//template <typename PFP> //template <typename PFP>
//void generateCity(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, float sideSize, unsigned int nbSquares); //void generateCity(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, float sideSize, unsigned int nbSquares);
template<typename PFP> template <typename PFP>
Dart generateBuilding(EnvMap& envMap, Dart d, float height, unsigned int buildingType) ; Dart generateBuilding(EnvMap& envMap, Dart d, float height, unsigned int buildingType) ;
template<typename PFP> template <typename PFP>
void generateMall(typename PFP::MAP& map, typename PFP::TVEC3& position, void generateMall(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark,
CellMarker& obstacleMark, CellMarker& buildingMark, float sideSize) ; CellMarker& buildingMark, float sideSize) ;
template<typename PFP> template <typename PFP>
void generatePathToUpperStair(typename PFP::MAP& map, typename PFP::TVEC3& position, void generatePathToUpperStair(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dLower,
Dart dLower, Dart dUpper) ; Dart dUpper) ;
/*******************************************************************************/ /*******************************************************************************/
template<typename PFP> template <typename PFP>
void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position, void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark,
CellMarker& obstacleMark, CellMarker& buildingMark, float radius, CellMarker& buildingMark, float radius, unsigned int nbSquares) ;
unsigned int nbSquares) ;
/*******************************************************************************/ /*******************************************************************************/
template<typename PFP> template <typename PFP>
void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position) ; void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position) ;
template<typename PFP> template <typename PFP>
bool isAnEar(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dd, float& area) ; bool isAnEar(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dd, float& area) ;
template<typename PFP> template <typename PFP>
bool canRemoveEdgeConvex(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, bool canRemoveEdgeConvex(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d,
CellMarker& obstacleMark) ; CellMarker& obstacleMark) ;
template<typename PFP> template <typename PFP>
void convexifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position, void convexifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark) ; CellMarker& obstacleMark, CellMarker& buildingMark) ;
template<typename PFP> template <typename PFP>
void installGuardRail(typename PFP::MAP& map, typename PFP::TVEC3& position, 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.
...@@ -127,8 +127,8 @@ public: ...@@ -127,8 +127,8 @@ public:
CellMarker pedWayMark ; CellMarker pedWayMark ;
#ifndef SPATIAL_HASHING #ifndef SPATIAL_HASHING
static const unsigned int nbAgentsToSubdivide = 4 ; static const unsigned int nbAgentsToSubdivide = 10 ;
static const unsigned int nbAgentsToSimplify = 1 ; static const unsigned int nbAgentsToSimplify = 4 ;
CellMarker refineMark ; CellMarker refineMark ;
CellMarker coarsenMark ; CellMarker coarsenMark ;
...@@ -139,20 +139,27 @@ public: ...@@ -139,20 +139,27 @@ public:
#endif #endif
#ifdef SPATIAL_HASHING #ifdef SPATIAL_HASHING
float a_cell_nb_x, a_cell_nb_y ; unsigned int agentGridSize(unsigned int i)
float o_cell_nb_x, o_cell_nb_y ; {
return geometry.size(i) / minCellSize ;
}
unsigned int obstacleGridSize(unsigned int i)
{
return geometry.size(i) / obstacleDistance ;
}
Geom::Vec2ui agentPositionCell(VEC3& pos) Geom::Vec2ui agentPositionCell(VEC3& pos)
{ {
VEC3 relativePos = pos - geometry.min(); VEC3 relativePos = pos - geometry.min() ;
relativePos /= minCellSize; relativePos /= minCellSize ;
return Geom::Vec2ui(relativePos[0], relativePos[1]) ; return Geom::Vec2ui(relativePos[0], relativePos[1]) ;
} }
Geom::Vec2ui obstaclePositionCell(VEC3& pos) Geom::Vec2ui obstaclePositionCell(VEC3& pos)
{ {
VEC3 relativePos = pos - geometry.min(); VEC3 relativePos = pos - geometry.min() ;
relativePos /= obstacleDistance; relativePos /= obstacleDistance ;
return Geom::Vec2ui(relativePos[0], relativePos[1]) ; return Geom::Vec2ui(relativePos[0], relativePos[1]) ;
} }
...@@ -166,12 +173,14 @@ public: ...@@ -166,12 +173,14 @@ public:
* INLINE FUNCTIONS * * INLINE FUNCTIONS *
**************************************/ **************************************/
template<typename T> template <typename T>
inline void removeElementFromVector(std::vector<T>& a, T ag) inline void removeElementFromVector(std::vector<T>& a, T ag)
{ {
typename std::vector<T>::iterator end = a.template end() ; typename std::vector<T>::iterator end = a.template end() ;
for (typename std::vector<T>::iterator it = a.begin() ; it != end ; ++it) { for (typename std::vector<T>::iterator it = a.begin(); it != end; ++it)
if ( *it == ag) { {
if (*it == ag)
{
*it = a.back() ; *it = a.back() ;
a.pop_back() ; a.pop_back() ;
return ; return ;
...@@ -180,7 +189,8 @@ inline void removeElementFromVector(std::vector<T>& a, T ag) ...@@ -180,7 +189,8 @@ inline void removeElementFromVector(std::vector<T>& a, T ag)
} }
#ifndef SPATIAL_HASHING #ifndef SPATIAL_HASHING
inline unsigned int EnvMap::totalNeighborSize(Dart d) { inline unsigned int EnvMap::totalNeighborSize(Dart d)
{
return agentvect[d].size() + neighborAgentvect[d].size() ; return agentvect[d].size() + neighborAgentvect[d].size() ;
} }
...@@ -190,7 +200,8 @@ inline void EnvMap::nbAgentsIncrease(Dart d) ...@@ -190,7 +200,8 @@ inline void EnvMap::nbAgentsIncrease(Dart d)
if (totalNeighborSize(d) < nbAgentsToSubdivide) return ; if (totalNeighborSize(d) < nbAgentsToSubdivide) return ;
std::pair<bool, bool>& sf = subdivisableFace[d] ; std::pair<bool, bool>& sf = subdivisableFace[d] ;
if (sf.first == false || (sf.first == true && sf.second)) { if (sf.first == false || (sf.first == true && sf.second))
{
refineMark.mark(d) ; refineMark.mark(d) ;
refineCandidate.push_back(d) ; refineCandidate.push_back(d) ;
} }
...@@ -213,9 +224,11 @@ inline void EnvMap::pushAgentInCells(Agent* agent, Dart d) ...@@ -213,9 +224,11 @@ inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
// nbAgentsIncrease(d); // nbAgentsIncrease(d);
Dart dd = d ; Dart dd = d ;
do { do
{
Dart ddd = map.alpha1(map.alpha1(dd)) ; Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd) { while (ddd != dd)
{
neighborAgentvect[ddd].push_back(agent) ; neighborAgentvect[ddd].push_back(agent) ;
// nbAgentsIncrease(ddd); // nbAgentsIncrease(ddd);
ddd = map.alpha1(ddd) ; ddd = map.alpha1(ddd) ;
...@@ -232,9 +245,11 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d) ...@@ -232,9 +245,11 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
// nbAgentsDecrease(d) ; // nbAgentsDecrease(d) ;
Dart dd = d ; Dart dd = d ;
do { do
{
Dart ddd = map.alpha1(map.alpha1(dd)) ; Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd) { while (ddd != dd)
{
removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ; removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ;
// nbAgentsDecrease(ddd) ; // nbAgentsDecrease(ddd) ;
ddd = map.alpha1(ddd) ; ddd = map.alpha1(ddd) ;
...@@ -246,7 +261,7 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d) ...@@ -246,7 +261,7 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
inline void EnvMap::pushObstacleInCells(Obstacle* o, Dart d) inline void EnvMap::pushObstacleInCells(Obstacle* o, Dart d)
{ {
assert(map.getCurrentLevel() == map.getMaxLevel()) ; assert(map.getCurrentLevel() == map.getMaxLevel()) ;
assert( !buildingMark.isMarked(d)) ; assert(!buildingMark.isMarked(d)) ;
obstvect[d].push_back(o) ; obstvect[d].push_back(o) ;
...@@ -270,7 +285,7 @@ inline void EnvMap::pushObstacleInCells(Obstacle* o, Dart d) ...@@ -270,7 +285,7 @@ inline void EnvMap::pushObstacleInCells(Obstacle* o, Dart d)
inline void EnvMap::popObstacleInCells(Obstacle* o, Dart d) inline void EnvMap::popObstacleInCells(Obstacle* o, Dart d)
{ {
assert(map.getCurrentLevel() == map.getMaxLevel()) ; assert(map.getCurrentLevel() == map.getMaxLevel()) ;
assert( !buildingMark.isMarked(d)) ; assert(!buildingMark.isMarked(d)) ;
removeElementFromVector<Obstacle*>(obstvect[d], o) ; removeElementFromVector<Obstacle*>(obstvect[d], o) ;
......
...@@ -7,70 +7,72 @@ ...@@ -7,70 +7,72 @@
inline void renderDart(EnvMap& m, Dart d) inline void renderDart(EnvMap& m, Dart d)
{ {
PFP::VEC3 p1 = m.position[d]; PFP::VEC3 p1 = m.position[d] ;
PFP::VEC3 p2 = m.position[m.map.phi1(d)]; PFP::VEC3 p2 = m.position[m.map.phi1(d)] ;
glBegin(GL_LINES); glBegin(GL_LINES) ;
glVertex3f(p1[0],p1[1],p1[2]); glVertex3f(p1[0], p1[1], p1[2]) ;
glVertex3f(p2[0],p2[1],p2[2]); glVertex3f(p2[0], p2[1], p2[2]) ;
glEnd(); glEnd() ;
} }
inline void renderFace(EnvMap& m, Dart d) inline void renderFace(EnvMap& m, Dart d)
{ {
Dart dd=d; Dart dd = d ;
do { do
renderDart(m,dd); {
dd = m.map.phi1(dd); renderDart(m, dd) ;
}while(dd!=d); dd = m.map.phi1(dd) ;
} while (dd != d) ;
} }
inline void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p) inline void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
{ {
Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,d,m.position); Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map, d, m.position) ;
p[2] -= 1000; p[2] -= 1000 ;
Geom::intersectionPlaneRay(pl,p,VEC3(0,0,-1),p); Geom::intersectionPlaneRay(pl, p, VEC3(0, 0, -1), p) ;
VEC3 pos1(m.position[d]); VEC3 pos1(m.position[d]) ;
VEC3 pos2(m.position[m.map.phi1(d)]); VEC3 pos2(m.position[m.map.phi1(d)]) ;
pos2[2] += 2; pos2[2] += 2 ;
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP) ;
glVertex3fv(&p[0]); glVertex3fv(&p[0]) ;
glVertex3fv(& pos1[0]); glVertex3fv(&pos1[0]) ;
glVertex3fv(& pos2[0]); glVertex3fv(&pos2[0]) ;
glEnd(); glEnd() ;
} }
static const float cosT[5] = { 1, 0.309017, -0.809017, -0.809017, 0.309017 }; static const float cosT[5] = { 1, 0.309017, -0.809017, -0.809017, 0.309017 } ;
static const float sinT[5] = { 0, 0.951057, 0.587785, -0.587785, -0.951057 }; static const float sinT[5] = { 0, 0.951057, 0.587785, -0.587785, -0.951057 } ;
inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false, bool showObstacleDist = false) inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false,
bool showObstacleDist = false)
{ {
#ifdef SPATIAL_HASHING #ifdef SPATIAL_HASHING
const VEC3& pos = agent->pos; const VEC3& pos = agent->pos ;
#else #else
VEC3 pos = agent->part_.m_position; VEC3 pos = agent->part_.m_position ;
#endif #endif
float radius = agent->radius_; float radius = agent->radius_ ;
// Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,agent->part_.d,m.position); // Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,agent->part_.d,m.position);
// pos[2] -= 1000; // pos[2] -= 1000;
// Geom::intersectionPlaneRay(pl,pos,VEC3(0,0,-1),pos); // Geom::intersectionPlaneRay(pl,pos,VEC3(0,0,-1),pos);
glLineWidth(1.0f); glLineWidth(1.0f) ;
// VEC3 col = Utils::color_map_BCGYR(float(agent->agentNo)/float(agent->sim_->agents_.size())); // VEC3 col = Utils::color_map_BCGYR(float(agent->agentNo)/float(agent->sim_->agents_.size()));
// glColor3fv(col.data()); // glColor3fv(col.data());
glColor3f(1.0f, 0.0f, 0.0f); glColor3f(1.0f, 0.0f, 0.0f) ;
glBegin(GL_POLYGON); glBegin(GL_POLYGON) ;
for(unsigned int i = 0; i < 5; ++i) for (unsigned int i = 0; i < 5; ++i)
glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2]+0.01f); glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2] + 0.01f) ;
glEnd(); glEnd() ;
VEC3 dir = agent->velocity_; VEC3 dir = agent->velocity_ ;
dir.normalize(); dir.normalize() ;
//draw the speed vector //draw the speed vector
// VEC3 base(0,0,1); // VEC3 base(0,0,1);
// VEC3 myAxisRot = base^dir; // VEC3 myAxisRot = base^dir;
// myAxisRot.normalize(); // myAxisRot.normalize();
...@@ -88,37 +90,38 @@ inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false, ...@@ -88,37 +90,38 @@ inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false,
// glEnd(); // glEnd();
// glPopMatrix(); // glPopMatrix();
//show goals //show goals
if(true) if (true)