static void test_reach(const RasterMap& map, fixed mwind, fixed mc) { GlideSettings settings; settings.SetDefaults(); GlidePolar polar(mc); SpeedVector wind(Angle::Degrees(0), mwind); TerrainRoute route; route.UpdatePolar(settings, polar, polar, wind); route.SetTerrain(&map); GeoPoint origin(map.GetMapCenter()); fixed pd = map.PixelDistance(origin, 1); printf("# pixel size %g\n", (double)pd); bool retval= true; short horigin = map.GetHeight(origin)+1000; AGeoPoint aorigin(origin, RoughAltitude(horigin)); RoutePlannerConfig config; config.SetDefaults(); retval = route.SolveReach(aorigin, config, RoughAltitude::Max()); ok(retval, "reach solve", 0); PrintHelper::print_reach_tree(route); GeoPoint dest(origin.longitude-Angle::Degrees(0.02), origin.latitude-Angle::Degrees(0.02)); { Directory::Create(_T("output/results")); std::ofstream fout("output/results/terrain.txt"); unsigned nx = 100; unsigned ny = 100; for (unsigned i=0; i< nx; ++i) { for (unsigned j=0; j< ny; ++j) { fixed fx = (fixed)i / (nx - 1) * 2 - fixed(1); fixed fy = (fixed)j / (ny - 1) * 2 - fixed(1); GeoPoint x(origin.longitude + Angle::Degrees(fixed(0.6) * fx), origin.latitude + Angle::Degrees(fixed(0.6) * fy)); short h = map.GetInterpolatedHeight(x); AGeoPoint adest(x, RoughAltitude(h)); ReachResult reach; route.FindPositiveArrival(adest, reach); if ((i % 5 == 0) && (j % 5 == 0)) { AGeoPoint ao2(x, RoughAltitude(h + 1000)); route.SolveReach(ao2, config, RoughAltitude::Max()); } fout << x.longitude.Degrees() << " " << x.latitude.Degrees() << " " << h << " " << (int)reach.terrain << "\n"; } fout << "\n"; } fout << "\n"; } }
void RasterRenderer::ScanMap(const RasterMap &map, const WindowProjection &projection) { // Coordinates of the MapWindow center unsigned x = projection.GetScreenWidth() / 2; unsigned y = projection.GetScreenHeight() / 2; // GeoPoint corresponding to the MapWindow center GeoPoint center = projection.ScreenToGeo(x, y); // GeoPoint "next to" Gmid (depends on terrain resolution) GeoPoint neighbor = projection.ScreenToGeo(x + quantisation_pixels, y + quantisation_pixels); // Geographical edge length of pixel in the MapWindow center in meters pixel_size = M_SQRT1_2 * center.DistanceS(neighbor); // set resolution if (pixel_size < 3000) { // Data point size of the (terrain) map in meters multiplied by 256 auto map_pixel_size = map.PixelDistance(center, 1); // How many screen pixels does one data point stretch? auto q = map_pixel_size / pixel_size; /* round down to reduce slope shading artefacts (caused by RasterBuffer interpolation) */ quantisation_effective = std::max(1, (int)q); /* disable slope shading when zoomed in very near (not enough terrain resolution to make a useful slope calculation) */ if (quantisation_effective > 25) quantisation_effective = 0; } else /* disable slope shading when zoomed out very far (too tiny) */ quantisation_effective = 0; #ifdef ENABLE_OPENGL bounds = projection.GetScreenBounds().Scale(1.5); bounds.IntersectWith(map.GetBounds()); height_matrix.Fill(map, bounds, projection.GetScreenWidth() / quantisation_pixels, projection.GetScreenHeight() / quantisation_pixels, true); last_quantisation_pixels = quantisation_pixels; #else height_matrix.Fill(map, projection, quantisation_pixels, true); #endif }
void RasterRenderer::ScanMap(const RasterMap &map, const WindowProjection &projection) { // Coordinates of the MapWindow center unsigned x = projection.GetScreenWidth() / 2; unsigned y = projection.GetScreenHeight() / 2; // GeoPoint corresponding to the MapWindow center GeoPoint Gmid = projection.ScreenToGeo(x, y); // GeoPoint "next to" Gmid (depends on terrain resolution) GeoPoint Gneighbor = projection.ScreenToGeo(x + quantisation_pixels, y + quantisation_pixels); // Geographical edge length of pixel in the MapWindow center in meters pixel_size = fixed_sqrt_half * Gmid.Distance(Gneighbor); // set resolution if (pixel_size < fixed(3000)) { /* round down to reduce slope shading artefacts (caused by RasterBuffer interpolation) */ fixed map_pixel_size = map.PixelDistance(Gmid, 1); fixed q = map_pixel_size / pixel_size; quantisation_effective = std::max(1, (int)q); if (quantisation_effective > 25) /* disable slope shading when zoomed in very near (not enough terrain resolution to make a useful slope calculation) */ quantisation_effective = 0; } else /* disable slope shading when zoomed out very far (too tiny) */ quantisation_effective = 0; #ifdef ENABLE_OPENGL bounds = projection.GetScreenBounds().Scale(fixed(1.5)); height_matrix.Fill(map, bounds, projection.GetScreenWidth() / quantisation_pixels, projection.GetScreenHeight() / quantisation_pixels, true); last_quantisation_pixels = quantisation_pixels; #else height_matrix.Fill(map, projection, quantisation_pixels, true); #endif }
static void test_troute(const RasterMap& map, fixed mwind, fixed mc, RoughAltitude ceiling) { GlideSettings settings; settings.SetDefaults(); GlidePolar polar(mc); SpeedVector wind(Angle::Degrees(0), mwind); TerrainRoute route; route.UpdatePolar(settings, polar, polar, wind); route.SetTerrain(&map); GeoPoint origin(map.GetMapCenter()); fixed pd = map.PixelDistance(origin, 1); printf("# pixel size %g\n", (double)pd); bool retval= true; { Directory::Create(_T("output/results")); std::ofstream fout ("output/results/terrain.txt"); unsigned nx = 100; unsigned ny = 100; for (unsigned i=0; i< nx; ++i) { for (unsigned j=0; j< ny; ++j) { fixed fx = (fixed)i / (nx - 1) * 2 - fixed(1); fixed fy = (fixed)j / (ny - 1) * 2 - fixed(1); GeoPoint x(origin.longitude + Angle::Degrees(fixed(0.6) * fx), origin.latitude + Angle::Degrees(fixed(0.4) * fy)); short h = map.GetInterpolatedHeight(x); fout << x.longitude.Degrees() << " " << x.latitude.Degrees() << " " << h << "\n"; } fout << "\n"; } fout << "\n"; } RoutePlannerConfig config; config.mode = RoutePlannerConfig::Mode::BOTH; unsigned i=0; for (fixed ang = fixed(0); ang < fixed_two_pi; ang += fixed(M_PI / 8)) { GeoPoint dest = GeoVector(fixed(40000.0), Angle::Radians(ang)).EndPoint(origin); short hdest = map.GetHeight(dest)+100; retval = route.Solve(AGeoPoint(origin, RoughAltitude(map.GetHeight(origin) + 100)), AGeoPoint(dest, RoughAltitude(positive(mc) ? hdest : std::max(hdest, (short)3200))), config, ceiling); char buffer[80]; sprintf(buffer,"terrain route solve, dir=%g, wind=%g, mc=%g ceiling=%d", (double)ang, (double)mwind, (double)mc, (int)ceiling); ok(retval, buffer, 0); PrintHelper::print_route(route); i++; } // polar.SetMC(fixed(0)); // route.UpdatePolar(polar, wind); }
static void test_troute(const RasterMap &map, double mwind, double mc, int ceiling) { GlideSettings settings; settings.SetDefaults(); RoutePlannerConfig config; config.mode = RoutePlannerConfig::Mode::BOTH; GlidePolar polar(mc); SpeedVector wind(Angle::Degrees(0), mwind); TerrainRoute route; route.UpdatePolar(settings, config, polar, polar, wind); route.SetTerrain(&map); GeoPoint origin(map.GetMapCenter()); auto pd = map.PixelDistance(origin, 1); printf("# pixel size %g\n", (double)pd); bool retval= true; { Directory::Create(Path(_T("output/results"))); std::ofstream fout ("output/results/terrain.txt"); unsigned nx = 100; unsigned ny = 100; for (unsigned i=0; i< nx; ++i) { for (unsigned j=0; j< ny; ++j) { auto fx = (double)i / (nx - 1) * 2 - 1; auto fy = (double)j / (ny - 1) * 2 - 1; GeoPoint x(origin.longitude + Angle::Degrees(0.6 * fx), origin.latitude + Angle::Degrees(0.4 * fy)); TerrainHeight h = map.GetInterpolatedHeight(x); fout << x.longitude.Degrees() << " " << x.latitude.Degrees() << " " << h.GetValue() << "\n"; } fout << "\n"; } fout << "\n"; } unsigned i=0; for (double ang = 0; ang < M_2PI; ang += M_PI / 8) { GeoPoint dest = GeoVector(40000.0, Angle::Radians(ang)).EndPoint(origin); int hdest = map.GetHeight(dest).GetValueOr0() + 100; retval = route.Solve(AGeoPoint(origin, map.GetHeight(origin).GetValueOr0() + 100), AGeoPoint(dest, mc > 0 ? hdest : std::max(hdest, 3200)), config, ceiling); char buffer[80]; sprintf(buffer,"terrain route solve, dir=%g, wind=%g, mc=%g ceiling=%d", (double)ang, (double)mwind, (double)mc, (int)ceiling); ok(retval, buffer, 0); PrintHelper::print_route(route); i++; } // polar.SetMC(0); // route.UpdatePolar(polar, wind); }