new ScanConverter method
This commit is contained in:
@@ -48,9 +48,6 @@ namespace PointCloudWeb.Server.ScanConverter
|
|||||||
//scan.RAY = (scan.RAY + 90) % 360;
|
//scan.RAY = (scan.RAY + 90) % 360;
|
||||||
|
|
||||||
return scan;
|
return scan;
|
||||||
if (scan.RAX == 1) return scan;
|
|
||||||
|
|
||||||
return new ScanDataPoint();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,6 @@ namespace PointCloudWeb.Server.Tests.Services
|
|||||||
|
|
||||||
var expected = new Point(x, y, z);
|
var expected = new Point(x, y, z);
|
||||||
|
|
||||||
var service = new ScanConverterService();
|
|
||||||
var point = ScanConverterService.Transform(scan);
|
var point = ScanConverterService.Transform(scan);
|
||||||
Assert.Equal(expected, point);
|
Assert.Equal(expected, point);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using PointCloudWeb.Server.Models;
|
using PointCloudWeb.Server.Models;
|
||||||
using PointCloudWeb.Server.Utils;
|
|
||||||
|
|
||||||
namespace PointCloudWeb.Server.Services
|
namespace PointCloudWeb.Server.Services
|
||||||
{
|
{
|
||||||
@@ -38,7 +37,7 @@ namespace PointCloudWeb.Server.Services
|
|||||||
|
|
||||||
private void InitSampleData()
|
private void InitSampleData()
|
||||||
{
|
{
|
||||||
EthTestData.CreateData(this);
|
//EthTestData.CreateData(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RaiseIfNotExists(Guid id)
|
private void RaiseIfNotExists(Guid id)
|
||||||
@@ -61,7 +60,7 @@ namespace PointCloudWeb.Server.Services
|
|||||||
|
|
||||||
public PointCloud AddPointCloud(Guid? id = null)
|
public PointCloud AddPointCloud(Guid? id = null)
|
||||||
{
|
{
|
||||||
if (id != null && _pointClouds.Contains(id))
|
if (_pointClouds.Contains(id))
|
||||||
throw new ArgumentOutOfRangeException($"Add of existing id \"{id}\" not possible!");
|
throw new ArgumentOutOfRangeException($"Add of existing id \"{id}\" not possible!");
|
||||||
|
|
||||||
var pc = new PointCloud(id ?? Guid.NewGuid(), $"Scan #{_pointClouds.Count + 1}");
|
var pc = new PointCloud(id ?? Guid.NewGuid(), $"Scan #{_pointClouds.Count + 1}");
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using PointCloudWeb.Server.Models;
|
using PointCloudWeb.Server.Models;
|
||||||
using PointCloudWeb.Server.Utils;
|
|
||||||
|
|
||||||
namespace PointCloudWeb.Server.Services
|
namespace PointCloudWeb.Server.Services
|
||||||
{
|
{
|
||||||
@@ -8,73 +7,14 @@ namespace PointCloudWeb.Server.Services
|
|||||||
{
|
{
|
||||||
public static Point Transform(ScanDataPoint scan)
|
public static Point Transform(ScanDataPoint scan)
|
||||||
{
|
{
|
||||||
// if (scan.RAX >= 90 || scan.RAY >= 90)
|
var alpha = scan.RAX * Math.PI / 180;
|
||||||
// return new Point(0, 0, 0);
|
var beta = scan.RAY * Math.PI / 180;
|
||||||
|
|
||||||
var degreeXa = (scan.RAX) % 360;
|
var p = new Point(
|
||||||
var degreeYa = scan.RAY;
|
y: (int)(scan.DistanceMM * Math.Sin(alpha)),
|
||||||
|
x: (int)(scan.DistanceMM * Math.Cos(beta) * Math.Cos(alpha)),
|
||||||
var factorY = 1;
|
z: (int)(scan.DistanceMM * Math.Sin(beta) * Math.Cos(alpha))
|
||||||
var factorZ = 1;
|
|
||||||
if (180 <= degreeXa && degreeXa <= 360)
|
|
||||||
{
|
|
||||||
factorY = -1;
|
|
||||||
factorZ = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var degreeXb = 180 - 90 - degreeXa;
|
|
||||||
var degreeYb = 180 - 90 - degreeYa;
|
|
||||||
|
|
||||||
var radXa = degreeXa * Math.PI / 180;
|
|
||||||
var radXb = degreeXb * Math.PI / 180;
|
|
||||||
var radYa = degreeYa * Math.PI / 180;
|
|
||||||
var radYb = degreeYb * Math.PI / 180;
|
|
||||||
|
|
||||||
var sinXa = Math.Sin(radXa);
|
|
||||||
var sinXb = Math.Sin(radXb);
|
|
||||||
var sinYa = Math.Sin(radYa);
|
|
||||||
var sinYb = Math.Sin(radYb);
|
|
||||||
|
|
||||||
if (sinXa == 0)
|
|
||||||
{
|
|
||||||
sinXa = 1;
|
|
||||||
sinXb = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sinYa == 0)
|
|
||||||
{
|
|
||||||
sinYa = 1;
|
|
||||||
sinYb = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
var z = Math.Sqrt(
|
|
||||||
Math.Pow(
|
|
||||||
Math.Pow(sinXb, 2) / Math.Pow(sinXa, 2)
|
|
||||||
+ Math.Pow(sinYb, 2) / Math.Pow(sinYa, 2)
|
|
||||||
+ 1
|
|
||||||
, -1)
|
|
||||||
* Math.Pow(scan.DistanceMM, 2)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var p = new Point
|
|
||||||
{
|
|
||||||
X = NumericUtils.Round(z * sinYb / sinYa),
|
|
||||||
Y = factorY * NumericUtils.Round(z * sinXb / sinXa),
|
|
||||||
Z = factorZ * NumericUtils.Round(z)
|
|
||||||
};
|
|
||||||
//return p;
|
|
||||||
|
|
||||||
//https://stackoverflow.com/questions/52781607/3d-point-from-two-angles-and-a-distance
|
|
||||||
var beta = radYa;
|
|
||||||
var alpha = radXa;
|
|
||||||
|
|
||||||
p = new Point
|
|
||||||
{
|
|
||||||
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;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,12 +38,10 @@ namespace PointCloudWeb.Server.Utils
|
|||||||
public static void CreateData(PointCloudService pointCloudService)
|
public static void CreateData(PointCloudService pointCloudService)
|
||||||
{
|
{
|
||||||
var pc = pointCloudService.AddPointCloud();
|
var pc = pointCloudService.AddPointCloud();
|
||||||
pc.Name = "Scan 1";
|
|
||||||
LoadPointCloudFromEthFile(pc, "ETH-Data/Hokuyo_0.csv");
|
LoadPointCloudFromEthFile(pc, "ETH-Data/Hokuyo_0.csv");
|
||||||
pointCloudService.PointCloudCompleted(pc.Id);
|
pointCloudService.PointCloudCompleted(pc.Id);
|
||||||
|
|
||||||
pc = pointCloudService.AddPointCloud();
|
pc = pointCloudService.AddPointCloud();
|
||||||
pc.Name = "Scan 2";
|
|
||||||
LoadPointCloudFromEthFile(pc, "ETH-Data/Hokuyo_1.csv");
|
LoadPointCloudFromEthFile(pc, "ETH-Data/Hokuyo_1.csv");
|
||||||
pointCloudService.PointCloudCompleted(pc.Id);
|
pointCloudService.PointCloudCompleted(pc.Id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user