| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TeamAAS_VP.Controls
- {
- /// <summary>
- /// 支持旋转的矩形
- /// </summary>
- public class RotatedRect : BindableBase
- {
- private double _x;
- private double _y;
- private double _width;
- private double _height;
- private double _angle; // 旋转角度,单位:度
- public double X
- {
- get => _x;
- set => SetProperty(ref _x, value);
- }
- public double Y
- {
- get => _y;
- set => SetProperty(ref _y, value);
- }
- public double Width
- {
- get => _width;
- set => SetProperty(ref _width, Math.Max(0, value));
- }
- public double Height
- {
- get => _height;
- set => SetProperty(ref _height, Math.Max(0, value));
- }
- public double Angle
- {
- get => _angle;
- set => SetProperty(ref _angle, NormalizeAngle(value));
- }
- public double CenterX => X + Width / 2;
- public double CenterY => Y + Height / 2;
- public RotatedRect()
- {
- }
- public RotatedRect(double x, double y, double width, double height, double angle = 0)
- {
- X = x;
- Y = y;
- Width = width;
- Height = height;
- Angle = angle;
- }
- private double NormalizeAngle(double angle)
- {
- // 将角度规范到0-360度
- angle %= 360;
- if (angle < 0) angle += 360;
- return angle;
- }
- public System.Windows.Rect ToRect()
- {
- return new System.Windows.Rect(X, Y, Width, Height);
- }
- public OpenCvSharp.RotatedRect ToCvRotatedRect()
- {
- var center = new OpenCvSharp.Point2f((float)CenterX, (float)CenterY);
- var size = new OpenCvSharp.Size2f((float)Width, (float)Height);
- return new OpenCvSharp.RotatedRect(center, size, (float)Angle);
- }
- public bool ContainsPoint(System.Windows.Point point)
- {
- // 简化版:不考虑旋转的包含检测
- return point.X >= X && point.X <= X + Width &&
- point.Y >= Y && point.Y <= Y + Height;
- }
- public override string ToString()
- {
- return $"X={X:F1}, Y={Y:F1}, W={Width:F1}, H={Height:F1}, Angle={Angle:F1}°";
- }
- }
- /// <summary>
- /// ROI操作模式
- /// </summary>
- public enum RoiOperationMode
- {
- None, // 无操作
- Draw, // 绘制
- Move, // 移动
- Resize, // 调整大小
- Rotate, // 旋转
- CornerResize // 角点调整
- }
- /// <summary>
- /// 拖动控制点类型
- /// </summary>
- public enum DragHandleType
- {
- None,
- TopLeft,
- TopRight,
- BottomLeft,
- BottomRight,
- Top,
- Right,
- Bottom,
- Left,
- Rotate
- }
- }
|