def CreatePiecewiseFunction(**params): """Create and return a piecewise function. Optionally, parameters can be given to assign to the piecewise function. """ pfunc = servermanager.piecewise_functions.PiecewiseFunction() servermanager.Register(pfunc) SetProperties(pfunc, **params) return pfunc
def CreateLookupTable(**params): """Create and return a lookup table. Optionally, parameters can be given to assign to the lookup table. """ lt = servermanager.rendering.PVLookupTable() servermanager.Register(lt) SetProperties(lt, **params) return lt
def __GetLookupTableForArray(self, aArray, **kwargs): """ Set the lookup table for the given array and assign the named properties. """ proxyName = '%d.%s.PVLookupTable' % (aArray.GetNumberOfComponents(), aArray.GetName()) lut = servermanager.ProxyManager().GetProxy('lookup_tables', proxyName) if not lut: lut = servermanager.rendering.PVLookupTable( ColorSpace="HSV", RGBPoints=[0, 0, 0, 1, 1, 1, 0, 0]) servermanager.Register(lut, registrationName=proxyName) for arg in kwargs.keys(): if not hasattr(lut, arg): raise AttributeError("LUT has no property %s" % (arg)) setattr(lut, arg, kwargs[arg]) return lut
def GetLookupTableForArray(arrayname, num_components, **params): """Used to get an existing lookuptable for a array or to create one if none exists. Keyword arguments can be passed in to initialize the LUT if a new one is created.""" proxyName = "%d.%s.PVLookupTable" % (int(num_components), arrayname) lut = servermanager.ProxyManager().GetProxy("lookup_tables", proxyName) if lut: return lut # No LUT exists for this array, create a new one. # TODO: Change this to go a LookupTableManager that is shared with the GUI, # so that the GUI and python end up create same type of LUTs. For now, # python will create a Blue-Red LUT, unless overridden by params. lut = servermanager.rendering.PVLookupTable( ColorSpace="HSV", RGBPoints=[0, 0, 0, 1, 1, 1, 0, 0]) SetProperties(lut, **params) servermanager.Register(lut, registrationName=proxyName) return lut
def CreateScalarBar(**params): """Create and return a scalar bar widget. The returned widget may be added to a render view by appending it to the view's representations The widget must have a valid lookup table before it is added to a view. It is possible to pass the lookup table (and other properties) as arguments to this method: lt = MakeBlueToRedLt(3.5, 7.5) bar = CreateScalarBar(LookupTable=lt, Title="Velocity") GetRenderView().Representations.append(bar) By default the returned widget is selectable and resizable. """ sb = servermanager.rendering.ScalarBarWidgetRepresentation() servermanager.Register(sb) sb.Selectable = 1 sb.Resizable = 1 sb.Enabled = 1 sb.Title = "Scalars" SetProperties(sb, **params) return sb
def CreateObject(*input, **params): """This function creates a new proxy. For pipeline objects that accept inputs, all non-keyword arguments are assumed to be inputs. All keyword arguments are assumed to be property,value pairs and are passed to the new proxy.""" # Instantiate the actual object from the given module. px = module.__dict__[key]() # Make sure non-keyword arguments are valid for inp in input: if inp != None and not isinstance(inp, servermanager.Proxy): if px.GetProperty("Input") != None: raise RuntimeError, "Expecting a proxy as input." else: raise RuntimeError, "This function does not accept non-keyword arguments." # Assign inputs if px.GetProperty("Input") != None: if len(input) > 0: px.Input = input else: # If no input is specified, try the active pipeline object if px.GetProperty("Input").GetRepeatable( ) and active_objects.get_selected_sources(): px.Input = active_objects.get_selected_sources() elif active_objects.source: px.Input = active_objects.source else: if len(input) > 0: raise RuntimeError, "This function does not expect an input." registrationName = None for nameParam in ['registrationName', 'guiName']: if nameParam in params: registrationName = params[nameParam] del params[nameParam] # Pass all the named arguments as property,value pairs for param in params.keys(): setattr(px, param, params[param]) try: # Register the proxy with the proxy manager. if registrationName: group, name = servermanager.Register( px, registrationName=registrationName) else: group, name = servermanager.Register(px) # Register pipeline objects with the time keeper. This is used to extract time values # from sources. NOTE: This should really be in the servermanager controller layer. if group == "sources": tk = servermanager.ProxyManager().GetProxiesInGroup( "timekeeper").values()[0] sources = tk.TimeSources if not px in sources: sources.append(px) active_objects.source = px except servermanager.MissingRegistrationInformation: pass return px