文档目录结构简洁化
This commit is contained in:
@@ -0,0 +1,286 @@
|
||||
# 分模算法改进总结
|
||||
|
||||
## 概述
|
||||
|
||||
本次改进实现了更合理的分模算法,使用传统几何方法计算分型面和分型线,同时预留了 AI 模型介入的接口。
|
||||
|
||||
## 主要改进
|
||||
|
||||
### 1. 分型面检测优化
|
||||
|
||||
#### 改进前
|
||||
- 固定使用 Z 方向作为分型方向
|
||||
- 分型面总是水平面(XY 平面)
|
||||
- 不考虑产品实际几何特征
|
||||
|
||||
#### 改进后
|
||||
实现三级检测策略:
|
||||
|
||||
```python
|
||||
def _detect_parting_surface(self, shape, analysis):
|
||||
"""
|
||||
优先级:
|
||||
1. AI 模型检测(如果已设置)
|
||||
2. 基于法向量分析的几何方法
|
||||
3. 简化方法(基于边界框,回退方案)
|
||||
"""
|
||||
```
|
||||
|
||||
**法向量分析** (`_analyze_face_normals`):
|
||||
- 统计所有面的法向量
|
||||
- 计算平均法向量作为最优分型方向
|
||||
- 自动适应产品几何特征
|
||||
|
||||
**代码位置**: [`mold_generator.py:637-684`](file:///d:/project/geMoldInsight/src/core/mold_generator.py#L637-L684)
|
||||
|
||||
### 2. 真实分型线计算
|
||||
|
||||
#### 改进前
|
||||
- 使用简化矩形(4 个点)
|
||||
- 不贴合产品实际轮廓
|
||||
|
||||
#### 改进后
|
||||
使用布尔运算求交线:
|
||||
|
||||
```python
|
||||
def _calculate_parting_line(self, shape, parting_surface):
|
||||
"""
|
||||
使用 BRepAlgoAPI_Section 计算产品与分型面的真实交线
|
||||
- 提取交线(边)
|
||||
- 沿边采样点(至少 10 个点)
|
||||
- 返回精确的分型线路径
|
||||
"""
|
||||
```
|
||||
|
||||
**代码位置**: [`mold_generator.py:706-758`](file:///d:/project/geMoldInsight/src/core/mold_generator.py#L706-L758)
|
||||
|
||||
### 3. AI 模型接口预留
|
||||
|
||||
#### 接口设计
|
||||
|
||||
添加了 AI 模型集成方法:
|
||||
|
||||
```python
|
||||
def set_ai_model(self, parting_detector=None, draft_analyzer=None):
|
||||
"""设置 AI 模型接口"""
|
||||
self.ai_parting_detector = parting_detector
|
||||
self.ai_draft_analyzer = draft_analyzer
|
||||
```
|
||||
|
||||
#### AI 模型能力
|
||||
|
||||
1. **分型面检测器** (`AIPartingSurfaceDetector`)
|
||||
- 分析产品 3D 几何
|
||||
- 预测最优分型面位置和方向
|
||||
- 识别倒扣(undercut)区域
|
||||
|
||||
2. **拔模分析器** (`AIDraftAnalyzer`)
|
||||
- 分析哪些面需要拔模
|
||||
- 预测最优拔模角度
|
||||
- 检测脱模干涉
|
||||
|
||||
3. **型腔布局优化器** (`AICavityLayoutOptimizer`)
|
||||
- 优化多型腔排列
|
||||
- 设计流道系统
|
||||
- 平衡材料流动
|
||||
|
||||
**代码位置**: [`ai_mold_assistant.py`](file:///d:/project/geMoldInsight/src/core/ai_mold_assistant.py)
|
||||
|
||||
#### 集成方式
|
||||
|
||||
```python
|
||||
from core.mold_generator import MoldCavityGenerator
|
||||
from core.ai_mold_assistant import AIPartingSurfaceDetector
|
||||
|
||||
# 创建 AI 模型
|
||||
parting_detector = AIPartingSurfaceDetector(model_path="models/parting_surface.pth")
|
||||
|
||||
# 设置到模具生成器
|
||||
generator = MoldCavityGenerator()
|
||||
generator.set_ai_model(parting_detector=parting_detector)
|
||||
|
||||
# 使用时会自动调用 AI 模型
|
||||
result = generator.generate_mold_cavities(product_shape)
|
||||
```
|
||||
|
||||
### 4. 拔模角处理改进
|
||||
|
||||
#### 改进前
|
||||
- 简化实现,直接返回原始形状
|
||||
- 记录警告日志
|
||||
|
||||
#### 改进后
|
||||
- 支持 AI 模型分析拔模
|
||||
- 使用几何方法计算拔模方向
|
||||
- 为完整实现预留接口(`BRepOffsetAPI_DraftAngle`)
|
||||
|
||||
**代码位置**: [`mold_generator.py:829-859`](file:///d:/project/geMoldInsight/src/core/mold_generator.py#L829-L859)
|
||||
|
||||
### 5. 分型线长度精确计算
|
||||
|
||||
#### 改进前
|
||||
```python
|
||||
def _calculate_parting_line_length(self, parting_line: List) -> float:
|
||||
return 250.0 # mm # 固定值
|
||||
```
|
||||
|
||||
#### 改进后
|
||||
```python
|
||||
def _calculate_parting_line_length(self, parting_line: List) -> float:
|
||||
"""计算折线总长度"""
|
||||
total_length = 0.0
|
||||
for i in range(1, len(parting_line)):
|
||||
p1 = np.array(parting_line[i-1])
|
||||
p2 = np.array(parting_line[i])
|
||||
total_length += np.linalg.norm(p2 - p1)
|
||||
return total_length
|
||||
```
|
||||
|
||||
**代码位置**: [`mold_generator.py:861-869`](file:///d:/project/geMoldInsight/src/core/mold_generator.py#L861-L869)
|
||||
|
||||
## 新增文件
|
||||
|
||||
### 1. `src/core/ai_mold_assistant.py`
|
||||
|
||||
AI 模型接口示例类:
|
||||
- `AIPartingSurfaceDetector` - 分型面检测器
|
||||
- `AIDraftAnalyzer` - 拔模分析器
|
||||
- `AICavityLayoutOptimizer` - 型腔布局优化器
|
||||
|
||||
### 2. `scripts/test_mold_splitting.py`
|
||||
|
||||
完整的分模算法测试脚本:
|
||||
- 测试简单长方体分模
|
||||
- 测试 STEP 文件分模
|
||||
- 测试 AI 模型接口
|
||||
- 测试分型线计算算法
|
||||
|
||||
### 3. `scripts/simple_test.py`
|
||||
|
||||
简化的测试脚本(用于快速验证)
|
||||
|
||||
## 使用示例
|
||||
|
||||
### 基本使用(几何方法)
|
||||
|
||||
```python
|
||||
from core.mold_generator import MoldCavityGenerator
|
||||
|
||||
# 创建模具生成器
|
||||
generator = MoldCavityGenerator(
|
||||
shrinkage_rate=0.005, # 0.5% 收缩率
|
||||
draft_angle=2.0, # 2 度拔模角
|
||||
material_density=1.05 # ABS 密度
|
||||
)
|
||||
|
||||
# 生成模具型腔
|
||||
result = generator.generate_mold_cavities(product_shape)
|
||||
|
||||
# 获取详细信息
|
||||
detailed_json = generator.generate_detailed_cavity_json(result)
|
||||
```
|
||||
|
||||
### 使用 AI 辅助
|
||||
|
||||
```python
|
||||
from core.mold_generator import MoldCavityGenerator
|
||||
from core.ai_mold_assistant import AIPartingSurfaceDetector
|
||||
|
||||
# 创建 AI 模型
|
||||
parting_detector = AIPartingSurfaceDetector(model_path="models/model.pth")
|
||||
|
||||
# 设置 AI 模型
|
||||
generator = MoldCavityGenerator()
|
||||
generator.set_ai_model(parting_detector=parting_detector)
|
||||
|
||||
# 使用时 AI 会自动介入
|
||||
result = generator.generate_mold_cavities(product_shape)
|
||||
```
|
||||
|
||||
## 技术细节
|
||||
|
||||
### 法向量分析算法
|
||||
|
||||
```python
|
||||
def _analyze_face_normals(self, shape):
|
||||
# 1. 遍历所有面
|
||||
for face in shape.faces:
|
||||
# 2. 获取面的法向量
|
||||
normal = surface.Plane().Position().Direction()
|
||||
face_normals.append(normal)
|
||||
|
||||
# 3. 计算平均法向量
|
||||
avg_normal = sum(face_normals) / len(face_normals)
|
||||
|
||||
# 4. 归一化
|
||||
return normalized(avg_normal)
|
||||
```
|
||||
|
||||
### 分型线计算流程
|
||||
|
||||
```
|
||||
产品形状 + 分型面
|
||||
↓
|
||||
BRepAlgoAPI_Section (布尔截面运算)
|
||||
↓
|
||||
提取交线 (TopExp_Explorer)
|
||||
↓
|
||||
沿边采样 (BRepAdaptor_Curve)
|
||||
↓
|
||||
点列表 [[x,y,z], ...]
|
||||
```
|
||||
|
||||
## 性能对比
|
||||
|
||||
| 功能 | 改进前 | 改进后 |
|
||||
|------|--------|--------|
|
||||
| 分型面方向 | 固定 Z 方向 | 自动适应产品几何 |
|
||||
| 分型线点数 | 4 点(矩形) | 10+ 点(真实轮廓) |
|
||||
| 分型线长度 | 固定 250mm | 精确计算 |
|
||||
| AI 集成 | 无 | 完整接口预留 |
|
||||
| 拔模分析 | 简化 | 支持 AI 和几何方法 |
|
||||
|
||||
## 后续优化方向
|
||||
|
||||
### 短期(无需 AI)
|
||||
1. 改进法向量计算精度(使用高斯权重)
|
||||
2. 优化分型面位置(考虑脱模方向)
|
||||
3. 完整实现拔模角处理(使用 `BRepOffsetAPI_DraftAngle`)
|
||||
|
||||
### 中期(机器学习)
|
||||
1. 收集模具设计案例数据
|
||||
2. 训练分型面识别模型(PointNet++)
|
||||
3. 集成到现有系统
|
||||
|
||||
### 长期(深度学习 + 仿真)
|
||||
1. 端到端模具生成
|
||||
2. 结合 Moldflow 物理仿真
|
||||
3. 数字孪生系统
|
||||
|
||||
## 代码变更总结
|
||||
|
||||
### 修改文件
|
||||
- `src/core/mold_generator.py` - 核心分模算法改进
|
||||
|
||||
### 新增文件
|
||||
- `src/core/ai_mold_assistant.py` - AI 模型接口
|
||||
- `scripts/test_mold_splitting.py` - 完整测试脚本
|
||||
- `scripts/simple_test.py` - 简化测试脚本
|
||||
|
||||
### 新增导入
|
||||
```python
|
||||
from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section
|
||||
from OCC.Core.BRepAdaptor import BRepAdaptor_Surface, BRepAdaptor_Curve
|
||||
from OCC.Core.TopExp import TopExp_Explorer
|
||||
from OCC.Core.TopAbs import TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX
|
||||
```
|
||||
|
||||
## 总结
|
||||
|
||||
本次改进实现了:
|
||||
1. ✅ **更合理的分型面检测** - 基于法向量分析,自动适应产品几何
|
||||
2. ✅ **真实的分型线计算** - 使用布尔运算求交线,不是简化矩形
|
||||
3. ✅ **AI 模型接口预留** - 可随时集成 AI 辅助功能
|
||||
4. ✅ **精确的参数计算** - 分型线长度、拔模方向等
|
||||
|
||||
所有改进都使用了 OpenCASCADE 的几何算法,保证了计算的准确性和可靠性。AI 接口的设计使得未来可以轻松集成深度学习模型,提升分模智能化水平。
|
||||
Reference in New Issue
Block a user