-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
74 lines (53 loc) · 1.47 KB
/
main.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
#include <iostream>
#include <cmath>
#include "concaveHull2d.h"
int main(int argc, char *argv[])
{
std::vector<Point2D> p;
FILE *fpx = fopen("x.txt", "r");
FILE *fpy = fopen("y.txt", "r");
for (int i = 0; i < 100; i++)
{
Point2D tmp;
fscanf(fpx, "%lf", &tmp.x);
fscanf(fpy, "%lf", &tmp.y);
p.push_back(tmp);
}
fclose(fpx);
fclose(fpy);
double minx = 0, maxx = 0;
double miny = 0, maxy = 0;
for (int i = 0; i < p.size(); i++)
{
minx = p[i].x < minx ? p[i].x : minx;
maxx = p[i].x > maxx ? p[i].x : maxx;
miny = p[i].y < miny ? p[i].y : miny;
maxy = p[i].y > maxy ? p[i].y : maxy;
}
for (int i = 0; i < p.size(); i++)
{
p[i].x = (p[i].x - minx) / (maxx - minx);
p[i].y = (p[i].y - miny) / (maxy - miny);
}
ConCaveHull *concavehull_ = new ConCaveHull();
concavehull_->setData(p);
concavehull_->setParameters(120,20);
concavehull_->computeConcaveHull();
vector<Point2D> pCH = concavehull_->getConcaveHull();
pCH.push_back(pCH[0]); // °üÂçˇâąŐ
fpx = fopen("pCH.txt", "w");
for (int i = 0; i < pCH.size(); i++)
{
fprintf(fpx, "%f\t%f\n", pCH[i].x*(maxx - minx) + minx, pCH[i].y*(maxy - miny) + miny);
}
fclose(fpx);
fpx = fopen("p.txt", "w");
for (int i = 0; i < p.size(); i++)
{
fprintf(fpx, "%f\t%f\n", p[i].x*(maxx - minx) + minx, p[i].y*(maxy - miny) + miny);
}
fclose(fpx);
vector<Point2D>().swap(pCH);
delete concavehull_;
return 0;
}