Added visualization to confirm paths
This commit is contained in:
17
RenderPath/RenderPath.csproj
Normal file
17
RenderPath/RenderPath.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
46
RenderPath/Renderer.cs
Normal file
46
RenderPath/Renderer.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Pathfinding;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using OSMDatastructure.Graph;
|
||||
|
||||
namespace RenderPath;
|
||||
|
||||
public class Renderer
|
||||
{
|
||||
[SuppressMessage("Interoperability", "CA1416:Plattformkompatibilität überprüfen")]
|
||||
public static Bitmap DrawFromPath(List<PathNode> nodes)
|
||||
{
|
||||
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);
|
||||
|
||||
float latDiff = maxLat - minLat;
|
||||
float lonDiff = maxLon - minLon;
|
||||
|
||||
const int imageMaxSize = 10000;
|
||||
float scaleFactor = latDiff > lonDiff ? imageMaxSize / latDiff : imageMaxSize / lonDiff;
|
||||
|
||||
int pixelsX = (int)(lonDiff * scaleFactor);
|
||||
int pixelsY = (int)(latDiff * scaleFactor);
|
||||
|
||||
Bitmap ret = new Bitmap(pixelsX, pixelsY, PixelFormat.Format32bppRgb);
|
||||
|
||||
Graphics g = Graphics.FromImage(ret);
|
||||
Pen p = new Pen(Color.Black, 2);
|
||||
g.Clear(Color.White);
|
||||
|
||||
for (int i = 0; i < nodes.Count - 1; i++)
|
||||
{
|
||||
Coordinates c1 = nodes[i].coordinates;
|
||||
Coordinates c2 = nodes[i+1].coordinates;
|
||||
Point p1 = new(Convert.ToInt32((c1.longitude - minLon) * scaleFactor), Convert.ToInt32((maxLat - c1.latitude) * scaleFactor));
|
||||
Point p2 = new(Convert.ToInt32((c2.longitude - minLon) * scaleFactor), Convert.ToInt32((maxLat - c2.latitude) * scaleFactor));
|
||||
g.DrawLine(p, p1, p2);
|
||||
}
|
||||
|
||||
ret.Save(@"D:\render.png", ImageFormat.Bmp);
|
||||
return ret;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user