diff --git a/OSCADSharp/OSCADSharp/Solids/Imported/ImageImportOptions.cs b/OSCADSharp/OSCADSharp/Solids/Imported/ImageImportOptions.cs index 83f5357..bef6777 100644 --- a/OSCADSharp/OSCADSharp/Solids/Imported/ImageImportOptions.cs +++ b/OSCADSharp/OSCADSharp/Solids/Imported/ImageImportOptions.cs @@ -6,15 +6,35 @@ using System.Threading.Tasks; namespace OSCADSharp.Solids.Imported { + /// /// Configuration options for processing imported images /// public class ImageImportOptions { + /// + /// Determines how height should be applied to imported images + /// + public enum HeightMappingMode + { + /// + /// No height mapping at all + /// + None, + /// + /// Extends texture upward with a flat base + /// + Vertical, + /// + /// Height is applied so both sides of the image are textured + /// + Bidirectional + } + /// /// Indicates whether height-mapping should be used /// - public bool HeightMapping { get; set; } = true; + public HeightMappingMode HeightMapping { get; set; } = HeightMappingMode.Vertical; /// /// Converts the colors in the image to black and white diff --git a/OSCADSharp/OSCADSharp/Solids/Imported/ImportedImage.cs b/OSCADSharp/OSCADSharp/Solids/Imported/ImportedImage.cs index d13a0d0..ae09544 100644 --- a/OSCADSharp/OSCADSharp/Solids/Imported/ImportedImage.cs +++ b/OSCADSharp/OSCADSharp/Solids/Imported/ImportedImage.cs @@ -35,7 +35,11 @@ namespace OSCADSharp.Solids.Imported options = new ImageImportOptions(); } - processor = new CubistImageProcessor(imagePath, options.HeightMapping, options.UseGrayScale, options.SimplificationAmount); + processor = new CubistImageProcessor(imagePath, + Enum.GetName(typeof(ImageImportOptions.HeightMappingMode), options.HeightMapping), + options.UseGrayScale, + options.SimplificationAmount); + 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 11e47e1..edbd27e 100644 --- a/OSCADSharp/OSCADSharp/Utility/Images/CubistImageProcessor.cs +++ b/OSCADSharp/OSCADSharp/Utility/Images/CubistImageProcessor.cs @@ -17,7 +17,7 @@ namespace OSCADSharp.Utility.Images #region Private Fields private int scannedRows = 0; private string imagePath; - private bool includeHeight; + private string heightMode; private Dictionary heightMappings; List cubes = new List(); private Color[,] pixels; @@ -29,9 +29,9 @@ namespace OSCADSharp.Utility.Images public Bounds ImageBounds { get; set; } #endregion - internal CubistImageProcessor(string imagePath, bool includeHeight = true, bool useGrayScale = false, byte simplificationAmount = 0) + internal CubistImageProcessor(string imagePath, string heightMode = "None", bool useGrayScale = false, byte simplificationAmount = 0) { - this.includeHeight = includeHeight; + this.heightMode = heightMode; this.imagePath = imagePath; this.useGrayScale = useGrayScale; this.simplificationAmount = simplificationAmount; @@ -68,13 +68,13 @@ namespace OSCADSharp.Utility.Images if (color.A != 0) { - if (this.includeHeight) + if (this.heightMode != "None") { cube.Size.Z = heightMappings[color]; } string cubeColor = String.Format("[{0}, {1}, {2}]", color.R == 0 ? 0 : color.R / 255.0, color.G == 0 ? 0 : color.G / 255.0, color.B == 0 ? 0 : color.B / 255.0); - cubes.Add(cube.Translate(((Point)start).X, ((Point)start).Y, 0) + cubes.Add(cube.Translate(((Point)start).X, ((Point)start).Y, this.getZTranslationForHeightMode(cube.Size.Z)) .Color(cubeColor, color.A)); } } @@ -85,6 +85,18 @@ namespace OSCADSharp.Utility.Images return cubes; } + private double getZTranslationForHeightMode(double cubeHeight) + { + if(this.heightMode != "Bidirectional") + { + return 0; + } + else + { + return -cubeHeight / 2; + } + } + private void simplifyColors(Bitmap img) { var simplifier = new ImageSimplifier(img.Width, img.Height, pixels); @@ -119,7 +131,7 @@ namespace OSCADSharp.Utility.Images private void setHeightMappings(Bitmap img) { - if (this.includeHeight) + if (this.heightMode != "None") { this.heightMappings = new Dictionary(); double max = 4 * 256;