<s> from core . modules . module_registry import get_module_registry <EOL> from core . modules . vistrails_module import Module <EOL> from core . modules . basic_modules import File , Integer <EOL> class VTKRenderOffscreen ( Module ) : <EOL> def compute ( self ) : <EOL> r = self . get_input ( "<STR_LIT>" ) . vtkInstance <EOL> window = vtk . vtkRenderWindow ( ) <EOL> w = self . force_get_input ( "<STR_LIT:width>" , <NUM_LIT> ) <EOL> h = self . force_get_input ( "<STR_LIT>" , <NUM_LIT> ) <EOL> window . OffScreenRenderingOn ( ) <EOL> window . SetSize ( w , h ) <EOL> window . AddRenderer ( r ) <EOL> window . Start ( ) <EOL> window . Render ( ) <EOL> win2image = vtk . vtkWindowToImageFilter ( ) <EOL> win2image . SetInput ( window ) <EOL> win2image . Update ( ) <EOL> writer = vtk . vtkPNGWriter ( ) <EOL> writer . SetInput ( win2image . GetOutput ( ) ) <EOL> output = self . interpreter . filePool . create_file ( suffix = '<STR_LIT>' ) <EOL> writer . SetFileName ( output . name ) <EOL> writer . Write ( ) <EOL> window . Finalize ( ) <EOL> self . set_output ( "<STR_LIT:image>" , output ) <EOL> def register_self ( ) : <EOL> registry = get_module_registry ( ) <EOL> r = registry . get_descriptor_by_name ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) . module <EOL> registry . add_module ( VTKRenderOffscreen ) <EOL> registry . add_input_port ( VTKRenderOffscreen , '<STR_LIT>' , r ) <EOL> registry . add_input_port ( VTKRenderOffscreen , '<STR_LIT:width>' , Integer ) <EOL> registry . add_input_port ( VTKRenderOffscreen , '<STR_LIT>' , Integer ) <EOL> registry . add_output_port ( VTKRenderOffscreen , '<STR_LIT:image>' , File ) </s>
