[vtkusers] vertex colors

Amy Squillacote amy.squillacote at kitware.com
Tue Jan 9 15:12:40 EST 2007


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
>
>
>
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>   



More information about the vtkusers mailing list