[vtkusers] Invoke "Interactor"-Event to vtkSphereWidget
Rocco Gasteiger
post at rocco-gasteiger.de
Mon Jun 14 04:35:59 EDT 2010
Hi Karthik,
Thank you for your fast respond. I invoke the Render()-call in several ways
but it was not successful.
I tried the render call on the interactor of the widget as well as with the
GetCurrentRenderer-method of the widget itself. But it doesn't help. I have
to press the i-key again.
In my code below I added an observer to the widget renderer, listening to
the vtkCommand::Start/EndEvent. If I called Render() in the associated
vtkCommand-class I got a stack overflow exception because I step into a
recursive render loop. So I removed the observer.
What I've tried now is to add a pointer of my widget to my own interactor
style. Every time, I double click on my scene object I process my own
interactor behavior which also enables the sphere widget and calls the
Render()-method like mentioned above. Here is a code snippet to illustrate
this:
// in my main-class
myMouseStyle->SetWidget(widget);
// in my derived style-class
widget->SetEnabled(1);
widget->SetHandleVisibility(1);
widget->GetCurrentRenderer->Render();// Doesn't work
this->Interactor->Render(); // Doesn't work
Do you have any reasons why it doesn't work? I have to mention that I use a
QVTKWidget to display my vtk-scene. Can this have an influence on it?
Best regards, Rocco
-----Ursprüngliche Nachricht-----
Von: Karthik Krishnan [mailto:karthik.krishnan at kitware.com]
Gesendet: Sonntag, 13. Juni 2010 11:43
An: Rocco Gasteiger
Betreff: Re: [vtkusers] Invoke "Interactor"-Event to vtkSphereWidget
You must invoke Render() explicitly on the widget after invoking SetEnabled.
Recently (roughly a year ago), the Render() call was removed from
SetEnabled, so that multiple widgets could be enabled without
triggering several renders.
On 6/12/10, Rocco Gasteiger <post at rocco-gasteiger.de> wrote:
> Dear vtk-users,
>
>
>
> I want to use a vtkSphereWidget in my scene to orient a geometry.
Currently,
> I have to press the key "i" to enable this widget (i.e. make the handle
> visible). However, I want to enable this widget once the widget geometry
is
> shown in my render window. For this purpose I add an observer to my
renderer
> with the parameters "vtkCommand::StartEvent" and a derived class of
> vtkCommand as callback-command. Additionally, I set a pointer to the
> vtkSphereWidget in my derived callback-command. When the event is
processed
> (and I proved that this event is throwing!), I call "SetEnabled(1)" in my
> derived callback-command. However, the handle is not visible. I need to
> press the "i"-key to make it visible. I also tried to add observers to the
> interactor but the problem is still the same.
>
>
>
> Can anybody give me a hint what I'm doing wrong?
>
>
>
> Thanks in advance, Rocco
>
>
>
>
>
> P.S. Here is a code snippet of what I'm doing currently:
>
>
>
> // The main-class:
>
> .
>
> vtkSmartPointer<vtkSphereWidget> sphereWidget =
> vtkSmartPointer<vtkSphereWidget>::New();
>
> sphereWidget ->SetInteractor(windowInteractor);
>
> sphereWidget ->SetCurrentRenderer(renderer);
>
> sphereWidget ->SetEnabled(1);
>
> sphereWidget ->SetHandleSize(0.03);
>
> sphereWidget ->SetPhiResolution(20);
>
> sphereWidget ->SetThetaResolution(20);
>
> sphereWidget ->GetSphereProperty()->BackfaceCullingOn();
>
> sphereWidget ->SetHandleVisibility(1);
>
> .
>
>
>
> vtkSmartPointer<vtkMyWidgetCallback> widgetCallback =
> vtkSmartPointer<vtkMyWidgetCallback>::New();
>
> widgetCallback->SetWidget(sphereWidget);
>
> renderer->AddObserver(vtkCommand::StartEvent, widgetCallback);
>
>
>
> // The derived vtkCommand class
>
> class vtkMyWidgetCallback : public vtkCommand
>
> {
>
> public:
>
> static vtkMyWidgetCallback *New()
>
> {
>
> return new vtkMyWidgetCallback;
>
> }
>
>
>
> virtual void Execute(vtkObject *caller, unsigned long,
> void*)
>
> {
>
>
>
> sphereWidget ->SetEnabled(1);
>
> sphereWidget ->SetHandleVisibility(1);
>
> cout << "Widget on!" << endl;
>
> }
>
> void SetWidget(vtkSphereWidget* widget);
>
>
>
> vtkSphereWidget* sphereWidget;
>
> };
>
>
>
> inline void vtkMyWidgetCallback::SetWidget(vtkSphereWidget* widget)
>
> {
>
> sphereWidget = widget;
>
> }
>
>
>
>
>
>
>
>
More information about the vtkusers
mailing list