[vtkusers] Updating transfer function in volume rendering

Dženan Zukić dzenanz at gmail.com
Tue Feb 8 10:20:24 EST 2011


I have found a solution, following a suggestion here:
http://vtk.1045678.n5.nabble.com/Updating-color-transfer-function-for-GPU-volume-td3312776.html
I modified the code to following:

void MainWindow::on_TF_chosen(QAction *action)
{
    if (volume) //volume is loaded and set up
    {
        volume->SetProperty( tf[action->data().toInt()] );
        volume->GetProperty()->GetRGBTransferFunction()->Modified();
        volume->GetProperty()->GetScalarOpacity()->Modified();
        vis->GetRenderWindow()->Render();
    }
}

That is, I just added calls to modified() to color and opacity transfer
functions.

2011/2/7 Dženan Zukić <dzenanz at gmail.com>

> Hi all,
>
> I have the following menu handler:
>
> void MainWindow::on_TF_chosen(QAction *action)
> {
>     if (volume) //volume is loaded and set up
>     {
>         volume->SetProperty( tf[action->data().toInt()] );
>         vis->GetRenderWindow()->Render();
>     }
> }
>
> tf is an array of vtkVolumeProperty*s, containing combinations of color
> and opacity transfer functions. However, when transfer function is changed
> with this procedure, the result is not what I expect: transfer functions are
> either not changed, or they are changed to something I didn't specify.
>
> Is there some call missing here, something like "UpdateTransferFunctions"?
>
> This is the code from form constructor:
>
> //manually create transfer functions
> tf[0] = vtkVolumeProperty::New();
> vtkPiecewiseFunction *opacityFun0 = vtkPiecewiseFunction::New();
> tf[0]->SetScalarOpacity( opacityFun0 );
> opacityFun0->AddPoint(0, 0);
> opacityFun0->AddPoint(255, 0 );
> tf[0]->ShadeOn();
> tf[0]->SetScalarOpacityUnitDistance(0.8919);
>
> tf[1] = vtkVolumeProperty::New();
> vtkColorTransferFunction *colorFun1 = vtkColorTransferFunction::New();
> vtkPiecewiseFunction *opacityFun1 = vtkPiecewiseFunction::New();
> tf[1]->SetColor( colorFun1 );
> tf[1]->SetScalarOpacity( opacityFun1 );
> tf[1]->SetInterpolationTypeToLinear();
> colorFun1->AddRGBPoint( 0, .55, .75, .85 );
> colorFun1->AddRGBPoint( 80, .88, .60, .29 );
> opacityFun1->AddPoint(0, 0);
> opacityFun1->AddPoint(80, .5 );
> tf[1]->ShadeOn();
> tf[1]->SetScalarOpacityUnitDistance(0.8919);
>
> tf[2] = vtkVolumeProperty::New();
> vtkColorTransferFunction *colorFun2 = vtkColorTransferFunction::New();
> vtkPiecewiseFunction *opacityFun2 = vtkPiecewiseFunction::New();
> tf[2]->SetColor( colorFun2 );
> tf[2]->SetScalarOpacity( opacityFun2 );
> tf[2]->SetInterpolationTypeToLinear();
> colorFun2->AddRGBPoint( 0, .55, .9, .5 );
> colorFun2->AddRGBPoint( 160, .88, .1, .1 );
> opacityFun2->AddPoint(0, 0);
> opacityFun2->AddPoint(160, .6 );
> tf[2]->ShadeOn();
> tf[2]->SetScalarOpacityUnitDistance(0.8919);
>
> Thanks,
> Dženan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110208/32a138a1/attachment.htm>


More information about the vtkusers mailing list