/
asAreaCompGrid.cpp
355 lines (304 loc) · 12 KB
/
asAreaCompGrid.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can read the License at http://opensource.org/licenses/CDDL-1.0
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL Header Notice in
* each file and include the License file (licence.txt). If applicable,
* add the following below this CDDL Header, with the fields enclosed
* by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* The Original Software is AtmoSwing.
* The Original Software was developed at the University of Lausanne.
* All Rights Reserved.
*
*/
/*
* Portions Copyright 2008-2013 Pascal Horton, University of Lausanne.
* Portions Copyright 2013-2015 Pascal Horton, Terranum.
*/
#include "asAreaCompGrid.h"
#include "asAreaCompRegGrid.h"
#include "asAreaGaussGrid.h"
#include "asAreaCompGaussGrid.h"
#include "asAreaCompGenGrid.h"
asAreaCompGrid * asAreaCompGrid::GetInstance(const wxString &type, double xMin, int xPtsNb, double xStep, double yMin,
int yPtsNb, double yStep, float level, float height, int flatAllowed)
{
// If empty, set Regular.
if (type.IsEmpty()) {
wxLogVerbose(_("The given grid type is empty. A regular grid has been considered."));
double xWidth = (double) (xPtsNb - 1) * xStep;
double yWidth = (double) (yPtsNb - 1) * yStep;
asAreaCompGrid *area = new asAreaCompRegGrid(xMin, xWidth, xStep, yMin, yWidth, yStep, level, height,
flatAllowed);
return area;
} else if (type.IsSameAs("Regular", false)) {
double xWidth = (double) (xPtsNb - 1) * xStep;
double yWidth = (double) (yPtsNb - 1) * yStep;
asAreaCompGrid *area = new asAreaCompRegGrid(xMin, xWidth, xStep, yMin, yWidth, yStep, level, height,
flatAllowed);
return area;
} else if (type.IsSameAs("GaussianT62", false)) {
asAreaCompGrid *area = new asAreaCompGaussGrid(xMin, xPtsNb, yMin, yPtsNb, GaussianT62, level, height,
flatAllowed);
return area;
} else if (type.IsSameAs("GaussianT382", false)) {
asAreaCompGrid *area = new asAreaCompGaussGrid(xMin, xPtsNb, yMin, yPtsNb, GaussianT382, level, height,
flatAllowed);
return area;
} else if (type.IsSameAs("Generic", false)) {
asAreaCompGrid *area = new asAreaCompGenGrid(xMin, xPtsNb, yMin, yPtsNb, level, height, flatAllowed);
return area;
} else {
wxLogError(_("Given grid type: %s"), type);
asThrowException("The given grid type doesn't correspond to any existing option.");
}
}
a1d asAreaCompGrid::GetXaxis(const wxString &type, double xMin, double xMax, double xStep)
{
a1d axis;
if (type.IsSameAs("Regular", false)) {
wxASSERT(xStep > 0);
auto ni = (int) asRound(360 / xStep);
axis = a1d::LinSpaced(ni * 3 + 1, -360, 720);
} else if (type.IsSameAs("GaussianT62", false)) {
asAreaGaussGrid::BuildLonAxis(axis, GaussianT62);
} else if (type.IsSameAs("GaussianT382", false)) {
asAreaGaussGrid::BuildLonAxis(axis, GaussianT382);
} else {
wxLogError(_("Cannot build axis for the given grid type (%s)."), type);
asThrowException(wxString::Format(_("Cannot build axis for the given grid type (%s)."), type));
}
wxASSERT(axis.size() > 0);
int start = asFindClosest(&axis[0], &axis[axis.size() - 1], xMin);
int end = asFindClosest(&axis[0], &axis[axis.size() - 1], xMax);
wxASSERT(start >= 0);
wxASSERT(end >= 0);
wxASSERT(end >= start);
wxASSERT(axis.size() > end - start + 1);
return axis.segment(start, end - start + 1);
}
a1d asAreaCompGrid::GetYaxis(const wxString &type, double yMin, double yMax, double yStep)
{
a1d axis;
if (type.IsSameAs("Regular", false)) {
wxASSERT(yStep > 0);
int ni = (int) asRound(180 / yStep);
axis = a1d::LinSpaced(ni + 1, -90, 90);
} else if (type.IsSameAs("GaussianT62", false)) {
asAreaGaussGrid::BuildLatAxis(axis, GaussianT62);
} else if (type.IsSameAs("GaussianT382", false)) {
asAreaGaussGrid::BuildLatAxis(axis, GaussianT382);
} else {
wxLogError(_("Cannot build axis for the given grid type (%s)."), type);
asThrowException(wxString::Format(_("Cannot build axis for the given grid type (%s)."), type));
}
wxASSERT(axis.size() > 0);
int start = asFindClosest(&axis[0], &axis[axis.size() - 1], yMin);
int end = asFindClosest(&axis[0], &axis[axis.size() - 1], yMax);
wxASSERT(start >= 0);
wxASSERT(end >= 0);
wxASSERT(end >= start);
wxASSERT(axis.size() > end - start + 1);
return axis.segment(start, end - start + 1);
}
asAreaCompGrid::asAreaCompGrid(const Coo &cornerUL, const Coo &cornerUR, const Coo &cornerLL, const Coo &cornerLR,
float level, float height, int flatAllowed)
: asAreaComp(cornerUL, cornerUR, cornerLL, cornerLR, level, height, flatAllowed),
m_axesInitialized(false)
{
}
asAreaCompGrid::asAreaCompGrid(double xMin, double xWidth, double yMin, double yWidth, float level, float height,
int flatAllowed)
: asAreaComp(xMin, xWidth, yMin, yWidth, level, height, flatAllowed),
m_axesInitialized(false)
{
}
asAreaCompGrid::asAreaCompGrid(float level, float height)
: asAreaComp(level, height),
m_axesInitialized(false)
{
}
int asAreaCompGrid::GetXaxisPtsnb()
{
int ptsLon = 0;
for (int iArea = 0; iArea < GetNbComposites(); iArea++) {
if (iArea == 0) {
ptsLon += GetXaxisCompositePtsnb(iArea);
} else if (iArea == 4) {
// Do nothing here
} else {
if (GetComposite(iArea).GetYmin() == GetComposite(iArea - 1).GetYmin()) {
if (GetXaxisCompositeEnd(iArea) == GetAxisXmax()) {
ptsLon += GetXaxisCompositePtsnb(iArea) - 1;
} else {
ptsLon += GetXaxisCompositePtsnb(iArea);
}
}
}
}
return ptsLon;
}
int asAreaCompGrid::GetYaxisPtsnb()
{
int ptsLat = 0;
for (int iArea = 0; iArea < GetNbComposites(); iArea++) {
if (iArea == 0) {
ptsLat += GetYaxisCompositePtsnb(iArea);
} else if (iArea == 4) {
// Do nothing here
} else {
if (GetComposite(iArea).GetXmin() == GetComposite(iArea - 1).GetXmin()) {
if (GetYaxisCompositeEnd(iArea) == GetAxisYmax()) {
ptsLat += GetYaxisCompositePtsnb(iArea) - 1;
} else {
ptsLat += GetYaxisCompositePtsnb(iArea);
}
}
}
}
return ptsLat;
}
double asAreaCompGrid::GetXaxisWidth() const
{
double widthLon = 0;
for (int iArea = 0; iArea < GetNbComposites(); iArea++) {
if (iArea == 0) {
widthLon += GetXaxisCompositeWidth(iArea);
} else if (iArea == 4) {
// Do nothing here
} else {
if (GetComposite(iArea).GetYmin() == GetComposite(iArea - 1).GetYmin()) {
widthLon += GetXaxisCompositeWidth(iArea);
}
}
}
return widthLon;
}
double asAreaCompGrid::GetYaxisWidth() const
{
double widthLat = 0;
for (int iArea = 0; iArea < GetNbComposites(); iArea++) {
if (iArea == 0) {
widthLat += GetYaxisCompositeWidth(iArea);
} else if (iArea == 4) {
// Do nothing here
} else {
if (GetComposite(iArea).GetXmin() == GetComposite(iArea - 1).GetXmin()) {
widthLat += GetYaxisCompositeWidth(iArea);
}
}
}
return widthLat;
}
a1d asAreaCompGrid::GetXaxis()
{
a1d xAxis;
wxASSERT(GetNbComposites() > 0);
for (int iArea = 0; iArea < GetNbComposites(); iArea++) {
if (iArea == 0) {
xAxis = GetXaxisComposite(iArea);
} else if (iArea == 4) {
// Do nothing here
} else {
if (GetComposite(iArea).GetYmin() == GetComposite(iArea - 1).GetYmin()) {
a1d xAxisBis = GetXaxisComposite(iArea);
if (GetXaxisCompositeEnd(iArea) == GetAxisXmax()) {
a1d xAxisFinal(xAxisBis.size() + xAxis.size() - 1);
xAxisFinal.head(xAxisBis.size()) = xAxisBis;
for (int i = 1; i < xAxis.size(); i++) {
xAxisFinal[xAxisBis.size() - 1 + i] = xAxis[i] + GetAxisXmax();
}
return xAxisFinal;
} else {
a1d xAxisFinal(xAxisBis.size() + xAxis.size());
xAxisFinal.head(xAxisBis.size()) = xAxisBis;
for (int i = 0; i < xAxis.size(); i++) {
xAxisFinal[xAxisBis.size() + i] = xAxis[i] + GetAxisXmax();
}
return xAxisFinal;
}
}
}
}
return xAxis;
}
a1d asAreaCompGrid::GetYaxis()
{
a1d yAxis;
wxASSERT(GetNbComposites() > 0);
for (int iArea = 0; iArea < GetNbComposites(); iArea++) {
if (iArea == 0) {
yAxis = GetYaxisComposite(iArea);
} else if (iArea == 4) {
// Do nothing here
} else {
if (GetComposite(iArea).GetXmin() == GetComposite(iArea - 1).GetXmin()) {
wxLogError(_("This function has not been tested"));
a1d yAxisBis = GetYaxisComposite(iArea);
if (GetXaxisCompositeEnd(iArea) == GetAxisXmax()) {
a1d yAxisFinal(yAxisBis.size() + yAxis.size() - 1);
yAxisFinal.head(yAxisBis.size()) = yAxisBis;
for (int i = 1; i < yAxis.size(); i++) {
yAxisFinal[yAxisBis.size() - 1 + i] = yAxis[i] + GetAxisYmax();
}
return yAxisFinal;
} else {
a1d yAxisFinal(yAxisBis.size() + yAxis.size());
yAxisFinal.head(yAxisBis.size()) = yAxisBis;
for (int i = 0; i < yAxis.size(); i++) {
yAxisFinal[yAxisBis.size() + i] = yAxis[i] + GetAxisYmax();
}
return yAxisFinal;
}
}
}
}
return yAxis;
}
void asAreaCompGrid::SetLastRowAsNewComposite()
{
wxASSERT(GetNbComposites() == 1);
asArea area1 = GetComposite(0);
Coo cornerLR1 = area1.GetCornerLR();
Coo cornerUR1 = area1.GetCornerUR();
a1d xAxis = GetXaxisComposite(0);
cornerLR1.x = xAxis[xAxis.size() - 2];
cornerUR1.x = xAxis[xAxis.size() - 2];
area1.SetCornerLR(cornerLR1);
area1.SetCornerUR(cornerUR1);
Coo cornerLR2 = area1.GetCornerLR();
Coo cornerUR2 = area1.GetCornerUR();
Coo cornerLL2 = area1.GetCornerLL();
Coo cornerUL2 = area1.GetCornerUL();
cornerLR2.x = 0;
cornerUR2.x = 0;
cornerLL2.x = 0;
cornerUL2.x = 0;
asArea area2(cornerUL2, cornerUR2, cornerLL2, cornerLR2, m_level, m_height, asFLAT_ALLOWED);
// Add the composite in this specific order to be consistent with the other implementations.
m_composites.clear();
m_composites.push_back(area2);
m_composites.push_back(area1);
}
void asAreaCompGrid::RemoveLastRowOnComposite(int i)
{
wxASSERT(GetNbComposites() > 1);
asArea area = GetComposite(i);
Coo cornerLR = area.GetCornerLR();
Coo cornerUR = area.GetCornerUR();
a1d xAxis = GetXaxisComposite(i);
cornerLR.x = xAxis[xAxis.size() - 2];
cornerUR.x = xAxis[xAxis.size() - 2];
area.SetCornerLR(cornerLR);
area.SetCornerUR(cornerUR);
m_composites[i] = area;
}