def addVTKCameraToRenderer(self, vtkRenderer, pipeline): """addVTKCameraToRenderer(renderer: Module, pipeline: Pipeline) -> Module Adds a vtkCamera module to the received vtkRenderer. If a camera already exists, it returns this camera""" vtkCamera = self.findUpstreamModuleByClass( vtkRenderer, self.getModuleClassByName("edu.utah.sci.vistrails.vtk", "vtkCamera"), pipeline ) if not vtkCamera is None: ### If a camera is already connected to the renderer, just return it return vtkCamera # Making sure we create the vtkCamera module using the current version of # the vtk package version = self.getPackageVersion("edu.utah.sci.vistrails.vtk") vtkCamera = Module( id=pipeline.fresh_module_id(), name="vtkCamera", package="edu.utah.sci.vistrails.vtk", version=version ) action = create_action([("add", vtkCamera)]) pipeline.perform_action(action) src = registry.get_port_spec("edu.utah.sci.vistrails.vtk", "vtkCamera", None, "self", "output") dst = registry.get_port_spec("edu.utah.sci.vistrails.vtk", "vtkRenderer", None, "SetActiveCamera", "input") inputPort = Port( id=pipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkRenderer.id, moduleName=vtkRenderer.name ) outputPort = Port( id=pipeline.get_tmp_id(Port.vtType), spec=src, moduleId=vtkCamera.id, moduleName=vtkCamera.name ) connection = Connection(id=pipeline.fresh_connection_id(), ports=[inputPort, outputPort]) action = create_action([("add", connection)]) pipeline.perform_action(action) return vtkCamera
def getClearPipelines(self, dimensions, clientDimensions): result = [] for row in range(dimensions[3]): for column in range(dimensions[2]): localPipeline = Pipeline() vtkversion = self.getPackageVersion("edu.utah.sci.vistrails.vtk") vtkCell = Module(id=localPipeline.fresh_module_id(), name="VTKCell", package="edu.utah.sci.vistrails.vtk", version=vtkversion) action = create_action([('add',vtkCell)]) localPipeline.perform_action(action) vtkRenderer = Module(id=localPipeline.fresh_module_id(), name="vtkRenderer", package="edu.utah.sci.vistrails.vtk", version=vtkversion) action = create_action([('add',vtkRenderer)]) localPipeline.perform_action(action) src = registry.get_port_spec('edu.utah.sci.vistrails.vtk','vtkRenderer', None, 'self','output') dst = registry.get_port_spec('edu.utah.sci.vistrails.vtk','VTKCell', None, 'AddRenderer','input') inputPort = Port(id=localPipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkCell.id, moduleName=vtkCell.name) outputPort = Port(id=localPipeline.get_tmp_id(Port.vtType), spec=src, moduleId=vtkRenderer.id, moduleName=vtkRenderer.name) connection = Connection(id=localPipeline.fresh_connection_id(), ports=[inputPort,outputPort]) action = create_action([('add',connection)]) localPipeline.perform_action(action) cellLocation = self.getCellLocationModule(vtkCell, localPipeline) if not cellLocation is None: self.deleteModule(cellLocation, localPipeline) dim = clientDimensions[(column+dimensions[0], row+dimensions[1])] self.addCellLocation(vtkCell, localPipeline, (column, row), dimensions, dim) result.append(((dimensions[0]+column,dimensions[1]+row), serialize(localPipeline))) return result
def getClearPipelines(self, dimensions, clientDimensions): result = [] for row in range(dimensions[3]): for column in range(dimensions[2]): localPipeline = Pipeline() vtkversion = self.getPackageVersion("edu.utah.sci.vistrails.vtk") vtkCell = Module( id=localPipeline.fresh_module_id(), name="VTKCell", package="edu.utah.sci.vistrails.vtk", version=vtkversion, ) action = create_action([("add", vtkCell)]) localPipeline.perform_action(action) vtkRenderer = Module( id=localPipeline.fresh_module_id(), name="vtkRenderer", package="edu.utah.sci.vistrails.vtk", version=vtkversion, ) action = create_action([("add", vtkRenderer)]) localPipeline.perform_action(action) src = registry.get_port_spec("edu.utah.sci.vistrails.vtk", "vtkRenderer", None, "self", "output") dst = registry.get_port_spec("edu.utah.sci.vistrails.vtk", "VTKCell", None, "AddRenderer", "input") inputPort = Port( id=localPipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkCell.id, moduleName=vtkCell.name ) outputPort = Port( id=localPipeline.get_tmp_id(Port.vtType), spec=src, moduleId=vtkRenderer.id, moduleName=vtkRenderer.name, ) connection = Connection(id=localPipeline.fresh_connection_id(), ports=[inputPort, outputPort]) action = create_action([("add", connection)]) localPipeline.perform_action(action) cellLocation = self.getCellLocationModule(vtkCell, localPipeline) if not cellLocation is None: self.deleteModule(cellLocation, localPipeline) dim = clientDimensions[(column + dimensions[0], row + dimensions[1])] self.addCellLocation(vtkCell, localPipeline, (column, row), dimensions, dim) result.append(((dimensions[0] + column, dimensions[1] + row), serialize(localPipeline))) return result
def addVTKCameraToRenderer(self, vtkRenderer, pipeline): """addVTKCameraToRenderer(renderer: Module, pipeline: Pipeline) -> Module Adds a vtkCamera module to the received vtkRenderer. If a camera already exists, it returns this camera""" vtkCamera = self.findUpstreamModuleByClass(vtkRenderer, self.getModuleClassByName('edu.utah.sci.vistrails.vtk','vtkCamera'), pipeline) if not vtkCamera is None: ### If a camera is already connected to the renderer, just return it return vtkCamera # Making sure we create the vtkCamera module using the current version of # the vtk package version = self.getPackageVersion("edu.utah.sci.vistrails.vtk") vtkCamera = Module(id=pipeline.fresh_module_id(), name="vtkCamera", package="edu.utah.sci.vistrails.vtk", version=version) action = create_action([('add',vtkCamera)]) pipeline.perform_action(action) src = registry.get_port_spec('edu.utah.sci.vistrails.vtk','vtkCamera', None, 'self','output') dst = registry.get_port_spec('edu.utah.sci.vistrails.vtk','vtkRenderer', None, 'SetActiveCamera','input') inputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkRenderer.id, moduleName=vtkRenderer.name) outputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=src, moduleId=vtkCamera.id, moduleName=vtkCamera.name) connection = Connection(id=pipeline.fresh_connection_id(), ports=[inputPort,outputPort]) action = create_action([('add',connection)]) pipeline.perform_action(action) return vtkCamera
def addCellLocation(self, vtkCell, pipeline, position, dimensions, deviceDimensions): """addCellLocation(vtkCell: Module, pipeline: Pipeline, position: (Int, Int)) -> None This method adds a CellLocation module to the vtkCell to ensure that it is sent to the right spreadsheet cell in the display wall. This is done according to the tuple in position""" print "Device Dimensions", deviceDimensions ### Adds the CellLocation Module # We need to make sure we create the Cell Location Module using # the current spreadsheet version version = self.getPackageVersion("edu.utah.sci.vistrails.spreadsheet") cellLocation = Module(id=pipeline.fresh_module_id(), name="CellLocation", package="edu.utah.sci.vistrails.spreadsheet", version=version) action = create_action([('add',cellLocation)]) pipeline.perform_action(action) cellLocation = pipeline.get_module_by_id(cellLocation.id) vtkCell = pipeline.get_module_by_id(vtkCell.id) src = registry.get_port_spec('edu.utah.sci.vistrails.spreadsheet','CellLocation', None, 'self','output') dst = registry.get_port_spec('edu.utah.sci.vistrails.vtk','VTKCell', None, 'Location','input') ### Connects the CellLocation module to the vtkCell inputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkCell.id, moduleName=vtkCell.name) outputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=src, moduleId=cellLocation.id, moduleName=cellLocation.name) connection = Connection(id=pipeline.fresh_connection_id(), ports=[inputPort,outputPort]) action = create_action([('add',connection)]) pipeline.perform_action(action) action_list = [] ### Creates the Column function spec = registry.get_port_spec('edu.utah.sci.vistrails.spreadsheet','CellLocation',None, 'Column','input') columnFunction = spec.create_module_function() columnFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) columnFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) columnFunction.db_parameters_id_index[columnFunction.db_parameters[0].db_id] = columnFunction.db_parameters[0] action_list.append(('add',columnFunction, cellLocation.vtType, cellLocation.id)) ### Creates the Row function spec = registry.get_port_spec('edu.utah.sci.vistrails.spreadsheet','CellLocation',None, 'Row','input') rowFunction = spec.create_module_function() rowFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) rowFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) rowFunction.db_parameters_id_index[rowFunction.db_parameters[0].db_id] = rowFunction.db_parameters[0] action_list.append(('add',rowFunction, cellLocation.vtType, cellLocation.id)) action = create_action(action_list) pipeline.perform_action(action) cellLocation = pipeline.get_module_by_id(cellLocation.id) columnFunction = [x for x in cellLocation._get_functions() if x.name == "Column"][0] rowFunction = [x for x in cellLocation._get_functions() if x.name == "Row"][0] ### Sets the value of columnFunction and rowFunction paramList = [] # columnValue = (dimensions[0] + position[0]) % 2 + 1 # rowValue = (dimensions[1] + position[1]) % 2 + 1 gPos = (dimensions[0] + position[0], dimensions[1] + position[1]) columnValue = (gPos[0]-deviceDimensions[0]) % deviceDimensions[2] + 1 rowValue = (gPos[1]-deviceDimensions[1]) % deviceDimensions[3] + 1 print (columnValue, rowValue) ### changes the Column function paramList.append((str(columnValue), columnFunction.params[0].type, columnFunction.params[0].namespace, columnFunction.params[0].identifier, None)) ### changes the Row function paramList.append((str(rowValue), rowFunction.params[0].type, rowFunction.params[0].namespace, rowFunction.params[0].identifier, None)) action_list = [] for i in xrange(len(paramList)): (p_val, p_type, p_namespace, p_identifier, p_alias) = paramList[i] function = columnFunction if i == 0 else rowFunction old_param = function.params[0] param_id = pipeline.get_tmp_id(ModuleParam.vtType) new_param = ModuleParam(id=param_id, pos=i, name='<no description>', alias=p_alias, val=p_val, type=p_type, identifier=p_identifier, namespace=p_namespace, ) action_list.append(('change', old_param, new_param, function.vtType, function.real_id)) action = create_action(action_list) pipeline.perform_action(action)
def setCamera(self, vtkCell, camera, pipeline, position, dimensions, doZoom): """ setCamera(vtkCell: Module, camera: Module, pipeline: Pipeline, position: (Int, Int), dimensions: (Int, Int), doZoom: Bool) -> Pipeline This method modifies the received camera in the received pipeline to have it match the requirements for the display wall """ functionList = camera._get_functions() windowCenterFunction = None zoomFunction = None for function in functionList: if function.name == "SetWindowCenter": windowCenterFunction = function if function.name == "Zoom": zoomFunction = function action_list = [] if windowCenterFunction is None: spec = registry.get_port_spec('edu.utah.sci.vistrails.vtk','vtkCamera', None, 'SetWindowCenter','input') windowCenterFunction = spec.create_module_function() windowCenterFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) windowCenterFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) windowCenterFunction.db_parameters[1].db_id = pipeline.get_tmp_id(ModuleParam.vtType) windowCenterFunction.db_parameters_id_index[windowCenterFunction.db_parameters[0].db_id] = windowCenterFunction.db_parameters[0] windowCenterFunction.db_parameters_id_index[windowCenterFunction.db_parameters[1].db_id] = windowCenterFunction.db_parameters[1] action_list.append(('add', windowCenterFunction, camera.vtType, camera.id)) if zoomFunction is None: spec = registry.get_port_spec('edu.utah.sci.vistrails.vtk','vtkCamera', None, 'Zoom','input') zoomFunction = spec.create_module_function() zoomFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) zoomFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) zoomFunction.db_parameters_id_index[zoomFunction.db_parameters[0].db_id] = zoomFunction.db_parameters[0] action_list.append(('add', zoomFunction, camera.vtType, camera.id)) action = create_action(action_list) pipeline.perform_action(action) camera = pipeline.get_module_by_id(camera.id) functionList = camera._get_functions() windowCenterFunction = [x for x in camera._get_functions() if x.name == "SetWindowCenter"][0] if doZoom: zoomFunction = [x for x in camera._get_functions() if x.name == "Zoom"][0] columnCenter = - dimensions[2] + (position[0]*2+1); rowCenter = dimensions[3] - (position[1]*2+1); zoom = min(dimensions[2], dimensions[3]) # zoom = min(dimensions[2] - dimensions[0]+1, dimensions[3] - dimensions[1]+1) paramList = [] ### changes the setWindowCenter function paramList.append((str(columnCenter), windowCenterFunction.params[0].type, windowCenterFunction.params[0].namespace, windowCenterFunction.params[0].identifier, None)) paramList.append((str(rowCenter), windowCenterFunction.params[1].type, windowCenterFunction.params[1].namespace, windowCenterFunction.params[1].identifier, None)) if doZoom: ### changes the zoom function paramList.append((str(zoom), zoomFunction.params[0].type, zoomFunction.params[0].namespace, zoomFunction.params[0].identifier, None)) action_list = [] for i in xrange(len(paramList)): (p_val, p_type, p_namespace, p_identifier, p_alias) = paramList[i] function = windowCenterFunction if i == 0 or i == 1 else zoomFunction old_param = function.params[i] if i == 0 or i == 1 else function.params[0] param_id = pipeline.get_tmp_id(ModuleParam.vtType) new_param = ModuleParam(id=param_id, pos=i, name='<no description>', alias=p_alias, val=p_val, type=p_type, identifier=p_identifier, namespace=p_namespace,) action_list.append(('change', old_param, new_param, function.vtType, function.real_id)) action = create_action(action_list) pipeline.perform_action(action) serializedPipeline = serialize(pipeline) result = ((dimensions[0]+position[0], dimensions[1]+position[1]), serializedPipeline) return result
def addCellLocation(self, vtkCell, pipeline, position, dimensions, deviceDimensions): """addCellLocation(vtkCell: Module, pipeline: Pipeline, position: (Int, Int)) -> None This method adds a CellLocation module to the vtkCell to ensure that it is sent to the right spreadsheet cell in the display wall. This is done according to the tuple in position""" print "Device Dimensions", deviceDimensions ### Adds the CellLocation Module # We need to make sure we create the Cell Location Module using # the current spreadsheet version version = self.getPackageVersion("edu.utah.sci.vistrails.spreadsheet") cellLocation = Module( id=pipeline.fresh_module_id(), name="CellLocation", package="edu.utah.sci.vistrails.spreadsheet", version=version, ) action = create_action([("add", cellLocation)]) pipeline.perform_action(action) cellLocation = pipeline.get_module_by_id(cellLocation.id) vtkCell = pipeline.get_module_by_id(vtkCell.id) src = registry.get_port_spec("edu.utah.sci.vistrails.spreadsheet", "CellLocation", None, "self", "output") dst = registry.get_port_spec("edu.utah.sci.vistrails.vtk", "VTKCell", None, "Location", "input") ### Connects the CellLocation module to the vtkCell inputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkCell.id, moduleName=vtkCell.name) outputPort = Port( id=pipeline.get_tmp_id(Port.vtType), spec=src, moduleId=cellLocation.id, moduleName=cellLocation.name ) connection = Connection(id=pipeline.fresh_connection_id(), ports=[inputPort, outputPort]) action = create_action([("add", connection)]) pipeline.perform_action(action) action_list = [] ### Creates the Column function spec = registry.get_port_spec("edu.utah.sci.vistrails.spreadsheet", "CellLocation", None, "Column", "input") columnFunction = spec.create_module_function() columnFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) columnFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) columnFunction.db_parameters_id_index[columnFunction.db_parameters[0].db_id] = columnFunction.db_parameters[0] action_list.append(("add", columnFunction, cellLocation.vtType, cellLocation.id)) ### Creates the Row function spec = registry.get_port_spec("edu.utah.sci.vistrails.spreadsheet", "CellLocation", None, "Row", "input") rowFunction = spec.create_module_function() rowFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) rowFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) rowFunction.db_parameters_id_index[rowFunction.db_parameters[0].db_id] = rowFunction.db_parameters[0] action_list.append(("add", rowFunction, cellLocation.vtType, cellLocation.id)) action = create_action(action_list) pipeline.perform_action(action) cellLocation = pipeline.get_module_by_id(cellLocation.id) columnFunction = [x for x in cellLocation._get_functions() if x.name == "Column"][0] rowFunction = [x for x in cellLocation._get_functions() if x.name == "Row"][0] ### Sets the value of columnFunction and rowFunction paramList = [] # columnValue = (dimensions[0] + position[0]) % 2 + 1 # rowValue = (dimensions[1] + position[1]) % 2 + 1 gPos = (dimensions[0] + position[0], dimensions[1] + position[1]) columnValue = (gPos[0] - deviceDimensions[0]) % deviceDimensions[2] + 1 rowValue = (gPos[1] - deviceDimensions[1]) % deviceDimensions[3] + 1 print (columnValue, rowValue) ### changes the Column function paramList.append( ( str(columnValue), columnFunction.params[0].type, columnFunction.params[0].namespace, columnFunction.params[0].identifier, None, ) ) ### changes the Row function paramList.append( ( str(rowValue), rowFunction.params[0].type, rowFunction.params[0].namespace, rowFunction.params[0].identifier, None, ) ) action_list = [] for i in xrange(len(paramList)): (p_val, p_type, p_namespace, p_identifier, p_alias) = paramList[i] function = columnFunction if i == 0 else rowFunction old_param = function.params[0] param_id = pipeline.get_tmp_id(ModuleParam.vtType) new_param = ModuleParam( id=param_id, pos=i, name="<no description>", alias=p_alias, val=p_val, type=p_type, identifier=p_identifier, namespace=p_namespace, ) action_list.append(("change", old_param, new_param, function.vtType, function.real_id)) action = create_action(action_list) pipeline.perform_action(action)
def setCamera(self, vtkCell, camera, pipeline, position, dimensions, doZoom): """ setCamera(vtkCell: Module, camera: Module, pipeline: Pipeline, position: (Int, Int), dimensions: (Int, Int), doZoom: Bool) -> Pipeline This method modifies the received camera in the received pipeline to have it match the requirements for the display wall """ functionList = camera._get_functions() windowCenterFunction = None zoomFunction = None for function in functionList: if function.name == "SetWindowCenter": windowCenterFunction = function if function.name == "Zoom": zoomFunction = function action_list = [] if windowCenterFunction is None: spec = registry.get_port_spec("edu.utah.sci.vistrails.vtk", "vtkCamera", None, "SetWindowCenter", "input") windowCenterFunction = spec.create_module_function() windowCenterFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) windowCenterFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) windowCenterFunction.db_parameters[1].db_id = pipeline.get_tmp_id(ModuleParam.vtType) windowCenterFunction.db_parameters_id_index[ windowCenterFunction.db_parameters[0].db_id ] = windowCenterFunction.db_parameters[0] windowCenterFunction.db_parameters_id_index[ windowCenterFunction.db_parameters[1].db_id ] = windowCenterFunction.db_parameters[1] action_list.append(("add", windowCenterFunction, camera.vtType, camera.id)) if zoomFunction is None: spec = registry.get_port_spec("edu.utah.sci.vistrails.vtk", "vtkCamera", None, "Zoom", "input") zoomFunction = spec.create_module_function() zoomFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) zoomFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) zoomFunction.db_parameters_id_index[zoomFunction.db_parameters[0].db_id] = zoomFunction.db_parameters[0] action_list.append(("add", zoomFunction, camera.vtType, camera.id)) action = create_action(action_list) pipeline.perform_action(action) camera = pipeline.get_module_by_id(camera.id) functionList = camera._get_functions() windowCenterFunction = [x for x in camera._get_functions() if x.name == "SetWindowCenter"][0] if doZoom: zoomFunction = [x for x in camera._get_functions() if x.name == "Zoom"][0] columnCenter = -dimensions[2] + (position[0] * 2 + 1) rowCenter = dimensions[3] - (position[1] * 2 + 1) zoom = min(dimensions[2], dimensions[3]) # zoom = min(dimensions[2] - dimensions[0]+1, dimensions[3] - dimensions[1]+1) paramList = [] ### changes the setWindowCenter function paramList.append( ( str(columnCenter), windowCenterFunction.params[0].type, windowCenterFunction.params[0].namespace, windowCenterFunction.params[0].identifier, None, ) ) paramList.append( ( str(rowCenter), windowCenterFunction.params[1].type, windowCenterFunction.params[1].namespace, windowCenterFunction.params[1].identifier, None, ) ) if doZoom: ### changes the zoom function paramList.append( ( str(zoom), zoomFunction.params[0].type, zoomFunction.params[0].namespace, zoomFunction.params[0].identifier, None, ) ) action_list = [] for i in xrange(len(paramList)): (p_val, p_type, p_namespace, p_identifier, p_alias) = paramList[i] function = windowCenterFunction if i == 0 or i == 1 else zoomFunction old_param = function.params[i] if i == 0 or i == 1 else function.params[0] param_id = pipeline.get_tmp_id(ModuleParam.vtType) new_param = ModuleParam( id=param_id, pos=i, name="<no description>", alias=p_alias, val=p_val, type=p_type, identifier=p_identifier, namespace=p_namespace, ) action_list.append(("change", old_param, new_param, function.vtType, function.real_id)) action = create_action(action_list) pipeline.perform_action(action) serializedPipeline = serialize(pipeline) result = ((dimensions[0] + position[0], dimensions[1] + position[1]), serializedPipeline) return result