Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vga parallel #400

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions depthmapX/mainwindowmoduleregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#include "mainwindowmoduleregistry.hpp"
#include "modules/segmentshortestpaths/gui/segmentpathsmainwindow.h"
#include "modules/vgaparallel/gui/vgaparallelmainwindow.h"

void MainWindowModuleRegistry::populateModules() {
// Register any main window modules here
REGISTER_MAIN_WINDOW_MODULE(SegmentPathsMainWindow);
REGISTER_MAIN_WINDOW_MODULE(VGAParallelMainWindow)
// *********
}
2 changes: 2 additions & 0 deletions depthmapXcli/modeparserregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "stepdepthparser.h"
#include "mapconvertparser.h"
#include "modules/segmentshortestpaths/cli/segmentshortestpathparser.h"
#include "modules/vgaparallel/cli/vgaparallelparser.h"


void ModeParserRegistry::populateParsers()
Expand All @@ -43,5 +44,6 @@ void ModeParserRegistry::populateParsers()
REGISTER_PARSER(StepDepthParser);
REGISTER_PARSER(MapConvertParser);
REGISTER_PARSER(SegmentShortestPathParser);
REGISTER_PARSER(VgaParallelParser)
// *********
}
1 change: 1 addition & 0 deletions depthmapXcli/runmethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Point2f;

namespace dm_runmethods{
std::unique_ptr<MetaGraph> loadGraph(const std::string& filename, IPerformanceSink &perfWriter);
std::unique_ptr<Communicator> getCommunicator(const CommandLineParser &clp);
void importFiles(const CommandLineParser &cmdP, const ImportParser &parser, IPerformanceSink &perfWriter);
void linkGraph(const CommandLineParser &cmdP, const LinkParser &parser, IPerformanceSink &perfWriter );
void runVga(const CommandLineParser &cmdP, const VgaParser &vgaP, const IRadiusConverter &converter, IPerformanceSink &perfWriter );
Expand Down
34 changes: 34 additions & 0 deletions modules/vgaparallel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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()
14 changes: 14 additions & 0 deletions modules/vgaparallel/RegressionTest/regressionconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"rundir": "rundir",
"basebinlocation": "../../BaselineBinaries",
"testbinlocation": "../../../build",
"testcases": {
"shortest_segment_metric_path": [{
"infile": "../../../testdata/barnsbury_extended1_segment.graph",
"outfile": "out.graph",
"mode": "VGAPARALLEL",
"extraArgs": {
}
}]
}
}
24 changes: 24 additions & 0 deletions modules/vgaparallel/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

set(vgaparallelcli vgaparallelcli)
set(vgaparallelcli_SRCS
vgaparallelparser.cpp)

set(modules_cli "${modules_cli}" "vgaparallelcli" CACHE INTERNAL "modules_cli" FORCE)

add_compile_definitions(VGAPARALLEL_CLI_LIBRARY)

add_library(${vgaparallelcli} OBJECT ${vgaparallelcli_SRCS})
118 changes: 118 additions & 0 deletions modules/vgaparallel/cli/vgaparallelparser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// 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 <http://www.gnu.org/licenses/>.

#include "vgaparallelparser.h"
#include "depthmapXcli/exceptions.h"
#include "depthmapXcli/parsingutils.h"
#include "depthmapXcli/runmethods.h"
#include "depthmapXcli/simpletimer.h"
#include "modules/vgaparallel/core/vgaangularopenmp.h"
#include "modules/vgaparallel/core/vgametricopenmp.h"
#include "modules/vgaparallel/core/vgavisualglobalopenmp.h"
#include "modules/vgaparallel/core/vgavisuallocaladjmatrix.h"
#include "modules/vgaparallel/core/vgavisuallocalopenmp.h"
#include "salalib/options.h"
#include <cstring>
#include <iostream>

using namespace depthmapX;

VgaParallelParser::VgaParallelParser() : m_vgaMode(VgaMode::NONE) {}

void VgaParallelParser::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], "visiblity-global") == 0) {
m_vgaMode = VgaMode::VISBILITY_GLOBAL;
} else if (std::strcmp(argv[i], "visibility-local") == 0) {
m_vgaMode = VgaMode::VISBILITY_LOCAL;
} else if (std::strcmp(argv[i], "visibility-local-adjmatrix") == 0) {
m_vgaMode = VgaMode::VISBILITY_LOCAL_ADJMATRIX;
} 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 {
throw CommandLineException(std::string("Invalid VGAPARALLEL mode: ") + argv[i]);
}
} else if (std::strcmp(argv[i], "-vr") == 0) {
ENFORCE_ARGUMENT("-vr", i)
m_radius = argv[i];
}
++i;
}

if (m_vgaMode == VgaMode::VISBILITY_GLOBAL) {
if (m_radius.empty()) {
throw CommandLineException(
"Global measures in VGA/visibility analysis require a radius, use -vr <radius>");
}
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 <radius>");
}
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);
}
}
}

