| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using TeamAAS.FlowEditor.Execution;
- using TeamAAS.FlowEditor.Models;
- using TeamAAS.FlowEditor.Plugins;
- using Plugins.Vpp.Models;
- namespace Plugins.Vpp
- {
- // ─────────────────────────────────────────────────────────────────────
- // VisionPro 几何测量算子(算子级节点):卡尺 / 找圆 / 找直线。
- // ─────────────────────────────────────────────────────────────────────
- /// <summary>Vp卡尺测量:边缘对位置与宽度。</summary>
- [Serializable]
- [Plugin("Vp卡尺测量", PluginCategory.Vpp模块, typeof(VpCaliperModel), "Ruler",
- NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量,
- Description = "Cognex Caliper 卡尺:高级编辑进原生界面摆卡尺/调极性;输出边缘位置与宽度")]
- public class VpCaliperPlugin : VpToolPluginBase<VpCaliperModel>
- {
- protected override string ToolTypeName => "CogCaliperTool";
- /// <summary>预设终端:卡尺匹配分数(边缘位置/宽度已由 类型化结果 覆盖)。</summary>
- public override VpPresetTerminal[] PresetTerminals => new[]
- {
- new VpPresetTerminal("分数", "Results[0].Score"),
- };
- protected override IEnumerable<OutputField> DeclareResultFields()
- {
- yield return new OutputField("位置1", typeof(double));
- yield return new OutputField("位置2", typeof(double));
- yield return new OutputField("宽度", typeof(double));
- }
- protected override void ExtractResults(object tool, Dictionary<string, object> results)
- {
- results["位置1"] = Get(tool, "Results[0].Edge0Position");
- results["位置2"] = Get(tool, "Results[0].Edge1Position");
- results["宽度"] = Get(tool, "Results[0].Width");
- Log(2, $"卡尺完成:宽度={results["宽度"]}");
- }
- }
- /// <summary>Vp找圆:圆心与半径。</summary>
- [Serializable]
- [Plugin("Vp找圆", PluginCategory.Vpp模块, typeof(VpFindCircleModel), "CircleOutline",
- NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量,
- Description = "Cognex FindCircle:高级编辑进原生界面设置搜索区域与卡尺组;输出圆心/半径")]
- public class VpFindCirclePlugin : VpToolPluginBase<VpFindCircleModel>
- {
- protected override string ToolTypeName => "CogFindCircleTool";
- protected override IEnumerable<OutputField> DeclareResultFields()
- {
- yield return new OutputField("圆心X", typeof(double));
- yield return new OutputField("圆心Y", typeof(double));
- yield return new OutputField("半径", typeof(double));
- }
- protected override void ExtractResults(object tool, Dictionary<string, object> results)
- {
- results["圆心X"] = Get(tool, "Results.Circle.Center.X");
- results["圆心Y"] = Get(tool, "Results.Circle.Center.Y");
- results["半径"] = Get(tool, "Results.Circle.Radius");
- Log(2, $"找圆完成:圆心=({results["圆心X"]},{results["圆心Y"]}),半径={results["半径"]}");
- }
- }
- /// <summary>Vp找直线:直线拟合。</summary>
- [Serializable]
- [Plugin("Vp找直线", PluginCategory.Vpp模块, typeof(VpFindLineModel), "VectorLine",
- NodeShape = NodeCategory.Normal, IsSubFlowNode = true, VisionCategory = VisionPlugin.几何测量,
- Description = "Cognex FindLine:高级编辑进原生界面设置搜索带与卡尺组;输出拟合直线")]
- public class VpFindLinePlugin : VpToolPluginBase<VpFindLineModel>
- {
- protected override string ToolTypeName => "CogFindLineTool";
- protected override IEnumerable<OutputField> DeclareResultFields()
- {
- yield return new OutputField("直线", typeof(object));
- yield return new OutputField("合格", typeof(bool));
- }
- protected override void ExtractResults(object tool, Dictionary<string, object> results)
- {
- var line = Get(tool, "Results.Line");
- results["直线"] = line;
- results["合格"] = line != null;
- Log(2, $"找直线完成:{(line != null ? "已拟合" : "未找到直线")}");
- }
- }
- }
- namespace Plugins.Vpp.Models
- {
- using TeamAAS.FlowEditor.Plugins;
- /// <summary>Vp卡尺测量模型。</summary>
- [Serializable]
- public class VpCaliperModel : VpToolModelBase
- {
- }
- /// <summary>Vp找圆模型。</summary>
- [Serializable]
- public class VpFindCircleModel : VpToolModelBase
- {
- }
- /// <summary>Vp找直线模型。</summary>
- [Serializable]
- public class VpFindLineModel : VpToolModelBase
- {
- }
- }
|