Using IndexedLookUp color in volume rendering

Hi Andras,

Sorry to bother you again. I found some interesting things about the RGBA volume rendering and can’t figure out the reason.

Right now, I have around two modes to achieve the task. Mode 1 uses the regular color transfer function with one channel and Mode 2 uses the RGBA volume rendering without independentcomponentoff(). The task actually requires colorful rendering, but I only use (255,255,255) here for convenience.


    // Data generation
    maskgrid->SetDimensions( dims ); // dims = 500x500x50
    vtkNew<vtkInformation> info;
    maskgrid->SetScalarType(VTK_UNSIGNED_CHAR, info);
    maskgrid->SetSpacing(1.0, 1.0, 1.0);
    maskgrid->SetOrigin(0.0, 0.0, 0.0);


    vtkNew<vtkUnsignedCharArray> scalars;
    scalars->SetNumberOfComponents(1); //mode 1
    scalars->SetNumberOfComponents(4); //mode 2
    scalars->SetNumberOfTuples( dims[0] * dims[1] * dims[2] );
    scalars->Fill(0);

    // ---------Set Data---------
    // scalars.setTuple1(pointIdx, 255); //mode 1
    // scalars.setTuple4(pointIdx, 255, 255, 255, 1); //mode 2
    // .....
    // ---------Set Data---------
    maskgrid->GetPointData()->SetScalars(scalars);

    // Rendering

    vtkNew<vtkPiecewiseFunction> opacityFunc;
    opacityFunc2->AddPoint(0, 0);
    opacityFunc2->AddPoint(0.1, 1);

    vtkNew<vtkColorTransferFunction> colorTransferFunction;
    colorTransferFunction2->AddRGBPoint(0.1, 0.0, 0.0, 0.0);
    colorTransferFunction2->AddRGBPoint(255, 1.0, 1.0, 1.0);

    vtkNew<vtkVolumeProperty> volumeProperty; 
    volumeProperty2->SetColor(colorTransferFunction); // only for mode 1 with independent components on 
    volumeProperty2->SetScalarOpacity(opacityFunc); // for both mode 1&2 
    volumeProperty2-> IndependentComponentsOff(); // only for mode 2

    // An extra sphere with a radius of 100 and an outline are rendered for reference.

    //The rest of the pipeline is the same, including actor and renderer


All the above are the only difference between the two modes. I suppose the results from the two paths are mostly the same, but it actually differs a lot.

The result from mode 1 looks as I expected:


However, the result from mode 2 looks weird:


A lot of structures below the surface disappear except the one in the corner (and even that one seems incomplete). Also, if I look from bottom to top, most of the structures disappear.

This looks like an out-of-range error in the data array to me, but I don’t see any issue here. I’ve checked the number of tuples. It is dim[0] x dim[1] x dim[2], and the number of components is 4. Do you know if you have any other clues about the issue?

Thanks.

=====================================================
Update:

Something weird happened again. I switch the vtkFixedPointVolumeRayCastMapper to vtkGPUVolumeRayCastMapper and it comes up with a very light white, just like with a very low alpha value. Then I change the alpha value to 255 and everything is fixed up.

I don’t understand why the alpha value would change that, as my opacity transfer function should already reach 1. Also, I thought the vtkFixedPointVolumeRayCastMapper should have a similar performance as the vtkGPUVolumeRayCastMapper, but obviously, there’s some difference.

I’ll keep working with real RGBA value instead of all-white color.