diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs index b2538c9..2d5e860 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/ScanDataController.cs @@ -7,22 +7,23 @@ namespace PointCloudWeb.Server.Controllers { [ApiController] [Route("[controller]")] - public class DataController : ControllerBase + public class ScanDataController : ControllerBase { private readonly ScanDataService _scanDataService; - public DataController(ScanDataService scanDataService) + public ScanDataController(ScanDataService scanDataService) { - this._scanDataService = scanDataService; - } - - [HttpPost] - public void PostScanData([FromBody] ScanDataList data) - { - _scanDataService.AddScan(data); + _scanDataService = scanDataService; } [HttpPut] + public void SendScanData([FromBody] ScanDataList data) + { + _scanDataService.AddScanData(data); + } + + [HttpPut] + [Route("finished/{id:Guid}")] public void ScanFinished(Guid id) { _scanDataService.ScanFinished(id); diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs index 0a44f99..7fe2930 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs @@ -5,6 +5,7 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Globalization; using System.IO; using System.Numerics; using System.Text; @@ -112,7 +113,13 @@ namespace PointCloudWeb.Server.Models var stringBuilder = new StringBuilder(); foreach (var point in _points) { - stringBuilder.AppendLine(string.Join(',', point.X, point.Y, point.Z)); + // + 0.001 Otherwise points are outside of the bounding box by a floating-error, then Potree-Converter fails + stringBuilder.AppendLine(string.Join(',', + (point.X + 0.001).ToString(CultureInfo.InvariantCulture), + (point.Y + 0.001).ToString(CultureInfo.InvariantCulture), + (point.Z + 0.001).ToString(CultureInfo.InvariantCulture) + ) + ); } return stringBuilder.ToString(); @@ -148,14 +155,14 @@ namespace PointCloudWeb.Server.Models return pc; } - public bool Contains(Guid id) + public bool Contains(Guid? id) { return GetById(id) != null; } - public PointCloud GetById(Guid id) + public PointCloud GetById(Guid? id) { - return Find(pc => pc.Id == id); + return id == null ? null : Find(pc => pc.Id == id); } public void RemoveById(Guid id) diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs index abc34d5..75f3a75 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs @@ -23,7 +23,7 @@ namespace PointCloudWeb.Server.Services { var pathTarget = Globals.PotreeDataPath + $"/{id.ToString()}"; var tempFile = Globals.TempPath + $"/{id}.las"; - + var pc = _pointClouds.GetById(id); pc.WriteToLas(tempFile); @@ -47,19 +47,24 @@ namespace PointCloudWeb.Server.Services throw new ArgumentOutOfRangeException($"The Id {id.ToString()} was not found!"); } - public void AddPoints(Guid id, IList points) + public void AddPoints(Guid id, IEnumerable points) { - RaiseIfNotExists(id); - - var pc = _pointClouds.GetById(id); + var pc = _pointClouds.GetById(id) + ?? AddPointCloud(id); foreach (var point in points) - pc.Points.Add(point); + { + if (point.X != 0 || point.Y != 0 || point.Z != 0) + pc.Points.Add(point); + } } - public PointCloud AddPointCloud() + public PointCloud AddPointCloud(Guid? id = null) { - var pc = new PointCloud(Guid.NewGuid(), ""); + if (id != null && _pointClouds.Contains(id)) + throw new ArgumentOutOfRangeException($"Add of existing id \"{id}\" not possible!"); + + var pc = new PointCloud(id ?? Guid.NewGuid(), $"Scan #{_pointClouds.Count + 1}"); _pointClouds.Add(pc); return pc; } diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs index 4fc2464..dea50ed 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanConverterService.cs @@ -62,17 +62,17 @@ namespace PointCloudWeb.Server.Services Y = factorY * NumericUtils.Round(z * sinXb / sinXa), Z = factorZ * NumericUtils.Round(z) }; - return p; + //return p; //https://stackoverflow.com/questions/52781607/3d-point-from-two-angles-and-a-distance - var pitch = radYa; - var yaw = radXa; + var beta = radYa; + var alpha = radXa; p = new Point { - X = (int) (scan.DistanceMM * Math.Sin(yaw) * Math.Cos(pitch)), - Y = (int) (scan.DistanceMM * Math.Sin(pitch)), - Z = (int) (scan.DistanceMM * Math.Cos(yaw) * Math.Cos(pitch)) + Y = (int)(scan.DistanceMM * Math.Sin(alpha)), + X = (int)(scan.DistanceMM * Math.Cos(beta) * Math.Cos(alpha)), + Z = (int)(scan.DistanceMM * Math.Sin(beta) * Math.Cos(alpha)) }; return p; diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs index 35c37d5..95a2b8a 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/ScanDataService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using PointCloudWeb.Server.Models; namespace PointCloudWeb.Server.Services @@ -13,26 +14,13 @@ namespace PointCloudWeb.Server.Services _pointCloudService = pointCloudService; } - private IList ConvertToPoints(ScanDataList scanData) - { - var list = new List(); + private static IEnumerable ConvertToPoints(ScanDataList scanData) + => scanData.ScanPoints.Select(ScanConverterService.Transform).ToList(); - foreach (var scan in scanData.ScanPoints) - { - list.Add(ScanConverterService.Transform(scan)); - } - - return list; - } - - public void AddScan(ScanDataList scanData) - { - _pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData)); - } + public void AddScanData(ScanDataList scanData) + => _pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData)); public void ScanFinished(Guid id) - { - _pointCloudService.PointCloudCompleted(id); - } + => _pointCloudService.PointCloudCompleted(id); } } \ No newline at end of file