コード例 #1
0
ファイル: Imath.py プロジェクト: yjcnbnbnb200/cortex
    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)
コード例 #2
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))
コード例 #3
0
ファイル: USDSceneTest.py プロジェクト: SimonForgot/cortex
    def testPrimVarTypes(self):

        root = IECoreScene.SceneInterface.create(
            os.path.dirname(__file__) + "/data/primVars.usda",
            IECore.IndexedIO.OpenMode.Read)

        object = root.child("root").child("sphere").readObject(0.0)

        expected = {
            'test_Bool_Scalar_constant':
            IECore.BoolData(0),
            'test_Double2_Array_constant':
            IECore.V2dVectorData([
                imath.V2d(1.1, 1.2),
                imath.V2d(2.1, 2.2),
                imath.V2d(3.1, 3.2)
            ]),
            'test_Double2_Scalar_constant':
            IECore.V2dData(imath.V2d(0.1, 0.2)),
            'test_Double3_Array_constant':
            IECore.V3dVectorData([
                imath.V3d(1.1, 1.2, 1.3),
                imath.V3d(2.1, 2.2, 2.3),
                imath.V3d(3.1, 3.2, 3.3)
            ]),
            'test_Double3_Scalar_constant':
            IECore.V3dData(imath.V3d(0.1, 0.2, 0.3)),
            'test_Double_Array_constant':
            IECore.DoubleVectorData([1.2, 1.3, 1.4]),
            'test_Double_Scalar_constant':
            IECore.DoubleData(1.1),
            'test_Float2_Array_constant':
            IECore.V2fVectorData([
                imath.V2f(1.1, 1.2),
                imath.V2f(2.1, 2.2),
                imath.V2f(3.1, 3.2)
            ]),
            'test_Float2_Scalar_constant':
            IECore.V2fData(imath.V2f(0.1, 0.2)),
            'test_Float3_Array_constant':
            IECore.V3fVectorData([
                imath.V3f(1.1, 1.2, 1.3),
                imath.V3f(2.1, 2.2, 2.3),
                imath.V3f(3.1, 3.2, 3.3)
            ]),
            'test_Float3_Scalar_constant':
            IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
            'test_Float_Array_constant':
            IECore.FloatVectorData([0.7, 0.8, 0.9]),
            'test_Float_Scalar_constant':
            IECore.FloatData(0.6),
            'test_Half_Array_constant':
            IECore.HalfVectorData([0.0999756, 0.199951, 0.300049]),
            'test_Half_Scalar_constant':
            IECore.HalfData(0.5),
            'test_Int2_Array_constant':
            IECore.V2iVectorData(
                [imath.V2i(3, 4),
                 imath.V2i(5, 6),
                 imath.V2i(7, 8)]),
            'test_Int2_Scalar_constant':
            IECore.V2iData(imath.V2i(1, 2)),
            'test_Int3_Array_constant':
            IECore.V3iVectorData(
                [imath.V3i(3, 4, 5),
                 imath.V3i(5, 6, 7),
                 imath.V3i(7, 8, 9)]),
            'test_Int3_Scalar_constant':
            IECore.V3iData(imath.V3i(1, 2, 3)),
            'test_Int64_Array_constant':
            IECore.Int64VectorData([
                9223372036854775805, 9223372036854775806, 9223372036854775807
            ]),
            'test_Int64_Scalar_constant':
            IECore.Int64Data(-9223372036854775808),
            'test_Int_Array_constant':
            IECore.IntVectorData([0, -1, -2]),
            'test_Int_Scalar_constant':
            IECore.IntData(-1),
            'test_String_Array_constant':
            IECore.StringVectorData(["is", "a", "test"]),
            'test_String_Scalar_constant':
            IECore.StringData('this'),
            'test_Token_Array_constant':
            IECore.InternedStringVectorData([
                IECore.InternedString("t-is"),
                IECore.InternedString("t-a"),
                IECore.InternedString("t-test")
            ]),
            'test_Token_Scalar_constant':
            IECore.InternedStringData(IECore.InternedString("t-this")),
            'test_UChar_Array_constant':
            IECore.UCharVectorData([0, 1, 2]),
            'test_UChar_Scalar_constant':
            IECore.UCharData(0),
            'test_UInt64_Array_constant':
            IECore.UInt64VectorData([
                18446744073709551613, 18446744073709551614,
                18446744073709551615
            ]),
            'test_UInt64_Scalar_constant':
            IECore.UInt64Data(18446744073709551615),
            'test_UInt_Array_constant':
            IECore.UIntVectorData([4294967293, 4294967294, 4294967295]),
            'test_UInt_Scalar_constant':
            IECore.UIntData(4294967295),
            #'test_color3d_Array_constant' : IECore.Color3dVectorData([IECore.Color3d(1.1, 1.2, 1.3), IECore.Color3d(2.1, 2.2, 2.3), IECore.Color3d(3.1, 3.2, 3.3)]),
            #'test_color3d_Scalar_constant' : IECore.Color3dData(IECore.Color3d(0.1, 0.2, 0.3)),
            'test_color3f_Array_constant':
            IECore.Color3fVectorData([
                imath.Color3f(1.1, 1.2, 1.3),
                imath.Color3f(2.1, 2.2, 2.3),
                imath.Color3f(3.1, 3.2, 3.3)
            ]),
            'test_color3f_Scalar_constant':
            IECore.Color3fData(imath.Color3f(0.1, 0.2, 0.3)),
            #'test_color4d_Array_constant' : IECore.Color4dVectorData([IECore.Color4d(1.1, 1.2, 1.3, 1.4), IECore.Color4d(2.1, 2.2, 2.3, 2.4), IECore.Color4d(3.1, 3.2, 3.3, 3.4)]),
            #'test_color4d_Scalar_constant' : IECore.Color4dData(IECore.Color4d(0.1, 0.2, 0.3, 0.4)),
            'test_color4f_Array_constant':
            IECore.Color4fVectorData([
                imath.Color4f(1.1, 1.2, 1.3, 1.4),
                imath.Color4f(2.1, 2.2, 2.3, 2.4),
                imath.Color4f(3.1, 3.2, 3.3, 3.4)
            ]),
            'test_color4f_Scalar_constant':
            IECore.Color4fData(imath.Color4f(0.1, 0.2, 0.3, 0.4)),
            'test_matrix3d_Array_constant':
            IECore.M33dVectorData([
                imath.M33d(0, 0, 0, 0, 1, 0, 0, 0, 0),
                imath.M33d(0, 0, 0, 0, 0, 0, 0, 0, 2),
                imath.M33d(0, 0, 4, 0, 0, 0, 0, 0, 0)
            ]),
            'test_matrix3d_Scalar_constant':
            IECore.M33dData(imath.M33d(0, 0, 0, 0, 0, 0, 0, 0, 0)),
            'test_matrix4d_Array_constant':
            IECore.M44dVectorData([
                imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0),
                imath.M44d(1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0)
            ]),
            'test_matrix4d_Scalar_constant':
            IECore.M44dData(
                imath.M44d(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
            'test_normal3d_Array_constant':
            IECore.V3dVectorData([
                imath.V3d(1.1, 1.2, 1.3),
                imath.V3d(2.1, 2.2, 2.3),
                imath.V3d(3.1, 3.2, 3.3)
            ]),
            'test_normal3d_Scalar_constant':
            IECore.V3dData(imath.V3d(0.1, 0.2, 0.3)),
            'test_normal3f_Array_constant':
            IECore.V3fVectorData([
                imath.V3f(1.1, 1.2, 1.3),
                imath.V3f(2.1, 2.2, 2.3),
                imath.V3f(3.1, 3.2, 3.3)
            ]),
            'test_normal3f_Scalar_constant':
            IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
            'test_point3d_Array_constant':
            IECore.V3dVectorData([
                imath.V3d(1.1, 1.2, 1.3),
                imath.V3d(2.1, 2.2, 2.3),
                imath.V3d(3.1, 3.2, 3.3)
            ]),
            'test_point3d_Scalar_constant':
            IECore.V3dData(imath.V3d(0.1, 0.2, 0.3)),
            'test_point3f_Array_constant':
            IECore.V3fVectorData([
                imath.V3f(1.1, 1.2, 1.3),
                imath.V3f(2.1, 2.2, 2.3),
                imath.V3f(3.1, 3.2, 3.3)
            ]),
            'test_point3f_Scalar_constant':
            IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
            'test_quatd_Array_constant':
            IECore.QuatdVectorData([
                imath.Quatd(1, 0, 0, 0),
                imath.Quatd(0, 1, 0, 0),
                imath.Quatd(0, 0, 1, 0)
            ]),
            'test_quatd_Scalar_constant':
            IECore.QuatdData(imath.Quatd(0, 0, 0, 1)),
            'test_quatf_Array_constant':
            IECore.QuatfVectorData([
                imath.Quatf(1, 0, 0, 0),
                imath.Quatf(0, 1, 0, 0),
                imath.Quatf(0, 0, 1, 0)
            ]),
            'test_quatf_Scalar_constant':
            IECore.QuatfData(imath.Quatf(0, 0, 0, 1)),
            'test_vector3d_Array_constant':
            IECore.V3dVectorData([
                imath.V3d(1.1, 1.2, 1.3),
                imath.V3d(2.1, 2.2, 2.3),
                imath.V3d(3.1, 3.2, 3.3)
            ]),
            'test_vector3d_Scalar_constant':
            IECore.V3dData(imath.V3d(0.1, 0.2, 0.3)),
            'test_vector3f_Array_constant':
            IECore.V3fVectorData([
                imath.V3f(1.1, 1.2, 1.3),
                imath.V3f(2.1, 2.2, 2.3),
                imath.V3f(3.1, 3.2, 3.3)
            ]),
            'test_vector3f_Scalar_constant':
            IECore.V3fData(imath.V3f(0.1, 0.2, 0.3)),
        }

        for primVarName, primVarExpectedValue in expected.items():
            self.assertTrue(primVarName in object.keys())
            p = object[primVarName]
            self.assertEqual(p.data, primVarExpectedValue)
コード例 #4
0
ファイル: testCask.py プロジェクト: tanant/cask
    def test_pod_extent(self):
        filename = os.path.join(TEMPDIR, "cask_pod_extent.abc")

        extent = 5
        v = imath.UnsignedCharArray(extent)
        for i in range(0, extent):
            v[i] = i

        a = cask.Archive()

        # create test properties
        foo = a.top.children["foo"] = cask.Xform()
        bar = foo.properties["bar"] = cask.Property()
        baz = foo.properties["baz"] = cask.Property()
        qux = foo.properties["qux"] = cask.Property()
        quux = foo.properties["quux"] = cask.Property()
        garply = foo.properties["garply"] = cask.Property()
        waldo = foo.properties["waldo"] = cask.Property()
        fred = foo.properties["fred"] = cask.Property()
        color = foo.properties["color"] = cask.Property()
        color.metadata["interpretation"] = "rgb"
        
        # set test values
        v = imath.UnsignedCharArray(5)
        for i in range(0, 5):
            v[i] = i
        bar.set_value(v)
        baz.set_value(["a", "b", "c"])
        qux.set_value(imath.Box3d())
        quux.set_value(imath.M33d())
        garply.set_value(imath.M44d())
        waldo.set_value(1)
        fred.set_value([1, 2, 3, 4])
        color.set_value(imath.Color3f(1, 2, 3))
       
        # export
        a.write_to_file(filename)
        a.close()

        # reimport the test file
        a = cask.Archive(filename)

        # recover the test properties
        foo = a.top.children["foo"]
        bar = foo.properties["bar"]
        baz = foo.properties["baz"]
        qux = foo.properties["qux"]
        quux = foo.properties["quux"]
        garply = foo.properties["garply"]
        waldo = foo.properties["waldo"]
        fred = foo.properties["fred"]
        color = foo.properties["color"]
        
        # assert pod, extent values
        self.assertEqual(bar.extent(), 5)
        self.assertEqual(bar.pod(), alembic.Util.POD.kUint8POD)
        self.assertEqual(bar.values[0], v)
        self.assertEqual(baz.extent(), 1)
        self.assertEqual(baz.pod(), alembic.Util.POD.kStringPOD)
        self.assertEqual(list(baz.values[0]), ["a", "b", "c"])
        self.assertEqual(qux.extent(), 6)
        self.assertEqual(qux.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(qux.values[0], imath.Box3d())
        self.assertEqual(quux.extent(), 9)
        self.assertEqual(quux.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(quux.values[0], imath.M33d())
        self.assertEqual(garply.extent(), 16)
        self.assertEqual(garply.pod(), alembic.Util.POD.kFloat64POD)
        self.assertEqual(garply.values[0], imath.M44d())
        self.assertEqual(waldo.extent(), 1)
        self.assertEqual(waldo.pod(), alembic.Util.POD.kInt32POD)
        self.assertEqual(waldo.values[0], 1)
        self.assertEqual(fred.extent(), 1)
        self.assertEqual(fred.pod(), alembic.Util.POD.kInt32POD)
        self.assertEqual(list(fred.values[0]), [1, 2, 3, 4])
        self.assertEqual(color.extent(), 3)
        self.assertEqual(color.pod(), alembic.Util.POD.kFloat32POD)
        self.assertEqual(color.metadata["interpretation"], "rgb")
        self.assertEqual(color.values[0], imath.Color3f(1, 2, 3))