VTK/Examples/MiscPointData
From KitwarePublic
< VTK | Examples(Redirected from Add Miscellaneous Data to Points in a Polydata)
This demo attaches a vector (in this case a float vector of length 1) to each point in a polydata.
#include <vtkCellData.h> #include <vtkDoubleArray.h> #include <vtkPoints.h> #include <vtkPolyData.h> #include <vtkPointData.h> #include <vtkSmartPointer.h> #include <vtkXMLPolyDataReader.h> #include <vtkPolyDataNormals.h> int main(int argc, char *argv[]) { //get filename from command line vtkstd::string filename = argv[1]; //first command line argument //Read the file vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New(); cout << "Reading " << filename << endl; reader->SetFileName(filename.c_str()); reader->Update(); //extract the polydata vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput(); //get the number of points in the polydata vtkIdType idNumPointsInFile = polydata->GetNumberOfPoints(); //add distances to each point vtkSmartPointer<vtkFloatArray> distances = vtkSmartPointer<vtkFloatArray>::New(); distances->SetNumberOfComponents(1); distances->SetName("Distances"); for(unsigned int i = 0; i < idNumPointsInFile; i++) { distances->InsertNextValue(vtkMath::Random(0.0,1.0);); } polydata->GetPointData()->AddArray(distances); return 0; }

