mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-25 20:08:28 +00:00
Added IImageProcessor, PolygonalImageProcessor
This commit is contained in:
parent
d951b5bea0
commit
3ea6f2cb08
@ -58,14 +58,16 @@ namespace OSCADSharp.ConsoleTests
|
|||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var img = ImportedImage.FromFile("seahawks coaster.png").Scale(1, 1, Inches.Quarter + Inches.Eigth);
|
var img = ImportedImage.FromFile("seahawks coaster.png").Scale(1, 1, Inches.Quarter + Inches.Eigth);
|
||||||
var imgPos = img.Position();
|
img.ToFile("testImg").Open();
|
||||||
var _base = new Cylinder(img.Bounds().Width + Inches.Quarter, Inches.Quarter);
|
|
||||||
|
|
||||||
var rim = _base.Clone().Scale(1, 1, 1.25) - _base.Clone().Scale(.9, .9, 3.5).Translate(0, 0, -Inches.Eigth);
|
//var imgPos = img.Position();
|
||||||
var coaster = img + _base.Translate(imgPos.X, imgPos.Y, 0) + rim.Translate(imgPos.X, imgPos.Y, Inches.Quarter); ;
|
//var _base = new Cylinder(img.Bounds().Width + Inches.Quarter, Inches.Quarter);
|
||||||
|
|
||||||
|
//var rim = _base.Clone().Scale(1, 1, 1.25) - _base.Clone().Scale(.9, .9, 3.5).Translate(0, 0, -Inches.Eigth);
|
||||||
|
//var coaster = img + _base.Translate(imgPos.X, imgPos.Y, 0) + rim.Translate(imgPos.X, imgPos.Y, Inches.Quarter); ;
|
||||||
|
|
||||||
|
|
||||||
coaster.ToFile("seaImg").Open();
|
//coaster.ToFile("seaImg").Open();
|
||||||
|
|
||||||
//makePeg();
|
//makePeg();
|
||||||
|
|
||||||
|
|||||||
@ -49,8 +49,11 @@
|
|||||||
<Compile Include="OSCADObject.BasicTransforms.cs" />
|
<Compile Include="OSCADObject.BasicTransforms.cs" />
|
||||||
<Compile Include="OSCADObject.Booleans.cs" />
|
<Compile Include="OSCADObject.Booleans.cs" />
|
||||||
<Compile Include="Solids\Imported\CubistImageProcessor.cs" />
|
<Compile Include="Solids\Imported\CubistImageProcessor.cs" />
|
||||||
|
<Compile Include="Solids\Imported\IImageProcessor.cs" />
|
||||||
|
<Compile Include="Solids\Imported\ImageImportMode.cs" />
|
||||||
<Compile Include="Solids\Imported\ImportedImage.cs" />
|
<Compile Include="Solids\Imported\ImportedImage.cs" />
|
||||||
<Compile Include="Solids\Imported\ImportedModel.cs" />
|
<Compile Include="Solids\Imported\ImportedModel.cs" />
|
||||||
|
<Compile Include="Solids\Imported\PolygonalImageProcessor.cs" />
|
||||||
<Compile Include="Utility\Dependencies.cs" />
|
<Compile Include="Utility\Dependencies.cs" />
|
||||||
<Compile Include="IO\DefaultFileInvoker.cs" />
|
<Compile Include="IO\DefaultFileInvoker.cs" />
|
||||||
<Compile Include="IO\DefaultFileWriter.cs" />
|
<Compile Include="IO\DefaultFileWriter.cs" />
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace OSCADSharp.Solids.Imported
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processes a bitmap image by treating contiguous same-color regions as cubes
|
/// Processes a bitmap image by treating contiguous same-color regions as cubes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class CubistImageProcessor
|
internal class CubistImageProcessor : IImageProcessor
|
||||||
{
|
{
|
||||||
#region Private Fields
|
#region Private Fields
|
||||||
private string imagePath;
|
private string imagePath;
|
||||||
@ -19,15 +19,15 @@ namespace OSCADSharp.Solids.Imported
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Internal Fields
|
#region Internal Fields
|
||||||
internal Bounds ImageBounds { get; set; }
|
public Bounds ImageBounds { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public CubistImageProcessor(string imagePath)
|
internal CubistImageProcessor(string imagePath)
|
||||||
{
|
{
|
||||||
this.imagePath = imagePath;
|
this.imagePath = imagePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal OSCADObject ProcessImage()
|
public OSCADObject ProcessImage()
|
||||||
{
|
{
|
||||||
this.cubes = this.processImage();
|
this.cubes = this.processImage();
|
||||||
OSCADObject obj = new OSCADObject.MultiStatementObject("union()", cubes);
|
OSCADObject obj = new OSCADObject.MultiStatementObject("union()", cubes);
|
||||||
@ -36,8 +36,9 @@ namespace OSCADSharp.Solids.Imported
|
|||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region Private Methods
|
||||||
private List<OSCADObject> processImage()
|
private List<OSCADObject> processImage()
|
||||||
{
|
{
|
||||||
Bitmap img = new Bitmap(Image.FromFile(this.imagePath));
|
Bitmap img = new Bitmap(Image.FromFile(this.imagePath));
|
||||||
@ -174,5 +175,8 @@ namespace OSCADSharp.Solids.Imported
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
OSCADSharp/OSCADSharp/Solids/Imported/IImageProcessor.cs
Normal file
15
OSCADSharp/OSCADSharp/Solids/Imported/IImageProcessor.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using OSCADSharp.Spatial;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OSCADSharp.Solids.Imported
|
||||||
|
{
|
||||||
|
internal interface IImageProcessor
|
||||||
|
{
|
||||||
|
OSCADObject ProcessImage();
|
||||||
|
Bounds ImageBounds { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
26
OSCADSharp/OSCADSharp/Solids/Imported/ImageImportMode.cs
Normal file
26
OSCADSharp/OSCADSharp/Solids/Imported/ImageImportMode.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OSCADSharp.Solids.Imported
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ways to process imported images into 3D models
|
||||||
|
/// </summary>
|
||||||
|
public enum ImageImportMode
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Cubist import mode subdivides the image into rectangular sections,
|
||||||
|
/// forming the bitmap from groupings of cubes representing its pixels
|
||||||
|
/// </summary>
|
||||||
|
Cubist,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Polygonal import model scans the image for sections that can be represented
|
||||||
|
/// by whole polygons for each contiguous area
|
||||||
|
/// </summary>
|
||||||
|
Polygonal
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -24,19 +24,30 @@ namespace OSCADSharp.Solids.Imported
|
|||||||
/// Creates an imported image from the specified file
|
/// Creates an imported image from the specified file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="imagePath"></param>
|
/// <param name="imagePath"></param>
|
||||||
|
/// <param name="mode"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ImportedImage FromFile(string imagePath)
|
public static ImportedImage FromFile(string imagePath, ImageImportMode mode = ImageImportMode.Cubist)
|
||||||
{
|
{
|
||||||
|
IImageProcessor processor;
|
||||||
|
if(mode == ImageImportMode.Cubist)
|
||||||
|
{
|
||||||
|
processor = new CubistImageProcessor(imagePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
processor = new PolygonalImageProcessor(imagePath);
|
||||||
|
}
|
||||||
|
|
||||||
var processor = new CubistImageProcessor(imagePath);
|
|
||||||
var obj = processor.ProcessImage();
|
var obj = processor.ProcessImage();
|
||||||
|
|
||||||
var img = new ImportedImage() {
|
var img = new ImportedImage()
|
||||||
|
{
|
||||||
m_Object = obj,
|
m_Object = obj,
|
||||||
m_Bounds = processor.ImageBounds
|
m_Bounds = processor.ImageBounds
|
||||||
};
|
};
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,76 @@
|
|||||||
|
using OSCADSharp.Spatial;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OSCADSharp.Solids.Imported
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Processes a bitmap image by treating contiguous same-color regions as cubes
|
||||||
|
/// </summary>
|
||||||
|
internal class PolygonalImageProcessor : IImageProcessor
|
||||||
|
{
|
||||||
|
#region Private Fields
|
||||||
|
private string imagePath;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Public Fields
|
||||||
|
public Bounds ImageBounds { get; set; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
internal PolygonalImageProcessor(string imagePath)
|
||||||
|
{
|
||||||
|
this.imagePath = imagePath;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public OSCADObject ProcessImage()
|
||||||
|
{
|
||||||
|
var polygons = this.processImage();
|
||||||
|
OSCADObject obj = new OSCADObject.MultiStatementObject("union()", polygons);
|
||||||
|
obj = obj.Rotate(0, 0, 180);
|
||||||
|
obj = obj.Translate(ImageBounds.Length, ImageBounds.Width, 0);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<OSCADObject> 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ImageBounds = new Bounds(new Vector3(), new Vector3(img.Width, img.Height, 1));
|
||||||
|
|
||||||
|
var separatedColors = this.separateColors(img);
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<string, List<KeyValuePair<Point, Color>>> separateColors(Bitmap img)
|
||||||
|
{
|
||||||
|
var colorGroupings = new Dictionary<string, List<KeyValuePair<Point, Color>>>();
|
||||||
|
for (int column = 0; column < img.Width; column++)
|
||||||
|
{
|
||||||
|
for (int row = 0; row < img.Height; row++)
|
||||||
|
{
|
||||||
|
var color = img.GetPixel(column, row);
|
||||||
|
if (!colorGroupings.ContainsKey(color.Name))
|
||||||
|
{
|
||||||
|
colorGroupings[color.Name] = new List<KeyValuePair<Point, Color>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
colorGroupings[color.Name].Add(new KeyValuePair<Point, Color>(new Point(column, row), color));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return colorGroupings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user