From 2d5990c01b55dff8ebca6162227423556492b896 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Tue, 17 Aug 2021 21:45:44 +0200 Subject: [PATCH] add rotation and transformation of PointClouds in map-view --- .../Controllers/PointCloudController.cs | 39 ----------- .../Controllers/PointCloudInfoController.cs | 8 ++- .../PointCloudWeb.Server/Models/PointCloud.cs | 69 +++---------------- .../Models/PointCloudDto.cs | 17 ----- .../Models/PointCloudInfoDto.cs | 33 ++++++++- .../Services/PointCloudService.cs | 11 ++- 6 files changed, 55 insertions(+), 122 deletions(-) delete mode 100644 PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs delete mode 100644 PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs deleted file mode 100644 index 1af0905..0000000 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudController.cs +++ /dev/null @@ -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 GetAll() - { - var result = new List(); - 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); - } - } -} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudInfoController.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudInfoController.cs index 121bf94..f279f72 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudInfoController.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Controllers/PointCloudInfoController.cs @@ -3,6 +3,7 @@ using PointCloudWeb.Server.Models; using PointCloudWeb.Server.Services; using System; using System.Collections.Generic; +using System.Numerics; namespace PointCloudWeb.Server.Controllers { @@ -17,7 +18,8 @@ namespace PointCloudWeb.Server.Controllers _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] public IList GetAll() @@ -57,7 +59,11 @@ namespace PointCloudWeb.Server.Controllers var pc = _pointCloudService.GetById(newPc.Id); if (pc == null) return new NotFoundResult(); + 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); } } diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs index 31aba9f..6b680b0 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloud.cs @@ -1,8 +1,5 @@ -using PointCloudWeb.Server.Utils; using System; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -45,14 +42,9 @@ namespace PointCloudWeb.Server.Models public class PointCloud { - private readonly ObservableCollection _points; - private Matrix4x4 _transformation; - public PointCloud(Guid id, string name) { - _points = new ObservableCollection(); - _points.CollectionChanged += PointsCollectionChanged; - TransformedPoints = new List(); + Points = new List(); Id = id; Name = name; } @@ -61,63 +53,22 @@ namespace PointCloudWeb.Server.Models public string Name { get; set; } - public IList Points => _points; + public IList Points { get; } - // ReSharper disable once MemberCanBePrivate.Global - public Matrix4x4 Transformation - { - get => _transformation; - set - { - _transformation = value; - TransformationChanged(); - } - } + public Vector3 Transformation { get; set; } + public Vector3 Rotation { get; set; } - public IList 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 public string ToStringXyz() { 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(',', - (point.X).ToString(CultureInfo.InvariantCulture), - (point.Y).ToString(CultureInfo.InvariantCulture), - (point.Z).ToString(CultureInfo.InvariantCulture) + stringBuilder.AppendLine(string.Join(',', + (point.X).ToString(CultureInfo.InvariantCulture), + (point.Y).ToString(CultureInfo.InvariantCulture), + (point.Z).ToString(CultureInfo.InvariantCulture) ) ); } @@ -143,7 +94,7 @@ namespace PointCloudWeb.Server.Models cloudCompare.Start(); cloudCompare.WaitForExit(); } - + public void WriteToLas(string fileName) { var fileNameXyz = Path.ChangeExtension(fileName, ".xyz"); diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs deleted file mode 100644 index 81356a2..0000000 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudDto.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace PointCloudWeb.Server.Models -{ - public class PointCloudDto - { - public PointCloudDto(Guid id, IList points) - { - Id = id; - Points = points; - } - - public Guid Id { get; } - public IList Points { get; } - } -} \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudInfoDto.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudInfoDto.cs index f8c06ab..f2d963b 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudInfoDto.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Models/PointCloudInfoDto.cs @@ -1,20 +1,47 @@ using System; +using System.Numerics; + +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable MemberCanBePrivate.Global 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; 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 string Name { get; set; } + public Vector3Ser Rotation { get; set; } + public Vector3Ser Transformation { get; set; } } } \ No newline at end of file diff --git a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs index 322412c..7b7ecbd 100644 --- a/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs +++ b/PointCloudWeb.Server/PointCloudWeb.Server/Services/PointCloudService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Numerics; using PointCloudWeb.Server.Models; using PointCloudWeb.Server.Utils; @@ -73,11 +74,15 @@ namespace PointCloudWeb.Server.Services public PointCloud GetById(Guid id) => _pointClouds.GetById(id); - public void RegisterPointCloud(Guid id) + private void RegisterPointCloud(Guid 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 // if (_pointClouds.IndexOf(pointCloud) == 0) // return;