[vtkusers] Displaying a 2D image as a volume

Mark Wyszomierski markww at gmail.com
Wed Feb 27 11:02:22 EST 2008


Ok glad it worked - I don't think it's a bug with your original
approach though. I use a similar method here:

    http://devsample.org/index.php?option=com_content&task=view&id=18&Itemid=1

I got the same behavior. As soon as I add another image, it renders ok.

Mark

On Wed, Feb 27, 2008 at 10:55 AM,  <J.S.Wijnhout at lumc.nl> wrote:
> Hi,
>
> Thanks for the suggestion, that actually worked! I'm not sure what is
> wrong with my original approach (a bug perhaps?), but padding the image
> with transparent voxels work. For those of you who have the same
> problem:
>
>    double minValue = _image->GetScalarTypeMax ();
>    double maxValue = _image->GetScalarTypeMin ();
>    // This is a custom function to determine the min/max gray values:
>    DetermineMinMax ( _image, minValue, maxValue );
>    vtkImageShiftScale *scaler = vtkImageShiftScale::New ();
>    scaler->SetInput ( _image );
>    scaler->SetOutputScalarTypeToUnsignedChar ();
>
>    // Map to [1,255], the value 0 is reserved for a transparency hack:
>    int delta = maxValue - minValue;
>    scaler->SetShift ( ( delta / 254.0 ) - minValue );
>    scaler->SetScale ( 254.0 / delta );
>
>
>    vtkImageConstantPad *padder = vtkImageConstantPad::New ();
>    int extent [ 6 ];
>    _image->GetExtent ( extent );
>    extent [ 2 ] = 3;
>    extent [ 5 ] = 3;
>    padder->SetOutputWholeExtent ( extent );
>    padder->SetInput ( scaler->GetOutput () );
>    padder->SetConstant ( 0.0 );
>
>    // Modify the transfer functions such that pixel value 0 (the
>    // value the image is padded with in the z-dimension) corresponds to
> a
>    // completely transparent voxel and value 1 to pure black:
>    vtkPiecewiseFunction *opacityTransferFunction =
> vtkPiecewiseFunction::New ();
>    opacityTransferFunction->AddPoint ( 0, 0.0 );
>    opacityTransferFunction->AddPoint ( 0.5, 1.0 );
>    opacityTransferFunction->AddPoint ( 1, 1.0 );
>    opacityTransferFunction->AddPoint ( 255, 1.0 );
>    vtkColorTransferFunction *colorTransferFunction =
> vtkColorTransferFunction::New ();
>    colorTransferFunction->AddRGBPoint ( 0, 0.0, 0.0, 0.0 );
>    colorTransferFunction->AddRGBPoint ( 1, 0.0, 0.0, 0.0 );
>    colorTransferFunction->AddRGBPoint ( 255, 1.0, 1.0, 1.0 );
>
>    vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New ();
>    volumeProperty->SetColor ( colorTransferFunction );
>    volumeProperty->SetScalarOpacity ( opacityTransferFunction );
>
>    vtkVolumeRayCastCompositeFunction *rayCastFunction =
> vtkVolumeRayCastCompositeFunction::New ();
>
>    vtkVolumeRayCastMapper *hiResVolumeMapper =
> vtkVolumeRayCastMapper::New ();
>    hiResVolumeMapper->SetInput ( padder->GetOutput () );
>    hiResVolumeMapper->SetVolumeRayCastFunction ( rayCastFunction );
>
>    vtkVolume *volume = vtkVolume::New ();
>    volume->SetProperty ( volumeProperty );
>    volume->SetMapper ( hiResVolumeMapper );
>
>
> best,
> Jeroen
>



More information about the vtkusers mailing list