add PointCloudInfo Controller

This commit is contained in:
Tim Wundenberg
2021-07-30 20:31:27 +02:00
parent f27628c57d
commit 8bef0824ce
13 changed files with 122 additions and 25 deletions

3
.gitignore vendored
View File

@@ -2,4 +2,5 @@
bin/ bin/
obj/ obj/
.vscode/ .vscode/
node_modules/ node_modules/
*.csproj.user

View File

@@ -18,7 +18,7 @@ namespace PointCloudWeb.Server.Controllers
this.pointCloudService = pointCloudService; this.pointCloudService = pointCloudService;
} }
private PointCloudDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudDto(pc.Id, pc.Name, pc.TransformedPoints); private PointCloudDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudDto(pc.Id, pc.TransformedPoints);
[HttpGet] [HttpGet]
public IList<PointCloudDto> GetAll() public IList<PointCloudDto> GetAll()

View File

@@ -0,0 +1,53 @@
using Microsoft.AspNetCore.Mvc;
using PointCloudWeb.Server.Models;
using PointCloudWeb.Server.Services;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PointCloudWeb.Server.Controllers
{
[ApiController]
[Route("[controller]")]
public class PointCloudInfoController
{
private readonly PointCloudService pointCloudService;
public PointCloudInfoController(PointCloudService pointCloudService)
{
this.pointCloudService = pointCloudService;
}
private PointCloudInfoDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudInfoDto(pc.Id, pc.Name);
[HttpGet]
public IList<PointCloudInfoDto> GetAll()
{
var result = new List<PointCloudInfoDto>();
foreach (var pc in pointCloudService.GetAll())
result.Add(ConvertPointCloudToDto(pc));
return result;
}
[HttpGet]
[Route("{id:Guid}")]
public ActionResult<PointCloudInfoDto> GetById(Guid id)
{
var pc = pointCloudService.GetById(id);
if (pc == null)
return new NotFoundResult();
return ConvertPointCloudToDto(pc);
}
[HttpPut]
public ActionResult<PointCloudInfoDto> UpdatePointCloud([FromBody] PointCloudInfoDto newPc)
{
var pc = pointCloudService.GetById(newPc.Id);
if (pc == null)
return new NotFoundResult();
pc.Name = newPc.Name;
return ConvertPointCloudToDto(pc);
}
}
}

View File

