Viewer of IsoFields is added
This commit is contained in:
61
FieldVisualizer/Services/ColorServices/ColorOperations.cs
Normal file
61
FieldVisualizer/Services/ColorServices/ColorOperations.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace FieldVisualizer.Services.ColorServices
|
||||
{
|
||||
public static class ColorOperations
|
||||
{
|
||||
const byte Alpha = 0xff;
|
||||
public static Color GetColorByValue(IValueRange range, IColorMap map, double val)
|
||||
{
|
||||
double minVal = range.BottomValue;
|
||||
double maxVal = range.TopValue;
|
||||
if (range.TopValue == minVal || map.Colors.Count == 0) { return map.Colors[0]; }
|
||||
if (val > maxVal || val < minVal) { return Colors.Gray; }
|
||||
if (val == minVal) { return map.Colors[0]; }
|
||||
if (val == maxVal) { return map.Colors[map.Colors.Count - 1]; }
|
||||
|
||||
double valPerc = (val - minVal) / (maxVal - minVal);// value%
|
||||
double colorPerc = 1d / (map.Colors.Count - 1); // % of each block of color. the last is the "100% Color"
|
||||
double blockOfColor = valPerc / colorPerc;// the integer part repersents how many block to skip
|
||||
int blockIdx = (int)Math.Truncate(blockOfColor);// Idx of
|
||||
double valPercResidual = valPerc - (blockIdx * colorPerc);//remove the part represented of block
|
||||
double percOfColor = valPercResidual / colorPerc;// % of color of this block that will be filled
|
||||
|
||||
Color cTarget = map.Colors[blockIdx];
|
||||
Color cNext = map.Colors[blockIdx + 1];
|
||||
|
||||
var deltaR = cNext.R - cTarget.R;
|
||||
var deltaG = cNext.G - cTarget.G;
|
||||
var deltaB = cNext.B - cTarget.B;
|
||||
|
||||
var R = cTarget.R + (deltaR * percOfColor);
|
||||
var G = cTarget.G + (deltaG * percOfColor);
|
||||
var B = cTarget.B + (deltaB * percOfColor);
|
||||
|
||||
Color c = map.Colors[0];
|
||||
c = Color.FromArgb(Alpha, (byte)R, (byte)G, (byte)B);
|
||||
return c;
|
||||
}
|
||||
public static IEnumerable<IValueColorRange> GetValueColorRanges(IValueRange fullRange, IEnumerable<IValueRange> valueRanges, IColorMap colorMap)
|
||||
{
|
||||
var colorRanges = new List<IValueColorRange>();
|
||||
foreach (var valueRange in valueRanges)
|
||||
{
|
||||
IValueColorRange valueColorRange = new ValueColorRange();
|
||||
valueColorRange.IsActive = true;
|
||||
valueColorRange.BottomValue = valueRange.BottomValue;
|
||||
valueColorRange.AverageValue = (valueRange.BottomValue + valueRange.TopValue) / 2;
|
||||
valueColorRange.TopValue = valueRange.TopValue;
|
||||
valueColorRange.BottomColor = GetColorByValue(fullRange, colorMap, valueColorRange.BottomValue);
|
||||
valueColorRange.TopColor = GetColorByValue(fullRange, colorMap, valueColorRange.TopValue);
|
||||
colorRanges.Add(valueColorRange);
|
||||
}
|
||||
return colorRanges;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace FieldVisualizer.Services.PrimitiveServices
|
||||
{
|
||||
public static class PrimitiveOperations
|
||||
{
|
||||
public static IValueRange GetValuRange(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
{
|
||||
double minVal =0d, maxVal = 0d;
|
||||
foreach (var primitive in valuePrimitives)
|
||||
{
|
||||
minVal = Math.Min(minVal, primitive.Value);
|
||||
maxVal = Math.Max(maxVal, primitive.Value);
|
||||
}
|
||||
return new ValueRange() { BottomValue = minVal, TopValue = maxVal };
|
||||
}
|
||||
|
||||
public static double[] GetMinMaxX(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
{
|
||||
List<double> coords = GetXs(valuePrimitives);
|
||||
return new double[] { coords.Min(), coords.Max() };
|
||||
}
|
||||
|
||||
public static double GetSizeX(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
{
|
||||
double[] coords = GetMinMaxX(valuePrimitives);
|
||||
return coords[1] - coords[0];
|
||||
}
|
||||
|
||||
public static double[] GetMinMaxY(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
{
|
||||
List<double> coords = GetYs(valuePrimitives);
|
||||
return new double[] { coords.Min(), coords.Max() };
|
||||
}
|
||||
|
||||
public static double GetSizeY(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
{
|
||||
double[] coords = GetMinMaxY(valuePrimitives);
|
||||
return coords[1] - coords[0];
|
||||
}
|
||||
|
||||
public static List<double> GetXs(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
{
|
||||
List<double> coords = new List<double>();
|
||||
foreach (var primitive in valuePrimitives)
|
||||
{
|
||||
if (primitive is IRectanglePrimitive)
|
||||
{
|
||||
IRectanglePrimitive rectanglePrimitive = primitive as IRectanglePrimitive;
|
||||
coords.Add(rectanglePrimitive.CenterX + rectanglePrimitive.Width / 2);
|
||||
coords.Add(rectanglePrimitive.CenterX - rectanglePrimitive.Width / 2);
|
||||
}
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
|
||||
public static List<double> GetYs(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
{
|
||||
List<double> coords = new List<double>();
|
||||
foreach (var primitive in valuePrimitives)
|
||||
{
|
||||
if (primitive is IRectanglePrimitive)
|
||||
{
|
||||
IRectanglePrimitive rectanglePrimitive = primitive as IRectanglePrimitive;
|
||||
coords.Add(rectanglePrimitive.CenterY + rectanglePrimitive.Height / 2);
|
||||
coords.Add(rectanglePrimitive.CenterY - rectanglePrimitive.Height / 2);
|
||||
}
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
FieldVisualizer/Services/ValueRanges/ValueRangeOperations.cs
Normal file
34
FieldVisualizer/Services/ValueRanges/ValueRangeOperations.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Services.ValueRanges
|
||||
{
|
||||
public static class ValueRangeOperations
|
||||
{
|
||||
public static IEnumerable<IValueRange> DivideValueRange (IValueRange valueRange, int divisionNumber)
|
||||
{
|
||||
List<IValueRange> valueRanges = new List<IValueRange>();
|
||||
if (valueRange.BottomValue == valueRange.TopValue)
|
||||
{
|
||||
var newRange = new ValueRange() { BottomValue = valueRange.BottomValue, TopValue = valueRange.TopValue };
|
||||
valueRanges.Add(newRange);
|
||||
}
|
||||
else
|
||||
{
|
||||
double dVal = (valueRange.TopValue - valueRange.BottomValue) / divisionNumber;
|
||||
double currentBottom = valueRange.BottomValue;
|
||||
for (int i = 0; i < divisionNumber; i++ )
|
||||
{
|
||||
currentBottom = i * dVal;
|
||||
var newRange = new ValueRange() { BottomValue = currentBottom, TopValue = currentBottom + dVal };
|
||||
valueRanges.Add(newRange);
|
||||
}
|
||||
}
|
||||
return valueRanges;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user