aboutsummaryrefslogtreecommitdiff
path: root/scatterplot.cpp
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2015-12-19 22:11:33 +0100
committerSamuel Fadel <samuelfadel@gmail.com>2015-12-19 22:11:33 +0100
commit841ede5c34a5cb001b540ed13a8439dc8df7d2a9 (patch)
tree11970d698ded9c6353895eca37ca662241edda4b /scatterplot.cpp
parente20c03905d6f8418963bd3ce63040e2fe571a6da (diff)
Experimenting using VoronoiSplat as a texture.
Diffstat (limited to 'scatterplot.cpp')
-rw-r--r--scatterplot.cpp118
1 files changed, 86 insertions, 32 deletions
diff --git a/scatterplot.cpp b/scatterplot.cpp
index 10e9765..b9d7aea 100644
--- a/scatterplot.cpp
+++ b/scatterplot.cpp
@@ -1,5 +1,6 @@
#include "scatterplot.h"
+#include "voronoisplat.h"
#include "geometry.h"
#include <cmath>
@@ -104,6 +105,26 @@ void Scatterplot::updateMaterials()
update();
}
+QSGNode *Scatterplot::createSplatNode()
+{
+ if (m_xy.n_rows < 1) {
+ return 0;
+ }
+
+ QSGSimpleTextureNode *node = new QSGSimpleTextureNode;
+ VoronoiSplatTexture *tex = new VoronoiSplatTexture(QSize(width(), height()));
+ tex->setSites(m_xy);
+ tex->setValues(m_colorData);
+ tex->setColormap(m_colorScale);
+ tex->updateTexture();
+ window()->resetOpenGLState();
+ node->setTexture(tex);
+ node->setOwnsTexture(true);
+ node->setRect(x(), y(), width(), height());
+ node->setSourceRect(0, 0, width(), height());
+ return node;
+}
+
QSGNode *Scatterplot::createGlyphNodeTree()
{
if (m_xy.n_rows < 1) {
@@ -153,6 +174,10 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
QSGNode *root = 0;
if (!oldNode) {
root = new QSGNode;
+ QSGNode *splatNode = createSplatNode();
+ if (splatNode) {
+ root->appendChildNode(splatNode);
+ }
QSGNode *glyphTreeRoot = createGlyphNodeTree();
if (glyphTreeRoot) {
root->appendChildNode(glyphTreeRoot);
@@ -165,6 +190,67 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
return root;
}
+ QSGNode *splatNode = root->firstChild();
+ updateSplat(splatNode);
+
+ QSGNode *glyphsRootNode = root->firstChild()->nextSibling()->firstChild();
+ updateGlyphs(glyphsRootNode);
+
+ if (m_shouldUpdateGeometry) {
+ m_shouldUpdateGeometry = false;
+ }
+ if (m_shouldUpdateMaterials) {
+ m_shouldUpdateMaterials = false;
+ }
+
+ // Selection rect
+ if (m_currentInteractionState == INTERACTION_SELECTING) {
+ QSGSimpleRectNode *selectionNode = 0;
+ if (!root->firstChild()->nextSibling()->nextSibling()) {
+ selectionNode = new QSGSimpleRectNode;
+ selectionNode->setColor(SELECTION_COLOR);
+ root->appendChildNode(selectionNode);
+ } else {
+ selectionNode = static_cast<QSGSimpleRectNode *>(root->firstChild()->nextSibling()->nextSibling());
+ }
+
+ selectionNode->setRect(QRectF(m_dragOriginPos, m_dragCurrentPos));
+ selectionNode->markDirty(QSGNode::DirtyGeometry);
+ } else {
+ QSGNode *node = root->firstChild()->nextSibling()->nextSibling();
+ if (node) {
+ root->removeChildNode(node);
+ delete node;
+ }
+ }
+
+ animationTick();
+ return root;
+}
+
+void Scatterplot::updateSplat(QSGNode *node)
+{
+ QSGSimpleTextureNode *texNode = static_cast<QSGSimpleTextureNode *>(node);
+ VoronoiSplatTexture *tex =
+ static_cast<VoronoiSplatTexture *>(texNode->texture());
+
+ if (m_shouldUpdateGeometry) {
+ tex->setSites(m_xy);
+ }
+
+ if (m_shouldUpdateMaterials) {
+ tex->setValues(m_colorData);
+ tex->setColormap(m_colorScale);
+ }
+
+ if (tex->updateTexture()) {
+ window()->resetOpenGLState();
+ }
+}
+
+void Scatterplot::updateGlyphs(QSGNode *node)
+{
+
qreal x, y, tx, ty, moveTranslationF;
if (m_currentInteractionState == INTERACTION_MOVING) {
@@ -177,7 +263,6 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
m_sx.setRange(PADDING, width() - PADDING);
m_sy.setRange(height() - PADDING, PADDING);
- QSGNode *node = root->firstChild()->firstChild();
float t = m_animationEasing.valueForProgress(m_t);
for (arma::uword i = 0; i < m_xy.n_rows; i++) {
const arma::rowvec &oldRow = m_oldXY.row(i);
@@ -211,37 +296,6 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
node = node->nextSibling();
}
-
- if (m_shouldUpdateGeometry) {
- m_shouldUpdateGeometry = false;
- }
- if (m_shouldUpdateMaterials) {
- m_shouldUpdateMaterials = false;
- }
-
- // Selection rect
- if (m_currentInteractionState == INTERACTION_SELECTING) {
- QSGSimpleRectNode *selectionNode = 0;
- if (!root->firstChild()->nextSibling()) {
- selectionNode = new QSGSimpleRectNode;
- selectionNode->setColor(SELECTION_COLOR);
- root->appendChildNode(selectionNode);
- } else {
- selectionNode = static_cast<QSGSimpleRectNode *>(root->firstChild()->nextSibling());
- }
-
- selectionNode->setRect(QRectF(m_dragOriginPos, m_dragCurrentPos));
- selectionNode->markDirty(QSGNode::DirtyGeometry);
- } else {
- node = root->firstChild()->nextSibling();
- if (node) {
- root->removeChildNode(node);
- delete node;
- }
- }
-
- animationTick();
- return root;
}
void Scatterplot::resetAnimation()