Commit 7f81911e authored by Thomas Jund's avatar Thomas Jund

SA2.5 pr agents ponctuel ok, pb sur les agents poly

parent 6f108282
......@@ -12,12 +12,19 @@
//#define EXPORTING_AGENT
//#define EXPORTING_OBJ
#ifdef SECURED
#include "Algo/MovingObjects/particle_cell_2D_secured.h"
#else
#ifdef TWO_AND_HALF_DIM
#include "Algo/MovingObjects/particle_cell_2DandHalf.h"
#else
#include "Algo/MovingObjects/particle_cell_2D.h"
#endif
#endif
#ifdef EXPORTING_AGENT
#include "Utils/vbo.h"
#include "Utils/Shaders/shaderSimpleColor.h"
......@@ -39,6 +46,8 @@ public:
Agent(Simulator* sim, const VEC3& position, const VEC3& goals, Dart d) ;
Agent(Simulator* sim, const VEC3& position, const VEC3& goals) ;
static void rotate(const VEC3& planeN1, const VEC3& planeN2, VEC3& project);
void init(const VEC3& start, const VEC3& goal);
void initGL();
void draw();
......@@ -101,7 +110,12 @@ public:
#ifdef SECURED
CGoGN::Algo::Surface::MovingObjects::ParticleCell2DSecured<PFP> part_ ;
#else
#ifdef TWO_AND_HALF_DIM
CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP> part_ ;
#else
CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP> part_ ;
#endif
#endif
#endif
......@@ -114,6 +128,8 @@ public:
MovingObstacle **movingObstacles_;
int nb_mos;
static VEC3 xyPlane;
static unsigned int maxNeighbors_ ;
static unsigned int maxMovingObstacles_;
......
......@@ -40,8 +40,10 @@ Algo::Surface::Modelisation::Polyhedron<PFP> generateGrid(EnvMap& envMap)
{
unsigned int nx = envMap.geometry.size(0) / envMap.maxCellSize ;
unsigned int ny = envMap.geometry.size(1) / envMap.maxCellSize ;
if (nx < 1) nx = 1 ;
if (ny < 1) ny = 1 ;
if (nx < 1)
nx = 1 ;
if (ny < 1)
ny = 1 ;
std::cout << " - Generate Grid : " << nx << " x " << ny << std::endl ;
......@@ -607,15 +609,26 @@ void generatePlanet(EnvMap& envMap)
unsigned int nx = envMap.geometry.size(0) / envMap.maxCellSize ;
unsigned int ny = envMap.geometry.size(1) / envMap.maxCellSize ;
if (nx < 1)
nx = 1 ;
nx = 20 ;
if (ny < 1)
ny = 1 ;
ny = 20 ;
std::cout << "nx : " << nx << " ny " << ny << std::endl;
Algo::Surface::Modelisation::Polyhedron<PFP> prim(envMap.map, envMap.position) ;
prim.cylinder_topo(nx, ny, true, true) ;
double xRadius = envMap.geometry.size(0) / 2 * M_PI;
double yRadius = envMap.geometry.size(1) / 2 * M_PI ;
unsigned int count = 0;
for(Dart d = envMap.map.begin() ; d != envMap.map.end() ; envMap.map.next(d))
count++;
std::cout << "count : " << count << std::endl;
double xRadius = envMap.geometry.size(0);
double yRadius = envMap.geometry.size(1);
std::cout << "radius : " << xRadius+yRadius << std::endl;
prim.embedSphere((xRadius+yRadius)/2.0f) ;
}
......
......@@ -33,6 +33,7 @@ class ArticulatedObstacle;
#include "pfp.h"
//#define EXPORTING3
#define TWO_AND_HALF_DIM
#ifdef EXPORTING3
#include "Utils/Shaders/shaderPhongTexture.h"
......
......@@ -6,7 +6,13 @@
#include "utils.h"
#include "env_map.h"
#include <set>
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
#ifdef TWO_AND_HALF_DIM
#include "Algo/MovingObjects/particle_cell_2DandHalf_memo.h"
#else
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
#endif
#define EXPORTING_BOXES
......@@ -55,7 +61,11 @@ public:
unsigned int nbVertices;
#ifdef TWO_AND_HALF_DIM
CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>* * parts_;
#else
CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>* * parts_;
#endif
PFP::MAP map;
VertexAttribute<VEC3> position;
......
......@@ -96,6 +96,8 @@ public:
void setupCityScenario(int nbLines, int nbRank) ;
void setupScenario(unsigned int nbMaxAgent, bool pedWay=false) ;
void setupPlanetScenario(unsigned int nbAgents, unsigned int nbObstacles);
void addMovingObstacles(unsigned int nb);
void addMovingObstacle(Dart d, unsigned int obstType=0);
......
......@@ -11,10 +11,12 @@
#include "Geometry/frame.h"
#include "Utils/colorMaps.h"
VEC3 Agent::xyPlane = VEC3(0,0,1);
unsigned int Agent::maxNeighbors_ = 10 ;
unsigned int Agent::maxMovingObstacles_ = 20;
//float Agent::averageMaxSpeed_ = 2.0f ;
float Agent::averageMaxSpeed_ = 20.0f ;
float Agent::averageMaxSpeed_ = 2.0f ;
// float Agent::averageMaxSpeed_ = 20.0f ;
// float Agent::neighborDist_ = 10.0f ;
float Agent::neighborDist_ = 20.0f ;
float Agent::neighborDistSq_ = neighborDist_ * neighborDist_ ;
......@@ -69,6 +71,17 @@ Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal) :
init(start,goal);
}
void Agent::rotate(const VEC3& planeN1, const VEC3& planeN2, VEC3& project)
{
// rotate from face plane to (x,y) plane
float angle = Geom::angle(planeN1, planeN2) ;
if(angle > 0.0f)
{
VEC3 axis = planeN1 ^ planeN2 ;
project = Geom::rotate(axis, angle, project) ;
}
}
void Agent::init(const VEC3& start, const VEC3& goal)
{
......@@ -96,6 +109,7 @@ void Agent::init(const VEC3& start, const VEC3& goal)
goals_.clear() ;
goals_.push_back(goal) ;
goals_.push_back(start) ;
float ratio = (80.0f + rand() % 20) / 100.0f ;
maxSpeed_ = averageMaxSpeed_ * ratio ; // from 80% to 100% of averageMaxSpeed_
// color1 = 1.0f * ratio ; // red = high speed agents
......@@ -109,7 +123,9 @@ void Agent::init(const VEC3& start, const VEC3& goal)
// color1=0;
// color2 = 1.0f;
// }
for (unsigned int i=0 ; i<4 ; ++i) meanVelocity_[i].set(0) ;
for (unsigned int i=0 ; i<4 ; ++i)
meanVelocity_[i].set(0) ;
agentNeighbors_.reserve(maxNeighbors_ * 2) ;
obstacleNeighbors_.reserve(maxNeighbors_ * 2) ;
movingObstacleNeighbors_.reserve(maxNeighbors_ * 2) ;
......
......@@ -195,6 +195,9 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
scale(20.0f);
}
break;
case 6:
CityGenerator::generatePlanet<PFP>(*this);
break;
}
// CityGenerator::simplifyFreeSpace<PFP>(map, position, obstacleMark, buildingMark);
......@@ -350,75 +353,6 @@ void EnvMap::initGL()
}
std::cout << "bb " << bbTest.min() << " & " << bbTest.max() << std::endl;
// unsigned int i =0;
// for(std::vector<PFP::MAP * >::iterator it = m_map_Export.begin() ; it != m_map_Export.end() ; ++it, ++i)
// {
//
// CityGenerator::planetify<PFP>(**it, position_nmap[i], 2000.0f, bbTest);
// }
// m_map_Export = new PFP2::MAP();
//
// std::vector<std::string> attrNames ;
// m_obj_Export = new Algo::Surface::Import::OBJModel<PFP2>(m_map_Export);
// m_obj_Export->import("./meshRessources/cityTex/Building11.obj",attrNames);
//
// position_Export = m_map_Export.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
// TraversorV<PFP2::MAP> tV(m_map_Export);
//
// VEC3 bary(0);
// unsigned int count = 0;
// for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
// {
// bary += position_Export[d];
// count++;
// }
// bary /= float(count);
//
// for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
// {
//// position_Export[d] -= bary;
// position_Export[d] *= 100.0f;
// std::cout << position_Export[d] << std::endl;
// position_Export[d] += VEC3(2000,0,0);
// std::cout << position_Export[d] << std::endl;
// }
//
// m_texcoordVBO_Export = new Utils::VBO();
// m_positionVBO_Export = new Utils::VBO();
// m_normalVBO_Export = new Utils::VBO();
//
// m_texture_Export = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
//
// if (m_texture_Export->load("./meshRessources/cityTex/AO_Buildings11.png"))
// m_texture_Export->update();
// else
// std::cout << "problem : loading texture" << std::endl;
//
// m_texture_Export->setWrapping(GL_CLAMP_TO_EDGE);
//
// m_shaderTex_Export = new ShaderCustomTex();
// m_shaderTex_Export->setAttributePosition(m_positionVBO_Export);
// m_shaderTex_Export->setAttributeTexCoord(m_texcoordVBO_Export);
// m_shaderTex_Export->setTextureUnit(GL_TEXTURE0);
// m_shaderTex_Export->setTexture(m_texture_Export);
//
// glEnable(GL_TEXTURE_2D);
//
// m_map_Export.setBrowser(NULL);
//
// if (!m_obj_Export->hasNormals())
// {
// normal_Export = m_map_Export.getAttribute<VEC3, VERTEX>("normal") ;
// if(!normal_Export.isValid())
// normal_Export = m_map_Export.addAttribute<VEC3, VERTEX>("normal") ;
//
// Algo::Surface::Geometry::computeNormalVertices<PFP2>(m_map_Export, m_obj_Export->m_positions, normal_Export) ;
// m_obj_Export->setNormalAttribute(normal_Export);
// }
//
// m_nbIndice_Export = m_obj_Export->createSimpleVBO_PTN(m_positionVBO_Export,m_texcoordVBO_Export,m_normalVBO_Export);
#endif
}
......
......@@ -143,7 +143,12 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
if(dInside==NIL)
dInside = sim_->envMap_.getBelongingCell(pos[0]);
#ifdef TWO_AND_HALF_DIM
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>*[nbVertices];
#else
parts_ = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>*[nbVertices];
#endif
obstacles_ = new Obstacle*[nbVertices];
belonging_cells = new std::vector<Dart>[nbVertices];
neighbor_cells = new std::vector<Dart>[nbVertices];
......@@ -161,15 +166,20 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
}
for (unsigned int i = 0; i < nbVertices; ++i)
{
Dart d = sim_->envMap_.getBelongingCell(pos[i]);
CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>* part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
parts_[i] = part;
center += pos[i];
{
Dart d = sim_->envMap_.getBelongingCell(pos[i]);
#ifdef TWO_AND_HALF_DIM
CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>* part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalf<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
if(i==0)
dDir = d;
}
#else
CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>* part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2D<PFP>(sim_->envMap_.map, d, pos[i], sim_->envMap_.position);
#endif
parts_[i] = part;
center += pos[i];
if(i==0)
dDir = d;
}
center /= nbVertices;
front=(pos[0] + pos[1]) / 2;
......@@ -225,6 +235,7 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
//extrude face to build a cage
// compute edgeLength for mass-spring
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, -10.0f) ;
// Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, 0.0f) ;
map.fillHole(groundFace);
groundFace = map.phi2(groundFace);
......@@ -836,7 +847,11 @@ void MovingObstacle::update()
std::vector<Dart> MovingObstacle::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1, Dart& d2)
{
#ifdef TWO_AND_HALF_DIM
CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalfMemo<PFP> * registering_part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DAndHalfMemo<PFP>(sim_->envMap_.map, d1,pos,sim_->envMap_.position);
#else
CGoGN::Algo::Surface::MovingObjects::ParticleCell2DMemo<PFP> * registering_part = new CGoGN::Algo::Surface::MovingObjects::ParticleCell2DMemo<PFP>(sim_->envMap_.map, d1,pos,sim_->envMap_.position);
#endif
std::vector<Dart> result =(registering_part->move(dest));
d2=registering_part->d;
// CGoGNout<<"d1 : "<< *d1<<"|| d2 : "<< *d2<<"|| start : "<< pos<<"|| stop : "<< dest<<CGoGNendl;
......
......@@ -68,6 +68,16 @@ void Simulator::init( float dimension, unsigned int nbAgent, unsigned int nbObst
// addPathToObstacles();
addPathsToAgents();
break;
case 6:
#ifdef TWO_AND_HALF_DIM
envMap_.init(config,200.0,200.0, minSize, 400.0f);
setupPlanetScenario(nbAgent,nbObst);
addMovingObstacles(nbObst);
addPathToObstacles();
#else
std::cout << "Agents not in 2.5D mode" << std::endl;
#endif
break;
default:
std::cout << "Unknown scenario !" << std::endl ;
exit(1) ;
......@@ -640,6 +650,64 @@ void Simulator::setupScenario(unsigned int nbMaxAgent, bool pedWay)
swapAgentsGoals() ;
}
void Simulator::setupPlanetScenario(unsigned int nbAgents, unsigned int nbObstacles)
{
/*
* Add agents, specifying their start position, and store their goals on the
* opposite side of the environment.
*/
Dart d = envMap_.map.begin();
CellMarker<FACE> filled(envMap_.map);
unsigned int nbx = 1;
unsigned int nby = 1;
unsigned int bMax = nbAgents / (nbx*nby);
for (unsigned int i = 0; i < bMax && d != envMap_.map.end(); ++i)
{
bool found = false;
VEC3 pos;
Dart dCell;
while(!found && d != envMap_.map.end())
{
if(!filled.isMarked(d) && !envMap_.buildingMark.isMarked(d))
{
filled.mark(d);
pos = Algo::Surface::Geometry::faceCentroid<PFP>(envMap_.map, d, envMap_.position);
dCell = d;
found = true;
}
envMap_.map.next(d);
}
if(found)
{
float ecart = 3.0f;
Geom::Plane3D<PFP::REAL> pl(Algo::Surface::Geometry::faceNormal<PFP>(envMap_.map, dCell, envMap_.position), 0.0f);
VEC3 posinit = VEC3(pos[0] - (float(nbx)/2.0f * ecart), pos[1] - (float(nby)/2.0f * ecart), pos[2]);
for(unsigned int curx = 0; curx < nbx; ++curx)
{
for(unsigned int cury = 0; cury < nby; ++cury)
{
VEC3 displ(ecart * curx, ecart * cury, 0.0f);
Agent::rotate(Agent::xyPlane, pl.normal(), displ);
VEC3 posagent = posinit + displ;
// VEC3 posagent = posinit + VEC3(ecart * curx, ecart * cury, 0.0f);
addAgent(posagent,-1.0f * posagent, dCell);
// agents_.back()->goals_.push_back(posagent);
// agents_.back()->goals_.push_back(VEC3(0,0,0));
// agents_.back()->goals_.push_back(-1.0f * posagent);
agents_.back()->curGoal_ = 1;
}
}
}
}
std::cout << "nb agents : " << agents_.size() << std::endl;
swapAgentsGoals();
}
void Simulator::addMovingObstacles(unsigned int nb)
{
TraversorF<PFP::MAP> tF(envMap_.map);
......@@ -665,7 +733,7 @@ void Simulator::addMovingObstacles(unsigned int nb)
}
if (found)
addMovingObstacle(dCell,1) ;
addMovingObstacle(dCell,0) ;
}
}
......@@ -685,10 +753,31 @@ void Simulator::addMovingObstacle(Dart d, unsigned int obstType)
VEC3 xSide (2.0f,0.0f,0.0f);
VEC3 ySide (0.0f,5.0f,0.0f);
#ifdef TWO_AND_HALF_DIM
Geom::Plane3D<PFP::REAL> pl(Algo::Surface::Geometry::faceNormal<PFP>(envMap_.map, d, envMap_.position), 0.0f);
VEC3 displ = -xSide-ySide;
Agent::rotate(Agent::xyPlane, pl.normal(), displ);
vPos.push_back(start + displ);
displ = xSide-ySide;
Agent::rotate(Agent::xyPlane, pl.normal(), displ);
vPos.push_back(start + displ);
displ = xSide+ySide;
Agent::rotate(Agent::xyPlane, pl.normal(), displ);
vPos.push_back(start + displ);
displ = ySide-xSide;
Agent::rotate(Agent::xyPlane, pl.normal(), displ);
vPos.push_back(start + displ);
#else
vPos.push_back(start-xSide-ySide);
vPos.push_back(start+xSide-ySide);
vPos.push_back(start+xSide+ySide);
vPos.push_back(start-xSide+ySide);
#endif
}
break;
case 1 :
......@@ -715,7 +804,7 @@ void Simulator::addMovingObstacle(Dart d, unsigned int obstType)
return;
}
bool orientAccordingToFace=true;
bool orientAccordingToFace=false;
if(mm!=NULL && orientAccordingToFace)
{
while(envMap_.pedWayMark.isMarked(envMap_.map.phi2(d)))
......
......@@ -125,9 +125,15 @@ void SocialAgents::cb_initGL()
float tailleX = bb.size(0) ;
float tailleY = bb.size(1) ;
float tailleZ = bb.size(2) ;
float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ)/5.0f ;
float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;
if(simulator.config<6)
gWidthObj /= 5.0f;
setParamObject(gWidthObj, gPosObj.data()) ;
std::cout << "Bb " << bb << std::endl;
// choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment