Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Terminator Combined Rendering as python script
# Prelude
from vistrails.packages.vtk.vtk_wrapper import vvtk
# Prelude
import requests
# Prelude
from vistrails.packages.vtk.vtk_wrapper import vvtk
# Prelude
import vtk
# Prelude
from vistrails.packages.vtk.vtk_wrapper import vvtk
# Prelude
from vistrails.packages.vtk import tf_widget
# Prelude
from vistrails.core.modules.basic_modules import PathObject
# Prelude
import tempfile
# Prelude
from vistrails.packages.vtk.vtk_wrapper import vvtk
# Prelude
from vistrails.packages.vtk.vtk_wrapper import vvtk
# PRELUDE ENDS -- pipeline code follows
# MODULE 383 org.vistrails.vistrails.vtk:vtkPlane
vtk_plane = vvtk.vtkPlane()
vtk_plane._cleanup()
# MODULE 361 org.vistrails.vistrails.vtk:vtkVolumeRayCastCompositeFunction
vtk_volume_ray_cast_composite_function = vvtk.vtkVolumeRayCastCompositeFunction()
vtk_volume_ray_cast_composite_function._cleanup()
# MODULE 349 org.vistrails.vistrails.vtk:vtkCamera
vtk_camera = vvtk.vtkCamera()
vtk_camera.SetPosition(745.0, -453.0, 370.0)
vtk_camera.SetViewUp(0.0, 0.0, -1.0)
vtk_camera.SetFocalPoint(135.0, 135.0, 150.0)
vtk_camera._cleanup()
# MODULE 401 org.vistrails.vistrails.url:DownloadFile
# FUNCTION url url
url = 'http://www.vistrails.org/download/download.php?type=DATA&id=head.120.vtk'
_, path = tempfile.mkstemp()
r = requests.get(url, stream=True)
with open(path, 'wb') as f:
for chunk in r:
f.write(chunk)
file = PathObject(path)
# MODULE 341 org.vistrails.vistrails.vtk:vtkStructuredPointsReader
# CONNECTION File file
vtk_structured_points_reader = vvtk.vtkStructuredPointsReader()
def input_t(value):
return value.name
def output_t(value):
from vistrails.core.modules.basic_modules import PathObject
return PathObject(value)
file = input_t(file)
vtk_structured_points_reader.SetFileName(file)
vtk_structured_points_reader.Update()
Output = vtk_structured_points_reader.GetOutput()
GetOutputPort0 = vtk_structured_points_reader.GetOutputPort()
vtk_structured_points_reader._cleanup()
# MODULE 376 org.vistrails.vistrails.vtk:vtkContourFilter
# CONNECTION SetInputConnection0 GetOutputPort0
vtk_contour_filter = vvtk.vtkContourFilter()
vtk_contour_filter.SetValue(0, 67.0)
vtk_contour_filter.SetInputConnection(0, GetOutputPort0)
vtk_contour_filter.Update()
GetOutputPort0_2 = vtk_contour_filter.GetOutputPort()
vtk_contour_filter._cleanup()
# MODULE 365 org.vistrails.vistrails.vtk:vtkVolumeRayCastMapper
# CONNECTION AddInputConnection GetOutputPort0
# CONNECTION VolumeRayCastFunction vtk_volume_ray_cast_composite_function
# CONNECTION AddClippingPlane vtk_plane
AddInputConnection = [GetOutputPort0]
AddClippingPlane = [vtk_plane]
VolumeRayCastFunction = [vtk_volume_ray_cast_composite_function]
vtk_volume_ray_cast_mapper = vvtk.vtkVolumeRayCastMapper()
for AddClippingPlaneItem in AddClippingPlane:
vtk_volume_ray_cast_mapper.AddClippingPlane(AddClippingPlaneItem)
for AddInputConnectionItem in AddInputConnection:
vtk_volume_ray_cast_mapper.AddInputConnection(AddInputConnectionItem)
for VolumeRayCastFunctionItem in VolumeRayCastFunction:
vtk_volume_ray_cast_mapper.SetVolumeRayCastFunction(VolumeRayCastFunctionItem)
vtk_volume_ray_cast_mapper.Update()
vtk_volume_ray_cast_mapper._cleanup()
# MODULE 400 org.vistrails.vistrails.vtk:vtkScaledTransferFunction
# FUNCTION TransferFunction TransferFunction_2
TransferFunction_2 = tf_widget.TransferFunction.parse('<transfer_function max_range="1.0" min_range="0.0"><point opacity="0.0" scalar="0.0"><color B="0.0" G="0.0" R="0.0" /></point><point opacity="0.0" scalar="0.0776021828653"><color B="0.0" G="0.0" R="0.0" /></point><point opacity="0.620071684588" scalar="0.14157014157"><color B="0.462745098039" G="0.537254901961" R="0.890196078431" /></point><point opacity="0.0" scalar="0.20592020592"><color B="0.0" G="0.0" R="0.0" /></point><point opacity="0.0" scalar="0.251911830859"><color B="1.0" G="1.0" R="1.0" /></point><point opacity="0.971655328798" scalar="0.463338831759"><color B="1.0" G="1.0" R="1.0" /></point><point opacity="0.0" scalar="0.683760683761"><color B="0.270588235294" G="0.270588235294" R="0.270588235294" /></point><point opacity="0.0" scalar="1.0"><color B="0.0" G="0.0" R="0.0" /></point></transfer_function>')
# CONNECTION Dataset Output
tf = TransferFunction_2
tf._min_range, tf._max_range = Output.GetScalarRange()
# MODULE 357 org.vistrails.vistrails.vtk:vtkVolumeProperty
# CONNECTION TransferFunction TransferFunction_2
vtk_volume_property = vvtk.vtkVolumeProperty()
vtk_volume_property.SetInterpolationTypeToLinear()
vtk_volume_property.ShadeOn()
vtk_volume_property.SetTransferFunction(TransferFunction_2)
vtk_volume_property._cleanup()
# MODULE 353 org.vistrails.vistrails.vtk:vtkVolume
# CONNECTION Property vtk_volume_property
# CONNECTION Mapper vtk_volume_ray_cast_mapper
Mapper = [vtk_volume_ray_cast_mapper]
Property = [vtk_volume_property]
vtk_volume = vvtk.vtkVolume()
for MapperItem in Mapper:
vtk_volume.SetMapper(MapperItem)
for PropertyItem in Property:
vtk_volume.SetProperty(PropertyItem)
vtk_volume.Update()
vtk_volume._cleanup()
# MODULE 372 org.vistrails.vistrails.vtk:vtkImplicitPlaneWidget
# CONNECTION Prop3D vtk_volume
Prop3D = [vtk_volume]
vtk_implicit_plane_widget = vvtk.vtkImplicitPlaneWidget()
vtk_implicit_plane_widget.SetPlaceFactor(1.25)
for Prop3DItem in Prop3D:
vtk_implicit_plane_widget.SetProp3D(Prop3DItem)
vtk_implicit_plane_widget._cleanup()
# MODULE 379 org.vistrails.vistrails.vtk:vtkInteractionHandler
# CONNECTION Observer vtk_implicit_plane_widget
# CONNECTION SharedData vtk_plane
SharedData_2 = [vtk_plane]
def interactionHandler(observer, shareddata):
observer.GetPlane(shareddata.vtkInstance)
if len(SharedData_2)==1:
SharedData_2 = SharedData_2[0]
def eventHandler(obj, event):
f = event[0].lower() + event[1:]
f = f.replace('Event', 'Handler')
if f in locals():
locals(f)(obj, SharedData_2)
vtk_implicit_plane_widget.AddObserver('InteractionEvent', eventHandler)
if hasattr(vtk_implicit_plane_widget.vtkInstance, 'PlaceWidget'):
vtk_implicit_plane_widget.vtkInstance.PlaceWidget()
Instance = vtk_implicit_plane_widget
# MODULE 399 org.vistrails.vistrails.vtk:vtkClipPolyData
# CONNECTION SetInputConnection0 GetOutputPort0_2
# CONNECTION ClipFunction vtk_plane
ClipFunction = [vtk_plane]
vtk_clip_poly_data = vvtk.vtkClipPolyData()
vtk_clip_poly_data.InsideOutOn()
for ClipFunctionItem in ClipFunction:
vtk_clip_poly_data.SetClipFunction(ClipFunctionItem)
vtk_clip_poly_data.SetInputConnection(0, GetOutputPort0_2)
vtk_clip_poly_data.Update()
GetOutputPort0_3 = vtk_clip_poly_data.GetOutputPort()
vtk_clip_poly_data._cleanup()
# MODULE 395 org.vistrails.vistrails.vtk:vtkPolyDataMapper
# CONNECTION SetInputConnection0 GetOutputPort0_3
vtk_poly_data_mapper = vvtk.vtkPolyDataMapper()
vtk_poly_data_mapper.ScalarVisibilityOff()
vtk_poly_data_mapper.SetInputConnection(0, GetOutputPort0_3)
vtk_poly_data_mapper.Update()
vtk_poly_data_mapper._cleanup()
# MODULE 387 org.vistrails.vistrails.vtk:vtkProperty
vtk_property = vvtk.vtkProperty()
vtk_property.SetDiffuseColor((1, 1, 1))
vtk_property._cleanup()
# MODULE 391 org.vistrails.vistrails.vtk:vtkActor
# CONNECTION Property vtk_property
# CONNECTION Mapper vtk_poly_data_mapper
Mapper_2 = [vtk_poly_data_mapper]
Property_2 = [vtk_property]
vtk_actor = vvtk.vtkActor()
for MapperItem in Mapper_2:
vtk_actor.SetMapper(MapperItem)
for PropertyItem in Property_2:
vtk_actor.SetProperty(PropertyItem)
vtk_actor._cleanup()
# MODULE 345 org.vistrails.vistrails.vtk:vtkRenderer
# CONNECTION ActiveCamera vtk_camera
# CONNECTION AddVolume vtk_volume
# CONNECTION AddActor vtk_actor
ActiveCamera = [vtk_camera]
AddActor = [vtk_actor]
AddVolume = [vtk_volume]
vtk_renderer = vvtk.vtkRenderer()
for AddActorItem in AddActor:
vtk_renderer.AddActor(AddActorItem)
for AddVolumeItem in AddVolume:
vtk_renderer.AddVolume(AddVolumeItem)
for ActiveCameraItem in ActiveCamera:
vtk_renderer.SetActiveCamera(ActiveCameraItem)
vtk_renderer.SetBackground((0.0, 0.0, 0.0))
vtk_renderer._cleanup()
# MODULE 368 org.vistrails.vistrails.vtk:VTKCell
# CONNECTION AddRenderer vtk_renderer
# CONNECTION InteractionHandler Instance
AddRenderer = [vtk_renderer]
InteractionHandler = [Instance]
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(AddRenderer[0].vtkInstance)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renWin.SetSize(1024, 768)
iren.Initialize()
for iHandler in InteractionHandler:
iHandler.SetInteractor(iren)
renWin.Render()
iren.Start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.