Skip to content

Commit

Permalink
v4.2.4
Browse files Browse the repository at this point in the history
- **Setting - MaxDegreeOfParallelism:**
  - (Add) Value `-2`: Will utilize an optimal number in order to relief some load and therefore preventing the computer from lags and freezes, mostly this is the processor core count less a few. The more cores the CPU haves the larger is the margin up to a limit. (Optimal/Recommended)
  - (Add) Value `0`: Will utilize the processor core count. (Fast/Performance). Note that `0` is only equal to `Max` if you don't change your CPU or translate settings to other machine.
  - (Change) `!` preset will set the value as would the `-2` in the runtime. However it's recommended to use `-2` instead of the fixed positive number
  - (Change) Default value from `-1` to `-2` **(For current users is recommended to change to `-2`)**
- **Tool - Stir resin:**
  - (Add) Option to output a dummy pixel
  - (Add) Exposure time setting to allow to set the time of layer exposure
  - (Add) Informative text warning about the fact that each stir will increase in height due no ability to run layers in same Z position
  - (Add) Tooltips on the labels
  - (Improvement) Always allow the tool to run even if applied before
  - (Improvement) Do not allow to run the tool when stir number multiplied by layer height pass the set lift height when running on printers with no ability to run layers in same Z position
  - (Improvement) Instead of grey out incompatible fields, hide them and show the text (Incompatible with the current printer / file format)
- (Add) Benchmark tool: Allow to change thread count for the multi-thread test
  • Loading branch information
sn4k3 committed Mar 2, 2024
1 parent 5021e60 commit 4047b14
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 166 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## 02/03/2024 - v4.2.4

- **Setting - MaxDegreeOfParallelism:**
- (Add) Value `-2`: Will utilize an optimal number in order to relief some load and therefore preventing the computer from lags and freezes, mostly this is the processor core count less a few. The more cores the CPU haves the larger is the margin up to a limit. (Optimal/Recommended)
- (Add) Value `0`: Will utilize the processor core count. (Fast/Performance). Note that `0` is only equal to `Max` if you don't change your CPU or translate settings to other machine.
- (Change) `!` preset will set the value as would the `-2` in the runtime. However it's recommended to use `-2` instead of the fixed positive number
- (Change) Default value from `-1` to `-2` **(For current users is recommended to change to `-2`)**
- **Tool - Stir resin:**
- (Add) Option to output a dummy pixel
- (Add) Exposure time setting to allow to set the time of layer exposure
- (Add) Informative text warning about the fact that each stir will increase in height due no ability to run layers in same Z position
- (Add) Tooltips on the labels
- (Improvement) Always allow the tool to run even if applied before
- (Improvement) Do not allow to run the tool when stir number multiplied by layer height pass the set lift height when running on printers with no ability to run layers in same Z position
- (Improvement) Instead of grey out incompatible fields, hide them and show the text (Incompatible with the current printer / file format)
- (Add) Benchmark tool: Allow to change thread count for the multi-thread test

## 29/02/2024 - v4.2.3

- (Add) Benchmark test: GC Memory Copy and Pooled Memory Copy
Expand Down
3 changes: 2 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@
- Michael Pullen
- Albeck Károly
- Mark Johnston
- Ivan Ivanov
- Ivan Ivanov
- Simon Christ
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<!-- Enable Build Acceleration in Visual Studio. -->
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>

<UVtoolsVersion>4.2.3</UVtoolsVersion>
<UVtoolsVersion>4.2.4</UVtoolsVersion>
<AvaloniaVersion>11.0.7</AvaloniaVersion>
</PropertyGroup>

