[vtkusers] [vtk-users] capture mouse event

toulgen toulgen at gmail.com
Mon Jul 6 10:06:23 EDT 2009


If I comment this line:

==

renWin->SetParentId(hWnd);   //<-- hWnd : handle of my windows where I
display my rendering

==

I intercept all events !!!

 

In fact, I create a view under my MFC project. Then I call my C++ method
with handle of my View.

I don’t understand why if I display the rendered on my window (View under
MFC) I can’t capture events?

 

Any Idea.

 

 

  _____  

De : toulgen [mailto:toulgen at gmail.com] 
Envoyé : lundi 6 juillet 2009 15:33
À : 'Will Schroeder'
Cc : 'vtkusers at vtk.org'
Objet : RE: [vtk-users] capture mouse event

 

No, I don’t receive answer.

 

I try this code :

 

My code:

========

vtkConeSource *cone = vtkConeSource::New();

cone->SetHeight( 3.0 );

cone->SetRadius( 1.0 );

cone->SetResolution( 10 );

 

vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();

coneMapper->SetInputConnection( cone->GetOutputPort() );

 

vtkActor *coneActor = vtkActor::New();

coneActor->SetMapper( coneMapper );

 

 

vtkRenderer *ren1= vtkRenderer::New();

ren1->AddActor( coneActor );

ren1->AddActor( coneActor2 );

ren1->SetBackground( 0.1, 0.2, 0.4 );

 

vtkRenderWindow *renWin = vtkRenderWindow::New();

renWin->AddRenderer( ren1 );

renWin->SetSize( 300, 300 );

renWin->SetParentId(hWnd);   //<-- hWnd : handle of my windows where I
display my rendering

  

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

iren->SetRenderWindow(renWin);

 

vtkMyCallback *callb = vtkMyCallback::New();

vtkInteractorStyleUser *style = vtkInteractorStyleUser::New();

style->AddObserver(vtkCommand::AnyEvent, callb);

iren->SetInteractorStyle(style);

  

iren->Initialize();

//iren->Start(); //<- Not used

 

 

 

vtkMyCallback Class:

====================

class vtkMyCallback : public vtkCommand

{

public:

  static vtkMyCallback *New() 

    { 

                        

            return new vtkMyCallback; 

    }

 

 virtual void Execute(vtkObject *caller, unsigned long Id, void* ptVal)

    {

             vtkInteractorStyleUser *style = static_cast<
vtkInteractorStyleUser* >(caller);

 

                        switch( Id)

                        { 

                                   case vtkCommand::CharEvent: // <-- Never
captured event 

                                               switch( style->GetChar() )

                                               { 

                                                           case 'h': 

 
OutputDebugString("*********** >>> h <<<************** \n\n\n");

 
break; 

                                               } 

                                               break; 

 

                                   case vtkCommand::MouseWheelBackwardEvent:
// <-- Never captured event

 
OutputDebugString("MouseWheelBackwardEvent \n");

                                               break;

 

                                   case vtkCommand::MouseWheelForwardEvent:
// <-- Never captured event

 
OutputDebugString("MouseWheelForwardEvent \n");

                                               break;

 

                                   case vtkCommand::MouseMoveEvent: // <--
OK

 
OutputDebugString("MouseMoveEvent\n");

                                               break;

 

                                   case vtkCommand::LeftButtonPressEvent: //
<-- OK

 
OutputDebugString("LeftButtonPressEvent \n");

                                               break;

 

                                   case vtkCommand::RightButtonPressEvent:
// <-- OK

 
OutputDebugString("RightButtonPressEvent \n");

                                               break;

                        } 

    }

};

 

 

I can intercept MouseMoveEvent, LeftButtonPressEvent and
RightButtonPressEvent events. But never with this events:
MouseWheelBackwardEvent, MouseWheelForwardEvent and CharEvent.

 

Have you any idea ? or examples ?

 

Thank you,

ToulGen

  _____  

De : Will Schroeder [mailto:will.schroeder at kitware.com] 
Envoyé : mercredi 1 juillet 2009 12:53
À : toulgen
Objet : Re: [vtk-developers] capture mouse event

 

Did you receive an answer? If not you have some studying to do :-) You will
want to start with the interactor styles.

Will

On Thu, Jun 25, 2009 at 11:20 AM, toulgen <toulgen at gmail.com> wrote:

Hi,

 

I use this pipeline to render volume.

 

My question is: how I can capture a mouse event? I want to zoom in/zoom out
my volume with mouse wheel scrolls.

 

Thx,

ToulGen

 

My code :

========

    this->m_vtkpRendererVolume = vtkRenderer::New();

 

    this->m_vtkpRenWin = vtkRenderWindow::New();

            this->m_vtkpRenWin->DoubleBufferOn();

            this->m_vtkpRenWin->SetDesiredUpdateRate(1);

            this->m_vtkpRenWin->SetSize(this->m_Width, this->m_Height);

            this->m_vtkpRenWin->AddRenderer( this->m_vtkpRendererVolume );

 

            this->m_vtkpRenWin ->SetParentId(hWnd); 

            

    // Make interactive

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();

            iren->SetStillUpdateRate(1); 

            iren->SetDesiredUpdateRate(10); 

            iren->SetRenderWindow(this->m_vtkpRenWin);

 

    // Standard transfer functions

    ...

 

    vtkVolumeRayCastCompositeFunction *compositeFunction =
vtkVolumeRayCastCompositeFunction::New();

            compositeFunction->SetCompositeMethodToInterpolateFirst();

 

    vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();

    volumeMapper->SetVolumeRayCastFunction(compositeFunction);

            volumeMapper->SetInput(this->m_vtkpVolume->GetOutput());

 

    m_vtkpVolumeForDisplay = vtkVolume::New();

    m_vtkpVolumeForDisplay->SetMapper(volumeMapper);

    m_vtkpVolumeForDisplay->SetProperty(volumeProperty);

 

            this->m_vtkpRendererVolume->AddVolume(m_vtkpVolumeForDisplay);

            

    this->m_vtkpRenWin->Render();


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtk-developers




-- 
William J. Schroeder, PhD
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
will.schroeder at kitware.com
http://www.kitware.com
(518) 881-4902

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090706/2116ad0a/attachment.htm>


More information about the vtkusers mailing list