Add VTKWidget to an action in CamiTK
Warning
This is a work in progress. http://camitk.imag.fr/
VTK widgets are usefull for interactives actions. They can be easily add in CamiTK actions.
Creating a class for your widget¶
The first step is the creation of a class for the VTK widget. This class must inherit from the vtkCommand class.
Example with a vtkImplicitPlaneWidget :
1 2 3 4 5 6 7 8 | using namespace camitk; class PlaneWidget : public vtkCommand { public: PlaneWidget(); virtual ~PlaneWidget(); vtkSmartPointer<vtkImplicitPlaneWidget> planeWidget; // Your VTK Widget virtual void Execute(vtkObject *caller, unsigned long, void *); // Inherited from vtkCommand }; |
Adding your widget to your CamiTK action¶
Once your VTK widget is created, you need to add it in your header file :
1 2 3 4 5 6 7 8 9 | class YourAction : public camitk::Action { public: YourAction(ActionExtension *); // The constructor. virtual QWidget *getWidget(); // Method called when the action when the action is triggered (i.e. started). public slots: virtual ApplyStatus apply(); // Method called when the action is applied. private: PlaneWidget *widget; // Your widget }; |
Then, you must implement the getWidget() method :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | QWidget *YourAction::getWidget() { // Creating the clipping plane widget (the first time getWidget() is called) if(!widget->planeWidget) { vtkRenderWindowInteractor *iren = InteractiveViewer::get3DViewer()->getRendererWidget()->GetRenderWindow()->GetInteractor(); widget->planeWidget = vtkSmartPointer < vtkImplicitPlaneWidget >::New(); widget->planeWidget->SetInteractor(iren); // Set the properties of the widget ... widget->planeWidget->AddObserver(vtkCommand::EndInteractionEvent,this->widget); } return Action::getWidget(); } |