Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

viewer.cpp 66.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),
Thomas Jund's avatar
Thomas Jund committed
44
45
	drawEnvLines(false),
	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);

Arash HABIBI's avatar
Arash HABIBI 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
286
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

#ifdef EXPORTING

#if 1
	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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
	std::vector<std::string> attrNames ;
	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"))
			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
399
400
// 	m_shaderTexAgent = new ShaderCustomTex();
	m_shaderTexAgent = new ShaderPhongTexCust();
Thomas Jund's avatar
Thomas Jund committed
401
402
403
404
	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
405
406
407
408
409
		
	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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

	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);
428
#endif
Thomas Jund's avatar
Thomas Jund committed
429

pitiot's avatar
pitiot committed
430
#ifdef EXPORTING_AGENT
Thomas Jund's avatar
Thomas Jund committed
431
432
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
Thomas Jund's avatar
merge  
Thomas Jund committed
433
			simulator.agents_[i]->initGL();
Thomas Jund's avatar
Thomas Jund committed
434
435
436
437
//
//#ifdef EXPORTING_OBJ
//			registerShader(simulator.agents_[i]->m_shaderTex);
//#endif
438
439
440
			registerShader(simulator.agents_[i]->m_ghost_shader);
		}
#endif
441
442
443
444
445
446
447
448
//	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
449
450
451
452
453
454
455
456
457
458
459
460
461
}

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
462

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

void SocialAgents::updateObstaclePredTriVBO()
{
pitiot's avatar
pitiot committed
469
//	CGoGNout<<"update"<<CGoGNendl;
Thomas Jund's avatar
Thomas Jund committed
470
471
472
473
474
	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
475
476
477
478
479
		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
480

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

pitiot's avatar
up  
pitiot committed
484
485
			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
486

487
488

		}
Thomas Jund's avatar
Thomas Jund committed
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
		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
515
516
517
518
519
520
521
522
523
524
525
526
#ifdef ONERING
	CellMarker<FACE> cmF(simulator.envMap_.map);
	TraversorF<PFP::MAP> tF(simulator.envMap_.map);
	for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next())
	{
		if(simulator.envMap_.neighborObstvect[d].size() > 0 && !(simulator.envMap_.obstvect[d].size()>0))
			cmF.mark(d);
	}

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

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

Thomas Jund's avatar
Thomas Jund committed
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
	simulator.envMap_.map.setBrowser(NULL);

	CellMarker<FACE> cmF2(simulator.envMap_.map);
	TraversorF<PFP::MAP> tF2(simulator.envMap_.map);
	for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next())
	{
		if(simulator.envMap_.obstvect[d].size() > 0)
		{
			cmF2.mark(d);
		}
	}

	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
555
	if(upType & Algo::Render::GL2::LINES)
Sylvain Thery's avatar
Sylvain Thery committed
556
		m_render->initPrimitives<PFP>(simulator.envMap_.map, Algo::Render::GL2::LINES,false) ;
Thomas Jund's avatar
Thomas Jund committed
557
558

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

Arash HABIBI's avatar
Arash HABIBI committed
562
563
564
565
566
//-----------------------------------
// 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
567
568
//static void drawEllipse(VEC3 F1, VEC3 F2, float s, int N)
//{
Thomas Jund's avatar
Thomas Jund committed
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
//	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
600
601
602
603
604
605
606
607
608
609
610
//	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
611
//}
Arash HABIBI's avatar
Arash HABIBI committed
612
613
614

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

Thomas Jund's avatar
Thomas Jund committed
615
616
617
618
619
620
621
622
623
624
625
626
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]);

627
628
629
630
631
632
633
634
635
636
637
638
//	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
639
640
641
642

	updateGLMatrices();
}

