From 5982df60c49362f2c4f0931300af7974a241698d Mon Sep 17 00:00:00 2001 From: sladro Date: Sat, 20 Sep 2025 15:34:10 +0800 Subject: [PATCH] feat: implement actual volume percentage calculation for shell analysis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- CreoManager.cpp | 17 ++++++++++++++++- CreoManager.h | 6 +++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CreoManager.cpp b/CreoManager.cpp index 294e5b9..92d150c 100644 --- a/CreoManager.cpp +++ b/CreoManager.cpp @@ -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& 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(); diff --git a/CreoManager.h b/CreoManager.h index 6458858..bbf4a02 100644 --- a/CreoManager.h +++ b/CreoManager.h @@ -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);