-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cpp
67 lines (59 loc) · 1.45 KB
/
Utils.cpp
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
#include "Utils.h"
#include <vector>
#include <sstream>
bool Utils::isHeaderLine(const std::string &line)
{
const std::vector<std::string> headerKeywords = {
"VERSION", "FIELDS", "SIZE", "TYPE", "COUNT",
"WIDTH", "HEIGHT", "VIEWPOINT", "POINTS", "DATA", "FORMAT"};
for (const auto &keyword : headerKeywords)
{
if (line.find(keyword) != std::string::npos)
{
return true;
}
}
return false;
}
bool Utils::checkFileExtension(const std::string &filename)
{
if (filename.size() >= 3)
{
return filename.substr(filename.size() - 3) == ".pt";
}
return false;
}
bool Utils::checkVersion(const std::string &line)
{
std::istringstream iss(line);
std::string versionLabel;
int version;
if (iss >> versionLabel >> version && versionLabel == "VERSION")
{
char extraChar;
if (iss >> extraChar)
{
return false;
}
return true;
}
return false;
}
bool Utils::checkFormat(const std::string &line)
{
return (line == "FORMAT x y z" || line == "FORMAT x y z r g b");
}
bool Utils::checkData(const std::string &line)
{
return (line == "DATA ascii");
}
bool Utils::checkPointsCount(const std::string &line, int &count)
{
std::istringstream iss(line);
std::string pointsLabel;
if (iss >> pointsLabel >> count && pointsLabel == "POINTS" && count > 0)
{
return true;
}
return false;
}