[vtkusers] Adding chars to 3D char array in python or how to add colors to array?
David Doria
daviddoria+vtk at gmail.com
Mon Dec 21 08:30:40 EST 2009
On Mon, Dec 21, 2009 at 2:42 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> Hi Lynx,
>
> Use SetTuple3(), the doubles are converted to the array type before
> they are stored.
>
> colors = vtk.vtkUnsignedCharArray()
> colors.SetNumberOfComponents (3)
> colors.InsertNextTuple3(255, 255, 255)
> colors.InsertNextTuple3(0, 255, 127)
>
> Also a note about this example: it's best to use SetScalars() to add
> colors to the data, so that you don't have to do anything special in
> order to display them. That example is misleading, the array name
> "Colors" doesn't have any special meaning in VTK.
>
> smoothed_polys.GetPointData().SetScalars(colors)
>
> Hope this helps.
>
> David
David G,
I always wondered we can't add a vtkPolyData::SetColors (which could
simply call SetScalars). It seems much less confusing than having to
tell people, "rather than create an array called colors, you have to
use SetScalars". In fact,
polydata->SetPointColors(colors)
rather than
polydata->GetPointData()->SetColors(colors)
would also prevent having to include of vtkPointData.h
What do you think about both of these things?
Lynx - when you get it working, don't forget to add it to the examples
:) As you're seeing, I don't believe there is much documentation for
the python API so these examples will help serve as that documentation
(so comment well!)
Thanks,
David
More information about the vtkusers
mailing list