コード例 #1
0
	def __getConstant( self, R, G, B, A, Z, ZBack, dim = imath.V2i( 512 ) ) :

		c = GafferImage.Constant()
		c["format"].setValue( GafferImage.Format( imath.Box2i( imath.V2i( 0 ), dim ), 1 ) )
		c["color"].setValue( imath.Color4f( R, G, B, A ) )

		d = GafferImage.FlatToDeep()
		d["in"].setInput( c["out"] )
		d["depth"].setValue( Z )
		d["zBackMode"].setValue( GafferImage.FlatToDeep.ZBackMode.Thickness )
		d["thickness"].setValue( ZBack - Z )

		return (c,d)
コード例 #2
0
    def testOverall(self):

        constant = GafferImage.Constant()
        constant["color"].setValue(imath.Color4f(0.1, 0.2, 0.3, 0.5))

        shuffle = GafferImage.Shuffle()
        shuffle["in"].setInput(constant["out"])
        shuffle["channels"].addChild(shuffle.ChannelPlug("Z", "R"))
        shuffle["channels"].addChild(shuffle.ChannelPlug("ZBack", "G"))
        shuffle["enabled"].setValue(False)

        addDepth = GafferImage.FlatToDeep()
        addDepth["in"].setInput(shuffle["out"])
        addDepth["enabled"].setValue(False)

        self.assertEqual(addDepth["out"]["channelNames"].getValue(),
                         IECore.StringVectorData(["R", "G", "B", "A"]))

        addDepth["enabled"].setValue(True)
        self.assertEqual(addDepth["out"]["channelNames"].getValue(),
                         IECore.StringVectorData(["R", "G", "B", "A", "Z"]))
        addDepth["zBackMode"].setValue(
            GafferImage.FlatToDeep.ZBackMode.Thickness)
        self.assertEqual(
            addDepth["out"]["channelNames"].getValue(),
            IECore.StringVectorData(["R", "G", "B", "A", "Z", "ZBack"]))

        with Gaffer.Context() as c:
            c["image:tileOrigin"] = imath.V2i(0)

            c["image:channelName"] = "R"
            rHash = constant["out"]["channelData"].hash()

            c["image:channelName"] = "G"
            gHash = constant["out"]["channelData"].hash()

            # TEST Z CHANNEL
            c["image:channelName"] = "Z"

            tilePixels = GafferImage.ImagePlug.tileSize()**2

            initialZHash = addDepth["out"]["channelData"].hash()
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0] * tilePixels))

            addDepth["depth"].setValue(42.0)

            newZHash = addDepth["out"]["channelData"].hash()
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([42.0] * tilePixels))
            self.assertNotEqual(initialZHash, newZHash)

            addDepth["zMode"].setValue(GafferImage.FlatToDeep.ZMode.Channel)
            addDepth["zChannel"].setValue("R")
            self.assertEqual(addDepth["out"]["channelData"].hash(), rHash)
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0.1] * tilePixels))

            addDepth["zChannel"].setValue("G")
            self.assertEqual(addDepth["out"]["channelData"].hash(), gHash)
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0.2] * tilePixels))

            addDepth["zChannel"].setValue("Q")
            six.assertRaisesRegex(
                self, RuntimeError,
                'FlatToDeep : Cannot find requested Z channel - no channel "Q" found.',
                addDepth["out"]["channelData"].hash)
            six.assertRaisesRegex(
                self, RuntimeError,
                'FlatToDeep : Cannot find requested Z channel - no channel "Q" found.',
                addDepth["out"]["channelData"].getValue)

            addDepth["zChannel"].setValue("Z")
            shuffle["enabled"].setValue(True)
            self.assertEqual(shuffle["out"]["channelData"].hash(),
                             addDepth["out"]["channelData"].hash())
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0.1] * tilePixels))

            addDepth["zMode"].setValue(GafferImage.FlatToDeep.ZMode.Constant)
            addDepth["depth"].setValue(0.0)
            shuffle["enabled"].setValue(False)

            # TEST ZBack CHANNEL
            c["image:channelName"] = "ZBack"

            initialZBackHash = addDepth["out"]["channelData"].hash()
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0] * tilePixels))

            addDepth["depth"].setValue(42.0)

            newZBackHash = addDepth["out"]["channelData"].hash()
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([42.0] * tilePixels))
            self.assertNotEqual(initialZBackHash, newZBackHash)

            addDepth["thickness"].setValue(0.09)

            newerZBackHash = addDepth["out"]["channelData"].hash()
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([42.09] * tilePixels))
            self.assertNotEqual(newZBackHash, newerZBackHash)

            addDepth["zBackMode"].setValue(
                GafferImage.FlatToDeep.ZBackMode.Channel)
            addDepth["zBackChannel"].setValue("R")
            self.assertEqual(addDepth["out"]["channelData"].hash(), rHash)
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0.1] * tilePixels))

            addDepth["zBackChannel"].setValue("G")
            self.assertEqual(addDepth["out"]["channelData"].hash(), gHash)
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0.2] * tilePixels))

            addDepth["zBackChannel"].setValue("Q")
            six.assertRaisesRegex(
                self, RuntimeError,
                'FlatToDeep : Cannot find requested ZBack channel - no channel "Q" found.',
                addDepth["out"]["channelData"].hash)
            six.assertRaisesRegex(
                self, RuntimeError,
                'FlatToDeep : Cannot find requested ZBack channel - no channel "Q" found.',
                addDepth["out"]["channelData"].getValue)

            addDepth["zBackChannel"].setValue("ZBack")
            shuffle["enabled"].setValue(True)
            self.assertEqual(shuffle["out"]["channelData"].hash(),
                             addDepth["out"]["channelData"].hash())
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0.2] * tilePixels))

            addDepth["zBackMode"].setValue(
                GafferImage.FlatToDeep.ZBackMode.Thickness)

            self.assertEqual(newerZBackHash,
                             addDepth["out"]["channelData"].hash())
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([42.09] * tilePixels))

            addDepth["zMode"].setValue(GafferImage.FlatToDeep.ZMode.Channel)
            addDepth["zChannel"].setValue("Z")
            self.assertNotEqual(newerZBackHash,
                                addDepth["out"]["channelData"].hash())
            self.assertEqual(addDepth["out"]["channelData"].getValue(),
                             IECore.FloatVectorData([0.19] * tilePixels))
