aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
blob: 0f7f8c8cea0cf6361c70713429ea88c979eca111 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <cmath>
#include <memory>
#include <QSurfaceFormat>
#include <QApplication>
#include <QQmlApplicationEngine>

#include "mp.h"
#include "scatterplot.h"
#include "interactionhandler.h"

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    qmlRegisterType<Scatterplot>("PM", 1, 0, "Scatterplot");

    // Set up multisampling
    QSurfaceFormat fmt;
    fmt.setSamples(16);
    QSurfaceFormat::setDefaultFormat(fmt);
    QQmlApplicationEngine engine(QUrl("qrc:///main_view.qml"));

    std::unique_ptr<InteractionHandler> interactionHandler((InteractionHandler *) 0);
    if (argc > 1) {
        arma::mat dataset;
        dataset.load(argv[1], arma::raw_ascii);
        arma::mat X = dataset.cols(0, dataset.n_cols - 2);
        arma::vec labels = dataset.col(dataset.n_cols - 1);

        arma::uword n = dataset.n_rows;
        arma::uword subsampleSize = (arma::uword) sqrt(n) * 3;
        arma::uvec sampleIndices = arma::randi<arma::uvec>(subsampleSize, arma::distr_param(0, n-1));
        arma::mat Ys = arma::randn(subsampleSize, 2);
        Ys = mp::forceScheme(mp::dist(X.rows(sampleIndices)), Ys);
        arma::mat subsampleData(subsampleSize, 3);
        subsampleData.cols(0, 1) = Ys;
        subsampleData.col(2) = labels(sampleIndices);

        Scatterplot *subsamplePlot = engine.rootObjects()[0]->findChild<Scatterplot *>("subsamplePlot");
        subsamplePlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton);
        subsamplePlot->setData(subsampleData);
        Scatterplot *plot = engine.rootObjects()[0]->findChild<Scatterplot *>("plot");

        // connect both plots through interaction handler
        interactionHandler = std::unique_ptr<InteractionHandler>(new InteractionHandler(X, labels, sampleIndices));
        QObject::connect(subsamplePlot, SIGNAL(dataChanged(const arma::mat &)),
                         interactionHandler.get(), SLOT(setSubsample(const arma::mat &)));
        QObject::connect(interactionHandler.get(), SIGNAL(subsampleChanged(const arma::mat &)),
                         plot, SLOT(setData(const arma::mat &)));
        interactionHandler.get()->setSubsample(Ys);
    }

    return app.exec();
}