[vtkusers] problems with craeting a volume from png files

Norman Rzezovski norrze at web.de
Mon Jul 4 10:24:57 EDT 2005


Hi everyone

I have a couple of png files (test201.png - test257.png) that are slices
from a vein system, the veins being white, the surroundings black. I want to
build a volume from these slices, using the following code (put together
from various examples):

vtkRenderer ren1 = new vtkRenderer();
vtkRenderWindow renWin = new vtkRenderWindow();
renWin.AddRenderer(ren1);
vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);

vtkPNGReader pngreader = new vtkPNGReader();
pngreader.SetFilePrefix("data/png/test2");
pngreader.SetFilePattern("%s%.2d.png");
pngreader.SetDataExtent(1,256,1,256,0,57);
pngreader.SetFileNameSliceOffset(1);
pngreader.SetDataSpacing(1,1,1);
pngreader.SetDataByteOrderToLittleEndian();
pngreader.UpdateWholeExtent();

vtkPiecewiseFunction opacityTransferFunction = new vtkPiecewiseFunction();
opacityTransferFunction.AddPoint(0, 0.0);
opacityTransferFunction.AddPoint(10, 0.259);
opacityTransferFunction.AddPoint(50, 1.0);

vtkColorTransferFunction colorTransferFunction = new
vtkColorTransferFunction();
colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0);
colorTransferFunction.AddRGBPoint(10.0, 0.259, 0.259, 0.3);
colorTransferFunction.AddRGBPoint(255.0, 1.0, 1.0, 0.3);

vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
volumeProperty.SetColor(colorTransferFunction);
volumeProperty.SetScalarOpacity(opacityTransferFunction);
volumeProperty.SetInterpolationTypeToLinear();
volumeProperty.ShadeOff();

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

vtkVolume volume = new vtkVolume();
volume.SetMapper(volumeMapper);
volume.SetProperty(volumeProperty);
ren1.AddVolume(volume);
ren1.SetBackground(0.1, 0.2, 0.4);
renWin.Render();
iren.Initialize();

All I get from this is a blue window with a few yellow dots. The window
immediately vanishes after half a second.
What am I doing wrong?

Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050704/0209d52c/attachment.htm>


More information about the vtkusers mailing list