[vtkusers] Updating color scale for glypsh.

Zoltan Kovacs Zoltan.Kovacs at esi-group.com
Tue Jul 24 11:23:43 EDT 2018


Dear all,

I fail to update the lookup table for a VTU file particle data visualized by sphere glyphs. The VTU file
contains the fields "Radii" and "Mass"  with the particle coordinates. I use the following code to set up the color scale for the particles with coloring based on the field "Radii":

    vtkSmartPointer<vtkXMLUnstructuredGridReader>           reader;
    vtkSmartPointer<vtkDataSetMapper>                       mapper;
    vtkSmartPointer<vtkActor>                               actor;
    vtkSmartPointer<vtkGlyph3D>                             glyph;
    vtkSmartPointer<vtkScalarBarActor>                      scalarBar;
    vtkSmartPointer<vtkLookupTable>                         lookupTable;
    vtkSmartPointer<vtkSphereSource>                        sphere;

    reader           = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
    mapper           = vtkSmartPointer<vtkDataSetMapper>::New();
    actor            = vtkSmartPointer<vtkActor>::New();
    sphere           = vtkSmartPointer<vtkSphereSource>::New();
    glyph            = vtkSmartPointer<vtkGlyph3D>::New();
    lookupTable      = vtkSmartPointer<vtkLookupTable>::New();
    scalarBar        = vtkSmartPointer<vtkScalarBarActor>::New();


    reader->SetFileName(fileNameStdStr.c_str());
    reader->Update();
    reader->GetOutput()->GetPointData()->SetActiveScalars("Radii");
    reader->GetOutput()->GetPointData()->GetScalars()->GetRange(range);

    // lookup table
    lookupTable->SetTableRange(range[0], range[1]);
    lookupTable->SetHueRange(0.6667, 0.0);
    lookupTable->SetSaturationRange(1, 1);
    lookupTable->SetValueRange(1, 1);
    lookupTable->Build();

    scalarBar->SetTitle("Radii");
    scalarBar->SetNumberOfLabels(4);

    // initialize shpere source amd glyphs
    sphere->SetThetaResolution(10);
    sphere->SetPhiResolution(10);
    sphere->Update();

    glyph->SetScaleModeToScaleByScalar();
    glyph->SetScaleFactor(2.0);

    // connect the output of the VTU file reader and the sphere source and to the glyps
    glyph->SetInputConnection(reader->GetOutputPort());
    glyph->SetSourceConnection(sphere->GetOutputPort());
    glyph->Update();

    mapper->SetInputConnection(glyph->GetOutputPort());
    mapper->ScalarVisibilityOn();
    mapper->SetColorModeToMapScalars();
    mapper->SetScalarRange(lookupTable->GetTableRange());
    mapper->SetLookupTable(lookupTable);
    mapper->Update();


This works well, as seen on in the picture snapshot1.png. However when I modify the lookup
table by setting to the field "Mass" I can only update the color bar but the color scale for
the particles remains the same and the colors of the particles become out of range. The
picture snapshot2.png shows this behavior. The code for the modification of the color scale
repeating the original setup is the following:


  readerVTU->GetOutput()->GetPointData()->SetActiveScalars("Mass");
  readerVTU->GetOutput()->GetPointData()->GetScalars()->GetRange(range);

  lookupTable->SetTableRange(range[0], range[1]);
  lookupTable->SetHueRange(0.6667, 0.0);
  lookupTable->SetSaturationRange(1, 1);
  lookupTable->SetValueRange(1, 1);
  lookupTable->Modified();
  scalarBar->SetTitle("Mass");

  mapper->ScalarVisibilityOn();
  mapper->SetColorModeToMapScalars();
  mapper->SetScalarRange(lookupTable->GetTableRange());
  mapper->SetLookupTable(lookupTable);
  mapper->Update();

  I guess something is missing from the update and someone may know what is needed to the
  proper update of the particle color scale. Thanks a lot.

  Kind regards,
  Zoltan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180724/37b32bc5/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: snapshot1.png
Type: image/png
Size: 191133 bytes
Desc: snapshot1.png
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180724/37b32bc5/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: snapshot2.png
Type: image/png
Size: 132705 bytes
Desc: snapshot2.png
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180724/37b32bc5/attachment-0003.png>


More information about the vtkusers mailing list