pyvista / pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)
https://docs.pyvista.org
MIT License
2.66k stars 489 forks source link

Saving/pickling the "entire plot"? #1234

Closed sampotter closed 1 year ago

sampotter commented 3 years ago

Sorry if this question has an obvious answer, but after setting up a plotter, adding meshes to it, etc.---that is, getting to the point where I am happily inspecting the plot, rotating it around, zooming in and out---can I save the whole thing to disk and reload it later? I know that I can take screenshots and make movies. However, I have a large number of plots that I'm generating for testing purposes. I'd like to be able to generate them all in a batch, then open them up and inspect them one at a time afterwards. I can't tell in advance which part of each plot I'm going to want to inspect.

banesullivan commented 3 years ago

You can export scenes to a couple of formats. See:

However, this won't preserve many of PyVista's plotting options so it depends on what you are including in your scene (e.g. axes actors, widgets, special lighting, special render techniques are not going to be exported)

I would suggest preformatting all of your data (run filters, transforms, etc) then save that out and have a minimal PyVista script to plot those data

banesullivan commented 3 years ago

I'll leave this in PyVista as a feature request because I believe there are methods of serializing a VTK scene graph which we do not currently leverage but this needs further investigation

sampotter commented 3 years ago

Had no trouble with either of these methods, but at least for what I'm doing export_obj was close to useless. Compare a screenshot of the original scene:

cutset

with the macOS quicklook (spacebar) view of the exported OBJ:

Screen Shot 2021-03-24 at 12 06 43 PM

I haven't had any problems with using quicklook to preview OBJ files before, so I'm assuming this OBJ file is correctly displayed.

As for export_vtkjs, I was able to save a .vtkjs file to disk, but after 5 minutes of research was unable to figure out how to view the contents of this file. ;-)


For the feature request, it would be nice to be able to just do something like: plotter.save('blah'); Plotter.from_file('blah').show() (or similar).

banesullivan commented 3 years ago

the vtkjs file can be viewed with VTK.js' standalone scene loader which we host here: http://viewer.pyvista.org

And originated from here: https://kitware.github.io/vtk-js/examples/StandaloneSceneLoader.html

banesullivan commented 3 years ago

The issue you're noticing with the exporting OBJ file is likely because the VTK OBJ exporter isn't properly exporting the lighting, etc.

banesullivan commented 3 years ago

For this somewhat simple scene, the vtkjs exported should capture everything.

banesullivan commented 3 years ago

As I mention in https://github.com/pyvista/pyvista/pull/698#issue-409107010, there are some new features in VTK 9 that might handle this. I'll try to research this when/if I find time

sampotter commented 3 years ago

Thanks, that works. After dragging and dropping, got this:

Screen Shot 2021-03-24 at 12 14 56 PM

Loading the scene took a while... maybe 3-4s. But this should work OK for now.