@@ -9,9 +9,9 @@ namespace PointCloudWeb.Server.Controllers
[Route("[controller]")] [Route("[controller]")]
public class DataController : ControllerBase public class DataController : ControllerBase
{ {
private readonly DataService scanDataService; private readonly ScanDataService scanDataService;
public DataController(DataService scanDataService) public DataController(ScanDataService scanDataService)
{ {
this.scanDataService = scanDataService; this.scanDataService = scanDataService;
} }

View File

@@ -117,12 +117,12 @@ namespace PointCloudWeb.Server.Models
public bool Contains(Guid id) public bool Contains(Guid id)
{ {
return this.Any(pc => pc.Id == id); return GetById(id) != null;
} }
public PointCloud GetById(Guid id) public PointCloud GetById(Guid id)
{ {
return this.First(pc => pc.Id == id); return this.Find(pc => pc.Id == id);
} }
public void RemoveById(Guid id) public void RemoveById(Guid id)

View File

@@ -7,15 +7,13 @@ namespace PointCloudWeb.Server.Models
{ {
public class PointCloudDto public class PointCloudDto
{ {
public PointCloudDto(Guid id, string name, IList<Point> points) public PointCloudDto(Guid id, IList<Point> points)
{ {
Id = id; Id = id;
Name = name;
Points = points; Points = points;
} }
public Guid Id { get; } public Guid Id { get; }
public string Name { get; }
public IList<Point> Points { get; } public IList<Point> Points { get; }
} }
} }

View File

@@ -0,0 +1,20 @@
using System;
namespace PointCloudWeb.Server.Models
{
public class PointCloudInfoDto
{
public PointCloudInfoDto() : this(Guid.Empty, "")
{
}
public PointCloudInfoDto(Guid id, string name)
{
Id = id;
Name = name;
}
public Guid Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace PointCloudWeb.Server.Models namespace PointCloudWeb.Server.Models
{ {
@@ -31,5 +32,10 @@ namespace PointCloudWeb.Server.Models
public double RAX { get; set; } public double RAX { get; set; }
public double RAY { get; set; } public double RAY { get; set; }
public override string ToString()
{
return String.Join(", ", new string[] { RAY.ToString(), RAX.ToString(), DistanceMM.ToString() });
}
} }
} }

View File

@@ -4,5 +4,9 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
</ItemGroup>
</Project> </Project>

View File

@@ -6,13 +6,22 @@ namespace PointCloudWeb.Server.Services
{ {
public class PointCloudService public class PointCloudService
{ {
private readonly IPointCloudRegistationService pointCloudRegistation; //private readonly IPointCloudRegistationService pointCloudRegistation;
private readonly PointCloudCollection pointClouds; private readonly PointCloudCollection pointClouds;
public PointCloudService(IPointCloudRegistationService pointCloudRegistation) public PointCloudService(/*IPointCloudRegistationService pointCloudRegistation*/)
{ {
pointClouds = new PointCloudCollection(); pointClouds = new PointCloudCollection();
this.pointCloudRegistation = pointCloudRegistation; //this.pointCloudRegistation = pointCloudRegistation;
InitSamleData();
}
private void InitSamleData()
{
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 1"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 2"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 3"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 4"));
} }
private void RaiseIfNotExists(Guid id) private void RaiseIfNotExists(Guid id)
@@ -50,8 +59,8 @@ namespace PointCloudWeb.Server.Services
if (pointClouds.IndexOf(pointCloud) == 0) if (pointClouds.IndexOf(pointCloud) == 0)
return; return;
var transformation = pointCloudRegistation.RegisterPointCloud(pointCloud, pointClouds[0]); //var transformation = pointCloudRegistation.RegisterPointCloud(pointCloud, pointClouds[0]);
pointCloud.Transformation = transformation; //pointCloud.Transformation = transformation;
} }
public void RegisterPointClouds() public void RegisterPointClouds()

View File

@@ -8,17 +8,18 @@ namespace PointCloudWeb.Server.Services
{ {
public Point Transform(ScanDataPoint scan) public Point Transform(ScanDataPoint scan)
{ {
var factorZ = 1; if (scan.RAX >= 180 || scan.RAY >= 180)
return new Point(0, 0, 0);
var degreeXA = scan.RAX; var degreeXA = scan.RAX;
var degreeYA = scan.RAY; var degreeYA = scan.RAY;
if (degreeXA > 270 && degreeYA > 270) //if (degreeXA > 270 && degreeYA > 270)
{ //{
degreeXA -= 270; // degreeXA -= 270;
degreeYA -= 270; // degreeYA -= 270;
factorZ = -1; // factorZ = -1;
} //}
var degreeXB = 180 - 90 - degreeXA; var degreeXB = 180 - 90 - degreeXA;
var degreeYB = 180 - 90 - degreeYA; var degreeYB = 180 - 90 - degreeYA;
@@ -46,7 +47,7 @@ namespace PointCloudWeb.Server.Services
{ {
X = NumericUtils.Round(z * sinYB / sinYA), X = NumericUtils.Round(z * sinYB / sinYA),
Y = NumericUtils.Round(z * sinXB / sinXA), Y = NumericUtils.Round(z * sinXB / sinXA),
Z = factorZ * NumericUtils.Round(z) Z = NumericUtils.Round(z)
}; };
return p; return p;

View File

@@ -4,12 +4,12 @@ using PointCloudWeb.Server.Models;
namespace PointCloudWeb.Server.Services namespace PointCloudWeb.Server.Services
{ {
public class DataService public class ScanDataService
{ {
private readonly PointCloudService pointCloudService; private readonly PointCloudService pointCloudService;
private readonly ScanConverterService scanConverterService; private readonly ScanConverterService scanConverterService;
public DataService(PointCloudService pointCloudService, ScanConverterService scanConverterService) public ScanDataService(PointCloudService pointCloudService, ScanConverterService scanConverterService)
{ {
this.pointCloudService = pointCloudService; this.pointCloudService = pointCloudService;
this.scanConverterService = scanConverterService; this.scanConverterService = scanConverterService;

View File

@@ -1,10 +1,12 @@
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PointCloudWeb.Server.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -31,7 +33,7 @@ namespace PointCloudWeb.Server
app.UseRouting(); app.UseRouting();
app.UseAuthorization(); //app.UseAuthorization();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
@@ -42,6 +44,9 @@ namespace PointCloudWeb.Server
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddSingleton<PointCloudService>();
services.AddTransient<ScanConverterService>();
services.AddTransient<ScanDataService>();
services.AddControllers(); services.AddControllers();
} }
} }