Last active
June 16, 2022 12:28
-
-
Save pangyuteng/cf6345c4e5f8f77756064e4de9ef76c7 to your computer and use it in GitHub Desktop.
vtk offscreen rendering - tested on ubuntu, anaconda py3.6 - thank you clinicalgraphics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' 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() |
Dockerfile for vtk-offscreen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
clinicalgraphics no longer maintains the off-screen vtk
notes for alternatives: