-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadarComparator.cpp
More file actions
94 lines (79 loc) · 3.73 KB
/
Copy pathRadarComparator.cpp
File metadata and controls
94 lines (79 loc) · 3.73 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
#include "RadarComparator.h"
#include "ConfigProvider.h"
#include "GTiffWriter.h"
#include "IComparator.h"
#include <utility>
RadarComparator::RadarComparator(std::vector<std::string> configPaths) {
RadarComparator::configPaths = std::move(configPaths);
configProvider = new ConfigProvider();
pipelines.reserve(RadarComparator::configPaths.size());
for (const auto & configPath : RadarComparator::configPaths) {
pipelines.emplace_back(configProvider->providePipeline(configPath));
destinationPaths.emplace_back(configProvider->getDestinationPath());
thresholds.emplace_back(configProvider->getThreshold());
betterCompression.emplace_back(configProvider->getBetterCompression());
}
RadarComparator::glHandler = pipelines.at(0)->getGLHandler();
compareShaderPath = "compare.glsl";
}
RadarComparator::~RadarComparator() {
delete configProvider;
for (auto pipeline : pipelines) delete pipeline;
configProvider = nullptr;
}
/**
* Reads all the point-clouds in the pipelines in pipelines and adds a shared min and max value, so the point-clouds will be scaled and rasterized coherently.
* @return a Vector containing all the read point-clouds
*/
std::vector<rawPointCloud *> RadarComparator::setupPointClouds() {
std::vector<rawPointCloud *> readerReturns(pipelines.size());
for (auto i = 0ul; i < pipelines.size(); i++) {
readerReturns.at(i) = pipelines.at(i)->getCloudReader()->apply(true);
}
std::vector<doublePoint> mins, maxs;
for (auto pointCloud : readerReturns) {
mins.emplace_back(pointCloud->min);
maxs.emplace_back(pointCloud->max);
}
auto absoluteMin = mergeDoublePoints(mins).first,
absoluteMax = mergeDoublePoints(maxs).second;
for (auto pointCloud : readerReturns) {
pointCloud->min = absoluteMin;
pointCloud->max = absoluteMax;
}
return readerReturns;
}
void addColor(std::vector<std::vector<int>>& colors, std::vector<int> color) {
colors.at(0).emplace_back(color.at(0));
colors.at(1).emplace_back(color.at(1));
colors.at(2).emplace_back(color.at(2));
}
/**
* Writes the pixel-wise comparisons to a Geotiff-File, with Values falling below a threshold marked in red.
* @param comparisons a vector of pixel-wise comparisons to be written as Geotiff-Files
*/
void RadarComparator::writeThresholdMaps(const std::vector<heightMap *> &comparisons) {
std::vector<std::vector<int>> colors(3);
for (auto i = 0ul; i < comparisons.size(); i++) {
auto writer = new GTiffWriter(false, "", betterCompression.at(i));
for (auto pos = 0ul; pos < comparisons.at(i)->resolutionX * comparisons.at(i)->resolutionY; pos++) {
auto height = comparisons.at(i)->heights.at(pos);
auto integerHeight = (int) (height * 255);
if (height != 0 && denormalizeValue(height, comparisons.at(i)->min.z, comparisons.at(i)->max.z) < thresholds.at(i)) addColor(colors, {255 - integerHeight, 0, 0});
else addColor(colors, {integerHeight, integerHeight, integerHeight});
}
writer->setDestinationDEM(destinationPaths.at(i) + "_color_" + std::to_string(i));
writer->writeRGB(colors, (int) comparisons.at(i)->resolutionX, (int) comparisons.at(i)->resolutionY);
colors = std::vector<std::vector<int>>(3);
delete writer;
}
}
/**
* Writes the pixel-wise comparisons to a Geotiff-File,
* as a regular Geotiff-File and an additional Geotiff, with Values falling below a threshold marked in red.
* @param comparisons a vector of pixel-wise comparisons to be writen as Geotiff-Files
*/
void RadarComparator::writeComparisons(std::vector<heightMap *> comparisons){
writeThresholdMaps(comparisons);
IComparator::writeComparisons(comparisons);
}