[vtkusers] Seg fault in DICOM volume rendering app

Moore, Brett BRETT.MOORE at ttu.edu
Wed Mar 21 14:07:36 EDT 2007


Hi,

I am attempting to render a volume consisting of 25 16-bit DICOM images. The application seems to build correctly, but seg faults during rendering.  (I am running VTK 5.0 under Mandriva 2007.  The default nv driver is currently used).  I could use a bit of assistance in determining where the issue lies.  I suspect the problem is associated with the 16-bit nature of the DICOM images.

Here is the relevant portion of the code:

  renderer = vtkRenderer::New();
  
  renwin = vtkRenderWindow::New();
  renwin -> AddRenderer(renderer);
  renwin -> SetSize(SIZE,SIZE);     
  
  iren = vtkRenderWindowInteractor::New();
  iren -> SetRenderWindow(renwin);

  cout << endl << "Loading data files..." << endl;
  reader = vtkDICOMImageReader::New();
  reader -> SetDirectoryName("dicom");

  // Image is 16 bits: confirmed
  // cout << reader -> GetBitsAllocated() << endl;

  vtkImageCast *cast = vtkImageCast::New();
  cast -> SetInput(reader->GetOutput());
  cast -> SetOutputScalarTypeToUnsignedShort();

  // ----------------------------------------------------
  // Create transfer functions
  oTFun = vtkPiecewiseFunction::New();
  oTFun -> AddPoint(0,0.0);
  oTFun -> AddPoint(65535,1.0);

  vtkColorTransferFunction *cTFun = vtkColorTransferFunction::New();
  cTFun -> AddRGBPoint(0,0.85,0.85,0.85);
  cTFun -> AddRGBPoint(65535,1.0,1.0,1.0);
  
   volumeProperty = vtkVolumeProperty::New();
   volumeProperty -> SetColor(cTFun);
   volumeProperty -> SetScalarOpacity(oTFun);
   volumeProperty -> ShadeOn();
   volumeProperty -> SetInterpolationTypeToLinear();

   compositeFunction = vtkVolumeRayCastCompositeFunction::New();

   volumeMapper = vtkVolumeRayCastMapper::New();
   volumeMapper -> SetVolumeRayCastFunction(compositeFunction);
   volumeMapper -> SetInput(cast -> GetOutput());

   vtkVolume *volume = vtkVolume::New();
   volume -> SetMapper(volumeMapper);
   volume -> SetProperty(volumeProperty);

   renderer -> AddVolume(volume);
   renwin -> Render();
   
   iren -> Start();


I also have the gdb stack trace (which makes me believe *I* screwed something up in the rendering pipeline):

#0  0xb7adcf99 in vtkCastRay_TrilinSample_Shaded<unsigned short> ()
   from /usr/bin/../lib/libvtkVolumeRendering.so.5.0
#1  0xb7ad5be3 in vtkVolumeRayCastCompositeFunction::CastRay ()
   from /usr/bin/../lib/libvtkVolumeRendering.so.5.0
#2  0xb7aeae7c in VolumeRayCastMapper_CastRays ()
   from /usr/bin/../lib/libvtkVolumeRendering.so.5.0
#3  0xb67366e2 in vtkMultiThreader::SingleMethodExecute ()
   from /usr/bin/../lib/libvtkCommon.so.5.0
#4  0xb7aeda43 in vtkVolumeRayCastMapper::Render ()
   from /usr/bin/../lib/libvtkVolumeRendering.so.5.0
#5  0xb7e4003e in vtkVolume::RenderTranslucentGeometry ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#6  0xb7e1a6a2 in vtkRenderer::UpdateGeometry ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#7  0xb7e72586 in vtkOpenGLRenderer::DeviceRender ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#8  0xb7e1c30f in vtkRenderer::Render ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#9  0xb7e221bc in vtkRendererCollection::Render ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#10 0xb7e0f283 in vtkRenderWindow::DoStereoRender ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#11 0xb7e115e7 in vtkRenderWindow::DoFDRender ()
#12 0xb7e12279 in vtkRenderWindow::DoAARender ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#13 0xb7e10892 in vtkRenderWindow::Render ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#14 0xb7e8316e in vtkXOpenGLRenderWindow::Render ()
   from /usr/bin/../lib/libvtkRendering.so.5.0
#15 0x080498c9 in main ()

Notice that I used a VTKImageCast to fix a suitable datatype for volume rendering.  If I try to pipe the reader output directly to the volume mapper:

  reader -> SetDataScalarTypeToUnsignedShort();
  ... 
  <snip>
  ...
  volumeMapper -> SetInput(cast -> GetOutput());

I get the following error:
  ERROR: In /home/glehmann/rpm/BUILD/VTK/VolumeRendering/vtkVolumeRayCastMapper.cxx, line 326
  vtkVolumeRayCastMapper (0x80679e8): Cannot volume render data of type short, only unsigned char or unsigned short.

Any suggestions?
Thanks!
Brett






More information about the vtkusers mailing list