[vtkusers] vtkScalarBarActor range problem

Randy Heiland heiland at ncsa.uiuc.edu
Wed Jul 12 14:37:08 EDT 2000


I can't figure out how to update the range (labels) on a vtkScalarBarActor when
its associated mapper changes.  I've included a test pgm.

thanks for any help,
--Randy

//
// Try to resolve confusion over a mapper's (scalar) range and its
// associated LUT's (table, scalar) range
//

#include <stdlib.h>
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkLookupTable.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkScalarBarActor.h"

int main(int argc, char **argv)
{
  vtkRenderer *renderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(renderer);

  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

  // ----  explicitly define one LUT
  vtkLookupTable *lut = vtkLookupTable::New();
  lut->Build();

  // ----- create line #1 ---------
  vtkPoints *pts1 = vtkPoints::New();
    pts1->InsertPoint(0, -1,0,0);
    pts1->InsertPoint(1,  0,0,0);
    pts1->InsertPoint(2,  1,0,0);

  vtkScalars *scalars1 = vtkScalars::New();
//???
//    scalars1->SetLookupTable(lut);
    scalars1->InsertScalar(0, -1.1);
    scalars1->InsertScalar(1,  0.2);
    scalars1->InsertScalar(2,  2.2);

  vtkCellArray *ca1 = vtkCellArray::New();
    ca1->InsertNextCell(3);
    ca1->InsertCellPoint(0);
    ca1->InsertCellPoint(1);
    ca1->InsertCellPoint(2);

  vtkPolyData *line1 = vtkPolyData::New();
    line1->SetPoints(pts1);
    line1->SetLines(ca1);
    line1->GetPointData()->SetScalars(scalars1);
//    float *line1Range = line1->GetPointData()->GetScalars()->GetRange();
//    printf("line1Range = %f %f",line1Range[0],line1Range[1]);

  vtkPolyDataMapper *line1Map = vtkPolyDataMapper::New();
    line1Map->SetInput(line1);
    line1Map->ScalarVisibilityOn();
    line1Map->SetLookupTable(lut);
    line1Map->SetScalarRange(-1.1,2.2);

  vtkActor *line1Actor = vtkActor::New();
    line1Actor->SetMapper(line1Map);

  // ----- Add actor ---------
  vtkScalarBarActor *ColorBarActor = vtkScalarBarActor::New();
  ColorBarActor->SetLookupTable(line1Map->GetLookupTable());
  ColorBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
  ColorBarActor->GetPositionCoordinate()->SetValue(0.1, 0.01);
  ColorBarActor->SetOrientationToHorizontal();
  ColorBarActor->SetWidth(0.8);
  ColorBarActor->SetHeight(0.05);


  // ----- Add actor ---------
  renderer->AddActor(line1Actor);
  renderer->AddActor2D(ColorBarActor);

  renderer->SetBackground(0,0,0);
  renWin->SetSize(300,300);

  cout<<"------------ line1Map:"<<endl;
  line1Map->PrintSelf(cout,4);

  renWin->Render();



  cout << "\n--- press key to change range -> 0,2:" <<endl;
  int val;;
//  cin >> val;
  getchar();

  // Change the scalar range of the mapper
//  line1Map->SetScalarRange(-1.1,2.2);
  line1Map->SetScalarRange(0.0,2.0);

  // Change the scalar range of the LUT
  lut->SetTableRange(0.0,2.0);
  lut->Build();
  line1Map->SetLookupTable(lut);
  line1Map->Update();

  ColorBarActor->SetLookupTable(line1Map->GetLookupTable());


  cout<<"------------ line1Map(2):"<<endl;
  line1Map->PrintSelf(cout,8);

  renWin->Render();
  iren->Start();
}




More information about the vtkusers mailing list