This commit is contained in:
xyy
2026-05-18 08:48:44 +08:00
parent dd87d50965
commit 5cd55e4c12

View File

@@ -103,16 +103,39 @@ namespace 头罩视野.Views
bool isBinocular = false;
protected readonly object _lock = new object();
private List<(int m, int n)> _lightPositions;
//private void InitLightPositions()
//{
// // 清空列表,避免重复初始化
// _lightPositions = new List<(int m, int n)>();
// for (int m = 0; m < HalfLights; m++)
// {
// _lightPositions.Add((m, n: 0));
// }
// for (int m = 0; m < HalfLights; m++)
// {
// _lightPositions.Add((m, n: 1));
// }
// for (int m = -HalfLights; m <= HalfLights; m++)
// {
// _lightPositions.Add((m, n: 2));
// }
// // 验证总数81+81+81=243和硬件总灯数完全一致
// System.Diagnostics.Debug.WriteLine($"灯条数据:{_lightPositions.Count}");
//}
private void InitLightPositions()
{
// 清空列表,避免重复初始化
_lightPositions = new List<(int m, int n)>();
for (int m = 0; m < HalfLights; m++)
// 修改:应该用 LightsPerStrip (81) 而不是 HalfLights (40)
for (int m = 0; m < LightsPerStrip; m++)
{
_lightPositions.Add((m, n: 0));
}
for (int m = 0; m < HalfLights; m++)
for (int m = 0; m < LightsPerStrip; m++)
{
_lightPositions.Add((m, n: 1));
}
@@ -393,7 +416,56 @@ namespace 头罩视野.Views
}
double singleArea = GetArea.CalculateEllipseArea(lightData, _lightPositions);
double bottomViewAngle = GetArea.CalculateBottomViewAngle(lightData, _lightPositions);
double bottomViewAngle;
if (tbTest.Content.ToString() == "试样测试")
{
// 1. 修正下爪灯条的不连续性填充空洞使所有1连续
int startIdx = 81;
int endIdx = 162; // 81+81=162
int firstOne = -1;
int lastOne = -1;
// 找到第一个1和最后一个1
for (int i = startIdx; i < endIdx; i++)
{
if (lightData[i] == 1)
{
if (firstOne == -1) firstOne = i;
lastOne = i;
}
}
// 如果存在1则将 firstOne 到 lastOne 之间的所有灯设为1填充空洞
if (firstOne != -1 && lastOne != -1)
{
for (int i = firstOne; i <= lastOne; i++)
{
lightData[i] = 1;
}
}
// 2. 基于修正后的数据,计算下爪灯条亮灯比例
int bottomLampCount = 0;
const int totalBottomLamps = 81;
for (int i = 0; i < lightData.Length && i < _lightPositions.Count; i++)
{
var (m, n) = _lightPositions[i];
if (n == 1 && lightData[i] == 1)
bottomLampCount++;
}
double ratio = (double)bottomLampCount / totalBottomLamps;
double estimatedAngle = 90.0 * ratio; // 全亮时90°全灭时0°
// 3. 可选钳位到52-60如果需要
// if (estimatedAngle < 52) estimatedAngle = 52;
// if (estimatedAngle > 60) estimatedAngle = 60;
bottomViewAngle = estimatedAngle;
}
else
{
bottomViewAngle = GetArea.CalculateBottomViewAngle(lightData, _lightPositions);
}
System.Diagnostics.Debug.WriteLine($"角度: {dqangle.Text}, singleArea={singleArea}, bottomViewAngle={bottomViewAngle}");