Expand Down
21 changes: 14 additions & 7 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
- (Add) Benchmark test: GC Memory Copy and Pooled Memory Copy
- (Add) Photon Mono M5s Pro (m5sp) support and corresponding PrusaSlicer printer (#842)
- (Add) Tool: Stir resin - Allow to stir the resin in the VAT by moving the build plate up and down multiple times (#839)
- (Improvement) Improve the dummy pixel location to match the first pixel of the layer (if possible)
- (Improvement) Better format for readable time from seconds, it now can show/hide days, hours, minutes and seconds when optimal
- (Improvement) The setting `MaxDegreeOfParallelism` is now used when calculating the batch size for the parallel operations under file decode and encode
- (Fix) Layer import: Unable to import layers from image files (#841)
- **Setting - MaxDegreeOfParallelism:**
- (Add) Value `-2`: Will utilize an optimal number in order to relief some load and therefore preventing the computer from lags and freezes, mostly this is the processor core count less a few. The more cores the CPU haves the larger is the margin up to a limit. (Optimal/Recommended)
- (Add) Value `0`: Will utilize the processor core count. (Fast/Performance). Note that `0` is only equal to `Max` if you don't change your CPU or translate settings to other machine.
- (Change) `!` preset will set the value as would the `-2` in the runtime. However it's recommended to use `-2` instead of the fixed positive number
- (Change) Default value from `-1` to `-2` **(For current users is recommended to change to `-2`)**
- **Tool - Stir resin:**
- (Add) Option to output a dummy pixel
- (Add) Exposure time setting to allow to set the time of layer exposure
- (Add) Informative text warning about the fact that each stir will increase in height due no ability to run layers in same Z position
- (Add) Tooltips on the labels
- (Improvement) Always allow the tool to run even if applied before
- (Improvement) Do not allow to run the tool when stir number multiplied by layer height pass the set lift height when running on printers with no ability to run layers in same Z position
- (Improvement) Instead of grey out incompatible fields, hide them and show the text (Incompatible with the current printer / file format)
- (Add) Benchmark tool: Allow to change thread count for the multi-thread test

38 changes: 35 additions & 3 deletions UVtools.Core/CoreSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,49 @@ public static CultureInfo OptimalCultureInfo
}
}

/// <summary>
/// Gets the optimal maximum degree of parallelism
/// </summary>
public static int OptimalMaxDegreeOfParallelism
{
get
{
var processorCount = Environment.ProcessorCount;
return processorCount switch
{
//>= 24 => processorCount - 6,
>= 20 => processorCount - 5,
>= 16 => processorCount - 4,
>= 12 => processorCount - 3,
>= 8 => processorCount - 2,
>= 4 => processorCount - 1,
_ => processorCount
};
}
}

/// <summary>
/// Gets or sets the maximum number of concurrent tasks enabled by this ParallelOptions instance.
/// Less or equal to 0 will set to auto number
/// -2 = Auto-optimal number
/// -1 = .NET scheduler
/// 0 = <see cref="Environment.ProcessorCount"/>
/// 1 = Single thread
/// n = Multi threads
/// </summary>
public static int MaxDegreeOfParallelism
{
get => _maxDegreeOfParallelism;
set => _maxDegreeOfParallelism = value > 0 ? Math.Min(value, Environment.ProcessorCount) : -1;
set
{
_maxDegreeOfParallelism = value switch
{
<= -2 => OptimalMaxDegreeOfParallelism, // Auto-optimal number
-1 => -1, // .NET scheduler
0 => Environment.ProcessorCount, // Max threads
_ => Math.Clamp(value, 1, Environment.ProcessorCount) // Custom number
};
}
}

/// <summary>
Expand Down Expand Up @@ -94,8 +127,7 @@ public static ParallelOptions GetParallelOptions(CancellationToken token = defau
/// Gets the ParallelOptions with <see cref="MaxDegreeOfParallelism"/> and the <see cref="CancellationToken"/> set
/// </summary>
public static ParallelOptions GetParallelOptions(OperationProgress progress) => GetParallelOptions(progress.Token);




/// <summary>
/// Gets or sets if operations run via CUDA when possible
Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/Layers/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public double NonZeroPixelPercentage
public bool IsEmpty => _nonZeroPixelCount == 0;

/// <summary>
/// Gets if this layer is a dummy layer to bypass a firmware constrain, that is contain at most one pixel and exposure time no more than 0.01s
/// Gets if this layer is a dummy layer to bypass a firmware constrain, that is contained at most one pixel and exposure time no more than 0.01s
/// </summary>
public bool IsDummy => _nonZeroPixelCount <= 1 || _exposureTime <= 0.01;

Expand Down
100 changes: 81 additions & 19 deletions UVtools.Core/Operations/OperationStirResin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
Expand All @@ -34,11 +36,14 @@ public enum StirMethod
#region Members
private StirMethod _method = StirMethod.StirOnly;
private ushort _stirs = 10;
private bool _outputDummyPixel = true;
private decimal _exposureTime;
private decimal _liftHeight = 45;
private decimal _liftSpeed;
private decimal _retractSpeed;
private decimal _waitTimeBeforeStir;
private decimal _waitTimeAfterLift;

#endregion

#region Overrides
Expand All @@ -63,7 +68,7 @@ public enum StirMethod

public override string ProgressAction => "Processed layers";

public override string? ValidateSpawn()
/*public override string? ValidateSpawn()
{
if (SlicerFile.Count >= 2 && SlicerFile[0].PositionZ == SlicerFile[1].PositionZ)
{
Expand All @@ -72,25 +77,39 @@ public enum StirMethod
}
return base.ValidateSpawn();
}
}*/

public override string? ValidateInternally()
{
var sb = new StringBuilder();

if (_stirs <= 0)
{
return "The number of stirs must be greater than 0.";
sb.AppendLine("The number of stirs must be greater than 0.");
}

if (!SlicerFile.CanUseSameLayerPositionZ)
{
var lastStirPosition = Layer.RoundHeight(_stirs * Layer.HeightPrecisionIncrementFloat);
if (lastStirPosition >= (float)_liftHeight)
{
var maxStirs = (int)(_liftHeight / Layer.HeightPrecisionIncrement - 1);
sb.AppendLine($"Your printer and/or file format does not support layers in same position, as so, each stir will increment in height by {Layer.HeightPrecisionIncrementFloat}mm.");
sb.AppendLine($"> Your current settings ({_stirs} stirs x {Layer.HeightPrecisionIncrementFloat}mm = {lastStirPosition}mm) is equal or greater than the defined lift height of {_liftHeight}mm.");
sb.AppendLine($"> As the lift height should be above resin level, all consequent stirs are useless.");
sb.AppendLine($"> Please lower your stir number up to {maxStirs} stirs to optimize the process and to be below the lift height.");
}
}

if (_method == StirMethod.StirAndPrint)
{
if (!SlicerFile.CanUseSameLayerPositionZ)
{
return $"Your printer and/or file format is not compatible with the method {_method}.\n" +
$"Please select another method.";
sb.AppendLine($"Your printer and/or file format is not compatible with the method {_method}. Please select another method.");
}
}

return null;
return sb.ToString();
}

public override string ToString()
Expand All @@ -110,6 +129,7 @@ public override string ToString()

public override void InitWithSlicerFile()
{
if (_exposureTime == 0) _exposureTime = SlicerFile.SupportGCode ? 0 : 0.01m;
if (_liftSpeed == 0) _liftSpeed = (decimal)SlicerFile.MaximumSpeed;
if (_retractSpeed == 0) _retractSpeed = _liftSpeed;
}
Expand Down Expand Up @@ -141,6 +161,29 @@ public ushort Stirs
}
}

