viewer.h 10.5 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
/*******************************************************************************
David Cazier's avatar
David Cazier committed
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 <iostream>
pitiot's avatar
stats    
pitiot committed
26
#include <fstream>
pitiot's avatar
merging    
pitiot committed
27
#include <sstream>
David Cazier's avatar
David Cazier committed
28
#include <sys/time.h>
Pierre Kraemer's avatar
Pierre Kraemer committed
29

30
#include "Utils/Qt/qtQGLV.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
31
#include "ui_socialAgents.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32
#include "Utils/Qt/qtui.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
33
34
35

#include "simulator.h"
#include "env_render.h"
Thomas's avatar
Thomas committed
36
#include "exportObstacles.h"
37
#include "gl2ps.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
38

Pierre Kraemer's avatar
Pierre Kraemer committed
39
#include "Algo/Geometry/boundingbox.h"
40

Pierre Kraemer's avatar
Pierre Kraemer committed
41
#include "Algo/Export/exportPov.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
42
#include "Utils/GLSLShader.h"
Pierre Kraemer's avatar
yeah    
Pierre Kraemer committed
43
#include "Utils/colorMaps.h"
Thomas Jund's avatar
Thomas Jund committed
44
45
46
47
48
49
50
51

#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Render/GL2/topoRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderPhong.h"
#include "Utils/colorMaps.h"
#include "Utils/vbo.h"
Thomas Jund's avatar
Thomas Jund committed
52
#include "Utils/fbo.h"
Thomas Jund's avatar
Thomas Jund committed
53
54
#include "Utils/drawer.h"
#include "Utils/pointSprite.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
55

Thomas Jund's avatar
Thomas Jund committed
56
#include "shaderCustom.h"
Thomas Jund's avatar
Thomas Jund committed
57
#include "shaderPhongTexCust.h"
Thomas Jund's avatar
Thomas Jund committed
58

pitiot's avatar
pitiot committed
59
//#define DRAW_REGISTRATION //montre l'enregistrement détaillé des obstacles mobiles dansla topologie
pitiot's avatar
pitiot committed
60
61
62
63


#define AFFICHE_MESH
//#define EXPORTING // ne pas activer
pitiot's avatar
pitiot committed
64
65
//#define ONERING	     // affiche l'enregistrement global des obstacles mobiles en tant que cellules
//#define SHADOWSHELL // shadowshells ... old
Thomas Jund's avatar
Thomas Jund committed
66

Pierre Kraemer's avatar
Pierre Kraemer committed
67
68
using namespace CGoGN ;

David Cazier's avatar
David Cazier committed
69
typedef PFP::MAP MAP ;
Pierre Kraemer's avatar
Pierre Kraemer committed
70

71
class SocialAgents : public Utils::QT::SimpleQGLV
Pierre Kraemer's avatar
Pierre Kraemer committed
72
{
Pierre Kraemer's avatar
Pierre Kraemer committed
73
74
	Q_OBJECT

Pierre Kraemer's avatar
Pierre Kraemer committed
75
public:
pitiot's avatar
pitiot committed
76
	SocialAgents(unsigned int config, unsigned int minSize, unsigned int nbAgent , unsigned int nbObst ,bool resolution, unsigned int iterations) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
77

Pierre Kraemer's avatar
Pierre Kraemer committed
78
79
	void initGUI() ;

Thomas Jund's avatar
Thomas Jund committed
80
81
	void updateVBOprimitives(int upType);

Pierre Kraemer's avatar
Pierre Kraemer committed
82
	void cb_initGL() ;
Thomas Jund's avatar
Thomas Jund committed
83
84
85
86
	void initRendering();
	void updateObstacleVBO();
	void updateAgentPredTriVBO();
	void updateObstaclePredTriVBO();
pitiot's avatar
pitiot committed
87
	void drawCell(Dart d, float width, float r, float g, float b);
Thomas Jund's avatar
Thomas Jund committed
88

Thomas Jund's avatar
Thomas Jund committed
89
	void moveCameraTo(VEC3 newPos);
Pierre Kraemer's avatar
Pierre Kraemer committed
90
	void cb_redraw() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
91

Pierre Kraemer's avatar
Pierre Kraemer committed
92
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
93
94
95
	void exportInfoFace(std::ofstream& out, Dart d) ;
	bool exportScenePov(PFP::MAP& map, PFP::TVEC3& position, const std::string& filename,
	                    PFP::VEC3 cameraPos, PFP::VEC3 cameraLook, PFP::VEC3 translate,
Sylvain Thery's avatar
Sylvain Thery committed
96
	                    float angle_X, float angle_Y, float angle_Z) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
#endif
David Cazier's avatar
David Cazier committed
98

99
100
//	void cb_keyPress(int keycode) ;
	void keyPressEvent(QKeyEvent *e);
Pierre Kraemer's avatar
Pierre Kraemer committed
101

Thomas Jund's avatar
Thomas Jund committed
102
103
104
105
106
107
108
109
	//RENDERING
	Geom::Vec4f colDif ;
	Geom::Vec4f colSpec ;
	Geom::Vec4f colClear ;
	Geom::Vec4f colNormal ;

	//navigation map
	Algo::Render::GL2::MapRender* m_render;
Thomas Jund's avatar
Thomas Jund committed
110
	Algo::Render::GL2::MapRender* m_renderPedway;
Thomas Jund's avatar
Thomas Jund committed
111
112
113
114
115
116
	Algo::Render::GL2::TopoRender* m_renderTopo;
	Utils::VBO* m_positionVBO;
	Utils::VBO* m_normalVBO;
	Utils::VBO* m_colorVBO;
	Utils::ShaderSimpleColor* m_simpleColorShader;

Thomas Jund's avatar
Thomas Jund committed
117
118
	Algo::Render::GL2::MapRender* m_renderWithin;

Thomas Jund's avatar
Thomas Jund committed
119
120
121
122
123
	//building
	Algo::Render::GL2::MapRender* m_render_scenary;
	Utils::VBO* m_positionVBO_scenary;
	Utils::VBO* m_normalVBO_scenary;
	Utils::VBO* m_colorVBO_scenary;
Thomas Jund's avatar
Thomas Jund committed
124
125
126
#ifdef EXPORTING
	ShaderCustom* m_flatShader_scenary;
#else
Thomas Jund's avatar
Thomas Jund committed
127
	Utils::ShaderFlat* m_flatShader_scenary;
Thomas Jund's avatar
Thomas Jund committed
128
#endif
Thomas Jund's avatar
Thomas Jund committed
129

Thomas Jund's avatar
merge    
Thomas Jund committed
130

Thomas Jund's avatar
Thomas Jund committed
131
132
133
134
135
136
137
138
139
140
141
#ifdef EXPORTING_OBJ
	PFP2::MAP mapAgent;
	VertexAttribute<VEC3> positionAgent;
	VertexAttribute<VEC3> normalAgent;

	Algo::Render::GL2::MapRender* m_renderAgent;
	Utils::VBO* m_positionVBOAgent;
	Utils::VBO* m_normalVBOAgent;

	Utils::Texture<2,Geom::Vec3uc>* m_textureAgent;
	Utils::VBO* m_texcoordVBOAgent;
Thomas Jund's avatar
Thomas Jund committed
142
143
// 	ShaderCustomTex* m_shaderTexAgent;
	ShaderPhongTexCust* m_shaderTexAgent;
Thomas Jund's avatar
Thomas Jund committed
144
145
146
	Algo::Surface::Import::OBJModel<PFP2> m_objAgent;
	unsigned int m_nbIndicesAgent;
#endif
Thomas Jund's avatar
Thomas Jund committed
147
148
149
150
151
152
153
154
155
	//agents
	Utils::VBO* m_agentsVBO;
	Utils::PointSprite* m_sprite;

	//obstacles ground
	std::vector<Algo::Render::GL2::MapRender*> m_obst_render;
	std::vector<Utils::VBO*> m_obst_VBO;
	std::vector<Utils::ShaderFlat*> m_obstShader;

Thomas Jund's avatar
Thomas Jund committed
156
157
158
159
	//city ground
	Utils::ShaderFlat* m_Ground_Shader;
	Utils::VBO* m_Ground_VBO;

Thomas Jund's avatar
Thomas Jund committed
160
161
162
163
164
165
166
167
	//prediction triangles
	std::vector<Algo::Render::GL2::MapRender*> m_triObst_render;
	std::vector<Utils::VBO*> m_triObst_VBO;
	std::vector<Utils::ShaderSimpleColor*> m_triObst_Shader;
	std::vector<Algo::Render::GL2::MapRender*> m_triAgent_render;
	std::vector<Utils::VBO*> m_triAgent_VBO;
	std::vector<Utils::ShaderSimpleColor*> m_triAgent_Shader;

Thomas Jund's avatar
Thomas Jund committed
168
169
170
171
172
	static const unsigned int N_THETA = 64;
	static const unsigned int N_PHI   = 128;
	static const float        RADIUS  = 3950.0f;
	Utils::GLSLShader m_DeferedShader;
	Utils::GLSLShader m_DeferedShader2;
pitiot's avatar
stats    
pitiot committed
173
174
	std::stringstream filename;
	std::stringstream name;
Thomas Jund's avatar
Thomas Jund committed
175

Thomas Jund's avatar
Thomas Jund committed
176
177
178
179
	enum renderMode {SIMPLE} ;
	int m_renderStyle;
	//////

pitiot's avatar
merging    
pitiot committed
180
181
182
	// ARASH : camera input file
	std::ifstream cam_input_file;
	bool cif_exists;
pitiot's avatar
merging    
pitiot committed
183

pitiot's avatar
merging    
pitiot committed
184
	unsigned int cif_begin, cif_end;
pitiot's avatar
merging    
pitiot committed
185

pitiot's avatar
merging    
pitiot committed
186
187
188
189
190
191
192
193
	VEC3 *cif_lookfrom;
	VEC3 *cif_lookat;
	VEC3 *cif_upvector;
	void readCameraInputFile(char *filename);

	std::ofstream cam_output_file;


Thomas Jund's avatar
Thomas Jund committed
194
195
	Geom::BoundingBox<PFP::VEC3> bb ;

David Cazier's avatar
David Cazier committed
196
	Utils::QT::uiDockInterface dock ;
Pierre Kraemer's avatar
Pierre Kraemer committed
197

David Cazier's avatar
David Cazier committed
198
	QTimer* timer ;
199
200
	time_t elapsedTime;
	long int time_update;
Pierre Kraemer's avatar
Pierre Kraemer committed
201

David Cazier's avatar
David Cazier committed
202
203
204
205
206
207
208
	/* nbIterations counts the current number of iterations
	 * When maxIterations is reached the simulation is stopped
	 * If maxIterations is set to 0 the simulation is never stopped (interactive)
	 */
	unsigned int nbIterations ;
	unsigned int maxIterations ;

