pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
60 stars 4 forks source link

add_volume results in a blank image #175

Open samarthswarup opened 4 years ago

samarthswarup commented 4 years ago

Description

I am trying a very simple add_volume example:

import pyvista as pv
from pyvista import examples

model = examples.download_damavand_volcano()
opacity = [0, 0.75, 0, 0.75, 1.0]
clim = [0, 100]

p = pv.Plotter()
p.add_volume(model, cmap="magma", clim=clim,
             opacity=opacity, opacity_unit_distance=6000,)
p.show()
print(pv.Report())

When I run this, a window pops up, but it only displays a blank image:

blank_output

On the other hand, if I try to save the image to file, like so:

import pyvista as pv
from pyvista import examples

model = examples.download_damavand_volcano()
opacity = [0, 0.75, 0, 0.75, 1.0]
clim = [0, 100]

p = pv.Plotter(off_screen=True)
p.add_volume(model, cmap="magma", clim=clim,
             opacity=opacity, opacity_unit_distance=6000,)
p.show(screenshot='volcano.png')
print(pv.Report())

then it saves an image: volcano

Here is the output of pv.Report():

--------------------------------------------------------------------------------
  Date: Mon Jun 08 15:16:14 2020 EDT

                OS : Darwin
            CPU(s) : 12
           Machine : x86_64
      Architecture : 64bit
               RAM : 16.0 GB
       Environment : Python
        GPU Vendor : ATI Technologies Inc.
      GPU Renderer : AMD Radeon Pro 560X OpenGL Engine
       GPU Version : 4.1 ATI-3.5.5

  Python 3.7.4 (default, Aug 13 2019, 15:17:50)  [Clang 4.0.1
  (tags/RELEASE_401/final)]

           pyvista : 0.25.1
               vtk : 8.2.0
             numpy : 1.16.6
           imageio : 2.6.0
           appdirs : 1.4.3
            scooby : 0.5.4
            meshio : 4.0.13
        matplotlib : 3.1.3
             PyQt5 : 5.9.2
           IPython : 7.8.0
             scipy : 1.3.1
              tqdm : 4.36.1

  Intel(R) Math Kernel Library Version 2019.0.4 Product Build 20190411 for
  Intel(R) 64 architecture applications
--------------------------------------------------------------------------------

Example Data

banesullivan commented 4 years ago

Very strange... I have similar hardware but not exactly the same. I cannot reproduce this at the moment

Are you using an external monitor?


FYI: originally posted on https://stackoverflow.com/questions/62250320/pyvista-add-volume-shows-a-blank-image

it appears add_mesh is okay but add_volume is not showing.

banesullivan commented 4 years ago

Can you also try this simpler example:

import pyvista as pv

model = pv.Wavelet()

p = pv.Plotter(notebook=False)
p.add_volume(model)
p.show()
samarthswarup commented 4 years ago

I am using an external monitor (LG 27MD5KA), but the same problem happens even if I don't use it. I also tried the simpler example above, but that also shows a blank image.

banesullivan commented 4 years ago

This is very, very odd behavior. Let's do some debugging... use this snippet with a box in there so we can see where the volume should be:

import pyvista as pv

model = pv.Wavelet()

p = pv.Plotter(notebook=False)
p.add_volume(model)
p.add_mesh(model.outline(), color='white')
p.show()

Can you try clicking the scene to move the camera a bit? Also, can you hit the r and v keys a few times to see if those reset the camera and cause the volume to appear?

If those two things fail, can you try passing differing arguments of mapper to add_volume to see if any of these make a difference? Choices are: 'fixed_point', 'gpu', 'open_gl', and 'smart'. Then do the same thing of clicking the scene trying to move the camera around.

E.g.

import pyvista as pv

model = pv.Wavelet()

p = pv.Plotter(notebook=False)
p.add_volume(model, mapper='fixed_point')
p.add_mesh(model.outline(), color='white')
p.show()
samarthswarup commented 4 years ago

Here is the output for the first snippet. I clicked on it and moved the camera a bit (that's the image below). I also tried hitting r and v a few times, but the volume did not show up.

Screen Shot 2020-06-08 at 4 33 48 PM

However, the second snippet does result in the volume showing up. It only works for fixed_point. For gpu, open_gl, and smart, it looks like the output above.

Screen Shot 2020-06-08 at 4 34 43 PM
banesullivan commented 4 years ago

Aha, then you need to use the 'fixed_point' mapper for volume rendering from now on (this is the default mapper for windows, and Mac uses 'smart' by default). There are a few issues in the main PyVista repo detailing how defaults for the volume mapper were chosen and we tried to use something that works for most people as the different mappers can have issues with specific hardware. To get around this, we have a way to set a default for the volume mapper. After you import pyvista, set 'fixed_point' as the default mapper in rcParams so that you no longer have to specify it:

import pyvista as pv
pv.rcParams['volume_mapper'] = 'fixed_point'

model = pv.Wavelet()

p = pv.Plotter(notebook=False)
p.add_volume(model) # Note you do not need to specify mapper now
p.add_mesh(model.outline(), color='white')
p.show()
banesullivan commented 4 years ago

So set pv.rcParams['volume_mapper'] = 'fixed_point' then run your original workflow

samarthswarup commented 4 years ago

Thanks. I tried the damavand volcano example again, with and without fixed_point for the volume mapper. For completeness, here's the code again:

import pyvista as pv
from pyvista import examples
pv.rcParams['volume_mapper'] = 'fixed_point'

model = examples.download_damavand_volcano()
opacity = [0, 0.75, 0, 0.75, 1.0]
clim = [0, 100]

p = pv.Plotter(off_screen=True)
p.add_volume(model, cmap="magma", clim=clim,
             opacity=opacity, opacity_unit_distance=6000,)
p.show(screenshot='volcano.png')

This takes about 2 minutes to run and produces the following image: volcano

If I comment out the line pv.rcParams['volume_mapper'] = 'fixed_point', it takes about 2 seconds to run and produces the following image: volcano1

Any idea what might be causing this difference?

banesullivan commented 4 years ago

If I comment out the line pv.rcParams['volume_mapper'] = 'fixed_point', it takes about 2 seconds to run and produces the following image:

huh, I thought you said the default mapper doesn't work for you? I'm not following which mappers work for you and which don't...

However, it doesn't surprise me that the 'fixed_point' mapper has poor performance for these data.

samarthswarup commented 4 years ago

Hi Bane:

I am able to save the image to file using the default mapper, as I had mentioned in my original post, but not able to display it on screen.

jpmorr commented 3 years ago

Hi, I've been having a similar issue today but I'm using Windows and found that the volume is only rendered with the mapper='smart' option for my own small dataset. When I run any of the examples from the website I don't specify anything extra and they always plot. I've no idea why I need to use smart especially for my own small dataset (30-50K points).