fix sending of ScanData

This commit is contained in:
Tim Wundenberg
2021-08-11 19:41:25 +02:00
parent 5769b91229
commit e45f0312e0
5 changed files with 46 additions and 45 deletions

View File

@@ -7,22 +7,23 @@ namespace PointCloudWeb.Server.Controllers
{ {
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
public class DataController : ControllerBase public class ScanDataController : ControllerBase
{ {
private readonly ScanDataService _scanDataService; private readonly ScanDataService _scanDataService;
public DataController(ScanDataService scanDataService) public ScanDataController(ScanDataService scanDataService)
{ {
this._scanDataService = scanDataService; _scanDataService = scanDataService;
}
[HttpPost]
public void PostScanData([FromBody] ScanDataList data)
{
_scanDataService.AddScan(data);
} }
[HttpPut] [HttpPut]
public void SendScanData([FromBody] ScanDataList data)
{
_scanDataService.AddScanData(data);
}
[HttpPut]
[Route("finished/{id:Guid}")]
public void ScanFinished(Guid id) public void ScanFinished(Guid id)
{ {
_scanDataService.ScanFinished(id); _scanDataService.ScanFinished(id);

View File

@@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO; using System.IO;
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
@@ -112,7 +113,13 @@ namespace PointCloudWeb.Server.Models
var stringBuilder = new StringBuilder(); var stringBuilder = new StringBuilder();
foreach (var point in _points) 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(); return stringBuilder.ToString();
@@ -148,14 +155,14 @@ namespace PointCloudWeb.Server.Models
return pc; return pc;
} }
public bool Contains(Guid id) public bool Contains(Guid? id)
{ {
return GetById(id) != null; 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) public void RemoveById(Guid id)

View File

@@ -47,19 +47,24 @@ namespace PointCloudWeb.Server.Services
throw new ArgumentOutOfRangeException($"The Id {id.ToString()} was not found!"); throw new ArgumentOutOfRangeException($"The Id {id.ToString()} was not found!");
} }
public void AddPoints(Guid id, IList<Point> points) public void AddPoints(Guid id, IEnumerable<Point> points)
{ {
RaiseIfNotExists(id); var pc = _pointClouds.GetById(id)
?? AddPointCloud(id);
var pc = _pointClouds.GetById(id);
foreach (var point in points) 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); _pointClouds.Add(pc);
return pc; return pc;
} }

View File

@@ -62,17 +62,17 @@ namespace PointCloudWeb.Server.Services
Y = factorY * NumericUtils.Round(z * sinXb / sinXa), Y = factorY * NumericUtils.Round(z * sinXb / sinXa),
Z = factorZ * NumericUtils.Round(z) Z = factorZ * NumericUtils.Round(z)
}; };
return p; //return p;
//https://stackoverflow.com/questions/52781607/3d-point-from-two-angles-and-a-distance //https://stackoverflow.com/questions/52781607/3d-point-from-two-angles-and-a-distance
var pitch = radYa; var beta = radYa;
var yaw = radXa; var alpha = radXa;
p = new Point p = new Point
{ {
X = (int) (scan.DistanceMM * Math.Sin(yaw) * Math.Cos(pitch)), Y = (int)(scan.DistanceMM * Math.Sin(alpha)),
Y = (int) (scan.DistanceMM * Math.Sin(pitch)), X = (int)(scan.DistanceMM * Math.Cos(beta) * Math.Cos(alpha)),
Z = (int) (scan.DistanceMM * Math.Cos(yaw) * Math.Cos(pitch)) Z = (int)(scan.DistanceMM * Math.Sin(beta) * Math.Cos(alpha))
}; };
return p; return p;

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using PointCloudWeb.Server.Models; using PointCloudWeb.Server.Models;
namespace PointCloudWeb.Server.Services namespace PointCloudWeb.Server.Services
@@ -13,26 +14,13 @@ namespace PointCloudWeb.Server.Services
_pointCloudService = pointCloudService; _pointCloudService = pointCloudService;
} }
private IList<Point> ConvertToPoints(ScanDataList scanData) private static IEnumerable<Point> ConvertToPoints(ScanDataList scanData)
{ => scanData.ScanPoints.Select(ScanConverterService.Transform).ToList();
var list = new List<Point>();
foreach (var scan in scanData.ScanPoints) public void AddScanData(ScanDataList scanData)
{ => _pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData));
list.Add(ScanConverterService.Transform(scan));
}
return list;
}
public void AddScan(ScanDataList scanData)
{
_pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData));
}
public void ScanFinished(Guid id) public void ScanFinished(Guid id)
{ => _pointCloudService.PointCloudCompleted(id);
_pointCloudService.PointCloudCompleted(id);
}
} }
} }