2018-01-13:vtk_01_Cylinder


描述:A hello world example. This example creates a minimal visualization program, demonstrating VTK's basic rendering and pipeline creation.
vtkPolyDataMapper
vtkActor vtkRenderer
vtkRenderWindow
vtkRenderWindowInteractor


Cylinder.cpp

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main(int, char *[])
{
  // This creates a polygonal cylinder model with eight circumferential facets
  // (i.e, in practice an octagonal prism).
  vtkSmartPointer cylinder = vtkSmartPointer::New();
  cylinder->SetResolution(8);

  // The mapper is responsible for pushing the geometry into the graphics library.
  // It may also do color mapping, if scalars or other attributes are defined.
  vtkSmartPointer cylinderMapper = vtkSmartPointer::New();
  cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

  // The actor is a grouping mechanism: besides the geometry (mapper), it
  // also has a property, transformation matrix, and/or texture map.
  // Here we set its color and rotate it around the X and Y axes.
  vtkSmartPointer cylinderActor = vtkSmartPointer::New();
  cylinderActor->SetMapper(cylinderMapper);
  cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
  cylinderActor->RotateX(30.0);
  cylinderActor->RotateY(-45.0);

  // The renderer generates the image
  // which is then displayed on the render window.
  // It can be thought of as a scene to which the actor is added
  vtkSmartPointer renderer = vtkSmartPointer::New();
  renderer->AddActor(cylinderActor);
  renderer->SetBackground(0.1, 0.2, 0.4);
  // Zoom in a little by accessing the camera and invoking its "Zoom" method.
  renderer->ResetCamera();
  renderer->GetActiveCamera()->Zoom(1.5);

  // The render window is the actual GUI window
  // that appears on the computer screen
  vtkSmartPointer renderWindow = vtkSmartPointer::New();
  renderWindow->SetSize(200, 200);
  renderWindow->AddRenderer(renderer);

  // The render window interactor captures mouse events
  // and will perform appropriate camera or actor manipulation
  // depending on the nature of the events.
  vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // This starts the event loop and as a side effect causes an initial render.
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(Cylinder)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(${PROJECT_NAME} main.cpp )
target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})

运行结果为:


2018-01-13:vtk_01_Cylinder_第1张图片
Screenshot from 2018-01-13 20-48-27.png

你可能感兴趣的:(2018-01-13:vtk_01_Cylinder)