Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SocialAgents3D
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Pitiot
SocialAgents3D
Commits
aed8ba52
Commit
aed8ba52
authored
May 28, 2013
by
Arash HABIBI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scenario3.ok
parent
f5ff2aab
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
191 additions
and
53 deletions
+191
-53
include/agent.h
include/agent.h
+2
-2
include/env_map.h
include/env_map.h
+1
-1
include/moving_mesh.h
include/moving_mesh.h
+1
-1
include/moving_obstacle.h
include/moving_obstacle.h
+1
-1
include/viewer.h
include/viewer.h
+14
-1
src/agent.cpp
src/agent.cpp
+27
-33
src/env_map.cpp
src/env_map.cpp
+4
-3
src/simulator.cpp
src/simulator.cpp
+11
-0
src/viewer.cpp
src/viewer.cpp
+130
-11
No files found.
include/agent.h
View file @
aed8ba52
...
...
@@ -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_
;
...
...
include/env_map.h
View file @
aed8ba52
...
...
@@ -32,7 +32,7 @@ class ArticulatedObstacle;
#include "pfp.h"
//
#define EXPORTING3
#define EXPORTING3
//#define TWO_AND_HALF_DIM
#ifdef EXPORTING3
...
...
include/moving_mesh.h
View file @
aed8ba52
...
...
@@ -18,7 +18,7 @@
using
namespace
std
;
//
#define EXPORTING2
#define EXPORTING2
class
MovingMesh
{
...
...
include/moving_obstacle.h
View file @
aed8ba52
...
...
@@ -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"
...
...
include/viewer.h
View file @
aed8ba52
...
...
@@ -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
;
...
...
src/agent.cpp
View file @
aed8ba52
...
...
@@ -26,7 +26,7 @@ float Agent::radius_ = 3.0f ;
float
Agent
::
timeHorizon_
=
10.0
f
;
//float Agent::timeHorizon_ = 100.0f ;
float
Agent
::
timeHorizonObst_
=
10.0
f
;
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
=
1
0.0
;
float
ag_ambient_damping
=
5
0.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
=
5
0.0
;
double
ag_mass
=
20
0.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
=
20
0.0
;
// agent-agent interaction stiffness
double
ag_stiffness
=
5
0.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_
;
...
...
src/env_map.cpp
View file @
aed8ba52
...
...
@@ -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.0
f
;
position_Export
[
d
]
+=
VEC3
(
2000
,
0
,
0
);
// pour scenario5
//position_Export[d] *= 100.0f;
//position_Export[d] += VEC3(2000,0,0);
}
...
...
src/simulator.cpp
View file @
aed8ba52
...
...
@@ -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
;
...
...
src/viewer.cpp
View file @
aed8ba52
...
...
@@ -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() ;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment