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]
[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);

View File

@@ -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)

View File

@@ -47,19 +47,24 @@ namespace PointCloudWeb.Server.Services
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);
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;
}

View File

@@ -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;

View File

@@ -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<Point> ConvertToPoints(ScanDataList scanData)
{
var list = new List<Point>();
private static IEnumerable<Point> 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);
}
}