viewer.cpp 41.9 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
28
#include <string>

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

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

59
	glEnable(GL_POINT_SMOOTH) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
60
61
}

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

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

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

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

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

	colClear = Geom::Vec4f(0.7f, 0.7f, 0.7f, 0.5f) ;
	colDif = Geom::Vec4f(0.9f, 0.9f, 0.9f, 1.0f) ;
	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
103

David Cazier's avatar
David Cazier committed
104
	Geom::BoundingBox<PFP::VEC3> bb ;
David Cazier's avatar
David Cazier committed
105
	bb = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.map, simulator.envMap_.position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
106
107
108
109
	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
110
	float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ);///10.0f ;
111
	setParamObject(gWidthObj, gPosObj.data()) ;
Thomas Jund's avatar
Thomas Jund committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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

	// 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();

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

		m_flatShader_scenary = new Utils::ShaderFlat();
		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()
{
	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) ;

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

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

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;
		}
		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
274
}
Pierre Kraemer's avatar
Pierre Kraemer committed
275

Arash HABIBI's avatar
Arash HABIBI committed
276
277
278
279
280
281
282
//-----------------------------------
// 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)
{
pitiot's avatar
merging    
pitiot committed
283
	float a,b=0;
Arash HABIBI's avatar
Arash HABIBI committed
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
	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
314
315
316
317
318
319
320
321
322
323
324
//	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
325
326
327
328
}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
329
330
void SocialAgents::cb_redraw()
{
Thomas Jund's avatar
Thomas Jund committed
331
332
333
334
335
336
337
338
339
340
341
//	glEnable(GL_LINE_SMOOTH);
	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);
//	glEnable(GL_BLEND);
//	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

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

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

