From 5574dfa2c660d3fa7b479ff6f1bf9a7f141f17e1 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 8 May 2016 21:38:27 -0700 Subject: [PATCH] Optimized out a bottleneck in CubistImageProcessor.cs --- .../Solids/Imported/CubistImageProcessor.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/OSCADSharp/OSCADSharp/Solids/Imported/CubistImageProcessor.cs b/OSCADSharp/OSCADSharp/Solids/Imported/CubistImageProcessor.cs index f466638..adddb07 100644 --- a/OSCADSharp/OSCADSharp/Solids/Imported/CubistImageProcessor.cs +++ b/OSCADSharp/OSCADSharp/Solids/Imported/CubistImageProcessor.cs @@ -14,6 +14,7 @@ namespace OSCADSharp.Solids.Imported internal class CubistImageProcessor : IImageProcessor { #region Private Fields + private int scannedRows = 0; private string imagePath; List cubes = new List(); #endregion @@ -34,17 +35,10 @@ namespace OSCADSharp.Solids.Imported return obj.Scale(1, -1, 1).Translate(0, ImageBounds.Width, 0); } - #region Private Methods private List processImage() { - Bitmap img = new Bitmap(Image.FromFile(this.imagePath)); - - if (img.Width > 200 || img.Height > 200) - { - throw new InvalidOperationException("Cannot process images larger greater than 200x200 pixels"); - } - + Bitmap img = new Bitmap(Image.FromFile(this.imagePath)); this.ImageBounds = new Bounds(new Vector3(), new Vector3(img.Width, img.Height, 1)); List cubes = new List(); @@ -157,17 +151,21 @@ namespace OSCADSharp.Solids.Imported } + + private Point? getNextPoint(Bitmap img, ref bool[,] visited, int width, int height) { - for (int column = 0; column < width; column++) + int rowStart = this.scannedRows; + for (int row = rowStart; row < height; row++) { - for (int row = 0; row < height; row++) + for (int column = 0; column < width; column++) { if (visited[column, row] == false) { return new Point(column, row); } } + this.scannedRows++; } return null;