Thomas Jund's avatar
Thomas Jund committed
209
210
	unsigned int nbGeneratedPov;

Pierre Kraemer's avatar
Pierre Kraemer committed
211
	// to count fps
David Cazier's avatar
David Cazier committed
212
	unsigned int frames ;
David Cazier's avatar
David Cazier committed
213
214
	struct timespec startTime ;
	time_t nextUpdate ;
David Cazier's avatar
David Cazier committed
215

David Cazier's avatar
David Cazier committed
216
	Simulator simulator ;
David Cazier's avatar
David Cazier committed
217
218
219
220
	SelectorTrue allDarts ;

	bool render_anim ;
	int visu ;
221
	Utils::Drawer* m_ds;
Pierre Kraemer's avatar
Pierre Kraemer committed
222
223
224
225
	bool drawEnvLines ;
	bool drawEnvFaces ;
	bool drawEnvTopo ;
	bool drawObstacles ;
pitiot's avatar
pitiot committed
226
	bool drawMovingObstacles ;
Pierre Kraemer's avatar
Pierre Kraemer committed
227
228
229
230
	bool drawAgents ;
	bool drawAgentsNeighborDist ;
	bool drawAgentsObstacleDist ;
	bool drawAgentsPredictionTri ;
231
	bool drawAgentsPath ;
