Added visualization to confirm paths

This commit is contained in:
glax 2023-04-13 00:24:33 +02:00
parent 13915c9773
commit a70284aa87
6 changed files with 79 additions and 14 deletions

View File

@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
<ProjectReference Include="..\RenderPath\RenderPath.csproj" />
</ItemGroup>
</Project>

View File

@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pathfinding", "Pathfinding\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{1D364F40-1681-4D36-A625-83B324F6AC89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenderPath", "RenderPath\RenderPath.csproj", "{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -30,5 +32,9 @@ Global
{1D364F40-1681-4D36-A625-83B324F6AC89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D364F40-1681-4D36-A625-83B324F6AC89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D364F40-1681-4D36-A625-83B324F6AC89}.Release|Any CPU.Build.0 = Release|Any CPU
{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54CAC127-4EB6-4E06-A5C8-35343C5FF76A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View 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
View 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;
}
}

View File

@ -13,21 +13,15 @@ public class Server
Console.SetOut(newConsole);
Console.SetError(newConsole);
RegionConverter.ConvertXMLToRegions("D:/stuttgart-regbez-latest.osm", "D:/stuttgart-regbez-latest");
//RegionConverter.ConvertXMLToRegions("D:/stuttgart-regbez-latest.osm", "D:/stuttgart-regbez-latest");
//RegionConverter.ConvertXMLToRegions("D:/map.osm", "D:/map");
//RegionConverter.ConvertXMLToRegions("D:/germany-latest.osm", "D:/germany-latest");
/*
Coordinates start = new Coordinates(48.794567f, 9.820625f);
Coordinates finish = new Coordinates(48.79593f, 9.824013f);
DateTime startTime = DateTime.Now;
OsmNode[] path = Pathfinder.CustomAStar("D:/map", start, finish, Tag.SpeedType.car).ToArray();
TimeSpan duration = DateTime.Now - startTime;
Console.WriteLine($"Took {duration.TotalMilliseconds}ms ({duration:g})");
for (int i = 0; i < path.Length - 1; i++)
{
Console.WriteLine(path[i]);
}
Console.WriteLine();*/
Coordinates start = new Coordinates( 48.7933798f, 9.8275859f);
Coordinates finish = new Coordinates( 48.8407632f, 10.0676979f);
List<PathNode> result = Pathfinder.AStar("D:/stuttgart-regbez-latest", start,
finish, Tag.SpeedType.car, 20, 2,
0);
RenderPath.Renderer.DrawFromPath(result);
}
}

View File

@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\Pathfinding\Pathfinding.csproj" />
<ProjectReference Include="..\RenderPath\RenderPath.csproj" />
</ItemGroup>
<ItemGroup>