From 992ad77b19550b0db4c0d992683509e2b4266374 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 26 May 2015 15:21:27 -0300 Subject: Main program can now read dataset from standard input if no arguments are given. --- main.cpp | 59 ++++++++++++++++++++++++++++++----------------------------- 1 file 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 #include +#include #include #include #include @@ -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 *) 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(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("subsamplePlot"); - subsamplePlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); - subsamplePlot->setData(subsampleData); - Scatterplot *plot = engine.rootObjects()[0]->findChild("plot"); - - // connect both plots through interaction handler - interactionHandler = std::unique_ptr(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(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("subsamplePlot"); + subsamplePlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); + subsamplePlot->setData(subsampleData); + Scatterplot *plot = engine.rootObjects()[0]->findChild("plot"); + + // connect both plots through interaction handler + 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(); } -- cgit v1.2.3