[vtkusers] assigning a color for each cell
David E DeMarle
dave.demarle at kitware.com
Tue Jul 21 15:56:10 EDT 2009
Two things:
Instead of using InsertNextValue, allocate the array first
(call set number of components then setnumber of tuples) and then call SetValue.
Every insertnextvalue has to check against the size of the array and
then possible reallocated and move the old contents.
Then, instead of making two arrays, a color array, and then an index
into that color array, just make a 3 component unsigned char array and
set that to be the scalars. VTK will render directly those unless you
tell it not to.
David E DeMarle
Kitware, Inc.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x109
On Tue, Jul 21, 2009 at 2:23 PM, Leseur Guillaume<guiles1er at yahoo.fr> wrote:
> 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
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
More information about the vtkusers
mailing list