Commit 78c423cc authored by Arash HABIBI's avatar Arash HABIBI
Browse files

juste_pour_pouvoir_faire_pull

parents 419ba993 762c7fdb
......@@ -16,6 +16,8 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
QT4_WRAP_UI( socialAgents_ui ../include/socialAgents.ui )
QT4_WRAP_CPP( socialAgents_moc ../include/viewer.h )
add_executable( socialAgents
......
......@@ -328,7 +328,7 @@ inline void EnvMap::addObstAsNeighbor (Obstacle * o, const std::vector<Dart>& b
} while(first==NIL && d!=beg);
++it;
}while(first==NIL && it!=belonging_cells.end());
assert(!buildingMark.isMarked(d)) ;
// assert(!buildingMark.isMarked(d)) ;
assert(first!=NIL) ;
// CGoGNout<<"first : "<<first<<CGoGNendl;
d=first;
......
......@@ -5,6 +5,8 @@
#include "agent.h"
#include "Utils/colorMaps.h"
#include "Algo/Render/GL1/map_glRender.h"
inline void renderDart(EnvMap& m, Dart d)
{
PFP::VEC3 p1 = m.position[d] ;
......@@ -44,17 +46,66 @@ inline void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
}
inline void renderObstacle(EnvMap& m, MovingObstacle * obst, bool showBelonging=false, bool renderPath = false)
inline void renderObstacle(EnvMap& m, MovingObstacle * obst, bool showBelonging=false, bool renderPath = false, bool showVertices=false)
{
glBegin(GL_POLYGON) ;
for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
{
const VEC3& p = obst->getPosition(i) ;
glVertex3fv(p.data()) ;
}
glEnd() ;
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) ;
glColor3f(0,1,0);
Algo::Render::GL1::renderTriQuadPoly<PFP>(obst->map, Algo::Render::GL1::LINE,
1.0, obst->position,
obst->normal) ;
if(showVertices)
{
glPointSize(3.0f) ;
glColor3f(0.0,0.0,1.0);
glBegin(GL_POINTS) ;
for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
{
const VEC3& p = obst->getPosition(i) ;
glVertex3fv(p.data()) ;
}
glEnd() ;
glPointSize(1.0f) ;
}
glColor3f(1.0,0.0,1.0);
glBegin(GL_LINE_LOOP) ;
for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
{
const VEC3& p = obst->vertices[i] ;
const VEC3& p = obst->getDilatedPosition(i) ;
glVertex3fv(p.data()) ;
}
glEnd() ;
// glColor3f(0.0,1.0,1.0);
// glBegin(GL_LINES) ;
// for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
// {
// const VEC3& p = obst->getPosition(i) ;
// glVertex3fv(p.data()) ;
// const VEC3& p2 = obst->getDilatedPosition(i) ;
// glVertex3fv(p2.data()) ;
// }
// glEnd() ;
glLineWidth(5.0f) ;
glColor3f(1.0,1.0,0.0);
glBegin(GL_LINES) ;
VEC3 p = obst->getPosition(0) ;
glVertex3fv(p.data()) ;
p += 20.0f*obst->velocity_;
glVertex3fv(p.data()) ;
glEnd() ;
if (renderPath)
{
glLineWidth(3.0f) ;
......
......@@ -15,19 +15,25 @@ using namespace std;
class MovingMesh
{
public:
MovingMesh(EnvMap * envMap, Dart d, std::string filename);
MovingMesh(EnvMap& envMap, Dart d, std::string filename);
void linkWithObstacle(MovingObstacle * mo);
void transform(Geom::Matrix44f m);
void translate(VEC3 v);
void scale(float val);
void moveInFace(PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> pos);
void move();
void animate();
std::vector<VEC3> computeProjectedPointSet();
void draw();
std::vector<VEC3> computeProjectedPointSet(float maxHeight);
std::vector<VEC3> jarvisConvexHull(std::vector<VEC3> projectedPointSet);
std::vector<VEC3> computeSkeleton(std::vector<VEC3> projectedPointSet, unsigned int nodeNumber);
PFP::MAP& motherMap;
VertexAttribute<VEC3>& motherPosition;
PFP::MAP map;
VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal;
......
......@@ -16,7 +16,7 @@ class Simulator ;
class MovingObstacle
{
public:
MovingObstacle(Simulator* sim, int index, std::vector<PFP::VEC3> pos, std::vector<VEC3> goals,bool spin, ArticulatedObstacle * art=NULL, int ind2=-1);
MovingObstacle(Simulator* sim, int index, std::vector<PFP::VEC3> pos, std::vector<VEC3> goals, bool rigid, bool spin, ArticulatedObstacle * art=NULL, int indParent=-1);
bool test_opposition(VEC3 o, VEC3 p1, VEC3 p2);
// void contournerBatiment();
void updateAgentNeighbors() ;
......@@ -26,11 +26,35 @@ public:
void computeNewVelocity();
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
VEC3 getDilatedPosition(unsigned int ind); //vertex position with velocity dilatation
VEC3 getPosition(unsigned int ind); // vertex position
void update();
unsigned int nbVertices;
CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP> *registering_part;
std::vector<PFP::VEC3> vertices;
// std::vector<PFP::VEC3> vertices;
PFP::MAP map;
VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal;
VertexAttribute<VEC3> deformation;
VertexAttribute<VEC3> velocity;
EdgeAttribute<float> edgeLength;
Dart groundFace;
//vector de détails pour la deformation
// std::vector<PFP::VEC3> verticesDeformation;
//gestion pour du mass-ressort
// std::vector<PFP::VEC3> verticesVelocity;
// std::vector<float> edgeLength;
// std::vector<float> verticesAngle;
// float rigidity;
float gravity_dist;
VEC3 center;
int nb_agents_voisins;
......@@ -71,6 +95,7 @@ public:
VEC3 newVelocity_;
VEC3 prefVelocity_;
Simulator* sim_;
bool rigid_;
bool spinning;
ArticulatedObstacle * parent;
int index_parent;
......
......@@ -6,7 +6,7 @@
class Obstacle
{
public:
Obstacle(const VEC3& point1, const VEC3& point2, const VEC3& prevPoint, const VEC3& nextPoint,
Obstacle(const VEC3 point1, const VEC3 point2, const VEC3 prevPoint, const VEC3 nextPoint,
MovingObstacle * moving1, unsigned int ind) :
p1(point1), p2(point2), prevP(prevPoint), nextP(nextPoint),
mo(moving1), index(ind)
......@@ -17,10 +17,10 @@ public:
// nextP[2] = 0 ;
}
const VEC3& p1 ;
const VEC3& p2 ;
const VEC3& prevP ;
const VEC3& nextP ;
VEC3 p1 ;
VEC3 p2 ;
VEC3 prevP ;
VEC3 nextP ;
MovingObstacle * mo ;
unsigned int index ;
} ;
......
......@@ -80,11 +80,11 @@ public:
class Simulator
{
public:
Simulator(unsigned int config, unsigned int minSize) ;
Simulator(unsigned int config, unsigned int minSize, unsigned int nbAgent=1000, unsigned int nbObst=20) ;
~Simulator() ;
void init(float dimension, bool enablePathFinding = false) ;
void init(float dimension, unsigned int nbAgent, unsigned int nbObst, bool enablePathFinding = false) ;
void doStep() ;
......@@ -120,6 +120,7 @@ public:
EnvMap envMap_ ;
std::vector<Agent*> agents_ ;
std::vector<MovingObstacle*> movingObstacles_;
std::vector<MovingMesh*> movingMeshes_; //for visualization only
int minSize;
unsigned int config;
float timeStep_ ;
......
......@@ -51,7 +51,7 @@ class SocialAgents : public Utils::QT::SimpleQT
Q_OBJECT
public:
SocialAgents(unsigned int config, unsigned int minSize, unsigned int iterations) ;
SocialAgents(unsigned int config, unsigned int minSize, unsigned int nbAgent , unsigned int nbObst , unsigned int iterations) ;
void initGUI() ;
......
......@@ -206,13 +206,14 @@ void Agent::updateObstacleNeighbors()
{
float distSq = distSqPointLineSegment((*it)->p1, (*it)->p2, part_.getPosition()) ;
if ((obstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistObst)
&&distSq < rangeSq_)
&& distSq < rangeSq_)
{
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
if (distSq > maxDistObst) maxDistObst = distSq ;
obstacleNeighbors_.push_back(std::make_pair(distSq, *it)) ;
if (distSq > maxDistObst)
maxDistObst = distSq ;
obstacleNeighbors_.push_back(std::make_pair(distSq, *it)) ;
}
......@@ -222,12 +223,13 @@ void Agent::updateObstacleNeighbors()
{
float distSq = distSqPointLineSegment((*it)->p1, (*it)->p2, part_.getPosition()) ;
if ((movingObstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistMovingObst)
&&distSq < rangeSq_)
&& distSq < rangeSq_)
{
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
if (distSq > maxDistMovingObst) maxDistMovingObst = distSq ;
if (distSq > maxDistMovingObst)
maxDistMovingObst = distSq ;
movingObstacleNeighbors_.push_back(std::make_pair(distSq, *it)) ;
}
......@@ -235,6 +237,7 @@ void Agent::updateObstacleNeighbors()
}
}
}
for(std::vector<Obstacle*>::const_iterator it = neighborObst.begin() ; it != neighborObst.end() ; ++it)
{
if ((*it)->mo==NULL)
......@@ -259,7 +262,7 @@ void Agent::updateObstacleNeighbors()
if ((movingObstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistMovingObst)
&&distSq < rangeSq_)
{
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
if (distSq > maxDistMovingObst) maxDistMovingObst = distSq ;
......@@ -270,16 +273,18 @@ void Agent::updateObstacleNeighbors()
}
}
}
if (obstacleNeighbors_.size() > maxNeighbors_)
{
sim_->nbSorts++ ;
std::sort(obstacleNeighbors_.begin(), obstacleNeighbors_.end(), obstacleSort) ;
}
if (movingObstacleNeighbors_.size() > maxNeighbors_)
{
sim_->nbSorts++ ;
std::sort(movingObstacleNeighbors_.begin(), movingObstacleNeighbors_.end(), obstacleSort) ;
}
// if (obstacleNeighbors_.size() > maxNeighbors_)
// {
// sim_->nbSorts++ ;
// std::sort(obstacleNeighbors_.begin(), obstacleNeighbors_.end(), obstacleSort) ;
// }
//
// if (movingObstacleNeighbors_.size() > maxNeighbors_)
// {
// sim_->nbSorts++ ;
// std::sort(movingObstacleNeighbors_.begin(), movingObstacleNeighbors_.end(), obstacleSort) ;
// }
......@@ -655,7 +660,7 @@ void Agent::computeNewVelocity()
double ag_stiffness = 500.0; // agent-agent interaction stiffness
double ag_damping = 1.0; // agent-agent interaction damping
double ag_phys_radius_coef = 20.0;
double ag_power = 8; // the power to which elevate the agent-agent distance
double ag_power = 1; // the power to which elevate the agent-agent distance
unsigned int nbA = 0 ;
......
......@@ -10,7 +10,7 @@ ArticulatedObstacle::ArticulatedObstacle(Simulator* sim, int index, int currentI
{
std::vector<VEC3> goal;
goal.push_back(members[i-1]->center);
MovingObstacle * mo4= new MovingObstacle(sim,currentIndex+1+i ,pos[i],goal,true, this,i);
MovingObstacle * mo4= new MovingObstacle(sim,currentIndex+1+i ,pos[i],goal, true, true, this,i);
members.push_back(mo4);
}
......
......@@ -74,7 +74,7 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
{
case 0 :
// CityGenerator::generateGrid<PFP>(*this) ;
CityGenerator::generateCity<PFP>(*this,1) ;
CityGenerator::generateCity<PFP>(*this,0) ;
break ;
case 1 :
CityGenerator::generateGrid<PFP>(*this) ;
......@@ -98,13 +98,13 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
Algo::Import::importSVG<PFP>(map, filename, position, obstacleMark, buildingMark) ;
std::string filename2 = "./svg/mapBuild.svg" ;
Algo::Import::importSVG<PFP>(mapScenary, filename2, positionScenary, obstacleMarkS, buildingMarkS) ;
// Algo::Import::importSVG<PFP>(mapScenary, filename2, positionScenary, obstacleMarkS, buildingMarkS) ;
Geom::BoundingBox<PFP::VEC3> bb1, bb2 ;
bb1 = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
bb2 = Algo::Geometry::computeBoundingBox<PFP>(mapScenary, positionScenary) ;
bb1.addPoint(bb2.min());
bb1.addPoint(bb2.max());
// bb2 = Algo::Geometry::computeBoundingBox<PFP>(mapScenary, positionScenary) ;
// bb1.addPoint(bb2.min());
// bb1.addPoint(bb2.max());
// CityGenerator::planetify<PFP>(map, position, 100.0f, bb1);
// CityGenerator::planetify<PFP>(mapScenary, positionScenary, 100.0f, bb1);
......@@ -183,7 +183,7 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
Algo::Modelisation::TwoNPlusOneSubdivision<PFP,PFP::TVEC3, VEC3>(map,position,nb);
markPedWay();
scale(5.0f);
scale(20.0f);
}
break;
}
......@@ -536,13 +536,11 @@ void EnvMap::pushObstacleInCells(Obstacle * o)// réenregistre l'obstacle en que
if (mo != NULL)
{
int n = o->index;
VEC3 p1 = mo->vertices[n];
VEC3 p2 = mo->vertices[(n+1)%(mo->nbVertices)];
Dart d1=NIL;
Dart d2=NIL;
std::vector<Dart> memo;
memo = mo->getMemoCross(p1,p2,d1);
memo = mo->getMemoCross(o->p1,o->p2,d1);
d2=mo->registering_part->d;
if(map.sameFace(d1,d2))
......@@ -559,8 +557,6 @@ void EnvMap::pushObstacleInCells(Obstacle * o)// réenregistre l'obstacle en que
void EnvMap::popAndPushObstacleInCells(Obstacle* o, int n)// maj de l'enregistrement
{
MovingObstacle * mo = o->mo;
VEC3 p1 = mo->vertices[n];
VEC3 p2 = mo->vertices[(n+1)%mo->nbVertices];
Dart d1=NIL;
Dart d2=NIL;
......@@ -571,7 +567,7 @@ void EnvMap::popAndPushObstacleInCells(Obstacle* o, int n)// maj de l'enregistre
// if(p1->crossCell != CGoGN::Algo::MovingObjects::NO_CROSS
// || p2->crossCell != CGoGN::Algo::MovingObjects::NO_CROSS)
// {
memo = mo->getMemoCross(p1,p2,d1);
memo = mo->getMemoCross(o->p1,o->p2,d1);
d2=mo->registering_part->d;
// memo.sort();
// modif=true;
......@@ -720,7 +716,8 @@ void EnvMap::refine()
subdivisable = sf.second ;
else
{
float minSizeSq = minCellSize * minCellSize ; // diametre de vision de l'agent au carré
// float minSizeSq = minCellSize * minCellSize ; // diametre de vision de l'agent au carré
float minSizeSq = Agent::neighborDistSq_;
fLevel = map.faceLevel(old) ;
map.setCurrentLevel(fLevel) ;
......
#include "moving_mesh.h"
#include "Algo/Render/GL1/map_glRender.h"
MovingMesh::MovingMesh(EnvMap * envMap, Dart d, std::string filename):
MovingMesh::MovingMesh(EnvMap& envMap, Dart d, std::string filename):
motherMap(envMap.map),
motherPosition(envMap.position),
constrainedV(map)
{
std::vector<std::string> attrNames ;
......@@ -12,13 +15,19 @@ constrainedV(map)
position = map.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
normal = map.addAttribute<VEC3, VERTEX>("normal");
scale(2.5f);
scale(4.0f);
// scale(2.5f);
// scale(0.5f);
VEC3 v = Algo::Geometry::faceCentroid<PFP>(motherMap, d, motherPosition) ;
translate(v);
TraversorV<PFP::MAP> tv(map);
std::vector<Dart> obstDarts;
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
{
obstDarts.push_back(d);
obstDarts.push_back(dd);
}
smg = new ShapeMatchingQuadratic<PFP>(map,position,obstDarts,0.5f);
......@@ -30,6 +39,24 @@ void MovingMesh::linkWithObstacle(MovingObstacle * mo)
this->mo = mo;
}
void MovingMesh::transform(Geom::Matrix44f m)
{
TraversorV<PFP::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] = Geom::transform(position[d],m);
}
}
void MovingMesh::translate(VEC3 v)
{
TraversorV<PFP::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] += v;
}
}
void MovingMesh::scale(float val)
{
TraversorV<PFP::MAP> tv(map);
......@@ -99,28 +126,36 @@ void MovingMesh::animate()
}
}
std::vector<VEC3> MovingMesh::computeProjectedPointSet()
void MovingMesh::draw()
{
std::vector<VEC3> res;
return res;
glColor3f(0,1,0);
Algo::Render::GL1::renderTriQuadPoly<PFP>(map, Algo::Render::GL1::LINE,
1.0, position,
normal) ;
}
double jarvisFindAngle(VEC3 v1, VEC3 v2)
std::vector<VEC3> MovingMesh::computeProjectedPointSet(float maxHeight)
{
double deltaX=(double)(v2[0]-v1[0]);
double deltaY=(double)(v2[1]-v1[1]);
double angle;
std::vector<VEC3> res;
if (deltaX==0 && deltaY==0)
return 0;
TraversorV<PFP::MAP> tv(map);
for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
{
if(position[dd][2]<maxHeight)
res.push_back(position[dd]);
}
angle=std::atan2(deltaY,deltaX)*57.295779513082;
res = jarvisConvexHull(res);
res.pop_back();
if (angle < 0)
angle += 360.;
Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(motherMap, motherMap.begin(), motherPosition);
for(unsigned int i = 0; i < res.size() ; ++i)
{
VEC3& v = res[i];
pl.project(v);
}
return angle;
return res;
}
std::vector<VEC3> MovingMesh::jarvisConvexHull(std::vector<VEC3> pointSet)
......@@ -128,66 +163,51 @@ std::vector<VEC3> MovingMesh::jarvisConvexHull(std::vector<VEC3> pointSet)
assert(pointSet.size()>2);
std::vector<unsigned int> convHull;
int maxAngle=0, minAngle=0;
unsigned int minPoint=0, maxPoint=0;
unsigned int cP; //currPoint
for(unsigned int i=1; i<pointSet.size(); ++i)
if(pointSet[i][1]>pointSet[maxPoint][1])
maxPoint=i;
unsigned int minPoint=0;
unsigned int curr;
for(unsigned int i=1; i<pointSet.size(); ++i) //FOR ALL POINTS IN THE SET, FIND MIN POINT
if(pointSet[i][1]<pointSet[maxPoint][1])
if(pointSet[i][1]>pointSet[minPoint][1])
minPoint=i;
convHull.push_back(minPoint);
cP =minPoint;
while(cP!=maxPoint) //build left hand side
{
maxAngle=cP;
for(unsigned int i=0; i<pointSet.size(); ++i) //LOOP FOR ALL POINTS IN THE SET, FIND POINT WITH LOWEST RELATIVE ANGLE
{
if ((i==maxPoint || std::find(convHull.begin(), convHull.end(), i)==convHull.end())
&& jarvisFindAngle(pointSet[cP],pointSet[maxAngle]) < jarvisFindAngle(pointSet[cP],pointSet[i])
&& jarvisFindAngle(pointSet[cP],pointSet[i])<=270)
{
maxAngle=i;
}
}
cP=maxAngle;
convHull.push_back(cP); //add point to final perimeter list
}
cP=minPoint;
while(cP!=maxPoint) //build right hand side
{
minAngle=maxPoint;
for(unsigned int i=0; i<pointSet.size(); ++i) //LOOP FOR ALL POINTS IN THE SET, FIND POINT WITH GREATEST RELATIVE ANGLE
{
if ((i==maxPoint || std::find(convHull.begin(), convHull.end(), i)==convHull.end())
&& jarvisFindAngle(pointSet[cP],pointSet[minAngle])> jarvisFindAngle(pointSet[cP],pointSet[i])
&& jarvisFindAngle(pointSet[cP],pointSet[i])>=90)
{
minAngle=i;
}
}
cP=minAngle;
convHull.push_back(cP); //add point to final perimeter list
}
curr = minPoint;
do {
unsigned int i=0;
bool trouve=false;
for( ;!trouve && i<pointSet.size(); ++i)
{
if((pointSet[i][0] != pointSet[curr][0]) || (pointSet[i][1] != pointSet[curr][1]))
{
bool left=true;
for(unsigned int j=0;left && j<pointSet.size(); ++j)
{
if(Geom::testOrientation2D(pointSet[j],pointSet[curr],pointSet[i])==Geom::RIGHT)
{
left=false;
}
}
if(left)
trouve = true;
}
}
if(trouve)
{
curr = i-1;
convHull.push_back(curr);