diff --git a/OSCADSharp/OSCADSharp/Solids/Imported/ImageImportOptions.cs b/OSCADSharp/OSCADSharp/Solids/Imported/ImageImportOptions.cs
index a87e1b6..97a8809 100644
--- a/OSCADSharp/OSCADSharp/Solids/Imported/ImageImportOptions.cs
+++ b/OSCADSharp/OSCADSharp/Solids/Imported/ImageImportOptions.cs
@@ -15,5 +15,10 @@ namespace OSCADSharp.Solids.Imported
/// Indicates whether height-mapping should be used
///
public bool HeightMapping { get; set; } = true;
+
+ ///
+ /// Converts the colors in the image to black and white
+ ///
+ public bool UseGrayScale { get; set; } = false;
}
}
diff --git a/OSCADSharp/OSCADSharp/Solids/Imported/ImportedImage.cs b/OSCADSharp/OSCADSharp/Solids/Imported/ImportedImage.cs
index 1ae7cfe..8302590 100644
--- a/OSCADSharp/OSCADSharp/Solids/Imported/ImportedImage.cs
+++ b/OSCADSharp/OSCADSharp/Solids/Imported/ImportedImage.cs
@@ -35,7 +35,7 @@ namespace OSCADSharp.Solids.Imported
options = new ImageImportOptions();
}
- processor = new CubistImageProcessor(imagePath, options.HeightMapping);
+ processor = new CubistImageProcessor(imagePath, options.HeightMapping, options.UseGrayScale);
var obj = processor.ProcessImage();
var img = new ImportedImage()
diff --git a/OSCADSharp/OSCADSharp/Utility/Images/CubistImageProcessor.cs b/OSCADSharp/OSCADSharp/Utility/Images/CubistImageProcessor.cs
index 7c984fd..dd2e968 100644
--- a/OSCADSharp/OSCADSharp/Utility/Images/CubistImageProcessor.cs
+++ b/OSCADSharp/OSCADSharp/Utility/Images/CubistImageProcessor.cs
@@ -21,16 +21,18 @@ namespace OSCADSharp.Utility.Images
private Dictionary heightMappings;
List cubes = new List();
private Color[,] pixels;
+ private bool useGrayScale;
#endregion
#region Internal Fields
public Bounds ImageBounds { get; set; }
#endregion
- internal CubistImageProcessor(string imagePath, bool includeHeight = true)
+ internal CubistImageProcessor(string imagePath, bool includeHeight = true, bool useGrayScale = false)
{
this.includeHeight = includeHeight;
this.imagePath = imagePath;
+ this.useGrayScale = useGrayScale;
}
public OSCADObject ProcessImage()
@@ -44,7 +46,7 @@ namespace OSCADSharp.Utility.Images
private List processImage()
{
Bitmap img = new Bitmap(Image.FromFile(this.imagePath));
- this.setPixelArray(img);
+ this.setColorArray(img);
this.setHeightMappings(img);
this.ImageBounds = new Bounds(new Vector3(), new Vector3(img.Width, img.Height, 1));
@@ -80,18 +82,32 @@ namespace OSCADSharp.Utility.Images
return cubes;
}
- private void setPixelArray(Bitmap img)
+ private void setColorArray(Bitmap img)
{
this.pixels = new Color[img.Width, img.Height];
for (int x = 0; x < img.Width; x++)
{
for (int y = 0; y < img.Height; y++)
{
- pixels[x, y] = img.GetPixel(x, y);
+ setPixelColorValue(img, x, y);
}
}
}
+ private void setPixelColorValue(Bitmap img, int x, int y)
+ {
+ if(this.useGrayScale)
+ {
+ Color rgbColor = img.GetPixel(x, y);
+ int grayscaleVal = (rgbColor.R + rgbColor.G + rgbColor.B) / 3;
+ pixels[x, y] = Color.FromArgb(rgbColor.A, grayscaleVal, grayscaleVal, grayscaleVal);
+ }
+ else
+ {
+ pixels[x, y] = img.GetPixel(x, y);
+ }
+ }
+
private void setHeightMappings(Bitmap img)
{
if (this.includeHeight)