Add Global Information to a VTP file
<source lang="cpp"> //add random points (and vertices) to the file vtkSmartPointer<vtkPoints> Points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New(); for ( unsigned int i = 0; i < 4; ++i ) { vtkIdType pid[1]; pid[0] = Points->InsertNextPoint(drand48(), drand48(), drand48()); Vertices->InsertNextCell(1,pid); }
vtkSmartPointer<vtkPolyData> pdata = vtkSmartPointer<vtkPolyData>::New();
//add the points to the dataset pdata->SetPoints(Points); pdata->SetVerts(Vertices);
//add a FileIndex of "4" to the file vtkSmartPointer<vtkIntArray> MyArray = vtkSmartPointer<vtkIntArray>::New(); MyArray->SetNumberOfComponents(1); MyArray->InsertNextValue(4); MyArray->SetName("FileIndex");
pdata->GetFieldData()->AddArray(MyArray);
//add a Location of (10, 20, 30) to the file vtkSmartPointer<vtkDoubleArray> Location = vtkSmartPointer<vtkDoubleArray>::New(); double loc[3] = {10.0, 20.0, 30.0}; Location->SetNumberOfComponents(3); Location->SetName("Location"); Location->InsertNextTuple(loc);
pdata->GetFieldData()->AddArray(Location);
//write the file vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New(); writer->SetInput(pdata);
string OutputFilename = "TestGlobalInfo.vtp"; writer->SetFileName(OutputFilename.c_str()); writer->Write(); cout << "Wrote " << OutputFilename.c_str() << endl; </source>