add backend for registration
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using PointCloudWeb.Server.Models;
|
using PointCloudWeb.Server.Models;
|
||||||
using PointCloudWeb.Server.Services;
|
using PointCloudWeb.Server.Services;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace PointCloudWeb.Server.Controllers
|
namespace PointCloudWeb.Server.Controllers
|
||||||
{
|
{
|
||||||
@@ -8,17 +9,23 @@ namespace PointCloudWeb.Server.Controllers
|
|||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class DataController : ControllerBase
|
public class DataController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly DataService _scanDataService;
|
private readonly DataService scanDataService;
|
||||||
|
|
||||||
public DataController(DataService scanDataService)
|
public DataController(DataService scanDataService)
|
||||||
{
|
{
|
||||||
_scanDataService = scanDataService;
|
this.scanDataService = scanDataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void PostScanData([FromBody] ScanDataList data)
|
public void PostScanData([FromBody] ScanDataList data)
|
||||||
{
|
{
|
||||||
_scanDataService.AddScan(data);
|
scanDataService.AddScan(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut]
|
||||||
|
public void ScanFinished(Guid id)
|
||||||
|
{
|
||||||
|
scanDataService.ScanFinished(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,11 +16,11 @@ namespace PointCloudWeb.Server.Controllers
|
|||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly ILogger<WeatherForecastController> _logger;
|
private readonly ILogger<WeatherForecastController> logger;
|
||||||
|
|
||||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
using PointCloudWeb.Server.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
namespace PointCloudWeb.Server.Models
|
namespace PointCloudWeb.Server.Models
|
||||||
{
|
{
|
||||||
@@ -34,21 +38,71 @@ namespace PointCloudWeb.Server.Models
|
|||||||
|
|
||||||
public override int GetHashCode() => HashCode.Combine(X, Y, Z);
|
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 class PointCloud
|
public class PointCloud
|
||||||
{
|
{
|
||||||
public PointCloud(String name, Guid id)
|
private ObservableCollection<Point> points;
|
||||||
|
private Matrix4x4 transformation;
|
||||||
|
|
||||||
|
public PointCloud(string name, Guid id)
|
||||||
{
|
{
|
||||||
Points = new List<Point>();
|
points = new ObservableCollection<Point>();
|
||||||
|
points.CollectionChanged += PointsCollectionChanged;
|
||||||
|
TransformedPoints = new List<Point>();
|
||||||
Id = id;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Guid Id { get; private set; }
|
public Guid Id { get; private set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public IList<Point> Points { get; private set; }
|
|
||||||
|
public IList<Point> Points { get => points; }
|
||||||
|
|
||||||
|
public Matrix4x4 Transformation
|
||||||
|
{
|
||||||
|
get => transformation;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
TransformationChanged();
|
||||||
|
transformation = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IList<Point> TransformedPoints { get; private set; }
|
||||||
|
|
||||||
|
private Point GetTransformedPoint(Point point)
|
||||||
|
{
|
||||||
|
if (Transformation.IsIdentity)
|
||||||
|
return new Point(point.X, point.Y, point.Z);
|
||||||
|
|
||||||
|
var v = new Vector3(point.X, point.Y, point.Z);
|
||||||
|
v = Vector3.Transform(v, Transformation);
|
||||||
|
|
||||||
|
return new Point(NumericUtils.Round(v.X), NumericUtils.Round(v.Y), NumericUtils.Round(v.Z));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PointsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (TransformedPoints.Count > 0)
|
||||||
|
TransformationChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TransformationChanged()
|
||||||
|
{
|
||||||
|
TransformedPoints.Clear();
|
||||||
|
|
||||||
|
if (Transformation.IsIdentity)
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var point in Points)
|
||||||
|
{
|
||||||
|
var transformedPoint = GetTransformedPoint(point);
|
||||||
|
TransformedPoints.Add(transformedPoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PointCloudCollection : List<PointCloud>
|
public class PointCloudCollection : List<PointCloud>
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
using PointCloudWeb.Server.Models;
|
|
||||||
|
|
||||||
namespace PointCloudWeb.Server.Services
|
|
||||||
{
|
|
||||||
public interface IPointCloudRegistation
|
|
||||||
{
|
|
||||||
public TransformationMatrix RegisterPointCloud(PointCloud pc1, PointCloud pc2)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
class TransformationMatrix { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using PointCloudWeb.Server.Models;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
|
namespace PointCloudWeb.Server.Services
|
||||||
|
{
|
||||||
|
public interface IPointCloudRegistationService
|
||||||
|
{
|
||||||
|
public Matrix4x4 RegisterPointCloud(PointCloud source, PointCloud target);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,16 +6,18 @@ namespace PointCloudWeb.Server.Services
|
|||||||
{
|
{
|
||||||
public class PointCloudService
|
public class PointCloudService
|
||||||
{
|
{
|
||||||
private readonly PointCloudCollection _pointClouds;
|
private readonly IPointCloudRegistationService pointCloudRegistation;
|
||||||
|
private readonly PointCloudCollection pointClouds;
|
||||||
|
|
||||||
public PointCloudService()
|
public PointCloudService(IPointCloudRegistationService pointCloudRegistation)
|
||||||
{
|
{
|
||||||
_pointClouds = new PointCloudCollection();
|
pointClouds = new PointCloudCollection();
|
||||||
|
this.pointCloudRegistation = pointCloudRegistation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RaiseIfNotExists(Guid id)
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +25,7 @@ namespace PointCloudWeb.Server.Services
|
|||||||
{
|
{
|
||||||
RaiseIfNotExists(id);
|
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);
|
||||||
@@ -31,16 +33,21 @@ namespace PointCloudWeb.Server.Services
|
|||||||
|
|
||||||
public void RegisterPointCloud(Guid id)
|
public void RegisterPointCloud(Guid id)
|
||||||
{
|
{
|
||||||
RegisterPointClouds(new List<Guid>() { id });
|
RaiseIfNotExists(id);
|
||||||
|
var pointCloud = pointClouds.GetById(id);
|
||||||
|
|
||||||
|
//the first can't be registered
|
||||||
|
if (pointClouds.IndexOf(pointCloud) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var transformation = pointCloudRegistation.RegisterPointCloud(pointCloud, pointClouds[0]);
|
||||||
|
pointCloud.Transformation = transformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterPointClouds(IList<Guid> ids)
|
public void RegisterPointClouds()
|
||||||
{
|
{
|
||||||
//ensure that every element in "ids" is in "_pointClouds"
|
foreach (var pointCloud in pointClouds)
|
||||||
foreach (var id in ids)
|
RegisterPointCloud(pointCloud.Id);
|
||||||
RaiseIfNotExists(id);
|
|
||||||
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
|
||||||
using PointCloudWeb.Server.Models;
|
using PointCloudWeb.Server.Models;
|
||||||
|
using PointCloudWeb.Server.Utils;
|
||||||
|
|
||||||
namespace PointCloudWeb.Server.Services
|
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);
|
|
||||||
|
|
||||||
public Point Transform(ScanDataPoint scan)
|
public Point Transform(ScanDataPoint scan)
|
||||||
{
|
{
|
||||||
var factorZ = 1;
|
var factorZ = 1;
|
||||||
@@ -46,9 +44,9 @@ namespace PointCloudWeb.Server.Services
|
|||||||
|
|
||||||
var p = new Point()
|
var p = new Point()
|
||||||
{
|
{
|
||||||
X = Round(z * sinYB / sinYA),
|
X = NumericUtils.Round(z * sinYB / sinYA),
|
||||||
Y = Round(z * sinXB / sinXA),
|
Y = NumericUtils.Round(z * sinXB / sinXA),
|
||||||
Z = factorZ * Round(z)
|
Z = factorZ * NumericUtils.Round(z)
|
||||||
};
|
};
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ namespace PointCloudWeb.Server.Services
|
|||||||
{
|
{
|
||||||
public class DataService
|
public class DataService
|
||||||
{
|
{
|
||||||
private readonly PointCloudService _pointCloudService;
|
private readonly PointCloudService pointCloudService;
|
||||||
private readonly ScanConverterService _scanConverterService;
|
private readonly ScanConverterService scanConverterService;
|
||||||
|
|
||||||
public DataService(PointCloudService pointCloudService, ScanConverterService scanConverterService)
|
public DataService(PointCloudService pointCloudService, ScanConverterService scanConverterService)
|
||||||
{
|
{
|
||||||
_pointCloudService = pointCloudService;
|
this.pointCloudService = pointCloudService;
|
||||||
_scanConverterService = scanConverterService;
|
this.scanConverterService = scanConverterService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IList<Point> ConvertToPoints(ScanDataList scanData)
|
private IList<Point> ConvertToPoints(ScanDataList scanData)
|
||||||
@@ -21,7 +21,7 @@ namespace PointCloudWeb.Server.Services
|
|||||||
|
|
||||||
foreach (var scan in scanData.ScanPoints)
|
foreach (var scan in scanData.ScanPoints)
|
||||||
{
|
{
|
||||||
list.Add(_scanConverterService.Transform(scan));
|
list.Add(scanConverterService.Transform(scan));
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -29,7 +29,12 @@ namespace PointCloudWeb.Server.Services
|
|||||||
|
|
||||||
public void AddScan(ScanDataList scanData)
|
public void AddScan(ScanDataList scanData)
|
||||||
{
|
{
|
||||||
_pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData));
|
pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ScanFinished(Guid id)
|
||||||
|
{
|
||||||
|
pointCloudService.RegisterPointCloud(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace PointCloudWeb.Server.Utils
|
||||||
|
{
|
||||||
|
public static class NumericUtils
|
||||||
|
{
|
||||||
|
public static int Round(double value) => (int)Math.Round(double.IsNaN(value) ? 0 : value, 0, MidpointRounding.AwayFromZero);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user