forked from varoudis/depthmapX
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathisovistparser.cpp
More file actions
100 lines (86 loc) · 3.12 KB
/
isovistparser.cpp
File metadata and controls
100 lines (86 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// 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/>.
#include "isovistparser.h"
#include "parsingutils.h"
#include "exceptions.h"
#include "salalib/entityparsing.h"
#include <sstream>
#include "runmethods.h"
#include <cstring>
using namespace depthmapX;
IsovistParser::IsovistParser()
{
}
std::string IsovistParser::getModeName() const
{
return "ISOVIST";
}
std::string IsovistParser::getHelp() const
{
return "Arguments for isovist mode:\n" \
" -ii <x,y[,angle,viewangle]> Define an isoivist at position x,y with\n"\
" optional direction angle and view angle for partial isovists\n"\
" -if <isovist file> load isovist definitions from a file (csv)\n"\
" the relevant headers must be called x, y, angle and viewangle\n"\
" the latter two are optional.\n"\
" Those two arguments cannot be mixed\n"\
" Angles for partial isovists are in degrees, counted anti-clockwise with 0°\n"\
" pointing to the right.\n\n";
}
void IsovistParser::parse(int argc, char **argv)
{
std::string isovistFile;
for( int i = 1; i < argc; ++i)
{
if (std::strcmp(argv[i], "-ii") == 0 )
{
if ( !isovistFile.empty())
{
throw CommandLineException("-ii cannot be used together with -if");
}
ENFORCE_ARGUMENT("-ii", i);
m_isovists.push_back(EntityParsing::parseIsovist(argv[i]));
}
else if( std::strcmp(argv[i], "-if") == 0)
{
if ( !isovistFile.empty())
{
throw CommandLineException("-if can only be used once");
}
if (!m_isovists.empty())
{
throw depthmapX::CommandLineException("-if cannot be used together with -ii");
}
ENFORCE_ARGUMENT("-if",i);
isovistFile = argv[i];
}
}
if (!isovistFile.empty())
{
std::ifstream file(isovistFile);
if ( !file.good())
{
std::stringstream message;
message << "Failed to find file " << isovistFile;
throw depthmapX::CommandLineException(message.str());
}
m_isovists = EntityParsing::parseIsovists(file, ',');
}
if (m_isovists.empty())
{
throw CommandLineException("No isovists defined. Use -ii or -if");
}
}
void IsovistParser::run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const
{
dm_runmethods::runIsovists(clp, m_isovists, perfWriter);
}