diff --git a/头罩视野slove/头罩视野/Views/PageTest.xaml.cs b/头罩视野slove/头罩视野/Views/PageTest.xaml.cs index d33d5b0..6eb09d4 100644 --- a/头罩视野slove/头罩视野/Views/PageTest.xaml.cs +++ b/头罩视野slove/头罩视野/Views/PageTest.xaml.cs @@ -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}");