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 c8492cd9 authored by Arash HABIBI's avatar Arash HABIBI
Browse files

nouvelle raideur

parents a89ac220 b5f9230a
......@@ -25,6 +25,7 @@ add_executable( socialAgentsD
../src/env_map.cpp
../src/agent.cpp
../src/moving_obstacle.cpp
../src/articulated_obstacle.cpp
../src/simulator.cpp
../src/moving_mesh.cpp
../src/gl2ps.c
......
......@@ -23,6 +23,7 @@ add_executable( socialAgents
../src/env_map.cpp
../src/agent.cpp
../src/moving_obstacle.cpp
../src/articulated_obstacle.cpp
../src/simulator.cpp
../src/moving_mesh.cpp
../src/gl2ps.c
......
......@@ -13,11 +13,10 @@ class Simulator ;
class Agent
{
public:
#ifdef SPATIAL_HASHING
Agent(Simulator* sim, const VEC3& position) ;
#else
Agent(Simulator* sim, const VEC3& position, Dart d) ;
#endif
Agent(Simulator* sim, const VEC3& position, const VEC3& goals, Dart d) ;
Agent(Simulator* sim, const VEC3& position, const VEC3& goals) ;
void init(const VEC3& start, const VEC3& goal);
VEC3 getPosition() ;
......@@ -50,19 +49,20 @@ public:
CGoGN::Algo::MovingObjects::ParticleCell2D<PFP> part_ ;
#endif
unsigned int curGoal_ ;
std::vector<VEC3> goals_ ;
VEC3 finalGoal ;
Dart finalDart ;
unsigned int curGoal_ ;
MovingObstacle **movingObstacles_;
int nb_mos;
static unsigned int maxNeighbors_ ;
static unsigned int maxMovingObstacles_;
static float maxSpeed_ ;
static float averageMaxSpeed_ ;
static float neighborDist_ ;
static float neighborDistSq_ ;
static float radius_ ;
......@@ -78,12 +78,12 @@ public:
float color3;
unsigned int agentNo ;
float maxSpeed_ ;
VEC3 velocity_ ;
VEC3 newVelocity_ ;
VEC3 prefVelocity_ ;
VEC3 meanSpeed_ ;
// VEC3 meanPos_;
VEC3 meanVelocity_[4] ;
VEC3 meanDirection_ ;
Simulator* sim_;
bool alive;
......
#ifndef M_ARTICULATED_OBSTACLE_H
#define M_ARTICULATED_OBSTACLE_H
#include "moving_obstacle.h"
using namespace std;
class ArticulatedObstacle
{
public:
ArticulatedObstacle(Simulator* sim, int index, int currentIndex, std::vector<PFP::VEC3> * pos, int nbParts, std::vector<VEC3> goals);
std::vector<MovingObstacle *> members;
int index;
int nbBodyPart;
std::vector<VEC3> goals;
VEC3 curGoal;
};
#endif
......@@ -15,7 +15,7 @@ bool notDiagonalAdjacentToAnObstacle(typename PFP::MAP& map, Dart d, CellMarker<
template <typename PFP> Algo::Modelisation::Polyhedron<PFP> generateGrid(EnvMap& envMap) ;
template <typename PFP> void generateCity(EnvMap& envMap) ;
template <typename PFP> void generateCity(EnvMap& envMap, unsigned int nbBuildings) ;
template <typename PFP>
Algo::Modelisation::Polyhedron<PFP> generateTrianGrid(typename PFP::MAP& map,
......@@ -28,6 +28,9 @@ template <typename PFP>
Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d,
CellMarker<FACE>& buildingMark, float height) ;
template <typename PFP>
Dart extrudeBuilding(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, unsigned int buildingType, float height);
#ifndef SPATIAL_HASHING
template <typename PFP>
bool animateCity(EnvMap* envMap) ;
......@@ -47,9 +50,21 @@ void generatePathToUpperStair(typename PFP::MAP& map, typename PFP::TVEC3& posit
/*******************************************************************************/
//template <typename PFP>
//void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker<EDGE>& obstacleMark,
// CellMarker<FACE>& buildingMark, float radius, unsigned int nbSquares) ;
template <typename PFP>
void generatePlanet(EnvMap& envMap) ;
template <typename PFP>
typename PFP::VEC3 parametrization(typename PFP::VEC3 p, float r, const Geom::BoundingBox<typename PFP::VEC3>& bb);
template <typename PFP>
void planetify(typename PFP::MAP& map, typename PFP::TVEC3& position, float r);
template <typename PFP>
void generatePlanet(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker<EDGE>& obstacleMark,
CellMarker<FACE>& buildingMark, float radius, unsigned int nbSquares) ;
void planetify(typename PFP::MAP& map, typename PFP::TVEC3& position, float r, const Geom::BoundingBox<typename PFP::VEC3>& bb);
/*******************************************************************************/
......
......@@ -63,9 +63,9 @@ Algo::Modelisation::Polyhedron<PFP> generateGrid(EnvMap& envMap)
}
template <typename PFP>
void generateCity(EnvMap& envMap)
void generateCity(EnvMap& envMap, unsigned int nbBuildings)
{
unsigned int nbBuilding = 1000 ;
unsigned int nbBuilding = nbBuildings ;
std::cout << " - Generate City : " << nbBuilding << " buildings" << std::endl ;
generateGrid<PFP>(envMap) ;
......@@ -76,7 +76,7 @@ void generateCity(EnvMap& envMap)
if (!envMap.buildingMark.isMarked(d) && (rand() % 12 == 0)
&& notDiagonalAdjacentToAnObstacle<PFP>(envMap.map, d, envMap.buildingMark))
{
generateBuilding<PFP>(envMap, d, (1 + (rand() % 3)) * 2.0f, rand() % 4) ;
generateBuilding<PFP>(envMap, d, (1 + (rand() % 3)) * 50.0f, rand() % 4) ;
--nbBuilding ;
}
}
......@@ -198,6 +198,75 @@ Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, D
return dRoof ;
}
template <typename PFP>
Dart extrudeBuilding(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, unsigned int buildingType, float height)
{
Dart dRoof ;
// VEC3 sky(0,0,1.0f);
VEC3 v1(position[map.phi1(d)]-position[d]);
VEC3 v2(position[map.template phi<11>(d)]-position[d]);
VEC3 sky = (v1^v2);
sky.normalize();
dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, d, height) ;
switch (buildingType)
{
case 0 : //basic
{
break ;
}
case 1 : //with roof 1 slope
{
dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, dRoof, height/3.0f) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
break ;
}
case 2 : //with roof 2 slopes
{
dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, dRoof, height/3.0f) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
typename PFP::VEC3 mid1 = (position[dNext] + position[map.phi1(dNext)]) / 2.0f ;
typename PFP::VEC3 mid2 = (position[dPrev] + position[map.phi1(dPrev)]) / 2.0f ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
position[dRoof] = mid2 ;
position[map.phi1(dRoof)] = mid1 ;
break ;
}
case 3 : //with multiple stairs
{
unsigned int nbStairs = rand() % 5 ;
for (unsigned int i = 0; i < nbStairs; ++i)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
Dart dRoofSmall = Algo::Modelisation::extrudeFace<PFP>(map, position, dRoof, 0.0f) ;
Dart dd = dRoofSmall ;
do
{
position[dd] = position[dd] + (c - position[dd]) / 3.0f ;
dd = map.phi1(dd) ;
} while (dd != dRoofSmall) ;
dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, dRoofSmall, height/2.0f) ;
}
bool spike = rand() % 2 ;
if (spike)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
c[2] += height / 1.5f ;
dRoof = Algo::Modelisation::trianguleFace<PFP>(map, dRoof) ;
position[dRoof] = c ;
}
break ;
}
}
return dRoof;
}
#ifndef SPATIAL_HASHING
template <typename PFP>
bool animateCity(EnvMap* envMap)
......@@ -354,58 +423,58 @@ Dart generateBuilding(EnvMap& envMap, Dart d, float height, unsigned int buildin
switch (buildingType)
{
case 0 :
{
break ;
}
case 1 :
{
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height / 3) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
break ;
}
case 2 :
{
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height / 3) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
typename PFP::VEC3 mid1 = (position[dNext] + position[map.phi1(dNext)]) / 2.0f ;
typename PFP::VEC3 mid2 = (position[dPrev] + position[map.phi1(dPrev)]) / 2.0f ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
position[dRoof] = mid2 ;
position[map.phi1(dRoof)] = mid1 ;
break ;
}
case 3 :
{
unsigned int nbStairs = rand() % 5 ;
for (unsigned int i = 0; i < nbStairs; ++i)
case 0 :
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
Dart dRoofSmall = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, 0.0f) ;
Dart dd = dRoofSmall ;
do
{
position[dd] = position[dd] + (c - position[dd]) / 3.0f ;
dd = map.phi1(dd) ;
} while (dd != dRoofSmall) ;
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoofSmall, buildingMark,
height / 2.0f) ;
break ;
}
bool spike = rand() % 2 ;
if (spike)
case 1 :
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
c[2] += height / 1.5f ;
dRoof = Algo::Modelisation::trianguleFace<PFP>(map, dRoof) ;
position[dRoof] = c ;
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height / 3) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
break ;
}
case 2 :
{
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height / 3) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
typename PFP::VEC3 mid1 = (position[dNext] + position[map.phi1(dNext)]) / 2.0f ;
typename PFP::VEC3 mid2 = (position[dPrev] + position[map.phi1(dPrev)]) / 2.0f ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
position[dRoof] = mid2 ;
position[map.phi1(dRoof)] = mid1 ;
break ;
}
case 3 :
{
unsigned int nbStairs = rand() % 5 ;
for (unsigned int i = 0; i < nbStairs; ++i)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
Dart dRoofSmall = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, 0.0f) ;
Dart dd = dRoofSmall ;
do
{
position[dd] = position[dd] + (c - position[dd]) / 3.0f ;
dd = map.phi1(dd) ;
} while (dd != dRoofSmall) ;
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoofSmall, buildingMark,
height / 2.0f) ;
}
bool spike = rand() % 2 ;
if (spike)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
c[2] += height / 1.5f ;
dRoof = Algo::Modelisation::trianguleFace<PFP>(map, dRoof) ;
position[dRoof] = c ;
}
break ;
}
break ;
}
}
return dRoof ;
......@@ -548,6 +617,44 @@ void generatePlanet(EnvMap& envMap)
prim.embedSphere((xRadius+yRadius)/2.0f) ;
}
template <typename PFP>
typename PFP::VEC3 parametrization(typename PFP::VEC3 p, float r,const Geom::BoundingBox<typename PFP::VEC3>& bb)
{
p[0] = 2.0f*M_PI*(p[0]-bb.min()[0])/bb.size(0);
p[1] = ((2.0f*M_PI*(p[1]-bb.min()[1])/bb.size(1))-M_PI)/2.0f;
return typename PFP::VEC3(2.0f*r*cos(p[0])*cos(p[1]),
2.0f*r*sin(p[0])*cos(p[1]),
2.0f*r*sin(p[1]));
}
template <typename PFP>
void planetify(typename PFP::MAP& map, typename PFP::TVEC3& position, float r)
{
Geom::BoundingBox<typename PFP::VEC3> bb ;
bb = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
typedef typename PFP::VEC3 VEC3 ;
TraversorV<typename PFP::MAP> tv(map);
//apply inverted transformation to build a sphere from planar coordinates (not working)
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] = parametrization<PFP>(position[d], r, bb);
}
}
template <typename PFP>
void planetify(typename PFP::MAP& map, typename PFP::TVEC3& position, float r,const Geom::BoundingBox<typename PFP::VEC3>& bb)
{
TraversorV<typename PFP::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] = parametrization<PFP>(position[d], r, bb);
}
}
template <typename PFP>
void simplifyFreeSpace(typename PFP::MAP& map, typename PFP::TVEC3& position,
CellMarker<EDGE>& obstacleMark, CellMarker<FACE>& buildingMark)
......
......@@ -28,32 +28,9 @@ using namespace CGoGN ;
class Agent;
class Obstacle;
class MovingObstacle;
class ArticulatedObstacle;
struct PFP : public PFP_STANDARD
{
// definition de la carte
typedef Algo::IHM::ImplicitHierarchicalMap MAP ;
// definition des listes d'agent
typedef std::vector<Agent*> AGENTS ;
typedef std::vector<Obstacle*> OBSTACLES ;
typedef std::vector<MovingObstacle*> MOVINGOBSTACLES;
typedef NoMathIONameAttribute<AGENTS> AGENTVECT ;
typedef NoMathIONameAttribute<OBSTACLES> OBSTACLEVECT ;
typedef NoMathIONameAttribute<MOVINGOBSTACLES> MOVINGOBSTACLEVECT;
typedef VertexAttribute<PFP::VEC3> TVEC3;
typedef FaceAttribute<AGENTVECT> TAB_AGENTVECT ;
typedef FaceAttribute<OBSTACLEVECT> TAB_OBSTACLEVECT ;
typedef NoMathIONameAttribute<std::pair<bool, bool> > BOOLATTRIB ;
} ;
typedef PFP::VEC3 VEC3 ;
typedef PFP::REAL REAL ;
#include "pfp.h"
class EnvMap
{
......@@ -75,6 +52,8 @@ public:
EnvMap() ;
void init(unsigned int config, REAL width, REAL height, REAL minSize, REAL maxSize) ;
void scale(float val);
void markPedWay() ;
unsigned int mapMemoryCost() ;
......@@ -149,7 +128,7 @@ public:
#ifndef SPATIAL_HASHING
static const unsigned int nbAgentsToSubdivide = 5 ;
static const unsigned int nbAgentsToSimplify = 1 ;
static const unsigned int nbAgentsToSimplify = 4 ;
CellMarker<FACE> refineMark ;
CellMarker<FACE> coarsenMark ;
......@@ -184,8 +163,7 @@ public:
return ht_agents[c];
}
const std::vector<Agent*>& getNeighbors(Agent* a) ;
void getOneRingNeighbors(Agent* a, std::vector<Agent*>& neighbors) ;
const std::vector<Agent*>& getNeighborAgents(Agent* a) ;
void addAgentInGrid(Agent* a) ;
void addAgentInGrid(Agent* a, Geom::Vec2ui c) ;
......@@ -194,6 +172,7 @@ public:
void removeAgentFromGrid(Agent* a, Geom::Vec2ui c) ;
HashTable2D< std::vector<Agent*> > ht_agents ;
HashTable2D< std::vector<Agent*> > ht_neighbor_agents ;
HashTable2D< std::vector<Obstacle*> > ht_obstacles ;
#endif
} ;
......
......@@ -26,6 +26,7 @@ inline void renderFace(EnvMap& m, Dart d)
} 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) ;
......@@ -42,11 +43,37 @@ inline void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
glEnd() ;
}
inline void renderObstacle(EnvMap& m, MovingObstacle * obst, bool showBelonging=false, bool renderPath = false)
{
glBegin(GL_POLYGON) ;
for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
{
const VEC3& p = obst->vertices[i] ;
glVertex3fv(p.data()) ;
}
glEnd() ;
if (renderPath)
{
glLineWidth(3.0f) ;
glBegin(GL_LINE_STRIP) ;
for (std::vector<VEC3>::iterator it = ++(obst->goals_.begin()) ; it != obst->goals_.end() ;
++it)
{
glVertex3f((*it)[0], (*it)[1], (*it)[2]) ;
}
glEnd() ;
glLineWidth(1.0f) ;
}
}
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, float c1=1.0f,float c2=0, float c3=0 )
bool showObstacleDist = false, bool renderPath = false, float c1=1.0f,float c2=0, float c3=0 )
{
#ifdef SPATIAL_HASHING
const VEC3& pos = agent->pos ;
......@@ -61,9 +88,9 @@ inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false,
glLineWidth(1.0f) ;
// VEC3 col = Utils::color_map_BCGYR(float(agent->agentNo)/float(agent->sim_->agents_.size()));
// glColor3fv(col.data());
glColor3f(c1,c2,c3) ;
VEC3 col = Utils::color_map_BCGYR(float(agent->agentNo)/float(agent->sim_->agents_.size()));
glColor3fv(col.data());
// glColor3f(c1,c2,c3) ;
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) ;
......@@ -96,7 +123,7 @@ inline void renderAgent(EnvMap& m, Agent* agent, bool showNeighborDist = false,
// glPopMatrix();
//show goals
if (true)
if (renderPath)
{
glLineWidth(3.0f) ;
glBegin(GL_LINE_STRIP) ;
......
......@@ -10,13 +10,13 @@
using namespace std;
PFP::VEC3 rotate (PFP::VEC3 pos1, PFP::VEC3 center, float angle);
float get_angle (PFP::VEC3 v1, PFP::VEC3 v2);
PFP::VEC3 get_center (ArticulatedObstacle * art, int index);
class Simulator ;
class MovingObstacle
{
public:
MovingObstacle(Simulator* sim, int index, std::vector<PFP::VEC3> pos, std::vector<VEC3> goals,bool spin);
MovingObstacle(Simulator* sim, int index, std::vector<PFP::VEC3> pos, std::vector<VEC3> goals,bool spin, ArticulatedObstacle * art=NULL, int ind2=-1);
bool test_opposition(VEC3 o, VEC3 p1, VEC3 p2);
// void contournerBatiment();
void updateAgentNeighbors() ;
......@@ -63,11 +63,17 @@ public:
float obstacle_range;
static float timeHorizonObst_;
float velocity_factor;
float color1;
float color2;
float color3;
bool seen;
VEC3 velocity_;
VEC3 newVelocity_;
VEC3 prefVelocity_;
Simulator* sim_;
bool spinning;
ArticulatedObstacle * parent;
int index_parent;
};
#endif
#ifndef PATH_FINDER
#define PATH_FINDER
#include "env_map.h"
namespace CGoGN
{
......@@ -8,20 +10,17 @@ namespace PathFinder
{
template <typename PFP>
float pathCostSqr(typename PFP::MAP& map, const typename PFP::TVEC3& position, Dart startPos,
Dart stopPos, CellMarker<FACE>& bad) ;
float pathCostSqr(EnvMap& envMap, const typename PFP::TVEC3& position, Dart start, Dart goal) ;
template <typename PFP>
std::vector<Dart> pathFindAStar(typename PFP::MAP& map, const typename PFP::TVEC3& position,
Dart startPos, Dart stopPos, CellMarker<FACE>& bad) ;
std::vector<Dart> pathFindAStar(EnvMap& envMap, const typename PFP::TVEC3& position,
Dart start, Dart goal, CellMarker<FACE>& bad) ;
//computation of a "Rapidly exploring random tree"
//requires the definition of states for the moving objects
template <typename STATE>
std::vector<VEC3> pathRRT(STATE startState, VEC3 stopPos,
float sampleSize, float epsilon,
STATE (*fctStep)(STATE start, VEC3 goal, float sampleSize)
);
std::vector<VEC3> pathRRT(STATE startState, VEC3 stopPos, float sampleSize, float epsilon,
STATE (*fctStep)(STATE start, VEC3 goal, float sampleSize)) ;
}
......
......@@ -9,176 +9,176 @@ namespace PathFinder
{
template <typename PFP>
float pathCostSqr(typename PFP::MAP& map, const typename PFP::TVEC3& position, Dart startPos,
Dart stopPos, CellMarker<FACE>& bad)
float pathCost(EnvMap& envMap, const typename PFP::TVEC3& position, Dart start, Dart goal)
{
// float penalty=100000000.0f;
// Dart dd = startPos;