From d9873ab8ccdac367287d1cc577c70757157c5099 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Fri, 16 Jul 2021 23:21:30 +0200 Subject: [PATCH] source code cleanup --- .../Services/ScanConverterServiceTest.cs | 7 +--- .../Controllers/ScanDataController.cs | 2 +- .../Controllers/WeatherForecastController.cs | 2 +- .../PointCloudWeb.Server/Models/PointCloud.cs | 33 ++++++++++--------- .../PointCloudWeb.Server/Models/ScanData.cs | 23 ++++++------- .../Models/WeatherForecast.cs | 5 ++- .../PointCloudWeb.Server/Program.cs | 12 +++---- .../Services/IPointCloudRegistration.cs | 4 +-- .../Services/PointCloudService.cs | 21 +++++++++++- .../Services/ScanConverterService.cs | 2 +- .../Services/ScanDataService.cs | 10 +++--- .../PointCloudWeb.Server/Startup.cs | 14 ++++---- 12 files changed, 75 insertions(+), 60 deletions(-) diff --git a/PointCloudWeb.Server/PointCloudWeb.Server.Tests/Services/ScanConverterServiceTest.cs b/PointCloudWeb.Server/PointCloudWeb.Server.Tests/Services/ScanConverterServiceTest.cs index 11220d4..fbae4e8 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server.Tests/Services/ScanConverterServiceTest.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server.Tests/Services/ScanConverterServiceTest.cs @@ -7,7 +7,6 @@ namespace PointCloudWeb.Server.Tests.Services { public class ScanConverterServiceTest { - [Theory] [InlineData(2, 2, 2)] [InlineData(2, 1, 1)] @@ -22,19 +21,16 @@ namespace PointCloudWeb.Server.Tests.Services [InlineData(0, 1, 1)] [InlineData(1, 0, 1)] [InlineData(1, 1, 1)] - [InlineData(-1, 1, 1)] [InlineData(1, -1, 1)] [InlineData(-1, -1, 1)] [InlineData(-5, 12, 7)] [InlineData(-5, -12, 7)] [InlineData(-22, 13, 11)] - [InlineData(0, 0, -1)] [InlineData(0, -1, -1)] [InlineData(-1, 0, -1)] [InlineData(-1, -1, -1)] - [InlineData(1, 1, -1)] [InlineData(5, 12, -7)] [InlineData(-1, 1, -1)] @@ -70,7 +66,6 @@ namespace PointCloudWeb.Server.Tests.Services var service = new ScanConverterService(); var point = service.Transform(scan); Assert.Equal(expected, point); - } } -} +} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs index 20b2154..e4e4a49 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs @@ -21,4 +21,4 @@ namespace PointCloudWeb.Server.Controllers _scanDataService.AddScan(data); } } -} +} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/WeatherForecastController.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/WeatherForecastController.cs index 28b6054..2f9067c 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/WeatherForecastController.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/WeatherForecastController.cs @@ -36,4 +36,4 @@ namespace PointCloudWeb.Server.Controllers .ToArray(); } } -} +} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs index 482dd51..c2e1e3b 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs @@ -6,12 +6,10 @@ namespace PointCloudWeb.Server.Models { public class Point { - public int X { get; set; } - public int Y { get; set; } - public int Z { get; set; } + public Point() : this(0, 0, 0) + { + } - - public Point() : this(0, 0, 0) { } public Point(int x, int y, int z) { X = x; @@ -19,6 +17,10 @@ namespace PointCloudWeb.Server.Models Z = z; } + public int X { get; set; } + public int Y { get; set; } + public int Z { get; set; } + public override bool Equals(object obj) { if ((obj == null) || !GetType().Equals(obj.GetType())) @@ -30,33 +32,27 @@ namespace PointCloudWeb.Server.Models } } + public override int GetHashCode() => HashCode.Combine(X, Y, Z); public override string ToString() => (X.ToString() + " " + Y.ToString() + " " + Z.ToString()); - public override int GetHashCode() => HashCode.Combine(X, Y, Z); } - public class PointCloud { - public Guid Id { get; private set; } - public string Name { get; set; } - public IList Points { get; private set; } - public PointCloud(String name, Guid id) { Points = new List(); Id = id; Name = name; } + + public Guid Id { get; private set; } + public string Name { get; set; } + public IList Points { get; private set; } } public class PointCloudCollection : List { - public PointCloud GetById(Guid id) - { - return this.First(pc => pc.Id == id); - } - public PointCloud AddNew() { var id = Guid.NewGuid(); @@ -70,6 +66,11 @@ namespace PointCloudWeb.Server.Models return this.Any(pc => pc.Id == id); } + public PointCloud GetById(Guid id) + { + return this.First(pc => pc.Id == id); + } + public void RemoveById(Guid id) { Remove(GetById(id)); diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/ScanData.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/ScanData.cs index eeb713e..266d3b1 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/ScanData.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/ScanData.cs @@ -1,16 +1,16 @@ - using System; using System.Collections.Generic; namespace PointCloudWeb.Server.Models { + public class ScanDataList + { + public Guid Id { get; set; } + public IList ScanPoints { get; set; } + } + public class ScanDataPoint { - //RotationAngle on {X, Y} Axis - public double RAX { get; set; } - public double RAY { get; set; } - public float DistanceMM { get; set; } - public ScanDataPoint() { RAY = 0; @@ -24,11 +24,12 @@ namespace PointCloudWeb.Server.Models RAY = ray; DistanceMM = distanceMM; } - } - public class ScanDataList - { - public Guid Id { get; set; } - public IList ScanPoints { get; set; } + public float DistanceMM { get; set; } + + //RotationAngle on {X, Y} Axis + public double RAX { get; set; } + + public double RAY { get; set; } } } \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/WeatherForecast.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/WeatherForecast.cs index 93974ee..67d28bf 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/WeatherForecast.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/WeatherForecast.cs @@ -6,10 +6,9 @@ namespace PointCloudWeb.Server { public DateTime Date { get; set; } + public string Summary { get; set; } public int TemperatureC { get; set; } public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } } -} +} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Program.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Program.cs index 083e77a..821f4ef 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Program.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Program.cs @@ -11,16 +11,16 @@ namespace PointCloudWeb.Server { public class Program { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); + + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } } -} +} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/IPointCloudRegistration.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/IPointCloudRegistration.cs index d0929be..d64af5e 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/IPointCloudRegistration.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/IPointCloudRegistration.cs @@ -4,11 +4,11 @@ namespace PointCloudWeb.Server.Services { public interface IPointCloudRegistation { - class TransformationMatrix { } - public TransformationMatrix RegisterPointCloud(PointCloud pc1, PointCloud pc2) { return null; } + + class TransformationMatrix { } } } \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs index 76f86fd..b89c5fa 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs @@ -13,15 +13,34 @@ namespace PointCloudWeb.Server.Services _pointClouds = new PointCloudCollection(); } - public void AddPoints(Guid id, IList points) + private void RaiseIfNotExists(Guid id) { if (!_pointClouds.Contains(id)) throw new ArgumentOutOfRangeException("The Id {0} was not found!", id.ToString()); + } + + public void AddPoints(Guid id, IList points) + { + RaiseIfNotExists(id); var pc = _pointClouds.GetById(id); foreach (var point in points) pc.Points.Add(point); } + + public void RegisterPointCloud(Guid id) + { + RegisterPointClouds(new List() { id }); + } + + public void RegisterPointClouds(IList ids) + { + //ensure that every element in "ids" is in "_pointClouds" + foreach (var id in ids) + RaiseIfNotExists(id); + + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs index b9143be..dc11998 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs @@ -7,6 +7,7 @@ namespace PointCloudWeb.Server.Services public class ScanConverterService { private int Round(double value) => (int)Math.Round(double.IsNaN(value) ? 0 : value, 0, MidpointRounding.AwayFromZero); + public Point Transform(ScanDataPoint scan) { var factorZ = 1; @@ -43,7 +44,6 @@ namespace PointCloudWeb.Server.Services * Math.Pow(scan.DistanceMM, 2) ); - var p = new Point() { X = Round(z * sinYB / sinYA), diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs index b94f4e4..a8eae49 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs @@ -15,11 +15,6 @@ namespace PointCloudWeb.Server.Services _scanConverterService = scanConverterService; } - public void AddScan(ScanDataList scanData) - { - _pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData)); - } - private IList ConvertToPoints(ScanDataList scanData) { var list = new List(); @@ -31,5 +26,10 @@ namespace PointCloudWeb.Server.Services return list; } + + public void AddScan(ScanDataList scanData) + { + _pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData)); + } } } \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Startup.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Startup.cs index 01d13a5..d4c986f 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Startup.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Startup.cs @@ -21,12 +21,6 @@ namespace PointCloudWeb.Server public IConfiguration Configuration { get; } - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddControllers(); - } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { @@ -44,5 +38,11 @@ namespace PointCloudWeb.Server endpoints.MapControllers(); }); } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + } } -} +} \ No newline at end of file