コード例 #3
0
    def testChannelRequest(self):

        ts = GafferImage.ImagePlug.tileSize()

        a = GafferImage.Constant()
        a["color"].setValue(imath.Color4f(0.1, 0.2, 0.3, 0.4))

        addDepthA = GafferImage.FlatToDeep()
        addDepthA["in"].setInput(a["out"])
        addDepthA["depth"].setValue(2.0)
        addDepthA["zBackMode"].setValue(
            GafferImage.FlatToDeep.ZBackMode.Thickness)
        addDepthA["thickness"].setValue(1.0)

        ad = GafferImage.DeleteChannels()
        ad["in"].setInput(addDepthA["out"])
        ad["mode"].setValue(GafferImage.DeleteChannels.Mode.Delete)
        ad["channels"].setValue(IECore.StringVectorData(["G", "Z", "ZBack"]))

        b = GafferImage.Constant()
        b["color"].setValue(imath.Color4f(0.5, 0.6, 0.7, 0.8))

        addDepthB = GafferImage.FlatToDeep()
        addDepthB["in"].setInput(b["out"])
        addDepthB["depth"].setValue(4.0)
        addDepthB["zBackMode"].setValue(
            GafferImage.FlatToDeep.ZBackMode.Thickness)
        addDepthB["thickness"].setValue(1.0)

        bd = GafferImage.DeleteChannels()
        bd["in"].setInput(addDepthB["out"])
        bd["mode"].setValue(GafferImage.DeleteChannels.Mode.Delete)
        bd["channels"].setValue(IECore.StringVectorData(["R", "A"]))

        merge = GafferImage.DeepMerge()
        merge["in"][0].setInput(ad["out"])
        merge["in"][1].setInput(bd["out"])

        ad["enabled"].setValue(False)
        bd["enabled"].setValue(False)

        expectedChannelData = {}
        expectedChannelData["R"] = IECore.FloatVectorData([0.1, 0.5] * ts * ts)
        expectedChannelData["G"] = IECore.FloatVectorData([0.2, 0.6] * ts * ts)
        expectedChannelData["B"] = IECore.FloatVectorData([0.3, 0.7] * ts * ts)
        expectedChannelData["A"] = IECore.FloatVectorData([0.4, 0.8] * ts * ts)
        expectedChannelData["Z"] = IECore.FloatVectorData([2.0, 4.0] * ts * ts)
        expectedChannelData["ZBack"] = IECore.FloatVectorData([3.0, 5.0] * ts *
                                                              ts)

        for channelName in expectedChannelData:
            actualChannelData = merge["out"].channelData(
                channelName, imath.V2i(0))
            self.assertEqual(actualChannelData,
                             expectedChannelData[channelName])

        ad["enabled"].setValue(True)
        bd["enabled"].setValue(True)

        expectedChannelData = {}
        expectedChannelData["R"] = IECore.FloatVectorData([0.1, 0.0] * ts * ts)
        expectedChannelData["G"] = IECore.FloatVectorData([0.0, 0.6] * ts * ts)
        expectedChannelData["B"] = IECore.FloatVectorData([0.3, 0.7] * ts * ts)
        expectedChannelData["A"] = IECore.FloatVectorData([0.4, 0.0] * ts * ts)
        expectedChannelData["Z"] = IECore.FloatVectorData([0.0, 4.0] * ts * ts)
        expectedChannelData["ZBack"] = IECore.FloatVectorData([0.0, 5.0] * ts *
                                                              ts)

        for channelName in expectedChannelData:
            actualChannelData = merge["out"].channelData(
                channelName, imath.V2i(0))
            self.assertEqual(actualChannelData,
                             expectedChannelData[channelName])
