VTK/ExamplesBoneyard/Cxx/Widgets/Contour

From KitwarePublic
Jump to navigationJump to search
VTK Examples Baseline Widgets TestContourWidget.png

ContourWidget.cxx

#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkContourWidget.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>

int main(int, char *[])
{  
  // Create a renderer and render window
  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);

  // Create an interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
  
  // Create a contour widget
  vtkSmartPointer<vtkContourWidget> contourWidget = 
      vtkSmartPointer<vtkContourWidget>::New();
  contourWidget->SetInteractor(renderWindowInteractor);
  contourWidget->CreateDefaultRepresentation();
  
  renderWindow->Render();
  renderWindowInteractor->Initialize();
  renderWindow->Render();
  contourWidget->On();

  // Begin mouse interaction
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(Contour)

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

add_executable(Contour MACOSX_BUNDLE Contour.cxx)

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

Download and Build Contour

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

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

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

./Contour

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.