Skip to content

BUG: Opacity of streamlines interacting with visual ordering of visualization modules #491

Closed

Description

@Mallcock1

Changing the opacity of streamlines to anything other than its default value (1.0) brings the streamlines to the front of the scene even when there are other objects that should obscure them.

For example, I refer you to the magnetic fieldline example given here: http://docs.enthought.com/mayavi/mayavi/auto/example_magnetic_field_lines.html.

Running the code as it is gives the following scene:
test_bug_1

However, if we change the opacity of the fieldlines so that it is different it its default value of 1.0 (either by adding field_lines.actor.property.opacity = 0.99 or by manually adjusting the opacity in the Mayavi pipeline) we get something like the following scene:
test_bug_2
The fieldlines are now at the front of the scene, however the isocontours should still obscure then like in the previous image.

Activity

  1. changed the title [-]Opacity of streamlines interacting with visual ordering of visualization modules[/-] [+]BUG: Opacity of streamlines interacting with visual ordering of visualization modules[/+] on Mar 6, 2017
  2. Mallcock1 commented on Apr 7, 2017

    @Mallcock1
    Author

    Is this an issue which will be fixable in the near future? If not, I would appreciate knowing so that I can find another way around my problem. Thank you

  3. luukko commented on May 10, 2017

    @luukko

    This seems to apply to other objects as well. I'm using contour3d with points3d and setting the opacity of the points to anything other than 1.0 causes the surface not to obscure them anymore.

  4. jeswcollins commented on Sep 24, 2017

    @jeswcollins

    I see what I think is the same issue with two points3d objects. Here are some examples showing how the appearance of 2 spheres rendered depends on rendering order if the opacity is set to .99, but not if opacity is set to 1.

    mlab.figure()
    mlab.points3d(0,0,1,color=(.8,.8,.8),resolution=100,opacity=.99)
    mlab.points3d(0,0,0,color=(.8,.8,.8),resolution=100,opacity=.99)

    2

    mlab.figure()
    mlab.points3d(0,0,0,color=(.8,.8,.8),resolution=100,opacity=.99)
    mlab.points3d(0,0,1,color=(.8,.8,.8),resolution=100,opacity=.99)

    4

    mlab.figure()
    mlab.points3d(0,0,1,color=(.8,.8,.8),resolution=100)
    mlab.points3d(0,0,0,color=(.8,.8,.8),resolution=100)

    1

    mlab.figure()
    mlab.points3d(0,0,0,color=(.8,.8,.8),resolution=100)
    mlab.points3d(0,0,1,color=(.8,.8,.8),resolution=100)

    3

    The issue does not seem to depend on choice of lights or light_manager ('vtk' or 'raymond').

    I suppose one workaround may be first sorting the objects to be rendered by their depth along an axis into or out of the screen.

  5. prabhuramachandran commented on Sep 24, 2017

    @prabhuramachandran
    Member

    You probably need to set the front-face culling option on. Try this:

    mlab.figure()
    g1 = mlab.points3d(0,0,1,color=(.8,.8,.8),resolution=100,opacity=.99)
    g2 = mlab.points3d(0,0,0,color=(.8,.8,.8),resolution=100,opacity=.99)
    g1.actor.property.frontface_culling = True
    g2.actor.property.frontface_culling = True
    
  6. jeswcollins commented on Sep 24, 2017

    @jeswcollins

    Thanks Prabhu---I think the frontface_culling improved the visuals, but the rendering order still was a factor only in the semi-transparent case.

    I reproduced that observation in vtk alone (it's a lower level issue).

    After more reading, I think there is a solution or two built into vtk, but another solution may be to sort the objects before rendering.

    Here are a couple links about vtk that seemed relevant:
    https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/CorrectlyRenderingTranslucentGeometry
    https://www.vtk.org/Wiki/VTK/Depth_Peeling

    And a couple links I used for reproducing the sphere case:
    https://lorensen.github.io/VTKExamples/site/Python/GeometricObjects/Sphere/
    https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/Opacity

  7. Mallcock1 commented on Sep 25, 2017

    @Mallcock1
    Author

    Thanks for adding to the discussion and for the helpful links. I am not very knowledgeable about VTK or depth peeling, but a simple solution that I found that worked for my original example and the project I am working on was to include this:

    scene = mlab.gcf().scene
    scene.renderer.set(use_depth_peeling=True)
    

    which I adapted from this question about a similar issue..

  8. jeswcollins commented on Sep 29, 2017

    @jeswcollins

    Thanks for the help Matt and Prabhu.

    I tried depth_peeling, which for my actual use case is more helpful than it is for this 2 sphere example. But compared to reordering the spheres, the edges seem less...anti-aliased I think might be the term?

    f=mlab.figure()
    f.scene.renderer.use_depth_peeling=1
    g0=mlab.points3d(0,0,1,color=(.8,.8,.8),resolution=100,opacity=.99)
    g1=mlab.points3d(0,0,0,color=(.8,.8,.8),resolution=100,opacity=.99)  
    g0.actor.property.frontface_culling = True
    g1.actor.property.frontface_culling = True

    image

    For my 3d plotting, I have a list of points and a list of colors. So instead of depth peeling I used this function to reorder those lists together before plotting:

    def orderTransparentRender(cl,c):
        '''Opacity < 1 rendering results in appearance of spheres incorrectly in front of or behind other spheres
        One solution is setting f.scene.renderer.use_depth_peeling=1, however this seemed to result in less anti-aliased edges?
        This function sorts the cluster list cl and color list c together.
        '''
        cz=zip(cl,c)
        cz=sorted(cz,key=lambda x:-1*x[0][2])
        cz=zip(*cz)
        return cz[0],cz[1]

    Otherwise the sorted call could be all that's required. I learned that from the python docs: https://wiki.python.org/moin/HowTo/Sorting. I learned about python's zip here: https://stackoverflow.com/questions/1663807/how-can-i-iterate-through-two-lists-in-parallel

  9. prabhuramachandran commented on Aug 26, 2018

    @prabhuramachandran
    Member

    With recent VTK versions this works well for me:

    from mayavi import mlab
    f = mlab.figure()
    mlab.points3d(0,0,1,color=(.8,.8,.8),resolution=100,opacity=.99)
    mlab.points3d(0,0,0,color=(.8,.8,.8),resolution=100,opacity=.99)
    f.scene.renderer.use_depth_peeling = True
    

    Also, there is an f.scene.renderer.maximum_number_of_peels that you could potentially use. It is 4 by default but you could set it to zero for no limit although this will slow down rendering. You could tinker with this.

    May I close this issue? I think this does seem to fix many problems I have seen before.

  10. Mallcock1 commented on Aug 26, 2018

    @Mallcock1
    Author
  11. prabhuramachandran commented on Aug 26, 2018

    @prabhuramachandran
    Member

    Great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions