3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Printing.hpp"
26 #include "TestUtil.hpp"
27 #include "Route/TerrainRoute.hpp"
28 #include "Terrain/RasterMap.hpp"
29 #include "OS/ConvertPathName.hpp"
30 #include "Compatibility/path.h"
31 #include "GlideSolvers/GlideSettings.hpp"
32 #include "GlideSolvers/GlidePolar.hpp"
33 #include "Geo/SpeedVector.hpp"
34 #include "Geo/GeoVector.hpp"
35 #include "Operation/Operation.hpp"
36 #include "OS/FileUtil.hpp"
41 test_troute(const RasterMap
& map
, fixed mwind
, fixed mc
, RoughAltitude ceiling
)
43 GlideSettings settings
;
44 settings
.SetDefaults();
46 SpeedVector
wind(Angle::Degrees(0), mwind
);
48 route
.UpdatePolar(settings
, polar
, polar
, wind
);
49 route
.SetTerrain(&map
);
51 GeoPoint
origin(map
.GetMapCenter());
53 fixed pd
= map
.PixelDistance(origin
, 1);
54 printf("# pixel size %g\n", (double)pd
);
59 Directory::Create(_T("output/results"));
60 std::ofstream
fout ("output/results/terrain.txt");
63 for (unsigned i
=0; i
< nx
; ++i
) {
64 for (unsigned j
=0; j
< ny
; ++j
) {
65 fixed fx
= (fixed
)i
/ (nx
- 1) * 2 - fixed(1);
66 fixed fy
= (fixed
)j
/ (ny
- 1) * 2 - fixed(1);
67 GeoPoint
x(origin
.longitude
+ Angle::Degrees(fixed(0.6) * fx
),
68 origin
.latitude
+ Angle::Degrees(fixed(0.4) * fy
));
69 short h
= map
.GetInterpolatedHeight(x
);
70 fout
<< x
.longitude
.Degrees() << " " << x
.latitude
.Degrees() << " " << h
<< "\n";
77 RoutePlannerConfig config
;
78 config
.mode
= RoutePlannerConfig::Mode::BOTH
;
81 for (fixed ang
= fixed(0); ang
< fixed_two_pi
; ang
+= fixed(M_PI
/ 8)) {
82 GeoPoint dest
= GeoVector(fixed(40000.0), Angle::Radians(ang
)).EndPoint(origin
);
84 short hdest
= map
.GetHeight(dest
)+100;
86 retval
= route
.Solve(AGeoPoint(origin
,
87 RoughAltitude(map
.GetHeight(origin
) + 100)),
89 RoughAltitude(positive(mc
)
91 : std::max(hdest
, (short)3200))),
94 sprintf(buffer
,"terrain route solve, dir=%g, wind=%g, mc=%g ceiling=%d",
95 (double)ang
, (double)mwind
, (double)mc
, (int)ceiling
);
96 ok(retval
, buffer
, 0);
97 PrintHelper::print_route(route
);
101 // polar.SetMC(fixed(0));
102 // route.UpdatePolar(polar, wind);
105 int main(int argc
, char** argv
) {
107 const char hc_path
[] = "tmp/terrain";
108 const char *map_path
;
109 if ((argc
<2) || !strlen(argv
[0])) {
115 TCHAR jp2_path
[4096];
116 _tcscpy(jp2_path
, PathName(map_path
));
117 _tcscat(jp2_path
, _T(DIR_SEPARATOR_S
) _T("terrain.jp2"));
119 TCHAR j2w_path
[4096];
120 _tcscpy(j2w_path
, PathName(map_path
));
121 _tcscat(j2w_path
, _T(DIR_SEPARATOR_S
) _T("terrain.j2w"));
123 NullOperationEnvironment operation
;
124 RasterMap
map(jp2_path
, j2w_path
, NULL
, operation
);
126 map
.SetViewCenter(map
.GetMapCenter(), fixed(100000));
127 } while (map
.IsDirty());
130 test_troute(map
, fixed(0), fixed(0.1), RoughAltitude(10000));
131 test_troute(map
, fixed(0), fixed(0), RoughAltitude(10000));
132 test_troute(map
, fixed(5.0), fixed(1), RoughAltitude(10000));
134 return exit_status();