mirror of
https://github.com/eliasstepanik/OSCADSharpDotnet7.git
synced 2026-01-11 13:38:33 +00:00
In-Progress PolygonImageProcessor (finding neighbors now)
This commit is contained in:
parent
cdd04e9f95
commit
d40977fa4d
@ -57,9 +57,9 @@ namespace OSCADSharp.ConsoleTests
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var img = ImportedImage.FromFile("seahawks coaster.png").Scale(1, 1, Inches.Quarter + Inches.Eigth);
|
||||
var img = ImportedImage.FromFile("sample.png", ImageImportMode.Polygonal).Scale(1, 1, Inches.Quarter + Inches.Eigth);
|
||||
var imgPos = img.Position();
|
||||
var _base = new Cylinder(img.Bounds().Width + Inches.Quarter, Inches.Quarter);
|
||||
var _base = new Cylinder(img.Bounds().Width + Inches.Quarter, Inches.Quarter) { Resolution = 100 };
|
||||
|
||||
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); ;
|
||||
|
||||
@ -50,9 +50,85 @@ namespace OSCADSharp.Solids.Imported
|
||||
this.ImageBounds = new Bounds(new Vector3(), new Vector3(img.Width, img.Height, 1));
|
||||
|
||||
var separatedColors = this.separateColors(img);
|
||||
IEnumerable<List<KeyValuePair<Point, Color>>> contiguousSections = new List<List<KeyValuePair<Point, Color>>>();
|
||||
|
||||
foreach (var colorGroup in separatedColors.Values)
|
||||
{
|
||||
var sections = this.getContiguousSections(colorGroup);
|
||||
contiguousSections = contiguousSections.Concat(sections);
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private List<List<KeyValuePair<Point, Color>>> getContiguousSections(List<KeyValuePair<Point, Color>> colorGrouping)
|
||||
{
|
||||
KeyValuePair<Point, Color>[,] grid = createGrid(colorGrouping);
|
||||
var sections = new List<List<KeyValuePair<Point, Color>>>();
|
||||
|
||||
while (colorGrouping.Count > 0)
|
||||
{
|
||||
var origin = colorGrouping[0];
|
||||
colorGrouping.RemoveAt(0);
|
||||
sections.Add(this.getNeighbors(origin, grid, colorGrouping));
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
private List<KeyValuePair<Point, Color>> getNeighbors(KeyValuePair<Point, Color> origin, KeyValuePair<Point, Color>[,] grid, List<KeyValuePair<Point, Color>> colorGrouping)
|
||||
{
|
||||
List<KeyValuePair<Point, Color>> neighbors = new List<KeyValuePair<Point, Color>>();
|
||||
Queue<KeyValuePair<Point, Color>> nextOrigins = new Queue<KeyValuePair<Point, Color>>();
|
||||
nextOrigins.Enqueue(origin);
|
||||
|
||||
while(nextOrigins.Count > 0)
|
||||
{
|
||||
List<Point> neighboringPoints = new List<Point>() {
|
||||
new Point(origin.Key.X, origin.Key.Y + 1), //Above
|
||||
new Point(origin.Key.X, origin.Key.Y - 1), //Below
|
||||
new Point(origin.Key.X - 1, origin.Key.Y), //Left
|
||||
new Point(origin.Key.X + 1, origin.Key.Y), //Right
|
||||
new Point(origin.Key.X - 1, origin.Key.Y+1), //UpperLeft
|
||||
new Point(origin.Key.X + 1, origin.Key.Y + 1), //UpperRight
|
||||
new Point(origin.Key.X - 1, origin.Key.Y - 1), //LowerLeft
|
||||
new Point(origin.Key.X + 1, origin.Key.Y - 1), //LowerRight
|
||||
};
|
||||
|
||||
foreach (var pt in neighboringPoints)
|
||||
{
|
||||
//Todo: Find neighboring points
|
||||
}
|
||||
}
|
||||
|
||||
return neighbors;
|
||||
}
|
||||
|
||||
private static KeyValuePair<Point, Color>[,] createGrid(List<KeyValuePair<Point, Color>> colorGrouping)
|
||||
{
|
||||
Point topLeft = new Point(int.MaxValue, int.MaxValue);
|
||||
Point bottomRight = new Point(int.MinValue, int.MinValue);
|
||||
|
||||
|
||||
foreach (var pair in colorGrouping)
|
||||
{
|
||||
if (pair.Key.X < topLeft.X)
|
||||
topLeft.X = pair.Key.X;
|
||||
|
||||
if (pair.Key.Y < topLeft.Y)
|
||||
topLeft.Y = pair.Key.Y;
|
||||
|
||||
if (pair.Key.X > bottomRight.X)
|
||||
bottomRight.X = pair.Key.X;
|
||||
|
||||
if (pair.Key.Y > bottomRight.Y)
|
||||
bottomRight.Y = pair.Key.Y;
|
||||
}
|
||||
|
||||
int width = bottomRight.X - topLeft.X;
|
||||
int height = bottomRight.Y - topLeft.Y;
|
||||
return new KeyValuePair<Point, Color>[width, height];
|
||||
}
|
||||
|
||||
private Dictionary<string, List<KeyValuePair<Point, Color>>> separateColors(Bitmap img)
|
||||
{
|
||||
var colorGroupings = new Dictionary<string, List<KeyValuePair<Point, Color>>>();
|
||||
@ -61,12 +137,13 @@ namespace OSCADSharp.Solids.Imported
|
||||
for (int row = 0; row < img.Height; row++)
|
||||
{
|
||||
var color = img.GetPixel(column, row);
|
||||
if (!colorGroupings.ContainsKey(color.Name))
|
||||
string key = String.Format("{0}-{1}-{2}", color.R, color.G, color.B);
|
||||
if (!colorGroupings.ContainsKey(key))
|
||||
{
|
||||
colorGroupings[color.Name] = new List<KeyValuePair<Point, Color>>();
|
||||
colorGroupings[key] = new List<KeyValuePair<Point, Color>>();
|
||||
}
|
||||
|
||||
colorGroupings[color.Name].Add(new KeyValuePair<Point, Color>(new Point(column, row), color));
|
||||
colorGroupings[key].Add(new KeyValuePair<Point, Color>(new Point(column, row), color));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user