[vtkusers] vtkInteractionStyle

verena kinder verena.kinder at web.de
Wed Apr 13 10:22:37 EDT 2005


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




More information about the vtkusers mailing list