Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

viewer.cpp 48.6 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
SocialAgents::SocialAgents(unsigned int config, unsigned int minSize, unsigned int nbAgent, unsigned int nbObst, unsigned int iterations) :
Thomas Jund's avatar
Thomas Jund committed
32
	m_renderStyle(0),
David Cazier's avatar
David Cazier committed
33
34
	nbIterations(0),
	maxIterations(iterations),
Thomas Jund's avatar
Thomas Jund committed
35
	nbGeneratedPov(0),
David Cazier's avatar
David Cazier committed
36
	frames(0),
pitiot's avatar
maj    
pitiot committed
37
	nextUpdate(0),
38
	simulator(config, minSize, nbAgent, nbObst),
David Cazier's avatar
David Cazier committed
39
	render_anim(false),
Thomas Jund's avatar
Thomas Jund committed
40
41
	drawEnvLines(false),
	drawEnvFaces(true),
David Cazier's avatar
David Cazier committed
42
	drawEnvTopo(false),
pitiot's avatar
maj    
pitiot committed
43
44
	drawObstacles(false),
	drawMovingObstacles(true),
David Cazier's avatar
David Cazier committed
45
46
47
	drawAgents(true),
	drawAgentsNeighborDist(false),
	drawAgentsObstacleDist(false),
pitiot's avatar
maj    
pitiot committed
48
	drawAgentsPredictionTri(false),
49
	drawAgentsPath(false),
pitiot's avatar
pitiot committed
50
	drawObstPredictionTri(false),
51
	drawObstPath(false),
pitiot's avatar
merging    
pitiot committed
52
	draw_dart(false),
53
	draw_posX(false),
pitiot's avatar
merging    
pitiot committed
54
	draw_elipse(false)
Pierre Kraemer's avatar
Pierre Kraemer committed
55
{
David Cazier's avatar
David Cazier committed
56
57
	timer = new QTimer(this) ;
	connect(timer, SIGNAL(timeout()), this, SLOT(animate())) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
58

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

61
	glEnable(GL_POINT_SMOOTH) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
62
63
}

Pierre Kraemer's avatar
Pierre Kraemer committed
64
void SocialAgents::initGUI()
Pierre Kraemer's avatar
Pierre Kraemer committed
65
{
David Cazier's avatar
David Cazier committed
66
	setDock(&dock) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
67

pitiot's avatar
maj    
pitiot committed
68
69
70
71
	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
72

David Cazier's avatar
David Cazier committed
73
74
75
76
77
	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
78
	setCallBack(dock.check_drawMovingObstacles, SIGNAL(toggled(bool)), SLOT(slot_drawMovingObstacles(bool))) ;
David Cazier's avatar
David Cazier committed
79
	setCallBack(dock.check_drawAgents, SIGNAL(toggled(bool)), SLOT(slot_drawAgents(bool))) ;
pitiot's avatar
maj    
pitiot committed
80
	setCallBack(dock.check_drawAgentsPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPredictionTri(bool))) ;
pitiot's avatar
pitiot committed
81
	setCallBack(dock.check_drawObstPredictionTri, SIGNAL(toggled(bool)), SLOT(slot_drawObstPredictionTri(bool))) ;
pitiot's avatar
maj    
pitiot committed
82
83
	setCallBack(dock.check_drawAgentsNeighborDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsNeighborDist(bool))) ;
	setCallBack(dock.check_drawAgentsObstacleDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsObstacleDist(bool))) ;
84
	setCallBack(dock.check_drawAgentsPath, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsPath(bool))) ;
85
	setCallBack(dock.check_drawObstPath, SIGNAL(toggled(bool)), SLOT(slot_drawObstPath(bool))) ;
pitiot's avatar
maj    
pitiot committed
86
87
	setCallBack(dock.check_dart, SIGNAL(toggled(bool)), SLOT(slot_dart(bool))) ;
	setCallBack(dock.check_slide, SIGNAL(valueChanged(int)), SLOT(slot_slide(int))) ;
88
89
90
	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
91
	setCallBack(dock.check_elipse, SIGNAL(toggled(bool)), SLOT(slot_elipse(bool))) ;
Thomas Jund's avatar
Thomas Jund committed
92
93
94

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

Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
void SocialAgents::cb_initGL()
{
Thomas Jund's avatar
Thomas Jund committed
99
100
101
	std::cout << "initGL" << std::endl;

	colClear = Geom::Vec4f(0.7f, 0.7f, 0.7f, 0.5f) ;
Thomas Jund's avatar
Thomas Jund committed
102
	colDif = Geom::Vec4f(0.3f, 0.3f, 0.3f, 1.0f) ;
Thomas Jund's avatar
Thomas Jund committed
103
104
	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
105

David Cazier's avatar
David Cazier committed
106
	bb = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.map, simulator.envMap_.position) ;
Thomas Jund's avatar
Thomas Jund committed
107
108
109
110
111
112
113
	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
114
115
116
117
	VEC3 gPosObj = bb.center() ;
	float tailleX = bb.size(0) ;
	float tailleY = bb.size(1) ;
	float tailleZ = bb.size(2) ;
Thomas Jund's avatar
Thomas Jund committed
118
	float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ);///10.0f ;
119
	setParamObject(gWidthObj, gPosObj.data()) ;
Thomas Jund's avatar
Thomas Jund committed
120
121
122
123
124
125
126
127

	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);

	// create the render
	m_render = new Algo::Render::GL2::MapRender();
	m_renderTopo = new Algo::Render::GL2::TopoRender();

