[vtkusers] Coloring PolyDatas depending on various (externally computed) values
David Doria
daviddoria at gmail.com
Mon Oct 25 20:42:02 EDT 2010
On Mon, Oct 25, 2010 at 6:04 PM, Arnaud GELAS
<arnaud_gelas at hms.harvard.edu>wrote:
> Hi all,
>
> I would like to color some PolyData depending on different kind of
> information/data.
>
> For each polydata, I have an initial color (chosen by the user), and N
> values (volumes, surface, etc...), and I would like to efficiently switch
> from the chosen color, to a color which represents the value.
>
> - To store these values (computed externally), which vtkPolyData's data
> container should I use?
> Note that I have about 10k meshes with ~500 triangles, and about 10
> computed values, and I'd like each polydata to store its N value.
> - vtkFieldData?
> - vtkCellData?
> - vtkPointData?
> - How can I efficiently switch from rendering with colors which would
> represent one value (e.g. volume), to colors which would represent another
> one (e.g. surface), then to the original color (the one chosen by the user)?
>
>
> Thanks in advance,
> Arnaud
>
Arnaud,
The choice of Field,Cell, or Point data depends strictly on where these
colors are defined. Are they defined at the points of the meshes or the
triangles? If its at the points (i.e. each point has a color), you'll want
to use PointData. If it's at the triangles (i.e. each triangle has a color)
you want to use CellData. FieldData is for "global information" about the
whole data set typically, so you wouldn't want to use that here.
Lets go forward assuming that the colors are defined on the points. You
would want to do this
vtkUnsignedCharArray* colors1 = vtkUnsignedCharArray::New();
colors1->SetName("colors1");
... fill the colors array
vtkUnsignedCharArray* colors2 = vtkUnsignedCharArray::New();
colors2->SetName("colors2");
... fill the colors array
polydata->GetPointData()->AddArray(colors1);
polydata->GetPointData()->AddArray(colors2);
Now here is the key. To select which one is used, use this:
polydata->GetPointData()->SetActiveScalars("colors1");
I think that is what you were looking for? Give it a try and let us know if
it wasn't.
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101025/472fa76a/attachment.htm>
More information about the vtkusers
mailing list