void VgaParallelParser::run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const {

auto mgraph = dm_runmethods::loadGraph(clp.getFileName().c_str(), perfWriter);

std::unique_ptr<IAnalysis> analysis = nullptr;

RadiusConverter radiusConverter;
switch (getVgaMode()) {
case VgaMode::VISBILITY_GLOBAL:
analysis = std::unique_ptr<IAnalysis>(new VGAVisualGlobalOpenMP(
mgraph->getDisplayedPointMap(), radiusConverter.ConvertForVisibility(getRadius()), false));
break;
case VgaMode::VISBILITY_LOCAL:
analysis = std::unique_ptr<IAnalysis>(new VGAVisualLocalOpenMP(mgraph->getDisplayedPointMap()));
break;
case VgaMode::VISBILITY_LOCAL_ADJMATRIX:
analysis = std::unique_ptr<IAnalysis>(new VGAVisualLocalAdjMatrix(mgraph->getDisplayedPointMap(), false));
break;
case VgaMode::METRIC:
analysis = std::unique_ptr<IAnalysis>(
new VGAMetricOpenMP(mgraph->getDisplayedPointMap(), radiusConverter.ConvertForMetric(getRadius()), false));
break;
case VgaMode::ANGULAR:
analysis = std::unique_ptr<IAnalysis>(new VGAAngularOpenMP(
mgraph->getDisplayedPointMap(), radiusConverter.ConvertForMetric(getRadius()), false));
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;
}
52 changes: 52 additions & 0 deletions modules/vgaparallel/cli/vgaparallelparser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 <http://www.gnu.org/licenses/>.

#pragma once

#include "depthmapXcli/commandlineparser.h"
#include "depthmapXcli/imodeparser.h"
#include "depthmapXcli/radiusconverter.h"
#include <string>

class VgaParallelParser : public IModeParser {
public:
virtual std::string getModeName() const { return "VGA"; }

virtual std::string getHelp() const {
return "Mode options for VGAPARALLEL:\n"
"-vm <vga mode> one of visiblity-global (default algorithm)"
" visibility-local (default algorithm)"
" visibility-local-adjmatrix (alternative algorithm)"
" metric (default algorithm)"
" angular (default algorithm)\n"
"-vr <radius> radius between 1 and 99 or n, to limit visibility\n";
}

public:
VgaParallelParser();
virtual void parse(int argc, char *argv[]);
virtual void run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const;

enum VgaMode { NONE, VISBILITY_GLOBAL, VISBILITY_LOCAL, VISBILITY_LOCAL_ADJMATRIX, METRIC, ANGULAR };

// vga options
VgaMode getVgaMode() const { return m_vgaMode; }
const std::string &getRadius() const { return m_radius; }

private:
// vga options
VgaMode m_vgaMode;
std::string m_radius;
};
24 changes: 24 additions & 0 deletions modules/vgaparallel/cliTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

set(vgaparallelclitest vgaparallelclitest)
set(vgaparallelclitest_SRCS
vgaparallelparsertest.cpp)

set(modules_cliTest "${modules_cliTest}" "vgaparallelclitest" CACHE INTERNAL "modules_cliTest" FORCE)

add_compile_definitions(VGAPARALLEL_CLI_TEST_LIBRARY)

add_library(${vgaparallelclitest} OBJECT ${vgaparallelclitest_SRCS})
83 changes: 83 additions & 0 deletions modules/vgaparallel/cliTest/vgaparallelparsertest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 <http://www.gnu.org/licenses/>.

#include "modules/vgaparallel/cli/vgaparallelparser.h"
#include "cliTest/argumentholder.h"
#include "cliTest/selfcleaningfile.h"
#include <catch.hpp>

TEST_CASE("VgaParallelParser", "Error cases") {
SECTION("Missing argument to -vr") {
VgaParallelParser parser;
ArgumentHolder ah{
"prog",
"-vr",
};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-vr requires an argument"));
}

SECTION("Missing argument to -vm") {
VgaParallelParser parser;
ArgumentHolder ah{"prog", "-vm"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("-vm requires an argument"));
}

SECTION("rubbish input to -vm") {
VgaParallelParser parser;
ArgumentHolder ah{"prog", "-vm", "foo"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()), Catch::Contains("Invalid VGAPARALLEL mode: foo"));
}

SECTION("no input to -vr in metric analysis") {
VgaParallelParser parser;
ArgumentHolder ah{"prog", "-vm", "metric"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()),
Catch::Contains("Metric vga requires a radius, use -vr <radius>"));
}

SECTION("rubbish input to -vr in metric analysis") {
VgaParallelParser parser;
ArgumentHolder ah{"prog", "-vm", "metric", "-vr", "foo"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()),
Catch::Contains("Radius must be a positive integer number or n, got foo"));
}

SECTION("no input to -vr in visual global analysis") {
VgaParallelParser parser;
ArgumentHolder ah{"prog", "-vm", "visiblity-global"};
REQUIRE_THROWS_WITH(
parser.parse(ah.argc(), ah.argv()),
Catch::Contains("Global measures in VGA/visibility analysis require a radius, use -vr <radius>"));
}

SECTION("rubbish input to -vr in visual global analysis") {
VgaParallelParser parser;
ArgumentHolder ah{"prog", "-vm", "visiblity-global", "-vr", "foo"};
REQUIRE_THROWS_WITH(parser.parse(ah.argc(), ah.argv()),
Catch::Contains("Radius must be a positive integer number or n, got foo"));
}
}

TEST_CASE("Successful VgaParallelParser", "Read successfully") {
VgaParallelParser parser;

SECTION("Read from commandline") {
ArgumentHolder ah{"prog", "-vm", "metric", "-vr", "5"};
parser.parse(ah.argc(), ah.argv());
}

REQUIRE(parser.getVgaMode() == VgaParallelParser::VgaMode::METRIC);
REQUIRE(parser.getRadius() == "5");
}
Loading