修改空轨的日志级别;
This commit is contained in:
parent
27b4e546a2
commit
1a959ceb9d
@ -180,7 +180,7 @@ public static class RailGeometryHelper
|
||||
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[空轨] 开始提取空轨中心线: {railModel.DisplayName}");
|
||||
LogManager.Debug($"[空轨] 开始提取空轨中心线: {railModel.DisplayName}");
|
||||
|
||||
// 1. 创建高度检测器实例
|
||||
var heightDetector = new ChannelHeightDetector();
|
||||
@ -217,7 +217,7 @@ public static class RailGeometryHelper
|
||||
pathPoints.Add(new Point3D(x, y, bottomHeight));
|
||||
}
|
||||
|
||||
LogManager.Info($"[空轨] 生成 {pathPoints.Count} 个路径点,总长度: {distance2D:F2}m");
|
||||
LogManager.Debug($"[空轨] 生成 {pathPoints.Count} 个路径点,总长度: {distance2D:F2}m");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@ -640,7 +640,7 @@ namespace NavisworksTransport
|
||||
return;
|
||||
}
|
||||
|
||||
LogManager.Info($"[空轨] 开始预计算 {items.Count} 个空轨模型的基准路径");
|
||||
LogManager.Debug($"[空轨] 开始预计算 {items.Count} 个空轨模型的基准路径");
|
||||
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
@ -655,7 +655,7 @@ namespace NavisworksTransport
|
||||
if (baselinePath != null && baselinePath.PathPoints != null && baselinePath.PathPoints.Count > 0)
|
||||
{
|
||||
successCount++;
|
||||
LogManager.Info($"[空轨] 成功提取模型 {item.DisplayName} 的基准路径,共 {baselinePath.PathPoints.Count} 个点,总长度 {baselinePath.TotalLength:F2} 模型单位");
|
||||
LogManager.Debug($"[空轨] 成功提取模型 {item.DisplayName} 的基准路径,共 {baselinePath.PathPoints.Count} 个点,总长度 {baselinePath.TotalLength:F2} 模型单位");
|
||||
|
||||
// 自动可视化基准路径
|
||||
var railModelId = $"{item.DisplayName}_{item.GetHashCode()}";
|
||||
|
||||
@ -165,7 +165,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[空轨] 步骤1: 开始提取完整基准路径: {railModel.DisplayName}");
|
||||
LogManager.Debug($"[空轨] 步骤1: 开始提取完整基准路径: {railModel.DisplayName}");
|
||||
|
||||
// 检查缓存
|
||||
var cacheKey = $"baseline_{railModel.DisplayName}_{railModel.GetHashCode()}";
|
||||
@ -174,19 +174,19 @@ namespace NavisworksTransport.PathPlanning
|
||||
// 检查缓存是否过期
|
||||
if (DateTime.Now - cachedPath.CreatedTime < _cacheValidDuration)
|
||||
{
|
||||
LogManager.Info($"[空轨] 使用缓存的基准路径");
|
||||
LogManager.Debug($"[空轨] 使用缓存的基准路径");
|
||||
return cachedPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Info($"[空轨] 基准路径缓存已过期,重新提取");
|
||||
LogManager.Debug($"[空轨] 基准路径缓存已过期,重新提取");
|
||||
_baselinePathCache.Remove(cacheKey);
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 OBB 方法提取基准路径
|
||||
var pathPoints = ExtractRailBottomCenterLineByOBB(railModel, samplingInterval);
|
||||
LogManager.Info($"[空轨] 生成 {pathPoints.Count} 个采样点");
|
||||
LogManager.Debug($"[空轨] 生成 {pathPoints.Count} 个采样点");
|
||||
|
||||
// 计算路径长度
|
||||
double totalLength = CalculatePathLength(pathPoints);
|
||||
@ -205,7 +205,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
// 加入缓存
|
||||
_baselinePathCache[cacheKey] = baselinePath;
|
||||
|
||||
LogManager.Info($"[空轨] 步骤1完成: 基准路径总长度 {totalLength:F2},{pathPoints.Count}个采样点");
|
||||
LogManager.Debug($"[空轨] 步骤1完成: 基准路径总长度 {totalLength:F2},{pathPoints.Count}个采样点");
|
||||
return baselinePath;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -239,7 +239,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
return false;
|
||||
}
|
||||
|
||||
LogManager.Info($"[空轨] 步骤3: 吸附点到基准路径,输入点=({inputPoint.X:F2}, {inputPoint.Y:F2}, {inputPoint.Z:F2})");
|
||||
LogManager.Debug($"[空轨] 步骤3: 吸附点到基准路径,输入点=({inputPoint.X:F2}, {inputPoint.Y:F2}, {inputPoint.Z:F2})");
|
||||
|
||||
Point3D nearestPoint = baselinePath.PathPoints[0];
|
||||
double minDistance = double.MaxValue;
|
||||
@ -259,7 +259,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
if (minDistance <= maxSnapDistance)
|
||||
{
|
||||
snappedPoint = nearestPoint;
|
||||
LogManager.Info($"[空轨] 步骤3完成: 吸附到 ({nearestPoint.X:F2}, {nearestPoint.Y:F2}, {nearestPoint.Z:F2}),距离 {minDistance:F2}");
|
||||
LogManager.Debug($"[空轨] 步骤3完成: 吸附到 ({nearestPoint.X:F2}, {nearestPoint.Y:F2}, {nearestPoint.Z:F2}),距离 {minDistance:F2}");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -291,9 +291,9 @@ namespace NavisworksTransport.PathPlanning
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[空轨] 步骤4: 提取路径段");
|
||||
LogManager.Info($"[空轨] 起点: ({snappedStartPoint.X:F2}, {snappedStartPoint.Y:F2}, {snappedStartPoint.Z:F2})");
|
||||
LogManager.Info($"[空轨] 终点: ({snappedEndPoint.X:F2}, {snappedEndPoint.Y:F2}, {snappedEndPoint.Z:F2})");
|
||||
LogManager.Debug($"[空轨] 步骤4: 提取路径段");
|
||||
LogManager.Debug($"[空轨] 起点: ({snappedStartPoint.X:F2}, {snappedStartPoint.Y:F2}, {snappedStartPoint.Z:F2})");
|
||||
LogManager.Debug($"[空轨] 终点: ({snappedEndPoint.X:F2}, {snappedEndPoint.Y:F2}, {snappedEndPoint.Z:F2})");
|
||||
|
||||
// 在基准路径中找到起点和终点的索引
|
||||
int startIndex = FindNearestPointIndex(baselinePath.PathPoints, snappedStartPoint);
|
||||
@ -304,7 +304,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
throw new InvalidOperationException("无法在基准路径中找到起点或终点");
|
||||
}
|
||||
|
||||
LogManager.Info($"[空轨] 起点索引: {startIndex}, 终点索引: {endIndex}");
|
||||
LogManager.Debug($"[空轨] 起点索引: {startIndex}, 终点索引: {endIndex}");
|
||||
|
||||
// 确保起点在终点之前
|
||||
if (startIndex > endIndex)
|
||||
@ -326,11 +326,11 @@ namespace NavisworksTransport.PathPlanning
|
||||
double baselineInterval = baselinePath.TotalLength / (baselinePath.PathPoints.Count - 1);
|
||||
if (samplingInterval > baselineInterval * 1.5)
|
||||
{
|
||||
LogManager.Info($"[空轨] 需要重采样: 基准间隔{baselineInterval:F3},目标间隔{samplingInterval:F3}");
|
||||
LogManager.Debug($"[空轨] 需要重采样: 基准间隔{baselineInterval:F3},目标间隔{samplingInterval:F3}");
|
||||
segmentPoints = ResamplePath(segmentPoints, samplingInterval);
|
||||
}
|
||||
|
||||
LogManager.Info($"[空轨] 步骤4完成: 提取了 {segmentPoints.Count} 个路径点");
|
||||
LogManager.Debug($"[空轨] 步骤4完成: 提取了 {segmentPoints.Count} 个路径点");
|
||||
return segmentPoints;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -387,7 +387,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
{
|
||||
_railCache.Clear();
|
||||
_baselinePathCache.Clear();
|
||||
LogManager.Info("[空轨] 缓存已清除");
|
||||
LogManager.Debug("[空轨] 缓存已清除");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -397,7 +397,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
{
|
||||
var cacheKey = $"baseline_{railModel.DisplayName}_{railModel.GetHashCode()}";
|
||||
_baselinePathCache.Remove(cacheKey);
|
||||
LogManager.Info($"[空轨] 已清除模型 {railModel.DisplayName} 的基准路径缓存");
|
||||
LogManager.Debug($"[空轨] 已清除模型 {railModel.DisplayName} 的基准路径缓存");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -437,7 +437,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
if (baselinePath != null && baselinePath.PathPoints != null && baselinePath.PathPoints.Count > 0)
|
||||
{
|
||||
successCount++;
|
||||
LogManager.Info($"[空轨] 成功提取模型 {item.DisplayName} 的基准路径,共 {baselinePath.PathPoints.Count} 个点");
|
||||
LogManager.Debug($"[空轨] 成功提取模型 {item.DisplayName} 的基准路径,共 {baselinePath.PathPoints.Count} 个点");
|
||||
|
||||
// 渲染基准路径
|
||||
var railModelId = $"{item.DisplayName}_{item.GetHashCode()}";
|
||||
@ -476,8 +476,8 @@ namespace NavisworksTransport.PathPlanning
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[空轨] 使用 OBB 方法提取下表面中心线: {railModel.DisplayName}");
|
||||
LogManager.Info($"[空轨] 采样间隔: {samplingInterval:F2}");
|
||||
LogManager.Debug($"[空轨] 使用 OBB 方法提取下表面中心线: {railModel.DisplayName}");
|
||||
LogManager.Debug($"[空轨] 采样间隔: {samplingInterval:F2}");
|
||||
|
||||
// 1. 计算 OBB 包围体
|
||||
var obb = ComputeOrientedBoundingBox(railModel);
|
||||
@ -487,8 +487,8 @@ namespace NavisworksTransport.PathPlanning
|
||||
var axisLength = obb.GetAxisLength(0);
|
||||
var principalAxisVector = principalAxis.ToVector3D();
|
||||
|
||||
LogManager.Info($"[空轨] OBB 主轴长度: {axisLength:F2}(模型单位)");
|
||||
LogManager.Info($"[空轨] 主轴方向: ({principalAxisVector.X:F3}, {principalAxisVector.Y:F3}, {principalAxisVector.Z:F3})");
|
||||
LogManager.Debug($"[空轨] OBB 主轴长度: {axisLength:F2}(模型单位)");
|
||||
LogManager.Debug($"[空轨] 主轴方向: ({principalAxisVector.X:F3}, {principalAxisVector.Y:F3}, {principalAxisVector.Z:F3})");
|
||||
|
||||
// 3. 计算中心线的起点和终点(下表面)
|
||||
var center = obb.Center;
|
||||
@ -510,7 +510,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
axisVector.Z * zAxisDirection.Z;
|
||||
absDotProducts[i - 1] = Math.Abs(dotProduct);
|
||||
|
||||
LogManager.Info($"[空轨] Axis {i} 与 Z 轴方向点积: {dotProduct:F3}, 绝对值: {absDotProducts[i - 1]:F3}");
|
||||
LogManager.Debug($"[空轨] Axis {i} 与 Z 轴方向点积: {dotProduct:F3}, 绝对值: {absDotProducts[i - 1]:F3}");
|
||||
}
|
||||
|
||||
// 选择点积绝对值最大的轴(最接近 Z 轴方向)
|
||||
@ -519,26 +519,26 @@ namespace NavisworksTransport.PathPlanning
|
||||
var downAxis = obb.GetAxis(downAxisIndex);
|
||||
var downAxisVector = downAxis.ToVector3D();
|
||||
|
||||
LogManager.Info($"[空轨] 下表面轴索引: {downAxisIndex}, 方向: ({downAxisVector.X:F3}, {downAxisVector.Y:F3}, {downAxisVector.Z:F3})");
|
||||
LogManager.Debug($"[空轨] 下表面轴索引: {downAxisIndex}, 方向: ({downAxisVector.X:F3}, {downAxisVector.Y:F3}, {downAxisVector.Z:F3})");
|
||||
|
||||
// 计算下表面偏移(使用半长度)
|
||||
var downHalfLength = obb.GetAxisLength(downAxisIndex) / 2;
|
||||
var downOffset = downAxisVector * downHalfLength;
|
||||
|
||||
LogManager.Info($"[空轨] 下表面偏移向量: ({downOffset.X:F3}, {downOffset.Y:F3}, {downOffset.Z:F3})");
|
||||
LogManager.Debug($"[空轨] 下表面偏移向量: ({downOffset.X:F3}, {downOffset.Y:F3}, {downOffset.Z:F3})");
|
||||
|
||||
// 中心线起点和终点
|
||||
var startCenter = center - direction * (axisLength / 2) + downOffset;
|
||||
var endCenter = center + direction * (axisLength / 2) + downOffset;
|
||||
|
||||
LogManager.Info($"[空轨] 中心线起点: ({startCenter.X:F2}, {startCenter.Y:F2}, {startCenter.Z:F2})");
|
||||
LogManager.Info($"[空轨] 中心线终点: ({endCenter.X:F2}, {endCenter.Y:F2}, {endCenter.Z:F2})");
|
||||
LogManager.Debug($"[空轨] 中心线起点: ({startCenter.X:F2}, {startCenter.Y:F2}, {startCenter.Z:F2})");
|
||||
LogManager.Debug($"[空轨] 中心线终点: ({endCenter.X:F2}, {endCenter.Y:F2}, {endCenter.Z:F2})");
|
||||
|
||||
// 4. 沿中心线采样
|
||||
var aabb = railModel.BoundingBox();
|
||||
var baseline = SampleLine(startCenter, endCenter, samplingInterval);
|
||||
|
||||
LogManager.Info($"[空轨] OBB 方法完成,生成 {baseline.Count} 个采样点");
|
||||
LogManager.Debug($"[空轨] OBB 方法完成,生成 {baseline.Count} 个采样点");
|
||||
|
||||
// 5. 使用射线投射获取下表面的精确高度(处理不平整的下表面)
|
||||
var triangles = GeometryHelper.ExtractTriangles(new[] { railModel });
|
||||
@ -571,7 +571,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Info($"[空轨] 射线投射调整: {successCount}/{baseline.Count} 个点已调整");
|
||||
LogManager.Debug($"[空轨] 射线投射调整: {successCount}/{baseline.Count} 个点已调整");
|
||||
|
||||
if (adjustedBaseline.Count >= 2)
|
||||
{
|
||||
@ -597,8 +597,8 @@ namespace NavisworksTransport.PathPlanning
|
||||
{
|
||||
// 输出 ModelItem 的 AABB 包围盒信息
|
||||
var aabb = modelItem.BoundingBox();
|
||||
LogManager.Info($"[空轨] AABB包围盒: Min({aabb.Min.X:F2}, {aabb.Min.Y:F2}, {aabb.Min.Z:F2}), Max({aabb.Max.X:F2}, {aabb.Max.Y:F2}, {aabb.Max.Z:F2})");
|
||||
LogManager.Info($"[空轨] AABB尺寸: X={aabb.Max.X - aabb.Min.X:F2}, Y={aabb.Max.Y - aabb.Min.Y:F2}, Z={aabb.Max.Z - aabb.Min.Z:F2}");
|
||||
LogManager.Debug($"[空轨] AABB包围盒: Min({aabb.Min.X:F2}, {aabb.Min.Y:F2}, {aabb.Min.Z:F2}), Max({aabb.Max.X:F2}, {aabb.Max.Y:F2}, {aabb.Max.Z:F2})");
|
||||
LogManager.Debug($"[空轨] AABB尺寸: X={aabb.Max.X - aabb.Min.X:F2}, Y={aabb.Max.Y - aabb.Min.Y:F2}, Z={aabb.Max.Z - aabb.Min.Z:F2}");
|
||||
|
||||
// 使用 GeometryHelper 提取三角形
|
||||
var triangles = GeometryHelper.ExtractTriangles(new[] { modelItem });
|
||||
@ -619,7 +619,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
throw new InvalidOperationException($"模型 {modelItem.DisplayName} 没有几何体顶点");
|
||||
}
|
||||
|
||||
LogManager.Info($"[空轨] 提取到 {points.Count} 个唯一顶点");
|
||||
LogManager.Debug($"[空轨] 提取到 {points.Count} 个唯一顶点");
|
||||
|
||||
// 使用 PCA 计算 OBB
|
||||
return ComputeOBBByPCA(points);
|
||||
@ -643,7 +643,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
points.Average(p => p.Z)
|
||||
);
|
||||
|
||||
LogManager.Info($"[空轨] 质心: ({centroid.X:F2}, {centroid.Y:F2}, {centroid.Z:F2})");
|
||||
LogManager.Debug($"[空轨] 质心: ({centroid.X:F2}, {centroid.Y:F2}, {centroid.Z:F2})");
|
||||
|
||||
// 2. 计算协方差矩阵
|
||||
double covXX = 0, covYY = 0, covZZ = 0;
|
||||
@ -687,7 +687,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
sortedEigenvectors[i] = eigenvectors[sortedIndices[i]];
|
||||
}
|
||||
|
||||
LogManager.Info($"[空轨] OBB特征值(降序): {sortedEigenvalues[0]:F4}, {sortedEigenvalues[1]:F4}, {sortedEigenvalues[2]:F4}");
|
||||
LogManager.Debug($"[空轨] OBB特征值(降序): {sortedEigenvalues[0]:F4}, {sortedEigenvalues[1]:F4}, {sortedEigenvalues[2]:F4}");
|
||||
|
||||
// 5. 将点转换到主轴坐标系
|
||||
var axes = sortedEigenvectors;
|
||||
@ -714,7 +714,7 @@ namespace NavisworksTransport.PathPlanning
|
||||
var minZ = projectedPoints.Min(p => p.Z);
|
||||
var maxZ = projectedPoints.Max(p => p.Z);
|
||||
|
||||
LogManager.Info($"[空轨] 投影范围: Axis0=[{minX:F2}, {maxX:F2}], Axis1=[{minY:F2}, {maxY:F2}], Axis2=[{minZ:F2}, {maxZ:F2}]");
|
||||
LogManager.Debug($"[空轨] 投影范围: Axis0=[{minX:F2}, {maxX:F2}], Axis1=[{minY:F2}, {maxY:F2}], Axis2=[{minZ:F2}, {maxZ:F2}]");
|
||||
|
||||
// 7. 创建 OBB(使用投影范围的中点作为中心,而不是质心)
|
||||
var obbCenter = new Point3D(
|
||||
@ -740,15 +740,15 @@ namespace NavisworksTransport.PathPlanning
|
||||
|
||||
};
|
||||
|
||||
LogManager.Info($"[空轨] OBB各轴长度(模型单位): {obb.GetAxisLength(0):F2}, {obb.GetAxisLength(1):F2}, {obb.GetAxisLength(2):F2}");
|
||||
LogManager.Debug($"[空轨] OBB各轴长度(模型单位): {obb.GetAxisLength(0):F2}, {obb.GetAxisLength(1):F2}, {obb.GetAxisLength(2):F2}");
|
||||
|
||||
// 输出 OBB 中心和轴方向
|
||||
LogManager.Info($"[空轨] OBB中心: ({obb.Center.X:F2}, {obb.Center.Y:F2}, {obb.Center.Z:F2})");
|
||||
LogManager.Debug($"[空轨] OBB中心: ({obb.Center.X:F2}, {obb.Center.Y:F2}, {obb.Center.Z:F2})");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
var axis = obb.GetAxis(i);
|
||||
var axisVector = axis.ToVector3D();
|
||||
LogManager.Info($"[空轨] Axis {i} 方向: ({axisVector.X:F3}, {axisVector.Y:F3}, {axisVector.Z:F3}), 长度: {obb.GetAxisLength(i):F2}");
|
||||
LogManager.Debug($"[空轨] Axis {i} 方向: ({axisVector.X:F3}, {axisVector.Y:F3}, {axisVector.Z:F3}), 长度: {obb.GetAxisLength(i):F2}");
|
||||
}
|
||||
|
||||
return obb;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user