[vtkusers] Volume Rendering

lappadj at libero.it lappadj at libero.it
Fri Oct 12 16:38:39 EDT 2001


Hi,
i utilize this code for rendering one volume of Bmp slices from MRI 
scan,but the effect of the rendering is not good,the resultant image 
appear split in two half,is possible to be one error on the slices 
format,because i convert dicom images into bmp images?Can you help me?
Thanks a lot 

Massimiliano La Paglia
  
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStructuredPointsReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkBMPReader.h"

#include "SaveImage.h"

void main( int argc, char *argv[] )
{
  // Create the renderer, render window, and interactor
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren1);
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

 //Legge bmp file
	vtkBMPReader *imagein=vtkBMPReader::New();
	imagein->SetFilePrefix ("C:/vtkdata/knee/pat");
	imagein->SetDataExtent(0, 255, 0, 255,1,64);

	
	// Create a transfer function mapping scalar value to opacity
      vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
      oTFun->AddSegment(80, 0.0, 255, 1.0);

  // Create a transfer function mapping scalar value to color (grey)
  vtkPiecewiseFunction *cTFun = vtkPiecewiseFunction::New();
    cTFun->AddSegment(0, 1.0, 255, 1.0);

  // Create a property for the volume and set the transfer functions.
  // Turn shading on and use trilinear interpolation
  vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
    volumeProperty->SetColor(cTFun);
    volumeProperty->SetScalarOpacity(oTFun);
    volumeProperty->SetInterpolationTypeToLinear();
    volumeProperty->ShadeOn();

  // Create a ray function - this is a compositing ray function
  vtkVolumeRayCastCompositeFunction *compositeFunction = 
    vtkVolumeRayCastCompositeFunction::New();

  // Create the volume mapper and set the ray function and scalar input
  vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
    volumeMapper->SetInput(imagein->GetOutput());
    volumeMapper->SetVolumeRayCastFunction(compositeFunction);

  // Create the volume and set the mapper and property
  vtkVolume *volume = vtkVolume::New();
    volume->SetMapper(volumeMapper);
    volume->SetProperty(volumeProperty);

  // Add this volume to the renderer and get a closer look
  ren1->AddVolume(volume);
  ren1->GetActiveCamera()->Azimuth(20.0);
  ren1->GetActiveCamera()->Dolly(1.60);
  ren1->ResetCameraClippingRange();
  
  renWin->SetSize(300,300);

  renWin->Render();

  SAVEIMAGE( renWin );

  // Interact with the data at 3 frames per second
  iren->SetDesiredUpdateRate(1.0);
  iren->SetStillUpdateRate(0.001);
  iren->Start();

  // Clean up
  ren1->Delete();
  renWin->Delete();
  iren->Delete();
  imagein->Delete();
  oTFun->Delete();
  cTFun->Delete();
  volumeProperty->Delete();
  compositeFunction->Delete();
  volumeMapper->Delete();
  volume->Delete();
}








More information about the vtkusers mailing list