VTK renders into IPython Notebook
This function takes a vtkRenderer object and displays the output directly into IPython Notebook
def vtk_show(renderer, w=100, h=100):
"""
Takes vtkRenderer instance and returns an IPython Image with the rendering.
"""
renderWindow = vtkRenderWindow()
renderWindow.SetOffScreenRendering(1)
renderWindow.AddRenderer(renderer)
renderWindow.SetSize(w, h)
renderWindow.Render()
windowToImageFilter = vtkWindowToImageFilter()
windowToImageFilter.SetInput(renderWindow)
windowToImageFilter.Update()
writer = vtkPNGWriter()
writer.SetWriteToMemory(1)
writer.SetInputConnection(windowToImageFilter.GetOutputPort())
writer.Write()
data = str(buffer(writer.GetResult()))
from IPython.display import Image
return Image(data)
Read article: (http://pyscience.wordpress.com/2014/09/03/ipython-notebook-vtk/)
Written by Adamos Kyriakou
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#