Display Mode 2

Hello all

when I set the displaymode=2 on an ais_shape I get a dotted line around the dimensions of TopoDS_Shape.
when I increase the dimensions of the TopoDS_Shape the dotted outline is updated correct - so far, so good.

but if I make a dimension of the TopoDS_Shape smaller, for example the length, the dotted line is not updated at all. But the selection is correct as you can see on the attached picture.

Any help is appreciated!

Attachments: 
Daniel Duesentrieb's picture

I bring this up again. I spend now many hours try to fix this. it becomes a real problem now.

let me explain again:

ais_shape, showing a BRepPrimAPI_MakeBox... and with displaymode (dm) 1: 
when I change the dimensions of the shap and redisplay all is correct displayed. I can go larder and smaller no problem at all, in all display modes BUT 2

if I switch ONCE to display mode 2, and i increasy the size, all is good. but I can go smaller anymore then the size i had when switching to dm 2. 

it is like in dm2 it only updates when it is increasing but not decreasing. This must be a bug.

I tried everything:

//m_occView->context()->Erase(m_aisMain, Standard_False);
//m_occView->context()->Display(m_aisMain, Standard_True);
//m_occView->context()->Redisplay(m_aisMain, Standard_True);

m_aisMain->UnsetAttributes(); // Clears cached visual attributes
m_aisMain->SetToUpdate(); // Marks the shape as needing a full update
m_occView->context()->Redisplay(m_aisMain,       true, true);

m_occView->getView()->Invalidate(); // Marks everything as needing a redraw
m_occView->getView()->Update();

m_occView->context()->UpdateCurrentViewer();

nothing works

I so need help here.

Thanks!

Daniel Duesentrieb's picture
Bnd_Box bbox = m_aisDisplay->BoundingBox(); // Get the bounding box

bbox is only accurate updated if it gets bigger

BRepBndLib::AddOptimal(m_aisDisplay->Shape(), bbox);

this always works correct

m_aisDisplay->BoundingBox().CornerMax().SetXYZ(bbox.CornerMax().XYZ());
m_aisDisplay->BoundingBox().CornerMin().SetXYZ(bbox.CornerMin().XYZ());

was hoping i can overwrite but this doesn't work

now I am out of ideas

gkv311 n's picture

AIS_Shape::Compute() for display mode 2 displays bounding box of a shape returned by AIS_Shape::BoundingBox().

If you'll take a look at AIS_Shape::BoundingBox() implementation, you'll see that bounding box is cached in myBB and updated only when flag myCompBB is changed:

  if(myCompBB) {
    BRepBndLib::Add (myshape, myBB, false);
    myCompBB = Standard_False;
  }

and the only place where this flag is changed is AIS_Shape::SetShape():

  void SetShape (const TopoDS_Shape& theShape)
  {
    myshape  = theShape;
    myCompBB = Standard_True;
  }

Neither of the methods resets bounding box (myBB.SetVoid() or similar), hence it is only expanded, which is indeed a bug. You may file a bugfix to OCCT or workaround bug by clearing myBB on your own or implementing ::Compute() at application level.

Anyway, if you really want to display box around the shape, then overriding ::Compute() and displaying oriented bounding box BRepBndLib::AddOBB() instead of AABB might look better to user.

Daniel Duesentrieb's picture

Thank you!

Not sure if I have to do something now. Report that bug? Could you do this and I just wait until it is fixed?

Dmitrii Pasukhin's picture
Daniel Duesentrieb's picture

great news - thanks!

gkv311 n's picture

Test case:

pload MODELING VISUALIZATION
box b 100 200 300
vinit View1
vdisplay b -dispMode 2
# OK
box b 10 200 300
vdisplay b -dispMode 2
# KO - bounding box is not shrunk

Possible fix:

Subject: [PATCH] Visualization, AIS_Shape::BoundingBox() - reset bounding box
 before adding a shape to it

---
 src/AIS/AIS_Shape.cxx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx
index eb9e7f68e7..ceb4d863dd 100644
--- a/src/AIS/AIS_Shape.cxx
+++ b/src/AIS/AIS_Shape.cxx
@@ -792,7 +792,9 @@ const Bnd_Box& AIS_Shape::BoundingBox()
     return myBB;
   }

-  if(myCompBB) {
+  if (myCompBB)
+  {
+    myBB.SetVoid();
     BRepBndLib::Add (myshape, myBB, false);
     myCompBB = Standard_False;
   }
--