[vtkusers] vtkInteractionStyle

David Cole david.cole at kitware.com
Wed Apr 13 11:15:14 EDT 2005


Take a look at the class hierarchy diagram for vtkInteractorStyle at 
http://www.vtk.org/doc/nightly/html/classvtkInteractorStyle.html

Looks from the code snippet you gave...

code from the main:
......
#include "vtkMyInteractorStyle.h"
#include "vtkInteractorStyleSwitch.h"

...that before your change, a vtkInteractorStyleSwitch was instantiated. 
You can derive your class from vtkInteractorStyleSwitch rather than 
vtkInteractorStyle and inherit all of its behavior. Be sure to call the 
parent class for keys you don't handle yourself in OnChar. That way, 
you'll get all the behavior you had before you wrote your own.


HTH,
David


verena kinder wrote:

>Hello!
>
>In order to interact to my render Window by keypress I derive a class vtkMyInteractorStyle from vtkInteractorStyle.
>
>Code vtkMyInteractorStyle.h:
>#ifndef __vtkMyInteractorStyle_h
>#define __vtkMyInteractorStyle_h
>
>#include "vtkInteractorStyle.h"
>
>class vtkMyInteractorStyle : public vtkInteractorStyle
>{
>public:
>  
>  virtual void OnChar();
>};
>
>#endif
>
>Code vtkMyInteractorStyle.cxx:
>
>#include "vtkMyInteractorStyle.h"
>
>#include "vtkCallbackCommand.h"
>#include "vtkCommand.h"
>#include "vtkObjectFactory.h"
>#include "vtkRenderWindowInteractor.h"
>
>#include <iostream>
>using namespace std;
>
>
>//----------------------------------------------------------------------------
>void vtkMyInteractorStyle::OnChar()
>{
>  switch (this->Interactor->GetKeyCode())
>    {
>    case 'w':
>    case 'W':
>      cout<<"You press the W key "<<endl;
>      break;
>    }
>}
>
>code from the main:
>......
>#include "vtkMyInteractorStyle.h"
>#include "vtkInteractorStyleSwitch.h"
>
>#include <iostream>
>using namespace std;
>
>
>int main (int argc, char **argv)
>{
>  
>/**********************************************************
>SET RENDER WINDOW and INTERCTION VALUES
>************************************************************/
>  vtkRenderer *aRenderer = vtkRenderer::New();
>  aRenderer->SetBackground(1.0,0.0,0.0);
>  vtkRenderWindow *renWin = vtkRenderWindow::New();
>    renWin->AddRenderer(aRenderer);
>  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>    iren->SetRenderWindow(renWin);
>    vtkMyInteractorStyle *style=vtkMyInteractorStyle::New();
>    iren->SetInteractorStyle(style);
>/***************************************************************/
>.......
>
>
>
>/**************************************START RENDERING*******************************/
>
>     aRenderer->AddProp(vol);
>     aRenderer->AddActor(axesActor);
>     renWin->Render();
>  // Initialize the event loop and then start it.
>     iren->Initialize();
>     iren->Start();
>
>
>/*************************************DELETE******************************************/
> 
>  return 0;
>
>}
>
>But if I set : 
>	iren->SetInteractorStyle(style);
>I overwrite the exsisting interactions like zooming with the mouse and so on.
>But that I dont't want because I need them.
>
>How can I handle this problem?
>What function shall I add to my class?
>
>Thanks !
>
>Verena  
>
>
>
>
>______________________________________________________________
>Verschicken Sie romantische, coole und witzige Bilder per SMS!
>Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
>
>_______________________________________________
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the 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/20050413/7f69513b/attachment.htm>


More information about the vtkusers mailing list