Pierre Kraemer's avatar
Pierre Kraemer committed
643
644
void SocialAgents::cb_redraw()
{
Thomas Jund's avatar
Thomas Jund committed
645
646
647
648
649
650
651
652
653
654
655
656
657
658
	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
659
//	glEnable(GL_CULL_FACE);
Thomas Jund's avatar
Thomas Jund committed
660
661
662
663
664
	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
665

Thomas Jund's avatar
Thomas Jund committed
666
667
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
	glEnable(GL_LIGHTING);
pitiot's avatar
maj  
pitiot committed
668

669
	glEnable( GL_MULTISAMPLE );
670
	simulator.envMap_.draw();
Thomas Jund's avatar
Thomas Jund committed
671

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

David Cazier's avatar
David Cazier committed
674
675
	if (drawAgents)
	{
Thomas Jund's avatar
Thomas Jund committed
676
#ifdef EXPORTING_OBJ
Thomas Jund's avatar
Thomas Jund committed
677
678
679
680
681
682
683
684
685
686
687
		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
688
#else
Thomas Jund's avatar
Thomas Jund committed
689
690
691
692
693
694
695
		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
696

Thomas Jund's avatar
Thomas Jund committed
697
698
699
700
701
		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
702
#endif
Thomas Jund's avatar
Thomas Jund committed
703

Thomas Jund's avatar
Thomas Jund committed
704
#ifdef EXPORTING_AGENT
705
706
707
708
709
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
		{
			simulator.agents_[i]->draw();
		}
#endif
Thomas Jund's avatar
Thomas Jund committed
710

711
712
713
714
		if(target_Agent)
		{
			glDisable(GL_LIGHTING);
			VEC3 pos =simulator.agents_[agentSlider]->part_.getPosition();
Thomas Jund's avatar
Thomas Jund committed
715
			m_ds->newList(GL_COMPILE_AND_EXECUTE);
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
			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
731
	}
pitiot's avatar
up  
pitiot committed
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
	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));
748

pitiot's avatar
up  
pitiot committed
749
750
751
		m_ds->end();
		m_ds->endList();
	}
pitiot's avatar
maj  
pitiot committed
752
753
	if (drawMovingObstacles)
	{
Thomas Jund's avatar
Thomas Jund committed
754
#ifdef SHADOWSHELL
755
		updateObstacleVBO();
Thomas Jund's avatar
Thomas Jund committed
756
#endif
Thomas Jund's avatar
Thomas Jund committed
757
758
759

		for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i)
		{
Thomas Jund's avatar
Thomas Jund committed
760
#ifdef SHADOWSHELL
pitiot's avatar
up  
pitiot committed
761
			if(simulator.movingObstacles_[i]->index==12){
pitiot's avatar
pitiot committed
762
763
				Utils::ShaderFlat* moShader = m_obstShader[i];

Thomas Jund's avatar
Thomas Jund committed
764
765
766
767
//			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.));

768
769
770
			moShader->enableVertexAttribs();
			glDrawArrays(GL_POLYGON, 0, simulator.movingObstacles_[i]->nbVertices);
			moShader->disableVertexAttribs();
pitiot's avatar
pitiot committed
771
			}
Thomas Jund's avatar
Thomas Jund committed
772
#endif
773

774
#ifdef EXPORTING_BOXES
Thomas Jund's avatar
Thomas Jund committed
775
			simulator.movingObstacles_[i]->draw(drawObstPath);
776
#endif
Thomas Jund's avatar
Thomas Jund committed
777
		}
Arash HABIBI's avatar
Arash HABIBI committed
778
779
780
781

		// Commente par Arash (Pourquoi ?)
		for (std::vector<MovingMesh*>::iterator it = simulator.movingMeshes_.begin() ; it != simulator.movingMeshes_.end() ; ++it)
			(*it)->draw();
pitiot's avatar
maj  
pitiot committed
782
783
784

	}

Pierre Kraemer's avatar
Pierre Kraemer committed
785
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
786
787
	if (drawAgentsPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
788
789
790
		updateAgentPredTriVBO();

		for(unsigned int i = 0 ; i < simulator.agents_.size() ; ++i)
David Cazier's avatar
David Cazier committed
791
		{
Thomas Jund's avatar
Thomas Jund committed
792
793
794
795
796
			Utils::ShaderSimpleColor* agShader = m_triAgent_Shader[i];

			agShader->enableVertexAttribs();
			glDrawArrays(GL_LINE_LOOP, 0, 3);
			agShader->disableVertexAttribs();
Pierre Kraemer's avatar
Pierre Kraemer committed
797
798
		}
	}
