private void FindCircleFrm_Load(object sender, EventArgs e) { cmbox_shape.SelectedIndex = 0; circleEvent.CircleGauge.Attach(picbox_ToolEdit.MFrameShape); picbox_ToolEdit.MShapes.Add(circleEvent.CircleGauge); foreach (var item in circleEvent.ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; cmbox_shape.Items.Add(se.Config.ToolName); } } picbox_ToolEdit.MFrameShape = circleEvent.shape; for (int i = 0; i < cmbox_shape.Items.Count; i++) { string s = cmbox_shape.Items[i].ToString(); if (s == circleEvent.circleConfig.ShapeName) { cmbox_shape.SelectedIndex = i; break; } } comboBox1.SelectedIndexChanged += delegate { UpdateUIToEvent(); }; comboBox2.SelectedIndexChanged += delegate { UpdateUIToEvent(); }; numTextBox1.TextChanged += delegate { UpdateUIToEvent(); }; numTextBox2.TextChanged += delegate { UpdateUIToEvent(); }; numTextBox3.TextChanged += delegate { UpdateUIToEvent(); }; chkbox_fullcircle.CheckedChanged += delegate { UpdateUIToEvent(); }; cmbox_shape.SelectedIndexChanged += delegate { UpdateUIToEvent(); }; Run(); }
public override bool Run(bool isTaskRun) { float linkX1, linkY1, linkX2, linkY2; GetValueFromLinkStr(config.LinkCenterX1, out linkX1); GetValueFromLinkStr(config.LinkCenterY1, out linkY1); GetValueFromLinkStr(config.LinkCenterX2, out linkX2); GetValueFromLinkStr(config.LinkCenterY2, out linkY2); config.CenterX1 = linkX1; config.CenterY1 = linkY1; config.CenterX2 = linkX2; config.CenterY2 = linkY2; Distance = (float)Math.Sqrt(Math.Pow(config.CenterX1 - config.CenterX2, 2) + Math.Pow(config.CenterY1 - config.CenterY2, 2)); ResultData.Name = config.ToolName; ResultData.ValueParams.Clear(); ResultData.ValueParams.Add("距离", new float[] { Distance }); if (isTaskRun) { ParentTask.ResultDatas.Add(ResultData); } if (config.ShapeName != null && config.ShapeName != string.Empty && config.ShapeName != "默认坐标系") { foreach (var item in ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; if (se.Config.ToolName == config.ShapeName) { Shape.SetCenterXY(se.OrgX, se.OrgY); Shape.Angle = se.Angle; break; } } } } else { Shape.SetCenterXY(0, 0); Shape.Angle = 0; } return(true); }
private void Get2PDistFrm_Load(object sender, EventArgs e) { this.chkBox_Draw.CheckedChanged += delegate { panel1.Visible = chkBox_Draw.Checked; }; cmbox_shape.SelectedIndex = 0; foreach (var item in getEvent.ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; cmbox_shape.Items.Add(se.Config.ToolName); } } UpdateEventToUI(); }
public override bool Run(bool isTaskRun) { int index = rectConfig.SelectImgIndex - 1; if (index < 0 || index >= ParentTask.Imgs.Count) { InputImg = null; return(false); } InputImg = ParentTask.Imgs[index].Img; if (InputImg == null || InputImg.IsVoid) { return(false); } if (rectConfig.ShapeName != null && rectConfig.ShapeName != string.Empty && rectConfig.ShapeName != "默认坐标系") { foreach (var item in ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; if (se.Config.ToolName == rectConfig.ShapeName) { shape.SetCenterXY(se.OrgX, se.OrgY); shape.Angle = se.Angle; break; } } } } else { shape.SetCenterXY(0, 0); shape.Angle = 0; } RectGauge.Name = Config.ToolName; RectGauge.Attach(shape); string toolName; string key; int part1, part2, valueIndex; float[] values; if (rectConfig.LinkCenterX != null && rectConfig.LinkCenterX != string.Empty) { part1 = rectConfig.LinkCenterX.IndexOf('.'); part2 = rectConfig.LinkCenterX.IndexOf('['); toolName = rectConfig.LinkCenterX.Substring(0, part1); key = rectConfig.LinkCenterX.Substring(part1 + 1, part2 - part1 - 1); valueIndex = Convert.ToInt16(rectConfig.LinkCenterX.Substring(part2 + 1, 1)); Result data = ParentTask.ResultDatas.Find((m) => { if (m.Name == toolName) { return(true); } return(false); }); if (data != null) { data.ValueParams.TryGetValue(key, out values); if (values != null && values.Length > valueIndex) { linkcenterx = values[valueIndex]; rectConfig.CenterX = linkcenterx + rectConfig.LinkOffsetCenterX; } } } if (rectConfig.LinkCenterY != null && rectConfig.LinkCenterY != string.Empty) { part1 = rectConfig.LinkCenterY.IndexOf('.'); part2 = rectConfig.LinkCenterY.IndexOf('['); toolName = rectConfig.LinkCenterY.Substring(0, part1); key = rectConfig.LinkCenterY.Substring(part1 + 1, part2 - part1 - 1); valueIndex = Convert.ToInt16(rectConfig.LinkCenterY.Substring(part2 + 1, 1)); Result data = ParentTask.ResultDatas.Find((m) => { if (m.Name == toolName) { return(true); } return(false); }); if (data != null) { data.ValueParams.TryGetValue(key, out values); if (values != null && values.Length > valueIndex) { linkcentery = values[valueIndex]; rectConfig.CenterY = linkcentery + rectConfig.LinkOffsetCenterY; } } } if (rectConfig.LinkAngle != null && rectConfig.LinkAngle != string.Empty) { part1 = rectConfig.LinkAngle.IndexOf('.'); part2 = rectConfig.LinkAngle.IndexOf('['); toolName = rectConfig.LinkAngle.Substring(0, part1); key = rectConfig.LinkAngle.Substring(part1 + 1, part2 - part1 - 1); valueIndex = Convert.ToInt16(rectConfig.LinkAngle.Substring(part2 + 1, 1)); Result data = ParentTask.ResultDatas.Find((m) => { if (m.Name == toolName) { return(true); } return(false); }); if (data != null) { data.ValueParams.TryGetValue(key, out values); if (values != null && values.Length > valueIndex) { linkangle = values[valueIndex]; rectConfig.Angle = linkangle + rectConfig.LinkOffsetAngle; } } } RectGauge.SetCenterXY(rectConfig.CenterX, rectConfig.CenterY); RectGauge.SetSize(rectConfig.SizeX, rectConfig.SizeY); RectGauge.Angle = rectConfig.Angle; RectGauge.Tolerance = rectConfig.Tolerance; RectGauge.Threshold = rectConfig.Threshold; RectGauge.TransitionChoice = (ETransitionChoice)rectConfig.TransitionChoice; RectGauge.TransitionType = (ETransitionType)rectConfig.TransitionType; RectGauge.SamplingStep = rectConfig.SamplingStep; RectGauge.NumFilteringPasses = rectConfig.Passes; RectGauge.Measure(InputImg); //输出结果 float centerX = RectGauge.MeasuredRectangle.CenterX; float centerY = RectGauge.MeasuredRectangle.CenterY; float angle = RectGauge.MeasuredRectangle.Angle; float width = RectGauge.MeasuredRectangle.SizeX; float height = RectGauge.MeasuredRectangle.SizeY; float notPassNum = RectGauge.NumSamples - RectGauge.NumValidSamples; ResultData.Name = rectConfig.ToolName; ResultData.ValueParams.Clear(); ResultData.ValueParams.Add("中心X", new float[] { centerX }); ResultData.ValueParams.Add("中心Y", new float[] { centerY }); ResultData.ValueParams.Add("角度", new float[] { angle }); ResultData.ValueParams.Add("宽度", new float[] { width }); ResultData.ValueParams.Add("高度", new float[] { height }); ResultData.ValueParams.Add("异常点数", new float[] { notPassNum }); if (isTaskRun) { ParentTask.ResultDatas.Add(ResultData); } //if (!RectGauge.Valid) //{ // return false; //} //判定 bool result = true; foreach (var item in rectConfig.ResultsDetermines) { if (item.Enable) { switch (item.Name) { case "中心X": if (centerX < item.Min || centerX > item.Max) { result = false; } break; case "中心Y": if (centerY < item.Min || centerY > item.Max) { result = false; } break; case "角度": if (angle < item.Min || angle > item.Max) { result = false; } break; case "宽度": if (width < item.Min || width > item.Max) { result = false; } break; case "高度": if (height < item.Min || height > item.Max) { result = false; } break; case "异常点数": if (notPassNum < item.Min || notPassNum > item.Max) { result = false; } break; default: break; } } } if (!result) { return(false); } return(true); }
public override bool Run(bool isTaskRun) { int index = pointConfig.SelectImgIndex - 1; if (index < 0 || index >= ParentTask.Imgs.Count) { InputImg = null; return(false); } InputImg = ParentTask.Imgs[index].Img; if (InputImg == null || InputImg.IsVoid) { return(false); } if (pointConfig.ShapeName != null && pointConfig.ShapeName != string.Empty && pointConfig.ShapeName != "默认坐标系") { foreach (var item in ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; if (se.Config.ToolName == pointConfig.ShapeName) { shape.SetCenterXY(se.OrgX, se.OrgY); shape.Angle = se.Angle; break; } } } } else { shape.SetCenterXY(0, 0); shape.Angle = 0; } PointGauge.Name = Config.ToolName; PointGauge.Attach(shape); PointGauge.SetCenterXY(pointConfig.CenterX, pointConfig.CenterY); PointGauge.Tolerance = pointConfig.Tolerance; PointGauge.ToleranceAngle = pointConfig.Angle; PointGauge.Threshold = pointConfig.Threshold; PointGauge.TransitionChoice = (ETransitionChoice)pointConfig.TransitionChoice; PointGauge.TransitionType = (ETransitionType)pointConfig.TransitionType; PointGauge.Measure(InputImg); //输出结果 if (PointGauge.Valid) { numPoints = 1; } else { numPoints = 0; } EPoint p = PointGauge.Shape; centerX = p.X; centerY = p.Y; ResultData.Name = pointConfig.ToolName; ResultData.ValueParams.Clear(); ResultData.ValueParams.Add("点个数", new float[] { numPoints }); ResultData.ValueParams.Add("X坐标", new float[] { centerX }); ResultData.ValueParams.Add("Y坐标", new float[] { centerY }); if (isTaskRun) { ParentTask.ResultDatas.Add(ResultData); } //判定 bool result = true; foreach (var item in pointConfig.ResultsDetermines) { if (item.Enable) { switch (item.Name) { case "点个数": if (numPoints < item.Min || numPoints > item.Max) { result = false; } break; default: break; } } } if (!result) { return(false); } return(true); }
public override bool Run(bool isTaskRun) { float linkX1, linkY1, linkX2, linkY2, linkA2; GetValueFromLinkStr(config.LinkP_CenterX, out linkX1); GetValueFromLinkStr(config.LinkP_CenterY, out linkY1); GetValueFromLinkStr(config.LinkL_CenterX, out linkX2); GetValueFromLinkStr(config.LinkL_CenterY, out linkY2); GetValueFromLinkStr(config.LinkL_Angle, out linkA2); config.P_CenterX = linkX1; config.P_CenterY = linkY1; config.L_CenterX = linkX2; config.L_CenterY = linkY2; config.L_Angle = linkA2; double a = 0; double b = 0; double c = 0; if (config.L_Angle % 180 == 0) { a = 0; b = -1; c = config.L_CenterY; P_Intersection = new PointF(config.P_CenterX, config.L_CenterY); } else if (config.L_Angle % 90 == 0) { a = -1; b = 0; c = config.L_CenterX; P_Intersection = new PointF(config.L_CenterX, config.P_CenterY); } else { a = Math.Tan(config.L_Angle * (Math.PI / 180)); b = -1; c = config.L_CenterY - a * config.L_CenterX; double k2 = -1 / a; double b2 = config.P_CenterY - k2 * config.P_CenterX; double p_x0 = (c - b2) / (k2 - a); double p_y0 = a * p_x0 + c; P_Intersection = new PointF((float)p_x0, (float)p_y0); } Distance = (float)Math.Abs((a * config.P_CenterX + b * config.P_CenterY + c) / (Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2)))); ResultData.Name = config.ToolName; ResultData.ValueParams.Clear(); ResultData.ValueParams.Add("距离", new float[] { Distance }); if (isTaskRun) { ParentTask.ResultDatas.Add(ResultData); } if (config.ShapeName != null && config.ShapeName != string.Empty && config.ShapeName != "默认坐标系") { foreach (var item in ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; if (se.Config.ToolName == config.ShapeName) { Shape.SetCenterXY(se.OrgX, se.OrgY); Shape.Angle = se.Angle; break; } } } } else { Shape.SetCenterXY(0, 0); Shape.Angle = 0; } return(true); }
public override bool Run(bool isTaskRun) { int index = lineConfig.SelectImgIndex - 1; if (index < 0 || index >= ParentTask.Imgs.Count) { InputImg = null; return(false); } InputImg = ParentTask.Imgs[index].Img; if (InputImg == null || InputImg.IsVoid) { return(false); } if (lineConfig.ShapeName != null && lineConfig.ShapeName != string.Empty && lineConfig.ShapeName != "默认坐标系") { foreach (var item in ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; if (se.Config.ToolName == lineConfig.ShapeName) { shape.SetCenterXY(se.OrgX, se.OrgY); shape.Angle = se.Angle; break; } } } } else { shape.SetCenterXY(0, 0); shape.Angle = 0; } LineGauge.Name = Config.ToolName; LineGauge.Attach(shape); LineGauge.SetCenterXY(lineConfig.CenterX, lineConfig.CenterY); LineGauge.Length = lineConfig.Length; LineGauge.Angle = lineConfig.Angle; LineGauge.Tolerance = lineConfig.Tolerance; LineGauge.Threshold = lineConfig.Threshold; LineGauge.TransitionChoice = (ETransitionChoice)lineConfig.TransitionChoice; LineGauge.TransitionType = (ETransitionType)lineConfig.TransitionType; LineGauge.SamplingStep = lineConfig.SamplingStep; LineGauge.NumFilteringPasses = lineConfig.Passes; LineGauge.Measure(InputImg); //输出结果 float centerX = LineGauge.MeasuredLine.CenterX; float centerY = LineGauge.MeasuredLine.CenterY; float angle = LineGauge.MeasuredLine.Angle; float notPassNum = LineGauge.NumSamples - LineGauge.NumValidSamples; ResultData.Name = lineConfig.ToolName; ResultData.ValueParams.Clear(); ResultData.ValueParams.Add("中心X", new float[] { centerX }); ResultData.ValueParams.Add("中心Y", new float[] { centerY }); ResultData.ValueParams.Add("角度", new float[] { angle }); ResultData.ValueParams.Add("异常点数", new float[] { notPassNum }); if (isTaskRun) { ParentTask.ResultDatas.Add(ResultData); } //if (!RectGauge.Valid) //{ // return false; //} //判定 bool result = true; foreach (var item in lineConfig.ResultsDetermines) { if (item.Enable) { switch (item.Name) { case "中心X": if (centerX < item.Min || centerX > item.Max) { result = false; } break; case "中心Y": if (centerY < item.Min || centerY > item.Max) { result = false; } break; case "角度": if (angle < item.Min || angle > item.Max) { result = false; } break; case "异常点数": if (notPassNum < item.Min || notPassNum > item.Max) { result = false; } break; default: break; } } } if (!result) { return(false); } return(true); }
public ShapeFrm(ShapeEvent shapeE) { InitializeComponent(); shapeEvent = shapeE; }
public override bool Run(bool isTaskRun) { if (config.ShapeName != null && config.ShapeName != string.Empty && config.ShapeName != "默认坐标系") { foreach (var item in ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; if (se.Config.ToolName == config.ShapeName) { Shape.SetCenterXY(se.OrgX, se.OrgY); Shape.Angle = se.Angle; break; } } } } else { Shape.SetCenterXY(0, 0); Shape.Angle = 0; } float linkX1, linkY1, linkA1, linkX2, linkY2, linkA2; GetValueFromLinkStr(config.LinkL_CenterX1, out linkX1); GetValueFromLinkStr(config.LinkL_CenterY1, out linkY1); GetValueFromLinkStr(config.LinkL_Angle1, out linkA1); GetValueFromLinkStr(config.LinkL_CenterX2, out linkX2); GetValueFromLinkStr(config.LinkL_CenterY2, out linkY2); GetValueFromLinkStr(config.LinkL_Angle2, out linkA2); config.L_CenterX1 = linkX1; config.L_CenterY1 = linkY1; config.L_Angle1 = linkA1; config.L_CenterX2 = linkX2; config.L_CenterY2 = linkY2; config.L_Angle2 = linkA2; double k1, b1, k2, b2; k1 = Math.Tan(config.L_Angle1 * (Math.PI / 180)); b1 = config.L_CenterY1 - k1 * config.L_CenterX1; k2 = Math.Tan(config.L_Angle2 * (Math.PI / 180)); b2 = config.L_CenterY2 - k2 * config.L_CenterX2; HaveIntersection = k1 != k2; if (HaveIntersection) { double p_x, p_y; if (config.L_Angle1 % 90 == 0 && config.L_Angle1 % 180 != 0) { p_x = config.L_CenterX1; p_y = k2 * config.L_CenterX1 + b2; } else if (config.L_Angle2 % 90 == 0 && config.L_Angle2 % 180 != 0) { p_x = config.L_CenterX2; p_y = k1 * config.L_CenterX2 + b1; } else { p_x = (b1 - b2) / (k2 - k1); p_y = k1 * p_x + b1; } P_Intersection = new PointF((float)p_x, (float)p_y); if (config.IsNormalShape) { P_Intersection = ToolGroupEdit.GetRotatePoint(new PointF(), P_Intersection, Shape.Angle); P_Intersection.X += Shape.CenterX; P_Intersection.Y += Shape.CenterY; } } else { P_Intersection = new PointF(); } ResultData.Name = config.ToolName; ResultData.ValueParams.Clear(); ResultData.ValueParams.Add("有无交点", new float[] { Convert.ToSingle(HaveIntersection) }); ResultData.ValueParams.Add("交点X坐标", new float[] { P_Intersection.X }); ResultData.ValueParams.Add("交点Y坐标", new float[] { P_Intersection.Y }); if (isTaskRun) { ParentTask.ResultDatas.Add(ResultData); } return(true); }
public override bool Run(bool isTaskRun) { int index = circleConfig.SelectImgIndex - 1; if (index < 0 || index >= ParentTask.Imgs.Count) { InputImg = null; return(false); } InputImg = ParentTask.Imgs[index].Img; if (InputImg == null || InputImg.IsVoid) { return(false); } if (circleConfig.ShapeName != null && circleConfig.ShapeName != string.Empty && circleConfig.ShapeName != "默认坐标系") { foreach (var item in ParentTask.Events) { if (item is ShapeEvent) { ShapeEvent se = item as ShapeEvent; if (se.Config.ToolName == circleConfig.ShapeName) { shape.SetCenterXY(se.OrgX, se.OrgY); shape.Angle = se.Angle; break; } } } } else { shape.SetCenterXY(0, 0); shape.Angle = 0; } CircleGauge.Name = Config.ToolName; CircleGauge.Attach(shape); CircleGauge.SetCenterXY(circleConfig.CenterX, circleConfig.CenterY); CircleGauge.Diameter = circleConfig.Diameter; CircleGauge.Amplitude = circleConfig.Amplitude; CircleGauge.Angle = circleConfig.Angle; CircleGauge.Tolerance = circleConfig.Tolerance; CircleGauge.Threshold = circleConfig.Threshold; CircleGauge.TransitionChoice = (ETransitionChoice)circleConfig.TransitionChoice; CircleGauge.TransitionType = (ETransitionType)circleConfig.TransitionType; CircleGauge.SamplingStep = circleConfig.SamplingStep; CircleGauge.NumFilteringPasses = circleConfig.Passes; CircleGauge.Measure(InputImg); //输出结果 float centerX = CircleGauge.MeasuredCircle.CenterX; float centerY = CircleGauge.MeasuredCircle.CenterY; float diameter = CircleGauge.MeasuredCircle.Diameter; float length = CircleGauge.MeasuredCircle.ArcLength; float notPassNum = CircleGauge.NumSamples - CircleGauge.NumValidSamples; ResultData.Name = circleConfig.ToolName; ResultData.ValueParams.Clear(); ResultData.ValueParams.Add("中心X", new float[] { centerX }); ResultData.ValueParams.Add("中心Y", new float[] { centerY }); ResultData.ValueParams.Add("直径", new float[] { diameter }); ResultData.ValueParams.Add("周长", new float[] { length }); ResultData.ValueParams.Add("异常点数", new float[] { notPassNum }); if (isTaskRun) { ParentTask.ResultDatas.Add(ResultData); } //if (!RectGauge.Valid) //{ // return false; //} //判定 bool result = true; foreach (var item in circleConfig.ResultsDetermines) { if (item.Enable) { switch (item.Name) { case "中心X": if (centerX < item.Min || centerX > item.Max) { result = false; } break; case "中心Y": if (centerY < item.Min || centerY > item.Max) { result = false; } break; case "直径": if (diameter < item.Min || diameter > item.Max) { result = false; } break; case "周长": if (length < item.Min || length > item.Max) { result = false; } break; case "异常点数": if (notPassNum < item.Min || notPassNum > item.Max) { result = false; } break; default: break; } } } if (!result) { return(false); } return(true); }