VTK/Examples/Broken/Interaction/RecordEvents

From KitwarePublic
< VTK‎ | Examples
Jump to navigationJump to search

Record mouse and keyboard events.

RecordEvents.cxx

#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorEventRecorder.h>

int main(int argc, char*argv[])
{
  vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->Update();
  
  vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(sphereSource->GetOutputPort());
  
  vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  
  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  interactor->SetRenderWindow(renderWindow);
  
  // Add the actors to the renderer, set the background and size
  
  renderer->AddActor(actor);
  
  vtkSmartPointer<vtkInteractorEventRecorder> recorder = vtkSmartPointer<vtkInteractorEventRecorder>::New();
  recorder->SetInteractor(interactor);
  recorder->SetFileName("events.log");

  renderWindow->Render();
  interactor->Initialize();
  recorder->EnabledOn();
  recorder->Record();
  
  interactor->Start();
  
  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(RecordEvents)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(RecordEvents MACOSX_BUNDLE RecordEvents.cxx)

if(VTK_LIBRARIES)
  target_link_libraries(RecordEvents ${VTK_LIBRARIES})
else()
  target_link_libraries(RecordEvents vtkHybrid vtkWidgets)
endif()

Download and Build RecordEvents

Click here to download RecordEvents. and its CMakeLists.txt file.

Once the tarball RecordEvents.tar has been downloaded and extracted,

cd RecordEvents/build 
  • If VTK is installed:
cmake ..
  • If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

make

and run it:

./RecordEvents

WINDOWS USERS PLEASE NOTE: Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.