pitiot's avatar
pitiot committed
799
800
801

	if (drawObstPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
802
		updateObstaclePredTriVBO();
Thomas Jund's avatar
Thomas Jund committed
803

804
		for(unsigned int i = 0 ; i < m_triObst_Shader.size() ; ++i)
Thomas Jund's avatar
Thomas Jund committed
805
806
		{
			Utils::ShaderSimpleColor* moShader = m_triObst_Shader[i];
pitiot's avatar
up  
pitiot committed
807
			MovingObstacle * mo =simulator.movingObstacles_[i];
Thomas Jund's avatar
Thomas Jund committed
808
			moShader->enableVertexAttribs();
pitiot's avatar
up  
pitiot committed
809
			glDrawArrays(GL_LINE_LOOP, 0, 4*mo->nbVertices);
Thomas Jund's avatar
Thomas Jund committed
810
			moShader->disableVertexAttribs();
Thomas Jund's avatar
Thomas Jund committed
811
		}
pitiot's avatar
pitiot committed
812
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
813
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
814
815

	//draw the environment
David Cazier's avatar
David Cazier committed
816
817
	if (drawEnvLines)
	{
Thomas Jund's avatar
Thomas Jund committed
818
819
		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
820
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
821

David Cazier's avatar
David Cazier committed
822
	if (drawEnvTopo)
pitiot's avatar
pitiot committed
823
	{
Thomas Jund's avatar
Thomas Jund committed
824
		m_renderTopo->drawTopo();
pitiot's avatar
pitiot committed
825

Thomas Jund's avatar
Thomas Jund committed
826
827
		if (draw_dart && dartSlider < (simulator.envMap_.map.end().index))
				m_renderTopo->overdrawDart(dartSlider,5.0f,0,1.0f,0.5f);
Pierre Kraemer's avatar
Pierre Kraemer committed
828
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
829

pitiot's avatar
maj  
pitiot committed
830
831
832
	if (drawEnvFaces)
	{
		glEnable(GL_POLYGON_OFFSET_FILL) ;
833
		glPolygonOffset(1.0f, -0.5f) ;
Thomas Jund's avatar
Thomas Jund committed
834
835
836
		switch(m_renderStyle)
		{
		case SIMPLE:
Thomas Jund's avatar
Thomas Jund committed
837
#ifdef ONERING
Thomas Jund's avatar
Thomas Jund committed
838
			m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.));
Thomas Jund's avatar
Thomas Jund committed
839
#else
Thomas Jund's avatar
Thomas Jund committed
840
			m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.));
Thomas Jund's avatar
Thomas Jund committed
841
#endif
Thomas Jund's avatar
Thomas Jund committed
842
			m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
pitiot's avatar
maj  
pitiot committed
843

Thomas Jund's avatar
Thomas Jund committed
844
845
846
847
848
#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
849
850
851
852
			break;
		}
		glDisable(GL_POLYGON_OFFSET_FILL) ;
	}
pitiot's avatar
maj  
pitiot committed
853

Thomas Jund's avatar
Thomas Jund committed
854

David Cazier's avatar
David Cazier committed
855
	++frames ;
pitiot's avatar
maj  
pitiot committed
856
857
	struct timespec realTime ;
	clock_gettime(CLOCK_MONOTONIC, &realTime) ;
pitiot's avatar
stats  
pitiot committed
858
	elapsedTime += timespec_delta(startTime,realTime).tv_nsec ;
859
	clock_gettime(CLOCK_MONOTONIC, &startTime) ;
pitiot's avatar
l  
pitiot committed
860
	float refresh = 1;
861
	if(display_times)
Thomas Jund's avatar
Thomas Jund committed
862
	{
863
		CGoGNout <<CGoGNendl;
pitiot's avatar
stats  
pitiot committed
864
865
866
867
868
869
870
		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;
871
872
		CGoGNout <<CGoGNendl;
		display_times= false;
Thomas Jund's avatar
Thomas Jund committed
873

874
		}
pitiot's avatar
l  
pitiot committed
875
	if (elapsedTime/(1000000000.0f*refresh) >= nextUpdate)
