forked from varoudis/depthmapX
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathstepdepthparser.cpp
More file actions
122 lines (111 loc) · 4.09 KB
/
stepdepthparser.cpp
File metadata and controls
122 lines (111 loc) · 4.09 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
// 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/>.
#include "stepdepthparser.h"
#include "exceptions.h"
#include "parsingutils.h"
#include "salalib/entityparsing.h"
#include "runmethods.h"
#include <sstream>
#include <cstring>
using namespace depthmapX;
void StepDepthParser::parse(int argc, char ** argv)
{
std::vector<std::string> points;
std::string pointFile;
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]))
{
std::stringstream message;
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())
{
throw CommandLineException("-sdf cannot be used together with -sdp");
}
ENFORCE_ARGUMENT("-sdf", i)
pointFile = argv[i];
}
else if ( std::strcmp ("-sdt", argv[i]) == 0)
{
ENFORCE_ARGUMENT("-sdt", i)
if ( std::strcmp(argv[i], "angular") == 0 )
{
m_stepType = StepType::ANGULAR;
}
else if ( std::strcmp(argv[i], "metric") == 0 )
{
m_stepType = StepType::METRIC;
}
else if ( std::strcmp(argv[i], "visual") == 0 )
{
m_stepType = StepType::VISUAL;
}
else
{
throw CommandLineException(std::string("Invalid step type: ") + argv[i]);
}
}
}
if (pointFile.empty() && points.empty())
{
throw CommandLineException("Either -sdp or -sdf 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_stepDepthPoints.insert(std::end(m_stepDepthPoints), 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_stepDepthPoints.insert(std::end(m_stepDepthPoints), std::begin(parsed), std::end(parsed));
}
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);
}