170 lines
6.8 KiB
C#
170 lines
6.8 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
|
|
namespace VisionUI.Pattern {
|
|
/// <summary>
|
|
/// Interaction logic for ForceOkWindow.xaml
|
|
/// </summary>
|
|
public partial class ForceOkWindow : Window {
|
|
private static Logger _logger = new Logger("ForceOkWindow");
|
|
public string WINDOW_TITLE => "Force OK Window";
|
|
public ForceOkResult Result { get; private set; } = null;
|
|
|
|
private static FovInfo _FovInfo;
|
|
|
|
public ForceOkWindow(FovInfo fovInfo, PatternInfo patternInfo, object findImage) {
|
|
InitializeComponent();
|
|
|
|
_FovInfo = fovInfo;
|
|
|
|
SetTitle();
|
|
CreateView(patternInfo, findImage);
|
|
}
|
|
|
|
public void SetTitle() {
|
|
Title = WINDOW_TITLE;
|
|
}
|
|
|
|
public void CreateView(PatternInfo patternInfo, object findImage) {
|
|
IpViewManager.CreateForceOkView(_FovInfo, patternInfo, findImage, this);
|
|
gridForceOkView.Children.Add(IpViewManager.ForceOkView);
|
|
}
|
|
|
|
public void ResetPosition() {
|
|
Left = WindowUtil.GetLeftWithRatioOnMainWindow(0.1);
|
|
Top = WindowUtil.GetTopWithRatioOnMainWindow(0.2);
|
|
}
|
|
|
|
protected override void OnClosing(CancelEventArgs e) {
|
|
Result = new ForceOkResult() {
|
|
FoundStatus = IpViewManager.ForceOkView.IsApply ? eFoundStatus.ForceOK : eFoundStatus.NotFound,
|
|
ForceOkPoint = IpViewManager.ForceOkView.ForceOkPoint.Clone() as ImagePoint,
|
|
NewFindResult = IpViewManager.ForceOkView.NewFindResult?.Clone() as PatternResult
|
|
};
|
|
((IDisposable)IpViewManager.ForceOkView).Dispose();
|
|
}
|
|
|
|
public static PatternResult Show(
|
|
FovInfo fovInfo, PatternIndex patternIndex, object findImage, PatternResult patternResult) {
|
|
|
|
ForceOkWindow forceOkWindow = null;
|
|
var patternAgent = PatternAgentManager.GetAgent(fovInfo);
|
|
var patternInfo = patternAgent.GetPatternInfo(patternIndex);
|
|
|
|
Application.Current.Dispatcher.Invoke(() => {
|
|
forceOkWindow = new ForceOkWindow(fovInfo, patternInfo, findImage);
|
|
forceOkWindow.Show();
|
|
});
|
|
|
|
if (forceOkWindow != null) {
|
|
while (!forceOkWindow.IsDone()) {
|
|
Thread.Sleep(100);
|
|
}
|
|
|
|
if (forceOkWindow.Result.FoundStatus == eFoundStatus.ForceOK) {
|
|
var forceOkPoint = forceOkWindow.Result.ForceOkPoint;
|
|
var newFindResult = forceOkWindow.Result.NewFindResult;
|
|
|
|
if (newFindResult != null &&
|
|
newFindResult.Results != null &&
|
|
newFindResult.Status == eFoundStatus.FoundOK) {
|
|
patternResult = newFindResult;
|
|
}
|
|
else {
|
|
patternResult.Status = eFoundStatus.ForceOK;
|
|
patternResult.Results = CreateResults(
|
|
patternInfo.PatternType,
|
|
IpAdapter.Instance.IpEnvironment.GetImageCenter(findImage),
|
|
forceOkPoint);
|
|
patternAgent.SetLineCenterPoint(patternResult, patternInfo, IpViewManager.ForceOkView.GetDisplay());
|
|
}
|
|
|
|
patternResult.FovId = _FovInfo.FovId;
|
|
patternResult.PatternIndex = patternInfo.GetPatternIndex().Clone() as PatternIndex;
|
|
patternResult.MoreInfo = CreateFixtureResult(patternAgent, patternInfo, forceOkPoint);
|
|
|
|
_logger.I($"Force OK ({forceOkWindow.Result.FoundStatus}) : {forceOkPoint}");
|
|
}
|
|
else {
|
|
_logger.I($"Force OK ({forceOkWindow.Result.FoundStatus})");
|
|
}
|
|
}
|
|
|
|
return patternResult;
|
|
}
|
|
|
|
public bool IsDone() {
|
|
return Result != null;
|
|
}
|
|
|
|
private static IEnumerable<BaseResult> CreateResults(
|
|
ePatternType patternType, ImagePoint imageCenter, ImagePoint forceOkPoint) {
|
|
|
|
if (patternType == ePatternType.ImageModelFinder ||
|
|
patternType == ePatternType.ShapeModelFinder) {
|
|
var results = new List<ModelFinderResult>();
|
|
results.Add(new ModelFinderResult(
|
|
position: forceOkPoint,
|
|
offset: (forceOkPoint - imageCenter) as ImagePoint,
|
|
angle: Angle.CreateWithDegree(0),
|
|
score: 0.1));
|
|
return results;
|
|
}
|
|
else if (patternType == ePatternType.LineFinder) {
|
|
var results = new List<LineFinderResult>();
|
|
results.Add(new LineFinderResult(
|
|
position: forceOkPoint,
|
|
angle: Angle.CreateWithDegree(0),
|
|
lineEquation: null,
|
|
contextId: null));
|
|
return results;
|
|
}
|
|
else if (patternType == ePatternType.LineIntersection) {
|
|
var results = new List<LineIntersectionResult>();
|
|
results.Add(new LineIntersectionResult(
|
|
position: forceOkPoint,
|
|
offset: (forceOkPoint - imageCenter) as ImagePoint,
|
|
line1PatternResult: null,
|
|
line2PatternResult: null));
|
|
return results;
|
|
}
|
|
else if (patternType == ePatternType.PatternMatching) {
|
|
var results = new List<PatternMatchingResult>();
|
|
results.Add(new PatternMatchingResult(
|
|
position: forceOkPoint,
|
|
offset: (forceOkPoint - imageCenter) as ImagePoint,
|
|
angle: Angle.CreateWithDegree(0),
|
|
score: 0.1));
|
|
return results;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private static FixtureResult CreateFixtureResult(
|
|
PatternAgentBase patternAgent, PatternInfo patternInfo, ImagePoint forceOkPoint) {
|
|
if (PatternConstants.IsFixturePatternType(patternInfo.PatternType)) {
|
|
var imageTrainParam = patternAgent.GetTrainParam(patternInfo) as ImageTrainParam;
|
|
var fixtureOrigin = imageTrainParam.TrainOrigin;
|
|
var fixtureResult = new FixtureResult() {
|
|
Origin = forceOkPoint.Clone() as ImagePoint,
|
|
Offset = (forceOkPoint - fixtureOrigin.Origin) as ImagePoint,
|
|
Rotation = fixtureOrigin.Angle.Clone() as Angle
|
|
};
|
|
return fixtureResult;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|