AIS_InteractiveContext::Erase not hiding displayed AIS_Shape

I have an AIS_InteractiveContext where I display some shapes as follows:

Handle(AIS_ColoredShape) displayedShape = new AIS_ColoredShape(transform.Shape());

context->Display(displayedShape, Standard_True);

As you can see, I have some custom Prs3d_Drawer objects for customizing the appearance of the shape.

I want to hide certain shapes in the model as follows:

AIS_ListOfInteractive objects;
AIS_ListIteratorOfListOfInteractive it;
for (it.Init(objects); it.More(); it.Next())
    Handle(AIS_InteractiveObject) obj = it.Value();

    if (shouldHide)
        context->Erase(obj, Standard_True);

However, the code above doesn't actually hide the corresponding shape like the description for AIS_InteractiveContext::Erase describes. I've tried this with and without the custom Prs3d_Drawer objects I'm using, and I've also tried to redraw/update the viewer and context with zero success.

AIS_InteractiveContext::Erase says "The object's presentations are simply flagged as invisible and therefore excluded from redrawing.". Is it possible that the actual presentations being used aren't linked to the context fully somehow? Am I missing something in how this function is supposed to work? 

Kirill Gavrilov's picture

Erase operation is pretty straight-forward, so there should be an error somewhere else in your code. It is difficult to deduce where problem may come from provided code snippet - I think that code snippet itself will work as expected being detached into dedicated sample.

If you are using an old OCCT, than problem might come from usage of Local Context (removed in up-to-date OCCT).

vinit View1
box b 1 2 3
explode b F
vdisplay -dispMode 1 b
vaspects b -subShapes b_1 b_2 -setColor RED
verase b
Ajith Subramanian's picture

Thanks for your reply. It did turn out to be an error in my code since I was displaying some shapes redundantly and it appeared as if AIS_InteractiveContext::Erase wasn't hiding the selected object since there were two instances of the same shape. :)