[vtkusers] coloring a sphere by elevation

Liam Kurmos quantum.leaf at gmail.com
Fri Aug 19 11:39:00 EDT 2011


Hi David,

coloring of the sphere using the lookuptable is working.

Im now trying to turn the output of vtkcurvatures into colour using a
similar approach. i set up an unsigned int array of colors in the same
way. My setting the LUT range very large all the colors being set are
middle hue green as expected however the rendered output is ignoring
these colors as though i had not set them and everything ends up
either red or blue.

i output my polydatamapper as an ascii file.

if i filter out the data it starts:

?xml version="1.0"?>
<VTKFile type="PolyData" version="0.1" byte_order="LittleEndian"
compressor="vtkZLibDataCompressor">
  <PolyData>
    <Piece NumberOfPoints="121426" NumberOfVerts="0" NumberOfLines="0"
NumberOfStrips="0" NumberOfPolys="230868">
      <PointData Scalars="Colors" Normals="Normals">
        <DataArray type="Float32" Name="ImageScalars" format="ascii"
RangeMin="254550" RangeMax="254550">
        </DataArray>
        <DataArray type="Float32" Name="Normals"
NumberOfComponents="3" format="ascii" RangeMin="0.99999995108"
RangeMax="1.0000000476">
        </DataArray>
        <DataArray type="UInt8" Name="Colors" NumberOfComponents="3"
format="ascii" RangeMin="256.03515384" RangeMax="256.12692166">
        </DataArray>
      </PointData>
      <CellData>
      </CellData>
      <Points>
        <DataArray type="Float32" Name="Points" NumberOfComponents="3"
format="ascii" RangeMin="0.16444380154" RangeMax="1.4197872303">
        </DataArray>
      </Points>

the colors dataarray shows green, although there seems to be trouble
with the min max range.

<DataArray type="UInt8" Name="Colors" NumberOfComponents="3"
format="ascii" RangeMin="256.03515384" RangeMax="256.12692166">
          24 255 0 24 255 0
          24 255 0 24 255 0
          24 255 0 24 255 0
          24 255 0 24 255 0...

can you suggest why im not seeing a green polydata?

vtkCurvatures *curv = vtkCurvatures::New();
    curv->SetInputConnection(oc->volume4D->contourer->GetOutputPort());
    curv->SetCurvatureTypeToGaussian();
    //        curv->SetCurvatureTypeToGaussian();
    //curv->SetCurvatureTypeToMinimum();
    //curvaturesFilter->SetCurvatureTypeToMaximum();
    vtkLookupTable* lut = vtkLookupTable::New();
    lut->SetHueRange(0, 0.6); //Red to Blue
    lut->SetAlphaRange(1, 1);
    lut->SetValueRange(1, 1.0);
    lut->SetSaturationRange(1.0, 1.0);
    lut->SetNumberOfTableValues(256 * 256 * 256);
    lut->SetRange(-10000000000000, 10000000000000); //altering range
appear not to effect output
    lut->Build();


    vtkSmartPointer<vtkUnsignedCharArray> colors =
            vtkSmartPointer<vtkUnsignedCharArray>::New();
    colors->SetNumberOfComponents(3);
    colors->SetName("Colors");

    vtkSmartPointer<vtkPolyData> polyd = curv->GetOutput();
    vtkSmartPointer<vtkPointData> pointd = polyd->GetPointData();
    polyd->Update();
    for (int i = 0; i < polyd->GetNumberOfPoints(); i++) {

        double val=
vtkDoubleArray::SafeDownCast(polyd->GetPointData()->GetScalars())->GetValue(i);
        double dcolor[3];
        lut->GetColor(val, dcolor);

        unsigned char color[3];
        for (unsigned int j = 0; j < 3; j++) {
            color[j] = static_cast<unsigned char> (255.0 * dcolor[j]);
        }

        colors->InsertNextTupleValue(color);
    }
    pointd->SetScalars(colors);
    pointd->Update();
    vtkPolyDataMapper* polyMap2 = vtkPolyDataMapper::New();

    polyMap2->SetInputConnection(polyd->GetProducerPort());
    polyMap2->GetInput()->Update();


    vtkSmartPointer<vtkXMLPolyDataWriter> writer =
            vtkSmartPointer<vtkXMLPolyDataWriter>::New();
    writer->SetFileName("test.vtp");
    writer->SetInput(polyMap2->GetInput());

    // Optional - set the mode. The default is binary.
    //writer->SetDataModeToBinary();
    writer->SetDataModeToAscii();

    writer->Write();

best regards,

Liam


On Fri, Aug 19, 2011 at 3:46 PM, Liam Kurmos <quantum.leaf at gmail.com> wrote:
>>
>> Did you see this example?
>>
>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Color_a_mesh_by_height
>>
>
> no missed that somehow. Cheers!
>
> i note this example does not use mapper->setLookuptable() but rather
> gets 'colors' from the LUT
> and does
>
>  outputPolyData->GetPointData()->SetScalars(colors);
>  mapper->SetInputConnection(outputPolyData->GetProducerPort());
>
> it looks like my lookup table was working but other that the
> sethuerange() (which worked) it was having no effect on the output
> when i did mapper->setLookuptable() . In fact i could remove my lut
> and the mapper->setlookuptable() and get the same output with red to
> blue hue range.
>
> all working now, thanks for the help.
>
> Liam
>
>
> On Fri, Aug 19, 2011 at 2:48 PM, David Doria <daviddoria at gmail.com> wrote:
>> On Fri, Aug 19, 2011 at 9:39 AM, Liam Kurmos <quantum.leaf at gmail.com> wrote:
>>>
>>> I'm creating an example to colour the surface of a sphere using a
>>> lookup table, where the scalar value is just the value of one of the
>>> vertex coords.
>>> The code below essentially works but only shows 2 colors.
>>>
>>> 2Qs:
>>>
>>> -why dont i see a range of colors from the lookup table?
>>>
>>> -i thought i should be able to get the coordinates of a vertex from
>>> the vtkPointData but i couldnt do this or find an example and had to
>>> use vtkPolyData->getPoint(i). Is it straight forward to get down to
>>> the points for pointdata?
>>>
>>>
>>> any thoughts appreciated,
>>>
>>>
>>> Liam
>>
>> Did you see this example?
>>
>> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/Color_a_mesh_by_height
>>
>> David
>



More information about the vtkusers mailing list