From 65d3c97fba964916f5f8baa36eb39b7d161d24a2 Mon Sep 17 00:00:00 2001 From: glax Date: Tue, 23 Jul 2024 04:24:52 +0200 Subject: [PATCH] Different Renders for different roads --- Graph_Renderer/Coloring.cs | 70 ++++++++++++++++++++------------------ Graph_Renderer/Program.cs | 2 +- Graph_Renderer/Renderer.cs | 4 +-- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/Graph_Renderer/Coloring.cs b/Graph_Renderer/Coloring.cs index e9e0c94..760778a 100644 --- a/Graph_Renderer/Coloring.cs +++ b/Graph_Renderer/Coloring.cs @@ -1,49 +1,53 @@ using System.Drawing; +using System.Runtime.Versioning; using astar.PathingHelper; using Graph; +using static System.Drawing.Color; namespace Graph_Renderer; +[SupportedOSPlatform("Windows")] public static class Coloring { - public static Color GetColorForWay(Way way) + public static Pen DefaultPen = new(Gray, 2); + public static Pen GetPenForWay(Way way) { if (!way.Tags.TryGetValue("highway", out string? highwayTypeStr)) - return Color.Gray; + return DefaultPen; if (!Enum.TryParse(highwayTypeStr, out HighwayType highwayType)) - return Color.Gray; + return DefaultPen; return ColorDictionary[highwayType]; } - private static readonly Dictionary ColorDictionary = new() { - { HighwayType.NONE, Color.Gray }, - { HighwayType.motorway, Color.OrangeRed }, - { HighwayType.trunk, Color.Orange }, - { HighwayType.primary, Color.Yellow }, - { HighwayType.secondary, Color.Aqua }, - { HighwayType.tertiary, Color.Black }, - { HighwayType.unclassified, Color.Gray }, - { HighwayType.residential, Color.Gray }, - { HighwayType.motorway_link, Color.OrangeRed }, - { HighwayType.trunk_link, Color.Orange }, - { HighwayType.primary_link, Color.Yellow }, - { HighwayType.secondary_link, Color.Aqua }, - { HighwayType.tertiary_link, Color.Black }, - { HighwayType.living_street, Color.Gray }, - { HighwayType.service, Color.Gray }, - { HighwayType.pedestrian, Color.ForestGreen }, - { HighwayType.track, Color.Gray }, - { HighwayType.bus_guideway, Color.Navy }, - { HighwayType.escape, Color.Gray }, - { HighwayType.raceway, Color.Gray }, - { HighwayType.road, Color.Gray }, - { HighwayType.busway, Color.Navy }, - { HighwayType.footway, Color.GreenYellow }, - { HighwayType.bridleway, Color.Gray }, - { HighwayType.steps, Color.PaleGreen }, - { HighwayType.corridor, Color.Green }, - { HighwayType.path, Color.Green }, - { HighwayType.cycleway, Color.Salmon }, - { HighwayType.construction, Color.Gray } + private static readonly Dictionary ColorDictionary = new() { + { HighwayType.NONE, DefaultPen }, + { HighwayType.motorway, new Pen(BlueViolet, 4) }, + { HighwayType.trunk, new Pen(Violet, 3) }, + { HighwayType.primary, new Pen(Yellow , 3) }, + { HighwayType.secondary, new Pen(Aqua ,2) }, + { HighwayType.tertiary, new Pen(Black ,2) }, + { HighwayType.unclassified, DefaultPen }, + { HighwayType.residential, DefaultPen }, + { HighwayType.motorway_link, new Pen(BlueViolet, 2) }, + { HighwayType.trunk_link, new Pen(Violet, 2) }, + { HighwayType.primary_link, new Pen(Yellow , 2) }, + { HighwayType.secondary_link, new Pen(Aqua ,1) }, + { HighwayType.tertiary_link, new Pen(Black ,1) }, + { HighwayType.living_street, DefaultPen }, + { HighwayType.service, DefaultPen }, + { HighwayType.pedestrian, new Pen(ForestGreen, 1) }, + { HighwayType.track, DefaultPen }, + { HighwayType.bus_guideway, new Pen(Navy ,1) }, + { HighwayType.escape, DefaultPen }, + { HighwayType.raceway, DefaultPen }, + { HighwayType.road, DefaultPen }, + { HighwayType.busway, new Pen(Navy, 1) }, + { HighwayType.footway, new Pen(GreenYellow ,1) }, + { HighwayType.bridleway, DefaultPen }, + { HighwayType.steps, new Pen(PaleGreen, 1) }, + { HighwayType.corridor, new Pen(Green, 1) }, + { HighwayType.path, new Pen(Green, 1) }, + { HighwayType.cycleway, new Pen(Salmon, 1) }, + { HighwayType.construction, DefaultPen } }; } \ No newline at end of file diff --git a/Graph_Renderer/Program.cs b/Graph_Renderer/Program.cs index daf48c4..f40a278 100644 --- a/Graph_Renderer/Program.cs +++ b/Graph_Renderer/Program.cs @@ -36,7 +36,7 @@ if (!arguments.TryGetValue(regionArg, out string[]? regionVal) || Logger logger = new(LogLevel.Information, consoleOut: Console.Out); -Route r = Astar.FindPath(startLat, startLon, endLat, endLon, regionSize, true, importPathVal[0], logger); +Route r = Astar.FindPath(startLat, startLon, endLat, endLon, regionSize, true, importPathVal[0]); Renderer.Render(r, 30000, "render.png"); diff --git a/Graph_Renderer/Renderer.cs b/Graph_Renderer/Renderer.cs index aa8b5cf..7b1f866 100644 --- a/Graph_Renderer/Renderer.cs +++ b/Graph_Renderer/Renderer.cs @@ -37,7 +37,7 @@ public static class Renderer foreach ((ulong neighborNodeId, ulong wayId) in node.Neighbors.Where(kv => r.Graph.ContainsNode(kv.Key))) { Point endCoordinates = PixelCoordinatesFromGeoCoordinates(r.Graph.Nodes[neighborNodeId], minCoordinates, multiplier, bitmap.Height); - graphics.DrawLine(new Pen(Coloring.GetColorForWay(r.Graph.Ways[wayId]), 2), startCoordinates, endCoordinates); + graphics.DrawLine(Coloring.GetPenForWay(r.Graph.Ways[wayId]), startCoordinates, endCoordinates); } //Previous @@ -50,7 +50,7 @@ public static class Renderer if (r.RouteFound) { - Pen route = new(Color.BlueViolet, 2); + Pen route = new(Color.Red, 2); foreach (Step step in r.Steps) { Point startCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node1, minCoordinates, multiplier, bitmap.Height);