首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误的BoundingBox维度提取pythonocc

错误的BoundingBox维度提取pythonocc
EN

Stack Overflow用户
提问于 2020-09-24 09:15:01
回答 1查看 92关注 0票数 1

我正在尝试从STP文件中提取框尺寸,它对一些样本有效,但不幸的是,对于其他样本,我得到了错误的提取,例如下面的压缩STP文件

https://github.com/tpaviot/pythonocc-demos/files/5272793/Test.zip

我得到了“x”的结果值: 6.802000200000001,但是正确的值是6.24,依此类推。

下面是我的代码

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2021-09-28 08:11:42

我刚刚遇到了同样的问题。

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

您也可以在code here中看到它。

这一差距似乎是通过在this function中放大而增加的。

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64038243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档