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)
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)
......
......@@ -8,7 +8,7 @@
#include "spatialHashing.h"
#include "Algo/MovingObjects/particle_cell_2D.h"
class Simulator;
class Simulator ;
class Agent
{
......@@ -16,78 +16,69 @@ public:
#ifdef SPATIAL_HASHING
Agent(Simulator* sim, const VEC3& position) ;
#else
Agent(Simulator* sim, const VEC3& position, Dart d);
Agent(Simulator* sim, const VEC3& position, Dart d) ;
#endif
VEC3 getPosition();
VEC3 getPosition() ;
void updateAgentNeighbors();
void updateObstacleNeighbors();
void updateAgentNeighbors() ;
void updateObstacleNeighbors() ;
void update();
void computePrefVelocity();
void computeNewVelocity();
void update() ;
void computeNewVelocity2();
void computePrefVelocity() ;
void computeNewVelocity() ;
bool linearProgram1(
const std::vector<Line>& lines, unsigned int lineNo,
float radius, const VEC3& optVelocity,
bool directionOpt, VEC3& result
);
void computeNewVelocity2() ;
unsigned int linearProgram2(
const std::vector<Line>& lines, float radius,
const VEC3& optVelocity, bool directionOpt,
VEC3& result
);
bool linearProgram1(const std::vector<Line>& lines, unsigned int lineNo, float radius,
const VEC3& optVelocity, bool directionOpt, 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, Obstacle*> > obstacleNeighbors_;
unsigned int linearProgram2(const std::vector<Line>& lines, float radius,
const VEC3& optVelocity, bool directionOpt, 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, Obstacle*> > obstacleNeighbors_ ;
#ifdef SPATIAL_HASHING
VEC3 pos ;
#else
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> part_;
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> part_ ;
#endif
std::vector<VEC3> goals_;
VEC3 finalGoal;
Dart finalDart;
unsigned int curGoal_;
static unsigned int maxNeighbors_;
static float maxSpeed_;
static float neighborDist_;
static float neighborDistSq_;
static float radius_;
static float timeHorizon_;
static float timeHorizonObst_;
static float range_;
static float rangeSq_;
std::vector<VEC3> goals_ ;
VEC3 finalGoal ;
Dart finalDart ;
unsigned int curGoal_ ;
static unsigned int maxNeighbors_ ;
static float maxSpeed_ ;
static float neighborDist_ ;
static float neighborDistSq_ ;
static float radius_ ;
static float timeHorizon_ ;
static float timeHorizonObst_ ;
static float range_ ;
static float rangeSq_ ;
static float timeStep ;
static unsigned int cptAgent ;
unsigned int agentNo ;
VEC3 velocity_;
VEC3 newVelocity_;
VEC3 prefVelocity_;
VEC3 meanSpeed_;
VEC3 velocity_ ;
VEC3 newVelocity_ ;
VEC3 prefVelocity_ ;
VEC3 meanSpeed_ ;
// VEC3 meanPos_;
Simulator* sim_;
};
Simulator* sim_ ;
} ;
#endif
......@@ -10,24 +10,26 @@ namespace CGoGN
namespace CityGenerator
{
template<typename PFP>
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(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,
typename PFP::TVEC3& position, unsigned int cX, unsigned int cY, float sideLength,
CellMarker& obstacleMark, CellMarker& buildingMark) ;
typename PFP::TVEC3& position,
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,
CellMarker& buildingMark, float height) ;
CellMarker& buildingMark, float height) ;
#ifndef SPATIAL_HASHING
template<typename PFP>
template <typename PFP>
bool animateCity(EnvMap* envMap) ;
#endif
......@@ -37,43 +39,42 @@ bool animateCity(EnvMap* envMap) ;
//template <typename PFP>
//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) ;
template<typename PFP>
void generateMall(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark, float sideSize) ;
template <typename PFP>
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) ;
template <typename PFP>
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) ;
template <typename PFP>
void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark,
CellMarker& buildingMark, float radius, unsigned int nbSquares) ;
/*******************************************************************************/
template<typename PFP>
template <typename PFP>
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) ;
template<typename PFP>
template <typename PFP>
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,
CellMarker& obstacleMark, CellMarker& buildingMark) ;
CellMarker& obstacleMark, CellMarker& buildingMark) ;
template<typename PFP>
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.
......@@ -127,8 +127,8 @@ public:
CellMarker pedWayMark ;
#ifndef SPATIAL_HASHING
static const unsigned int nbAgentsToSubdivide = 4 ;
static const unsigned int nbAgentsToSimplify = 1 ;
static const unsigned int nbAgentsToSubdivide = 10 ;
static const unsigned int nbAgentsToSimplify = 4 ;
CellMarker refineMark ;
CellMarker coarsenMark ;
......@@ -139,20 +139,27 @@ public:
#endif
#ifdef SPATIAL_HASHING
float a_cell_nb_x, a_cell_nb_y ;
float o_cell_nb_x, o_cell_nb_y ;
unsigned int agentGridSize(unsigned int i)
{
return geometry.size(i) / minCellSize ;
}
unsigned int obstacleGridSize(unsigned int i)
{
return geometry.size(i) / obstacleDistance ;
}
Geom::Vec2ui agentPositionCell(VEC3& pos)
{
VEC3 relativePos = pos - geometry.min();
relativePos /= minCellSize;
VEC3 relativePos = pos - geometry.min() ;
relativePos /= minCellSize ;
return Geom::Vec2ui(relativePos[0], relativePos[1]) ;
}
Geom::Vec2ui obstaclePositionCell(VEC3& pos)
{
VEC3 relativePos = pos - geometry.min();
relativePos /= obstacleDistance;
VEC3 relativePos = pos - geometry.min() ;
relativePos /= obstacleDistance ;
return Geom::Vec2ui(relativePos[0], relativePos[1]) ;
}
......@@ -166,12 +173,14 @@ public:
* 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) {
for (typename std::vector<T>::iterator it = a.begin(); it != end; ++it)
{
if (*it == ag)
{
*it = a.back() ;
a.pop_back() ;
return ;
......@@ -180,7 +189,8 @@ inline void removeElementFromVector(std::vector<T>& a, T ag)
}
#ifndef SPATIAL_HASHING
inline unsigned int EnvMap::totalNeighborSize(Dart d) {
inline unsigned int EnvMap::totalNeighborSize(Dart d)
{
return agentvect[d].size() + neighborAgentvect[d].size() ;
}
......@@ -190,7 +200,8 @@ inline void EnvMap::nbAgentsIncrease(Dart d)
if (totalNeighborSize(d) < nbAgentsToSubdivide) return ;
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) ;
refineCandidate.push_back(d) ;
}
......@@ -213,9 +224,11 @@ inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
// nbAgentsIncrease(d);
Dart dd = d ;
do {
do
{
Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd) {
while (ddd != dd)
{
neighborAgentvect[ddd].push_back(agent) ;
// nbAgentsIncrease(ddd);
ddd = map.alpha1(ddd) ;
......@@ -232,9 +245,11 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
// nbAgentsDecrease(d) ;
Dart dd = d ;
do {
do
{
Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd) {
while (ddd != dd)
{
removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ;
// nbAgentsDecrease(ddd) ;
ddd = map.alpha1(ddd) ;
......@@ -246,7 +261,7 @@ 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(!buildingMark.isMarked(d)) ;
obstvect[d].push_back(o) ;
......@@ -270,7 +285,7 @@ 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(!buildingMark.isMarked(d)) ;
removeElementFromVector<Obstacle*>(obstvect[d], o) ;
......
......@@ -7,70 +7,72 @@
inline void renderDart(EnvMap& m, Dart d)
{
PFP::VEC3 p1 = m.position[d];
PFP::VEC3 p2 = m.position[m.map.phi1(d)];
PFP::VEC3 p1 = m.position[d] ;
PFP::VEC3 p2 = m.position[m.map.phi1(d)] ;
glBegin(GL_LINES);
glVertex3f(p1[0],p1[1],p1[2]);
glVertex3f(p2[0],p2[1],p2[2]);
glEnd();
glBegin(GL_LINES) ;
glVertex3f(p1[0], p1[1], p1[2]) ;
glVertex3f(p2[0], p2[1], p2[2]) ;
glEnd() ;
}
inline void renderFace(EnvMap& m, Dart d)
{
Dart dd=d;
do {
renderDart(m,dd);
dd = m.map.phi1(dd);
}while(dd!=d);
Dart dd = d ;
do
{
renderDart(m, dd) ;
dd = m.map.phi1(dd) ;
} while (dd != d) ;
}
inline void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
{
Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,d,m.position);
p[2] -= 1000;
Geom::intersectionPlaneRay(pl,p,VEC3(0,0,-1),p);
VEC3 pos1(m.position[d]);
VEC3 pos2(m.position[m.map.phi1(d)]);
pos2[2] += 2;
glBegin(GL_LINE_LOOP);
glVertex3fv(&p[0]);
glVertex3fv(& pos1[0]);
glVertex3fv(& pos2[0]);
glEnd();
Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map, d, m.position) ;
p[2] -= 1000 ;
Geom::intersectionPlaneRay(pl, p, VEC3(0, 0, -1), p) ;
VEC3 pos1(m.position[d]) ;
VEC3 pos2(m.position[m.map.phi1(d)]) ;
pos2[2] += 2 ;
glBegin(GL_LINE_LOOP) ;
glVertex3fv(&p[0]) ;
glVertex3fv(&pos1[0]) ;
glVertex3fv(&pos2[0]) ;
glEnd() ;
}
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 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 } ;
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
const VEC3& pos = agent->pos;
const VEC3& pos = agent->pos ;
#else
VEC3 pos = agent->part_.m_position;
VEC3 pos = agent->part_.m_position ;
#endif
float radius = agent->radius_;
float radius = agent->radius_ ;
// Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(m.map,agent->part_.d,m.position);
// pos[2] -= 1000;
// 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()));
// glColor3fv(col.data());
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_POLYGON);
for(unsigned int i = 0; i < 5; ++i)
glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2]+0.01f);
glEnd();
VEC3 dir = agent->velocity_;
dir.normalize();
//draw the speed vector
glColor3f(1.0f, 0.0f, 0.0f) ;
glBegin(GL_POLYGON) ;
for (unsigned int i = 0; i < 5; ++i)
glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2] + 0.01f) ;
glEnd() ;
VEC3 dir = agent->velocity_ ;
dir.normalize() ;
//draw the speed vector
// VEC3 base(0,0,1);
// VEC3 myAxisRot = base^dir;
// myAxisRot.normalize();
......@@ -88,37 +90,38 @@ inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false,
// glEnd();
// glPopMatrix();
//show goals
if(true)
//show goals
if (true)
{
glLineWidth(3.0f);
glBegin(GL_LINE_STRIP);
for(std::vector<VEC3>::iterator it = ++(agent->goals_.begin()) ; it != agent->goals_.end() ; ++it)
glLineWidth(3.0f) ;
glBegin(GL_LINE_STRIP) ;
for (std::vector<VEC3>::iterator it = ++(agent->goals_.begin()); it != agent->goals_.end();
++it)
{
glVertex3f((*it)[0],(*it)[1],(*it)[2]);
glVertex3f((*it)[0], (*it)[1], (*it)[2]) ;
}
glEnd();
glLineWidth(1.0f);
glEnd() ;
glLineWidth(1.0f) ;
}
if(showNeighborDist)
if (showNeighborDist)
{
radius = agent->neighborDist_;
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_LINE_LOOP);
for(unsigned int i = 0; i < 5; ++i)
glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2]+0.01f);
glEnd();
radius = agent->neighborDist_ ;
glColor3f(0.0f, 1.0f, 0.0f) ;
glBegin(GL_LINE_LOOP) ;
for (unsigned int i = 0; i < 5; ++i)
glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2] + 0.01f) ;
glEnd() ;
}
if(showObstacleDist)
if (showObstacleDist)
{
radius = (agent->timeHorizonObst_ * agent->maxSpeed_) + agent->radius_;
glColor3f(0.0f,0.0f,1.0f);
glBegin(GL_LINE_LOOP);
for(unsigned int i = 0; i < 5; ++i)
glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2]+0.01f);
glEnd();
radius = (agent->timeHorizonObst_ * agent->maxSpeed_) + agent->radius_ ;
glColor3f(0.0f, 0.0f, 1.0f) ;
glBegin(GL_LINE_LOOP) ;
for (unsigned int i = 0; i < 5; ++i)
glVertex3f(pos[0] + (cosT[i] * radius), pos[1] + (sinT[i] * radius), pos[2] + 0.01f) ;
glEnd() ;
}
}
......
......@@ -7,8 +7,9 @@ namespace CGoGN
namespace ExportScene
{
template <typename PFP>
bool exportSceneToFile(typename PFP::MAP& map,const typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, std::string& filename);
template <typename PFP>
bool exportSceneToFile(typename PFP::MAP& map, const typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark, std::string& filename) ;
}
......
......@@ -7,34 +7,35 @@ namespace ExportScene
{
template <typename PFP>
bool exportSceneToFile(typename PFP::MAP& map,const typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, std::string& filename)
bool exportSceneToFile(typename PFP::MAP& map, const typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark, std::string& filename)
{
std::ofstream out(filename.c_str(), std::ios::out);
std::ofstream out(filename.c_str(), std::ios::out) ;
if (!out.good())
{
std::cerr << "(export) Unable to open file " << filename << std::endl;
return false;
std::cerr << "(export) Unable to open file " << filename << std::endl ;
return false ;
}
CellMarker f(map, FACE);
CellMarker f(map, FACE) ;
for(Dart d = map.begin(); d != map.end(); map.next(d))
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if(buildingMark.isMarked(d) && !f.isMarked(d))
if (buildingMark.isMarked(d) && !f.isMarked(d))
{
f.mark(d);
Dart dd = d;
f.mark(d) ;
Dart dd = d ;
do
{
out << position[dd] << std::endl;
dd = map.phi1(dd);
} while(dd != d);
out << std::endl;
out << position[dd] << std::endl ;
dd = map.phi1(dd) ;
} while (dd != d) ;
out << std::endl ;
}
}
out.close();
return true;
out.close() ;
return true ;
}
}
......
......@@ -67,7 +67,7 @@
#endif
/* Support for compressed PostScript/PDF/SVG and for embedded PNG
images in SVG */
images in SVG */
#if defined(HAVE_ZLIB) || defined(HAVE_LIBZ)
# define GL2PS_HAVE_ZLIB
......@@ -139,10 +139,10 @@
#define GL2PS_BLEND 4
/* Text alignment (o=raster position; default mode is BL):
+---+ +---+ +---+ +---+ +---+ +---+ +-o-+ o---+ +---o
| o | o | | o | | | | | | | | | | | |
+---+ +---+ +---+ +-o-+ o---+ +---o +---+ +---+ +---+
C CL CR B BL BR T TL TR */
+---+ +---+ +---+ +---+ +---+ +---+ +-o-+ o---+ +---o
| o | o | | o | | | | | | | | | | | |
+---+ +---+ +---+ +-o-+ o---+ +---o +---+ +---+ +---+
C CL CR B BL BR T TL TR */
#define GL2PS_TEXT_C 1
#define GL2PS_TEXT_CL 2
......@@ -154,43 +154,39 @@
#define GL2PS_TEXT_TL 8
#define GL2PS_TEXT_TR 9
typedef GLfloat GL2PSrgba[4];
typedef GLfloat GL2PSrgba[4] ;
#if defined(__cplusplus)
extern "C" {
extern "C"
{
#endif
GL2PSDLL_API GLint gl2psBeginPage(const char *title, const char *producer,
GLint viewport[4], GLint format, GLint sort,
GLint options, GLint colormode,
GLint colorsize, GL2PSrgba *colormap,
GLint nr, GLint ng, GLint nb, GLint buffersize,
FILE *stream, const char *filename);
GL2PSDLL_API GLint gl2psEndPage(void);
GL2PSDLL_API GLint gl2psSetOptions(GLint options);
GL2PSDLL_API GLint gl2psGetOptions(GLint *options);
GL2PSDLL_API GLint gl2psBeginViewport(GLint viewport[4]);
GL2PSDLL_API GLint gl2psEndViewport(void);
GL2PSDLL_API GLint gl2psText(const char *str, const char *fontname,
GLshort fontsize);
GL2PSDLL_API GLint gl2psTextOpt(const char *str, const char *fontname,
GLshort fontsize, GLint align, GLfloat angle);
GL2PSDLL_API GLint gl2psSpecial(GLint format, const char *str);