From 7ad4b526899f8bc764192e88e65306c788a9ed32 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Fri, 15 Jan 2016 22:35:13 +0100 Subject: VoronoiSplat & Scatterplot: splatting is now a separate component. The change was due to future functionality requirements, this separation provides grater flexibility. As a nice side effect, the cropping bug when first rendering the splat is now gone. --- voronoisplat.h | 61 +++++++++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 37 deletions(-) (limited to 'voronoisplat.h') diff --git a/voronoisplat.h b/voronoisplat.h index 9859e8d..fb93f09 100644 --- a/voronoisplat.h +++ b/voronoisplat.h @@ -1,63 +1,50 @@ #ifndef VORONOISPLAT_H #define VORONOISPLAT_H -#include -#include -#include -#include +#include + #include #include "colorscale.h" -class VoronoiSplatTexture - : public QSGDynamicTexture +class VoronoiSplat + : public QQuickFramebufferObject { + Q_OBJECT public: - // 'size' must be square (and power of 2) - VoronoiSplatTexture(const QSize &size); - virtual ~VoronoiSplatTexture(); + VoronoiSplat(QQuickItem *parent = 0); + + Renderer *createRenderer() const; - void bind(); + const std::vector &sites() const { return m_sites; } + const std::vector &values() const { return m_values; } + const std::vector &colormap() const { return m_cmap; } - // Call this whenever the texture should be updated (after changing the - // sites, values or colormap). When true is returned, should probably call - // resetOpenGLState() on QtQuick window - bool updateTexture(); + bool sitesChanged() const { return m_sitesChanged; } + bool valuesChanged() const { return m_valuesChanged; } + bool colormapChanged() const { return m_colormapChanged; } - bool hasAlphaChannel() const { return true; } - bool hasMipmaps() const { return false; } - int textureId() const { return m_tex; } - QSize textureSize() const { return m_size; } + void setSitesChanged(bool sitesChanged) { m_sitesChanged = sitesChanged; } + void setValuesChanged(bool valuesChanged) { m_valuesChanged = valuesChanged; } + void setColormapChanged(bool colormapChanged) { m_colormapChanged = colormapChanged; } +signals: + void sitesChanged(const arma::mat &sites); + void valuesChanged(const arma::vec &values); + void colormapChanged(const ColorScale *scale); + +public slots: // 'points' should be a 2D points matrix (each point in a row) void setSites(const arma::mat &points); // Set the value to be colormapped in each site void setValues(const arma::vec &values); - // Set colormap data based on the given color scale; + // Set colormap data based on the given color scale void setColormap(const ColorScale *scale); private: - void setupShaders(); - void setupVAOs(); - void setupTextures(); - - void updateSites(); - void updateValues(); - void updateColormap(); - void computeDT(); - - QOpenGLFunctions gl; - QOpenGLShaderProgram *m_program1, *m_program2; - GLuint m_FBO; - GLuint m_VBOs[3]; - GLuint m_textures[2], m_colormapTex, m_tex; - QOpenGLVertexArrayObject m_sitesVAO, m_2ndPassVAO; - std::vector m_sites, m_values, m_cmap; - QSize m_size; - bool m_sitesChanged, m_valuesChanged, m_colormapChanged; }; -- cgit v1.2.3