[vtkusers] How to use LookupTable correctly?

Khew Sing Yoong sykhew at simbiosys.ca
Thu Jun 22 13:28:26 EDT 2006


Hi there,

I am fairly new to vtk and I am having problems drawing lines with 
colours using a lookup table. I am using VTK 5.0.

In a snapshot: create a vtkPolyData, assign 3 points, and connect them 
with 2 lines in the form of an L shape.
I want to color the first point Red, second Green, third Blue, hence I 
assign 0, 1, 2 as scalar values for each point respectively.
Then I created a lookup table for the PolyDataMapper with 0,1,2 mapping 
to RGB.
Connect the pipe and the results weren't as expected. Green never shows up!

Can somebody be kind enough to help me out here a little? Maybe I missed 
something? Thank you in advance! :)

SY


    vtkPolyData * data = vtkPolyData::New();
    vtkPoints *Points = vtkPoints::New();
    vtkCellArray *Lines= vtkCellArray::New();
    vtkIntArray *color = vtkIntArray::New();
    Points->Allocate(3);
    Lines->Allocate(2);
    color->SetName("Color");
    color->SetNumberOfComponents(1);

    Points->InsertNextPoint(0, 1, 0);
    Points->InsertNextPoint(0, 0, 0);
    Points->InsertNextPoint(1, 0, 0);
    vtkIdType line[2];
    line[0] = 0;
    line[1] = 1;
    Lines->InsertNextCell(2, line);
    line[0] = 1;
    line[1] = 2;
    Lines->InsertNextCell(2, line);
    color->InsertNextValue(0);
    color->InsertNextValue(1);
    color->InsertNextValue(2);
    data->SetPoints(Points);
    data->SetLines(Lines);
    data->GetPointData()->SetScalars(color);
    data->Squeeze();
    
    vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();
    mapper->SetInput(data);
    mapper->SetScalarVisibility(1);

    vtkLookupTable * lut = vtkLookupTable::New();
    lut->SetTableRange(0, 3);
    lut->SetNumberOfColors(3);
    lut->Build();
    lut->SetTableValue(0, 1, 0, 0, 1);
    lut->SetTableValue(1, 0, 1, 0, 1);
    lut->SetTableValue(2, 0, 0, 1, 1);
    
    mapper->SetLookupTable(lut);
    mapper->SetScalarModeToUsePointFieldData();
    mapper->SetColorModeToMapScalars();
    mapper->SelectColorArray("Color");

    vtkActor * actor = vtkActor::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetLineWidth(2);
    ren1->AddActor(actor);



More information about the vtkusers mailing list