[vtkusers] VTK Interactor problem

Florian Schiffers florian.schiffers at physik.uni-erlangen.de
Fri Aug 23 05:55:16 EDT 2013


Hello,

thank you again!

I'll try to explain my problem again:

I have this Class ElectrodeDetectorPlugin and there I have some vtkData 
like m_InputData, m_MaximaData etc.

Basically I will load a 3D Model (m_InputData) into my renderWindow and 
at first I just want to transform the object in the normal way 
(spinning, zooming, roation, etc.)

But than, I press a button on my GUI (with QT) and now I want the 
transformations to stop (for that I have Style2) and I than want to pick 
a point with - for example - the right mouse button event and the VTK 
Point Picker. After picking a point I want to do some operatios on 
m_InputData, m_MaximaData and than I want to redraw all of them!

The big problem is: MouseInteractorStyle2 doesn't know the m_InputData, 
m_MaximaData objects and all the other functions of the 
ElectrodeDetectorPlugin etc.
The same is for the callback functions, because they are no 
memberfunctions of the ElectrodeDetectorPlugin (as far as I see).

Maybe it is not even a vtkProblem. Maybe it is more a problem of me 
understanding object-oriented programming C++. (I'm still a student and 
just a beginner in  C++)

The only way I was able to connect the Interactor with the member 
functions of ElectrodeDetectorPlugin was this way (But I dont like this 
way):

m_QtSlotConnector->Connect( widget->GetRenderWindow()->GetInteractor(), 
vtkCommand::RightButtonPressEvent, 
this,SLOT(RightButtonPressEventHandling(vtkObject*, unsigned long, 
void*, void*)));

thank you again!
Flo

