Fri, 08/26/2016 - 06:42
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?
Thanks
Jim
Fri, 08/26/2016 - 08:51
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 - http://opencascade.blogspot.com/2009/04/all-inclusive-bounding-box.html.
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.
Roman
P.S. You should rather prefer using "void Display (const TopoDS_Shape& bShape)".
Sun, 08/28/2016 - 23:43
Thank you.
That's an excellent explanation.
Jim