Thomas Jund's avatar
Thomas Jund committed
128
129
130
	if(simulator.config==5)
		m_renderPedway = new Algo::Render::GL2::MapRender();

Thomas Jund's avatar
Thomas Jund committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
	// 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
153
154
155
#ifdef EXPORTING
		m_flatShader_scenary = new ShaderCustom();
#else
Thomas Jund's avatar
Thomas Jund committed
156
		m_flatShader_scenary = new Utils::ShaderFlat();
Thomas Jund's avatar
Thomas Jund committed
157
#endif
Thomas Jund's avatar
Thomas Jund committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
		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);
//	m_sprite->setSize(Agent::radius_);
	m_sprite->setSize((50.0f/gWidthObj) *  Agent::radius_ );

	registerShader(m_simpleColorShader);
	registerShader(m_sprite);

	initRendering();
}

void SocialAgents::initRendering()
{
	if(simulator.config==5)
	{
		m_render_scenary->initPrimitives<PFP>(simulator.envMap_.mapScenary, allDarts, Algo::Render::GL2::LINES,false) ;
		m_render_scenary->initPrimitives<PFP>(simulator.envMap_.mapScenary, allDarts, Algo::Render::GL2::TRIANGLES,false) ;
Thomas Jund's avatar
Thomas Jund committed
195
196
197
198
199
200
201
202
203
204
205

		m_render->initPrimitives<PFP>(simulator.envMap_.map, allDarts, Algo::Render::GL2::LINES,false) ;
		m_render->initPrimitives<PFP>(simulator.envMap_.map, allDarts, Algo::Render::GL2::TRIANGLES,false) ;

		m_renderPedway->initPrimitives<PFP>(simulator.envMap_.map, allDarts, Algo::Render::GL2::LINES,false) ;
		m_renderPedway->initPrimitives<PFP>(simulator.envMap_.map, allDarts, Algo::Render::GL2::TRIANGLES,false) ;
	}
	else
	{
		m_render->initPrimitives<PFP>(simulator.envMap_.map, allDarts, Algo::Render::GL2::LINES,false) ;
		m_render->initPrimitives<PFP>(simulator.envMap_.map, allDarts, Algo::Render::GL2::TRIANGLES,false) ;
Thomas Jund's avatar
Thomas Jund committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
	}

	m_renderTopo->updateData<PFP>(simulator.envMap_.map, simulator.envMap_.position, 0.9, 0.9, allDarts);


	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();
		shader->setAmbiant(Geom::Vec4f(1.,0.,0.,0.)) ;
		shader->setDiffuse(Geom::Vec4f(1.,0.,0.,0.));

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

	updateObstacleVBO();
Thomas Jund's avatar
Thomas Jund committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

#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
298
299
300

	for(unsigned int i = 0 ; i < simulator.movingMeshes_.size() ; ++i)
		registerShader(simulator.movingMeshes_[i]->m_simpleColorShader);
Thomas Jund's avatar
Thomas Jund committed
301
302
303
304
305
306
307
308
309
310
311
312
313
}

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
314

Thomas Jund's avatar
Thomas Jund committed
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
		vbo->releasePtr();
	}
}

void SocialAgents::updateObstaclePredTriVBO()
{
	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());

		VEC3 p = simulator.movingObstacles_[i]->getDilatedPosition(0);
		data[0] = p;

		p = simulator.envMap_.position[simulator.movingObstacles_[i]->registering_part->d];
		data[1] = p;

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

		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)
{
	if(upType & Algo::Render::GL2::TRIANGLES)
		m_render->initPrimitives<PFP>(simulator.envMap_.map, allDarts, Algo::Render::GL2::TRIANGLES, false) ;

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

	if(upType & Algo::Render::GL2::POINTS)
		m_render->initPrimitives<PFP>(simulator.envMap_.map, allDarts, Algo::Render::GL2::POINTS) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
369
}
Pierre Kraemer's avatar
Pierre Kraemer committed
370

Arash HABIBI's avatar
Arash HABIBI committed
371
372
373
374
375
376
377
//-----------------------------------
// An ellipse has two foci placed at
// F1 and F2. The ellipse is the set
// of points M for whom MF1 + MF2 = s

static void drawEllipse(VEC3 F1, VEC3 F2, float s, int N)
{
Thomas Jund's avatar
Thomas Jund committed
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
//	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
409
410
411
412
413
414
415
416
417
418
419
//	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();
Arash HABIBI's avatar
Arash HABIBI committed
420
421
422
423
}

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

Thomas Jund's avatar
Thomas Jund committed
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
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]);

	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;

	updateGLMatrices();
}

