Files
UVtools/UVtools.Core/Operations/OperationMorph.cs
T
Tiago Conceição 5c5670f0b1 v1.3.5
* (Add) Pixel Dimming: Chamfer - Allow the number of walls pixels to be gradually varied as the operation progresses from the starting layer to the ending layer (#106)
* (Add) PrusaSlicer print profiles: 0.01, 0.02, 0.03, 0.04, 0.15, 0.2
* (Change) Morph: "Fade" to "Chamfer" naming, created profiles need redo
* (Change) Pixel Dimming: Allow start with 0px walls when using "Walls Only"
* (Change) PrusaSlicer print profiles names, reduced bottom layers and raft height
* (Remove) PrusaSlicer print profiles with 3 digit z precision (0.025 and 0.035)
* (Fix) PW0, PWS, PWMX, PWMO, PWMS, PWX file formats, where 4 offsets (16 bytes) were missing on preview image, leading to wrong table size. Previous converted files with UVtools wont open from now on, you need to reconvert them. (ezrec/uv3dp#124)
* (Fix) Unable to run Re-Height tool due a rounding problem on some cases (#101)
* (Fix) Layer preview end with exception when no per layer settings are available (SL1 case)
2020-12-04 01:00:37 +00:00

128 lines
4.0 KiB
C#

/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.Xml.Serialization;
using Emgu.CV.CvEnum;
using UVtools.Core.Objects;
namespace UVtools.Core.Operations
{
[Serializable]
public sealed class OperationMorph : Operation
{
private MorphOp _morphOperation = MorphOp.Erode;
private uint _iterationsStart = 1;
private uint _iterationsEnd = 1;
private bool _chamfer;
#region Overrides
public override string Title => "Morph";
public override string Description =>
$"Morph Model - " +
$"Various operations that can be used to change the physical structure of the model or individual layers.";
public override string ConfirmationText =>
$"morph model layers {LayerIndexStart} through {LayerIndexEnd}?";
public override string ProgressTitle =>
$"Morphing layers {LayerIndexStart} through {LayerIndexEnd}";
public override string ProgressAction => "Morphed layers";
#endregion
#region Properties
public static StringTag[] MorphOperations => new[]
{
new StringTag("Erode - Contracts the boundaries within the object", MorphOp.Erode),
new StringTag("Dilate - Expands the boundaries within the object", MorphOp.Dilate),
new StringTag("Gap Closing - Closes small holes inside the objects", MorphOp.Close),
new StringTag("Noise Removal - Removes small isolated pixels", MorphOp.Open),
new StringTag("Gradient - Removes the interior areas of objects", MorphOp.Gradient),
};
public byte MorphOperationIndex
{
get
{
for (byte i = 0; i < MorphOperations.Length; i++)
{
if ((MorphOp) MorphOperations[i].Tag == MorphOperation) return i;
}
return 0;
}
}
public MorphOp MorphOperation
{
get => _morphOperation;
set => RaiseAndSetIfChanged(ref _morphOperation, value);
}
public uint IterationsStart
{
get => _iterationsStart;
set => RaiseAndSetIfChanged(ref _iterationsStart, value);
}
public uint IterationsEnd
{
get => _iterationsEnd;
set => RaiseAndSetIfChanged(ref _iterationsEnd, value);
}
public bool Chamfer
{
get => _chamfer;
set => RaiseAndSetIfChanged(ref _chamfer, value);
}
[XmlIgnore]
public Kernel Kernel { get; set; } = new Kernel();
public override string ToString()
{
var result = $"[{_morphOperation}] [Iterations: {_iterationsStart}/{_iterationsEnd}] [Chamfer: {_chamfer}]" + LayerRangeString;
if (!string.IsNullOrEmpty(ProfileName)) result = $"{ProfileName}: {result}";
return result;
}
#endregion
#region Equality
private bool Equals(OperationMorph other)
{
return _morphOperation == other._morphOperation && _iterationsStart == other._iterationsStart && _iterationsEnd == other._iterationsEnd && _chamfer == other._chamfer;
}
public override bool Equals(object obj)
{
return ReferenceEquals(this, obj) || obj is OperationMorph other && Equals(other);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _morphOperation;
hashCode = (hashCode * 397) ^ (int) _iterationsStart;
hashCode = (hashCode * 397) ^ (int) _iterationsEnd;
hashCode = (hashCode * 397) ^ _chamfer.GetHashCode();
return hashCode;
}
}
#endregion
}
}