Viewer of IsoFields is added
This commit is contained in:
13
FieldVisualizer/Entities/ColorMaps/ColorMap.cs
Normal file
13
FieldVisualizer/Entities/ColorMaps/ColorMap.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
using System.Text;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps
|
||||
{
|
||||
public class ColorMap : IColorMap
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<Color> Colors { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using FieldVisualizer.InfraStructures.Enums;
|
||||
using FieldVisualizer.InfraStructures.Exceptions;
|
||||
using FieldVisualizer.InfraStructures.Strings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps.Factories
|
||||
{
|
||||
public static class ColorMapFactory
|
||||
{
|
||||
public static IColorMap GetColorMap(ColorMapsTypes mapsTypes)
|
||||
{
|
||||
if (mapsTypes == ColorMapsTypes.FullSpectrum) { return GetFullSpectrum(); }
|
||||
if (mapsTypes == ColorMapsTypes.RedToWhite) { return GetRedToWhite(); }
|
||||
if (mapsTypes == ColorMapsTypes.RedToBlue) { return GetRedToBlue(); }
|
||||
if (mapsTypes == ColorMapsTypes.BlueToWhite) { return GetBlueToWhite(); }
|
||||
else { throw new FieldVisulizerException(ErrorStrings.ColorMapTypeIsUnknown); }
|
||||
}
|
||||
|
||||
private static IColorMap GetFullSpectrum()
|
||||
{
|
||||
ColorMap colorMap = new ColorMap();
|
||||
colorMap.Name = "FullSpectrumColorMap";
|
||||
List<Color> colors = new List<Color>();
|
||||
byte Alpha = 0xff;
|
||||
colors.AddRange(new Color[]{
|
||||
Color.FromArgb(Alpha, 0xFF, 0x80, 0x80) ,//
|
||||
Color.FromArgb(Alpha, 0xFF, 0, 0x80) ,//
|
||||
Color.FromArgb(Alpha, 0xFF, 0, 0) ,//Red
|
||||
Color.FromArgb(Alpha, 0xFF, 0x45, 0) ,//Orange Red
|
||||
Color.FromArgb(Alpha, 0xFF, 0xD7, 0) ,//Gold
|
||||
Color.FromArgb(Alpha, 0xFF, 0xFF, 0) ,//Yellow
|
||||
Color.FromArgb(Alpha, 0x9A, 0xCD, 0x32) ,//Yellow Green
|
||||
Color.FromArgb(Alpha, 0, 0x80, 0) ,//Green
|
||||
Color.FromArgb(Alpha, 0, 0x64, 0) ,//Dark Green
|
||||
Color.FromArgb(Alpha, 0x2F, 0x4F, 0x4F) ,//Dark Slate Gray
|
||||
Color.FromArgb(Alpha, 0, 0, 0xFF) ,//Blue
|
||||
});
|
||||
colorMap.Colors = colors;
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
private static IColorMap GetRedToWhite()
|
||||
{
|
||||
ColorMap colorMap = new ColorMap();
|
||||
colorMap.Name = "FullSpectrumColorMap";
|
||||
List<Color> colors = new List<Color>();
|
||||
byte Alpha = 0xff;
|
||||
colors.AddRange(new Color[]{
|
||||
Color.FromArgb(Alpha, 0xFF, 0, 0) ,//Red
|
||||
Color.FromArgb(Alpha, 0xFF, 0xFF, 0xFF) ,//White
|
||||
});
|
||||
colorMap.Colors = colors;
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
private static IColorMap GetRedToBlue()
|
||||
{
|
||||
ColorMap colorMap = new ColorMap();
|
||||
colorMap.Name = "FullSpectrumColorMap";
|
||||
List<Color> colors = new List<Color>();
|
||||
byte Alpha = 0xff;
|
||||
colors.AddRange(new Color[]{
|
||||
Color.FromArgb(Alpha, 0xFF, 0, 0) ,//Red
|
||||
Color.FromArgb(Alpha, 0, 0, 0xFF) ,//Blue
|
||||
});
|
||||
colorMap.Colors = colors;
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
private static IColorMap GetBlueToWhite()
|
||||
{
|
||||
ColorMap colorMap = new ColorMap();
|
||||
colorMap.Name = "FullSpectrumColorMap";
|
||||
List<Color> colors = new List<Color>();
|
||||
byte Alpha = 0xff;
|
||||
colors.AddRange(new Color[]{
|
||||
Color.FromArgb(Alpha, 0, 0, 0xFF) ,//Blue
|
||||
Color.FromArgb(Alpha, 0xFF, 0xFF, 0xFF) ,//White
|
||||
});
|
||||
colorMap.Colors = colors;
|
||||
return colorMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
FieldVisualizer/Entities/ColorMaps/IColorMap.cs
Normal file
13
FieldVisualizer/Entities/ColorMaps/IColorMap.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
using System.Text;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps
|
||||
{
|
||||
public interface IColorMap
|
||||
{
|
||||
string Name { get;}
|
||||
List<Color> Colors { get; }
|
||||
}
|
||||
}
|
||||
19
FieldVisualizer/Entities/ColorMaps/IValueColorRange.cs
Normal file
19
FieldVisualizer/Entities/ColorMaps/IValueColorRange.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps
|
||||
{
|
||||
public interface IValueColorRange
|
||||
{
|
||||
bool IsActive { get; set; }
|
||||
double BottomValue { get; set; }
|
||||
double AverageValue { get; set; }
|
||||
double TopValue {get;set;}
|
||||
Color BottomColor { get; set; }
|
||||
Color TopColor { get; set; }
|
||||
}
|
||||
}
|
||||
19
FieldVisualizer/Entities/ColorMaps/ValueColorRange.cs
Normal file
19
FieldVisualizer/Entities/ColorMaps/ValueColorRange.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps
|
||||
{
|
||||
public class ValueColorRange : IValueColorRange
|
||||
{
|
||||
public bool IsActive { get; set; }
|
||||
public double BottomValue { get; set; }
|
||||
public double AverageValue { get; set; }
|
||||
public double TopValue { get; set; }
|
||||
public Color BottomColor { get; set; }
|
||||
public Color TopColor { get; set; }
|
||||
}
|
||||
}
|
||||
12
FieldVisualizer/Entities/Values/IValueRange.cs
Normal file
12
FieldVisualizer/Entities/Values/IValueRange.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values
|
||||
{
|
||||
public interface IValueRange
|
||||
{
|
||||
double TopValue { get; set; }
|
||||
double BottomValue { get; set; }
|
||||
}
|
||||
}
|
||||
14
FieldVisualizer/Entities/Values/Primitives/ICenter.cs
Normal file
14
FieldVisualizer/Entities/Values/Primitives/ICenter.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values.Primitives
|
||||
{
|
||||
public interface ICenter
|
||||
{
|
||||
double CenterX { get;}
|
||||
double CenterY { get;}
|
||||
}
|
||||
}
|
||||
15
FieldVisualizer/Entities/Values/Primitives/IPrimitiveSet.cs
Normal file
15
FieldVisualizer/Entities/Values/Primitives/IPrimitiveSet.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values.Primitives
|
||||
{
|
||||
public interface IPrimitiveSet
|
||||
{
|
||||
string Name { get; }
|
||||
IEnumerable<IValuePrimitive> ValuePrimitives { get; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values.Primitives
|
||||
{
|
||||
internal interface IRectanglePrimitive : IValuePrimitive
|
||||
{
|
||||
double Height { get; set; }
|
||||
double Width { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values.Primitives
|
||||
{
|
||||
public interface IValuePrimitive
|
||||
{
|
||||
double Value { get; }
|
||||
double CenterX { get; }
|
||||
double CenterY { get; }
|
||||
}
|
||||
}
|
||||
20
FieldVisualizer/Entities/Values/Primitives/PrimitiveSet.cs
Normal file
20
FieldVisualizer/Entities/Values/Primitives/PrimitiveSet.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values.Primitives
|
||||
{
|
||||
public class PrimitiveSet : IPrimitiveSet
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<IValuePrimitive> ValuePrimitives { get; set;}
|
||||
|
||||
public PrimitiveSet()
|
||||
{
|
||||
Name = "New set of primitives";
|
||||
ValuePrimitives = new List<IValuePrimitive>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values.Primitives
|
||||
{
|
||||
public class RectanglePrimitive : IRectanglePrimitive
|
||||
{
|
||||
public double Height { get; set; }
|
||||
public double Width { get; set; }
|
||||
public double Value { get; set; }
|
||||
public double CenterX { get; set; }
|
||||
public double CenterY { get; set; }
|
||||
}
|
||||
}
|
||||
12
FieldVisualizer/Entities/Values/ValueRange.cs
Normal file
12
FieldVisualizer/Entities/Values/ValueRange.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values
|
||||
{
|
||||
public class ValueRange : IValueRange
|
||||
{
|
||||
public double TopValue { get; set; }
|
||||
public double BottomValue { get; set; }
|
||||
}
|
||||
}
|
||||
16
FieldVisualizer/FieldVisualizer.csproj
Normal file
16
FieldVisualizer/FieldVisualizer.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<UseWPF>true</UseWPF>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Windows.Forms.DataVisualization" />
|
||||
<Reference Include="System.Windows.Forms.DataVisualization.Design" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
29
FieldVisualizer/FieldVisualizer.csproj.user
Normal file
29
FieldVisualizer/FieldVisualizer.csproj.user
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<ItemGroup>
|
||||
<Compile Update="Windows\UserControls\FieldViewer.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="Windows\UserControls\VerticalLegend.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="Windows\WndFieldViewer.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="Windows\UserControls\FieldViewer.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Update="Windows\UserControls\VerticalLegend.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Update="Windows\VerticalLegendTemplates.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Update="Windows\WndFieldViewer.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
14
FieldVisualizer/InfraStructures/Enums/ColorMapsTypes.cs
Normal file
14
FieldVisualizer/InfraStructures/Enums/ColorMapsTypes.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FieldVisualizer.InfraStructures.Enums
|
||||
{
|
||||
public enum ColorMapsTypes
|
||||
{
|
||||
FullSpectrum = 0,
|
||||
RedToWhite = 1,
|
||||
RedToBlue = 2,
|
||||
BlueToWhite = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FieldVisualizer.InfraStructures.Exceptions
|
||||
{
|
||||
public class FieldVisulizerException : Exception
|
||||
{
|
||||
public FieldVisulizerException(string errorString) : base(errorString)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
11
FieldVisualizer/InfraStructures/Strings/ErrorStrings.cs
Normal file
11
FieldVisualizer/InfraStructures/Strings/ErrorStrings.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FieldVisualizer.InfraStructures.Strings
|
||||
{
|
||||
public static class ErrorStrings
|
||||
{
|
||||
public static string ColorMapTypeIsUnknown => "#0001: ColorMap type is unknown";
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
FieldVisualizer/Windows/UserControls/FieldViewer.xaml
Normal file
41
FieldVisualizer/Windows/UserControls/FieldViewer.xaml
Normal file
@@ -0,0 +1,41 @@
|
||||
<UserControl x:Class="FieldVisualizer.Windows.UserControls.FieldViewer"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:FieldVisualizer.Windows.UserControls"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="200"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="30"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button x:Name="RebuildButton" Content="Rebuild" Click="RebuildButton_Click"/>
|
||||
<Button x:Name="ZoomInButton" Content="ZoomIn" Click="ZoomInButton_Click"/>
|
||||
<Button x:Name="ZoomOutButton" Content="ZoomOut" Click="ZoomOutButton_Click"/>
|
||||
<Button x:Name="ChangeColorMapButton" Content="ColorMap" Click="ChangeColorMapButton_Click"/>
|
||||
</StackPanel>
|
||||
<ScrollViewer Name="WorkPlaneViewer" Grid.Row="1" HorizontalScrollBarVisibility="Visible">
|
||||
<ScrollViewer.Background>
|
||||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
|
||||
<GradientStop Color="Black"/>
|
||||
<GradientStop Color="White" Offset="1"/>
|
||||
<GradientStop Color="#FF00EDFF" Offset="0"/>
|
||||
</LinearGradientBrush>
|
||||
</ScrollViewer.Background>
|
||||
<Viewbox Name="WorkPlaneBox" Margin="10">
|
||||
<Canvas Name="WorkPlaneCanvas"/>
|
||||
</Viewbox>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
|
||||
<local:VerticalLegend x:Name="LegendViewer" Grid.Column="2"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
135
FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs
Normal file
135
FieldVisualizer/Windows/UserControls/FieldViewer.xaml.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.ColorMaps.Factories;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.InfraStructures.Enums;
|
||||
using FieldVisualizer.Services.ColorServices;
|
||||
using FieldVisualizer.Services.PrimitiveServices;
|
||||
using FieldVisualizer.Services.ValueRanges;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace FieldVisualizer.Windows.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для FieldViewer.xaml
|
||||
/// </summary>
|
||||
public partial class FieldViewer : UserControl
|
||||
{
|
||||
public IPrimitiveSet _PrimitiveSet { get; set; }
|
||||
private double dX, dY;
|
||||
private ColorMapsTypes _ColorMapType;
|
||||
private IColorMap _ColorMap;
|
||||
private IValueRange _ValueRange;
|
||||
private IEnumerable<IValueRange> _ValueRanges;
|
||||
private IEnumerable<IValueColorRange> _ValueColorRanges;
|
||||
const int RangeNumber = 16;
|
||||
|
||||
public FieldViewer()
|
||||
{
|
||||
InitializeComponent();
|
||||
_ColorMapType = ColorMapsTypes.FullSpectrum;
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
_ValueRange = PrimitiveOperations.GetValuRange(_PrimitiveSet.ValuePrimitives);
|
||||
_ValueRanges = ValueRangeOperations.DivideValueRange(_ValueRange, RangeNumber);
|
||||
_ColorMap = ColorMapFactory.GetColorMap(_ColorMapType);
|
||||
_ValueColorRanges = ColorOperations.GetValueColorRanges(_ValueRange, _ValueRanges, _ColorMap);
|
||||
if ((_PrimitiveSet is null) == false)
|
||||
{
|
||||
ProcessPrimitives();
|
||||
LegendViewer.ValueColorRanges = _ValueColorRanges;
|
||||
LegendViewer.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessPrimitives()
|
||||
{
|
||||
WorkPlaneCanvas.Children.Clear();
|
||||
double sizeX = PrimitiveOperations.GetSizeX(_PrimitiveSet.ValuePrimitives);
|
||||
double sizeY = PrimitiveOperations.GetSizeY(_PrimitiveSet.ValuePrimitives);
|
||||
dX = PrimitiveOperations.GetMinMaxX(_PrimitiveSet.ValuePrimitives)[0];
|
||||
dY = PrimitiveOperations.GetMinMaxY(_PrimitiveSet.ValuePrimitives)[0];
|
||||
WorkPlaneCanvas.Width = Math.Abs(sizeX);
|
||||
WorkPlaneCanvas.Height = Math.Abs(sizeY);
|
||||
WorkPlaneBox.Width = WorkPlaneViewer.ActualWidth - 50;
|
||||
WorkPlaneBox.Height = WorkPlaneViewer.ActualHeight - 50;
|
||||
foreach (var primitive in _PrimitiveSet.ValuePrimitives)
|
||||
{
|
||||
if (primitive is IRectanglePrimitive)
|
||||
{
|
||||
IRectanglePrimitive rectanglePrimitive = primitive as IRectanglePrimitive;
|
||||
Rectangle rectangle = ProcessRectanglePrimitive(rectanglePrimitive);
|
||||
WorkPlaneCanvas.Children.Add(rectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WorkPlaneBox_MouseWheel(object sender, MouseWheelEventArgs e)
|
||||
{
|
||||
WorkPlaneBox.Height *= WorkPlaneBox.ActualHeight * 0.5;
|
||||
WorkPlaneBox.Width *= WorkPlaneBox.ActualWidth * 0.5;
|
||||
}
|
||||
|
||||
private Rectangle ProcessRectanglePrimitive(IRectanglePrimitive rectanglePrimitive)
|
||||
{
|
||||
Rectangle rectangle = new Rectangle();
|
||||
rectangle.Height = rectanglePrimitive.Height;
|
||||
rectangle.Width = rectanglePrimitive.Width;
|
||||
SolidColorBrush brush = new SolidColorBrush();
|
||||
brush.Color = ColorOperations.GetColorByValue(_ValueRange, _ColorMap, rectanglePrimitive.Value);
|
||||
foreach (var valueRange in _ValueColorRanges)
|
||||
{
|
||||
if (rectanglePrimitive.Value >= valueRange.BottomValue & rectanglePrimitive.Value <= valueRange.TopValue & (! valueRange.IsActive))
|
||||
{
|
||||
brush.Color = Colors.Gray;
|
||||
}
|
||||
}
|
||||
rectangle.ToolTip = rectanglePrimitive.Value;
|
||||
rectangle.Fill = brush;
|
||||
Canvas.SetLeft(rectangle, rectanglePrimitive.CenterX - dX);
|
||||
Canvas.SetTop(rectangle, rectanglePrimitive.CenterY - dY);
|
||||
return rectangle;
|
||||
}
|
||||
|
||||
private void RebuildButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ProcessPrimitives();
|
||||
}
|
||||
|
||||
private void ZoomInButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WorkPlaneBox.Width *= 1.2;
|
||||
WorkPlaneBox.Height *= 1.2;
|
||||
}
|
||||
|
||||
private void ChangeColorMapButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_ColorMapType < ColorMapsTypes.BlueToWhite) { _ColorMapType++;}
|
||||
else { _ColorMapType = 0;}
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void ZoomOutButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
WorkPlaneBox.Width *= 0.8;
|
||||
WorkPlaneBox.Height *= 0.8;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
FieldVisualizer/Windows/UserControls/VerticalLegend.xaml
Normal file
47
FieldVisualizer/Windows/UserControls/VerticalLegend.xaml
Normal file
@@ -0,0 +1,47 @@
|
||||
<UserControl x:Class="FieldVisualizer.Windows.UserControls.VerticalLegend"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:FieldVisualizer.Windows.UserControls"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid x:Name="grid">
|
||||
<StackPanel>
|
||||
<ListBox Name="LegendBox" ItemsSource="{Binding}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Height="30" Width="194" VerticalAlignment="Top" Background="{DynamicResource {x:Static SystemColors.MenuBarBrushKey}}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="30"/>
|
||||
<ColumnDefinition Width="10"/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="10"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Name="ActiveCheckBox" Grid.Column="0" IsChecked="{Binding Path=IsActive}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<Rectangle Grid.Column="1" Margin="0,2,0,2" ToolTip="{Binding Path=BottomValue}">
|
||||
<Rectangle.Fill>
|
||||
<SolidColorBrush Color="{Binding Path=BottomColor}"/>
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<Rectangle Grid.Column="2" Margin="0,2,0,2">
|
||||
<Rectangle.Fill>
|
||||
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
|
||||
<GradientStop Color="{Binding Path=BottomColor}"/>
|
||||
<GradientStop Color="{Binding Path=TopColor}" Offset="1"/>
|
||||
</LinearGradientBrush>
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<Rectangle Grid.Column="3" Margin="0,2,0,2" ToolTip="{Binding Path=TopValue}">
|
||||
<Rectangle.Fill>
|
||||
<SolidColorBrush Color="{Binding Path=TopColor}"/>
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
36
FieldVisualizer/Windows/UserControls/VerticalLegend.xaml.cs
Normal file
36
FieldVisualizer/Windows/UserControls/VerticalLegend.xaml.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace FieldVisualizer.Windows.UserControls
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для VerticalLegend.xaml
|
||||
/// </summary>
|
||||
public partial class VerticalLegend : UserControl
|
||||
{
|
||||
public IEnumerable<IValueColorRange> ValueColorRanges;
|
||||
public VerticalLegend()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
this.DataContext = ValueColorRanges;
|
||||
}
|
||||
}
|
||||
}
|
||||
4
FieldVisualizer/Windows/VerticalLegendTemplates.xaml
Normal file
4
FieldVisualizer/Windows/VerticalLegendTemplates.xaml
Normal file
@@ -0,0 +1,4 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
</ResourceDictionary>
|
||||
30
FieldVisualizer/Windows/WndFieldViewer.xaml
Normal file
30
FieldVisualizer/Windows/WndFieldViewer.xaml
Normal file
@@ -0,0 +1,30 @@
|
||||
<Window x:Class="FieldVisualizer.Windows.WndFieldViewer"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:FieldViewerControl="clr-namespace:FieldVisualizer.Windows.UserControls"
|
||||
xmlns:local="clr-namespace:FieldVisualizer.Windows"
|
||||
mc:Ignorable="d"
|
||||
Title="FieldViewer" Height="700" Width="1200" WindowStartupLocation="CenterOwner">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="300"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ListBox Name="SetsList" ItemsSource="{Binding}" SelectionChanged="SetsList_SelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Height="20">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="30"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="1" Text="{Binding Path=Name}" Width="270"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<FieldViewerControl:FieldViewer x:Name="FieldViewerControl" Grid.Column="1"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
40
FieldVisualizer/Windows/WndFieldViewer.xaml.cs
Normal file
40
FieldVisualizer/Windows/WndFieldViewer.xaml.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.Windows.UserControls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace FieldVisualizer.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для WndFieldViewer.xaml
|
||||
/// </summary>
|
||||
public partial class WndFieldViewer : Window
|
||||
{
|
||||
public WndFieldViewer(IEnumerable<IPrimitiveSet> primitiveSets)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = primitiveSets;
|
||||
foreach (var primitiveSet in primitiveSets)
|
||||
{
|
||||
FieldViewerControl._PrimitiveSet = primitiveSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SetsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
FieldViewerControl.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
FieldVisualizer/WindowsOperation/FieldViewerOperation.cs
Normal file
19
FieldVisualizer/WindowsOperation/FieldViewerOperation.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.Windows;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.WindowsOperation
|
||||
{
|
||||
public static class FieldViewerOperation
|
||||
{
|
||||
public static void ShowViewer(IEnumerable<IPrimitiveSet> primitiveSets)
|
||||
{
|
||||
WndFieldViewer Viewer = new WndFieldViewer(primitiveSets);
|
||||
Viewer.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user