[vtkusers] vtkMultiVolume, vtkOpenGLGPUVolumeRayCastMapper - How to use vtkVolume->GetProperty()->SetScalarOpacity( vtkPiecewiseFunction ) correctly?

Angelika Ophagen ophagen at dornheim-medical-images.de
Thu Oct 25 16:45:34 EDT 2018


Am Donnerstag, 25. Oktober 2018, 21:46:25 CEST schrieb Elvis Stansvik:
> Den tors 25 okt. 2018 kl 21:35 skrev Elvis Stansvik
> 
> <elvis.stansvik at orexplore.com>:
> > Hi Angelika,
> > 
> > See answer inline below.
> > 
> > Den tors 25 okt. 2018 kl 20:36 skrev Angelika Ophagen
> > 
> > <ophagen at dornheim-medical-images.de>:
> > > Hello,
> > > 
> > > I am trying to use vtkMultiVolume for a rather large application for 3D
> > > medical image data to meld multiple data - as my bachelor thesis
> > > project. I have based my code on commit
> > > https://gitlab.kitware.com/vtk/vtk/commit/9db353bb72c5567c4b75573b79517
> > > ec090d8df02 of the VTK and on branch nightly-master. I need color
> > > transfer functions, scalar opacity functions and image data separately
> > > for each volume. I cannot get the scalar opacity to do what I want,
> > > somehow. Even in a very small example*, alpha is 1 all over the volume
> > > in the end. Gradient opacity, which I do not need, afaik, will result
> > > in alpha values smaller 1.> 
> > Hm, I tried your code and can't reproduce the problem. It would be
> > good with a screenshot of what you're seeing.
> > 
> > When I run it, volumes are showing some transparency. See attached
> > pic1.png and pic2.png.
> > 
> > Keep in mind that the value produced by the opacity transfer function
> > is how much opacity is accumulated by a cast ray over one
> > ScalarOpacityUnitDistance (see this property on vtkVolumeProperty). It
> > defaults to 1.0 VTK world unit.
> > 
> > This means that, given the opacity functions you've set up in your
> > code, your 64x64x64, which have a spacing of 1.0, are going to look
> > mostly opaque (but not completely).
> 
> Put another way, with the ScalarOpacityUnitDistance set to its default
> value (1.0) and a 1.0 voxel spacing, you can think of your opacity
> transfer function as giving the opacity of one voxel. Since your
> volumes are 64x64x64 voxels, they're going to look roughly 64 times
> more opaque than your opacity function says.
> 
> There's really 4 things that influence the opacity of a rendered volume
> 
> - The number of voxels that you're "looking through" (the extent of your
> volume) - The spacing between those voxels (the spacing of your volume)
> - The scalar opacity unit distance (the ScalarOpacityUnitDistance property)
> - The opacity transfer function
> 
> HTH,
> Elvis

Thanks a lot!

If I understand you correctly, when I want my opacityTransferFunction to 
signify the transfer function for the whole dataset, I will need to set the 
ScalarOpacityUnitDistance to the maxValue - minValue of the dataset? Or is it 
the max size of the dataset? In this case they are the same values, because I 
was lazy with the test data.

I will immediately test that. We afaik never used ScalarOpacityUnitDistance 
before. Is it a new mechanism? As of now, we already use Release VTK 8.1 and 
it seems strange that our medical datasets look just like we want them when 
all we used to set were color and scalar opacity.

The example has a teeny weeny value range and I am not excluding any of its 
value range, which is very different from a 'real' dataset.

We are talking about medical images and they sometimes have a range that is 
already clamped by DICOM having only an amount of int16-range of values - of 
course you usually have invisible background, but in case of medical data - a 
LOT of the data is invisible most of the time. 

I am mapping the opacity to the grey values of the dataset. When I have a 
trapezoid function, I usually start at some grey value with 0 opacity then two 
nodes with some visibility and then another (lighter) grey value again with 
zero opacity. This function to me defines the opacity of the dataset, in it's 
entirety. Which additional information do I give the volume property with 
ScalarOpacityUnitDistance?

Should I put additional zero opacity nodes at the extremes of the dataset's 
value range, too? In case of a triangular function like so: _/\_ ?

