-
Notifications
You must be signed in to change notification settings - Fork 3
/
pathfilter.cpp
133 lines (108 loc) · 2.83 KB
/
pathfilter.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
128
129
130
131
132
133
#include "pathfilter.h"
#include <fstream>
void PathFilter::run(std::string pointFile, std::string outFile, int numPaths, double gap, double requiredLength)
{
printf("Running pathfilter with %d paths, %f gap, %f length.\n", numPaths, gap, requiredLength);
pm.ReadFile(pointFile, true);
//runFilter();
filterPoisson(numPaths, gap, requiredLength);
std::ofstream of;
of.open(outFile);
for(int i = 0; i < paths.size(); i++){
int id = paths[i];
of << id << std::endl;
}
of.close();
}
void PathFilter::runFilter()
{
for (auto &point : pm.points){
if ( (rand() % 5) == 0){
paths.push_back(point.m_id);
}
}
}
bool checkDistanceTotal(VRPoint& p, VRPoint& q, double gap){
return p.withinDistance(q, gap);
}
bool checkDistanceTime(VRPoint& p, VRPoint& q, double gap){
int length = std::min(p.positions.size(), q.positions.size());
for(int i = 0; i < length; i++){
if (glm::distance(p.positions[i], q.positions[i]) < gap){
return true;
}
}
return false;
}
//Checks if two paths are within a given distance of each other
bool checkDistance(VRPoint& p, VRPoint& q, double gap){
return checkDistanceTime(p, q, gap);
}
void PathFilter::filterPoisson(int number, double gap, double requiredLength)
{
std::vector<int> pathIDs;
std::vector<int> options;
for(int i = 0; i < pm.points.size(); i++){
if (pm.points[i].totalPathLength() > requiredLength){
options.push_back(i);
}
}
printf("%d paths found of suitable length.\n", options.size());
for (int i = 0; i < number; i++){
int oid;
int id;
bool valid;
int tries = 0;
do{
if (options.size() == 0){
break;
}
tries++;
oid = rand() % options.size();
id = options[oid];
options.erase( options.begin() + oid);
valid = true;
for(auto &other : pathIDs){
if (pm.points[id].withinDistance(pm.points[other], gap)){
valid = false;
continue;
}
}
}
while(!valid);
if (options.size() == 0){
break;
}
//Repeat the cycle above of trying new points until we find one that works.
pathIDs.push_back(id);
printf("Adding path %4d took %3d tries with %d options left..\n", i, tries, options.size());
}
for(int i = 0; i < pathIDs.size(); i++){
paths.push_back(pm.points[pathIDs[i]].m_id);
}
}
int main(int argc, char **argv){
std::string dataFile = "data/slices-68.out";
std::string outFile = "test.paths";
int numPaths = 200;
double gap = .005;
double cutoff = .003;
PathFilter pf;
if (argc >= 2){
dataFile = argv[1];
}
if (argc >= 3){
outFile = argv[2];
}
if (argc >= 4){
numPaths = atoi(argv[3]);
}
if (argc >= 5){
gap = atof(argv[4]);
}
if (argc >= 6){
cutoff = atof(argv[5]);
}
pf.run(dataFile, outFile, numPaths, gap, cutoff);
return 0;
}