Skip to content

Commit

Permalink
v0.4.2
Browse files Browse the repository at this point in the history
* (Add) Zoom times information
* (Add) Island checker, navigation and removal
* (Add) Layer repair with island repair
* (Add) Show mouse coordinates over layer image
* (Fix) Pixel edit cant remove faded AA pixels
* (Fix) Pixel edit cant add white pixels over faded AA pixels
* (Change) Nova3D Elfin printer build volume from 130x70 to 132x74
  • Loading branch information
sn4k3 committed Jun 3, 2020
1 parent 15d9b3e commit 6a2939b
Show file tree
Hide file tree
Showing 31 changed files with 4,023 additions and 326 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 03/06/2020 - v0.4.2 - Beta

* (Add) Zoom times information
* (Add) Island checker, navigation and removal
* (Add) Layer repair with island repair
* (Add) Show mouse coordinates over layer image
* (Fix) Pixel edit cant remove faded AA pixels
* (Fix) Pixel edit cant add white pixels over faded AA pixels
* (Change) Nova3D Elfin printer build volume from 130x70 to 132x74

## 01/06/2020 - v0.4.1 - Beta

* (Add) Opening, Closing and Gradient Mutators
Expand Down
19 changes: 19 additions & 0 deletions CompileWindows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@echo off
SET DIR=%~dp0

REM if exist "%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" SET MSBUILD_PATH="%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" SET MSBUILD_PATH="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe"

IF [%MSBUILD_PATH%] == [] GOTO noMSBuild

echo PrusaSL1Viewer.sln Compile
echo %MSBUILD_PATH%
%MSBUILD_PATH% -p:Configuration=Release PrusaSL1Viewer.sln
GOTO end


:noMSBuild
echo MSBuild.exe path not found!

:end
pause
6 changes: 3 additions & 3 deletions PrusaSL1Reader/CWSFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public override void Encode(string fileFullPath)

for(uint layerIndex = 0; layerIndex < LayerCount; layerIndex++)
{
LayerManager.Layer layer = this[layerIndex];
Layer layer = this[layerIndex];
var layerimagePath = $"{Path.GetFileNameWithoutExtension(fileFullPath)}{layer.Index:D4}.png";
outputFile.PutFileContent(layerimagePath, layer.RawData);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ public override void Decode(string fileFullPath)
// - .png - 4 numbers
string layerStr = zipArchiveEntry.Name.Substring(zipArchiveEntry.Name.Length - 4 - 4, 4);
uint iLayer = uint.Parse(layerStr);
LayerManager[iLayer] = new LayerManager.Layer(iLayer, zipArchiveEntry.Open(), zipArchiveEntry.Name);
LayerManager[iLayer] = new Layer(iLayer, zipArchiveEntry.Open(), zipArchiveEntry.Name);
}

}
Expand Down Expand Up @@ -419,7 +419,7 @@ private void UpdateGCode()

for (uint layerIndex = 0; layerIndex < LayerCount; layerIndex++)
{
LayerManager.Layer layer = this[layerIndex];
Layer layer = this[layerIndex];
GCode.AppendLine($"{GCodeKeywordSlice} {layerIndex}");
GCode.AppendLine("M106 S255");
GCode.AppendLine($"{GCodeKeywordDelay} " + (layerIndex < InitialLayerCount ? SliceSettings.HeadLayersExpoMs : SliceSettings.LayersExpoMs));
Expand Down
52 changes: 26 additions & 26 deletions PrusaSL1Reader/ChituboxFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public override string ToString()
#endregion

#region Layer
public class Layer
public class LayerData
{
/// <summary>
/// Gets the build platform Z position for this layer, measured in millimeters.
Expand Down Expand Up @@ -468,9 +468,9 @@ public byte[] Read(byte[] input)

public Preview[] Previews { get; protected internal set; }

public Layer[,] LayersDefinitions { get; private set; }
public LayerData[,] LayersDefinitions { get; private set; }

public Dictionary<string, Layer> LayersHash { get; } = new Dictionary<string, Layer>();
public Dictionary<string, LayerData> LayersHash { get; } = new Dictionary<string, LayerData>();

public override FileFormatType FileType => FileFormatType.Binary;

Expand Down Expand Up @@ -584,7 +584,7 @@ public override void Encode(string fileFullPath)
}

uint currentOffset = (uint)Helpers.Serializer.SizeOf(HeaderSettings);
LayersDefinitions = new Layer[HeaderSettings.LayerCount, HeaderSettings.AntiAliasLevel];
LayersDefinitions = new LayerData[HeaderSettings.LayerCount, HeaderSettings.AntiAliasLevel];
using (var outputFile = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write))
{

Expand Down Expand Up @@ -712,11 +712,11 @@ void rleRGB15()
}

HeaderSettings.LayersDefinitionOffsetAddress = currentOffset;
uint layerDataCurrentOffset = currentOffset + (uint) Helpers.Serializer.SizeOf(new Layer()) * HeaderSettings.LayerCount * HeaderSettings.AntiAliasLevel;
uint layerDataCurrentOffset = currentOffset + (uint) Helpers.Serializer.SizeOf(new LayerData()) * HeaderSettings.LayerCount * HeaderSettings.AntiAliasLevel;
for (uint layerIndex = 0; layerIndex < LayerCount; layerIndex++)
{
Layer layer = new Layer();
Layer layerHash = null;
LayerData layerData = new LayerData();
LayerData layerDataHash = null;
var image = this[layerIndex].Image;
rawData = IsCbtFile ? EncodeCbtImage(image, layerIndex) : EncodeCbddlpImage(image);

Expand All @@ -725,23 +725,23 @@ void rleRGB15()
if (HeaderSettings.EncryptionKey == 0)
{
string hash = Helpers.ComputeSHA1Hash(byteArr);
if (!LayersHash.TryGetValue(hash, out layerHash))
if (!LayersHash.TryGetValue(hash, out layerDataHash))
{
LayersHash.Add(hash, layer);
LayersHash.Add(hash, layerData);
}
}

//layer.DataAddress = CurrentOffset + (uint)Helpers.Serializer.SizeOf(layer);
layer.DataAddress = layerHash?.DataAddress ?? layerDataCurrentOffset;
layer.DataSize = layerHash?.DataSize ?? (uint)byteArr.Length;
layer.LayerPositionZ = layerIndex * HeaderSettings.LayerHeightMilimeter;
layer.LayerOffTimeSeconds = layerIndex < HeaderSettings.BottomLayersCount ? PrintParametersSettings.BottomLightOffDelay : PrintParametersSettings.LightOffDelay;
layer.LayerExposure = layerIndex < HeaderSettings.BottomLayersCount ? HeaderSettings.BottomExposureSeconds : HeaderSettings.LayerExposureSeconds;
LayersDefinitions[layerIndex, 0] = layer;
layerData.DataAddress = layerDataHash?.DataAddress ?? layerDataCurrentOffset;
layerData.DataSize = layerDataHash?.DataSize ?? (uint)byteArr.Length;
layerData.LayerPositionZ = layerIndex * HeaderSettings.LayerHeightMilimeter;
layerData.LayerOffTimeSeconds = layerIndex < HeaderSettings.BottomLayersCount ? PrintParametersSettings.BottomLightOffDelay : PrintParametersSettings.LightOffDelay;
layerData.LayerExposure = layerIndex < HeaderSettings.BottomLayersCount ? HeaderSettings.BottomExposureSeconds : HeaderSettings.LayerExposureSeconds;
LayersDefinitions[layerIndex, 0] = layerData;

currentOffset += Helpers.SerializeWriteFileStream(outputFile, layer);
currentOffset += Helpers.SerializeWriteFileStream(outputFile, layerData);

if (!ReferenceEquals(layerHash, null)) continue;
if (!ReferenceEquals(layerDataHash, null)) continue;

outputFile.Seek(layerDataCurrentOffset, SeekOrigin.Begin);
layerDataCurrentOffset += Helpers.WriteFileStream(outputFile, byteArr);
Expand Down Expand Up @@ -988,7 +988,7 @@ public override void Decode(string fileFullPath)
Debug.WriteLine($"{nameof(MachineName)}: {MachineName}");*/
//}

LayersDefinitions = new Layer[HeaderSettings.LayerCount, HeaderSettings.AntiAliasLevel];
LayersDefinitions = new LayerData[HeaderSettings.LayerCount, HeaderSettings.AntiAliasLevel];

uint layerOffset = HeaderSettings.LayersDefinitionOffsetAddress;

Expand All @@ -999,24 +999,24 @@ public override void Decode(string fileFullPath)
for (uint layerIndex = 0; layerIndex < HeaderSettings.LayerCount; layerIndex++)
{
inputFile.Seek(layerOffset, SeekOrigin.Begin);
Layer layer = Helpers.Deserialize<Layer>(inputFile);
LayersDefinitions[layerIndex, aaIndex] = layer;
LayerData layerData = Helpers.Deserialize<LayerData>(inputFile);
LayersDefinitions[layerIndex, aaIndex] = layerData;

layerOffset += (uint)Helpers.Serializer.SizeOf(layer);
layerOffset += (uint)Helpers.Serializer.SizeOf(layerData);
Debug.Write($"LAYER {layerIndex} -> ");
Debug.WriteLine(layer);
Debug.WriteLine(layerData);

layer.EncodedRle = new byte[layer.DataSize];
inputFile.Seek(layer.DataAddress, SeekOrigin.Begin);
inputFile.Read(layer.EncodedRle, 0, (int)layer.DataSize);
layerData.EncodedRle = new byte[layerData.DataSize];
inputFile.Seek(layerData.DataAddress, SeekOrigin.Begin);
inputFile.Read(layerData.EncodedRle, 0, (int)layerData.DataSize);
}
}

LayerManager = new LayerManager(LayerCount);

Parallel.For(0, LayerCount, layerIndex => {
var image = IsCbtFile ? DecodeCbtImage((uint) layerIndex) : DecodeCbddlpImage((uint) layerIndex);
this[layerIndex] = new LayerManager.Layer((uint)layerIndex, image);
this[layerIndex] = new Layer((uint)layerIndex, image);
});

/*byte[,][] rleArr = new byte[LayerCount, HeaderSettings.AntiAliasLevel][];
Expand Down
20 changes: 11 additions & 9 deletions PrusaSL1Reader/FileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using PrusaSL1Reader.Extensions;
Expand All @@ -23,7 +25,7 @@ namespace PrusaSL1Reader
/// <summary>
/// Slicer <see cref="FileFormat"/> representation
/// </summary>
public abstract class FileFormat : IFileFormat, IDisposable, IEquatable<FileFormat>, IEnumerable<LayerManager.Layer>
public abstract class FileFormat : IFileFormat, IDisposable, IEquatable<FileFormat>, IEnumerable<Layer>
{
#region Enums

Expand Down Expand Up @@ -308,29 +310,29 @@ protected FileFormat()
#endregion

#region Indexers
public LayerManager.Layer this[int index]
public Layer this[int index]
{
get => LayerManager[index];
set => LayerManager[index] = value;
}

public LayerManager.Layer this[uint index]
public Layer this[uint index]
{
get => LayerManager[index];
set => LayerManager[index] = value;
}

public LayerManager.Layer this[long index]
public Layer this[long index]
{
get => LayerManager[index];
set => LayerManager[index] = value;
}
#endregion

#region Numerators
public IEnumerator<LayerManager.Layer> GetEnumerator()
public IEnumerator<Layer> GetEnumerator()
{
return ((IEnumerable<LayerManager.Layer>)LayerManager.Layers).GetEnumerator();
return ((IEnumerable<Layer>)LayerManager.Layers).GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
Expand Down Expand Up @@ -443,7 +445,7 @@ public void SetThumbnails(Image<Rgba32> image)
Thumbnails[i] = image.Clone();
}
}

public virtual void Encode(string fileFullPath)
{
if (File.Exists(fileFullPath))
Expand Down Expand Up @@ -567,9 +569,9 @@ public virtual void Extract(string path, bool genericConfigExtract = true, bool
}
}

public virtual float GetHeightFromLayer(uint layerNum)
public virtual float GetHeightFromLayer(uint layerIndex)
{
return (float)Math.Round(layerNum * LayerHeight, 2);
return (float)Math.Round((layerIndex+1) * LayerHeight, 2);
}

public virtual object GetValueFromPrintParameterModifier(PrintParameterModifier modifier)
Expand Down
5 changes: 5 additions & 0 deletions PrusaSL1Reader/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,10 @@ public static bool SetPropertyValue(PropertyInfo attribute, object obj, string v
throw new Exception($"Data type '{name}' not recognized, contact developer.");
}
}

public static uint CoordinatesToPixelIndex(uint x, uint y, uint width)
{
return y * width + x;
}
}
}
4 changes: 2 additions & 2 deletions PrusaSL1Reader/IFileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ public interface IFileFormat
/// <summary>
/// Get height in mm from layer height
/// </summary>
/// <param name="layerNum">The layer height</param>
/// <param name="layerIndex"></param>
/// <returns>The height in mm</returns>
float GetHeightFromLayer(uint layerNum);
float GetHeightFromLayer(uint layerIndex);

/// <summary>
/// Gets the value attributed to <see cref="FileFormat.PrintParameterModifier"/>
Expand Down
Loading

0 comments on commit 6a2939b

Please sign in to comment.