88 lines
3.1 KiB
C#
88 lines
3.1 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using CogCommon;
|
|
using VisionCommon;
|
|
using Hermes;
|
|
using Cognex.VisionPro;
|
|
using Cognex.VisionPro.Caliper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Aurora.Api.DataType;
|
|
|
|
#pragma warning disable 1591
|
|
namespace CogPattern {
|
|
public enum ePolarity {
|
|
Any = CogCaliperPolarityConstants.DontCare,
|
|
Negative = CogCaliperPolarityConstants.LightToDark,
|
|
Positive = CogCaliperPolarityConstants.DarkToLight,
|
|
}
|
|
|
|
internal static class CogMeasureCommon {
|
|
//private static readonly Logger _Logger = new Logger(typeof(CogMeasureCommon).Name);
|
|
|
|
public static ePolarity ConvertToPolarity(CogCaliperPolarityConstants cogCaliperPolarity) {
|
|
switch (cogCaliperPolarity) {
|
|
case CogCaliperPolarityConstants.DontCare:
|
|
return ePolarity.Any;
|
|
case CogCaliperPolarityConstants.LightToDark:
|
|
return ePolarity.Negative;
|
|
case CogCaliperPolarityConstants.DarkToLight:
|
|
return ePolarity.Positive;
|
|
}
|
|
return ePolarity.Any;
|
|
}
|
|
|
|
public static CogCaliperPolarityConstants ConvertToCogCaliperPolarity(ePolarity polarity) {
|
|
switch (polarity) {
|
|
case ePolarity.Any:
|
|
return CogCaliperPolarityConstants.DontCare;
|
|
case ePolarity.Negative:
|
|
return CogCaliperPolarityConstants.LightToDark;
|
|
case ePolarity.Positive:
|
|
return CogCaliperPolarityConstants.DarkToLight;
|
|
}
|
|
return CogCaliperPolarityConstants.DontCare;
|
|
}
|
|
|
|
public static bool IsLineFound(CogFindLineTool cogFindLineTool) {
|
|
if (cogFindLineTool.Results.GetLine() != null && cogFindLineTool.Results.Count > 0) {
|
|
foreach (CogFindLineResult result in cogFindLineTool.Results) {
|
|
if (result.CaliperResults == null || result.CaliperResults.Count == 0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static bool IsEdgeFound(CogCaliperTool cogCaliperTool) {
|
|
if (cogCaliperTool.Results?.Edges?.Count > 0) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static Line<ImagePoint> GetMinLengthLine(
|
|
LineEquation lineEquation, ImageSize imageSize) {
|
|
var line1 = new Line<ImagePoint>(
|
|
new ImagePoint(0, lineEquation.GetY(0)),
|
|
new ImagePoint(imageSize.Width, lineEquation.GetY(imageSize.Width)));
|
|
|
|
var line2 = new Line<ImagePoint>(
|
|
new ImagePoint(lineEquation.GetX(0), 0),
|
|
new ImagePoint(lineEquation.GetX(imageSize.Height), imageSize.Height));
|
|
|
|
return line1.Length < line2.Length ? line1 : line2;
|
|
}
|
|
}
|
|
}
|
|
|