VTK/Examples/Broken/Widgets/CameraWidget

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

How to use this?

CameraWidget.cxx

#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCameraRepresentation.h>
#include <vtkCameraWidget.h>
 
int main (int argc, char *argv[])
{
  // A sphere
  vtkSmartPointer<vtkSphereSource> sphereSource = 
      vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->Update();
  
  vtkSmartPointer<vtkPolyDataMapper> mapper = 
      vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInput(sphereSource->GetOutput());
 
  vtkSmartPointer<vtkActor> actor = 
      vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
 
  // A renderer and render window
  vtkSmartPointer<vtkRenderer> renderer = 
      vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow = 
      vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
 
  // An interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
 
  // Add the actors to the scene
  renderer->AddActor(actor);
 
  // Render an image (lights and cameras are created automatically)
  renderWindow->Render();
  
  vtkSmartPointer<vtkCameraRepresentation> cameraRep = 
      vtkSmartPointer<vtkCameraRepresentation>::New();
  cameraRep->SetNumberOfFrames(2400);
  
  vtkSmartPointer<vtkCameraWidget> cameraWidget = 
      vtkSmartPointer<vtkCameraWidget>::New();
  cameraWidget->SetInteractor(renderWindowInteractor);
  cameraWidget->SetRepresentation(cameraRep);

  //cameraWidget->EnabledOn();
  cameraWidget->On();
 
  renderWindow->Render();
 
  renderWindowInteractor->Start();
 
  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(CameraWidget)

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

add_executable(CameraWidget MACOSX_BUNDLE CameraWidget.cxx)

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

Download and Build CameraWidget

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

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

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

./CameraWidget

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.