コード例 #4
0
    def __testMergedDifferentDataWindows(self, ensureOverlap=False):

        ts = GafferImage.ImagePlug.tileSize()
        tileCount = 2

        values1 = {
            "R": 0.25,
            "G": 0.5,
            "B": 1.0,
            "A": 0.5,
            "Z": 10.0,
            "ZBack": 12.0
        }
        values2 = {
            "R": 2.0,
            "G": 3.0,
            "B": 4.0,
            "A": 1.0,
            "Z": 20.0,
            "ZBack": 20.0
        }

        sourceFormat = GafferImage.Format(
            imath.Box2i(imath.V2i(0), imath.V2i(ts * tileCount)), 1)

        constant1 = GafferImage.Constant()
        constant1["format"].setValue(sourceFormat)
        constant1["color"].setValue(
            imath.Color4f(values1["R"], values1["G"], values1["B"],
                          values1["A"]))

        addDepth1 = GafferImage.FlatToDeep()
        addDepth1["in"].setInput(constant1["out"])
        addDepth1["depth"].setValue(values1["Z"])
        addDepth1["zBackMode"].setValue(
            GafferImage.FlatToDeep.ZBackMode.Thickness)
        addDepth1["thickness"].setValue(values1["ZBack"] - values1["Z"])

        constant2 = GafferImage.Constant()
        constant2["format"].setValue(sourceFormat)
        constant2["color"].setValue(
            imath.Color4f(values2["R"], values2["G"], values2["B"],
                          values2["A"]))

        addDepth2 = GafferImage.FlatToDeep()
        addDepth2["in"].setInput(constant2["out"])
        addDepth2["depth"].setValue(values2["Z"])
        addDepth2["zBackMode"].setValue(
            GafferImage.FlatToDeep.ZBackMode.Thickness)
        addDepth2["thickness"].setValue(values2["ZBack"] - values2["Z"])

        crop1 = GafferImage.Crop()
        crop1["in"].setInput(addDepth1["out"])
        crop1["affectDisplayWindow"].setValue(False)

        crop2 = GafferImage.Crop()
        crop2["in"].setInput(addDepth2["out"])
        crop2["affectDisplayWindow"].setValue(False)

        merge = GafferImage.DeepMerge()
        merge["in"][0].setInput(crop1["out"])
        merge["in"][1].setInput(crop2["out"])

        for i in range(10):
            crop1Area = imath.Box2i()
            crop1Area.extendBy(
                imath.V2i(int(random.uniform(0, sourceFormat.width())),
                          int(random.uniform(0, sourceFormat.height()))))
            crop1Area.extendBy(
                imath.V2i(int(random.uniform(0, sourceFormat.width())),
                          int(random.uniform(0, sourceFormat.height()))))

            crop2Area = imath.Box2i()
            crop2Area.extendBy(
                imath.V2i(int(random.uniform(0, sourceFormat.width())),
                          int(random.uniform(0, sourceFormat.height()))))
            crop2Area.extendBy(
                imath.V2i(int(random.uniform(0, sourceFormat.width())),
                          int(random.uniform(0, sourceFormat.height()))))

            # If we want to ensure that the two crop areas overlap, extend the second one to a random point
            # within the first one's area
            if ensureOverlap and not GafferImage.BufferAlgo.intersects(
                    crop1Area, crop2Area):
                crop2Area.extendBy(
                    imath.V2i(
                        int(
                            random.uniform(crop1Area.min().x,
                                           crop1Area.max().x)),
                        int(
                            random.uniform(crop1Area.min().y,
                                           crop1Area.max().y))))

            crop1["area"].setValue(crop1Area)
            crop2["area"].setValue(crop2Area)

            for tileX in range(tileCount):
                for tileY in range(tileCount):
                    tileOrigin = imath.V2i(tileX * ts, tileY * ts)

                    sampleOffsets = merge["out"].sampleOffsets(tileOrigin)

                    self.assertEqual(
                        sampleOffsets,
                        self.__getExpectedSampleOffsets(
                            tileOrigin, crop1Area, crop2Area))

                    for channelName in values1.keys():
                        channelData = merge["out"].channelData(
                            channelName, tileOrigin)

                        self.assertEqual(
                            channelData,
                            self.__getExpectedChannelData(
                                tileOrigin, crop1Area, values1[channelName],
                                crop2Area, values2[channelName]))
