[vtkusers] volume rendering questions

lpf lpf at vico-lab.com
Mon Nov 14 08:27:58 EST 2005


Hi
   I am rendering a 3D hear data, but when I rendering it.
Nothing display, the following is the code. I am sure that 
the file size information is correct and for the color and 
opacity tranfer function is no problem,too. I have tested 
the setting with volview.
    Who can tell me what's wrong, is anything else needed 
to set?



void main()
{
 vtkRenderer *ren = vtkRenderer::New();  
 ren->SetBackground(0.0,0.0,0.0);
 vtkRenderWindow *renWindow = vtkRenderWindow::New();
 renWindow->SetSize(500,500);
 renWindow->AddRenderer(ren);
 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); 
 iren->SetRenderWindow(renWindow);
 
 vtkImageReader* pReader = vtkImageReader::New();
     pReader->SetFileName("D:\\volume.im");
     pReader->SetDataScalarTypeToFloat();
     pReader->SetDataByteOrderToBigEndian();
     pReader->SetFileDimensionality(3);
     pReader->SetDataExtent(0,255,0,127,0,127);
     pReader->SetDataSpacing(0.39,0.78,0.78);
     pReader->SetHeaderSize(0);
     pReader->Update();

 vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();

 vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
     volumeMapper->SetVolumeRayCastFunction(compositeFunction);
     volumeMapper->SetInput(pReader->GetOutput());
     volumeMapper->SetSampleDistance(1);
  
 vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
        opacityTransferFunction->AddPoint(0,   0.000);
        opacityTransferFunction->AddPoint(142, 0.0);
        opacityTransferFunction->AddPoint(1085, 0.2);
        opacityTransferFunction->AddPoint(3000,0.2);

 vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
     colorTransferFunction->AddRGBPoint( 0, 0.3, 0.3, 1);
     colorTransferFunction->AddRGBPoint( 545, 0.3, 0.3, 1);
     colorTransferFunction->AddRGBPoint( 959, 0.3, 1, 0.3);
     colorTransferFunction->AddRGBPoint( 1085,1, 0.3, 0.3);
     colorTransferFunction->AddRGBPoint( 3000,1, 0.3, 0.3);

 vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
     volumeProperty->SetScalarOpacity(opacityTransferFunction);
     volumeProperty->SetColor(colorTransferFunction);

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

 ren->AddVolume(volume);   
 renWindow->Render()
 iren->Start(); 
}





More information about the vtkusers mailing list