Jund Thomas's avatar
Jund Thomas committed
232
	bool drawObstPredictionTri ;
233
	bool drawObstPath ;
pitiot's avatar
pitiot committed
234
	bool draw_dart;
pitiot's avatar
pitiot committed
235
	bool target_Agent;
236
	bool draw_posX;
pitiot's avatar
merging    
pitiot committed
237
	bool draw_elipse;
pitiot's avatar
pitiot committed
238
	unsigned int dartSlider;
pitiot's avatar
pitiot committed
239
	unsigned int agentSlider;
240
241
	int posXSlider;
	int posYSlider;
242
	bool display_times;
pitiot's avatar
stats    
pitiot committed
243
	bool percent;
Pierre Kraemer's avatar
Pierre Kraemer committed
244
public slots:
Arash HABIBI's avatar
Arash HABIBI committed
245
246

	void setCameraDebug();
Pierre Kraemer's avatar
Pierre Kraemer committed
247
	void animate() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
248

David Cazier's avatar
David Cazier committed
249
250
251
	void slot_timer(bool b)
	{
		b ? timer->start() : timer->stop() ;
pitiot's avatar
stats    
pitiot committed
252
		clock_gettime(CLOCK_MONOTONIC, &startTime) ;
pitiot's avatar
pitiot committed
253
//		display_times =b;
David Cazier's avatar
David Cazier committed
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
	}
	void slot_drawEnvLines(bool b)
	{
		drawEnvLines = b ;
		updateGL() ;
	}
	void slot_drawEnvFaces(bool b)
	{
		drawEnvFaces = b ;
		updateGL() ;
	}
	void slot_drawEnvTopo(bool b)
	{
		drawEnvTopo = b ;
		updateGL() ;
	}
	void slot_drawObstacles(bool b)
	{
		drawObstacles = b ;
		updateGL() ;
	}
	void slot_drawAgents(bool b)
	{
		drawAgents = b ;
		updateGL() ;
	}
	void slot_drawAgentsPredictionTri(bool b)
	{
		drawAgentsPredictionTri = b ;
Thomas Jund's avatar
Thomas Jund committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

		if(drawAgentsPredictionTri && m_triAgent_render.size()==0)
		{
			for(unsigned int i=0 ; i < simulator.agents_.size() ; ++i)
			{
					m_triAgent_render.push_back(new Algo::Render::GL2::MapRender());

					Utils::ShaderSimpleColor * shader = new Utils::ShaderSimpleColor();
					shader->setColor(Geom::Vec4f(1.,0.,1.,0.)) ;
//					shader->setAmbiant(Geom::Vec4f(1.,0.,1.,0.5)) ;
//					shader->setDiffuse(Geom::Vec4f(1.,0.,1.,0.5));

					Utils::VBO * vbo = new Utils::VBO();
					vbo->setDataSize(3);
					vbo->allocate(3);
					shader->setAttributePosition(vbo);

					m_triAgent_VBO.push_back(vbo);
					m_triAgent_Shader.push_back(shader);
					registerShader(shader);
			}
		}

David Cazier's avatar
David Cazier committed
306
307
		updateGL() ;
	}