コード例 #5
0
    def testChannelData(self):

        ts = GafferImage.ImagePlug.tileSize()

        constant1 = GafferImage.Constant()
        constant1["format"].setValue(
            GafferImage.Format(imath.Box2i(imath.V2i(0), imath.V2i(512)), 1))
        constant1["color"].setValue(imath.Color4f(0.25, 0.5, 1.0, 0.5))

        addDepth1 = GafferImage.FlatToDeep()
        addDepth1["in"].setInput(constant1["out"])
        addDepth1["depth"].setValue(10.0)

        constant2 = GafferImage.Constant()
        constant2["format"].setValue(
            GafferImage.Format(imath.Box2i(imath.V2i(0), imath.V2i(512)), 1))
        constant2["color"].setValue(imath.Color4f(2.0, 3.0, 4.0, 1.0))

        addDepth2 = GafferImage.FlatToDeep()
        addDepth2["in"].setInput(constant2["out"])
        addDepth2["depth"].setValue(20.0)

        merge = GafferImage.DeepMerge()
        merge["in"][0].setInput(addDepth1["out"])
        merge["in"][1].setInput(addDepth2["out"])

        expectedChannelData = {}
        expectedChannelData["R"] = IECore.FloatVectorData([0.25, 2.0] * ts *
                                                          ts)
        expectedChannelData["G"] = IECore.FloatVectorData([0.5, 3.0] * ts * ts)
        expectedChannelData["B"] = IECore.FloatVectorData([1.0, 4.0] * ts * ts)
        expectedChannelData["A"] = IECore.FloatVectorData([0.5, 1.0] * ts * ts)
        expectedChannelData["Z"] = IECore.FloatVectorData([10.0, 20.0] * ts *
                                                          ts)

        for channelName in expectedChannelData:
            actualChannelData = merge["out"].channelData(
                channelName, imath.V2i(0))
            self.assertEqual(actualChannelData,
                             expectedChannelData[channelName])

        addDepth1["zBackMode"].setValue(
            GafferImage.FlatToDeep.ZBackMode.Thickness)
        addDepth1["thickness"].setValue(2.0)

        expectedChannelData["ZBack"] = IECore.FloatVectorData([12.0, 20.0] *
                                                              ts * ts)

        for channelName in expectedChannelData:
            actualChannelData = merge["out"].channelData(
                channelName, imath.V2i(0))
            self.assertEqual(actualChannelData,
                             expectedChannelData[channelName])

        addDepth2["zBackMode"].setValue(
            GafferImage.FlatToDeep.ZBackMode.Thickness)
        addDepth2["thickness"].setValue(0.1)

        expectedChannelData["ZBack"] = IECore.FloatVectorData([12.0, 20.1] *
                                                              ts * ts)

        for channelName in expectedChannelData:
            actualChannelData = merge["out"].channelData(
                channelName, imath.V2i(0))
            self.assertEqual(actualChannelData,
                             expectedChannelData[channelName])