-
-
Save remram44/f18d5365fc1c9e7fb9ae9c4be32924fb to your computer and use it in GitHub Desktop.
api scripting example
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
import vistrails.core.api as API | |
from vistrails.core.modules.basic_modules import create_constant | |
org_vistrails_vistrails_vtk = API.load_package('org.vistrails.vistrails.vtk') | |
org_vistrails_vistrails_vtk_2 = API.load_package('org.vistrails.vistrails.vtk') | |
import requests | |
org_vistrails_vistrails_vtk_3 = API.load_package('org.vistrails.vistrails.vtk') | |
org_vistrails_vistrails_vtk_4 = API.load_package('org.vistrails.vistrails.vtk') | |
import vtk | |
org_vistrails_vistrails_vtk_5 = API.load_package('org.vistrails.vistrails.vtk') | |
from vistrails.core.modules.vistrails_module import ModuleConnector | |
from vistrails.core.modules.basic_modules import PathObject | |
import tempfile | |
org_vistrails_vistrails_vtk_6 = API.load_package('org.vistrails.vistrails.vtk') | |
# MODULE 364 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 351 org.vistrails.vistrails.vtk:vtkStructuredPointsReader | |
# CONNECTION File file | |
vtk_structured_points_reader = org_vistrails_vistrails_vtk.vtkStructuredPointsReader.descriptor.module() | |
mc = ModuleConnector(create_constant(file), 'value') | |
vtk_structured_points_reader.set_input_port('File', mc) | |
vtk_structured_points_reader.enable_output_port('GetOutputPort0') | |
vtk_structured_points_reader.compute() | |
GetOutputPort0 = vtk_structured_points_reader.get_output('GetOutputPort0') | |
# MODULE 359 org.vistrails.vistrails.vtk:vtkContourFilter | |
# FUNCTION Value Value | |
Value = [0, 67.0] | |
# CONNECTION SetInputConnection0 GetOutputPort0 | |
Value_2 = [Value] | |
vtk_contour_filter = org_vistrails_vistrails_vtk.vtkContourFilter.descriptor.module() | |
mc_3 = ModuleConnector(create_constant(Value_2), 'value') | |
vtk_contour_filter.set_input_port('Value', mc_3) | |
mc_3 = ModuleConnector(create_constant(GetOutputPort0), 'value') | |
vtk_contour_filter.set_input_port('SetInputConnection0', mc_3) | |
vtk_contour_filter.enable_output_port('GetOutputPort0') | |
vtk_contour_filter.compute() | |
GetOutputPort0_2 = vtk_contour_filter.get_output('GetOutputPort0') | |
# MODULE 355 org.vistrails.vistrails.vtk:vtkDataSetMapper | |
# FUNCTION ScalarVisibility ScalarVisibility | |
ScalarVisibility = False | |
# CONNECTION SetInputConnection0 GetOutputPort0_2 | |
vtk_data_set_mapper = org_vistrails_vistrails_vtk.vtkDataSetMapper.descriptor.module() | |
mc_5 = ModuleConnector(create_constant(ScalarVisibility), 'value') | |
vtk_data_set_mapper.set_input_port('ScalarVisibility', mc_5) | |
mc_5 = ModuleConnector(create_constant(GetOutputPort0_2), 'value') | |
vtk_data_set_mapper.set_input_port('SetInputConnection0', mc_5) | |
vtk_data_set_mapper.enable_output_port('Instance') | |
vtk_data_set_mapper.compute() | |
Instance_3 = vtk_data_set_mapper.get_output('Instance') | |
# MODULE 345 org.vistrails.vistrails.vtk:vtkCamera | |
# FUNCTION ViewUp ViewUp_2 | |
ViewUp_2 = [0.0, 0.0, -1.0] | |
# FUNCTION Position Position_2 | |
Position_2 = [745.0, -453.0, 369.0] | |
# FUNCTION FocalPoint FocalPoint_2 | |
FocalPoint_2 = [135.0, 135.0, 150.0] | |
FocalPoint_3 = [FocalPoint_2] | |
Position_3 = [Position_2] | |
ViewUp_3 = [ViewUp_2] | |
vtk_camera = org_vistrails_vistrails_vtk.vtkCamera.descriptor.module() | |
mc_8 = ModuleConnector(create_constant(Position_3), 'value') | |
vtk_camera.set_input_port('Position', mc_8) | |
mc_8 = ModuleConnector(create_constant(ViewUp_3), 'value') | |
vtk_camera.set_input_port('ViewUp', mc_8) | |
mc_8 = ModuleConnector(create_constant(FocalPoint_3), 'value') | |
vtk_camera.set_input_port('FocalPoint', mc_8) | |
vtk_camera.enable_output_port('Instance') | |
vtk_camera.compute() | |
Instance_4 = vtk_camera.get_output('Instance') | |
# MODULE 341 org.vistrails.vistrails.vtk:vtkActor | |
# CONNECTION Mapper Instance_3 | |
Mapper_2 = [Instance_3] | |
vtk_actor = org_vistrails_vistrails_vtk.vtkActor.descriptor.module() | |
mc_9 = ModuleConnector(create_constant(Mapper_2), 'value') | |
vtk_actor.set_input_port('Mapper', mc_9) | |
vtk_actor.enable_output_port('Instance') | |
vtk_actor.compute() | |
Instance_5 = vtk_actor.get_output('Instance') | |
# MODULE 363 org.vistrails.vistrails.vtk:vtkRenderer | |
# CONNECTION AddActor Instance_5 | |
# CONNECTION ActiveCamera Instance_4 | |
ActiveCamera_2 = [Instance_4] | |
AddActor = [Instance_5] | |
vtk_renderer = org_vistrails_vistrails_vtk.vtkRenderer.descriptor.module() | |
mc_11 = ModuleConnector(create_constant(AddActor), 'value') | |
vtk_renderer.set_input_port('AddActor', mc_11) | |
mc_11 = ModuleConnector(create_constant(ActiveCamera_2), 'value') | |
vtk_renderer.set_input_port('ActiveCamera', mc_11) | |
vtk_renderer.enable_output_port('Instance') | |
vtk_renderer.compute() | |
Instance_6 = vtk_renderer.get_output('Instance') | |
# MODULE 347 org.vistrails.vistrails.vtk:vtkRendererOutput | |
# CONNECTION value Instance_6 | |
value = [Instance_6] | |
renWin = vtk.vtkRenderWindow() | |
renWin.AddRenderer(value[0].vtkInstance) | |
iren = vtk.vtkRenderWindowInteractor() | |
iren.SetRenderWindow(renWin) | |
renWin.SetSize(1024, 768) | |
iren.Initialize() | |
renWin.Render() | |
iren.Start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment