fix hints and warnings

This commit is contained in:
Tim Wundenberg
2021-08-01 12:22:12 +02:00
parent c6d6a437dc
commit 419a468dc5
15 changed files with 90 additions and 152 deletions

View File

@@ -10,7 +10,7 @@ namespace PointCloudWeb.Server.ScanConverter
{
internal class Program
{
private static void Main(string[] args)
private static void Main()
{
var scanPoints = File.ReadAllLines("C:\\Users\\timwu\\Desktop\\Scans\\0yGrad-edited-scan.csv")
.Select(v => ScanDataPointFromCsv(v))

View File

@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/SweaWarningsMode/@EntryValue">ShowAndRun</s:String></wpf:ResourceDictionary>

View File

@@ -3,7 +3,6 @@ using PointCloudWeb.Server.Models;
using PointCloudWeb.Server.Services;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PointCloudWeb.Server.Controllers
{
@@ -11,11 +10,11 @@ namespace PointCloudWeb.Server.Controllers
[Route("[controller]")]
public class PointCloudController
{
private readonly PointCloudService pointCloudService;
private readonly PointCloudService _pointCloudService;
public PointCloudController(PointCloudService pointCloudService)
{
this.pointCloudService = pointCloudService;
this._pointCloudService = pointCloudService;
}
private PointCloudDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudDto(pc.Id, pc.TransformedPoints);
@@ -24,7 +23,7 @@ namespace PointCloudWeb.Server.Controllers
public IList<PointCloudDto> GetAll()
{
var result = new List<PointCloudDto>();
foreach (var pc in pointCloudService.GetAll())
foreach (var pc in _pointCloudService.GetAll())
result.Add(ConvertPointCloudToDto(pc));
return result;
@@ -33,7 +32,7 @@ namespace PointCloudWeb.Server.Controllers
[HttpGet]
public PointCloudDto GetById(Guid id)
{
var pc = pointCloudService.GetById(id) ?? throw new KeyNotFoundException();
var pc = _pointCloudService.GetById(id) ?? throw new KeyNotFoundException();
return ConvertPointCloudToDto(pc);
}
}

View File

@@ -3,7 +3,6 @@ using PointCloudWeb.Server.Models;
using PointCloudWeb.Server.Services;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PointCloudWeb.Server.Controllers
{
@@ -11,11 +10,11 @@ namespace PointCloudWeb.Server.Controllers
[Route("[controller]")]
public class PointCloudInfoController
{
private readonly PointCloudService pointCloudService;
private readonly PointCloudService _pointCloudService;
public PointCloudInfoController(PointCloudService pointCloudService)
{
this.pointCloudService = pointCloudService;
this._pointCloudService = pointCloudService;
}
private PointCloudInfoDto ConvertPointCloudToDto(PointCloud pc) => new PointCloudInfoDto(pc.Id, pc.Name);
@@ -24,7 +23,7 @@ namespace PointCloudWeb.Server.Controllers
public IList<PointCloudInfoDto> GetAll()
{
var result = new List<PointCloudInfoDto>();
foreach (var pc in pointCloudService.GetAll())
foreach (var pc in _pointCloudService.GetAll())
result.Add(ConvertPointCloudToDto(pc));
return result;
@@ -34,7 +33,7 @@ namespace PointCloudWeb.Server.Controllers
[Route("{id:Guid}")]
public ActionResult<PointCloudInfoDto> GetById(Guid id)
{
var pc = pointCloudService.GetById(id);
var pc = _pointCloudService.GetById(id);
if (pc == null)
return new NotFoundResult();
return ConvertPointCloudToDto(pc);
@@ -44,17 +43,17 @@ namespace PointCloudWeb.Server.Controllers
[Route("{id:Guid}")]
public ActionResult RemoveById(Guid id)
{
if (pointCloudService.GetById(id) == null)
if (_pointCloudService.GetById(id) == null)
return new NotFoundResult();
pointCloudService.RemoveById(id);
_pointCloudService.RemoveById(id);
return new OkResult();
}
[HttpPut]
public ActionResult<PointCloudInfoDto> UpdatePointCloud([FromBody] PointCloudInfoDto newPc)
{
var pc = pointCloudService.GetById(newPc.Id);
var pc = _pointCloudService.GetById(newPc.Id);
if (pc == null)
return new NotFoundResult();
pc.Name = newPc.Name;

View File

@@ -9,23 +9,23 @@ namespace PointCloudWeb.Server.Controllers
[Route("[controller]")]
public class DataController : ControllerBase
{
private readonly ScanDataService scanDataService;
private readonly ScanDataService _scanDataService;
public DataController(ScanDataService scanDataService)
{
this.scanDataService = scanDataService;
this._scanDataService = scanDataService;
}
[HttpPost]
public void PostScanData([FromBody] ScanDataList data)
{
scanDataService.AddScan(data);
_scanDataService.AddScan(data);
}
[HttpPut]
public void ScanFinished(Guid id)
{
scanDataService.ScanFinished(id);
_scanDataService.ScanFinished(id);
}
}
}

View File

@@ -1,39 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PointCloudWeb.Server.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
this.logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}

View File

@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
namespace PointCloudWeb.Server.Models
@@ -27,29 +27,27 @@ namespace PointCloudWeb.Server.Models
public override bool Equals(object obj)
{
if ((obj == null) || !GetType().Equals(obj.GetType()))
if (obj == null || GetType() != obj.GetType())
return false;
else
{
Point p = (Point)obj;
return (X == p.X) && (Y == p.Y) && (Z == p.Z);
}
var p = (Point) obj;
return X == p.X && Y == p.Y && Z == p.Z;
}
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
public override int GetHashCode() => HashCode.Combine(X, Y, Z);
public override string ToString() => X.ToString() + " " + Y.ToString() + " " + Z.ToString();
public override string ToString() => X + " " + Y + " " + Z;
}
public class PointCloud
{
private ObservableCollection<Point> points;
private Matrix4x4 transformation;
private readonly ObservableCollection<Point> _points;
private Matrix4x4 _transformation;
public PointCloud(Guid id, string name)
{
points = new ObservableCollection<Point>();
points.CollectionChanged += PointsCollectionChanged;
_points = new ObservableCollection<Point>();
_points.CollectionChanged += PointsCollectionChanged;
TransformedPoints = new List<Point>();
Id = id;
Name = name;
@@ -59,15 +57,18 @@ namespace PointCloudWeb.Server.Models
public string Name { get; set; }
public IList<Point> Points { get => points; }
public IList<Point> Points
{
get => _points;
}
public Matrix4x4 Transformation
{
get => transformation;
get => _transformation;
set
{
TransformationChanged();
transformation = value;
_transformation = value;
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PointCloudWeb.Server.Models
{

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
namespace PointCloudWeb.Server.Models
{
@@ -10,6 +11,7 @@ namespace PointCloudWeb.Server.Models
public IList<ScanDataPoint> ScanPoints { get; set; }
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class ScanDataPoint
{
public ScanDataPoint()
@@ -27,15 +29,17 @@ namespace PointCloudWeb.Server.Models
}
public float DistanceMM { get; set; }
//RotationAngle on {X, Y} Axis
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() });
return string.Join(
", ",
RAY.ToString(CultureInfo.InvariantCulture),
RAX.ToString(CultureInfo.InvariantCulture),
DistanceMM.ToString(CultureInfo.InvariantCulture));
}
}
}

View File

@@ -1,14 +0,0 @@
using System;
namespace PointCloudWeb.Server
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public string Summary { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View File

@@ -1,11 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PointCloudWeb.Server
{

View File

@@ -7,40 +7,40 @@ namespace PointCloudWeb.Server.Services
public class PointCloudService
{
//private readonly IPointCloudRegistationService pointCloudRegistation;
private readonly PointCloudCollection pointClouds;
private readonly PointCloudCollection _pointClouds;
public PointCloudService(/*IPointCloudRegistationService pointCloudRegistation*/)
{
pointClouds = new PointCloudCollection();
_pointClouds = new PointCloudCollection();
//this.pointCloudRegistation = pointCloudRegistation;
InitSampleData();
}
private void InitSampleData()
{
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"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 5"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 6"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 7"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 8"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 9"));
pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 10"));
_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"));
_pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 5"));
_pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 6"));
_pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 7"));
_pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 8"));
_pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 9"));
_pointClouds.Add(new PointCloud(Guid.NewGuid(), "Scan 10"));
}
private void RaiseIfNotExists(Guid id)
{
if (!pointClouds.Contains(id))
throw new ArgumentOutOfRangeException("The Id {0} was not found!", id.ToString());
if (!_pointClouds.Contains(id))
throw new ArgumentOutOfRangeException($"The Id {id.ToString()} was not found!");
}
public void AddPoints(Guid id, IList<Point> points)
{
RaiseIfNotExists(id);
var pc = pointClouds.GetById(id);
var pc = _pointClouds.GetById(id);
foreach (var point in points)
pc.Points.Add(point);
@@ -48,22 +48,22 @@ namespace PointCloudWeb.Server.Services
public IList<PointCloud> GetAll()
{
return pointClouds;
return _pointClouds;
}
public PointCloud GetById(Guid id)
{
return pointClouds.GetById(id);
return _pointClouds.GetById(id);
}
public void RegisterPointCloud(Guid id)
{
RaiseIfNotExists(id);
var pointCloud = pointClouds.GetById(id);
//the first can't be registered
if (pointClouds.IndexOf(pointCloud) == 0)
return;
// var pointCloud = _pointClouds.GetById(id);
//
// //the first can't be registered
// if (_pointClouds.IndexOf(pointCloud) == 0)
// return;
//var transformation = pointCloudRegistation.RegisterPointCloud(pointCloud, pointClouds[0]);
//pointCloud.Transformation = transformation;
@@ -71,13 +71,13 @@ namespace PointCloudWeb.Server.Services
public void RegisterPointClouds()
{
foreach (var pointCloud in pointClouds)
foreach (var pointCloud in _pointClouds)
RegisterPointCloud(pointCloud.Id);
}
public void RemoveById(Guid id)
{
pointClouds.RemoveById(id);
_pointClouds.RemoveById(id);
}
}
}

View File

@@ -11,8 +11,8 @@ namespace PointCloudWeb.Server.Services
if (scan.RAX >= 180 || scan.RAY >= 180)
return new Point(0, 0, 0);
var degreeXA = scan.RAX;
var degreeYA = scan.RAY;
var degreeXa = scan.RAX;
var degreeYa = scan.RAY;
//if (degreeXA > 270 && degreeYA > 270)
//{
@@ -21,23 +21,23 @@ namespace PointCloudWeb.Server.Services
// factorZ = -1;
//}
var degreeXB = 180 - 90 - degreeXA;
var degreeYB = 180 - 90 - degreeYA;
var degreeXb = 180 - 90 - degreeXa;
var degreeYb = 180 - 90 - degreeYa;
var radXA = degreeXA * Math.PI / 180;
var radXB = degreeXB * Math.PI / 180;
var radYA = degreeYA * Math.PI / 180;
var radYB = degreeYB * Math.PI / 180;
var radXa = degreeXa * Math.PI / 180;
var radXb = degreeXb * Math.PI / 180;
var radYa = degreeYa * Math.PI / 180;
var radYb = degreeYb * Math.PI / 180;
double sinXA = Math.Sin(radXA);
double sinXB = Math.Sin(radXB);
double sinYA = Math.Sin(radYA);
double sinYB = Math.Sin(radYB);
var sinXa = Math.Sin(radXa);
var sinXb = Math.Sin(radXb);
var sinYa = Math.Sin(radYa);
var sinYb = Math.Sin(radYb);
var z = Math.Sqrt(
Math.Pow(
Math.Pow(sinXB, 2) / Math.Pow(sinXA, 2)
+ Math.Pow(sinYB, 2) / Math.Pow(sinYA, 2)
Math.Pow(sinXb, 2) / Math.Pow(sinXa, 2)
+ Math.Pow(sinYb, 2) / Math.Pow(sinYa, 2)
+ 1
, -1)
* Math.Pow(scan.DistanceMM, 2)
@@ -45,8 +45,8 @@ namespace PointCloudWeb.Server.Services
var p = new Point()
{
X = NumericUtils.Round(z * sinYB / sinYA),
Y = NumericUtils.Round(z * sinXB / sinXA),
X = NumericUtils.Round(z * sinYb / sinYa),
Y = NumericUtils.Round(z * sinXb / sinXa),
Z = NumericUtils.Round(z)
};

View File

@@ -6,13 +6,13 @@ namespace PointCloudWeb.Server.Services
{
public class ScanDataService
{
private readonly PointCloudService pointCloudService;
private readonly ScanConverterService scanConverterService;
private readonly PointCloudService _pointCloudService;
private readonly ScanConverterService _scanConverterService;
public ScanDataService(PointCloudService pointCloudService, ScanConverterService scanConverterService)
{
this.pointCloudService = pointCloudService;
this.scanConverterService = scanConverterService;
_pointCloudService = pointCloudService;
_scanConverterService = scanConverterService;
}
private IList<Point> ConvertToPoints(ScanDataList scanData)
@@ -21,7 +21,7 @@ namespace PointCloudWeb.Server.Services
foreach (var scan in scanData.ScanPoints)
{
list.Add(scanConverterService.Transform(scan));
list.Add(_scanConverterService.Transform(scan));
}
return list;
@@ -29,12 +29,12 @@ namespace PointCloudWeb.Server.Services
public void AddScan(ScanDataList scanData)
{
pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData));
_pointCloudService.AddPoints(scanData.Id, ConvertToPoints(scanData));
}
public void ScanFinished(Guid id)
{
pointCloudService.RegisterPointCloud(id);
_pointCloudService.RegisterPointCloud(id);
}
}
}

View File

@@ -1,16 +1,9 @@
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;
using System.Threading.Tasks;
namespace PointCloudWeb.Server
{