viewer.cpp 70.8 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
/*******************************************************************************
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
 * Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
 *                                                                              *
 * This library is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation; either version 2.1 of the License, or (at your     *
 * option) any later version.                                                   *
 *                                                                              *
 * This library is distributed in the hope that it will be useful, but WITHOUT  *
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
 * for more details.                                                            *
 *                                                                              *
 * You should have received a copy of the GNU Lesser General Public License     *
 * along with this library; if not, write to the Free Software Foundation,      *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
 *                                                                              *
 * Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
24 25

#include "viewer.h"
26
#include "env_generator.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
27
#include <string>
Thomas Jund's avatar
Thomas Jund committed
28
#include "glm/gtc/type_ptr.hpp"
Thomas Jund's avatar
Thomas Jund committed
29
#include "Algo/Export/export.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31


pitiot's avatar
pitiot committed
32
SocialAgents::SocialAgents(unsigned int config, unsigned int minSize, unsigned int nbAgent, unsigned int nbObst,bool resolution, unsigned int iterations) :
33 34 35
#ifdef EXPORTING_OBJ
	m_objAgent(mapAgent),
#endif
36
	m_renderStyle(0),
David Cazier's avatar
David Cazier committed
37 38
	nbIterations(0),
	maxIterations(iterations),
Thomas Jund's avatar
Thomas Jund committed
39
	nbGeneratedPov(0),
David Cazier's avatar
David Cazier committed
40
	frames(0),
pitiot's avatar
maj  
pitiot committed
41
	nextUpdate(0),
pitiot's avatar
pitiot committed
42
	simulator(config, minSize, nbAgent, nbObst, resolution),
David Cazier's avatar
David Cazier committed
43
	render_anim(false),
pitiot's avatar
pitiot committed
44 45
	drawEnvLines(true),
	drawEnvFaces(true),
David Cazier's avatar
David Cazier committed
46
	drawEnvTopo(false),
pitiot's avatar
maj  
pitiot committed
47 48
	drawObstacles(false),
	drawMovingObstacles(true),
David Cazier's avatar
David Cazier committed
49 50 51
	drawAgents(true),
	drawAgentsNeighborDist(false),
	drawAgentsObstacleDist(false),
pitiot's avatar
maj  
pitiot committed
52
	drawAgentsPredictionTri(false),
53
	drawAgentsPath(false),
pitiot's avatar
pitiot committed
54
	drawObstPredictionTri(false),
55
	drawObstPath(false),
pitiot's avatar
merging  
pitiot committed
56
	draw_dart(false),
pitiot's avatar
pitiot committed
57
	target_Agent(false),
58
	draw_posX(false),
59 60
	draw_elipse(false),
	display_times(false)
Pierre Kraemer's avatar
Pierre Kraemer committed
61
{
David Cazier's avatar
David Cazier committed
62
	timer = new QTimer(this) ;
pitiot's avatar
stats  
pitiot committed
63 64 65 66 67 68 69 70 71 72 73 74

	switch (config){
		case 0 :name<<"cercle_";break;
		case 1 :name<<"corridor_";break;
		case 2 :name<<"corridorSnake_";break;
		case 3 :name<<"ville_";break;
		case 5 :name<<"strasbourg_";break;
		default : break;
	}

	filename<<name.str().c_str()<<nbAgent<<"_"<<nbObst<<"_"<<resolution;
	percent = false;
75 76
	time_update = 0 ;
	elapsedTime = 0;
David Cazier's avatar
David Cazier committed
77
	connect(timer, SIGNAL(timeout()), this, SLOT(animate())) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
78

pitiot's avatar
maj  
pitiot committed
79
	clock_gettime(CLOCK_MONOTONIC, &startTime) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
80

81
	glEnable(GL_POINT_SMOOTH) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83
}

Pierre Kraemer's avatar
Pierre Kraemer committed
84
void SocialAgents::initGUI()
Pierre Kraemer's avatar
Pierre Kraemer committed
85
{
David Cazier's avatar
David Cazier committed
86
	setDock(&dock) ;
pitiot's avatar
pitiot committed
87
//	dock.check_timer->setChecked(render_anim);
pitiot's avatar
maj  
pitiot committed
88 89 90 91
	dock.check_drawEnvLines->setChecked(drawEnvLines) ;
	dock.check_drawEnvFaces->setChecked(drawEnvFaces) ;
	dock.check_drawAgents->setChecked(drawAgents) ;
	dock.check_drawMovingObstacles->setChecked(drawMovingObstacles) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
92

David Cazier's avatar
David Cazier committed
93 94 95 96 97
	setCallBack(dock.check_timer, SIGNAL(toggled(bool)), SLOT(slot_timer(bool))) ;
	setCallBack(dock.check_drawEnvLines, SIGNAL(toggled(bool)), SLOT(slot_drawEnvLines(bool))) ;
	setCallBack(dock.check_drawEnvFaces, SIGNAL(toggled(bool)), SLOT(slot_drawEnvFaces(bool))) ;
	setCallBack(dock.check_drawEnvTopo, SIGNAL(toggled(bool)), SLOT(slot_drawEnvTopo(bool))) ;
	setCallBack(dock.check_drawObstacles, SIGNAL(toggled(bool)), SLOT(slot_drawObstacles(bool))) ;
pitiot's avatar
maj  
pitiot committed
98
	setCallBack(dock.check_drawMovingObstacles, SIGNAL(toggled(bool)), SLOT(slot_drawMovingObstacles(bool))) ;
David Cazier's avatar
David Cazier committed
99
	setCallBack(dock.check_drawAgents, SIGNAL(toggled(bool)), SLOT(slot_drawAgents(bool))) ;
pitiot's avatar
maj  
pitiot committed
100
	setCallBack(dock.check_drawAgentsPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPredictionTri(bool))) ;
pitiot's avatar
pitiot committed
101
	setCallBack(dock.check_drawObstPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawObstPredictionTri(bool))) ;
pitiot's avatar
maj  
pitiot committed
102 103
	setCallBack(dock.check_drawAgentsNeighborDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsNeighborDist(bool))) ;
	setCallBack(dock.check_drawAgentsObstacleDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsObstacleDist(bool))) ;
104
	setCallBack(dock.check_drawAgentsPath, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPath(bool))) ;
105
	setCallBack(dock.check_drawObstPath, SIGNAL(toggled(bool)), SLOT(slot_drawObstPath(bool))) ;
pitiot's avatar
maj  
pitiot committed
106 107
	setCallBack(dock.check_dart, SIGNAL(toggled(bool)), SLOT(slot_dart(bool))) ;
	setCallBack(dock.check_slide, SIGNAL(valueChanged(int)), SLOT(slot_slide(int))) ;
108 109 110
	setCallBack(dock.check_pos, SIGNAL(toggled(bool)), SLOT(slot_posX(bool))) ;
	setCallBack(dock.check_x_val, SIGNAL(valueChanged(int)), SLOT(slot_slide2(int))) ;
	setCallBack(dock.check_y_val, SIGNAL(valueChanged(int)), SLOT(slot_slide3(int))) ;
pitiot's avatar
merging  
pitiot committed
111
	setCallBack(dock.check_elipse, SIGNAL(toggled(bool)), SLOT(slot_elipse(bool))) ;
pitiot's avatar
pitiot committed
112 113
	setCallBack(dock.checkAgent, SIGNAL(toggled(bool)), SLOT(slot_Agent(bool))) ;
	setCallBack(dock.AgentSelect, SIGNAL(valueChanged(int)), SLOT(slot_AgentSlider(int))) ;
Thomas Jund's avatar
Thomas Jund committed
114 115 116

	dock.check_x_val->setRange(-100000, 100000) ;
	dock.check_y_val->setRange(-100000, 100000) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
117
}
Pierre Kraemer's avatar
Pierre Kraemer committed
118

Pierre Kraemer's avatar
Pierre Kraemer committed
119 120
void SocialAgents::cb_initGL()
{
Thomas Jund's avatar
Thomas Jund committed
121 122 123
	std::cout << "initGL" << std::endl;

	colClear = Geom::Vec4f(0.7f, 0.7f, 0.7f, 0.5f) ;
Thomas Jund's avatar
Thomas Jund committed
124
	colDif = Geom::Vec4f(0.3f, 0.3f, 0.3f, 1.0f) ;
Thomas Jund's avatar
Thomas Jund committed
125 126
	colSpec = Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f) ;
	colNormal = Geom::Vec4f(1.0f, 0.0f, 0.0f, 1.0f) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
127

David Cazier's avatar
David Cazier committed
128
	bb = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.map, simulator.envMap_.position) ;
Thomas Jund's avatar
Thomas Jund committed
129 130 131 132 133 134 135
	if(simulator.config==5)
	{
		Geom::BoundingBox<PFP::VEC3> bbBuilding = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.mapScenary, simulator.envMap_.positionScenary) ;
		bb.addPoint(bbBuilding.min());
		bb.addPoint(bbBuilding.max());
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
136 137 138 139
	VEC3 gPosObj = bb.center() ;
	float tailleX = bb.size(0) ;
	float tailleY = bb.size(1) ;
	float tailleZ = bb.size(2) ;
140 141 142 143 144
	float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;

	if(simulator.config<6)
		gWidthObj /= 5.0f;

145
	setParamObject(gWidthObj, gPosObj.data()) ;
Thomas Jund's avatar
Thomas Jund committed
146

147 148
	std::cout << "Bb " << bb << std::endl;

Thomas Jund's avatar
Thomas Jund committed
149 150 151 152 153
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);

	// create the render
	m_render = new Algo::Render::GL2::MapRender();
Thomas Jund's avatar
Thomas Jund committed
154 155 156 157
#ifdef ONERING
	m_renderWithin = new Algo::Render::GL2::MapRender();
#endif

Thomas Jund's avatar
Thomas Jund committed
158
	m_renderTopo = new Algo::Render::GL2::TopoRender();
159
	m_ds = new Utils::Drawer();
Thomas Jund's avatar
Thomas Jund committed
160

Thomas Jund's avatar
Thomas Jund committed
161 162 163
	if(simulator.config==5)
		m_renderPedway = new Algo::Render::GL2::MapRender();

Thomas Jund's avatar
Thomas Jund committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
	// create VBO for position
	m_positionVBO = new Utils::VBO();
	m_normalVBO = new Utils::VBO() ;

	// using simple shader with color
	m_simpleColorShader = new Utils::ShaderSimpleColor();
	m_simpleColorShader->setAttributePosition(m_positionVBO);
	m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.));

	m_positionVBO->updateData(simulator.envMap_.position) ;
	m_normalVBO->updateData(simulator.envMap_.normal) ;

	if(simulator.config==5)
	{
		m_render_scenary = new Algo::Render::GL2::MapRender();

		m_positionVBO_scenary = new Utils::VBO();
		m_normalVBO_scenary = new Utils::VBO() ;

		m_positionVBO_scenary->updateData(simulator.envMap_.positionScenary) ;
		m_normalVBO_scenary->updateData(simulator.envMap_.normalScenary) ;

Thomas Jund's avatar
Thomas Jund committed
186 187 188
#ifdef EXPORTING
		m_flatShader_scenary = new ShaderCustom();
#else
Thomas Jund's avatar
Thomas Jund committed
189
		m_flatShader_scenary = new Utils::ShaderFlat();
Thomas Jund's avatar
Thomas Jund committed
190
#endif
Thomas Jund's avatar
Thomas Jund committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
		m_flatShader_scenary->setAttributePosition(m_positionVBO_scenary);
		m_flatShader_scenary->setAmbiant(colClear) ;
		m_flatShader_scenary->setDiffuse(colDif) ;

		registerShader(m_flatShader_scenary);
	}

	m_agentsVBO = new Utils::VBO();
	m_agentsVBO->setDataSize(3);
	m_agentsVBO->allocate(simulator.agents_.size());


	PFP::VEC3* data = static_cast<PFP::VEC3*>(m_agentsVBO->lockPtr());
	for (unsigned int i=0; i< simulator.agents_.size(); ++i)
	{
		VEC3 p = simulator.agents_[i]->getPosition();
		data[i] = p;
	}
	m_agentsVBO->releasePtr();

	m_sprite = new Utils::PointSprite();
	m_sprite->setAttributePosition(m_agentsVBO);
213 214
	m_sprite->setSize(Agent::radius_);
//	m_sprite->setSize((50.0f/gWidthObj) *  Agent::radius_ );
Thomas Jund's avatar
Thomas Jund committed
215 216 217 218

	registerShader(m_simpleColorShader);
	registerShader(m_sprite);

pitiot's avatar
merging  
pitiot committed
219 220 221
	qglviewer::Camera* cam = getQGLWidget()->camera();
	cam->setSceneRadius(10000);

Thomas Jund's avatar
Thomas Jund committed
222 223 224 225 226
	initRendering();
}

void SocialAgents::initRendering()
{
227 228 229
//	dCD = new Utils::Drawer();
//	registerShader(dCD->getShader());

Thomas Jund's avatar
Thomas Jund committed
230 231
	if(simulator.config==5)
	{
Sylvain Thery's avatar
Sylvain Thery committed
232 233
		m_render_scenary->initPrimitives<PFP>(simulator.envMap_.mapScenary, Algo::Render::GL2::LINES,false) ;
		m_render_scenary->initPrimitives<PFP>(simulator.envMap_.mapScenary, Algo::Render::GL2::TRIANGLES,false) ;
Thomas Jund's avatar
Thomas Jund committed
234

235 236 237
		MapBrowserSelector mbs(simulator.envMap_.map,SelectorCellMarked<FACE>(simulator.envMap_.pedWayMark));
		simulator.envMap_.map.setBrowser(&mbs);

Sylvain Thery's avatar
Sylvain Thery committed
238
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ;
239 240 241
		m_renderPedway->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ;

		simulator.envMap_.map.setBrowser(NULL);
Thomas Jund's avatar
Thomas Jund committed
242

243
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
Sylvain Thery's avatar
Sylvain Thery committed
244
		m_renderPedway->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
Thomas Jund's avatar
Thomas Jund committed
245 246 247
	}
	else
	{
Sylvain Thery's avatar
Sylvain Thery committed
248 249
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ;
Thomas Jund's avatar
Thomas Jund committed
250 251 252 253

#ifdef ONERING
		m_renderWithin->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES,false) ;
#endif
Thomas Jund's avatar
Thomas Jund committed
254 255
	}

Sylvain Thery's avatar
Sylvain Thery committed
256
	m_renderTopo->updateData<PFP>(simulator.envMap_.map, simulator.envMap_.position, 0.9, 0.9);
Thomas Jund's avatar
Thomas Jund committed
257 258 259 260 261 262 263


	for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
	{
		m_obst_render.push_back(new Algo::Render::GL2::MapRender());

		Utils::ShaderFlat * shader = new Utils::ShaderFlat();
264 265
		shader->setAmbiant(Geom::Vec4f(1.,1.,0.,0.)) ;
		shader->setDiffuse(Geom::Vec4f(1.,1.,0.,0.));
Thomas Jund's avatar
Thomas Jund committed
266 267 268 269 270 271 272 273 274

		Utils::VBO * vbo = new Utils::VBO();
		vbo->setDataSize(3);
		vbo->allocate(simulator.movingObstacles_[i]->nbVertices);
		shader->setAttributePosition(vbo);

		m_obst_VBO.push_back(vbo);
		m_obstShader.push_back(shader);
		registerShader(shader);
275 276 277 278 279

		simulator.movingObstacles_[i]->initGL();
#ifdef EXPORTING_BOXES
		registerShader(simulator.movingObstacles_[i]->m_shader);
#endif
Thomas Jund's avatar
Thomas Jund committed
280 281 282
	}

	updateObstacleVBO();
Thomas Jund's avatar
Thomas Jund committed
283 284 285

#ifdef EXPORTING

pitiot's avatar
pitiot committed
286
#if 0
Thomas Jund's avatar
Thomas Jund committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
	m_Ground_VBO = new Utils::VBO();
	m_Ground_VBO->setDataSize(3);
	m_Ground_VBO->allocate(4);
	PFP::VEC3* data = static_cast<PFP::VEC3*>(m_Ground_VBO->lockPtr());
	data[0] = VEC3(bb.min()[0], bb.min()[1], 0);
	data[1] = VEC3(bb.max()[0], bb.min()[1], 0);
	data[2] = VEC3(bb.max()[0], bb.max()[1], 0);
	data[3] = VEC3(bb.min()[0], bb.max()[1], 0);
	m_Ground_VBO->releasePtr();
#else
	m_Ground_VBO = new Utils::VBO();
	m_Ground_VBO->setDataSize(3);
	m_Ground_VBO->allocate(4*N_THETA*N_PHI);
	PFP::VEC3* data = static_cast<PFP::VEC3*>(m_Ground_VBO->lockPtr());

	for( unsigned int i=0, n=0; i<N_THETA; ++i )
	{
		float theta1 = M_PI* i   /N_THETA;
		float theta2 = M_PI*(i+1)/N_THETA;

		for( unsigned int j=0; j<N_PHI; ++j )
		{
			float phi1 = 2.0f*M_PI* j   /N_PHI;
			float phi2 = 2.0f*M_PI*(j+1)/N_PHI;

			float x, y, z;

			x = RADIUS * std::sin(theta1) * std::cos(phi1);
			y = RADIUS * std::cos(theta1);
			z = RADIUS * std::sin(theta1) * std::sin(phi1);
			data[n++] = VEC3(x,y,z);

			x = RADIUS * std::sin(theta1) * std::cos(phi2);
			y = RADIUS * std::cos(theta1);
			z = RADIUS * std::sin(theta1) * std::sin(phi2);
			data[n++] = VEC3(x,y,z);

			x = RADIUS * std::sin(theta2) * std::cos(phi2);
			y = RADIUS * std::cos(theta2);
			z = RADIUS * std::sin(theta2) * std::sin(phi2);
			data[n++] = VEC3(x,y,z);

			x = RADIUS * std::sin(theta2) * std::cos(phi1);
			y = RADIUS * std::cos(theta2);
			z = RADIUS * std::sin(theta2) * std::sin(phi1);
			data[n++] = VEC3(x,y,z);
		}
	}
	m_Ground_VBO->releasePtr();
#endif

	m_Ground_Shader = new Utils::ShaderFlat();
	m_Ground_Shader->setAmbiant (Geom::Vec4f(0.6f, 0.8f, 0.6f, 1.0f));
	m_Ground_Shader->setDiffuse (Geom::Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
	m_Ground_Shader->setAttributePosition(m_Ground_VBO);
	registerShader(m_Ground_Shader);

	if( !m_DeferedShader.loadShaders("./shaders/Defered.vert", "./shaders/Defered.frag") )
		std::cout << __FUNCTION__ << ": pas glop!" << std::endl;

	if( !m_DeferedShader2.loadShaders("./shaders/Defered2.vert", "./shaders/Defered2.frag") )
		std::cout << __FUNCTION__ << ": pas glop!" << std::endl;

#endif
Thomas Jund's avatar
Thomas Jund committed
351 352

	for(unsigned int i = 0 ; i < simulator.movingMeshes_.size() ; ++i)
Thomas Jund's avatar
Thomas Jund committed
353 354
	{
		simulator.movingMeshes_[i]->initGL();
Thomas Jund's avatar
Thomas Jund committed
355
#ifdef EXPORTING2
Thomas Jund's avatar
Thomas Jund committed
356 357
		registerShader(simulator.movingMeshes_[i]->m_shaderTex);
#else
Thomas Jund's avatar
Thomas Jund committed
358
		registerShader(simulator.movingMeshes_[i]->m_simpleColorShader);
Thomas Jund's avatar
Thomas Jund committed
359 360
#endif
	}
361 362 363 364 365 366 367

	simulator.envMap_.initGL();
#ifdef EXPORTING3
	for(unsigned int j = 0 ; j < simulator.envMap_.m_shaderTex_Export.size() ; ++j)
		registerShader(simulator.envMap_.m_shaderTex_Export[j]);
#endif

368
#ifdef EXPORTING_OBJ
Thomas Jund's avatar
Thomas Jund committed
369
	std::vector<std::string> attrNames ;
Arash HABIBI's avatar
Arash HABIBI committed
370
//	m_objAgent.import("./meshRessources/scenario3/mexicain_occ.obj",attrNames);
Thomas Jund's avatar
Thomas Jund committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
	m_objAgent.import("./meshRessources/Mexicainlowres2.obj",attrNames);
//	m_objAgent.import("./meshRessources/Mexicainhighres.obj",attrNames);
	positionAgent = mapAgent.getAttribute<VEC3, VERTEX>(attrNames[0]) ;

//	Geom::BoundingBox<PFP::VEC3> bb ;
//	bb = Algo::Geometry::computeBoundingBox<PFP>(map, position) ;
//	std::cout << "bb agent " << bb << std::endl;

	TraversorV<PFP2::MAP> tV(mapAgent);
	for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
	{
		positionAgent[d] /= 12.0f;
		positionAgent[d] *= Agent::radius_;
	}

	m_texcoordVBOAgent = new Utils::VBO();
	m_positionVBOAgent = new Utils::VBO();
	m_normalVBOAgent = new Utils::VBO();

	m_textureAgent = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);

//	if (m_textureAgent->load("./meshRessources/sombrero2lowres_grp.png"))
	if (m_textureAgent->load("./meshRessources/sombrero2_grp.png"))
Arash HABIBI's avatar
Arash HABIBI committed
394
//	if (m_textureAgent->load("./meshRessources/scenario3/mexicain_occ.png"))
Thomas Jund's avatar
Thomas Jund committed
395 396 397 398 399 400
			m_textureAgent->update();
	else
		std::cout << "problem : loading texture" << std::endl;

	m_textureAgent->setWrapping(GL_CLAMP_TO_EDGE);

Thomas Jund's avatar
Thomas Jund committed
401 402
// 	m_shaderTexAgent = new ShaderCustomTex();
	m_shaderTexAgent = new ShaderPhongTexCust();
Thomas Jund's avatar
Thomas Jund committed
403 404 405 406 407
	m_shaderTexAgent->setAttributePosition(m_positionVBOAgent);
	m_shaderTexAgent->setAttributeTexCoord(m_texcoordVBOAgent);
	m_shaderTexAgent->setTextureUnit(GL_TEXTURE0);
	m_shaderTexAgent->setTexture(m_textureAgent);

Thomas Jund's avatar
Thomas Jund committed
408 409 410 411
	m_shaderTexAgent->setAttributeNormal(m_normalVBOAgent);
	m_shaderTexAgent->setShininess(0.1f);
	m_shaderTexAgent->setAmbient(0.5f);
	m_shaderTexAgent->setSpecular(Geom::Vec4f(0.05));
Thomas Jund's avatar
Thomas Jund committed
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429

	glEnable(GL_TEXTURE_2D);

	if (!m_objAgent.hasNormals())
	{
		normalAgent = mapAgent.getAttribute<VEC3, VERTEX>("normal") ;
		if(!normalAgent.isValid())
			normalAgent = mapAgent.addAttribute<VEC3, VERTEX>("normal") ;

		Algo::Surface::Geometry::computeNormalVertices<PFP2>(mapAgent, m_objAgent.m_positions, normalAgent) ;
		m_objAgent.setNormalAttribute(normalAgent);
	}

	mapAgent.setBrowser(NULL);

	m_nbIndicesAgent = m_objAgent.createSimpleVBO_PTN(m_positionVBOAgent,m_texcoordVBOAgent,m_normalVBOAgent);

	registerShader(m_shaderTexAgent);
430
#endif
Thomas Jund's avatar
Thomas Jund committed
431

pitiot's avatar
pitiot committed
432
#ifdef EXPORTING_AGENT
Thomas Jund's avatar
Thomas Jund committed
433 434
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
Thomas Jund's avatar
merge  
Thomas Jund committed
435
			simulator.agents_[i]->initGL();
Thomas Jund's avatar
Thomas Jund committed
436 437 438 439
//
//#ifdef EXPORTING_OBJ
//			registerShader(simulator.agents_[i]->m_shaderTex);
//#endif
440 441 442
			registerShader(simulator.agents_[i]->m_ghost_shader);
		}
#endif
443 444 445 446 447 448 449 450
//	bb = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.m_map_Export, simulator.envMap_.position_Export) ;
//
//	VEC3 gPosObj = bb.center() ;
//	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);///10.0f ;
//	setParamObject(gWidthObj, gPosObj.data()) ;
Thomas Jund's avatar
Thomas Jund committed
451 452 453 454 455 456 457 458 459 460 461 462 463
}

void SocialAgents::updateObstacleVBO()
{
	for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
	{
		Utils::VBO * vbo = m_obst_VBO[i];
		PFP::VEC3* data = static_cast<PFP::VEC3*>(vbo->lockPtr());
		for (unsigned int j=0; j< simulator.movingObstacles_[i]->nbVertices; ++j)
		{
			VEC3 p = simulator.movingObstacles_[i]->getDilatedPosition(j);
			data[j] = p;
		}
Thomas Jund's avatar
Thomas Jund committed
464

Thomas Jund's avatar
Thomas Jund committed
465 466 467 468 469 470
		vbo->releasePtr();
	}
}

void SocialAgents::updateObstaclePredTriVBO()
{
pitiot's avatar
pitiot committed
471
//	CGoGNout<<"update"<<CGoGNendl;
Thomas Jund's avatar
Thomas Jund committed
472 473 474 475 476
	for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
	{

		Utils::VBO * vbo = m_triObst_VBO[i];
		PFP::VEC3* data = static_cast<PFP::VEC3*>(vbo->lockPtr());
pitiot's avatar
up  
pitiot committed
477 478 479 480 481
		for(unsigned int j =0; j<simulator.movingObstacles_[i]->nbVertices; j++ )
		{
			VEC3 p = simulator.movingObstacles_[i]->getDilatedPosition(j);
			data[j*4+0] = p;
			data[j*4+3] = p;
Thomas Jund's avatar
Thomas Jund committed
482

pitiot's avatar
up  
pitiot committed
483 484
			p = simulator.envMap_.position[simulator.movingObstacles_[i]->parts_[j]->d];
			data[j*4+1] = p;
Thomas Jund's avatar
Thomas Jund committed
485

pitiot's avatar
up  
pitiot committed
486 487
			p = simulator.envMap_.position[simulator.envMap_.map.phi1(simulator.movingObstacles_[i]->parts_[j]->d)];
			data[j*4+2] = p;
Thomas Jund's avatar
Thomas Jund committed
488

489 490

		}
Thomas Jund's avatar
Thomas Jund committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
		vbo->releasePtr();
	}
}

void SocialAgents::updateAgentPredTriVBO()
{
	for(unsigned int i=0 ; i < simulator.agents_.size() ; ++i)
	{
		Utils::VBO * vbo = m_triAgent_VBO[i];
		PFP::VEC3* data = static_cast<PFP::VEC3*>(vbo->lockPtr());

		VEC3 p = simulator.agents_[i]->getPosition();
		data[0] = p;

		p = simulator.envMap_.position[simulator.agents_[i]->part_.d];
		data[1] = p;

		p = simulator.envMap_.position[simulator.envMap_.map.phi1(simulator.agents_[i]->part_.d)];
		data[2] = p;

		vbo->releasePtr();
	}
}

void SocialAgents::updateVBOprimitives(int upType)
{
Thomas Jund's avatar
Thomas Jund committed
517 518
#ifdef ONERING
	CellMarker<FACE> cmF(simulator.envMap_.map);
pitiot's avatar
merge  
pitiot committed
519 520 521 522 523 524 525

	for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i)
	{


	MovingObstacle * mo =simulator.movingObstacles_[i];
	for (std::vector<std::pair<Dart, int> >::iterator it = mo->general_belonging.begin();	it != mo->general_belonging.end(); ++it)
Thomas Jund's avatar
Thomas Jund committed
526
	{
pitiot's avatar
merge  
pitiot committed
527 528 529 530 531 532
		if(!cmF.isMarked((*it).first))
		{
				cmF.mark((*it).first);

		}
	}
Thomas Jund's avatar
Thomas Jund committed
533 534 535 536 537
	}

	MapBrowserSelector mbs1(simulator.envMap_.map,SelectorCellMarked<FACE>(cmF));
	simulator.envMap_.map.setBrowser(&mbs1);

Thomas Jund's avatar
Thomas Jund committed
538
	if(upType & Algo::Render::GL2::TRIANGLES)
Sylvain Thery's avatar
Sylvain Thery committed
539
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ;
Thomas Jund's avatar
Thomas Jund committed
540

Thomas Jund's avatar
Thomas Jund committed
541 542 543
	simulator.envMap_.map.setBrowser(NULL);

	CellMarker<FACE> cmF2(simulator.envMap_.map);
pitiot's avatar
merge  
pitiot committed
544
	for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i)
Thomas Jund's avatar
Thomas Jund committed
545
	{
pitiot's avatar
merge  
pitiot committed
546 547 548 549 550


		MovingObstacle * mo =simulator.movingObstacles_[i];
		int n =mo->nbParticles;
		for (int i = 0; i< n-1;i++)
Thomas Jund's avatar
Thomas Jund committed
551
		{
pitiot's avatar
merge  
pitiot committed
552 553 554 555 556 557 558
			for (std::vector<Dart>::iterator it = mo->neighbor_cells[i].begin();	it !=  mo->neighbor_cells[i].end(); ++it)
			{
				if(!cmF.isMarked(*it)&& !cmF2.isMarked(*it))
				{
					cmF2.mark(*it);
				}
			}
Thomas Jund's avatar
Thomas Jund committed
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
		}
	}

	MapBrowserSelector mbs2(simulator.envMap_.map,SelectorCellMarked<FACE>(cmF2));
	simulator.envMap_.map.setBrowser(&mbs2);

	if(upType & Algo::Render::GL2::TRIANGLES)
		m_renderWithin->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ;

	simulator.envMap_.map.setBrowser(NULL);
#else
	if(upType & Algo::Render::GL2::TRIANGLES)
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::TRIANGLES, false) ;
#endif


Thomas Jund's avatar
Thomas Jund committed
575
	if(upType & Algo::Render::GL2::LINES)
Sylvain Thery's avatar
Sylvain Thery committed
576
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
Thomas Jund's avatar
Thomas Jund committed
577 578

	if(upType & Algo::Render::GL2::POINTS)
Sylvain Thery's avatar
Sylvain Thery committed
579
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::POINTS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
580
}
Pierre Kraemer's avatar
Pierre Kraemer committed
581

Arash HABIBI's avatar
Arash HABIBI committed
582 583 584 585 586
//-----------------------------------
// An ellipse has two foci placed at
// F1 and F2. The ellipse is the set
// of points M for whom MF1 + MF2 = s

pitiot's avatar
pitiot committed
587 588
//static void drawEllipse(VEC3 F1, VEC3 F2, float s, int N)
//{
Thomas Jund's avatar
Thomas Jund committed
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
//	float a,b=0;
//	VEC3 O,u,v;
//	O = 0.5f*(F1+F2);
//	u = F1-F2;
//	float c = (F1-F2).norm();
//	if(c==0)
//	{
//		u[0] = 1.0;
//		u[1] = 0.0;
//		v[0] = 0.0;
//		v[1] = 1.0;
//		a=s/2;
//		b=s/2;
//	}
//	else // c>0
//	{
//		u = (1.0f/c) * u;
//		v.zero();
//		v[0] = u[1];
//		v[1] = -u[0];
//
//		c = 0.5 * c;
//		a = s/2.0;
//		if(a<c)
//		{
//			cerr << "a=" << a << " and c=" << c << endl;
//			cerr << "No such an ellipse is possible" << endl;
//		}
//		else // a >= c
//			b = sqrt( a*a - c*c );
//	}
Thomas Jund's avatar
Thomas Jund committed
620 621 622 623 624 625 626 627 628 629 630
//	glBegin(GL_LINE_LOOP);
//	VEC3 M;
//	float dtheta = 2 * M_PI / N;
//	float theta;
//	for(theta=0; theta<2*M_PI; theta+=dtheta)
//	{
//		M = O + a*cos(theta)*u + b*sin(theta)*v;
//		glColor3f(0,0,1);
//		glVertex2f(M[0],M[1]);
//	}
//	glEnd();
pitiot's avatar
pitiot committed
631
//}
Arash HABIBI's avatar
Arash HABIBI committed
632 633 634

//-----------------------------------

Thomas Jund's avatar
Thomas Jund committed
635 636 637 638 639 640 641 642 643 644 645 646
void SocialAgents::moveCameraTo(VEC3 newPos)
{
	float& x = trans_x();
	float& y = trans_y();
	float& z = trans_z();

	x = newPos[0];
	y = newPos[1];
	z = newPos[2];

//	transfoTranslate(newPos[0],newPos[1],newPos[2]);

647 648 649 650 651 652 653 654 655 656 657 658
//	float * quat = curquat();
//
//	float theta = M_PI/2.0f;
//	float qx = 1 * sin(theta/2.0f);
//	float qy = 0 * sin(theta/2.0f);
//	float qz = 0 * sin(theta/2.0f);
//	float qw = cos(theta/2.0f);
//
//	quat[0] = qx;
//	quat[1] = qy;
//	quat[2] = qz;
//	quat[3] = qw;
Thomas Jund's avatar
Thomas Jund committed
659 660 661 662

	updateGLMatrices();
}

Pierre Kraemer's avatar
Pierre Kraemer committed
663 664
void SocialAgents::cb_redraw()
{
Thomas Jund's avatar
Thomas Jund committed
665 666 667 668 669 670 671 672 673 674 675 676 677 678
	pushTransfoMatrix();

#ifdef EXPORTING
	Utils::FBO fbo( width(), height() );
	int deferedColorAttachment = fbo.createAttachColorTexture( GL_RGB );
	int deferedNormalAttachment = fbo.createAttachColorTexture( GL_RGB );
	fbo.createAttachDepthTexture();
	fbo.bind();
	fbo.enableAllColorAttachments();
#endif

	glClearColor( 0.8f, 0.8f, 1.0f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT );

Thomas Jund's avatar
Thomas Jund committed
679
//	glEnable(GL_CULL_FACE);
Thomas Jund's avatar
Thomas Jund committed
680 681 682 683 684
	glEnable(GL_MULTISAMPLE);
	glEnable(GL_LINE_SMOOTH);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glEnable(GL_POINT_SMOOTH);
	glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
Thomas Jund's avatar
Thomas Jund committed
685

Thomas Jund's avatar
Thomas Jund committed
686 687
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
	glEnable(GL_LIGHTING);
pitiot's avatar
maj  
pitiot committed
688

689
	glEnable( GL_MULTISAMPLE );
690
	simulator.envMap_.draw();
Thomas Jund's avatar
Thomas Jund committed
691

Thomas Jund's avatar
Thomas Jund committed
692
	dock.check_slide->setRange(0, simulator.envMap_.map.end().index) ;
693

David Cazier's avatar
David Cazier committed
694 695
	if (drawAgents)
	{
pitiot's avatar
pitiot committed
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
		if(drawAgentsPath)
		{
			for (unsigned int i=0; i< simulator.agents_.size(); ++i)
			{
				Agent * ag = simulator.agents_[i];
				m_ds->newList(GL_COMPILE_AND_EXECUTE);
				m_ds->begin(GL_LINE_STRIP);

				VEC3 col = Utils::color_map_BCGYR(float(ag->agentNo)/float(simulator.agents_.size()));
				m_ds->color3f(col[0],col[1],col[2]);
				m_ds->vertex(ag->getPosition());
				for(unsigned int i = 0 ; i < ag->goals_.size() ; i++)
				{
					m_ds->vertex(ag->goals_[(ag->curGoal_+i)%(ag->goals_.size())]);
				}

				m_ds->end();
				m_ds->endList();
			}

		}

Thomas Jund's avatar
Thomas Jund committed
718
#ifdef EXPORTING_OBJ
Thomas Jund's avatar
Thomas Jund committed
719 720 721 722 723 724 725 726 727 728 729
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
			m_nbIndicesAgent = m_objAgent.createSimpleVBO_PTN(m_positionVBOAgent,m_texcoordVBOAgent,m_normalVBOAgent);
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

			m_shaderTexAgent->setTransformation(simulator.agents_[i]->m_transfo);
			m_shaderTexAgent->activeTexture();
			m_shaderTexAgent->enableVertexAttribs();
			glDrawArrays(GL_TRIANGLES, 0, m_nbIndicesAgent);
			m_shaderTexAgent->disableVertexAttribs();
		}
Thomas Jund's avatar
Thomas Jund committed
730
#else
pitiot's avatar
pitiot committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
		//test thomas P
//		glDisable(GL_LIGHTING);
//		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
//		{
//			VEC3 pos =simulator.agents_[i]->part_.getPosition();
//			m_ds->newList(GL_COMPILE_AND_EXECUTE);
//			m_ds->lineWidth(5.0f);
//			m_ds->pointSize(10.0f);
//			m_ds->begin(GL_POINTS);
//			// fait varier la couleur du plus pres au plus loin
//
//			m_ds->color3f(simulator.agents_[i]->color1 , simulator.agents_[i]->color2, simulator.agents_[i]->color3);
//
//			m_ds->vertex(pos);
//
//			m_ds->end();
//			m_ds->endList();
//		}

//	///	save
Thomas Jund's avatar
Thomas Jund committed
751 752 753 754 755 756 757
		PFP::VEC3* data = static_cast<PFP::VEC3*>(m_agentsVBO->lockPtr());
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
			VEC3 p = simulator.agents_[i]->getPosition();
			data[i] = p;
		}
		m_agentsVBO->releasePtr();
Pierre Kraemer's avatar
Pierre Kraemer committed
758

Thomas Jund's avatar
Thomas Jund committed
759 760 761 762 763
		m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f));
		m_sprite->enableVertexAttribs();
		glDrawArrays(GL_POINTS, 0, simulator.agents_.size());
		m_sprite->disableVertexAttribs();
		m_sprite->postdraw();
Thomas Jund's avatar
Thomas Jund committed
764
#endif
Thomas Jund's avatar
Thomas Jund committed
765

Thomas Jund's avatar
Thomas Jund committed
766
#ifdef EXPORTING_AGENT
767 768 769 770 771
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
			simulator.agents_[i]->draw();
		}
#endif
Thomas Jund's avatar
Thomas Jund committed
772

773 774 775 776
		if(target_Agent)
		{
			glDisable(GL_LIGHTING);
			VEC3 pos =simulator.agents_[agentSlider]->part_.getPosition();
Thomas Jund's avatar
Thomas Jund committed
777
			m_ds->newList(GL_COMPILE_AND_EXECUTE);
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
			m_ds->lineWidth(5.0f);
			m_ds->pointSize(10.0f);
			m_ds->begin(GL_POINTS);
			// fait varier la couleur du plus pres au plus loin

			m_ds->color3f(0.0f , 1.0f, 0.9f);

			m_ds->vertex(pos);
			m_ds->vertex(pos+VEC3(0,0,50));

			m_ds->vertex(pos+VEC3(0,10,50));

			m_ds->end();
			m_ds->endList();
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
793
	}
pitiot's avatar
up  
pitiot committed
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
	if (draw_posX)
	{
		glDisable(GL_LIGHTING);
		VEC3 pos =VEC3 (posXSlider,posYSlider,0);
		m_ds->newList(GL_COMPILE_AND_EXECUTE);
		m_ds->lineWidth(5.0f);
		m_ds->pointSize(10.0f);
		m_ds->begin(GL_POINTS);
		// fait varier la couleur du plus pres au plus loin

		m_ds->color3f(0.0f , 1.0f, 0.9f);

		m_ds->vertex(pos);
		m_ds->vertex(pos+VEC3(0,0,50));

		m_ds->vertex(pos+VEC3(0,10,50));
810

pitiot's avatar
up  
pitiot committed
811 812 813
		m_ds->end();
		m_ds->endList();
	}
pitiot's avatar
pitiot committed
814 815


pitiot's avatar
maj  
pitiot committed
816 817
	if (drawMovingObstacles)
	{
Thomas Jund's avatar
Thomas Jund committed
818
#ifdef SHADOWSHELL
819
		updateObstacleVBO();
Thomas Jund's avatar
Thomas Jund committed
820
#endif
Thomas Jund's avatar
Thomas Jund committed
821 822 823

		for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i)
		{
Thomas Jund's avatar
Thomas Jund committed
824
#ifdef SHADOWSHELL
pitiot's avatar
merging  
pitiot committed
825
			if(false){
pitiot's avatar
pitiot committed
826 827
				Utils::ShaderFlat* moShader = m_obstShader[i];

Thomas Jund's avatar
Thomas Jund committed
828 829 830 831
//			moShader->setAmbiant(Geom::Vec4f(0.43137254902,0.76862745098,0.8862745098,0.));
			moShader->setAmbiant(Geom::Vec4f(0,0,0,0.));
			moShader->setDiffuse(Geom::Vec4f(0.,0.,0.,0.));

832 833 834
			moShader->enableVertexAttribs();
			glDrawArrays(GL_POLYGON, 0, simulator.movingObstacles_[i]->nbVertices);
			moShader->disableVertexAttribs();
pitiot's avatar
pitiot committed
835
			}
Thomas Jund's avatar
Thomas Jund committed
836
#endif
837

pitiot's avatar
merging  
pitiot committed
838

pitiot's avatar
pitiot committed
839
			simulator.movingObstacles_[i]->draw(drawObstPath, drawObstacles);
pitiot's avatar
pitiot committed
840 841 842 843
#ifdef DRAW_REGISTRATION
			MovingObstacle * mo =simulator.movingObstacles_[i];
			if (drawEnvTopo)
				{
pitiot's avatar
pitiot committed
844 845
				unsigned int n = mo->nbVertices;
					if(n<mo->nbParticles)
pitiot's avatar
pitiot committed
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
					{
						for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin();	it != mo->belonging_cells[n].end(); ++it)
						{

							drawCell((*it),5.0f,0,1.0f,0.5f);
						}
						for (std::vector<Dart>::iterator it = mo->neighbor_cells[n].begin();	it != mo->neighbor_cells[n].end(); ++it)
						{

							drawCell((*it),5.0f,1.0f,0,0.5f);
						}

					}
				}
#endif

pitiot's avatar
merging  
pitiot committed
862

Thomas Jund's avatar
Thomas Jund committed
863
		}
Arash HABIBI's avatar
Arash HABIBI committed
864

pitiot's avatar
merging  
pitiot committed
865
		//		 Commente par Arash
pitiot's avatar
plop  
pitiot committed
866 867 868 869
#ifdef AFFICHE_MESH
		 for (std::vector<MovingMesh*>::iterator it = simulator.movingMeshes_.begin() ; it != simulator.movingMeshes_.end() ; ++it)
			(*it)->draw();
#endif
pitiot's avatar
maj  
pitiot committed
870 871 872

	}

Pierre Kraemer's avatar
Pierre Kraemer committed
873
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
874 875
	if (drawAgentsPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
876 877 878
		updateAgentPredTriVBO();

		for(unsigned int i = 0 ; i < simulator.agents_.size() ; ++i)
David Cazier's avatar
David Cazier committed
879
		{
Thomas Jund's avatar
Thomas Jund committed
880 881 882 883 884
			Utils::ShaderSimpleColor* agShader = m_triAgent_Shader[i];

			agShader->enableVertexAttribs();
			glDrawArrays(GL_LINE_LOOP, 0, 3);
			agShader->disableVertexAttribs();
Pierre Kraemer's avatar
Pierre Kraemer committed
885 886
		}
	}
pitiot's avatar
pitiot committed
887 888 889

	if (drawObstPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
890
		updateObstaclePredTriVBO();
Thomas Jund's avatar
Thomas Jund committed
891

892
		for(unsigned int i = 0 ; i < m_triObst_Shader.size() ; ++i)
Thomas Jund's avatar
Thomas Jund committed
893 894
		{
			Utils::ShaderSimpleColor* moShader = m_triObst_Shader[i];
pitiot's avatar
up  
pitiot committed
895
			MovingObstacle * mo =simulator.movingObstacles_[i];
Thomas Jund's avatar
Thomas Jund committed
896
			moShader->enableVertexAttribs();
pitiot's avatar
up  
pitiot committed
897
			glDrawArrays(GL_LINE_LOOP, 0, 4*mo->nbVertices);
Thomas Jund's avatar
Thomas Jund committed
898
			moShader->disableVertexAttribs();
Thomas Jund's avatar
Thomas Jund committed
899
		}
pitiot's avatar
pitiot committed
900
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
901
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
902 903

	//draw the environment
David Cazier's avatar
David Cazier committed
904 905
	if (drawEnvLines)
	{
Thomas Jund's avatar
Thomas Jund committed
906 907
		m_simpleColorShader->setColor(Geom::Vec4f(0.5,0.5,0.5,0.));
		m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
908
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
909

David Cazier's avatar
David Cazier committed
910
	if (drawEnvTopo)
pitiot's avatar
pitiot committed
911
	{
Thomas Jund's avatar
Thomas Jund committed
912
		m_renderTopo->drawTopo();
pitiot's avatar
pitiot committed
913

Thomas Jund's avatar
Thomas Jund committed
914
		if (draw_dart && dartSlider < (simulator.envMap_.map.end().index))
pitiot's avatar
pitiot committed
915
				m_renderTopo->overdrawDart(dartSlider,10.0f,0.5f,1.0f,0.5f);
pitiot's avatar
pitiot committed
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931

		if(drawObstacles)
		{
			CGoGN::CellMarkerStore<FACE> m(simulator.envMap_.map) ;
				for (Dart d = simulator.envMap_.map.begin(); d != simulator.envMap_.map.end(); simulator.envMap_.map.next(d))
				{
					if (!m.isMarked(d))
					{
						m.mark(d) ;
						if(simulator.envMap_.obstvect[d].size()!=0)
						{
							drawCell(d,5.0f,0,1.0f,0.5f);
						}
					}
				}
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
932
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
933

pitiot's avatar
maj  
pitiot committed
934 935 936
	if (drawEnvFaces)
	{
		glEnable(GL_POLYGON_OFFSET_FILL) ;
937
		glPolygonOffset(1.0f, -0.5f) ;
Thomas Jund's avatar
Thomas Jund committed
938 939 940
		switch(m_renderStyle)
		{
		case SIMPLE:
Thomas Jund's avatar
Thomas Jund committed
941
#ifdef ONERING
Thomas Jund's avatar
Thomas Jund committed
942
			m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.));
Thomas Jund's avatar
Thomas Jund committed
943
#else
Thomas Jund's avatar
Thomas Jund committed
944
			m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.));
Thomas Jund's avatar
Thomas Jund committed
945
#endif
Thomas Jund's avatar
Thomas Jund committed
946
			m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
pitiot's avatar
maj  
pitiot committed
947

Thomas Jund's avatar
Thomas Jund committed
948 949 950 951 952
#ifdef ONERING
//			m_simpleColorShader->setColor(Geom::Vec4f(1.0,0.8,0.7,0.));
			m_simpleColorShader->setColor(Geom::Vec4f(0.7,0.7,0.75,0.));
			m_renderWithin->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
#endif
Thomas Jund's avatar
Thomas Jund committed
953 954 955 956
			break;
		}
		glDisable(GL_POLYGON_OFFSET_FILL) ;
	}
pitiot's avatar
maj  
pitiot committed
957

Thomas Jund's avatar
Thomas Jund committed
958

David Cazier's avatar
David Cazier committed
959
	++frames ;
pitiot's avatar
maj  
pitiot committed
960 961
	struct timespec realTime ;
	clock_gettime(CLOCK_MONOTONIC, &realTime) ;
pitiot's avatar
stats  
pitiot committed
962
	elapsedTime += timespec_delta(startTime,realTime).tv_nsec ;
963
	clock_gettime(CLOCK_MONOTONIC, &startTime) ;
pitiot's avatar
l  
pitiot committed
964
	float refresh = 1;
965
	if(display_times)
Thomas Jund's avatar
Thomas Jund committed
966
	{
967
		CGoGNout <<CGoGNendl;
pitiot's avatar
stats  
pitiot committed
968 969 970 971 972 973 974
		CGoGNout << "temps mis pour "<<nbIterations<< " : "<< elapsedTime/10000000.0f<<CGoGNendl;
		CGoGNout << "temps mis pour l'affichage : "<< (long int)elapsedTime/10000000.0f - ((time_update)/1000000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour le DoStep : "<< ((time_update)/10000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour les Agents : "<< (( simulator.time_agent)/10000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour les Agents Polygonaux : "<< ((simulator.time_obstacle)/10000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour le Comportement : "<< ((simulator.time_behave)/10000000.0f)<<CGoGNendl;
		CGoGNout << "temps mis pour la multirésolution : "<<((simulator.time_multires)/10000000.0f)<<CGoGNendl;
975 976
		CGoGNout <<CGoGNendl;
		display_times= false;
Thomas Jund's avatar
Thomas Jund committed
977

978
		}
pitiot's avatar
l  
pitiot committed
979
	if (elapsedTime/(1000000000.0f*refresh) >= nextUpdate)
David Cazier's avatar
David Cazier committed
980 981
	{
		// Sortie des stats pour analyse externe
982 983 984
//		std::cout << elapsedTime << ";" << frames << ";" << sim.nbUpdates << ";"
//		    << sim.totalNeighbors << ";" << sim.nearNeighbors << ";" << sim.nbSorts << ";"
//		    << sim.nbRefineCandidate << ";" << sim.nbCoarsenCandidate << std::endl ;
pitiot's avatar
maj  
pitiot committed
985

David Cazier's avatar
David Cazier committed
986 987
		// Affichage des stats dans la barre d'état
		std::ostringstream oss ;
pitiot's avatar
l  
pitiot committed
988 989
		oss << "Elapsed time : " << elapsedTime/(1000000000.0f*refresh);
		oss << " | " << ((float)frames)/refresh << " fps" ;
David Cazier's avatar
David Cazier committed
990
		oss << " | Iterations " << nbIterations ;
David Cazier's avatar
David Cazier committed
991 992 993 994 995 996 997 998 999
		oss << " | Neighbors " << simulator.totalNeighbors
			<< " [" << (simulator.nbUpdates == 0 ? 0 : simulator.totalNeighbors / simulator.nbUpdates) << "]" ;
		oss << " | Near Neighbors " << simulator.nearNeighbors
			<< " [" << (simulator.nbUpdates == 0 ? 0 : simulator.nearNeighbors / simulator.nbUpdates) << "]" ;
		oss << " | Sorts " << simulator.nbSorts
			<< " [" << (simulator.nbUpdates == 0 ? 0 : 100 * simulator.nbSorts / simulator.nbUpdates) << "%]" ;
		oss << " | To Refine " << simulator.nbRefineCandidate ;
		oss << " | To Coarsen " << simulator.nbCoarsenCandidate ;
		if(simulator.detect_agent_collision)
1000
		{
David Cazier's avatar
David Cazier committed
1001
			oss << " | agents morts : "<<simulator.nb_dead;
1002
		}
pitiot's avatar
maj  
pitiot committed
1003 1004 1005
		glColor3f(1.0f, 1.0f, 1.0f) ;
		statusMsg(oss.str().c_str()) ;

David Cazier's avatar
David Cazier committed
1006 1007 1008 1009 1010 1011
		simulator.nbUpdates = 0 ;
		simulator.totalNeighbors = 0 ;
		simulator.nearNeighbors = 0 ;
		simulator.nbSorts = 0 ;
		simulator.nbRefineCandidate = 0 ;
		simulator.nbCoarsenCandidate = 0 ;
David Cazier's avatar
David Cazier committed
1012
		frames = 0 ;
pitiot's avatar
l  
pitiot committed
1013
		nextUpdate = elapsedTime/(1000000000.0f*refresh) + 1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1014
	}
Thomas Jund's avatar
Thomas Jund committed
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034


#ifdef EXPORTING
	fbo.unbind();


	Utils::FBO fbo2( width(), height() );
	int deferedEdgesAttachment = fbo2.createAttachColorTexture( GL_RGBA );
	fbo2.bind();

	glMatrixMode( GL_PROJECTION );
	glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();
	glDisable( GL_LIGHTING );
	glColor3ub( 255, 255, 255 );

	glActiveTexture( GL_TEXTURE0 );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, *fbo.getColorTexId(deferedColorAttachment) );
1035 1036
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
Thomas Jund's avatar
Thomas Jund committed
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109

	glActiveTexture( GL_TEXTURE1 );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, *fbo.getDepthTexId() );
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);

	glActiveTexture( GL_TEXTURE2 );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, *fbo.getColorTexId(deferedNormalAttachment) );


	m_DeferedShader.bind();
	int samplerId = 0;
	m_DeferedShader.setuniformi<1>( "u_FrameBufferColor", &samplerId );
	samplerId = 1;
	m_DeferedShader.setuniformi<1>( "u_FrameBufferDepth", &samplerId );
	samplerId = 2;
	m_DeferedShader.setuniformi<1>( "u_FrameBufferNormal", &samplerId );

	glBegin( GL_QUADS );
		glTexCoord2i( 0, 0 );
		glVertex2i( -1, -1 );
		glTexCoord2i( 1, 0 );
		glVertex2i(  1, -1 );
		glTexCoord2i( 1, 1 );
		glVertex2i(  1,  1 );
		glTexCoord2i( 0, 1 );
		glVertex2i( -1,  1 );
	glEnd();

	m_DeferedShader.unbind();

	fbo2.unbind();




	glActiveTexture( GL_TEXTURE1 );
	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, *fbo2.getColorTexId(deferedEdgesAttachment) );


	m_DeferedShader2.bind();
	samplerId = 0;
	m_DeferedShader2.setuniformi<1>( "u_FrameBufferColor", &samplerId );
	samplerId = 1;
	m_DeferedShader2.setuniformi<1>( "u_FrameBufferEdgeDepth", &samplerId );
	samplerId = 2;
	m_DeferedShader2.setuniformi<1>( "u_FrameBufferNormal", &samplerId );

	glBegin( GL_QUADS );
		glTexCoord2i( 0, 0 );
		glVertex2i( -1, -1 );
		glTexCoord2i( 1, 0 );
		glVertex2i(  1, -1 );
		glTexCoord2i( 1, 1 );
		glVertex2i(  1,  1 );
		glTexCoord2i( 0, 1 );
		glVertex2i( -1,  1 );
	glEnd();

	m_DeferedShader2.unbind();




#endif

	popTransfoMatrix();
Arash HABIBI's avatar
Arash HABIBI committed
1110 1111 1112

	//--------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

pitiot's avatar
merge  
pitiot committed
1113 1114 1115 1116 1117 1118
//	qglviewer::Vec lookfrom, lookat, upvector;
//	qglviewer::Camera* cam = getQGLWidget()->camera();
//	cerr << "---------------------------------------------" << endl;
//	cerr << cam->position()[0] << " "  << cam->position()[1] << " "  << cam->position()[2] << endl;
//	cerr << cam->viewDirection()[0] << " "  << cam->viewDirection()[1] << " "  << cam->viewDirection()[2] << endl;
//	cerr << cam->upVector()[0] << " "  << cam->upVector()[1] << " "  << cam->upVector()[2] << endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
1119 1120
}

pitiot's avatar
pitiot committed
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
void SocialAgents::drawCell(Dart d, float width, float r, float g, float b)
{
	Dart dd = d;
	do{
	m_renderTopo->overdrawDart(dd,width,r,g,b);
	dd=simulator.envMap_.map.phi1(dd);
	}while(dd!=d);

}

Arash HABIBI's avatar
Arash HABIBI committed
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
//------------------------------------------------------------

void SocialAgents::setCameraDebug()
{
	qglviewer::Vec lookfrom, lookat, upvector;
	qglviewer::Camera* cam = getQGLWidget()->camera();

	lookfrom.setValue(-52.2146,-1045.85,557.488);
	lookat.setValue(-47.8132,-957.687,510.494);
	upvector.setValue(-0.000967862, 0.47043, 0.882437);
/*
	lookfrom.setValue(0,0,1000);
	lookat.setValue(0,0,0);
	upvector.setValue(0.5,0.5,0.0);
*/
/*
	lookfrom.setValue(0,-1000,0);
	lookat.setValue(0,0,0);
	upvector.setValue(0.5,0.0,0.5);
*/
	cam->setPosition(lookfrom);
	cam->lookAt(lookat);
	cam->setUpVector(upvector);
}
pitiot's avatar
pitiot committed
1155

