ImmediateModeRendering + SetLookupTable bug

Randy Heiland heiland at ncsa.uiuc.edu
Tue Mar 21 08:28:05 EST 2000


This is a follow-on to my post awhile back regarding a bug that is demonstrated
by having 2 polydata/mappers and doing ImmediateModeRenderingOn *and*
SetLookupTable on each mapper (where SetScalarRange is different for each).
 The bug's symptom is that one actor's LUT gets "overridden" by the other (the
last actor added to the renderer "wins").

I've attached the following super-simple pgm that demonstrates this - at least
on an SGI and on a Linux/Mesa box, both using a recent Nightly VTK.  Note that
if you do NOT use ImmediateModeRendering OR you do NOT explicitly
SetLookupTable, the pgm behaves as one would expect.

While I start to dig into the code to find this bug, if anyone has any useful
feedback, e.g., "I'm using vtk XXX on machine YYY and the bug doesn't appear",
or better yet, "Yes, we fixed that already", I'd like to hear from you.

--Randy



//
// This pgm illustrates a bug with using ImmediateModeRenderingOn together
// with an explicit LUT for two distinct mappers - using one or the other
// is OK, but used together there's a problem in that one actor's mapper
// overrides the other's.
//

#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 default 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->InsertScalar(0, 0.0);
    scalars1->InsertScalar(1, 1.0);
    scalars1->InsertScalar(2, 2.0);

  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->ImmediateModeRenderingOn();
    line1Map->SetScalarRange(0.0,2.0);
    // Note: the combo of ImmediateModeRenderingOn + SetLookupTable is a bug
    line1Map->SetLookupTable(lut);

  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->InsertScalar(0, 0.0);
    scalars2->InsertScalar(1, 1.0);
    scalars2->InsertScalar(2, 2.0);

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

  vtkPolyDataMapper *line2Map = vtkPolyDataMapper::New();
    line2Map->SetInput(line2);
    line2Map->ScalarVisibilityOn();
    line2Map->ImmediateModeRenderingOn();
    line2Map->SetScalarRange(0.0,1.0);
    // Note: the combo of ImmediateModeRenderingOn + SetLookupTable is a bug
    line2Map->SetLookupTable(lut);

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


  // ----- Add the actors ---------
  // Note: the actor that's added last gets its LUT used
  renderer->AddActor(line1Actor);
  renderer->AddActor(line2Actor);

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

  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