[vtkusers] assigning a color for each cell

Leseur Guillaume guiles1er at yahoo.fr
Tue Jul 21 14:23:15 EDT 2009


Hello everyone,

I have a cell array and I'm assigning a color to each cell.
So far I have a working solution, it's doing the job when there are a few cells, but it takes awfully long when there are a thousands of them.
There probably is another way to do that faster.

My (relevant) code is:

//creating a color attribute for the cells
vtkFloatArray* Colors = vtkFloatArray::New();
    Colors->SetName("Colors");

//creating a transfer function
vtkColorTransferFunction* MyColorFunction = vtkColorTransferFunction::New();

//building colors and MyColorFunction:
for (var indice=0;indice<imax;++indice) {
    MyColorFunction->AddRGBPoint(indice,r,g,b);
    Colors->InsertNextValue(indice);
}

//assigning points, vertices and colors
    polydata->SetPoints(Points);
    polydata->SetPolys(Vertices);
    polydata->GetCellData()->AddArray(Colors);

// and with the mapper, I have:
contMapper->SetInput(polydata);
contMapper->SetScalarModeToUseCellFieldData();
contMapper->SetLookupTable(MyColorFunction);
contMapper->SelectColorArray("Colors");

So as I said, this is perfectly working, but the for loop is taking forever, if someone knows how to achieve the same result faster, that would be great!

Thank you,

Guillaume



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090721/f763d141/attachment.htm>


More information about the vtkusers mailing list