2012-01-04

Adding two SCALARS in POINTDATA for one vtkPolyData object in VTK

by Forrest Sheng Bao http://fsbao.net

In VTK (either the file format or the library), we sometimes associate more than one scalars to points. I just figured out how to do this in VTK (in C++, similarly in its Python, Tcl or Java wrapper).

Suppose I have a vtkPolyData pointer
vtkPolyData* mesh;
and two vtkDoubleArray (you can consider a vtkDoubleArray as a list of scalars) pointers
vtkDoubleArray* depth; 
 vtkDoubleArray* curv; 

This is how I do it:

depth->SetName("Depth");
mesh->GetPointData()->SetScalars(depth);
curv->SetName("Curvature");
mesh->GetPointData()->AddArray(curv);

You may test this by writing mesh into a VTK-format file:

vtkPolyDataWriter* writer=vtkPolyDataWriter::New();
 writer->SetFileName("test_dump.vtk");
 
 writer->SetInput(mesh);
 writer->Update();
 writer->Write();
 writer->Delete();

My only question is whether the use of AddArray() function is correct. What is I wanna set a Normal? or a Tensor?

No comments: