[vtkusers] RGB colours for many lines in vtkPolyData

Arkadiusz Zychewicz oczykota at gmail.com
Tue Oct 13 14:57:10 EDT 2009


Hi,
   I have to display many lines (~10000) and each one must have different
colour.  For now I use scalar colour for that, but I cannot represent
black or white colour. I  want to adopt the lookupTable but I cannot
figure out how it works.


    vtkPoints* m_points = vtkPoints::New();
    vtkCellArray*m_lines = vtkCellArray::New();
    vtkFloatArray* m_lineScalars = vtkFloatArray::New();
    vtkLookupTable* m_lookupTable = vtkLookupTable::New();

int m_curPointID = 0
for(int i = 0; i < lines.size(); i++){
     m_lineScalars->SetNumberOfComponents(1);
     m_points->InsertNextPoint(lines.getStart());
     m_lineScalars->InsertNextTuple1(scalar); //this gives colour
                              // exp.: (r*256*256+g*256+b)/0xffffff
     m_points->InsertNextPoint(lines.getEnd());
     m_lineScalars->InsertNextTuple1(scalar);

     m_lines->InsertNextCell(2);
     m_lines->InsertCellPoint(m_curPointID);
     m_lines->InsertCellPoint(m_curPointID + 1);
     m_curPointID += 2;

}
    m_lookupTable->SetNumberOfColors(0xffffff);
     m_lookupTable->SetNumberOfTableValues(0xffffff);
     m_lookupTable->Build();
     int size = 0xff;
     for (int ir = 0; ir < size; ir++) {
         for (int ig = 0; ig < size; ig++) {
             for (int ib = 0; ib < size; ib++) {
                 double r = ir / (double) size;
                 double g = ig / (double) size;
                 double b = ib / (double) size;
                 m_lookupTable->SetTableValue(ir * size * size + ig *
size + ib, r, g, b);
             }
         }
     }

     m_lookupTable->SetTableRange(0, 1);


     // Create poly data
     vtkPolyData* polyData = vtkPolyData::New();
     polyData->SetPoints(m_points);
     polyData->SetLines(m_lines);
     polyData->GetPointData()->SetScalars(m_lineScalars);





More information about the vtkusers mailing list