viewer.h 10 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 57
#include "shaderCustom.h"

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

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

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

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

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

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

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

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

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

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

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

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

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

Thomas Jund's avatar
merge  
Thomas Jund committed
124

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

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

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

pitiot's avatar
merging  
pitiot committed
173 174 175 176 177 178 179 180 181 182 183 184
	// ARASH : camera input file
	std::ifstream cam_input_file;
	bool cif_exists;
	unsigned int cif_begin, cif_end;
	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
185 186
	Geom::BoundingBox<PFP::VEC3> bb ;

David Cazier's avatar
David Cazier committed
187
	Utils::QT::uiDockInterface dock ;
Pierre Kraemer's avatar
Pierre Kraemer committed
188

David Cazier's avatar
David Cazier committed
189
	QTimer* timer ;
190 191
	time_t elapsedTime;
	long int time_update;
Pierre Kraemer's avatar
Pierre Kraemer committed
192

David Cazier's avatar
David Cazier committed
193 194 195 196 197 198 199
	/* 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
200 201
	unsigned int nbGeneratedPov;

Pierre Kraemer's avatar
Pierre Kraemer committed
202
	// to count fps
David Cazier's avatar
David Cazier committed
203
	unsigned int frames ;
David Cazier's avatar
David Cazier committed
204 205
	struct timespec startTime ;
	time_t nextUpdate ;
David Cazier's avatar
David Cazier committed
206

David Cazier's avatar
David Cazier committed
207
	Simulator simulator ;
David Cazier's avatar
David Cazier committed
208 209 210 211
	SelectorTrue allDarts ;

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

David Cazier's avatar
David Cazier committed
238 239 240
	void slot_timer(bool b)
	{
		b ? timer->start() : timer->stop() ;
pitiot's avatar
stats  
pitiot committed
241
		clock_gettime(CLOCK_MONOTONIC, &startTime) ;
pitiot's avatar
pitiot committed
242
//		display_times =b;
David Cazier's avatar
David Cazier committed
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
	}
	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
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

		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
295 296
		updateGL() ;
	}
Jund Thomas's avatar
Jund Thomas committed
297 298 299
	void slot_drawObstPredictionTri(bool b)
	{
		drawObstPredictionTri = b ;
Thomas Jund's avatar
Thomas Jund committed
300 301 302 303 304

		if(drawObstPredictionTri && m_triObst_render.size()==0)
		{
			for(unsigned int i=0 ; i < simulator.movingObstacles_.size() ; ++i)
			{
pitiot's avatar
pitiot committed
305 306
//				for(unsigned int j=0 ; j < simulator.movingObstacles_[i]->nbVertices ; ++j)
//				{
Thomas Jund's avatar
Thomas Jund committed
307 308 309 310 311 312 313 314 315
					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
316
					vbo->allocate(4*simulator.movingObstacles_[i]->nbVertices);
Thomas Jund's avatar
Thomas Jund committed
317 318 319 320 321
					shader->setAttributePosition(vbo);

					m_triObst_VBO.push_back(vbo);
					m_triObst_Shader.push_back(shader);
					registerShader(shader);
pitiot's avatar
pitiot committed
322
//				}
Thomas Jund's avatar
Thomas Jund committed
323 324 325
			}
		}

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