David Cazier's avatar
David Cazier committed
876
877
	{
		// Sortie des stats pour analyse externe
878
879
880
//		std::cout << elapsedTime << ";" << frames << ";" << sim.nbUpdates << ";"
//		    << sim.totalNeighbors << ";" << sim.nearNeighbors << ";" << sim.nbSorts << ";"
//		    << sim.nbRefineCandidate << ";" << sim.nbCoarsenCandidate << std::endl ;
pitiot's avatar
maj  
pitiot committed
881

David Cazier's avatar
David Cazier committed
882
883
		// Affichage des stats dans la barre d'état
		std::ostringstream oss ;
pitiot's avatar
l  
pitiot committed
884
885
		oss << "Elapsed time : " << elapsedTime/(1000000000.0f*refresh);
		oss << " | " << ((float)frames)/refresh << " fps" ;
David Cazier's avatar
David Cazier committed
886
		oss << " | Iterations " << nbIterations ;
David Cazier's avatar
David Cazier committed
887
888
889
890
891
892
893
894
895
		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)
896
		{
David Cazier's avatar
David Cazier committed
897
			oss << " | agents morts : "<<simulator.nb_dead;
898
		}
pitiot's avatar
maj  
pitiot committed
899
900
901
		glColor3f(1.0f, 1.0f, 1.0f) ;
		statusMsg(oss.str().c_str()) ;

David Cazier's avatar
David Cazier committed
902
903
904
905
906
907
		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
908
		frames = 0 ;
pitiot's avatar
l  
pitiot committed
909
		nextUpdate = elapsedTime/(1000000000.0f*refresh) + 1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
910
	}
Thomas Jund's avatar
Thomas Jund committed
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930


#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) );
931
932
	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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005

	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();
Pierre Kraemer's avatar
Pierre Kraemer committed
1006
1007
}

Pierre Kraemer's avatar
Pierre Kraemer committed
1008
void SocialAgents::animate()
Pierre Kraemer's avatar
Pierre Kraemer committed
1009
{
pitiot's avatar
pitiot committed
1010
1011
//	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
1012

pitiot's avatar
pitiot committed
1013
1014
//	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
1015
//
pitiot's avatar
pitiot committed
1016
1017
1018
//	CityGenerator::animateCity<PFP>(&simulator.envMap_) ;
//	if (CityGenerator::animateCity<PFP>(&simulator.envMap_)) simulator.addPathToCorner() ;
//	simulator.addPathsToAgents() ;
David Cazier's avatar
David Cazier committed
1019
//
Thomas Jund's avatar
merge  
Thomas Jund committed
1020

pitiot's avatar
pitiot committed
1021
//	std::cout << "t : " << simulator.globalTime_ << std::endl ;
David Cazier's avatar
David Cazier committed
1022
1023
1024
1025
1026
//
//	timeval startTime ;
//	gettimeofday(&startTime, NULL) ;
//	timeval endTime ;
//	long seconds, nseconds ;
Thomas's avatar
Thomas committed
1027

David Cazier's avatar
David Cazier committed
1028
	nbIterations++ ;
Arash HABIBI's avatar
Arash HABIBI committed
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058

	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);
	}

David Cazier's avatar
David Cazier committed
1059
1060
	if (maxIterations > 0 && nbIterations > maxIterations)
	{
pitiot's avatar
up  
pitiot committed
1061
//		std::cout << "t : " << simulator.globalTime_ << std::endl ;
David Cazier's avatar
David Cazier committed
1062
		timer->stop() ;
pitiot's avatar
stats  
pitiot committed
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
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
		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
1137
1138
		exit(0) ;
	}
pitiot's avatar
stats  
pitiot committed
1139
1140
		struct timespec begTime ;
		clock_gettime(CLOCK_MONOTONIC, &begTime) ;
1141

Arash HABIBI's avatar
Arash HABIBI committed
1142
		simulator.doStep() ;
pitiot's avatar
stats  
pitiot committed
1143
1144
1145
1146
		struct timespec endTime ;
		clock_gettime(CLOCK_MONOTONIC, &endTime) ;

		time_update += timespec_delta(begTime,endTime).tv_nsec;
Pierre Kraemer's avatar
Pierre Kraemer committed
1147