Arash HABIBI's avatar
Arash HABIBI committed
1156
//------------------------------------------------------------
pitiot's avatar
pitiot committed
1157

Pierre Kraemer's avatar
Pierre Kraemer committed
1158
void SocialAgents::animate()
Pierre Kraemer's avatar
Pierre Kraemer committed
1159
{
pitiot's avatar
pitiot committed
1160 1161
//	if(simulator.nbSteps_ % simulator.nbStepsPerUnit_ == 0 && (simulator.nbSteps_ / simulator.nbStepsPerUnit_) % 10 == 0)
//		std::cout << round(simulator.globalTime_) << " " << simulator.envMap_.mapMemoryCost() << std::endl;
Thomas's avatar
Thomas committed
1162

pitiot's avatar
pitiot committed
1163 1164
//	if (simulator.nbSteps_ % simulator.nbStepsPerUnit_ == 0 && (simulator.nbSteps_ / simulator.nbStepsPerUnit_) % 10 == 0) std::cout
//	    << round(simulator.globalTime_) << " " << simulator.envMap_.mapMemoryCost() << std::endl ;
David Cazier's avatar
David Cazier committed
1165
//
pitiot's avatar
pitiot committed
1166 1167 1168
//	CityGenerator::animateCity<PFP>(&simulator.envMap_) ;
//	if (CityGenerator::animateCity<PFP>(&simulator.envMap_)) simulator.addPathToCorner() ;
//	simulator.addPathsToAgents() ;
David Cazier's avatar
David Cazier committed
1169
//
Arash HABIBI's avatar
Arash HABIBI committed
1170
//
pitiot's avatar
pitiot committed
1171
//	std::cout << "t : " << nbIterations << std::endl ;
Arash HABIBI's avatar
Arash HABIBI committed
1172
//
David Cazier's avatar
David Cazier committed
1173 1174 1175 1176 1177
//
//	timeval startTime ;
//	gettimeofday(&startTime, NULL) ;
//	timeval endTime ;
//	long seconds, nseconds ;
Thomas's avatar
Thomas committed
1178

David Cazier's avatar
David Cazier committed
1179
	nbIterations++ ;
pitiot's avatar
merging  
pitiot committed
1180

Arash HABIBI's avatar
Arash HABIBI committed
1181 1182
	// setCameraDebug();

pitiot's avatar
pitiot committed
1183

pitiot's avatar
merging  
pitiot committed
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
	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);
	}