Jund Thomas's avatar
Jund Thomas committed
308
309
310
	void slot_drawObstPredictionTri(bool b)
	{
		drawObstPredictionTri = b ;
Thomas Jund's avatar
Thomas Jund committed
311
312
313
314
315

		if(drawObstPredictionTri && m_triObst_render.size()==0)
		{
			for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
			{
pitiot's avatar
pitiot committed
316
317
//				for(unsigned int j=0 ; j < simulator.movingObstacles_[i]->nbVertices ; ++j)
//				{
Thomas Jund's avatar
Thomas Jund committed
318
319
320
321
322
323
324
325
326
					m_triObst_render.push_back(new Algo::Render::GL2::MapRender());

					Utils::ShaderSimpleColor * shader = new Utils::ShaderSimpleColor();
					shader->setColor(Geom::Vec4f(1.,0.,1.,0.)) ;
//					shader->setAmbiant(Geom::Vec4f(1.,0.,1.,0.5)) ;
//					shader->setDiffuse(Geom::Vec4f(1.,0.,1.,0.5));

					Utils::VBO * vbo = new Utils::VBO();
					vbo->setDataSize(3);
pitiot's avatar
up    
pitiot committed
327
					vbo->allocate(4*simulator.movingObstacles_[i]->nbVertices);
Thomas Jund's avatar
Thomas Jund committed
328
329
330
331
332
					shader->setAttributePosition(vbo);

					m_triObst_VBO.push_back(vbo);
					m_triObst_Shader.push_back(shader);
					registerShader(shader);
pitiot's avatar
pitiot committed
333
//				}
Thomas Jund's avatar
Thomas Jund committed
334
335
336
			}
		}

Jund Thomas's avatar
Jund Thomas committed
337
338
		updateGL() ;
	}
David Cazier's avatar
David Cazier committed
339
340
341
342
343
344
345
346
347
348
	void slot_drawAgentsNeighborDist(bool b)
	{
		drawAgentsNeighborDist = b ;
		updateGL() ;
	}
	void slot_drawAgentsObstacleDist(bool b)
	{
		drawAgentsObstacleDist = b ;
		updateGL() ;
	}
349
350
351
352
353
	void slot_drawAgentsPath(bool b)
	{
		drawAgentsPath= b ;
		updateGL() ;
	}
354
355
356
357
358
	void slot_drawMovingObstacles(bool b)
	{
		drawMovingObstacles = b ;
		updateGL() ;
	}
359
360
361
362
363
	void slot_drawObstPath(bool b)
	{
		drawObstPath= b ;
		updateGL() ;
	}
364
365
366
367
368
369
370
371
372
373
	void slot_dart(bool b)
	{
		draw_dart = b ;
		updateGL() ;
	}
	void slot_slide(int i)
	{
		dartSlider = i;
		updateGL();
	}
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
	void slot_posX(bool b)
	{
		draw_posX = b ;
		updateGL() ;
	}
	void slot_slide2(int i)
	{
		posXSlider = i;
		updateGL();
	}
	void slot_slide3(int i)
	{
		posYSlider = i;
		updateGL();
	}
pitiot's avatar
merging    
pitiot committed
389
	void slot_elipse(bool b)
390
391
392
393
	{
		draw_elipse = b;
		updateGL();
	}
pitiot's avatar
pitiot committed
394
	void slot_Agent(bool b)
Thomas Jund's avatar
merge    
Thomas Jund committed
395
396
397
398
	{
	target_Agent = b ;
		updateGL() ;
	}
pitiot's avatar
pitiot committed
399
	void slot_AgentSlider(int i)
Thomas Jund's avatar
merge    
Thomas Jund committed
400
401
402
403
	{
	agentSlider = i ;
		updateGL() ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
404
} ;