diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2015-05-26 15:21:27 -0300 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2015-05-26 15:21:27 -0300 |
commit | 992ad77b19550b0db4c0d992683509e2b4266374 (patch) | |
tree | 6babf73047b3d2afae6528bab49f42f9f19f8f02 | |
parent | b28e59710967f89a0623132b1d91b4c37e417e28 (diff) |
Main program can now read dataset from standard input if no arguments are given.
-rw-r--r-- | main.cpp | 59 |
1 files changed, 30 insertions, 29 deletions
@@ -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(); } |