[vtkusers] creating volumes from tiff image slices

Jesse Corrington corrington_j at hotmail.com
Wed Aug 17 14:38:58 EDT 2005


I am using vtk with java, and trying to create volumes from tiff image 
slices.  I have 500 slices, names recon000.tiff through recon499.tif.  I am 
able to create and volume, and see it in the window, but it appears as if 
part of one end of the volume is choped off, and appears on the other side 
of the viewport.  Here is what i am doing.  Thanks in advance for the help.

Jesse

// create renderer, render window, and interactor
		  vtkRenderer aRenderer = new vtkRenderer();
		  vtkRenderWindow renWin = new vtkRenderWindow();
		  renWin.AddRenderer(aRenderer);
		  vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
		  iren.SetRenderWindow(renWin);

		  vtkImageReader reader = new vtkImageReader();
		  reader.SetFilePrefix("");
		  reader.SetFilePrefix(directory);
		  reader.SetFilePattern("%s/recon%.3d.tif");
		  reader.SetDataScalarTypeToUnsignedChar();

		  //todo, get the size of the first image and use it for this
		  reader.SetDataExtent(0, width, 0, height, 0, 499);
		  reader.SetDataByteOrderToBigEndian();
		  reader.Update();

		  //color transfer function
		  vtkColorTransferFunction colorTransfer = new vtkColorTransferFunction();
		  colorTransfer.AddRGBPoint(0, 0, 0, 0);
		  colorTransfer.AddRGBPoint(255, 1, 0, .5);

		  //Create transfer mapping scalar value to opacity
		  vtkPiecewiseFunction opacityTransfer = new vtkPiecewiseFunction();
		  opacityTransfer.AddPoint(100, 0.0);
		  opacityTransfer.AddPoint(160, .2);
		  opacityTransfer.AddPoint(255, 1);

		  //create the gradiant opacity transfer function
		  vtkPiecewiseFunction gtFun = new vtkPiecewiseFunction();
		  gtFun.AddPoint(0, 0);
		  gtFun.AddPoint(5, 0);
		  gtFun.AddPoint(10, 1);
		  gtFun.AddPoint(255, 1);

		  vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
		  volumeProperty.SetColor(colorTransfer);
		  volumeProperty.SetScalarOpacity(opacityTransfer);
		  volumeProperty.SetGradientOpacity(gtFun);
		  volumeProperty.SetInterpolationTypeToLinear();
		  volumeProperty.ShadeOn();

		  vtkVolumeRayCastCompositeFunction compositeFunction = new 
vtkVolumeRayCastCompositeFunction();
		  vtkVolumeRayCastMapper volumeMapper = new vtkVolumeRayCastMapper();
		  volumeMapper.SetInput(reader.GetOutput());
		  volumeMapper.SetVolumeRayCastFunction(compositeFunction);

		  vtkVolume volume = new vtkVolume();
		  volume.SetMapper(volumeMapper);
		  volume.SetProperty(volumeProperty);

		  // set the initial view
		  vtkCamera aCamera = new vtkCamera();
		  aCamera.SetViewUp (0, 0, -1);
		  aCamera.SetPosition (0, 1, 0);
		  aCamera.SetFocalPoint (0, 0, 0);
		  aCamera.ComputeViewPlaneNormal();

		  // add the actors to the renderer
		  aRenderer.AddVolume(volume);
		  aRenderer.SetActiveCamera(aCamera);
		  aRenderer.ResetCamera ();
		  aCamera.Dolly(1.5);

		  aRenderer.SetBackground(1, 1, 1);
		  renWin.SetSize(500, 500);

		  aRenderer.ResetCameraClippingRange ();

		  // Initialize the event loop and then start it.
		  iren.Initialize();
		  iren.Start();

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963




More information about the vtkusers mailing list