Save Pathfinding result to file.

Load result for render.
This commit is contained in:
2023-04-13 19:18:25 +02:00
parent 08ebc9a26b
commit 055a751c9d
8 changed files with 123 additions and 50 deletions

View File

@ -8,10 +8,12 @@
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OSMDatastructure\OSMDatastructure.csproj" />
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
</ItemGroup>
</Project>

View File

@ -1,20 +1,34 @@
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text.Json;
using OSMDatastructure.Graph;
using Pathfinding;
namespace RenderPath;
public class Renderer
{
[SuppressMessage("Interoperability", "CA1416:Plattformkompatibilität überprüfen")]
public static void DrawLoadedNodes(Dictionary<OsmNode, double> gScoreDict, List<Coordinates> pathCoordinates, string workingDir)
public static void DrawGraph(string resultPath)
{
float minLat = gScoreDict.Min(kv => kv.Key.coordinates.latitude);
float minLon = gScoreDict.Min(kv => kv.Key.coordinates.longitude);
float maxLat = gScoreDict.Max(kv => kv.Key.coordinates.latitude);
float maxLon = gScoreDict.Max(kv => kv.Key.coordinates.longitude);
FileStream fs = new FileStream(resultPath, FileMode.Open);
PathResult graph = JsonSerializer.Deserialize<PathResult>(fs)!;
List<Coordinates> coords = new List<Coordinates>();
foreach (PathNode node in graph.pathNodes)
coords.Add(node.coordinates);
string workingDir = new DirectoryInfo(resultPath).FullName;
DrawLoadedNodes(graph.nodes!, graph.gScore!, coords, workingDir);
}
[SuppressMessage("Interoperability", "CA1416:Plattformkompatibilität überprüfen")]
public static void DrawLoadedNodes(HashSet<OsmNode> nodes, Dictionary<ulong, double> gScoreDict, List<Coordinates> pathCoordinates, string workingDir)
{
float minLat = nodes.Min(node => node.coordinates.latitude);
float minLon = nodes.Min(node => node.coordinates.longitude);
float maxLat = nodes.Max(node => node.coordinates.latitude);
float maxLon = nodes.Max(node => node.coordinates.longitude);
double minWeight = gScoreDict.Min(kv => kv.Value);
double maxWeight = gScoreDict.Max(kv => kv.Value);
@ -36,12 +50,14 @@ public class Renderer
Color center = Color.FromArgb(255, 255, 0);
Color end = Color.FromArgb(0, 255, 0);
foreach (KeyValuePair<OsmNode, double> kv in gScoreDict)
foreach (KeyValuePair<ulong, double> kv in gScoreDict)
{
double percentage = (kv.Value - minWeight) / (maxWeight - minWeight);
Brush b = new SolidBrush(GradientPick(percentage, start, center, end));
float x = (kv.Key.coordinates.longitude - minLon) * scaleFactor;
float y = (maxLat - kv.Key.coordinates.latitude) * scaleFactor;
OsmNode node = nodes.First(node => node.nodeId.Equals(kv.Key));
float x = (node.coordinates.longitude - minLon) * scaleFactor;
float y = (maxLat - node.coordinates.latitude) * scaleFactor;
g.FillEllipse(b, x, y, 2, 2);
}
@ -56,7 +72,7 @@ public class Renderer
g.DrawLine(p, p1, p2);
}
ret.Save(Path.Join(Directory.GetParent(workingDir)!.FullName, "routing.png"), ImageFormat.Bmp);
ret.Save($"{workingDir}-routing.png", ImageFormat.Bmp);
}
/*