VTK/Examples/Broken/Interaction/Flight

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

This example is currently broken. The sphere disappears if you click the left mouse button. The arrow keys do nothing.

Left mouse button press produces forward motion. Right mouse button press produces reverse motion. Moving mouse during motion steers user in desired direction. Keyboard controls are: Left/Right/Up/Down Arrows for steering direction 'A' forward, 'Z' reverse motion Ctrl Key causes sidestep instead of steering in mouse and key modes Shift key is accelerator in mouse and key modes Ctrl and Shift together causes Roll in mouse and key modes

Flight.cxx

#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSphereSource.h>
#include <vtkInteractorStyleFlight.h>

int main (int argc, char *argv[])
{

  vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
  
  //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);

  // an interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // add the actors to the scene
  renderer->AddActor(actor);
  renderer->SetBackground(1,1,1); // Background color white

  // render an image (lights and cameras are created automatically)
  renderWindow->Render();

  vtkSmartPointer<vtkInteractorStyleFlight> style = 
      vtkSmartPointer<vtkInteractorStyleFlight>::New(); //like paraview
  
  renderWindowInteractor->SetInteractorStyle( style );
  
  // begin mouse interaction
  renderWindowInteractor->Start();
  
  return EXIT_SUCCESS;
}

Please try the new VTKExamples website.

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(Flight)

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

add_executable(Flight MACOSX_BUNDLE Flight.cxx)

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

Download and Build Flight

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

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

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

./Flight

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.