aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.cpp59
1 files changed, 30 insertions, 29 deletions
diff --git a/main.cpp b/main.cpp
index 0f7f8c8..2024ae7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,5 +1,6 @@
#include <cmath>
#include <memory>
+#include <iostream>
#include <QSurfaceFormat>
#include <QApplication>
#include <QQmlApplicationEngine>
@@ -20,35 +21,35 @@ int main(int argc, char **argv)
QSurfaceFormat::setDefaultFormat(fmt);
QQmlApplicationEngine engine(QUrl("qrc:///main_view.qml"));
- std::unique_ptr<InteractionHandler> interactionHandler((InteractionHandler *) 0);
- if (argc > 1) {
- arma::mat dataset;
+ arma::mat dataset;
+ if (argc > 1)
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);
- }
-
+ else
+ dataset.load(std::cin, 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
+ std::unique_ptr<InteractionHandler> 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();
}