BRepBndLib :: The corner coordinates of Bnd_Box obtained by Add are misaligned by about 15.


I use OpenCascade V7.4.0 for windows 32bit.

I want to know the maximum and minimum X, Y, Z coordinates of the model,
I tried to find the coordinates using BRepBndLib as below source.

    Bnd_Box bb;
    BRepBndLib::Add( shape, bb );
    bb.SetGap( 0.0 );
    gp_Pnt pntMin = bb.CornerMin();
    gp_Pnt pntMax = bb.CornerMax();

However, the output may be 15mm larger than the actual size.

checking, the coordinates are displayed correctly when the model is displayed once.
However, I do not want to display it due to the processing.

As a result of referring to the forums in the past, we changed BRepBndLib :: Add to BRepBndLib :: Add Optimal.
As a result, the 15mm error is gone.

I used it for a while with that modification.
But after cutting another model, I rotated it and acquired the maximum and minimum XYZ coordinates, and an error of 0.0001 occurred.

In this case, changing to BRepBndLib :: Add did not raise an error.

Even in the above two cases, I would like to be able to get the maximum, minimum X, Y, Z coordinates.
Is there any good way?

Best regards.

Kirill Gavrilov's picture

Check the documentation of BRepBndLib::Add():

The resulting bounding box may be somewhat larger than the object

So that this method is expected to return larger box, not only due to topological tolerance (which you are trying to eliminate by Bnd_Box::SetGap()), but also by rough algorithms applied on analytical geometry to get bounding box faster. Normally, larger bounding box returned by BRepBndLib::Add() is not an issue, because it is expected to be larger to a small extent, and because it is expected to be used in algorithms where bounding box is supplimentary (used in optimization structures).

BRepBndLib::AddOptimal() looks like more appropriate for calculating precise bounding box. I have some doubts if it is used often, so that BRepBndLib::Add() has probably lesser number of unknown bugs. You may note from implementation details, that it adds sub-boxes in different way than BRepBndLib::Add():

      aLocBox.Enlarge(P3d->Deflection() + Tol);
      Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
      aLocBox.Get(xmin, ymin, zmin, xmax, ymax, zmax);
      B.Update(xmin, ymin, zmin, xmax, ymax, zmax);

which practically means that Shape tolerance becomes integral part of final Bnd_Box, which cannot be eliminated by Bnd_Box::SetGap(0.0).

Both have flags to use triangulation to speed up bounding box calculations. In that case occuracy of triangulation stored inside of TopoDS_Shape dramatically affects result bounding box, and practically speaking BRepBndLib::AddOptimal() works almost the same as BRepBndLib::Add().

nobakazukoudai_158418's picture

Hello, Kirill.
Thank you for your reply.

I have one question.
Why do I get the coordinates correctly after displaying the model once in [MyCode]?

Best regards.

Kirill Gavrilov's picture

Because displaying the model needs creating a triangulation.