-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobileMappingReader.cpp
More file actions
59 lines (47 loc) · 2.09 KB
/
Copy pathMobileMappingReader.cpp
File metadata and controls
59 lines (47 loc) · 2.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
#include "MobileMappingReader.h"
#include <array>
#include <fstream>
#include <iostream>
namespace EFTDEM {
void MobileMappingReader::readPointsFromFile(PointCloud &pointCloud, const std::string &path, const int debug) {
std::cout << "Reading point cloud at " << path << "...\n";
std::ifstream file{path, std::ios::in};
if (!file.is_open()) {
std::cerr << "Point cloud at " << path << " could not be opened!\n";
throw std::exception{};
}
std::array<std::string, 5> dataColumns;
std::string currentLine;
getline(file, currentLine);
while (getline(file, currentLine)) {
std::size_t lastPosition = 0;
for (auto &column: dataColumns) {
auto delimiterPosition = currentLine.find(',', lastPosition);
column = currentLine.substr(lastPosition,
std::min(delimiterPosition - lastPosition,
currentLine.size() - lastPosition));
lastPosition = delimiterPosition + 1;
}
if (dataColumns[3] != "1") continue;
Point<double> p{std::stod(dataColumns[0]), std::stod(dataColumns[1]), std::stod(dataColumns[2])};
pointCloud.points.emplace_back(p);
for (auto axis = 0; axis < 3; ++axis) {
if (p[axis] < pointCloud.mins[axis]) pointCloud.mins[axis] = p[axis];
if (p[axis] > pointCloud.maxs[axis]) pointCloud.maxs[axis] = p[axis];
}
}
if (debug) printOutput(pointCloud, debug);
}
void MobileMappingReader::printOutput(const PointCloud &pointCloud, const int approximateNumLines) {
std::cout << "\nLimits:\n";
std::cout << "\tx: " << "{" << pointCloud.mins.x << ", " << pointCloud.maxs.x << "}\n";
std::cout << "\ty: " << "{" << pointCloud.mins.y << ", " << pointCloud.maxs.y << "}\n";
std::cout << "\tz: " << "{" << pointCloud.mins.z << ", " << pointCloud.maxs.z << "}\n";
std::cout << "Points:\n";
for (std::size_t i = 0; i < pointCloud.points.size(); i += pointCloud.points.size() / approximateNumLines) {
const auto &point = pointCloud.points[i];
std::cout << "\t" << i << ": {" << point.x << ", " << point.y << ", " << point.z << "}\n";
}
std::cout << "\t[...]\n\n";
}
} // EFTDEM