[vtkusers]help: Volume Rendering problems

lpf lpf at vico-lab.com
Mon Nov 21 09:12:51 EST 2005


Hi, VTK users
    Now I am rendering a volume Data, it is raw single 3D data, at first I render it slice by slice, 
it is no problem,
so I think file reading is no problem , but when I render it as volume, Nothing display, who can 
tell me what's wrong
    My VTK is Version 4.0
    Here is the code
------------------------------------------------------
#include "vtkImageReader.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
int main()
{
 vtkImageReader* reader = vtkImageReader::New();
  reader->SetFileName("D:\\volume.im"); //single 3D raw data
  reader->SetDataScalarTypeToFloat();
  reader->SetDataByteOrderToBigEndian();
  reader->SetFileDimensionality(3);
  reader->SetDataExtent(0,255,0,127,0,127);
  reader->SetDataSpacing(0.39,0.78,0.78);
  reader->SetHeaderSize(0);
  reader->Update();

 vtkPiecewiseFunction *opacityFun = vtkPiecewiseFunction::New();
  opacityFun->AddPoint(0,  0.0);
  opacityFun->AddPoint(10, 0.0);
  opacityFun->AddPoint(500, 0.1);
  opacityFun->AddPoint(5000, 0.4);

 vtkColorTransferFunction *colorFun = vtkColorTransferFunction::New();
  colorFun->AddRGBPoint(0, 0.3, 0.3, 1.0);
  colorFun->AddRGBPoint(5000,1.0, 0.0, 0.0);

 vtkVolumeProperty *volProperty = vtkVolumeProperty::New();
  volProperty->SetScalarOpacity(opacityFun);
  volProperty->SetColor(colorFun);

 vtkVolumeRayCastCompositeFunction *compositeFun = vtkVolumeRayCastCompositeFunction::New();

 vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
  volumeMapper->SetVolumeRayCastFunction(compositeFun);
  volumeMapper->SetInput(reader->GetOutput());

 vtkVolume* volProp = vtkVolume::New();
  volProp->SetMapper(volumeMapper);
  volProp->SetProperty(volProperty);

 vtkRenderer *render = vtkRenderer::New();
  render->AddVolume(volProp);
  render->SetBackground(1.0,1.0,1.0);
 vtkRenderWindow *renWin = vtkRenderWindow::New();
 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  renWin->AddRenderer(render);
  renWin->SetSize(500,500);
  renWin->SetInteractor(iren);

 renWin->Render();
 iren->Start();
}
------------------------------------------------------



Best regards
PengFei Liu 




More information about the vtkusers mailing list