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 36f52fea authored by Thomas's avatar Thomas
Browse files

merge

parents ada40ede 7d618dcf
......@@ -4,7 +4,7 @@ project(SocialAgents)
#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)
add_subdirectory(${CMAKE_SOURCE_DIR}/Release Release)
......
......@@ -85,7 +85,7 @@ public:
VEC3 prefVelocity_;
VEC3 meanSpeed_;
VEC3 meanPos_;
// VEC3 meanPos_;
Simulator* sim_;
};
......
......@@ -10,57 +10,67 @@ 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(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> generateGrid(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> void generateCity(EnvMap& envMap) ;
template <typename PFP>
Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, CellMarker& buildingMark, float height);
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) ;
#ifndef SPATIAL_HASHING
template <typename PFP>
bool animateCity(EnvMap* envMap);
template<typename PFP>
bool animateCity(EnvMap* envMap) ;
#endif
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>
void generateCity(EnvMap* envMap, float sideSize, unsigned int nbSquares);
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>
void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position);
template<typename PFP>
void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position) ;
template <typename PFP>
bool isAnEar(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dd, float& area);
template<typename PFP>
bool isAnEar(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart dd, float& area) ;
template <typename PFP>
bool canRemoveEdgeConvex(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, CellMarker& obstacleMark);
template<typename PFP>
bool canRemoveEdgeConvex(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d,
CellMarker& obstacleMark) ;
template <typename PFP>
void convexifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark);
template<typename PFP>
void convexifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark) ;
template <typename PFP>
void installGuardRail(typename PFP::MAP& map,typename PFP::TVEC3& position, CellMarker& obstacleMark, CellMarker& buildingMark, float height);
template<typename PFP>
void installGuardRail(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker& obstacleMark, CellMarker& buildingMark, float height) ;
}
......
This diff is collapsed.
......@@ -23,198 +23,231 @@
#include "spatialHashing.h"
using namespace CGoGN;
using namespace CGoGN ;
class Agent;
class Obstacle;
class Agent ;
class Obstacle ;
struct PFP: public PFP_STANDARD
struct PFP : public PFP_STANDARD
{
// definition de la carte
// typedef EmbeddedMap2 MAP;
typedef Algo::IHM::ImplicitHierarchicalMap MAP;
typedef Algo::IHM::ImplicitHierarchicalMap MAP ;
// definition des listes d'agent
typedef std::vector<Agent*> AGENTS;
typedef std::vector<Obstacle*> OBSTACLES;
typedef NoMathIONameAttribute<AGENTS> AGENTVECT;
typedef NoMathIONameAttribute<OBSTACLES> OBSTACLEVECT;
typedef AttributeHandler<AGENTVECT> TAB_AGENTVECT;
typedef AttributeHandler<OBSTACLEVECT> TAB_OBSTACLEVECT;
typedef std::vector<Agent*> AGENTS ;
typedef std::vector<Obstacle*> OBSTACLES ;
typedef NoMathIONameAttribute<AGENTS> AGENTVECT ;
typedef NoMathIONameAttribute<OBSTACLES> OBSTACLEVECT ;
typedef AttributeHandler<AGENTVECT> TAB_AGENTVECT ;
typedef AttributeHandler<OBSTACLEVECT> TAB_OBSTACLEVECT ;
typedef NoMathIONameAttribute<std::pair<bool,bool> > BOOLATTRIB;
};
typedef NoMathIONameAttribute<std::pair<bool, bool> > BOOLATTRIB ;
} ;
typedef PFP::VEC3 VEC3;
typedef PFP::VEC3 VEC3 ;
typedef PFP::REAL REAL ;
class EnvMap
{
public :
EnvMap();
void markPedWay();
public:
PFP::MAP map ;
unsigned int mapMemoryCost();
void scale(float scaleVal);
/* 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() ;
#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 clearUpdateCandidates();
void updateMap();
void resetAgentInFace(Agent* agent);
void resetAgentInFace(Agent* agent) ;
#endif
PFP::MAP map;
PFP::TVEC3 position;
PFP::TVEC3 normal;
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
PFP::MAP mapScenary;
PFP::TVEC3 positionScenary;
PFP::TVEC3 normalScenary;
CellMarker obstacleMarkS;
CellMarker buildingMarkS;
PFP::MAP mapScenary ;
PFP::TVEC3 positionScenary ;
PFP::TVEC3 normalScenary ;
CellMarker obstacleMarkS ;
CellMarker buildingMarkS ;
std::vector<Dart> newBuildings;
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_OBSTACLEVECT obstvect;
#endif
CellMarker obstacleMark;
CellMarker buildingMark;
CellMarker pedWayMark;
PFP::TAB_OBSTACLEVECT obstvect ;
CellMarker obstacleMark ;
CellMarker buildingMark ;
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 *
**************************************/
* 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 void EnvMap::pushAgentInCells(Agent* agent, Dart d)
inline unsigned int EnvMap::totalNeighborSize(Dart d) {
return agentvect[d].size() + neighborAgentvect[d].size() ;
}
inline void EnvMap::nbAgentsIncrease(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);
if (refineMark.isMarked(d)) return ;
if (totalNeighborSize(d) < nbAgentsToSubdivide) return ;
Dart dd = d;
do
{
Dart ddd = map.alpha1(map.alpha1(dd));
while(ddd != dd)
{
neighborAgentvect[ddd].push_back(agent);
ddd = map.alpha1(ddd);
}
dd = map.phi1(dd);
} while(dd != d);
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::popAgentInCells(Agent* agent, Dart d)
inline void EnvMap::nbAgentsDecrease(Dart d)
{
assert(map.getCurrentLevel() == map.getMaxLevel());
assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end());
if (coarsenMark.isMarked(d) || refineMark.isMarked(d)) return ;
if (totalNeighborSize(d) > nbAgentsToSimplify) return ;
removeElementFromVector<Agent* >(agentvect[d], agent);
coarsenMark.mark(d) ;
coarsenCandidate.push_back(map.faceOldestDart(d)) ;
}
Dart dd = d;
do
{
Dart ddd = map.alpha1(map.alpha1(dd));
while(ddd != dd)
{
removeElementFromVector<Agent* >(neighborAgentvect[ddd], agent);
ddd = map.alpha1(ddd);
inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
{
assert(map.getCurrentLevel() == map.getMaxLevel()) ;
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) ;
} while (dd != d) ;
}
inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
{
assert(map.getCurrentLevel() == map.getMaxLevel()) ;
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);
} while(dd != d);
dd = map.phi1(dd) ;
} while (dd != 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);
......@@ -235,10 +268,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);
......@@ -258,8 +291,8 @@ inline void EnvMap::popObstacleInCells(Obstacle* o, Dart d)
inline void EnvMap::clearUpdateCandidates()
{
refineCandidate.clear();
coarsenCandidate.clear();
refineCandidate.clear() ;
coarsenCandidate.clear() ;
}
#endif
......
......@@ -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