How can I determine which handle of a vtkLineWidget2 is active and get it's current position?

Hello!!!

I’m trying to use vtkLineWidget2 in such a way that the ends of the line “snap” to the nearest point under the cursor. Positioning a handle is easy enough, but I can’t figure out how to determine which handle is active?

The widget has a StartInteractionEvent, InteractionEvent and EndInteractionEvent which I’m listening to, but I can’t find any way to get the active end so that I can position it to the location of the nearest point.

Any help will be gratefully received.

Doug

I’m contrast to most other parts of VTK, these interaction widgets are not used very widely, probably mostly because they are both very limited (ad you noticed, API is missing for accessing basic information; but there are many other issues) and they are also very complex (the state is distributed between the widget and representation objects; and events are used to keep them in sync). So, most likely you will need to modify them to do what you need. You might be able to add some features by creating your own derived classes, but it is possible that you have to clone and modify them (and maybe you can try to contribute back your changes to VTK).

Thanks Andras,

Is the pattern of separating the widget from its representation the preferred approach in VTK? Or would I be better using the original vtkLineWidget as the base for modification?

Separation of widget (=logic) and representatiom (=GUI) is a useful concept. For example, it is necessary if you want to display a widget in all your views. It also allows several smaller, more cohesive classes than one big complex class. In our application (3D Slicer) we preserved this design, just got rid of the event-based synchronization (which is an unnecessary complication, unless you build a distributed system).

GUI development is always very complex and time-consuming, and it is even harder for 3D interactions. I would recommend to find a VTK-based free, open-source application framework that already provides these widgets (such as 3D Slicer for medical image computing, ParaView for general engineering/scientific visualization, etc) and extend/customize these.