viewer.h 9.65 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>
David Cazier's avatar
David Cazier committed
27
#include <sys/time.h>
Pierre Kraemer's avatar
Pierre Kraemer committed
28

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

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

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

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

#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
51
#include "Utils/fbo.h"
Thomas Jund's avatar
Thomas Jund committed
52 53
#include "Utils/drawer.h"
#include "Utils/pointSprite.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
54

Thomas Jund's avatar
Thomas Jund committed
55 56
#include "shaderCustom.h"

57
//#define EXPORTING
Thomas Jund's avatar
Thomas Jund committed
58
//#define ONERING
pitiot's avatar
Merge  
pitiot committed
59
#define SHADOWSHELL
Thomas Jund's avatar
Thomas Jund committed
60

Pierre Kraemer's avatar
Pierre Kraemer committed
61 62
using namespace CGoGN ;

David Cazier's avatar
David Cazier committed
63
typedef PFP::MAP MAP ;
Pierre Kraemer's avatar
Pierre Kraemer committed
64

65
class SocialAgents : public Utils::QT::SimpleQGLV
Pierre Kraemer's avatar
Pierre Kraemer committed
66
{
Pierre Kraemer's avatar
Pierre Kraemer committed
67 68
	Q_OBJECT

Pierre Kraemer's avatar
Pierre Kraemer committed
69
public:
pitiot's avatar
pitiot committed
70
	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
71

Pierre Kraemer's avatar
Pierre Kraemer committed
72 73
	void initGUI() ;

Thomas Jund's avatar
Thomas Jund committed
74 75
	void updateVBOprimitives(int upType);

Pierre Kraemer's avatar
Pierre Kraemer committed
76
	void cb_initGL() ;
Thomas Jund's avatar
Thomas Jund committed
77 78 79 80 81
	void initRendering();
	void updateObstacleVBO();
	void updateAgentPredTriVBO();
	void updateObstaclePredTriVBO();

Thomas Jund's avatar
Thomas Jund committed
82
	void moveCameraTo(VEC3 newPos);
Pierre Kraemer's avatar
Pierre Kraemer committed
83
	void cb_redraw() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
84

Pierre Kraemer's avatar
Pierre Kraemer committed
85
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
86 87 88
	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
89
	                    float angle_X, float angle_Y, float angle_Z) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
90
#endif
David Cazier's avatar
David Cazier committed
91

92 93
//	void cb_keyPress(int keycode) ;
	void keyPressEvent(QKeyEvent *e);
Pierre Kraemer's avatar
Pierre Kraemer committed
94

Thomas Jund's avatar
Thomas Jund committed
95 96 97 98 99 100 101 102
	//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
103
	Algo::Render::GL2::MapRender* m_renderPedway;
Thomas Jund's avatar
Thomas Jund committed
104 105 106 107 108 109
	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
110 111
	Algo::Render::GL2::MapRender* m_renderWithin;

Thomas Jund's avatar
Thomas Jund committed
112 113 114 115 116
	//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
117 118 119
#ifdef EXPORTING
	ShaderCustom* m_flatShader_scenary;
#else
Thomas Jund's avatar
Thomas Jund committed
120
	Utils::ShaderFlat* m_flatShader_scenary;
Thomas Jund's avatar
Thomas Jund committed
121
#endif
Thomas Jund's avatar
Thomas Jund committed
122

Thomas Jund's avatar
merge  
Thomas Jund committed
123

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

Thomas Jund's avatar
Thomas Jund committed
152 153 154 155 156 157 158 159
	//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
160 161 162 163 164
	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
165 166
	std::stringstream filename;
	std::stringstream name;
Thomas Jund's avatar
Thomas Jund committed
167

Thomas Jund's avatar
Thomas Jund committed
168 169 170 171
	enum renderMode {SIMPLE} ;
	int m_renderStyle;
	//////

Thomas Jund's avatar
Thomas Jund committed
172 173
	Geom::BoundingBox<PFP::VEC3> bb ;

David Cazier's avatar
David Cazier committed
174
	Utils::QT::uiDockInterface dock ;
Pierre Kraemer's avatar
Pierre Kraemer committed
175

David Cazier's avatar
David Cazier committed
176
	QTimer* timer ;
177 178
	time_t elapsedTime;
	long int time_update;
Pierre Kraemer's avatar
Pierre Kraemer committed
179

