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 shortest paths #397

Draft
wants to merge 4 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/vgapaths/gui/vgapathsmainwindow.h"

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


void ModeParserRegistry::populateParsers()
Expand All @@ -43,5 +45,7 @@ void ModeParserRegistry::populateParsers()
REGISTER_PARSER(StepDepthParser);
REGISTER_PARSER(MapConvertParser);
REGISTER_PARSER(SegmentShortestPathParser);
REGISTER_PARSER(ShortestPathParser);
REGISTER_PARSER(IsovistZoneParser);
// *********
}
34 changes: 34 additions & 0 deletions modules/vgapaths/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()
37 changes: 37 additions & 0 deletions modules/vgapaths/RegressionTest/regressionconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"rundir": "rundir",
"basebinlocation": "../../BaselineBinaries",
"testbinlocation": "../../../build",
"testcases": {
"vga_shortest_metric_path": [{
"infile": "../../../testdata/gallery_connected.graph",
"outfile": "out.graph",
"mode": "VGASHORTESTPATH",
"extraArgs": {
"-spo":"0.8,7.7",
"-spd":"5,5.4",
"-spt":"metric"
}
}],
"vga_shortest_angular_path": [{
"infile": "../../../testdata/gallery_connected.graph",
"outfile": "out.graph",
"mode": "VGASHORTESTPATH",
"extraArgs": {
"-spo":"0.8,7.7",
"-spd":"5,5.4",
"-spt":"angular"
}
}],
"vga_shortest_visual_path": [{
"infile": "../../../testdata/gallery_connected.graph",
"outfile": "out.graph",
"mode": "VGASHORTESTPATH",
"extraArgs": {
"-spo":"0.8,7.7",
"-spd":"5,5.4",
"-spt":"visual"
}
}]
}
}
25 changes: 25 additions & 0 deletions modules/vgapaths/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

set(vgapathscli vgapathscli)
set(vgapathscli_SRCS
shortestpathparser.cpp
isovistzoneparser.cpp)

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

add_compile_definitions(VGAPATHS_CLI_LIBRARY)

add_library(${vgapathscli} OBJECT ${vgapathscli_SRCS})
117 changes: 117 additions & 0 deletions modules/vgapaths/cli/isovistzoneparser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (C) 2019 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 "isovistzoneparser.h"
#include "depthmapXcli/exceptions.h"
#include "depthmapXcli/parsingutils.h"
#include "depthmapXcli/runmethods.h"
#include "depthmapXcli/simpletimer.h"
#include "modules/vgapaths/core/vgaisovistzone.h"
#include "salalib/entityparsing.h"
#include <cstring>
#include <sstream>

using namespace depthmapX;

void IsovistZoneParser::parse(int argc, char **argv) {

std::vector<std::string> origins;
std::string originsFile;
for (int i = 1; i < argc; ++i) {
if (std::strcmp("-izo", argv[i]) == 0) {
ENFORCE_ARGUMENT("-izo", i)
if (!has_only_digits_dots_commas(argv[i])) {
std::stringstream message;
message << "Invalid origin point provided (" << argv[i]
<< "). Should only contain digits dots and commas" << std::flush;
throw CommandLineException(message.str().c_str());
}
origins.push_back(argv[i]);
} else if (std::strcmp("-izr", argv[i]) == 0) {
ENFORCE_ARGUMENT("-izr", i)
if (!has_only_digits_dots_commas(argv[i])) {
std::stringstream message;
message << "Invalid restriction distance provided (" << argv[i]
<< "). Should only contain digits dots and commas" << std::flush;
throw CommandLineException(message.str().c_str());
}
m_restrictDistance = std::stof(argv[i]);
} else if (std::strcmp("-izf", argv[i]) == 0) {
ENFORCE_ARGUMENT("-izf", i)
originsFile = argv[i];
} else if (std::strcmp("-izn", argv[i]) == 0) {
ENFORCE_ARGUMENT("-izn", i)
m_originSets.push_back(argv[i]);
}
}

if (!originsFile.empty()) {
std::ifstream file(originsFile);
if (!file.good()) {
std::stringstream message;
message << "Failed to find file " << originsFile;
throw depthmapX::CommandLineException(message.str());
}
auto pointSets = EntityParsing::parsePointSets(file, ',');
m_originSets = pointSets.first;
m_origins = pointSets.second;
} else if (origins.empty()) {
throw CommandLineException("At least one origin point (-izo) or a file (-izf) must be provided");
} else if (m_originSets.size() > 0 & origins.size() != m_originSets.size()) {
throw CommandLineException("Origin sets must either not be provided or be provided for every origin");
} else {
for (const auto &origin : origins) {
m_origins.push_back(EntityParsing::parsePoint(origin));
}
if (m_originSets.size() == 0) {
for (const auto &origin : origins) {
m_originSets.push_back("");
}
}
}
}

void IsovistZoneParser::run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const {
auto mGraph = dm_runmethods::loadGraph(clp.getFileName().c_str(), perfWriter);

auto &graphRegion = mGraph->getRegion();
PointMap &map = mGraph->getDisplayedPointMap();

std::map<std::string, std::set<PixelRef>> pixelsFrom;
auto namesIter = m_originSets.begin();
for (const Point2f &origin : m_origins) {
if (!graphRegion.contains(origin) || !map.getRegion().contains(origin)) {
throw depthmapX::RuntimeException("Origin point " + std::to_string(origin.x) + ", " +
std::to_string(origin.y) + " outside of target region");
}
PixelRef pixelFrom = map.pixelate(origin);
if (!map.getPoint(pixelFrom).filled()) {
throw depthmapX::RuntimeException("Origin point " + std::to_string(origin.x) + ", " +
std::to_string(origin.y) + " not filled in target pointmap");
}
pixelsFrom[*namesIter].insert(pixelFrom);
namesIter++;
}

std::cout << "ok\nCalculating isovist zone... " << std::flush;

std::unique_ptr<Communicator> comm(new ICommunicator());

DO_TIMED("Calculating isovist zone", VGAIsovistZone(map, pixelsFrom, m_restrictDistance).run(comm.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;
}
48 changes: 48 additions & 0 deletions modules/vgapaths/cli/isovistzoneparser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (C) 2017 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/>.

#pragma once

#include "depthmapXcli/imodeparser.h"
#include "genlib/p2dpoly.h"
#include <vector>

class IsovistZoneParser : public IModeParser {
public:
IsovistZoneParser() {}

virtual std::string getModeName() const { return "ISOVISTZONE"; }

virtual std::string getHelp() const {
return "Mode options for pointmap ISOVISTZONE are:\n"
" -izo <point> Origin point (can be given multiple times)\n"
" -izn <name> Set of an origin. Either not provided or provided for every origin\n"
" -izf <file path> load origins from a file (csv)\n"
" the relevant headers must be called x, y and set\n"
" the last one is optional.\n"
" -izr <distance> Restrict distance of isovist zone from origins\n";
}

virtual void parse(int argc, char **argv);

virtual void run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const;

std::vector<Point2f> getOrigins() const { return m_origins; }

private:
std::vector<Point2f> m_origins;
std::vector<std::string> m_originSets;
float m_restrictDistance = -1;
};
Loading