Skip to content

Commit

Permalink
- HADAAS UI 수정 사항 적용
Browse files Browse the repository at this point in the history
- HADAAS 성능 개선
  • Loading branch information
HyunPark committed Jan 25, 2023
1 parent a2b942d commit e0ac48a
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 82 deletions.
52 changes: 36 additions & 16 deletions netCDFLibrary/Data/ColorPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ namespace netCDFLibrary.Data
{
public class ContourItem
{

public double Threshold {get; set;}
public Scalar Color {get; set;}
public int Thickness {get; set;}

public double Threshold { get; set; }
public Scalar Color { get; set; }
public int Thickness { get; set; }
}

public class ColorPaletteOptions
{
public ColormapTypes colorMap { get; set; }
Expand All @@ -19,13 +18,15 @@ public class ColorPaletteOptions
public double upper { get; set; }
public double alphaValue { get; set; } = 1.0;

public bool isReverse { get; set; } = false;
public bool isYFlip { get; set; } = false;
public bool isAutoFit { get; set; } = true;
public bool isReverseColor { get; set; } = false;
public List<ContourItem> Contours { get; set; } = new();

public double DataRange => (this.upper - this.lower);
public double DataOffset => this.lower / this.DataRange;

public double Normalize(double value) => (value - this.lower) / this.DataRange;

public double Normalize(double value, double outMin, double outMax)
Expand Down Expand Up @@ -58,14 +59,14 @@ public double Normalize(double value, double outMin, double outMax)

ret = ret * (outMax - outMin) + outMin;
return ret;

}

public double Transform(double ratio) => ratio * this.DataRange + this.lower;

public IEnumerable<string> GenerateTicks(int tickCount = 7, string format = "0.00#")
{
for(int i = 0; i < this.colorCount; i++) {
for (int i = 0; i < this.colorCount; i++)
{
if (i % tickCount == 0)
{
var ratio = (double)i / this.colorCount;
Expand All @@ -74,18 +75,21 @@ public IEnumerable<string> GenerateTicks(int tickCount = 7, string format = "0.0
}
}
}

public ColorPaletteOptions(ColormapTypes colorMap, double lower = 0.0, double upper = 1.0, int colorCount = 255)
{
this.colorMap = colorMap;
this.lower = lower;
this.upper = upper;
this.colorCount = colorCount;
}

public ColorPaletteOptions(string colorMap = "Jet", double lower = 0.0, double upper = 1.0, int colorCount = 255)
: this(ColorPalette.colorMaps.ContainsKey(colorMap) ? ColorPalette.colorMaps[colorMap] : ColormapTypes.Jet, lower, upper, colorCount)
{
}
}

public class ColorPalette
{
internal static readonly Dictionary<string, ColormapTypes> colorMaps = Enum.GetValues<ColormapTypes>().ToDictionary(v => v.ToString(), v => v);
Expand All @@ -96,12 +100,17 @@ public class ColorPalette
public double alpha => 255.0 / this.Options.DataRange;
public double beta => -255.0 * this.Options.DataOffset;

public LinearGradientBrush ColorBrush { get; private set; } = new();
public LinearGradientBrush ZeroOneColorBrush { get; private set; } = new();
public LinearGradientBrush OneZeroColorBrush { get; private set; } = new();
public LinearGradientBrush ColorBrush => this.Options.isReverse ? this.OneZeroColorBrush : this.ZeroOneColorBrush;

private ColorPalette() {
private ColorPalette()
{
}

private List<Color> ColorTable = new();
private List<Color> RColorTable = new();

public Color this[double value]
{
get
Expand All @@ -111,6 +120,7 @@ public Color this[double value]
return this.GetColor(colorIndex);
}
}

public int GetColorIndex(double value)
{
var normalizedValue = this.Options.Normalize(value);
Expand All @@ -125,6 +135,7 @@ public int GetColorIndex(double value)
}
return colorIndex;
}

public Color GetColor(int idx)
{
if (idx > this.Options.colorCount || idx > this.RColorTable.Count)
Expand All @@ -134,11 +145,13 @@ public Color GetColor(int idx)

return this.RColorTable[idx];
}

public void UpdatePalette(ColorPaletteOptions options)
{
this.Options = options;
this.UpdatePalette();
}

public void UpdatePalette()
{
var colorCount = this.Options.colorCount;
Expand All @@ -148,7 +161,7 @@ public void UpdatePalette()
for (int i = 0; i < colorSrc.Rows; i++)
{
var ratio = (double)i / colorSrc.Rows;
var value =this.Options.Transform(ratio);
var value = this.Options.Transform(ratio);
colorSrcIndexer[0, i] = value;
}
Mat bwSrc = new();
Expand All @@ -169,28 +182,35 @@ public void UpdatePalette()
}

this.RColorTable = this.ColorTable.ToArray().Reverse().ToList();
List<GradientStop> colors = new List<GradientStop>();
List<GradientStop> colors = new List<GradientStop>();

for (int i = 0; i < this.ColorTable.Count; i++)
{

colors.Add(new GradientStop()
{
Color = this.ColorTable[i],
Offset = (float)i / colorCount
});
}
this.ColorBrush = new LinearGradientBrush()
this.ZeroOneColorBrush = new LinearGradientBrush()
{
StartPoint = new System.Windows.Point(0, 0),
EndPoint = new System.Windows.Point(0, 1),
GradientStops = new GradientStopCollection(colors)
};
this.OneZeroColorBrush = new LinearGradientBrush()
{
StartPoint = new System.Windows.Point(0, 1),
EndPoint = new System.Windows.Point(0, 0),
GradientStops = new GradientStopCollection(colors)
};
}
public static ColorPalette Create(ColorPaletteOptions options) {

public static ColorPalette Create(ColorPaletteOptions options)
{
var palette = new ColorPalette();
palette.UpdatePalette(options);
return palette;
}
}
}
}
61 changes: 47 additions & 14 deletions netCDFLibrary/Data/CoordinateScaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public CoordinateScaler(double minX, double maxX, double minY, double maxY, doub
this.YGap = (this.MaxY - this.MinY) / this.Height;
this.IsYFlip = isYFlip;
}

