예제 #1
0
    def testMultMethods(self):

        v = imath.M33f().translate(imath.V2f(1, 2)).multVecMatrix(imath.V2f(0))
        self.assertEqual(v, imath.V2f(1, 2))

        v = imath.M33f().translate(imath.V2f(1, 2)).multDirMatrix(imath.V2f(1))
        self.assertEqual(v, imath.V2f(1))
예제 #2
0
    def testIndexing(self):
        """Test M33f indexing via [] operator"""

        m = imath.M33f()

        # test __setitem__
        m[0][0] = 10.0
        m[0][1] = 11.0
        m[0][2] = 12.0
        m[1][0] = 13.0
        m[1][1] = 14.0
        m[1][2] = 15.0
        m[2][0] = 16.0
        m[2][1] = 17.0
        m[2][2] = 18.0

        # test __getitem__
        self.assertEqual(m[0][0], 10.0)
        self.assertEqual(m[0][1], 11.0)
        self.assertEqual(m[0][2], 12.0)
        self.assertEqual(m[1][0], 13.0)
        self.assertEqual(m[1][1], 14.0)
        self.assertEqual(m[1][2], 15.0)
        self.assertEqual(m[2][0], 16.0)
        self.assertEqual(m[2][1], 17.0)
        self.assertEqual(m[2][2], 18.0)

        self.assertEqual(
            m, imath.M33f(10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0,
                          18.0))
예제 #3
0
    def testConstructors(self):
        """Test M33f constructors"""
        m = imath.M33f()

        m = imath.M33f(2)

        m = imath.M33f(1, 0, 0, 0, 1, 0, 0, 0, 1)

        m = imath.M33f(1, 0, 0, 0, 1, 0, 0, 0, 1)
예제 #4
0
    def testConstructFromOtherType(self):

        md = imath.M33d(1, 2, 3, 4, 5, 6, 7, 8, 9)
        mf = imath.M33f(1, 2, 3, 4, 5, 6, 7, 8, 9)

        mf2 = imath.M33f(md)
        self.assertEqual(mf2, mf)

        md2 = imath.M33d(mf)
        self.assertEqual(md2, md)
예제 #5
0
    def testConstructors(self):
        """Test Eulerf constructors"""

        #
        e = imath.Eulerf()
        self.assertEqual(e.x, 0)
        self.assertEqual(e.y, 0)
        self.assertEqual(e.z, 0)

        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        #
        ecopy = imath.Eulerf(e)
        self.assertEqual(ecopy.x, 0)
        self.assertEqual(ecopy.y, 0)
        self.assertEqual(ecopy.z, 0)

        self.assertEqual(ecopy.order(), imath.Eulerf.Order.XYZ)

        #
        e = imath.Eulerf(imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)

        #
        e = imath.Eulerf(imath.V3f(0, 0, 0))
        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        e = imath.Eulerf(imath.V3f(0, 0, 0), imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)

        #
        e = imath.Eulerf(0, 0, 0)
        e = imath.Eulerf(imath.V3f(0, 0, 0))
        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        e = imath.Eulerf(0, 0, 0, imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)

        #
        e = imath.Eulerf(imath.M33f())
        e = imath.Eulerf(imath.V3f(0, 0, 0))
        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        e = imath.Eulerf(imath.M33f(), imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)

        #
        e = imath.Eulerf(imath.M44f())
        e = imath.Eulerf(imath.V3f(0, 0, 0))
        self.assertEqual(e.order(), imath.Eulerf.Order.XYZ)

        e = imath.Eulerf(imath.M44f(), imath.Eulerf.Order.ZYX)
        self.assertEqual(e.order(), imath.Eulerf.Order.ZYX)
예제 #6
0
    def testOutTransform(self):

        t1 = GafferImage.ImageTransform()
        t2 = GafferImage.ImageTransform()

        t1["transform"]["scale"]["x"].setValue(.5)
        t2["transform"]["scale"]["x"].setValue(2)

        self.assertNotEqual(t2["__outTransform"].getValue(), imath.M33f())

        t2["in"].setInput(t1["out"])

        self.assertEqual(t2["__outTransform"].getValue(), imath.M33f())
