Skip to content

Instantly share code, notes, and snippets.

@pangyuteng
Last active June 16, 2022 12:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pangyuteng/cf6345c4e5f8f77756064e4de9ef76c7 to your computer and use it in GitHub Desktop.
Save pangyuteng/cf6345c4e5f8f77756064e4de9ef76c7 to your computer and use it in GitHub Desktop.
vtk offscreen rendering - tested on ubuntu, anaconda py3.6 - thank you clinicalgraphics.
sudo su -
# go to system root, cd ..
mkdir /opt/anaconda3
# installed anaconda to /opt/anaconda3
bash /Temp/Anaconda3-5.1.0-Linux-x86_64.sh
# create py 3.6
/opt/anaconda3/bin/conda create -p /opt/envs/conda/py36 python=3.6
# activate py 3.6
source /opt/anaconda3/bin/activate /opt/envs/conda/py36
# install prebuilt vtk for offscreen rendering
conda install -c clinicalgraphics vtk-offscreen
# test out env py36
python test_offscreen.py
# refs.
#https://groups.google.com/a/continuum.io/forum/#!msg/anaconda/qinxkmvlnSg/tCiE_yvgDAAJ
#https://askubuntu.com/questions/34880/use-of-opt-and-usr-local-directories-in-the-context-of-a-pc
#tried installing mayavi first, doc below looks promissing, but after many failed attempts, resorted to vtk-offscreen from clinicalgraphics
#http://docs.enthought.com/mayavi/mayavi/tips.html
''' from https://gist.github.com/certik/5687727 '''
from vtk import (vtkSphereSource, vtkPolyDataMapper, vtkActor, vtkRenderer,
vtkRenderWindow, vtkWindowToImageFilter, vtkPNGWriter)
sphereSource = vtkSphereSource()
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(sphereSource.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)
renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.SetOffScreenRendering(1)
renderWindow.AddRenderer(renderer)
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1)
renderWindow.Render()
windowToImageFilter = vtkWindowToImageFilter()
windowToImageFilter.SetInput(renderWindow)
windowToImageFilter.Update()
writer = vtkPNGWriter()
writer.SetFileName("sphere.png")
writer.SetInputConnection(windowToImageFilter.GetOutputPort())
writer.Write()
@pangyuteng
Copy link
Author

pangyuteng commented Sep 1, 2021

clinicalgraphics no longer maintains the off-screen vtk

notes for alternatives:

@pangyuteng
Copy link
Author

Dockerfile for vtk-offscreen

https://github.com/sawtellellc/vtk-offscreen

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