Last active
June 2, 2018 03:21
-
-
Save 1f0/8f7326c9996eb4d6ae4784edcf9bc8a0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 __future__ import print_function | |
import sys | |
import vtk | |
ren = vtk.vtkRenderer() | |
renWin = vtk.vtkRenderWindow() | |
renWin.AddRenderer(ren) | |
renWin.SetSize(512,512) | |
reader = vtk.vtkOBJReader() | |
reader.SetFileName(sys.argv[1]) | |
reader.Update() | |
obj = reader.GetOutput() | |
mapper = vtk.vtkPolyDataMapper() | |
mapper.SetInputConnection(reader.GetOutputPort()) | |
# Create actor and set the mapper and the texture | |
actor = vtk.vtkActor() | |
actor.GetProperty().SetOpacity(0.7) | |
actor.SetMapper(mapper) | |
if len(sys.argv)==4: | |
import xml.etree.ElementTree | |
e = xml.etree.ElementTree.parse(sys.argv[3]).getroot() | |
camera = vtk.vtkCamera() | |
props = e[0] | |
pos = props[0] | |
def at(p, i): | |
return float(p[i].attrib['value']) | |
camera.SetPosition(at(props[0],0), at(props[0],1), at(props[0],2)) | |
camera.SetFocalPoint(at(props[1],0), at(props[1],1), at(props[1],2)) | |
camera.SetViewUp(at(props[2],0), at(props[2],1), at(props[2],2)) | |
ren.SetActiveCamera(camera) | |
ren.AddActor(actor) | |
# paraview default color | |
ren.SetBackground(81/255.0,87/255.0,110/255.0,); | |
renWin.Render() | |
# # screenshot code: | |
w2if = vtk.vtkWindowToImageFilter() | |
w2if.SetInput(renWin) | |
w2if.Update() | |
writer = vtk.vtkPNGWriter() | |
writer.SetFileName(sys.argv[2]) | |
writer.SetInputConnection(w2if.GetOutputPort()) | |
writer.Write() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment