Skip to content

Commit

Permalink
v0.8.2.4
Browse files Browse the repository at this point in the history
* (Add) Layer Importer: Option to merge images
* (Improvement) Layer difference computation time, faster render
  • Loading branch information
sn4k3 committed Sep 22, 2020
1 parent 732d27e commit 2f848af
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 100 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 22/09/2020 - v0.8.2.4

* (Add) Layer Importer: Option to merge images
* (Improvement) Layer difference computation time, faster render

## 19/09/2020 - v0.8.2.3

* (Add) Tooltip for next and previous layer buttons with associated shortcut (#61)
Expand Down
4 changes: 3 additions & 1 deletion UVtools.Core/FileFormats/FileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ public virtual uint LayerCount


public abstract float PrintTime { get; }


public float PrintTimeHours => (float) Math.Round(PrintTime / 3600, 2);

public abstract float UsedMaterial { get; }

public abstract float MaterialCost { get; }
Expand Down
5 changes: 5 additions & 0 deletions UVtools.Core/FileFormats/IFileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public interface IFileFormat
/// </summary>
float PrintTime { get; }

/// <summary>
/// Gets the estimate print time in hours
/// </summary>
float PrintTimeHours { get; }

/// <summary>
/// Gets the estimate used material in ml
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions UVtools.Core/Layer/LayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,16 @@ public void Import(OperationLayerImport operation, OperationProgress progress =
{
var mat = CvInvoke.Imread(operation.Files[i], ImreadModes.Grayscale);
uint layerIndex = (uint) (startIndex + i);
if (operation.MergeImages)
{
if (!(this[layerIndex] is null))
{
using (var oldMat = this[layerIndex].LayerMat)
{
CvInvoke.Add(oldMat, mat, mat);
}
}
}
this[layerIndex] = new Layer(layerIndex, mat);

lock (progress.Mutex)
Expand Down
1 change: 1 addition & 0 deletions UVtools.Core/Operations/OperationLayerImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public override StringTag Validate(params object[] parameters)
public bool ReplaceStartLayer { get; set; }
public bool ReplaceSubsequentLayers { get; set; }
public bool DiscardRemainingLayers { get; set; }
public bool MergeImages { get; set; }

public List<string> Files { get; } = new List<string>();

Expand Down
6 changes: 3 additions & 3 deletions UVtools.Core/UVtools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<RepositoryUrl>https://github.com/sn4k3/UVtools</RepositoryUrl>
<PackageProjectUrl>https://github.com/sn4k3/UVtools</PackageProjectUrl>
<Description>MSLA/DLP, file analysis, repair, conversion and manipulation</Description>
<Version>0.8.2.3</Version>
<Version>0.8.2.4</Version>
<Copyright>Copyright © 2020 PTRTECH</Copyright>
<PackageIcon>UVtools.png</PackageIcon>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyVersion>0.8.2.3</AssemblyVersion>
<FileVersion>0.8.2.3</FileVersion>
<AssemblyVersion>0.8.2.4</AssemblyVersion>
<FileVersion>0.8.2.4</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
18 changes: 17 additions & 1 deletion UVtools.GUI/Controls/Tools/CtrlToolLayerImport.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion UVtools.GUI/Controls/Tools/CtrlToolLayerImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public override bool UpdateOperation()
Operation.ReplaceStartLayer = cbReplaceStartLayer.Checked;
Operation.ReplaceSubsequentLayers = cbReplaceSubsequentLayers.Checked;
Operation.DiscardRemainingLayers = cbDiscardRemainingLayers.Checked;
Operation.MergeImages = cbMergeImages.Checked;
return true;
}

Expand Down Expand Up @@ -79,10 +80,12 @@ private void EventClick(object sender, EventArgs e)
{
if (ReferenceEquals(sender, cbReplaceSubsequentLayers))
{
cbDiscardRemainingLayers.Enabled = cbReplaceSubsequentLayers.Checked;
cbDiscardRemainingLayers.Enabled = cbDiscardRemainingLayers.Enabled = cbReplaceSubsequentLayers.Checked;
cbMergeImages.Enabled = cbReplaceSubsequentLayers.Checked;
if (!cbReplaceSubsequentLayers.Checked)
{
cbDiscardRemainingLayers.Checked = false;
cbMergeImages.Checked = false;
}
}

Expand Down
101 changes: 33 additions & 68 deletions UVtools.GUI/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ void ShowLayer(bool direction)
/// Shows a layer number
/// </summary>
/// <param name="layerNum">Layer number</param>
void ShowLayer(uint layerNum)
unsafe void ShowLayer(uint layerNum)
{
if (SlicerFile is null) return;

Expand Down Expand Up @@ -2316,8 +2316,10 @@ void ShowLayer(uint layerNum)

CvInvoke.CvtColor(ActualLayerImage, ActualLayerImageBgr, ColorConversion.Gray2Bgr);

var imageSpan = ActualLayerImage.GetPixelSpan<byte>();
var imageBgrSpan = ActualLayerImageBgr.GetPixelSpan<byte>();
//var imageSpan = ActualLayerImage.GetPixelSpan<byte>();
//var imageBgrSpan = ActualLayerImageBgr.GetPixelSpan<byte>();
var imageSpan = ActualLayerImage.GetBytePointer();
var imageBgrSpan = ActualLayerImageBgr.GetBytePointer();


if (btnLayerImageLayerOutlineEdgeDetection.Checked)
Expand All @@ -2332,71 +2334,30 @@ void ShowLayer(uint layerNum)
{
if (layerNum > 0 && layerNum < SlicerFile.LayerCount - 1)
{
using (var previousImage = SlicerFile[layerNum - 1].LayerMat)
using (var nextImage = SlicerFile[layerNum + 1].LayerMat)
Mat previousImage = null;
Mat nextImage = null;

// Can improve performance on >4K images?
Parallel.Invoke(
() => { previousImage = SlicerFile[ActualLayer - 1].LayerMat; },
() => { nextImage = SlicerFile[ActualLayer + 1].LayerMat; });

/*using (var previousImage = SlicerFile[_actualLayer - 1].LayerMat)
using (var nextImage = SlicerFile[_actualLayer + 1].LayerMat)
{*/
//var previousSpan = previousImage.GetPixelSpan<byte>();
//var nextSpan = nextImage.GetPixelSpan<byte>();

var previousSpan = previousImage.GetBytePointer();
var nextSpan = nextImage.GetBytePointer();

int width = ActualLayerImage.Width;
int channels = ActualLayerImageBgr.NumberOfChannels;
Parallel.For(0, ActualLayerImageBgr.Height, y =>
{
var previousSpan = previousImage.GetPixelSpan<byte>();
var nextSpan = nextImage.GetPixelSpan<byte>();

/*Parallel.For(0, imageSpan.Length, i =>
{
var currentByte = ActualLayerImage.GetSinglePixelSpan<byte>(i);
var previousByte = previousImage.GetSinglePixelSpan<byte>(i);
var nextByte = nextImage.GetSinglePixelSpan<byte>(i);
if (currentByte[0] != 0) return;
Color color = Color.Empty;
if (previousByte[0] > 0 && nextByte[0] > 0)
{
color = Settings.Default.PreviousNextLayerColor;
}
else if (previousByte[0] > 0)
{
color = Settings.Default.PreviousLayerColor;
}
else if (nextByte[0] > 0)
{
color = Settings.Default.NextLayerColor;
}
if (color.IsEmpty) return;
ActualLayerImageBgr.SetByte(i * 3, new[]{ color.B , color.G, color.R });
});*/

/*Parallel.For(0, ActualLayerImage.Height, y =>
{
var currentSpan = ActualLayerImage.GetPixelRowSpan<byte>(y);
var currentRGBSpan = ActualLayerImageBgr.GetPixelRowSpan<byte>(y);
var previousSpan = previousImage.GetPixelRowSpan<byte>(y);
var nextSpan = nextImage.GetPixelRowSpan<byte>(y);
for (int x = 0; x < currentSpan.Length; x++)
{
if (currentSpan[x] != 0) continue;
Color color = Color.Empty;
if (previousSpan[x] > 0 && nextSpan[x] > 0)
{
color = Settings.Default.PreviousNextLayerColor;
}
else if (previousSpan[x] > 0)
{
color = Settings.Default.PreviousLayerColor;
}
else if (nextSpan[x] > 0)
{
color = Settings.Default.NextLayerColor;
}
if (color.IsEmpty) continue;
var bgrPixel = x * 3;
currentRGBSpan[bgrPixel] = color.B; // B
currentRGBSpan[++bgrPixel] = color.G; // G
currentRGBSpan[++bgrPixel] = color.R; // R
}
});*/

for (int pixel = 0; pixel < imageSpan.Length; pixel++)
for (int x = 0; x < width; x++)
{
int pixel = y * width + x;
if (imageSpan[pixel] != 0) continue;
Color color = Color.Empty;
if (previousSpan[pixel] > 0 && nextSpan[pixel] > 0)
Expand All @@ -2413,12 +2374,16 @@ void ShowLayer(uint layerNum)
}

if (color.IsEmpty) continue;
var bgrPixel = pixel * 3;
var bgrPixel = pixel * channels;
imageBgrSpan[bgrPixel] = color.B; // B
imageBgrSpan[++bgrPixel] = color.G; // G
imageBgrSpan[++bgrPixel] = color.R; // R
//imageBgrSpan[++bgrPixel] = color.A; // A
}
}
});

previousImage.Dispose();
nextImage.Dispose();
}
}

Expand Down
4 changes: 2 additions & 2 deletions UVtools.GUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.8.2.3")]
[assembly: AssemblyFileVersion("0.8.2.3")]
[assembly: AssemblyVersion("0.8.2.4")]
[assembly: AssemblyFileVersion("0.8.2.4")]
4 changes: 4 additions & 0 deletions UVtools.GUI/UVtools.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -51,6 +52,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>UVtools.ico</ApplicationIcon>
Expand All @@ -67,6 +69,7 @@
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
Expand All @@ -77,6 +80,7 @@
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
Expand Down
Loading

0 comments on commit 2f848af

Please sign in to comment.