viewer.h 10.3 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 60
#define DRAW_REGISTRATION //montre l'enregistrement des obstacles mobiles
//#define AFFICHE_MESH
61
//#define EXPORTING
Thomas Jund's avatar
Thomas Jund committed
62
//#define ONERING
Arash HABIBI's avatar
Arash HABIBI committed
63
//#define SHADOWSHELL
Thomas Jund's avatar
Thomas Jund committed
64

Pierre Kraemer's avatar
Pierre Kraemer committed
65 66
using namespace CGoGN ;

David Cazier's avatar
David Cazier committed
67
typedef PFP::MAP MAP ;
Pierre Kraemer's avatar
Pierre Kraemer committed
68

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

Pierre Kraemer's avatar
Pierre Kraemer committed
73
public:
pitiot's avatar
pitiot committed
74
	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
75

Pierre Kraemer's avatar
Pierre Kraemer committed
76 77
	void initGUI() ;

Thomas Jund's avatar
Thomas Jund committed
78 79
	void updateVBOprimitives(int upType);

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
90
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
91 92 93
	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
94
	                    float angle_X, float angle_Y, float angle_Z) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
95
#endif
David Cazier's avatar
David Cazier committed
96

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

Thomas Jund's avatar
Thomas Jund committed
100 101 102 103 104 105 106 107
	//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
108
	Algo::Render::GL2::MapRender* m_renderPedway;
Thomas Jund's avatar
Thomas Jund committed
109 110 111 112 113 114
	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
115 116
	Algo::Render::GL2::MapRender* m_renderWithin;

Thomas Jund's avatar
Thomas Jund committed
117 118 119 120 121
	//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
122 123 124
#ifdef EXPORTING
	ShaderCustom* m_flatShader_scenary;
#else
Thomas Jund's avatar
Thomas Jund committed
125
	Utils::ShaderFlat* m_flatShader_scenary;
Thomas Jund's avatar
Thomas Jund committed
126
#endif
Thomas Jund's avatar
Thomas Jund committed
127

Thomas Jund's avatar
merge  
Thomas Jund committed
128

Thomas Jund's avatar
Thomas Jund committed
129 130 131 132 133 134 135 136 137 138 139
#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
140 141
// 	ShaderCustomTex* m_shaderTexAgent;
	ShaderPhongTexCust* m_shaderTexAgent;
Thomas Jund's avatar
Thomas Jund committed
142 143 144
	Algo::Surface::Import::OBJModel<PFP2> m_objAgent;
	unsigned int m_nbIndicesAgent;
#endif
Thomas Jund's avatar
Thomas Jund committed
145 146 147 148 149 150 151 152 153
	//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
154 155 156 157
	//city ground
	Utils::ShaderFlat* m_Ground_Shader;
	Utils::VBO* m_Ground_VBO;

Thomas Jund's avatar
Thomas Jund committed
158 159 160 161 162 163 164 165
	//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
166 167 168 169 170
	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
171 172
	std::stringstream filename;
	std::stringstream name;
Thomas Jund's avatar
Thomas Jund committed
173

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

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

pitiot's avatar
merging  
pitiot committed
182
	unsigned int cif_begin, cif_end;
pitiot's avatar
merging  
pitiot committed
183

pitiot's avatar
merging  
pitiot committed
184 185 186 187 188 189 190 191
	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
192 193
	Geom::BoundingBox<PFP::VEC3> bb ;

David Cazier's avatar
David Cazier committed
194
	Utils::QT::uiDockInterface dock ;
Pierre Kraemer's avatar
Pierre Kraemer committed
195

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

David Cazier's avatar
David Cazier committed
200 201 202 203 204 205 206
	/* 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
207 208
	unsigned int nbGeneratedPov;

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

David Cazier's avatar
David Cazier committed
214
	Simulator simulator ;
David Cazier's avatar
David Cazier committed
215 216 217 218
	SelectorTrue allDarts ;

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

David Cazier's avatar
David Cazier committed
245 246 247
	void slot_timer(bool b)
	{
		b ? timer->start() : timer->stop() ;
pitiot's avatar
stats  
pitiot committed
248
		clock_gettime(CLOCK_MONOTONIC, &startTime) ;
pitiot's avatar
pitiot committed
249
//		display_times =b;
David Cazier's avatar
David Cazier committed
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
	}
	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
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301

		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
302 303
		updateGL() ;
	}
Jund Thomas's avatar
Jund Thomas committed
304 305 306
	void slot_drawObstPredictionTri(bool b)
	{
		drawObstPredictionTri = b ;
Thomas Jund's avatar
Thomas Jund committed
307 308 309 310 311

		if(drawObstPredictionTri && m_triObst_render.size()==0)
		{
			for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
			{
pitiot's avatar
pitiot committed
312 313
//				for(unsigned int j=0 ; j < simulator.movingObstacles_[i]->nbVertices ; ++j)
//				{
Thomas Jund's avatar
Thomas Jund committed
314 315 316 317 318 319 320 321 322
					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
323
					vbo->allocate(4*simulator.movingObstacles_[i]->nbVertices);
Thomas Jund's avatar
Thomas Jund committed
324 325 326 327 328
					shader->setAttributePosition(vbo);

					m_triObst_VBO.push_back(vbo);
					m_triObst_Shader.push_back(shader);
					registerShader(shader);
pitiot's avatar
pitiot committed
329
//				}
Thomas Jund's avatar
Thomas Jund committed
330 331 332
			}
		}

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