I was wondering how one could write a polydata including its colour to file. For instance I understand that polydata’s do not intrinsically hold information about their colour, well unless one includes this in its field data i.e the point data. So what I do is tag the colour as an array (vtkDoubleArray) and set that as the scalar for the point data.
const char* colourString = "colour"; vtkSmartPointer<vtkDoubleArray> colour = vtkSmartPointer<vtkDoubleArray>::New(); colour->vtkAbstractArray::SetNumberOfComponents(3); colour->SetName(colourString); //... loop & set values colour->InsertNextTuple3(r,g,b); // r, g, b are doubles polydata->GetPointData()->SetScalars(colour);
The problem is when I try writing the file out and loading the result in for example Paraview I don’t see the expected colour. I’m trying the write the files in formats such as stl (using vtkSTLWriter), ply (using vtkPLYWriter) and lastly vtk using just vtkPolyDataWriter. Can someone help me out with this?