def testChannelsPlug( self ) : main = self.__constantLayer( "", imath.Color4f( 1, 0.5, 0.25, 1 ) ) diffuse = self.__constantLayer( "diffuse", imath.Color4f( 0, 0.25, 0.5, 1 ) ) copy = GafferImage.CopyChannels() copy["in"][0].setInput( main["out"] ) copy["in"][1].setInput( diffuse["out"] ) copy["channels"].setValue( "diffuse.R" ) self.assertEqual( copy["out"]["channelNames"].getValue(), IECore.StringVectorData( [ "R", "G", "B", "A", "diffuse.R" ] ), ) copy["channels"].setValue( "diffuse.R diffuse.B" ) self.assertEqual( copy["out"]["channelNames"].getValue(), IECore.StringVectorData( [ "R", "G", "B", "A", "diffuse.R", "diffuse.B" ] ), ) copy["channels"].setValue( "diffuse.*" ) self.assertEqual( copy["out"]["channelNames"].getValue(), IECore.StringVectorData( [ "R", "G", "B", "A", "diffuse.R", "diffuse.G", "diffuse.B", "diffuse.A" ] ), )
def testCsParameterTrumpsColorAttribute(self): # if there is no Cs parameter value specified then we should get # Cs from the attribute state. g = IECoreScene.Group() g.addChild(self.mesh()) g.addState( IECoreScene.AttributeState({"color": imath.Color3f(1, 0, 0)})) g.addState(self.constantShader()) image = self.renderImage(g) self.assertImageValues(image, [(imath.V2f(0.5), imath.Color4f(1, 0, 0, 1))]) # but if there is a Cs parameter, it should override the colour # from the attribute state. g = IECoreScene.Group() g.addChild(self.mesh()) g.addState( IECoreScene.AttributeState({"color": imath.Color3f(1, 0, 0)})) s = self.constantShader() s.parameters["Cs"] = imath.Color3f(0, 1, 0) g.addState(s) image = self.renderImage(g) self.assertImageValues(image, [(imath.V2f(0.5), imath.Color4f(0, 1, 0, 1))])
def testLayer(self): c1 = GafferImage.Constant() c2 = GafferImage.Constant() c1["color"].setValue(imath.Color4f(1, 0.5, 0.25, 1)) c2["color"].setValue(imath.Color4f(1, 0.5, 0.25, 1)) c2["layer"].setValue("diffuse") self.assertEqual(c1["out"]["channelNames"].getValue(), IECore.StringVectorData(["R", "G", "B", "A"])) self.assertEqual( c2["out"]["channelNames"].getValue(), IECore.StringVectorData( ["diffuse.R", "diffuse.G", "diffuse.B", "diffuse.A"])) for channelName in ("R", "G", "B", "A"): self.assertEqual( c1["out"].channelDataHash(channelName, imath.V2i(0)), c2["out"].channelDataHash("diffuse." + channelName, imath.V2i(0))) self.assertEqual( c1["out"].channelData(channelName, imath.V2i(0)), c2["out"].channelData("diffuse." + channelName, imath.V2i(0)))
def testPerChannelHash(self): i = GafferImage.ImageReader() i["fileName"].setValue( os.path.expandvars( "$GAFFER_ROOT/python/GafferImageTest/images/colorbars_half_max.exr" )) clamp = GafferImage.Clamp() clamp["in"].setInput(i["out"]) clamp["max"].setValue(imath.Color4f(1., 1., 1., 1.)) redHash = clamp["out"].channelDataHash("R", imath.V2i(0)) greenHash = clamp["out"].channelDataHash("G", imath.V2i(0)) blueHash = clamp["out"].channelDataHash("B", imath.V2i(0)) clamp["max"].setValue(imath.Color4f(.25, 1., 1., 1.)) redHash2 = clamp["out"].channelDataHash("R", imath.V2i(0)) greenHash2 = clamp["out"].channelDataHash("G", imath.V2i(0)) blueHash2 = clamp["out"].channelDataHash("B", imath.V2i(0)) self.assertNotEqual(redHash, redHash2) self.assertEqual(greenHash, greenHash2) self.assertEqual(blueHash, blueHash2)
def testExtraColors(self): maya.cmds.file(os.path.dirname(__file__) + "/scenes/colouredPlane.ma", force=True, open=True) mesh = "pPlaneShape1" converter = IECoreMaya.FromMayaShapeConverter.create( mesh, IECoreScene.MeshPrimitive.staticTypeId()) converter['extraColors'] = True m = converter.convert() self.assertEqual(m['cAlpha_Cs'].data, IECore.FloatVectorData([0, 1, 0.8, 0.5])) self.assertEqual( m['cRGB_Cs'].data, IECore.Color3fVectorData([ imath.Color3f(1, 0, 0), imath.Color3f(0), imath.Color3f(0, 0, 1), imath.Color3f(0, 1, 0) ])) self.assertEqual( m['cRGBA_Cs'].data, IECore.Color4fVectorData([ imath.Color4f(1, 1, 0, 0.5), imath.Color4f(1, 1, 1, 1), imath.Color4f(0, 1, 1, 1), imath.Color4f(0, 1, 0, 0.5) ]))
def testMultipleLayers(self): main = GafferImage.Constant() main["color"].setValue(imath.Color4f(1, 0.5, 0.25, 1)) diffuse = GafferImage.Constant() diffuse["color"].setValue(imath.Color4f(0.25, 0.5, 0.75, 1)) diffuse["layer"].setValue("diffuse") m = GafferImage.CopyChannels() m["in"][0].setInput(main["out"]) m["in"][1].setInput(diffuse["out"]) m["channels"].setValue("*") cdl = GafferImage.CDL() cdl["in"].setInput(m["out"]) self.assertImagesEqual(cdl["out"], m["out"]) mainCDLSampler = GafferImage.ImageSampler() mainCDLSampler["image"].setInput(cdl["out"]) mainCDLSampler["pixel"].setValue(imath.V2f(0.5)) mainCDLSampler["channels"].setValue( IECore.StringVectorData(["R", "G", "B", "A"])) diffuseCDLSampler = GafferImage.ImageSampler() diffuseCDLSampler["image"].setInput(cdl["out"]) diffuseCDLSampler["pixel"].setValue(imath.V2f(0.5)) diffuseCDLSampler["channels"].setValue( IECore.StringVectorData(["diffuse." + x for x in "RGBA"])) self.assertEqual(mainCDLSampler["color"].getValue(), main["color"].getValue()) self.assertEqual(diffuseCDLSampler["color"].getValue(), diffuse["color"].getValue()) cdl["saturation"].setValue(0.5) self.assertNotEqual(mainCDLSampler["color"].getValue(), main["color"].getValue()) self.assertEqual(diffuseCDLSampler["color"].getValue(), diffuse["color"].getValue()) cdl["channels"].setValue("*[RGB]") self.assertNotEqual(mainCDLSampler["color"].getValue(), main["color"].getValue()) self.assertNotEqual(diffuseCDLSampler["color"].getValue(), diffuse["color"].getValue()) self.assertNotEqual(mainCDLSampler["color"].hash(), diffuseCDLSampler["color"].hash()) self.assertNotEqual(mainCDLSampler["color"].getValue(), diffuseCDLSampler["color"].getValue()) cdl["channels"].setValue("diffuse.[RGB]") self.assertEqual(mainCDLSampler["color"].getValue(), main["color"].getValue()) self.assertNotEqual(diffuseCDLSampler["color"].getValue(), diffuse["color"].getValue())
def testTileNotAvailableInContextExpressions(self): # We don't want expressions on the index to be sensitive # to the image:tileOrigin or image:channelName context entries, # because then an invalid image could result from splicing together # different images, even requesting tiles outside the data window. script = Gaffer.ScriptNode() script["switch"] = Gaffer.Switch() script["switch"].setup(GafferImage.ImagePlug()) script["in0"] = GafferImage.Constant() script["in0"]["color"].setValue(imath.Color4f(1, 1, 1, 1)) script["in1"] = GafferImage.Constant() script["in0"]["color"].setValue(imath.Color4f(0, 0, 0, 0)) script["switch"]["in"][0].setInput(script["in0"]["out"]) script["switch"]["in"][1].setInput(script["in1"]["out"]) script["expression"] = Gaffer.Expression() script["expression"].setExpression( inspect.cleandoc(""" assert( context.get( "image:channelName", None ) is None ) assert( context.get( "image:tileOrigin", None ) is None ) parent["switch"]["index"] = 1 """)) self.assertEqual( script["switch"]["out"].channelData("R", imath.V2i(0))[0], 0)
def testColor4fVectorDataPrimimitiveVariable(self): m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f(imath.V2f(-1), imath.V2f(1))) m["myColor"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.Color4fVectorData([ imath.Color4f(1, 0, 0, 1), imath.Color4f(0, 2, 0, 0), imath.Color4f(0, 0, 3, 0.25), imath.Color4f(4, 0, 0, 1), ])) with IECoreArnold.UniverseBlock(writable=True) as universe: n = IECoreArnold.NodeAlgo.convert(m, universe, "testMesh") a = arnold.AiNodeGetArray(n, "myColor") self.assertEqual(arnold.AiArrayGetType(a.contents), arnold.AI_TYPE_RGBA) self.assertEqual(arnold.AiArrayGetNumElements(a.contents), 4) self.assertEqual(arnold.AiArrayGetRGBA(a, 0), arnold.AtRGBA(1, 0, 0, 1)) self.assertEqual(arnold.AiArrayGetRGBA(a, 1), arnold.AtRGBA(0, 2, 0, 0)) self.assertEqual(arnold.AiArrayGetRGBA(a, 2), arnold.AtRGBA(0, 0, 3, 0.25)) self.assertEqual(arnold.AiArrayGetRGBA(a, 3), arnold.AtRGBA(4, 0, 0, 1))
def testShaderInputs(self): s = GafferArnold.ArnoldShader() s.loadShader("physical_sky") s["parameters"]["intensity"].setValue(2) # Test setting up a matte closure connected to "shader" # Note that this doesn't currently render correctly, but SolidAngle assures me that they are fixing # it and is the preferred way s2 = GafferArnold.ArnoldShader() s2.loadShader("matte") s2["parameters"]["color"].setValue(imath.Color4f(0, 1, 0, 0.5)) l = GafferArnold.ArnoldLight() l.loadShader("skydome_light") l["parameters"]["color"].setInput(s["out"]) l["parameters"]["shader"].setInput(s2["out"]) network = l["out"].attributes("/light")["ai:light"] self.assertEqual(len(network), 3) self.assertEqual(network[0].name, "physical_sky") self.assertEqual(network[0].parameters["intensity"].value, 2) self.assertEqual(network[1].name, "matte") self.assertEqual(network[1].parameters["color"].value, imath.Color4f(0, 1, 0, 0.5)) self.assertEqual(network[2].parameters["color"].value, "link:" + network[0].parameters["__handle"].value) self.assertEqual(network[2].parameters["shader"].value, "link:" + network[1].parameters["__handle"].value) s["parameters"]["intensity"].setValue(4) network = l["out"].attributes("/light")["ai:light"] self.assertEqual(network[0].parameters["intensity"].value, 4)
def testEdits(self): r = IECoreGL.Renderer() r.setOption("gl:mode", IECore.StringData("deferred")) r.worldBegin() r.worldEnd() with IECore.CapturingMessageHandler() as handler: r.attributeBegin() r.setAttribute("gl:color", IECore.Color4fData(imath.Color4f(1, 2, 3, 4))) r.attributeEnd() self.assertEqual(len(handler.messages), 3) with IECore.CapturingMessageHandler() as handler: r.command("editBegin", {}) r.attributeBegin() r.setAttribute("gl:color", IECore.Color4fData(imath.Color4f(1, 2, 3, 4))) r.attributeEnd() r.command("editEnd", {}) self.assertEqual(len(handler.messages), 0)
def test( self ) : s = GafferScene.OpenGLShader() s.loadShader( "Texture" ) self.assertEqual( len( s["parameters"] ), 3 ) self.assertTrue( isinstance( s["parameters"]["mult"], Gaffer.FloatPlug ) ) self.assertTrue( isinstance( s["parameters"]["tint"], Gaffer.Color4fPlug ) ) self.assertTrue( isinstance( s["parameters"]["texture"], GafferImage.ImagePlug ) ) s["parameters"]["mult"].setValue( 0.5 ) s["parameters"]["tint"].setValue( imath.Color4f( 1, 0.5, 0.25, 1 ) ) i = GafferImage.ImageReader() i["fileName"].setValue( os.path.expandvars( "$GAFFER_ROOT/python/GafferImageTest/images/checker.exr" ) ) s["parameters"]["texture"].setInput( i["out"] ) a = s.attributes() self.assertEqual( a.keys(), [ "gl:surface"] ) self.failUnless( isinstance( a["gl:surface"].outputShader(), IECoreScene.Shader ) ) self.assertEqual( a["gl:surface"].outputShader().name, "Texture" ) self.assertEqual( a["gl:surface"].outputShader().type, "gl:surface" ) self.assertEqual( a["gl:surface"].outputShader().parameters["mult"], IECore.FloatData( 0.5 ) ) self.assertEqual( a["gl:surface"].outputShader().parameters["tint"].value, imath.Color4f( 1, 0.5, 0.25, 1 ) ) self.assertTrue( isinstance( a["gl:surface"].outputShader().parameters["texture"], IECore.CompoundData ) ) self.failUnless( "displayWindow" in a["gl:surface"].outputShader().parameters["texture"] ) self.failUnless( "dataWindow" in a["gl:surface"].outputShader().parameters["texture"] ) self.failUnless( "channels" in a["gl:surface"].outputShader().parameters["texture"] )
def testTimeContext(self): script = Gaffer.ScriptNode() script["constant"] = GafferImage.Constant() script["constant"]["format"].setValue(GafferImage.Format(1, 1, 1.0)) script["e"] = Gaffer.Expression() script["e"].setExpression( 'parent["constant"]["color"] = imath.Color4f( context["frame"] )') script["timeWarp"] = Gaffer.TimeWarp() script["timeWarp"].setup(GafferImage.ImagePlug()) script["timeWarp"]["in"].setInput(script["constant"]["out"]) script["timeWarp"]["speed"].setValue(0) script["timeWarp"]["offset"].setValue(3) script["sampler"] = GafferImage.ImageSampler() script["sampler"]["pixel"].setValue(imath.V2f(0.5, 0.5)) script["sampler"]["image"].setInput(script["timeWarp"]["out"]) self.assertEqual(script["sampler"]["color"].getValue(), imath.Color4f(3)) script["e2"] = Gaffer.Expression() script["e2"].setExpression( inspect.cleandoc(""" assert( context.get( "image:channelName", None ) is None ) assert( context.get( "image:tileOrigin", None ) is None ) parent["timeWarp"]["offset"] = 5 """)) self.assertEqual(script["sampler"]["color"].getValue(), imath.Color4f(5))
def testCompoundNumericTypes( self ) : p = IECore.Parameterised( "" ) p.parameters().addParameters( [ IECore.V2iParameter( "v2i", "", imath.V2i( 1, 2 ) ), IECore.V3fParameter( "v3f", "", imath.V3f( 1, 2, 3 ) ), IECore.Color4fParameter( "color4f", "", imath.Color4f( 0.25, 0.5, 0.75, 1 ) ), ] ) ph = GafferCortex.ParameterisedHolderNode() ph.setParameterised( p ) self.assertEqual( ph["parameters"]["v2i"].defaultValue(), imath.V2i( 1, 2 ) ) self.assertEqual( ph["parameters"]["v3f"].defaultValue(), imath.V3f( 1, 2, 3 ) ) self.assertEqual( ph["parameters"]["color4f"].defaultValue(), imath.Color4f( 0.25, 0.5, 0.75, 1 ) ) self.assertEqual( ph["parameters"]["v2i"].getValue(), imath.V2i( 1, 2 ) ) self.assertEqual( ph["parameters"]["v3f"].getValue(), imath.V3f( 1, 2, 3 ) ) self.assertEqual( ph["parameters"]["color4f"].getValue(), imath.Color4f( 0.25, 0.5, 0.75, 1 ) ) ph["parameters"]["v2i"].setValue( imath.V2i( 2, 3 ) ) ph["parameters"]["v3f"].setValue( imath.V3f( 4, 5, 6 ) ) ph["parameters"]["color4f"].setValue( imath.Color4f( 0.1, 0.2, 0.3, 0.5 ) ) ph.setParameterisedValues() self.assertEqual( p["v2i"].getTypedValue(), imath.V2i( 2, 3 ) ) self.assertEqual( p["v3f"].getTypedValue(), imath.V3f( 4, 5, 6 ) ) self.assertEqual( p["color4f"].getTypedValue(), imath.Color4f( 0.1, 0.2, 0.3, 0.5 ) )
def testMismatchedDataWindow( self ) : # Set up a situation where we're copying channels # from an image with a smaller data window than the # primary input. main = self.__constantLayer( "", imath.Color4f( 1 ), size = imath.V2i( 64 ) ) diffuse = self.__constantLayer( "diffuse", imath.Color4f( 0.5 ), size = imath.V2i( 60 ) ) copy = GafferImage.CopyChannels() copy["in"][0].setInput( main["out"] ) copy["in"][1].setInput( diffuse["out"] ) copy["channels"].setValue( "*" ) # Format should be taken from the primary input, and data window should be the union # of both input data windows. self.assertEqual( copy["out"]["format"].getValue(), main["out"]["format"].getValue() ) self.assertEqual( copy["out"]["dataWindow"].getValue(), main["out"]["dataWindow"].getValue() ) # And CopyChannels must take care to properly fill in with # black any missing areas from the second input. for channel in ( "R", "G", "B", "A" ) : diffuseDW = diffuse["out"]["dataWindow"].getValue() copyDW = copy["out"]["dataWindow"].getValue() sampler = GafferImage.Sampler( copy["out"], "diffuse." + channel, copyDW ) for x in range( copyDW.min().x, copyDW.max().x ) : for y in range( copyDW.min().y, copyDW.max().y ) : if GafferImage.BufferAlgo.contains( diffuseDW, imath.V2i( x, y ) ) : self.assertEqual( sampler.sample( x, y ), 0.5 ) else : self.assertEqual( sampler.sample( x, y ), 0 )
def testConvertArbGeomParams(self): a = IECoreScene.SceneInterface.create( os.path.dirname(__file__) + "/data/coloredMesh.abc", IECore.IndexedIO.OpenMode.Read) m = a.child("pPlane1").readObjectAtSample(0) self.failUnless(m.arePrimitiveVariablesValid()) self.failUnless("colorSet1" in m) self.assertEqual( m["colorSet1"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.FaceVarying) self.failUnless( isinstance(m["colorSet1"].data, IECore.Color4fVectorData)) self.assertEqual(len(m["colorSet1"].data), 4) self.assertEqual( m["colorSet1"].expandedData(), IECore.Color4fVectorData([ imath.Color4f(1, 0, 0, 1), imath.Color4f(0, 0, 0, 1), imath.Color4f(0, 0, 1, 1), imath.Color4f(0, 1, 0, 1), ])) self.failUnless("ABC_int" in m) self.assertEqual(m["ABC_int"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Constant) self.assertEqual(m["ABC_int"].data, IECore.IntVectorData([10]))
def testUniform3iParameters(self): c1 = IECoreScene.Group() c1.addChild(self.mesh()) c1.addState(self.colorShader()) c2 = c1.copy() c1.state()[0].parameters["rgbI"] = IECore.V3iData(imath.V3i(0, 1, 1)) c2.state()[0].parameters["rgbI"] = IECore.V3iData(imath.V3i(1, 1, 0)) c1.setTransform( IECoreScene.MatrixTransform(imath.M44f().translate( imath.V3f(0.2, 0, 0)))) c2.setTransform( IECoreScene.MatrixTransform(imath.M44f().translate( imath.V3f(-0.2, 0, 0)))) g = IECoreScene.Group() g.addChild(c1) g.addChild(c2) image = self.renderImage(g) self.assertImageValues(image, [ (imath.V2f(0.7, 0.5), imath.Color4f(0, 1, 1, 1)), (imath.V2f(0.3, 0.5), imath.Color4f(1, 1, 0, 1)), ])
def test(self): xRamp = GafferImage.Ramp() xRamp["format"].setValue(GafferImage.Format(75, 75, 1.000)) xRamp["endPosition"].setValue(imath.V2f(75, 0)) xRamp["ramp"]["p1"]["y"].setValue(imath.Color4f(75, 0, 0, 0)) yRamp = GafferImage.Ramp() yRamp["format"].setValue(GafferImage.Format(75, 75, 1.000)) yRamp["endPosition"].setValue(imath.V2f(0, 75)) yRamp["ramp"]["p1"]["y"].setValue(imath.Color4f(0, 75, 0, 0)) rampMerge = GafferImage.Merge() rampMerge["operation"].setValue(GafferImage.Merge.Operation.Add) rampMerge["in"]["in0"].setInput(xRamp["out"]) rampMerge["in"]["in1"].setInput(yRamp["out"]) sampler = GafferImage.ImageSampler() sampler["image"].setInput(rampMerge["out"]) hashes = set() for x in range(0, 75): for y in range(0, 75): sampler["pixel"].setValue(imath.V2f(x + 0.5, y + 0.5)) c = sampler["color"].getValue() for i in range(4): self.assertAlmostEqual(c[i], [x + 0.5, y + 0.5, 0, 0][i], places=4) hashes.add(str(sampler["color"].hash())) self.assertEqual(len(hashes), 75 * 75)
def testConstantPrimVarTemporarilyOverridesShaderParameter(self): c1 = IECoreScene.Group() c1.addChild(self.mesh()) c1.addState(self.colorShader()) c2 = c1.copy() c1.state()[0].parameters["rgbF"] = IECore.V3iData(imath.V3i(0, 1, 1)) c1.children()[0]["rgbF"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.V3fData(imath.V3f(1, 1, 0))) c1.setTransform( IECoreScene.MatrixTransform(imath.M44f().translate( imath.V3f(0.2, 0, 0)))) c2.setTransform( IECoreScene.MatrixTransform(imath.M44f().translate( imath.V3f(-0.2, 0, 0)))) g = IECoreScene.Group() g.addChild(c1) g.addChild(c2) image = self.renderImage(g) self.assertImageValues(image, [ (imath.V2f(0.7, 0.5), imath.Color4f(1, 1, 0, 1)), (imath.V2f(0.3, 0.5), imath.Color4f(0, 0, 0, 1)), ])
def testSwitching(self): in0 = GafferImage.Constant() in0["format"].setValue(GafferImage.Format(100, 100, 1.0)) in0["color"].setValue(imath.Color4f(1, 0, 0, 1)) in1 = GafferImage.Constant() in1["format"].setValue(GafferImage.Format(100, 100, 1.0)) in0["color"].setValue(imath.Color4f(0, 1, 0, 1)) switch = Gaffer.Switch() switch.setup(GafferImage.ImagePlug()) switch["in"][0].setInput(in0["out"]) switch["in"][1].setInput(in1["out"]) self.assertImageHashesEqual(switch["out"], in0["out"]) self.assertImagesEqual(switch["out"], in0["out"]) switch["index"].setValue(1) self.assertImageHashesEqual(switch["out"], in1["out"]) self.assertImagesEqual(switch["out"], in1["out"]) switch["enabled"].setValue(False) self.assertImageHashesEqual(switch["out"], in0["out"]) self.assertImagesEqual(switch["out"], in0["out"])
def testSplineAsTexture(self): c1 = IECoreScene.Group() c1.addChild(self.mesh()) c1.addState(self.textureShader()) c2 = c1.copy() c1.state()[0].parameters["sampler"] = self.splineGradient( imath.Color3f(1, 0, 0), imath.Color3f(1, 0, 0)) c1.setTransform( IECoreScene.MatrixTransform(imath.M44f().translate( imath.V3f(0.2, 0, 0)))) c2.setTransform( IECoreScene.MatrixTransform(imath.M44f().translate( imath.V3f(-0.2, 0, 0)))) g = IECoreScene.Group() g.addChild(c1) g.addChild(c2) image = self.renderImage(g) self.assertImageValues(image, [ (imath.V2f(0.7, 0.5), imath.Color4f(1, 0, 0, 1)), (imath.V2f(0.3, 0.5), imath.Color4f(0, 0, 0, 1)), ])
def testCatalogueName(self): c1 = GafferImage.Catalogue() c2 = GafferImage.Catalogue() c2["name"].setValue("catalogue2") self.assertEqual(len(c1["images"]), 0) self.assertEqual(len(c2["images"]), 0) constant1 = GafferImage.Constant() constant2 = GafferImage.Constant() constant1["format"].setValue(GafferImage.Format(100, 100)) constant2["format"].setValue(GafferImage.Format(100, 100)) constant1["color"].setValue(imath.Color4f(1, 0, 0, 1)) constant2["color"].setValue(imath.Color4f(0, 1, 0, 1)) self.sendImage( constant1["out"], c1, ) self.sendImage(constant2["out"], c2, extraParameters={ "catalogue:name": "catalogue2", }) self.assertEqual(len(c1["images"]), 1) self.assertEqual(len(c2["images"]), 1) self.assertImagesEqual(c1["out"], constant1["out"]) self.assertImagesEqual(c2["out"], constant2["out"])
def testSameMeshTwoShaders(self): c1 = IECoreScene.Group() c1.addChild(self.mesh()) c1.addState(self.colorShader()) c1.state()[0].parameters["rgbF"] = IECore.V3fData(imath.V3f(0, 1, 1)) c2 = IECoreScene.Group() c2.addChild(self.mesh()) c2.addState(self.textureShader()) c2.state()[0].parameters["sampler"] = IECore.StringData( os.path.dirname(__file__) + "/images/yellow.exr") c1.setTransform( IECoreScene.MatrixTransform(imath.M44f().translate( imath.V3f(0.2, 0, 0)))) c2.setTransform( IECoreScene.MatrixTransform(imath.M44f().translate( imath.V3f(-0.2, 0, 0)))) g = IECoreScene.Group() g.addChild(c1) g.addChild(c2) image = self.renderImage(g) self.assertImageValues(image, [ (imath.V2f(0.7, 0.5), imath.Color4f(0, 1, 1, 1)), (imath.V2f(0.3, 0.5), imath.Color4f(1, 1, 0, 1)), ])
def testLoadDifferentShader(self): mix = GafferArnold.ArnoldShader() mix.loadShader("mix") switch = GafferArnold.ArnoldShader() switch.loadShader("switch_rgba") shader = GafferArnold.ArnoldShader() shader.loadShader("switch_rgba") def assertParametersEqual(s1, s2, ignore=[]): self.assertEqual(set(s1["parameters"].keys()), set(s2["parameters"].keys())) for k in s1["parameters"].keys(): if k in ignore: continue self.assertEqual(s1["parameters"][k].getValue(), s2["parameters"][k].getValue()) assertParametersEqual(shader, switch) shader["parameters"]["input1"].setValue(imath.Color4f(0.25)) shader.loadShader("mix", keepExistingValues=True) assertParametersEqual(shader, mix, ignore=["input1"]) self.assertEqual(shader["parameters"]["input1"].getValue(), imath.Color4f(0.25)) shader.loadShader("switch_rgba", keepExistingValues=False) assertParametersEqual(shader, switch)
def testChannelRequest(self): a = GafferImage.Constant() a["color"].setValue(imath.Color4f(0.1, 0.2, 0.3, 0.4)) ad = GafferImage.DeleteChannels() ad["in"].setInput(a["out"]) ad["mode"].setValue(GafferImage.DeleteChannels.Mode.Delete) ad["channels"].setValue("R") b = GafferImage.Constant() b["color"].setValue(imath.Color4f(1.0, 0.3, 0.1, 0.2)) bd = GafferImage.DeleteChannels() bd["in"].setInput(b["out"]) bd["mode"].setValue(GafferImage.DeleteChannels.Mode.Delete) bd["channels"].setValue("G") merge = GafferImage.Merge() merge["in"][0].setInput(ad["out"]) merge["in"][1].setInput(bd["out"]) merge["operation"].setValue(GafferImage.Merge.Operation.Add) sampler = GafferImage.ImageSampler() sampler["image"].setInput(merge["out"]) sampler["pixel"].setValue(imath.V2f(10)) self.assertAlmostEqual(sampler["color"]["r"].getValue(), 0.0 + 1.0) self.assertAlmostEqual(sampler["color"]["g"].getValue(), 0.2 + 0.0) self.assertAlmostEqual(sampler["color"]["b"].getValue(), 0.3 + 0.1) self.assertAlmostEqual(sampler["color"]["a"].getValue(), 0.4 + 0.2)
def testDefaultChannelMultipartRead(self): # This test multipart file contains a "rgb" subimage with R, G, B channels, an "RGBA" subimage # with an A channel, and a "depth" subimage with a Z channel. # The standard would expect this to be loaded with channel names like "RGBA.A" and "depth.Z", # but in practice, applications expect these default layers to be loaded as the standard layer # names, so we conform to this pratical expection, and just name the channels R, G, B, A, and Z # The test file was created with this command # > oiiotool --create 4x4 3 --addc 0.1,0.2,0.3 --attrib "oiio:subimagename" rgb -create 4x4 1 --chnames A --addc 0.4 --attrib "oiio:subimagename" RGBA -create 4x4 1 --chnames Z --addc 4.2 --attrib "oiio:subimagename" depth --siappendall -o multipartDefaultChannels.exr multipartReader = GafferImage.OpenImageIOReader() multipartReader["fileName"].setValue( self.multipartDefaultChannelsFileName) self.assertEqual( set(multipartReader["out"]["channelNames"].getValue()), set(["R", "G", "B", "A", "Z"])) sampler = GafferImage.ImageSampler() sampler["image"].setInput(multipartReader["out"]) sampler["pixel"].setValue(imath.V2f(2)) self.assertEqual(sampler["color"].getValue(), imath.Color4f(0.1, 0.2, 0.3, 0.4)) sampler['channels'].setValue( IECore.StringVectorData(["Z", "Z", "Z", "Z"])) self.assertEqual(sampler["color"].getValue(), imath.Color4f(4.2)) # Similar sort of image, but this time is ambiguous because subimages "rgb" and "RGBA" both # define channels RGB. This should trigger a warning, and take RGB from the first subimage, # but A from the second subimage, because it is only found there. # The test file was created with this command: # > oiiotool --create 4x4 3 --addc 0.1,0.2,0.3 --attrib "oiio:subimagename" rgb -create 4x4 4 --addc 0.4,0.5,0.6,0.7 --attrib "oiio:subimagename" RGBA --siappendall -o multipartDefaultChannelsOverlap.exr multipartReader["fileName"].setValue( self.multipartDefaultChannelsOverlapFileName) with IECore.CapturingMessageHandler() as mh: self.assertEqual( set(multipartReader["out"]["channelNames"].getValue()), set(["R", "G", "B", "A"])) self.assertEqual(len(mh.messages), 3) self.assertTrue(mh.messages[0].message.startswith( 'Ignoring channel "R" in subimage "1"')) self.assertTrue(mh.messages[1].message.startswith( 'Ignoring channel "G" in subimage "1"')) self.assertTrue(mh.messages[2].message.startswith( 'Ignoring channel "B" in subimage "1"')) for i in range(3): self.assertTrue( mh.messages[i].message.endswith('already in subimage "0".')) sampler['channels'].setToDefault() self.assertEqual(sampler["color"].getValue(), imath.Color4f(0.1, 0.2, 0.3, 0.7))
def testDeepWithFlatMask(self): # Set up a mask maskReader = GafferImage.ImageReader() maskReader["fileName"].setValue(self.radialPath) maskText = GafferImage.Text() maskText["in"].setInput(maskReader["out"]) maskText["area"].setValue( imath.Box2i(imath.V2i(0, 0), imath.V2i(256, 256))) maskText["text"].setValue('Test\nTest\nTest\nTest') maskOffset = GafferImage.Offset() maskOffset["in"].setInput(maskText["out"]) representativeDeepImage = GafferImage.ImageReader() representativeDeepImage["fileName"].setValue( self.representativeDeepImagePath) deepGradeBlack = GafferImage.Grade() deepGradeBlack["in"].setInput(representativeDeepImage["out"]) deepGradeBlack["multiply"].setValue(imath.Color4f(0, 0, 0, 1)) deepMix = GafferImage.Mix() deepMix["in"]["in0"].setInput(representativeDeepImage["out"]) deepMix["in"]["in1"].setInput(deepGradeBlack["out"]) deepMix["mask"].setInput(maskOffset["out"]) deepMix["maskChannel"].setValue('R') postFlatten = GafferImage.DeepToFlat() postFlatten["in"].setInput(deepMix["out"]) preFlatten = GafferImage.DeepToFlat() preFlatten["in"].setInput(representativeDeepImage["out"]) flatGradeBlack = GafferImage.Grade() flatGradeBlack["in"].setInput(preFlatten["out"]) flatGradeBlack["multiply"].setValue(imath.Color4f(0, 0, 0, 1)) flatMix = GafferImage.Mix() flatMix["in"]["in0"].setInput(preFlatten["out"]) flatMix["in"]["in1"].setInput(flatGradeBlack["out"]) flatMix["mask"].setInput(maskOffset["out"]) flatMix["maskChannel"].setValue('R') for o in [ imath.V2i(0, 0), imath.V2i(-3, -8), imath.V2i(-7, -79), imath.V2i(12, 8) ]: maskOffset["offset"].setValue(o) self.assertImagesEqual(postFlatten["out"], flatMix["out"], maxDifference=0.000003)
def testSerialisationWithZeroAlpha( self ) : s = Gaffer.ScriptNode() s["c"] = GafferImage.Constant() s["c"]["color"].setValue( imath.Color4f( 0, 1, 0, 0 ) ) s2 = Gaffer.ScriptNode() s2.execute( s.serialise() ) self.assertEqual( s2["c"]["color"].getValue(), imath.Color4f( 0, 1, 0, 0 ) )
def testRepeatedChannels(self): c = GafferImage.Constant() s = GafferImage.ImageStats() s["in"].setInput(c["out"]) s["area"].setValue(c["out"]["format"].getValue().getDisplayWindow()) s["channels"].setValue(IECore.StringVectorData(["A", "A", "A", "A"])) self.assertEqual(s["min"].getValue(), imath.Color4f(1)) self.assertEqual(s["max"].getValue(), imath.Color4f(1))
def testUnpremultiplied(self): i = GafferImage.ImageReader() i["fileName"].setValue(self.checkerFile) shuffleAlpha = GafferImage.Shuffle() shuffleAlpha["channels"].addChild( GafferImage.Shuffle.ChannelPlug("channel")) shuffleAlpha["in"].setInput(i["out"]) shuffleAlpha["channels"]["channel"]["out"].setValue('A') shuffleAlpha["channels"]["channel"]["in"].setValue('R') gradeAlpha = GafferImage.Grade() gradeAlpha["in"].setInput(shuffleAlpha["out"]) gradeAlpha["channels"].setValue('[RGBA]') gradeAlpha["offset"].setValue(imath.Color4f(0, 0, 0, 0.1)) unpremultipliedGrade = GafferImage.Grade() unpremultipliedGrade["in"].setInput(gradeAlpha["out"]) unpremultipliedGrade["processUnpremultiplied"].setValue(True) unpremultipliedGrade["gamma"].setValue(imath.Color4f(2, 2, 2, 1.0)) unpremultiply = GafferImage.Unpremultiply() unpremultiply["in"].setInput(gradeAlpha["out"]) bareGrade = GafferImage.Grade() bareGrade["in"].setInput(unpremultiply["out"]) bareGrade["gamma"].setValue(imath.Color4f(2, 2, 2, 1.0)) premultiply = GafferImage.Premultiply() premultiply["in"].setInput(bareGrade["out"]) # Assert that with a non-zero alpha, processUnpremultiplied is identical to: # unpremult, grade, and premult self.assertImagesEqual(unpremultipliedGrade["out"], premultiply["out"]) # Assert that grading alpha to 0 inside the grade still premults at the end correctly unpremultipliedGrade["channels"].setValue('[RGBA]') unpremultipliedGrade["multiply"].setValue(imath.Color4f(1, 1, 1, 0)) zeroGrade = GafferImage.Grade() zeroGrade["channels"].setValue('[RGBA]') zeroGrade["in"].setInput(gradeAlpha["out"]) zeroGrade["multiply"].setValue(imath.Color4f(0, 0, 0, 0)) self.assertImagesEqual(unpremultipliedGrade["out"], zeroGrade["out"]) unpremultipliedGrade["multiply"].setValue(imath.Color4f(1, 1, 1, 1)) # Assert that when input alpha is zero, processUnpremultiplied doesn't affect the result gradeAlpha["multiply"].setValue(imath.Color4f(1, 1, 1, 0.0)) gradeAlpha["offset"].setValue(imath.Color4f(0, 0, 0, 0.0)) defaultGrade = GafferImage.Grade() defaultGrade["in"].setInput(gradeAlpha["out"]) defaultGrade["gamma"].setValue(imath.Color4f(2, 2, 2, 1.0)) self.assertImagesEqual(unpremultipliedGrade["out"], defaultGrade["out"])
def test( self ) : i = GafferImage.Constant() i["color"].setValue( imath.Color4f( 1, 0, 0, 1 ) ) ref = GafferImage.Constant() sat = GafferImage.Saturation() sat["in"].setInput(i["out"]) # Test default passthrough self.assertEqual( sat["out"].channelDataHash( "R", imath.V2i( 0 ) ), i["out"].channelDataHash( "R", imath.V2i( 0 ) ) ) self.assertImagesEqual( sat["out"], i["out"] ) # Test fully desaturating each channel sat["saturation"].setValue( 0 ) self.assertNotEqual( sat["out"].channelDataHash( "R", imath.V2i( 0 ) ), i["out"].channelDataHash( "R", imath.V2i( 0 ) ) ) ref["color"].setValue( imath.Color4f( 0.2126, 0.2126, 0.2126, 1 ) ) self.assertImagesEqual( sat["out"], ref["out"] ) i["color"].setValue( imath.Color4f( 0, 1, 0, 1 ) ) ref["color"].setValue( imath.Color4f( 0.7152, 0.7152, 0.7152, 1 ) ) self.assertImagesEqual( sat["out"], ref["out"] ) i["color"].setValue( imath.Color4f( 0, 0, 1, 1 ) ) ref["color"].setValue( imath.Color4f( 0.0722, 0.0722, 0.0722, 1 ) ) self.assertImagesEqual( sat["out"], ref["out"] ) # Test increasing/decreasing saturation i["color"].setValue( imath.Color4f( 0.6, 0.5, 0.5, 1 ) ) ref["color"].setValue( imath.Color4f( 0.52126, 0.52126, 0.52126, 1 ) ) self.assertImagesEqual( sat["out"], ref["out"] ) sat["saturation"].setValue( 2 ) ref["color"].setValue( imath.Color4f( 0.67874, 0.47874, 0.47874, 1 ) ) self.assertImagesEqual( sat["out"], ref["out"], maxDifference = 1e-7 )