add PointCloudController
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
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 PointCloudController
|
||||||
|
{
|
||||||
|
private readonly PointCloudService pointCloudService;
|
||||||
|
|
||||||
|
public PointCloudController(PointCloudService pointCloudService)
|
||||||
|
{
|
||||||
|
this.pointCloudService = pointCloudService;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PointCloudDto ConvertPointCloudToDto(PointCloud pc)
|
||||||
|
{
|
||||||
|
return new PointCloudDto(pc.Id, pc.Name, pc.TransformedPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IList<PointCloudDto> GetAll()
|
||||||
|
{
|
||||||
|
var result = new List<PointCloudDto>();
|
||||||
|
foreach (var pc in pointCloudService.GetAll())
|
||||||
|
result.Add(ConvertPointCloudToDto(pc));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public PointCloudDto GetById(Guid id)
|
||||||
|
{
|
||||||
|
var pc = pointCloudService.GetById(id) ?? throw new KeyNotFoundException();
|
||||||
|
return ConvertPointCloudToDto(pc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,7 +46,7 @@ namespace PointCloudWeb.Server.Models
|
|||||||
private ObservableCollection<Point> points;
|
private ObservableCollection<Point> points;
|
||||||
private Matrix4x4 transformation;
|
private Matrix4x4 transformation;
|
||||||
|
|
||||||
public PointCloud(string name, Guid id)
|
public PointCloud(Guid id, string name)
|
||||||
{
|
{
|
||||||
points = new ObservableCollection<Point>();
|
points = new ObservableCollection<Point>();
|
||||||
points.CollectionChanged += PointsCollectionChanged;
|
points.CollectionChanged += PointsCollectionChanged;
|
||||||
@@ -110,7 +110,7 @@ namespace PointCloudWeb.Server.Models
|
|||||||
public PointCloud AddNew()
|
public PointCloud AddNew()
|
||||||
{
|
{
|
||||||
var id = Guid.NewGuid();
|
var id = Guid.NewGuid();
|
||||||
var pc = new PointCloud(id.ToString(), id);
|
var pc = new PointCloud(id, "Scan #" + (Count + 1).ToString());
|
||||||
Add(pc);
|
Add(pc);
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PointCloudWeb.Server.Models
|
||||||
|
{
|
||||||
|
public class PointCloudDto
|
||||||
|
{
|
||||||
|
public PointCloudDto(Guid id, string name, IList<Point> points)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Name = name;
|
||||||
|
Points = points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Guid Id { get; }
|
||||||
|
public string Name { get; }
|
||||||
|
public IList<Point> Points { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,6 +31,16 @@ namespace PointCloudWeb.Server.Services
|
|||||||
pc.Points.Add(point);
|
pc.Points.Add(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IList<PointCloud> GetAll()
|
||||||
|
{
|
||||||
|
return pointClouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PointCloud GetById(Guid id)
|
||||||
|
{
|
||||||
|
return pointClouds.GetById(id);
|
||||||
|
}
|
||||||
|
|
||||||
public void RegisterPointCloud(Guid id)
|
public void RegisterPointCloud(Guid id)
|
||||||
{
|
{
|
||||||
RaiseIfNotExists(id);
|
RaiseIfNotExists(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user