check point
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Align;
|
||||
|
||||
public class AlignElement:IGraphicsElement
|
||||
{
|
||||
public bool Editable { get; set; }
|
||||
public bool IsGood { get; set; }
|
||||
public Vector2 Location { get; set; }
|
||||
public void Draw(ICanvas canvas)
|
||||
{
|
||||
canvas.DrawCross(Location);
|
||||
}
|
||||
|
||||
public void FillMat(Mat mat)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public INode? GetNode(Vector2 position, float thDistance)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPivot(Vector2 pivot)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public void MovePivot(Vector2 pivot)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.ArrayHorizontal;
|
||||
|
||||
public class ArrayHorizontalAnchorNode:INode
|
||||
{
|
||||
private readonly ArrayHorizontalElement _parent;
|
||||
|
||||
public ArrayHorizontalAnchorNode(ArrayHorizontalElement parent)
|
||||
{
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 position)
|
||||
{
|
||||
_parent.Location = position - _parent.Offset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.ArrayHorizontal;
|
||||
|
||||
public class ArrayHorizontalElement:IGraphicsElement
|
||||
{
|
||||
public bool Editable { get; set; }
|
||||
|
||||
public Dictionary<int,bool> IsGood=new Dictionary<int, bool>();
|
||||
|
||||
public Vector2 Location { get; set; }
|
||||
public Vector2 Offset { get; set; }
|
||||
|
||||
|
||||
public Vector2 BlockSize { get; set; }
|
||||
public int Margin { get; set; } = 5;
|
||||
public int BlockCount { get; set; } = 5;
|
||||
|
||||
public void Draw(ICanvas canvas)
|
||||
{
|
||||
GenerateLocations().Select((l, i) => (l, i)).ToList().ForEach(((Vector2 l, int i) x) => canvas.DrawRectangle(x.l, BlockSize, IsGood.GetValueOrDefault(x.i,true)));
|
||||
canvas.DrawNode(Offset + Location);
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<Vector2> GenerateLocations()
|
||||
{
|
||||
for (int i = 0; i < BlockCount; i++)
|
||||
yield return Offset + Location + (new Vector2(1, 0) * i * (BlockSize.X + Margin));
|
||||
}
|
||||
|
||||
public void FillMat(Mat mat)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public INode? GetNode(Vector2 position, float thDistance)
|
||||
{
|
||||
if ((Location + Offset - position).Length() < thDistance)
|
||||
{
|
||||
return new ArrayHorizontalAnchorNode(this);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPivot(Vector2 pivot)
|
||||
{
|
||||
Location += Offset;
|
||||
Offset = pivot;
|
||||
Location -= Offset;
|
||||
}
|
||||
|
||||
public void MovePivot(Vector2 pivot)
|
||||
{
|
||||
Offset = pivot;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void Save(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(Editable);
|
||||
bw.Write(Location.X);
|
||||
bw.Write(Location.Y);
|
||||
bw.Write(Offset.X);
|
||||
bw.Write(Offset.Y);
|
||||
bw.Write(BlockSize.X);
|
||||
bw.Write(BlockSize.Y);
|
||||
bw.Write(BlockCount);
|
||||
|
||||
}
|
||||
|
||||
public void Load(BinaryReader br)
|
||||
{
|
||||
Editable = br.ReadBoolean();
|
||||
Location = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
Offset = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
BlockSize = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
BlockCount = br.ReadInt32();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Edge;
|
||||
|
||||
public class EdgeElement:IGraphicsElement
|
||||
{
|
||||
public bool Editable { get; set; }
|
||||
public bool IsGood { get; set; }
|
||||
public Vector2 Location { get; set; }
|
||||
public float Rotation { get; set; }
|
||||
public void Draw(ICanvas canvas)
|
||||
{
|
||||
float endX = Location.X + MathF.Cos(Rotation)*1000;
|
||||
float endY = Location.Y + MathF.Sin(Rotation) * 1000;
|
||||
float startX = Location.X - MathF.Cos(Rotation) * 1000;
|
||||
float startY = Location.Y - MathF.Sin(Rotation) * 1000;
|
||||
canvas.DrawLine(new Vector2(startX,startY), new Vector2(endX, endY), LineType.Construction);
|
||||
}
|
||||
|
||||
public void FillMat(Mat mat)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public INode? GetNode(Vector2 position, float thDistance)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetPivot(Vector2 pivot)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void MovePivot(Vector2 pivot)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Edge;
|
||||
|
||||
public struct EdgeOrigin
|
||||
{
|
||||
public Vector2 Location { get; set; }
|
||||
public float Rotation { get; set; }
|
||||
public bool Found { get; set; }
|
||||
public float endX => Location.X + MathF.Cos(Rotation) * 1000;
|
||||
public float endY => Location.Y + MathF.Sin(Rotation) * 1000;
|
||||
public float startX => Location.X - MathF.Cos(Rotation) * 1000;
|
||||
public float startY => Location.Y - MathF.Sin(Rotation) * 1000;
|
||||
public float Slope=>(endY-startY)/(endX-startX);
|
||||
public float YIntercept => startY - (Slope * startX);
|
||||
public bool Intersection(EdgeOrigin other, out float x, out float y)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
// Line 1
|
||||
Vector2 line1Start = new Vector2(startX, startY);
|
||||
|
||||
|
||||
// Line 2
|
||||
Vector2 line2Start = new Vector2(other.startX, other.startY);
|
||||
|
||||
|
||||
// Calculate the slopes of the lines
|
||||
double line1Slope = Slope;
|
||||
double line2Slope = other.Slope;
|
||||
|
||||
if (line1Slope == line2Slope) return false;
|
||||
|
||||
// Calculate the y-intercepts of the lines
|
||||
double line1Intercept = line1Start.Y - line1Slope * line1Start.X;
|
||||
double line2Intercept = line2Start.Y - line2Slope * line2Start.X;
|
||||
|
||||
// Calculate the intersection point
|
||||
double intersectionX = (line2Intercept - line1Intercept) / (line1Slope - line2Slope);
|
||||
double intersectionY = line1Slope * intersectionX + line1Intercept;
|
||||
|
||||
// Create the intersection point object
|
||||
x = (float)intersectionX;
|
||||
y = (float)intersectionY;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Location.ToString()} {Rotation} rad";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Rectangle;
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.FixedRectangle;
|
||||
|
||||
public class FixedRectangleAnchorNode:INode
|
||||
{
|
||||
private readonly FixedRectangleElement _owner;
|
||||
|
||||
public FixedRectangleAnchorNode(FixedRectangleElement owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 position)
|
||||
{
|
||||
|
||||
_owner.Location=position-_owner.Offset;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.FixedRectangle;
|
||||
|
||||
public class FixedRectangleElement : IGraphicsElement
|
||||
{
|
||||
public bool Editable { get; set; }
|
||||
public bool IsGood { get; set; }
|
||||
public Vector2 Location { get; set; }
|
||||
public Vector2 Offset { get; set; }
|
||||
public Vector2 Size { get; set; }
|
||||
|
||||
public void Draw(ICanvas canvas)
|
||||
{
|
||||
canvas.DrawRectangle(Offset + Location, Size, IsGood);
|
||||
canvas.DrawNode(Offset + Location);
|
||||
|
||||
}
|
||||
|
||||
public void FillMat(Mat mat)
|
||||
{
|
||||
var location = Offset + Location;
|
||||
Cv2.Rectangle(mat,
|
||||
new Rect((int)location.X, (int)location.Y, (int)Size.X,
|
||||
(int)Size.Y),
|
||||
Scalar.White, -1);
|
||||
}
|
||||
|
||||
public INode? GetNode(Vector2 position, float thDistance)
|
||||
{
|
||||
if ((Location + Offset - position).Length() < thDistance)
|
||||
{
|
||||
return new FixedRectangleAnchorNode(this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPivot(Vector2 pivot)
|
||||
{
|
||||
Location += Offset;
|
||||
Offset = pivot;
|
||||
Location -= Offset;
|
||||
}
|
||||
|
||||
public void MovePivot(Vector2 pivot)
|
||||
{
|
||||
Offset = pivot;
|
||||
}
|
||||
|
||||
public FixedRectangleElement()
|
||||
{
|
||||
Location = Vector2.Zero;
|
||||
Size = Vector2.Zero;
|
||||
Offset = Vector2.Zero;
|
||||
}
|
||||
}
|
||||
13
Hawkeye.VisionBuilder.Workflow/Datatypes/Elements/ICanvas.cs
Normal file
13
Hawkeye.VisionBuilder.Workflow/Datatypes/Elements/ICanvas.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements;
|
||||
|
||||
public interface ICanvas
|
||||
{
|
||||
void DrawRectangle(Vector2 start, Vector2 size, bool isGood);
|
||||
void DrawLine(Vector2 start, Vector2 end, LineType type);
|
||||
void DrawPoly(Vector2[] points, bool isGood);
|
||||
void DrawCross(Vector2 location);
|
||||
void DrawNode(Vector2 location);
|
||||
void DrawArrow(Vector2 location, Vector2 direction);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Parent;
|
||||
using Hawkeye.VisionBuilder.Workflow.Links;
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements;
|
||||
|
||||
public interface IGraphicsElement
|
||||
{
|
||||
|
||||
|
||||
|
||||
public bool Editable { get; set; }
|
||||
|
||||
public void Draw(ICanvas canvas);
|
||||
public void FillMat(Mat mat);
|
||||
public INode? GetNode(Vector2 position, float thDistance);
|
||||
public void SetPivot(Vector2 pivot);
|
||||
public void MovePivot(Vector2 pivot);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements;
|
||||
|
||||
public interface INode
|
||||
{
|
||||
public void SetPosition(Vector2 position);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Line;
|
||||
|
||||
public class LineElement:IGraphicsElement
|
||||
{
|
||||
public bool Editable { get; set; }
|
||||
public bool IsGood { get; set; }
|
||||
|
||||
public Vector2 Start { get; set; }
|
||||
public Vector2 End { get; set; }
|
||||
|
||||
public void Draw(ICanvas canvas)
|
||||
{
|
||||
canvas.DrawLine(Start, End,LineType.Construction);
|
||||
}
|
||||
|
||||
public void FillMat(Mat mat)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public INode? GetNode(Vector2 position, float thDistance)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPivot(Vector2 pivot)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void MovePivot(Vector2 pivot)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements;
|
||||
|
||||
public enum LineType
|
||||
{
|
||||
Good,
|
||||
Bad,
|
||||
Construction
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Parent;
|
||||
using Hawkeye.VisionBuilder.Workflow.Links;
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Origin;
|
||||
|
||||
public class OriginElement
|
||||
{
|
||||
private static readonly OriginElement _default = new OriginElement();
|
||||
private Vector2 _location;
|
||||
|
||||
public static OriginElement Default => _default;
|
||||
|
||||
public Vector2 Location
|
||||
{
|
||||
get => _location;
|
||||
set => _location = value;
|
||||
}
|
||||
|
||||
|
||||
public OriginElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Parent;
|
||||
|
||||
public interface IHaveParentCoordinates
|
||||
{
|
||||
public Vector2 Location { get; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Parent;
|
||||
|
||||
public class NoParentCoordinates:IHaveParentCoordinates
|
||||
{
|
||||
private NoParentCoordinates()
|
||||
{
|
||||
}
|
||||
|
||||
public static NoParentCoordinates Instance { get; }=new NoParentCoordinates();
|
||||
public Vector2 Location { get; set; }=Vector2.Zero;
|
||||
public float Rotation { get; set; } = 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Parent;
|
||||
using Hawkeye.VisionBuilder.Workflow.Links;
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Poly;
|
||||
|
||||
public class PolyElement : IGraphicsElement
|
||||
{
|
||||
|
||||
public IGraphicsElement Parent { get; set; }
|
||||
public Vector2 Location { get; set; }
|
||||
public bool Editable { get; set; }
|
||||
public bool IsGood { get; set; }
|
||||
|
||||
public void Draw(ICanvas canvas)
|
||||
{
|
||||
canvas.DrawPoly(Points, IsGood);
|
||||
}
|
||||
|
||||
public void FillMat(Mat mat)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public INode? GetNode(Vector2 position, float thDistance)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPivot(Vector2 pivot)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void MovePivot(Vector2 pivot)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Vector2[] Points { get; set; } = Array.Empty<Vector2>();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Rectangle;
|
||||
|
||||
public class RectangleAnchorNode:INode
|
||||
{
|
||||
private readonly RectangleElement _owner;
|
||||
|
||||
public RectangleAnchorNode(RectangleElement owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 position)
|
||||
{
|
||||
|
||||
_owner.Location=position-_owner.Offset;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Xml;
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Origin;
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Parent;
|
||||
using Hawkeye.VisionBuilder.Workflow.Links;
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Rectangle;
|
||||
|
||||
public class RectangleElement : IGraphicsElement
|
||||
{
|
||||
|
||||
public bool Editable { get; set; }
|
||||
public bool IsGood { get; set; }
|
||||
|
||||
public Vector2 Location { get; set; }
|
||||
public Vector2 Offset { get; set; }
|
||||
|
||||
public Vector2 Size { get; set; }
|
||||
|
||||
public void Draw(ICanvas canvas)
|
||||
{
|
||||
|
||||
canvas.DrawRectangle(Offset+Location, Size,IsGood);
|
||||
canvas.DrawNode(Offset+Location);
|
||||
canvas.DrawNode(Offset+Location + Size);
|
||||
|
||||
}
|
||||
|
||||
public void FillMat(Mat mat)
|
||||
{
|
||||
var location = Offset + Location;
|
||||
Cv2.Rectangle(mat,
|
||||
new Rect((int)location.X, (int)location.Y, (int)Size.X,
|
||||
(int)Size.Y),
|
||||
Scalar.White, -1);
|
||||
}
|
||||
|
||||
|
||||
public INode? GetNode(Vector2 position,float thDistance)
|
||||
{
|
||||
if ((Location + Offset - position).Length()< thDistance)
|
||||
{
|
||||
return new RectangleAnchorNode(this);
|
||||
}
|
||||
if((Size + Location+Offset - position).Length() < thDistance)
|
||||
{
|
||||
return new RectangleSizeNode(this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPivot(Vector2 pivot)
|
||||
{
|
||||
Location += Offset;
|
||||
Offset =pivot;
|
||||
Location-=Offset;
|
||||
}
|
||||
|
||||
public void MovePivot(Vector2 pivot)
|
||||
{
|
||||
Offset = pivot;
|
||||
}
|
||||
|
||||
public RectangleElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void Save(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(Editable);
|
||||
bw.Write(IsGood);
|
||||
bw.Write(Location.X);
|
||||
bw.Write(Location.Y);
|
||||
bw.Write(Offset.X);
|
||||
bw.Write(Offset.Y);
|
||||
bw.Write(Size.X);
|
||||
bw.Write(Size.Y);
|
||||
}
|
||||
|
||||
public void Load(BinaryReader br)
|
||||
{
|
||||
Editable = br.ReadBoolean();
|
||||
IsGood = br.ReadBoolean();
|
||||
Location = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
Offset = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
Size = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
}
|
||||
|
||||
public void SaveXML(XmlWriter writer)
|
||||
{
|
||||
writer.WriteStartElement("Editable");
|
||||
writer.WriteString(Editable.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("IsGood");
|
||||
writer.WriteString(IsGood.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("LocationX");
|
||||
writer.WriteString(Location.X.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("LocationY");
|
||||
writer.WriteString(Location.Y.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("OffsetX");
|
||||
writer.WriteString(Offset.X.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("OffsetY");
|
||||
writer.WriteString(Offset.Y.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("SizeX");
|
||||
writer.WriteString(Size.X.ToString());
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteStartElement("SizeY");
|
||||
writer.WriteString(Size.Y.ToString());
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
public void LoadXML(XmlReader reader)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Editable")
|
||||
{
|
||||
Editable = bool.Parse(reader.ReadElementContentAsString());
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "IsGood")
|
||||
{
|
||||
IsGood = bool.Parse(reader.ReadElementContentAsString());
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "LocationX")
|
||||
{
|
||||
var x = float.Parse(reader.ReadElementContentAsString());
|
||||
Location = new Vector2(x, Location.Y);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "LocationY")
|
||||
{
|
||||
var y = float.Parse(reader.ReadElementContentAsString());
|
||||
Location = new Vector2(Location.X, y);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "OffsetX")
|
||||
{
|
||||
var x = float.Parse(reader.ReadElementContentAsString());
|
||||
Offset = new Vector2(x, Offset.Y);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "OffsetY")
|
||||
{
|
||||
var y = float.Parse(reader.ReadElementContentAsString());
|
||||
Offset = new Vector2(Offset.X, y);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "SizeX")
|
||||
{
|
||||
var x = float.Parse(reader.ReadElementContentAsString());
|
||||
Size = new Vector2(x, Size.Y);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "SizeY")
|
||||
{
|
||||
var y = float.Parse(reader.ReadElementContentAsString());
|
||||
Size = new Vector2(Size.X, y);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "RectangleElement")
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Rectangle;
|
||||
|
||||
public class RectangleSizeNode:INode
|
||||
{
|
||||
private readonly RectangleElement _owner;
|
||||
|
||||
public RectangleSizeNode(RectangleElement owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 position)
|
||||
{
|
||||
_owner.Size=position-_owner.Location - _owner.Offset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.RotatedRectangle;
|
||||
|
||||
public class RotatedRectangleAnchorNode:INode
|
||||
{
|
||||
private readonly RotatedRectangleElement _owner;
|
||||
|
||||
public RotatedRectangleAnchorNode(RotatedRectangleElement owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 position)
|
||||
{
|
||||
|
||||
_owner.Location=position-_owner.Offset;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.Rectangle;
|
||||
|
||||
using OpenCvSharp;
|
||||
using Point = OpenCvSharp.Point;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.RotatedRectangle;
|
||||
|
||||
public class RotatedRectangleElement:IGraphicsElement
|
||||
{
|
||||
public bool Editable { get; set; }
|
||||
public bool IsGood { get; set; }
|
||||
|
||||
public Vector2 Location { get; set; }
|
||||
public Vector2 Offset { get; set; }
|
||||
|
||||
public Vector2 Height { get; set; }
|
||||
public float HalfWidth { get; set; }
|
||||
|
||||
|
||||
public void Draw(ICanvas canvas)
|
||||
{
|
||||
var type = IsGood ? LineType.Good : LineType.Bad;
|
||||
var perpendicular = new Vector2(Height.Y, -Height.X);
|
||||
perpendicular.Normalize();
|
||||
|
||||
canvas.DrawLine(Offset + Location - perpendicular * HalfWidth, Offset + Location+perpendicular*HalfWidth, type);
|
||||
canvas.DrawLine(Offset + Location + Height - perpendicular * HalfWidth, Offset + Location + Height + perpendicular * HalfWidth, type);
|
||||
canvas.DrawLine(
|
||||
Offset + Location + perpendicular * HalfWidth
|
||||
, Offset + Location + Height + perpendicular * HalfWidth
|
||||
, type);
|
||||
canvas.DrawLine(
|
||||
Offset + Location - perpendicular * HalfWidth
|
||||
, Offset + Location + Height - perpendicular * HalfWidth
|
||||
, type);
|
||||
canvas.DrawNode(Offset + Location);
|
||||
canvas.DrawNode(Offset + Location + Height);
|
||||
canvas.DrawNode(Offset + Location + Height + perpendicular * HalfWidth);
|
||||
|
||||
canvas.DrawArrow(Offset + Location, Height);
|
||||
|
||||
}
|
||||
|
||||
public void FillMat(Mat mat)
|
||||
{
|
||||
var perpendicular = new Vector2(Height.Y, -Height.X);
|
||||
perpendicular.Normalize();
|
||||
var p1 = Offset + Location - perpendicular * HalfWidth;
|
||||
var p2 = Offset + Location + perpendicular * HalfWidth;
|
||||
var p3 = Offset + Location + Height + perpendicular * HalfWidth;
|
||||
var p4 = Offset + Location + Height - perpendicular * HalfWidth;
|
||||
mat.FillPoly(new IEnumerable<Point>[]
|
||||
{
|
||||
new List<Point>()
|
||||
{
|
||||
new Point(p1.X,p1.Y),
|
||||
new Point(p2.X,p2.Y),
|
||||
new Point(p3.X,p3.Y),
|
||||
new Point(p4.X,p4.Y),
|
||||
}
|
||||
},Scalar.White);
|
||||
}
|
||||
|
||||
|
||||
public INode? GetNode(Vector2 position, float thDistance)
|
||||
{
|
||||
if ((Location + Offset - position).Length() < thDistance)
|
||||
{
|
||||
return new RotatedRectangleAnchorNode(this);
|
||||
}
|
||||
if ((Height + Location + Offset - position).Length() < thDistance)
|
||||
{
|
||||
return new RotatedRectangleHeightNode(this);
|
||||
}
|
||||
|
||||
var perpendicular = new Vector2(Height.Y, -Height.X);
|
||||
perpendicular.Normalize();
|
||||
if (((Offset + Location + Height + perpendicular * HalfWidth) - position).Length() < thDistance)
|
||||
{
|
||||
return new RotatedRectangleHalfWidthNode(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetPivot(Vector2 pivot)
|
||||
{
|
||||
Location += Offset;
|
||||
Offset = pivot;
|
||||
Location -= Offset;
|
||||
}
|
||||
|
||||
public void MovePivot(Vector2 pivot)
|
||||
{
|
||||
Offset = pivot;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void Save(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(Editable);
|
||||
bw.Write(IsGood);
|
||||
bw.Write(Location.X);
|
||||
bw.Write(Location.Y);
|
||||
bw.Write(Offset.X);
|
||||
bw.Write(Offset.Y);
|
||||
bw.Write(Height.X);
|
||||
bw.Write(Height.Y);
|
||||
bw.Write(HalfWidth);
|
||||
}
|
||||
|
||||
public void Load(BinaryReader br)
|
||||
{
|
||||
Editable = br.ReadBoolean();
|
||||
IsGood = br.ReadBoolean();
|
||||
Location = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
Offset = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
Height = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
HalfWidth = br.ReadSingle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.RotatedRectangle;
|
||||
|
||||
public class RotatedRectangleHalfWidthNode:INode
|
||||
{
|
||||
private readonly RotatedRectangleElement _owner;
|
||||
|
||||
public RotatedRectangleHalfWidthNode(RotatedRectangleElement owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 position)
|
||||
{
|
||||
_owner.HalfWidth = (position - (_owner.Height + _owner.Location + _owner.Offset)).Length();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes.Elements.RotatedRectangle;
|
||||
|
||||
public class RotatedRectangleHeightNode:INode
|
||||
{
|
||||
private readonly RotatedRectangleElement _owner;
|
||||
|
||||
public RotatedRectangleHeightNode(RotatedRectangleElement owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 position)
|
||||
{
|
||||
_owner.Height=position-_owner.Location;
|
||||
}
|
||||
}
|
||||
7
Hawkeye.VisionBuilder.Workflow/Datatypes/FilePath.cs
Normal file
7
Hawkeye.VisionBuilder.Workflow/Datatypes/FilePath.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
|
||||
public class FilePath
|
||||
{
|
||||
public string Path { get; set; }
|
||||
public string Format { get; set; } = "Model file(*.h5)|*.h5";
|
||||
}
|
||||
10
Hawkeye.VisionBuilder.Workflow/Datatypes/HawkeyeImage.cs
Normal file
10
Hawkeye.VisionBuilder.Workflow/Datatypes/HawkeyeImage.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
|
||||
public class HawkeyeImage
|
||||
{
|
||||
|
||||
public Mat ImageData { get; init; }
|
||||
public string Filename { get; init; }
|
||||
}
|
||||
68
Hawkeye.VisionBuilder.Workflow/Datatypes/LutData.cs
Normal file
68
Hawkeye.VisionBuilder.Workflow/Datatypes/LutData.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
|
||||
public class LutData
|
||||
{
|
||||
public LutData()
|
||||
{
|
||||
LUT = new byte[256 * 4];
|
||||
|
||||
Points = new Vector2[4][];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Points[i] = new Vector2[2];
|
||||
|
||||
Points[i][0] = new Vector2(0, 0);
|
||||
Points[i][1] = new Vector2(255, 255);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
LUT[i] = (byte)i;
|
||||
LUT[i+256] = (byte)i;
|
||||
LUT[i+256*2] = (byte)i;
|
||||
LUT[i+256*3] = (byte)i;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] LUT { get; set; }
|
||||
public Vector2[][] Points { get; set; }
|
||||
|
||||
public void Serialize(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(LUT.Length);
|
||||
bw.Write(LUT);
|
||||
bw.Write(Points.Length);
|
||||
for (int i = 0; i < Points.Length; i++)
|
||||
{
|
||||
bw.Write(Points[i].Length);
|
||||
for (int j = 0; j < Points[i].Length; j++)
|
||||
{
|
||||
bw.Write(Points[i][j].X);
|
||||
bw.Write(Points[i][j].Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Deserialize(BinaryReader br)
|
||||
{
|
||||
var length = br.ReadInt32();
|
||||
LUT = br.ReadBytes(length);
|
||||
length = br.ReadInt32();
|
||||
Points = new Vector2[length][];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var length2 = br.ReadInt32();
|
||||
Points[i] = new Vector2[length2];
|
||||
for (int j = 0; j < length2; j++)
|
||||
{
|
||||
Points[i][j] = new Vector2(br.ReadSingle(), br.ReadSingle());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
6
Hawkeye.VisionBuilder.Workflow/Datatypes/Pattern.cs
Normal file
6
Hawkeye.VisionBuilder.Workflow/Datatypes/Pattern.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
|
||||
public class Pattern
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Hawkeye.VisionBuilder.Workflow.Datatypes;
|
||||
|
||||
public class SelectFromList
|
||||
{
|
||||
public string Value { get; set; }
|
||||
public Func<List<string>> GetList { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user