[vtkusers] Bug in vtkScalarBarActor

Andreas Kuhn kuhnan at ee.ethz.ch
Thu Dec 18 12:11:57 EST 2003


Hi,

I have a problem with vtkScalarBarActor:
Whenever I use the vtkScalarBarActor in combination with a transparent
actor, the scalar bar is completely grey on startup of the window. When
I resize the window the scalar bar gets colored.
I've posted an example code below which shows the problem. If you
comment out the line "aSphere->GetProperty()->SetOpacity(0.5);" the
scalar bar works fine. Otherwise the scalar bar is grey on startup.

Does someone know a solution to this problem?

Thanks a lot,
Andreas





#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkScalarBarActor.h"
#include "vtkLookupTable.h"
#include "vtkFloatArray.h"
#include "vtkPolyData.h"
#include "vtkPointData.h"

int main( int argc, char *argv[] )
{
  vtkIntArray *scalars = vtkIntArray::New();

  // create sphere geometry
  vtkSphereSource *sphere = vtkSphereSource::New();
    sphere->SetRadius(1.0);
    sphere->SetThetaResolution(18);
    sphere->SetPhiResolution(18);
    sphere->Update();

  for (int i=0; i<sphere->GetOutput()->GetNumberOfPoints(); i++){
    scalars->InsertNextTuple1(i);
  }
  sphere->GetOutput()->GetPointData()->SetScalars(scalars);

    // create a lookup table
  vtkLookupTable *looktable = vtkLookupTable::New();
    looktable->SetTableRange (0,
sphere->GetOutput()->GetNumberOfPoints());
    looktable->SetHueRange (0, 0.55);

  // map to graphics library
  vtkPolyDataMapper *map = vtkPolyDataMapper::New();
    map->SetLookupTable(looktable);
    map->ScalarVisibilityOn();
    map->SetScalarModeToUsePointData();
    map->UseLookupTableScalarRangeOn();
		map->SetColorModeToMapScalars();
    map->SetInput(sphere->GetOutput());

  //create ScalarBar
  vtkScalarBarActor *scalarBar = vtkScalarBarActor::New();
    scalarBar->SetLookupTable(map->GetLookupTable());

  // actor coordinates geometry, properties, transformation
  vtkActor *aSphere = vtkActor::New();
    aSphere->SetMapper(map);

////////////////////////////////////////////////////////////////////
    //if you comment next line out scalarBar is working fine
    aSphere->GetProperty()->SetOpacity(0.5);
////////////////////////////////////////////////////////////////////

  // a renderer and render window
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

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

  // add the actor to the scene
  ren1->AddActor(aSphere);
  ren1->AddActor2D(scalarBar);
  ren1->SetBackground(1,1,1); // Background color white

  // render an image (lights and cameras are created automatically)
  renWin->Render();

  // begin mouse interaction
  iren->Start();

  return 1;
}




More information about the vtkusers mailing list