-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmapAMDcalc.cpp
127 lines (120 loc) · 3.35 KB
/
mapAMDcalc.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
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
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
struct Point{
int x,y,z;
};
double getDist(Point p1, Point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) + (p1.z-p2.z)*(p1.z-p2.z));
}
int main()
{
string line;
int axis_index = 0;
Point p;
vector<Point> points1;
ifstream mapInfoFile1("00dataset/testset.txt");
while ( getline (mapInfoFile1,line) )
{
line.erase(remove(line.begin(), line.end(), ';'), line.end());
line.erase(remove(line.begin(), line.end(), '['), line.end());
line.erase(remove(line.begin(), line.end(), ']'), line.end());
double measurement = std::stod(line);
switch (axis_index)
{
case 0:
p.x = measurement;
break;
case 1:
p.y = measurement;
break;
case 2:
p.z = measurement;
break;
}
if (axis_index == 2)
{
points1.push_back(p);
}
axis_index = (axis_index + 1) % 3;
}
mapInfoFile1.close();
cout << "Test" << endl;
vector<Point> points2;
ifstream mapInfoFile2("015dataset/mapOutput015-02.txt");
while ( getline (mapInfoFile2,line) )
{
line.erase(remove(line.begin(), line.end(), ';'), line.end());
line.erase(remove(line.begin(), line.end(), '['), line.end());
line.erase(remove(line.begin(), line.end(), ']'), line.end());
double measurement = std::stod(line);
switch (axis_index)
{
case 0:
p.x = measurement;
break;
case 1:
p.y = measurement;
break;
case 2:
p.z = measurement;
break;
}
if (axis_index == 2)
{
points2.push_back(p);
}
axis_index = (axis_index + 1) % 3;
}
mapInfoFile2.close();
double chamferDistance = 0;
double hausdorffDistance = 0;
cout << "Size 1 = " << points1.size() << " Size 2 = " << points2.size() << endl;
double maxMinDist = 0;
for (int i = 0; i < points1.size(); i++)
{
double minDist = 99999;
for (int j = 0; j < points2.size(); j++)
{
double dist = getDist(points1[i], points2[j]);
if (dist < minDist)
{
minDist = dist;
}
}
if (minDist > maxMinDist)
{
maxMinDist = minDist;
}
chamferDistance += minDist;
}
chamferDistance /= points1.size() * 2;
hausdorffDistance += maxMinDist / 2;
maxMinDist = 0;
for (int i = 0; i < points2.size(); i++)
{
double minDist = 99999;
for (int j = 0; j < points1.size(); j++)
{
double dist = getDist(points2[i], points1[j]);
if (dist < minDist)
{
minDist = dist;
}
}
if (minDist > maxMinDist)
{
maxMinDist = minDist;
}
chamferDistance += minDist;
}
chamferDistance /= points2.size() * 2;
hausdorffDistance += maxMinDist / 2;
cout << "Chamfer Distance = " << chamferDistance << endl;
cout << "Hausdorff Distance = " << hausdorffDistance << endl;
}