From d9d0beb9069d0e1e40499bcfd12b8204d4356b04 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Wed, 13 Jan 2016 12:04:55 +0100 Subject: Scatterplot: individual glyph opacity methods & signals. * Removed code that handles selection coordination between cpPlot and full data plot from main * Full plot has control points invisible (opacity = 0) by default --- main.cpp | 20 +++++++++++++------- scatterplot.cpp | 35 ++++++++++++++++++++++++++++++++--- scatterplot.h | 7 ++++++- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index 0ce1b58..593c922 100644 --- a/main.cpp +++ b/main.cpp @@ -61,7 +61,7 @@ int main(int argc, char **argv) arma::vec labels = m->labels(); arma::uword n = X.n_rows; - int cpSize = (int) (3 * sqrt(n)); + int cpSize; arma::uvec cpIndices; arma::mat Ys; @@ -73,6 +73,7 @@ int main(int argc, char **argv) cpIndices.load(indicesFilename.toStdString(), arma::raw_ascii); cpSize = cpIndices.n_elem; } else { + cpSize = (int) (3 * sqrt(n)); // cpIndices = relevanceSampling(X, cpSize); cpIndices = arma::randi(cpSize, arma::distr_param(0, n-1)); } @@ -136,7 +137,7 @@ int main(int argc, char **argv) QObject::connect(cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), m, SLOT(setCP(const arma::mat &))); - // Update projection as the cp is modified + // Update projection as the cp are modified InteractionHandler interactionHandler(X, cpIndices); m->setInteractionHandler(&interactionHandler); QObject::connect(cpPlot, SIGNAL(xyChanged(const arma::mat &)), @@ -148,11 +149,11 @@ int main(int argc, char **argv) m->setTechnique(InteractionHandler::TECHNIQUE_LAMP); // Linking between selections in cp plot and full dataset plot - SelectionHandler selectionHandler(cpIndices); - QObject::connect(cpPlot, SIGNAL(selectionChanged(const QSet &)), - &selectionHandler, SLOT(setSelection(const QSet &))); - QObject::connect(&selectionHandler, SIGNAL(selectionChanged(const QSet &)), - plot, SLOT(setSelection(const QSet &))); + //SelectionHandler selectionHandler(cpIndices); + //QObject::connect(cpPlot, SIGNAL(selectionChanged(const QSet &)), + // &selectionHandler, SLOT(setSelection(const QSet &))); + //QObject::connect(&selectionHandler, SIGNAL(selectionChanged(const QSet &)), + // plot, SLOT(setSelection(const QSet &))); // Connections between history graph and cp plot //HistoryGraph *history = engine.rootObjects()[0]->findChild("history"); @@ -176,6 +177,11 @@ int main(int argc, char **argv) cpPlot->setXY(Ys, false); cpPlot->update(); + arma::vec plotOpacities(X.n_rows); + plotOpacities.fill(0.4f); + plotOpacities(cpIndices).fill(0.0f); + plot->setOpacityData(plotOpacities); + auto ret = app.exec(); skelft2DDeinitialization(); diff --git a/scatterplot.cpp b/scatterplot.cpp index d779182..fae97e3 100644 --- a/scatterplot.cpp +++ b/scatterplot.cpp @@ -10,8 +10,8 @@ static const qreal GLYPH_OPACITY_SELECTED = 1.0; static const QColor OUTLINE_COLOR(0, 0, 0); static const QColor SELECTION_COLOR(128, 128, 128, 96); -static const int GLYPH_SIZE = 6.f; -static const float PADDING = 10.f; +static const int GLYPH_SIZE = 4.0f; +static const float PADDING = 10.0f; Scatterplot::Scatterplot(QQuickItem *parent) : QQuickItem(parent) @@ -70,6 +70,12 @@ void Scatterplot::setXY(const arma::mat &xy, bool updateView) autoScale(); } + if (m_opacityData.n_elem != m_xy.n_rows) { + arma::vec opacityData(xy.n_rows); + opacityData.fill(GLYPH_OPACITY); + setOpacityData(opacityData, false); + } + if (updateView) { updateGeometry(); } @@ -107,6 +113,25 @@ void Scatterplot::setAutoScale(bool autoScale) } } +void Scatterplot::setOpacityData(const arma::vec &opacityData, bool updateView) +{ + if (m_xy.n_rows > 0 && opacityData.n_elem != m_xy.n_rows) { + return; + } + + m_opacityData = opacityData; + emit opacityDataChanged(m_opacityData); + + if (updateView) { + update(); + } +} + +void Scatterplot::setOpacityData(const arma::vec &opacityData) +{ + setOpacityData(opacityData, true); +} + void Scatterplot::setScale(const LinearScale &sx, const LinearScale &sy, bool updateView) { m_sx = sx; @@ -320,7 +345,7 @@ void Scatterplot::updateGlyphs(QSGNode *glyphsNode) bool isSelected = m_selectedGlyphs.contains(i); QSGOpacityNode *glyphOpacityNode = static_cast(node); - glyphOpacityNode->setOpacity(isSelected ? GLYPH_OPACITY_SELECTED : GLYPH_OPACITY); + glyphOpacityNode->setOpacity(m_opacityData[i]); QSGGeometryNode *glyphOutlineNode = static_cast(node->firstChild()); QSGGeometryNode *glyphNode = static_cast(node->firstChild()->nextSibling()); @@ -452,6 +477,10 @@ bool Scatterplot::updateSelection(bool mergeSelection) void Scatterplot::setSelection(const QSet &selection) { m_selectedGlyphs = selection; + for (auto it = m_selectedGlyphs.cbegin(); + it != m_selectedGlyphs.cend(); it++) { + m_opacityData[*it] = GLYPH_OPACITY_SELECTED; + } update(); emit selectionChanged(selection); diff --git a/scatterplot.h b/scatterplot.h index 1c61656..7649a3f 100644 --- a/scatterplot.h +++ b/scatterplot.h @@ -20,6 +20,7 @@ public: void setColorScale(ColorScale *colorScale); void setXY(const arma::mat &xy, bool updateView); void setColorData(const arma::vec &colorData, bool updateView); + void setOpacityData(const arma::vec &opacityData, bool updateView); void setScale(const LinearScale &sx, const LinearScale &sy, bool updateView); void setAutoScale(bool autoScale); Q_INVOKABLE bool saveToFile(const QUrl &url); @@ -28,6 +29,7 @@ signals: void xyChanged(const arma::mat &XY) const; void xyInteractivelyChanged(const arma::mat &XY) const; void colorDataChanged(const arma::vec &colorData) const; + void opacityDataChanged(const arma::vec &opacityData) const; void selectionChanged(const QSet &selection) const; void displaySplatChanged(bool displaySplat) const; void scaleChanged(const LinearScale &sx, const LinearScale &sy) const; @@ -35,6 +37,7 @@ signals: public slots: void setXY(const arma::mat &xy); void setColorData(const arma::vec &colorData); + void setOpacityData(const arma::vec &opacityData); void setSelection(const QSet &selection); void setDisplaySplat(bool displaySplat); void setScale(const LinearScale &sx, const LinearScale &sy); @@ -80,8 +83,10 @@ private: bool m_shouldUpdateGeometry, m_shouldUpdateMaterials; bool m_displaySplat; - arma::vec m_colorData; ColorScale *m_colorScale; + + arma::vec m_colorData; + arma::vec m_opacityData; }; #endif // SCATTERPLOT_H -- cgit v1.2.3