Section: Visualization Toolkit Widget Classes
.SECTION User API A user would use this class as follows. \begin{verbatim} vtkWidgetSet *set = vtkWidgetSet::New(); vtkParallelopipedWidget *w1 = vtkParallelopipedWidget::New(); set->AddWidget(w1); w1->SetInteractor(axialRenderWindow->GetInteractor()); vtkParallelopipedWidget *w2 = vtkParallelopipedWidget::New(); set->AddWidget(w2); w2->SetInteractor(coronalRenderWindow->GetInteractor()); vtkParallelopipedWidget *w3 = vtkParallelopipedWidget::New(); set->AddWidget(w3); w3->SetInteractor(sagittalRenderWindow->GetInteractor()); set->SetEnabled(1); \end{verbatim}
.SECTION Motivation The motivation for this class is really to provide a usable API to tie together multiple widgets of the same kind. To enable this, subclasses of vtkAbstractWidget, must be written as follows: They will generally have callback methods mapped to some user interaction such as: \begin{verbatim} this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonPressEvent, vtkEvent::NoModifier, 0, 0, NULL, vtkPaintbrushWidget::BeginDrawStrokeEvent, this, vtkPaintbrushWidget::BeginDrawCallback); \end{verbatim} The callback invoked when the left button is pressed looks like: \begin{verbatim} void vtkPaintbrushWidget::BeginDrawCallback(vtkAbstractWidget *w) { vtkPaintbrushWidget *self = vtkPaintbrushWidget::SafeDownCast(w); self->WidgetSet->DispatchAction(self, &vtkPaintbrushWidget::BeginDrawAction); } \end{verbatim} The actual code for handling the drawing is written in the BeginDrawAction method. \begin{verbatim} void vtkPaintbrushWidget::BeginDrawAction( vtkPaintbrushWidget *dispatcher) { // Do stuff to draw... // Here dispatcher is the widget that was interacted with, the one that // dispatched an action to all the other widgets in its group. You may, if // necessary find it helpful to get parameters from it. // For instance for a ResizeAction: // if (this != dispatcher) // { // double *newsize = dispatcher->GetRepresentation()->GetSize(); // this->WidgetRep->SetSize(newsize); // } // else // { // this->WidgetRep->IncrementSizeByDelta(); // } } \end{verbatim}
To create an instance of class vtkWidgetSet, simply invoke its constructor as follows
obj = vtkWidgetSet
obj
is an instance of the vtkWidgetSet class.
string = obj.GetClassName ()
- Standard methods for a VTK class.
int = obj.IsA (string name)
- Standard methods for a VTK class.
vtkWidgetSet = obj.NewInstance ()
- Standard methods for a VTK class.
vtkWidgetSet = obj.SafeDownCast (vtkObject o)
- Standard methods for a VTK class.
obj.SetEnabled (int )
- Method for activiating and deactiviating all widgets in the group.
obj.EnabledOn ()
- Method for activiating and deactiviating all widgets in the group.
obj.EnabledOff ()
- Method for activiating and deactiviating all widgets in the group.
obj.AddWidget (vtkAbstractWidget )
- Add a widget to the set.
obj.RemoveWidget (vtkAbstractWidget )
- Remove a widget from the set
int = obj.GetNumberOfWidgets ()
- Get number of widgets in the set.
vtkAbstractWidget = obj.GetNthWidget (int )
- Get the Nth widget in the set.