[vtkusers] volume rendering problem!

Paul McGuinness mcguinpg at maths.tcd.ie
Fri Jul 4 10:10:14 EDT 2003


Hi All,

I am having a problem displaying the volume rendering of ironProt.vtk. The
code compiles, and the display window appears but there is no rendering in
the window, the window is just empty. Can someone please help me, I am
reading in the file using vtkImageReader and using vtkImageCast to convert
it to unsigned-short. Then vtkVolumeRayCastMapper sets its input to the
vtkImageCast object's output, see below. I am using vtk4.2.2.
Please can someone help,
Happy 4th July,
Paul.


int main( int argc, char *argv[] )
         {
vtkRenderer *ren1 =vtkRenderer::New();
vtkRenderWindow *renWin=vtkRenderWindow::New();
    renWin->AddRenderer(ren1);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

vtkImageReader *reader =vtkImageReader::New();
reader->SetFileName("ironProt.vtk");


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


vtkPiecewiseFunction *opacityTransferFunction =
vtkPiecewiseFunction::New();
    opacityTransferFunction->AddPoint(20,   0.0);
    opacityTransferFunction->AddPoint(255,  0.2);

vtkColorTransferFunction *colorTransferFunction =
vtkColorTransferFunction::New();
    colorTransferFunction->AddRGBPoint( 0.0, 0.0, 0.0, 0.0);
    colorTransferFunction->AddRGBPoint(64.0, 1.0, 0.0, 0.0);
    colorTransferFunction->AddRGBPoint(128.0, 0.0, 0.0, 1.0);
    colorTransferFunction->AddRGBPoint(192.0, 0.0, 1.0, 0.0);
    colorTransferFunction->AddRGBPoint(255.0, 0.0, 0.2, 0.0);

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

vtkVolumeRayCastCompositeFunction  *compositeFunction=
vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
    volumeMapper->SetVolumeRayCastFunction(compositeFunction);
    volumeMapper->SetInput(imgcas->GetOutput());

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

ren1->AddVolume(volume);
ren1->SetBackground(1, 1 ,1);
renWin->SetSize(600, 600);
renWin->Render();
iren->Start();

}






More information about the vtkusers mailing list