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

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
39
#include "Algo/Export/exportPov.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
40
#include "Utils/GLSLShader.h"
Pierre Kraemer's avatar
yeah  
Pierre Kraemer committed
41
#include "Utils/colorMaps.h"
Thomas Jund's avatar
Thomas Jund committed
42 43 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"
#include "Utils/drawer.h"
#include "Utils/pointSprite.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
52 53 54

using namespace CGoGN ;

David Cazier's avatar
David Cazier committed
55
typedef PFP::MAP MAP ;
Pierre Kraemer's avatar
Pierre Kraemer committed
56

Pierre Kraemer's avatar
Pierre Kraemer committed
57
class SocialAgents : public Utils::QT::SimpleQT
Pierre Kraemer's avatar
Pierre Kraemer committed
58
{
Pierre Kraemer's avatar
Pierre Kraemer committed
59 60
	Q_OBJECT

Pierre Kraemer's avatar
Pierre Kraemer committed
61
public:
62
	SocialAgents(unsigned int config, unsigned int minSize, unsigned int nbAgent , unsigned int nbObst , unsigned int iterations) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
63

Pierre Kraemer's avatar
Pierre Kraemer committed
64 65
	void initGUI() ;

Thomas Jund's avatar
Thomas Jund committed
66 67
	void updateVBOprimitives(int upType);

Pierre Kraemer's avatar
Pierre Kraemer committed
68
	void cb_initGL() ;
Thomas Jund's avatar
Thomas Jund committed
69 70 71 72 73
	void initRendering();
	void updateObstacleVBO();
	void updateAgentPredTriVBO();
	void updateObstaclePredTriVBO();

Pierre Kraemer's avatar
Pierre Kraemer committed
74
	void cb_redraw() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
75

Pierre Kraemer's avatar
Pierre Kraemer committed
76
#ifndef SPATIAL_HASHING
David Cazier's avatar
David Cazier committed
77 78 79 80 81
	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,
	                    float angle_X, float angle_Y, float angle_Z,
	                    const FunctorSelect& good = SelectorTrue()) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
82
#endif
David Cazier's avatar
David Cazier committed
83

Pierre Kraemer's avatar
Pierre Kraemer committed
84 85
	void cb_keyPress(int keycode) ;

Thomas Jund's avatar
Thomas Jund committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
	//RENDERING
	Geom::Vec4f colDif ;
	Geom::Vec4f colSpec ;
	Geom::Vec4f colClear ;
	Geom::Vec4f colNormal ;

	//navigation map
	Algo::Render::GL2::MapRender* m_render;
	Algo::Render::GL2::TopoRender* m_renderTopo;
	Utils::VBO* m_positionVBO;
	Utils::VBO* m_normalVBO;
	Utils::VBO* m_colorVBO;
	Utils::ShaderSimpleColor* m_simpleColorShader;

	//building
	Algo::Render::GL2::MapRender* m_render_scenary;
	Utils::VBO* m_positionVBO_scenary;
	Utils::VBO* m_normalVBO_scenary;
	Utils::VBO* m_colorVBO_scenary;
	Utils::ShaderFlat* m_flatShader_scenary;

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

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

	enum renderMode {SIMPLE} ;
	int m_renderStyle;
	//////

David Cazier's avatar
David Cazier committed
128
	Utils::QT::uiDockInterface dock ;
Pierre Kraemer's avatar
Pierre Kraemer committed
129

David Cazier's avatar
David Cazier committed
130
	QTimer* timer ;
Pierre Kraemer's avatar
Pierre Kraemer committed
131

David Cazier's avatar
David Cazier committed
132 133 134 135 136 137 138
	/* 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
139 140
	unsigned int nbGeneratedPov;

Pierre Kraemer's avatar
Pierre Kraemer committed
141
	// to count fps
David Cazier's avatar
David Cazier committed
142
	unsigned int frames ;
David Cazier's avatar
David Cazier committed
143 144
	struct timespec startTime ;
	time_t nextUpdate ;
David Cazier's avatar
David Cazier committed
145

David Cazier's avatar
David Cazier committed
146
	Simulator simulator ;
David Cazier's avatar
David Cazier committed
147 148 149 150
	SelectorTrue allDarts ;

	bool render_anim ;
	int visu ;
Pierre Kraemer's avatar
Pierre Kraemer committed
151

Pierre Kraemer's avatar
Pierre Kraemer committed
152 153 154 155
	bool drawEnvLines ;
	bool drawEnvFaces ;
	bool drawEnvTopo ;
	bool drawObstacles ;
pitiot's avatar
pitiot committed
156
	bool drawMovingObstacles ;
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159 160
	bool drawAgents ;
	bool drawAgentsNeighborDist ;
	bool drawAgentsObstacleDist ;
	bool drawAgentsPredictionTri ;
161
	bool drawAgentsPath ;
Jund Thomas's avatar
Jund Thomas committed
162
	bool drawObstPredictionTri ;
163
	bool drawObstPath ;
pitiot's avatar
pitiot committed
164
	bool draw_dart;
165
	bool draw_posX;
pitiot's avatar
merging  
pitiot committed
166
	bool draw_elipse;
pitiot's avatar
pitiot committed
167
	unsigned int dartSlider;
168 169
	int posXSlider;
	int posYSlider;
Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172

public slots:
	void animate() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
173

David Cazier's avatar
David Cazier committed
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
	void slot_timer(bool b)
	{
		b ? timer->start() : timer->stop() ;
	}
	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
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228

		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
229 230
		updateGL() ;
	}
Jund Thomas's avatar
Jund Thomas committed
231 232 233
	void slot_drawObstPredictionTri(bool b)
	{
		drawObstPredictionTri = b ;
Thomas Jund's avatar
Thomas Jund committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256

		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
257 258
		updateGL() ;
	}
David Cazier's avatar
David Cazier committed
259 260 261 262 263 264 265 266 267 268
	void slot_drawAgentsNeighborDist(bool b)
	{
		drawAgentsNeighborDist = b ;
		updateGL() ;
	}
	void slot_drawAgentsObstacleDist(bool b)
	{
		drawAgentsObstacleDist = b ;
		updateGL() ;
	}
269 270 271 272 273
	void slot_drawAgentsPath(bool b)
	{
		drawAgentsPath= b ;
		updateGL() ;
	}
274 275 276 277 278
	void slot_drawMovingObstacles(bool b)
	{
		drawMovingObstacles = b ;
		updateGL() ;
	}
279 280 281 282 283
	void slot_drawObstPath(bool b)
	{
		drawObstPath= b ;
		updateGL() ;
	}
284 285 286 287 288 289 290 291 292 293
	void slot_dart(bool b)
	{
		draw_dart = b ;
		updateGL() ;
	}
	void slot_slide(int i)
	{
		dartSlider = i;
		updateGL();
	}
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
	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
309
	void slot_elipse(bool b)
310 311 312 313
	{
		draw_elipse = b;
		updateGL();
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
314
} ;