/
auto_model.cpp
274 lines (254 loc) · 6.29 KB
/
auto_model.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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include "auto_model.h"
double plusOrMinus() {
double y;
srand((int)time(0));
if (random(1) < 0.5) {
y = -1;
} else {
y = 1;
}
return y;
}
Vehicle randomVehicle(double distance, double width, const Direction& d, double vRange) {
srand((int)time(0));
double x = random((int)width) - (width / 2);
double y = 0 + distance;
double z = ANTENNA_HEIGHT;
Point p(x, y, z);
double v = random((int)vRange);
Vehicle vehicle(p, d, v);
return vehicle;
}
vector<Material> materialList() {
// 玻璃
Material m1(1.5, "glass");
// 钢
Material m2(2.5, "steel");
// 铝
Material m3(1.4, "aluminum");
// 水泥
Material m4(1.6, "concrete");
vector<Material> materials;
materials.push_back(m1);
materials.push_back(m2);
materials.push_back(m3);
materials.push_back(m4);
return materials;
}
Surface randomSurface(const Point& p0,
double width,
vector<Material> materials) {
double x1 = p0.x;
double y1 = p0.y + width;
double z1 = 0;
Point p1(x1, y1, z1);
time_t t;
srand((int)time(&t));
int mSize = materials.size();
int mIndex = (int)random(mSize);
Material m = materials[mIndex];
Surface s(p0, p1, m);
s.init();
return s;
}
double randomNum(double range[2]) {
double min = range[0];
double max = range[1];
if (range[0] > range[1]) {
max = range[0];
min = range[1];
}
int rangeInt = (int)(max - min);
double num = min + rand()%rangeInt;
return num;
}
// 随机模型1
Model randomModel(double length,
double width,
double margin,
double sMaxH,
double sMinH,
double sMaxW,
double sMinW,
double surfaceInterval,
double vRange,
int dFlag) {
Direction* tdp;
Direction* rdp;
switch(dFlag) {
case 1:
tdp = new Direction(0, 1, 0);
rdp = new Direction(0, 1, 0);
break;
case 2:
tdp = new Direction(0, -1, 0);
rdp = new Direction(0, -1, 0);
break;
case 3:
tdp = new Direction(0, 1, 0);
rdp = new Direction(0, -1, 0);
break;
case 4:
tdp = new Direction(0, -1, 0);
rdp = new Direction(0, 1, 0);
break;
default:
double ty = plusOrMinus();
double ry = plusOrMinus();
Direction td(0, ty, 0);
Direction rd(0, ry, 0);
break;
}
Vehicle tx = randomVehicle(0, width, *tdp, vRange);
Vehicle rx = randomVehicle(length, width, *rdp, vRange);
vector<Material> materials = materialList();
vector<Surface> surfaces;
double totalLength = 0;
srand((int)time(0));
while (totalLength <= length) {
double x0 = (width / 2) + random((int)margin);
double y0 = totalLength;
double z0 = sMinH + random(int(sMaxH - sMinH));
Point p0(x0, y0, z0);
double sWidth = sMinW + random((int)(sMaxW - sMinW));
double x1 = x0;
double y1 = y0 + sWidth;
double z1 = 0;
Point p1(x1, y1, z1);
Surface s(p0, p1);
surfaces.push_back(s);
totalLength = y0 + sWidth + random((int)surfaceInterval);
}
totalLength = 0;
while (totalLength <= length) {
double x0 = -((width / 2) + random((int)margin));
double y0 = totalLength;
double z0 = sMinH + random(int(sMaxH - sMinH));
Point p0(x0, y0, z0);
double sWidth = sMinW + random((int)(sMaxW - sMinW));
double x1 = x0;
double y1 = y0 + sWidth;
double z1 = 0;
Point p1(x1, y1, z1);
Surface s(p0, p1);
surfaces.push_back(s);
totalLength = y0 + sWidth + random((int)surfaceInterval);
}
int sizeM = materials.size();
for (int i = 0; i < (int)surfaces.size(); i++) {
int indexM = random(sizeM);
surfaces[i].setMaterial(materials[indexM]);
surfaces[i].init();
}
Direction tad(0,0,1);
Direction tarp(0,0,0);
Direction taPolar(sqrt(double(2))/2, 0, sqrt(double(2))/2);
Antenna ta(tad, tarp, taPolar, 10);
vector<Antenna> tas;
tas.push_back(ta);
Direction rad(0,0,1);
Direction rarp(0,0,0);
Direction raVPolar(1, 0, 0);
Direction raHPolar(0, 0, 1);
Antenna ra(rad, rarp, raVPolar, raHPolar);
vector<Antenna> ras;
ras.push_back(ra);
Model model(tx, rx, surfaces, tas, ras);
return model;
}
/*
Model RandomModel::produce(double length[2],
double width[2],
double margin[2],
double bH[2],
double bW[2],
double bInterval[2],
double vRange[2],
int dFlag) {
srand((int)time(0));
this->roadProduce(length, width, margin);
this->vehicleProduce(vRange, dFlag);
}*/
void RandomModel::roadProduce(double length[2], double width[2], double margin[2]) {
this->length = this->randomNum(length);
this->width = this->randomNum(width);
this->margin = this->randomNum(margin);
}
void RandomModel::vehicleProduce(double vRange[2], int dFlag) {
this->vehicleDirect(dFlag);
this->vehicleVelocity(vRange);
double halfWidth = this->width;
double widthRange[2] = {-halfWidth, halfWidth};
double xt = this->randomNum(widthRange);
double yt = 0;
double zt = ANTENNA_HEIGHT;
Point pt(xt, yt, zt);
Vehicle* txp = new Vehicle(pt, this->dTx, this->vTx);
double xr = this->randomNum(widthRange);
double yr = 0 + this->length;
double zr = ANTENNA_HEIGHT;
Point pr(xr, yr, zr);
Vehicle* rxp = new Vehicle(pr, this->dRx, this->vRx);
this->tx = *txp;
this->rx = *rxp;
}
void RandomModel::vehicleDirect(int dFlag) {
Direction* tdp;
Direction* rdp;
switch(dFlag) {
case 1:
tdp = new Direction(0, 1, 0);
rdp = new Direction(0, 1, 0);
break;
case 2:
tdp = new Direction(0, -1, 0);
rdp = new Direction(0, -1, 0);
break;
case 3:
tdp = new Direction(0, 1, 0);
rdp = new Direction(0, -1, 0);
break;
case 4:
tdp = new Direction(0, -1, 0);
rdp = new Direction(0, 1, 0);
break;
default:
double ty = plusOrMinus();
double ry = plusOrMinus();
tdp = new Direction(0, ty, 0);
rdp = new Direction(0, ry, 0);
break;
}
this->dTx = *tdp;
this->dRx = *rdp;
}
double RandomModel::randomNum(double range[2]) {
double min = range[0];
double max = range[1];
if (range[0] > range[1]) {
max = range[0];
min = range[1];
}
int rangeInt = (int)(max - min);
double num = min + rand()%rangeInt;
return num;
}
void RandomModel::vehicleVelocity(double vRange[2]) {
this->vTx = this->randomNum(vRange);
this->vRx = this->randomNum(vRange);
}
// 随机模型2
/*
Model randomModel(double length[2],
double width[2],
double margin[2],
double bH[2],
double bW[2],
double bInterval[2],
double vRange[2],
int dFlag) {
srand((int)time(0));
Model model();
return model;
}
*/