def testDirtyPropagation(self): n = GafferTest.StringInOutNode() c = Gaffer.ContextVariables() c.setup(Gaffer.StringPlug()) c["in"].setInput(n["out"]) # adding a variable should dirty the output: dirtied = GafferTest.CapturingSlot(c.plugDirtiedSignal()) c["variables"].addChild( Gaffer.NameValuePlug("a", IECore.StringData("A"), "member1", flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)) self.assertIn(c["out"], [p[0] for p in dirtied]) # modifying the variable should dirty the output: dirtied = GafferTest.CapturingSlot(c.plugDirtiedSignal()) c["variables"]["member1"]["value"].setValue("b") self.assertIn(c["out"], [p[0] for p in dirtied]) # removing the variable should also dirty the output: dirtied = GafferTest.CapturingSlot(c.plugDirtiedSignal()) c["variables"].removeChild(c["variables"]["member1"]) self.assertIn(c["out"], [p[0] for p in dirtied])
def test(self): p = GafferScene.Plane() a = GafferScene.Attributes() a["in"].setInput(p["out"]) a["attributes"].addMember("user:something", IECore.StringData("$a")) d = Gaffer.DeleteContextVariables() d.setup(GafferScene.ScenePlug()) d["in"].setInput(a["out"]) c = Gaffer.ContextVariables() c.setup(GafferScene.ScenePlug()) c["in"].setInput(d["out"]) c["variables"].addMember("a", IECore.StringData("aardvark")) self.assertEqual(a["out"].attributes("/plane")["user:something"], IECore.StringData("")) self.assertEqual(c["out"].attributes("/plane")["user:something"], IECore.StringData("aardvark")) d["variables"].setValue("a") self.assertEqual(c["out"].attributes("/plane")["user:something"], IECore.StringData(""))
def testPivotExpression(self): script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["expression"] = Gaffer.Expression() script["expression"].setExpression( inspect.cleandoc(""" parent["plane"]["transform"]["pivot"]["x"] = context["x"] """)) script["variables"] = Gaffer.ContextVariables() script["variables"].setup(GafferScene.ScenePlug()) script["variables"]["in"].setInput(script["plane"]["out"]) script["variables"]["variables"].addChild( Gaffer.NameValuePlug("x", 1.0)) view = GafferSceneUI.SceneView() view["in"].setInput(script["variables"]["out"]) view.setContext(script.context()) GafferSceneUI.ContextAlgo.setSelectedPaths( view.getContext(), IECore.PathMatcher(["/plane"])) tool = GafferSceneUI.TranslateTool(view) tool["active"].setValue(True) self.assertEqual(tool.selection()[0].path, "/plane") self.assertEqual(tool.handlesTransform(), imath.M44f().translate(imath.V3f(1, 0, 0)))
def testContextLeaks(self): script = Gaffer.ScriptNode() script["plane"] = GafferScene.Plane() script["plane"]["sets"].setValue("A") script["contextVariables"] = Gaffer.ContextVariables() script["contextVariables"].setup(GafferScene.ScenePlug()) script["contextVariables"]["in"].setInput(script["plane"]["out"]) script["contextVariables"]["variables"].addOptionalMember( "a", IECore.StringData("aardvark"), plugName="a") script["expression"] = Gaffer.Expression() script["expression"].setExpression( inspect.cleandoc(""" parent["contextVariables"]["enabled"] = True parent["contextVariables"]["variables"]["a"]["enabled"] = True parent["contextVariables"]["variables"]["a"]["name"] = "b" parent["contextVariables"]["variables"]["a"]["value"] = "b" """)) with Gaffer.ContextMonitor(script["expression"]) as cm: self.assertSceneValid(script["contextVariables"]["out"]) self.assertFalse( set(cm.combinedStatistics().variableNames()).intersection( {"scene:path", "scene:setName", "scene:filter:inputScene"}))
def testPatternMatching( self ) : n = GafferTest.StringInOutNode() self.assertHashesValid( n ) d = Gaffer.DeleteContextVariables() d.setup( Gaffer.StringPlug() ) d["in"].setInput( n["out"] ) c = Gaffer.ContextVariables() c.setup( Gaffer.StringPlug() ) c["in"].setInput( d["out"] ) n["in"].setValue( "$a1_$a2_$b1_$b2_$c1_$c2" ) self.assertEqual( c["out"].getValue(), "_____" ) c["variables"].addMember( "a1", IECore.StringData( "A1" ) ) c["variables"].addMember( "a2", IECore.StringData( "A2" ) ) c["variables"].addMember( "b1", IECore.StringData( "B1" ) ) c["variables"].addMember( "b2", IECore.StringData( "B2" ) ) c["variables"].addMember( "c1", IECore.StringData( "C1" ) ) c["variables"].addMember( "c2", IECore.StringData( "C2" ) ) self.assertEqual( c["out"].getValue(), "A1_A2_B1_B2_C1_C2" ) d["variables"].setValue( "a* c*" ) self.assertEqual( c["out"].getValue(), "__B1_B2__" )
def testExtraVariables( self ) : s = Gaffer.ScriptNode() s["n"] = GafferTest.StringInOutNode() s["c"] = Gaffer.ContextVariables() s["c"].setup( Gaffer.StringPlug() ) s["c"]["in"].setInput( s["n"]["out"] ) s["n"]["in"].setValue( "$a" ) self.assertEqual( s["c"]["out"].getValue(), "" ) dirtied = GafferTest.CapturingSlot( s["c"].plugDirtiedSignal() ) s["c"]["extraVariables"].setValue( IECore.CompoundData( { "a" : "A" } ) ) self.failUnless( s["c"]["out"] in { p[0] for p in dirtied } ) self.assertEqual( s["c"]["out"].getValue(), "A" ) # Extra variables trump regular variables of the same name s["c"]["variables"].addChild( Gaffer.NameValuePlug( "a", IECore.StringData( "B" ) ) ) self.assertEqual( s["c"]["out"].getValue(), "A" ) s2 = Gaffer.ScriptNode() s2.execute( s.serialise() ) self.assertEqual( s2["c"]["out"].getValue(), "A" )
def testNullMember(self): p = GafferScene.Plane() c = Gaffer.ContextVariables() c.setup(GafferScene.ScenePlug()) c["in"].setInput(p["out"]) c["variables"].addMember("", IECore.StringData("aardvark")) self.assertSceneValid(c["out"])
def testEnabledPlugAffectsOutput( self ) : c = Gaffer.ContextVariables() c.setup( Gaffer.StringPlug() ) cs = GafferTest.CapturingSlot( c.plugDirtiedSignal() ) c["enabled"].setValue( False ) self.assertEqual( len( cs ), 2 ) self.assertEqual( { x[0] for x in cs }, { c["enabled"], c["out"] } )
def test( self ) : n = GafferTest.StringInOutNode() self.assertHashesValid( n ) c = Gaffer.ContextVariables() c.setup( Gaffer.StringPlug() ) c["in"].setInput( n["out"] ) n["in"].setValue( "$a" ) self.assertEqual( c["out"].getValue(), "" ) c["variables"].addChild( Gaffer.NameValuePlug( "a", IECore.StringData( "A" ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) ) self.assertEqual( c["out"].getValue(), "A" )
def test(self): n = GafferTest.StringInOutNode() self.assertHashesValid(n) c = Gaffer.ContextVariables() c.setup(Gaffer.StringPlug()) c["in"].setInput(n["out"]) n["in"].setValue("$a") self.assertEqual(c["out"].getValue(), "") c["variables"].addMember("a", IECore.StringData("A")) self.assertEqual(c["out"].getValue(), "A")
def testInputFromContextVariables( self ) : plane = GafferScene.Plane() variables = Gaffer.ContextVariables() variables.setup( GafferScene.ScenePlug() ) variables["in"].setInput( plane["out"] ) render = GafferAppleseed.AppleseedRender() render["in"].setInput( variables["out"] ) render["mode"].setValue( render.Mode.SceneDescriptionMode ) render["fileName"].setValue( os.path.join( self.temporaryDirectory(), "test.appleseed" ) ) self.assertNotEqual( render["task"].hash(), IECore.MurmurHash() ) render["task"].execute() self.assertTrue( os.path.exists( render["fileName"].getValue() ) )
def testTaskAttributes(self): s = Gaffer.ScriptNode() s["n"] = GafferDispatchTest.LoggingTaskNode() s["n"]["frame"] = Gaffer.StringPlug(defaultValue="${frame}", flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic) s["n"]["dispatcher"]["batchSize"].setValue(10) s["n"]["dispatcher"]["tractor"]["tags"].setValue( "myTag1 ${myTagContext2}") s["expression"] = Gaffer.Expression() s["expression"].setExpression( """parent["n"]["dispatcher"]["tractor"]["service"] = context.get("service", "")""" ) # add context variables: myTagContext2 and service s["context"] = Gaffer.ContextVariables() s["context"].setup(GafferDispatch.TaskNode.TaskPlug()) s["context"]["in"].setInput(s["n"]["task"]) variable = s["context"]["variables"].addMember("tag", Gaffer.StringPlug()) variable["name"].setValue("myTagContext2") variable["value"].setValue("myTag2") variable = s["context"]["variables"].addMember("service", Gaffer.StringPlug()) variable["name"].setValue("service") variable["value"].setValue("myService") s["job"] = Gaffer.TaskList() s["job"]["preTasks"][0].setInput(s["context"]["out"]) dispatcher = self.__dispatcher() dispatcher["framesMode"].setValue(dispatcher.FramesMode.CustomRange) dispatcher["frameRange"].setValue("1-10") job = self.__job([s["job"]], dispatcher) self.assertEqual(len(job.subtasks), 10) task = job.subtasks[0].subtasks[0] self.assertEqual(task.title, "n 1-10") self.assertEqual(len(task.cmds), 1) command = task.cmds[0] self.assertEqual(command.service, "myService", "context variables were not expanded correctly") self.assertEqual(command.tags, ["myTag1", "myTag2"])
def __init__(self, name='CatalogueSelect'): GafferImage.ImageProcessor.__init__(self, name) self["imageName"] = Gaffer.StringPlug() self["__context"] = Gaffer.ContextVariables() self["__context"].setup(self["in"]) self["__context"]["variables"].addChild( Gaffer.NameValuePlug("catalogue:imageName", "", "imageNameMember")) self["__context"]["variables"]["imageNameMember"]["value"].setInput( self["imageName"]) self["__context"]["in"].setInput(self["in"]) self["out"].setInput(self["__context"]["out"]) self['out'].setFlags(Gaffer.Plug.Flags.Serialisable, False)
def testConnectNameSwitch(self): s = Gaffer.ScriptNode() s["n"] = GafferTest.AddNode() s["s"] = Gaffer.NameSwitch() g = GafferUI.GraphGadget(s) g.getLayout().connectNode(g, s["s"], Gaffer.StandardSet([s["n"]])) self.assertIsInstance(s["s"]["in"][0], Gaffer.NameValuePlug) self.assertTrue(isinstance(s["s"]["in"][0]["value"], Gaffer.IntPlug)) self.assertEqual(s["s"]["in"][0]["value"].getInput(), s["n"]["sum"]) s["c"] = Gaffer.ContextVariables() g.getLayout().connectNode(g, s["c"], Gaffer.StandardSet([s["s"]])) self.assertIsInstance(s["c"]["in"], Gaffer.IntPlug) self.assertEqual(s["c"]["in"].getInput(), s["s"]["out"]["value"])
def testSerialisationUsesSetup( self ) : s1 = Gaffer.ScriptNode() s1["c"] = Gaffer.ContextVariables() s1["c"].setup( Gaffer.IntPlug() ) ss = s1.serialise() self.assertIn( "setup", ss ) self.assertEqual( ss.count( "addChild" ), 1 ) self.assertNotIn( "Dynamic", ss ) self.assertNotIn( "setInput", ss ) s2 = Gaffer.ScriptNode() s2.execute( ss ) self.assertIn( "in", s2["c"] ) self.assertIn( "out", s2["c"] ) self.assertIsInstance( s2["c"]["in"], Gaffer.IntPlug ) self.assertIsInstance( s2["c"]["out"], Gaffer.IntPlug )
def testSerialisation(self): s = Gaffer.ScriptNode() s["n"] = GafferTest.StringInOutNode() s["c"] = Gaffer.ContextVariables() s["c"].setup(Gaffer.StringPlug()) s["c"]["in"].setInput(s["n"]["out"]) s["n"]["in"].setValue("$a") self.assertEqual(s["c"]["out"].getValue(), "") s["c"]["variables"].addMember("a", IECore.StringData("A")) self.assertEqual(s["c"]["out"].getValue(), "A") s2 = Gaffer.ScriptNode() s2.execute(s.serialise()) self.assertEqual(s2["c"].keys(), s["c"].keys()) self.assertEqual(s2["c"]["out"].getValue(), "A")
def testSerialisation( self ) : s = Gaffer.ScriptNode() s["n"] = GafferTest.StringInOutNode() s["c"] = Gaffer.ContextVariables() s["c"].setup( Gaffer.StringPlug() ) s["c"]["in"].setInput( s["n"]["out"] ) s["n"]["in"].setValue( "$a" ) self.assertEqual( s["c"]["out"].getValue(), "" ) s["c"]["variables"].addChild( Gaffer.NameValuePlug( "a", IECore.StringData( "A" ), flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic ) ) self.assertEqual( s["c"]["out"].getValue(), "A" ) s2 = Gaffer.ScriptNode() s2.execute( s.serialise() ) self.assertEqual( s2["c"].keys(), s["c"].keys() ) self.assertEqual( s2["c"]["out"].getValue(), "A" )
def testExtraVariablesExpression( self ) : s = Gaffer.ScriptNode() s["n"] = GafferTest.StringInOutNode() s["c"] = Gaffer.ContextVariables() s["c"].setup( Gaffer.StringPlug() ) s["c"]["in"].setInput( s["n"]["out"] ) s["n"]["in"].setValue( "$a$b$c" ) self.assertEqual( s["c"]["out"].getValue(), "" ) s["e"] = Gaffer.Expression() s["e"].setExpression( inspect.cleandoc( """ result = IECore.CompoundData() if context.getFrame() > 1 : result["a"] = "A" if context.getFrame() > 2 : result["b"] = "B" if context.getFrame() > 3 : result["c"] = "C" parent["c"]["extraVariables"] = result """ ) ) with Gaffer.Context() as c : self.assertEqual( s["c"]["out"].getValue(), "" ) c.setFrame( 2 ) self.assertEqual( s["c"]["out"].getValue(), "A" ) c.setFrame( 3 ) self.assertEqual( s["c"]["out"].getValue(), "AB" ) c.setFrame( 4 ) self.assertEqual( s["c"]["out"].getValue(), "ABC" )
def testDirtyPropagation(self): n = GafferTest.StringInOutNode() c = Gaffer.ContextVariables() c.setup(Gaffer.StringPlug()) c["in"].setInput(n["out"]) # adding a variable should dirty the output: dirtied = GafferTest.CapturingSlot(c.plugDirtiedSignal()) c["variables"].addMember("a", IECore.StringData("A")) self.failUnless(c["out"] in [p[0] for p in dirtied]) # modifying the variable should dirty the output: dirtied = GafferTest.CapturingSlot(c.plugDirtiedSignal()) c["variables"]["member1"]["value"].setValue("b") self.failUnless(c["out"] in [p[0] for p in dirtied]) # removing the variable should also dirty the output: dirtied = GafferTest.CapturingSlot(c.plugDirtiedSignal()) c["variables"].removeChild(c["variables"]["member1"]) self.failUnless(c["out"] in [p[0] for p in dirtied])
def testPerformance(self): c = Gaffer.ContextVariables() c.setup(Gaffer.IntPlug()) for i in range(10): c["variables"].addChild( Gaffer.NameValuePlug("a%i" % i, IECore.StringData("A" * 100), flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)) c["variables"].addChild( Gaffer.NameValuePlug("intName", IECore.IntData(100), flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)) # This would be a bit more representative if our source node was actually affected by the context variables, # but without access to OSL in this test we don't have any efficient way to read context variables handy, # and we're mostly just interested in the amount of overhead anyway n = GafferTest.MultiplyNode() c["in"].setInput(n["product"]) GafferTest.parallelGetValue(c["out"], 1000000, "iter")
def __init__( self, name = "MultiMonoImageReader" ) : GafferImage.ImageNode.__init__( self, name ) self["fileName"] = Gaffer.StringPlug( "fileName", defaultValue = "${token}.${extension}" ) self["resize"] = Gaffer.FloatPlug( defaultValue = 1.0, minValue = 0.001 ) fitsReader = GafferAstro.FITSReader() self["__FITSReader"] = fitsReader fitsReader["fileName"].setInput( self["fileName"] ) xisfReader = GafferAstro.XISFReader() self["__XISFReader"] = xisfReader xisfReader["fileName"].setInput( self["fileName"] ) imageReader = GafferImage.ImageReader() self["__ImageReader"] = imageReader imageReader["fileName"].setInput( self["fileName"] ) readerSwitch = Gaffer.Switch() readerSwitch.setup( fitsReader["out"] ) self["__ReaderSwitch"] = readerSwitch readerSwitch["in"][0].setInput( fitsReader["out"] ) readerSwitch["in"][1].setInput( xisfReader["out"] ) readerSwitch["in"][2].setInput( imageReader["out"] ) switchExpression = Gaffer.Expression() self["__SwitchExpression"] = switchExpression switchExpression.setExpression( inspect.cleandoc( """ map = { "fits" : 0, "xisf" : 1 } parent["__ReaderSwitch"]["index"] = map.get( context[ "extension" ], 2 ) """ ), "python" ) scale = GafferAstro.Scale() self["__Scale"] = scale scale["in"].setInput( readerSwitch["out"] ) scale["factor"].setInput( self["resize"] ) scale["filter"].setValue( "sharp-gaussian" ) variables = Gaffer.ContextVariables() variables.setup( scale["out"] ) self["__Variables"] = variables variables["in"].setInput( scale["out"] ) variables["variables"].addChild( Gaffer.NameValuePlug( "extension", IECore.StringData( "" ), name="extension" ) ) variables["variables"].addChild( Gaffer.NameValuePlug( "token", IECore.StringData( "" ), name="token" ) ) collectChannels = GafferAstro.CollectChannels() self["__CollectChannels"] = collectChannels collectChannels["in"].setInput( variables["out"] ) collectChannels["channelVariable"].setValue( "channel" ) self["out"].setInput( collectChannels["out"] ) spreadsheet = Gaffer.Spreadsheet() self["__Spreadsheet"] = spreadsheet spreadsheet["selector"].setValue( "${channel}" ) Gaffer.Metadata.registerValue( spreadsheet["rows"], "spreadsheet:columnsNeedSerialisation", False, persistent = False ) tokenColumnIndex = spreadsheet["rows"].addColumn( Gaffer.StringPlug( "filenameToken", defaultValue="${channel}" ) ) extensionColumnIndex = spreadsheet["rows"].addColumn( Gaffer.StringPlug( "extension", defaultValue = "xisf" ) ) Gaffer.Metadata.registerValue( spreadsheet["rows"].defaultRow()["cells"]["extension"]["value"], 'preset:fits', 'fits', persistent = False ) Gaffer.Metadata.registerValue( spreadsheet["rows"].defaultRow()["cells"]["extension"]["value"], 'preset:xisf', 'xisf', persistent = False ) Gaffer.Metadata.registerValue( spreadsheet["rows"].defaultRow()["cells"]["extension"]["value"], 'preset:tif', 'tif', persistent = False ) Gaffer.Metadata.registerValue( spreadsheet["rows"].defaultRow()["cells"]["extension"]["value"], 'presetsPlugValueWidget:allowCustom', True, persistent = False ) Gaffer.Metadata.registerValue( spreadsheet["rows"].defaultRow()["cells"]["extension"]["value"], 'plugValueWidget:type', 'GafferUI.PresetsPlugValueWidget', persistent = False ) self["__Variables"]["variables"]["extension"]["value"].setInput( spreadsheet["out"]["extension"] ) collectChannels["channels"].setInput( spreadsheet["activeRowNames"] ) variablesExpression = Gaffer.Expression() self["__variablesExpression"] = variablesExpression variablesExpression.setExpression( inspect.cleandoc( """ customToken = parent["__Spreadsheet"]["out"]["filenameToken"] channel = context["channel"] parent["__Variables"]["variables"]["token"]["value"] = customToken or channel """ .format( tokenIndex = tokenColumnIndex ) ), "python" ) promotedRowsPlug = Gaffer.PlugAlgo.promote( spreadsheet["rows"] ) Gaffer.Metadata.registerValue( promotedRowsPlug, "spreadsheet:columnsNeedSerialisation", False, persistent = False )
def testBadCachePolicyHang(self): # Using the legacy cache policy for OSLImage.shadingPlug creates a hang due to tbb task stealing, # though it's a bit hard to actually demonstrate constant = GafferImage.Constant() constant["format"].setValue(GafferImage.Format(128, 128, 1.000)) # Need a slow to compute OSL code in order to trigger hang mandelbrotCode = self.mandelbrotNode() # In order to trigger the hang, we need to mix threads which are stuck waiting for an expression which # uses the Standard policy with threads that are actually finishing, so that tbb tries to start up new # threads while we're waiting for the expression result. To do this, we use the "var" context variable # to create two versions of this OSLCode mandelbrotCode["varExpression"] = Gaffer.Expression() mandelbrotCode["varExpression"].setExpression( 'parent.parameters.iterations = 100000 + context( "var", 0 );', "OSL") oslImage = GafferOSL.OSLImage() oslImage["channels"].addChild( Gaffer.NameValuePlug( "", Gaffer.Color3fPlug( "value", defaultValue=imath.Color3f(1, 1, 1), flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, ), True, "channel", Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)) oslImage["in"].setInput(constant["out"]) oslImage["channels"]["channel"]["value"][0].setInput( mandelbrotCode["out"]["outFloat"]) oslImage["channels"]["channel"]["value"][1].setInput( mandelbrotCode["out"]["outFloat"]) oslImage["channels"]["channel"]["value"][2].setInput( mandelbrotCode["out"]["outFloat"]) # This imageStats is use to create non-blocking slow calculations imageStats = GafferImage.ImageStats() imageStats["in"].setInput(oslImage["out"]) imageStats["area"].setValue( imath.Box2i(imath.V2i(0, 0), imath.V2i(64, 64))) # This box does the non-blocking slow calculation, followed by a blocking slow calculation. # This ensures that tasks which do just the non-block calculation will start finishing while # the blocking slow calculation is still running, allowing tbb to try running more threads # on the blocking calcluation, realizing they can't run, and stealing tasks onto those threads # which can hit the Standard policy lock on the expression upstream and deadlock, unless the # OSLImage isolates its threads correctly expressionBox = Gaffer.Box() expressionBox.addChild( Gaffer.FloatVectorDataPlug("inChannelData", defaultValue=IECore.FloatVectorData( []))) expressionBox.addChild(Gaffer.FloatPlug("inStat")) expressionBox.addChild( Gaffer.FloatPlug("out", direction=Gaffer.Plug.Direction.Out)) expressionBox["inChannelData"].setInput(oslImage["out"]["channelData"]) expressionBox["inStat"].setInput(imageStats["average"]["r"]) expressionBox["contextVariables"] = Gaffer.ContextVariables() expressionBox["contextVariables"].setup( Gaffer.FloatVectorDataPlug("in", defaultValue=IECore.FloatVectorData( []))) expressionBox["contextVariables"]["variables"].addChild( Gaffer.NameValuePlug("image:tileOrigin", Gaffer.V2iPlug("value"), True, "member1")) expressionBox["contextVariables"]["variables"].addChild( Gaffer.NameValuePlug("image:channelName", Gaffer.StringPlug("value", defaultValue='R'), True, "member2")) expressionBox["contextVariables"]["variables"].addChild( Gaffer.NameValuePlug("var", Gaffer.IntPlug("value", defaultValue=1), True, "member3")) expressionBox["contextVariables"]["in"].setInput( expressionBox["inChannelData"]) expressionBox["expression"] = Gaffer.Expression() expressionBox["expression"].setExpression( inspect.cleandoc(""" d = parent["contextVariables"]["out"] parent["out"] = d[0] + parent["inStat"] """)) # Create a switch to mix which tasks perform the non-blocking or blocking calculation - we need a mixture # to trigger the hang switch = Gaffer.Switch() switch.setup(Gaffer.IntPlug( "in", defaultValue=0, )) switch["in"][0].setInput(expressionBox["out"]) switch["in"][1].setInput(imageStats["average"]["r"]) switch["switchExpression"] = Gaffer.Expression() switch["switchExpression"].setExpression( 'parent.index = ( stoi( context( "testContext", "0" ) ) % 10 ) > 5;', "OSL") # In order to evaluate this expression a bunch of times at once with different values of "testContext", # we set up a simple scene that can be evaluated with GafferSceneTest.traversScene. # In theory, we could use a simple function that used a parallel_for to evaluate switch["out"], but for # some reason we don't entirely understand, this does not trigger the hang import GafferSceneTest import GafferScene sphere = GafferScene.Sphere() pathFilter = GafferScene.PathFilter() pathFilter["paths"].setValue(IECore.StringVectorData(['/sphere'])) customAttributes = GafferScene.CustomAttributes() customAttributes["attributes"].addChild( Gaffer.NameValuePlug("foo", Gaffer.FloatPlug("value"), True, "member1")) customAttributes["attributes"]["member1"]["value"].setInput( switch["out"]) customAttributes["in"].setInput(sphere["out"]) customAttributes["filter"].setInput(pathFilter["out"]) collectScenes = GafferScene.CollectScenes() collectScenes["in"].setInput(customAttributes["out"]) collectScenes["rootNames"].setValue( IECore.StringVectorData([str(i) for i in range(1000)])) collectScenes["rootNameVariable"].setValue('testContext') # When OSLImage.shadingPlug is not correctly isolated, and grain size on ShadingEngine is smaller than the # image tile size, this fails about 50% of the time. Running it 5 times makes the failure pretty consistent. for i in range(5): Gaffer.ValuePlug.clearCache() Gaffer.ValuePlug.clearHashCache() GafferSceneTest.traverseScene(collectScenes["out"])
while time.time() < endtime: GafferUI.EventLoop.waitForIdle(1) mainWindow = GafferUI.ScriptWindow.acquire(script) viewer = mainWindow.getLayout().editors(GafferUI.Viewer)[0] graphEditor = mainWindow.getLayout().editors(GafferUI.GraphEditor)[0] nodeEditor = mainWindow.getLayout().editors(GafferUI.NodeEditor)[0] sceneInspector = mainWindow.getLayout().editors( GafferSceneUI.SceneInspector)[0] hierarchyView = mainWindow.getLayout().editors(GafferSceneUI.HierarchyView)[0] pythonEditor = mainWindow.getLayout().editors(GafferUI.PythonEditor)[0] # Concept: Reading a Context Variable textNode = GafferScene.Text() contextVariablesNode = Gaffer.ContextVariables() contextVariablesNode.setup(GafferScene.ScenePlug("in", )) contextVariablesNode["variables"].addChild( Gaffer.NameValuePlug( "", Gaffer.StringPlug( "value", defaultValue='', flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic, ), True, "member1", Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)) textNode["text"].setValue('${message}') contextVariablesNode["variables"]["member1"]["name"].setValue('message') contextVariablesNode["variables"]["member1"]["value"].setValue('received') contextVariablesNode["in"].setInput(textNode["out"]) script.addChild(textNode)
def createIntProcessor(): n = Gaffer.ContextVariables() n.setup(Gaffer.IntPlug()) return n