public CoordinateScaler(double minX, double maxX, double minY, double maxY, double width, double height, double XGap, double YGap, bool isYFlip = false)
{
this.MinX = minX;
Expand All @@ -44,26 +45,46 @@ public CoordinateScaler(double minX, double maxX, double minY, double maxY, doub
}

public bool XContains(double X) => this.MinX <= X && this.MaxX > X;

public bool YContains(double Y) => this.MinY <= Y && this.MaxY > Y;

public bool Contains(double Y, double X) => this.XContains(X) && this.YContains(Y);

public double XOffset(int col) => this.MinX + (col * this.XGap);

public double YOffset(int row) => this.MinY + (row * this.YGap);

public (double, double) GetOffset(int row, int col) => (this.YOffset(row), this.XOffset(col));

public (double, double) this[int row, int col] => this.GetOffset(row, col);

private double XNormalize(double value)
{
return (value > 180) ? value - 360 : value < -180 ? value + 360 : value;
}

private double YNormalize(double value)
{
return (value > 90) ? value - 180 : value < -90 ? value + 180 : value;
}

public int FindYIndex(double Y)
{
if (Y < this.MinY || Y > this.MaxY)
var actualY = Y;
if (actualY <= this.MinY)
{
return -1;
actualY = this.MinY;
}

int YOffset = this.IsYFlip ? (int)this.Height : 0;
if (actualY >= this.MaxY)
{
actualY = this.MaxY;
}

var result = (int)((Y - this.MinY) / this.YGap);
if(result != 0 && YOffset != 0)
int YOffset = this.IsYFlip ? (int)this.Height - 1 : 0;

var result = (int)((actualY - this.MinY) / this.YGap);
if (result != 0 && YOffset != 0)
{
result = Math.Abs(YOffset - result);
}
Expand All @@ -76,29 +97,41 @@ public int FindYIndex(double Y)

public int FindXIndex(double X)
{
if (X < this.MinX || X > this.MaxX)
var actualX = X;
if (actualX <= this.MinX)
{
actualX = this.MinX;
}

if (actualX >= this.MaxX)
{
return -1;
actualX = this.MaxX;
}
var result = (int)((X - this.MinX) / this.XGap);
var result = (int)((actualX - this.MinX) / this.XGap);
if (result == (int)this.Width)
{
return result - 1;
}
return result;
}

public (int, int) FindIndex(double Y, double X)
{
return (this.FindYIndex(Y), this.FindXIndex(X));
}

public CoordinateScaler GetNearest(double minX, double minY, double maxX, double maxY)
{

var normMinX = this.XNormalize(minX);
var normMinY = this.YNormalize(minY);

var normMaxX = this.XNormalize(maxX);
var normMaxY = this.YNormalize(maxY);
// Arrange Boundaries
var actualMinX = Math.Min(minX, maxX);
var actualMaxX = Math.Max(minX, maxX);
var actualMinY = Math.Min(minY, maxY);
var actualMaxY = Math.Max(minY, maxY);
var actualMinX = Math.Min(normMinX, normMaxX);
var actualMaxX = Math.Max(normMinX, normMaxX);
var actualMinY = Math.Min(normMinY, normMaxY);
var actualMaxY = Math.Max(normMinY, normMaxY);

//
actualMinX = Math.Max(this.MinX, actualMinX);
Expand All @@ -123,4 +156,4 @@ public CoordinateScaler GetNearest(double minX, double minY, double maxX, double
};
}
}
}
}
11 changes: 8 additions & 3 deletions netCDFLibrary/Data/DataScale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public struct DataScale
public readonly string? LongName = "";
public readonly string? StandardName = "";
public readonly string? Units = "";
internal DataScale(Variable variable) : this(variable, defaultScaleFactorKeys, defaultAddOffsetKeys, defaultMissingValueKeys, defaultFillValueKeys) { }

internal DataScale(Variable variable) : this(variable, defaultScaleFactorKeys, defaultAddOffsetKeys, defaultMissingValueKeys, defaultFillValueKeys)
{
}

internal DataScale(Variable variable, string[] ScaleFactorKeys, string[] AddOffsetKeys, string[] MissingValueKeys, string[] FillValueKeys)
{
this.Name = variable.Metadata.GetDisplayName();
Expand Down Expand Up @@ -65,13 +69,14 @@ internal DataScale(Variable variable, string[] ScaleFactorKeys, string[] AddOffs
this.MissingValue = this.FillValue;
}
}

internal double Transform(object? value)
{
if (value == null)
{
return this.MissingValue;
}
if(Convert.ToDouble(value) == this.MissingValue)
if (Convert.ToDouble(value) == this.MissingValue)
{
return this.MissingValue;
}
Expand All @@ -82,4 +87,4 @@ internal double Transform(object? value)
}
}
}
}
}
Loading

0 comments on commit e0ac48a

Please sign in to comment.