[vtkusers] VTK Interactor problem

Alex Malyushytskyy alexmalvtk at gmail.com
Thu Aug 22 18:11:25 EDT 2013


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> 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 inteventId,
> 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: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>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> 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
>>>
>>> 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/20130822/eef810c3/attachment.htm>


More information about the vtkusers mailing list