Before VTK interactively using interactive styles and adding listening events two ways to extend VTK interaction. Recently contacted the widget that VTK used to complete the interaction. Because physical parts are provided, the interaction is more user-friendly. VTK's widget class was redesigned from the VTk5.1. The separation of interaction and entity expression is realized. To create a VTK widget, you need to complete the following steps:
1 Instantiating Widgets
2 instantiating an appropriate geometric expression
3 You can add interaction to widge with the Add listener event (each widget component has default events and handling methods)
4 the part must be activated or the part will not appear in the window
The widget has its own widget event (vtkWidgetEvent.h). Some widget events are listed here:
NoEvent |
|
Select |
|
Endselect |
|
Delete |
|
Translate |
|
Endtranslate |
|
Scale |
|
Endscale |
|
Resize |
The conversion between Vtkevent and Widgetevent takes the Vtkwidgeteventtranslator class. The class can be obtained through the Geteventtranslator function.
There are two important functions in the Vtkwidgeteventtranslator class:
void Settranslation (unsigned long vtkevent, int modifier, char keycode, int repeatcount, const char *keysym, unsigned lon g widgetevent) int removetranslation (unsigned long vtkevent, int modifier, char keycode, int repeatcount, char *keysym)
One of the two functions is to add a vtkevent event and turn it into a widget event, and the other is to delete the event. All two functions have overloaded versions and only the longest are listed here. You can do this by using these two functions:
1. Delete the VTK event and WIDGWT event correspondence so that the widget event will not be monitored.
2. Change the correspondence between VTK events and widget events such as: vtkevent::leftbuttionpressevent corresponding widgetwvwnt::select can be changed to Vtkevent:: Keypressevent Correspondence Widgetwvwnt::select
The handler function for the Widgetevent event is a protected static function. The corresponding processing has been realized in the inside. The widgetevent is associated with the handler function within the general part through Vtkwidgetcallbackmapper.
For example: Select-------selectaction ();
Delete-------deleteaction ();
Widget->addobserver (Vtkcommand::interactionevent, seedcallback);
Use this function to add new events and callback functions to the part.
VTK:VTK Entity Interaction Widget