1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* 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();
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
}
}
|