forked from james-yoo/DBSCAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
66 lines (53 loc) · 1.52 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
#include <stdio.h>
#include <iostream>
#include "dbscan.h"
#define MINIMUM_POINTS 4 // minimum number of cluster
#define EPSILON (0.75*0.75) // distance for clustering, metre^2
void readBenchmarkData(vector<Point>& points)
{
// load point cloud
FILE *stream;
stream = fopen ("benchmark_hepta.dat","ra");
unsigned int minpts, num_points, cluster, i = 0;
double epsilon;
fscanf(stream, "%u\n", &num_points);
Point *p = (Point *)calloc(num_points, sizeof(Point));
while (i < num_points)
{
fscanf(stream, "%f,%f,%f,%d\n", &(p[i].x), &(p[i].y), &(p[i].z), &cluster);
p[i].clusterID = UNCLASSIFIED;
points.push_back(p[i]);
++i;
}
free(p);
fclose(stream);
}
void printResults(vector<Point>& points, int num_points)
{
int i = 0;
printf("Number of points: %u\n"
" x y z cluster_id\n"
"-----------------------------\n"
, num_points);
while (i < num_points)
{
printf("%5.2lf %5.2lf %5.2lf: %d\n",
points[i].x,
points[i].y, points[i].z,
points[i].clusterID);
++i;
}
}
int main()
{
vector<Point> points;
// read point data
readBenchmarkData(points);
// constructor
DBSCAN ds(MINIMUM_POINTS, EPSILON, points);
// main loop
ds.run();
// result of DBSCAN algorithm
printResults(ds.m_points, ds.getTotalPointSize());
return 0;
}