[vtk] ImmediateModeRendering/colormap bug?

Randy Heiland heiland at ncsa.uiuc.edu
Thu Mar 2 09:26:12 EST 2000


The following pgm seems to demonstrate a bug with using ImmediateModeRendering.
 The pgm reads in the office.vtk dataset (a structured grid containing a vector
field and a scalar field).  I then display a streamtube and a slicing plane,
colormapped differently.  And I use ImmediateModeRendering for the associated
mappers.  A refresh of the render window will cause the colormap on the
streamtube to be "overridden".  However, by not using ImmediateModeRendering on
the tubeMapper, it works fine.

I'm using vtk3.1 on an SGI.

--Randy

-------------------------------------------------------------
#include <stdlib.h>
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStructuredGridReader.h"
#include "vtkDataObjectReader.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredGridOutlineFilter.h"
#include "vtkPlaneSource.h"
#include "vtkExtractVectorComponents.h"
#include "vtkExtractGrid.h"
#include "vtkStreamLine.h"
#include "vtkGeometryFilter.h"
#include "vtkTubeFilter.h"
#include "vtkProbeFilter.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);

  // do a blue -> red LUT  (default is red -> blue)
  vtkLookupTable *clut = vtkLookupTable::New();
  clut->SetHueRange(0.667, 0.0);
  clut->Build();

  cout << "reading data...";
  cout.flush();
  vtkStructuredGridReader *sgR1 = vtkStructuredGridReader::New();
  // bounds: 0,4.5, 0,4.5, 0,2.5
  // temp range: -3.87, 0.719
  // max vec norm: 0.805
  sgR1->SetFileName("../../../vtkdata/office.vtk");
  sgR1->Update();
  cout << "done." << endl;

  float
maxnormVel=sgR1->GetOutput()->GetPointData()->GetVectors()->GetMaxNorm();
  cout << "maxnormVel = " << maxnormVel << endl;


  vtkStructuredGridOutlineFilter *bbox = vtkStructuredGridOutlineFilter::New();
  bbox->SetInput(sgR1->GetOutput());
  vtkPolyDataMapper *bboxMapper = vtkPolyDataMapper::New();
  bboxMapper->SetInput(bbox->GetOutput());
  vtkActor *bboxActor = vtkActor::New();
  bboxActor->SetMapper(bboxMapper);

  // -------- Create a streamline/tube colormapped with speed

  vtkStreamLine *streamer = vtkStreamLine::New();
  streamer->SetInput(sgR1->GetOutput());
  streamer->SetStartPosition(2,2,1);

  streamer->SetMaximumPropagationTime(100);
  streamer->SetStepLength(0.1);
  // vs.  "fraction of size of each cell"
  //streamer->SetIntegrationStepLength(0.05);

  //  vel magnitude
  streamer->SpeedScalarsOn();
  streamer->SetIntegrationDirectionToIntegrateBothDirections();
  //streamer->SetIntegrationDirectionToForward();
  //streamer->Update();

  float tubeRadius = .10;
  int tubeFaces = 6;
  vtkTubeFilter *streamTube = vtkTubeFilter::New();
  streamTube->SetInput(streamer->GetOutput());
  streamTube->SetRadius(tubeRadius);
  streamTube->SetNumberOfSides(tubeFaces);
  //streamTube->SetVaryRadiusToVaryRadiusByVector();

  vtkPolyDataMapper *tubeMapper = vtkPolyDataMapper::New();

// NB - if we don't use ImmediateModeRendering here, it works OK
  tubeMapper->ImmediateModeRenderingOn();
  tubeMapper->SetInput(streamTube->GetOutput());
  //tubeMapper->.SetInput(streamer->.GetOutput());
  tubeMapper->SetScalarRange(0.0,maxnormVel);
  tubeMapper->SetLookupTable(clut);

  vtkActor *streamerActor = vtkActor::New();
  streamerActor->SetMapper(tubeMapper);



  // -------- Create a slicing plane colormapped with temp

  vtkPlaneSource *xplane = vtkPlaneSource::New();
  float xval = 3.67;
  xplane->SetOrigin(xval, 0.01,0.01);
  xplane->SetPoint1(xval, 4.5, 0.01);
  xplane->SetPoint2(xval, 0.01,2.5);
  xplane->SetResolution(40,40);
  xplane->SetResolution(10,10);

  vtkProbeFilter *xprobe = vtkProbeFilter::New();
  xprobe->SetSource(sgR1->GetOutput());
  xprobe->SetInput(xplane->GetOutput());

  vtkGeometryFilter *xprobeGeom = vtkGeometryFilter::New();
  xprobeGeom->SetInput(xprobe->GetOutput());

  vtkPolyDataMapper *xsliceMapper = vtkPolyDataMapper::New();
  xsliceMapper->ImmediateModeRenderingOn();
  xsliceMapper->SetInput(xprobeGeom->GetOutput());
  xsliceMapper->ScalarVisibilityOn();
  xsliceMapper->SetScalarRange(-4,1);
  xsliceMapper->SetLookupTable(clut);

  vtkActor *xsliceActor = vtkActor::New();
  xsliceActor->SetMapper(xsliceMapper);


  //----------------------
  renderer->AddActor(bboxActor);
  renderer->AddActor(streamerActor);
  renderer->AddActor(xsliceActor);

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

//  renderer->GetActiveCamera()->Azimuth(30);
  renderer->GetActiveCamera()->Roll(30);
  renderer->GetActiveCamera()->Elevation(-45);

  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