Bounding boxes for trimmed surfaces?

I’ve noticed when using rhino3dm.File3dmObject.Geometry.GetBoundingBox() the box returned ignores surface trimming, and encompasses control points for curves.

I fear I’m asking a dumb question, but how can I work around this and get bounding boxes that don’t include control points / untrimmed portions of objects?

try shrinktrimmedsurfaces

This functionality isn’t available in stand alone rhinod3m. If you have a render mesh attached to your Brep, you can use the mesh’s bounding box to get a tighter bbox.

Hi @stevebaer , what about in Compute? Is it available there?

Yes, compute can handle this.

Thanks Steve. I can’t find it in Compute?

https://compute-rhino3d.readthedocs.io/en/latest/search.html?q=bounding&check_keywords=yes&area=default#

Hey @fergus.hudson, here are a few options…

import compute_rhino3d.Util
import compute_rhino3d.Mesh
from rhino3dm import File3dm, MeshType

# compute_rhino3d.Util.url = 'http://192.168.1.218:8080/'

f = File3dm.Read('trim.3dm')

brep = f.Objects[0].Geometry # get trimmed surface

# option 1. - bounding box from trimmed surface (ignores trim)

a = brep.GetBoundingBox()

# option 2. - bounding box from render mesh (might not be present)

mesh = brep.Faces[0].GetMesh(MeshType.Any)
b = mesh.GetBoundingBox()

# option 3. - use compute to mesh surface, then get bounding box (if you don't have a render mesh)

c = compute_rhino3d.Mesh.CreateFromBrep(brep)[0].GetBoundingBox()

n = File3dm()
n.Objects.AddBrep(brep)
n.Objects.AddBrep(a.ToBrep())
n.Objects.AddBrep(b.ToBrep())
n.Objects.AddBrep(c.ToBrep())
n.Write('box.3dm', 7)

print('Saved to box.3dm')

trim.3dm (2.9 MB)

In theory it should be possible to use compute to calculate the accurate bounding box directly, but I couldn’t see it. We’ll have to look into that!

1 Like

I just updated compute to properly handle computing an accurate bounding box for all geometry types. There was some code in compute.rhino3d that was not properly deserializing to the GeometryBase class from JSON.

The python client library has been updated on pypi.org at
https://pypi.org/project/compute-rhino3d/
and the docs on the next function can be found at
https://compute-rhino3d.readthedocs.io/en/latest/GeometryBase.html

I have also updated the C# client library available at
https://compute.rhino3d.com/sdk/csharp
The javascript client has also been updated at
https://www.npmjs.com/package/compute-rhino3d

I apologise for being dense @stevebaer but are you able to provide a 2 or 3 line example?

I cannot get it to work for me. compute_rhino3d.GeometryBase is abstract, and compute_rhino3d.Brep (for example) doesn’t implement GetBoundingBox( … ).

(rhino3dm.Brep does but that’s the untrimmed version)

Here you go, @fergus.hudson!

import compute_rhino3d.GeometryBase
from rhino3dm import BoundingBox

# [...] get `brep` from somewhere

# Brep derives from GeometryBase, so it can be passed to GetBoundingBox()
data = compute_rhino3d.GeometryBase.GetBoundingBox(brep, True)

# GetBoundingBox() returns a dict that isn't automatically deserialised, but
# we can easily construct a BoundingBox from the data if we need it
bbox = BoundingBox(data['Min']['X'], data['Min']['Y'], data['Min']['Z'], data['Max']['X'], data['Max']['Y'], data['Max']['Z'])

print(bbox)

@stevebaer, do we need a DecodeToBoundingBox and/or a DecodeToBox in Utils?

Probably

Thanks Will, much appreciated, that is what I was doing, I get this result: (my server is up and operating fine, I have v0.12.1 of the compute python library)

Ah wait - if I use compute.rhino3d.com instead of my server it works…

Yes, I fixed a bug in compute so you’ll probably need to update the code on your server

Hi @stevebaer, am I understanding correctly that the fix isn’t merged yet? Do you have an eta on when it will be?

@fergus.hudson, the “instances of abstract classes cannot be created” bug has already been fixed (see #129). Have you tried updating your server? If you used the bootstrap script to set up your server then there’s a handy update script that you can download and run.