Write two cubes to a VTP file
<source lang="cpp">
- 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>