From d7d2942010188d0b655ab6a93d8a26a7736a38a1 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Fri, 16 Sep 2016 13:54:53 +0200
Subject: [PATCH] making points from delauney map accessible (e.g. for gui)

---
 .../SimulationComponent/Data/AuxiliaryData.cs |  2 +-
 .../Data/Engine/FuelConsumptionMap.cs         | 15 +++++++++++
 VectoCore/VectoCore/Utils/DelaunayMap.cs      | 27 +++++++++++++++----
 3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/AuxiliaryData.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/AuxiliaryData.cs
index 82e5d44bb4..2b651cdf9d 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Data/AuxiliaryData.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/AuxiliaryData.cs
@@ -86,7 +86,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
 			var zValidationRules = new[] { new RangeAttribute(0, 100.SI().Kilo.Watt.Value()) };
 
 			var results = new List<ValidationResult>();
-			foreach (var entry in data._map.Points) {
+			foreach (var entry in data._map.Entries) {
 				context.DisplayName = AuxiliaryDataReader.Fields.AuxSpeed;
 				if (!Validator.TryValidateValue(entry.X, context, results, xValidationRules)) {
 					return new ValidationResult(string.Concat(results));
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs
index 94f64c6bfc..10ddce62dc 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/Engine/FuelConsumptionMap.cs
@@ -29,6 +29,7 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
+using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
 using System.Diagnostics;
 using TUGraz.VectoCommon.Exceptions;
@@ -72,6 +73,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
 				angularVelocity.AsRPM);
 		}
 
+		public IReadOnlyCollection<Entry> Entries
+		{
+			get
+			{
+				var entries = _fuelMap.Entries;
+				var retVal = new Entry[entries.Count];
+				var i = 0;
+				foreach (var entry in entries) {
+					retVal[i++] = new Entry(entry.Y.SI<PerSecond>(), entry.X.SI<NewtonMeter>(), entry.Z.SI<KilogramPerSecond>());
+				}
+				return retVal;
+			}
+		}
+
 		public class Entry
 		{
 			[Required, SIRange(0, 5000 * Constants.RPMToRad)] public readonly PerSecond EngineSpeed;
diff --git a/VectoCore/VectoCore/Utils/DelaunayMap.cs b/VectoCore/VectoCore/Utils/DelaunayMap.cs
index 661a91b450..f7c751035d 100644
--- a/VectoCore/VectoCore/Utils/DelaunayMap.cs
+++ b/VectoCore/VectoCore/Utils/DelaunayMap.cs
@@ -46,7 +46,7 @@ namespace TUGraz.VectoCore.Utils
 {
 	public sealed class DelaunayMap : LoggingObject
 	{
-		internal ICollection<Point> Points = new HashSet<Point>();
+		private ICollection<Point> Points = new HashSet<Point>();
 		private Triangle[] _triangles;
 		private Edge[] _convexHull;
 
@@ -66,6 +66,19 @@ namespace TUGraz.VectoCore.Utils
 			Points.Add(new Point(x, y, z));
 		}
 
+		public IReadOnlyCollection<Point> Entries
+		{
+			get
+			{
+				var retVal = new Point[Points.Count];
+				var i = 0;
+				foreach (var pt in Points) {
+					retVal[i++] = new Point(pt.X * (_maxX - _minX) + _minX, pt.Y * (_maxY - _minY) + _minY, pt.Z);
+				}
+				return retVal;
+			}
+		}
+
 		/// <summary>
 		/// Triangulate the points.
 		/// </summary>
@@ -229,23 +242,27 @@ namespace TUGraz.VectoCore.Utils
 		[MethodImpl(MethodImplOptions.AggressiveInlining)]
 		public double? Interpolate(double x, double y)
 		{
-			if (_triangles == null)
+			if (_triangles == null) {
 				throw new VectoException("Interpolation not possible. Call DelaunayMap.Triangulate first.");
+			}
 
 			x = (x - _minX) / (_maxX - _minX);
 			y = (y - _minY) / (_maxY - _minY);
 
 			var i = 0;
-			while (i < _triangles.Length && !_triangles[i].IsInside(x, y, true))
+			while (i < _triangles.Length && !_triangles[i].IsInside(x, y, true)) {
 				i++;
+			}
 			if (i == _triangles.Length) {
 				i = 0;
-				while (i < _triangles.Length && !_triangles[i].IsInside(x, y, false))
+				while (i < _triangles.Length && !_triangles[i].IsInside(x, y, false)) {
 					i++;
+				}
 			}
 
-			if (i == _triangles.Length)
+			if (i == _triangles.Length) {
 				return null;
+			}
 
 			var tr = _triangles[i];
 			var plane = new Plane(tr);
-- 
GitLab