diff options
-rw-r--r-- | interactionhandler.cpp | 16 | ||||
-rw-r--r-- | interactionhandler.h | 8 | ||||
-rw-r--r-- | main.cpp | 96 | ||||
-rw-r--r-- | main.h | 40 | ||||
-rw-r--r-- | main_view.qml | 6 |
5 files changed, 87 insertions, 79 deletions
diff --git a/interactionhandler.cpp b/interactionhandler.cpp index 4046acc..64304c7 100644 --- a/interactionhandler.cpp +++ b/interactionhandler.cpp @@ -3,10 +3,10 @@ #include "mp.h" InteractionHandler::InteractionHandler(const arma::mat &X, - const arma::uvec &sampleIndices) + const arma::uvec &cpIndices) : m_X(X) , m_Y(X.n_rows, 2) - , m_sampleIndices(sampleIndices) + , m_cpIndices(cpIndices) , m_technique(TECHNIQUE_LAMP) { } @@ -19,24 +19,24 @@ void InteractionHandler::setTechnique(InteractionHandler::Technique technique) m_technique = technique; } -void InteractionHandler::setSubsample(const arma::mat &Ys) +void InteractionHandler::setCP(const arma::mat &Ys) { switch (m_technique) { case TECHNIQUE_PLMP: - mp::plmp(m_X, m_sampleIndices, Ys, m_Y); + mp::plmp(m_X, m_cpIndices, Ys, m_Y); break; case TECHNIQUE_LSP: // TODO - // mp::lsp(m_X, m_sampleIndices, Ys, m_Y); + // mp::lsp(m_X, m_cpIndices, Ys, m_Y); break; case TECHNIQUE_LAMP: - mp::lamp(m_X, m_sampleIndices, Ys, m_Y); + mp::lamp(m_X, m_cpIndices, Ys, m_Y); break; case TECHNIQUE_PEKALSKA: // TODO - // mp::pekalska(m_X, m_sampleIndices, Ys, m_Y); + // mp::pekalska(m_X, m_cpIndices, Ys, m_Y); break; } - emit subsampleChanged(m_Y); + emit cpChanged(m_Y); } diff --git a/interactionhandler.h b/interactionhandler.h index eeda230..ace192a 100644 --- a/interactionhandler.h +++ b/interactionhandler.h @@ -16,21 +16,21 @@ public: TECHNIQUE_PEKALSKA }; - InteractionHandler(const arma::mat &X, const arma::uvec &sampleIndices); + InteractionHandler(const arma::mat &X, const arma::uvec &cpIndices); void setTechnique(Technique technique); signals: - void subsampleChanged(const arma::mat &Y); + void cpChanged(const arma::mat &Y); public slots: - void setSubsample(const arma::mat &Ys); + void setCP(const arma::mat &Ys); protected: InteractionHandler() {} private: arma::mat m_X, m_Y; - arma::uvec m_sampleIndices; + arma::uvec m_cpIndices; Technique m_technique; }; @@ -41,13 +41,13 @@ int main(int argc, char **argv) parser.addPositionalArgument("dataset", "Dataset filename (.tbl file)"); QCommandLineOption indicesFileOutputOption(QStringList() << "i" << "indices", - "Filename to store the subsample indices. Omitting this option disables saving indices.", + "Filename to store the control points' indices. Omitting this option disables saving indices.", "filename"); parser.addOption(indicesFileOutputOption); - QCommandLineOption subsampleFileOutputOption(QStringList() << "s" << "subsample", - "Filename to store subsample mapping. Omitting this option disables saving subsamples.", + QCommandLineOption cpFileOutputOption(QStringList() << "c" << "cpoints", + "Filename to store the control points' map. Omitting this option disables saving this map.", "filename"); - parser.addOption(subsampleFileOutputOption); + parser.addOption(cpFileOutputOption); parser.process(app); QStringList args = parser.positionalArguments(); @@ -61,8 +61,8 @@ int main(int argc, char **argv) arma::vec labels = m->labels(); arma::uword n = X.n_rows; - int subsampleSize = (int) (3 * sqrt(n)); - arma::uvec sampleIndices; + int cpSize = (int) (3 * sqrt(n)); + arma::uvec cpIndices; arma::mat Ys; if (parser.isSet(indicesFileOutputOption)) { @@ -70,27 +70,27 @@ int main(int argc, char **argv) m->setIndicesSavePath(indicesFilename); QFile indicesFile(indicesFilename); if (indicesFile.exists()) { - sampleIndices.load(indicesFilename.toStdString(), arma::raw_ascii); - subsampleSize = sampleIndices.n_elem; + cpIndices.load(indicesFilename.toStdString(), arma::raw_ascii); + cpSize = cpIndices.n_elem; } else { - // sampleIndices = relevanceSampling(X, subsampleSize); - sampleIndices = arma::randi<arma::uvec>(subsampleSize, arma::distr_param(0, n-1)); + // cpIndices = relevanceSampling(X, cpSize); + cpIndices = arma::randi<arma::uvec>(cpSize, arma::distr_param(0, n-1)); } } - if (parser.isSet(subsampleFileOutputOption)) { - const QString &subsampleFilename = parser.value(subsampleFileOutputOption); - m->setSubsampleSavePath(subsampleFilename); - QFile subsampleFile(subsampleFilename); - if (subsampleFile.exists()) { - Ys.load(subsampleFilename.toStdString(), arma::raw_ascii); + if (parser.isSet(cpFileOutputOption)) { + const QString &cpFilename = parser.value(cpFileOutputOption); + m->setCPSavePath(cpFilename); + QFile cpFile(cpFilename); + if (cpFile.exists()) { + Ys.load(cpFilename.toStdString(), arma::raw_ascii); } else { - Ys.set_size(subsampleSize, 2); - mp::forceScheme(mp::dist(X.rows(sampleIndices)), Ys); + Ys.set_size(cpSize, 2); + mp::forceScheme(mp::dist(X.rows(cpIndices)), Ys); } } - m->setSubsampleIndices(sampleIndices); - m->setSubsample(Ys); + m->setCPIndices(cpIndices); + m->setCP(Ys); qmlRegisterType<Scatterplot>("PM", 1, 0, "Scatterplot"); qmlRegisterType<HistoryGraph>("PM", 1, 0, "HistoryGraph"); @@ -122,47 +122,47 @@ int main(int argc, char **argv) //ContinuousColorScale colorScale = ContinuousColorScale::builtin(ContinuousColorScale::RED_GRAY_BLUE); //colorScale.setExtents(-1, 1); - Scatterplot *subsamplePlot = engine.rootObjects()[0]->findChild<Scatterplot *>("subsamplePlot"); - subsamplePlot->setDisplaySplat(false); - subsamplePlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); - // subsamplePlot->setColorData(arma::zeros<arma::vec>(subsampleSize)); - subsamplePlot->setColorScale(&colorScale); + Scatterplot *cpPlot = engine.rootObjects()[0]->findChild<Scatterplot *>("cpPlot"); + cpPlot->setDisplaySplat(false); + cpPlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); + // cpPlot->setColorData(arma::zeros<arma::vec>(cpSize)); + cpPlot->setColorScale(&colorScale); Scatterplot *plot = engine.rootObjects()[0]->findChild<Scatterplot *>("plot"); skelft2DInitialization(plot->width()); - // Keep track of the current subsample (in order to save them later, if requested) - QObject::connect(subsamplePlot, SIGNAL(xyChanged(const arma::mat &)), - m, SLOT(setSubsample(const arma::mat &))); - QObject::connect(subsamplePlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), - m, SLOT(setSubsample(const arma::mat &))); + // Keep track of the current cp (in order to save them later, if requested) + QObject::connect(cpPlot, SIGNAL(xyChanged(const arma::mat &)), + m, SLOT(setCP(const arma::mat &))); + QObject::connect(cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), + m, SLOT(setCP(const arma::mat &))); - // Update projection as the subsample is modified - InteractionHandler interactionHandler(X, sampleIndices); + // Update projection as the cp is modified + InteractionHandler interactionHandler(X, cpIndices); m->setInteractionHandler(&interactionHandler); - QObject::connect(subsamplePlot, SIGNAL(xyChanged(const arma::mat &)), - &interactionHandler, SLOT(setSubsample(const arma::mat &))); - QObject::connect(subsamplePlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), - &interactionHandler, SLOT(setSubsample(const arma::mat &))); - QObject::connect(&interactionHandler, SIGNAL(subsampleChanged(const arma::mat &)), + QObject::connect(cpPlot, SIGNAL(xyChanged(const arma::mat &)), + &interactionHandler, SLOT(setCP(const arma::mat &))); + QObject::connect(cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), + &interactionHandler, SLOT(setCP(const arma::mat &))); + QObject::connect(&interactionHandler, SIGNAL(cpChanged(const arma::mat &)), plot, SLOT(setXY(const arma::mat &))); m->setTechnique(InteractionHandler::TECHNIQUE_LAMP); - // Linking between selections in subsample plot and full dataset plot - SelectionHandler selectionHandler(sampleIndices); - QObject::connect(subsamplePlot, SIGNAL(selectionChanged(const QSet<int> &)), + // Linking between selections in cp plot and full dataset plot + SelectionHandler selectionHandler(cpIndices); + QObject::connect(cpPlot, SIGNAL(selectionChanged(const QSet<int> &)), &selectionHandler, SLOT(setSelection(const QSet<int> &))); QObject::connect(&selectionHandler, SIGNAL(selectionChanged(const QSet<int> &)), plot, SLOT(setSelection(const QSet<int> &))); - // Connections between history graph and subsample plot + // Connections between history graph and cp plot //HistoryGraph *history = engine.rootObjects()[0]->findChild<HistoryGraph *>("history"); - //QObject::connect(subsamplePlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), + //QObject::connect(cpPlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), // history, SLOT(addHistoryItem(const arma::mat &))); //QObject::connect(history, SIGNAL(currentItemChanged(const arma::mat &)), - // subsamplePlot, SLOT(setXY(const arma::mat &))); + // cpPlot, SLOT(setXY(const arma::mat &))); QObject::connect(plot, SIGNAL(scaleChanged(const LinearScale<float> &, const LinearScale<float> &)), - subsamplePlot, SLOT(setScale(const LinearScale<float> &, const LinearScale<float> &))); + cpPlot, SLOT(setScale(const LinearScale<float> &, const LinearScale<float> &))); BarChart *barChart = engine.rootObjects()[0]->findChild<BarChart *>("barChart"); barChart->setValues(arma::randn<arma::vec>(100)); @@ -171,10 +171,10 @@ int main(int argc, char **argv) plot->setColorScale(&colorScale); plot->setColorData(labels, false); - subsamplePlot->setAutoScale(false); - subsamplePlot->setColorData(labels(sampleIndices), false); - subsamplePlot->setXY(Ys, false); - subsamplePlot->update(); + cpPlot->setAutoScale(false); + cpPlot->setColorData(labels(cpIndices), false); + cpPlot->setXY(Ys, false); + cpPlot->update(); auto ret = app.exec(); @@ -22,11 +22,11 @@ public: Q_INVOKABLE bool saveData() const { bool ret = true; - if (m_subsample.n_elem > 0 && m_indicesSavePath.size() > 0) { - ret = ret && m_subsample.save(m_subsampleSavePath, arma::raw_ascii); + if (m_cp.n_elem > 0 && m_indicesSavePath.size() > 0) { + ret = ret && m_cp.save(m_cpSavePath, arma::raw_ascii); } - if (m_subsampleIndices.n_elem > 0 && m_subsampleSavePath.size() > 0) { - ret = ret && m_subsampleIndices.save(m_indicesSavePath, arma::raw_ascii); + if (m_cpIndices.n_elem > 0 && m_cpSavePath.size() > 0) { + ret = ret && m_cpIndices.save(m_indicesSavePath, arma::raw_ascii); } return ret; @@ -34,10 +34,18 @@ public: Q_INVOKABLE bool loadDataset(const std::string &path) { return m_dataset.load(path, arma::raw_ascii); } - Q_INVOKABLE void setIndicesSavePath(const std::string &path) { m_indicesSavePath = path; } - Q_INVOKABLE void setIndicesSavePath(const QString &path) { setIndicesSavePath(path.toStdString()); } - Q_INVOKABLE void setSubsampleSavePath(const std::string &path) { m_subsampleSavePath = path; } - Q_INVOKABLE void setSubsampleSavePath(const QString &path) { setSubsampleSavePath(path.toStdString()); } + Q_INVOKABLE void setIndicesSavePath(const std::string &path) { + m_indicesSavePath = path; + } + Q_INVOKABLE void setIndicesSavePath(const QString &path) { + setIndicesSavePath(path.toStdString()); + } + Q_INVOKABLE void setCPSavePath(const std::string &path) { + m_cpSavePath = path; + } + Q_INVOKABLE void setCPSavePath(const QString &path) { + setCPSavePath(path.toStdString()); + } void setInteractionHandler(InteractionHandler *interactionHandler) { m_interactionHandler = interactionHandler; @@ -53,14 +61,14 @@ public: arma::vec labels() const { return m_dataset.col(m_dataset.n_cols - 1); } public slots: - void setSubsampleIndices(const arma::uvec &indices) { m_subsampleIndices = indices; } - void setSubsample(const arma::mat &subsample) { - if (subsample.n_cols != 2 - || subsample.n_rows != m_subsampleIndices.n_elem) { + void setCPIndices(const arma::uvec &indices) { m_cpIndices = indices; } + void setCP(const arma::mat &cp) { + if (cp.n_cols != 2 + || cp.n_rows != m_cpIndices.n_elem) { return; } - m_subsample = subsample; + m_cp = cp; } private: @@ -71,9 +79,9 @@ private: ~Main() {} Q_DISABLE_COPY(Main) - arma::mat m_dataset, m_subsample; - arma::uvec m_subsampleIndices; - std::string m_indicesSavePath, m_subsampleSavePath; + arma::mat m_dataset, m_cp; + arma::uvec m_cpIndices; + std::string m_indicesSavePath, m_cpSavePath; InteractionHandler *m_interactionHandler; }; diff --git a/main_view.qml b/main_view.qml index b871898..3ea6fc7 100644 --- a/main_view.qml +++ b/main_view.qml @@ -89,8 +89,8 @@ ApplicationWindow { } Scatterplot { - id: subsamplePlot - objectName: "subsamplePlot" + id: cpPlot + objectName: "cpPlot" x: parent.x y: parent.y anchors.fill: parent @@ -129,7 +129,7 @@ ApplicationWindow { text: "&Save data" shortcut: "Ctrl+S" onTriggered: { - console.log("Saving subsample mapping...") + console.log("Saving control points' map...") Main.saveData() } } |