Thomas Jund's avatar
Thomas Jund committed
1148
1149
1150
1151
1152
1153
1154
1155
1156
	m_positionVBO->updateData(simulator.envMap_.position);

	if (drawEnvFaces)
		updateVBOprimitives(Algo::Render::GL2::TRIANGLES);

	if (drawEnvLines)
		updateVBOprimitives(Algo::Render::GL2::LINES);

	if(drawEnvTopo)
Sylvain Thery's avatar
Sylvain Thery committed
1157
		m_renderTopo->updateData<PFP>(simulator.envMap_.map, simulator.envMap_.position, 0.9, 0.9);
Thomas Jund's avatar
Thomas Jund committed
1158

David Cazier's avatar
David Cazier committed
1159
1160
1161
//	gettimeofday(&endTime, NULL) ;
//	seconds = endTime.tv_sec - startTime.tv_sec ;
//	nseconds = endTime.tv_usec - startTime.tv_usec ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1162
//
David Cazier's avatar
David Cazier committed
1163
1164
1165
//	elapsedTime += (seconds + nseconds / 1000000.0) ;
//
//	if (sim.globalTime_ - int(sim.globalTime_) == 0.0f && int(sim.globalTime_) % 1500 == 0)
Thomas's avatar
Thomas committed
1166
//	{
David Cazier's avatar
David Cazier committed
1167
1168
//		std::cout << "end " << elapsedTime << std::endl ;
//		timer->stop() ;
Thomas's avatar
Thomas committed
1169
//	}
David Cazier's avatar
David Cazier committed
1170
//
pitiot's avatar
pitiot committed
1171
//	if (simulator.reachedGoal())
1172
//	{
David Cazier's avatar
David Cazier committed
1173
1174
//		std::cout << "end " << elapsedTime << std::endl ;
//		timer->stop() ;
1175
//	}
Thomas's avatar
Thomas committed
1176

