IsoFieldViewer was changed

This commit is contained in:
Evgeny Redikultsev
2024-02-24 17:59:37 +05:00
parent 8572e1f93d
commit 541f23c0a8
16 changed files with 224 additions and 129 deletions

View File

@@ -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();

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -8,4 +8,12 @@
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
<Folder Include="InfraStructures\Enums\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StructureHelperCommon\StructureHelperCommon.csproj" />
</ItemGroup>
</Project>

View File

@@ -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
}
}

View File

@@ -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");
}
}
}
}

View File

@@ -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());

View File

@@ -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()

View File

@@ -14,6 +14,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StructureHelperLogics", "StructureHelperLogics\StructureHelperLogics.csproj", "{C9192AE7-EE6D-409C-A05C-3549D78CBB34}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FieldVisualizer", "FieldVisualizer\FieldVisualizer.csproj", "{6CAC5B83-81F3-47C2-92A1-0F94A58491C2}"
ProjectSection(ProjectDependencies) = postProject
{F1548BD2-7FE8-46C2-9BC4-9BA813A5C59A} = {F1548BD2-7FE8-46C2-9BC4-9BA813A5C59A}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@@ -13,6 +13,7 @@ namespace StructureHelperCommon.Models.Materials
public List<IMaterialSafetyFactor> SafetyFactors { get; set; }
public LimitStates LimitState { get; set; }
public CalcTerms CalcTerm { get; set; }
public double Age { get; set; }
public ILibMaterialEntity MaterialEntity { get; set; }
public bool WorkInCompression { get; set; }
public bool WorkInTension { get; set; }

View File

@@ -38,6 +38,7 @@ namespace StructureHelperCommon.Models.Materials
concreteOptions.ExternalFactor.Tensile = strength.Tensile;
concreteOptions.WorkInTension = options.WorkInTension;
concreteOptions.RelativeHumidity = options.RelativeHumidity;
concreteOptions.Age = options.Age;
}
}
}

View File

@@ -1,17 +1,17 @@
using StructureHelperCommon.Infrastructures.Enums;
using LoaderCalculator.Data.Materials;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Materials.Libraries;
using LMBuilders = LoaderCalculator.Data.Materials.MaterialBuilders;
using LMLogic = LoaderCalculator.Data.Materials.MaterialBuilders.MaterialLogics;
using LM = LoaderCalculator.Data.Materials;
using LoaderCalculator.Data.Materials;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Materials;
namespace StructureHelperLogics.Models.Materials
{
public class ConcreteLibMaterial : IConcreteLibMaterial
{
const double maxAge = 70d * 365 * 24 * 60 * 60;
const MaterialTypes materialType = MaterialTypes.Concrete;
private readonly List<IMaterialLogic> materialLogics;
private LMBuilders.ConcreteOptions lmOptions;
@@ -26,14 +26,18 @@ namespace StructureHelperLogics.Models.Materials
public bool TensionForULS { get ; set; }
/// <inheritdoc/>
public bool TensionForSLS { get; set; }
/// <summary>
/// Humidity of concrete
/// </summary>
/// <inheritdoc/>
public double RelativeHumidity { get; set; }
/// <inheritdoc/>
public IMaterialLogic MaterialLogic { get; set; }
/// <inheritdoc/>
public double MinAge { get; set; }
/// <inheritdoc/>
public double MaxAge { get; set; }
/// <inheritdoc/>
public List<IMaterialLogic> MaterialLogics => materialLogics;
public ConcreteLibMaterial()
{
materialLogics = ProgramSetting.MaterialLogics.Where(x => x.MaterialType == materialType).ToList();
@@ -44,6 +48,8 @@ namespace StructureHelperLogics.Models.Materials
TensionForULS = false;
TensionForSLS = true;
RelativeHumidity = 0.55d;
MinAge = 0d;
MaxAge = maxAge;
}
public object Clone()
@@ -107,6 +113,7 @@ namespace StructureHelperLogics.Models.Materials
{
options.WorkInTension = false;
}
options.Age = MinAge;
}
else if (limitState == LimitStates.SLS)
{
@@ -118,6 +125,14 @@ namespace StructureHelperLogics.Models.Materials
{
options.WorkInTension = false;
}
if (calcTerm == CalcTerms.LongTerm)
{
options.Age = MaxAge;
}
else
{
options.Age = MinAge;
}
}
else
{

View File

@@ -11,6 +11,11 @@ namespace StructureHelperLogics.Models.Materials
{
bool TensionForULS { get; set; }
bool TensionForSLS { get; set; }
/// <summary>
/// Humidity of concrete
/// </summary>
double RelativeHumidity { get; set; }
double MinAge { get; set; }
double MaxAge { get; set; }
}
}

View File

@@ -1,10 +1,8 @@
using FieldVisualizer.Entities.ColorMaps;
using FieldVisualizer.Entities.ColorMaps.Factories;
using FieldVisualizer.Entities.Values;
using FieldVisualizer.InfraStructures.Enums;
using FieldVisualizer.Services.ColorServices;
using NUnit.Framework;
using System.Windows.Media;
namespace StructureHelperTests.FieldsVisualizerTests.ColorOperationTests
{

View File

@@ -1,14 +1,7 @@
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.Entities.Values.Primitives;
using FieldVisualizer.Services.PrimitiveServices;
using FieldVisualizer.Windows;
using NUnit.Framework;
using System.Collections.Generic;
using System.Windows.Media;
namespace StructureHelperTests.FieldsVisualizerTests.WindowTests
{