mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-08 17:42:31 +02:00
Convert pixel dimming to toolwindow
This commit is contained in:
@@ -641,7 +641,7 @@ namespace UVtools.Core
|
||||
}
|
||||
}
|
||||
|
||||
public void MutatePixelDimming(Mat evenPatternMask, Mat oddPatternMask = null, ushort borderSize = 5, bool dimOnlyBorders = false)
|
||||
public void PixelDimming(OperationPixelDimming operation, Mat evenPatternMask, Mat oddPatternMask = null)
|
||||
{
|
||||
var anchor = new Point(-1, -1);
|
||||
var kernel = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), anchor);
|
||||
@@ -655,9 +655,9 @@ namespace UVtools.Core
|
||||
using (Mat erode = new Mat())
|
||||
using (Mat diff = new Mat())
|
||||
{
|
||||
CvInvoke.Erode(dst, erode, kernel, anchor, borderSize, BorderType.Reflect101, default);
|
||||
CvInvoke.Erode(dst, erode, kernel, anchor, (int) operation.BorderSize, BorderType.Reflect101, default);
|
||||
CvInvoke.Subtract(dst, erode, diff);
|
||||
if (dimOnlyBorders)
|
||||
if (operation.BordersOnly)
|
||||
{
|
||||
CvInvoke.BitwiseAnd(diff, Index % 2 == 0 ? evenPatternMask : oddPatternMask, dst);
|
||||
CvInvoke.Add(erode, dst, dst);
|
||||
|
||||
@@ -419,23 +419,22 @@ namespace UVtools.Core
|
||||
progress.Token.ThrowIfCancellationRequested();
|
||||
}
|
||||
|
||||
public void MutatePixelDimming(uint startLayerIndex, uint endLayerIndex, Matrix<byte> evenPattern = null,
|
||||
Matrix<byte> oddPattern = null, ushort borderSize = 5, bool dimOnlyBorders = false, OperationProgress progress = null)
|
||||
public void PixelDimming(OperationPixelDimming operation, OperationProgress progress = null)
|
||||
{
|
||||
if (ReferenceEquals(progress, null)) progress = new OperationProgress();
|
||||
progress.Reset("Dimming pixels", endLayerIndex - startLayerIndex + 1);
|
||||
if (progress is null) progress = new OperationProgress();
|
||||
progress.Reset(operation.ProgressAction, operation.LayerRangeCount);
|
||||
|
||||
if (ReferenceEquals(evenPattern, null))
|
||||
if (operation.EvenPattern is null)
|
||||
{
|
||||
evenPattern = new Matrix<byte>(2, 2)
|
||||
operation.EvenPattern = new Matrix<byte>(2, 2)
|
||||
{
|
||||
[0, 0] = 127, [0, 1] = 255,
|
||||
[1, 0] = 255, [1, 1] = 127,
|
||||
};
|
||||
|
||||
if (ReferenceEquals(oddPattern, null))
|
||||
if (operation.OddPattern is null)
|
||||
{
|
||||
oddPattern = new Matrix<byte>(2, 2)
|
||||
operation.OddPattern = new Matrix<byte>(2, 2)
|
||||
{
|
||||
[0, 0] = 255, [0, 1] = 127,
|
||||
[1, 0] = 127, [1, 1] = 255,
|
||||
@@ -443,36 +442,32 @@ namespace UVtools.Core
|
||||
}
|
||||
}
|
||||
|
||||
if (ReferenceEquals(oddPattern, null))
|
||||
if (operation.OddPattern is null)
|
||||
{
|
||||
oddPattern = evenPattern;
|
||||
operation.OddPattern = operation.EvenPattern;
|
||||
}
|
||||
|
||||
using (Mat mat = this[0].LayerMat)
|
||||
using (Mat matEven = mat.CloneBlank())
|
||||
using (Mat matOdd = mat.CloneBlank())
|
||||
{
|
||||
using (var matEven = mat.CloneBlank())
|
||||
{
|
||||
using (Mat matOdd = mat.CloneBlank())
|
||||
{
|
||||
CvInvoke.Repeat(evenPattern, mat.Rows / evenPattern.Rows + 1, mat.Cols / evenPattern.Cols + 1, matEven);
|
||||
CvInvoke.Repeat(oddPattern, mat.Rows / oddPattern.Rows + 1, mat.Cols / oddPattern.Cols + 1, matOdd);
|
||||
CvInvoke.Repeat(operation.EvenPattern, mat.Rows / operation.EvenPattern.Rows + 1,
|
||||
mat.Cols / operation.EvenPattern.Cols + 1, matEven);
|
||||
CvInvoke.Repeat(operation.OddPattern, mat.Rows / operation.OddPattern.Rows + 1,
|
||||
mat.Cols / operation.OddPattern.Cols + 1, matOdd);
|
||||
|
||||
using (var evenPatternMask = new Mat(matEven, new Rectangle(0, 0, mat.Width, mat.Height)))
|
||||
using (var evenPatternMask = new Mat(matEven, new Rectangle(0, 0, mat.Width, mat.Height)))
|
||||
using (var oddPatternMask = new Mat(matOdd, new Rectangle(0, 0, mat.Width, mat.Height)))
|
||||
{
|
||||
Parallel.For(operation.LayerIndexStart, operation.LayerIndexEnd + 1, layerIndex =>
|
||||
{
|
||||
if (progress.Token.IsCancellationRequested) return;
|
||||
this[layerIndex].PixelDimming(operation, evenPatternMask, oddPatternMask);
|
||||
lock (progress.Mutex)
|
||||
{
|
||||
using (var oddPatternMask = new Mat(matOdd, new Rectangle(0, 0, mat.Width, mat.Height)))
|
||||
{
|
||||
Parallel.For(startLayerIndex, endLayerIndex + 1, layerIndex =>
|
||||
{
|
||||
if (progress.Token.IsCancellationRequested) return;
|
||||
this[layerIndex].MutatePixelDimming(evenPatternMask, oddPatternMask, borderSize, dimOnlyBorders);
|
||||
lock (progress.Mutex)
|
||||
{
|
||||
progress++;
|
||||
}
|
||||
});
|
||||
}
|
||||
progress++;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.Text;
|
||||
using Emgu.CV;
|
||||
using UVtools.Core.Objects;
|
||||
|
||||
namespace UVtools.Core.Operations
|
||||
{
|
||||
public class OperationPixelDimming : Operation
|
||||
{
|
||||
#region Overrides
|
||||
public override string Title => "Pixel dimming";
|
||||
public override string Description =>
|
||||
"Dims pixels in a chosen pattern over white pixels neighborhood. The selected pattern will be repeated over the image width and height as a mask. Benefits are:\n" +
|
||||
"1) Reduce layer expansion in big masses\n" +
|
||||
"2) Reduce cross layer exposure\n" +
|
||||
"3) Extend pixels life\n" +
|
||||
"NOTE: Run only this tool after all repairs and other transformations.";
|
||||
|
||||
public override string ConfirmationText =>
|
||||
$"dim pixels from layers {LayerIndexStart} to {LayerIndexEnd}";
|
||||
|
||||
public override string ProgressTitle =>
|
||||
$"Dimming from layers {LayerIndexStart} to {LayerIndexEnd}";
|
||||
|
||||
public override string ProgressAction => "Dimmed layers";
|
||||
|
||||
public override StringTag Validate(params object[] parameters)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (BorderSize == 0 && BordersOnly)
|
||||
{
|
||||
sb.AppendLine("Border size must be positive in order to use \"Dims only the borders\" function.");
|
||||
}
|
||||
|
||||
if (EvenPattern is null && OddPattern is null)
|
||||
{
|
||||
sb.AppendLine("Either even or odd pattern must contain a valid matrix.");
|
||||
}
|
||||
|
||||
return new StringTag(sb.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public uint BorderSize { get; set; }
|
||||
public bool BordersOnly { get; set; }
|
||||
public Matrix<byte> EvenPattern { get; set; }
|
||||
public Matrix<byte> OddPattern { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -150,11 +150,12 @@ namespace UVtools.GUI.Controls
|
||||
/// <summary>
|
||||
/// Updates operation object with items retrieved from form fields
|
||||
/// </summary>
|
||||
public virtual void UpdateOperation()
|
||||
public virtual bool UpdateOperation()
|
||||
{
|
||||
if (ParentToolWindow is null) return;
|
||||
if (ParentToolWindow is null) return true;
|
||||
BaseOperation.LayerIndexStart = ParentToolWindow.LayerRangeStart;
|
||||
BaseOperation.LayerIndexEnd = ParentToolWindow.LayerRangeEnd;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -164,7 +165,7 @@ namespace UVtools.GUI.Controls
|
||||
public virtual bool ValidateForm()
|
||||
{
|
||||
if (BaseOperation is null) return true;
|
||||
UpdateOperation();
|
||||
if(!UpdateOperation()) return false;
|
||||
return ValidateFormFromString(BaseOperation.Validate());
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +58,12 @@ namespace UVtools.GUI.Controls.Tools
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
Operation.NewResolutionX = NewResolutionX;
|
||||
Operation.NewResolutionY = NewResolutionY;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,11 +34,12 @@ namespace UVtools.GUI.Controls.Tools
|
||||
cbFlipDirection.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
Operation.FlipDirection = (Enumerations.FlipDirection)cbFlipDirection.SelectedItem;
|
||||
Operation.MakeCopy = cbMakeCopy.Checked;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,11 @@ namespace UVtools.GUI.Controls.Tools
|
||||
lbHeights.Text = $"Heights: {Program.SlicerFile.TotalHeight}mm → {Program.SlicerFile.TotalHeight + extraHeight}mm (+ {extraHeight}mm)";
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
Operation.Clones = (uint) nmClones.Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,13 @@ namespace UVtools.GUI.Controls.Tools
|
||||
nmInsertAfterLayer_ValueChanged(nmInsertAfterLayer, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
Operation.InsertAfterLayerIndex = (uint)nmInsertAfterLayer.Value;
|
||||
Operation.ReplaceStartLayer = cbReplaceStartLayer.Checked;
|
||||
Operation.ReplaceSubsequentLayers = cbReplaceSubsequentLayers.Checked;
|
||||
Operation.DiscardRemainingLayers = cbDiscardRemainingLayers.Checked;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,10 +46,11 @@ namespace UVtools.GUI.Controls.Tools
|
||||
ButtonOkEnabled = cbMultiplier.SelectedIndex >= 0;
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
Operation.Item = (OperationLayerReHeight.OperationLayerReHeightItem)cbMultiplier.SelectedItem;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace UVtools.GUI.Controls.Tools
|
||||
}
|
||||
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
Operation.IterationsStart = (uint) nmIterationsStart.Value;
|
||||
@@ -39,6 +39,7 @@ namespace UVtools.GUI.Controls.Tools
|
||||
Operation.MorphOperation = (MorphOp)((StringTag) cbMorphOperation.SelectedItem).Tag;
|
||||
Operation.Kernel.Anchor = ctrlKernel.KernelAnchor;
|
||||
Operation.Kernel.Matrix = ctrlKernel.GetMatrix();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void EventCheckedChanged(object sender, EventArgs e)
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace UVtools.GUI.Controls.Tools
|
||||
lbPlacementY.Text = $"Placement Y: {Operation.DstRoi.Y} / {Operation.ImageHeight - Operation.SrcRoi.Height}";
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
byte i = 0;
|
||||
@@ -73,6 +73,7 @@ namespace UVtools.GUI.Controls.Tools
|
||||
Operation.MarginTop = (int)nmMarginTop.Value;
|
||||
Operation.MarginRight = (int)nmMarginRight.Value;
|
||||
Operation.MarginBottom = (int)nmMarginBottom.Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace UVtools.GUI.Controls.Tools
|
||||
EventValueChanged(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
|
||||
@@ -77,6 +77,7 @@ namespace UVtools.GUI.Controls.Tools
|
||||
|
||||
Operation.Cols = (ushort)nmCols.Value;
|
||||
Operation.Rows = (ushort)nmRows.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void EventValueChanged(object sender, EventArgs e)
|
||||
|
||||
+348
-568
File diff suppressed because it is too large
Load Diff
+70
-262
@@ -8,193 +8,100 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Emgu.CV;
|
||||
using Emgu.CV.CvEnum;
|
||||
using UVtools.Core.Extensions;
|
||||
using UVtools.Core.Operations;
|
||||
|
||||
namespace UVtools.GUI.Forms
|
||||
namespace UVtools.GUI.Controls.Tools
|
||||
{
|
||||
public partial class FrmMutationPixelDimming : Form
|
||||
public partial class CtrlToolPixelDimming : CtrlToolWindowContent
|
||||
{
|
||||
class MatrixTexbox
|
||||
#region Subclasses
|
||||
class TexboxMatrix
|
||||
{
|
||||
public Matrix<byte> Pattern;
|
||||
public TextBox Textbox;
|
||||
public Matrix<byte> Pattern { get; set; }
|
||||
public TextBox Textbox { get; }
|
||||
|
||||
public MatrixTexbox(Matrix<byte> pattern, TextBox textbox)
|
||||
public TexboxMatrix(TextBox textbox)
|
||||
{
|
||||
Pattern = pattern;
|
||||
Textbox = textbox;
|
||||
}
|
||||
}
|
||||
#region Properties
|
||||
|
||||
private Mutation Mutation { get; }
|
||||
|
||||
public uint LayerRangeStart
|
||||
{
|
||||
get => (uint) nmLayerRangeStart.Value;
|
||||
set => nmLayerRangeStart.Value = value;
|
||||
}
|
||||
|
||||
public uint LayerRangeEnd
|
||||
{
|
||||
get => (uint)Math.Min(nmLayerRangeEnd.Value, Program.SlicerFile.LayerCount-1);
|
||||
set => nmLayerRangeEnd.Value = value;
|
||||
}
|
||||
|
||||
public uint BorderSize
|
||||
{
|
||||
get => (uint)nmBorderSize.Value;
|
||||
set => nmBorderSize.Value = value;
|
||||
}
|
||||
|
||||
public bool DimsOnlyBorders
|
||||
{
|
||||
get => cbDimsOnlyBorders.Checked;
|
||||
set => cbDimsOnlyBorders.Checked = value;
|
||||
}
|
||||
|
||||
public Matrix<byte> EvenPattern { get; private set; }
|
||||
public Matrix<byte> OddPattern { get; private set; }
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public FrmMutationPixelDimming(Mutation mutation)
|
||||
public OperationPixelDimming Operation { get; }
|
||||
|
||||
public CtrlToolPixelDimming()
|
||||
{
|
||||
InitializeComponent();
|
||||
Mutation = mutation;
|
||||
DialogResult = DialogResult.Cancel;
|
||||
|
||||
nmBorderSize.Select();
|
||||
|
||||
Text = $"Mutate: {mutation.MenuName}";
|
||||
lbDescription.Text = Mutation.Description;
|
||||
|
||||
nmLayerRangeEnd.Value = Program.SlicerFile.LayerCount-1;
|
||||
|
||||
ItemClicked(btnDimPatternChessBoard, null);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
protected override void OnKeyUp(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyUp(e);
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
if (tbEvenPattern.ContainsFocus || tbOddPattern.ContainsFocus) return;
|
||||
btnMutate.PerformClick();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ModifierKeys & Keys.Shift) == Keys.Shift && (ModifierKeys & Keys.Control) == Keys.Control)
|
||||
{
|
||||
if (e.KeyCode == Keys.A)
|
||||
{
|
||||
btnLayerRangeAllLayers.PerformClick();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.KeyCode == Keys.C)
|
||||
{
|
||||
btnLayerRangeCurrentLayer.PerformClick();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.KeyCode == Keys.B)
|
||||
{
|
||||
btnLayerRangeBottomLayers.PerformClick();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.KeyCode == Keys.N)
|
||||
{
|
||||
btnLayerRangeNormalLayers.PerformClick();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
Operation = new OperationPixelDimming();
|
||||
SetOperation(Operation);
|
||||
EventClick(btnDimPatternChessBoard, null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
private void ItemClicked(object sender, EventArgs e)
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
if (ReferenceEquals(sender, btnLayerRangeAllLayers))
|
||||
{
|
||||
nmLayerRangeStart.Value = 0;
|
||||
nmLayerRangeEnd.Value = Program.SlicerFile.LayerCount-1;
|
||||
return;
|
||||
}
|
||||
base.UpdateOperation();
|
||||
Operation.BorderSize = (uint) nmBorderSize.Value;
|
||||
Operation.BordersOnly = cbDimsOnlyBorders.Checked;
|
||||
|
||||
if (ReferenceEquals(sender, btnLayerRangeCurrentLayer))
|
||||
{
|
||||
nmLayerRangeStart.Value = Program.FrmMain.ActualLayer;
|
||||
nmLayerRangeEnd.Value = Program.FrmMain.ActualLayer;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(sender, btnLayerRangeBottomLayers))
|
||||
{
|
||||
nmLayerRangeStart.Value = 0;
|
||||
nmLayerRangeEnd.Value = Program.SlicerFile.InitialLayerCount-1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(sender, btnLayerRangeNormalLayers))
|
||||
{
|
||||
nmLayerRangeStart.Value = Program.SlicerFile.InitialLayerCount - 1;
|
||||
nmLayerRangeEnd.Value = Program.SlicerFile.LayerCount - 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(sender, btnImportImageMask))
|
||||
{
|
||||
using (var fileOpen = new OpenFileDialog
|
||||
var matrixTextbox = new[]
|
||||
{
|
||||
CheckFileExists = true,
|
||||
Filter = "Image Files(*.PNG;*.BMP;*.JPEG;*.JPG;*.GIF)|*.PNG;*.BMP;*.JPEG;*.JPG;*.GIF"
|
||||
})
|
||||
{
|
||||
if (fileOpen.ShowDialog() != DialogResult.OK) return;
|
||||
new TexboxMatrix(tbEvenPattern),
|
||||
new TexboxMatrix(tbOddPattern),
|
||||
};
|
||||
|
||||
using (var image = CvInvoke.Imread(fileOpen.FileName, ImreadModes.Grayscale))
|
||||
|
||||
foreach (var item in matrixTextbox)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(item.Textbox.Text))
|
||||
{
|
||||
item.Pattern = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var row = 0; row < item.Textbox.Lines.Length; row++)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
|
||||
var bytes = item.Textbox.Lines[row].Trim().Split(' ');
|
||||
if (row == 0)
|
||||
{
|
||||
var span = image.GetPixelRowSpan<byte>(y);
|
||||
string line = string.Empty;
|
||||
for (int x = 0; x < span.Length; x++)
|
||||
item.Pattern = new Matrix<byte>(item.Textbox.Lines.Length, bytes.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Pattern.Cols != bytes.Length)
|
||||
{
|
||||
line += $"{span[x]} ";
|
||||
MessageBoxError($"Row {row + 1} have invalid number of pixels, the pattern must have equal pixel count per line, per defined on line 1");
|
||||
return false;
|
||||
}
|
||||
|
||||
line = line.Trim();
|
||||
sb.Append(line);
|
||||
|
||||
if(y < image.Height-1)
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
tbEvenPattern.Text = sb.ToString();
|
||||
tbOddPattern.Text = string.Empty;
|
||||
for (int col = 0; col < bytes.Length; col++)
|
||||
{
|
||||
if (byte.TryParse(bytes[col], out var value))
|
||||
{
|
||||
item.Pattern[row, col] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBoxError($"{bytes[col]} is a invalid number, use values from 0 to 255");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Operation.EvenPattern = matrixTextbox[0].Pattern;
|
||||
Operation.OddPattern = matrixTextbox[1].Pattern;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void EventClick(object sender, EventArgs e)
|
||||
{
|
||||
if (ReferenceEquals(sender, btnDimPatternSolid))
|
||||
{
|
||||
tbEvenPattern.Text = nmPixelDimBrightness.Value.ToString(CultureInfo.InvariantCulture);
|
||||
@@ -217,7 +124,7 @@ namespace UVtools.GUI.Forms
|
||||
|
||||
if (ReferenceEquals(sender, btnDimPatternSparse))
|
||||
{
|
||||
|
||||
|
||||
tbEvenPattern.Text = string.Format(
|
||||
"{0} 255 255 255{1}" +
|
||||
"255 255 {0} 255"
|
||||
@@ -298,7 +205,7 @@ namespace UVtools.GUI.Forms
|
||||
"255 255 {0} 255 {0} 255{1}" +
|
||||
"255 255 255 {0} 255 255{1}" +
|
||||
"255 255 255 255 255 255"
|
||||
|
||||
|
||||
, nmPixelDimBrightness.Value, Environment.NewLine);
|
||||
return;
|
||||
}
|
||||
@@ -377,13 +284,13 @@ namespace UVtools.GUI.Forms
|
||||
for (byte col = 0; col < size; col++)
|
||||
{
|
||||
//byte value = bytes[rnd.Next(0, bytes.Length)];
|
||||
byte value = (byte) rnd.Next(0, 2);
|
||||
byte value = (byte)rnd.Next(0, 2);
|
||||
text += value == 1 ? "255" : nmPixelDimBrightness.Value.ToString(CultureInfo.InvariantCulture);
|
||||
if (col < size-1)
|
||||
if (col < size - 1)
|
||||
text += " ";
|
||||
}
|
||||
|
||||
if (row < size-1) text += Environment.NewLine;
|
||||
if (row < size - 1) text += Environment.NewLine;
|
||||
}
|
||||
|
||||
tbEvenPattern.Text = text;
|
||||
@@ -393,7 +300,7 @@ namespace UVtools.GUI.Forms
|
||||
|
||||
if (ReferenceEquals(sender, btnInfillPatternRectilinear))
|
||||
{
|
||||
tbEvenPattern.Text = $"0{Environment.NewLine}".Repeat((int) nmInfillSpacing.Value) + $"255{Environment.NewLine}".Repeat((int)nmInfillSpacing.Value);
|
||||
tbEvenPattern.Text = $"0{Environment.NewLine}".Repeat((int)nmInfillSpacing.Value) + $"255{Environment.NewLine}".Repeat((int)nmInfillSpacing.Value);
|
||||
tbEvenPattern.Text = tbEvenPattern.Text.Trim('\n', '\r');
|
||||
|
||||
tbOddPattern.Text = string.Empty;
|
||||
@@ -407,7 +314,7 @@ namespace UVtools.GUI.Forms
|
||||
p1 += p1.Repeat((int)nmInfillThickness.Value);
|
||||
|
||||
|
||||
var p2 = "255 ".Repeat((int) nmInfillSpacing.Value) + "255 ".Repeat((int) nmInfillThickness.Value);
|
||||
var p2 = "255 ".Repeat((int)nmInfillSpacing.Value) + "255 ".Repeat((int)nmInfillThickness.Value);
|
||||
p2 = p2.Trim() + Environment.NewLine;
|
||||
p2 += p2.Repeat((int)nmInfillThickness.Value);
|
||||
|
||||
@@ -422,12 +329,12 @@ namespace UVtools.GUI.Forms
|
||||
{
|
||||
var p1 = string.Empty;
|
||||
var pos = 0;
|
||||
for (sbyte dir = 1; dir >= -1; dir-=2)
|
||||
for (sbyte dir = 1; dir >= -1; dir -= 2)
|
||||
{
|
||||
while (pos >= 0 && pos <= nmInfillSpacing.Value)
|
||||
{
|
||||
p1 += "0 ".Repeat(pos);
|
||||
p1 += "255 ".Repeat((int) nmInfillThickness.Value);
|
||||
p1 += "255 ".Repeat((int)nmInfillThickness.Value);
|
||||
p1 += "0 ".Repeat((int)nmInfillSpacing.Value - pos);
|
||||
p1 = p1.Trim() + Environment.NewLine;
|
||||
|
||||
@@ -441,105 +348,6 @@ namespace UVtools.GUI.Forms
|
||||
tbOddPattern.Text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(sender, btnMutate))
|
||||
{
|
||||
if (!btnMutate.Enabled) return;
|
||||
if (LayerRangeStart > LayerRangeEnd)
|
||||
{
|
||||
MessageBox.Show("Layer range start can't be higher than layer end.\nPlease fix and try again.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
nmLayerRangeStart.Select();
|
||||
return;
|
||||
}
|
||||
|
||||
if (BorderSize == 0 && DimsOnlyBorders)
|
||||
{
|
||||
MessageBox.Show("Border size must be positive in order to use \"Dims only the borders\" function.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var matrixTextbox = new[]
|
||||
{
|
||||
new MatrixTexbox(EvenPattern, tbEvenPattern),
|
||||
new MatrixTexbox(OddPattern, tbOddPattern),
|
||||
};
|
||||
|
||||
|
||||
foreach (var item in matrixTextbox)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(item.Textbox.Text))
|
||||
{
|
||||
item.Pattern = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var row = 0; row < item.Textbox.Lines.Length; row++)
|
||||
{
|
||||
|
||||
var bytes = item.Textbox.Lines[row].Trim().Split(' ');
|
||||
if (row == 0)
|
||||
{
|
||||
/*if (tbPattern.Lines.Length % 2 != 0 || bytes.Length % 2 != 0)
|
||||
{
|
||||
MessageBox.Show($"Rows and columns must be in even numbers", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}*/
|
||||
item.Pattern = new Matrix<byte>(item.Textbox.Lines.Length, bytes.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.Pattern.Cols != bytes.Length)
|
||||
{
|
||||
MessageBox.Show($"Row {row + 1} have invalid number of pixels, the pattern must have equal pixel count per line, per defined on line 1", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int col = 0; col < bytes.Length; col++)
|
||||
{
|
||||
if (byte.TryParse(bytes[col], out var value))
|
||||
{
|
||||
item.Pattern[row, col] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show($"{bytes[col]} is a invalid number, use values from 0 to 255", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EvenPattern = matrixTextbox[0].Pattern;
|
||||
OddPattern = matrixTextbox[1].Pattern;
|
||||
|
||||
|
||||
/*if (X == 100 && Y == 100)
|
||||
{
|
||||
MessageBox.Show($"X and Y cant be 100% together.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}*/
|
||||
|
||||
if (MessageBox.Show($"Are you sure you want to {Mutation.Mutate}?", Text, MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(sender, btnCancel))
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+10
-18
@@ -118,29 +118,21 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>148, 17</value>
|
||||
</metadata>
|
||||
<data name="lbX.ToolTip" xml:space="preserve">
|
||||
<value>Selects the number of iterations/passes to perform on each layer using this mutator.
|
||||
Enable the "Fade in/out" to fade the iteration over layers, you can use a start iteration higher than end to perform a inverse fade.
|
||||
WARNING: Using high iteration values can destroy your model depending on the mutator being used, please use low values or with caution!</value>
|
||||
</data>
|
||||
<data name="lbLayerRange.ToolTip" xml:space="preserve">
|
||||
<value>Selects the layers range within start layer and end layer where mutator will operate.
|
||||
Select same layer start as end to operate only within that layer.
|
||||
Note: "Layer Start" start can't be higher than "Layer End".</value>
|
||||
</data>
|
||||
<metadata name="cmLayerRange.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<data name="label1.ToolTip" xml:space="preserve">
|
||||
<value>Selects the number of iterations/passes to perform on each layer using this mutator.
|
||||
Enable the "Fade in/out" to fade the iteration over layers, you can use a start iteration higher than end to perform a inverse fade.
|
||||
WARNING: Using high iteration values can destroy your model depending on the mutator being used, please use low values or with caution!</value>
|
||||
</data>
|
||||
<data name="label6.ToolTip" xml:space="preserve">
|
||||
<value>Selects the layers range within start layer and end layer where mutator will operate.
|
||||
Select same layer start as end to operate only within that layer.
|
||||
Note: "Layer Start" start can't be higher than "Layer End".</value>
|
||||
</data>
|
||||
<data name="label1.ToolTip" xml:space="preserve">
|
||||
<value>Selects the number of iterations/passes to perform on each layer using this mutator.
|
||||
Enable the "Fade in/out" to fade the iteration over layers, you can use a start iteration higher than end to perform a inverse fade.
|
||||
WARNING: Using high iteration values can destroy your model depending on the mutator being used, please use low values or with caution!</value>
|
||||
</data>
|
||||
<data name="lbX.ToolTip" xml:space="preserve">
|
||||
<value>Selects the number of iterations/passes to perform on each layer using this mutator.
|
||||
Enable the "Fade in/out" to fade the iteration over layers, you can use a start iteration higher than end to perform a inverse fade.
|
||||
WARNING: Using high iteration values can destroy your model depending on the mutator being used, please use low values or with caution!</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -43,13 +43,14 @@ namespace UVtools.GUI.Controls.Tools
|
||||
ButtonOkEnabled = Operation.CanValidate();
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
Operation.X = nmX.Value;
|
||||
Operation.Y = nmY.Value;
|
||||
Operation.ConstrainXY = cbConstrainXY.Checked;
|
||||
Operation.IsFade = cbFade.Checked;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,11 @@ namespace UVtools.GUI.Controls.Tools
|
||||
SetOperation(Operation);
|
||||
}
|
||||
|
||||
public override void UpdateOperation()
|
||||
public override bool UpdateOperation()
|
||||
{
|
||||
base.UpdateOperation();
|
||||
Operation.AngleDegrees = nmDegrees.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void EventValueChanged(object sender, EventArgs e)
|
||||
|
||||
+14
-10
@@ -52,6 +52,7 @@ namespace UVtools.GUI
|
||||
new OperationMenuItem(new OperationSolidify(), Resources.square_solid_16x16),
|
||||
new OperationMenuItem(new OperationMorph(), Resources.Geometry_16x16),
|
||||
new OperationMenuItem(new OperationMask(), Resources.mask_16x16),
|
||||
new OperationMenuItem(new OperationPixelDimming(), Resources.pixel_16x16),
|
||||
new OperationMenuItem(new OperationChangeResolution(), Resources.resize_16x16),
|
||||
new OperationMenuItem(new OperationLayerReHeight(), Resources.ladder_16x16),
|
||||
new OperationMenuItem(new OperationPattern(), Resources.pattern_16x16)
|
||||
@@ -111,7 +112,7 @@ namespace UVtools.GUI
|
||||
"Mask"
|
||||
)
|
||||
},*/
|
||||
{
|
||||
/*{
|
||||
LayerManager.Mutate.PixelDimming, new Mutation(LayerManager.Mutate.PixelDimming, "Pixel Dimming",
|
||||
Resources.chessboard_16x16,
|
||||
"Dims pixels in a chosen pattern over white pixels neighborhood. The selected pattern will be repeated over the image width and height as a mask. Benefits are:\n" +
|
||||
@@ -121,7 +122,7 @@ namespace UVtools.GUI
|
||||
"NOTE: Run only this tool after all repairs and other transformations.",
|
||||
"Dim"
|
||||
)
|
||||
},
|
||||
},*/
|
||||
/*{
|
||||
LayerManager.Mutate.Erode, new Mutation(LayerManager.Mutate.Erode, null,
|
||||
Resources.compress_alt_16x16,
|
||||
@@ -3700,7 +3701,7 @@ namespace UVtools.GUI
|
||||
}
|
||||
|
||||
break;*/
|
||||
case LayerManager.Mutate.PixelDimming:
|
||||
/*case LayerManager.Mutate.PixelDimming:
|
||||
using (FrmMutationPixelDimming inputBox = new FrmMutationPixelDimming(Mutations[mutator]))
|
||||
{
|
||||
if (inputBox.ShowDialog() != DialogResult.OK) return;
|
||||
@@ -3711,9 +3712,9 @@ namespace UVtools.GUI
|
||||
evenPattern = inputBox.EvenPattern;
|
||||
oddPattern = inputBox.OddPattern;
|
||||
}
|
||||
|
||||
break;
|
||||
case LayerManager.Mutate.ThresholdPixels:
|
||||
|
||||
break;*/
|
||||
/*case LayerManager.Mutate.ThresholdPixels:
|
||||
using (FrmMutationThreshold inputBox = new FrmMutationThreshold(Mutations[mutator]))
|
||||
{
|
||||
if (inputBox.ShowDialog() != DialogResult.OK) return;
|
||||
@@ -3743,7 +3744,7 @@ namespace UVtools.GUI
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
break;*/
|
||||
}
|
||||
|
||||
DisableGUI();
|
||||
@@ -3783,10 +3784,10 @@ namespace UVtools.GUI
|
||||
SlicerFile.LayerManager.Mask(layerStart, layerEnd, mat, progress);
|
||||
mat?.Dispose();
|
||||
break;*/
|
||||
case LayerManager.Mutate.PixelDimming:
|
||||
SlicerFile.LayerManager.MutatePixelDimming(layerStart, layerEnd, evenPattern, oddPattern,
|
||||
/*case LayerManager.Mutate.PixelDimming:
|
||||
SlicerFile.LayerManager.PixelDimming(layerStart, layerEnd, evenPattern, oddPattern,
|
||||
(ushort) iterationsStart, fade, progress);
|
||||
break;
|
||||
break;*/
|
||||
/*case LayerManager.Mutate.Erode:
|
||||
SlicerFile.LayerManager.MutateErode(layerStart, layerEnd, (int) iterationsStart,
|
||||
(int) iterationsEnd, fade, progress, kernel, kernelAnchor);
|
||||
@@ -4519,6 +4520,9 @@ namespace UVtools.GUI
|
||||
case OperationMask operation:
|
||||
SlicerFile.LayerManager.Mask(operation, FrmLoading.RestartProgress());
|
||||
break;
|
||||
case OperationPixelDimming operation:
|
||||
SlicerFile.LayerManager.PixelDimming(operation, FrmLoading.RestartProgress());
|
||||
break;
|
||||
|
||||
case OperationChangeResolution operation:
|
||||
SlicerFile.LayerManager.ChangeResolution(operation, FrmLoading.RestartProgress(false));
|
||||
|
||||
@@ -170,6 +170,12 @@
|
||||
<Compile Include="Controls\SplitButton.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\Tools\CtrlToolPixelDimming.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Controls\Tools\CtrlToolPixelDimming.Designer.cs">
|
||||
<DependentUpon>CtrlToolPixelDimming.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Controls\Tools\CtrlToolMask.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
@@ -271,12 +277,6 @@
|
||||
<Compile Include="Forms\FrmMutationThreshold.Designer.cs">
|
||||
<DependentUpon>FrmMutationThreshold.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\FrmMutationPixelDimming.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forms\FrmMutationPixelDimming.Designer.cs">
|
||||
<DependentUpon>FrmMutationPixelDimming.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\FrmToolWindow.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -330,6 +330,9 @@
|
||||
<EmbeddedResource Include="Controls\CtrlToolWindowContent.resx">
|
||||
<DependentUpon>CtrlToolWindowContent.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Controls\Tools\CtrlToolPixelDimming.resx">
|
||||
<DependentUpon>CtrlToolPixelDimming.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Controls\Tools\CtrlToolMask.resx">
|
||||
<DependentUpon>CtrlToolMask.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@@ -381,9 +384,6 @@
|
||||
<EmbeddedResource Include="Forms\FrmMutationThreshold.resx">
|
||||
<DependentUpon>FrmMutationThreshold.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\FrmMutationPixelDimming.resx">
|
||||
<DependentUpon>FrmMutationPixelDimming.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Forms\FrmToolWindow.resx">
|
||||
<DependentUpon>FrmToolWindow.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
Reference in New Issue
Block a user