[vtkusers] I can't change opacity using vtkVolumeRayCastIsosurfaceFunction

Shwu Ping Vong svong at email.arc.nasa.gov
Wed May 8 14:05:15 EDT 2002


Hi vtkusers,

Please help me with the following scenario:

I am doing volume rendering using the vtkVolumeRayCastIsosurfaceFunction
as the ray caster function.  Below is the code I have.  The problem I am
facing now is no matter what value I give to
opacityTransferFunction->AddPoint(), the opacity of the object rendered
stays the same.  If I use vtkVolumeRayCastCompositeFunction instead,
then I can change the opacity of the object.  Can anyone tell me why
that is so?  What is wrong with this piece of code?

Thanks in advance,
Shwuping Vong

=====================================================================

#include "vtkStructuredPointsReader.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolumeRayCastIsosurfaceFunction.h"
#include "vtkVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkActor.h"

int main()
{

vtkStructuredPointsReader *reader =  vtkStructuredPointsReader::New();
 reader-> SetFileName
("/home/svong/vtk40Data/VTKData/Data/ironProt.vtk");

vtkPiecewiseFunction *opacityTransferFunction =
vtkPiecewiseFunction::New();
    opacityTransferFunction-> AddPoint  (0 ,  0);
    opacityTransferFunction-> AddPoint ( 255,   0.3);

vtkColorTransferFunction *colorTransferFunction =
vtkColorTransferFunction::New();
    colorTransferFunction-> AddRGBPoint  ( 0, 1.0, 1.0, 1.0);
    colorTransferFunction-> AddRGBPoint (255, 1.0, 1.0, 1.0);

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

vtkVolumeRayCastIsosurfaceFunction *isoFunction =
vtkVolumeRayCastIsosurfaceFunction::New();
    isoFunction-> SetIsoValue (128.0);

vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
    volumeMapper-> SetInput (reader-> GetOutput());
    volumeMapper-> SetVolumeRayCastFunction (isoFunction);

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

vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin-> AddRenderer( ren1);
    renWin-> SetSize (200, 200);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren-> SetRenderWindow (renWin);

ren1-> AddVolume (volume);
ren1-> SetBackground (0.1, 0.2, 0.4);
renWin-> Render();
iren-> Initialize();
iren->Start();

return 0;
}




More information about the vtkusers mailing list