confusion over vtkScalars & vtkLookupTable

Randy Heiland heiland at ncsa.uiuc.edu
Wed Mar 22 14:56:49 EST 2000


No ImmediateModeRendering-related question, I promise.  But in digging around
on that problem, I came to realize that I don't understand what is actually
happening between vtkScalars and vtkLookupTable.  It does what I expect (using
display lists), but the  PrintSelf of the two mappers in the attached pgm is
not what I expected.  Note that I dump both mappers before rendering, render,
then dump both again.  The condensed results (causing my confusion) are:

------------ line1Map:
    Lookup Table:
      Table Range: (0, 1)
    Scalar Visibility: On
    Scalar Range: (-1.1, 2.2)
------------ line2Map:
    Lookup Table:
      Table Range: (0, 1)
    Scalar Visibility: On
    Scalar Range: (0.3, 2.9)

<render>

------------ line1Map(2):
        Lookup Table:
          Table Range: (0.3, 2.9)    (??  really the range of line2Map)
        Scalar Visibility: On
        Scalar Range: (-1.1, 2.2)
------------ line2Map(2):
        Lookup Table:
          Table Range: (0.3, 2.9)
        Scalar Visibility: On
        Scalar Range: (0.3, 2.9)

Basically, why *does* the LUT maintain a Table Range?  Couldn't it simply be a
normalized range and the specified range on the mapper would simply map into
the normalized LUT?  I'm missing something and any insight would be
appreciated.

thanks,
--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"


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);


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

  vtkScalars *scalars2 = vtkScalars::New();
//???
//    scalars2->SetLookupTable(lut);
    scalars2->InsertScalar(0, 0.3);
    scalars2->InsertScalar(1, 0.9);
    scalars2->InsertScalar(2, 2.9);

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

  vtkPolyData *line2 = vtkPolyData::New();
    line2->SetPoints(pts2);
    line2->SetLines(ca2);
    line2->GetPointData()->SetScalars(scalars2);
//    float *line2Range = line2->GetPointData()->GetScalars()->GetRange();
//    printf("line2Range = %f %f",line2Range[0],line2Range[1]);

  vtkPolyDataMapper *line2Map = vtkPolyDataMapper::New();
    line2Map->SetInput(line2);
    line2Map->ScalarVisibilityOn();
    line2Map->SetLookupTable(lut);
    line2Map->SetScalarRange(0.3,2.9);

  vtkActor *line2Actor = vtkActor::New();
    line2Actor->SetMapper(line2Map);


  // ----- Add the actors ---------
  renderer->AddActor(line1Actor);
  renderer->AddActor(line2Actor);

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

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

  renWin->Render();

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

  renWin->Render();
  iren->Start();
}
--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list