[vtkusers] vtkMultiVolume, vtkOpenGLGPUVolumeRayCastMapper - How to use vtkVolume->GetProperty()->SetScalarOpacity( vtkPiecewiseFunction ) correctly?
Elvis Stansvik
elvis.stansvik at orexplore.com
Thu Oct 25 15:46:25 EDT 2018
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/9db353bb72c5567c4b75573b79517ec090d8df02 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
>
> 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
More information about the vtkusers
mailing list