[vtkusers] Coloring PolyDatas depending on various (externally computed) values

David Doria daviddoria at gmail.com
Tue Oct 26 10:02:01 EDT 2010


>
> David,
>
> It works fine with PointData and CellData; however I could not figure out
> how to proceed with FieldData (There is no method SetActive at this level in
> the hierarchy :-/, and my values are attributes to one mesh (constant for a
> single mesh).
> Is there a way to proceed with vtkFieldData?
>
> ---
>
> If not, I can use CellData instead. In this case, I can switch from active
> scalar array to original mesh colors by setting it to one that does not
> belong to the mesh:
>
> polydata->GetCellData->SetActiveScalars( "" );
>
> Is there a better way to proceed?
>
> Thanks,
> Arnaud
>

The reason that you can't set active scalars on the FieldData is probably
that it doesn't always make sense to apply arrays from the FieldData to the
data because it is not necessarily "aligned" (the same length).

Since it is a single color per object/mesh, can you color the actor based on
the field data value (the 0th value in the array)?

Something like:

vtkFloatArray* colorArray
= vtkFloatArray::SafeDownCast(polydata->GetFieldData()->GetArray("color1"));
float color[3];
colorArray->GetTupleValue(0, color);

actor->GetProperty()->SetColor(color);

?

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101026/0fd583d1/attachment.htm>


More information about the vtkusers mailing list