[vtkusers] Coloring cells of a 3D polygon

Michael Bell mbell at coventor.com
Mon Feb 19 16:16:53 EST 2001


vtkusers,

	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.

Michael

      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);





More information about the vtkusers mailing list