[vtkusers] Re: Texture mapping problem.

Goodwin Lawlor goodwin.lawlor at ucd.ie
Wed Jun 7 11:06:46 EDT 2006


John Ryan wrote:
> Hi,
> 
> I'm having a problem displaying a vtkVolume using 
> vtkVolumeTextureMapper2D read in from vtkBMPReader.
> 
> I've got a volume of one hundred 512X512 slices from bmp files, labelled 
> 0 to 99. I've experimented with iso-surfaces, so the volume has read in 
> ok. But, when I try to display a texture volume, it looks like the pixel 
> information is getting mixed up. I've tried casting to unsigned chars to 
> no avail.
> 
> Has anyone encountered this problem or know how to combat it?
> 
> Some of the code is below...
> 
> John
> 
>    //READ IN
>    vtkBMPReader *v = vtkBMPReader::New();
>    v->SetFilePrefix("dataset/im.bmp");      v->SetDataSpacing (3.2, 3.2, 
> 1.5);
>    v->SetDataExtent(1,512,1,512,0,99);
>    //v->SetDataExtent(0,64,0,64,0,99);
>    v->Update();
> 
>    //OPACITY TF
>    vtkPiecewiseFunction *opacityTF = vtkPiecewiseFunction::New();
>    opacityTF->AddPoint(   200.0,  0.0 );
>    opacityTF->AddPoint(   210.0,  1.0 );
>    opacityTF->AddPoint(   255.0,  1.0 );
> 
>    //COLOUR TF
>    vtkColorTransferFunction *colorTF = vtkColorTransferFunction::New();
>    colorTF->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
>    colorTF->AddRGBPoint(64.0, 1.0, 0.0, 0.0);
>    colorTF->AddRGBPoint(128.0, 0.0, 0.0, 1.0);
>    colorTF->AddRGBPoint(255.0, 0.0, 0.2, 0.0);
> 
>    //PROPERTIES
>    vtkVolumeProperty *volprop = vtkVolumeProperty::New();
>    volprop->SetColor(colorTF);
>    volprop->SetScalarOpacity(opacityTF);
>    volprop->ShadeOn();
>    volprop->SetInterpolationTypeToLinear();
>    volprop->SetSpecularPower(10.0);
>    volprop->SetSpecular(.7);
>    volprop->SetAmbient(.5);
>    volprop->SetDiffuse(.5);
> 
>    vtkImageCast *cast = vtkImageCast::New();
>    cast->SetInput(v->GetOutput());
>    cast->SetOutputScalarTypeToUnsignedChar();
> 
>    vtkVolumeTextureMapper2D *volumeMapper = 
> vtkVolumeTextureMapper2D::New();
>    volumeMapper->SetInput( cast->GetOutput() );
> 
>    //VOLUME ACTOR
>    vtkVolume *volume = vtkVolume::New();
>    volume->SetMapper(volumeMapper);
>    volume->SetProperty(volprop);

Hi John,

vtkImageCast can be unpredictable since your input image data may be 
outside the range of an UnsignedChar. Try vtkImageShiftScale as below 
(taken from the class's c++ test), which will squeeze your image data 
into the [0,255] range and cast your data to UnsignedChar.

   double range[2];
   v->GetOutput()->GetScalarRange(range);

   vtkImageShiftScale* shifter = vtkImageShiftScale::New();
     shifter->SetShift(-1.0*range[0]);
     shifter->SetScale(255.0/(range[1]-range[0]));
     shifter->SetOutputScalarTypeToUnsignedChar();
     shifter->SetInputConnection(v->GetOutputPort());

Alternatively, see if "cast->ClampOverflowOn();" does anything for you.


hth

Goodwin





More information about the vtkusers mailing list