147 lines
5.4 KiB
C#
147 lines
5.4 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api.DataType;
|
|
using VisionCommon;
|
|
using Matrox.MatroxImagingLibrary;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace MilUI {
|
|
public class CircleMode : DisplayMode {
|
|
private MIL_ID _displayId;
|
|
private MIL_ID _graphicContext;
|
|
private MIL_ID _graphicListId;
|
|
private ImageSize _imageSize;
|
|
private StaticPoint _pixelSize;
|
|
private MilGraphics _milGraphics;
|
|
private MilGraphics _tempMilGraphics;
|
|
private bool _isMouseRighttDown = false;
|
|
private ImagePoint _measurePointStart = new ImagePoint();
|
|
private ImagePoint _measurePointMove = new ImagePoint();
|
|
private ImagePoint _measurePointEnd = new ImagePoint();
|
|
private List<MIL_INT> _colors;
|
|
private int _colorIndex = 0;
|
|
|
|
public CircleMode(
|
|
MIL_ID displayId, MIL_ID graphicContext, MIL_ID graphicListId,
|
|
ImageSize imageSize, StaticPoint pixelSize) {
|
|
_displayId = displayId;
|
|
_graphicContext = graphicContext;
|
|
_graphicListId = graphicListId;
|
|
_imageSize = imageSize;
|
|
_pixelSize = pixelSize;
|
|
_milGraphics = new MilGraphics(_displayId, _graphicListId);
|
|
_tempMilGraphics = new MilGraphics(_displayId, _graphicListId);
|
|
_colors = new List<MIL_INT>() {
|
|
MIL.M_COLOR_YELLOW,
|
|
MIL.M_COLOR_MAGENTA
|
|
};
|
|
}
|
|
|
|
public MIL_INT GetColor() {
|
|
return _colors[_colorIndex];
|
|
}
|
|
|
|
public void ChangeColor() {
|
|
_colorIndex++;
|
|
|
|
if (_colors.Count <= _colorIndex) {
|
|
_colorIndex = 0;
|
|
}
|
|
}
|
|
|
|
public override void MouseLeftDown(MIL_ID EventID) {
|
|
}
|
|
|
|
public override void MouseMove(MIL_ID EventID) {
|
|
if (_isMouseRighttDown) {
|
|
var currentMousePoint = GetMousePoint(EventID);
|
|
|
|
if (_measurePointMove.X != currentMousePoint.X ||
|
|
_measurePointMove.Y != currentMousePoint.Y) {
|
|
MIL_INT combinationKeys = 0;
|
|
MIL.MdispGetHookInfo(EventID, MIL.M_COMBINATION_KEYS, ref combinationKeys);
|
|
AddMeasureInfo(GetColor(), _tempMilGraphics, combinationKeys, _measurePointStart, currentMousePoint);
|
|
}
|
|
_measurePointMove = currentMousePoint;
|
|
}
|
|
}
|
|
|
|
public override void MouseRightDown(MIL_ID EventID) {
|
|
MIL_INT combinationKeys = 0;
|
|
MIL.MdispGetHookInfo(EventID, MIL.M_COMBINATION_KEYS, ref combinationKeys);
|
|
|
|
if (!_isMouseRighttDown) {
|
|
_isMouseRighttDown = true;
|
|
_measurePointStart = GetMousePoint(EventID);
|
|
}
|
|
else {
|
|
_isMouseRighttDown = false;
|
|
_measurePointEnd = GetMousePoint(EventID);
|
|
AddMeasureInfo(GetColor(), _milGraphics, combinationKeys, _measurePointStart, _measurePointEnd);
|
|
ChangeColor();
|
|
}
|
|
}
|
|
|
|
private bool IsLocatedInImageArea(ImageSize imageSize, ImagePoint p) {
|
|
return (p.X < imageSize.Width) && (p.Y < imageSize.Height);
|
|
}
|
|
|
|
public override void GraphicSelectionModified(MIL_ID EventID) {
|
|
}
|
|
|
|
public override void Clear() {
|
|
_milGraphics.Clear();
|
|
_tempMilGraphics.Clear();
|
|
}
|
|
|
|
private void AddMeasureInfo(
|
|
MIL_INT color, MilGraphics milGraphics, MIL_INT combinationKeys,
|
|
ImagePoint pStart, ImagePoint pEnd) {
|
|
_tempMilGraphics.Clear();
|
|
|
|
var radius = MathUtil.CalculateDistance(pStart, pEnd);
|
|
DrawCircle(color, milGraphics, pStart, radius);
|
|
|
|
var msgs = GetDistanceText(pStart, pEnd);
|
|
DisplayDrawer.AddTextList(
|
|
_displayId, _graphicContext, _graphicListId,
|
|
color, milGraphics, _imageSize,
|
|
new ImagePoint(pEnd.X + 10, pEnd.Y + 10),
|
|
msgs);
|
|
}
|
|
|
|
private void DrawCircle(
|
|
MIL_INT color, MilGraphics milGraphics, ImagePoint origin, double radius) {
|
|
MIL.MgraColor(_graphicContext, color);
|
|
MIL.MgraArc(_graphicContext, _graphicListId, origin.X, origin.Y, radius, radius, 0, 360);
|
|
milGraphics.Add();
|
|
milGraphics.SetResizable(false);
|
|
milGraphics.SetRotatable(false);
|
|
milGraphics.SetTranslatable(false);
|
|
milGraphics.SetSpecificFeature(false);
|
|
milGraphics.SetFixedAspectRatio(1.0);
|
|
}
|
|
|
|
private List<string> GetDistanceText(ImagePoint p1, ImagePoint p2) {
|
|
var pixelDistance = MathUtil.CalculateDistance(p1, p2);
|
|
var worldDistance = GetDistance(p1, p2, _pixelSize);
|
|
|
|
return new List<string>() {
|
|
string.Format("R : {0:0.0000} [px]", pixelDistance),
|
|
string.Format("R : {0:0.0000} [mm]", worldDistance),
|
|
string.Format("D : {0:0.0000} [px]", pixelDistance * 2),
|
|
string.Format("D : {0:0.0000} [mm]", worldDistance * 2)
|
|
};
|
|
}
|
|
|
|
private double GetDistance(ImagePoint p1, ImagePoint p2, StaticPoint scale) {
|
|
return Math.Sqrt(
|
|
Math.Pow((p1.X - p2.X) * scale.X, 2) +
|
|
Math.Pow((p1.Y - p2.Y) * scale.Y, 2));
|
|
}
|
|
}
|
|
}
|