feat: implement actual volume percentage calculation for shell analysis

- Add GetComponentVolume() function to calculate component volumes using OTK API
- Add volume_percentage field to ShellAnalysisItem structure
- Calculate total assembly volume at analysis start
- Calculate each component's volume percentage during analysis
- Replace hardcoded 0.0 with actual volume percentages in results

Now each component shows its real volume contribution percentage instead of 0.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
sladro 2025-09-20 15:34:10 +08:00
parent 731fb259f5
commit 5982df60c4
2 changed files with 21 additions and 2 deletions

View File

@ -1608,6 +1608,11 @@ CreoManager::ShellAnalysisResult CreoManager::AnalyzeShellFeaturesEnhanced(const
return result;
}
// Calculate total assembly volume
pfcSolid_ptr assembly_solid = pfcSolid::cast(assembly);
pfcMassProperty_ptr total_mass_props = assembly_solid->GetMassProperty(nullptr);
double total_volume = total_mass_props->GetVolume();
// Execute multi-directional extreme value projection algorithm (now returns complete analysis data)
ProjectionAnalysisData analysisData = PerformMultiDirectionalProjectionAnalysis(assembly);
const std::unordered_set<int>& outerComponentIds = analysisData.outerComponentIds;
@ -1690,6 +1695,11 @@ CreoManager::ShellAnalysisResult CreoManager::AnalyzeShellFeaturesEnhanced(const
item.type = "COMPONENT";
item.feature_id = stableFeatureId; // Use stable feature ID
// Calculate component volume percentage
pfcSolid_ptr comp_solid = pfcSolid::cast(compModel);
double comp_volume = GetComponentVolume(comp_solid);
item.volume_percentage = (comp_volume / total_volume) * 100.0;
// Build full path including assembly hierarchy
try {
pfcModel_ptr currentModel = sessionInfo.session->GetCurrentModel();
@ -1813,7 +1823,7 @@ CreoManager::ShellAnalysisResult CreoManager::AnalyzeShellFeaturesEnhanced(const
deletion.type = item.type;
deletion.reason = item.reason;
deletion.confidence = item.confidence;
deletion.volume_reduction = 0.0; // Not calculated in projection analysis
deletion.volume_reduction = item.volume_percentage;
deletion.part_file = ""; // Component name is already in 'name'
deletion.part_path = item.path; // Use full component path
deletion.component_type = "COMPONENT";
@ -3199,6 +3209,11 @@ bool CreoManager::ComponentClassifier::IsSpecificInternalModel(const std::string
return false;
}
double CreoManager::GetComponentVolume(pfcSolid_ptr solid) {
pfcMassProperty_ptr mass_props = solid->GetMassProperty(nullptr);
return mass_props->GetVolume();
}
bool CreoManager::ComponentClassifier::IsLikelyInternal(const AABB& compAABB, const AABB& globalAABB) {
// Rule 1: Extremely small components (volume < 0.1% of total)
Vector3D compSize = compAABB.diagonal();

View File

@ -314,6 +314,7 @@ public:
std::string reason;
std::string path; // 组件完整路径
bool is_deletable = false;
double volume_percentage = 0.0; // Component volume percentage
};
struct ShellAnalysisResult {
@ -418,7 +419,10 @@ public:
// 会话信息获取
SessionInfo GetSessionInfo();
// Volume calculation
double GetComponentVolume(pfcSolid_ptr solid);
// 字符串转换辅助函数
std::string XStringToString(const xstring& xstr);