[vtkusers] Setting colors for Points does not work properly

David Doria daviddoria at gmail.com
Thu Dec 8 07:23:14 EST 2011


2011/12/8 Boehm, Lukas <Lukas.Boehm at cellent.de>:
> Hi,
>
>
>
> i wrote a small POC to set some points in the render window. This works fine
> and I’ve found many examples which describe how to set the color for each
> point. But that’s the problem. I’ve got the following code:
>
>
>
>             vtkRenderWindow renderWindow = this.renderWindowControl1.RenderWindow;
>
>             // create points-object
>
>             vtkPoints pts = vtkPoints.New();
>
>             // create double-array for colors
>
>             vtkDoubleArray colors = vtkDoubleArray.New();
>
>             colors.SetName("colors");
>
>             colors.SetNumberOfComponents(3);
>
>             // insert point and color-tuple
>
>             pts.InsertNextPoint(0.0, 0.0, 0.0);
>
>             colors.InsertNextTuple3(0.3, 0.0, 0.0);
>
>
>
>             vtkPolyData polyData = vtkPolyData.New();
>
>             // add points to polydata object
>
>             polyData.SetPoints(pts);
>
>             // add colors to polydata object
>
>             polyData.GetPointData().AddArray(colors);
>
>
>
>             // points should be displayed as crosses
>
>             vtkGlyphSource2D cross = vtkGlyphSource2D.New();
>
>             cross.SetGlyphTypeToCross();
>
>             vtkGlyph3D glyph = vtkGlyph3D.New();
>
>             // connect polydata with glyph-object
>
>             glyph.SetInputConnection(0, polyData.GetProducerPort());
>
>             glyph.SetSourceConnection(0, cross.GetOutputPort());
>
>             // define the input array for colors
>
>             glyph.SetInputArrayToProcess(3, 0, 0, 0, "colors");
>
>             glyph.SetColorModeToColorByScalar();
>
>             vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
>
>             mapper.SetInput(glyph.GetOutput());
>
>             vtkActor actor = vtkActor.New();
>
>             actor.SetMapper(mapper);
>
>
>
> This code produces a yellow cross. But if I want to change the rgb values of
> the point it does not work, as I expected. If I change the line
>
>
>
>             colors.InsertNextTuple3(0.3, 0.0, 0.0);
>
>
>
> to
>
>             colors.InsertNextTuple3(0.3, 0.9, 0.9);
>
>
>
> then the cross is still yellow. I would have expected that the three values
> are interpreted as rgb values. The only interpreted value is the first
> double. If I change the first double value, the color of the cross changes.
> But I have to set rgb colors.
>
>
>
> Do you understand my problem? Do I make a mistake? I am using VTK 5.6.1.599
> with C#.NET.
>
>
>
> Thank you very much.
>
> Lukas

You have to use a vtkUnsignedCharArray instead of a vtkDoubleArray,
and the range of each component must be [0, 255]. You can add double
data to your points as you did, but it will be interpreted by a
colormap type of operation instead of directly used as colors.

David



More information about the vtkusers mailing list