[vtkusers] Invoke "Interactor"-Event to vtkSphereWidget

Rocco Gasteiger post at rocco-gasteiger.de
Sat Jun 12 05:44:29 EDT 2010


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;

}

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100612/ddc23206/attachment.htm>


More information about the vtkusers mailing list