Does AIS_Shape alter the geometry of TopoDS_Shape ?

I have a TopoDS_Shape, which I am  displaying with this function:

void Display(TopoDS_Shape& bShape)

    Handle(AIS_Shape) ais = new AIS_Shape(bShape);
    anAIScontext->SetColor(ais, Quantity_NOC_YELLOW);
    anAIScontext->SetMaterial(ais, Graphic3d_NOM_GOLD, Standard_False);
    anAIScontext->Display(ais, Standard_False);

This works.

HOWEVER, I find the call  " Handle(AIS_Shape) ais = new AIS_Shape(bShape);" alters the geometry of bShape!

 I get the bounding box of bShape with:

    Bnd_Box aBounds;
    BRepBndLib::Add(bShape, aBounds);
    aBounds.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);

If  get the bounding box before calling my Display() function, then after calling it, I get different results!

The difference is not huge, but bigger than it should be , e.g aZmax is 20.000001 before  calling Display() ,and 20.003 after .

This surprises me a lot. I thought the "AIS_Shape(bShape)"  function would just copy data from bShape, not alter it.

I want to rely on the data in bShape, even after it has been displayed.

Can anyone explain what is going on?

Or am I misunderstanding how things work?



Roman Lygin's picture

Hi Jim,

The matter of the fact is that computation of a bounding box depends on whether the shape does or does not contain triangulation. When you display the AIS_Shape for the first time, apparently it does triangulate your shape (which did not have triangulation before that). So the results differ.

This effect is explained here -

With that, you could pre-triangulate your shape prior to calling bounding box computation (using BRepMesh_IncrementalMesh).

Ideally you might want to pre-triangulate with exact same parameters that will be used during the display and avoid re-triangulation inside displaying the AIS_Shape. For that you would need to disable automatic re-triangulation using Prs3d_Drawer::SetAutoTriangulation (false), e.g.:

anAISContext->DefaultDrawer()->SetAutoTriangulation (false),

or likewise per individual AIS_Shape.

However, for simplicity and if performance is not an concern, just trust the AIS to re-triangulate as needed during the display.

Hope this helps.


P.S. You should rather prefer using "void Display (const TopoDS_Shape& bShape)".

Jim Williams's picture

Thank you.

That's an excellent explanation.