VTK/Examples/Cxx/PolyData/Curvatures

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Revision as of 11:43, 25 June 2010 by Lorensen (talk | contribs) (Style and get range from data for mapper.)
Jump to navigationJump to search

Curvatures.cxx

#include <vtkSmartPointer.h>
#include <vtkCurvatures.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>

int main(int argc, char *argv[])
{
  // Parse command line arguments
  if(argc != 2)
    {
    std::cerr << "Usage: " << argv[0] << " Filename(.vtp)" << std::endl;
    return EXIT_FAILURE;
    }
 
  // Create a polydata
  vtkSmartPointer<vtkXMLPolyDataReader> reader = 
    vtkSmartPointer<vtkXMLPolyDataReader>::New();
  reader->SetFileName(argv[1]);
  
  vtkSmartPointer<vtkCurvatures> curvaturesFilter = 
    vtkSmartPointer<vtkCurvatures>::New();
  curvaturesFilter->SetInputConnection(reader->GetOutputPort());
  //curvaturesFilter->SetCurvatureTypeToGaussian();
  //curvaturesFilter->SetCurvatureTypeToMean();
  //curvaturesFilter->SetCurvatureTypeToMaximum();
  curvaturesFilter->SetCurvatureTypeToMinimum();
      
  // To inspect more closely, if required
  vtkSmartPointer<vtkXMLPolyDataWriter> writer = 
    vtkSmartPointer<vtkXMLPolyDataWriter>::New();
  writer->SetInputConnection(curvaturesFilter->GetOutputPort());
  writer->SetFileName("gauss.vtp");
  writer->Write();
  
  // Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper = 
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(curvaturesFilter->GetOutputPort());
  mapper->SetScalarRange(curvaturesFilter->GetOutput()->GetScalarRange());

  vtkSmartPointer<vtkActor> actor = 
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
 
  // Create a renderer, render window, and interactor
  vtkSmartPointer<vtkRenderer> renderer = 
    vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow = 
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
 
  // Add the actor to the scene
  renderer->AddActor(actor);
  renderer->SetBackground(.1, .2, .3); // Background color blue
 
  //Render and interact
  renderWindow->Render();
  renderWindowInteractor->Start();
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(Curvatures)

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

ADD_EXECUTABLE(Curvatures Curvatures.cxx)
TARGET_LINK_LIBRARIES(Curvatures vtkHybrid)