-
Notifications
You must be signed in to change notification settings - Fork 2
/
HeightNormalizerFunction
241 lines (223 loc) · 7.03 KB
/
HeightNormalizerFunction
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;
#include "prototypes.h" //FIXME
#include "functions.cpp"
/*
-Purpose:
Things have different heights. We need to take this into account.
Thus, at the end of the point placing process but before the writing process,
There must be a function that scrubs through the list of waypoints, recognizes
which are mandatory and which are points in between, and attempts to make the
waypoint heights be evenly distributed.
-Process:
Mandatory waypoint found
Keep track of which are the points in between it and the next mandatory waypoint
Find the heigh difference between the two key points
Divide it by the number of points
Assign incrementally increasing height to the points in the middle, then repeat
-Requirements
Takes in a vector(?), determines what points are critical/mandatory, determines
How many points are in the middle, subtracts height to get height difference,
Divides height difference to get even increases.
*/
//IF ERROR, SET TO 200 ft, IF NEGATIVE HEIGHT, no, set to 200
void calculate(vector<point>& points);
void readData(const string &inp, vector<point>& points);
int findCP(const vector<point>& points, unsigned index);
bool isAscending(const vector<point>& points, unsigned startIndex, unsigned endIndex);
int main()
{
cout << "Testing Function: " << endl;
cout << endl;
//three points, ascending order, CP is last point
//don't declare a size yet, you're going to be ending up filling it with garbage values
vector<point> test1;
cout << "Testing a set of 3 points, in ascending order: "<<endl;
point temp = point();
temp.height = 200;
temp.crit = true;
point temp1 = point();
temp1.height = 200;
point temp2 = point();
temp2.height = 400;
temp2.crit = true;
test1.push_back(temp); //ask about height
test1.push_back(temp1);
test1.push_back(temp2);
for(int i = 0; i < test1.size(); i++)
{
cout<<test1.at(i).height << " ";
}
calculate(test1);
cout << endl;
for(int i = 0; i < test1.size(); i++)
{
cout<<test1.at(i).height << " ";
}
cout << endl;
//cout << "Supposed to be: 266.666, " << endl;
//cout << endl;
//cout.flush();
//three points, descending order, CP is last point
vector<point> test2;
cout << "\nTesting a set of 3 points, in descending order: "<<endl;
point Temp = point();
Temp.height = 400;
Temp.crit = true;
point Temp1 = point();
Temp1.height = 200;
point Temp2 = point();
Temp2.height = 200;
Temp2.crit = true;
test2.push_back(Temp); //ask about height
test2.push_back(Temp1);
test2.push_back(Temp2);
for(int i = 0; i < test2.size(); i++)
{
cout<<test2.at(i).height << " ";
}
cout << endl;
calculate(test2);
for(int i = 0; i < test2.size(); i++)
{
cout<<test2.at(i).height << " ";
}
cout << endl;
//cout << endl;
//three points, all negative
/*vector<point> test3;
cout << "\nTesting a set of 3 points, all negative"<<endl;
point TTemp = point();
TTemp.height = -400;
point TTemp1 = point();
TTemp1.height = -200;
point TTemp2 = point();
TTemp2.height = -200;
test3.push_back(TTemp); //ask about height
test3.push_back(TTemp1);
test3.push_back(TTemp2);
for(int i = 0; i < test3.size(); i++)
{
cout<<test3.at(i).height << " ";
}
cout << endl;
calculate(test3);
for(int i = 0; i < test3.size(); i++)
{
cout<<test3.at(i).height << " ";
}
cout << endl; */
//cout << endl;
vector<point> test4;
cout << "\nTesting a set of 4 points, in ascending order: "<<endl;
point TTTemp = point();
TTTemp.height = 200;
TTTemp.crit = true;
point TTTemp1 = point();
TTTemp1.height = 200;
point TTTemp2 = point();
TTTemp2.height = 200;
point TTTemp3 = point();
TTTemp3.height = 400;
TTTemp3.crit = true;
test4.push_back(TTTemp); //ask about height
test4.push_back(TTTemp1);
test4.push_back(TTTemp2);
test4.push_back(TTTemp3);
for(int i = 0; i < test4.size(); i++)
{
cout<<test4.at(i).height << " ";
}
cout << endl;
calculate(test4);
for(int i = 0; i < test4.size(); i++)
{
cout<<test4.at(i).height << " ";
}
cout << endl;
vector<point> test5;
cout << "\nTesting a set of 5 points, in ascending order: "<<endl;
point TTTTemp = point();
TTTTemp.height = 2000;
TTTTemp.crit = true;
point TTTTemp1 = point();
TTTTemp1.height = -2000;
point TTTTemp2 = point();
TTTTemp2.height = -2000;
point tTTTTemp2 = point();
tTTTTemp2.height = -2000;
point TTTTemp3 = point();
TTTTemp3.height = 4000;
TTTTemp3.crit = true;
test5.push_back(TTTTemp); //ask about height
test5.push_back(TTTTemp1);
test5.push_back(TTTTemp2);
test5.push_back(tTTTTemp2);
test5.push_back(TTTTemp3);
for(int i = 0; i < test5.size(); i++)
{
cout<<test5.at(i).height << " ";
}
cout << endl;
calculate(test5);
for(int i = 0; i < test5.size(); i++)
{
cout<<test5.at(i).height << " ";
}
cout << endl;
}
/*CALCULATES deltaH AND ADDS TO EACH POINT
* Works with findCP function
*/
//list use when you have items,
//front, back middle end for lists, list doesnt have everything stored in order
// linked with pointers
// IF NOT A CRITICAL, HEIGHT = 200
void calculate(vector<point>& points)
{
//(abs(deltaH)/n+1), n being number of points, h being change in height;
int index1 = findCP(points, 0);
int index2 = findCP(points, 1);
int incrementScalarP = 1;
int incrementScalarN = points.size() - 2;
for(int i = index1 + 1; i < index2; i++)
{
if(points.at(i).height < 0)
{
cout << "Error, passing in negative height."<< endl;
cout << "Changing height to positive..."<< endl;
points.at(i).height = points.at(i).height * -1;
cout << points.at(i).height<<endl;
}
double deltaH = abs(points.at(index1).height - points.at(index2).height);
double increment = (deltaH)/(points.size());
if(points.at(index1).height < points.at(index2).height)
{
points.at(i).height += incrementScalarP * increment;
incrementScalarP++;
}
else
{
points.at(i).height += incrementScalarN * increment;
incrementScalarN--;
}
}
}
/* FINDS CRITICAL POINT
* Returns index of first found CP, starting from index given
*/
//FIX ME: if it doesnt find a CP, return -1
int findCP(const vector<point>& points, unsigned index)
{
for(int i = index; i < points.size(); i++){
if(points.at(i).crit)
{
return i;
}
}
return -1;
}