VTK/Examples/Cxx/Broken/Images/ImageViewer2

From KitwarePublic
< VTK‎ | Examples‎ | Cxx(Redirected from VTK/Examples/Broken/ImageViewer2)
Jump to navigationJump to search

This example is currently broken. Shouldn't the image stay facing the camera?

ImageViewer2.cxx

#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkImageViewer2.h>
#include <vtkImageCanvasSource2D.h>

int main(int argc, char* argv[])
{
  vtkSmartPointer<vtkImageCanvasSource2D> drawing = 
    vtkSmartPointer<vtkImageCanvasSource2D>::New();
  drawing->SetScalarTypeToUnsignedChar();
  drawing->SetNumberOfScalarComponents(3);
  drawing->SetExtent(0, 20, 0, 50, 0, 0);
  drawing->FillBox(0,20,0,50);
  drawing->SetDrawColor(255, 0, 0, 0);
  drawing->DrawCircle(9, 10, 5);
  drawing->Update();
  
  // Create rendering window and everything...
  vtkSmartPointer<vtkRenderer> renderer = 
      vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow = 
      vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  
  vtkSmartPointer<vtkRenderWindowInteractor> interactor = 
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  interactor->SetRenderWindow(renderWindow);

  vtkSmartPointer<vtkImageViewer2> viewer = 
      vtkSmartPointer<vtkImageViewer2>::New();
  
 viewer->SetInputConnection( drawing->GetOutputPort() );
  viewer->SetupInteractor(interactor);
  
  interactor->Initialize();
  viewer->Render();
  interactor->Start();
 
  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(ImageViewer2)

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

add_executable(ImageViewer2 MACOSX_BUNDLE ImageViewer2.cxx)

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

Download and Build ImageViewer2

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

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

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

./ImageViewer2

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.