From 6f1beb2254746eb8cffb4565f22da64fa31c9f4e Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Tue, 15 Feb 2022 10:44:38 +0100 Subject: [PATCH] [VECTO] Upgrade to NET5.0 --- VECTO/VECTO.vbproj | 32 +++++++-- VectoCore/VectoCore/Utils/DelaunayMap.cs | 69 ++++++++++++++++++++ VectoCore/VectoCore/VectoCore.csproj | 27 +++++--- VectoCore/VectoCoreTest/VectoCoreTest.csproj | 6 -- 4 files changed, 115 insertions(+), 19 deletions(-) diff --git a/VECTO/VECTO.vbproj b/VECTO/VECTO.vbproj index 237da87a28..3819e88f52 100644 --- a/VECTO/VECTO.vbproj +++ b/VECTO/VECTO.vbproj @@ -13,6 +13,7 @@ <Configurations>Debug;Release;Deploy</Configurations> <DefineDebug>false</DefineDebug> <DefineTrace>false</DefineTrace> + <TargetFrameworks>net45;net48;net5.0-windows</TargetFrameworks> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> @@ -28,17 +29,38 @@ </PackageReference> </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\VectoCommon\VectoCommon\VectoCommon.csproj" /> - <ProjectReference Include="..\VectoCore\VectoCore\VectoCore.csproj" /> + + <ItemGroup Condition="'$(TargetFramework)'=='net45'"> + <Reference Include="Microsoft.Build.Framework" /> + <Reference Include="System.ComponentModel.DataAnnotations" /> + <Reference Include="System.Windows.Forms.DataVisualization" /> </ItemGroup> - - <ItemGroup> + + <ItemGroup Condition="'$(TargetFramework)'=='net48'"> <Reference Include="Microsoft.Build.Framework" /> <Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.Windows.Forms.DataVisualization" /> </ItemGroup> + + + <ItemGroup Condition="'$(TargetFramework)'=='net5.0-windows'"> + <PackageReference Include="System.Drawing.Common" Version="6.0.0" /> + <Reference Include="System.Windows.Forms"> + <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.dll</HintPath> + </Reference> + <Reference Include="System.Windows.Forms.DataVisualization"> + <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.DataVisualization.dll</HintPath> + </Reference> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\VectoCommon\VectoCommon\VectoCommon.csproj" /> + <ProjectReference Include="..\VectoCore\VectoCore\VectoCore.csproj" /> + </ItemGroup> + + + <ItemGroup> <Import Include="Microsoft.VisualBasic" /> <Import Include="System" /> diff --git a/VectoCore/VectoCore/Utils/DelaunayMap.cs b/VectoCore/VectoCore/Utils/DelaunayMap.cs index b7f4ce81b8..bd42c4ab5d 100644 --- a/VectoCore/VectoCore/Utils/DelaunayMap.cs +++ b/VectoCore/VectoCore/Utils/DelaunayMap.cs @@ -31,8 +31,12 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.IO; using System.Linq; using System.Runtime.CompilerServices; +using System.Windows.Forms.DataVisualization.Charting; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; @@ -126,6 +130,7 @@ namespace TUGraz.VectoCore.Utils triangles.AddRange(newTriangles); + //DrawGraph(pointCount, triangles, superTriangle, xmin, xmax, ymin, ymax, point); pointCount++; // check invariant: m = 2n-2-k @@ -138,6 +143,9 @@ namespace TUGraz.VectoCore.Utils } } +#if TRACE + DrawGraph(pointCount, triangles, superTriangle, points); +#endif _convexHull = triangles.FindAll(t => t.SharesVertexWith(superTriangle)). SelectMany(t => t.GetEdges()). Where(e => !(superTriangle.Contains(e.P1) || superTriangle.Contains(e.P2))).ToArray(); @@ -158,6 +166,67 @@ namespace TUGraz.VectoCore.Utils } } + public void DrawGraph() + { + var superTriangle = new Triangle(new Point(-1, -1), new Point(4, -1), new Point(-1, 4)); + DrawGraph(0, _triangles, superTriangle, _points.ToArray()); + } + + /// <summary> + /// Draws the delaunay map (except supertriangle). + /// </summary> + private static void DrawGraph(int i, IEnumerable<Triangle> triangles, Triangle superTriangle, Point[] points, + Point lastPoint = null) + { + var xmin = Math.Min(points.Min(p => p.X), lastPoint?.X ?? double.NaN); + var xmax = Math.Max(points.Max(p => p.X), lastPoint?.X ?? double.NaN); + var ymin = Math.Min(points.Min(p => p.Y), lastPoint?.Y ?? double.NaN); + var ymax = Math.Max(points.Max(p => p.Y), lastPoint?.Y ?? double.NaN); + + using (var chart = new Chart { Width = 1000, Height = 1000 }) { + chart.ChartAreas.Add(new ChartArea("main") { + AxisX = new Axis { Minimum = Math.Min(xmin, xmin), Maximum = Math.Max(xmax, xmax) }, + AxisY = new Axis { Minimum = Math.Min(ymin, ymin), Maximum = Math.Max(ymax, ymax) } + }); + + foreach (var tr in triangles) { + if (tr.SharesVertexWith(superTriangle)) { + continue; + } + + var series = new Series { + ChartType = SeriesChartType.FastLine, + Color = lastPoint != null && tr.Contains(lastPoint) ? Color.Red : Color.Blue + }; + series.Points.AddXY(tr.P1.X, tr.P1.Y); + series.Points.AddXY(tr.P2.X, tr.P2.Y); + series.Points.AddXY(tr.P3.X, tr.P3.Y); + series.Points.AddXY(tr.P1.X, tr.P1.Y); + chart.Series.Add(series); + } + + if (lastPoint != null) { + var series = new Series { + ChartType = SeriesChartType.Point, + Color = Color.Red, + MarkerSize = 5, + MarkerStyle = MarkerStyle.Circle + }; + series.Points.AddXY(lastPoint.X, lastPoint.Y); + chart.Series.Add(series); + } + + var frame = new StackFrame(2); + var method = frame.GetMethod(); + System.Diagnostics.Debug.Assert(method.DeclaringType != null, "method.DeclaringType != null"); + var type = method.DeclaringType.Name.Split(Path.GetInvalidFileNameChars()).Join(""); + var methodName = method.Name.Split(Path.GetInvalidFileNameChars()).Join(""); + Directory.CreateDirectory("delaunay"); + chart.SaveImage($"delaunay\\{type}_{methodName}_{superTriangle.GetHashCode()}_{i}.png", + ChartImageFormat.Png); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public double Interpolate(SI x, SI y) { diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj index 1cd43f48c1..819ecfad0b 100644 --- a/VectoCore/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore/VectoCore.csproj @@ -12,19 +12,33 @@ <PackageReference Include="Ninject.Extensions.Factory" Version="3.3.3" /> <PackageReference Include="NLog" Version="4.7.13" /> <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" /> - - </ItemGroup> + </ItemGroup> - <ItemGroup Condition="'$(TargetFramework)'=='net45'" > + <ItemGroup Condition="'$(TargetFramework)'=='net45'"> <Reference Include="Microsoft.VisualBasic" /> <PackageReference Include="System.ValueTuple" Version="4.5.0" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Windows.Forms.DataVisualization" /> </ItemGroup> - <ItemGroup Condition="'$(TargetFramework)'=='net48'" > + <ItemGroup Condition="'$(TargetFramework)'=='net48'"> <Reference Include="Microsoft.VisualBasic" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Windows.Forms.DataVisualization" /> </ItemGroup> + <ItemGroup Condition="'$(TargetFramework)'=='net5.0'"> + <PackageReference Include="System.Drawing.Common" Version="6.0.0" /> + <Reference Include="System.Windows.Forms"> + <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.dll</HintPath> + </Reference> + <Reference Include="System.Windows.Forms.DataVisualization"> + <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.DataVisualization.dll</HintPath> + </Reference> + </ItemGroup> + + <ItemGroup> <InternalsVisibleTo Include="VectoAPI" /> @@ -292,16 +306,13 @@ + <ItemGroup> <Compile Update="JSONKeys.Designer.cs"> <DesignTime>True</DesignTime> <AutoGen>True</AutoGen> <DependentUpon>JSONKeys.resx</DependentUpon> </Compile> - </ItemGroup> - - - <ItemGroup> <EmbeddedResource Update="JSONKeys.resx"> <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>JSONKeys.Designer.cs</LastGenOutput> diff --git a/VectoCore/VectoCoreTest/VectoCoreTest.csproj b/VectoCore/VectoCoreTest/VectoCoreTest.csproj index 780733442d..2733448c6d 100644 --- a/VectoCore/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCore/VectoCoreTest/VectoCoreTest.csproj @@ -7,7 +7,6 @@ <TargetFrameworks>net5.0</TargetFrameworks> </PropertyGroup> - <ItemGroup> <PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" /> @@ -18,11 +17,6 @@ <PackageReference Include="NLog" Version="4.7.13" /> </ItemGroup> - <ItemGroup Condition="'$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'net48'"> - <Reference Include="System.Windows.Forms" /> - <Reference Include="System.Windows.Forms.DataVisualization" /> - </ItemGroup> - <ItemGroup> <ProjectReference Include="..\..\VectoCommon\VectoCommon\VectoCommon.csproj" /> <ProjectReference Include="..\..\VectoCommon\VectoHashing\VectoHashing.csproj" /> -- GitLab