source code cleanup

This commit is contained in:
Tim Wundenberg
2021-07-16 23:21:30 +02:00
parent 5bf8228628
commit d9873ab8cc
12 changed files with 75 additions and 60 deletions

View File

@@ -7,7 +7,6 @@ namespace PointCloudWeb.Server.Tests.Services
{ {
public class ScanConverterServiceTest public class ScanConverterServiceTest
{ {
[Theory] [Theory]
[InlineData(2, 2, 2)] [InlineData(2, 2, 2)]
[InlineData(2, 1, 1)] [InlineData(2, 1, 1)]
@@ -22,19 +21,16 @@ namespace PointCloudWeb.Server.Tests.Services
[InlineData(0, 1, 1)] [InlineData(0, 1, 1)]
[InlineData(1, 0, 1)] [InlineData(1, 0, 1)]
[InlineData(1, 1, 1)] [InlineData(1, 1, 1)]
[InlineData(-1, 1, 1)] [InlineData(-1, 1, 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(-5, -12, 7)] [InlineData(-5, -12, 7)]
[InlineData(-22, 13, 11)] [InlineData(-22, 13, 11)]
[InlineData(0, 0, -1)] [InlineData(0, 0, -1)]
[InlineData(0, -1, -1)] [InlineData(0, -1, -1)]
[InlineData(-1, 0, -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(-1, 1, -1)] [InlineData(-1, 1, -1)]
@@ -70,7 +66,6 @@ namespace PointCloudWeb.Server.Tests.Services
var service = new ScanConverterService(); var service = new ScanConverterService();
var point = service.Transform(scan); var point = service.Transform(scan);
Assert.Equal(expected, point); Assert.Equal(expected, point);
} }
} }
} }

View File

@@ -6,12 +6,10 @@ namespace PointCloudWeb.Server.Models
{ {
public class Point public class Point
{ {
public int X { get; set; } public Point() : this(0, 0, 0)
public int Y { get; set; } {
public int Z { get; set; } }
public Point() : this(0, 0, 0) { }
public Point(int x, int y, int z) public Point(int x, int y, int z)
{ {
X = x; X = x;
@@ -19,6 +17,10 @@ namespace PointCloudWeb.Server.Models
Z = z; Z = z;
} }
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if ((obj == null) || !GetType().Equals(obj.GetType())) 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 string ToString() => (X.ToString() + " " + Y.ToString() + " " + Z.ToString());
public override int GetHashCode() => HashCode.Combine(X, Y, Z);
} }
public class PointCloud public class PointCloud
{ {
public Guid Id { get; private set; }
public string Name { get; set; }
public IList<Point> Points { get; private set; }
public PointCloud(String name, Guid id) public PointCloud(String name, Guid id)
{ {
Points = new List<Point>(); Points = new List<Point>();
Id = id; Id = id;
Name = name; Name = name;
} }
public Guid Id { get; private set; }
public string Name { get; set; }
public IList<Point> Points { get; private set; }
} }
public class PointCloudCollection : List<PointCloud> public class PointCloudCollection : List<PointCloud>
{ {
public PointCloud GetById(Guid id)
{
return this.First(pc => pc.Id == id);
}
public PointCloud AddNew() public PointCloud AddNew()
{ {
var id = Guid.NewGuid(); var id = Guid.NewGuid();
@@ -70,6 +66,11 @@ namespace PointCloudWeb.Server.Models
return this.Any(pc => pc.Id == id); return this.Any(pc => pc.Id == id);
} }
public PointCloud GetById(Guid id)
{
return this.First(pc => pc.Id == id);
}
public void RemoveById(Guid id) public void RemoveById(Guid id)
{ {
Remove(GetById(id)); Remove(GetById(id));

View File

@@ -1,16 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace PointCloudWeb.Server.Models namespace PointCloudWeb.Server.Models
{ {
public class ScanDataList
{
public Guid Id { get; set; }
public IList<ScanDataPoint> ScanPoints { get; set; }
}
public class ScanDataPoint 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() public ScanDataPoint()
{ {
RAY = 0; RAY = 0;
@@ -24,11 +24,12 @@ namespace PointCloudWeb.Server.Models
RAY = ray; RAY = ray;
DistanceMM = distanceMM; DistanceMM = distanceMM;
} }
}
public class ScanDataList public float DistanceMM { get; set; }
{
public Guid Id { get; set; } //RotationAngle on {X, Y} Axis
public IList<ScanDataPoint> ScanPoints { get; set; } public double RAX { get; set; }
public double RAY { get; set; }
} }
} }

View File

@@ -6,10 +6,9 @@ namespace PointCloudWeb.Server
{ {
public DateTime Date { get; set; } public DateTime Date { get; set; }
public string Summary { get; set; }
public int TemperatureC { get; set; } public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
} }
} }

View File

@@ -11,16 +11,16 @@ namespace PointCloudWeb.Server
{ {
public class Program public class Program
{ {
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => .ConfigureWebHostDefaults(webBuilder =>
{ {
webBuilder.UseStartup<Startup>(); webBuilder.UseStartup<Startup>();
}); });
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
} }
} }

View File

@@ -4,11 +4,11 @@ namespace PointCloudWeb.Server.Services
{ {
public interface IPointCloudRegistation public interface IPointCloudRegistation
{ {
class TransformationMatrix { }
public TransformationMatrix RegisterPointCloud(PointCloud pc1, PointCloud pc2) public TransformationMatrix RegisterPointCloud(PointCloud pc1, PointCloud pc2)
{ {
return null; return null;
} }
class TransformationMatrix { }
} }
} }

View File

@@ -13,15 +13,34 @@ namespace PointCloudWeb.Server.Services
_pointClouds = new PointCloudCollection(); _pointClouds = new PointCloudCollection();
} }
public void AddPoints(Guid id, IList<Point> points) private void RaiseIfNotExists(Guid id)
{ {
if (!_pointClouds.Contains(id)) if (!_pointClouds.Contains(id))
throw new ArgumentOutOfRangeException("The Id {0} was not found!", id.ToString()); throw new ArgumentOutOfRangeException("The Id {0} was not found!", id.ToString());
}
public void AddPoints(Guid id, IList<Point> points)
{
RaiseIfNotExists(id);
var pc = _pointClouds.GetById(id); var pc = _pointClouds.GetById(id);
foreach (var point in points) foreach (var point in points)
pc.Points.Add(point); pc.Points.Add(point);
} }
public void RegisterPointCloud(Guid id)
{
RegisterPointClouds(new List<Guid>() { id });
}
public void RegisterPointClouds(IList<Guid> ids)
{
//ensure that every element in "ids" is in "_pointClouds"
foreach (var id in ids)
RaiseIfNotExists(id);
throw new NotImplementedException();
}
} }
} }

View File

@@ -7,6 +7,7 @@ namespace PointCloudWeb.Server.Services
public class ScanConverterService public class ScanConverterService
{ {
private int Round(double value) => (int)Math.Round(double.IsNaN(value) ? 0 : value, 0, MidpointRounding.AwayFromZero); private int Round(double value) => (int)Math.Round(double.IsNaN(value) ? 0 : value, 0, MidpointRounding.AwayFromZero);
public Point Transform(ScanDataPoint scan) public Point Transform(ScanDataPoint scan)
{ {
var factorZ = 1; var factorZ = 1;
@@ -43,7 +44,6 @@ namespace PointCloudWeb.Server.Services
* Math.Pow(scan.DistanceMM, 2) * Math.Pow(scan.DistanceMM, 2)
); );
var p = new Point() var p = new Point()
{ {
X = Round(z * sinYB / sinYA), X = Round(z * sinYB / sinYA),

View File

@@ -15,11 +15,6 @@ namespace PointCloudWeb.Server.Services
_scanConverterService = scanConverterService; _scanConverterService = scanConverterService;
} }
public void AddScan(ScanDataList scanData)
{
_pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData));
}
private IList<Point> ConvertToPoints(ScanDataList scanData) private IList<Point> ConvertToPoints(ScanDataList scanData)
{ {
var list = new List<Point>(); var list = new List<Point>();
@@ -31,5 +26,10 @@ namespace PointCloudWeb.Server.Services
return list; return list;
} }
public void AddScan(ScanDataList scanData)
{
_pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData));
}
} }
} }

View File

@@ -21,12 +21,6 @@ namespace PointCloudWeb.Server
public IConfiguration Configuration { get; } 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. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ {
@@ -44,5 +38,11 @@ namespace PointCloudWeb.Server
endpoints.MapControllers(); 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();
}
} }
} }