Difference between revisions of "VTK/Examples/Boneyard/Frustum"

From KitwarePublic
< VTK‎ | Examples
Jump to navigationJump to search
(Style cleanup)
Line 15: Line 15:
 
#include <vtkPolyDataMapper.h>
 
#include <vtkPolyDataMapper.h>
  
int main(int argc, char *argv[])
+
int main(int, char *[])
 
{
 
{
   vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
+
   vtkSmartPointer<vtkCamera> camera =
 +
    vtkSmartPointer<vtkCamera>::New();
 
   double planesArray[24];
 
   double planesArray[24];
 
    
 
    
 
   camera->GetFrustumPlanes(1, planesArray);
 
   camera->GetFrustumPlanes(1, planesArray);
 
    
 
    
   vtkSmartPointer<vtkPlanes> planes = vtkSmartPointer<vtkPlanes>::New();
+
   vtkSmartPointer<vtkPlanes> planes =
 +
    vtkSmartPointer<vtkPlanes>::New();
 
   planes->SetFrustumPlanes(planesArray);
 
   planes->SetFrustumPlanes(planesArray);
 
    
 
    
   vtkSmartPointer<vtkFrustumSource> frustumSource = vtkSmartPointer<vtkFrustumSource>::New();
+
   vtkSmartPointer<vtkFrustumSource> frustumSource =
 +
    vtkSmartPointer<vtkFrustumSource>::New();
 
   frustumSource->SetPlanes(planes);
 
   frustumSource->SetPlanes(planes);
 
   frustumSource->Update();
 
   frustumSource->Update();
Line 31: Line 34:
 
   vtkPolyData* frustum = frustumSource->GetOutput();
 
   vtkPolyData* frustum = frustumSource->GetOutput();
  
   vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
+
   vtkSmartPointer<vtkPolyDataMapper> mapper =
 +
    vtkSmartPointer<vtkPolyDataMapper>::New();
 
   mapper->SetInput(frustum);
 
   mapper->SetInput(frustum);
  
   vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
+
   vtkSmartPointer<vtkActor> actor =
 +
    vtkSmartPointer<vtkActor>::New();
 
   actor->SetMapper(mapper);
 
   actor->SetMapper(mapper);
 
    
 
    
 
   // a renderer and render window
 
   // a renderer and render window
   vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
+
   vtkSmartPointer<vtkRenderer> renderer =
   vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
+
    vtkSmartPointer<vtkRenderer>::New();
 +
   vtkSmartPointer<vtkRenderWindow> renderWindow =
 +
    vtkSmartPointer<vtkRenderWindow>::New();
 
   renderWindow->AddRenderer(renderer);
 
   renderWindow->AddRenderer(renderer);
  
 
   // an interactor
 
   // an interactor
   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
+
   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
 +
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
 
   renderWindowInteractor->SetRenderWindow(renderWindow);
 
   renderWindowInteractor->SetRenderWindow(renderWindow);
  
 
   // add the actors to the scene
 
   // add the actors to the scene
 
   renderer->AddActor(actor);
 
   renderer->AddActor(actor);
   renderer->SetBackground(1,1,1); // Background color white
+
   renderer->SetBackground( .2, .1, .3); // Background color dark purple
  
 
   // render an image (lights and cameras are created automatically)
 
   // render an image (lights and cameras are created automatically)
Line 55: Line 63:
 
   // begin mouse interaction
 
   // begin mouse interaction
 
   renderWindowInteractor->Start();
 
   renderWindowInteractor->Start();
   return 0;
+
   return EXIT_SUCCESS;
 
}
 
}
 +
 
</source>
 
</source>
  

Revision as of 13:17, 4 May 2010

This example gets the frustum from a camera and displays it on the screen.

DisplayFrustum.cxx

#include <vtkFrustumSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkCamera.h>
#include <vtkPlanes.h>
#include <vtkMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>

int main(int, char *[])
{
  vtkSmartPointer<vtkCamera> camera =
    vtkSmartPointer<vtkCamera>::New();
  double planesArray[24];
  
  camera->GetFrustumPlanes(1, planesArray);
  
  vtkSmartPointer<vtkPlanes> planes =
    vtkSmartPointer<vtkPlanes>::New();
  planes->SetFrustumPlanes(planesArray);
  
  vtkSmartPointer<vtkFrustumSource> frustumSource =
    vtkSmartPointer<vtkFrustumSource>::New();
  frustumSource->SetPlanes(planes);
  frustumSource->Update();
  
  vtkPolyData* frustum = frustumSource->GetOutput();

  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInput(frustum);

  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( .2, .1, .3); // Background color dark purple

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

  // begin mouse interaction
  renderWindowInteractor->Start();
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(Frustum)

FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(DisplayFrustum DisplayFrustum.cxx)
TARGET_LINK_LIBRARIES(DisplayFrustum vtkHybrid)