Repository navigation
Expand file tree
/
Copy pathvisprepparser.cpp
More file actions
130 lines (119 loc) · 4.39 KB
/
Copy pathvisprepparser.cpp
File metadata and controls
130 lines (119 loc) · 4.39 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 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 "visprepparser.h"
#include "exceptions.h"
#include "parsingutils.h"
#include "salalib/entityparsing.h"
#include "runmethods.h"
#include <sstream>
#include <cstring>
using namespace depthmapX;
void VisPrepParser::parse(int argc, char ** argv)
{
std::vector<std::string> points;
std::string pointFile;
for ( int i = 1; i < argc; ++i )
{
if ( std::strcmp ("-pg", argv[i]) == 0)
{
if (m_grid >= 0)
{
throw CommandLineException("-pg can only be used once");
}
ENFORCE_ARGUMENT("-pg", i)
m_grid = std::atof(argv[i]);
if (m_grid <= 0)
{
throw CommandLineException(std::string("-pg must be a number >0, got ") + argv[i]);
}
}
else if ( std::strcmp ("-pp", argv[i]) == 0)
{
if (!pointFile.empty())
{
throw CommandLineException("-pp cannot be used together with -pf");
}
ENFORCE_ARGUMENT("-pp", i)
if (!has_only_digits_dots_commas(argv[i]))
{
std::stringstream message;
message << "Invalid fill 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("-pf", argv[i]) == 0 )
{
if (!points.empty())
{
throw CommandLineException("-pf cannot be used together with -pp");
}
ENFORCE_ARGUMENT("-pf", i)
pointFile = argv[i];
}
else if ( std::strcmp("-pr", argv[i]) == 0)
{
ENFORCE_ARGUMENT("-pr", i);
m_maxVisibility = std::atof(argv[i]);
if ( m_maxVisibility == 0.0)
{
std::stringstream message;
message << "Restricted visibility of '" << argv[i] << "' makes no sense, use a positive number or -1 for unrestricted";
throw CommandLineException(message.str());
}
}
else if ( std::strcmp("-pb", argv[i]) == 0 )
{
m_boundaryGraph = true;
}
}
if (m_grid < 0)
{
throw CommandLineException("Use -pg to define grid");
}
if (pointFile.empty() && points.empty())
{
throw CommandLineException("Either -pp or -pf must be given");
}
if(!pointFile.empty())
{
std::ifstream pointsStream(pointFile);
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<Point2f> parsed = EntityParsing::parsePoints(pointsStream, '\t');
m_fillPoints.insert(std::end(m_fillPoints), std::begin(parsed), std::end(parsed));
}
else if(!points.empty())
{
std::stringstream pointsStream;
pointsStream << "x,y";
std::vector<std::string>::iterator iter = points.begin(), end =
points.end();
for ( ; iter != end; ++iter )
{
pointsStream << "\n" << *iter;
}
std::vector<Point2f> parsed = EntityParsing::parsePoints(pointsStream, ',');
m_fillPoints.insert(std::end(m_fillPoints), std::begin(parsed), std::end(parsed));
}
}
void VisPrepParser::run(const CommandLineParser &clp, IPerformanceSink &perfWriter) const
{
dm_runmethods::runVisualPrep(clp, m_grid, m_fillPoints, m_maxVisibility, m_boundaryGraph, perfWriter);
}