Pierre Kraemer's avatar
Pierre Kraemer committed
452
453
void SocialAgents::cb_redraw()
{
Thomas Jund's avatar
Thomas Jund committed
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
	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
469
//	glEnable(GL_CULL_FACE);
Thomas Jund's avatar
Thomas Jund committed
470
471
472
473
474
	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
475
476
477
478
479
480
481
482
483
484
485
486
487

	glEnable(GL_POLYGON_OFFSET_FILL) ;
	glPolygonOffset( 2.0f,2.0f) ;

#ifdef EXPORTING
	m_Ground_Shader->enableVertexAttribs();
//	glDrawArrays(GL_QUADS, 0, 4*N_THETA*N_PHI );
	glDrawArrays(GL_POLYGON, 0, 4);
	m_Ground_Shader->disableVertexAttribs();
#endif

	glDisable(GL_POLYGON_OFFSET_FILL) ;

Thomas Jund's avatar
Thomas Jund committed
488
489
490

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
	glEnable(GL_LIGHTING);
pitiot's avatar
maj    
pitiot committed
491

Thomas Jund's avatar
Thomas Jund committed
492

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

pitiot's avatar
maj    
pitiot committed
495
496
	if (draw_dart)
	{
Thomas Jund's avatar
Thomas Jund committed
497
498
499
500
501
502
//		if (dartSlider < (simulator.envMap_.map.end().index))
//		{
//			glColor3f(1.0f, 0.0f, 0.0f) ;
//			glLineWidth(5.0f) ;
//			renderDart(simulator.envMap_, dartSlider) ;
//		}
pitiot's avatar
maj    
pitiot committed
503
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
504

505
506
507
508
	if (draw_posX)
	{
	}

David Cazier's avatar
David Cazier committed
509
510
	if (drawAgents)
	{
Thomas Jund's avatar
Thomas Jund committed
511
512
		PFP::VEC3* data = static_cast<PFP::VEC3*>(m_agentsVBO->lockPtr());
		for (unsigned int i=0; i< simulator.agents_.size(); ++i)
David Cazier's avatar
David Cazier committed
513
		{
Thomas Jund's avatar
Thomas Jund committed
514
515
			VEC3 p = simulator.agents_[i]->getPosition();
			data[i] = p;
Pierre Kraemer's avatar
Pierre Kraemer committed
516
		}
Thomas Jund's avatar
Thomas Jund committed
517
		m_agentsVBO->releasePtr();
Pierre Kraemer's avatar
Pierre Kraemer committed
518

Thomas Jund's avatar
Thomas Jund committed
519
520
521
522
523
524
525
526
527
		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();



//		for (std::vector<Agent*>::iterator it = simulator.agents_.begin() ; it != simulator.agents_.end() ; ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
528
//		{
Thomas Jund's avatar
Thomas Jund committed
529
530
531
//			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
//			renderAgent(simulator.envMap_, *it, drawAgentsNeighborDist, drawAgentsObstacleDist, drawAgentsPath,
//			 (*it)->color1, (*it)->color2, (*it)->color3) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
532
//		}
Pierre Kraemer's avatar
Pierre Kraemer committed
533
	}
534

pitiot's avatar
maj    
pitiot committed
535
536
	if (drawMovingObstacles)
	{
Thomas Jund's avatar
Thomas Jund committed
537
538
539
540
541
542
543
544
545
546
547
		updateObstacleVBO();

		for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i)
		{
			Utils::ShaderFlat* moShader = m_obstShader[i];

			moShader->enableVertexAttribs();
			glDrawArrays(GL_POLYGON, 0, simulator.movingObstacles_[i]->nbVertices);
			moShader->disableVertexAttribs();
		}

Arash HABIBI's avatar
nickel    
Arash HABIBI committed
548
549
		// Commente par Arash
		/*for (std::vector<MovingMesh*>::iterator it = simulator.movingMeshes_.begin() ; it != simulator.movingMeshes_.end() ; ++it)
Thomas Jund's avatar
Thomas Jund committed
550
551
		{
			(*it)->draw();
Arash HABIBI's avatar
nickel    
Arash HABIBI committed
552
		}*/
553

554
		glColor3f(1.0f, 1.0f, 1.0f) ;
David Cazier's avatar
David Cazier committed
555
		for (std::vector<MovingObstacle*>::iterator it = simulator.movingObstacles_.begin() ; it != simulator.movingObstacles_.end() ; ++it)
pitiot's avatar
maj    
pitiot committed
556
		{
pitiot's avatar
merging    
pitiot committed
557
558
			if (draw_elipse)
			{	// Dessiner les foyers
Thomas Jund's avatar
Thomas Jund committed
559
560
561
562
563
564
565
566
567
//				glBegin(GL_POINTS);
//				glColor3f(1.0,0.0,0.0);
//				glVertex3fv((*it)->focus1.data());
//				glColor3f(0.0,1.0,0.0);
//				glVertex3fv((*it)->focus2.data());
//				glEnd();
//
//				// Dessiner l'ellipse
//				 drawEllipse((*it)->focus1,(*it)->focus2,(*it)->sum_dist_foci,20);
pitiot's avatar
merging    
pitiot committed
568
			}
569

Thomas Jund's avatar
Thomas Jund committed
570
//			renderObstacle(simulator.envMap_, *it,false,drawObstPath, true);
pitiot's avatar
maj    
pitiot committed
571
572
573
574

		}
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
575
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
576
577
	if (drawAgentsPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
578
579
580
		updateAgentPredTriVBO();

		for(unsigned int i = 0 ; i < simulator.agents_.size() ; ++i)
David Cazier's avatar
David Cazier committed
581
		{
Thomas Jund's avatar
Thomas Jund committed
582
583
584
585
586
			Utils::ShaderSimpleColor* agShader = m_triAgent_Shader[i];

			agShader->enableVertexAttribs();
			glDrawArrays(GL_LINE_LOOP, 0, 3);
			agShader->disableVertexAttribs();
Pierre Kraemer's avatar
Pierre Kraemer committed
587
588
		}
	}
pitiot's avatar
pitiot committed
589
590
591

	if (drawObstPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
592
		updateObstaclePredTriVBO();
Thomas Jund's avatar
Thomas Jund committed
593

Thomas Jund's avatar
Thomas Jund committed
594
595
596
		for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i)
		{
			Utils::ShaderSimpleColor* moShader = m_triObst_Shader[i];
Thomas Jund's avatar
Thomas Jund committed
597

Thomas Jund's avatar
Thomas Jund committed
598
599
600
			moShader->enableVertexAttribs();
			glDrawArrays(GL_LINE_LOOP, 0, 3);
			moShader->disableVertexAttribs();
Thomas Jund's avatar
Thomas Jund committed
601
		}
pitiot's avatar
pitiot committed
602
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
603
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
604
605

	//draw the environment
David Cazier's avatar
David Cazier committed
606
607
	if (drawEnvLines)
	{
Thomas Jund's avatar
Thomas Jund committed
608
609
		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
610
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
611

David Cazier's avatar
David Cazier committed
612
	if (drawEnvTopo)
Thomas Jund's avatar
Thomas Jund committed
613
		m_renderTopo->drawTopo();
614

David Cazier's avatar
David Cazier committed
615
616
	if (drawObstacles)
	{
617
618
619
620
621
		glColor3f(0.0f, 0.0f, 1.0f) ;
		glLineWidth(3.0f) ;

		TraversorE<PFP::MAP> tE(simulator.envMap_.map);
		for (Dart d = tE.begin() ; d != tE.end() ; d = tE.next())
David Cazier's avatar
David Cazier committed
622
		{
pitiot's avatar
maj    
pitiot committed
623
624

				///show buildings
625
//				if(simulator.envMap_.buildingMark.isMarked(d))
pitiot's avatar
maj    
pitiot committed
626
//				{
627
//					renderFace(simulator.envMap_,d);
pitiot's avatar
maj    
pitiot committed
628
629
//				}

630
//				if ((simulator.envMap_.obstvect[d].size()) != 0)
Jund Thomas's avatar
Jund Thomas committed
631
//				{
632
//					renderFace(simulator.envMap_, d) ;
Jund Thomas's avatar
Jund Thomas committed
633
//				}
pitiot's avatar
maj    
pitiot committed
634

Arash HABIBI's avatar
Arash HABIBI committed
635
				if(simulator.envMap_.obstacleMark.isMarked(d))
pitiot's avatar
maj    
pitiot committed
636
				{
Arash HABIBI's avatar
Arash HABIBI committed
637
638
					renderDart(simulator.envMap_,d);
				}
pitiot's avatar
maj    
pitiot committed
639

640
				if(simulator.envMap_.map.isBoundaryEdge(d))
pitiot's avatar
pitiot committed
641
				{
642
					renderDart(simulator.envMap_,d);
pitiot's avatar
maj    
pitiot committed
643
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
644
645
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
646

pitiot's avatar
maj    
pitiot committed
647
648
649
650
651
	if (drawEnvFaces)
	{
		glEnable(GL_LIGHTING) ;
		glEnable(GL_POLYGON_OFFSET_FILL) ;
		glPolygonOffset(1.0f, 1.0f) ;
Thomas Jund's avatar
Thomas Jund committed
652
653
654
655
656
		switch(m_renderStyle)
		{
		case SIMPLE:
			m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.));
			m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
pitiot's avatar
maj    
pitiot committed
657

Thomas Jund's avatar
Thomas Jund committed
658
659
660
661
662
663
664
665
			if(simulator.config==5)
			{
				m_render_scenary->draw(m_flatShader_scenary, Algo::Render::GL2::TRIANGLES);
			}
			break;
		}
		glDisable(GL_POLYGON_OFFSET_FILL) ;
	}
pitiot's avatar
maj    
pitiot committed
666

Thomas Jund's avatar
Thomas Jund committed
667

David Cazier's avatar
David Cazier committed
668
	++frames ;
pitiot's avatar
maj    
pitiot committed
669
670
671
672
673
	struct timespec realTime ;
	clock_gettime(CLOCK_MONOTONIC, &realTime) ;
	time_t elapsedTime = realTime.tv_sec - startTime.tv_sec ;

	if (elapsedTime >= nextUpdate)
David Cazier's avatar
David Cazier committed
674
675
	{
		// Sortie des stats pour analyse externe
676
677
678
//		std::cout << elapsedTime << ";" << frames << ";" << sim.nbUpdates << ";"
//		    << sim.totalNeighbors << ";" << sim.nearNeighbors << ";" << sim.nbSorts << ";"
//		    << sim.nbRefineCandidate << ";" << sim.nbCoarsenCandidate << std::endl ;
pitiot's avatar
maj    
pitiot committed
679

David Cazier's avatar
David Cazier committed
680
681
		// Affichage des stats dans la barre d'état
		std::ostringstream oss ;
pitiot's avatar
maj    
pitiot committed
682
		oss << "Elapsed time : " << elapsedTime ;
David Cazier's avatar
David Cazier committed
683
684
		oss << " | " << frames << " fps" ;
		oss << " | Iterations " << nbIterations ;
David Cazier's avatar
David Cazier committed
685
686
687
688
689
690
691
692
693
		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)
694
		{
David Cazier's avatar
David Cazier committed
695
			oss << " | agents morts : "<<simulator.nb_dead;
696
		}
pitiot's avatar
maj    
pitiot committed
697
698
699
		glColor3f(1.0f, 1.0f, 1.0f) ;
		statusMsg(oss.str().c_str()) ;

David Cazier's avatar
David Cazier committed
700
701
702
703
704
705
		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
706
		frames = 0 ;
pitiot's avatar
maj    
pitiot committed
707
		nextUpdate = elapsedTime + 1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
708
	}
Thomas Jund's avatar
Thomas Jund committed
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801


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

	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
802
803
}

Pierre Kraemer's avatar
Pierre Kraemer committed
804
void SocialAgents::animate()
Pierre Kraemer's avatar
Pierre Kraemer committed
805
{
pitiot's avatar
maj    
pitiot committed
806
807
//	if(sim.nbSteps_ % sim.nbStepsPerUnit_ == 0 && (sim.nbSteps_ / sim.nbStepsPerUnit_) % 10 == 0)
//		std::cout << round(sim.globalTime_) << " " << sim.envMap_.mapMemoryCost() << std::endl;
Thomas's avatar
Thomas committed
808

David Cazier's avatar
David Cazier committed
809
810
811
//	if (sim.nbSteps_ % sim.nbStepsPerUnit_ == 0 && (sim.nbSteps_ / sim.nbStepsPerUnit_) % 10 == 0) std::cout
//	    << round(sim.globalTime_) << " " << sim.envMap_.mapMemoryCost() << std::endl ;
//
Pierre Kraemer's avatar
Pierre Kraemer committed
812
//	CityGenerator::animateCity<PFP>(&sim.envMap_) ;
David Cazier's avatar
David Cazier committed
813
814
815
//	if (CityGenerator::animateCity<PFP>(&sim.envMap_)) sim.addPathToCorner() ;
//	sim.addPathsToAgents() ;
//
Arash HABIBI's avatar
Arash HABIBI committed
816
	// std::cout << "t : " << simulator.globalTime_ << std::endl ;
David Cazier's avatar
David Cazier committed
817
818
819
820
821
//
//	timeval startTime ;
//	gettimeofday(&startTime, NULL) ;
//	timeval endTime ;
//	long seconds, nseconds ;
Thomas's avatar
Thomas committed
822

David Cazier's avatar
David Cazier committed
823
824
825
826
827
828
	nbIterations++ ;
	if (maxIterations > 0 && nbIterations > maxIterations)
	{
		timer->stop() ;
		exit(0) ;
	}
Arash HABIBI's avatar
Arash HABIBI committed
829
		simulator.doStep() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
830

Thomas Jund's avatar
Thomas Jund committed
831
832
833
834
835
836
837
838
839
840
841
	m_positionVBO->updateData(simulator.envMap_.position);

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

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

	if(drawEnvTopo)
		m_renderTopo->updateData<PFP>(simulator.envMap_.map, simulator.envMap_.position, 0.9, 0.9, allDarts);

David Cazier's avatar
David Cazier committed
842
843
844
//	gettimeofday(&endTime, NULL) ;
//	seconds = endTime.tv_sec - startTime.tv_sec ;
//	nseconds = endTime.tv_usec - startTime.tv_usec ;
Pierre Kraemer's avatar
Pierre Kraemer committed
845
//
David Cazier's avatar
David Cazier committed
846
847
848
//	elapsedTime += (seconds + nseconds / 1000000.0) ;
//
//	if (sim.globalTime_ - int(sim.globalTime_) == 0.0f && int(sim.globalTime_) % 1500 == 0)
Thomas's avatar
Thomas committed
849
//	{
David Cazier's avatar
David Cazier committed
850
851
//		std::cout << "end " << elapsedTime << std::endl ;
//		timer->stop() ;
Thomas's avatar
Thomas committed
852
//	}
David Cazier's avatar
David Cazier committed
853
854
//
//	if (sim.reachedGoal())
855
//	{
David Cazier's avatar
David Cazier committed
856
857
//		std::cout << "end " << elapsedTime << std::endl ;
//		timer->stop() ;
858
//	}
Thomas's avatar
Thomas committed
859

Pierre Kraemer's avatar
Pierre Kraemer committed
860
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
861
862
	if (render_anim)
	{
863
864
		std::ostringstream oss ;
		std::ostringstream tmpNb ;
Thomas Jund's avatar
Thomas Jund committed
865
866
867
		tmpNb << std::setfill('0') << std::setw(5) << nbGeneratedPov ;
//		oss << "./DeCirkelMesh/meshCercle" << tmpNb.str() << ".pov" ;
		oss << "./DeCorridorMesh/meshCorrida" << tmpNb.str() << ".pov" ;
868
		std::string chaine = oss.str() ;
David Cazier's avatar
David Cazier committed
869
870
871
872
873
//		VEC3 agPos = sim.agents_[0]->meanPos_ ;
//		agPos[2] = agPos[1] ;
//		agPos[1] = 0.0f ;
//		VEC3 camPos(agPos) ;
//		VEC3 camLook(agPos) ;
Thomas Jund's avatar
Thomas Jund committed
874

David Cazier's avatar
David Cazier committed
875
876
877
//		camPos = camPos
//		    + VEC3(-10 - 0.05 * nbGenerated, 30 + 0.05 * nbGenerated,
//		           log(1.0f + nbGenerated / 700.0f)) ;
Thomas's avatar
Thomas committed
878

879
//travelling city nbMaxAgent 15000, nbSquare 40 (45?)
David Cazier's avatar
David Cazier committed
880
881
882
883
884
885
886
887
//		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)) ;
Thomas's avatar
Thomas committed
888

889
//travelling horizontal
David Cazier's avatar
David Cazier committed
890
891
892
893
894
895
//		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 ;
Thomas's avatar
Thomas committed
896

897
//vertical view
David Cazier's avatar
David Cazier committed
898
899
900
901
902
//		VEC3 camPos(0, 300, 0) ;
//		Geom::BoundingBox<VEC3> bb = sim.getAgentsBB() ;
//		VEC3 seeEveryone = bb.max() - bb.min() ;
//		if (seeEveryone[0] > 200)
//			camPos[1] += seeEveryone[0] ;
Thomas's avatar
Thomas committed
903
//		else
David Cazier's avatar
David Cazier committed
904
905
//			camPos[1] += 200 ;
//		VEC3 camLook(0) ;
Thomas's avatar
Thomas committed
906

907
//video intro
David Cazier's avatar
David Cazier committed
908
909
//		VEC3 camPos(-20, 10, 75) ;
//		VEC3 camLook(-25, 0, 0) ;
Thomas's avatar
Thomas committed
910

911
//mall
David Cazier's avatar
David Cazier committed
912
913
//		VEC3 camPos(-500, 500, -400) ;
//		VEC3 camLook(100, 100, 0) ;
914

915
//openStreetMap
David Cazier's avatar
David Cazier committed
916
917
//		VEC3 camPos(500, 75, 400) ;
//		VEC3 camLook(-250, 0, 650) ;
918

919
//pathDyn
pitiot's avatar
maj    
pitiot committed
920
921
922
923
//		VEC3 camPos(-700, 700, -1800) ;
//		VEC3 camLook(200, 0, 0) ;

//corridor side
pitiot's avatar
pitiot committed
924
925
926
927
928
929
930
931
//		VEC3 camPos(-700, 100, 0) ;
//		VEC3 camLook(200, 0, 0) ;

//corridor top
//		VEC3 camPos(0, 300, 0) ;
//		VEC3 camLook(0, 0, 0) ;

//corridor take2
Jund Thomas's avatar
Jund Thomas committed
932
933
934
935
//		VEC3 camPos(-350, 200, 0) ;
//		VEC3 camLook(0, 0, 0) ;

//openStreetMap mapRoad & mapBuildings
Jund Thomas's avatar
Jund Thomas committed
936
937
938
939
//		VEC3 camPos(-200, 100, 500) ;
//		VEC3 camLook(1000, 0, 0) ;

//openStreetMap sphere
Thomas Jund's avatar
Thomas Jund committed
940
941
942
//		VEC3 camPos(-200, 100, 500) ;
//		VEC3 camLook(100, 0, 0) ;

Thomas Jund's avatar
Thomas Jund committed
943
944
945
946
947
948
//		//diligences / Cercle
//		VEC3 camPos(0, 300, 750) ;
//		VEC3 camLook(0, 0, 0) ;

		//corridor
		VEC3 camPos(0, 300, 750) ;
Thomas Jund's avatar
Thomas Jund committed
949
		VEC3 camLook(0, 0, 0) ;
Jund Thomas's avatar
Jund Thomas committed
950

951

Thomas Jund's avatar
Thomas Jund committed
952
953
954
955
956
957
958
		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++;
		}
David Cazier's avatar
David Cazier committed
959

Thomas Jund's avatar
Thomas Jund committed
960
		if (nbIterations >= 20000)
David Cazier's avatar
David Cazier committed
961
		{
962
963
			std::cout << "enough .pov generated" << std::endl ;
			exit(0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
964
965
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
966
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
967

968
	updateGL() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
969
}
970

Pierre Kraemer's avatar
Pierre Kraemer committed
971
#ifndef SPATIAL_HASHING
Thomas's avatar
Thomas committed
972
973
974
void SocialAgents::exportInfoFace(std::ofstream& out, Dart d)
{
	//get corner
975
	Dart dd = d ;
David Cazier's avatar
David Cazier committed
976
	VEC3 cornerLeftBottom = simulator.envMap_.position[d] ;
David Cazier's avatar
David Cazier committed
977
978
	do
	{
David Cazier's avatar
David Cazier committed
979
		VEC3 p = simulator.envMap_.position[dd] ;
980
981
982
		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
983
		dd = simulator.envMap_.map.phi1(dd) ;
984
	} while (dd != d) ;
Thomas's avatar
Thomas committed
985
986

	//draw text
David Cazier's avatar
David Cazier committed
987
	if (!simulator.envMap_.buildingMark.isMarked(d))
David Cazier's avatar
David Cazier committed
988
	{
989
990
		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
991
992
		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;
993
994
995
996
		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
997
998
		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;
999
		out << "}" << std::endl ;
Thomas's avatar
Thomas committed
1000
1001
1002
1003
	}

	//draw vectors
	//contains
David Cazier's avatar
David Cazier committed
1004
	for (unsigned int i = 0 ; i < simulator.envMap_.agentvect[d].size() ; ++i)
David Cazier's avatar
David Cazier committed
1005
	{
David Cazier's avatar
David Cazier committed
1006
		Agent * ag = simulator.envMap_.agentvect[d][i] ;
1007
1008

		int j = 0 ;
David Cazier's avatar
David Cazier committed
1009
		for (unsigned int iA = 0 ; iA < simulator.agents_.size() ; ++iA)
David Cazier's avatar
David Cazier committed
1010
		{
David Cazier's avatar
David Cazier committed
1011
			if (simulator.agents_[iA] == ag)
David Cazier's avatar
David Cazier committed
1012
			{
1013
1014
				j = iA ;
				break ;
Thomas's avatar
Thomas committed
1015
1016
1017
			}
		}

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

1020
		out << "scale 0.5" << std::endl ;
Thomas's avatar
Thomas committed
1021

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

David Cazier's avatar
David Cazier committed
1025
1026
//		VEC3 pBase(ag->getPosition()) ;
//		VEC3 posR(pBase) ;
Thomas's avatar
Thomas committed
1027
//
David Cazier's avatar
David Cazier committed
1028
1029
1030
1031
//		Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(sim.envMap_.map, ag->part_.d,
//		                                                         sim.envMap_.position) ;
//		posR[2] -= 1000 ;
//		Geom::intersectionPlaneRay(pl, posR, VEC3(0, 0, -1), posR) ;
Thomas's avatar
Thomas committed
1032
//
David Cazier's avatar
David Cazier committed
1033
//		VEC3 dir = ag->meanDirection_ ;
David Cazier's avatar
David Cazier committed
1034
1035
1036
//		VEC3 base(0, -1, 0) ;
//		VEC3 axisRot = base ^ dir ;
//		int sign = axisRot[2] > 0 ? 1 : -1 ;
Thomas's avatar
Thomas committed
1037
//
David Cazier's avatar
David Cazier committed
1038
1039
1040
//		57, 2957795
//		: conversion from radian to degree
//		float myRot = acos(-dir[1])*57.2957795f ;
Thomas's avatar
Thomas committed
1041
//
David Cazier's avatar
David Cazier committed
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
//		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 ;
1052
1053

		out << "}" << std::endl ;
Thomas's avatar
Thomas committed
1054
1055
1056
	}

	//neighbours
David Cazier's avatar
David Cazier committed
1057
	for (unsigned int i = 0 ; i < simulator.envMap_.neighborAgentvect[d].size() ; ++i)
David Cazier's avatar
David Cazier committed
1058
	{
David Cazier's avatar
David Cazier committed
1059
		Agent * ag = simulator.envMap_.neighborAgentvect[d][i] ;
1060
1061

		int j = 0 ;
David Cazier's avatar
David Cazier committed
1062
		for (unsigned int iA = 0 ; iA < simulator.agents_.size() ; ++iA)
David Cazier's avatar
David Cazier committed
1063
		{
David Cazier's avatar
David Cazier committed
1064
			if (simulator.agents_[iA] == ag)
David Cazier's avatar
David Cazier committed
1065
			{
1066
1067
				j = iA ;
				break ;
Thomas's avatar
Thomas committed
1068
1069
1070
			}
		}

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

1073
		out << "scale 0.5" << std::endl ;
Thomas's avatar
Thomas committed
1074

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

David Cazier's avatar
David Cazier committed
1079
1080
//		VEC3 pBase(ag->getPosition()) ;
//		VEC3 posR(pBase) ;
Thomas's avatar
Thomas committed
1081
//
David Cazier's avatar
David Cazier committed
1082
1083
1084
1085
//		Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(sim.envMap_.map, ag->part_.d,
//		                                                         sim.envMap_.position) ;
//		posR[2] -= 1000 ;
//		Geom::intersectionPlaneRay(pl, posR, VEC3(0, 0, -1), posR) ;
Thomas's avatar
Thomas committed
1086
//
David Cazier's avatar
David Cazier committed
1087
//		VEC3 dir = ag->meanDirection_ ;
David Cazier's avatar
David Cazier committed
1088
1089
1090
//		VEC3 base(0, -1, 0) ;
//		VEC3 axisRot = base ^ dir ;
//		int sign = axisRot[2] > 0 ? 1 : -1 ;
Thomas's avatar
Thomas committed
1091
//
David Cazier's avatar
David Cazier committed
1092
1093
//		//57,2957795 : conversion from radian to degree
//		float myRot = acos(-dir[1]) * 57.2957795f ;
Thomas's avatar
Thomas committed
1094
//
David Cazier's avatar
David Cazier committed
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
//		out << "rotate <0,0," << sign * myRot << ">" << std::endl ;
//		out << "rotate <" << -90 << "," << 0 << "," << 0 << "> " << std::endl ;
		if (i < 8)
			out << "translate < " << 12 + cornerLeftBottom[0] + 5 + 1 + i * 2 << ","
			    << cornerLeftBottom[2] + 2 << "," << cornerLeftBottom[1] + 7 + 1.5 << ">"
			    << std::endl ;
		else
			out << "translate < " << 12 + cornerLeftBottom[0] + 5 + 1 + (i - 8) * 2 << ","
			    << cornerLeftBottom[2] + 2 << "," << cornerLeftBottom[1] + 7 + 1.5 + 3 << ">"
			    << std::endl ;
1105
1106

		out << "no_shadow }" << std::endl ;
Thomas's avatar
Thomas committed
1107
1108
1109
	}
}

David Cazier's avatar
David Cazier committed
1110
1111
1112
1113
bool SocialAgents::exportScenePov(PFP::MAP& map, PFP::TVEC3& position, const std::string& filename,
                                  PFP::VEC3 cameraPos, PFP::VEC3 cameraLook, PFP::VEC3 translate,
                                  float angle_X, float angle_Y, float angle_Z,
                                  const FunctorSelect& good)
Pierre Kraemer's avatar
Pierre Kraemer committed
1114
{
Thomas Jund's avatar
Thomas Jund committed
1115
	static const bool draft = false ;
1116
	static const bool highlightAgent = false ;
Thomas Jund's avatar
Thomas Jund committed
1117
	static const bool wireDisplay = true ;
1118
	static const bool infoFaces = false ;
pitiot's avatar
maj    
pitiot committed
1119
1120
	static const bool exportPath = false ;
	static const bool exportMovObst = true ;
Thomas Jund's avatar
Thomas Jund committed
1121
1122
1123
	static const bool exportCity = false ;
	static const bool exportSphere = false ;
	static const bool exportDilatedPos = false;
1124
1125
1126
1127

	unsigned int highlightAgentNo = 0 ;

	std::ofstream out(filename.c_str(), std::ios::out) ;
David Cazier's avatar
David Cazier committed
1128
1129
	if (!out.good())
	{
1130
1131
		std::cerr << "(export) Unable to open file " << filename << std::endl ;
		return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1132
1133
	}

1134
1135
1136
1137
	float angleX = angle_X ;
	float angleY = angle_Y ;
	float angleZ = angle_Z ;

1138
	//view the agent from an upper position
David Cazier's avatar
David Cazier committed
1139
1140
	if (highlightAgent)
	{
David Cazier's avatar
David Cazier committed
1141
		Agent * agent = simulator.agents_[highlightAgentNo] ;
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
		cameraLook = agent->getPosition() ;
		VEC3 goalV = (agent->goals_[agent->curGoal_] - agent->getPosition()) ;
		goalV.normalize() ;
		cameraPos = cameraLook - goalV * 50.0f ;
		float tmp = cameraPos[1] ;
		cameraPos[1] = cameraPos[2] + 400.0f ;
		cameraPos[2] = tmp ;
		tmp = cameraLook[1] ;
		cameraLook[2] = cameraLook[1] ;
		cameraLook[1] = tmp ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1152
1153
	}

David Cazier's avatar
David Cazier committed
1154
1155
	if (!draft)
	{
1156
1157
1158
1159
		out << "#include \"Sheriff_animated_POV_geom.inc\"" << std::endl ;
		out << "#include \"Cowbow_animated_POV_geom.inc\"" << std::endl ;
		out << "#include \"sombrero2_highres_POV_geom.inc\"" << std::endl ;
		out << "#include \"sombrero3_highres_POV_geom.inc\"" << std::endl ;
Jund Thomas's avatar
Jund Thomas committed
1160
		out << "#include \"transforms.inc\"" << std::endl ;
Thomas's avatar
Thomas committed
1161
	}
1162

David Cazier's avatar
David Cazier committed
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
//	out
//	    << "#declare PosSpline = spline { natural_spline 0.0,<0,3000,-1> 0.3,<0,500,-1> 0.6,<250,200,200> 1.0,<500,75,400>}"
//	    << std::endl ;
//	out
//	    << "#declare LookSpline = spline { natural_spline 0.0,<0,0,200> 0.3,<-250,0,500> 0.6,<-125,0,350> 1.0,<-250,0,650>}"
//	    << std::endl ;
//
//	if ((sim.globalTime_ - 1000.0f) / 120.0f < 1.0f)
//		out << "camera { location PosSpline(" << (sim.globalTime_ - 1000.0f) / 120.0f
//		    << ") look_at LookSpline(" << (sim.globalTime_ - 1000.0f) / 120.0f << ") " ;
1173
//	else
1174
	out << "camera { location <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2]
David Cazier's avatar
David Cazier committed
1175
	    << "> look_at <" << cameraLook[0] << "," << cameraLook[1] << "," << cameraLook[2] << "> " ;
1176

David Cazier's avatar
David Cazier committed
1177
1178
1179
1180
	if (highlightAgent)
	{
		out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << "> "
		    << std::endl ;
1181
1182
1183
		out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> }" << std::endl ;
	}
	out << "}" << std::endl ;
1184

Pierre Kraemer's avatar
Pierre Kraemer committed
1185
	//set a sky sphere
1186
1187
	out << "sphere { <0, 0, 0>, 5000" ;
	out << "texture{ pigment { color rgb <1, 1, 1>}	finish { ambient 1 diffuse 0 } } }"
David Cazier's avatar
David Cazier committed
1188
	    << std::endl ;
1189

Jund Thomas's avatar
Jund Thomas committed
1190
1191
1192
	//green ground
	if(exportCity)
	{
Jund Thomas's avatar
Jund Thomas committed
1193
1194
1195
1196
1197
1198
1199
1200
1201
		if(exportSphere)
		{
			out << "sphere { <0,0,0>, 195 texture{ pigment { color rgb <0.6, 0.8, 0.6>}	finish { ambient rgb 0.3 brilliance 0.2 } } }" << std::endl;
		}
		else
		{
			out << "plane { <0,1,0>, -0.001" ;
			out << "texture{ pigment { color rgb <0.6, 0.8, 0.6>}	finish { ambient rgb 0.3 brilliance 0.2 } } }" << std::endl ;
		}
Jund Thomas's avatar
Jund Thomas committed
1202
	}
David Cazier's avatar
David Cazier committed
1203
//	out << "light_source { <-800, 800, -800> color rgb 0.25 }" << std::endl ;
Jund Thomas's avatar
Jund Thomas committed
1204

Pierre Kraemer's avatar
Pierre Kraemer committed
1205
	//set a high quality rendering
1206
1207
1208
	out << "global_settings {" << std::endl ;
	out << "radiosity {" << std::endl ;
	out << "pretrace_start 0.08 pretrace_end 0.04" << std::endl ;
Thomas's avatar
Thomas committed
1209
1210
1211
//	if(draft)
//		out << "count 10 nearest_count 10 error_bound 0.25 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1.4 adc_bailout 0.01/2 normal off media off} max_trace_level 5}" << std::endl;
//	else
Jund Thomas's avatar
Jund Thomas committed
1212
	out << "count 300 nearest_count 10 error_bound 0.10 recursion_limit 1 low_error_factor 0.2 gray_threshold 0.0 minimum_reuse 0.015 brightness 1.4 adc_bailout 0.01/2 normal off media off} max_trace_level 60}" << std::endl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1213

David Cazier's avatar
David Cazier committed
1214
	for (unsigned int i = 0 ; i < simulator.agents_.size() ;