Pierre Kraemer's avatar
Pierre Kraemer committed
1177
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
1178
1179
	if (render_anim)
	{
Thomas Jund's avatar
Thomas Jund committed
1180
		if(nbIterations%4==0)
1181
		{
Arash HABIBI's avatar
Arash HABIBI committed
1182
1183
			// getQGLWidget()->resize(800,600);
			getQGLWidget()->resize(1024,768);
1184
1185
1186
1187
1188
1189
1190
1191
			updateGL() ;
//			getQGLWidget()->setSnapshotQuality(100);

			std::ostringstream tmpNb ;
			unsigned int counter = getQGLWidget()->snapshotCounter();
			tmpNb << std::setfill('0') << std::setw(5) << counter ;

			getQGLWidget()->setSnapshotCounter(++counter);
Thomas Jund's avatar
Thomas Jund committed
1192
1193
1194
//			QString filename("./export/meshCercleBA" );
//			QString filename("./export/meshCorridorBA" );
//			QString filename("./export/oneRing" );
Arash HABIBI's avatar
Arash HABIBI committed
1195
			QString filename("./export/scenario3." );
1196
1197
1198
1199
1200
1201
1202
1203
1204
			filename.append((tmpNb.str()).c_str());
			filename.append(".png");
//			getQGLWidget()->setSnapshotFileName(filename);
//			getQGLWidget()->setSnapshotFormat(QString("PNG"));
			QImage image = getQGLWidget()->grabFrameBuffer ();
			if( !image.save( filename, "PNG" ) )
			{
			  QMessageBox::warning( this, "Save Image", "Error saving image." );
			}
Jund Thomas's avatar
Jund Thomas committed
1205

Thomas Jund's avatar
Thomas Jund committed
1206
			if (nbIterations >= 20000)
1207
1208
1209
1210
			{
				std::cout << "enough .png generated" << std::endl ;
				exit(0) ;
			}
Jund Thomas's avatar
Jund Thomas committed
1211

Thomas Jund's avatar
Thomas Jund committed
1212
1213
			if(nbIterations % 1000 == 0)
				std::cout << "image " << nbIterations << std::endl;
1214
		}
Thomas Jund's avatar
Thomas Jund committed
1215

1216
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
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
//		std::ostringstream oss ;
//		std::ostringstream tmpNb ;
//		tmpNb << std::setfill('0') << std::setw(5) << nbGeneratedPov ;
////		oss << "./DeCirkelMesh/meshCercle" << tmpNb.str() << ".pov" ;
//		oss << "./DeCorridorMesh/meshCorrida" << tmpNb.str() << ".pov" ;
//		std::string chaine = oss.str() ;
////		VEC3 agPos = sim.agents_[0]->meanPos_ ;
////		agPos[2] = agPos[1] ;
////		agPos[1] = 0.0f ;
////		VEC3 camPos(agPos) ;
////		VEC3 camLook(agPos) ;
//
////		camPos = camPos
////		    + VEC3(-10 - 0.05 * nbGenerated, 30 + 0.05 * nbGenerated,
////		           log(1.0f + nbGenerated / 700.0f)) ;
//
////travelling city nbMaxAgent 15000, nbSquare 40 (45?)
////		VEC3 camPos(-800, 10, -800) ;
////		camPos = camPos
////		    + VEC3(-10 - 0.3 * nbGenerated, 30 + 0.3 * nbGenerated,
////		           400.0f * log(1.0f + nbGenerated / 700.0f)) ;
////		VEC3 camLook(0, 0, 0) ;
////		camLook = camLook
////		    + VEC3(-10 - 0.1 * nbGenerated, 30 + 0.1 * nbGenerated,
////		           400.0f * log(1.0f + nbGenerated / 700.0f)) ;
//
////travelling horizontal
////		VEC3 camPos(0, 5, -200) ;
////		camPos = camPos + VEC3(-10 - 0.15 * nbGenerated, 0, 0) ;
////		VEC3 camLook = camPos ;
////		camLook[0] += 0.15 * nbGenerated ;
////		camLook[2] += 100 ;
////		camLook[1] = 0 ;
//
////vertical view
////		VEC3 camPos(0, 300, 0) ;
////		Geom::BoundingBox<VEC3> bb = simulator.getAgentsBB() ;
////		VEC3 seeEveryone = bb.max() - bb.min() ;
////		if (seeEveryone[0] > 200)
////			camPos[1] += seeEveryone[0] ;
////		else
////			camPos[1] += 200 ;
////		VEC3 camLook(0) ;
//
////video intro
////		VEC3 camPos(-20, 10, 75) ;
////		VEC3 camLook(-25, 0, 0) ;
//
////mall
////		VEC3 camPos(-500, 500, -400) ;
////		VEC3 camLook(100, 100, 0) ;
//
////openStreetMap
////		VEC3 camPos(500, 75, 400) ;
////		VEC3 camLook(-250, 0, 650) ;
//
////pathDyn
////		VEC3 camPos(-700, 700, -1800) ;
////		VEC3 camLook(200, 0, 0) ;
//
////corridor side
////		VEC3 camPos(-700, 100, 0) ;
////		VEC3 camLook(200, 0, 0) ;
//
////corridor top
////		VEC3 camPos(0, 300, 0) ;
////		VEC3 camLook(0, 0, 0) ;
//
////corridor take2
////		VEC3 camPos(-350, 200, 0) ;
////		VEC3 camLook(0, 0, 0) ;
//
////openStreetMap mapRoad & mapBuildings
////		VEC3 camPos(-200, 100, 500) ;
////		VEC3 camLook(1000, 0, 0) ;
//
////openStreetMap sphere
////		VEC3 camPos(-200, 100, 500) ;
////		VEC3 camLook(100, 0, 0) ;
//
////		//diligences / Cercle
////		VEC3 camPos(0, 300, 750) ;
////		VEC3 camLook(0, 0, 0) ;
//
//		//corridor
Thomas Jund's avatar
Thomas Jund committed
1301
1302
//		VEC3 camPos(0, 300, 750) ;
//		VEC3 camLook(0, 0, 0) ;
pitiot's avatar
up  
pitiot committed
1303
//
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
//
////		if(nbIterations%2==0)
////		{
////			exportScenePov(simulator.envMap_.map,simulator.envMap_.position,chaine,camPos,camLook,VEC3(0.0f,0,0),0,0,0);
////			// 		exportScenePov(sim.envMap_.map,sim.envMap_.position,chaine,VEC3(43,762,65),VEC3(0,762,0),VEC3(1.0f,0,0),0,0,0);
////		//		exportScenePov(sim.envMap_.map,sim.envMap_.position,chaine,VEC3(43,762,65+(1500.0f*float(nbGenerated)/400.0f)),VEC3(0,762,0),VEC3(1.0f,0,0),0,0,0);
////			nbGeneratedPov++;
////		}
////
////		if (nbIterations >= 20000)
////		{
////			std::cout << "enough .pov generated" << std::endl ;
////			exit(0) ;
////		}
Pierre Kraemer's avatar
Pierre Kraemer committed
1318
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
1319
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
1320

1321
	updateGL() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1322
}
1323

