Reply

3D model bounding box

[ Edited ]

I had a need to calculate the bounding box of a 3D model and finally figured it out. Solid Edge ST6 introduced a new method, View.GetModelRange(), which gives us a min and max Vector3d from which we can calculate the bounding box. The screenshot below is a modified version of the OverlayAddin in the Samples for Solid Edge on CodePlex where I visually draw the bounding box with yellow lines using OpenGL. This helped me to be sure that I had the coordinates right. You might also notice that I've got some text overlayed on the screen. I'm using GDI+ for that, also in the OverlayAddin sample. The code I wrote to calculate the bounding box will be incorporated in the next release of the samples.

 

I don't get to do much cool Solid Edge stuff these days but I was pretty proud of myself on this one. Hopefully someone will find the code useful once I get it released. 

 

 

The code is not clean or optimized but here it is.

 

private void DrawBoundingBox(object pUnknownIGL)
{
    IGL gl = pUnknownIGL as IGL;

    if (gl == null) return;

    Vector3d min = new Vector3d();
    Vector3d max = new Vector3d();
    _view.GetModelRange(out min.X, out min.Y, out min.Z, out max.X, out max.Y, out max.Z);

    gl.glColor3f(1, 1, 0);
    gl.glLineWidth(2);
    gl.glPointSize(2);

    gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST);

    {
        gl.glBegin(GL.GL_LINE_LOOP);

        gl.glVertex3d(min.X, min.Y, max.Z);
        gl.glVertex3d(max.X, min.Y, max.Z);
        gl.glVertex3d(max.X, max.Y, max.Z);
        gl.glVertex3d(min.X, max.Y, max.Z);

        gl.glEnd();
    }

    {
        gl.glBegin(GL.GL_LINE_LOOP);

        gl.glVertex3d(min.X, min.Y, min.Z);
        gl.glVertex3d(max.X, min.Y, min.Z);
        gl.glVertex3d(max.X, max.Y, min.Z);
        gl.glVertex3d(min.X, max.Y, min.Z);

        gl.glEnd();
    }

    {
        gl.glBegin(GL.GL_LINES);

        gl.glVertex3d(min.X, min.Y, min.Z);
        gl.glVertex3d(min.X, min.Y, max.Z);

        gl.glVertex3d(max.X, max.Y, min.Z);
        gl.glVertex3d(max.X, max.Y, max.Z);

        gl.glVertex3d(min.X, max.Y, min.Z);
        gl.glVertex3d(min.X, max.Y, max.Z);

        gl.glVertex3d(max.X, min.Y, min.Z);
        gl.glVertex3d(max.X, min.Y, max.Z);

        gl.glEnd();
    }

    {
        gl.glColor3f(1, 0, 0);
        gl.glBegin(GL.GL_LINES);

        // Diagonal line between min & max points.
        gl.glVertex3d(min.X, min.Y, min.Z);
        gl.glVertex3d(max.X, max.Y, max.Z);

        gl.glEnd();
    }
}

 

Jason Newell
Applications Architect
www.jasonnewell.net
3 REPLIES

Re: 3D model bounding box

Hi, @jnewell

 

Is it possible to calculate bounding box by GetRange or GetRange?

However, from this page (for ST7), the remark shows that the edges of bounding box may not be parallel to the axes of the global coordinate system. But this remark is not in SDK reference for ST4. 

 

Thanks,

Guan

Re: 3D model bounding box

P.S.

My goal is not to obtain the minimum bounding box of the body (or shell). I just want to get a box

'contain' the body (or shell) to reduce intersection test (I have lots of small bodies or shells).

 

GetExactRange or GetRange seems to return the minimum x, y, z of the underlaying bounding box in its first parameter, and the maximum x, y, z in the second parameter. Is that how it works?

 

If so, a larger box defined by these 2 points may hold the inside bodies or shells, or not?

Re: 3D model bounding box

Without writing a some test code and displaying the coordinates with OpenGL like in the original post, I don't really have any way to know for sure. The sample addin that was on CodeProject got moved to GitHub. I don't mind giving it a shot but it will be the weekend before I can look at it.

Jason Newell
Applications Architect
www.jasonnewell.net