Difference between revisions of "VTK/Examples/Cxx/PolyData/Curvatures"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to navigationJump to search
(Style and get range from data for mapper.)
Line 13: Line 13:
 
int main(int argc, char *argv[])
 
int main(int argc, char *argv[])
 
{
 
{
   //parse command line arguments
+
   // Parse command line arguments
 
   if(argc != 2)
 
   if(argc != 2)
 
     {
 
     {
     std::cout << "Required arguments: Filename" << std::endl;
+
     std::cerr << "Usage: " << argv[0] << " Filename(.vtp)" << std::endl;
 
     return EXIT_FAILURE;
 
     return EXIT_FAILURE;
 
     }
 
     }
 
   
 
   
   //create a set of points
+
   // Create a polydata
 
   vtkSmartPointer<vtkXMLPolyDataReader> reader =  
 
   vtkSmartPointer<vtkXMLPolyDataReader> reader =  
      vtkSmartPointer<vtkXMLPolyDataReader>::New();
+
    vtkSmartPointer<vtkXMLPolyDataReader>::New();
 
   reader->SetFileName(argv[1]);
 
   reader->SetFileName(argv[1]);
  reader->Update();
 
 
    
 
    
 
   vtkSmartPointer<vtkCurvatures> curvaturesFilter =  
 
   vtkSmartPointer<vtkCurvatures> curvaturesFilter =  
      vtkSmartPointer<vtkCurvatures>::New();
+
    vtkSmartPointer<vtkCurvatures>::New();
 
   curvaturesFilter->SetInputConnection(reader->GetOutputPort());
 
   curvaturesFilter->SetInputConnection(reader->GetOutputPort());
 
   //curvaturesFilter->SetCurvatureTypeToGaussian();
 
   //curvaturesFilter->SetCurvatureTypeToGaussian();
Line 33: Line 32:
 
   //curvaturesFilter->SetCurvatureTypeToMaximum();
 
   //curvaturesFilter->SetCurvatureTypeToMaximum();
 
   curvaturesFilter->SetCurvatureTypeToMinimum();
 
   curvaturesFilter->SetCurvatureTypeToMinimum();
  curvaturesFilter->Update();
 
 
        
 
        
   //to inspect more closely, if required
+
   // To inspect more closely, if required
 
   vtkSmartPointer<vtkXMLPolyDataWriter> writer =  
 
   vtkSmartPointer<vtkXMLPolyDataWriter> writer =  
      vtkSmartPointer<vtkXMLPolyDataWriter>::New();
+
    vtkSmartPointer<vtkXMLPolyDataWriter>::New();
 
   writer->SetInputConnection(curvaturesFilter->GetOutputPort());
 
   writer->SetInputConnection(curvaturesFilter->GetOutputPort());
 
   writer->SetFileName("gauss.vtp");
 
   writer->SetFileName("gauss.vtp");
 
   writer->Write();
 
   writer->Write();
 
    
 
    
    //Create a mapper and actor
+
  // Create a mapper and actor
 
   vtkSmartPointer<vtkPolyDataMapper> mapper =  
 
   vtkSmartPointer<vtkPolyDataMapper> mapper =  
      vtkSmartPointer<vtkPolyDataMapper>::New();
+
    vtkSmartPointer<vtkPolyDataMapper>::New();
 
   mapper->SetInputConnection(curvaturesFilter->GetOutputPort());
 
   mapper->SetInputConnection(curvaturesFilter->GetOutputPort());
+
  mapper->SetScalarRange(curvaturesFilter->GetOutput()->GetScalarRange());
 +
 
 
   vtkSmartPointer<vtkActor> actor =  
 
   vtkSmartPointer<vtkActor> actor =  
      vtkSmartPointer<vtkActor>::New();
+
    vtkSmartPointer<vtkActor>::New();
 
   actor->SetMapper(mapper);
 
   actor->SetMapper(mapper);
 
   
 
   
   //Create a renderer, render window, and interactor
+
   // Create a renderer, render window, and interactor
 
   vtkSmartPointer<vtkRenderer> renderer =  
 
   vtkSmartPointer<vtkRenderer> renderer =  
      vtkSmartPointer<vtkRenderer>::New();
+
    vtkSmartPointer<vtkRenderer>::New();
 
   vtkSmartPointer<vtkRenderWindow> renderWindow =  
 
   vtkSmartPointer<vtkRenderWindow> renderWindow =  
      vtkSmartPointer<vtkRenderWindow>::New();
+
    vtkSmartPointer<vtkRenderWindow>::New();
 
   renderWindow->AddRenderer(renderer);
 
   renderWindow->AddRenderer(renderer);
 
   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =  
 
   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =  
      vtkSmartPointer<vtkRenderWindowInteractor>::New();
+
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
 
   renderWindowInteractor->SetRenderWindow(renderWindow);
 
   renderWindowInteractor->SetRenderWindow(renderWindow);
 
   
 
   
   //Add the actor to the scene
+
   // Add the actor to the scene
 
   renderer->AddActor(actor);
 
   renderer->AddActor(actor);
   renderer->SetBackground(1,1,1); // Background color white
+
   renderer->SetBackground(.1, .2, .3); // Background color blue
 
   
 
   
 
   //Render and interact
 
   //Render and interact
Line 70: Line 69:
 
   return EXIT_SUCCESS;
 
   return EXIT_SUCCESS;
 
}
 
}
 
 
</source>
 
</source>
  

Revision as of 11:43, 25 June 2010

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)