예제 #7
0
    def testMatrixParameters(self):

        c1 = IECoreScene.Group()
        c1.addChild(self.mesh())
        c1.addState(self.matrixShader())

        c2 = c1.copy()
        c3 = c1.copy()
        c4 = c1.copy()
        c1.state()[0].parameters["m3"] = IECore.M33fData(
            imath.M33f(*[i * 0.1 for i in range(9)]))
        c2.state()[0].parameters["m4"] = IECore.M44fData(
            imath.M44f(*[i * 0.01 for i in range(16)]))
        c3.state()[0].parameters["m3v"] = IECore.M33fVectorData([
            imath.M33f(*[0, 0, 0, i * 0.01, i * 0.02, i * 0.03, 0, 0, 0])
            for i in range(8)
        ])
        c4.state()[0].parameters["m4v"] = IECore.M44fVectorData([
            imath.M44f(*[
                0, 0, 0, 0, i * 0.005, i * 0.01, i *
                0.02, 0, 0, 0, 0, 0, 0, 0, 0, 0
            ]) for i in range(8)
        ])

        c1.setTransform(
            IECoreScene.MatrixTransform(imath.M44f().translate(
                imath.V3f(-0.2, 0.2, 0))))
        c2.setTransform(
            IECoreScene.MatrixTransform(imath.M44f().translate(
                imath.V3f(0.2, 0.2, 0))))
        c3.setTransform(
            IECoreScene.MatrixTransform(imath.M44f().translate(
                imath.V3f(-0.2, -0.2, 0))))
        c4.setTransform(
            IECoreScene.MatrixTransform(imath.M44f().translate(
                imath.V3f(0.2, -0.2, 0))))

        g = IECoreScene.Group()
        g.addChild(c1)
        g.addChild(c2)
        g.addChild(c3)
        g.addChild(c4)

        image = self.renderImage(g)

        self.assertImageValues(image, [
            (imath.V2f(0.3, 0.3), imath.Color4f(0.6, 0.7, 0.8, 1)),
            (imath.V2f(0.7, 0.3), imath.Color4f(0.20, 0.22, 0.24, 1)),
            (imath.V2f(0.3, 0.7), imath.Color4f(0.28, 0.56, 0.84, 1)),
            (imath.V2f(0.7, 0.7), imath.Color4f(0.14, 0.28, 0.56, 1)),
        ])
예제 #8
0
    def testValueTypes(self):

        for v in [
                IECore.FloatVectorData([1, 2, 3]),
                IECore.IntVectorData([1, 2, 3]),
                IECore.StringVectorData(["1", "2", "3"]),
                IECore.V3fVectorData([imath.V3f(x) for x in range(1, 5)]),
                IECore.Color3fVectorData(
                    [imath.Color3f(x) for x in range(1, 5)]),
                IECore.M44fVectorData([imath.M44f() * x for x in range(1, 5)]),
                IECore.M33fVectorData([imath.M33f() * x for x in range(1, 5)]),
                IECore.V2iVectorData([imath.V2i(x) for x in range(1, 5)]),
                IECore.V3fData(imath.V3f(1, 2, 3)),
                IECore.V2fData(imath.V2f(1, 2)),
                IECore.M44fData(imath.M44f(*range(16))),
                IECore.Box2fData(imath.Box2f(imath.V2f(0, 1), imath.V2f(1,
                                                                        2))),
                IECore.Box2iData(
                    imath.Box2i(imath.V2i(-1, 10), imath.V2i(11, 20))),
                IECore.Box3fData(
                    imath.Box3f(imath.V3f(0, 1, 2), imath.V3f(3, 4, 5))),
                IECore.Box3iData(
                    imath.Box3i(imath.V3i(0, 1, 2), imath.V3i(3, 4, 5))),
                IECore.InternedStringVectorData(["a", "b"])
        ]:
            if 'value' in dir(v):
                expected = v.value
            else:
                expected = v
            self.assertEqual(
                expected,
                Gaffer.NameValuePlug("test", v)["value"].getValue())
예제 #9
0
	def testTransformOrderExplicit( self ) :

		plug = Gaffer.Transform2DPlug()

		displayWindow = imath.Box2i( imath.V2i(0), imath.V2i(9) )
		pixelAspect = 1.

		t =	imath.V2f( 100, 0 )
		r =	90
		s =	imath.V2f( 2, 2 )
		p = imath.V2f( 10, -10 )
		plug["translate"].setValue(  t )
		plug["rotate"].setValue( r )
		plug["scale"].setValue( s )
		plug["pivot"].setValue( p )

		# Test if this is equal to a simple hardcoded matrix, down to floating point error
		# This verifies that translation is not being affected by rotation and scale,
		# which is what users will expect
		self.assertTrue( plug.matrix().equalWithAbsError(
			imath.M33f(
				0,   2, 0,
				-2,  0, 0,
				90, -30, 1),
			2e-6
		) )
