VTK/Examples/Cxx/Boneyard/GeometricObjects/WriteFile/Sphere

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

This example creates a sphere and writes it to a file.

Sphere.cxx

#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkXMLPolyDataWriter.h>

int main(int, char *[])
{
  //Create a sphere.
  vtkSmartPointer<vtkSphereSource> sphereSource =
    vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->SetCenter(0.0, 0.0, 0.0);
  sphereSource->SetRadius(5.0);
  sphereSource->Update();

  vtkSmartPointer<vtkPolyData> sphere =
    sphereSource->GetOutput();

  //Write the file.
  vtkSmartPointer<vtkXMLPolyDataWriter> writer =
    vtkSmartPointer<vtkXMLPolyDataWriter>::New();
  writer->SetInput(sphere);
  writer->SetFileName("sphere.vtp");
  writer->Write();

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(Sphere)

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

ADD_EXECUTABLE(Sphere Sphere.cxx)
TARGET_LINK_LIBRARIES(Sphere vtkHybrid)