From b87d8a03002243c9d1a8e332e108d39309255be6 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 20 Apr 2023 19:41:40 +0200 Subject: [PATCH] Changed calls to new backend. Pathfinder now finds the result and returns itself. Pathfinder includes PathResult for later usage. --- API/Program.cs | 9 ++++----- Server/Server.cs | 26 ++++++++++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/API/Program.cs b/API/Program.cs index ef175b3..56182bc 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -16,20 +16,19 @@ var app = builder.Build(); app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lonEnd, Tag.SpeedType vehicle, double stayOnSameRoadPriority, double useHigherLevelRoadsPriority, double useRoadsWithLessJunctionsPriority) => { - - PathResult result = Pathfinder.AStar("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart), + Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest").AStar(new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd), vehicle, useHigherLevelRoadsPriority, stayOnSameRoadPriority, useRoadsWithLessJunctionsPriority); - return result; + return result.pathResult; } ); app.MapGet("/getShortestRoute", (float latStart, float lonStart, float latEnd, float lonEnd) => { - PathResult result = Pathfinder.AStar("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart), + Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest").AStar(new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd), Tag.SpeedType.any, 0, 0, 0); - return result; + return result.pathResult; } ); diff --git a/Server/Server.cs b/Server/Server.cs index d3dfcce..2dcf16c 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -1,4 +1,5 @@ using System.Drawing; +using System.Drawing.Imaging; using OSMDatastructure; using OSMDatastructure.Graph; using Pathfinding; @@ -11,25 +12,30 @@ public class Server public static void Main(string[] args) { - ConsoleWriter newConsole = new ConsoleWriter(); + ConsoleWriter newConsole = new(); Console.SetOut(newConsole); Console.SetError(newConsole); + + string workingDir = "D:/stuttgart-regbez-latest"; //RegionConverter.ConvertXMLToRegions("D:/stuttgart-regbez-latest.osm", "D:/stuttgart-regbez-latest"); //RegionConverter.ConvertXMLToRegions("D:/map.osm", "D:/map"); //RegionConverter.ConvertXMLToRegions("D:/germany-latest.osm", "D:/germany-latest"); - - Coordinates start = new Coordinates(48.7933798f, 9.8275859f); - Coordinates finish = new Coordinates(48.795918f, 9.021618f); - PathResult result = Pathfinder.AStar("D:/stuttgart-regbez-latest", start, + Coordinates start = new (48.7933798f, 9.8275859f); + Coordinates finish = new (48.795918f, 9.021618f); + Pathfinder result = new Pathfinder(workingDir).AStar(start, finish, Tag.SpeedType.car, 0.01, 0.0001, 0); - Console.WriteLine("Drawing area"); - ValueTuple area = Renderer.DrawArea(result.regionManager); - - Console.WriteLine("Drawing route"); - Renderer.DrawGraph(result.name, area.Item1, area.Item2); + string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName; + string resultFileName = $"{new DirectoryInfo(workingDir).Name}-{DateTime.Now.ToFileTime()}.result"; + result.SaveResult(Path.Join(parentFolder, resultFileName)); + + string renderFileName = $"{new DirectoryInfo(workingDir).Name}-{DateTime.Now.ToFileTime()}.render.png"; + Image render = Renderer.DrawPathfinder(result); +#pragma warning disable CA1416 + render.Save(Path.Join(parentFolder, renderFileName), ImageFormat.Png); +#pragma warning restore CA1416 } } \ No newline at end of file