VTK/Examples/Cxx/Broken/Widgets/PlaybackWidget

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

PlaybackWidget.cxx

#include "vtkSmartPointer.h"
#include "vtkPlaybackWidget.h"
#include "vtkPlaybackRepresentation.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCommand.h"
#include "vtkInteractorEventRecorder.h"

class vtkSubclassPlaybackRepresentation : public vtkPlaybackRepresentation
{
public:
  static vtkSubclassPlaybackRepresentation *New() {return new vtkSubclassPlaybackRepresentation;}
  virtual void Play() {std::cout << "play\n";}
  virtual void Stop() {std::cout << "stop\n";}
  virtual void ForwardOneFrame() {std::cout << "forward one frame\n";}
  virtual void BackwardOneFrame() {std::cout << "backward one frame\n";}
  virtual void JumpToBeginning() {std::cout << "jump to beginning\n";}
  virtual void JumpToEnd() {std::cout << "jump to end\n";}
};


int main(int vtkNotUsed(argc), char *vtkNotUsed(argv)[])
{
  // Create the RenderWindow, Renderer and both Actors
  //
  vtkSmartPointer<vtkRenderer> ren1 =
    vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renWin =
    vtkSmartPointer<vtkRenderWindow>::New();
  renWin->AddRenderer(ren1);

  vtkSmartPointer<vtkRenderWindowInteractor> iren =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  iren->SetRenderWindow(renWin);

  // Create a test pipeline
  //
  vtkSmartPointer<vtkSphereSource> ss =
    vtkSmartPointer<vtkSphereSource>::New();
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInput(ss->GetOutput());
  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  // Create the widget
  vtkSmartPointer<vtkSubclassPlaybackRepresentation> rep =
    vtkSmartPointer<vtkSubclassPlaybackRepresentation>::New();

  vtkSmartPointer<vtkPlaybackWidget> widget =
    vtkSmartPointer<vtkPlaybackWidget>::New();
  widget->SetInteractor(iren);
  widget->SetRepresentation(rep);

  // Add the actors to the renderer, set the background and size
  ren1->AddActor(actor);
  ren1->SetBackground(0.1, 0.2, 0.4);
  renWin->SetSize(300, 300);

  // record events
  vtkSmartPointer<vtkInteractorEventRecorder> recorder =
    vtkSmartPointer<vtkInteractorEventRecorder>::New();
  recorder->SetInteractor(iren);
  recorder->SetFileName("record.log");
  recorder->Record();
//  recorder->ReadFromInputStringOn();
//  recorder->SetInputString(eventLog);

  iren->Initialize();
  renWin->Render();
  widget->On();
//  recorder->Play();

  // Remove the observers so we can go interactive. Without this the "-I"
  // testing option fails.
  recorder->Off();

  iren->Start();
  
  return EXIT_SUCCESS;

}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(PlaybackWidget)

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

add_executable(PlaybackWidget MACOSX_BUNDLE PlaybackWidget.cxx)

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

Download and Build PlaybackWidget

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

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

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

./PlaybackWidget

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.