add rotation and transformation of PointClouds in map-view

This commit is contained in:
Tim Wundenberg
2021-08-17 21:45:44 +02:00
parent 6b6207bc0e
commit 2d5990c01b
6 changed files with 55 additions and 122 deletions

View File

@@ -1,39 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using PointCloudWeb.Server.Models;
using PointCloudWeb.Server.Services;
using System;
using System.Collections.Generic;
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) => new PointCloudDto(pc.Id, 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);
}
}
}

View File

@@ -3,6 +3,7 @@ using PointCloudWeb.Server.Models;
using PointCloudWeb.Server.Services; using PointCloudWeb.Server.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics;
namespace PointCloudWeb.Server.Controllers namespace PointCloudWeb.Server.Controllers
{ {
@@ -17,7 +18,8 @@ namespace PointCloudWeb.Server.Controllers
_pointCloudService = pointCloudService; _pointCloudService = pointCloudService;
} }
private PointCloudInfoDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudInfoDto(pc.Id, pc.Name); private static PointCloudInfoDto ConvertPointCloudToDto(PointCloud pc) =>
new PointCloudInfoDto(pc.Id, pc.Name, pc.Rotation, pc.Transformation);
[HttpGet] [HttpGet]
public IList<PointCloudInfoDto> GetAll() public IList<PointCloudInfoDto> GetAll()
@@ -57,7 +59,11 @@ namespace PointCloudWeb.Server.Controllers
var pc = _pointCloudService.GetById(newPc.Id); var pc = _pointCloudService.GetById(newPc.Id);
if (pc == null) if (pc == null)
return new NotFoundResult(); return new NotFoundResult();
pc.Name = newPc.Name; pc.Name = newPc.Name;
pc.Rotation = new Vector3(newPc.Rotation.X, newPc.Rotation.Y, newPc.Rotation.Z);
pc.Transformation = new Vector3(newPc.Transformation.X, newPc.Transformation.Y, newPc.Transformation.Z);
return ConvertPointCloudToDto(pc); return ConvertPointCloudToDto(pc);
} }
} }

View File

@@ -1,8 +1,5 @@
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.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
@@ -45,14 +42,9 @@ namespace PointCloudWeb.Server.Models
public class PointCloud public class PointCloud
{ {
private readonly ObservableCollection<Point> _points;
private Matrix4x4 _transformation;
public PointCloud(Guid id, string name) public PointCloud(Guid id, string name)
{ {
_points = new ObservableCollection<Point>(); Points = new List<Point>();
_points.CollectionChanged += PointsCollectionChanged;
TransformedPoints = new List<Point>();
Id = id; Id = id;
Name = name; Name = name;
} }
@@ -61,59 +53,18 @@ namespace PointCloudWeb.Server.Models
public string Name { get; set; } public string Name { get; set; }
public IList<Point> Points => _points; public IList<Point> Points { get; }
// ReSharper disable once MemberCanBePrivate.Global public Vector3 Transformation { get; set; }
public Matrix4x4 Transformation public Vector3 Rotation { get; set; }
{
get => _transformation;
set
{
_transformation = value;
TransformationChanged();
}
}
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();
}
private void TransformationChanged()
{
TransformedPoints.Clear();
if (Transformation.IsIdentity)
return;
foreach (var point in Points)
{
var transformedPoint = GetTransformedPoint(point);
TransformedPoints.Add(transformedPoint);
}
}
// ReSharper disable once MemberCanBePrivate.Global // ReSharper disable once MemberCanBePrivate.Global
public string ToStringXyz() public string ToStringXyz()
{ {
var stringBuilder = new StringBuilder(); var stringBuilder = new StringBuilder();
foreach (var point in _points) foreach (var point in Points)
{ {
// + 0.001 Otherwise points are outside of the bounding box by a floating-error, then Potree-Converter fails
stringBuilder.AppendLine(string.Join(',', stringBuilder.AppendLine(string.Join(',',
(point.X).ToString(CultureInfo.InvariantCulture), (point.X).ToString(CultureInfo.InvariantCulture),
(point.Y).ToString(CultureInfo.InvariantCulture), (point.Y).ToString(CultureInfo.InvariantCulture),

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
namespace PointCloudWeb.Server.Models
{
public class PointCloudDto
{
public PointCloudDto(Guid id, IList<Point> points)
{
Id = id;
Points = points;
}
public Guid Id { get; }
public IList<Point> Points { get; }
}
}

View File

@@ -1,20 +1,47 @@
using System; using System;
using System.Numerics;
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global
namespace PointCloudWeb.Server.Models namespace PointCloudWeb.Server.Models
{ {
public class PointCloudInfoDto [Serializable]
public class Vector3Ser
{ {
public PointCloudInfoDto() : this(Guid.Empty, "") public Vector3Ser() : this(0, 0, 0)
{ {
} }
public PointCloudInfoDto(Guid id, string name) public Vector3Ser(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
}
public class PointCloudInfoDto
{
public PointCloudInfoDto() : this(Guid.Empty, "", Vector3.Zero, Vector3.Zero)
{
}
public PointCloudInfoDto(Guid id, string name, Vector3 rotation, Vector3 transformation)
{ {
Id = id; Id = id;
Name = name; Name = name;
Rotation = new Vector3Ser(rotation.X, rotation.Y, rotation.Z);
Transformation = new Vector3Ser(transformation.X, transformation.Y, transformation.Z);
} }
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public Vector3Ser Rotation { get; set; }
public Vector3Ser Transformation { get; set; }
} }
} }

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Numerics;
using PointCloudWeb.Server.Models; using PointCloudWeb.Server.Models;
using PointCloudWeb.Server.Utils; using PointCloudWeb.Server.Utils;
@@ -73,11 +74,15 @@ namespace PointCloudWeb.Server.Services
public PointCloud GetById(Guid id) => _pointClouds.GetById(id); public PointCloud GetById(Guid id) => _pointClouds.GetById(id);
public void RegisterPointCloud(Guid id) private void RegisterPointCloud(Guid id)
{ {
RaiseIfNotExists(id); RaiseIfNotExists(id);
// var pointCloud = _pointClouds.GetById(id);
// var pc = GetById(id);
pc.Transformation = Vector3.Zero;
pc.Rotation = Vector3.Zero;
// //the first can't be registered // //the first can't be registered
// if (_pointClouds.IndexOf(pointCloud) == 0) // if (_pointClouds.IndexOf(pointCloud) == 0)
// return; // return;