Illustrative Line Visualization
Implementation of the method by Everts et al. for visualizing dense line data.
glwidget.h
1 #ifndef GLWIDGET_H
2 #define GLWIDGET_H
3 
4 #include "trackfile.h"
5 #include "camera.h"
6 
7 #include <QOpenGLWidget>
8 #include <QOpenGLFunctions_4_0_Core>
9 #include <QOpenGLDebugLogger>
10 #include <QTimer>
11 #include <QElapsedTimer>
12 #include <QOpenGLShaderProgram>
13 #include <QOpenGLBuffer>
14 #include <QOpenGLVertexArrayObject>
15 #include <QMatrix4x4>
16 #include <QOpenGLTexture>
17 
21 class GLWidget : public QOpenGLWidget, QOpenGLFunctions_4_0_Core
22 {
23  Q_OBJECT
24 
25  public:
33  GLWidget(QWidget* parent = Q_NULLPTR, int updateRate = 60, bool sampleShading = true, int anisotropy = 1);
34 
35  ~GLWidget();
36 
41  virtual void setTrackData(const QVector<Track>&& tracks);
42 
43  public slots:
44 
49  virtual void setWireframe(bool enabled)
50  {
51  wireframe = enabled;
52  }
53 
58  virtual void setThickness(int p_thickness) {
59  thickness = p_thickness;
60  }
61 
66  virtual void setHalo(int p_halo) {
67  halo = p_halo;
68  }
69 
74  virtual void setStripDepth(int p_stripDepth){
75  stripDepth = p_stripDepth;
76  }
77 
82  virtual void setDepthCueing(int p_depthCueing){
83  depthCueing = p_depthCueing;
84  }
85 
86  protected slots:
87 
94  virtual void updateFrame();
95 
102  virtual void paintGL() Q_DECL_OVERRIDE;
103 
110  virtual void initializeGL() Q_DECL_OVERRIDE;
111 
119  virtual void resizeGL(int w, int h) Q_DECL_OVERRIDE;
120 
121  signals:
122 
127  void frameRate(int fps);
128 
129  protected:
130 
135  void keyPressEvent(QKeyEvent* event) Q_DECL_OVERRIDE;
136 
141  void mousePressEvent(QMouseEvent *event) override;
142 
147  void mouseMoveEvent(QMouseEvent *event) override;
148 
153  void wheelEvent(QWheelEvent* event) Q_DECL_OVERRIDE;
154 
155  private:
156 
164  QOpenGLShaderProgram* createShaderProgram(const QString& pathVS, const QString& pathFS, const QString& pathGS = "");
165 
166  // Logger
167  QOpenGLDebugLogger* logger = Q_NULLPTR;
168 
169  // Counter for frames
170  int frameCounter = 0;
171 
172  // Called every second to compute fps
173  QTimer fpsTimer;
174 
175  // Updates the widget periodically, to force paintGL() invocation
176  // Also calls updateFrame()
177  QTimer updateTimer;
178 
179  // Timer to compute delta time
180  QElapsedTimer frameTimer;
181 
182  // Flag for sample shading
183  const bool sampleShading;
184 
185  // Maximum number of samples used for anisotropic filtering
186  const int anisotropy;
187 
188  // Flag for wireframe mode
189  bool wireframe = false;
190 
191  // Line thickness value
192  int thickness = 0;
193 
194  // Halo size value
195  int halo = 0;
196 
197  // Depth cueing value
198  int depthCueing = 0;
199 
200  // Strip depth value
201  int stripDepth = 0;
202 
203  // Indicates if loaded tracks should be filtered by just considering
204  // tracks that intersect with z = 0
205  bool filterTracks = false;
206 
207  // The current track data
208  QVector<Track> tracks;
209 
210  // Texture for the strips
211  QOpenGLTexture* textureStroke = Q_NULLPTR;
212 
213  // Texture for the tapering stencil mask
214  QOpenGLTexture* textureStripMask = Q_NULLPTR;
215 
216  // Program for rendering
217  QOpenGLShaderProgram* program = Q_NULLPTR;
218 
219  // Vertex buffer
220  QOpenGLBuffer vbo;
221 
222  // UV buffer
223  QOpenGLBuffer uvBuffer;
224 
225  // Directions buffer
226  QOpenGLBuffer dirBuffer;
227 
228  // Vertex array object
229  QOpenGLVertexArrayObject vao;
230 
231  // Camera
232  Camera* camera = nullptr;
233 
234  // View model matrix
235  QMatrix4x4 matViewModel;
236 
237  // Proj matrix
238  QMatrix4x4 matProj;
239 
240  // Number of vertices (for current dataset)
241  int numVertices = 0;
242 
243  // Last mouse position (for camera movement)
244  QPoint m_lastPos;
245 
253  float interpolateSliderValue(int value, float min, float max);
254 
262  QVector3D normalizedPoint(QVector3D point, QVector3D min, QVector3D range, float scale);
263 };
264 
265 #endif // GLWIDGET_H
void mousePressEvent(QMouseEvent *event) override
Handles mouse click interaction for camera movement.
Definition: glwidget.cpp:457
virtual void setTrackData(const QVector< Track > &&tracks)
Prepares track data for rendering.
Definition: glwidget.cpp:189
Class for orbital cameras.
Definition: camera.h:13
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE
Handles key presses for toggling track filtering.
Definition: glwidget.cpp:448
virtual void setWireframe(bool enabled)
Enables / disables wireframe mode.
Definition: glwidget.h:49
GLWidget(QWidget *parent=Q_NULLPTR, int updateRate=60, bool sampleShading=true, int anisotropy=1)
Constructs a new OpenGL widget.
Definition: glwidget.cpp:7
void mouseMoveEvent(QMouseEvent *event) override
Handles mouse movement interaction for camera movement.
Definition: glwidget.cpp:462
virtual void initializeGL() Q_DECL_OVERRIDE
Initializes everything related to OpenGL.
Definition: glwidget.cpp:47
virtual void setStripDepth(int p_stripDepth)
Sets the strip depth value.
Definition: glwidget.h:74
virtual void setDepthCueing(int p_depthCueing)
sets the depth cueing value
Definition: glwidget.h:82
virtual void setHalo(int p_halo)
Sets the halo width value.
Definition: glwidget.h:66
virtual void resizeGL(int w, int h) Q_DECL_OVERRIDE
Handles resizing of the widget.
Definition: glwidget.cpp:385
virtual void updateFrame()
Updates the scene.
Definition: glwidget.cpp:391
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE
Handles mouse wheel interaction for camera movement.
Definition: glwidget.cpp:478
virtual void paintGL() Q_DECL_OVERRIDE
Renders the scene.
Definition: glwidget.cpp:406
virtual void setThickness(int p_thickness)
Sets the line thickness value.
Definition: glwidget.h:58
Widget encapsulating the OpenGL context.
Definition: glwidget.h:21
void frameRate(int fps)
Signals the current frames per second periodically.