Pierre Kraemer's avatar
Pierre Kraemer committed
1324
#ifndef SPATIAL_HASHING
Thomas's avatar
Thomas committed
1325
1326
1327
void SocialAgents::exportInfoFace(std::ofstream& out, Dart d)
{
	//get corner
1328
	Dart dd = d ;
David Cazier's avatar
David Cazier committed
1329
	VEC3 cornerLeftBottom = simulator.envMap_.position[d] ;
David Cazier's avatar
David Cazier committed
1330
1331
	do
	{
David Cazier's avatar
David Cazier committed
1332
		VEC3 p = simulator.envMap_.position[dd] ;
1333
1334
1335
		if (cornerLeftBottom[0] > p[0]) cornerLeftBottom[0] = p[0] ;
		if (cornerLeftBottom[1] > p[1]) cornerLeftBottom[1] = p[1] ;
		if (cornerLeftBottom[2] > p[2]) cornerLeftBottom[2] = p[2] ;
David Cazier's avatar
David Cazier committed
1336
		dd = simulator.envMap_.map.phi1(dd) ;
1337
	} while (dd != d) ;
Thomas's avatar
Thomas committed
1338
1339

	//draw text
David Cazier's avatar
David Cazier committed
1340
	if (!simulator.envMap_.buildingMark.isMarked(d))
David Cazier's avatar
David Cazier committed
1341
	{
1342
1343
		out << "object {" << std::endl ;
		out << "polygon { 4 , <0,0,0>, <11,0,0>, <11,0,6>, <0,0,6> }" << std::endl ;
pitiot's avatar
maj  
pitiot committed
1344
1345
		out << "texture { pigment{ color rgb<0,1,1> } finish { ambient 1 diffuse 0 } }" << std::endl;
		out << "translate < " << cornerLeftBottom[0]+5 << "," << cornerLeftBottom[2]+2 << "," << cornerLeftBottom[1]+7 << ">" << std::endl;
1346
1347
1348
1349
		out << "}" << std::endl ;

		out << "object {" << std::endl ;
		out << "polygon { 4 , <0,0,0>, <17,0,0>, <17,0,6>, <0,0,6> }" << std::endl ;
pitiot's avatar
maj  
pitiot committed
1350
1351
		out << "texture { pigment{ color rgb<0.25,1,0> } finish { ambient 1 diffuse 0 } }" << std::endl;
		out << "translate < " << 12+cornerLeftBottom[0]+5 << "," << cornerLeftBottom[2]+2 << "," << cornerLeftBottom[1]+7 << ">" << std::endl;
1352
		out << "}" << std::endl ;
Thomas's avatar
Thomas committed
1353
1354
1355
1356
	}

	//draw vectors
	//contains
David Cazier's avatar
David Cazier committed
1357
	for (unsigned int i = 0 ; i < simulator.envMap_.agentvect[d].size() ; ++i)
David Cazier's avatar
David Cazier committed
1358
	{
David Cazier's avatar
David Cazier committed
1359
		Agent * ag = simulator.envMap_.agentvect[d][i] ;
1360
1361

		int j = 0 ;
David Cazier's avatar
David Cazier committed
1362
		for (unsigned int iA = 0 ; iA < simulator.agents_.size() ; ++iA)
David Cazier's avatar
David Cazier committed
1363
		{
David Cazier's avatar
David Cazier committed
1364
			if (simulator.agents_[iA] == ag)
David Cazier's avatar
David Cazier committed
1365
			{
1366
1367
				j = iA ;
				break ;
Thomas's avatar
Thomas committed
1368
1369
1370
			}
		}

1371
		out << "cylinder {" << " <0,0,0>, <0,6,0>, 1.5 " << std::endl ;
Thomas's avatar
Thomas committed
1372

1373
		out << "scale 0.5" << std::endl ;
Thomas's avatar
Thomas committed
1374

David Cazier's avatar
David Cazier committed
1375
		VEC3 col = Utils::color_map_BCGYR(float(j) / float(simulator.agents_.size())) ;
pitiot's avatar
maj  
pitiot committed
1376
		out << "pigment { color <" << col[0]  << "," << col[1] << "," << col[2]<< "> }" << std::endl;
Thomas's avatar
Thomas committed
1377

David Cazier's avatar
David Cazier committed
1378
1379
//		VEC3 pBase(ag->getPosition()) ;
//		VEC3 posR(pBase) ;
Thomas's avatar
Thomas committed
1380
//
pitiot's avatar
pitiot committed
1381
1382
//		Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(simulator.envMap_.map, ag->part_.d,
//		                                                         simulator.envMap_.position) ;
David Cazier's avatar
David Cazier committed
1383
1384
//		posR[2] -= 1000 ;
//		Geom::intersectionPlaneRay(pl, posR, VEC3(0, 0, -1), posR) ;
Thomas's avatar
Thomas committed
1385
//
David Cazier's avatar
David Cazier committed
1386
//		VEC3 dir = ag->meanDirection_ ;
David Cazier's avatar
David Cazier committed
1387
1388
1389
//		VEC3 base(0, -1, 0) ;
//		VEC3 axisRot = base ^ dir ;
//		int sign = axisRot[2] > 0 ? 1 : -1 ;
Thomas's avatar
Thomas committed
1390
//
David Cazier's avatar
David Cazier committed
1391
1392
1393
//		57, 2957795
//		: conversion from radian to degree
//		float myRot = acos(-dir[1])*57.2957795f ;
Thomas's avatar
Thomas committed
1394
//
David Cazier's avatar
David Cazier committed
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
//		out << "rotate <0,0," << sign * myRot << ">" << std::endl ;
//		out << "rotate <" << -90 << "," << 0 << "," << 0 << "> " << std::endl ;
		if (i < 5)
			out << "translate < " << cornerLeftBottom[0] + 5 + 1 + i * 2 << ","
			    << cornerLeftBottom[2] + 2 << "," << cornerLeftBottom[1] + 7 + 1.5 << ">"
			    << std::endl ;
		else
			out << "translate < " << cornerLeftBottom[0] + 5 + 1 + (i - 5) * 2 << ","
			    << cornerLeftBottom[2] + 2 << "," << cornerLeftBottom[1] + 7 + 1.5 + 3 << ">"
			    << std::endl ;
1405
1406

		out << "}" << std::endl ;
Thomas's avatar
Thomas committed
1407
1408
1409
	}

	//neighbours
David Cazier's avatar
David Cazier committed
1410
	for (unsigned int i = 0 ; i < simulator.envMap_.neighborAgentvect[d].size() ; ++i)
David Cazier's avatar
David Cazier committed
1411
	{
David Cazier's avatar
David Cazier committed
1412
		Agent * ag = simulator.envMap_.neighborAgentvect[d][i] ;
1413
1414

		int j = 0 ;
David Cazier's avatar
David Cazier committed
1415
		for (unsigned int iA = 0 ; iA < simulator.agents_.size() ; ++iA)
David Cazier's avatar
David Cazier committed
1416
		{
David Cazier's avatar
David Cazier committed
1417
			if (simulator.agents_[iA] == ag)
David Cazier's avatar
David Cazier committed
1418
			{
1419
1420
				j = iA ;
				break ;
Thomas's avatar
Thomas committed
1421
1422
1423
			}
		}

1424
		out << "cylinder {" << " <0,0,0>, <0,6,0>, 1.5 " << std::endl ;
Thomas's avatar
Thomas committed
1425

1426
		out << "scale 0.5" << std::endl ;
Thomas's avatar
Thomas committed
1427

David Cazier's avatar
David Cazier committed
1428
		VEC3 col = Utils::color_map_BCGYR(float(j) / float(simulator.agents_.size())) ;