页面逻辑调整
This commit is contained in:
@@ -29,6 +29,27 @@ namespace 头罩视野.Services
|
|||||||
return _standardTotalArea - binocularTotalArea;
|
return _standardTotalArea - binocularTotalArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//计算双目视野
|
||||||
|
|
||||||
|
public static double CalculateBinocularArea(
|
||||||
|
List<int> leftFinal,
|
||||||
|
List<int> rightFinal,
|
||||||
|
List<(int m, int n)> lightPositions)
|
||||||
|
{
|
||||||
|
// 双目并集:左眼亮 OR 右眼亮 = 亮
|
||||||
|
int[] binocularData = new int[243];
|
||||||
|
for (int i = 0; i < 243; i++)
|
||||||
|
{
|
||||||
|
binocularData[i] = leftFinal[i] | rightFinal[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算面积
|
||||||
|
return CalculateEllipseArea(binocularData, lightPositions);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//下方视野 下方视野角度 = 人眼到「最低亮灯条」的夹角
|
//下方视野 下方视野角度 = 人眼到「最低亮灯条」的夹角
|
||||||
|
|
||||||
public static double CalculateBottomViewAngle(int[] lightData, List<(int m, int n)> lightPositions)
|
public static double CalculateBottomViewAngle(int[] lightData, List<(int m, int n)> lightPositions)
|
||||||
@@ -107,101 +128,6 @@ namespace 头罩视野.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// 传入:81个灯的亮灭数据(0=灭,1=亮)
|
|
||||||
//// 返回:椭圆面积
|
|
||||||
//public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
|
||||||
//{
|
|
||||||
// //if (lightData.Length != totalLights || lightPositions.Count != totalLights)
|
|
||||||
// // throw new Exception("必须是81个灯的数据");
|
|
||||||
|
|
||||||
// // 第一步:收集所有亮灯坐标
|
|
||||||
// List<System.Drawing.Point> brightPoints = new List<System.Drawing.Point>();
|
|
||||||
// for (int i = 0; i < totalLights; i++)
|
|
||||||
// {
|
|
||||||
// if (totalLights > lightData.Count())
|
|
||||||
// {
|
|
||||||
|
|
||||||
// }
|
|
||||||
// if (lightData[i] == 1)
|
|
||||||
// {
|
|
||||||
|
|
||||||
|
|
||||||
// var (m, n) = lightPositions[i];
|
|
||||||
// System.Drawing.Point p = GetLightPoint(m, n);
|
|
||||||
// brightPoints.Add(p);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 第二步:用亮点拟合椭圆
|
|
||||||
// var (cx, cy, a, b, area) = FitEllipse(brightPoints);
|
|
||||||
|
|
||||||
// // 返回面积
|
|
||||||
// return area;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
|
||||||
//{
|
|
||||||
// // 日志:方法入口
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"===== CalculateEllipseArea 开始 =====");
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"lightData.Length = {lightData?.Length ?? 0}");
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"lightPositions.Count = {lightPositions?.Count ?? 0}");
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"totalLights = {totalLights}");
|
|
||||||
|
|
||||||
// // 1. 参数校验
|
|
||||||
// if (lightData == null || lightPositions == null)
|
|
||||||
// {
|
|
||||||
// System.Diagnostics.Debug.WriteLine("错误:lightData 或 lightPositions 为 null");
|
|
||||||
// return double.NaN;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (lightData.Length != totalLights || lightPositions.Count != totalLights)
|
|
||||||
// {
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"数据长度不匹配:lightData.Length={lightData.Length}, totalLights={totalLights}, lightPositions.Count={lightPositions.Count}");
|
|
||||||
// // 这里可以根据实际需要决定是否抛出异常或使用较小长度继续
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 2. 收集亮灯坐标
|
|
||||||
// List<System.Drawing.Point> brightPoints = new List<System.Drawing.Point>();
|
|
||||||
// for (int i = 0; i < totalLights && i < lightData.Length && i < lightPositions.Count; i++)
|
|
||||||
// {
|
|
||||||
// if (lightData[i] == 1)
|
|
||||||
// {
|
|
||||||
// var (m, n) = lightPositions[i];
|
|
||||||
// System.Drawing.Point p = GetLightPoint(m, n);
|
|
||||||
// brightPoints.Add(p);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"收集到的亮灯点数:{brightPoints.Count}");
|
|
||||||
|
|
||||||
// if (brightPoints.Count < 5)
|
|
||||||
// {
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"警告:亮灯点不足5个(实际{brightPoints.Count}),无法拟合椭圆,返回 NaN");
|
|
||||||
// return double.NaN;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 3. 拟合椭圆
|
|
||||||
// var (cx, cy, a, b, area) = FitEllipse(brightPoints);
|
|
||||||
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"拟合结果:cx={cx}, cy={cy}, a={a}, b={b}, area={area}");
|
|
||||||
|
|
||||||
// if (double.IsNaN(a) || double.IsNaN(b) || double.IsNaN(area))
|
|
||||||
// {
|
|
||||||
// System.Diagnostics.Debug.WriteLine("错误:拟合结果包含 NaN");
|
|
||||||
// return double.NaN;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (a <= 0 || b <= 0)
|
|
||||||
// {
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"错误:椭圆半轴无效(a={a}, b={b}),面积计算将得到 NaN 或 0");
|
|
||||||
// return double.NaN;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// System.Diagnostics.Debug.WriteLine($"最终返回面积:{area}");
|
|
||||||
// return area;
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
||||||
{
|
{
|
||||||
// 参数有效性检查
|
// 参数有效性检查
|
||||||
|
|||||||
@@ -47,6 +47,12 @@ namespace 头罩视野.Views
|
|||||||
private double _binocularTotalArea = 0; // 双目总视野面积
|
private double _binocularTotalArea = 0; // 双目总视野面积
|
||||||
double maxBottomViewAngle = 0; //记录所有姿态里的最大下方视野
|
double maxBottomViewAngle = 0; //记录所有姿态里的最大下方视野
|
||||||
|
|
||||||
|
|
||||||
|
// 最终左眼视野(永远243个)
|
||||||
|
private List<int> _leftFinalData = new List<int>();
|
||||||
|
// 最终右眼视野(永远243个)
|
||||||
|
private List<int> _rightFinalData = new List<int>();
|
||||||
|
|
||||||
// 表跟数据存储列表
|
// 表跟数据存储列表
|
||||||
public List<dynamic> DataList = new List<dynamic>();
|
public List<dynamic> DataList = new List<dynamic>();
|
||||||
|
|
||||||
@@ -54,7 +60,6 @@ namespace 头罩视野.Views
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
InitLightPositions();
|
InitLightPositions();
|
||||||
System.Diagnostics.Debug.WriteLine("页面加载了!111111111");
|
|
||||||
_timer = InitDispatcherTimer();
|
_timer = InitDispatcherTimer();
|
||||||
// 2. 初始化定时器:500毫秒 执行一次
|
// 2. 初始化定时器:500毫秒 执行一次
|
||||||
|
|
||||||
@@ -116,32 +121,7 @@ namespace 头罩视野.Views
|
|||||||
testTimer.Stop();
|
testTimer.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
////测试btn 测试按钮:读取数据,存入共享列表
|
|
||||||
//private async void Button_Click_Test(object sender, RoutedEventArgs e)
|
|
||||||
//{
|
|
||||||
|
|
||||||
// ma.BtnClickFunction(Function.ButtonType.复归型, 100);
|
|
||||||
// ButtonTest.Content = "测试中....";
|
|
||||||
// _isTesting = true;
|
|
||||||
// testTimer.Start();
|
|
||||||
// bool isLeftOnly = btnLeft.Content.ToString() == "左眼开" && btnRight.Content.ToString() == "右眼关";
|
|
||||||
// bool isRightOnly = btnRight.Content.ToString() == "右眼开" && btnLeft.Content.ToString() == "左眼关";
|
|
||||||
// bool isBinocular = btnLeft.Content.ToString() == "左眼开" && btnRight.Content.ToString() == "右眼开";
|
|
||||||
// if (isLeftOnly)
|
|
||||||
// {
|
|
||||||
// _leftTotalArea = 0;
|
|
||||||
// }
|
|
||||||
// else if (isRightOnly)
|
|
||||||
// {
|
|
||||||
// _rightTotalArea = 0;
|
|
||||||
|
|
||||||
// }
|
|
||||||
// else if (isBinocular)
|
|
||||||
// {
|
|
||||||
// _binocularTotalArea = 0;
|
|
||||||
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
private async void Button_Click_Test(object sender, RoutedEventArgs e)
|
private async void Button_Click_Test(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (_isTesting)
|
if (_isTesting)
|
||||||
@@ -171,11 +151,17 @@ namespace 头罩视野.Views
|
|||||||
//_binocularTotalArea = 0;
|
//_binocularTotalArea = 0;
|
||||||
//maxBottomViewAngle = 0;
|
//maxBottomViewAngle = 0;
|
||||||
|
|
||||||
|
// 初始化:全部设为0(灭)
|
||||||
|
_leftFinalData = Enumerable.Repeat(0, 243).ToList();
|
||||||
|
_rightFinalData = Enumerable.Repeat(0, 243).ToList();
|
||||||
|
|
||||||
|
// 面积也清空
|
||||||
|
|
||||||
|
|
||||||
isLeftOnly = btnLeft.Content.ToString() == "左眼关" && btnRight.Content.ToString() == "右眼开";
|
isLeftOnly = btnLeft.Content.ToString() == "左眼关" && btnRight.Content.ToString() == "右眼开";
|
||||||
isRightOnly = btnLeft.Content.ToString() == "左眼开" && btnRight.Content.ToString() == "右眼关";
|
isRightOnly = btnLeft.Content.ToString() == "左眼开" && btnRight.Content.ToString() == "右眼关";
|
||||||
isBinocular = btnLeft.Content.ToString() == "左眼关" && btnRight.Content.ToString() == "右眼关";
|
isBinocular = btnLeft.Content.ToString() == "左眼关" && btnRight.Content.ToString() == "右眼关";
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine("start11111");
|
|
||||||
await calCurrentangle();
|
await calCurrentangle();
|
||||||
|
|
||||||
_nextTargetAngle = _stepAngle;
|
_nextTargetAngle = _stepAngle;
|
||||||
@@ -192,19 +178,13 @@ namespace 头罩视野.Views
|
|||||||
{
|
{
|
||||||
zmsyarea.Text = _leftTotalArea.ToString("0"); // 左目
|
zmsyarea.Text = _leftTotalArea.ToString("0"); // 左目
|
||||||
ymsyarea.Text = _rightTotalArea.ToString("0"); // 右目
|
ymsyarea.Text = _rightTotalArea.ToString("0"); // 右目
|
||||||
smsyarea.Text = _binocularTotalArea.ToString("0"); // 双目
|
|
||||||
|
|
||||||
// 3. 计算空白区视野面积(双目时才有效)
|
|
||||||
//if (double.TryParse(smsyarea.Text, out double binocularTotalArea))
|
// 计算下方视野°
|
||||||
//{
|
|
||||||
// double blankArea = GetArea.GetBlankViewArea(binocularTotalArea);
|
|
||||||
// kbsyarea.Text = blankArea.ToString("0.00"); // 空白视野面积
|
|
||||||
//}
|
|
||||||
//// 4. 计算下方视野面积
|
|
||||||
int botViAnInt = (int)Math.Round(BotViAn);
|
int botViAnInt = (int)Math.Round(BotViAn);
|
||||||
xfsyarea.Text = botViAnInt.ToString("0"); // 下方视野
|
xfsyarea.Text = botViAnInt.ToString("0"); // 下方视野
|
||||||
|
|
||||||
// 5. 计算视野保存率(双目)根据左右目视野不同算不同的值
|
// 计算视野保存率(双目)根据左右目视野不同,算不同的值
|
||||||
|
|
||||||
if (isLeftOnly)
|
if (isLeftOnly)
|
||||||
{
|
{
|
||||||
@@ -222,15 +202,17 @@ namespace 头罩视野.Views
|
|||||||
double blankArea = GetArea.GetBlankViewArea(_rightTotalArea);
|
double blankArea = GetArea.GetBlankViewArea(_rightTotalArea);
|
||||||
kbsyarea.Text = blankArea.ToString("0"); // 空白视野面积
|
kbsyarea.Text = blankArea.ToString("0"); // 空白视野面积
|
||||||
}
|
}
|
||||||
|
if (_leftFinalData != null && _leftFinalData.Count > 0 &&_rightFinalData != null && _rightFinalData.Count > 0)
|
||||||
else if (isBinocular)
|
|
||||||
{
|
{
|
||||||
|
// ✅ 传值调用:把左右眼最终数据传给方法
|
||||||
|
_binocularTotalArea = GetArea.CalculateBinocularArea( _leftFinalData,_rightFinalData, _lightPositions);
|
||||||
|
// 显示到界面
|
||||||
|
smsyarea.Text = _binocularTotalArea.ToString("0.00");
|
||||||
|
|
||||||
|
// 视野保存率(如果需要)
|
||||||
double binocularRateD = GetArea.CalcVisionRate(_binocularTotalArea);
|
double binocularRateD = GetArea.CalcVisionRate(_binocularTotalArea);
|
||||||
sybhl.Text = binocularRateD.ToString("0"); // 视野保存率
|
sybhl.Text = binocularRateD.ToString("0.0"); // 视野保存率
|
||||||
double blankArea = GetArea.GetBlankViewArea(_binocularTotalArea);
|
|
||||||
kbsyarea.Text = blankArea.ToString("0"); // 空白视野面积
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//if (double.TryParse(smsyarea.Text, out double totalAreaForRate))
|
//if (double.TryParse(smsyarea.Text, out double totalAreaForRate))
|
||||||
//{
|
//{
|
||||||
@@ -241,6 +223,7 @@ namespace 头罩视野.Views
|
|||||||
ShowAreaData();
|
ShowAreaData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//读取灯泡的数据
|
//读取灯泡的数据
|
||||||
|
|
||||||
private async Task ReadLightBarData()
|
private async Task ReadLightBarData()
|
||||||
@@ -335,11 +318,28 @@ namespace 头罩视野.Views
|
|||||||
|
|
||||||
// 5. 根据当前测试模式(左眼/右眼/双目),累加面积
|
// 5. 根据当前测试模式(左眼/右眼/双目),累加面积
|
||||||
if (isLeftOnly)
|
if (isLeftOnly)
|
||||||
|
{
|
||||||
_leftTotalArea += singleArea;
|
_leftTotalArea += singleArea;
|
||||||
|
// 实时合并左眼:只要亮过一次,就永久亮
|
||||||
|
for (int i = 0; i < 243; i++)
|
||||||
|
{
|
||||||
|
if (lightData[i] == 1)
|
||||||
|
_leftFinalData[i] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (isRightOnly)
|
else if (isRightOnly)
|
||||||
|
{
|
||||||
_rightTotalArea += singleArea;
|
_rightTotalArea += singleArea;
|
||||||
else if (isBinocular)
|
// 实时合并右眼
|
||||||
_binocularTotalArea += singleArea;
|
for (int i = 0; i < 243; i++)
|
||||||
|
{
|
||||||
|
if (lightData[i] == 1)
|
||||||
|
_rightFinalData[i] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 6. 更新下方视野的最大值(取所有角度中最大的)
|
// 6. 更新下方视野的最大值(取所有角度中最大的)
|
||||||
if (bottomViewAngle > maxBottomViewAngle)
|
if (bottomViewAngle > maxBottomViewAngle)
|
||||||
@@ -698,11 +698,10 @@ namespace 头罩视野.Views
|
|||||||
private void Page_Loaded(object sender, RoutedEventArgs e)
|
private void Page_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine("页面加载了!112222222");
|
|
||||||
_timer.Start();
|
_timer.Start();
|
||||||
ma = new Function(_modbusMaster);
|
ma = new Function(_modbusMaster);
|
||||||
c = new DataChange();
|
c = new DataChange();
|
||||||
|
|
||||||
//zmsyarea.Text = "4.00"; // 左目
|
//zmsyarea.Text = "4.00"; // 左目
|
||||||
//smsyarea.Text = "5.00"; // 双目
|
//smsyarea.Text = "5.00"; // 双目
|
||||||
//kbsyarea.Text = "6.00"; // 空白
|
//kbsyarea.Text = "6.00"; // 空白
|
||||||
|
|||||||
Reference in New Issue
Block a user