VTK/Examples/Broken/Interaction/PlayBackEvents

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

This example plays back events that have been recorded to a file.

PlayBackEvents.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"); 
  recorder->EnabledOn();

  renderWindow->Render();
  interactor->Initialize();

  recorder->Play();
  
  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(PlayBackEvents)

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

add_executable(PlayBackEvents MACOSX_BUNDLE PlayBackEvents.cxx)

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

Download and Build PlayBackEvents

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

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

cd PlayBackEvents/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:

./PlayBackEvents

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.