[vtkusers] vtkInteractionStyle
verena kinder
verena.kinder at web.de
Wed Apr 13 11:53:59 EDT 2005
OK I test the Observer!
class code:
class vtkMyInter : public vtkCommand
{
public:
static vtkMyInter *New()
{ return new vtkMyInter; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
cout << "W press"<< endl;
}
};
and the main:
vtkMyInter *mo1 = vtkMyInter::New();
iren->RemoveObservers ( vtkCommand::KeyPressEvent );
iren->AddObserver ( vtkCommand::KeyPressEvent, mo1 );
iren->Initialize();
iren->Start();
But how can I make my program reacts only on the KeyPressEvent 'w'?
In this moment it reacts whenever I press a key.
And in this moment I only use cout in my method, but is it also possible to change the background from the Renderer or something like that?
Thanks
Verena
"Markus Erbacher" <Markus.Erbacher at gmx.de> schrieb am 13.04.05 16:44:40:
>
> Hi Verena,
>
> I don't know about Interactorstyles, but if you just want to get the
> keypressevent, you could also create an Observer. All you need to do is to
> derive your class from vtkCommand.
>
> class Observer : public vtkCommand
> {
> public:
> virtual void Execute(vtkObject* Wdg, unsigned long Event, void* Calldata);
> };
>
> In Execute you can then call cout<<"You press the W key "<<endl;
>
> To use the Observer you must register it with the interactor you are using.
> To do so delete the old Observer for the keypressed-event from the
> Interactor an replace it with the new one. Looks like this:
>
> Interactor->RemoveObservers ( vtkCommand::KeyPressEvent );
> Interactor->AddObserver ( vtkCommand::KeyPressEvent, NewObserverExtra );
>
>
> Markus
>
> > 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
> >
>
> --
> +++ NEU: GMX DSL_Flatrate! Schon ab 14,99 EUR/Monat! +++
>
> GMX Garantie: Surfen ohne Tempo-Limit! http://www.gmx.net/de/go/dsl
______________________________________________________________
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