add PointCloudInfo Controller
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ bin/
|
||||
obj/
|
||||
.vscode/
|
||||
node_modules/
|
||||
*.csproj.user
|
||||
@@ -18,7 +18,7 @@ namespace PointCloudWeb.Server.Controllers
|
||||
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]
|
||||
public IList<PointCloudDto> GetAll()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,9 @@ namespace PointCloudWeb.Server.Controllers
|
||||
[Route("[controller]")]
|
||||
public class DataController : ControllerBase
|
||||
{
|
||||
private readonly DataService scanDataService;
|
||||
private readonly ScanDataService scanDataService;
|
||||
|
||||
public DataController(DataService scanDataService)
|
||||
public DataController(ScanDataService scanDataService)
|
||||
{
|
||||
this.scanDataService = scanDataService;
|
||||
}
|
||||
|
||||
@@ -117,12 +117,12 @@ namespace PointCloudWeb.Server.Models
|
||||
|
||||
public bool Contains(Guid id)
|
||||
{
|
||||
return this.Any(pc => pc.Id == id);
|
||||
return GetById(id) != null;
|
||||
}
|
||||
|
||||
public PointCloud GetById(Guid id)
|
||||
{
|
||||
return this.First(pc => pc.Id == id);
|
||||
return this.Find(pc => pc.Id == id);
|
||||
}
|
||||
|
||||
public void RemoveById(Guid id)
|
||||
|
||||
@@ -7,15 +7,13 @@ namespace PointCloudWeb.Server.Models
|
||||
{
|
||||
public class PointCloudDto
|
||||
{
|
||||
public PointCloudDto(Guid id, string name, IList<Point> points)
|
||||
public PointCloudDto(Guid id, IList<Point> points)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Points = points;
|
||||
}
|
||||
|
||||
public Guid Id { get; }
|
||||
public string Name { get; }
|
||||
public IList<Point> Points { get; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace PointCloudWeb.Server.Models
|
||||
{
|
||||
@@ -31,5 +32,10 @@ namespace PointCloudWeb.Server.Models
|
||||
public double RAX { get; set; }
|
||||
|
||||
public double RAY { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Join(", ", new string[] { RAY.ToString(), RAX.ToString(), DistanceMM.ToString() });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,9 @@
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -6,13 +6,22 @@ namespace PointCloudWeb.Server.Services
|
||||
{
|
||||
public class PointCloudService
|
||||
{
|
||||
private readonly IPointCloudRegistationService pointCloudRegistation;
|
||||
//private readonly IPointCloudRegistationService pointCloudRegistation;
|
||||
private readonly PointCloudCollection pointClouds;
|
||||
|
||||
public PointCloudService(IPointCloudRegistationService pointCloudRegistation)
|
||||
public PointCloudService(/*IPointCloudRegistationService pointCloudRegistation*/)
|
||||
{
|
||||
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)
|
||||
@@ -50,8 +59,8 @@ namespace PointCloudWeb.Server.Services
|
||||
if (pointClouds.IndexOf(pointCloud) == 0)
|
||||
return;
|
||||
|
||||
var transformation = pointCloudRegistation.RegisterPointCloud(pointCloud, pointClouds[0]);
|
||||
pointCloud.Transformation = transformation;
|
||||
//var transformation = pointCloudRegistation.RegisterPointCloud(pointCloud, pointClouds[0]);
|
||||
//pointCloud.Transformation = transformation;
|
||||
}
|
||||
|
||||
public void RegisterPointClouds()
|
||||
|
||||
@@ -8,17 +8,18 @@ namespace PointCloudWeb.Server.Services
|
||||
{
|
||||
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 degreeYA = scan.RAY;
|
||||
|
||||
if (degreeXA > 270 && degreeYA > 270)
|
||||
{
|
||||
degreeXA -= 270;
|
||||
degreeYA -= 270;
|
||||
factorZ = -1;
|
||||
}
|
||||
//if (degreeXA > 270 && degreeYA > 270)
|
||||
//{
|
||||
// degreeXA -= 270;
|
||||
// degreeYA -= 270;
|
||||
// factorZ = -1;
|
||||
//}
|
||||
|
||||
var degreeXB = 180 - 90 - degreeXA;
|
||||
var degreeYB = 180 - 90 - degreeYA;
|
||||
@@ -46,7 +47,7 @@ namespace PointCloudWeb.Server.Services
|
||||
{
|
||||
X = NumericUtils.Round(z * sinYB / sinYA),
|
||||
Y = NumericUtils.Round(z * sinXB / sinXA),
|
||||
Z = factorZ * NumericUtils.Round(z)
|
||||
Z = NumericUtils.Round(z)
|
||||
};
|
||||
|
||||
return p;
|
||||
|
||||
@@ -4,12 +4,12 @@ using PointCloudWeb.Server.Models;
|
||||
|
||||
namespace PointCloudWeb.Server.Services
|
||||
{
|
||||
public class DataService
|
||||
public class ScanDataService
|
||||
{
|
||||
private readonly PointCloudService pointCloudService;
|
||||
private readonly ScanConverterService scanConverterService;
|
||||
|
||||
public DataService(PointCloudService pointCloudService, ScanConverterService scanConverterService)
|
||||
public ScanDataService(PointCloudService pointCloudService, ScanConverterService scanConverterService)
|
||||
{
|
||||
this.pointCloudService = pointCloudService;
|
||||
this.scanConverterService = scanConverterService;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PointCloudWeb.Server.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -31,7 +33,7 @@ namespace PointCloudWeb.Server
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
//app.UseAuthorization();
|
||||
|
||||
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.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<PointCloudService>();
|
||||
services.AddTransient<ScanConverterService>();
|
||||
services.AddTransient<ScanDataService>();
|
||||
services.AddControllers();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user