mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-14 06:58:34 +00:00
Added a HeightMappingMode enumeration and Bidirectional height mapping support.
This commit is contained in:
parent
adc38a9742
commit
18a93f8b93
@ -6,15 +6,35 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OSCADSharp.Solids.Imported
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Configuration options for processing imported images
|
||||
/// </summary>
|
||||
public class ImageImportOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines how height should be applied to imported images
|
||||
/// </summary>
|
||||
public enum HeightMappingMode
|
||||
{
|
||||
/// <summary>
|
||||
/// No height mapping at all
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// Extends texture upward with a flat base
|
||||
/// </summary>
|
||||
Vertical,
|
||||
/// <summary>
|
||||
/// Height is applied so both sides of the image are textured
|
||||
/// </summary>
|
||||
Bidirectional
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether height-mapping should be used
|
||||
/// </summary>
|
||||
public bool HeightMapping { get; set; } = true;
|
||||
public HeightMappingMode HeightMapping { get; set; } = HeightMappingMode.Vertical;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the colors in the image to black and white
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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<Color, int> heightMappings;
|
||||
List<OSCADObject> cubes = new List<OSCADObject>();
|
||||
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<Color, int>();
|
||||
double max = 4 * 256;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user