VTK/Examples/Broken/Widgets/PointHandleRepresentation2D

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

How do you use the handle?

PointHandleRepresentation2D.cxx

#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkCommand.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <vtkHandleWidget.h>
#include <vtkPolygonalHandleRepresentation3D.h>

int main(int argc, char *argv[])
{
  vtkSmartPointer<vtkSphereSource> sphereSource = 
      vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->Update();
  
  //Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper = 
      vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(sphereSource->GetOutputPort());
  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);
  renderer->AddActor(actor);
  
  // an interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  vtkSmartPointer<vtkHandleWidget> handleWidget = 
      vtkSmartPointer<vtkHandleWidget>::New();
  handleWidget->SetInteractor(renderWindowInteractor);
  
  renderWindow->Render();
  
  renderWindowInteractor->Initialize();
  renderWindow->Render();
  handleWidget->On();
  
  renderWindowInteractor->Start();
  
  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(PointHandleRepresentation2D)

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

add_executable(PointHandleRepresentation2D MACOSX_BUNDLE PointHandleRepresentation2D.cxx)

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

Download and Build PointHandleRepresentation2D

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

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

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

./PointHandleRepresentation2D

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.