Fancy hilighting

I need to make faces of a shape have different attributes (color, transparency, ...). I achieved this by creating a custom Interactive Object class that inherits from AIS_Shape. In the Compute method I explore the shape and assign every face a different drawer before adding it. It was either that or displaying all its faces as different Interactive Objects.

I added an extra display mode to my custom Interactive Object that uses the same attributes, except for the transparency value (which is higher, making it translucent).

I open a local context and use it to select faces. What I want to achieve is that the whole object use the new display mode (AIS_InteractiveContext::SetDisplayMode doesn't seem to work in Local Context), but, when the mouse is on top of a face, the face is drawn opaque instead of having its wire drawn in another color and thicker line (default behavior). In other words: I want the hilighted face to be opaque while the other faces are translucent.

Recomputing the presentation works, but it's too slow. Adding a new AIS_Shape with the hilighted face as shape works too, but it's also too slow. SetHilightMode doesn't seem to do what I want.

Is there any mechanism I could use here to speed up the process?

I also take the opportunity to ask: what's the best way to change the Display Mode in Local Context?

Paul Jimenez's picture

I found a way, but if you have a better idea, don't hesitate to tell me.

The problem with the performance is caused by the OpenGL driver I'm using which makes use of GDI (Mesa3D). If at least I could find a way to compile GLDirect instead of GDI...

To cache the presentation I'm using a std::map. I defined an operator < for TopoDS_Shape that uses HashCode. It seems to work good so far, but I don't know how likely it is for two different shapes to produce the same hash code with upper set to std::numeric_limits::max().

I also found that it's not possible to change the display mode in local context. If I do it, it'll just ignore it. I'm not even trying to use it that way now.

Thanks in advance for any ideas.