예제 #10
0
        def __test(fileName, size, filter):

            inputFileName = os.path.dirname(__file__) + "/images/" + fileName

            reader = GafferImage.ImageReader()
            reader["fileName"].setValue(inputFileName)

            inSize = reader["out"]["format"].getValue().getDisplayWindow(
            ).size()
            inSize = imath.V2f(inSize.x, inSize.y)

            deleteChannels = GafferImage.DeleteChannels()
            deleteChannels["mode"].setValue(1)
            deleteChannels["channels"].setValue(IECore.StringVectorData(['R']))
            deleteChannels["in"].setInput(reader["out"])

            scale = imath.V2f(size.x, size.y) / inSize

            resample = GafferImage.Resample()
            resample["in"].setInput(deleteChannels["out"])
            resample["matrix"].setValue(imath.M33f().scale(scale))
            resample["filter"].setValue(filter)
            resample["boundingMode"].setValue(
                GafferImage.Sampler.BoundingMode.Clamp)

            crop = GafferImage.Crop()
            crop["in"].setInput(resample["out"])
            crop["area"].setValue(imath.Box2i(imath.V2i(0), size))

            borderForFilterWidth = 60
            sampleRegion = reader["out"]["dataWindow"].getValue()
            sampleRegion.setMin(sampleRegion.min() -
                                imath.V2i(borderForFilterWidth))
            sampleRegion.setMax(sampleRegion.max() +
                                imath.V2i(borderForFilterWidth))

            s = GafferImage.Sampler(reader["out"], "R", sampleRegion,
                                    GafferImage.Sampler.BoundingMode.Clamp)
            resampledS = GafferImage.Sampler(
                resample["out"], "R", resample["out"]["dataWindow"].getValue())

            for y in range(size.y):
                for x in range(size.x):
                    resampled = resampledS.sample(x, y)
                    self.assertAlmostEqual(
                        resampled,
                        GafferImage.FilterAlgo.sampleBox(
                            s,
                            imath.V2f(x + 0.5, y + 0.5) / scale,
                            max(1.0 / scale[0], 1.0), max(1.0 / scale[1], 1.0),
                            filter),
                        places=5)
                    self.assertAlmostEqual(
                        resampled,
                        GafferImage.FilterAlgo.sampleParallelogram(
                            s,
                            imath.V2f(x + 0.5, y + 0.5) / scale,
                            imath.V2f(1.0 / scale[0], 0),
                            imath.V2f(0, 1.0 / scale[1]), filter),
                        places=5)
예제 #11
0
    def testMultiplication(self):
        vectorTypes = [
            IECore.V3fVectorData(
                [imath.V3f(1), imath.V3f(2),
                 imath.V3f(3)], IECore.GeometricData.Interpretation.Vector),
            IECore.V3dVectorData(
                [imath.V3d(1), imath.V3d(2),
                 imath.V3d(3)], IECore.GeometricData.Interpretation.Vector),
        ]
        matrixTypes = [
            IECore.M33fData(imath.M33f() * 3),
            IECore.M33dData(imath.M33d() * 3),
            IECore.M44fData(imath.M44f().scale(imath.V3f(3))),
            IECore.M44dData(imath.M44d().scale(imath.V3d(3))),
            IECore.TransformationMatrixfData(
                IECore.TransformationMatrixf(imath.V3f(3), imath.Eulerf(),
                                             imath.V3f(0))),
            IECore.TransformationMatrixdData(
                IECore.TransformationMatrixd(imath.V3d(3), imath.Eulerd(),
                                             imath.V3d(0))),
        ]
        for vector in vectorTypes:

            targetVector = vector.copy()
            for i in range(len(targetVector)):
                targetVector[i] = targetVector[i] * 3

            for matrix in matrixTypes:
                res = IECore.MatrixMultiplyOp()(object=vector.copy(),
                                                matrix=matrix)
                if res == targetVector:
                    continue
                raise Exception("Error testing vector " + str(type(vector)) +
                                " against matrix " + str(type(matrix)) +
                                ". Resulted " + str(res))