pitiot's avatar
maj    
pitiot committed
345
346
	if (draw_dart)
	{
Thomas Jund's avatar
Thomas Jund committed
347
348
349
350
351
352
//		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
353
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
354

355
356
357
358
	if (draw_posX)
	{
	}

David Cazier's avatar
David Cazier committed
359
360
	if (drawAgents)
	{
Thomas Jund's avatar
Thomas Jund committed
361
362
		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
363
		{
Thomas Jund's avatar
Thomas Jund committed
364
365
			VEC3 p = simulator.agents_[i]->getPosition();
			data[i] = p;
Pierre Kraemer's avatar
Pierre Kraemer committed
366
		}
Thomas Jund's avatar
Thomas Jund committed
367
		m_agentsVBO->releasePtr();
Pierre Kraemer's avatar
Pierre Kraemer committed
368

Thomas Jund's avatar
Thomas Jund committed
369
370
371
372
373
374
375
376
377
		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
378
//		{
Thomas Jund's avatar
Thomas Jund committed
379
380
381
//			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
382
//		}
Pierre Kraemer's avatar
Pierre Kraemer committed
383
	}
384

pitiot's avatar
maj    
pitiot committed
385
386
	if (drawMovingObstacles)
	{
Thomas Jund's avatar
Thomas Jund committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
		updateObstacleVBO();

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

//			moShader->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f));
			moShader->enableVertexAttribs();
			glDrawArrays(GL_POLYGON, 0, simulator.movingObstacles_[i]->nbVertices);
			moShader->disableVertexAttribs();
//			moShader->postdraw();
		}


Thomas Jund's avatar
Thomas Jund committed
401
402
403
404
//		for (std::vector<MovingMesh*>::iterator it = simulator.movingMeshes_.begin() ; it != simulator.movingMeshes_.end() ; ++it)
//		{
//			(*it)->draw();
//		}
405

406
		glColor3f(1.0f, 1.0f, 1.0f) ;
David Cazier's avatar
David Cazier committed
407
		for (std::vector<MovingObstacle*>::iterator it = simulator.movingObstacles_.begin() ; it != simulator.movingObstacles_.end() ; ++it)
pitiot's avatar
maj    
pitiot committed
408
		{
pitiot's avatar
merging    
pitiot committed
409
410
			if (draw_elipse)
			{	// Dessiner les foyers
Thomas Jund's avatar
Thomas Jund committed
411
412
413
414
415
416
417
418
419
//				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
420
			}
421

Thomas Jund's avatar
Thomas Jund committed
422
//			renderObstacle(simulator.envMap_, *it,false,drawObstPath, true);
pitiot's avatar
maj    
pitiot committed
423
424
425
426

		}
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
427
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
428
429
	if (drawAgentsPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
430
431
432
		updateAgentPredTriVBO();

		for(unsigned int i = 0 ; i < simulator.agents_.size() ; ++i)
David Cazier's avatar
David Cazier committed
433
		{
Thomas Jund's avatar
Thomas Jund committed
434
435
436
437
438
			Utils::ShaderSimpleColor* agShader = m_triAgent_Shader[i];

			agShader->enableVertexAttribs();
			glDrawArrays(GL_LINE_LOOP, 0, 3);
			agShader->disableVertexAttribs();
Pierre Kraemer's avatar
Pierre Kraemer committed
439
440
		}
	}
pitiot's avatar
pitiot committed
441
442
443

	if (drawObstPredictionTri)
	{
Thomas Jund's avatar
Thomas Jund committed
444
		updateObstaclePredTriVBO();
Thomas Jund's avatar
Thomas Jund committed
445

Thomas Jund's avatar
Thomas Jund committed
446
447
448
		for(unsigned int i = 0 ; i < simulator.movingObstacles_.size() ; ++i)
		{
			Utils::ShaderSimpleColor* moShader = m_triObst_Shader[i];
Thomas Jund's avatar
Thomas Jund committed
449

Thomas Jund's avatar
Thomas Jund committed
450
451
452
			moShader->enableVertexAttribs();
			glDrawArrays(GL_LINE_LOOP, 0, 3);
			moShader->disableVertexAttribs();
Thomas Jund's avatar
Thomas Jund committed
453
		}
pitiot's avatar
pitiot committed
454
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
455
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
456
457

	//draw the environment
David Cazier's avatar
David Cazier committed
458
459
	if (drawEnvLines)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
460
461
#ifdef SPATIAL_HASHING
#else
Thomas Jund's avatar
Thomas Jund committed
462
463
		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
464
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
465
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
466

David Cazier's avatar
David Cazier committed
467
	if (drawEnvTopo)
Thomas Jund's avatar
Thomas Jund committed
468
		m_renderTopo->drawTopo();
469

David Cazier's avatar
David Cazier committed
470
471
	if (drawObstacles)
	{
472
473
474
475
476
		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
477
		{
pitiot's avatar
maj    
pitiot committed
478
479

				///show buildings
480
//				if(simulator.envMap_.buildingMark.isMarked(d))
pitiot's avatar
maj    
pitiot committed
481
//				{
482
//					renderFace(simulator.envMap_,d);
pitiot's avatar
maj    
pitiot committed
483
484
//				}

485
//				if ((simulator.envMap_.obstvect[d].size()) != 0)
Jund Thomas's avatar
Jund Thomas committed
486
//				{
487
//					renderFace(simulator.envMap_, d) ;
Jund Thomas's avatar
Jund Thomas committed
488
//				}
pitiot's avatar
maj    
pitiot committed
489

Arash HABIBI's avatar
Arash HABIBI committed
490
				if(simulator.envMap_.obstacleMark.isMarked(d))
pitiot's avatar
maj    
pitiot committed
491
				{
Arash HABIBI's avatar
Arash HABIBI committed
492
493
					renderDart(simulator.envMap_,d);
				}
pitiot's avatar
maj    
pitiot committed
494

495
				if(simulator.envMap_.map.isBoundaryEdge(d))
pitiot's avatar
pitiot committed
496
				{
497
					renderDart(simulator.envMap_,d);
pitiot's avatar
maj    
pitiot committed
498
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
499
		}
500

Pierre Kraemer's avatar
Pierre Kraemer committed
501
502
503
#ifdef SPATIAL_HASHING

#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
504
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
505

pitiot's avatar
maj    
pitiot committed
506
507
508
509
510
	if (drawEnvFaces)
	{
		glEnable(GL_LIGHTING) ;
		glEnable(GL_POLYGON_OFFSET_FILL) ;
		glPolygonOffset(1.0f, 1.0f) ;
Thomas Jund's avatar
Thomas Jund committed
511
512
513
514
515
516
		switch(m_renderStyle)
		{
		case SIMPLE:
			m_simpleColorShader->setColor(Geom::Vec4f(0.9,0.9,0.9,0.));
			//for(std::vector<Algo::Render::GL2::MapRender*>::iterator it = m_render.begin() ; it != m_render.end() ; ++it)
			m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
pitiot's avatar
maj    
pitiot committed
517

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

David Cazier's avatar
David Cazier committed
527
	++frames ;
pitiot's avatar
maj    
pitiot committed
528
529
530
531
532
	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
533
534
	{
		// Sortie des stats pour analyse externe
535
536
537
//		std::cout << elapsedTime << ";" << frames << ";" << sim.nbUpdates << ";"
//		    << sim.totalNeighbors << ";" << sim.nearNeighbors << ";" << sim.nbSorts << ";"
//		    << sim.nbRefineCandidate << ";" << sim.nbCoarsenCandidate << std::endl ;
pitiot's avatar
maj    
pitiot committed
538

David Cazier's avatar
David Cazier committed
539
540
		// Affichage des stats dans la barre d'état
		std::ostringstream oss ;
pitiot's avatar
maj    
pitiot committed
541
		oss << "Elapsed time : " << elapsedTime ;
David Cazier's avatar
David Cazier committed
542
543
		oss << " | " << frames << " fps" ;
		oss << " | Iterations " << nbIterations ;
David Cazier's avatar
David Cazier committed
544
545
546
547
548
549
550
551
552
		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)
553
		{
David Cazier's avatar
David Cazier committed
554
			oss << " | agents morts : "<<simulator.nb_dead;
555
		}
pitiot's avatar
maj    
pitiot committed
556
557
558
		glColor3f(1.0f, 1.0f, 1.0f) ;
		statusMsg(oss.str().c_str()) ;

David Cazier's avatar
David Cazier committed
559
560
561
562
563
564
		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
565
		frames = 0 ;
pitiot's avatar
maj    
pitiot committed
566
		nextUpdate = elapsedTime + 1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
567
568
569
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
570
void SocialAgents::animate()
Pierre Kraemer's avatar
Pierre Kraemer committed
571
{
pitiot's avatar
maj    
pitiot committed
572
573
//	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
574

David Cazier's avatar
David Cazier committed
575
576
577
//	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
578
//	CityGenerator::animateCity<PFP>(&sim.envMap_) ;
David Cazier's avatar
David Cazier committed
579
580
581
//	if (CityGenerator::animateCity<PFP>(&sim.envMap_)) sim.addPathToCorner() ;
//	sim.addPathsToAgents() ;
//
Thomas Jund's avatar
Thomas Jund committed
582
	std::cout << "t : " << simulator.globalTime_ << std::endl ;
David Cazier's avatar
David Cazier committed
583
584
585
586
587
//
//	timeval startTime ;
//	gettimeofday(&startTime, NULL) ;
//	timeval endTime ;
//	long seconds, nseconds ;
Thomas's avatar
Thomas committed
588

David Cazier's avatar
David Cazier committed
589
590
591
592
593
594
	nbIterations++ ;
	if (maxIterations > 0 && nbIterations > maxIterations)
	{
		timer->stop() ;
		exit(0) ;
	}
Arash HABIBI's avatar
Arash HABIBI committed
595
		simulator.doStep() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
596

Thomas Jund's avatar
Thomas Jund committed
597
598
599
600
601
602
603
604
605
606
607
	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
608
609
610
//	gettimeofday(&endTime, NULL) ;
//	seconds = endTime.tv_sec - startTime.tv_sec ;
//	nseconds = endTime.tv_usec - startTime.tv_usec ;
Pierre Kraemer's avatar
Pierre Kraemer committed
611
//
David Cazier's avatar
David Cazier committed
612
613
614
//	elapsedTime += (seconds + nseconds / 1000000.0) ;
//
//	if (sim.globalTime_ - int(sim.globalTime_) == 0.0f && int(sim.globalTime_) % 1500 == 0)
Thomas's avatar
Thomas committed
615
//	{
David Cazier's avatar
David Cazier committed
616
617
//		std::cout << "end " << elapsedTime << std::endl ;
//		timer->stop() ;
Thomas's avatar
Thomas committed
618
//	}
David Cazier's avatar
David Cazier committed
619
620
//
//	if (sim.reachedGoal())
621
//	{
David Cazier's avatar
David Cazier committed
622
623
//		std::cout << "end " << elapsedTime << std::endl ;
//		timer->stop() ;
624
//	}
Thomas's avatar
Thomas committed
625

Pierre Kraemer's avatar
Pierre Kraemer committed
626
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
627
628
	if (render_anim)
	{
629
630
		std::ostringstream oss ;
		std::ostringstream tmpNb ;
Thomas Jund's avatar
Thomas Jund committed
631
632
633
		tmpNb << std::setfill('0') << std::setw(5) << nbGeneratedPov ;
//		oss << "./DeCirkelMesh/meshCercle" << tmpNb.str() << ".pov" ;
		oss << "./DeCorridorMesh/meshCorrida" << tmpNb.str() << ".pov" ;
634
		std::string chaine = oss.str() ;
David Cazier's avatar
David Cazier committed
635
636
637
638
639
//		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
640

David Cazier's avatar
David Cazier committed
641
642
643
//		camPos = camPos
//		    + VEC3(-10 - 0.05 * nbGenerated, 30 + 0.05 * nbGenerated,
//		           log(1.0f + nbGenerated / 700.0f)) ;
Thomas's avatar
Thomas committed
644

645
//travelling city nbMaxAgent 15000, nbSquare 40 (45?)
David Cazier's avatar
David Cazier committed
646
647
648
649
650
651
652
653
//		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
654

655
//travelling horizontal
David Cazier's avatar
David Cazier committed
656
657
658
659
660
661
//		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
662

663
//vertical view
David Cazier's avatar
David Cazier committed
664
665
666
667
668
//		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
669
//		else
David Cazier's avatar
David Cazier committed
670
671
//			camPos[1] += 200 ;
//		VEC3 camLook(0) ;
Thomas's avatar
Thomas committed
672

673
//video intro
David Cazier's avatar
David Cazier committed
674
675
//		VEC3 camPos(-20, 10, 75) ;
//		VEC3 camLook(-25, 0, 0) ;
Thomas's avatar
Thomas committed
676

677
//mall
David Cazier's avatar
David Cazier committed
678
679
//		VEC3 camPos(-500, 500, -400) ;
//		VEC3 camLook(100, 100, 0) ;
680

681
//openStreetMap
David Cazier's avatar
David Cazier committed
682
683
//		VEC3 camPos(500, 75, 400) ;
//		VEC3 camLook(-250, 0, 650) ;
684

685
//pathDyn
pitiot's avatar
maj    
pitiot committed
686
687
688
689
//		VEC3 camPos(-700, 700, -1800) ;
//		VEC3 camLook(200, 0, 0) ;

//corridor side
pitiot's avatar
pitiot committed
690
691
692
693
694
695
696
697
//		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
698
699
700
701
//		VEC3 camPos(-350, 200, 0) ;
//		VEC3 camLook(0, 0, 0) ;

//openStreetMap mapRoad & mapBuildings
Jund Thomas's avatar
Jund Thomas committed
702
703
704
705
//		VEC3 camPos(-200, 100, 500) ;
//		VEC3 camLook(1000, 0, 0) ;

//openStreetMap sphere
Thomas Jund's avatar
Thomas Jund committed
706
707
708
//		VEC3 camPos(-200, 100, 500) ;
//		VEC3 camLook(100, 0, 0) ;

Thomas Jund's avatar
Thomas Jund committed
709
710
711
712
713
714
//		//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
715
		VEC3 camLook(0, 0, 0) ;
Jund Thomas's avatar
Jund Thomas committed
716

717

Thomas Jund's avatar
Thomas Jund committed
718
719
720
721
722
723
724
		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
725

Thomas Jund's avatar
Thomas Jund committed
726
		if (nbIterations >= 20000)
David Cazier's avatar
David Cazier committed
727
		{
728
729
			std::cout << "enough .pov generated" << std::endl ;
			exit(0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
730
731
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
732
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
733

734
	updateGL() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
735
}
736

Pierre Kraemer's avatar
Pierre Kraemer committed
737
#ifndef SPATIAL_HASHING
Thomas's avatar
Thomas committed
738
739
740
void SocialAgents::exportInfoFace(std::ofstream& out, Dart d)
{
	//get corner
741
	Dart dd = d ;
David Cazier's avatar
David Cazier committed
742
	VEC3 cornerLeftBottom = simulator.envMap_.position[d] ;
David Cazier's avatar
David Cazier committed
743
744
	do
	{
David Cazier's avatar
David Cazier committed
745
		VEC3 p = simulator.envMap_.position[dd] ;
746
747
748
		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
749
		dd = simulator.envMap_.map.phi1(dd) ;
750
	} while (dd != d) ;
Thomas's avatar
Thomas committed
751
752

	//draw text
David Cazier's avatar
David Cazier committed
753
	if (!simulator.envMap_.buildingMark.isMarked(d))
David Cazier's avatar
David Cazier committed
754
	{
755
756
		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
757
758
		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;
759
760
761
762
		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
763
764
		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;
765
		out << "}" << std::endl ;
Thomas's avatar
Thomas committed
766
767
768
769
	}

	//draw vectors
	//contains
David Cazier's avatar
David Cazier committed
770
	for (unsigned int i = 0 ; i < simulator.envMap_.agentvect[d].size() ; ++i)
David Cazier's avatar
David Cazier committed
771
	{
David Cazier's avatar
David Cazier committed
772
		Agent * ag = simulator.envMap_.agentvect[d][i] ;
773
774

		int j = 0 ;
David Cazier's avatar
David Cazier committed
775
		for (unsigned int iA = 0 ; iA < simulator.agents_.size() ; ++iA)
David Cazier's avatar
David Cazier committed
776
		{
David Cazier's avatar
David Cazier committed
777
			if (simulator.agents_[iA] == ag)
David Cazier's avatar
David Cazier committed
778
			{
779
780
				j = iA ;
				break ;
Thomas's avatar
Thomas committed
781
782
783
			}
		}

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

786
		out << "scale 0.5" << std::endl ;
Thomas's avatar
Thomas committed
787

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

David Cazier's avatar
David Cazier committed
791
792
//		VEC3 pBase(ag->getPosition()) ;
//		VEC3 posR(pBase) ;
Thomas's avatar
Thomas committed
793
//
David Cazier's avatar
David Cazier committed
794
795
796
797
//		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
798
//
David Cazier's avatar
David Cazier committed
799
//		VEC3 dir = ag->meanDirection_ ;
David Cazier's avatar
David Cazier committed
800
801
802
//		VEC3 base(0, -1, 0) ;
//		VEC3 axisRot = base ^ dir ;
//		int sign = axisRot[2] > 0 ? 1 : -1 ;
Thomas's avatar
Thomas committed
803
//
David Cazier's avatar
David Cazier committed
804
805
806
//		57, 2957795
//		: conversion from radian to degree
//		float myRot = acos(-dir[1])*57.2957795f ;
Thomas's avatar
Thomas committed
807
//
David Cazier's avatar
David Cazier committed
808
809
810
811
812
813
814
815
816
817
//		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 ;
818
819

		out << "}" << std::endl ;
Thomas's avatar
Thomas committed
820
821
822
	}

	//neighbours
David Cazier's avatar
David Cazier committed
823
	for (unsigned int i = 0 ; i < simulator.envMap_.neighborAgentvect[d].size() ; ++i)
David Cazier's avatar
David Cazier committed
824
	{
David Cazier's avatar
David Cazier committed
825
		Agent * ag = simulator.envMap_.neighborAgentvect[d][i] ;
826
827

		int j = 0 ;
David Cazier's avatar
David Cazier committed
828
		for (unsigned int iA = 0 ; iA < simulator.agents_.size() ; ++iA)
David Cazier's avatar
David Cazier committed
829
		{
David Cazier's avatar
David Cazier committed
830
			if (simulator.agents_[iA] == ag)
David Cazier's avatar
David Cazier committed
831
			{
832
833
				j = iA ;
				break ;
Thomas's avatar
Thomas committed
834
835
836
			}
		}

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

839
		out << "scale 0.5" << std::endl ;
Thomas's avatar
Thomas committed
840

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

David Cazier's avatar
David Cazier committed
845
846
//		VEC3 pBase(ag->getPosition()) ;
//		VEC3 posR(pBase) ;
Thomas's avatar
Thomas committed
847
//
David Cazier's avatar
David Cazier committed
848
849
850
851
//		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
852
//
David Cazier's avatar
David Cazier committed
853
//		VEC3 dir = ag->meanDirection_ ;
David Cazier's avatar
David Cazier committed
854
855
856
//		VEC3 base(0, -1, 0) ;
//		VEC3 axisRot = base ^ dir ;
//		int sign = axisRot[2] > 0 ? 1 : -1 ;
Thomas's avatar
Thomas committed
857
//
David Cazier's avatar
David Cazier committed
858
859
//		//57,2957795 : conversion from radian to degree
//		float myRot = acos(-dir[1]) * 57.2957795f ;
Thomas's avatar
Thomas committed
860
//
David Cazier's avatar
David Cazier committed
861
862
863
864
865
866
867
868
869
870
//		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 ;
871
872

		out << "no_shadow }" << std::endl ;
Thomas's avatar
Thomas committed
873
874
875
	}
}

David Cazier's avatar
David Cazier committed
876
877
878
879
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
880
{
Thomas Jund's avatar
Thomas Jund committed
881
	static const bool draft = false ;
882
	static const bool highlightAgent = false ;
Thomas Jund's avatar
Thomas Jund committed
883
	static const bool wireDisplay = true ;
884
	static const bool infoFaces = false ;
pitiot's avatar
maj    
pitiot committed
885
886
	static const bool exportPath = false ;
	static const bool exportMovObst = true ;
Thomas Jund's avatar
Thomas Jund committed
887
888
889
	static const bool exportCity = false ;
	static const bool exportSphere = false ;
	static const bool exportDilatedPos = false;
890
891
892
893

	unsigned int highlightAgentNo = 0 ;

	std::ofstream out(filename.c_str(), std::ios::out) ;
David Cazier's avatar
David Cazier committed
894
895
	if (!out.good())
	{
896
897
		std::cerr << "(export) Unable to open file " << filename << std::endl ;
		return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
898
899
	}

900
901
902
903
	float angleX = angle_X ;
	float angleY = angle_Y ;
	float angleZ = angle_Z ;

904
	//view the agent from an upper position
David Cazier's avatar
David Cazier committed
905
906
	if (highlightAgent)
	{
David Cazier's avatar
David Cazier committed
907
		Agent * agent = simulator.agents_[highlightAgentNo] ;
908
909
910
911
912
913
914
915
916
917
		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
918
919
	}

David Cazier's avatar
David Cazier committed
920
921
	if (!draft)
	{
922
923
924
925
		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
926
		out << "#include \"transforms.inc\"" << std::endl ;
Thomas's avatar
Thomas committed
927
	}
928

David Cazier's avatar
David Cazier committed
929
930
931
932
933
934
935
936
937
938
//	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 << ") " ;
939
//	else
940
	out << "camera { location <" << cameraPos[0] << "," << cameraPos[1] << "," << cameraPos[2]
David Cazier's avatar
David Cazier committed
941
	    << "> look_at <" << cameraLook[0] << "," << cameraLook[1] << "," << cameraLook[2] << "> " ;
942

David Cazier's avatar
David Cazier committed
943
944
945
946
	if (highlightAgent)
	{
		out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << "> "
		    << std::endl ;
947
948
949
		out << "rotate <" << angleX << "," << angleY << "," << angleZ << "> }" << std::endl ;
	}
	out << "}" << std::endl ;
950

Pierre Kraemer's avatar
Pierre Kraemer committed
951
	//set a sky sphere
952
953
	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
954
	    << std::endl ;
955

Jund Thomas's avatar
Jund Thomas committed
956
957
958
	//green ground
	if(exportCity)
	{
Jund Thomas's avatar
Jund Thomas committed
959
960
961
962
963
964
965
966
967
		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
968
	}
David Cazier's avatar
David Cazier committed
969
//	out << "light_source { <-800, 800, -800> color rgb 0.25 }" << std::endl ;
Jund Thomas's avatar
Jund Thomas committed
970

Pierre Kraemer's avatar
Pierre Kraemer committed
971
	//set a high quality rendering
972
973
974
	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
975
976
977
//	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
978
	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
979

David Cazier's avatar
David Cazier committed
980
	for (unsigned int i = 0 ; i < simulator.agents_.size() ; ++i)
David Cazier's avatar
David Cazier committed
981
982
983
	{
		if (draft)
		{
984
			out << "cylinder {" << " <0,0,0>, <0,6,0>, 1.5 " << std::endl ;
Thomas's avatar
Thomas committed
985

986
			out << "scale 0.5" << std::endl ;
Thomas's avatar
Thomas committed
987

David Cazier's avatar
David Cazier committed
988
			VEC3 col = Utils::color_map_BCGYR(float(i) / float(simulator.agents_.size())) ;
989
			out << "pigment { color <" << col[0] << "," << col[1] << "," << col[2] << "> }"
David Cazier's avatar
David Cazier committed
990
			    << std::endl ;
991
		}
David Cazier's avatar
David Cazier committed
992
993
994
995
		else
		{
			if (i == 0)
			{
996
997
998
				out << "object {" << " Sheriff_animated_ " << std::endl ;
				out << "scale 0.165745856" << std::endl ;
			}
David Cazier's avatar
David Cazier committed
999
1000
			else if (i % 7 == 0)
			{
1001
1002
1003
				out << "object {" << " Cowbow_animated_ " << std::endl ;
				out << "scale 0.170454545" << std::endl ;
			}
David Cazier's avatar
David Cazier committed
1004
1005
			else if (i % 7 < 5)
			{
1006
1007
				out << "object {" << " sombrero2_highres_ " << std::endl ;
				out << "scale 0.127659574" << std::endl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1008
			}
David Cazier's avatar
David Cazier committed
1009
1010
			else
			{
1011
1012
				out << "object {" << " sombrero3_highres_ " << std::endl ;
				out << "scale 0.132743363" << std::endl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
1013
			}
1014
		}
1015

David Cazier's avatar
David Cazier committed
1016
		VEC3 pBase(simulator.agents_[i]->getPosition()) ;
1017
		VEC3 posR(pBase) ;
1018

1019
1020
1021
//			Geom::Plane3D<float> pl = Algo::Geometry::facePlane<PFP>(map,sim.agents_[i]->part_.d,position);
//			posR[2] -= 1000;
//			Geom::intersectionPlaneRay(pl,posR,VEC3(0,0,-1),posR);
1022

David Cazier's avatar
David Cazier committed
1023
		VEC3 dir = simulator.agents_[i]->meanDirection_ ;
1024
1025
1026
		VEC3 base(0, -1, 0) ;
		VEC3 axisRot = base ^ dir ;
		int sign = axisRot[2] > 0 ? 1 : -1 ;
Jund Thomas's avatar
Jund Thomas committed
1027
1028

		//57,2957795 : conversion from radian to degree
David Cazier's avatar
David Cazier committed
1029
		float myRot = acos(-dir[1]) * 57.2957795f ;
Jund Thomas's avatar
Jund Thomas committed
1030

1031
		out << "rotate <0,0," << -90 + sign * myRot << ">" << std::endl ;
David Cazier's avatar
David Cazier committed
1032
1033
		out << "rotate <" << angleX - 90 << "," << angleY << "," << angleZ << "> " << std::endl ;
		out << "translate <" << posR[0] << "," << posR[2] << "," << posR[1] << "> " << std::endl ;
Jund Thomas's avatar
Jund Thomas committed
1034
		out << "translate <" << translate[0] << "," << translate[1] << "," << translate[2] << ">" << std::endl ;
1035
1036
		out << "}" << std::endl ;

David Cazier's avatar
David Cazier committed
1037
1038
		if (exportPath)
		{
1039
			out << "sphere_sweep { cubic_spline" << std::endl ;
David Cazier's avatar
David Cazier committed
1040
1041
			out << simulator.agents_[i]->goals_.size() << "," << std::endl ;
			for (unsigned int j = 0 ; j < simulator.agents_[i]->goals_.size() ; ++j)
David Cazier's avatar
David Cazier committed
1042
			{
David Cazier's avatar
David Cazier committed
1043
1044
				out << "<" << simulator.agents_[i]->goals_[j][0] << "," << simulator.agents_[i]->goals_[j][2]
				    << "," << simulator.agents_[i]->goals_[j][1] << ">, 4" << std::endl ;
1045
1046
			}

David Cazier's avatar
David Cazier committed
1047
			VEC3 col = Utils::color_map_BCGYR(float(i) / float(simulator.agents_.size())) ;
1048
			out << "pigment { color <" << col[0] << "," << col[1] << "," << col[2] << "> }"
David Cazier's avatar
David Cazier committed
1049
			    << std::endl ;
1050
			out << " }" << std::endl ;
1051
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
1052
1053
	}

pitiot's avatar
maj    
pitiot committed
1054
1055
	if(exportMovObst)
	{
David Cazier's avatar
David Cazier committed
1056
		for (std::vector<MovingObstacle*>::iterator it = simulator.movingObstacles_.begin() ; it != simulator.movingObstacles_.end() ; ++it)
pitiot's avatar
maj    
pitiot committed
1057
1058
		{
			float bottom = 0.0f;
pitiot's avatar
pitiot committed
1059
1060
			float height = 10.0f;

pitiot's avatar
maj    
pitiot committed
1061
1062
1063
1064
1065
1066
1067
			unsigned int nbPoints = (*it)->nbVertices;

			out << "prism {" << std::endl;
			out << "linear_sweep" << std::endl;
			out << "linear_spline" << std::endl;
			out << bottom << std::endl; // sweep the following shape from here ...
			out << bottom+height << std::endl; // ... up through here
pitiot's avatar
pitiot committed
1068
			out << nbPoints+1 << std::endl; // the number of points making up the shape ...
pitiot's avatar
maj    
pitiot committed
1069
1070
1071

			for(unsigned int i=0; i <= nbPoints ; ++i)
			{
Thomas Jund's avatar
Thomas Jund committed
1072
1073
1074
				VEC3 pos = (*it)->getPosition(i%nbPoints);
				if(exportDilatedPos)
					pos = (*it)->getDilatedPosition(i%nbPoints);
pitiot's avatar
maj    
pitiot committed
1075
1076
				out << "<" << pos[0] << "," << pos[1] << ">" << std::endl;
			}
Thomas Jund's avatar
Thomas Jund committed
1077
1078
1079
1080
			if(exportDilatedPos)
				out << "pigment { Yellow }" << std::endl;
			else
				out << "pigment { Red }" << std::endl;
pitiot's avatar
maj