Write two cubes to a VTP file

From KitwarePublic
Revision as of 13:11, 11 April 2009 by Daviddoria (talk | contribs) (New page: <source lang="cpp"> #include <vtkCubeSource.h> void WriteTwoCubes(const string &OutputFilename) { vtkSmartPointer<vtkCubeSource> Cube1 = vtkSmartPointer<vtkCubeSource>::New(); Cube1->S...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

<source lang="cpp">

  1. include <vtkCubeSource.h>


void WriteTwoCubes(const string &OutputFilename) { vtkSmartPointer<vtkCubeSource> Cube1 = vtkSmartPointer<vtkCubeSource>::New(); Cube1->SetCenter(0.0, 0.0, 0.0); Cube1->SetXLength(.5); Cube1->SetYLength(.5); Cube1->SetZLength(.5);

vtkSmartPointer<vtkCubeSource> Cube2 = vtkSmartPointer<vtkCubeSource>::New(); Cube2->SetCenter(5.0, 0.0, 0.0); Cube2->SetXLength(.5); Cube2->SetYLength(.5); Cube2->SetZLength(.5);

vtkSmartPointer<vtkPolyData> polydata1 = Cube1->GetOutput(); vtkSmartPointer<vtkPolyData> polydata2 = Cube2->GetOutput();

vtkSmartPointer<vtkAppendPolyData> CombinedData = vtkSmartPointer<vtkAppendPolyData>::New();; CombinedData->AddInput(polydata1); CombinedData->AddInput(polydata2);

//write the file vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); writer->SetInput(CombinedData->GetOutput());

writer->SetFileName(OutputFilename.c_str()); writer->Write();

} </source>