I wrote the following and trying to understand why only the density scalar is visible in the VTP file written out.
What is the correct way to add multiple point data ?
void example_02()
{
std::string filename ("vtp_polys_02.vtp");
auto points = vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(0, 1, 0);
points->InsertNextPoint(1, 0, 0);
auto cells = vtkSmartPointer<vtkCellArray>::New();
cells->InsertNextCell({0,1,2});
auto polydata = vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->SetPolys(cells);
{
vtkSmartPointer<vtkFloatArray> velocity =
vtkSmartPointer<vtkFloatArray>::New();
velocity->SetName("velocity");
velocity->SetNumberOfComponents(3);
float u[3] = {1,0,0};
float v[3] = {0,10,0};
float w[3] = {0,0,100};
velocity->InsertNextTuple(u);
velocity->InsertNextTuple(v);
velocity->InsertNextTuple(w);
polydata->GetPointData()->SetScalars(velocity);
}
{
vtkSmartPointer<vtkFloatArray> density =
vtkSmartPointer<vtkFloatArray>::New();
density->SetName("density");
density->SetNumberOfComponents(1);
float d0 = 0.5;
float d1 = 1;
float d2 = 2.7;
density->InsertNextTuple(&d0);
density->InsertNextTuple(&d1);
density->InsertNextTuple(&d2);
polydata->GetPointData()->SetScalars(density);
}
auto writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
writer->SetFileName(filename.c_str());
writer->SetInputData(polydata);
writer->Write();
}