pitiot's avatar
pitiot committed
1212

David Cazier's avatar
David Cazier committed
1213 1214
	if (maxIterations > 0 && nbIterations > maxIterations)
	{
pitiot's avatar
up  
pitiot committed
1215
//		std::cout << "t : " << simulator.globalTime_ << std::endl ;
David Cazier's avatar
David Cazier committed
1216
		timer->stop() ;
pitiot's avatar
stats  
pitiot committed
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
		if (filename != NULL)
		{
			if (percent) filename<<"_percent";

			std::stringstream datas;
			datas<<"stats/"<<filename.str().c_str()<<".dat";

			std::stringstream gnuplots;
			gnuplots<<"stats/"<<filename.str().c_str()<<".plt";

			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);
			float rendu = 0/*(float)elapsedTime - (((float)time_update)/CLOCKS_PER_SEC)*/ ;
			float multi = ((simulator.time_multires)/1000000000.0f);;
			float sum = multi +upAgent+upObst+behaviour+rendu;

			if(percent)
			{
				multi = (multi/sum)*100;
				upAgent=(upAgent/sum)*100;
				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

			if(fichier)  // si l'ouverture a réussi
			{
				// instructions


				fichier<<"#Multires\tMaJ des agents\tMaJ des obstacles\tComportement\tRendu"<<endl;
				fichier<<0<<" "<<multi<<" "<<upAgent<<" "<<upObst<<" "<<behaviour<<" "<<rendu<<endl;
				fichier.close();

			}
			else  // sinon
			{
					cerr << "Erreur à l'ouverture !" << endl;
			}
			ofstream plot(gnuplot.c_str(), ios::out | ios::trunc);  //déclaration du flux et ouverture du fichier
			if(plot)  // si l'ouverture a réussi
			{

				plot<<"set title '"<<maxIterations<<" itérations scénario "<<name.str().c_str()<<" "<<simulator.agents_.size()<<" agents "<<simulator.movingObstacles_.size()<<" agents polygonaux'"<<endl;
				plot<<"set xtics ('' -1)"<<endl;
				if(percent)
				{
					plot<<"set terminal svg"<<endl<<"set output 'stats/svg/"<<filename.str().c_str()<<".svg'"<<endl<<"set key top right"<<endl<<"set boxwidth 0.5"<<endl<<
							"set ylabel 'Percent of ressource'"<<endl<<"set style fill solid border -1"<<endl<<"set xrange [-1:2]"<<endl<<"set yrange [0:105]"<<endl<<
							"plot '"<<data<<"' using 1:($2+$3+$4+$5+$6) with boxes title 'Multires','"<<data<<"' using 1:($3+$4+$5+$6) with boxes title 'MaJ Agent','"<<data<<
							"' using 1:($4+$5+$6) with boxes title 'MaJ Agents polgonaux','"<<data<<"' using 1:($5+$6) with boxes title 'Comportement'"<<endl<<"#,'"
							<<data<<"' using 1:6 with boxes title 'Rendu'";
				}
				else
				{
					plot<<"set terminal svg"<<endl<<"set output 'stats/svg/"<<filename.str().c_str()<<".svg'"<<endl<<"set key top right"<<endl<<"set boxwidth 0.5"<<endl<<
					"set ylabel 'time ressource in sec'"<<endl<<"set style fill solid border -1"<<endl<<"set xrange [-1:2]"<<endl<<"set yrange [0:"<<sum+(2*sum/100)<<"]"<<endl<<
					"plot '"<<data<<"' using 1:($2+$3+$4+$5+$6) with boxes title 'Multires','"<<data<<"' using 1:($3+$4+$5+$6) with boxes title 'MaJ Agent','"<<data<<
					"' using 1:($4+$5+$6) with boxes title 'MaJ Agents polgonaux','"<<data<<"' using 1:($5+$6) with boxes title 'Comportement'"<<endl<<"#,'"
					<<data<<"' using 1:6 with boxes title 'Rendu'";
				}

				plot.close();
			}
			else  // sinon
					cerr << "Erreur à l'ouverture !" << endl;
		}

David Cazier's avatar
David Cazier committed
1291 1292
		exit(0) ;
	}
pitiot's avatar
stats  
pitiot committed
1293
		struct timespec begTime ;
pitiot's avatar
pitiot committed
1294 1295 1296
		int nb_max=2;
//		if (nbIterations>9000) nb_max=2;
//		else nb_max=10000;
pitiot's avatar
stats  
pitiot committed
1297
		clock_gettime(CLOCK_MONOTONIC, &begTime) ;
pitiot's avatar
pitiot committed
1298 1299
		for(int n =1; n<nb_max; n++)
			simulator.doStep() ;
pitiot's avatar
stats  
pitiot committed
1300 1301 1302
		struct timespec endTime ;
		clock_gettime(CLOCK_MONOTONIC, &endTime) ;

pitiot's avatar
pitiot committed
1303
		time_update += timespec_delta(begTime,endTime).tv_nsec/nb_max;
Pierre Kraemer's avatar
Pierre Kraemer committed
1304

Thomas Jund's avatar
Thomas Jund committed
1305 1306 1307 1308 1309 1310 1311 131