im using vtk 9.2 to render 3d volumes with the following code
auto mapper = vtkSmartPointer<vtkOpenGLGPUVolumeRayCastMapper>::New();
mapper->SetInputConnection(imagedata->GetOutputPort());
auto actor = vtkSmartPointer<vtkVolume>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colortransferfunction);
actor->GetProperty()->SetScalarOpacity(scalaropacityfunction);
actor->GetProperty()->ShadeOn();
actor->GetProperty()->SetInterpolationTypeToLinear();
renderer->AddViewProp(actor);
everythings works fine for volumes with a z dimension greater than 1 (fx 500x500x500)
when i load “volumetric” data with z dimension 1 (for example an extracted slice, 500x500x1), the same code produces simply a black and opaque image in the renderwindow.
Using vtkImageSliceMapper and vtkImageSlice, a render result is visible for the same data. As far as i understand, i cannot make use of a scalar opacity function with vtkImageSlice. It simply uses the alpha values of the image, which i dont have since my data is grayscale CT data and the scalar opacity is created via code/user interaction in a widget.
I tried to check the behaviour of paraview, but when loading a single slice and setting the rendering to volume, paraview crashes.
Why does the code above produce no result for a volume with 1 slice? Is there a setting/property for that case on vtkVolume/vtkRenderer/vtkOpenGLGPUVolumeRayCastMapper?
Or is there a way to use vtkPiecewiseFunction with vtkImageSlice for scalar opacity?
edit: i digged into the code that creates the shader code and i noticed that
actor->GetProperty()->GetSliceFunction();
returns nullptr and thats why vtk doesnt create the shader code that calculates g_intersection. so i would rephrase my question:
edit: i tried setting the plane and moving it through the volume with a slider. this worked when using a volume with z > 1 as expected, but when setting the plane and/or moving it through a volume with z dimension = 1 no render result is produced.
Ideally, thin volumes (z = 1) should be renderable but my guess is that the GPU raycaster is running into boundary conditions where start and stop ray positions are near-coincident.
So, to answer the question about your other approach, vtkImageSlice allows specifying properties via vtkImageProperty which in turn, accepts a lookup table via SetLookupTable(vtkScalarsToColors*). You could set the lookup table to a vtkLookupTable with RGBA table values.That should let you map scalars to both color and opacity.