[Paraview] Particle attributes in vtkPolyData

Randy Hudson hudson at mcs.anl.gov
Mon Apr 10 12:19:06 EDT 2006


I've written a reader for ParaView 2.4.2 that reads particles from an 
HDF5 file and loads them into a vtkPolyData object.

It stuffs vtkPoints, vtkCellArray and vtkDoubleArray objects into the 
same places, in vtkPolyData, as is done in 
<paraview_src>/VTK/IO/vtkParticleReader.cxx (although I'm not using 
vtkSmartPointer, fwiw).

The issueproblem, though, is that no scalar-attribute-based property 
shows up on the "Color by" menu on the "Display" tab, so I can't color 
the particles by the scalar attribute.

HOWEVER, if I read the particles into paraview and then use File --> 
Save Geometry to create a ".pvd" file, and then load THAT back into 
paraview, the scalar attribute shows up on the "Color by" menu, and the 
particles CAN be colored by it. 

It was, therefore, there all along -- and, it would seem, in the right 
place.


Does it looks as though I'm doing things correctly?


Here's most of the relevant code:

    scalar_var = new double[NumberOfParticles];
    for(i=0; i<NumberOfParticles; i++)
        scalar_var[i] = particles[i].realProps[varname_index];

    aVTKPolyData = vtkPolyData::New();
    variable_color1 = vtkDoubleArray::New();
    pts1 = vtkPoints::New();
    ca1 = vtkCellArray::New();

    variable_color1->SetName(varname);
    for(i=0; i<NumberOfParticles; i++) {
        variable_color1->InsertNextValue(scalar_var[i]);

    for(i=0; i<NumberOfParticles; i++) {
        pts1->InsertPoint(i, xyz_position[i].x, xyz_position[i].y,
    xyz_position[i].z);
        ca1->InsertNextCell(1);
        ca1->InsertCellPoint(i);
    }

    aVTKPolyData->SetPoints(pts1);
    aVTKPolyData->SetVerts(ca1);
    aVTKPolyData->GetPointData()->SetScalars(variable_color1);


-- 

Randy.




More information about the ParaView mailing list