[vtkusers] VTKPoints and VTKLookupTable

Toh Da Jun tohdj at bii.a-star.edu.sg
Wed Mar 16 20:52:07 EST 2005


I'm trying to display points on screen in different colors.
I've searched through the user forum and wrote the following codes.
Yet the points are all in one color. any idea where i went wrong...when
i've followed the advices given by fellow users?

BTW, the printout for the lookout table seems weird, because the first
10 table values are the same. And the lut.GetTableValue(x, rgba); uses a
double vector for rgba instead of float (which is true for the C++
version).

Language is Java. VTK is version 4.2.

tohdj

========= source codes =============

        // Draw the points
        polyVertexPoints = new vtkPoints();
        polyVertexPoints.SetData(PointCoords);
        vtkPolyVertex aPolyVertex = new vtkPolyVertex();
        (aPolyVertex.GetPointIds()).SetNumberOfIds(NumPoints);
        
        for (int i=0; i<m_iDimension; i++)
            for (int j=0; j<m_iDimension; j++)
                (aPolyVertex.GetPointIds()).SetId((i*m_iDimension+j),
(i*m_iDimension+j));
        
        vtkPolyData aPolyData = new vtkPolyData();
        aPolyData.Allocate(1, 1);
        aPolyData.InsertNextCell(aPolyVertex.GetCellType(),
aPolyVertex.GetPointIds());
        aPolyData.SetPoints(polyVertexPoints);
        
        vtkPolyDataMapper aPolyVertexMapper = new vtkPolyDataMapper();
        aPolyVertexMapper.SetInput( aPolyData );
        aPolyVertexMapper.SetScalarRange( 0, NumPoints * 4 );
        aPolyVertexMapper.ScalarVisibilityOn();        

        vtkLookupTable lut = new vtkLookupTable();
        lut.SetRange( 0, 0.5 );
        lut.SetNumberOfColors( 5 );
        lut.SetHueRange( 0, 0 );
        lut.SetSaturationRange( 0, 0 );
        lut.SetAlphaRange( 1, 1 );
        lut.SetValueRange( 0, 1 );
        lut.Build();
        aPolyVertexMapper.SetLookupTable( lut );
        
       
	System.out.println("GetNumberOfColors()="+lut.GetNumberOfColors());
        double [] rgba = new double[4];
        for (int x=0; x<lut.GetNumberOfColors(); x++) {
            lut.GetTableValue(x, rgba);
            System.out.println(x+".\t"+rgba[0]+", "+rgba[1]+",
"+rgba[2]+", "+rgba[3]+".");
        }
        
        vtkActor aPolyVertexActor = new vtkActor();
        aPolyVertexActor.SetMapper(aPolyVertexMapper);
        
        ren.AddActor(aPolyVertexActor);






More information about the vtkusers mailing list