[vtkusers] vertex colors
dean.inglis at camris.ca
dean.inglis at camris.ca
Tue Jan 9 15:39:40 EST 2007
thanks Amy!
I tried assigning random numbers
(vtkMath::Random(0,1)) to a vtkDoubleArray
and it did work: I got a mix of r,g,b etc. all
over the mesh. I figured out what was unexpected
and I am getting what I expect now. Also, it
seems that opacity values are ignored (fourth
element of tuple 4 in my case) so that one
has to set opacity (globally and not per vertex)
through an actor's property. If I'm wrong on this
please correct...
Dean
> Hi Dean,
>
> The problem is that vtkMappers can do what you're trying to do only if
> the type of the scalars is unsigned char. If the scalars are of any
> other type, they are passed through a lookup table to determine the
> color associated with a particular scalar value.
>
> If you create your colors array as a vtkUnsignedChar array (and thus
> using the range 0 - 255 instead of 0 - 1), then if ScalarVisibility in
> the mapper is set to 1 and ColorMode is set to VTK_COLOR_MODE_DEFAULT,
> you should get what you're looking for.
>
> If you don't have control over the creation of the colors array, then
> you'd need to do something like vtkImageShiftScale, but for vtkPolyData
> to convert your colors array to the appropriate type. I don't think such
> a class exists in VTK, but it wouldn't be hard to write.
>
> - Amy
>
> Dean Inglis wrote:
> > I have a triangluar surface mesh with
> > rgba color data associated with each
> > vertex (point) of the polydata mesh:
> >
> > vtkDoubleArray* colors = vtkDoubleArray::New();
> > colors->SetNumberOfComponents(4);
> > for( int i = 0 i< nverts; i++)
> > {
> > colors->SetTuple4(i, r[i], g[i], b[i], o[i] );
> > }
> >
> > // where r,g,b,o are double precision red green blue and opacity values
> > // ranging from 0 - 1
> >
> > vtkPolyData* surf = vtkPolyData::New();
> > surf->SetPoints(surfPoints);
> > surf->SetPolys(surfCells);
> > surf->GetPointData()->SetScalars(colors);
> >
> > How do I get the polydata mapper to use these
> > scalars to color the mesh? Is it...
> >
> > mapper->SetInput(surf);
> > mapper->SetScalarVisibilityOn();
> >
> > ? I'm not getting what I expect.
> >
> > thanks,
> > Dean
More information about the vtkusers
mailing list