python - 错误的BoundingBox尺寸提取pythonocc
问题描述
我正在尝试从 STP 文件中提取框尺寸,它适用于一些示例,但不幸的是,我对其他示例的提取错误,例如下面的压缩 STP 文件
https://github.com/tpaviot/pythonocc-demos/files/5272793/Test.zip
我得到了“x”的结果值:6.802000200000001,但正确的值是 6.24,y 和 z 值以此类推。
这是我的代码
from future import print_function
from OCC.Extend.DataExchange import read_step_file
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.BRepBndLib import brepbndlib_Add
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.STEPControl import STEPControl_Reader
shapes = read_step_file('path/to/stpfile')
def read_stp_file(file_path):
step_reader = STEPControl_Reader()
status = step_reader.ReadFile(file_path)
if status == IFSelect_RetDone:
fails_only = False
step_reader.TransferRoots()
shape = step_reader.Shape(1)
return shape
else:
print("Error: can't read file.")
bbox = Bnd_Box()
use_mesh = True
mesh = BRepMesh_IncrementalMesh()
mesh.SetParallelDefault(True)
mesh.SetShape(shapes)
mesh.Perform()
assert mesh.IsDone()
brepbndlib_Add(shapes, bbox, use_mesh)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
print('x value : >>>> ', xmax - xmin)
解决方案
推荐阅读
- ios - 不存在捆绑 URL 确保您正在运行打包服务器
- flutter - 使fluttertext连续增长直到达到最大宽度,然后溢出
- python - 取一个 8 位数字并将它们分成两个 4 位数字
- mysql - MySql每小时选择第一行,接下来5分钟跳过行
- javascript - 在两个度数之间旋转箭头
- c# - 无法使用 C# 枚举 AD 组的成员
- javascript - Javascript if else 条件不返回所需的输出
- python - 想要将多次出现的#替换为//
- tomcat - 无法使用 manager-gui 部署 WAR 文件
- python - 使用黄金价格数据库的 Tensorflow 回归