Skip to content

Commit

Permalink
v4.4.2
Browse files Browse the repository at this point in the history
- (Add) Tool - Redraw model: Add multiple operator modes (#926)
- (Fix) Tool - Redraw model: Redo (Ctrl + Shift + Z) would cause a crash
- (Fix) Pixel Editor: Make the content scrollable when the window is resized to a smaller size
- (Fix) Calibration - Exposure time finder: When the "Multiple exposures" panel is collapsed it become disabled and unusable
- (Fix) Layer preview - Difference: Fixes the white background over black pixels
- (Fix) macOS: "Avalonia Application" to "UVtools" title on some app managers
  • Loading branch information
sn4k3 committed Sep 14, 2024
1 parent c116aff commit f56dc04
Show file tree
Hide file tree
Showing 16 changed files with 738 additions and 628 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 14/09/2024 - v4.4.2

- (Add) Tool - Redraw model: Add multiple operator modes (#926)
- (Fix) Tool - Redraw model: Redo (Ctrl + Shift + Z) would cause a crash
- (Fix) Pixel Editor: Make the content scrollable when the window is resized to a smaller size
- (Fix) Calibration - Exposure time finder: When the "Multiple exposures" panel is collapsed it become disabled and unusable
- (Fix) Layer preview - Difference: Fixes the white background over black pixels
- (Fix) macOS: Change title "Avalonia Application" to "UVtools" on some app managers

## 19/08/2024 - v4.4.1

- (Add) Pixel Editor: Fill tool and merge into Erase section, left click fills and right click erases
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<CommonPublishDir>$(MSBuildThisFileDirectory)publish</CommonPublishDir>

<UVtoolsVersion>4.4.1</UVtoolsVersion>
<UVtoolsVersion>4.4.2</UVtoolsVersion>
<AvaloniaVersion>11.1.3</AvaloniaVersion>
</PropertyGroup>

Expand Down
11 changes: 6 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- (Add) Pixel Editor: Fill tool and merge into Erase section, left click fills and right click erases
- (Improvement) SL1: Implement missing material override properties
- (Fix) File formats: Error while trying to generate a thumbnail for a file that have a empty first layer (#912)
- (Upgrade) AvaloniaUI from 11.1.1 to 11.1.3
- (Upgrade) .NET from 6.0.32 to 6.0.33
- (Add) Tool - Redraw model: Add multiple operator modes (#926)
- (Fix) Tool - Redraw model: Redo (Ctrl + Shift + Z) would cause a crash
- (Fix) Pixel Editor: Make the content scrollable when the window is resized to a smaller size
- (Fix) Calibration - Exposure time finder: When the "Multiple exposures" panel is collapsed it become disabled and unusable
- (Fix) Layer preview - Difference: Fixes the white background over black pixels
- (Fix) macOS: Change title "Avalonia Application" to "UVtools" on some app managers

19 changes: 6 additions & 13 deletions UVtools.Core/Extensions/EmguExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ public static byte[] CreateByteArray(this Mat mat)
public static Mat New(this Mat mat)
=> new(mat.Size, mat.Depth, mat.NumberOfChannels);

/// <summary>
/// Creates a new <see cref="Mat"/> with same size and type of the source
/// </summary>
/// <param name="src"></param>
/// <param name="color"></param>
/// <returns></returns>
public static Mat New(this Mat src, MCvScalar color)
=> InitMat(src.Size, color, src.NumberOfChannels, src.Depth);

/// <summary>
/// Creates a new blanked (All zeros) <see cref="Mat"/> with same size and type of the source
/// </summary>
Expand All @@ -97,9 +88,10 @@ public static UMat NewZeros(this UMat mat)
/// </summary>
/// <param name="mat"></param>
/// <param name="color"></param>
/// <param name="mask"></param>
/// <returns></returns>
public static Mat NewSetTo(this Mat mat, MCvScalar color)
=> InitMat(mat.Size, color, mat.NumberOfChannels, mat.Depth);
public static Mat NewSetTo(this Mat mat, MCvScalar color, IInputArray? mask = null)
=> InitMat(mat.Size, color, mat.NumberOfChannels, mat.Depth, mask);


/// <summary>
Expand Down Expand Up @@ -134,12 +126,13 @@ public static UMat InitUMat(Size size, int channels = 1, DepthType depthType = D
/// <param name="color"></param>
/// <param name="channels"></param>
/// <param name="depthType"></param>
/// <param name="mask"></param>
/// <returns></returns>
public static Mat InitMat(Size size, MCvScalar color, int channels = 1, DepthType depthType = DepthType.Cv8U)
public static Mat InitMat(Size size, MCvScalar color, int channels = 1, DepthType depthType = DepthType.Cv8U, IInputArray? mask = null)
{
if (size.IsEmpty) return new();
var mat = new Mat(size, depthType, channels);
mat.SetTo(color);
mat.SetTo(color, mask);
return mat;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ public Mat[] GetLayers(bool isPreview = false)
var bars = Bars;
var bulleyes = BullsEyes;
var textSize = TextSize;

int featuresMarginX = (int)(Xppmm * _featuresMargin);
int featuresMarginY = (int)(Yppmm * _featuresMargin);
ushort startCaseThickness = StaircaseThickness;
Expand Down
92 changes: 87 additions & 5 deletions UVtools.Core/Operations/OperationRedrawModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using System;
using System.ComponentModel;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
Expand All @@ -23,13 +24,37 @@ namespace UVtools.Core.Operations;
public class OperationRedrawModel : Operation
#pragma warning restore CS0659 // Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
#region Enums
public enum RedrawModelOperators : byte
{
[Description("Set: to a brightness")]
Set,
[Description("Add: with a brightness")]
Add,
[Description("Subtract: with a brightness")]
Subtract,
[Description("Multiply: with a brightness")]
Multiply,
[Description("Divide: with a brightness")]
Divide,
[Description("Minimum: set to a brightness if is lower than the current pixel")]
Minimum,
[Description("Maximum: set to a brightness if is higher than the current pixel")]
Maximum,
[Description("AbsDiff: perform a absolute difference between pixel and brightness")]
AbsDiff,
}

#endregion

#region Members

private string _filePath = null!;
private byte _brightness = 220;
private bool _contactPointsOnly = true;
private RedrawTypes _redrawType = RedrawTypes.Supports;
private bool _ignoreContactLessPixels = true;
private RedrawModelOperators _operator = RedrawModelOperators.Minimum;

#endregion

Expand All @@ -44,7 +69,7 @@ public class OperationRedrawModel : Operation
"Note: Run this tool prior to any made modification. You must find the optimal exposure/brightness combo, or supports can fail.";

public override string ConfirmationText => "redraw the "+ (_redrawType == RedrawTypes.Supports ? "supports" : "model") +
$" with an brightness of {_brightness}?";
" with an"+ (_redrawType == RedrawTypes.Model || !_contactPointsOnly ? $" {_operator}" : string.Empty) + $" brightness of {_brightness}?";

public override string ProgressTitle => "Redrawing " + (_redrawType == RedrawTypes.Supports ? "supports" : "model");

Expand All @@ -59,13 +84,30 @@ public class OperationRedrawModel : Operation
sb.AppendLine("The selected file is not valid.");
}

if (_redrawType == RedrawTypes.Model || _contactPointsOnly)
{
switch (_operator)
{
case RedrawModelOperators.Add:
case RedrawModelOperators.Subtract:
case RedrawModelOperators.Maximum:
case RedrawModelOperators.AbsDiff:
if (_brightness == 0) sb.AppendLine($"{_operator} with a brightness of 0 yield no result, please use a value larger than 0.");
break;
case RedrawModelOperators.Divide:
if (_brightness == 0) sb.AppendLine($"{_operator} with a brightness of 0 is not valid, please use a value larger than 0.");
else if (_brightness == 1) sb.AppendLine($"{_operator} with a brightness of 0 yield no result, please use a value larger than 0.");
break;
}
}

return sb.ToString();
}


public override string ToString()
{
var result = $"[{_redrawType}] [B: {_brightness}] [CS: {_contactPointsOnly}] [ICLP: {_ignoreContactLessPixels}]";
var result = $"[{_redrawType}] [B: {_brightness}] [OP: {_operator}] [CS: {_contactPointsOnly}] [ICLP: {_ignoreContactLessPixels}]";
if (!string.IsNullOrEmpty(ProfileName)) result = $"{ProfileName}: {result}";
return result;
}
Expand Down Expand Up @@ -104,7 +146,11 @@ public RedrawTypes RedrawType
set => RaiseAndSetIfChanged(ref _redrawType, value);
}

public static Array RedrawTypesItems => Enum.GetValues(typeof(RedrawTypes));
public RedrawModelOperators Operator
{
get => _operator;
set => RaiseAndSetIfChanged(ref _operator, value);
}

public byte Brightness
{
Expand Down Expand Up @@ -169,14 +215,18 @@ protected override bool ExecuteInternally(OperationProgress progress)
if (startLayerIndex < 0) return false;
Parallel.For(0, otherFile.LayerCount, CoreSettings.GetParallelOptions(progress), layerIndex =>
{
if (SlicerFile[layerIndex].IsEmpty)
{
progress.LockAndIncrement();
return;
}
progress.PauseIfRequested();
var fullMatLayerIndex = startLayerIndex + layerIndex;
using var fullMat = SlicerFile[fullMatLayerIndex].LayerMat;
using var original = fullMat.Clone();
using var bodyMat = otherFile[layerIndex].LayerMat;
using var fullMatRoi = GetRoiOrDefault(fullMat);
using var bodyMatRoi = GetRoiOrDefault(bodyMat);
using var patternMat = EmguExtensions.InitMat(fullMatRoi.Size, new MCvScalar(255 - _brightness));
using var supportsMat = new Mat();
bool modified = false;
Expand Down Expand Up @@ -229,9 +279,41 @@ protected override bool ExecuteInternally(OperationProgress progress)
case RedrawTypes.Model:
CvInvoke.BitwiseAnd(fullMatRoi, bodyMatRoi, supportsMat); // Model
break;
default:
throw new ArgumentOutOfRangeException(nameof(RedrawType), _redrawType, null);
}
CvInvoke.Subtract(fullMatRoi, patternMat, fullMatRoi, supportsMat);
using var patternMat = fullMatRoi.NewSetTo(new MCvScalar(_brightness), supportsMat);
switch (_operator)
{
case RedrawModelOperators.Set:
patternMat.CopyTo(fullMatRoi, fullMatRoi);
break;
case RedrawModelOperators.Add:
CvInvoke.Add(fullMatRoi, patternMat, fullMatRoi, supportsMat);
break;
case RedrawModelOperators.Subtract:
CvInvoke.Subtract(fullMatRoi, patternMat, fullMatRoi, supportsMat);
break;
case RedrawModelOperators.Multiply:
CvInvoke.Multiply(fullMatRoi, patternMat, fullMatRoi, EmguExtensions.ByteScale);
break;
case RedrawModelOperators.Divide:
CvInvoke.Divide(fullMatRoi, patternMat, fullMatRoi);
break;
case RedrawModelOperators.Minimum:
CvInvoke.Min(fullMatRoi, patternMat, fullMatRoi);
break;
case RedrawModelOperators.Maximum:
CvInvoke.Max(fullMatRoi, patternMat, fullMatRoi);
break;
case RedrawModelOperators.AbsDiff:
CvInvoke.AbsDiff(fullMatRoi, patternMat, fullMatRoi);
break;
default:
throw new ArgumentOutOfRangeException(nameof(Operator), _operator, null);
}
modified = true;
}
Expand Down
4 changes: 2 additions & 2 deletions UVtools.Core/UVtools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<ItemGroup>
<PackageReference Include="AnimatedGif" Version="1.0.5" />
<PackageReference Include="BinarySerializer" Version="8.6.4.1" />
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.3.1" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.3.1" />
<PackageReference Include="Emgu.CV" Version="4.9.0.5494" />
<PackageReference Include="Emgu.CV.runtime.mini.macos" Version="4.9.0.5494" />
<PackageReference Include="Emgu.CV.runtime.mini.ubuntu-x64" Version="4.9.0.5494" />
Expand Down
3 changes: 3 additions & 0 deletions UVtools.UI/App.axaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:UVtools.UI.Converters"
xmlns:core="clr-namespace:UVtools.Core;assembly=UVtools.Core"
Name="{Binding Source={x:Static core:About.Software}}"
x:Class="UVtools.UI.App"
RequestedThemeVariant="Default">
<Application.Resources>
<converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
<converters:EnumToCollectionConverter x:Key="EnumToCollectionConverter" />
<converters:FromValueDescriptionToEnumConverter x:Key="FromValueDescriptionToEnumConverter" />
<converters:NumericUpDownValueConverter x:Key="NumericUpDownValueConverter" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@

<Expander Name="MultipleExposuresExpander"
HorizontalAlignment="Stretch"
IsExpanded="{Binding $self.IsEnabled}">
IsExpanded="{Binding $self.IsEnabled, Mode=OneTime}">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Multiple exposures"/>
Expand Down
Loading

0 comments on commit f56dc04

Please sign in to comment.