From c853b44dd138fd99e430580ec1bb1d0bd25293ff Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Mon, 11 Jan 2016 13:19:51 +0100 Subject: Scatterplot: control whether splat is displayed. * Subsample plot no longer displays splat --- main.cpp | 1 + scatterplot.cpp | 44 ++++++++++++++++++++++++++++++++++---------- scatterplot.h | 3 +++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index 41d0ed0..672ffd5 100644 --- a/main.cpp +++ b/main.cpp @@ -187,6 +187,7 @@ int main(int argc, char **argv) //ContinuousColorScale colorScale = ContinuousColorScale::builtin(ContinuousColorScale::RED_GRAY_BLUE); //colorScale.setExtents(-1, 1); Scatterplot *subsamplePlot = engine.rootObjects()[0]->findChild("subsamplePlot"); + subsamplePlot->setDisplaySplat(false); subsamplePlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); // subsamplePlot->setColorData(arma::zeros(subsampleSize)); subsamplePlot->setColorScale(&colorScale); diff --git a/scatterplot.cpp b/scatterplot.cpp index 2c9a57a..7505e88 100644 --- a/scatterplot.cpp +++ b/scatterplot.cpp @@ -20,6 +20,7 @@ Scatterplot::Scatterplot(QQuickItem *parent) , m_currentInteractionState(INTERACTION_NONE) , m_shouldUpdateGeometry(false) , m_shouldUpdateMaterials(false) + , m_displaySplat(true) , m_animationEasing(QEasingCurve::InOutQuart) { setClip(true); @@ -206,11 +207,14 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) return root; } - QSGNode *splatNode = root->firstChild(); - updateSplat(splatNode); + // This keeps track of where we are in the scene when updating + QSGNode *node = root->firstChild(); - QSGNode *glyphsRootNode = root->firstChild()->nextSibling(); - updateGlyphs(glyphsRootNode->firstChild()); + updateSplat(node); + node = node->nextSibling(); + + updateGlyphs(node->firstChild()); + node = node->nextSibling(); // Change update hints to false; the splat and glyphs were just updated if (m_shouldUpdateGeometry) { @@ -221,15 +225,15 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) } // Selection - QSGSimpleRectNode *selectionRectNode = - static_cast(root->firstChild()->nextSibling()->nextSibling()); + QSGSimpleRectNode *selectionNode = static_cast(node); if (m_currentInteractionState == INTERACTION_SELECTING) { - selectionRectNode->setRect(QRectF(m_dragOriginPos, m_dragCurrentPos)); - selectionRectNode->markDirty(QSGNode::DirtyGeometry); + selectionNode->setRect(QRectF(m_dragOriginPos, m_dragCurrentPos)); + selectionNode->markDirty(QSGNode::DirtyGeometry); } else { // Hide selection rect - selectionRectNode->setRect(QRectF(-1, -1, 0, 0)); + selectionNode->setRect(QRectF(-1, -1, 0, 0)); } + node = node->nextSibling(); animationTick(); return root; @@ -238,9 +242,17 @@ QSGNode *Scatterplot::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) void Scatterplot::updateSplat(QSGNode *node) { QSGSimpleTextureNode *texNode = static_cast(node); + + if (!m_displaySplat) { + // Hide the splat and return, ignoring update requests + texNode->setRect(0, 0, 0, 0); + return; + } + + texNode->setRect(x(), y(), width(), height()); + VoronoiSplatTexture *tex = static_cast(texNode->texture()); - if (m_shouldUpdateGeometry) { tex->setSites(m_xy); } @@ -439,6 +451,18 @@ void Scatterplot::setSelection(const QSet &selection) emit selectionChanged(selection); } +void Scatterplot::setDisplaySplat(bool displaySplat) +{ + if (m_displaySplat != displaySplat) { + m_displaySplat = displaySplat; + m_shouldUpdateGeometry = true; + m_shouldUpdateMaterials = true; + update(); + + emit displaySplatChanged(displaySplat); + } +} + void Scatterplot::applyManipulation() { m_sx.inverse(); diff --git a/scatterplot.h b/scatterplot.h index 50af274..8f2c8c4 100644 --- a/scatterplot.h +++ b/scatterplot.h @@ -25,11 +25,13 @@ signals: void xyInteractivelyChanged(const arma::mat &XY) const; void colorDataChanged(const arma::vec &colorData) const; void selectionChanged(const QSet &selection) const; + void displaySplatChanged(bool displaySplat) const; public slots: void setXY(const arma::mat &xy); void setColorData(const arma::vec &colorData); void setSelection(const QSet &selection); + void setDisplaySplat(bool displaySplat); protected: QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); @@ -72,6 +74,7 @@ private: bool m_shouldUpdateGeometry, m_shouldUpdateMaterials; + bool m_displaySplat; arma::vec m_colorData; ColorScale *m_colorScale; -- cgit v1.2.3