#include #include #include #include #include #include #include #include #include "main.h" #include "mp.h" #include "continuouscolorscale.h" #include "scatterplot.h" #include "voronoisplat.h" #include "historygraph.h" #include "barchart.h" #include "colormap.h" #include "manipulationhandler.h" #include "mapscalehandler.h" #include "selectionhandler.h" #include "projectionobserver.h" #include "skelft.h" static QObject *mainProvider(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) return Main::instance(); } arma::uvec extractCPs(const arma::mat &X) { int numCPs = (int) (3 * sqrt(X.n_rows)); return arma::randi(numCPs, arma::distr_param(0, X.n_rows - 1)); } int main(int argc, char **argv) { QApplication app(argc, argv); app.setApplicationName("pm"); app.setApplicationVersion("1.0"); // app.setAttribute(Qt::AA_ShareOpenGLContexts); QCommandLineParser parser; parser.setApplicationDescription("Interactive multidimensional projections."); parser.addHelpOption(); parser.addVersionOption(); parser.addPositionalArgument("dataset", "Dataset filename (.tbl file)"); QCommandLineOption indicesFileOutputOption(QStringList() << "i" << "indices", "Filename to store the control points' indices. Omitting this option disables saving indices.", "filename"); parser.addOption(indicesFileOutputOption); QCommandLineOption cpFileOutputOption(QStringList() << "c" << "cpoints", "Filename to store the control points' map. Omitting this option disables saving this map.", "filename"); parser.addOption(cpFileOutputOption); parser.process(app); QStringList args = parser.positionalArguments(); if (args.size() != 1) { parser.showHelp(1); } Main *m = Main::instance(); m->loadDataset(args[0].toStdString()); arma::mat X = m->X(); arma::vec labels = m->labels(); arma::uvec cpIndices; arma::mat Ys; // Load/generate indices QString indicesFilename; if (parser.isSet(indicesFileOutputOption)) { indicesFilename = parser.value(indicesFileOutputOption); } QFile indicesFile(indicesFilename); if (indicesFile.exists()) { m->setIndicesSavePath(indicesFilename); cpIndices.load(indicesFilename.toStdString(), arma::raw_ascii); } else { cpIndices = extractCPs(X); } // Load/generate CPs QString cpFilename; if (parser.isSet(cpFileOutputOption)) { cpFilename = parser.value(cpFileOutputOption); } QFile cpFile(cpFilename); if (cpFile.exists()) { m->setCPSavePath(cpFilename); Ys.load(cpFilename.toStdString(), arma::raw_ascii); } else { 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); qmlRegisterType("PM", 1, 0, "Scatterplot"); qmlRegisterType("PM", 1, 0, "HistoryGraph"); qmlRegisterType("PM", 1, 0, "BarChart"); qmlRegisterType("PM", 1, 0, "VoronoiSplat"); qmlRegisterType("PM", 1, 0, "Colormap"); qmlRegisterSingletonType
("PM", 1, 0, "Main", mainProvider); // Set up multisampling QSurfaceFormat fmt; fmt.setRenderableType(QSurfaceFormat::OpenGL); fmt.setVersion(4, 5); fmt.setRedBufferSize(8); fmt.setGreenBufferSize(8); fmt.setBlueBufferSize(8); fmt.setAlphaBufferSize(8); fmt.setSamples(8); QSurfaceFormat::setDefaultFormat(fmt); QQmlApplicationEngine engine(QUrl("qrc:///main_view.qml")); // Initialize pointers to visual components m->cpPlot = engine.rootObjects()[0]->findChild("cpPlot"); m->rpPlot = engine.rootObjects()[0]->findChild("rpPlot"); 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 &)), m, SLOT(setCP(const arma::mat &))); QObject::connect(m->cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), m, SLOT(setCP(const arma::mat &))); // Update projection as the cp are modified 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 &)), &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(&manipulationHandler, SIGNAL(rpChanged(const arma::mat &)), m->splat, SLOT(setSites(const arma::mat &))); // Connections between history graph and cp plot //HistoryGraph *history = engine.rootObjects()[0]->findChild("history"); //QObject::connect(cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), // history, SLOT(addHistoryItem(const arma::mat &))); //QObject::connect(history, SIGNAL(currentItemChanged(const arma::mat &)), // cpPlot, SLOT(setXY(const arma::mat &))); // 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 &))); // Linking between selections SelectionHandler cpSelectionHandler(cpIndices.n_elem); QObject::connect(m->cpPlot, SIGNAL(selectionInteractivelyChanged(const std::vector &)), &cpSelectionHandler, SLOT(setSelection(const std::vector &))); QObject::connect(m->cpBarChart, SIGNAL(selectionInteractivelyChanged(const std::vector &)), &cpSelectionHandler, SLOT(setSelection(const std::vector &))); 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 &))); // Recompute values whenever projection changes ProjectionObserver projectionObserver(X, cpIndices); m->projectionObserver = &projectionObserver; QObject::connect(&manipulationHandler, SIGNAL(mapChanged(const arma::mat &)), m->projectionObserver, SLOT(setMap(const arma::mat &))); 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 &))); 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); manipulationHandler.setCP(Ys); auto ret = app.exec(); skelft2DDeinitialization(); return ret; }