To me, that seems weird, because I just presume anything below range-min is 
zero and anything above range-max is zero. Unless you use the clamping, that 
is.

Thanks again!
A. Ophagen

Sorry, I babble when tired. Should go home and continue tomorrow, really.

> > As an example, I changed all your opacity functions to go from opacity
> > 0.0 to 0.1 instead (see pic3.png). Now it's easier to see that there's
> > some transparency.
> > 
> > Elvis
> > 
> > > I have debugged the shader source code right before they are given to
> > > openGL, I have stepped through the vtlVolumeInputHelper and
> > > vtkTextureObject and vtkOpenGLVolumeOpacityTable and checked the values
> > > of the actual float-Array and - kind of** - found my expected values in
> > > there until just before they were given to openGL. From all I have
> > > seen, there should be semi-transparent parts to my generated cuboids. I
> > > have not altered bias or scale of any volume or the multivolume and
> > > presume them to be 0 and 1 respectively.
> > > 
> > > I temporarily changed the fragment shader template to try and output the
> > > LUT values (for the 1st volume) instead of the image values***. The
> > > whole "volume" in my render window was opaque white. That was the trick
> > > I am most unfamiliar with, so it might have just failed to do what I
> > > wanted.
> > > 
> > > Have I not used vtkMultiVolume and  vtkOpenGLGPUVolumeRayCastMapper in
> > > the way they are supposed to be used? Please have a look at my small
> > > example code*.
> > > 
> > > Regards,
> > > A. Ophagen
> > > 
> > > --
> > > Dipl.-Übers. A. Ophagen
> > > Dornheim Medical Images GmbH
> > > Listemannstraße 10, 39104 Magdeburg, Deutschland
> > > WWW: http://www.dornheim-medical-images.de/
> > > E-Mail: info at dornheim-medical-images.de
> > > Tel: +49 (391) 5054 57 0
> > > Geschäftsführer: Lars Dornheim, Jana Dornheim
> > > Eingetragen beim Amtsgericht Stendal, HRB 10737
> > > 
> > > 
> > > * See gist here:
> > > https://gist.github.com/AOphagen/f09d302320db67168dd9fe7316bd35e5 ** I
> > > have found that the maximum image value is reduced from 127 to 63 in
> > > the process and that the LUT array has min value 0.3, but does not
> > > reach max value 0.8 in it's 1024 entries. It stops at about 0.54 -
> > > which still is not opaque at all - this should be unrelated. ***
> > > Snippet from fragment shader template's void finalizeRayCast() + my
> > > code (commented out already):
> > > 
> > > g_fragColor.r = g_fragColor.r * in_scale + in_bias * g_fragColor.a;
> > > g_fragColor.g = g_fragColor.g * in_scale + in_bias * g_fragColor.a;
> > > g_fragColor.b = g_fragColor.b * in_scale + in_bias * g_fragColor.a;
> > > gl_FragData[0] = g_fragColor;
> > > 
> > > //  gl_FragData[0].rgb = texture2D( in_opacityTransferFunc_0[0], vec2(
> > > gl_FragCoord.x, 0.0 ) ).rrr; //  gl_FragData[0].a = 1.0;
> > > 
> > > 
> > > 
> > > _______________________________________________
> > > Powered by www.kitware.com
> > > 
> > > Visit other Kitware open-source projects at
> > > http://www.kitware.com/opensource/opensource.html
> > > 
> > > Please keep messages on-topic and check the VTK FAQ at:
> > > http://www.vtk.org/Wiki/VTK_FAQ
> > > 
> > > Search the list archives at: http://markmail.org/search/?q=vtkusers
> > > 
> > > Follow this link to subscribe/unsubscribe:
> > > https://public.kitware.com/mailman/listinfo/vtkusers



-- 
Dipl.-Übers. A. Ophagen
Dornheim Medical Images GmbH
Listemannstraße 10, 39104 Magdeburg, Deutschland
WWW: http://www.dornheim-medical-images.de/
E-Mail: info at dornheim-medical-images.de
Tel: +49 (391) 5054 57 0
Geschäftsführer: Lars Dornheim, Jana Dornheim
Eingetragen beim Amtsgericht Stendal, HRB 10737




More information about the vtkusers mailing list