Commit aed8ba52 authored by Arash HABIBI's avatar Arash HABIBI

scenario3.ok

parent f5ff2aab
......@@ -10,7 +10,7 @@
#define SECURED
//#define EXPORTING_AGENT
// #define EXPORTING_OBJ
#define EXPORTING_OBJ
#ifdef SECURED
......@@ -156,7 +156,7 @@ public:
VEC3 velocity_ ;
VEC3 newVelocity_ ;
VEC3 prefVelocity_ ;
VEC3 meanVelocity_[4] ;
VEC3 meanVelocity_[50] ;
VEC3 meanDirection_ ;
Simulator* sim_;
......
......@@ -32,7 +32,7 @@ class ArticulatedObstacle;
#include "pfp.h"
//#define EXPORTING3
#define EXPORTING3
//#define TWO_AND_HALF_DIM
#ifdef EXPORTING3
......
......@@ -18,7 +18,7 @@
using namespace std;
// #define EXPORTING2
#define EXPORTING2
class MovingMesh
{
......
......@@ -14,7 +14,7 @@
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
#endif
#define EXPORTING_BOXES
// #define EXPORTING_BOXES
#ifdef EXPORTING_BOXES
#include "Algo/Render/GL2/mapRender.h"
......
......@@ -24,6 +24,7 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <sys/time.h>
#include "Utils/Qt/qtQGLV.h"
......@@ -56,7 +57,7 @@
//#define EXPORTING
//#define ONERING
#define SHADOWSHELL
//#define SHADOWSHELL
using namespace CGoGN ;
......@@ -169,6 +170,18 @@ public:
int m_renderStyle;
//////
// ARASH : camera input file
std::ifstream cam_input_file;
bool cif_exists;
int cif_begin, cif_end;
VEC3 *cif_lookfrom;
VEC3 *cif_lookat;
VEC3 *cif_upvector;
void readCameraInputFile(char *filename);
std::ofstream cam_output_file;
Geom::BoundingBox<PFP::VEC3> bb ;
Utils::QT::uiDockInterface dock ;
......
......@@ -26,7 +26,7 @@ float Agent::radius_ = 3.0f ;
float Agent::timeHorizon_ = 10.0f ;
//float Agent::timeHorizon_ = 100.0f ;
float Agent::timeHorizonObst_ = 10.0f ;
float Agent::range_ = 2*timeHorizonObst_ * averageMaxSpeed_ + radius_ ;
float Agent::range_ = 4*timeHorizonObst_ * averageMaxSpeed_ + radius_ ;
float Agent::rangeSq_ = range_ * range_ ;
unsigned int Agent::cptAgent = 0 ;
......@@ -505,11 +505,11 @@ void Agent::update()
#endif
meanDirection_.set(0) ;
for (unsigned int i=0 ; i<4 ; ++i) {
for (unsigned int i=0 ; i<50 ; ++i) {
meanDirection_ += meanVelocity_[i] ;
meanVelocity_[i] = meanVelocity_[(i+1)%4] ;
meanVelocity_[i] = meanVelocity_[(i+1)%50] ;
}
meanVelocity_[3] = velocity_ ;
meanVelocity_[49] = velocity_ ;
meanDirection_.normalize() ;
}
......@@ -745,7 +745,7 @@ void Agent::computeNewVelocity()
{
// The objective is to compute the sum of forces exerted on the agent.
double collision_softening_factor;
float ag_ambient_damping = 10.0;
float ag_ambient_damping = 50.0;
// double mass_var = 0.95;
// double average_mass = 1.0;
......@@ -759,7 +759,7 @@ void Agent::computeNewVelocity()
double rand = 2.0*drand48()-1.0; // compris entre -1 et 1
// double ag_mass = average_mass*(1 + rand*mass_var); // valeurs uniformement réparties entre min et max
double ag_mass = 50.0;
double ag_mass = 200.0;
/*
rand = 2.0*drand48()-1.0; // compris entre -1 et 1
radius_ = average_radius + rand*radius_var; // valeurs uniformement réparties entre min et max
......@@ -799,7 +799,7 @@ void Agent::computeNewVelocity()
obst_radius_infl = 100.; // scenario 0
else
obst_radius_infl = 40.; // scenario 1 et 3
float force_value;
float force_value=0.0;
int nobst=0;
#define ARASH
......@@ -874,49 +874,44 @@ void Agent::computeNewVelocity()
// double fixed_obst_stiffness = 50000.0; // agent-obstacle interaction stiffness
double fixed_obst_stiffness = 50000.0; // agent-obstacle interaction stiffness
// double fixed_obst_damping = 1.0; // agent-obstacle interaction damping
int fixed_obst_power = 1; // the power to which elevate the agent-obstacle distance
int fixed_obst_power = 4.0; // the power to which elevate the agent-obstacle distance
Obstacle* fixed_obst ;
for(std::vector<std::pair<float, Obstacle*> >::iterator it = obstacleNeighbors_.begin() ;
it != obstacleNeighbors_.end() ;
++it)
{
double dist = it->first;
// cerr << "nobst=" << nobst << "dist=" << dist << endl;
// double effective_range = 50*range_;
double effective_range = 10*range_;
float force_value=0.0;
if(dist < effective_range)
{
collision_softening_factor = pow(1-dist/effective_range,fixed_obst_power);
force_value = fixed_obst_stiffness*collision_softening_factor*(effective_range-dist);
}
fixed_obst=it->second ;
if(fixed_obst->mo!=NULL)
cerr << "Collision avec limace !!!" << endl;
VEC3 p1=fixed_obst->p1 ;
VEC3 p2=fixed_obst->p2 ;
vec=p2-p1;
vec.normalize();
VEC3 obst_vec=p2-p1;
obst_vec.normalize();
norm.zero();
norm[0]=obst_vec[1] ;
norm[1]=-obst_vec[0] ;
norm[0]=vec[1] ;
norm[1]=-vec[0] ;
forces += force_value * norm;
// cerr << "obstacles fixes : nobst=" << nobst << " dist=" << dist << " force=" << force_value*norm << endl;
double dist = it->first;
// double effective_range = 10*range_*2*drand48();
// double effective_range = 10*range_;
double effective_range = radius_*(1+10*drand48());
if(dist<effective_range)
{
collision_softening_factor = pow(1-dist/effective_range,fixed_obst_power);
float force_value = fixed_obst_stiffness*collision_softening_factor*(effective_range-dist);
forces += force_value * norm;
}
nobst++;
}
//----- forces dues à la répulsion des autres agents -------
double ag_stiffness = 200.0; // agent-agent interaction stiffness
double ag_stiffness = 50.0; // agent-agent interaction stiffness
double ag_damping = 1.0; // agent-agent interaction damping
// double ag_power = 1; // the power to which elevate the agent-agent distance
double ag_power = 4.0; // the power to which elevate the agent-agent distance
rand = 2.0*drand48()-1.0; // compris entre -1 et 1
double radius_var = 0.5;
rand = drand48(); // aleatoire compris entre 0 et 1
double radius_var = 8;
double ag_phys_radius_coef = 4.0*(1 + rand*radius_var); // valeurs uniformement réparties entre min et max
unsigned int nbA = 0 ;
......@@ -946,8 +941,7 @@ void Agent::computeNewVelocity()
if(dist < combinedRadius)
{
// collision_softening_factor = pow(1-dist/combinedRadius,ag_power);
collision_softening_factor = 1;
collision_softening_factor = pow(1-dist/combinedRadius,ag_power);
float force_value = - ag_stiffness*collision_softening_factor*(combinedRadius-dist)
- ag_damping * (dist - previous_dist) / sim_->timeStep_;
......
......@@ -234,7 +234,7 @@ void EnvMap::initGL()
std::vector<std::string> filenames;
std::vector<std::string> texturenames;
std::string dir("./meshRessources/cityTex/");
std::string dir("./meshRessources/scenario3/");
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL)
......@@ -289,8 +289,9 @@ void EnvMap::initGL()
TraversorV<PFP2::MAP> tV(*nmap);
for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
{
position_Export[d] *= 100.0f;
position_Export[d] += VEC3(2000,0,0);
// pour scenario5
//position_Export[d] *= 100.0f;
//position_Export[d] += VEC3(2000,0,0);
}
......
......@@ -665,9 +665,20 @@ void Simulator::setupScenario(unsigned int nbMaxAgent, bool pedWay)
*/
TraversorF<PFP::MAP> tF(envMap_.map);
Dart d = tF.begin() ;
//-----------------------
#define SCENARIO3
#if defined SCENARIO3
unsigned int nbx = 5 ;
unsigned int nby = 5 ;
#elif defined SCENARIO5
unsigned int nbx = 2 ;
unsigned int nby = 2 ;
#else
unsigned int nbx = 1 ;
unsigned int nby = 1 ;
#endif
//-----------------------
unsigned int bMax = nbx * nby > 0 ? nbMaxAgent / (nbx * nby) : nbMaxAgent ;
......
......@@ -216,6 +216,9 @@ void SocialAgents::cb_initGL()
registerShader(m_simpleColorShader);
registerShader(m_sprite);
qglviewer::Camera* cam = getQGLWidget()->camera();
cam->setSceneRadius(10000);
initRendering();
}
......@@ -766,9 +769,10 @@ void SocialAgents::cb_redraw()
simulator.movingObstacles_[i]->draw(drawObstPath);
#endif
}
// Commente par Arash
// for (std::vector<MovingMesh*>::iterator it = simulator.movingMeshes_.begin() ; it != simulator.movingMeshes_.end() ; ++it)
// (*it)->draw();
// Commente par Arash (Pourquoi ?)
for (std::vector<MovingMesh*>::iterator it = simulator.movingMeshes_.begin() ; it != simulator.movingMeshes_.end() ; ++it)
(*it)->draw();
}
......@@ -1016,13 +1020,42 @@ void SocialAgents::animate()
// long seconds, nseconds ;
nbIterations++ ;
if(cif_exists)
{
qglviewer::Vec lookfrom, lookat, upvector;
qglviewer::Camera* cam = getQGLWidget()->camera();
if(nbIterations<cif_begin)
{
lookfrom.setValue(cif_lookfrom[0][0],cif_lookfrom[0][1],cif_lookfrom[0][2]);
lookat. setValue(cif_lookat [0][0],cif_lookat [0][1],cif_lookat [0][2]);
upvector.setValue(cif_upvector[0][0],cif_upvector[0][1],cif_upvector[0][2]);
}
else if((nbIterations>=cif_begin)&&(nbIterations<cif_end))
{
lookfrom.setValue(cif_lookfrom[nbIterations-cif_begin][0],cif_lookfrom[nbIterations-cif_begin][1],cif_lookfrom[nbIterations-cif_begin][2]);
lookat. setValue(cif_lookat [nbIterations-cif_begin][0],cif_lookat [nbIterations-cif_begin][1],cif_lookat [nbIterations-cif_begin][2]);
upvector.setValue(cif_upvector[nbIterations-cif_begin][0],cif_upvector[nbIterations-cif_begin][1],cif_upvector[nbIterations-cif_begin][2]);
}
else
{
lookfrom.setValue(cif_lookfrom[cif_end-cif_begin][0],cif_lookfrom[cif_end-cif_begin][1],cif_lookfrom[cif_end-cif_begin][2]);
lookat. setValue(cif_lookat [cif_end-cif_begin][0],cif_lookat [cif_end-cif_begin][1],cif_lookat [cif_end-cif_begin][2]);
upvector.setValue(cif_upvector[cif_end-cif_begin][0],cif_upvector[cif_end-cif_begin][1],cif_upvector[cif_end-cif_begin][2]);
exit(0);
}
cam->setPosition(lookfrom);
cam->lookAt(lookat);
cam->setUpVector(upvector,true);
}
if (maxIterations > 0 && nbIterations > maxIterations)
{
// std::cout << "t : " << simulator.globalTime_ << std::endl ;
timer->stop() ;
if (filename != NULL)
{
if (percent) filename<<"_percent";
std::stringstream datas;
......@@ -1034,7 +1067,6 @@ void SocialAgents::animate()
string data = datas.str();
string gnuplot=gnuplots.str();
float upAgent=((simulator.time_agent)/1000000000.0f);
float upObst = ((simulator.time_obstacle)/1000000000.0f);
float behaviour = ((simulator.time_behave)/1000000000.0f);
......@@ -1049,8 +1081,6 @@ void SocialAgents::animate()
upObst = (upObst/sum)*100;
behaviour = (behaviour/sum)*100;
rendu =(rendu/sum)*100;
}
CGoGNout<<"temps total : "<<(time_update/1000000000.0f)<< CGoGNendl;
ofstream fichier(data.c_str(), ios::out | ios::trunc); //déclaration du flux et ouverture du fichier
......@@ -1141,10 +1171,10 @@ void SocialAgents::animate()
#ifndef SPATIAL_HASHING
if (render_anim)
{
if(nbIterations%4==0)
{
getQGLWidget()->resize(800,600);
// getQGLWidget()->resize(800,600);
getQGLWidget()->resize(1024,768);
updateGL() ;
// getQGLWidget()->setSnapshotQuality(100);
......@@ -1156,7 +1186,7 @@ void SocialAgents::animate()
// QString filename("./export/meshCercleBA" );
// QString filename("./export/meshCorridorBA" );
// QString filename("./export/oneRing" );
QString filename("./export/oneRingCercle" );
QString filename("./export/scenario3." );
filename.append((tmpNb.str()).c_str());
filename.append(".png");
// getQGLWidget()->setSnapshotFileName(filename);
......@@ -1813,6 +1843,7 @@ void SocialAgents::keyPressEvent(QKeyEvent *e)
std::string filename3("pedway.ply") ;
std::string filename4("buildingMap.ply") ;
std::string filename5("road.ply") ;
std::string filename6("road.obj") ;
MapBrowserSelector mbs(simulator.envMap_.map,SelectorCellMarked<FACE>(simulator.envMap_.pedWayMark));
simulator.envMap_.map.setBrowser(&mbs);
......@@ -1823,6 +1854,8 @@ void SocialAgents::keyPressEvent(QKeyEvent *e)
simulator.envMap_.map.setBrowser(&mbs2);
Algo::Surface::Export::exportPLY<PFP>(simulator.envMap_.map, simulator.envMap_.position,filename5.c_str(), false);
// Algo::Surface::Export::exportOBJ<PFP>(simulator.envMap_.map, simulator.envMap_.position,filename6.c_str());
// L'export OBJ ne semble pas marcher
simulator.envMap_.map.setBrowser(NULL);
......@@ -1830,6 +1863,19 @@ void SocialAgents::keyPressEvent(QKeyEvent *e)
Algo::Surface::Export::exportPLY<PFP>(simulator.envMap_.mapScenary, simulator.envMap_.positionScenary,filename4.c_str(), false);
break ;
}
case Qt::Key_G:
{
qglviewer::Camera* cam = getQGLWidget()->camera();
qglviewer::Vec lookat = cam->position() + 100*cam->viewDirection();
cam_output_file << nbIterations << " ";
cam_output_file << cam->position()[0] << " "<< cam->position()[1] << " "<< cam->position()[2] << " "
<< lookat[0] << " "<< lookat[1] << " "<< lookat[2] << " "
<< cam->upVector()[0] << " "<< cam->upVector()[1] << " "<< cam->upVector()[2] << endl;
break;
}
case Qt::Key_I:
{
getQGLWidget()->resize(800,600);
......@@ -1842,7 +1888,7 @@ void SocialAgents::keyPressEvent(QKeyEvent *e)
getQGLWidget()->setSnapshotCounter(++counter);
QString filename("./export/test" );
filename.append((tmpNb.str()).c_str());
filename.append((tmpNb.str()).c_str());
filename.append(".png");
// getQGLWidget()->setSnapshotFileName(filename);
// getQGLWidget()->setSnapshotFormat(QString("PNG"));
......@@ -1916,6 +1962,7 @@ void SocialAgents::keyPressEvent(QKeyEvent *e)
}
break;
}
case Qt::Key_5 :
{
FILE *fp ;
......@@ -1947,6 +1994,53 @@ void SocialAgents::keyPressEvent(QKeyEvent *e)
updateGL() ;
}
//---------------------------------------------------------
void SocialAgents::readCameraInputFile(char *filename)
{
std::string line, word;
// const char *c_line;
cif_exists=false;
cam_input_file.open(filename,std::ifstream::in);
if(cam_input_file.is_open())
{
cif_exists=true;
cam_input_file >> cif_begin;
cam_input_file >> cif_end;
int nb_steps=cif_end-cif_begin+1;
cif_lookfrom = new VEC3[nb_steps];
cif_lookat = new VEC3[nb_steps];
cif_upvector = new VEC3[nb_steps];
int i;
for(i=0;i<nb_steps;i++)
{
int j;
for(j=0;j<9;j++)
{
cam_input_file >> word;
std::istringstream iss(word);
switch(j)
{
case 0: iss >> cif_lookfrom[i][0]; break;
case 1: iss >> cif_lookfrom[i][1]; break;
case 2: iss >> cif_lookfrom[i][2]; break;
case 3: iss >> cif_lookat [i][0]; break;
case 4: iss >> cif_lookat [i][1]; break;
case 5: iss >> cif_lookat [i][2]; break;
case 6: iss >> cif_upvector[i][0]; break;
case 7: iss >> cif_upvector[i][1]; break;
case 8: iss >> cif_upvector[i][2]; break;
default : cerr << "Unexpected value for switch : " << j << endl; break;
}
}
}
cam_input_file.close();
}
}
/**********************************************************************************************
* MAIN FUNCTION *
**********************************************************************************************/
......@@ -1987,9 +2081,34 @@ int main(int argc, char** argv)
sa.setGeometry(0, 0, 1800, 1200) ;
sa.initGUI() ;
glewInit();
sa.cam_output_file.open("src/cam.out",std::ofstream::out);
sa.readCameraInputFile("src/cam.scn3.spline");
if(sa.cif_exists)
{
int i;
for(i=0;i<sa.cif_begin;i++)
{
sa.nbIterations = sa.cif_begin;
sa.simulator.doStep();
}
}
sa.show() ;
// if (argc > 1)
// sa.timer->start() ;
// Arash :
// S'il y a un cam input file, alors lire le premier
// entier N et faire marcher la simulation N fois.
// sa.readCameraInputFile("src/cam.scn3.spline");
// sa.cam_output_file.open("src/cam.out",std::ofstream::out);
// sa.cam_output_file("src/cam.out");
// int i;
// for(i=0;i<sa.cif_begin;i++)
// sa.animate();
return app.exec() ;
}
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