//Method mainly for the copy paste function, make a clone of the //poly that way when you change a point in one you don't change it for every //copied poly. public Polygon ClonePolygon(Polygon toClone) { var poly = new Polygon(); poly.Name = toClone.Name; foreach (PolyPoint child in toClone.Children) { var point = new PolyPoint(child.X, child.Y); poly.AddChild(point); } poly.Parent = toClone.Parent; return poly; }
public void ExecuteAutoTraceCommand(object o) { var dialog = new AutoTraceWindow(); dialog.ShowDialog(); var vm = dialog.DataContext as AutoTraceWindowVM; if (vm.IsOk) { using (var ms = new MemoryStream(Data)) { var imageBitmap = Image.FromStream(ms); var errorBuilder = new StringBuilder(); var shape = TraceService.CreateComplexShape(imageBitmap, 20000, errorBuilder, vm.HullTolerence, vm.AlphaTolerence, vm.MultipartDetection, vm.HoleDetection); if (shape != null) { var polygonGroup = new PolygonGroup("Body"); polygonGroup.Initialize(); var count = 1; foreach (var polygon in shape.Vertices) { var poly = new Polygon() { Name = "Polygon " + count }; foreach (var point in polygon) { poly.AddChild(new PolyPoint((int)point.X, (int)point.Y)); } polygonGroup.AddChild(poly); count++; } AddChild(polygonGroup); } ms.Close(); } } }
private static void AddDefaultFootBox(ImageFrame frame) { var footGroup = new PolygonGroup { Name = "Foot", Parent = frame }; footGroup.Initialize(); frame.AddChild(footGroup); var foot = new Polygon { Name = "Foot", Parent = footGroup }; var bottom = frame.TrimRectangle.Bottom - 1; var left = frame.TrimRectangle.Left; var right = frame.TrimRectangle.Right; var width = frame.TrimRectangle.Width; var tl = new PolyPoint(left + (int)(width * 0.25f), bottom - 2) { Parent = foot }; var tr = new PolyPoint(right - (int)(width * 0.25f), bottom - 2) { Parent = foot }; var br = new PolyPoint(right - (int)(width * 0.25f), bottom) { Parent = foot }; var bl = new PolyPoint(left + (int)(width * 0.25f), bottom) { Parent = foot }; foot.AddChild(tl); foot.AddChild(tr); foot.AddChild(br); foot.AddChild(bl); footGroup.AddChild(foot); }
private static void AddDefaultDepthBox(ImageFrame frame) { var depthGroup = new PolygonGroup { Name = "Depth", Parent = frame }; depthGroup.Initialize(); frame.AddChild(depthGroup); var depth = new Polygon { Name = "Depth", Parent = depthGroup }; var bottom = frame.TrimRectangle.Bottom - 1; var left = frame.TrimRectangle.Left; var right = frame.TrimRectangle.Right; var width = frame.TrimRectangle.Width; var defaultDepthPercentage = (int)(frame.TrimRectangle.Height * 0.125f); const float defaultWidthBorder = 0.9f; // 10% on each side = 80% var tl = new PolyPoint(left + (int)(width * defaultWidthBorder), bottom - defaultDepthPercentage) { Parent = depth }; var tr = new PolyPoint(right - (int)(width * defaultWidthBorder), bottom - defaultDepthPercentage) { Parent = depth }; var br = new PolyPoint(right - (int)(width * defaultWidthBorder), bottom) { Parent = depth }; var bl = new PolyPoint(left + (int)(width * defaultWidthBorder), bottom) { Parent = depth }; depth.AddChild(tl); depth.AddChild(tr); depth.AddChild(br); depth.AddChild(bl); depthGroup.AddChild(depth); }
private static void AddBodyTrace(ImageFrame frame) { using (var ms = new MemoryStream(frame.Data)) { var imageBitmap = Image.FromStream(ms); var errorBuilder = new StringBuilder(); var bodyGroup = new PolygonGroup { Name = "Body", Parent = frame }; bodyGroup.Initialize(); frame.AddChild(bodyGroup); var shape = TraceService.CreateSimpleShape(imageBitmap, 200, errorBuilder); if (shape == null) { frame.FailsAutoTrace = true; return; } var count = 1; foreach (var polygon in shape.Vertices) { var poly = new Polygon { Name = "Polygon " + count, Parent = bodyGroup }; foreach (var point in polygon) { var x = (int)ConvertUnits.ToDisplayUnits(point.X); var y = (int)ConvertUnits.ToDisplayUnits(point.Y); x += (int)(frame.Width * 0.5f); y += (int)(frame.Height * 0.5f); poly.AddChild(new PolyPoint(x, y) { Parent = poly }); } bodyGroup.AddChild(poly); count++; } } }
private static void TransformPolygon(NodeWithName @group, IEnumerable<Vector2> points, string name) { var poly = new Polygon {Name = name, Parent = @group}; foreach (var point in points) { var x = ConvertUnits.ToDisplayUnits(point.X); var y = ConvertUnits.ToDisplayUnits(point.Y); poly.AddChild(new PolyPoint((int) x, (int) y) {Parent = poly}); } @group.AddChild(poly); }