/// <summary>
/// True to output a dummy pixel on bounding rectangle position to avoid empty layer and blank image, otherwise set to false
/// </summary>
public bool OutputDummyPixel
{
get => _outputDummyPixel;
set => RaiseAndSetIfChanged(ref _outputDummyPixel, value);
}

/// <summary>
/// Gets or sets the exposure time in seconds (Keep this to very low value)
/// </summary>
public decimal ExposureTime
{
get => _exposureTime;
set
{
if (!RaiseAndSetIfChanged(ref _exposureTime, Math.Round(Math.Max(0, value), 3))) return;
RaisePropertyChanged(nameof(StirSeconds));
RaisePropertyChanged(nameof(StirTimeString));
}
}

/// <summary>
/// Gets or sets the lift height in mm between stirs
/// </summary>
Expand All @@ -149,7 +192,7 @@ public decimal LiftHeight
get => _liftHeight;
set
{
if (!RaiseAndSetIfChanged(ref _liftHeight, value)) return;
if (!RaiseAndSetIfChanged(ref _liftHeight, Math.Round(Math.Max(0, value), 2))) return;
RaisePropertyChanged(nameof(StirSeconds));
RaisePropertyChanged(nameof(StirTimeString));
}
Expand All @@ -163,7 +206,7 @@ public decimal LiftSpeed
get => _liftSpeed;
set
{
if (!RaiseAndSetIfChanged(ref _liftSpeed, Math.Round(value, 2))) return;
if (!RaiseAndSetIfChanged(ref _liftSpeed, Math.Round(Math.Max(0, value), 2))) return;
RaisePropertyChanged(nameof(StirSeconds));
RaisePropertyChanged(nameof(StirTimeString));
}
Expand All @@ -177,7 +220,7 @@ public decimal RetractSpeed
get => _retractSpeed;
set
{
if (!RaiseAndSetIfChanged(ref _retractSpeed, Math.Round(value, 2))) return;
if (!RaiseAndSetIfChanged(ref _retractSpeed, Math.Round(Math.Max(0, value), 2))) return;
RaisePropertyChanged(nameof(StirSeconds));
RaisePropertyChanged(nameof(StirTimeString));
}
Expand All @@ -191,7 +234,7 @@ public decimal WaitTimeBeforeStir
get => _waitTimeBeforeStir;
set
{
if (!RaiseAndSetIfChanged(ref _waitTimeBeforeStir, Math.Round(value, 2))) return;
if (!RaiseAndSetIfChanged(ref _waitTimeBeforeStir, Math.Round(Math.Max(0, value), 2))) return;
RaisePropertyChanged(nameof(StirSeconds));
RaisePropertyChanged(nameof(StirTimeString));
}
Expand All @@ -205,7 +248,7 @@ public decimal WaitTimeAfterLift
get => _waitTimeAfterLift;
set
{
if (!RaiseAndSetIfChanged(ref _waitTimeAfterLift, Math.Round(value, 2))) return;
if (!RaiseAndSetIfChanged(ref _waitTimeAfterLift, Math.Round(Math.Max(0, value), 2))) return;
RaisePropertyChanged(nameof(StirSeconds));
RaisePropertyChanged(nameof(StirTimeString));
}
Expand All @@ -214,7 +257,7 @@ public decimal WaitTimeAfterLift
/// <summary>
/// Gets the total time in seconds to stir the resin
/// </summary>
public decimal StirSeconds => OperationCalculator.LightOffDelayC.CalculateSeconds(_liftHeight, _liftSpeed, _retractSpeed, _waitTimeBeforeStir + _waitTimeAfterLift) * _stirs;
public decimal StirSeconds => OperationCalculator.LightOffDelayC.CalculateSeconds(_liftHeight, _liftSpeed, _retractSpeed, _exposureTime + _waitTimeBeforeStir + _waitTimeAfterLift) * _stirs;

