IsoFieldViewer was changed
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
using FieldVisualizer.InfraStructures.Enums;
|
||||
using FieldVisualizer.InfraStructures.Exceptions;
|
||||
using FieldVisualizer.InfraStructures.Exceptions;
|
||||
using FieldVisualizer.InfraStructures.Strings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps.Factories
|
||||
{
|
||||
public enum ColorMapsTypes
|
||||
{
|
||||
LiraSpectrum = 0, //Lira
|
||||
FullSpectrum = 1, //StaDiCon
|
||||
RedToWhite = 2,
|
||||
RedToBlue = 3,
|
||||
BlueToWhite = 4,
|
||||
}
|
||||
/// <summary>
|
||||
/// Factory for creating of different color maps
|
||||
/// </summary>
|
||||
@@ -18,13 +24,39 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories
|
||||
if (mapsTypes == ColorMapsTypes.RedToWhite) { return GetRedToWhite(); }
|
||||
if (mapsTypes == ColorMapsTypes.RedToBlue) { return GetRedToBlue(); }
|
||||
if (mapsTypes == ColorMapsTypes.BlueToWhite) { return GetBlueToWhite(); }
|
||||
if (mapsTypes == ColorMapsTypes.LiraSpectrum) { return GetLiraSpectrum(); }
|
||||
else { throw new FieldVisulizerException(ErrorStrings.ColorMapTypeIsUnknown); }
|
||||
}
|
||||
|
||||
private static IColorMap GetLiraSpectrum()
|
||||
{
|
||||
ColorMap colorMap = new()
|
||||
{
|
||||
Name = "LiraSpectrumColorMap"
|
||||
};
|
||||
List<Color> colors = new();
|
||||
byte Alpha = 0xff;
|
||||
colors.AddRange(new Color[]{
|
||||
Color.FromArgb(Alpha, 0, 0, 128) ,//Dark Blue
|
||||
Color.FromArgb(Alpha, 0, 0, 255) ,//Blue
|
||||
Color.FromArgb(Alpha, 0, 128, 255) ,//Blue
|
||||
Color.FromArgb(Alpha, 0, 200, 255) ,//Blue
|
||||
Color.FromArgb(Alpha, 60, 255, 255) ,//Light Blue
|
||||
Color.FromArgb(Alpha, 255, 255, 128) ,//Light Yellow
|
||||
Color.FromArgb(Alpha, 255, 255, 0) ,//Yellow
|
||||
Color.FromArgb(Alpha, 255, 215, 0) ,//Gold
|
||||
Color.FromArgb(Alpha, 255, 128, 0) ,//Orange Red
|
||||
Color.FromArgb(Alpha, 255, 0, 0) ,//Red
|
||||
});
|
||||
colorMap.Colors = colors;
|
||||
return colorMap;
|
||||
}
|
||||
private static IColorMap GetFullSpectrum()
|
||||
{
|
||||
ColorMap colorMap = new ColorMap();
|
||||
colorMap.Name = "FullSpectrumColorMap";
|
||||
ColorMap colorMap = new()
|
||||
{
|
||||
Name = "FullSpectrumColorMap"
|
||||
};
|
||||
List<Color> colors = new List<Color>();
|
||||
byte Alpha = 0xff;
|
||||
colors.AddRange(new Color[]{
|
||||
@@ -43,7 +75,6 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories
|
||||
colorMap.Colors = colors;
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
private static IColorMap GetRedToWhite()
|
||||
{
|
||||
ColorMap colorMap = new ColorMap();
|
||||
@@ -57,7 +88,6 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories
|
||||
colorMap.Colors = colors;
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
private static IColorMap GetRedToBlue()
|
||||
{
|
||||
ColorMap colorMap = new ColorMap();
|
||||
@@ -71,7 +101,6 @@ namespace FieldVisualizer.Entities.ColorMaps.Factories
|
||||
colorMap.Colors = colors;
|
||||
return colorMap;
|
||||
}
|
||||
|
||||
private static IColorMap GetBlueToWhite()
|
||||
{
|
||||
ColorMap colorMap = new ColorMap();
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps
|
||||
{
|
||||
/// <summary>
|
||||
/// Colored range for building color legend
|
||||
/// </summary>
|
||||
public interface IValueColorRange
|
||||
{
|
||||
/// <summary>
|
||||
/// Flag of activity
|
||||
/// </summary>
|
||||
bool IsActive { get; set; }
|
||||
/// <summary>
|
||||
/// Minimum value of range
|
||||
/// </summary>
|
||||
double BottomValue { get; set; }
|
||||
/// <summary>
|
||||
/// Average value of range
|
||||
/// </summary>
|
||||
double AverageValue { get; set; }
|
||||
/// <summary>
|
||||
/// Maximum value of range
|
||||
/// </summary>
|
||||
double TopValue {get;set;}
|
||||
/// <summary>
|
||||
/// Color correspondent to minimum value
|
||||
/// </summary>
|
||||
Color BottomColor { get; set; }
|
||||
/// <summary>
|
||||
/// Color correspondent to maximum value
|
||||
/// </summary>
|
||||
Color TopColor { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public class ValueColorRange : IValueColorRange
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool IsActive { get; set; }
|
||||
/// <inheritdoc/>
|
||||
public double BottomValue { get; set; }
|
||||
/// <inheritdoc/>
|
||||
public double AverageValue { get; set; }
|
||||
/// <inheritdoc/>
|
||||
public double TopValue { get; set; }
|
||||
/// <inheritdoc/>
|
||||
public Color BottomColor { get; set; }
|
||||
/// <inheritdoc/>
|
||||
public Color TopColor { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,12 @@
|
||||
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="InfraStructures\Enums\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\StructureHelperCommon\StructureHelperCommon.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FieldVisualizer.InfraStructures.Enums
|
||||
{
|
||||
public enum ColorMapsTypes
|
||||
{
|
||||
FullSpectrum = 0,
|
||||
RedToWhite = 1,
|
||||
RedToBlue = 2,
|
||||
BlueToWhite = 3
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
@@ -10,54 +11,123 @@ namespace FieldVisualizer.Services.ColorServices
|
||||
public static class ColorOperations
|
||||
{
|
||||
const byte Alpha = 0xff;
|
||||
public static Color GetColorByValue(IValueRange range, IColorMap map, double val)
|
||||
{
|
||||
if (range.TopValue == range.BottomValue || map.Colors.Count == 0) { return map.Colors[0]; }
|
||||
double minVal = range.BottomValue - 1e-15d*(Math.Abs(range.BottomValue));
|
||||
double maxVal = range.TopValue + 1e-15d * (Math.Abs(range.TopValue));
|
||||
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%
|
||||
if (valPerc >= 1d)
|
||||
{ return map.Colors[map.Colors.Count - 1]; }
|
||||
double colorPerc = 1d / (map.Colors.Count - 1d); // % 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;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fullRange"></param>
|
||||
/// <param name="valueRanges"></param>
|
||||
/// <param name="colorMap"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
IValueColorRange valueColorRange = new ValueColorRange
|
||||
{
|
||||
IsActive = true,
|
||||
BottomValue = valueRange.BottomValue,
|
||||
AverageValue = (valueRange.BottomValue + valueRange.TopValue) / 2,
|
||||
TopValue = valueRange.TopValue
|
||||
};
|
||||
valueColorRange.BottomColor = GetColorByValue(fullRange, colorMap, valueColorRange.BottomValue);
|
||||
valueColorRange.TopColor = GetColorByValue(fullRange, colorMap, valueColorRange.TopValue);
|
||||
colorRanges.Add(valueColorRange);
|
||||
}
|
||||
return colorRanges;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns color by value, range of value an color map
|
||||
/// </summary>
|
||||
/// <param name="range">Range of valoue</param>
|
||||
/// <param name="map">Color map</param>
|
||||
/// <param name="val">Value</param>
|
||||
/// <returns></returns>
|
||||
public static Color GetColorByValue(IValueRange range, IColorMap map, double val)
|
||||
{
|
||||
CheckColorMap(map);
|
||||
if (range.TopValue == range.BottomValue || map.Colors.Count == 1) //if range width is zero or map contain just 1 color
|
||||
{
|
||||
return map.Colors[0];
|
||||
}
|
||||
var valueRange = GetExtendedRange(range);
|
||||
if (val >= valueRange.TopValue || val <= valueRange.BottomValue)
|
||||
{
|
||||
return GetColorValueIsOutOfRange(valueRange, map, val);
|
||||
}
|
||||
return GetColorValueIsInRange(valueRange, map, val);
|
||||
}
|
||||
|
||||
private static Color GetColorValueIsOutOfRange(IValueRange range, IColorMap map, double val)
|
||||
{
|
||||
if (val > range.TopValue || val < range.BottomValue)
|
||||
{
|
||||
return Colors.Gray;
|
||||
}
|
||||
if (val == range.BottomValue)
|
||||
{
|
||||
return map.Colors[0];
|
||||
}
|
||||
if (val == range.TopValue)
|
||||
{
|
||||
return map.Colors[^1];
|
||||
}
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect);
|
||||
}
|
||||
|
||||
private static Color GetColorValueIsInRange(IValueRange range, IColorMap map, double val)
|
||||
{
|
||||
var deltaVal = val - range.BottomValue;
|
||||
var rangeWidth = range.TopValue - range.BottomValue;
|
||||
var valPerc = deltaVal / rangeWidth; // percent of value on the distance from minValue to maxValue
|
||||
if (valPerc >= 1d)
|
||||
{
|
||||
return map.Colors[^1];
|
||||
}
|
||||
double colorPerc = 1d / (map.Colors.Count - 1d); // % 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 c = GetColorByColorMap(map, blockIdx, percOfColor);
|
||||
return c;
|
||||
}
|
||||
|
||||
private static IValueRange GetExtendedRange(IValueRange range)
|
||||
{
|
||||
var minVal = range.BottomValue - 1e-15d * Math.Abs(range.BottomValue);
|
||||
var maxVal = range.TopValue + 1e-15d * Math.Abs(range.TopValue);
|
||||
return new ValueRange()
|
||||
{
|
||||
BottomValue = minVal,
|
||||
TopValue = maxVal
|
||||
};
|
||||
}
|
||||
|
||||
private static Color GetColorByColorMap(IColorMap map, int blockIdx, double percOfColor)
|
||||
{
|
||||
Color cTarget = map.Colors[blockIdx];
|
||||
Color cNext = map.Colors[blockIdx + 1];
|
||||
|
||||
var deltaRed = cNext.R - cTarget.R;
|
||||
var deltaGreen = cNext.G - cTarget.G;
|
||||
var deltaBlue = cNext.B - cTarget.B;
|
||||
|
||||
var Red = cTarget.R + (deltaRed * percOfColor);
|
||||
var Green = cTarget.G + (deltaGreen * percOfColor);
|
||||
var Blue = cTarget.B + (deltaBlue * percOfColor);
|
||||
|
||||
Color c = Color.FromArgb(Alpha, (byte)Red, (byte)Green, (byte)Blue);
|
||||
return c;
|
||||
}
|
||||
|
||||
private static void CheckColorMap(IColorMap map)
|
||||
{
|
||||
if (map.Colors.Count == 0)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": Color map is empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,22 @@
|
||||
using FieldVisualizer.Entities.ColorMaps.Factories;
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.ColorMaps.Factories;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.Infrastructure.Commands;
|
||||
using FieldVisualizer.InfraStructures.Enums;
|
||||
using FieldVisualizer.InfraStructures.Exceptions;
|
||||
using FieldVisualizer.InfraStructures.Strings;
|
||||
using FieldVisualizer.Services.ColorServices;
|
||||
using FieldVisualizer.Services.PrimitiveServices;
|
||||
using FieldVisualizer.Services.ValueRanges;
|
||||
using FieldVisualizer.Windows.UserControls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using FieldVisualizer.Windows.UserControls;
|
||||
using System.ComponentModel;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace FieldVisualizer.ViewModels.FieldViewerViewModels
|
||||
{
|
||||
@@ -177,7 +172,7 @@ namespace FieldVisualizer.ViewModels.FieldViewerViewModels
|
||||
|
||||
public FieldViewerViewModel()
|
||||
{
|
||||
_ColorMapType = ColorMapsTypes.FullSpectrum;
|
||||
_ColorMapType = ColorMapsTypes.LiraSpectrum;
|
||||
RebuildCommand = new RelayCommand(o => ProcessPrimitives(), o => PrimitiveValidation());
|
||||
ZoomInCommand = new RelayCommand(o => Zoom(1.2), o => PrimitiveValidation());
|
||||
ZoomOutCommand = new RelayCommand(o => Zoom(0.8), o => PrimitiveValidation());
|
||||
|
||||
@@ -1,23 +1,7 @@
|
||||
using FieldVisualizer.Entities.ColorMaps;
|
||||
using FieldVisualizer.Entities.ColorMaps.Factories;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.Infrastructure.Commands;
|
||||
using FieldVisualizer.InfraStructures.Enums;
|
||||
using FieldVisualizer.InfraStructures.Exceptions;
|
||||
using FieldVisualizer.InfraStructures.Strings;
|
||||
using FieldVisualizer.Services.ColorServices;
|
||||
using FieldVisualizer.Services.PrimitiveServices;
|
||||
using FieldVisualizer.Services.ValueRanges;
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.ViewModels.FieldViewerViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace FieldVisualizer.Windows.UserControls
|
||||
{
|
||||
@@ -39,17 +23,6 @@ namespace FieldVisualizer.Windows.UserControls
|
||||
viewModel.Legend = LegendViewer;
|
||||
}
|
||||
|
||||
//public FieldViewer(FieldViewerViewModel vm)
|
||||
//{
|
||||
// InitializeComponent();
|
||||
// viewModel = vm;
|
||||
// this.DataContext = viewModel;
|
||||
// PrimitiveSet = viewModel.PrimitiveSet;
|
||||
// viewModel.WorkPlaneBox = WorkPlaneBox;
|
||||
// viewModel.WorkPlaneCanvas = WorkPlaneCanvas;
|
||||
// viewModel.Legend = LegendViewer;
|
||||
//}
|
||||
|
||||
public IPrimitiveSet PrimitiveSet { get => viewModel.PrimitiveSet; set { viewModel.PrimitiveSet = value; } }
|
||||
|
||||
internal void Refresh()
|
||||
|
||||
Reference in New Issue
Block a user