[vtkusers] vtkcommand and events

Anka Kochanowska pluszcz at gmail.com
Thu Nov 19 09:11:33 EST 2009


Hi!
This one will work, the difference is in selecting InteractorStyle.

#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkCommand.h>
#include <vtkActor.h>
#include <vtkCallbackCommand.h>
#include <vtkSmartPointer.h>
#include <vtkPointPicker.h>
#include "vtkCamera.h"
#include "vtkInteractorObserver.h"
#include "vtkInteractorStyleTerrain.h"

void ClickCallbackFunction ( vtkObject* caller, long unsigned int eventId,
void* clientData, void* callData );

int main ( int argc, char* argv[] )
{

  vtkSmartPointer<vtkSphereSource> SphereSource =
vtkSmartPointer<vtkSphereSource>::New();
  SphereSource->SetCenter(0.0, 0.0, 0.0);
  SphereSource->SetRadius(5.0);
  SphereSource->Update();

  vtkSmartPointer<vtkPolyDataMapper> Mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
  Mapper->SetInput(SphereSource->GetOutput());

  vtkSmartPointer<vtkActor> Actor = vtkSmartPointer<vtkActor>::New();
  Actor->SetMapper(Mapper);

  vtkSmartPointer<vtkRenderer> Renderer =
vtkSmartPointer<vtkRenderer>::New();
  Renderer->SetBackground(1,1,1); // Background color white
  Renderer->AddActor(Actor);

  vtkSmartPointer<vtkRenderWindow> RenderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
  RenderWindow->AddRenderer(Renderer);

  vtkSmartPointer<vtkRenderWindowInteractor> RenderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
  RenderWindowInteractor->SetRenderWindow ( RenderWindow );

  vtkSmartPointer<vtkInteractorStyleTerrain> InteractorStyle =
vtkSmartPointer<vtkInteractorStyleTerrain>::New();

  RenderWindowInteractor->SetInteractorStyle( InteractorStyle );

  vtkSmartPointer<vtkCallbackCommand> ClickCallback =
vtkSmartPointer<vtkCallbackCommand>::New();
  ClickCallback->SetCallback ( ClickCallbackFunction );

//  RenderWindowInteractor->GetInteractorStyle()->AddObserver (
vtkCommand::LeftButtonPressEvent, ClickCallback );
  InteractorStyle->AddObserver ( vtkCommand::LeftButtonPressEvent,
ClickCallback );

  RenderWindowInteractor->Initialize();
  RenderWindowInteractor->Start();

  return 0 ;
}

void ClickCallbackFunction ( vtkObject* caller, long unsigned int eventId,
void* clientData, void* callData )
{
  vtkstd::cout << "Click callback" << vtkstd::endl;
}


On Thu, Nov 19, 2009 at 8:30 AM, David Doria
<daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>
> wrote:

> Radu, please "reply all" so the list gets your email too.
>
> I have the same problem - the callback just seems to be ignored:
> http://www.vtk.org/Wiki/Handle_mouse_events
>
> Thanks,
>
> David
>
> _______________________________________________
> 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/20091119/62b2b017/attachment.htm>


More information about the vtkusers mailing list