[vtkusers] Coloring PolyDatas depending on various (externally computed) values
Arnaud GELAS
arnaud_gelas at hms.harvard.edu
Tue Oct 26 09:49:11 EDT 2010
On 10/25/2010 08:42 PM, David Doria wrote:
> On Mon, Oct 25, 2010 at 6:04 PM, Arnaud GELAS
> <arnaud_gelas at hms.harvard.edu <mailto: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.
> o vtkFieldData?
> o vtkCellData?
> o 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
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101026/cbe89041/attachment.htm>
More information about the vtkusers
mailing list