From 8bef0824ceaef2f10b74b6752f9f679e66817d84 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Fri, 30 Jul 2021 20:31:27 +0200 Subject: [PATCH] add PointCloudInfo Controller --- .gitignore | 3 +- .../Controllers/PointCloudController.cs | 2 +- .../Controllers/PointCloudInfoController.cs | 53 +++++++++++++++++++ .../Controllers/ScanDataController.cs | 4 +- .../PointCloudWeb.Server/Models/PointCloud.cs | 4 +- .../Models/PointCloudDto.cs | 4 +- .../Models/PointCloudInfoDto.cs | 20 +++++++ .../PointCloudWeb.Server/Models/ScanData.cs | 6 +++ .../PointCloudWeb.Server.csproj | 4 ++ .../Services/PointCloudService.cs | 19 +++++-- .../Services/ScanConverterService.cs | 17 +++--- .../Services/ScanDataService.cs | 4 +- .../PointCloudWeb.Server/Startup.cs | 7 ++- 13 files changed, 122 insertions(+), 25 deletions(-) create mode 100644 PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudInfoController.cs create mode 100644 PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudInfoDto.cs diff --git a/.gitignore b/.gitignore index 3df151b..dc56c67 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ bin/ obj/ .vscode/ -node_modules/ \ No newline at end of file +node_modules/ +*.csproj.user \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs index fb6155b..a267025 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs @@ -18,7 +18,7 @@ namespace PointCloudWeb.Server.Controllers this.pointCloudService = pointCloudService; } - private PointCloudDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudDto(pc.Id, pc.Name, pc.TransformedPoints); + private PointCloudDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudDto(pc.Id, pc.TransformedPoints); [HttpGet] public IList GetAll() diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudInfoController.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudInfoController.cs new file mode 100644 index 0000000..3afc45f --- /dev/null +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudInfoController.cs @@ -0,0 +1,53 @@ +using Microsoft.AspNetCore.Mvc; +using PointCloudWeb.Server.Models; +using PointCloudWeb.Server.Services; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace PointCloudWeb.Server.Controllers +{ + [ApiController] + [Route("[controller]")] + public class PointCloudInfoController + { + private readonly PointCloudService pointCloudService; + + public PointCloudInfoController(PointCloudService pointCloudService) + { + this.pointCloudService = pointCloudService; + } + + private PointCloudInfoDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudInfoDto(pc.Id, pc.Name); + + [HttpGet] + public IList GetAll() + { + var result = new List(); + foreach (var pc in pointCloudService.GetAll()) + result.Add(ConvertPointCloudToDto(pc)); + + return result; + } + + [HttpGet] + [Route("{id:Guid}")] + public ActionResult GetById(Guid id) + { + var pc = pointCloudService.GetById(id); + if (pc == null) + return new NotFoundResult(); + return ConvertPointCloudToDto(pc); + } + + [HttpPut] + public ActionResult UpdatePointCloud([FromBody] PointCloudInfoDto newPc) + { + var pc = pointCloudService.GetById(newPc.Id); + if (pc == null) + return new NotFoundResult(); + pc.Name = newPc.Name; + return ConvertPointCloudToDto(pc); + } + } +} \ 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 e6be899..735cab4 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs @@ -9,9 +9,9 @@ namespace PointCloudWeb.Server.Controllers [Route("[controller]")] public class DataController : ControllerBase { - private readonly DataService scanDataService; + private readonly ScanDataService scanDataService; - public DataController(DataService scanDataService) + public DataController(ScanDataService scanDataService) { this.scanDataService = scanDataService; } diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs index 18d6c3a..01312bf 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs @@ -117,12 +117,12 @@ namespace PointCloudWeb.Server.Models public bool Contains(Guid id) { - return this.Any(pc => pc.Id == id); + return GetById(id) != null; } public PointCloud GetById(Guid id) { - return this.First(pc => pc.Id == id); + return this.Find(pc => pc.Id == id); } public void RemoveById(Guid id) diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs index 1e202b9..816626e 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs @@ -7,15 +7,13 @@ namespace PointCloudWeb.Server.Models { public class PointCloudDto { - public PointCloudDto(Guid id, string name, IList points) + public PointCloudDto(Guid id, IList points) { Id = id; - Name = name; Points = points; } public Guid Id { get; } - public string Name { get; } public IList Points { get; } } } \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudInfoDto.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudInfoDto.cs new file mode 100644 index 0000000..f8c06ab --- /dev/null +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudInfoDto.cs @@ -0,0 +1,20 @@ +using System; + +namespace PointCloudWeb.Server.Models +{ + public class PointCloudInfoDto + { + public PointCloudInfoDto() : this(Guid.Empty, "") + { + } + + public PointCloudInfoDto(Guid id, string name) + { + Id = id; + Name = name; + } + + public Guid Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/ScanData.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/ScanData.cs index 266d3b1..77e047b 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/ScanData.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/ScanData.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace PointCloudWeb.Server.Models { @@ -31,5 +32,10 @@ namespace PointCloudWeb.Server.Models public double RAX { get; set; } public double RAY { get; set; } + + public override string ToString() + { + return String.Join(", ", new string[] { RAY.ToString(), RAX.ToString(), DistanceMM.ToString() }); + } } } \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/PointCloudWeb.Server.csproj b/PointCloudWeb.Server/PointCloudWeb.Server/PointCloudWeb.Server.csproj index d12c450..7597c2f 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/PointCloudWeb.Server.csproj +++ b/PointCloudWeb.Server/PointCloudWeb.Server/PointCloudWeb.Server.csproj @@ -4,5 +4,9 @@ netcoreapp3.1 + + + + diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs index d77bd9c..2e94f12 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs @@ -6,13 +6,22 @@ namespace PointCloudWeb.Server.Services { public class PointCloudService { - private readonly IPointCloudRegistationService pointCloudRegistation; + //private readonly IPointCloudRegistationService pointCloudRegistation; private readonly PointCloudCollection pointClouds; - public PointCloudService(IPointCloudRegistationService pointCloudRegistation) + public PointCloudService(/*IPointCloudRegistationService pointCloudRegistation*/) { pointClouds = new PointCloudCollection(); - this.pointCloudRegistation = pointCloudRegistation; + //this.pointCloudRegistation = pointCloudRegistation; + InitSamleData(); + } + + private void InitSamleData() + { + pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 1")); + pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 2")); + pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 3")); + pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 4")); } private void RaiseIfNotExists(Guid id) @@ -50,8 +59,8 @@ namespace PointCloudWeb.Server.Services if (pointClouds.IndexOf(pointCloud) == 0) return; - var transformation = pointCloudRegistation.RegisterPointCloud(pointCloud, pointClouds[0]); - pointCloud.Transformation = transformation; + //var transformation = pointCloudRegistation.RegisterPointCloud(pointCloud, pointClouds[0]); + //pointCloud.Transformation = transformation; } public void RegisterPointClouds() diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs index 1045fd6..a756118 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs @@ -8,17 +8,18 @@ namespace PointCloudWeb.Server.Services { public Point Transform(ScanDataPoint scan) { - var factorZ = 1; + if (scan.RAX >= 180 || scan.RAY >= 180) + return new Point(0, 0, 0); var degreeXA = scan.RAX; var degreeYA = scan.RAY; - if (degreeXA > 270 && degreeYA > 270) - { - degreeXA -= 270; - degreeYA -= 270; - factorZ = -1; - } + //if (degreeXA > 270 && degreeYA > 270) + //{ + // degreeXA -= 270; + // degreeYA -= 270; + // factorZ = -1; + //} var degreeXB = 180 - 90 - degreeXA; var degreeYB = 180 - 90 - degreeYA; @@ -46,7 +47,7 @@ namespace PointCloudWeb.Server.Services { X = NumericUtils.Round(z * sinYB / sinYA), Y = NumericUtils.Round(z * sinXB / sinXA), - Z = factorZ * NumericUtils.Round(z) + Z = NumericUtils.Round(z) }; return p; diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs index 4a2fbf2..ed04f7e 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs @@ -4,12 +4,12 @@ using PointCloudWeb.Server.Models; namespace PointCloudWeb.Server.Services { - public class DataService + public class ScanDataService { private readonly PointCloudService pointCloudService; private readonly ScanConverterService scanConverterService; - public DataService(PointCloudService pointCloudService, ScanConverterService scanConverterService) + public ScanDataService(PointCloudService pointCloudService, ScanConverterService scanConverterService) { this.pointCloudService = pointCloudService; this.scanConverterService = scanConverterService; diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Startup.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Startup.cs index d4c986f..10f1065 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Startup.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Startup.cs @@ -1,10 +1,12 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using PointCloudWeb.Server.Services; using System; using System.Collections.Generic; using System.Linq; @@ -31,7 +33,7 @@ namespace PointCloudWeb.Server app.UseRouting(); - app.UseAuthorization(); + //app.UseAuthorization(); app.UseEndpoints(endpoints => { @@ -42,6 +44,9 @@ namespace PointCloudWeb.Server // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddSingleton(); + services.AddTransient(); + services.AddTransient(); services.AddControllers(); } }