diff --git a/cliTest/CMakeLists.txt b/cliTest/CMakeLists.txt index 7d79f531..2fe9b1d5 100644 --- a/cliTest/CMakeLists.txt +++ b/cliTest/CMakeLists.txt @@ -7,8 +7,6 @@ set(cliTest_SRCS testradiusconverter.cpp ../depthmapXcli/radiusconverter.cpp testsimpletimer.cpp - testvgaparser.cpp - ../depthmapXcli/vgaparser.cpp testlinkparser.cpp ../depthmapXcli/linkparser.cpp testagentparser.cpp @@ -31,8 +29,6 @@ set(cliTest_SRCS ../depthmapXcli/exportparser.cpp ../depthmapXcli/importparser.cpp testimportparser.cpp - ../depthmapXcli/stepdepthparser.cpp - teststepdepthparser.cpp ../depthmapXcli/segmentparser.cpp testsegmentparser.cpp ../depthmapXcli/mapconvertparser.cpp diff --git a/depthmapX/CMakeLists.txt b/depthmapX/CMakeLists.txt index e74b4af9..b52d773e 100644 --- a/depthmapX/CMakeLists.txt +++ b/depthmapX/CMakeLists.txt @@ -44,7 +44,6 @@ qt5_wrap_ui(UI_HDRS UI/RenameObjectDlg.ui UI/PushDialog.ui UI/PromptReplace.ui - UI/OptionsDlg.ui UI/NewLayerDlg.ui UI/MakeOptionsDlg.ui UI/MakeLayerDlg.ui diff --git a/depthmapX/GraphDoc.cpp b/depthmapX/GraphDoc.cpp index 547ca748..e60462c5 100644 --- a/depthmapX/GraphDoc.cpp +++ b/depthmapX/GraphDoc.cpp @@ -26,7 +26,6 @@ #include "mainwindow.h" #include "dialogs/MakeLayerDlg.h" -#include "dialogs/OptionsDlg.h" #include "dialogs/AxialAnalysisOptionsDlg.h" #include "dialogs/SegmentAnalysisDlg.h" #include "dialogs/GridDialog.h" @@ -1729,35 +1728,6 @@ void QGraphDoc::OnToolsUnmakeGraph() SetRedrawFlag(QGraphDoc::VIEW_ALL, QGraphDoc::REDRAW_GRAPH, QGraphDoc::NEW_DATA ); } -///////////////////////////////////////////////////////////////////////////// - -void QGraphDoc::OnToolsRun() -{ - if (m_communicator) { - QMessageBox::warning(this, tr("Warning"), tr("Please wait, another task is running"), QMessageBox::Ok, QMessageBox::Ok); - return; - } - - // This is easy! - COptionsDlg dlg; - - dlg.m_layer_names.push_back(""); - for (auto& dataMap: m_meta_graph->getDataMaps()) { - dlg.m_layer_names.push_back(dataMap.getName()); - } - - if (QDialog::Accepted != dlg.exec()) { - return; - } - - // This is easy too... too easy... hmm... crossed-fingers, here goes: - m_communicator = new CMSCommunicator(); - CreateWaitDialog(tr("Analysing graph...")); - m_communicator->SetFunction( CMSCommunicator::ANALYSEGRAPH ); - - m_thread.render(this); -} - void QGraphDoc::OnToolsPD() { if (m_communicator) { diff --git a/depthmapX/GraphDoc.h b/depthmapX/GraphDoc.h index 1766980c..e850c17a 100644 --- a/depthmapX/GraphDoc.h +++ b/depthmapX/GraphDoc.h @@ -301,7 +301,6 @@ public slots: void OnToolsMakeGraph(); void OnToolsUnmakeGraph(); void OnEditClear(); - void OnToolsRun(); void OnEditUndo(); void OnToolsPD(); void OnPushToLayer(); diff --git a/depthmapX/dialogs/CMakeLists.txt b/depthmapX/dialogs/CMakeLists.txt index 5fe12fed..fd885bb5 100644 --- a/depthmapX/dialogs/CMakeLists.txt +++ b/depthmapX/dialogs/CMakeLists.txt @@ -5,7 +5,6 @@ target_sources(depthmapX RenameObjectDlg.h PushDialog.h PromptReplace.h - OptionsDlg.h NewLayerDlg.h MakeOptionsDlg.h MakeLayerDlg.h @@ -37,7 +36,6 @@ target_sources(depthmapX RenameObjectDlg.cpp PushDialog.cpp PromptReplace.cpp - OptionsDlg.cpp NewLayerDlg.cpp MakeOptionsDlg.cpp MakeLayerDlg.cpp diff --git a/depthmapX/dialogs/OptionsDlg.cpp b/depthmapX/dialogs/OptionsDlg.cpp deleted file mode 100644 index 847e12dd..00000000 --- a/depthmapX/dialogs/OptionsDlg.cpp +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright (C) 2011-2012, Tasos Varoudis - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "OptionsDlg.h" -#include "mainwindow.h" -#include - -COptionsDlg::COptionsDlg(QWidget *parent) -: QDialog(parent) -{ - setupUi(this); - m_global = false; - m_local = false; - m_radius = tr(""); - m_gates_only = false; - m_output_type = -1; - m_radius2 = tr(""); - - foreach (QWidget *widget, QApplication::topLevelWidgets()) { - MainWindow *mainWin = qobject_cast(widget); - if (mainWin) - { - m_output_type = mainWin->m_options.output_type; - - m_local = mainWin->m_options.local; - m_global = mainWin->m_options.global; - m_gates_only = mainWin->m_options.gates_only; - - if ((int) mainWin->m_options.radius == -1) { - m_radius = QString("n"); - m_radius2 = QString("n"); - } - else if (m_output_type == Options::OUTPUT_VISUAL) { - char number[2]; - sprintf( number, "%d", (int) mainWin->m_options.radius ); - m_radius = QString(number); - m_radius2 = tr("n"); - } - else { - char number[32]; - sprintf( number, "%g", mainWin->m_options.radius ); - m_radius = tr("n"); - m_radius2 = QString(number); - } - break; - } - } -} - -void COptionsDlg::OnOutputType(bool value) -{ - UpdateData(true); - - if (m_output_type == Options::OUTPUT_VISUAL) { - c_local->setEnabled(true); - c_global->setEnabled(true); - c_radius->setEnabled(true); - } - else { - c_local->setEnabled(false); - c_global->setEnabled(false); - c_radius->setEnabled(false); - c_radius->setText(tr("n"));// <- essentially, undo changes - } - - if (m_output_type == Options::OUTPUT_METRIC) { - c_radius2->setEnabled(true); - } - else { - c_radius2->setText(tr("n"));// <- essentially, undo changes - c_radius2->setEnabled(false); - } -} - -void COptionsDlg::OnUpdateRadius(QString text) -{ - if (text.length()) { - if (!text.toInt() && text != tr("n")) { - QMessageBox::warning(this, tr("Warning"), tr("The radius must either be n or number in range 1-99"), QMessageBox::Ok, QMessageBox::Ok); - c_radius->setText(tr("n")); - } - } -} - -void COptionsDlg::OnUpdateRadius2(QString text) -{ - if (text.length()) { - if (text.toDouble() == 0.0 && text != tr("n")) { - QMessageBox::warning(this, tr("Warning"), tr("The radius must either be n or a positive number"), QMessageBox::Ok, QMessageBox::Ok); - c_radius2->setText(tr("n")); - } - } -} - -void COptionsDlg::OnOK() -{ - UpdateData(true); - - foreach (QWidget *widget, QApplication::topLevelWidgets()) { - MainWindow *mainWin = qobject_cast(widget); - if (mainWin) - { - mainWin->m_options.local = m_local; - mainWin->m_options.global = m_global; - mainWin->m_options.output_type = m_output_type; - mainWin->m_options.gates_only = m_gates_only; - mainWin->m_options.gatelayer = c_layer_selector->currentIndex() - 1; - - if (m_output_type == Options::OUTPUT_VISUAL) { - if (m_radius.compare(tr("n")) == 0) { // 0 means identical - mainWin->m_options.radius = -1.0; - } - else { - mainWin->m_options.radius = (double) m_radius.toInt(); - if (mainWin->m_options.radius <= 0.0) { - QMessageBox::warning(this, tr("Warning"), tr("The radius must either be n or a number in the range 1-99"), QMessageBox::Ok, QMessageBox::Ok); - return; - } - } - } - else { - if (m_radius2.compare(tr("n")) == 0) { // 0 means identical - mainWin->m_options.radius = -1.0; - } - else { - mainWin->m_options.radius = m_radius2.toDouble(); - if (mainWin->m_options.radius <= 0.0) { - QMessageBox::warning(this, tr("Warning"), tr("The radius must either be n or a positive number"), QMessageBox::Ok, QMessageBox::Ok); - return; - } - } - } - break; - } - } - accept(); -} - -void COptionsDlg::OnCancel() -{ - reject(); -} - -void COptionsDlg::UpdateData(bool value) -{ - if (value) - { - if (c_global->checkState()) - m_global = true; - else - m_global = false; - - if (c_local->checkState()) - m_local = true; - else - m_local = false; - - m_radius = c_radius->text(); - - if (c_output_type->isChecked()) - m_output_type = 0; - else if (c_radio1->isChecked()) - m_output_type = 1; - else if (c_radio2->isChecked()) - m_output_type = 2; - else if (c_radio3->isChecked()) - m_output_type = 3; - else if (c_radio4->isChecked()) - m_output_type = 4; - else - m_output_type = -1; - m_radius2 = c_radius2->text(); - } - else - { - if (m_global) - c_global->setCheckState(Qt::Checked); - else - c_global->setCheckState(Qt::Unchecked); - - if (m_local) - c_local->setCheckState(Qt::Checked); - else - c_local->setCheckState(Qt::Unchecked); - - c_radius->setText(m_radius); - - switch (m_output_type) - { - case 0: - c_output_type->setChecked(true); - break; - case 1: - c_radio1->setChecked(true); - break; - case 2: - c_radio2->setChecked(true); - break; - case 3: - c_radio3->setChecked(true); - break; - case 4: - c_radio4->setChecked(true); - break; - default: - break; - } - c_radius2->setText(m_radius2); - } -} - -void COptionsDlg::showEvent(QShowEvent * event) -{ - for (size_t i = 0; i < m_layer_names.size(); i++) { - c_layer_selector->addItem(QString(m_layer_names[i].c_str())); - } - foreach (QWidget *widget, QApplication::topLevelWidgets()) { - MainWindow *mainWin = qobject_cast(widget); - if (mainWin) - { - c_layer_selector->setCurrentIndex(mainWin->m_options.gatelayer + 1); - break; - } - } - - OnOutputType(false); - - UpdateData(false); -} diff --git a/depthmapX/mainwindow.cpp b/depthmapX/mainwindow.cpp index fff5c042..9ac9e5be 100644 --- a/depthmapX/mainwindow.cpp +++ b/depthmapX/mainwindow.cpp @@ -511,15 +511,6 @@ void MainWindow::OnToolsGenerateIsovistsFromFile() } } -void MainWindow::OnToolsRun() -{ - QGraphDoc* m_p = activeMapDoc(); - if(m_p) - { - m_p->OnToolsRun(); - } -} - void MainWindow::OnToolsAgentRun() { QGraphDoc* m_p = activeMapDoc(); @@ -2347,7 +2338,6 @@ void MainWindow::updateVisibilitySubMenu() unmakeVisibilityGraphAct->setEnabled(0); importVGALinksAct->setEnabled(0); makeIsovistPathAct->setEnabled(0); - runVisibilityGraphAnalysisAct->setEnabled(0); convertDataMapLinesAct->setEnabled(0); return; } @@ -2370,12 +2360,10 @@ void MainWindow::updateVisibilitySubMenu() if (m_p->m_meta_graph->viewingProcessedPoints()) { importVGALinksAct->setEnabled(true); - runVisibilityGraphAnalysisAct->setEnabled(true); } else { importVGALinksAct->setEnabled(0); - runVisibilityGraphAnalysisAct->setEnabled(0); } if ( !m_p->m_communicator && @@ -2386,29 +2374,6 @@ void MainWindow::updateVisibilitySubMenu() else convertDataMapLinesAct->setEnabled(0); } -void MainWindow::updateStepDepthSubMenu() -{ - QGraphDoc* m_p = activeMapDoc(); - if(!m_p) - { - visibilityStepAct->setEnabled(0); - metricStepAct->setEnabled(0); - angularStepAct->setEnabled(0); - return; - } - if (m_p->m_meta_graph->viewingProcessed() && m_p->m_meta_graph->isSelected()) - visibilityStepAct->setEnabled(true); - else visibilityStepAct->setEnabled(0); - - if ((m_p->m_meta_graph->viewingProcessedPoints() || (m_p->m_meta_graph->viewingProcessedLines() && m_p->m_meta_graph->getDisplayedShapeGraph().isSegmentMap())) && m_p->m_meta_graph->isSelected()) - metricStepAct->setEnabled(true); - else metricStepAct->setEnabled(0); - - if (m_p->m_meta_graph->viewingProcessedPoints() && m_p->m_meta_graph->isSelected()) - angularStepAct->setEnabled(true); - else angularStepAct->setEnabled(0); -} - void MainWindow::updateAgentToolsSubMenu() { QGraphDoc* m_p = activeMapDoc(); @@ -3084,21 +3049,6 @@ void MainWindow::createActions() makeIsovistPathAct = new QAction(tr("Make &Isovist Path..."), this); connect(makeIsovistPathAct, SIGNAL(triggered()), this, SLOT(OnToolsIsovistpath())); - runVisibilityGraphAnalysisAct = new QAction(tr("&Run Visibility Graph Analysis..."), this); - connect(runVisibilityGraphAnalysisAct, SIGNAL(triggered()), this, SLOT(OnToolsRun())); - - visibilityStepAct = new QAction(tr("&Visibility Step"), this); - visibilityStepAct->setStatusTip(tr("Step depth from current selection\nStep Depth")); - connect(visibilityStepAct, SIGNAL(triggered()), this, SLOT(OnToolsPD())); - - metricStepAct = new QAction(tr("&Metric Step"), this); - metricStepAct->setStatusTip(tr("Distance from current selection\nMetric Depth")); - connect(metricStepAct, SIGNAL(triggered()), this, SLOT(OnToolsMPD())); - - angularStepAct = new QAction(tr("&Angular Step"), this); - angularStepAct->setStatusTip(tr("Angular distance from current selection\nAngular Depth")); - connect(angularStepAct, SIGNAL(triggered()), this, SLOT(OnToolsAPD())); - convertDataMapLinesAct = new QAction(tr("Convert Data Map Lines to Merge Points"), this); convertDataMapLinesAct->setStatusTip(tr("Convert displayed data map lines to merge points for current visibility graph")); connect(convertDataMapLinesAct, SIGNAL(triggered()), this, SLOT(OnToolsPointConvShapeMap())); @@ -3594,11 +3544,6 @@ void MainWindow::createMenus() visibilitySubMenu->addAction(generateIsovistsAct); visibilitySubMenu->addAction(makeIsovistPathAct); visibilitySubMenu->addSeparator(); - visibilitySubMenu->addAction(runVisibilityGraphAnalysisAct); - stepDepthSubMenu = visibilitySubMenu->addMenu(tr("Step &Depth")); - stepDepthSubMenu->addAction(visibilityStepAct); - stepDepthSubMenu->addAction(metricStepAct); - stepDepthSubMenu->addAction(angularStepAct); visibilitySubMenu->addSeparator(); visibilitySubMenu->addAction(convertDataMapLinesAct); agentToolsSubMenu = toolsMenu->addMenu(tr("&Agent Tools")); @@ -3657,7 +3602,6 @@ void MainWindow::createMenus() connect(viewMenu, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu())); connect(visibilitySubMenu, SIGNAL(aboutToShow()), this, SLOT(updateVisibilitySubMenu())); - connect(stepDepthSubMenu, SIGNAL(aboutToShow()), this, SLOT(updateStepDepthSubMenu())); connect(agentToolsSubMenu, SIGNAL(aboutToShow()), this, SLOT(updateAgentToolsSubMenu())); connect(segmentSubMenu, SIGNAL(aboutToShow()), this, SLOT(updateSegmentSubMenu())); connect(segmentStepDepthSubMenu, SIGNAL(aboutToShow()), this, SLOT(updateSegmentStepDepthSubMenu())); diff --git a/depthmapX/mainwindow.h b/depthmapX/mainwindow.h index f6c023ad..bf4d271b 100644 --- a/depthmapX/mainwindow.h +++ b/depthmapX/mainwindow.h @@ -179,7 +179,6 @@ private slots: void OnWindow3dView(); void OnWindowGLView(); void OnViewScatterplot(); - void OnToolsRun(); void OnToolsAgentRun(); // MapView message void zoomModeTriggered(); @@ -215,7 +214,6 @@ private slots: void updateEditMenu(); void updateFileMenu(); void updateVisibilitySubMenu(); - void updateStepDepthSubMenu(); void updateSegmentStepDepthSubMenu(); void updateAgentToolsSubMenu(); void updateSegmentSubMenu(); @@ -294,7 +292,6 @@ private slots: QMenu *attributesMenu; QMenu *toolsMenu; QMenu *visibilitySubMenu; - QMenu *stepDepthSubMenu; QMenu *agentToolsSubMenu; QMenu *axialSubMenu; QMenu *segmentSubMenu; @@ -369,10 +366,6 @@ private slots: QAction *importVGALinksAct; QAction *generateIsovistsAct; QAction *makeIsovistPathAct; - QAction *runVisibilityGraphAnalysisAct; - QAction *visibilityStepAct; - QAction *metricStepAct; - QAction *angularStepAct; QAction *convertDataMapLinesAct; QAction *runAgentAnalysisAct; QAction *loadAgentProgramAct; diff --git a/depthmapX/mainwindowmoduleregistry.cpp b/depthmapX/mainwindowmoduleregistry.cpp index 5238510f..f0f614bb 100644 --- a/depthmapX/mainwindowmoduleregistry.cpp +++ b/depthmapX/mainwindowmoduleregistry.cpp @@ -16,9 +16,11 @@ #include "mainwindowmoduleregistry.hpp" #include "modules/segmentshortestpaths/gui/segmentpathsmainwindow.h" +#include "modules/vga/gui/vgamainwindow.h" void MainWindowModuleRegistry::populateModules() { // Register any main window modules here REGISTER_MAIN_WINDOW_MODULE(SegmentPathsMainWindow); + REGISTER_MAIN_WINDOW_MODULE(VGAMainWindow) // ********* } diff --git a/depthmapXcli/CMakeLists.txt b/depthmapXcli/CMakeLists.txt index 82ef1a97..f646bc31 100644 --- a/depthmapXcli/CMakeLists.txt +++ b/depthmapXcli/CMakeLists.txt @@ -6,7 +6,6 @@ set(depthmapXcli_SRCS commandlineparser.cpp runmethods.cpp radiusconverter.cpp - vgaparser.cpp linkparser.cpp performancewriter.cpp modeparserregistry.cpp @@ -17,7 +16,6 @@ set(depthmapXcli_SRCS isovistparser.cpp exportparser.cpp importparser.cpp - stepdepthparser.cpp segmentparser.cpp mapconvertparser.cpp) diff --git a/depthmapXcli/modeparserregistry.cpp b/depthmapXcli/modeparserregistry.cpp index e54a3d4f..aea34900 100644 --- a/depthmapXcli/modeparserregistry.cpp +++ b/depthmapXcli/modeparserregistry.cpp @@ -16,15 +16,15 @@ #include "modeparserregistry.h" #include "importparser.h" #include "linkparser.h" -#include "vgaparser.h" #include "visprepparser.h" #include "axialparser.h" #include "segmentparser.h" #include "agentparser.h" #include "isovistparser.h" #include "exportparser.h" -#include "stepdepthparser.h" #include "mapconvertparser.h" +#include "modules/vga/cli/vgaparser.h" +#include "modules/vga/cli/stepdepthparser.h" #include "modules/segmentshortestpaths/cli/segmentshortestpathparser.h" diff --git a/depthmapXcli/runmethods.cpp b/depthmapXcli/runmethods.cpp index 7065e8b2..0921e523 100644 --- a/depthmapXcli/runmethods.cpp +++ b/depthmapXcli/runmethods.cpp @@ -224,48 +224,6 @@ namespace dm_runmethods DO_TIMED("Writing graph", mgraph->write(cmdP.getOuputFile().c_str(),METAGRAPH_VERSION, false);) } - void runVga(const CommandLineParser &cmdP, const VgaParser &vgaP, const IRadiusConverter &converter, IPerformanceSink &perfWriter) - { - auto mgraph = loadGraph(cmdP.getFileName().c_str(), perfWriter); - - std::unique_ptr options(new Options()); - - std::cout << "Getting options..." << std::flush; - switch(vgaP.getVgaMode()) - { - case VgaParser::VgaMode::VISBILITY: - options->output_type = Options::OUTPUT_VISUAL; - options->local = vgaP.localMeasures(); - options->global = vgaP.globalMeasures(); - if (options->global ) - { - options->radius = converter.ConvertForVisibility(vgaP.getRadius()); - } - break; - case VgaParser::VgaMode::METRIC: - options->output_type = Options::OUTPUT_METRIC; - options->radius = converter.ConvertForMetric(vgaP.getRadius()); - break; - case VgaParser::VgaMode::ANGULAR: - options->output_type = Options::OUTPUT_ANGULAR; - break; - case VgaParser::VgaMode::ISOVIST: - options->output_type = Options::OUTPUT_ISOVIST; - break; - case VgaParser::VgaMode::THRU_VISION: - options->output_type = Options::OUTPUT_THRU_VISION; - break; - default: - throw depthmapX::SetupCheckException("Unsupported VGA mode"); - } - std::cout << " ok\nAnalysing graph..." << std::flush; - - DO_TIMED("Run VGA", mgraph->analyseGraph(getCommunicator(cmdP).get(), *options, cmdP.simpleMode() )) - std::cout << " ok\nWriting out result..." << std::flush; - DO_TIMED("Writing graph", mgraph->write(cmdP.getOuputFile().c_str(),METAGRAPH_VERSION, false)) - std::cout << " ok" << std::endl; - } - void fillGraph(MetaGraph& graph, const Point2f& point) { auto r = graph.getRegion(); @@ -723,51 +681,6 @@ namespace dm_runmethods } } - void runStepDepth( - const CommandLineParser &clp, - const StepDepthParser::StepType &stepType, - const std::vector &stepDepthPoints, - IPerformanceSink &perfWriter) - { - auto mGraph = loadGraph(clp.getFileName().c_str(),perfWriter); - - std::cout << "ok\nSelecting cells... " << std::flush; - - for( auto & point : stepDepthPoints ) { - auto graphRegion = mGraph->getRegion(); - if (!graphRegion.contains(point)) - { - throw depthmapX::RuntimeException("Point outside of target region"); - } - QtRegion r(point, point); - mGraph->setCurSel(r, true); - } - - std::cout << "ok\nCalculating step-depth... " << std::flush; - - Options options; - options.global = 0; - - switch (stepType) { - case StepDepthParser::StepType::ANGULAR: - options.point_depth_selection = 3; - break; - case StepDepthParser::StepType::METRIC: - options.point_depth_selection = 2; - break; - case StepDepthParser::StepType::VISUAL: - options.point_depth_selection = 1; - break; - default: { throw depthmapX::SetupCheckException("Error, unsupported step type"); } - } - - DO_TIMED("Calculating step-depth", mGraph->analyseGraph( getCommunicator(clp).get(), options, false)) - - std::cout << " ok\nWriting out result..." << std::flush; - DO_TIMED("Writing graph", mGraph->write(clp.getOuputFile().c_str(),METAGRAPH_VERSION, false)) - std::cout << " ok" << std::endl; - } - void runMapConversion(const CommandLineParser &clp, const MapConvertParser &mcp, IPerformanceSink &perfWriter) { auto mGraph = loadGraph(clp.getFileName().c_str(), perfWriter); diff --git a/depthmapXcli/runmethods.h b/depthmapXcli/runmethods.h index 5aa57538..361bdacd 100644 --- a/depthmapXcli/runmethods.h +++ b/depthmapXcli/runmethods.h @@ -20,7 +20,6 @@ #include "commandlineparser.h" #include "radiusconverter.h" #include "performancesink.h" -#include "vgaparser.h" #include "axialparser.h" #include "mapconvertparser.h" #include "segmentparser.h" @@ -28,7 +27,6 @@ #include "exportparser.h" #include "linkparser.h" #include "importparser.h" -#include "stepdepthparser.h" #include "salalib/isovistdef.h" #include @@ -45,14 +43,13 @@ class Point2f; namespace dm_runmethods{ std::unique_ptr loadGraph(const std::string& filename, IPerformanceSink &perfWriter); void importFiles(const CommandLineParser &cmdP, const ImportParser &parser, IPerformanceSink &perfWriter); + std::unique_ptr getCommunicator(const CommandLineParser &clp); void linkGraph(const CommandLineParser &cmdP, const LinkParser &parser, IPerformanceSink &perfWriter ); - void runVga(const CommandLineParser &cmdP, const VgaParser &vgaP, const IRadiusConverter &converter, IPerformanceSink &perfWriter ); void runVisualPrep(const CommandLineParser &clp, double gridSize, const std::vector &fillPoints, double maxVisibility, bool boundaryGraph, bool makeGraph, bool unmakeGraph, bool removeLinksWhenUnmaking, IPerformanceSink &perfWriter); void runAxialAnalysis(const CommandLineParser& clp, const AxialParser &ap, IPerformanceSink &perfWriter); void runSegmentAnalysis(const CommandLineParser& clp, const SegmentParser &sp, IPerformanceSink &perfWriter); void runAgentAnalysis(const CommandLineParser &cmdP, const AgentParser &agentP, IPerformanceSink &perfWriter ); void runIsovists(const CommandLineParser &cmdP, const std::vector &isovists, IPerformanceSink &perfWriter ); void exportData(const CommandLineParser &cmdP, const ExportParser &exportP, IPerformanceSink &perfWriter ); - void runStepDepth(const CommandLineParser &clp, const StepDepthParser::StepType &stepType, const std::vector &stepDepthPoints, IPerformanceSink &perfWriter); void runMapConversion(const CommandLineParser& clp, const MapConvertParser &mcp, IPerformanceSink &perfWriter); } diff --git a/depthmapXcli/vgaparser.cpp b/depthmapXcli/vgaparser.cpp deleted file mode 100644 index 2299d9d2..00000000 --- a/depthmapXcli/vgaparser.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (C) 2017 Christian Sailer - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "vgaparser.h" -#include "exceptions.h" -#include -#include "radiusconverter.h" -#include "runmethods.h" -#include "parsingutils.h" - -using namespace depthmapX; - - -VgaParser::VgaParser() : m_vgaMode(VgaMode::NONE), m_localMeasures(false), m_globalMeasures(false) -{} - -void VgaParser::parse(int argc, char *argv[]) -{ - for ( int i = 1; i < argc; ) - { - - if ( std::strcmp ("-vm", argv[i]) == 0) - { - if (m_vgaMode != VgaMode::NONE) - { - throw CommandLineException("-vm can only be used once, modes are mutually exclusive"); - } - ENFORCE_ARGUMENT("-vm", i) - if ( std::strcmp(argv[i], "isovist") == 0 ) - { - m_vgaMode = VgaMode::ISOVIST; - } - else if ( std::strcmp(argv[i], "visibility") == 0 ) - { - m_vgaMode = VgaMode::VISBILITY; - } - else if ( std::strcmp(argv[i], "metric") == 0 ) - { - m_vgaMode = VgaMode::METRIC; - } - else if ( std::strcmp(argv[i], "angular") == 0 ) - { - m_vgaMode = VgaMode::ANGULAR; - } - else if ( std::strcmp(argv[i], "thruvision") == 0) - { - m_vgaMode = VgaMode::THRU_VISION; - } - else - { - throw CommandLineException(std::string("Invalid VGA mode: ") + argv[i]); - } - } - else if ( std::strcmp(argv[i], "-vg") == 0 ) - { - m_globalMeasures = true; - } - else if ( std::strcmp(argv[i], "-vl") == 0 ) - { - m_localMeasures = true; - } - else if (std::strcmp(argv[i], "-vr") == 0) - { - ENFORCE_ARGUMENT("-vr", i) - m_radius = argv[i]; - } - ++i; - } - - if(m_vgaMode == VgaMode::NONE) - { - m_vgaMode = VgaMode::ISOVIST; - } - - if (m_vgaMode == VgaMode::VISBILITY && m_globalMeasures) - { - if (m_radius.empty()) - { - throw CommandLineException("Global measures in VGA/visibility analysis require a radius, use -vr "); - } - if (m_radius != "n" && !has_only_digits(m_radius)) - { - throw CommandLineException(std::string("Radius must be a positive integer number or n, got ") + m_radius); - } - - } - else if (m_vgaMode == VgaMode::METRIC) - { - if (m_radius.empty()) - { - throw CommandLineException("Metric vga requires a radius, use -vr "); - } - } -} - -void VgaParser::run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const -{ - RadiusConverter radiusConverter; - dm_runmethods::runVga(clp, *this, radiusConverter, perfWriter); -} diff --git a/modules/vga/CMakeLists.txt b/modules/vga/CMakeLists.txt new file mode 100644 index 00000000..70b4dd7b --- /dev/null +++ b/modules/vga/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright (C) 2020 Petros Koutsolampros + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +if(MODULES_CORE) +add_subdirectory(core) +endif() + +if(MODULES_GUI) + add_subdirectory(gui) +endif() + +if(MODULES_CLI) + add_subdirectory(cli) +endif() + +if(MODULES_CORE_TEST) + add_subdirectory(coreTest) +endif() + +if(MODULES_CLI_TEST) + add_subdirectory(cliTest) +endif() diff --git a/modules/vga/RegressionTest/regressionconfig.json b/modules/vga/RegressionTest/regressionconfig.json new file mode 100644 index 00000000..3025041d --- /dev/null +++ b/modules/vga/RegressionTest/regressionconfig.json @@ -0,0 +1,217 @@ +{ + "rundir": "rundir", + "basebinlocation": "../../BaselineBinaries", + "testbinlocation": "../../../build", + "testcases": { + "visibility_local": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "visibility", + "-vl": "" + } + }], + "visibility_local_only_map": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "visibility", + "-vl": "" + } + },{ + "infile": "out.graph", + "outfile": "out.csv", + "mode": "EXPORT", + "extraArgs": { + "-em": "pointmap-data-csv" + } + }], + "visibility_global_with_multiple_pointmaps": [{ + "infile": "../../../testdata/gallery_two_pointmaps.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "visibility", + "-vg": "", + "-vr": "3" + } + }], + "visibility_global_3": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "visibility", + "-vg": "", + "-vr": "3" + } + }], + "visibility_global_3_only_map": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "visibility", + "-vg": "", + "-vr": "3" + } + },{ + "infile": "out.graph", + "outfile": "out.csv", + "mode": "EXPORT", + "extraArgs": { + "-em": "pointmap-data-csv" + } + }], + "visibility_global_n": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "visibility", + "-vg": "", + "-vr": "n" + } + }], + "visibility_global_n_only_map": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "visibility", + "-vg": "", + "-vr": "n" + } + },{ + "infile": "out.graph", + "outfile": "out.csv", + "mode": "EXPORT", + "extraArgs": { + "-em": "pointmap-data-csv" + } + }], + "vga_isovist": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "isovist" + } + }], + "vga_isovist_only_map": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "isovist" + } + },{ + "infile": "out.graph", + "outfile": "out.csv", + "mode": "EXPORT", + "extraArgs": { + "-em": "pointmap-data-csv" + } + }], + "vga_angular": [{ + "infile": "../../../testdata/turns_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "angular" + } + }], + "vga_angular_only_map": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "angular" + } + },{ + "infile": "out.graph", + "outfile": "out.csv", + "mode": "EXPORT", + "extraArgs": { + "-em": "pointmap-data-csv" + } + }], + "vga_metric": [{ + "infile": "../../../testdata/turns_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "metric", + "-vr": "n" + } + }], + "vga_metric_only_map": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "metric", + "-vr": "n" + } + },{ + "infile": "out.graph", + "outfile": "out.csv", + "mode": "EXPORT", + "extraArgs": { + "-em": "pointmap-data-csv" + } + }], + "vga_thru_vision": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "thruvision" + } + }], + "vga_thru_vision_only_map": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "VGA", + "extraArgs": { + "-vm": "thruvision" + } + },{ + "infile": "out.graph", + "outfile": "out.csv", + "mode": "EXPORT", + "extraArgs": { + "-em": "pointmap-data-csv" + } + }], + "vga_visual_step_depth": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "STEPDEPTH", + "extraArgs":{ + "-sdp": "3,5", + "-sdt": "visual" + } + }], + "vga_metric_step_depth": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "STEPDEPTH", + "extraArgs":{ + "-sdp": "3,5", + "-sdt": "metric" + } + }], + "vga_angular_step_depth": [{ + "infile": "../../../testdata/gallery_connected.graph", + "outfile": "out.graph", + "mode": "STEPDEPTH", + "extraArgs":{ + "-sdp": "3,5", + "-sdt": "angular" + } + }] + } +} diff --git a/modules/vga/cli/CMakeLists.txt b/modules/vga/cli/CMakeLists.txt new file mode 100644 index 00000000..88b89833 --- /dev/null +++ b/modules/vga/cli/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (C) 2020 Petros Koutsolampros + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(vgacli vgacli) +set(vgacli_SRCS + vgaparser.cpp + stepdepthparser.cpp) + +set(modules_cli "${modules_cli}" "vgacli" CACHE INTERNAL "modules_cli" FORCE) + +add_compile_definitions(VGA_CLI_LIBRARY) + +add_library(${vgacli} OBJECT ${vgacli_SRCS}) diff --git a/depthmapXcli/stepdepthparser.cpp b/modules/vga/cli/stepdepthparser.cpp similarity index 52% rename from depthmapXcli/stepdepthparser.cpp rename to modules/vga/cli/stepdepthparser.cpp index df352e2a..7a3866a0 100644 --- a/depthmapXcli/stepdepthparser.cpp +++ b/modules/vga/cli/stepdepthparser.cpp @@ -14,109 +14,121 @@ // along with this program. If not, see . #include "stepdepthparser.h" -#include "exceptions.h" -#include "parsingutils.h" +#include "depthmapXcli/exceptions.h" +#include "depthmapXcli/parsingutils.h" +#include "depthmapXcli/runmethods.h" +#include "depthmapXcli/simpletimer.h" +#include "modules/vga/core/vgaangulardepth.h" +#include "modules/vga/core/vgametricdepth.h" +#include "modules/vga/core/vgavisualglobaldepth.h" #include "salalib/entityparsing.h" -#include "runmethods.h" -#include #include +#include using namespace depthmapX; -void StepDepthParser::parse(int argc, char ** argv) -{ +void StepDepthParser::parse(int argc, char **argv) { std::vector points; std::string pointFile; - for ( int i = 1; i < argc; ++i ) - { - if ( std::strcmp ("-sdp", argv[i]) == 0) - { - if (!pointFile.empty()) - { + for (int i = 1; i < argc; ++i) { + if (std::strcmp("-sdp", argv[i]) == 0) { + if (!pointFile.empty()) { throw CommandLineException("-sdp cannot be used together with -sdf"); } ENFORCE_ARGUMENT("-sdp", i) - if (!has_only_digits_dots_commas(argv[i])) - { + if (!has_only_digits_dots_commas(argv[i])) { std::stringstream message; - message << "Invalid step depth point provided (" - << argv[i] - << "). Should only contain digits dots and commas" - << std::flush; + message << "Invalid step depth point provided (" << argv[i] + << "). Should only contain digits dots and commas" << std::flush; throw CommandLineException(message.str().c_str()); } points.push_back(argv[i]); - } - else if ( std::strcmp("-sdf", argv[i]) == 0 ) - { - if (!points.empty()) - { + } else if (std::strcmp("-sdf", argv[i]) == 0) { + if (!points.empty()) { throw CommandLineException("-sdf cannot be used together with -sdp"); } ENFORCE_ARGUMENT("-sdf", i) pointFile = argv[i]; - } - else if ( std::strcmp ("-sdt", argv[i]) == 0) - { + } else if (std::strcmp("-sdt", argv[i]) == 0) { ENFORCE_ARGUMENT("-sdt", i) - if ( std::strcmp(argv[i], "angular") == 0 ) - { + if (std::strcmp(argv[i], "angular") == 0) { m_stepType = StepType::ANGULAR; - } - else if ( std::strcmp(argv[i], "metric") == 0 ) - { + } else if (std::strcmp(argv[i], "metric") == 0) { m_stepType = StepType::METRIC; - } - else if ( std::strcmp(argv[i], "visual") == 0 ) - { + } else if (std::strcmp(argv[i], "visual") == 0) { m_stepType = StepType::VISUAL; - } - else - { + } else { throw CommandLineException(std::string("Invalid step type: ") + argv[i]); } } } - if (pointFile.empty() && points.empty()) - { + if (pointFile.empty() && points.empty()) { throw CommandLineException("Either -sdp or -sdf must be given"); } - if(!pointFile.empty()) - { + if (!pointFile.empty()) { std::ifstream pointsStream(pointFile); - if (!pointsStream) - { + if (!pointsStream) { std::stringstream message; message << "Failed to load file " << pointFile << ", error " << std::strerror(errno) << std::flush; throw depthmapX::RuntimeException(message.str().c_str()); } std::vector parsed = EntityParsing::parsePoints(pointsStream, '\t'); m_stepDepthPoints.insert(std::end(m_stepDepthPoints), std::begin(parsed), std::end(parsed)); - } - else if(!points.empty()) - { + } else if (!points.empty()) { std::stringstream pointsStream; pointsStream << "x,y"; - std::vector::iterator iter = points.begin(), end = - points.end(); - for ( ; iter != end; ++iter ) - { + std::vector::iterator iter = points.begin(), end = points.end(); + for (; iter != end; ++iter) { pointsStream << "\n" << *iter; } std::vector parsed = EntityParsing::parsePoints(pointsStream, ','); m_stepDepthPoints.insert(std::end(m_stepDepthPoints), std::begin(parsed), std::end(parsed)); } - if (m_stepType == StepType::NONE) - { + if (m_stepType == StepType::NONE) { throw CommandLineException("Step depth type (-sdt) must be provided"); } } -void StepDepthParser::run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const -{ - dm_runmethods::runStepDepth(clp, m_stepType, m_stepDepthPoints, perfWriter); +void StepDepthParser::run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const { + auto mGraph = dm_runmethods::loadGraph(clp.getFileName().c_str(), perfWriter); + + std::cout << "ok\nSelecting cells... " << std::flush; + + for (auto &point : m_stepDepthPoints) { + auto graphRegion = mGraph->getRegion(); + if (!graphRegion.contains(point)) { + throw depthmapX::RuntimeException("Point outside of target region"); + } + QtRegion r(point, point); + mGraph->setCurSel(r, true); + } + + std::cout << "ok\nCalculating step-depth... " << std::flush; + + std::unique_ptr analysis = nullptr; + + switch (m_stepType) { + case StepDepthParser::StepType::ANGULAR: + analysis = std::unique_ptr(new VGAAngularDepth(mGraph->getDisplayedPointMap())); + break; + case StepDepthParser::StepType::METRIC: + analysis = std::unique_ptr(new VGAMetricDepth(mGraph->getDisplayedPointMap())); + break; + case StepDepthParser::StepType::VISUAL: + analysis = std::unique_ptr(new VGAVisualGlobalDepth(mGraph->getDisplayedPointMap())); + break; + default: { + throw depthmapX::SetupCheckException("Error, unsupported step type"); + } + } + + DO_TIMED("Calculating step-depth", analysis->run(dm_runmethods::getCommunicator(clp).get())) + + std::cout << " ok\nWriting out result..." << std::flush; + DO_TIMED("Writing graph", mGraph->write(clp.getOuputFile().c_str(), METAGRAPH_VERSION, false)) + std::cout << " ok" << std::endl; } diff --git a/depthmapXcli/stepdepthparser.h b/modules/vga/cli/stepdepthparser.h similarity index 69% rename from depthmapXcli/stepdepthparser.h rename to modules/vga/cli/stepdepthparser.h index 73c324ca..52deb90c 100644 --- a/depthmapXcli/stepdepthparser.h +++ b/modules/vga/cli/stepdepthparser.h @@ -15,37 +15,26 @@ #pragma once -#include "imodeparser.h" +#include "depthmapXcli/imodeparser.h" #include "genlib/p2dpoly.h" #include -class StepDepthParser : public IModeParser -{ -public: - StepDepthParser() : m_stepType(StepType::NONE) - {} +class StepDepthParser : public IModeParser { + public: + StepDepthParser() : m_stepType(StepType::NONE) {} - virtual std::string getModeName() const - { - return "STEPDEPTH"; - } + virtual std::string getModeName() const { return "STEPDEPTH"; } - virtual std::string getHelp() const - { - return "Mode options for pointmap STEPDEPTH are:\n" \ - " -sdp point where to calculate step depth from. Can be repeated\n" \ - " -sdf a file with a point per line to calculate step depth from\n" \ + virtual std::string getHelp() const { + return "Mode options for pointmap STEPDEPTH are:\n" + " -sdp point where to calculate step depth from. Can be repeated\n" + " -sdf a file with a point per line to calculate step depth from\n" " -sdt step type. One of metric, angular or visual\n"; } - enum class StepType { - NONE, - ANGULAR, - METRIC, - VISUAL - }; + enum class StepType { NONE, ANGULAR, METRIC, VISUAL }; - virtual void parse(int argc, char** argv); + virtual void parse(int argc, char **argv); virtual void run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const; @@ -53,10 +42,8 @@ class StepDepthParser : public IModeParser StepType getStepType() const { return m_stepType; } -private: + private: std::vector m_stepDepthPoints; StepType m_stepType; }; - - diff --git a/modules/vga/cli/vgaparser.cpp b/modules/vga/cli/vgaparser.cpp new file mode 100644 index 00000000..1d56c238 --- /dev/null +++ b/modules/vga/cli/vgaparser.cpp @@ -0,0 +1,131 @@ +// Copyright (C) 2017 Christian Sailer +// Copyright (C) 2020 Petros Koutsolampros + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "vgaparser.h" +#include "depthmapXcli/exceptions.h" +#include "depthmapXcli/parsingutils.h" +#include "depthmapXcli/runmethods.h" +#include "depthmapXcli/simpletimer.h" +#include "modules/vga/core/vgaangular.h" +#include "modules/vga/core/vgaisovist.h" +#include "modules/vga/core/vgametric.h" +#include "modules/vga/core/vgathroughvision.h" +#include "modules/vga/core/vgavisualglobal.h" +#include "modules/vga/core/vgavisuallocal.h" +#include "salalib/options.h" +#include +#include + +using namespace depthmapX; + +VgaParser::VgaParser() : m_vgaMode(VgaMode::NONE), m_localMeasures(false), m_globalMeasures(false) {} + +void VgaParser::parse(int argc, char *argv[]) { + for (int i = 1; i < argc;) { + + if (std::strcmp("-vm", argv[i]) == 0) { + if (m_vgaMode != VgaMode::NONE) { + throw CommandLineException("-vm can only be used once, modes are mutually exclusive"); + } + ENFORCE_ARGUMENT("-vm", i) + if (std::strcmp(argv[i], "isovist") == 0) { + m_vgaMode = VgaMode::ISOVIST; + } else if (std::strcmp(argv[i], "visibility") == 0) { + m_vgaMode = VgaMode::VISBILITY; + } else if (std::strcmp(argv[i], "metric") == 0) { + m_vgaMode = VgaMode::METRIC; + } else if (std::strcmp(argv[i], "angular") == 0) { + m_vgaMode = VgaMode::ANGULAR; + } else if (std::strcmp(argv[i], "thruvision") == 0) { + m_vgaMode = VgaMode::THRU_VISION; + } else { + throw CommandLineException(std::string("Invalid VGA mode: ") + argv[i]); + } + } else if (std::strcmp(argv[i], "-vg") == 0) { + m_globalMeasures = true; + } else if (std::strcmp(argv[i], "-vl") == 0) { + m_localMeasures = true; + } else if (std::strcmp(argv[i], "-vr") == 0) { + ENFORCE_ARGUMENT("-vr", i) + m_radius = argv[i]; + } + ++i; + } + + if (m_vgaMode == VgaMode::NONE) { + m_vgaMode = VgaMode::ISOVIST; + } + + if (m_vgaMode == VgaMode::VISBILITY && m_globalMeasures) { + if (m_radius.empty()) { + throw CommandLineException( + "Global measures in VGA/visibility analysis require a radius, use -vr "); + } + if (m_radius != "n" && !has_only_digits(m_radius)) { + throw CommandLineException(std::string("Radius must be a positive integer number or n, got ") + m_radius); + } + + } else if (m_vgaMode == VgaMode::METRIC) { + if (m_radius.empty()) { + throw CommandLineException("Metric vga requires a radius, use -vr "); + } + } +} + +void VgaParser::run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const { + + auto mgraph = dm_runmethods::loadGraph(clp.getFileName().c_str(), perfWriter); + + std::unique_ptr analysis = nullptr; + + RadiusConverter radiusConverter; + switch (getVgaMode()) { + case VgaMode::VISBILITY: + if (globalMeasures()) { + analysis = std::unique_ptr( + new VGAVisualGlobal(mgraph->getDisplayedPointMap(), radiusConverter.ConvertForVisibility(getRadius()), + false, clp.simpleMode())); + } + if (localMeasures()) { + analysis = std::unique_ptr( + new VGAVisualLocal(mgraph->getDisplayedPointMap(), false, clp.simpleMode())); + } + break; + case VgaMode::METRIC: + analysis = std::unique_ptr( + new VGAMetric(mgraph->getDisplayedPointMap(), radiusConverter.ConvertForMetric(getRadius()), false)); + break; + case VgaMode::ANGULAR: + analysis = std::unique_ptr( + new VGAAngular(mgraph->getDisplayedPointMap(), -1, false)); + break; + case VgaMode::ISOVIST: + analysis = std::unique_ptr(new VGAIsovist(mgraph->getDisplayedPointMap(), clp.simpleMode())); + break; + case VgaMode::THRU_VISION: + analysis = std::unique_ptr(new VGAThroughVision(mgraph->getDisplayedPointMap())); + break; + default: + throw depthmapX::SetupCheckException("Unsupported VGA mode"); + } + + std::cout << " ok\nAnalysing graph..." << std::flush; + + DO_TIMED("Run VGA", analysis->run(dm_runmethods::getCommunicator(clp).get())) + std::cout << " ok\nWriting out result..." << std::flush; + DO_TIMED("Writing graph", mgraph->write(clp.getOuputFile().c_str(), METAGRAPH_VERSION, false)) + std::cout << " ok" << std::endl; +} diff --git a/depthmapXcli/vgaparser.h b/modules/vga/cli/vgaparser.h similarity index 58% rename from depthmapXcli/vgaparser.h rename to modules/vga/cli/vgaparser.h index 5bcf949a..b9f87116 100644 --- a/depthmapXcli/vgaparser.h +++ b/modules/vga/cli/vgaparser.h @@ -15,51 +15,40 @@ #pragma once +#include "depthmapXcli/commandlineparser.h" +#include "depthmapXcli/imodeparser.h" +#include "depthmapXcli/radiusconverter.h" #include -#include "imodeparser.h" -#include "commandlineparser.h" -class VgaParser : public IModeParser -{ -public: - virtual std::string getModeName() const - { - return "VGA"; - } +class VgaParser : public IModeParser { + public: + virtual std::string getModeName() const { return "VGA"; } - virtual std::string getHelp() const - { - return "Mode options for VGA:\n"\ - "-vm one of isovist, visiblity, metric, angular, thruvision\n"\ - "-vg turn on global measures for visibility, requires radius between 1 and 99 or n\n"\ - "-vl turn on local measures for visibility\n"\ - "-vr set visibility radius\n"; + virtual std::string getHelp() const { + return "Mode options for VGA:\n" + "-vm one of isovist, visiblity, metric, angular, thruvision\n" + "-vg turn on global measures for visibility, requires radius between 1 and 99 or n\n" + "-vl turn on local measures for visibility\n" + "-vr set visibility radius\n"; } -public: + public: VgaParser(); virtual void parse(int argc, char *argv[]); - virtual void run(const CommandLineParser &clp, IPerformanceSink& perfWriter) const; + virtual void run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const; - enum VgaMode{ - NONE, - ISOVIST, - VISBILITY, - METRIC, - ANGULAR, - THRU_VISION - }; + enum VgaMode { NONE, ISOVIST, VISBILITY, METRIC, ANGULAR, THRU_VISION }; // vga options VgaMode getVgaMode() const { return m_vgaMode; } bool localMeasures() const { return m_localMeasures; } bool globalMeasures() const { return m_globalMeasures; } - const std::string & getRadius() const { return m_radius; } -private: + const std::string &getRadius() const { return m_radius; } + + private: // vga options VgaMode m_vgaMode; bool m_localMeasures; bool m_globalMeasures; std::string m_radius; }; - diff --git a/modules/vga/cliTest/CMakeLists.txt b/modules/vga/cliTest/CMakeLists.txt new file mode 100644 index 00000000..ed5f1bac --- /dev/null +++ b/modules/vga/cliTest/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (C) 2020 Petros Koutsolampros + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(vgaclitest vgaclitest) +set(vgaclitest_SRCS + vgaparsertest.cpp) + +set(modules_cliTest "${modules_cliTest}" "vgaclitest" CACHE INTERNAL "modules_cliTest" FORCE) + +add_compile_definitions(VGA_CLI_TEST_LIBRARY) + +add_library(${vgaclitest} OBJECT ${vgaclitest_SRCS}) diff --git a/cliTest/teststepdepthparser.cpp b/modules/vga/cliTest/teststepdepthparser.cpp similarity index 100% rename from cliTest/teststepdepthparser.cpp rename to modules/vga/cliTest/teststepdepthparser.cpp diff --git a/cliTest/testvgaparser.cpp b/modules/vga/cliTest/vgaparsertest.cpp similarity index 77% rename from cliTest/testvgaparser.cpp rename to modules/vga/cliTest/vgaparsertest.cpp index a1975b3c..019e6d85 100644 --- a/cliTest/testvgaparser.cpp +++ b/modules/vga/cliTest/vgaparsertest.cpp @@ -13,19 +13,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "modules/vga/cli/vgaparser.h" #include "catch.hpp" -#include "../depthmapXcli/vgaparser.h" -#include "argumentholder.h" +#include "cliTest/argumentholder.h" -TEST_CASE("VGA args invalid", "") -{ +TEST_CASE("VGA args invalid", "") { { ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", "VGA", "-vm"}; VgaParser p; REQUIRE_THROWS_WITH(p.parse(ah.argc(), ah.argv()), Catch::Contains("-vm requires an argument")); } - { ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", "VGA", "-vm", "foo"}; VgaParser p; @@ -38,11 +36,12 @@ TEST_CASE("VGA args invalid", "") REQUIRE_THROWS_WITH(p.parse(ah.argc(), ah.argv()), Catch::Contains("-vm can only be used once")); } - { ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", "VGA", "-vm", "visibility", "-vg"}; VgaParser p; - REQUIRE_THROWS_WITH(p.parse(ah.argc(), ah.argv()), Catch::Contains("Global measures in VGA/visibility analysis require a radius, use -vr ")); + REQUIRE_THROWS_WITH( + p.parse(ah.argc(), ah.argv()), + Catch::Contains("Global measures in VGA/visibility analysis require a radius, use -vr ")); } { @@ -52,20 +51,22 @@ TEST_CASE("VGA args invalid", "") } { - ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", "VGA", "-vm", "visibility", "-vg", "-vr", "foo"}; + ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", + "VGA", "-vm", "visibility", "-vg", "-vr", "foo"}; VgaParser p; - REQUIRE_THROWS_WITH(p.parse(ah.argc(), ah.argv()), Catch::Contains("Radius must be a positive integer number or n, got foo")); + REQUIRE_THROWS_WITH(p.parse(ah.argc(), ah.argv()), + Catch::Contains("Radius must be a positive integer number or n, got foo")); } { ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", "VGA", "-vm", "metric"}; VgaParser p; - REQUIRE_THROWS_WITH(p.parse(ah.argc(), ah.argv()), Catch::Contains("Metric vga requires a radius, use -vr ")); + REQUIRE_THROWS_WITH(p.parse(ah.argc(), ah.argv()), + Catch::Contains("Metric vga requires a radius, use -vr ")); } } -TEST_CASE("VGA args valid", "valid") -{ +TEST_CASE("VGA args valid", "valid") { { ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", "VGA"}; VgaParser cmdP; @@ -91,7 +92,8 @@ TEST_CASE("VGA args valid", "valid") } { - ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", "VGA", "-vm", "visibility", "-vl", "-vg", "-vr", "4"}; + ArgumentHolder ah{"prog", "-f", "infile", "-o", "outfile", "-m", "VGA", + "-vm", "visibility", "-vl", "-vg", "-vr", "4"}; VgaParser cmdP; cmdP.parse(ah.argc(), ah.argv()); REQUIRE(cmdP.getVgaMode() == VgaParser::VgaMode::VISBILITY); @@ -106,6 +108,4 @@ TEST_CASE("VGA args valid", "valid") cmdP.parse(ah.argc(), ah.argv()); REQUIRE(cmdP.getVgaMode() == VgaParser::VgaMode::THRU_VISION); } - - } diff --git a/modules/vga/core/CMakeLists.txt b/modules/vga/core/CMakeLists.txt new file mode 100644 index 00000000..f1ce0873 --- /dev/null +++ b/modules/vga/core/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (C) 2020 Petros Koutsolampros + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(vgacore vgacore) +set(vgacore_SRCS + vgaangular.cpp + vgaangulardepth.cpp + vgaisovist.cpp + vgametric.cpp + vgametricdepth.cpp + vgathroughvision.cpp + vgavisualglobal.cpp + vgavisualglobaldepth.cpp + vgavisuallocal.cpp) + +set(modules_core "${modules_core}" "vgacore" CACHE INTERNAL "modules_core" FORCE) + +add_compile_definitions(VGA_CORE_LIBRARY) + +add_library(${vgacore} OBJECT ${vgacore_SRCS}) diff --git a/salalib/vgamodules/vgaangular.cpp b/modules/vga/core/vgaangular.cpp similarity index 83% rename from salalib/vgamodules/vgaangular.cpp rename to modules/vga/core/vgaangular.cpp index 85005db8..f0523cdf 100644 --- a/salalib/vgamodules/vgaangular.cpp +++ b/modules/vga/core/vgaangular.cpp @@ -16,29 +16,29 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgaangular.h" +#include "vgaangular.h" #include "genlib/stringutils.h" -bool VGAAngular::run(Communicator *comm, PointMap &map, bool) { +bool VGAAngular::run(Communicator *comm) { time_t atime = 0; if (comm) { qtimer(atime, 0); - comm->CommPostMessage(Communicator::NUM_RECORDS, map.getFilledPointCount()); + comm->CommPostMessage(Communicator::NUM_RECORDS, m_map.getFilledPointCount()); } std::string radius_text; if (m_radius != -1.0) { - if (map.getRegion().width() > 100.0) { + if (m_map.getRegion().width() > 100.0) { radius_text = std::string(" R") + dXstring::formatString(m_radius, "%.f"); - } else if (map.getRegion().width() < 1.0) { + } else if (m_map.getRegion().width() < 1.0) { radius_text = std::string(" R") + dXstring::formatString(m_radius, "%.4f"); } else { radius_text = std::string(" R") + dXstring::formatString(m_radius, "%.2f"); } } - AttributeTable &attributes = map.getAttributeTable(); + AttributeTable &attributes = m_map.getAttributeTable(); // n.b. these must be entered in alphabetical order to preserve col indexing: std::string mean_depth_col_text = std::string("Angular Mean Depth") + radius_text; @@ -53,11 +53,11 @@ bool VGAAngular::run(Communicator *comm, PointMap &map, bool) { int count = 0; - for (size_t i = 0; i < map.getCols(); i++) { - for (size_t j = 0; j < map.getRows(); j++) { + for (size_t i = 0; i < m_map.getCols(); i++) { + for (size_t j = 0; j < m_map.getRows(); j++) { PixelRef curs = PixelRef(static_cast(i), static_cast(j)); - if (map.getPoint(curs).filled()) { + if (m_map.getPoint(curs).filled()) { if (m_gates_only) { count++; @@ -65,7 +65,7 @@ bool VGAAngular::run(Communicator *comm, PointMap &map, bool) { } // TODO: Break out miscs/dist/cumangle into local variables and remove from Point class - for (auto &point : map.getPoints()) { + for (auto &point : m_map.getPoints()) { point.m_misc = 0; point.m_dist = 0.0f; point.m_cumangle = -1.0f; @@ -79,7 +79,7 @@ bool VGAAngular::run(Communicator *comm, PointMap &map, bool) { std::set search_list; search_list.insert(AngularTriple(0.0f, curs, NoPixel)); - map.getPoint(curs).m_cumangle = 0.0f; + m_map.getPoint(curs).m_cumangle = 0.0f; while (search_list.size()) { std::set::iterator it = search_list.begin(); AngularTriple here = *it; @@ -87,16 +87,16 @@ bool VGAAngular::run(Communicator *comm, PointMap &map, bool) { if (m_radius != -1.0 && here.angle > m_radius) { break; } - Point &p = map.getPoint(here.pixel); + Point &p = m_map.getPoint(here.pixel); // nb, the filled check is necessary as diagonals seem to be stored with 'gaps' left in if (p.filled() && p.m_misc != ~0) { - p.getNode().extractAngular(search_list, &map, here); + p.getNode().extractAngular(search_list, &m_map, here); p.m_misc = ~0; if (!p.getMergePixel().empty()) { - Point &p2 = map.getPoint(p.getMergePixel()); + Point &p2 = m_map.getPoint(p.getMergePixel()); if (p2.m_misc != ~0) { p2.m_cumangle = p.m_cumangle; - p2.getNode().extractAngular(search_list, &map, + p2.getNode().extractAngular(search_list, &m_map, AngularTriple(here.angle, p.getMergePixel(), NoPixel)); p2.m_misc = ~0; } @@ -106,7 +106,7 @@ bool VGAAngular::run(Communicator *comm, PointMap &map, bool) { } } - AttributeRow &row = map.getAttributeTable().getRow(AttributeKey(curs)); + AttributeRow &row = m_map.getAttributeTable().getRow(AttributeKey(curs)); if (total_nodes > 0) { row.setValue(mean_depth_col, float(double(total_angle) / double(total_nodes))); } @@ -126,8 +126,8 @@ bool VGAAngular::run(Communicator *comm, PointMap &map, bool) { } } - map.setDisplayedAttribute(-2); - map.setDisplayedAttribute(mean_depth_col); + m_map.setDisplayedAttribute(-2); + m_map.setDisplayedAttribute(mean_depth_col); return true; } diff --git a/salalib/vgamodules/vgaangular.h b/modules/vga/core/vgaangular.h similarity index 81% rename from salalib/vgamodules/vgaangular.h rename to modules/vga/core/vgaangular.h index d4602264..41ed582d 100644 --- a/salalib/vgamodules/vgaangular.h +++ b/modules/vga/core/vgaangular.h @@ -18,17 +18,19 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" -class VGAAngular : IVGA { +class VGAAngular : public IAnalysis { private: + PointMap &m_map; double m_radius; bool m_gates_only; public: std::string getAnalysisName() const override { return "Angular Analysis"; } - bool run(Communicator *, PointMap &map, bool) override; - VGAAngular(double radius, bool gates_only) : m_radius(radius), m_gates_only(gates_only) {} + bool run(Communicator *) override; + VGAAngular(PointMap &map, double radius, bool gates_only) + : m_map(map), m_radius(radius), m_gates_only(gates_only) {} }; diff --git a/salalib/vgamodules/vgaangulardepth.cpp b/modules/vga/core/vgaangulardepth.cpp similarity index 71% rename from salalib/vgamodules/vgaangulardepth.cpp rename to modules/vga/core/vgaangulardepth.cpp index 3c6b1b60..775150f4 100644 --- a/salalib/vgamodules/vgaangulardepth.cpp +++ b/modules/vga/core/vgaangulardepth.cpp @@ -16,29 +16,29 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgaangulardepth.h" +#include "vgaangulardepth.h" #include "genlib/stringutils.h" -bool VGAAngularDepth::run(Communicator *, PointMap &map, bool) { +bool VGAAngularDepth::run(Communicator *) { - AttributeTable &attributes = map.getAttributeTable(); + AttributeTable &attributes = m_map.getAttributeTable(); // n.b., insert columns sets values to -1 if the column already exists int path_angle_col = attributes.insertOrResetColumn("Angular Step Depth"); for (auto iter = attributes.begin(); iter != attributes.end(); iter++) { PixelRef pix = iter->getKey().value; - map.getPoint(pix).m_misc = 0; - map.getPoint(pix).m_dist = 0.0f; - map.getPoint(pix).m_cumangle = -1.0f; + m_map.getPoint(pix).m_misc = 0; + m_map.getPoint(pix).m_dist = 0.0f; + m_map.getPoint(pix).m_cumangle = -1.0f; } std::set search_list; // contains root point - for (auto &sel : map.getSelSet()) { + for (auto &sel : m_map.getSelSet()) { search_list.insert(AngularTriple(0.0f, sel, NoPixel)); - map.getPoint(sel).m_cumangle = 0.0f; + m_map.getPoint(sel).m_cumangle = 0.0f; } // note that m_misc is used in a different manner to analyseGraph / PointDepth @@ -47,20 +47,20 @@ bool VGAAngularDepth::run(Communicator *, PointMap &map, bool) { std::set::iterator it = search_list.begin(); AngularTriple here = *it; search_list.erase(it); - Point &p = map.getPoint(here.pixel); + Point &p = m_map.getPoint(here.pixel); // nb, the filled check is necessary as diagonals seem to be stored with 'gaps' left in if (p.filled() && p.m_misc != ~0) { - p.getNode().extractAngular(search_list, &map, here); + p.getNode().extractAngular(search_list, &m_map, here); p.m_misc = ~0; - AttributeRow &row = map.getAttributeTable().getRow(AttributeKey(here.pixel)); + AttributeRow &row = m_map.getAttributeTable().getRow(AttributeKey(here.pixel)); row.setValue(path_angle_col, float(p.m_cumangle)); if (!p.getMergePixel().empty()) { - Point &p2 = map.getPoint(p.getMergePixel()); + Point &p2 = m_map.getPoint(p.getMergePixel()); if (p2.m_misc != ~0) { p2.m_cumangle = p.m_cumangle; - AttributeRow &mergePixelRow = map.getAttributeTable().getRow(AttributeKey(p.getMergePixel())); + AttributeRow &mergePixelRow = m_map.getAttributeTable().getRow(AttributeKey(p.getMergePixel())); mergePixelRow.setValue(path_angle_col, float(p2.m_cumangle)); - p2.getNode().extractAngular(search_list, &map, + p2.getNode().extractAngular(search_list, &m_map, AngularTriple(here.angle, p.getMergePixel(), NoPixel)); p2.m_misc = ~0; } @@ -68,8 +68,8 @@ bool VGAAngularDepth::run(Communicator *, PointMap &map, bool) { } } - map.setDisplayedAttribute(-2); - map.setDisplayedAttribute(path_angle_col); + m_map.setDisplayedAttribute(-2); + m_map.setDisplayedAttribute(path_angle_col); return true; } diff --git a/salalib/vgamodules/vgaangulardepth.h b/modules/vga/core/vgaangulardepth.h similarity index 83% rename from salalib/vgamodules/vgaangulardepth.h rename to modules/vga/core/vgaangulardepth.h index 9c9c24d2..7170b066 100644 --- a/salalib/vgamodules/vgaangulardepth.h +++ b/modules/vga/core/vgaangulardepth.h @@ -18,12 +18,16 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" -class VGAAngularDepth : IVGA { +class VGAAngularDepth : public IAnalysis { + private: + PointMap &m_map; + public: std::string getAnalysisName() const override { return "Angular Depth"; } - bool run(Communicator *comm, PointMap &map, bool) override; + bool run(Communicator *comm) override; + VGAAngularDepth(PointMap &map) : m_map(map) {} }; diff --git a/salalib/vgamodules/vgaisovist.cpp b/modules/vga/core/vgaisovist.cpp similarity index 77% rename from salalib/vgamodules/vgaisovist.cpp rename to modules/vga/core/vgaisovist.cpp index f568a696..8493c403 100644 --- a/salalib/vgamodules/vgaisovist.cpp +++ b/modules/vga/core/vgaisovist.cpp @@ -16,46 +16,47 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgaisovist.h" +#include "vgaisovist.h" #include "salalib/isovist.h" #include "genlib/stringutils.h" -bool VGAIsovist::run(Communicator *comm, PointMap &map, bool simple_version) { - map.m_hasIsovistAnalysis = false; +bool VGAIsovist::run(Communicator *comm) { + m_map.m_hasIsovistAnalysis = false; // note, BSP tree plays with comm counting... - if(comm) { + if (comm) { comm->CommPostMessage(Communicator::NUM_STEPS, 2); comm->CommPostMessage(Communicator::CURRENT_STEP, 1); } - BSPNode bspRoot = makeBSPtree(comm, map.getDrawingFiles()); + BSPNode bspRoot = makeBSPtree(comm, m_map.getDrawingFiles()); - AttributeTable &attributes = map.getAttributeTable(); + AttributeTable &attributes = m_map.getAttributeTable(); - if(comm) comm->CommPostMessage(Communicator::CURRENT_STEP, 2); + if (comm) + comm->CommPostMessage(Communicator::CURRENT_STEP, 2); time_t atime = 0; if (comm) { qtimer(atime, 0); - comm->CommPostMessage(Communicator::NUM_RECORDS, map.getFilledPointCount()); + comm->CommPostMessage(Communicator::NUM_RECORDS, m_map.getFilledPointCount()); } int count = 0; - for (size_t i = 0; i < map.getCols(); i++) { - for (size_t j = 0; j < map.getRows(); j++) { + for (size_t i = 0; i < m_map.getCols(); i++) { + for (size_t j = 0; j < m_map.getRows(); j++) { PixelRef curs = PixelRef(static_cast(i), static_cast(j)); - if (map.getPoint(curs).filled()) { + if (m_map.getPoint(curs).filled()) { count++; - if (map.getPoint(curs).contextfilled() && !curs.iseven()) { + if (m_map.getPoint(curs).contextfilled() && !curs.iseven()) { continue; } Isovist isovist; - isovist.makeit(&bspRoot, map.depixelate(curs), map.getRegion(), 0, 0); + isovist.makeit(&bspRoot, m_map.depixelate(curs), m_map.getRegion(), 0, 0); AttributeRow &row = attributes.getRow(AttributeKey(curs)); - isovist.setData(attributes, row, simple_version); - Node &node = map.getPoint(curs).getNode(); + isovist.setData(attributes, row, m_simple_version); + Node &node = m_map.getPoint(curs).getNode(); std::vector *occ = node.m_occlusion_bins; for (size_t k = 0; k < 32; k++) { occ[k].clear(); @@ -63,10 +64,10 @@ bool VGAIsovist::run(Communicator *comm, PointMap &map, bool simple_version) { } for (size_t k = 0; k < isovist.getOcclusionPoints().size(); k++) { const PointDist &pointdist = isovist.getOcclusionPoints().at(k); - int bin = whichbin(pointdist.m_point - map.depixelate(curs)); + int bin = whichbin(pointdist.m_point - m_map.depixelate(curs)); // only occlusion bins with a certain distance recorded (arbitrary scale note!) if (pointdist.m_dist > 1.5) { - PixelRef pix = map.pixelate(pointdist.m_point); + PixelRef pix = m_map.pixelate(pointdist.m_point); if (pix != curs) { occ[bin].push_back(pix); } @@ -84,12 +85,12 @@ bool VGAIsovist::run(Communicator *comm, PointMap &map, bool simple_version) { } } } - map.m_hasIsovistAnalysis = true; + m_map.m_hasIsovistAnalysis = true; return true; } -BSPNode VGAIsovist::makeBSPtree(Communicator *communicator, const std::vector& drawingFiles) { +BSPNode VGAIsovist::makeBSPtree(Communicator *communicator, const std::vector &drawingFiles) { std::vector partitionlines; for (const auto &pixelGroup : drawingFiles) { for (const auto &pixel : pixelGroup.m_spacePixels) { @@ -117,7 +118,7 @@ BSPNode VGAIsovist::makeBSPtree(Communicator *communicator, const std::vectorCommPostMessage(Communicator::NUM_RECORDS, static_cast(partitionlines.size())); qtimer(atime, 0); } diff --git a/salalib/vgamodules/vgaisovist.h b/modules/vga/core/vgaisovist.h similarity index 80% rename from salalib/vgamodules/vgaisovist.h rename to modules/vga/core/vgaisovist.h index 9454632e..ff3c44a6 100644 --- a/salalib/vgamodules/vgaisovist.h +++ b/modules/vga/core/vgaisovist.h @@ -18,13 +18,18 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" -class VGAIsovist : IVGA { +class VGAIsovist : public IAnalysis { + private: + PointMap &m_map; + bool m_simple_version; + public: std::string getAnalysisName() const override { return "Isovist Analysis"; } - bool run(Communicator *comm, PointMap &map, bool simple_version) override; + bool run(Communicator *comm) override; BSPNode makeBSPtree(Communicator *communicator, const std::vector &drawingFiles); + VGAIsovist(PointMap &map, bool simple_version) : m_map(map), m_simple_version(simple_version) {} }; diff --git a/salalib/vgamodules/vgametric.cpp b/modules/vga/core/vgametric.cpp similarity index 83% rename from salalib/vgamodules/vgametric.cpp rename to modules/vga/core/vgametric.cpp index 3fc22b33..dd3b1dca 100644 --- a/salalib/vgamodules/vgametric.cpp +++ b/modules/vga/core/vgametric.cpp @@ -16,31 +16,31 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgametric.h" +#include "vgametric.h" #include "genlib/stringutils.h" // This is a slow algorithm, but should give the correct answer // for demonstrative purposes -bool VGAMetric::run(Communicator *comm, PointMap &map, bool) { +bool VGAMetric::run(Communicator *comm) { time_t atime = 0; if (comm) { qtimer(atime, 0); - comm->CommPostMessage(Communicator::NUM_RECORDS, map.getFilledPointCount()); + comm->CommPostMessage(Communicator::NUM_RECORDS, m_map.getFilledPointCount()); } std::string radius_text; if (m_radius != -1.0) { if (m_radius > 100.0) { radius_text = std::string(" R") + dXstring::formatString(m_radius, "%.f"); - } else if (map.getRegion().width() < 1.0) { + } else if (m_map.getRegion().width() < 1.0) { radius_text = std::string(" R") + dXstring::formatString(m_radius, "%.4f"); } else { radius_text = std::string(" R") + dXstring::formatString(m_radius, "%.2f"); } } - AttributeTable &attributes = map.getAttributeTable(); + AttributeTable &attributes = m_map.getAttributeTable(); // n.b. these must be entered in alphabetical order to preserve col indexing: std::string mspa_col_text = std::string("Metric Mean Shortest-Path Angle") + radius_text; @@ -54,11 +54,11 @@ bool VGAMetric::run(Communicator *comm, PointMap &map, bool) { int count = 0; - for (size_t i = 0; i < map.getCols(); i++) { - for (size_t j = 0; j < map.getRows(); j++) { + for (size_t i = 0; i < m_map.getCols(); i++) { + for (size_t j = 0; j < m_map.getRows(); j++) { PixelRef curs = PixelRef(static_cast(i), static_cast(j)); - if (map.getPoint(curs).filled()) { + if (m_map.getPoint(curs).filled()) { if (m_gates_only) { count++; @@ -66,7 +66,7 @@ bool VGAMetric::run(Communicator *comm, PointMap &map, bool) { } // TODO: Break out miscs/dist/cumangle into local variables and remove from Point class - for (auto &point : map.getPoints()) { + for (auto &point : m_map.getPoints()) { point.m_misc = 0; point.m_dist = -1.0f; point.m_cumangle = 0.0f; @@ -86,26 +86,26 @@ bool VGAMetric::run(Communicator *comm, PointMap &map, bool) { std::set::iterator it = search_list.begin(); MetricTriple here = *it; search_list.erase(it); - if (m_radius != -1.0 && (here.dist * map.getSpacing()) > m_radius) { + if (m_radius != -1.0 && (here.dist * m_map.getSpacing()) > m_radius) { break; } - Point &p = map.getPoint(here.pixel); + Point &p = m_map.getPoint(here.pixel); // nb, the filled check is necessary as diagonals seem to be stored with 'gaps' left in if (p.filled() && p.m_misc != ~0) { - p.getNode().extractMetric(search_list, &map, here); + p.getNode().extractMetric(search_list, &m_map, here); p.m_misc = ~0; if (!p.getMergePixel().empty()) { - Point &p2 = map.getPoint(p.getMergePixel()); + Point &p2 = m_map.getPoint(p.getMergePixel()); if (p2.m_misc != ~0) { p2.m_cumangle = p.m_cumangle; - p2.getNode().extractMetric(search_list, &map, + p2.getNode().extractMetric(search_list, &m_map, MetricTriple(here.dist, p.getMergePixel(), NoPixel)); p2.m_misc = ~0; } } - total_depth += float(here.dist * map.getSpacing()); + total_depth += float(here.dist * m_map.getSpacing()); total_angle += p.m_cumangle; - euclid_depth += float(map.getSpacing() * dist(here.pixel, curs)); + euclid_depth += float(m_map.getSpacing() * dist(here.pixel, curs)); total_nodes += 1; } } @@ -129,8 +129,8 @@ bool VGAMetric::run(Communicator *comm, PointMap &map, bool) { } } - map.overrideDisplayedAttribute(-2); - map.setDisplayedAttribute(mspl_col); + m_map.overrideDisplayedAttribute(-2); + m_map.setDisplayedAttribute(mspl_col); return true; } diff --git a/salalib/vgamodules/vgametric.h b/modules/vga/core/vgametric.h similarity index 80% rename from salalib/vgamodules/vgametric.h rename to modules/vga/core/vgametric.h index d9e5a349..c133a279 100644 --- a/salalib/vgamodules/vgametric.h +++ b/modules/vga/core/vgametric.h @@ -18,17 +18,19 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" -class VGAMetric : IVGA { +class VGAMetric : public IAnalysis { private: + PointMap &m_map; double m_radius; bool m_gates_only; public: std::string getAnalysisName() const override { return "Metric Analysis"; } - bool run(Communicator *comm, PointMap &map, bool) override; - VGAMetric(double radius, bool gates_only) : m_radius(radius), m_gates_only(gates_only) {} + bool run(Communicator *comm) override; + VGAMetric(PointMap &map, double radius, bool gates_only) + : m_map(map), m_radius(radius), m_gates_only(gates_only) {} }; diff --git a/salalib/vgamodules/vgametricdepth.cpp b/modules/vga/core/vgametricdepth.cpp similarity index 66% rename from salalib/vgamodules/vgametricdepth.cpp rename to modules/vga/core/vgametricdepth.cpp index 68b31360..0deda945 100644 --- a/salalib/vgamodules/vgametricdepth.cpp +++ b/modules/vga/core/vgametricdepth.cpp @@ -16,34 +16,34 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgametricdepth.h" +#include "vgametricdepth.h" #include "genlib/stringutils.h" -bool VGAMetricDepth::run(Communicator *, PointMap &map, bool) { +bool VGAMetricDepth::run(Communicator *) { - AttributeTable &attributes = map.getAttributeTable(); + AttributeTable &attributes = m_map.getAttributeTable(); // n.b., insert columns sets values to -1 if the column already exists int path_angle_col = attributes.insertOrResetColumn("Metric Step Shortest-Path Angle"); int path_length_col = attributes.insertOrResetColumn("Metric Step Shortest-Path Length"); int dist_col = -1; - if (map.getSelSet().size() == 1) { + if (m_map.getSelSet().size() == 1) { // Note: Euclidean distance is currently only calculated from a single point dist_col = attributes.insertOrResetColumn("Metric Straight-Line Distance"); } for (auto iter = attributes.begin(); iter != attributes.end(); iter++) { PixelRef pix = iter->getKey().value; - map.getPoint(pix).m_misc = 0; - map.getPoint(pix).m_dist = -1.0f; - map.getPoint(pix).m_cumangle = 0.0f; + m_map.getPoint(pix).m_misc = 0; + m_map.getPoint(pix).m_dist = -1.0f; + m_map.getPoint(pix).m_cumangle = 0.0f; } // in order to calculate Penn angle, the MetricPair becomes a metric triple... std::set search_list; // contains root point - for (auto &sel : map.getSelSet()) { + for (auto &sel : m_map.getSelSet()) { search_list.insert(MetricTriple(0.0f, sel, NoPixel)); } @@ -53,40 +53,40 @@ bool VGAMetricDepth::run(Communicator *, PointMap &map, bool) { std::set::iterator it = search_list.begin(); MetricTriple here = *it; search_list.erase(it); - Point &p = map.getPoint(here.pixel); + Point &p = m_map.getPoint(here.pixel); // nb, the filled check is necessary as diagonals seem to be stored with 'gaps' left in if (p.filled() && p.m_misc != ~0) { - p.getNode().extractMetric(search_list, &map, here); + p.getNode().extractMetric(search_list, &m_map, here); p.m_misc = ~0; - AttributeRow &row = map.getAttributeTable().getRow(AttributeKey(here.pixel)); - row.setValue(path_length_col, float(map.getSpacing() * here.dist)); + AttributeRow &row = m_map.getAttributeTable().getRow(AttributeKey(here.pixel)); + row.setValue(path_length_col, float(m_map.getSpacing() * here.dist)); row.setValue(path_angle_col, float(p.m_cumangle)); - if (map.getSelSet().size() == 1) { + if (m_map.getSelSet().size() == 1) { // Note: Euclidean distance is currently only calculated from a single point - row.setValue(dist_col, float(map.getSpacing() * dist(here.pixel, *map.getSelSet().begin()))); + row.setValue(dist_col, float(m_map.getSpacing() * dist(here.pixel, *m_map.getSelSet().begin()))); } if (!p.getMergePixel().empty()) { - Point &p2 = map.getPoint(p.getMergePixel()); + Point &p2 = m_map.getPoint(p.getMergePixel()); if (p2.m_misc != ~0) { p2.m_cumangle = p.m_cumangle; - AttributeRow &mergePixelRow = - map.getAttributeTable().getRow(AttributeKey(p.getMergePixel())); - mergePixelRow.setValue(path_length_col, float(map.getSpacing() * here.dist)); + AttributeRow &mergePixelRow = m_map.getAttributeTable().getRow(AttributeKey(p.getMergePixel())); + mergePixelRow.setValue(path_length_col, float(m_map.getSpacing() * here.dist)); mergePixelRow.setValue(path_angle_col, float(p2.m_cumangle)); - if (map.getSelSet().size() == 1) { + if (m_map.getSelSet().size() == 1) { // Note: Euclidean distance is currently only calculated from a single point mergePixelRow.setValue( - dist_col, float(map.getSpacing() * dist(p.getMergePixel(), *map.getSelSet().begin()))); + dist_col, float(m_map.getSpacing() * dist(p.getMergePixel(), *m_map.getSelSet().begin()))); } - p2.getNode().extractMetric(search_list, &map, MetricTriple(here.dist, p.getMergePixel(), NoPixel)); + p2.getNode().extractMetric(search_list, &m_map, + MetricTriple(here.dist, p.getMergePixel(), NoPixel)); p2.m_misc = ~0; } } } } - map.setDisplayedAttribute(-2); - map.setDisplayedAttribute(path_length_col); + m_map.setDisplayedAttribute(-2); + m_map.setDisplayedAttribute(path_length_col); return true; } diff --git a/salalib/vgamodules/vgametricdepth.h b/modules/vga/core/vgametricdepth.h similarity index 84% rename from salalib/vgamodules/vgametricdepth.h rename to modules/vga/core/vgametricdepth.h index 00bec86f..0bf58025 100644 --- a/salalib/vgamodules/vgametricdepth.h +++ b/modules/vga/core/vgametricdepth.h @@ -18,12 +18,16 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" -class VGAMetricDepth : IVGA { +class VGAMetricDepth : public IAnalysis { + private: + PointMap &m_map; + public: std::string getAnalysisName() const override { return "Metric Depth"; } - bool run(Communicator *, PointMap &map, bool) override; + bool run(Communicator *) override; + VGAMetricDepth(PointMap &map) : m_map(map) {} }; diff --git a/salalib/vgamodules/vgathroughvision.cpp b/modules/vga/core/vgathroughvision.cpp similarity index 76% rename from salalib/vgamodules/vgathroughvision.cpp rename to modules/vga/core/vgathroughvision.cpp index 42ff110f..05f8fd26 100644 --- a/salalib/vgamodules/vgathroughvision.cpp +++ b/modules/vga/core/vgathroughvision.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgathroughvision.h" +#include "vgathroughvision.h" #include "salalib/agents/agenthelpers.h" #include "genlib/stringutils.h" @@ -24,39 +24,39 @@ // This is a slow algorithm, but should give the correct answer // for demonstrative purposes -bool VGAThroughVision::run(Communicator *comm, PointMap &map, bool) { +bool VGAThroughVision::run(Communicator *comm) { time_t atime = 0; if (comm) { qtimer(atime, 0); - comm->CommPostMessage(Communicator::NUM_RECORDS, map.getFilledPointCount()); + comm->CommPostMessage(Communicator::NUM_RECORDS, m_map.getFilledPointCount()); } - AttributeTable &attributes = map.getAttributeTable(); + AttributeTable &attributes = m_map.getAttributeTable(); // current version (not sure of differences!) - for (size_t i = 0; i < map.getCols(); i++) { - for (size_t j = 0; j < map.getRows(); j++) { + for (size_t i = 0; i < m_map.getCols(); i++) { + for (size_t j = 0; j < m_map.getRows(); j++) { PixelRef curs = PixelRef(static_cast(i), static_cast(j)); - map.getPoint(curs).m_misc = 0; + m_map.getPoint(curs).m_misc = 0; } } - bool hasGateColumn = map.getAttributeTable().hasColumn(g_col_gate); + bool hasGateColumn = m_map.getAttributeTable().hasColumn(g_col_gate); int count = 0; - for (size_t i = 0; i < map.getCols(); i++) { - for (size_t j = 0; j < map.getRows(); j++) { + for (size_t i = 0; i < m_map.getCols(); i++) { + for (size_t j = 0; j < m_map.getRows(); j++) { std::vector seengates; PixelRef curs = PixelRef(static_cast(i), static_cast(j)); - Point &p = map.getPoint(curs); - if (map.getPoint(curs).filled()) { + Point &p = m_map.getPoint(curs); + if (m_map.getPoint(curs).filled()) { p.getNode().first(); while (!p.getNode().is_tail()) { PixelRef x = p.getNode().cursor(); - PixelRefVector pixels = map.quickPixelateLine(x, curs); + PixelRefVector pixels = m_map.quickPixelateLine(x, curs); for (size_t k = 1; k < pixels.size() - 1; k++) { PixelRef key = pixels[k]; - map.getPoint(key).m_misc += 1; + m_map.getPoint(key).m_misc += 1; // TODO: Undocumented functionality. Shows how many times a gate is passed? if (hasGateColumn) { @@ -93,12 +93,12 @@ bool VGAThroughVision::run(Communicator *comm, PointMap &map, bool) { for (auto iter = attributes.begin(); iter != attributes.end(); iter++) { PixelRef pix = iter->getKey().value; - iter->getRow().setValue(col, static_cast(map.getPoint(pix).m_misc)); - map.getPoint(pix).m_misc = 0; + iter->getRow().setValue(col, static_cast(m_map.getPoint(pix).m_misc)); + m_map.getPoint(pix).m_misc = 0; } - map.overrideDisplayedAttribute(-2); - map.setDisplayedAttribute(col); + m_map.overrideDisplayedAttribute(-2); + m_map.setDisplayedAttribute(col); return true; } diff --git a/salalib/vgamodules/vgathroughvision.h b/modules/vga/core/vgathroughvision.h similarity index 83% rename from salalib/vgamodules/vgathroughvision.h rename to modules/vga/core/vgathroughvision.h index 5b101f44..86b550d3 100644 --- a/salalib/vgamodules/vgathroughvision.h +++ b/modules/vga/core/vgathroughvision.h @@ -18,12 +18,16 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" -class VGAThroughVision : IVGA { +class VGAThroughVision : public IAnalysis { + private: + PointMap &m_map; + public: std::string getAnalysisName() const override { return "Through Vision Analysis"; } - bool run(Communicator *comm, PointMap &map, bool) override; + bool run(Communicator *comm) override; + VGAThroughVision(PointMap &map) : m_map(map) {} }; diff --git a/salalib/vgamodules/vgavisualglobal.cpp b/modules/vga/core/vgavisualglobal.cpp similarity index 84% rename from salalib/vgamodules/vgavisualglobal.cpp rename to modules/vga/core/vgavisualglobal.cpp index ed29f4dd..79a7e479 100644 --- a/salalib/vgamodules/vgavisualglobal.cpp +++ b/modules/vga/core/vgavisualglobal.cpp @@ -16,17 +16,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgavisualglobal.h" +#include "vgavisualglobal.h" #include "genlib/stringutils.h" -bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version) { +bool VGAVisualGlobal::run(Communicator *comm) { time_t atime = 0; if (comm) { qtimer(atime, 0); - comm->CommPostMessage(Communicator::NUM_RECORDS, map.getFilledPointCount()); + comm->CommPostMessage(Communicator::NUM_RECORDS, m_map.getFilledPointCount()); } - AttributeTable &attributes = map.getAttributeTable(); + AttributeTable &attributes = m_map.getAttributeTable(); int entropy_col = -1, rel_entropy_col = -1, integ_dv_col = -1, integ_pv_col = -1, integ_tk_col = -1, depth_col = -1, count_col = -1; @@ -38,7 +38,7 @@ bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version // n.b. these must be entered in alphabetical order to preserve col indexing: // dX simple version test // TV #ifndef _COMPILE_dX_SIMPLE_VERSION - if (!simple_version) { + if (!m_simple_version) { std::string entropy_col_text = std::string("Visual Entropy") + radius_text; entropy_col = attributes.insertOrResetColumn(entropy_col_text.c_str()); } @@ -48,7 +48,7 @@ bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version integ_dv_col = attributes.insertOrResetColumn(integ_dv_col_text.c_str()); #ifndef _COMPILE_dX_SIMPLE_VERSION - if (!simple_version) { + if (!m_simple_version) { std::string integ_pv_col_text = std::string("Visual Integration [P-value]") + radius_text; integ_pv_col = attributes.insertOrResetColumn(integ_pv_col_text.c_str()); std::string integ_tk_col_text = std::string("Visual Integration [Tekl]") + radius_text; @@ -64,21 +64,21 @@ bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version int count = 0; - depthmapX::RowMatrix miscs(map.getRows(), map.getCols()); - depthmapX::RowMatrix extents(map.getRows(), map.getCols()); + depthmapX::RowMatrix miscs(m_map.getRows(), m_map.getCols()); + depthmapX::RowMatrix extents(m_map.getRows(), m_map.getCols()); - for (size_t i = 0; i < map.getCols(); i++) { - for (size_t j = 0; j < map.getRows(); j++) { + for (size_t i = 0; i < m_map.getCols(); i++) { + for (size_t j = 0; j < m_map.getRows(); j++) { PixelRef curs = PixelRef(i, j); - if (map.getPoint(curs).filled()) { + if (m_map.getPoint(curs).filled()) { - if ((map.getPoint(curs).contextfilled() && !curs.iseven()) || (m_gates_only)) { + if ((m_map.getPoint(curs).contextfilled() && !curs.iseven()) || (m_gates_only)) { count++; continue; } - for (size_t ii = 0; ii < map.getCols(); ii++) { - for (size_t jj = 0; jj < map.getRows(); jj++) { + for (size_t ii = 0; ii < m_map.getCols(); ii++) { + for (size_t jj = 0; jj < m_map.getRows(); jj++) { miscs(jj, ii) = 0; extents(jj, ii) = PixelRef(ii, jj); } @@ -100,20 +100,19 @@ bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version for (auto currLvlIter = searchTreeAtLevel.rbegin(); currLvlIter != searchTreeAtLevel.rend(); currLvlIter++) { int &pmisc = miscs(currLvlIter->y, currLvlIter->x); - Point &p = map.getPoint(*currLvlIter); + Point &p = m_map.getPoint(*currLvlIter); if (p.filled() && pmisc != ~0) { total_depth += level; total_nodes += 1; distribution.back() += 1; if ((int)m_radius == -1 || - (level < (int)m_radius && - (!p.contextfilled() || currLvlIter->iseven()))) { + (level < (int)m_radius && (!p.contextfilled() || currLvlIter->iseven()))) { extractUnseen(p.getNode(), search_tree[level + 1], miscs, extents); pmisc = ~0; if (!p.getMergePixel().empty()) { PixelRef mergePixel = p.getMergePixel(); int &p2misc = miscs(mergePixel.y, mergePixel.x); - Point &p2 = map.getPoint(mergePixel); + Point &p2 = m_map.getPoint(mergePixel); if (p2misc != ~0) { extractUnseen(p2.getNode(), search_tree[level + 1], miscs, extents); // did say p.misc @@ -131,13 +130,13 @@ bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version AttributeRow &row = attributes.getRow(AttributeKey(curs)); // only set to single float precision after divide // note -- total_nodes includes this one -- mean depth as per p.108 Social Logic of Space - if (!simple_version) { + if (!m_simple_version) { row.setValue(count_col, float(total_nodes)); // note: total nodes includes this one } // ERROR !!!!!! if (total_nodes > 1) { double mean_depth = double(total_depth) / double(total_nodes - 1); - if (!simple_version) { + if (!m_simple_version) { row.setValue(depth_col, float(mean_depth)); } // total nodes > 2 to avoid divide by 0 (was > 3) @@ -148,21 +147,21 @@ bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version double rra_p = ra / pvalue(total_nodes); double integ_tk = teklinteg(total_nodes, total_depth); row.setValue(integ_dv_col, float(1.0 / rra_d)); - if (!simple_version) { + if (!m_simple_version) { row.setValue(integ_pv_col, float(1.0 / rra_p)); } if (total_depth - total_nodes + 1 > 1) { - if (!simple_version) { + if (!m_simple_version) { row.setValue(integ_tk_col, float(integ_tk)); } } else { - if (!simple_version) { + if (!m_simple_version) { row.setValue(integ_tk_col, -1.0f); } } } else { row.setValue(integ_dv_col, (float)-1); - if (!simple_version) { + if (!m_simple_version) { row.setValue(integ_pv_col, (float)-1); row.setValue(integ_tk_col, (float)-1); } @@ -180,12 +179,12 @@ bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version rel_entropy += (float)prob * log2(prob / q); } } - if (!simple_version) { + if (!m_simple_version) { row.setValue(entropy_col, float(entropy)); row.setValue(rel_entropy_col, float(rel_entropy)); } } else { - if (!simple_version) { + if (!m_simple_version) { row.setValue(depth_col, (float)-1); row.setValue(entropy_col, (float)-1); row.setValue(rel_entropy_col, (float)-1); @@ -203,14 +202,14 @@ bool VGAVisualGlobal::run(Communicator *comm, PointMap &map, bool simple_version } } } - for (size_t i = 0; i < map.getCols(); i++) { - for (size_t j = 0; j < map.getRows(); j++) { + for (size_t i = 0; i < m_map.getCols(); i++) { + for (size_t j = 0; j < m_map.getRows(); j++) { PixelRef curs = PixelRef(static_cast(i), static_cast(j)); - map.getPoint(curs).m_misc = miscs(j, i); - map.getPoint(curs).m_extent = extents(j, i); + m_map.getPoint(curs).m_misc = miscs(j, i); + m_map.getPoint(curs).m_extent = extents(j, i); } } - map.setDisplayedAttribute(integ_dv_col); + m_map.setDisplayedAttribute(integ_dv_col); return true; } diff --git a/salalib/vgamodules/vgavisualglobal.h b/modules/vga/core/vgavisualglobal.h similarity index 78% rename from salalib/vgamodules/vgavisualglobal.h rename to modules/vga/core/vgavisualglobal.h index 7f6e89dc..9b56998d 100644 --- a/salalib/vgamodules/vgavisualglobal.h +++ b/modules/vga/core/vgavisualglobal.h @@ -18,21 +18,24 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" #include "genlib/simplematrix.h" -class VGAVisualGlobal : IVGA { +class VGAVisualGlobal : public IAnalysis { private: + PointMap &m_map; double m_radius; bool m_gates_only; + bool m_simple_version; public: std::string getAnalysisName() const override { return "Global Visibility Analysis"; } - bool run(Communicator *comm, PointMap &map, bool simple_version) override; + bool run(Communicator *comm) override; void extractUnseen(Node &node, PixelRefVector &pixels, depthmapX::RowMatrix &miscs, depthmapX::RowMatrix &extents); - VGAVisualGlobal(double radius, bool gates_only) : m_radius(radius), m_gates_only(gates_only) {} + VGAVisualGlobal(PointMap &map, double radius, bool gates_only, bool simple_version) + : m_map(map), m_radius(radius), m_gates_only(gates_only), m_simple_version(simple_version) {} }; diff --git a/salalib/vgamodules/vgavisualglobaldepth.cpp b/modules/vga/core/vgavisualglobaldepth.cpp similarity index 84% rename from salalib/vgamodules/vgavisualglobaldepth.cpp rename to modules/vga/core/vgavisualglobaldepth.cpp index 88bb865c..636d9678 100644 --- a/salalib/vgamodules/vgavisualglobaldepth.cpp +++ b/modules/vga/core/vgavisualglobaldepth.cpp @@ -16,26 +16,26 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgavisualglobaldepth.h" +#include "vgavisualglobaldepth.h" #include "genlib/stringutils.h" -bool VGAVisualGlobalDepth::run(Communicator *, PointMap &map, bool) { +bool VGAVisualGlobalDepth::run(Communicator *) { - AttributeTable &attributes = map.getAttributeTable(); + AttributeTable &attributes = m_map.getAttributeTable(); // n.b., insert columns sets values to -1 if the column already exists int col = attributes.insertOrResetColumn("Visual Step Depth"); for (auto iter = attributes.begin(); iter != attributes.end(); iter++) { PixelRef pix = iter->getKey().value; - map.getPoint(pix).m_misc = 0; - map.getPoint(pix).m_extent = pix; + m_map.getPoint(pix).m_misc = 0; + m_map.getPoint(pix).m_extent = pix; } std::vector search_tree; search_tree.push_back(PixelRefVector()); - for (auto &sel : map.getSelSet()) { + for (auto &sel : m_map.getSelSet()) { // need to convert from ints (m_selection_set) to pixelrefs for this op: search_tree.back().push_back(sel); } @@ -43,21 +43,21 @@ bool VGAVisualGlobalDepth::run(Communicator *, PointMap &map, bool) { size_t level = 0; while (search_tree[level].size()) { search_tree.push_back(PixelRefVector()); - const PixelRefVector& searchTreeAtLevel = search_tree[level]; + const PixelRefVector &searchTreeAtLevel = search_tree[level]; for (auto currLvlIter = searchTreeAtLevel.rbegin(); currLvlIter != searchTreeAtLevel.rend(); currLvlIter++) { - Point &p = map.getPoint(*currLvlIter); + Point &p = m_map.getPoint(*currLvlIter); if (p.filled() && p.m_misc != ~0) { AttributeRow &row = attributes.getRow(AttributeKey(*currLvlIter)); row.setValue(col, float(level)); if (!p.contextfilled() || currLvlIter->iseven() || level == 0) { - p.getNode().extractUnseen(search_tree[level + 1], &map); + p.getNode().extractUnseen(search_tree[level + 1], &m_map); p.m_misc = ~0; if (!p.getMergePixel().empty()) { - Point &p2 = map.getPoint(p.getMergePixel()); + Point &p2 = m_map.getPoint(p.getMergePixel()); if (p2.m_misc != ~0) { AttributeRow &mergePixelRow = attributes.getRow(AttributeKey(p.getMergePixel())); mergePixelRow.setValue(col, float(level)); - p2.getNode().extractUnseen(search_tree[level + 1], &map); // did say p.misc + p2.getNode().extractUnseen(search_tree[level + 1], &m_map); // did say p.misc p2.m_misc = ~0; } } @@ -70,14 +70,14 @@ bool VGAVisualGlobalDepth::run(Communicator *, PointMap &map, bool) { } // force redisplay: - map.setDisplayedAttribute(-2); - map.setDisplayedAttribute(col); + m_map.setDisplayedAttribute(-2); + m_map.setDisplayedAttribute(col); return true; } void VGAVisualGlobalDepth::extractUnseen(Node &node, PixelRefVector &pixels, depthmapX::RowMatrix &miscs, - depthmapX::RowMatrix &extents) { + depthmapX::RowMatrix &extents) { for (int i = 0; i < 32; i++) { Bin &bin = node.bin(i); for (auto pixVec : bin.m_pixel_vecs) { diff --git a/salalib/vgamodules/vgavisualglobaldepth.h b/modules/vga/core/vgavisualglobaldepth.h similarity index 85% rename from salalib/vgamodules/vgavisualglobaldepth.h rename to modules/vga/core/vgavisualglobaldepth.h index 53926ce9..64719ede 100644 --- a/salalib/vgamodules/vgavisualglobaldepth.h +++ b/modules/vga/core/vgavisualglobaldepth.h @@ -18,16 +18,20 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" #include "genlib/simplematrix.h" -class VGAVisualGlobalDepth : IVGA { +class VGAVisualGlobalDepth : public IAnalysis { + private: + PointMap &m_map; + public: std::string getAnalysisName() const override { return "Global Visibility Depth"; } - bool run(Communicator *comm, PointMap &map, bool simple_version) override; + bool run(Communicator *comm) override; void extractUnseen(Node &node, PixelRefVector &pixels, depthmapX::RowMatrix &miscs, depthmapX::RowMatrix &extents); + VGAVisualGlobalDepth(PointMap &map) : m_map(map) {} }; diff --git a/salalib/vgamodules/vgavisuallocal.cpp b/modules/vga/core/vgavisuallocal.cpp similarity index 78% rename from salalib/vgamodules/vgavisuallocal.cpp rename to modules/vga/core/vgavisuallocal.cpp index c167c4d3..e463a299 100644 --- a/salalib/vgamodules/vgavisuallocal.cpp +++ b/modules/vga/core/vgavisuallocal.cpp @@ -16,40 +16,40 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "salalib/vgamodules/vgavisuallocal.h" +#include "vgavisuallocal.h" #include "genlib/stringutils.h" -bool VGAVisualLocal::run(Communicator *comm, PointMap &map, bool simple_version) { +bool VGAVisualLocal::run(Communicator *comm) { time_t atime = 0; if (comm) { qtimer(atime, 0); - comm->CommPostMessage(Communicator::NUM_RECORDS, map.getFilledPointCount()); + comm->CommPostMessage(Communicator::NUM_RECORDS, m_map.getFilledPointCount()); } int cluster_col = -1, control_col = -1, controllability_col = -1; - if (!simple_version) { - cluster_col = map.getAttributeTable().insertOrResetColumn("Visual Clustering Coefficient"); - control_col = map.getAttributeTable().insertOrResetColumn("Visual Control"); - controllability_col = map.getAttributeTable().insertOrResetColumn("Visual Controllability"); + if (!m_simple_version) { + cluster_col = m_map.getAttributeTable().insertOrResetColumn("Visual Clustering Coefficient"); + control_col = m_map.getAttributeTable().insertOrResetColumn("Visual Control"); + controllability_col = m_map.getAttributeTable().insertOrResetColumn("Visual Controllability"); } int count = 0; - for (size_t i = 0; i < map.getCols(); i++) { - for (size_t j = 0; j < map.getRows(); j++) { + for (size_t i = 0; i < m_map.getCols(); i++) { + for (size_t j = 0; j < m_map.getRows(); j++) { PixelRef curs = PixelRef(static_cast(i), static_cast(j)); - if (map.getPoint(curs).filled()) { - if ((map.getPoint(curs).contextfilled() && !curs.iseven()) || (m_gates_only)) { + if (m_map.getPoint(curs).filled()) { + if ((m_map.getPoint(curs).contextfilled() && !curs.iseven()) || (m_gates_only)) { count++; continue; } - AttributeRow &row = map.getAttributeTable().getRow(AttributeKey(curs)); + AttributeRow &row = m_map.getAttributeTable().getRow(AttributeKey(curs)); // This is much easier to do with a straight forward list: PixelRefVector neighbourhood; PixelRefVector totalneighbourhood; - map.getPoint(curs).getNode().contents(neighbourhood); + m_map.getPoint(curs).getNode().contents(neighbourhood); // only required to match previous non-stl output. Without this // the output differs by the last digit of the float @@ -60,7 +60,7 @@ bool VGAVisualLocal::run(Communicator *comm, PointMap &map, bool simple_version) for (size_t i = 0; i < neighbourhood.size(); i++) { int intersect_size = 0, retro_size = 0; - Point &retpt = map.getPoint(neighbourhood[i]); + Point &retpt = m_map.getPoint(neighbourhood[i]); if (retpt.filled() && retpt.hasNode()) { retpt.getNode().first(); while (!retpt.getNode().is_tail()) { @@ -81,7 +81,7 @@ bool VGAVisualLocal::run(Communicator *comm, PointMap &map, bool simple_version) } } #ifndef _COMPILE_dX_SIMPLE_VERSION - if (!simple_version) { + if (!m_simple_version) { if (neighbourhood.size() > 1) { row.setValue(cluster_col, float(cluster / double(neighbourhood.size() * (neighbourhood.size() - 1.0)))); @@ -109,8 +109,8 @@ bool VGAVisualLocal::run(Communicator *comm, PointMap &map, bool simple_version) } #ifndef _COMPILE_dX_SIMPLE_VERSION - if (!simple_version) - map.setDisplayedAttribute(cluster_col); + if (!m_simple_version) + m_map.setDisplayedAttribute(cluster_col); #endif return true; diff --git a/salalib/vgamodules/vgavisuallocal.h b/modules/vga/core/vgavisuallocal.h similarity index 77% rename from salalib/vgamodules/vgavisuallocal.h rename to modules/vga/core/vgavisuallocal.h index ddd6e565..f932e7e3 100644 --- a/salalib/vgamodules/vgavisuallocal.h +++ b/modules/vga/core/vgavisuallocal.h @@ -18,16 +18,19 @@ #pragma once -#include "salalib/ivga.h" +#include "salalib/ianalysis.h" #include "salalib/pixelref.h" #include "salalib/pointdata.h" -class VGAVisualLocal : IVGA { +class VGAVisualLocal : public IAnalysis { private: + PointMap &m_map; bool m_gates_only; + bool m_simple_version; public: std::string getAnalysisName() const override { return "Local Visibility Analysis"; } - bool run(Communicator *comm, PointMap &map, bool simple_version) override; - VGAVisualLocal(bool gates_only) : m_gates_only(gates_only) {} + bool run(Communicator *comm) override; + VGAVisualLocal(PointMap &map, bool gates_only, bool simple_version) + : m_map(map), m_gates_only(gates_only), m_simple_version(simple_version) {} }; diff --git a/modules/vga/coreTest/CMakeLists.txt b/modules/vga/coreTest/CMakeLists.txt new file mode 100644 index 00000000..2971be1f --- /dev/null +++ b/modules/vga/coreTest/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (C) 2020 Petros Koutsolampros + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(vgacoretest vgacoretest) +set(vgacoretest_SRCS + vgacoretest.cpp) + +set(modules_coreTest "${modules_coreTest}" "vgacoretest" CACHE INTERNAL "modules_coreTest" FORCE) + +add_compile_definitions(VGA_CORE_TEST_LIBRARY) + +add_library(${vgacoretest} OBJECT ${vgacoretest_SRCS}) diff --git a/modules/vga/coreTest/vgacoretest.cpp b/modules/vga/coreTest/vgacoretest.cpp new file mode 100644 index 00000000..bec86a6d --- /dev/null +++ b/modules/vga/coreTest/vgacoretest.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2020 Petros Koutsolampros + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "catch.hpp" + +TEST_CASE("Dummy VGA Core test", "") {} diff --git a/modules/vga/gui/CMakeLists.txt b/modules/vga/gui/CMakeLists.txt new file mode 100644 index 00000000..4f77ec76 --- /dev/null +++ b/modules/vga/gui/CMakeLists.txt @@ -0,0 +1,42 @@ +# Copyright (C) 2020 Petros Koutsolampros + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(vgagui vgagui) + +set(CMAKE_AUTOUIC_SEARCH_PATHS UI "../../../depthmapX/UI") +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) + +set(vgagui_SRCS + uictrigger.cpp + vgamainwindow.cpp + vgaoptionsdlg.cpp) +set(modules_gui "${modules_gui}" "vgagui" CACHE INTERNAL "modules_gui" FORCE) + +find_package(Qt5 COMPONENTS Core Widgets Gui OpenGL REQUIRED) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${Qt5Core_INCLUDE_DIRS}) +include_directories(${Qt5Widgets_INCLUDE_DIRS}) +include_directories(${Qt5Gui_INCLUDE_DIRS}) + +add_definitions(${Qt5Core_DEFINITIONS}) +add_definitions(${Qt5Widgets_DEFINITIONS}) +add_definitions(${Qt5Gui_DEFINITIONS}) + +add_compile_definitions(VGA_GUI_LIBRARY) + +add_library(${vgagui} OBJECT ${vgagui_SRCS}) diff --git a/depthmapX/UI/OptionsDlg.ui b/modules/vga/gui/UI/vgaoptionsdlg.ui similarity index 94% rename from depthmapX/UI/OptionsDlg.ui rename to modules/vga/gui/UI/vgaoptionsdlg.ui index d45dc812..ddc01861 100644 --- a/depthmapX/UI/OptionsDlg.ui +++ b/modules/vga/gui/UI/vgaoptionsdlg.ui @@ -1,7 +1,7 @@ - COptionsDlg - + VGAOptionsDlg + 0 @@ -145,7 +145,7 @@ c_output_type clicked(bool) - COptionsDlg + VGAOptionsDlg OnOutputType(bool) @@ -161,7 +161,7 @@ c_radio1 clicked(bool) - COptionsDlg + VGAOptionsDlg OnOutputType(bool) @@ -177,7 +177,7 @@ c_radio2 clicked(bool) - COptionsDlg + VGAOptionsDlg OnOutputType(bool) @@ -193,7 +193,7 @@ c_radio3 clicked(bool) - COptionsDlg + VGAOptionsDlg OnOutputType(bool) @@ -209,7 +209,7 @@ c_radio4 clicked(bool) - COptionsDlg + VGAOptionsDlg OnOutputType(bool) @@ -225,7 +225,7 @@ c_radius textChanged(QString) - COptionsDlg + VGAOptionsDlg OnUpdateRadius(QString) @@ -241,7 +241,7 @@ c_radius2 textChanged(QString) - COptionsDlg + VGAOptionsDlg OnUpdateRadius2(QString) @@ -257,7 +257,7 @@ c_ok clicked() - COptionsDlg + VGAOptionsDlg OnOK() @@ -273,7 +273,7 @@ c_cancel clicked() - COptionsDlg + VGAOptionsDlg OnCancel() @@ -294,4 +294,4 @@ OnOK() OnCancel() - + \ No newline at end of file diff --git a/modules/vga/gui/uictrigger.cpp b/modules/vga/gui/uictrigger.cpp new file mode 100644 index 00000000..3d79019a --- /dev/null +++ b/modules/vga/gui/uictrigger.cpp @@ -0,0 +1,5 @@ +// This file is required to trigger cmake's AUTOUIC in the depthmapX directory +// if it is not included then the ui_*.h files in that directory are not generated +// and then not found by the module which is built first because it is a dependency +// of depthmapX. +#include "depthmapX/ui_ColourScaleDlg.h" diff --git a/modules/vga/gui/vgamainwindow.cpp b/modules/vga/gui/vgamainwindow.cpp new file mode 100644 index 00000000..7ac295f8 --- /dev/null +++ b/modules/vga/gui/vgamainwindow.cpp @@ -0,0 +1,209 @@ +// Copyright (C) 2020 Petros Koutsolampros + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "vgamainwindow.h" + +#include "modules/vga/core/vgaangular.h" +#include "modules/vga/core/vgaangulardepth.h" +#include "modules/vga/core/vgaisovist.h" +#include "modules/vga/core/vgametric.h" +#include "modules/vga/core/vgametricdepth.h" +#include "modules/vga/core/vgathroughvision.h" +#include "modules/vga/core/vgavisualglobal.h" +#include "modules/vga/core/vgavisualglobaldepth.h" +#include "modules/vga/core/vgavisuallocal.h" + +#include "vgaoptionsdlg.h" + +#include "depthmapX/mainwindowhelpers.h" + +#include +#include + +bool VGAMainWindow::createMenus(MainWindow *mainWindow) { + QMenu *toolsMenu = MainWindowHelpers::getOrAddRootMenu(mainWindow, tr("&Tools")); + QMenu *visibilitySubMenu = MainWindowHelpers::getOrAddMenu(toolsMenu, tr("&Visibility")); + connect(visibilitySubMenu, &QMenu::aboutToShow, this, + [this, mainWindow] { OnAboutToShowVisibilityMenu(mainWindow); }); + + m_vgaAct = new QAction(tr("&Run Visibility Graph Analysis..."), mainWindow); + m_vgaAct->setStatusTip(tr("Angular distance from current selection\nAngular Depth")); + connect(m_vgaAct, &QAction::triggered, this, [this, mainWindow] { OnVGA(mainWindow); }); + visibilitySubMenu->addAction(m_vgaAct); + + QMenu *stepMenu = MainWindowHelpers::getOrAddMenu(visibilitySubMenu, tr("Step &Depth")); + connect(stepMenu, &QMenu::aboutToShow, this, [this, mainWindow] { OnAboutToShowStepDepthMenu(mainWindow); }); + + m_angularStepAct = new QAction(tr("&Angular Step"), mainWindow); + m_angularStepAct->setStatusTip(tr("Angular distance from current selection\nAngular Depth")); + connect(m_angularStepAct, &QAction::triggered, this, + [this, mainWindow] { OnVGAStep(mainWindow, StepType::ANGULAR); }); + stepMenu->addAction(m_angularStepAct); + + m_metricStepAct = new QAction(tr("&Metric Step"), mainWindow); + m_metricStepAct->setStatusTip(tr("Distance from current selection\nMetric Depth")); + connect(m_metricStepAct, &QAction::triggered, this, + [this, mainWindow] { OnVGAStep(mainWindow, StepType::METRIC); }); + stepMenu->addAction(m_metricStepAct); + + m_visualStepAct = new QAction(tr("&Visibility Step"), mainWindow); + m_visualStepAct->setStatusTip(tr("Step depth from current selection\nStep Depth")); + connect(m_visualStepAct, &QAction::triggered, this, + [this, mainWindow] { OnVGAStep(mainWindow, StepType::VISUAL); }); + stepMenu->addAction(m_visualStepAct); + + return true; +} + +void VGAMainWindow::OnVGA(MainWindow *mainWindow) { + QGraphDoc *graphDoc = mainWindow->activeMapDoc(); + if (graphDoc == nullptr) + return; + + if (graphDoc->m_communicator) { + QMessageBox::warning(mainWindow, tr("Warning"), tr("Please wait, another process is running"), QMessageBox::Ok, + QMessageBox::Ok); + return; + } + if (graphDoc->m_meta_graph->getDisplayedMapType() != ShapeMap::POINTMAP) { + QMessageBox::warning(mainWindow, tr("Warning"), tr("Please make sure the displayed map is a pointmap"), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + + VGAOptionsDlg dlg; + + dlg.m_layer_names.push_back(""); + for (auto &dataMap : graphDoc->m_meta_graph->getDataMaps()) { + dlg.m_layer_names.push_back(dataMap.getName()); + } + + if (QDialog::Accepted != dlg.exec()) { + return; + } + + graphDoc->m_communicator = new CMSCommunicator(); + + if (dlg.m_output_type == Options::OUTPUT_ISOVIST) { + + graphDoc->m_communicator->setAnalysis(std::unique_ptr( + new VGAIsovist(graphDoc->m_meta_graph->getDisplayedPointMap(), graphDoc->m_communicator->simple_version))); + } else if (dlg.m_output_type == Options::OUTPUT_VISUAL) { + if (dlg.m_local) { + + graphDoc->m_communicator->setAnalysis(std::unique_ptr( + new VGAVisualLocal(graphDoc->m_meta_graph->getDisplayedPointMap(), dlg.m_gates_only, + graphDoc->m_communicator->simple_version))); + } + if (dlg.m_global) { + graphDoc->m_communicator->setAnalysis(std::unique_ptr( + new VGAVisualGlobal(graphDoc->m_meta_graph->getDisplayedPointMap(), dlg.m_numericRadius, + dlg.m_gates_only, graphDoc->m_communicator->simple_version))); + } + } else if (dlg.m_output_type == Options::OUTPUT_METRIC) { + graphDoc->m_communicator->setAnalysis(std::unique_ptr( + new VGAMetric(graphDoc->m_meta_graph->getDisplayedPointMap(), dlg.m_numericRadius, dlg.m_gates_only))); + } else if (dlg.m_output_type == Options::OUTPUT_ANGULAR) { + graphDoc->m_communicator->setAnalysis(std::unique_ptr( + new VGAAngular(graphDoc->m_meta_graph->getDisplayedPointMap(), dlg.m_numericRadius, dlg.m_gates_only))); + + } else if (dlg.m_output_type == Options::OUTPUT_THRU_VISION) { + graphDoc->m_communicator->setAnalysis( + std::unique_ptr(new VGAThroughVision(graphDoc->m_meta_graph->getDisplayedPointMap()))); + } + + graphDoc->m_communicator->SetFunction(CMSCommunicator::FROMCONNECTOR); + graphDoc->m_communicator->setSuccessUpdateFlags(QGraphDoc::NEW_DATA); + graphDoc->m_communicator->setSuccessRedrawFlags(QGraphDoc::VIEW_ALL, QGraphDoc::REDRAW_POINTS, + QGraphDoc::NEW_DATA); + + graphDoc->CreateWaitDialog(tr("Analysing graph...")); + graphDoc->m_thread.render(graphDoc); +} + +void VGAMainWindow::OnVGAStep(MainWindow *mainWindow, StepType stepType) { + QGraphDoc *graphDoc = mainWindow->activeMapDoc(); + if (graphDoc == nullptr) + return; + + if (graphDoc->m_communicator) { + QMessageBox::warning(mainWindow, tr("Warning"), tr("Please wait, another process is running"), QMessageBox::Ok, + QMessageBox::Ok); + return; + } + if (graphDoc->m_meta_graph->getDisplayedMapType() != ShapeMap::POINTMAP) { + QMessageBox::warning(mainWindow, tr("Warning"), tr("Please make sure the displayed map is a pointmap"), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + + graphDoc->m_communicator = new CMSCommunicator(); + switch (stepType) { + case StepType::ANGULAR: + graphDoc->m_communicator->setAnalysis( + std::unique_ptr(new VGAAngularDepth(graphDoc->m_meta_graph->getDisplayedPointMap()))); + break; + case StepType::METRIC: + graphDoc->m_communicator->setAnalysis( + std::unique_ptr(new VGAMetricDepth(graphDoc->m_meta_graph->getDisplayedPointMap()))); + break; + case StepType::VISUAL: + graphDoc->m_communicator->setAnalysis( + std::unique_ptr(new VGAVisualGlobalDepth(graphDoc->m_meta_graph->getDisplayedPointMap()))); + break; + } + graphDoc->m_communicator->SetFunction(CMSCommunicator::FROMCONNECTOR); + graphDoc->m_communicator->setSuccessUpdateFlags(QGraphDoc::NEW_DATA); + graphDoc->m_communicator->setSuccessRedrawFlags(QGraphDoc::VIEW_ALL, QGraphDoc::REDRAW_POINTS, + QGraphDoc::NEW_DATA); + + graphDoc->CreateWaitDialog(tr("Calculating step...")); + graphDoc->m_thread.render(graphDoc); +} + +void VGAMainWindow::OnAboutToShowVisibilityMenu(MainWindow *mainWindow) { + + QGraphDoc *graphDoc = mainWindow->activeMapDoc(); + if (!graphDoc) { + m_vgaAct->setEnabled(false); + return; + } + + if (graphDoc->m_meta_graph->viewingProcessedPoints()) { + m_vgaAct->setEnabled(true); + } else { + m_vgaAct->setEnabled(false); + } +} + +void VGAMainWindow::OnAboutToShowStepDepthMenu(MainWindow *mainWindow) { + QGraphDoc *graphDoc = mainWindow->activeMapDoc(); + if (!graphDoc) { + m_visualStepAct->setEnabled(false); + m_metricStepAct->setEnabled(false); + m_angularStepAct->setEnabled(false); + return; + } + + if (graphDoc->m_meta_graph->viewingProcessedPoints() && graphDoc->m_meta_graph->isSelected()) { + m_visualStepAct->setEnabled(true); + m_metricStepAct->setEnabled(true); + m_angularStepAct->setEnabled(true); + } else { + m_visualStepAct->setEnabled(false); + m_metricStepAct->setEnabled(false); + m_angularStepAct->setEnabled(false); + } +} diff --git a/modules/vga/gui/vgamainwindow.h b/modules/vga/gui/vgamainwindow.h new file mode 100644 index 00000000..7d941db3 --- /dev/null +++ b/modules/vga/gui/vgamainwindow.h @@ -0,0 +1,38 @@ +// Copyright (C) 2020 Petros Koutsolampros + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#pragma once + +#include "depthmapX/imainwindowmodule.h" + +class VGAMainWindow : public IMainWindowModule { + + private: + enum StepType { ANGULAR, METRIC, VISUAL }; + QAction *m_vgaAct; + QAction *m_angularStepAct; + QAction *m_metricStepAct; + QAction *m_visualStepAct; + + private slots: + void OnVGA(MainWindow *mainWindow); + void OnVGAStep(MainWindow *mainWindow, StepType stepType); + void OnAboutToShowVisibilityMenu(MainWindow *mainWindow); + void OnAboutToShowStepDepthMenu(MainWindow *mainWindow); + + public: + VGAMainWindow() : IMainWindowModule() {} + bool createMenus(MainWindow *mainWindow); +}; diff --git a/modules/vga/gui/vgaoptionsdlg.cpp b/modules/vga/gui/vgaoptionsdlg.cpp new file mode 100644 index 00000000..ac220cd9 --- /dev/null +++ b/modules/vga/gui/vgaoptionsdlg.cpp @@ -0,0 +1,199 @@ +// Copyright (C) 2011-2012, Tasos Varoudis + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "vgaoptionsdlg.h" +#include + +VGAOptionsDlg::VGAOptionsDlg(QWidget *parent, Options existingOptions) : QDialog(parent) { + setupUi(this); + m_global = false; + m_local = false; + m_radius = tr(""); + m_gates_only = false; + m_output_type = -1; + m_radius2 = tr(""); + + m_output_type = existingOptions.output_type; + + m_local = existingOptions.local; + m_global = existingOptions.global; + m_gates_only = existingOptions.gates_only; + m_gatelayer = existingOptions.gatelayer; + + if ((int)existingOptions.radius == -1) { + m_radius = QString("n"); + m_radius2 = QString("n"); + } else if (m_output_type == Options::OUTPUT_VISUAL) { + char number[2]; + sprintf(number, "%d", (int)existingOptions.radius); + m_radius = QString(number); + m_radius2 = tr("n"); + } else { + char number[32]; + sprintf(number, "%g", existingOptions.radius); + m_radius = tr("n"); + m_radius2 = QString(number); + } +} + +void VGAOptionsDlg::OnOutputType(bool value) { + UpdateData(true); + + if (m_output_type == Options::OUTPUT_VISUAL) { + c_local->setEnabled(true); + c_global->setEnabled(true); + c_radius->setEnabled(true); + } else { + c_local->setEnabled(false); + c_global->setEnabled(false); + c_radius->setEnabled(false); + c_radius->setText(tr("n")); // <- essentially, undo changes + } + + if (m_output_type == Options::OUTPUT_METRIC) { + c_radius2->setEnabled(true); + } else { + c_radius2->setText(tr("n")); // <- essentially, undo changes + c_radius2->setEnabled(false); + } +} + +void VGAOptionsDlg::OnUpdateRadius(QString text) { + if (text.length()) { + if (!text.toInt() && text != tr("n")) { + QMessageBox::warning(this, tr("Warning"), tr("The radius must either be n or number in range 1-99"), + QMessageBox::Ok, QMessageBox::Ok); + c_radius->setText(tr("n")); + } + } +} + +void VGAOptionsDlg::OnUpdateRadius2(QString text) { + if (text.length()) { + if (text.toDouble() == 0.0 && text != tr("n")) { + QMessageBox::warning(this, tr("Warning"), tr("The radius must either be n or a positive number"), + QMessageBox::Ok, QMessageBox::Ok); + c_radius2->setText(tr("n")); + } + } +} + +void VGAOptionsDlg::OnOK() { + UpdateData(true); + + m_gatelayer = c_layer_selector->currentIndex() - 1; + + if (m_output_type == Options::OUTPUT_VISUAL) { + if (m_radius.compare(tr("n")) == 0) { // 0 means identical + m_numericRadius = -1.0; + } else { + m_numericRadius = (double)m_radius.toInt(); + if (m_numericRadius <= 0.0) { + QMessageBox::warning(this, tr("Warning"), + tr("The radius must either be n or a number in the range 1-99"), QMessageBox::Ok, + QMessageBox::Ok); + return; + } + } + } else { + if (m_radius2.compare(tr("n")) == 0) { // 0 means identical + m_numericRadius = -1.0; + } else { + m_numericRadius = m_radius2.toDouble(); + if (m_numericRadius <= 0.0) { + QMessageBox::warning(this, tr("Warning"), tr("The radius must either be n or a positive number"), + QMessageBox::Ok, QMessageBox::Ok); + return; + } + } + } + accept(); +} + +void VGAOptionsDlg::OnCancel() { reject(); } + +void VGAOptionsDlg::UpdateData(bool value) { + if (value) { + if (c_global->checkState()) + m_global = true; + else + m_global = false; + + if (c_local->checkState()) + m_local = true; + else + m_local = false; + + m_radius = c_radius->text(); + + if (c_output_type->isChecked()) + m_output_type = 0; + else if (c_radio1->isChecked()) + m_output_type = 1; + else if (c_radio2->isChecked()) + m_output_type = 2; + else if (c_radio3->isChecked()) + m_output_type = 3; + else if (c_radio4->isChecked()) + m_output_type = 4; + else + m_output_type = -1; + m_radius2 = c_radius2->text(); + } else { + if (m_global) + c_global->setCheckState(Qt::Checked); + else + c_global->setCheckState(Qt::Unchecked); + + if (m_local) + c_local->setCheckState(Qt::Checked); + else + c_local->setCheckState(Qt::Unchecked); + + c_radius->setText(m_radius); + + switch (m_output_type) { + case 0: + c_output_type->setChecked(true); + break; + case 1: + c_radio1->setChecked(true); + break; + case 2: + c_radio2->setChecked(true); + break; + case 3: + c_radio3->setChecked(true); + break; + case 4: + c_radio4->setChecked(true); + break; + default: + break; + } + c_radius2->setText(m_radius2); + } +} + +void VGAOptionsDlg::showEvent(QShowEvent *event) { + for (size_t i = 0; i < m_layer_names.size(); i++) { + c_layer_selector->addItem(QString(m_layer_names[i].c_str())); + } + c_layer_selector->setCurrentIndex(m_gatelayer + 1); + + OnOutputType(false); + + UpdateData(false); +} diff --git a/depthmapX/dialogs/OptionsDlg.h b/modules/vga/gui/vgaoptionsdlg.h similarity index 56% rename from depthmapX/dialogs/OptionsDlg.h rename to modules/vga/gui/vgaoptionsdlg.h index 5e794902..252b0ec9 100644 --- a/depthmapX/dialogs/OptionsDlg.h +++ b/modules/vga/gui/vgaoptionsdlg.h @@ -13,31 +13,32 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#include "ui_OptionsDlg.h" +#include "ui_vgaoptionsdlg.h" +#include #include #include -#include -class COptionsDlg : public QDialog, public Ui::COptionsDlg -{ - Q_OBJECT -public: - COptionsDlg(QWidget *parent = 0); - bool m_global; - bool m_local; - QString m_radius; - bool m_gates_only; - int m_output_type; - QString m_radius2; - void UpdateData(bool value); - void showEvent(QShowEvent * event); +class VGAOptionsDlg : public QDialog, public Ui::VGAOptionsDlg { + Q_OBJECT + public: + VGAOptionsDlg(QWidget *parent = 0, Options existingOptions = Options()); + bool m_global; + bool m_local; + QString m_radius; + float m_numericRadius; + bool m_gates_only; + int m_gatelayer; + int m_output_type; + QString m_radius2; + void UpdateData(bool value); + void showEvent(QShowEvent *event); std::vector m_layer_names; - private slots: - void OnOutputType(bool); - void OnUpdateRadius(QString); - void OnUpdateRadius2(QString); - void OnOK(); - void OnCancel(); + private slots: + void OnOutputType(bool); + void OnUpdateRadius(QString); + void OnUpdateRadius2(QString); + void OnOK(); + void OnCancel(); }; diff --git a/salalib/CMakeLists.txt b/salalib/CMakeLists.txt index c4c435a7..a85b0ddb 100644 --- a/salalib/CMakeLists.txt +++ b/salalib/CMakeLists.txt @@ -32,9 +32,8 @@ set(salalib_SRCS add_compile_definitions(_DEPTHMAP SALALIB_LIBRARY) -add_library(${salalib} STATIC ${salalib_SRCS} ${vgamodules_SRCS} ${axialmodules_SRCS} ${segmmodules_SRCS} ${parsers_SRCS}) +add_library(${salalib} STATIC ${salalib_SRCS} ${axialmodules_SRCS} ${segmmodules_SRCS} ${parsers_SRCS}) -add_subdirectory(vgamodules) add_subdirectory(axialmodules) add_subdirectory(segmmodules) add_subdirectory(parsers) diff --git a/salalib/mgraph.cpp b/salalib/mgraph.cpp index c79a3e32..ed1a9f6f 100644 --- a/salalib/mgraph.cpp +++ b/salalib/mgraph.cpp @@ -37,15 +37,6 @@ #include "salalib/segmmodules/segmtopologicalpd.h" #include "salalib/axialmodules/axialintegration.h" #include "salalib/axialmodules/axialstepdepth.h" -#include "salalib/vgamodules/vgaisovist.h" -#include "salalib/vgamodules/vgavisualglobal.h" -#include "salalib/vgamodules/vgavisualglobaldepth.h" -#include "salalib/vgamodules/vgavisuallocal.h" -#include "salalib/vgamodules/vgametric.h" -#include "salalib/vgamodules/vgametricdepth.h" -#include "salalib/vgamodules/vgaangular.h" -#include "salalib/vgamodules/vgaangulardepth.h" -#include "salalib/vgamodules/vgathroughvision.h" #include "salalib/agents/agenthelpers.h" #include "mgraph440/mgraph.h" @@ -310,10 +301,7 @@ bool MetaGraph::analyseGraph( Communicator *communicator, Options options , bool try { analysisCompleted = true; if (options.point_depth_selection == 1) { - if (m_view_class & VIEWVGA) { - analysisCompleted = VGAVisualGlobalDepth().run(communicator, getDisplayedPointMap(), false); - } - else if (m_view_class & VIEWAXIAL) { + if (m_view_class & VIEWAXIAL) { if (!getDisplayedShapeGraph().isSegmentMap()) { analysisCompleted = AxialStepDepth().run(communicator, getDisplayedShapeGraph(), false); } @@ -325,16 +313,10 @@ bool MetaGraph::analyseGraph( Communicator *communicator, Options options , bool // Graph::calculate_point_depth_matrix( communicator ); } else if (options.point_depth_selection == 2) { - if (m_view_class & VIEWVGA) { - analysisCompleted = VGAMetricDepth().run(communicator, getDisplayedPointMap(), false); - } - else if (m_view_class & VIEWAXIAL && getDisplayedShapeGraph().isSegmentMap()) { + if (m_view_class & VIEWAXIAL && getDisplayedShapeGraph().isSegmentMap()) { analysisCompleted = SegmentMetricPD().run(communicator, getDisplayedShapeGraph(), false); } } - else if (options.point_depth_selection == 3) { - analysisCompleted = VGAAngularDepth().run(communicator, getDisplayedPointMap(), false); - } else if (options.point_depth_selection == 4) { if (m_view_class & VIEWVGA) { getDisplayedPointMap().binDisplay( communicator ); @@ -343,29 +325,6 @@ bool MetaGraph::analyseGraph( Communicator *communicator, Options options , bool analysisCompleted = SegmentTopologicalPD().run(communicator, getDisplayedShapeGraph(), false); } } - else if (options.output_type == Options::OUTPUT_ISOVIST) { - analysisCompleted = VGAIsovist().run(communicator, getDisplayedPointMap(), simple_version); - } - else if (options.output_type == Options::OUTPUT_VISUAL) { - bool localResult = true; - bool globalResult = true; - if (options.local) { - localResult = VGAVisualLocal(options.gates_only).run(communicator, getDisplayedPointMap(), simple_version); - } - if (options.global) { - globalResult = VGAVisualGlobal(options.radius, options.gates_only).run(communicator, getDisplayedPointMap(), simple_version); - } - analysisCompleted = globalResult & localResult; - } - else if (options.output_type == Options::OUTPUT_METRIC) { - analysisCompleted = VGAMetric(options.radius, options.gates_only).run(communicator, getDisplayedPointMap(), simple_version); - } - else if (options.output_type == Options::OUTPUT_ANGULAR) { - analysisCompleted = VGAAngular(options.radius, options.gates_only).run(communicator, getDisplayedPointMap(), simple_version); - } - else if (options.output_type == Options::OUTPUT_THRU_VISION) { - analysisCompleted = VGAThroughVision().run(communicator, getDisplayedPointMap(), simple_version); - } } catch (Communicator::CancelledException) { analysisCompleted = false; @@ -2128,12 +2087,12 @@ bool MetaGraph::analyseThruVision(Communicator *comm, int gatelayer) -1,colgates,PUSH_FUNC_TOT); } - try { - analysisCompleted = VGAThroughVision().run(comm, getDisplayedPointMap(), false); - } - catch (Communicator::CancelledException) { +// try { +// analysisCompleted = VGAThroughVision().run(comm, getDisplayedPointMap(), false); +// } +// catch (Communicator::CancelledException) { analysisCompleted = false; - } +// } // note after the analysis, the column order might have changed... retrieve: colgates = table.getColumnIndex(g_col_gate); diff --git a/salalib/pointdata.cpp b/salalib/pointdata.cpp index d3545fc9..3c2b2e0e 100644 --- a/salalib/pointdata.cpp +++ b/salalib/pointdata.cpp @@ -21,8 +21,6 @@ #include "salalib/pointdata.h" #include "salalib/parsers/mapinfodata.h" // for mapinfo interface -#include "salalib/vgamodules/vgavisuallocal.h" -#include "salalib/vgamodules/vgavisualglobal.h" #include "salalib/isovist.h" #include "salalib/mgraph.h" // Metagraphs are used... #include "salalib/ngraph.h"