Oversized BoundBox from STEP file

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
randy.heydon
Posts: 11
Joined: Mon Feb 17, 2014 11:10 pm

Oversized BoundBox from STEP file

Post by randy.heydon »

I'm experimenting with post-processing STEP files in FreeCAD, and have run into some unexpected behaviour. This file, generated with SolidWorks, loads fine except that the BoundBox is noticeably larger than the shape itself.

Code: Select all

>>> shape=Part.Shape()
>>> shape.read('step_files/milled_pocket.STEP')
...
Reading STEP file......
>>> shape.BoundBox.ZMin
-2.702513458301918
>>> min(v.Z for v in shape.Vertexes)
0.0
>>> shape.BoundBox.ZMax
12.227513458301917
>>> max(v.Z for v in shape.Vertexes)
6.35
This code shows that the vertical limits of the BoundBox are well beyond the outermost vertices of the part (and in case you aren't looking at the model right now, I assure you that the vertices are at the limits of the part). The Y limits are similarly off, but interestingly the X limits are correct. Most other files I've checked have the BoundBox tight around the part, so I don't know why this one is not.

Does anyone know why this discrepancy exists? Is there any way to correct for it? It is important for my application to correctly determine part thickness, so please let me know if you have any ideas to handle this.

Here are my specs. I'm using my distro's FreeCAD package, version 0.16.6712-3 right now.
OS: Linux
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.Unknown
Build type: Release
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 3.1.3
OCC version: 6.9.1
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Oversized BoundBox from STEP file

Post by wmayer »

Have a look at this blog: http://opencascade.blogspot.de/2009/04/ ... g-box.html
To avoid or at least reduce an oversized bbox create the tessellation of a shape beforehand. This mesh will be used to determine the bbox and thus should give much better results.
UR_
Veteran
Posts: 1355
Joined: Tue Jan 03, 2017 8:42 pm

Re: Oversized BoundBox from STEP file

Post by UR_ »

Testing this code:

Code: Select all

shape=Part.Shape()
shape.read("C:/Users/aio/Desktop/test.step")
shape.BoundBox.ZMin
Delievers:

Code: Select all

0.0

Screenshot:

Screenshot.png
Screenshot.png (10.33 KiB) Viewed 3150 times

Done with:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.12847 (Git)
Build type: Release
Branch: master
Hash: 4034851a5d2ed5c93a8ebedbf0ef40dab8700d94
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: German/Germany (de_DE)


Please note, there where significant changes in version 0.17 concerning step import.
Perhaps that's the reason.
UR_
Veteran
Posts: 1355
Joined: Tue Jan 03, 2017 8:42 pm

Re: Oversized BoundBox from STEP file

Post by UR_ »

wmayer wrote: Sun Dec 24, 2017 9:20 am ... thus should give much better results.
wmayer, you are right!!
There is a difference

Code: Select all

shape=Part.Shape()
shape.read("C:/Users/aio/Desktop/test.step")
shape.BoundBox
shape.tessellate(1)
shape.BoundBox

Code: Select all

BoundBox (-74.9277, -45.095, 0, 92.8518, 53.3672, 6.35)
.
.
.
BoundBox (-74.9277, -45.095, 0, 92.8518, 41.5887, 6.35)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Oversized BoundBox from STEP file

Post by DeepSOIC »

In Lattice2, I have a bounding box tool that computes bounding boxes not relying on tessellation. It gives precise answers... except that it's occasionally way out :oops:

It uses distToShape. So it is slow as a dead cow, especially for stuff like text shapes and gears.

code here: https://github.com/DeepSOIC/Lattice2/bl ... Box.py#L72
User avatar
Quaoar
Posts: 106
Joined: Thu Jul 27, 2017 11:56 am
Location: Nizhny Novgorod
Contact:

Re: Oversized BoundBox from STEP file

Post by Quaoar »

In OpenCascade, since release 7.1.0, there another bounding box called "optimal" (cannot say for sure right now as I writing from cafe). This latter one uses extrema internally and gives precise results so. However, it is reasonably slower than its imprecise counterpart. If I remember well, it is implemented in BRepBndLib::AddOptimal(). We use it in our projects and the results are quite nice.
FOSS CAD model inspection utility and prototyping framework: http://analysissitus.org
randy.heydon
Posts: 11
Joined: Mon Feb 17, 2014 11:10 pm

Re: Oversized BoundBox from STEP file

Post by randy.heydon »

Thanks for the suggestions everyone. For now I'll use the tessellate method; it looks accurate enough without having too much of a computational cost.

The weird thing about tessellate is that it generates a tessellation but shouldn't change the underlying part. Yet calling it is enough to correct the BoundBox on the part itself. Well I'm not complaining, it looks like it does the job.
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: Oversized BoundBox from STEP file

Post by easyw-fc »

Hi, is this 'AddOptimal' method available in FreeCAD? and is it exposed to python to get a more precise BBox?
Thanks
Maurice
User avatar
naxq0
Posts: 51
Joined: Wed Apr 25, 2018 7:45 am

Re: Oversized BoundBox from STEP file

Post by naxq0 »

easyw-fc wrote: Sun May 27, 2018 2:18 pm
Hi, is this 'AddOptimal' method available in FreeCAD? and is it exposed to python to get a more precise BBox?
Thanks
Maurice
That would definitely be a nice feature to add if its not already in FreeCAD
Post Reply