From 60a0bfb863aa2a05bafd943423c284f5c2d68863 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Mon, 25 Jan 2016 19:55:52 +0100 Subject: Scatterplots & splat now share the same scaling. --- main.cpp | 99 +++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 42 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 6af65b3..34eb240 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include @@ -16,7 +16,8 @@ #include "historygraph.h" #include "barchart.h" #include "colormap.h" -#include "interactionhandler.h" +#include "manipulationhandler.h" +#include "mapscalehandler.h" #include "selectionhandler.h" #include "projectionobserver.h" #include "skelft.h" @@ -71,6 +72,7 @@ int main(int argc, char **argv) arma::uvec cpIndices; arma::mat Ys; + // Load/generate indices QString indicesFilename; if (parser.isSet(indicesFileOutputOption)) { indicesFilename = parser.value(indicesFileOutputOption); @@ -83,8 +85,7 @@ int main(int argc, char **argv) cpIndices = extractCPs(X); } - arma::sort(cpIndices); - + // Load/generate CPs QString cpFilename; if (parser.isSet(cpFileOutputOption)) { cpFilename = parser.value(cpFileOutputOption); @@ -97,11 +98,17 @@ int main(int argc, char **argv) Ys.set_size(cpIndices.n_elem, 2); mp::forceScheme(mp::dist(X.rows(cpIndices)), Ys); } + if (cpIndices.n_elem != Ys.n_rows) { std::cerr << "The number of CP indices and the CP map do not match." << std::endl; return 1; } + // Sort indices so some operations become easier later + arma::uvec cpSortedIndices = arma::sort_index(cpIndices); + cpIndices = cpIndices(cpSortedIndices); + Ys = Ys.rows(cpSortedIndices); + m->setCPIndices(cpIndices); m->setCP(Ys); @@ -110,7 +117,6 @@ int main(int argc, char **argv) qmlRegisterType("PM", 1, 0, "BarChart"); qmlRegisterType("PM", 1, 0, "VoronoiSplat"); qmlRegisterType("PM", 1, 0, "Colormap"); - qmlRegisterType("PM", 1, 0, "InteractionHandler"); qmlRegisterSingletonType
("PM", 1, 0, "Main", mainProvider); // Set up multisampling @@ -126,15 +132,13 @@ int main(int argc, char **argv) QQmlApplicationEngine engine(QUrl("qrc:///main_view.qml")); + // Initialize pointers to visual components m->cpPlot = engine.rootObjects()[0]->findChild("cpPlot"); - m->cpPlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); - m->rpPlot = engine.rootObjects()[0]->findChild("rpPlot"); - - m->splat = engine.rootObjects()[0]->findChild("splat"); - skelft2DInitialization(m->splat->width()); - m->colormap = engine.rootObjects()[0]->findChild("colormap"); + m->splat = engine.rootObjects()[0]->findChild("splat"); + m->cpBarChart = engine.rootObjects()[0]->findChild("cpBarChart"); + m->rpBarChart = engine.rootObjects()[0]->findChild("rpBarChart"); // Keep track of the current cp (in order to save them later, if requested) QObject::connect(m->cpPlot, SIGNAL(xyChanged(const arma::mat &)), @@ -143,15 +147,16 @@ int main(int argc, char **argv) m, SLOT(setCP(const arma::mat &))); // Update projection as the cp are modified - InteractionHandler interactionHandler(X, cpIndices); - interactionHandler.setTechnique(InteractionHandler::TECHNIQUE_LAMP); - QObject::connect(m->cpPlot, SIGNAL(xyChanged(const arma::mat &)), - &interactionHandler, SLOT(setCP(const arma::mat &))); + ManipulationHandler manipulationHandler(X, cpIndices); + //QObject::connect(m->cpPlot, SIGNAL(xyChanged(const arma::mat &)), + // &manipulationHandler, SLOT(setCP(const arma::mat &))); QObject::connect(m->cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), - &interactionHandler, SLOT(setCP(const arma::mat &))); - QObject::connect(&interactionHandler, SIGNAL(cpChanged(const arma::mat &)), + &manipulationHandler, SLOT(setCP(const arma::mat &))); + QObject::connect(&manipulationHandler, SIGNAL(cpChanged(const arma::mat &)), + m->cpPlot, SLOT(setXY(const arma::mat &))); + QObject::connect(&manipulationHandler, SIGNAL(rpChanged(const arma::mat &)), m->rpPlot, SLOT(setXY(const arma::mat &))); - QObject::connect(&interactionHandler, SIGNAL(cpChanged(const arma::mat &)), + QObject::connect(&manipulationHandler, SIGNAL(rpChanged(const arma::mat &)), m->splat, SLOT(setSites(const arma::mat &))); // Connections between history graph and cp plot @@ -161,20 +166,20 @@ int main(int argc, char **argv) //QObject::connect(history, SIGNAL(currentItemChanged(const arma::mat &)), // cpPlot, SLOT(setXY(const arma::mat &))); - QObject::connect(m->rpPlot, SIGNAL(scaleChanged(const LinearScale &, const LinearScale &)), + // Keep both scatterplots scaled equally and to the full plot + MapScaleHandler mapScaleHandler; + QObject::connect(&mapScaleHandler, SIGNAL(scaleChanged(const LinearScale &, const LinearScale &)), m->cpPlot, SLOT(setScale(const LinearScale &, const LinearScale &))); + QObject::connect(&mapScaleHandler, SIGNAL(scaleChanged(const LinearScale &, const LinearScale &)), + m->rpPlot, SLOT(setScale(const LinearScale &, const LinearScale &))); + QObject::connect(&mapScaleHandler, SIGNAL(scaleChanged(const LinearScale &, const LinearScale &)), + m->splat, SLOT(setScale(const LinearScale &, const LinearScale &))); + QObject::connect(&manipulationHandler, SIGNAL(mapChanged(const arma::mat &)), + &mapScaleHandler, SLOT(scaleToMap(const arma::mat &))); QObject::connect(m->splat, SIGNAL(colorScaleChanged(const ColorScale &)), m->colormap, SLOT(setColorScale(const ColorScale &))); - m->cpBarChart = engine.rootObjects()[0]->findChild("cpBarChart"); - m->cpBarChart->setAcceptedMouseButtons(Qt::LeftButton); - m->setCPBarChartColorScale(Main::ColorScaleContinuous); - - m->rpBarChart = engine.rootObjects()[0]->findChild("rpBarChart"); - m->rpBarChart->setAcceptedMouseButtons(Qt::LeftButton); - m->setRPBarChartColorScale(Main::ColorScaleContinuous); - // Linking between selections SelectionHandler cpSelectionHandler(cpIndices.n_elem); QObject::connect(m->cpPlot, SIGNAL(selectionInteractivelyChanged(const std::vector &)), @@ -184,36 +189,46 @@ int main(int argc, char **argv) QObject::connect(&cpSelectionHandler, SIGNAL(selectionChanged(const std::vector &)), m->cpPlot, SLOT(setSelection(const std::vector &))); - //SelectionHandler rpSelectionHandler(X.n_rows - cpIndices.n_elem); - //QObject::connect(m->rpPlot, SIGNAL(selectionInteractivelyChanged(const std::vector &)), - // &rpSelectionHandler, SLOT(setSelection(const std::vector &))); - //QObject::connect(m->rpBarChart, SIGNAL(selectionInteractivelyChanged(const std::vector &)), - // &rpSelectionHandler, SLOT(setSelection(const std::vector &))); - //QObject::connect(&rpSelectionHandler, SIGNAL(selectionChanged(const std::vector &)), - // m->rpPlot, SLOT(setSelection(const std::vector &))); + SelectionHandler rpSelectionHandler(X.n_rows - cpIndices.n_elem); + QObject::connect(m->rpPlot, SIGNAL(selectionInteractivelyChanged(const std::vector &)), + &rpSelectionHandler, SLOT(setSelection(const std::vector &))); + QObject::connect(m->rpBarChart, SIGNAL(selectionInteractivelyChanged(const std::vector &)), + &rpSelectionHandler, SLOT(setSelection(const std::vector &))); + QObject::connect(&rpSelectionHandler, SIGNAL(selectionChanged(const std::vector &)), + m->rpPlot, SLOT(setSelection(const std::vector &))); + // Recompute values whenever projection changes ProjectionObserver projectionObserver(X, cpIndices); m->projectionObserver = &projectionObserver; - QObject::connect(&interactionHandler, SIGNAL(cpChanged(const arma::mat &)), + QObject::connect(&manipulationHandler, SIGNAL(mapChanged(const arma::mat &)), m->projectionObserver, SLOT(setMap(const arma::mat &))); - //QObject::connect(m->projectionObserver, SIGNAL(valuesChanged(const arma::vec &)), - // m->rpPlot, SLOT(setColorData(const arma::vec &))); - QObject::connect(m->projectionObserver, SIGNAL(valuesChanged(const arma::vec &)), + QObject::connect(m->projectionObserver, SIGNAL(rpValuesChanged(const arma::vec &)), + m->rpPlot, SLOT(setColorData(const arma::vec &))); + QObject::connect(m->projectionObserver, SIGNAL(rpValuesChanged(const arma::vec &)), m->splat, SLOT(setValues(const arma::vec &))); QObject::connect(m->projectionObserver, SIGNAL(cpValuesChanged(const arma::vec &)), m->cpBarChart, SLOT(setValues(const arma::vec &))); - //QObject::connect(m->projectionObserver, SIGNAL(rpValuesChanged(const arma::vec &)), - // m->rpBarChart, SLOT(setValues(const arma::vec &))); + QObject::connect(m->projectionObserver, SIGNAL(rpValuesChanged(const arma::vec &)), + m->rpBarChart, SLOT(setValues(const arma::vec &))); + + skelft2DInitialization(m->splat->width()); + + m->cpPlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); + m->cpBarChart->setAcceptedMouseButtons(Qt::LeftButton); + m->rpBarChart->setAcceptedMouseButtons(Qt::LeftButton); m->setColormapColorScale(Main::ColorScaleContinuous); m->setCPPlotColorScale(Main::ColorScaleContinuous); m->setRPPlotColorScale(Main::ColorScaleContinuous); m->setSplatColorScale(Main::ColorScaleContinuous); + m->setCPBarChartColorScale(Main::ColorScaleContinuous); + m->setRPBarChartColorScale(Main::ColorScaleContinuous); m->cpPlot->setAutoScale(false); + m->rpPlot->setAutoScale(false); m->cpPlot->setColorData(labels(cpIndices), false); - m->cpPlot->setXY(Ys, false); - m->cpPlot->update(); + + manipulationHandler.setCP(Ys); auto ret = app.exec(); -- cgit v1.2.3