[vtkusers] Coloring cells of a 3D polygon

Will Schroeder will.schroeder at kitware.com
Tue Feb 20 08:48:04 EST 2001

Hi Michael-

There are two problems.
1) You are adding scalars to the output of the filter before the filter executes.
    You can fix this by doing a CubeSource->Update() before adding the scalars.
    (The pipeline execution process initializes the output prior to filter execution.)

2) You really shouldn't add attribute data to the output of the filter anyway. This is
because if the filter re-executes it will destroy the data you added previously. Also,
if the scalars you add change the pipeline will not re-execute properly. A better
solution is to use something like vtkProgrammableAttributeDataFilter to take the output
of the cone source as its input, and then add the scalars. (You can of course create
your own class.) 


At 04:16 PM 2/19/2001 -0500, Michael Bell wrote:
>        Despite spending hours looking into the archives, I have not been able to
>color individual faces of a polygon in different colors. For example, I
>create a cube from vtkCubeSource. I create a lookup table with 6 colors, I
>then add scalars to the cube and associate the table with a mapper. In the
>end, neither the cube or any of its faces, change color.
>        I have successfully changed the colors of an axisActor by using a lookup
>table in a similar way, so I believe my problem is setting the scalars to
>the cells in the cube.
>Please help. See code below.
>      vtkCubeSource cubeSource = new vtkCubeSource();
>      vtkPolyDataMapper cubeMapper = new vtkPolyDataMapper();
>      vtkActor cubeActor = new vtkActor();
>      vtkScalars cubeScalars = new vtkScalars();
>      cubeScalars.SetNumberOfScalars(6);
>      cubeScalars.SetScalar(0,0);
>      cubeScalars.SetScalar(1,1);
>      cubeScalars.SetScalar(2,2);
>      cubeScalars.SetScalar(3,3);
>      cubeScalars.SetScalar(4,4);
>      cubeScalars.SetScalar(5,5);
>      cubeSource.GetOutput().GetCellData().SetScalars(cubeScalars);
>      vtkLookupTable lut = new vtkLookupTable();
>        lut.SetNumberOfColors(6);
>        lut.SetNumberOfTableValues(6);
>        lut.SetTableValue(0,1,0,0,1);
>        lut.SetTableValue(1,0,1,0,1);
>        lut.SetTableValue(2,0,0,1,1);
>        lut.SetTableValue(3,1,0,0,1);
>        lut.SetTableValue(4,0,1,0,1);
>        lut.SetTableValue(5,0,0,1,1);
>      cubeMapper.SetScalarModeToUseCellData();
>      cubeMapper.ScalarVisibilityOn();
>      cubeMapper.SetInput(cubeSource.GetOutput());
>      cubeMapper.SetLookupTable(lut);
>      cubeActor.SetMapper(cubeMapper);
>      renPanel.setActor(cubeActor);
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>Follow this link to subscribe/unsubscribe:

More information about the vtkusers mailing list