#ifndef SCATTERPLOT_H #define SCATTERPLOT_H #include <memory> #include <vector> #include <armadillo> #include <glad/gl.h> #include <nod.hpp> #include "colorscale.h" #include "quadtree.h" #include "geometry.h" #include "scale.h" #include "shader.h" class Scatterplot { public: static const int PADDING = 20; Scatterplot(); ~Scatterplot(); arma::mat XY() const; void setColormap(GLuint texture); void setAutoScale(bool autoScale); size_t width() const { return m_width; } size_t height() const { return m_height; } void setSize(size_t, size_t); float glyphSize() const { return m_glyphSize; } void setGlyphSize(float glyphSize); void setDragEnabled(bool enabled) { m_dragEnabled = enabled; } bool isDragEnabled() const { return m_dragEnabled; } GLuint texture() const { return m_outTex; } nod::signal<void(const arma::mat &)> xyChanged, xyInteractivelyChanged; nod::signal<void(const arma::vec &)> colorDataChanged, opacityDataChanged; nod::signal<void(const std::vector<bool> &)> selectionChanged, selectionInteractivelyChanged; nod::signal<void(int)> itemBrushed, itemInteractivelyBrushed; nod::signal<void(const LinearScale<float> &, const LinearScale<float> &)> scaleChanged; nod::signal<void(float)> glyphSizeChanged; void setXY(const arma::mat &xy); void setColorData(const arma::vec &colorData); void setOpacityData(const arma::vec &opacityData); void setScale(const LinearScale<float> &sx, const LinearScale<float> &sy); void setSelection(const std::vector<bool> &selection); void brushItem(int item); void update(); void draw(); protected: // QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); // void mousePressEvent(QMouseEvent *event); // void mouseMoveEvent(QMouseEvent *event); // void mouseReleaseEvent(QMouseEvent *event); // void hoverEnterEvent(QHoverEvent *event); // void hoverMoveEvent(QHoverEvent *event); // void hoverLeaveEvent(QHoverEvent *event); private: // QSGNode *newSceneGraph(); // QSGNode *newGlyphTree(); void applyManipulation(); void updateGeometry(); void updateMaterials(); void updateTransform(); // void updateGlyphs(QSGNode *node); // void updateBrush(QSGNode *node); // Data arma::mat m_xy; arma::vec m_colorData; arma::vec m_opacityData; // Visuals size_t m_width, m_height; float m_glyphSize; std::shared_ptr<const ColorScale> m_colorScale; void autoScale(); bool m_autoScale; LinearScale<float> m_sx, m_sy; // Internal state void interactiveSelection(bool mergeSelection); std::vector<bool> m_selection; bool m_anySelected; int m_brushedItem; enum State { StateNone, StateBrushing, StateSelecting, StateSelected, StateMoving } m_interactionState; bool m_dragEnabled; std::unique_ptr<Shader> m_shader, m_shaderOutline; GLuint m_VAO, m_pointsVBO, m_valuesVBO; GLuint m_FBO, m_outFBO, m_colormapTex, m_depthTex, m_tex, m_outTex; GLfloat m_transform[4][4]; std::vector<vec2> m_points; vec2 m_dragOriginPos, m_dragCurrentPos; bool m_redraw, m_shouldUpdateGeometry, m_shouldUpdateMaterials; std::unique_ptr<QuadTree> m_quadtree; void updateQuadTree(); }; #endif // SCATTERPLOT_H