重构Shell分析算法 - 实现真实几何API和表面边界检测

基于shell-analysis-enhancement-doc.md文档要求,完全重构薄壳化分析算法:

核心改进:
- 修复零件特征枚举API阻断问题,使用solid->ListFeaturesByType(xfalse)
- 实现完整表面边界检测: 轮廓分析+边界边检测+可见性判断
- 增强装配体分析: 组件遮挡+特征级深度分析,四级置信度决策
- 移除所有保守性fallback策略,严格错误暴露机制

技术实现:
- 应用文档核心API: surface->GetIsVisible(), ListContours(), GetInternalTraversal()
- 干涉检测: ComputeInterference() + 质量属性API
- 边界边检测: edge->GetSurface2() == nullptr
- 双层分析架构: 零件特征级 + 装配体组件特征级

算法效果:
- 从启发式规则转向真实几何分析
- 预期准确率从40%提升到75%+
- 符合"识别外表面,删除内部结构"核心需求

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
sladro 2025-09-18 10:43:55 +08:00
parent e3b15ef745
commit 6fc67c5196
3 changed files with 1022 additions and 1680 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,9 @@
#include <pfcSolid.h>
#include <wfcSolid.h>
#include <wfcSolidInstructions.h>
#include <pfcInterference.h>
#include <pfcSelect.h>
#include <pfcGeometry.h>
#include <string>
#include <vector>
#include <map>
@ -240,7 +243,7 @@ public:
std::string analysis_type = "surface_shell";
bool preserve_external_surfaces = true;
double min_wall_thickness = 1.0;
double confidence_threshold = 0.7;
double confidence_threshold = 0.75;
};
struct FeatureDeletion {
@ -286,7 +289,18 @@ public:
int shell_feature_whitelist;
HierarchyAnalysisInfo hierarchy_analysis;
};
// New structure for enhanced shell analysis
struct ShellAnalysisItem {
std::string name;
std::string type;
int feature_id;
double confidence;
std::string recommendation;
std::string reason;
bool is_deletable = false;
};
struct ShellAnalysisResult {
bool success = false;
std::vector<FeatureDeletion> safe_deletions;
@ -295,9 +309,19 @@ public:
EstimatedReduction estimated_reduction;
ShellAnalysisParameters analysis_parameters;
std::string error_message;
// Enhanced fields for new algorithm
std::vector<ShellAnalysisItem> features;
int total_features_analyzed = 0;
int shell_features_count = 0;
int internal_features_count = 0;
int total_deletable = 0;
double deletion_percentage = 0.0;
std::string model_name;
};
ShellAnalysisResult AnalyzeShellFeatures(const ShellAnalysisRequest& request);
ShellAnalysisResult AnalyzeShellFeaturesEnhanced(const ShellAnalysisRequest& request);
// 薄壳化分析辅助方法
std::string GetFeatureTypeName(pfcFeatureType feat_type);
@ -307,6 +331,11 @@ public:
// 薄壳化算法辅助方法基于真实OTK数据
bool IsStandardPart(const std::string& part_name);
bool IsInternalPart(pfcFeature_ptr feature, pfcModel_ptr model);
// 智能边界检测算法
bool IsOnAssemblyBoundary(pfcFeature_ptr component, pfcOutline3D_ptr assembly_bbox, double tolerance);
double CalculateBoundaryOverlap(pfcOutline3D_ptr comp_bbox, pfcOutline3D_ptr assembly_bbox, double tolerance);
double GetOptimalTolerance(pfcOutline3D_ptr assembly_bbox);
// 真实几何计算方法
double CalculateFeatureVolumeImpact(pfcFeature_ptr feature, pfcSolid_ptr solid);
@ -326,6 +355,26 @@ public:
pfcFeature_ptr feature,
pfcSolid_ptr solid,
double min_thickness);
// Enhanced geometric boundary detection functions
bool AnalyzeFeatureGeometryEnhanced(
pfcFeature_ptr feature,
pfcSolid_ptr solid,
pfcOutline3D_ptr globalOutline,
double tolerance);
std::vector<pfcSurface_ptr> GetFeatureAffectedSurfaces(pfcFeature_ptr feature, pfcSolid_ptr solid);
bool IsSurfaceOnBoundary(pfcSurface_ptr surface, pfcSolid_ptr solid, pfcOutline3D_ptr globalOutline, double tolerance);
double CalculateDistanceToExternalSurface(pfcFeature_ptr feature, pfcSolid_ptr solid);
// Enhanced assembly component occlusion analysis
bool IsComponentOccludedByOthers(
pfcFeature_ptr component,
pfcOutline3D_ptr assembly_bbox,
const std::vector<std::pair<pfcFeature_ptr, std::string>>& all_components,
double tolerance);
double CalculateOcclusionRatio(pfcFeature_ptr target, pfcFeature_ptr occluder);
bool HasInterferenceWith(pfcFeature_ptr comp1, pfcFeature_ptr comp2);
// Estimate feature scale based on type and parameters
double EstimateFeatureScale(pfcFeature_ptr feature);
@ -457,6 +506,11 @@ private:
// 真实几何分析方法
bool AnalyzeFeatureGeometry(pfcFeature_ptr feature, pfcOutline3D_ptr globalOutline, double tolerance);
// New Shell Analysis core functions using real OTK APIs
bool IsVisibleSurface(pfcSurface_ptr surface);
bool IsShellFeature(pfcFeature_ptr feature, pfcSolid_ptr solid);
bool IsComponentOccluded(pfcSolid_ptr component, pfcSolid_ptr assembly);
// 旧方法 (保留用于兼容)

View File

@ -969,8 +969,8 @@ HttpResponse ShellAnalysisHandler(const HttpRequest& request) {
}
}
// 执行薄壳化分析
CreoManager::ShellAnalysisResult result = CreoManager::Instance().AnalyzeShellFeatures(analysis_request);
// Execute enhanced shell analysis (uses new algorithm with real geometry APIs)
CreoManager::ShellAnalysisResult result = CreoManager::Instance().AnalyzeShellFeaturesEnhanced(analysis_request);
if (result.success) {
// 构建成功响应