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.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<HighwayType, Color> 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<HighwayType, Pen> 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 }
};
}

View File

@ -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");

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)))
{
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);