SpaghettiVis
Implementation of 2009 Everts et al. Depth-Dependent Halos: Illustrative Rendering of Dense Line Data
glwidget.h
1 #ifndef GLWIDGET_H
2 #define GLWIDGET_H
3 
4 #include <QCoreApplication>
5 #include <QOpenGLWidget>
6 #include <QOpenGLFunctions>
7 #include <QOpenGLDebugLogger>
8 #include <QOpenGLVertexArrayObject>
9 #include <QOpenGLBuffer>
10 #include <QGLShader>
11 #include <QOpenGLShaderProgram>
12 #include <QElapsedTimer>
13 #include <QTimer>
14 
15 #include "camera.h"
16 #include "linevertex.h"
17 
18 class MainWindow;
19 
23 class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
24 {
25  Q_OBJECT
26 
27  friend class MainWindow;
28 
29 public:
30  GLWidget(QWidget *parent, MainWindow *mainWindow);
31  ~GLWidget();
32 
38  void initLineRenderMode(std::vector<std::vector<LineVertex> > *lines);
39 
44 
46  glm::vec3 clipPlaneNormal;
48 
51  inline QImage getImage()
52  {
53  return this->grabFramebuffer();
54  }
55 
59  inline void updateClipPlaneNormal()
60  {
61  clipPlaneNormal = camera.getRight();
62  }
63 
67  {
68  NONE,
69  LINES,
70  POINTS
71  } renderMode;
72 
73 public slots:
74  void cleanup();
75 
76 signals:
77  void usedGPUMemoryChanged(float size);
78  void totalGPUMemoryChanged(float size);
79  void fpsChanged(int fps);
80  void graphicsDeviceInfoChanged(QString string);
81 
82 protected:
83 
84  void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
85  void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
86 
87  void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
88  void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
89 
90  void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
91 
92 protected slots:
93 
94  void paintGL() Q_DECL_OVERRIDE;
95  void initializeGL() Q_DECL_OVERRIDE;
96  void resizeGL(int w, int h) Q_DECL_OVERRIDE;
97 
98 private:
99 
100  void initShaders();
101 
102  void allocateGPUBufferLineData();
103  void drawLines();
104 
105  void calculateFPS();
106 
107  Camera camera;
108 
112  std::vector<std::vector<LineVertex> > *lines;
113  size_t nrLines;
114 
115  // GPU line vertex data and shaders
116  // each line vertex has 8 floats: 3 pos, 3 direction to next, 2 uv for triangle strip texturing
117  // NOTE: we store two sequential copies of each vertex (one with v = 0, one with v = 1) to draw lines as triangle strips
118  QOpenGLShaderProgram *shaderLinesWithHalos;
119  QOpenGLVertexArrayObject vaoLines; // VAO remembers states of buffer objects, allowing to easily bind/unbind different buffer states for rendering different objects in a scene.
120  QOpenGLBuffer vboLines;
121 
122  // GUI ELEMENTS
123 
124  QPoint lastMousePos; // last mouse position (to determine mouse movement delta)
125 
126  // vars to measure fps
127  size_t frameCount = 0;
128  size_t fps = 0;
129  qint64 previousTimeFPS;
130  QElapsedTimer fpsTimer;
131 
132  // memory usage
133  bool GL_NVX_gpu_memory_info_supported = false;
134  GLint total_mem_kb = 0;
135  GLint cur_avail_mem_kb = 0;
136 
137  // triggers the rendering events
138  QTimer paintTimer;
139 
140  QOpenGLDebugLogger *logger;
141  void printDebugMsg(const QOpenGLDebugMessage &msg) { qDebug() << qPrintable(msg.message()); }
142 
143  MainWindow *mainWindow;
144 
145 };
146 
147 #endif
glm::vec3 clipPlaneNormal
direction along which to clip. note: no real clipping we only discard fragments
Definition: glwidget.h:46
QImage getImage()
getImage
Definition: glwidget.h:51
RenderMode
RenderMode enum currently only LINES is supported.
Definition: glwidget.h:66
void updateClipPlaneNormal()
updateClipPlaneNormal set the clip plane normal to the current right camera vector this is much easie...
Definition: glwidget.h:59
float clipPlaneDistance
distance from origin in direction of clipPlaneNormal beyond which to clip
Definition: glwidget.h:47
float lineWidthDepthCueingFactor
how much the black line is drawn thinner with increasing depth
Definition: glwidget.h:42
The GLWidget class This is the main class containing the OpenGL context All interaction with OpenGL h...
Definition: glwidget.h:23
std::vector< std::vector< LineVertex > > * lines
Definition: glwidget.h:112
float lineWidthPercentageBlack
percentage of triangle strip drawn black to represent line (rest is white halo)
Definition: glwidget.h:41
float lineHaloMaxDepth
max depth displacement of halo
Definition: glwidget.h:43
void initLineRenderMode(std::vector< std::vector< LineVertex > > *lines)
set up OpenGL buffers and shaders to render lines
Definition: glwidget.cpp:127
float lineTriangleStripWidth
total width of triangle strip (black line + white halo)
Definition: glwidget.h:40
Camera class.
Definition: camera.h:12
The MainWindow class.
Definition: mainwindow.h:24
bool enableClipping
if enabled, clip beyond a specified clipping plane. note: no real clipping we only discard fragments ...
Definition: glwidget.h:45