【问题标题】:Wrong BoundingBox dimension extraction pythonocc错误的BoundingBox尺寸提取pythonocc
【发布时间】:2021-01-10 06:17:27
【问题描述】:

我正在尝试从 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)

【问题讨论】:

    标签: python 3d stp pythonocc


    【解决方案1】:

    我也遇到了同样的问题。

    我认为原因是,正如documentation of Get 也指出的那样,其中包含了某种差距。

    你也可以在code here看到它。

    似乎this function 中的 Enlarge 正在添加差距。

    由于只是在边界框周围添加了间隙,因此您可以通过GetGap() 获取它,然后从所有侧面再次将其删除。或者您使用SetGap 将其设置为0。

    我个人不知道为什么要添加这个差距,但BRepBndLib::Add 的文档甚至这么说:The resulting bounding box may be somewhat larger than the object.

    【讨论】:

      猜你喜欢
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      • 2019-05-25
      • 2018-06-12
      相关资源
      最近更新 更多