/// <summary>
/// Gets the total time in readable string to stir the resin
Expand All @@ -229,7 +272,7 @@ public bool Equals(OperationStirResin? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return _method == other._method && _stirs == other._stirs && _liftHeight == other._liftHeight && _liftSpeed == other._liftSpeed && _retractSpeed == other._retractSpeed && _waitTimeBeforeStir == other._waitTimeBeforeStir && _waitTimeAfterLift == other._waitTimeAfterLift;
return _method == other._method && _stirs == other._stirs && _outputDummyPixel == other._outputDummyPixel && _exposureTime == other._exposureTime && _liftHeight == other._liftHeight && _liftSpeed == other._liftSpeed && _retractSpeed == other._retractSpeed && _waitTimeBeforeStir == other._waitTimeBeforeStir && _waitTimeAfterLift == other._waitTimeAfterLift;
}

public override bool Equals(object? obj)
Expand Down Expand Up @@ -258,7 +301,7 @@ protected override bool ExecuteInternally(OperationProgress progress)
{
SlicerFile.SuppressRebuildPropertiesWork(() =>
{
using var mat = SlicerFile.CreateMatWithDummyPixelFromLayer(0);
using var mat = _outputDummyPixel ? SlicerFile.CreateMatWithDummyPixelFromLayer(0) : SlicerFile.CreateMat();
var layer = new Layer(mat, SlicerFile)
{
PositionZ = Layer.HeightPrecisionIncrementFloat,
Expand All @@ -268,12 +311,12 @@ protected override bool ExecuteInternally(OperationProgress progress)
WaitTimeAfterCure = 0,
WaitTimeAfterLift = (float)_waitTimeAfterLift,
LightPWM = SlicerFile.SupportGCode ? byte.MinValue : (byte)1,
ExposureTime = SlicerFile.BottomExposureTime = SlicerFile.SupportGCode ? 0 : 0.01f,
ExposureTime = (float)_exposureTime,
};
layer.SetWaitTimeBeforeCureOrLightOffDelay((float)_waitTimeBeforeStir);
var layers = layer.Clone(_stirs);
var stirLayers = layer.Clone(_stirs);
switch (_method)
{
Expand Down Expand Up @@ -301,10 +344,18 @@ protected override bool ExecuteInternally(OperationProgress progress)
SlicerFile.WaitTimeAfterLift = (float)_waitTimeAfterLift;
SlicerFile.LightPWM = SlicerFile.BottomLightPWM = SlicerFile.SupportGCode ? byte.MinValue : (byte)1;
SlicerFile.ExposureTime = SlicerFile.BottomExposureTime = SlicerFile.SupportGCode ? 0 : 0.01f;
SlicerFile.ExposureTime = (float)_exposureTime;
SlicerFile.Layers = layers;
if (!SlicerFile.CanUseSameLayerPositionZ)
{
// Fix positions
for (uint i = 1; i < stirLayers.Length; i++)
{
stirLayers[i].PositionZ = SlicerFile.CalculatePositionZ(i);
}
}
SlicerFile.Layers = stirLayers;
if (SlicerFile.ThumbnailsCount > 0)
{
Expand All @@ -328,7 +379,18 @@ protected override bool ExecuteInternally(OperationProgress progress)
}
case StirMethod.StirAndPrint:
{
SlicerFile.InsertRange(0, layers);
var layers = SlicerFile.ToList();
// Try to remove dummy layers, ie previous stir layers
for (int i = 0; i < layers.Count && layers[i].IsDummy; i++)
{
layers.RemoveAt(i);
i--;
}
layers.InsertRange(0, stirLayers);
SlicerFile.Layers = layers.ToArray();
break;
}
default:
Expand Down
2 changes: 1 addition & 1 deletion UVtools.Core/UVtools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<PackageReference Include="Emgu.CV.runtime.mini.windows" Version="4.8.1.5350" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.6" />
<PackageReference Include="KdTree" Version="1.4.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.9.2" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="System.Memory" Version="4.5.5" />
Expand Down
Loading

0 comments on commit 4047b14

Please sign in to comment.