Files
XplorePlane/XplorePlane/Views/ImageProcessing/EdgeLineFitPanel.xaml.cs
T
李伟 12938764b1 feat: 新增边缘查找拟合直线工具
- 新增 EdgeLineFitProcessor 算子(卡尺边缘检测 + 最小二乘/RANSAC直线拟合)
- 新增 EdgeLineFitPanel 辅助面板(参数配置、交互绘制卡尺)
- 支持任意角度旋转的卡尺区域,4个手柄控制长度/宽度
- 支持多次拟合累积显示,关闭面板后结果保留
- 极性箭头标识搜索方向(B→D / D→B / 双向)
- 卡尺亮绿色1px,拟合直线蓝色2px
- Ribbon快捷工具组新增「直线拟合」按钮
- 添加中英文本地化资源
2026-05-15 15:44:18 +08:00

54 lines
1.7 KiB
C#

using System.Windows;
using Prism.Ioc;
using XP.ImageProcessing.RoiControl.Controls;
using XplorePlane.Services.MainViewport;
using XplorePlane.ViewModels.ImageProcessing;
namespace XplorePlane.Views.ImageProcessing
{
public partial class EdgeLineFitPanel : Window
{
public EdgeLineFitPanel()
{
InitializeComponent();
var viewportService = ContainerLocator.Current?.Resolve<IMainViewportService>();
DataContext = new EdgeLineFitViewModel(viewportService);
Loaded += (s, e) =>
{
var mainWin = Owner as MainWindow;
if (mainWin != null)
{
var canvas = FindChild<PolygonRoiCanvas>(mainWin);
if (DataContext is EdgeLineFitViewModel vm)
{
vm.SetCanvas(canvas);
// 自动进入绘制模式
vm.DrawCaliperCommand.Execute();
}
}
};
Closed += (s, e) =>
{
if (DataContext is EdgeLineFitViewModel vm)
vm.OnPanelClosed();
};
}
private static T FindChild<T>(DependencyObject parent) where T : DependencyObject
{
int count = System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++)
{
var child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
if (child is T t) return t;
var result = FindChild<T>(child);
if (result != null) return result;
}
return null;
}
}
}