100 lines
3.7 KiB
C#
100 lines
3.7 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api.DataType;
|
|
using VisionCalibrator;
|
|
using VisionCommon;
|
|
using Matrox.MatroxImagingLibrary;
|
|
using System.Collections.Generic;
|
|
|
|
namespace MilUI {
|
|
public class PositionMode : DisplayMode {
|
|
private MIL_ID _displayId;
|
|
private MIL_ID _graphicContext;
|
|
private MIL_ID _graphicListId;
|
|
private ImageSize _imageSize;
|
|
private StaticPoint _pixelSize;
|
|
private MilGraphics _milGraphics;
|
|
private List<MIL_INT> _colors;
|
|
private FovInfo _fovInfo;
|
|
|
|
private int _colorIndex = 0;
|
|
private int _crossLength = 30;
|
|
|
|
public PositionMode(
|
|
FovInfo fovInfo,
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
ImageSize imageSize, StaticPoint pixelSize) {
|
|
_fovInfo = fovInfo;
|
|
_displayId = displayId;
|
|
_graphicContext = graphicContext;
|
|
_graphicListId = graphicListId;
|
|
_imageSize = imageSize;
|
|
_pixelSize = pixelSize;
|
|
_milGraphics = new MilGraphics(displayId, _graphicListId);
|
|
_colors = new List<MIL_INT>() {
|
|
MIL.M_COLOR_YELLOW,
|
|
MIL.M_COLOR_MAGENTA
|
|
};
|
|
}
|
|
|
|
public override void MouseLeftDown(MIL_ID EventID) {
|
|
}
|
|
|
|
public override void MouseMove(MIL_ID EventID) {
|
|
}
|
|
|
|
public override void MouseRightDown(MIL_ID EventID) {
|
|
var currentMousePoint = GetMousePoint(EventID);
|
|
DisplayDrawer.AddCross(
|
|
_displayId, _graphicContext, _graphicListId, GetColor(), _milGraphics,
|
|
new Cross(currentMousePoint, _crossLength));
|
|
AddPositionText(_graphicContext, _graphicListId, GetColor(), _milGraphics, _imageSize, currentMousePoint);
|
|
ChangeColor();
|
|
}
|
|
|
|
private void AddPositionText(
|
|
MIL_ID graphicContext, MIL_ID graphicListId,
|
|
MIL_INT color, MilGraphics milGraphics,
|
|
ImageSize imageSize, ImagePoint imagePosition) {
|
|
ImagePoint imageCenter = new ImagePoint(imageSize.Width / 2, imageSize.Height / 2);
|
|
ImagePoint imageOffsetFromCenter = (imagePosition - imageCenter) as ImagePoint;
|
|
|
|
var calFovRecipe = VisionRecipeManager.GetCalFovRecipe(_fovInfo);
|
|
var calibrator = CalibratorManager.GetCalibrator(_fovInfo);
|
|
var staticPosition = calibrator.TransformToCalibratedSpace(imagePosition, imageSize);
|
|
var imageCenterStaticPosition = calibrator.TransformToCalibratedSpace(imageCenter, imageSize);
|
|
StaticPoint staticOffset = (staticPosition - imageCenterStaticPosition) as StaticPoint;
|
|
|
|
var msgs = new List<string>() {
|
|
string.Format($"I.P({imagePosition.X:0.00}, {imagePosition.Y:0.00})"),
|
|
string.Format($"I.O({imageOffsetFromCenter.X:0.00}, {imageOffsetFromCenter.Y:0.00})"),
|
|
string.Format($"S.P({staticPosition.X:0.00}, {staticPosition.Y:0.00})"),
|
|
string.Format($"S.O({staticOffset.X:0.00}, {staticOffset.Y:0.00})")
|
|
};
|
|
DisplayDrawer.AddTextList(
|
|
_displayId, graphicContext, graphicListId, color, milGraphics, _imageSize, imagePosition, msgs);
|
|
}
|
|
|
|
public override void GraphicSelectionModified(MIL_ID EventID) {
|
|
}
|
|
|
|
public override void Clear() {
|
|
_milGraphics.Clear();
|
|
}
|
|
|
|
public MIL_INT GetColor() {
|
|
return _colors[_colorIndex];
|
|
}
|
|
|
|
public void ChangeColor() {
|
|
_colorIndex++;
|
|
|
|
if (_colors.Count <= _colorIndex) {
|
|
_colorIndex = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|