Different Renders for different roads

This commit is contained in:
glax 2024-07-23 04:24:52 +02:00
parent 61626a207b
commit 65d3c97fba
3 changed files with 40 additions and 36 deletions

View File

@ -1,49 +1,53 @@
using System.Drawing; using System.Drawing;
using System.Runtime.Versioning;
using astar.PathingHelper; using astar.PathingHelper;
using Graph; using Graph;
using static System.Drawing.Color;
namespace Graph_Renderer; namespace Graph_Renderer;
[SupportedOSPlatform("Windows")]
public static class Coloring 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)) if (!way.Tags.TryGetValue("highway", out string? highwayTypeStr))
return Color.Gray; return DefaultPen;
if (!Enum.TryParse(highwayTypeStr, out HighwayType highwayType)) if (!Enum.TryParse(highwayTypeStr, out HighwayType highwayType))
return Color.Gray; return DefaultPen;
return ColorDictionary[highwayType]; return ColorDictionary[highwayType];
} }
private static readonly Dictionary<HighwayType, Color> ColorDictionary = new() { private static readonly Dictionary<HighwayType, Pen> ColorDictionary = new() {
{ HighwayType.NONE, Color.Gray }, { HighwayType.NONE, DefaultPen },
{ HighwayType.motorway, Color.OrangeRed }, { HighwayType.motorway, new Pen(BlueViolet, 4) },
{ HighwayType.trunk, Color.Orange }, { HighwayType.trunk, new Pen(Violet, 3) },
{ HighwayType.primary, Color.Yellow }, { HighwayType.primary, new Pen(Yellow , 3) },
{ HighwayType.secondary, Color.Aqua }, { HighwayType.secondary, new Pen(Aqua ,2) },
{ HighwayType.tertiary, Color.Black }, { HighwayType.tertiary, new Pen(Black ,2) },
{ HighwayType.unclassified, Color.Gray }, { HighwayType.unclassified, DefaultPen },
{ HighwayType.residential, Color.Gray }, { HighwayType.residential, DefaultPen },
{ HighwayType.motorway_link, Color.OrangeRed }, { HighwayType.motorway_link, new Pen(BlueViolet, 2) },
{ HighwayType.trunk_link, Color.Orange }, { HighwayType.trunk_link, new Pen(Violet, 2) },
{ HighwayType.primary_link, Color.Yellow }, { HighwayType.primary_link, new Pen(Yellow , 2) },
{ HighwayType.secondary_link, Color.Aqua }, { HighwayType.secondary_link, new Pen(Aqua ,1) },
{ HighwayType.tertiary_link, Color.Black }, { HighwayType.tertiary_link, new Pen(Black ,1) },
{ HighwayType.living_street, Color.Gray }, { HighwayType.living_street, DefaultPen },
{ HighwayType.service, Color.Gray }, { HighwayType.service, DefaultPen },
{ HighwayType.pedestrian, Color.ForestGreen }, { HighwayType.pedestrian, new Pen(ForestGreen, 1) },
{ HighwayType.track, Color.Gray }, { HighwayType.track, DefaultPen },
{ HighwayType.bus_guideway, Color.Navy }, { HighwayType.bus_guideway, new Pen(Navy ,1) },
{ HighwayType.escape, Color.Gray }, { HighwayType.escape, DefaultPen },
{ HighwayType.raceway, Color.Gray }, { HighwayType.raceway, DefaultPen },
{ HighwayType.road, Color.Gray }, { HighwayType.road, DefaultPen },
{ HighwayType.busway, Color.Navy }, { HighwayType.busway, new Pen(Navy, 1) },
{ HighwayType.footway, Color.GreenYellow }, { HighwayType.footway, new Pen(GreenYellow ,1) },
{ HighwayType.bridleway, Color.Gray }, { HighwayType.bridleway, DefaultPen },
{ HighwayType.steps, Color.PaleGreen }, { HighwayType.steps, new Pen(PaleGreen, 1) },
{ HighwayType.corridor, Color.Green }, { HighwayType.corridor, new Pen(Green, 1) },
{ HighwayType.path, Color.Green }, { HighwayType.path, new Pen(Green, 1) },
{ HighwayType.cycleway, Color.Salmon }, { HighwayType.cycleway, new Pen(Salmon, 1) },
{ HighwayType.construction, Color.Gray } { HighwayType.construction, DefaultPen }
}; };
} }

View File

@ -36,7 +36,7 @@ if (!arguments.TryGetValue(regionArg, out string[]? regionVal) ||
Logger logger = new(LogLevel.Information, consoleOut: Console.Out); 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"); Renderer.Render(r, 30000, "render.png");

View File

@ -37,7 +37,7 @@ public static class Renderer
foreach ((ulong neighborNodeId, ulong wayId) in node.Neighbors.Where(kv => r.Graph.ContainsNode(kv.Key))) 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); 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 //Previous
@ -50,7 +50,7 @@ public static class Renderer
if (r.RouteFound) if (r.RouteFound)
{ {
Pen route = new(Color.BlueViolet, 2); Pen route = new(Color.Red, 2);
foreach (Step step in r.Steps) foreach (Step step in r.Steps)
{ {
Point startCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node1, minCoordinates, multiplier, bitmap.Height); Point startCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node1, minCoordinates, multiplier, bitmap.Height);