Skip to content

Commit

Permalink
v3.8.2
Browse files Browse the repository at this point in the history
- **Dynamic lifts:**
  - (Improvement) Remove the 'light-off delay' set logic as it is now better integrated on 'Wait time before cure' suggestion and should run/applied there if intended
  - (Fix) Prevent set NaN values to lift height and/or speed
  - (Fix) Lift height and speed for the current layer must be calculated from previous layer (#618)
- (Improvement) Windows auto-updater will install the update without dialogs, just displaying installation progress
  • Loading branch information
sn4k3 committed Dec 11, 2022
1 parent d406bc8 commit 439e0d1
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 181 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 11/12/2022 - v3.9.2

- **Dynamic lifts:**
- (Improvement) Remove the 'light-off delay' set logic as it is now better integrated on 'Wait time before cure' suggestion and should run/applied there if intended
- (Fix) Prevent set NaN values to lift height and/or speed
- (Fix) Lift height and speed for the current layer must be calculated from previous layer (#618)
- (Improvement) Windows auto-updater will install the update without dialogs, just displaying installation progress

## 03/12/2022 - v3.9.1

- (Improvement) Performance on pixel editor when using high count of layers below and/or above
Expand Down
7 changes: 5 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- (Improvement) Performance on pixel editor when using high count of layers below and/or above
- (Fix) Unable to disable specific issues detection
- **Dynamic lifts:**
- (Improvement) Remove the 'light-off delay' set logic as it is now better integrated on 'Wait time before cure' suggestion and should run/applied there if intended
- (Fix) Prevent set NaN values to lift height and/or speed
- (Fix) Lift height and speed for the current layer must be calculated from previous layer (#618)
- (Improvement) Windows auto-updater will install the update without dialogs, just displaying installation progress

44 changes: 44 additions & 0 deletions UVtools.Core/Layers/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,26 @@ public RectangleF BoundingRectangleMillimeters
}
}

/// <summary>
/// Gets the first pixel index on this layer
/// </summary>
public uint FirstPixelIndex => (uint)(BoundingRectangle.Y * SlicerFile.ResolutionX + BoundingRectangle.X);

/// <summary>
/// Gets the last pixel index on this layer
/// </summary>
public uint LastPixelIndex => (uint)(BoundingRectangle.Bottom * SlicerFile.ResolutionX + BoundingRectangle.Right);

/// <summary>
/// Gets the first pixel <see cref="Point"/> on this layer
/// </summary>
public Point FirstPixelPosition => BoundingRectangle.Location;

/// <summary>
/// Gets the last pixel <see cref="Point"/> on this layer
/// </summary>
public Point LastPixelPosition => new (BoundingRectangle.Right, BoundingRectangle.Bottom);

/// <summary>
/// Gets if is the first layer
/// </summary>
Expand Down Expand Up @@ -245,6 +265,18 @@ public Layer? PreviousLayer
}
}

/// <summary>
/// Gets the previous layer if available, otherwise return the calling layer itself
/// </summary>
public Layer PreviousLayerOrThis
{
get
{
if (IsFirstLayer || _index > SlicerFile.Count) return this;
return SlicerFile[_index - 1];
}
}

/// <summary>
/// Gets the previous layer with a different height from the current, returns null if no previous layer
/// </summary>
Expand Down Expand Up @@ -288,6 +320,18 @@ public Layer? NextLayer
}
}

/// <summary>
/// Gets the next layer if available, otherwise return the calling layer itself
/// </summary>
public Layer NextLayerOrThis
{
get
{
if (_index >= SlicerFile.LastLayerIndex) return this;
return SlicerFile[_index + 1];
}
}

/// <summary>
/// Gets the next layer with a different height from the current, returns null if no next layer
/// </summary>
Expand Down
90 changes: 22 additions & 68 deletions UVtools.Core/Operations/OperationDynamicLifts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace UVtools.Core.Operations;
public sealed class OperationDynamicLifts : Operation
{
#region Enums

public enum DynamicLiftsSetMethod : byte
{
// Reduces maximal lift height with the number of pixels in layer divided by maximal number of pixels in any layer. Increases the minimal speed with the same ratio.
Expand All @@ -30,18 +29,6 @@ public enum DynamicLiftsSetMethod : byte
[Description("Full Range: Squeezes lift height and lift speed within full range of smallest/largest values")]
FullRange
}

public enum DynamicLiftsLightOffDelaySetMode : byte
{
[Description("Set the light-off with an extra delay")]
UpdateWithExtraDelay,

[Description("Set the light-off without an extra delay")]
UpdateWithoutExtraDelay,

[Description("Set the light-off to zero")]
SetToZero,
}
#endregion

#region Members
Expand All @@ -56,10 +43,6 @@ public enum DynamicLiftsLightOffDelaySetMode : byte
private float _slowestLiftSpeed;
private float _fastestLiftSpeed;

private float _lightOffDelayBottomExtraTime = 3;
private float _lightOffDelayExtraTime = 2.5f;
private DynamicLiftsLightOffDelaySetMode _lightOffDelaySetMode = DynamicLiftsLightOffDelaySetMode.UpdateWithExtraDelay;

#endregion

#region Overrides
Expand Down Expand Up @@ -135,7 +118,6 @@ public override string ToString()
$" [Bottom speed: {_slowestBottomLiftSpeed}/{_fastestBottomLiftSpeed}mm/min]" +
$" [Height: {_smallestLiftHeight}/{_largestLiftHeight}mm]" +
$" [Speed: {_slowestLiftSpeed}/{_fastestLiftSpeed}mm/min]" +
$" [Light-off: {_lightOffDelaySetMode} {_lightOffDelayBottomExtraTime}/{_lightOffDelayExtraTime}s]" +
LayerRangeString;
if (!string.IsNullOrEmpty(ProfileName)) result = $"{ProfileName}: {result}";
return result;
Expand Down Expand Up @@ -199,24 +181,6 @@ public float FastestLiftSpeed
set => RaiseAndSetIfChanged(ref _fastestLiftSpeed, (float)Math.Round(value, 2));
}

public DynamicLiftsLightOffDelaySetMode LightOffDelaySetMode
{
get => _lightOffDelaySetMode;
set => RaiseAndSetIfChanged(ref _lightOffDelaySetMode, value);
}

public float LightOffDelayBottomExtraTime
{
get => _lightOffDelayBottomExtraTime;
set => RaiseAndSetIfChanged(ref _lightOffDelayBottomExtraTime, (float)Math.Round(value, 2));
}

public float LightOffDelayExtraTime
{
get => _lightOffDelayExtraTime;
set => RaiseAndSetIfChanged(ref _lightOffDelayExtraTime, (float)Math.Round(value, 2));
}

//public uint MinBottomLayerPixels => SlicerFile.Where(layer => layer.IsBottomLayer && !layer.IsEmpty && layer.Index >= LayerIndexStart && layer.Index <= LayerIndexEnd).Max(layer => layer.NonZeroPixelCount);
public uint MinBottomLayerPixels => (from layer in SlicerFile
where layer.IsBottomLayer
Expand Down Expand Up @@ -271,7 +235,7 @@ public override void InitWithSlicerFile()
if (_slowestBottomLiftSpeed <= 0) _slowestBottomLiftSpeed = SlicerFile.BottomLiftSpeed;
if (_fastestBottomLiftSpeed <= 0 || _fastestBottomLiftSpeed < _slowestBottomLiftSpeed) _fastestBottomLiftSpeed = _slowestBottomLiftSpeed;

if(_slowestLiftSpeed <= 0) _slowestLiftSpeed = SlicerFile.LiftSpeed;
if (_slowestLiftSpeed <= 0) _slowestLiftSpeed = SlicerFile.LiftSpeed;
if (_fastestLiftSpeed <= 0 || _fastestLiftSpeed < _slowestLiftSpeed) _fastestLiftSpeed = _slowestLiftSpeed;
}

Expand Down Expand Up @@ -326,29 +290,32 @@ protected override bool ExecuteInternally(OperationProgress progress)
for (uint layerIndex = LayerIndexStart; layerIndex <= LayerIndexEnd; layerIndex++)
{
progress.ThrowIfCancellationRequested();
var layer = SlicerFile[layerIndex];

var calculateLayer = SlicerFile[layerIndex == 0 ? 0 : layerIndex - 1];
var setLayer = SlicerFile[layerIndex];


// Height
// min - largestpixelcount
// x - pixelcount

// Speed
// max - minpixelCount
// x - pixelcount

if (layer.IsBottomLayer)
if (setLayer.IsBottomLayer)
{
switch (_setMethod)
{
case DynamicLiftsSetMethod.Traditional:
liftHeight = (_largestBottomLiftHeight * layer.NonZeroPixelCount / maxBottomPixels).Clamp(_smallestBottomLiftHeight, _largestBottomLiftHeight);
liftSpeed = (_fastestBottomLiftSpeed - (_fastestBottomLiftSpeed * layer.NonZeroPixelCount / maxBottomPixels)).Clamp(_slowestBottomLiftSpeed, _fastestBottomLiftSpeed);
liftHeight = (_largestBottomLiftHeight * calculateLayer.NonZeroPixelCount / maxBottomPixels).Clamp(_smallestBottomLiftHeight, _largestBottomLiftHeight);
liftSpeed = (_fastestBottomLiftSpeed - (_fastestBottomLiftSpeed * calculateLayer.NonZeroPixelCount / maxBottomPixels)).Clamp(_slowestBottomLiftSpeed, _fastestBottomLiftSpeed);
break;
case DynamicLiftsSetMethod.FullRange:
var pixelRatio = (layer.NonZeroPixelCount - minBottomPixels) / (float)(maxBottomPixels - minBottomPixels); // pixel_ratio is between 0 and 1
var pixelRatio = (calculateLayer.NonZeroPixelCount - minBottomPixels) / (float)(maxBottomPixels - minBottomPixels); // pixel_ratio is between 0 and 1
liftHeight = (_smallestBottomLiftHeight + ((_largestBottomLiftHeight - _smallestBottomLiftHeight) * pixelRatio)).Clamp(_smallestBottomLiftHeight, _largestBottomLiftHeight);
liftSpeed = (_fastestBottomLiftSpeed - ((_fastestBottomLiftSpeed - _slowestBottomLiftSpeed) * pixelRatio)).Clamp(_slowestBottomLiftSpeed, _fastestBottomLiftSpeed);
break;
default:
throw new NotImplementedException(nameof(SetMethod));
}

}
Expand All @@ -357,36 +324,26 @@ protected override bool ExecuteInternally(OperationProgress progress)
switch (_setMethod)
{
case DynamicLiftsSetMethod.Traditional:
liftHeight = (_largestLiftHeight * layer.NonZeroPixelCount / maxNormalPixels).Clamp(_smallestLiftHeight, _largestLiftHeight);
liftSpeed = (_fastestLiftSpeed - (_fastestLiftSpeed * layer.NonZeroPixelCount / maxNormalPixels)).Clamp(_slowestLiftSpeed, _fastestLiftSpeed);
liftHeight = (_largestLiftHeight * calculateLayer.NonZeroPixelCount / maxNormalPixels).Clamp(_smallestLiftHeight, _largestLiftHeight);
liftSpeed = (_fastestLiftSpeed - (_fastestLiftSpeed * calculateLayer.NonZeroPixelCount / maxNormalPixels)).Clamp(_slowestLiftSpeed, _fastestLiftSpeed);
break;
case DynamicLiftsSetMethod.FullRange:
var pixelRatio = (layer.NonZeroPixelCount - minNormalPixels) / (float)(maxNormalPixels - minNormalPixels); // pixel_ratio is between 0 and 1
var pixelRatio = (calculateLayer.NonZeroPixelCount - minNormalPixels) / (float)(maxNormalPixels - minNormalPixels); // pixel_ratio is between 0 and 1
liftHeight = (_smallestLiftHeight + ((_largestLiftHeight - _smallestLiftHeight) * pixelRatio)).Clamp(_smallestLiftHeight, _largestLiftHeight);
liftSpeed = (_fastestLiftSpeed - ((_fastestLiftSpeed - _slowestLiftSpeed) * pixelRatio)).Clamp(_slowestLiftSpeed, _fastestLiftSpeed);
break;
default:
throw new NotImplementedException(nameof(SetMethod));
}
}

layer.RetractHeight2 = 0;
layer.LiftHeightTotal = (float) Math.Round(liftHeight, 1);
layer.LiftSpeed = (float) Math.Round(liftSpeed, 1);