예제 #12
0
    def testConstructors(self):
        """Test M44f constructors"""
        m = imath.M44f(1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0.,
                       0., 1.)

        m3 = imath.M33f(1., 0., 0., 0., 1., 0., 0., 0., 1.)

        t = imath.V3f(5., 5., 5.)

        m = imath.M44f(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
예제 #13
0
    def testDeterminant(self):

        m = imath.M33f()
        self.assertAlmostEqual(m.determinant(), 1, 10)
        m.scale(imath.V2f(-1, 1))
        self.assertAlmostEqual(m.determinant(), -1, 10)
        m.scale(imath.V2f(1, -1))
        self.assertAlmostEqual(m.determinant(), 1, 10)
        m.scale(imath.V2f(3, -1))
        self.assertAlmostEqual(m.determinant(), -3, 10)
        m.scale(imath.V2f(3, 3))
        self.assertAlmostEqual(m.determinant(), -27, 10)
예제 #14
0
    def testMatrix(self):

        p = Gaffer.Transform2DPlug()

        p["pivot"].setValue(imath.V2f(1, 1))
        p["translate"].setValue(imath.V2f(1, 2))
        p["rotate"].setValue(45)
        p["scale"].setValue(imath.V2f(2, 3))

        pivotValue = p["pivot"].getValue()
        pivot = imath.M33f().translate(pivotValue)

        translateValue = p["translate"].getValue()
        translate = imath.M33f().translate(translateValue)

        rotate = imath.M33f().rotate(
            IECore.degreesToRadians(p["rotate"].getValue()))
        scale = imath.M33f().scale(p["scale"].getValue())
        invPivot = imath.M33f().translate(pivotValue * imath.V2f(-1.))

        transforms = {
            "p": pivot,
            "t": translate,
            "r": rotate,
            "s": scale,
            "pi": invPivot,
        }

        transform = imath.M33f()
        for m in ("pi", "s", "r", "t", "p"):
            transform = transform * transforms[m]

        self.assertEqual(p.matrix(), transform)
예제 #15
0
    def testDataWindow(self):

        c = GafferImage.Constant()
        c["format"].setValue(GafferImage.Format(100, 100))
        c["color"].setValue(imath.Color4f(1))

        r = GafferImage.Resample()
        r["in"].setInput(c["out"])
        r["matrix"].setValue(imath.M33f().translate(imath.V2f(
            10.5, 11.5)).scale(imath.V2f(0.1)))

        self.assertEqual(r["out"]["dataWindow"].getValue(),
                         imath.Box2i(imath.V2i(10, 11), imath.V2i(21, 22)))
예제 #16
0
    def testExtract(self):
        """Test Eulerf extract"""

        e = imath.Eulerf()
        e.extract(imath.M33f())

        e.extract(imath.M44f())

        e.extract(imath.Quatf())

        m = e.toMatrix33()
        m = e.toMatrix44()
        q = e.toQuat()
        v = e.toXYZVector()
예제 #17
0
    def testSincUpsize(self):

        c = GafferImage.Constant()
        c["format"].setValue(GafferImage.Format(100, 100))
        c["color"].setValue(imath.Color4f(1))

        r = GafferImage.Resample()
        r["matrix"].setValue(imath.M33f().scale(imath.V2f(4)))
        r["boundingMode"].setValue(GafferImage.Sampler.BoundingMode.Clamp)
        r["filter"].setValue("sinc")
        r["in"].setInput(c["out"])

        i = r["out"].image()
        self.assertEqual(i["R"], IECore.FloatVectorData([1.0] * 400 * 400))
예제 #18
0
	def testInvalidConversions( self ) :
		tests = [
			( IECore.FloatVectorData( [ 1, 2, 3 ] ), int(IECore.TypeId.V2fData) ),
			( imath.M33f(), int( IECore.TypeId.M44fData ) ),
			( IECore.FloatVectorData( [ 1, 2, 3, 4 ] ), int(IECore.TypeId.V3fData) ),
			( IECore.FloatVectorData( [ 1, 2 ] ), int(IECore.TypeId.V3fData) ),
			( IECore.FloatVectorData( [ 1, 2, 3, 4 ] ), int(IECore.TypeId.V3fVectorData) ),
			( IECore.FloatVectorData( [ 1, 2, 3, 4, 5 ] ), int(IECore.TypeId.V3fVectorData) ),
		]
		i = 0
		for ( obj, tt ) in tests:
			try:
				IECore.DataCastOp()( object = obj, targetType = tt )
			except:
				i += 1
			else:
				raise Exception, "Should fail on this test " + i
예제 #19
0
    def testOperators(self):
        """Test M33f operators"""

        x = 10
        y = 2
        m1 = imath.M33f(x)
        m2 = imath.M33f(y)

        self.assertEqual(m1 + m2, imath.M33f(x + y))
        self.assertEqual(m1 - m2, imath.M33f(x - y))
        self.assertEqual(m1 * y, imath.M33f(x * y))
        self.assertEqual(m1 / y, imath.M33f(x / y))
예제 #20
0
    def testMiscellaneousMethods(self):
        """Test M33f miscellaneous methods"""

        m1 = imath.M33f()
        m1.makeIdentity()

        m1 = imath.M33f(3)
        m2 = imath.M33f(3.1)
        self.assert_(m1.equalWithAbsError(m2, 0.1))

        m1 = imath.M33f(2)
        m2 = imath.M33f(3)
        self.assert_(m1.equalWithRelError(m2, 0.51))

        m1 = imath.M33f(1, 0, 0, 0, 2, 0, 0, 0, 3)
        self.assertEqual(m1.transposed().transposed(), m1)
예제 #21
0
	def testVectorData( self ) :

		p = Gaffer.CompoundDataPlug()

		m1 = Gaffer.NameValuePlug( "a", IECore.FloatVectorData( [ 1, 2, 3 ] ) )
		p.addChild( m1 )
		self.assertIsInstance( m1, Gaffer.ValuePlug )

		d, n = p.memberDataAndName( m1 )
		self.assertEqual( d, IECore.FloatVectorData( [ 1, 2, 3 ] ) )
		self.assertEqual( n, "a" )

		m2 = Gaffer.NameValuePlug( "b", IECore.IntVectorData( [ 1, 2, 3 ] ) )
		p.addChild( m2 )
		self.assertIsInstance( m2, Gaffer.ValuePlug )

		d, n = p.memberDataAndName( m2 )
		self.assertEqual( d, IECore.IntVectorData( [ 1, 2, 3 ] ) )
		self.assertEqual( n, "b" )

		m3 = Gaffer.NameValuePlug( "c", IECore.StringVectorData( [ "1", "2", "3" ] ) )
		p.addChild( m3 )
		self.assertIsInstance( m3, Gaffer.ValuePlug )

		d, n = p.memberDataAndName( m3 )
		self.assertEqual( d, IECore.StringVectorData( [ "1", "2", "3" ] ) )
		self.assertEqual( n, "c" )

		m4 = Gaffer.NameValuePlug( "d", IECore.V3fVectorData( [ imath.V3f( x ) for x in range( 1, 5 ) ] ) )
		p.addChild( m4 )
		self.assertIsInstance( m4, Gaffer.ValuePlug )

		d, n = p.memberDataAndName( m4 )
		self.assertEqual( d, IECore.V3fVectorData( [ imath.V3f( x ) for x in range( 1, 5 ) ] ) )
		self.assertEqual( n, "d" )

		m5 = Gaffer.NameValuePlug( "e", IECore.Color3fVectorData( [ imath.Color3f( x ) for x in range( 1, 5 ) ] ) )
		p.addChild( m5 )
		self.assertIsInstance( m5, Gaffer.ValuePlug )

		d, n = p.memberDataAndName( m5 )
		self.assertEqual( d, IECore.Color3fVectorData( [ imath.Color3f( x ) for x in range( 1, 5 ) ] ) )
		self.assertEqual( n, "e" )

		m6 = Gaffer.NameValuePlug( "f", IECore.M44fVectorData( [ imath.M44f() * x for x in range( 1, 5 ) ] ) )
		p.addChild( m6 )
		self.assertIsInstance( m6, Gaffer.ValuePlug )

		d, n = p.memberDataAndName( m6 )
		self.assertEqual( d, IECore.M44fVectorData( [ imath.M44f() * x for x in range( 1, 5 ) ] ) )
		self.assertEqual( n, "f" )

		m7 = Gaffer.NameValuePlug( "g", IECore.V2iVectorData( [ imath.V2i( x ) for x in range( 1, 5 ) ] ) )
		p.addChild( m7 )
		self.assertIsInstance( m7, Gaffer.ValuePlug )

		d, n = p.memberDataAndName( m7 )
		self.assertEqual( d, IECore.V2iVectorData( [ imath.V2i( x ) for x in range( 1, 5 ) ] ) )
		self.assertEqual( n, "g" )

		m8 = Gaffer.NameValuePlug( "h", IECore.M33fVectorData( [ imath.M33f() * x for x in range( 1, 5 ) ] ) )
		p.addChild( m8 )
		self.assertIsInstance( m8, Gaffer.ValuePlug )

		d, n = p.memberDataAndName( m8 )
		self.assertEqual( d, IECore.M33fVectorData( [ imath.M33f() * x for x in range( 1, 5 ) ] ) )
		self.assertEqual( n, "h" )
예제 #22
0
    def testBlindDataToHeader(self):

        displayWindow = imath.Box2i(imath.V2i(0, 0), imath.V2i(9, 9))
        dataWindow = displayWindow

        headerValues = {
            "one": IECore.IntData(1),
            "two": IECore.FloatData(2),
            "three": IECore.DoubleData(3),
            "four": {
                "five":
                IECore.V2fData(imath.V2f(5)),
                "six":
                IECore.V2iData(imath.V2i(6)),
                "seven":
                IECore.V3fData(imath.V3f(7)),
                "eight":
                IECore.V3iData(imath.V3i(8)),
                "nine": {
                    "ten":
                    IECore.Box2iData(imath.Box2i(imath.V2i(0), imath.V2i(10))),
                    "eleven":
                    IECore.Box2fData(imath.Box2f(imath.V2f(0), imath.V2f(11))),
                    "twelve":
                    IECore.M33fData(imath.M33f(12)),
                    "thirteen":
                    IECore.M44fData(imath.M44f(13)),
                },
                "fourteen":
                IECore.StringData("fourteen"),
                "fifteen":
                IECore.TimeCodeData(
                    IECore.TimeCode(1,
                                    2,
                                    3,
                                    4,
                                    dropFrame=True,
                                    bgf2=True,
                                    binaryGroup4=4)),
            }
        }

        imgOrig = self.__makeFloatImage(dataWindow, dataWindow)
        imgOrig.blindData().update(headerValues.copy())
        # now add some unsupported types
        imgOrig.blindData()['notSupported1'] = IECore.FloatVectorData(
            [0, 1, 2, 3, 4])
        imgOrig.blindData()['four']['notSupported2'] = IECore.DoubleVectorData(
            [0, 1, 2, 3, 4])

        w = IECore.Writer.create(imgOrig,
                                 "test/IECoreImage/data/exr/output.exr")
        self.assertEqual(type(w), IECoreImage.ImageWriter)
        w.write()

        self.assertTrue(os.path.exists("test/IECoreImage/data/exr/output.exr"))

        r = IECore.Reader.create("test/IECoreImage/data/exr/output.exr")
        imgNew = r.read()
        imgBlindData = imgNew.blindData()
        # eliminate default header info that comes from OIIO
        del imgBlindData['oiio:ColorSpace']
        del imgBlindData['compression']
        del imgBlindData['PixelAspectRatio']
        del imgBlindData['displayWindow']
        del imgBlindData['dataWindow']
        del imgBlindData['screenWindowCenter']
        del imgBlindData['screenWindowWidth']
        del imgBlindData["Software"]
        del imgBlindData["HostComputer"]
        del imgBlindData["DateTime"]

        self.assertEqual(imgBlindData, IECore.CompoundData(headerValues))
예제 #23
0
    def __matrix(self, inputDataWindow, outputDataWindow):

        return imath.M33f()
예제 #24
0
        def __test(fileName, size, filter):

            inputFileName = os.path.dirname(__file__) + "/images/" + fileName

            reader = GafferImage.ImageReader()
            reader["fileName"].setValue(inputFileName)

            inSize = reader["out"]["format"].getValue().getDisplayWindow(
            ).size()
            inSize = imath.V2f(inSize.x, inSize.y)

            deleteChannels = GafferImage.DeleteChannels()
            deleteChannels["mode"].setValue(1)
            deleteChannels["channels"].setValue(IECore.StringVectorData(['R']))
            deleteChannels["in"].setInput(reader["out"])

            scale = imath.V2f(size.x, size.y) / inSize

            resample = GafferImage.Resample()
            resample["in"].setInput(deleteChannels["out"])
            resample["matrix"].setValue(imath.M33f().scale(scale))
            resample["filter"].setValue(filter)
            resample["boundingMode"].setValue(
                GafferImage.Sampler.BoundingMode.Clamp)

            crop = GafferImage.Crop()
            crop["in"].setInput(resample["out"])
            crop["area"].setValue(imath.Box2i(imath.V2i(0), size))

            borderForFilterWidth = 60
            sampleRegion = reader["out"]["dataWindow"].getValue()
            sampleRegion.setMin(sampleRegion.min() -
                                imath.V2i(borderForFilterWidth))
            sampleRegion.setMax(sampleRegion.max() +
                                imath.V2i(borderForFilterWidth))

            s = GafferImage.Sampler(reader["out"], "R", sampleRegion,
                                    GafferImage.Sampler.BoundingMode.Clamp)

            w = imath.Box2i(imath.V2i(0), size - imath.V2i(1))
            boxImage = IECoreImage.ImagePrimitive(w, w)
            parallelImage = IECoreImage.ImagePrimitive(w, w)

            boxR = IECore.FloatVectorData(size.x * size.y)
            parallelR = IECore.FloatVectorData(size.x * size.y)

            for y in range(size.y):
                for x in range(size.x):
                    boxR[(size.y - 1 - y) * size.x +
                         x] = GafferImage.FilterAlgo.sampleBox(
                             s,
                             imath.V2f(x + 0.5, y + 0.5) / scale,
                             max(1.0 / scale[0], 1.0),
                             max(1.0 / scale[1], 1.0), filter)
                    parallelR[(size.y - 1 - y) * size.x +
                              x] = GafferImage.FilterAlgo.sampleParallelogram(
                                  s,
                                  imath.V2f(x + 0.5, y + 0.5) / scale,
                                  imath.V2f(1.0 / scale[0], 0),
                                  imath.V2f(0, 1.0 / scale[1]), filter)

            boxImage["R"] = boxR
            parallelImage["R"] = parallelR

            # Enable to write out images for visual comparison
            if False:
                tempDirectory = "/tmp"
                expectedFileName = tempDirectory + "/%s_%dx%d_%s_expected.exr" % (
                    os.path.splitext(fileName)[0], size.x, size.y, filter)
                expectedWriter = GafferImage.ImageWriter()
                expectedWriter["in"].setInput(crop["out"])
                expectedWriter["fileName"].setValue(expectedFileName)
                expectedWriter["task"].execute()

                outputFileName = tempDirectory + "/%s_%dx%d_%s.box.exr" % (
                    os.path.splitext(fileName)[0], size.x, size.y, filter)
                IECore.Writer.create(boxImage, outputFileName).write()
                outputFileName = tempDirectory + "/%s_%dx%d_%s.parallel.exr" % (
                    os.path.splitext(fileName)[0], size.x, size.y, filter)
                IECore.Writer.create(parallelImage, outputFileName).write()

            imageNode = GafferImage.ObjectToImage()
            imageNode["object"].setValue(boxImage)
            self.assertImagesEqual(crop["out"],
                                   imageNode["out"],
                                   maxDifference=0.000011,
                                   ignoreMetadata=True)

            imageNode["object"].setValue(parallelImage)
            self.assertImagesEqual(crop["out"],
                                   imageNode["out"],
                                   maxDifference=0.000011,
                                   ignoreMetadata=True)
예제 #25
0
    def testNonFlatThrows(self):

        resample = GafferImage.Resample()
        resample["matrix"].setValue(imath.M33f().scale(imath.V2f(0.5)))

        self.assertRaisesDeepNotSupported(resample)
예제 #26
0
    def testEquality(self):
        """Test M33f comparison for equality"""
        m1 = imath.M33f(3)
        m2 = imath.M33f(3)

        self.assertEqual(m1, m2)
예제 #27
0
    def testOperators(self):
        """Test V2f arithmetic operators"""
        v1 = imath.V2f(3.4, 9.2)
        v2 = imath.V2f(5.3, -0.4)

        # ADDITION

        # By definition
        self.assertEqual(v1 + v2, imath.V2f(v1.x + v2.x, v1.y + v2.y))

        # Commutative
        self.assertEqual(v1 + v2, v2 + v1)

        # Assignment
        v1_copy = imath.V2f(v1)
        temp = v1
        temp += v2
        self.assertEqual(temp, (v1_copy + v2))

        # SUBTRACTION

        # By definition
        self.assertEqual(v1 - v2, imath.V2f(v1.x - v2.x, v1.y - v2.y))
        self.assertEqual(v1 - v2, -v2 + v1)

        # Assignment
        v1_copy = imath.V2f(v1)
        temp = v1
        temp -= v2
        self.assertEqual(temp, v1_copy - v2)

        # NEGATION

        self.assertEqual(-v1, imath.V2f(-v1.x, -v1.y))
        self.assertEqual(-v1, v1.negate())
        self.assertEqual(-(-v1), v1)

        # MULTIPLICATION

        # By definition
        self.assertEqual(v1 * v2, imath.V2f(v1.x * v2.x, v1.y * v2.y))
        c = 3
        self.assertEqual(v1 * c, imath.V2f(v1.x * c, v1.y * c))

        # Commutative
        self.assertEqual(v1 * v2, v2 * v1)
        self.assertEqual(c * v1, imath.V2f(v1.x * c, v1.y * c))

        # Assignment
        v1_copy = imath.V2f(v1)
        temp = v1
        temp *= v2
        self.assertEqual(temp, v1_copy * v2)

        v1_copy = imath.V2f(v1)
        temp = v1
        temp *= c
        self.assertEqual(temp, v1_copy * c)

        # DIVISION

        # By definition
        self.assertEqual(v1 / v2, imath.V2f(v1.x / v2.x, v1.y / v2.y))
        self.assertEqual(v1 / c, imath.V2f(v1.x / c, v1.y / c))

        # Assignment
        v1_copy = imath.V2f(v1)
        temp = v1
        temp /= v2
        self.assertEqual(temp, v1_copy / v2)

        v1_copy = imath.V2f(v1)
        temp = v1
        temp /= c
        self.assertEqual(temp, v1_copy / c)

        # matrix multiplication

        v1 = imath.V2f(1, 2)
        m = imath.M33f().translate(imath.V2f(1, 2))
        v2 = v1 * m
        v1 *= m
        self.assertEqual(v1, v2)
        self.assertEqual(v1, imath.V2f(2, 4))
예제 #28
0
    def points(self):
        pData = IECore.V3fVectorData([
            imath.V3f(0, 1, 2),
            imath.V3f(1),
            imath.V3f(2),
            imath.V3f(3),
            imath.V3f(4),
            imath.V3f(5),
            imath.V3f(6),
            imath.V3f(7),
            imath.V3f(8),
            imath.V3f(9),
            imath.V3f(10),
            imath.V3f(11),
        ])

        points = IECoreScene.PointsPrimitive(pData)

        floatData = IECore.FloatData(1.5)
        v2fData = IECore.V2fData(imath.V2f(1.5, 2.5))
        v3fData = IECore.V3fData(imath.V3f(1.5, 2.5, 3.5))
        v3fData = IECore.V3fData(imath.V3f(1.5, 2.5, 3.5))
        color3fData = IECore.Color3fData(imath.Color3f(1.5, 2.5, 3.5))
        intData = IECore.IntData(1)
        v2iData = IECore.V2iData(imath.V2i(1, 2))
        v3iData = IECore.V3iData(imath.V3i(1, 2, 3))
        stringData = IECore.StringData("this is a string")
        m33fData = IECore.M33fData(
            imath.M33f(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
        m44fData = IECore.M44fData(
            imath.M44f(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0,
                       12.0, 13.0, 14.0, 15.0, 16.0))

        intRange = range(1, 13)
        floatVectorData = IECore.FloatVectorData([x + 0.5 for x in intRange])
        v2fVectorData = IECore.V2fVectorData(
            [imath.V2f(x, x + 0.5) for x in intRange])
        v3fVectorData = IECore.V3fVectorData(
            [imath.V3f(x, x + 0.5, x + 0.75) for x in intRange])
        color3fVectorData = IECore.Color3fVectorData(
            [imath.Color3f(x, x + 0.5, x + 0.75) for x in intRange])
        quatVectorData = IECore.QuatfVectorData(
            [imath.Quatf(x, x + 0.25, x + 0.5, x + 0.75) for x in intRange])
        intVectorData = IECore.IntVectorData(intRange)
        v2iVectorData = IECore.V2iVectorData(
            [imath.V2i(x, -x) for x in intRange])
        v3iVectorData = IECore.V3iVectorData(
            [imath.V3i(x, -x, x * 2) for x in intRange])
        stringVectorData = IECore.StringVectorData(
            ["string number %06d!" % x for x in intRange])
        m33fVectorData = IECore.M33fVectorData([
            imath.M33f(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
            for x in intRange
        ])
        m44fVectorData = IECore.M44fVectorData([
            imath.M44f(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0,
                       12.0, 13.0, 14.0, 15.0, 16.0) for x in intRange
        ])

        detailInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Constant
        uniformInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Uniform
        pointInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Vertex

        # add all valid detail attrib types
        points["floatDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, floatData)
        points["v2fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, v2fData)
        points["v3fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, v3fData)
        points["color3fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, color3fData)
        points["intDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, intData)
        points["v2iDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, v2iData)
        points["v3iDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, v3iData)
        points["stringDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, stringData)
        points["m33fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, m33fData)
        points["m44fDetail"] = IECoreScene.PrimitiveVariable(
            detailInterpolation, m44fData)

        # add all valid prim attrib types
        points["floatPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, floatVectorData[:1])
        points["v2fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, v2fVectorData[:1])
        points["v3fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, v3fVectorData[:1])
        points["color3fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, color3fVectorData[:1])
        points["quatPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, quatVectorData[:1])
        points["intPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, intVectorData[:1])
        points["v2iPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, v2iVectorData[:1])
        points["v3iPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, v3iVectorData[:1])
        points["stringPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, stringVectorData[:1],
            IECore.IntVectorData([0]))
        points["m33fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, m33fVectorData[:1])
        points["m44fPrim"] = IECoreScene.PrimitiveVariable(
            uniformInterpolation, m44fVectorData[:1])

        # add all valid point attrib types
        points["floatPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, floatVectorData)
        points["v2fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, v2fVectorData)
        points["v3fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, v3fVectorData)
        points["color3fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, color3fVectorData)
        points["quatPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, quatVectorData)
        points["intPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, intVectorData)
        points["v2iPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, v2iVectorData)
        points["v3iPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, v3iVectorData)
        points["stringPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, stringVectorData,
            IECore.IntVectorData(range(0, 12)))
        points["m33fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, m33fVectorData)
        points["m44fPoint"] = IECoreScene.PrimitiveVariable(
            pointInterpolation, m44fVectorData)

        return points
예제 #29
0
        def __test(fileName, size, filter):

            inputFileName = os.path.dirname(__file__) + "/images/" + fileName

            reader = GafferImage.ImageReader()
            reader["fileName"].setValue(inputFileName)

            inSize = reader["out"]["format"].getValue().getDisplayWindow(
            ).size()
            inSize = imath.V2f(inSize.x, inSize.y)

            resample = GafferImage.Resample()
            resample["in"].setInput(reader["out"])
            resample["matrix"].setValue(imath.M33f().scale(
                imath.V2f(size.x, size.y) / inSize))
            resample["filter"].setValue(filter)
            resample["boundingMode"].setValue(
                GafferImage.Sampler.BoundingMode.Clamp)

            crop = GafferImage.Crop()
            crop["in"].setInput(resample["out"])
            crop["area"].setValue(imath.Box2i(imath.V2i(0), size))

            outputFileName = self.temporaryDirectory() + "/%s_%dx%d_%s.exr" % (
                os.path.splitext(fileName)[0], size.x, size.y, filter)
            writer = GafferImage.ImageWriter()
            writer["in"].setInput(crop["out"])
            writer["channels"].setValue("[RGB]")
            writer["fileName"].setValue(outputFileName)
            writer["task"].execute()

            result = GafferImage.ImageReader()
            result["fileName"].setValue(writer["fileName"].getValue())

            expected = GafferImage.ImageReader()
            expected["fileName"].setValue(
                "%s/images/%s_%dx%d_%s.exr" %
                (os.path.dirname(__file__), os.path.splitext(fileName)[0],
                 size.x, size.y, filter))

            self.assertImagesEqual(result["out"],
                                   expected["out"],
                                   maxDifference=0.0005,
                                   ignoreMetadata=True)

            # Enable to write out images for visual comparison with OIIO.
            # The images will appear in a "resampleComparison" subdirectory
            # of the current directory.
            if False:

                if not os.path.exists("resampleComparison"):
                    os.makedirs("resampleComparison")

                shutil.copyfile(
                    outputFileName, "resampleComparison/gaffer_" +
                    os.path.basename(outputFileName))

                oiioOutputFileName = "resampleComparison/oiio_%s_%dx%d_%s.exr" % (
                    os.path.splitext(fileName)[0], size.x, size.y, filter)

                subprocess.check_call(
                    "oiiotool --threads 1 %s --ch R,G,B --resize:filter=%s %dx%d  -o %s"
                    % (inputFileName, filter, size.x, size.y,
                       oiioOutputFileName),
                    shell=True)
예제 #30
0
    def testCopyAndAssign(self):
        """Test M33f copy construction and assignment"""

        m1 = imath.M33f()
        m2 = imath.M33f(m1)
        self.failIf(m1 is m2)