Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Add pyvista.PolyData example #154

Merged
merged 1 commit into from
Jul 10, 2019

Conversation

thewtex
Copy link
Member

@thewtex thewtex commented Jul 10, 2019

@banesullivan I'm interested in your thoughts on how we can make this mesh rendering synergistic with pyvista.

@review-notebook-app
Copy link

Check out this pull request on ReviewNB: https://app.reviewnb.com/InsightSoftwareConsortium/itk-jupyter-widgets/pull/154

You'll be able to see visual diffs and write comments on notebook cells. Powered by ReviewNB.

@thewtex thewtex merged commit 9a58bfe into InsightSoftwareConsortium:master Jul 10, 2019
@thewtex thewtex deleted the pyvista branch July 10, 2019 02:40
@banesullivan
Copy link

This is interesting... REALLY interesting.

@banesullivan
Copy link

@thewtex - this is major - Considering vtkImageData (pyvista.UniformGrid) is already supported by itk-jupyter-widgets and now vtkPolyData (pyvista.PolyData) is supported, this means we can pretty much plot anything using itk-jupyter-widgets... we'd just have to apply a vtkExtractGeometry filter (.extract_geometry() on all PyVista mesh types) and send that to itk-jupyter-widgets.

This is perfect timing with some other PRs in PyVista (see pyvista/pyvista#268 and pyvista/pyvista#300). I'm going to hack at this and see what I can make happen for prototypes and share those here in a bit.

As for implementation and path forward: I'm wondering if we should approach this the same way as the other notebook plotting tools we've added in PyVista including VTKjs through panel, X3D and K3D, which convert an already rendered VTK window or if we should approach this differently. Perhaps we could move forward with pyvista/pyvista#299 and make a more general BasePlotter class and have a specific plotter class in PyVista that purely leverages itk-jupyter-widgets without having to render anything on the PyVista/VTK side.

@akaszynski - thoughts? This is absolutely the best option in my opinion for notebook plotting.

@banesullivan
Copy link

banesullivan commented Jul 10, 2019

@thewtex - I'm curious if there is a way to instantiate a Viewer object and add several geometries to it? Something along the lines of:

import pyvista as pv
from pyvista import examples

from itkwidgets import view, Viewer

mesh = examples.download_st_helens().warp_by_scalar().extract_geomerty()

plotter = Viewer()
plotter.geometries = [mesh,]
plotter.geometries.append(mesh.contour())
plotter

This doesn't seem to be working... I know I can pass many geometries upon instantiation, but ideally, I'd like to make a class that holds on to a Viewer and adds data to that scene much like a PyVista plotter:

class PlotterITK():
    def __init__(self, **kwargs):
        self.plotter = Viewer()
        
    def add_mesh(self, mesh, **kwargs):
        """Adds mesh to the scene"""
        mesh = mesh.extract_geometry()
        self.plotter.geometries.append(mesh)
        # Handle all the RGB mapping and styling as well
        
    def show(self, **kwargs):
        """Show in cell output"""
        return self.plotter
    
plotter = PlotterITK()
plotter.add_mesh(mesh) # pass args for coloring too
plotter.show()

@banesullivan
Copy link

Also, I thought we could plot scalar attributes on the geometries... is this not currently possible?

@banesullivan
Copy link

Also, what about plotting PolyData (geometries) along side ImageData:

import pyvista as pv
from pyvista import examples

from itkwidgets import view

vol = examples.download_knee_full()

view(image=vol, geometries=vol.contour())

This seems to only show the image data/volume and not the geometries

@thewtex
Copy link
Member Author

thewtex commented Jul 17, 2019

@banesullivan sorry for the late follow-up -- I have just returned from the SciPy conference, and I am catching up with GitHub notifications 📚

This is interesting... REALLY interesting.

I am glad you think so -- I would love to see good integration with PyVista!

@thewtex - this is major - Considering vtkImageData (pyvista.UniformGrid) is already supported by itk-jupyter-widgets and now vtkPolyData (pyvista.PolyData) is supported, this means we can pretty much plot anything using itk-jupyter-widgets... we'd just have to apply a vtkExtractGeometry filter (.extract_geometry() on all PyVista mesh types) and send that to itk-jupyter-widgets.

Yes, you nailed in right on the head! 🏗️ 🚀

This is perfect timing with some other PRs in PyVista (see pyvista/pyvista#268 and pyvista/pyvista#300). I'm going to hack at this and see what I can make happen for prototypes and share those here in a bit.

Awesome!! Yes, it would be very cool to have these widgets as a plotter backend for PyVista. I do not know enough about the PyVista architecture to suggest a path forward, but it is worth noting that, like K3D, these widgets are based on the ipywidgets / jupyter-widgets, but they obviously map very closely to the PyVista / VTK data and rendering model.

@thewtex
Copy link
Member Author

thewtex commented Jul 17, 2019

This doesn't seem to be working... I know I can pass many geometries upon instantiation, but ideally, I'd like to make a class that holds on to a Viewer and adds data to that scene much like a PyVista plotter:

Instead of

self.plotter.geometries.append(mesh)

does

self.plotter.geometries = self.plotter.geometries.append(mesh)

work? If not, I will certainly fix it :-)

This would be more in line with how the ipywidgets traitlets work.

@thewtex
Copy link
Member Author

thewtex commented Jul 17, 2019

Also, I thought we could plot scalar attributes on the geometries... is this not currently possible?

It will be possible very soon :-).

@thewtex
Copy link
Member Author

thewtex commented Jul 17, 2019

Also, what about plotting PolyData (geometries) along side ImageData:

This seems to only show the image data/volume and not the geometries

Thanks for the note -- #164 will track the fix for this.

@banesullivan
Copy link

@thewtex - can I specify the name of geometry so that it's not just Geometry 0/1/2/etc.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants