예제 #1
0
    def __testTransferImage(self, fileName):

        imageReader = GafferImage.ImageReader()
        imageReader["fileName"].setValue(os.path.expandvars(fileName))

        imagesReceived = GafferTest.CapturingSlot(
            GafferImage.Display.imageReceivedSignal())

        node = GafferImage.Display()
        server = IECoreImage.DisplayDriverServer()
        driverCreatedConnection = GafferImage.Display.driverCreatedSignal(
        ).connect(lambda driver, parameters: node.setDriver(driver))

        self.assertEqual(len(imagesReceived), 0)

        self.Driver.sendImage(imageReader["out"], port=server.portNumber())

        self.assertImagesEqual(imageReader["out"],
                               node["out"],
                               ignoreMetadata=True)

        self.assertEqual(len(imagesReceived), 1)
        self.assertEqual(imagesReceived[0][0], node["out"])

        return node
예제 #2
0
    def testVectorAndPointDisplays(self):

        server = IECoreImage.DisplayDriverServer(1559)
        time.sleep(2)

        subprocess.check_call([
            "kick", "-v", "0", "-dw", "-dp",
            os.path.join(os.path.dirname(__file__), "assFiles",
                         "vectorAndPointDisplays.ass")
        ])

        image = IECoreImage.ImageDisplayDriver.removeStoredImage(
            "vectorAndPointImage")
        channelNames = image.keys()

        self.assertEqual(len(channelNames), 10)
        self.assertTrue("R" in channelNames)
        self.assertTrue("G" in channelNames)
        self.assertTrue("B" in channelNames)
        self.assertTrue("A" in channelNames)
        self.assertTrue("P.R" in channelNames)
        self.assertTrue("P.G" in channelNames)
        self.assertTrue("P.B" in channelNames)
        self.assertTrue("N.R" in channelNames)
        self.assertTrue("N.G" in channelNames)
        self.assertTrue("N.B" in channelNames)
예제 #3
0
    def testPortNumber(self):

        s1 = IECoreImage.DisplayDriverServer(1559)
        self.assertEqual(s1.portNumber(), 1559)

        self.assertRaises(RuntimeError, IECoreImage.DisplayDriverServer, 1559)

        s2 = IECoreImage.DisplayDriverServer(0)
        self.assertNotEqual(s2.portNumber(), 0)
        self.assertNotEqual(s2.portNumber(), s1.portNumber())

        s3 = IECoreImage.DisplayDriverServer(0)
        self.assertNotEqual(s3.portNumber(), 0)
        self.assertNotEqual(s3.portNumber(), s2.portNumber())

        s4 = IECoreImage.DisplayDriverServer()
        self.assertNotEqual(s4.portNumber(), 0)
        self.assertNotEqual(s4.portNumber(), s3.portNumber())
예제 #4
0
    def testSetDriver(self):

        driversCreated = GafferTest.CapturingSlot(
            GafferImage.Display.driverCreatedSignal())

        server = IECoreImage.DisplayDriverServer()
        dataWindow = IECore.Box2i(IECore.V2i(0), IECore.V2i(100))

        driver = self.Driver(GafferImage.Format(dataWindow),
                             dataWindow, ["Y"],
                             port=server.portNumber())

        self.assertTrue(len(driversCreated), 1)

        display = GafferImage.Display()
        self.assertTrue(display.getDriver() is None)

        display.setDriver(driversCreated[0][0])
        self.assertTrue(display.getDriver().isSame(driversCreated[0][0]))

        driver.sendBucket(dataWindow, [
            IECore.FloatVectorData(
                [0.5] * dataWindow.size().x * dataWindow.size().y)
        ])

        self.assertEqual(
            display["out"]["format"].getValue().getDisplayWindow(), dataWindow)
        self.assertEqual(display["out"]["dataWindow"].getValue(), dataWindow)
        self.assertEqual(display["out"]["channelNames"].getValue(),
                         IECore.StringVectorData(["Y"]))
        self.assertEqual(
            display["out"].channelData("Y", IECore.V2i(0)),
            IECore.FloatVectorData([0.5] * GafferImage.ImagePlug.tileSize() *
                                   GafferImage.ImagePlug.tileSize()))

        display2 = GafferImage.Display()
        display2.setDriver(display.getDriver(), copy=True)

        self.assertImagesEqual(display["out"], display2["out"])

        driver.sendBucket(dataWindow, [
            IECore.FloatVectorData(
                [1] * dataWindow.size().x * dataWindow.size().y)
        ])

        self.assertEqual(
            display["out"].channelData("Y", IECore.V2i(0)),
            IECore.FloatVectorData([1] * GafferImage.ImagePlug.tileSize() *
                                   GafferImage.ImagePlug.tileSize()))

        self.assertEqual(
            display2["out"].channelData("Y", IECore.V2i(0)),
            IECore.FloatVectorData([0.5] * GafferImage.ImagePlug.tileSize() *
                                   GafferImage.ImagePlug.tileSize()))

        driver.close()
예제 #5
0
    def testPortRange(self):

        IECoreImage.DisplayDriverServer.setPortRange((45000, 45010))
        self.assertEqual(IECoreImage.DisplayDriverServer.getPortRange(),
                         (45000, 45010))

        s1 = IECoreImage.DisplayDriverServer()
        self.assertEqual(s1.portNumber(), 45000)

        s2 = IECoreImage.DisplayDriverServer()
        self.assertEqual(s2.portNumber(), 45001)

        # deleting servers should free the ports for reuse
        del s1, s2

        servers = []
        for p in range(45000, 45011):
            servers.append(IECoreImage.DisplayDriverServer(0))
            self.assertEqual(servers[-1].portNumber(), p)

        # make one more than the range allows
        six.assertRaisesRegex(self, RuntimeError,
                              ".*Unable to find a free port in the range.*",
                              IECoreImage.DisplayDriverServer, 0)

        # can't resuse ports
        errorMessage = ".*Unable to connect to port 45010.*Only one usage of each socket address.*is normally permitted" if (
            sys.platform == "win32") else (
                ".*Unable to connect to port 45010.*Address already in use.*")
        six.assertRaisesRegex(self, RuntimeError, errorMessage,
                              IECoreImage.DisplayDriverServer, 45010)

        # bad range
        six.assertRaisesRegex(self, RuntimeError, ".*portNumber must fall.*",
                              IECoreImage.DisplayDriverServer, 44999)
        six.assertRaisesRegex(self, RuntimeError, ".*portNumber must fall.*",
                              IECoreImage.DisplayDriverServer, 45011)
        six.assertRaisesRegex(self, RuntimeError,
                              ".*min port must be <= max port.*",
                              IECoreImage.DisplayDriverServer.setPortRange,
                              (45010, 45000))
예제 #6
0
	def setUp( self ):

		gc.collect()
		IECore.RefCounted.collectGarbage()
		# make sure we don't have symbols from previous tests
		self.assertEqual( IECore.RefCounted.numWrappedInstances(), 0 )

		# this is necessary so python will allow threads created by the display driver server
		# to enter into python when those threads execute procedurals.
		IECore.initThreads()

		self.server = IECoreImage.DisplayDriverServer( 1559 )
		time.sleep(2)
예제 #7
0
    def testPortRangeRegistry(self):

        IECoreImage.DisplayDriverServer.registerPortRange("a", (45000, 45010))
        self.assertEqual(
            IECoreImage.DisplayDriverServer.registeredPortRange("a"),
            (45000, 45010))

        IECoreImage.DisplayDriverServer.registerPortRange("b", (45011, 45020))
        self.assertEqual(
            IECoreImage.DisplayDriverServer.registeredPortRange("b"),
            (45011, 45020))
        six.assertRaisesRegex(
            self, RuntimeError, ".*is already registered.*",
            IECoreImage.DisplayDriverServer.registerPortRange, "b",
            (45021, 45030))

        IECoreImage.DisplayDriverServer.deregisterPortRange("b")
        six.assertRaisesRegex(
            self, RuntimeError, ".*is not registered.*",
            IECoreImage.DisplayDriverServer.deregisterPortRange, "b")
        six.assertRaisesRegex(
            self, RuntimeError, ".*is not registered.*",
            IECoreImage.DisplayDriverServer.registeredPortRange, "b")

        IECoreImage.DisplayDriverServer.registerPortRange("b", (45021, 45030))
        self.assertEqual(
            IECoreImage.DisplayDriverServer.registeredPortRange("b"),
            (45021, 45030))

        IECoreImage.DisplayDriverServer.setPortRange(
            IECoreImage.DisplayDriverServer.registeredPortRange("a"))
        s1 = IECoreImage.DisplayDriverServer()
        self.assertEqual(s1.portNumber(), 45000)

        IECoreImage.DisplayDriverServer.setPortRange(
            IECoreImage.DisplayDriverServer.registeredPortRange("b"))
        s2 = IECoreImage.DisplayDriverServer()
        self.assertEqual(s2.portNumber(), 45021)
예제 #8
0
    def testTileHashes(self):

        node = GafferImage.Display()
        server = IECoreImage.DisplayDriverServer()
        driverCreatedConnection = GafferImage.Display.driverCreatedSignal(
        ).connect(lambda driver, parameters: node.setDriver(driver))

        dataWindow = imath.Box2i(imath.V2i(-100, -200), imath.V2i(303, 557))
        driver = self.Driver(
            GafferImage.Format(dataWindow),
            dataWindow,
            ["Y"],
            port=server.portNumber(),
        )

        for i in range(0, 100):

            h1 = self.__tileHashes(node, "Y")
            t1 = self.__tiles(node, "Y")

            bucketWindow = imath.Box2i()
            while GafferImage.BufferAlgo.empty(bucketWindow):
                bucketWindow.extendBy(
                    imath.V2i(
                        int(
                            random.uniform(dataWindow.min().x,
                                           dataWindow.max().x)),
                        int(
                            random.uniform(dataWindow.min().y,
                                           dataWindow.max().y)),
                    ))

            numPixels = (bucketWindow.size().x + 1) * (bucketWindow.size().y +
                                                       1)
            bucketData = IECore.FloatVectorData()
            bucketData.resize(numPixels, i + 1)

            driver.sendBucket(bucketWindow, [bucketData])

            h2 = self.__tileHashes(node, "Y")
            t2 = self.__tiles(node, "Y")

            self.__assertTilesChangedInRegion(t1, t2, bucketWindow)
            self.__assertTilesChangedInRegion(h1, h2, bucketWindow)

        driver.close()
예제 #9
0
	def testMergedDisplays( self ) :

		server = IECoreImage.DisplayDriverServer( 1559 )
		time.sleep( 2 )

		os.system( "kick -v 0 -dw -dp contrib/IECoreArnold/test/IECoreArnold/data/assFiles/mergedDisplays.ass" )

		image = IECoreImage.ImageDisplayDriver.removeStoredImage( "mergedImage" )
		channelNames = image.keys()

		self.assertEqual( len( channelNames ), 7 )
		self.failUnless( "R" in channelNames )
		self.failUnless( "G" in channelNames )
		self.failUnless( "B" in channelNames )
		self.failUnless( "A" in channelNames )
		self.failUnless( "direct_diffuse.R" in channelNames )
		self.failUnless( "direct_diffuse.G" in channelNames )
		self.failUnless( "direct_diffuse.B" in channelNames )
예제 #10
0
	def testVectorAndPointDisplays( self ) :

		server = IECoreImage.DisplayDriverServer( 1559 )
		time.sleep( 2 )

		os.system( "kick -v 0 -dw -dp contrib/IECoreArnold/test/IECoreArnold/data/assFiles/vectorAndPointDisplays.ass" )

		image = IECoreImage.ImageDisplayDriver.removeStoredImage( "vectorAndPointImage" )
		channelNames = image.keys()

		self.assertEqual( len( channelNames ), 10 )
		self.failUnless( "R" in channelNames )
		self.failUnless( "G" in channelNames )
		self.failUnless( "B" in channelNames )
		self.failUnless( "A" in channelNames )
		self.failUnless( "P.R" in channelNames )
		self.failUnless( "P.G" in channelNames )
		self.failUnless( "P.B" in channelNames )
		self.failUnless( "N.R" in channelNames )
		self.failUnless( "N.G" in channelNames )
		self.failUnless( "N.B" in channelNames )
예제 #11
0
    def testMergedDisplays(self):

        server = IECoreImage.DisplayDriverServer(1559)
        time.sleep(2)

        subprocess.check_call([
            "kick", "-v", "0", "-dw", "-dp",
            os.path.join(os.path.dirname(__file__), "assFiles",
                         "mergedDisplays.ass")
        ])

        image = IECoreImage.ImageDisplayDriver.removeStoredImage("mergedImage")
        channelNames = image.keys()

        self.assertEqual(len(channelNames), 7)
        self.assertTrue("R" in channelNames)
        self.assertTrue("G" in channelNames)
        self.assertTrue("B" in channelNames)
        self.assertTrue("A" in channelNames)
        self.assertTrue("direct_diffuse.R" in channelNames)
        self.assertTrue("direct_diffuse.G" in channelNames)
        self.assertTrue("direct_diffuse.B" in channelNames)
예제 #12
0
	def testUsedPortException( self ):

		self.assertRaises( RuntimeError, lambda : IECoreImage.DisplayDriverServer( 1559 ) )
예제 #13
0
    def testSetDriver(self):

        driversCreated = GafferTest.CapturingSlot(
            GafferImage.Display.driverCreatedSignal())

        server = IECoreImage.DisplayDriverServer()
        dataWindow = imath.Box2i(imath.V2i(0),
                                 imath.V2i(GafferImage.ImagePlug.tileSize()))

        driver = self.Driver(GafferImage.Format(dataWindow),
                             dataWindow, ["Y"],
                             port=server.portNumber())

        try:

            self.assertTrue(len(driversCreated), 1)

            display = GafferImage.Display()
            self.assertTrue(display.getDriver() is None)

            dirtiedPlugs = GafferTest.CapturingSlot(
                display.plugDirtiedSignal())

            display.setDriver(driversCreated[0][0])
            self.assertTrue(display.getDriver().isSame(driversCreated[0][0]))

            # Ensure all the output plugs have been dirtied
            expectedDirty = {"__driverCount", "__channelDataCount",
                             "out"}.union({
                                 c.getName()
                                 for c in display["out"].children()
                             })
            self.assertEqual(expectedDirty,
                             set(e[0].getName() for e in dirtiedPlugs))

            del dirtiedPlugs[:]

            driver.sendBucket(dataWindow, [
                IECore.FloatVectorData(
                    [0.5] * dataWindow.size().x * dataWindow.size().y)
            ])

            self.assertEqual(
                display["out"]["format"].getValue().getDisplayWindow(),
                dataWindow)
            self.assertEqual(display["out"]["dataWindow"].getValue(),
                             dataWindow)
            self.assertEqual(display["out"]["channelNames"].getValue(),
                             IECore.StringVectorData(["Y"]))
            self.assertEqual(
                display["out"].channelData("Y", imath.V2i(0)),
                IECore.FloatVectorData([0.5] *
                                       GafferImage.ImagePlug.tileSize() *
                                       GafferImage.ImagePlug.tileSize()))

            # Ensure only channel data has been dirtied
            expectedDirty = {"channelData", "__channelDataCount", "out"}
            self.assertEqual(set(e[0].getName() for e in dirtiedPlugs),
                             expectedDirty)

            display2 = GafferImage.Display()
            display2.setDriver(display.getDriver(), copy=True)

            self.assertImagesEqual(display["out"], display2["out"])

            driver.sendBucket(dataWindow, [
                IECore.FloatVectorData(
                    [1] * dataWindow.size().x * dataWindow.size().y)
            ])

            self.assertEqual(
                display["out"].channelData("Y", imath.V2i(0)),
                IECore.FloatVectorData([1] * GafferImage.ImagePlug.tileSize() *
                                       GafferImage.ImagePlug.tileSize()))

            self.assertEqual(
                display2["out"].channelData("Y", imath.V2i(0)),
                IECore.FloatVectorData([0.5] *
                                       GafferImage.ImagePlug.tileSize() *
                                       GafferImage.ImagePlug.tileSize()))
        finally:
            driver.close()