switch (_lightOffDelaySetMode)
if (!float.IsNaN(liftHeight))
{
case DynamicLiftsLightOffDelaySetMode.UpdateWithExtraDelay:
layer.SetLightOffDelay(layer.IsBottomLayer ? _lightOffDelayBottomExtraTime : _lightOffDelayExtraTime);
break;
case DynamicLiftsLightOffDelaySetMode.UpdateWithoutExtraDelay:
layer.SetLightOffDelay();
break;
case DynamicLiftsLightOffDelaySetMode.SetToZero:
layer.LightOffDelay = 0;
break;
default:
throw new NotImplementedException();
setLayer.RetractHeight2 = 0;
setLayer.LiftHeightTotal = (float) Math.Round(liftHeight, 1);
if (!float.IsNaN(liftSpeed)) setLayer.LiftSpeed = (float)Math.Round(liftSpeed, 1);
}


progress++;
}
Expand All @@ -411,7 +368,7 @@ protected override bool ExecuteInternally(OperationProgress progress)

private bool Equals(OperationDynamicLifts other)
{
return _setMethod == other._setMethod && _smallestBottomLiftHeight.Equals(other._smallestBottomLiftHeight) && _largestBottomLiftHeight.Equals(other._largestBottomLiftHeight) && _smallestLiftHeight.Equals(other._smallestLiftHeight) && _largestLiftHeight.Equals(other._largestLiftHeight) && _slowestBottomLiftSpeed.Equals(other._slowestBottomLiftSpeed) && _fastestBottomLiftSpeed.Equals(other._fastestBottomLiftSpeed) && _slowestLiftSpeed.Equals(other._slowestLiftSpeed) && _fastestLiftSpeed.Equals(other._fastestLiftSpeed) && _lightOffDelayBottomExtraTime.Equals(other._lightOffDelayBottomExtraTime) && _lightOffDelayExtraTime.Equals(other._lightOffDelayExtraTime) && _lightOffDelaySetMode == other._lightOffDelaySetMode;
return _setMethod == other._setMethod && _smallestBottomLiftHeight.Equals(other._smallestBottomLiftHeight) && _largestBottomLiftHeight.Equals(other._largestBottomLiftHeight) && _smallestLiftHeight.Equals(other._smallestLiftHeight) && _largestLiftHeight.Equals(other._largestLiftHeight) && _slowestBottomLiftSpeed.Equals(other._slowestBottomLiftSpeed) && _fastestBottomLiftSpeed.Equals(other._fastestBottomLiftSpeed) && _slowestLiftSpeed.Equals(other._slowestLiftSpeed) && _fastestLiftSpeed.Equals(other._fastestLiftSpeed);
}

public override bool Equals(object? obj)
Expand All @@ -431,9 +388,6 @@ public override int GetHashCode()
hashCode.Add(_fastestBottomLiftSpeed);
hashCode.Add(_slowestLiftSpeed);
hashCode.Add(_fastestLiftSpeed);
hashCode.Add(_lightOffDelayBottomExtraTime);
hashCode.Add(_lightOffDelayExtraTime);
hashCode.Add((int)_lightOffDelaySetMode);
return hashCode.ToHashCode();
}

Expand Down
4 changes: 3 additions & 1 deletion UVtools.Core/Operations/OperationScripting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ public void ReloadScriptFromText(string? text = null)

ScriptGlobals = new ScriptGlobals { SlicerFile = SlicerFile, Operation = this };
_scriptState = CSharpScript.RunAsync(_scriptText,
ScriptOptions.Default.AddReferences(typeof(About).Assembly).WithAllowUnsafe(true),
ScriptOptions.Default
.AddReferences(typeof(About).Assembly)
.WithAllowUnsafe(true),
ScriptGlobals).Result;

var result = _scriptState.ContinueWithAsync("ScriptInit();").Result;
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 @@ -10,7 +10,7 @@
<RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl>
<PackageProjectUrl>https://github.com/sn4k3/UVtools</PackageProjectUrl>
<Description>MSLA/DLP, file analysis, calibration, repair, conversion and manipulation</Description>
<Version>3.9.1</Version>
<Version>3.9.2</Version>
<Copyright>Copyright © 2020 PTRTECH</Copyright>
<PackageIcon>UVtools.png</PackageIcon>
<Platforms>AnyCPU;x64</Platforms>
Expand Down
Loading

0 comments on commit 439e0d1

Please sign in to comment.