David Cazier's avatar
David Cazier committed
180 181 182 183 184 185 186
	/* 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
187 188
	unsigned int nbGeneratedPov;

Pierre Kraemer's avatar
Pierre Kraemer committed
189
	// to count fps
David Cazier's avatar
David Cazier committed
190
	unsigned int frames ;
David Cazier's avatar
David Cazier committed
191 192
	struct timespec startTime ;
	time_t nextUpdate ;
David Cazier's avatar
David Cazier committed
193

David Cazier's avatar
David Cazier committed
194
	Simulator simulator ;
David Cazier's avatar
David Cazier committed
195 196 197 198
	SelectorTrue allDarts ;

	bool render_anim ;
	int visu ;
199
	Utils::Drawer* m_ds;
Pierre Kraemer's avatar
Pierre Kraemer committed
200 201 202 203
	bool drawEnvLines ;
	bool drawEnvFaces ;
	bool drawEnvTopo ;
	bool drawObstacles ;
pitiot's avatar
pitiot committed
204
	bool drawMovingObstacles ;
Pierre Kraemer's avatar
Pierre Kraemer committed
205 206 207 208
	bool drawAgents ;
	bool drawAgentsNeighborDist ;
	bool drawAgentsObstacleDist ;
	bool drawAgentsPredictionTri ;
209
	bool drawAgentsPath ;
Jund Thomas's avatar
Jund Thomas committed
210
	bool drawObstPredictionTri ;
211
	bool drawObstPath ;
pitiot's avatar
pitiot committed
212
	bool draw_dart;
pitiot's avatar
pitiot committed
213
	bool target_Agent;
214
	bool draw_posX;
pitiot's avatar
merging  
pitiot committed
215
	bool draw_elipse;
pitiot's avatar
pitiot committed
216
	unsigned int dartSlider;
pitiot's avatar
pitiot committed
217
	unsigned int agentSlider;
218 219
	int posXSlider;
	int posYSlider;
220
	bool display_times;
pitiot's avatar
stats  
pitiot committed
221
	bool percent;
Pierre Kraemer's avatar
Pierre Kraemer committed
222 223
public slots:
	void animate() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
224

David Cazier's avatar
David Cazier committed
225 226 227
	void slot_timer(bool b)
	{
		b ? timer->start() : timer->stop() ;
pitiot's avatar
stats  
pitiot committed
228
		clock_gettime(CLOCK_MONOTONIC, &startTime) ;
pitiot's avatar
pitiot committed
229
//		display_times =b;
David Cazier's avatar
David Cazier 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
	}
	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
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281

		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
282 283
		updateGL() ;
	}
Jund Thomas's avatar
Jund Thomas committed
284 285 286
	void slot_drawObstPredictionTri(bool b)
	{
		drawObstPredictionTri = b ;
Thomas Jund's avatar
Thomas Jund committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309

		if(drawObstPredictionTri && m_triObst_render.size()==0)
		{
			for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
			{
					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);
					vbo->allocate(3);
					shader->setAttributePosition(vbo);

					m_triObst_VBO.push_back(vbo);
					m_triObst_Shader.push_back(shader);
					registerShader(shader);
			}
		}

Jund Thomas's avatar
Jund Thomas committed
310 311
		updateGL() ;
	}
David Cazier's avatar
David Cazier committed
312 313 314 315 316 317 318 319 320 321
	void slot_drawAgentsNeighborDist(bool b)
	{
		drawAgentsNeighborDist = b ;
		updateGL() ;
	}
	void slot_drawAgentsObstacleDist(bool b)
	{
		drawAgentsObstacleDist = b ;
		updateGL() ;
	}
322 323 324 325 326
	void slot_drawAgentsPath(bool b)
	{
		drawAgentsPath= b ;
		updateGL() ;
	}
327 328 329 330 331
	void slot_drawMovingObstacles(bool b)
	{
		drawMovingObstacles = b ;
		updateGL() ;
	}
332 333 334 335 336
	void slot_drawObstPath(bool b)
	{
		drawObstPath= b ;
		updateGL() ;
	}
337 338 339 340 341 342 343 344 345 346
	void slot_dart(bool b)
	{
		draw_dart = b ;
		updateGL() ;
	}
	void slot_slide(int i)
	{
		dartSlider = i;
		updateGL();
	}
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
	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
362
	void slot_elipse(bool b)
363 364 365 366
	{
		draw_elipse = b;
		updateGL();
	}
pitiot's avatar
pitiot committed
367
	void slot_Agent(bool b)
Thomas Jund's avatar
merge  
Thomas Jund committed
368 369 370 371
	{
	target_Agent = b ;
		updateGL() ;
	}
pitiot's avatar
pitiot committed
372
	void slot_AgentSlider(int i)
Thomas Jund's avatar
merge  
Thomas Jund committed
373 374 375 376
	{
	agentSlider = i ;
		updateGL() ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
377
} ;