Am 23.08.2013 00:11, schrieb Alex Malyushytskyy:
> I am am glad my comment helped somehow.
> I guess you MouseInteractorStyle1 and MouseInteractorStyle2 are 
> subclasses of vtkInteractorStyle which you want set depending on your 
> needs
> In this case why would you even need a callback?
> Do everything  there.
>
> Also I do not think your code is valid.
> I doubt below code will even compile:
>
>  vtkSmartPointer<MouseInteractorStyle1> style  = 
> vtkSmartPointer<MouseInteractorStyle1>::New(); // Style 1 for 
> manipulation Spin/Pan etc.
>  vtkSmartPointer<MouseInteractorStyle2> style  = 
> vtkSmartPointer<MouseInteractorStyle2>::New();
>
>
> You said you want different behavior for for example left mouse 
> release depending on some conditions.
> This means you have a few choices:
>
> a) subclass interactor style and do all you need within that single class.
> b) switch between different interactor styles. For example check 
> vtkInteractorStyleSwitch.
> c) use callbacks.
>
> I used a) and b) myself. Even though I have not used last approach I 
> guess you would still at least to either subclass interactor style so 
> it does nothing if actions of your interest happens or find an 
> existent class which satisfies above conditions. Otherwise default 
> interactor style will interfere with your code (For example rotation 
> will happen  when you want zoom or both )
>
>
> Hope this helps,
>   Alex
>
>
>
> On Thu, Aug 22, 2013 at 3:26 AM, Florian Schiffers 
> <florian.schiffers at physik.uni-erlangen.de 
> <mailto:florian.schiffers at physik.uni-erlangen.de>> wrote:
>
>     Hello,
>
>     thx for the answer. It helped me alot, but I still have the
>     problem that I cannot access to class member variables in a
>     callback function or the vtkInteractorStyleTrackballCamera Class.
>
>     I have a structure like this:
>
>     ( with pastebin: http://pastebin.com/qm42n1xh )
>
>     void ClickCallbackFunction ( vtkObject* caller, long unsigned int
>     eventId, void* clientData, void* callData );
>     ElectrodeDetectorPlugin::ElectrodeDetectorPlugin(QVTKWidget *p):
>     QObject(){
>         m_InputData                =    vtkSmartPointer <vtkPolyData>
>     :: New();
>         m_InputDataActor        =    vtkSmartPointer <vtkActor> :: New();
>
>         m_MaximaData           = vtkSmartPointer<vtkPolyData>::New();
>         m_InputMaximaActor            = vtkSmartPointer<vtkActor>::New();
>
>         vtkSmartPointer<MouseInteractorStyle1> style =  
>     vtkSmartPointer<MouseInteractorStyle1>::New(); // Style 1 for
>     manipulation Spin/Pan etc.
>         vtkSmartPointer<MouseInteractorStyle2> style =  
>     vtkSmartPointer<MouseInteractorStyle2>::New();
>         ... ....
>     renderWindow->GetInteractor()->SetInteractorStyle( style );
>        vtkSmartPointer<vtkCallbackCommand> clickCallback =
>     vtkSmartPointer<vtkCallbackCommand>::New();
>     clickCallback->SetCallback ( ClickCallbackFunction );  
>     renderWindowInteractor->AddObserver (
>     vtkCommand::LeftButtonPressEvent, clickCallback );
>
>     }
>     void ClickCallbackFunction ( vtkObject* vtkNotUsed(caller), long
>     unsigned int vtkNotUsed(eventId), void* vtkNotUsed(clientData),
>     void* vtkNotUsed(callData) ) { std::cout << "Click callback" <<
>     std::endl;
>
>        // Get the interactor like this:
>        vtkRenderWindowInteractor *iren =
>        static_cast<vtkRenderWindowInteractor*>(caller);
>
>        HERE I need to operations on m_InputData, m_MaximaData using PointPicker Methods
>        I also want to draw objects etc.
>        
>     }
>
>     I tried a lot of stuff, but they all didn't work. Do you have any
>     idea?
>
>     Thank you for your help!
>
>     best regards,
>     Flo
>
>     Am 21.08.2013 04 <tel:21.08.2013%2004>:04, schrieb Alex Malyushytskyy:
>>     I just want to add thet currently set . vtkInteractorStyle is
>>     defining which events are handled and how.
>>     So subclassing and overriding appropriate functionality is way to go.
>>     Also you can create multiple vtkInteractorStyle and set them
>>     active according to your needs.
>>
>>     Hope this helps.
>>
>>     Alex
>>
>>
>>     On Tue, Aug 20, 2013 at 4:08 PM, Alex Malyushytskyy
>>     <alexmalvtk at gmail.com <mailto:alexmalvtk at gmail.com>> wrote:
>>
>>         Subclass vtkInteractorStyle (or derived class ) you are using.
>>
>>         All the operations: rotation, calls as results on
>>         Keypressevents are initiated there.
>>         Depending on the actual subclass of vtkInteractorStyle things
>>         what you need to do are different,
>>         For example to suppress Keypressevents for
>>         vtkInteractorStyleRubberBand subclass you can just override
>>         void vtkInteractorStyleRubberBand::OnChar() to do nothing.
>>
>>         Regards,
>>              Alex
>>
>>
>>         On Tue, Aug 20, 2013 at 5:59 AM, Phys1k3r
>>         <florian.schiffers at physik.uni-erlangen.de
>>         <mailto:florian.schiffers at physik.uni-erlangen.de>> wrote:
>>
>>             Hello,
>>
>>             I have written a vtk-programm that allows me to display a
>>             3D data set (VTK
>>             and QT). Additonally you can interact with the 3D Data with
>>             'RightButtonPressEvent' and 'MiddleButtonPressEvent'.
>>             Both interaction are
>>             point picker interactions.
>>
>>             My problem is, that for example, when I press the
>>             'RightButton' two things
>>             happen at once:
>>
>>             1. Point on 3D Data get's picked
>>             2. Camera is zooming in/out (only when I move mouse
>>             during picking, but this
>>             happens from time to time)
>>
>>             The same happens with 'MiddleButtonPressEvent', the
>>             objects just get moved
>>             instead.
>>
>>             So basically I want a button on my GUI, where I can choose:
>>              1. Either Zoom in/out
>>              2. or pick a point
>>
>>             As an alternative I would be satisfied with something
>>             like this:
>>              1. Just OnLeftButtonDown() -> Just Zoom/Pan/Spin
>>              2. OnLeftButtonDown() + KeePressEvent -> Don't zoom,
>>             pick point instead
>>
>>             This is how I implemented the
>>             'MiddleButtonPressEventHandling' by now:
>>
>>
>>
>>             I know, this is not the best way, but it worked so far. I
>>             propably will
>>             implement it this way in the near future:
>>             http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/MouseEventsObserver
>>
>>             But even when I use the MouseEventsObserver I still have
>>             no Idea how
>>             suppress the Zoom/Pan/Spin Events...
>>
>>             Than I thought of this method instead:
>>             http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/MouseEvents
>>
>>             First of all, I don't need (and also don't want) all the
>>             features of the
>>             vtkInteractorStyle class like Keypressevents for p, r, s,
>>             u, v e (as you can
>>             find them here:
>>             http://www.vtk.org/doc/nightly/html/classvtkInteractorStyle.html
>>             at Detailed
>>             Description)
>>
>>             I just need to overwrite 'OnLeftButtonDown',
>>             'OnMiddleButtonDown',
>>             'OnRightButtonDown' etc.
>>
>>             So basically I tried things like this, but they don't
>>             work, of course:
>>
>>
>>
>>
>>             Honestly I have no idea how to solve my problem... I also
>>             haven't found much
>>             documentary besides the examples.
>>
>>             Thank you for your help, I really appreciate it
>>             Phys1k3r
>>
>>
>>
>>             --
>>             View this message in context:
>>             http://vtk.1045678.n5.nabble.com/VTK-Interactor-problem-tp5722887.html
>>             Sent from the VTK - Users mailing list archive at Nabble.com.
>>             _______________________________________________
>>             Powered by www.kitware.com <http://www.kitware.com>
>>
>>             Visit other Kitware open-source projects at
>>             http://www.kitware.com/opensource/opensource.html
>>
>>             Please keep messages on-topic and check the VTK FAQ at:
>>             http://www.vtk.org/Wiki/VTK_FAQ
>>
>>             Follow this link to subscribe/unsubscribe:
>>             http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
>>
>
>

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


More information about the vtkusers mailing list