示例#1
0
    def testConstructors(self):
        """Test Quatf constructors"""

        q = imath.Quatf()
        q = imath.Quatf(q)
        q = imath.Quatf(0.1, 0.2, 0.3, 0.4)
        q = imath.Quatf(0.1, imath.V3f(0.2, 0.3, 0.4))
示例#2
0
    def testEquality(self):
        """Test Quatf comparison for equality"""

        q1 = imath.Quatf(1, 2, 3, 4)
        q2 = imath.Quatf(1, 2, 3, 4)
        self.assertEqual(q1, q1)
        self.assertEqual(q1, q2)

        q2 = imath.Quatf(5, 2, 3, 4)
        self.assert_(q1 != q2)
示例#3
0
    def testTransformationMatrixParsing(self):

        p = IECore.CompoundParameter(members=[
            IECore.TransformationMatrixfParameter(
                name="t",
                description="d",
                defaultValue=IECore.TransformationMatrixf(),
            ),
        ])

        args = [
            "-t", '1', '2', '3', '10', '11', '12', '4', '5', '6', '7', '8',
            '9', 'ZYX', '1', '21', '22', '23', '26', '27', '28', '36', '37',
            '38', '46', '47', '48', '56', '57', '58'
        ]
        IECore.ParameterParser().parse(args, p)

        t = p["t"].getTypedValue()
        self.assertEqual(t.translate, imath.V3f(1, 2, 3))
        self.assertEqual(t.scale, imath.V3f(10, 11, 12))
        self.assertEqual(t.shear, imath.V3f(4, 5, 6))
        self.assertEqual(t.rotate, imath.V3f(7, 8, 9))
        self.assertEqual(t.rotate.order(), imath.Eulerf.Order.ZYX)
        self.assertEqual(t.rotationOrientation, imath.Quatf(1, 21, 22, 23))
        self.assertEqual(t.rotatePivot, imath.V3f(26, 27, 28))
        self.assertEqual(t.rotatePivotTranslation, imath.V3f(36, 37, 38))
        self.assertEqual(t.scalePivot, imath.V3f(46, 47, 48))
        self.assertEqual(t.scalePivotTranslation, imath.V3f(56, 57, 58))
示例#4
0
	def testTypeConvertion( self ) :

		self.assertEqual( IECore.DataCastOp()( object = IECore.FloatData( 2 ), targetType = int(IECore.TypeId.DoubleData) ), IECore.DoubleData( 2 ) )
		self.assertEqual( IECore.DataCastOp()( object = IECore.DoubleData( 2 ), targetType = int(IECore.TypeId.FloatData) ), IECore.FloatData( 2 ) )
		self.assertEqual( IECore.DataCastOp()( object = IECore.IntData( 2 ), targetType = int(IECore.TypeId.UIntData) ), IECore.UIntData( 2 ) )
		self.assertEqual( IECore.DataCastOp()( object = IECore.V3fData( imath.V3f( 2 ) ), targetType = int(IECore.TypeId.V3dData) ), IECore.V3dData( imath.V3d( 2 ) ) )
		self.assertEqual( IECore.DataCastOp()( object = IECore.QuatfData( imath.Quatf( 1,2,3,4 ) ), targetType = int(IECore.TypeId.QuatdData) ), IECore.QuatdData( imath.Quatd( 1,2,3,4 ) ) )
示例#5
0
    def test(self):

        tm = IECore.TransformationMatrixfData()
        p = IECore.TransformationMatrixfParameter(
            name="f",
            description="d",
            defaultValue=tm,
        )
        p.validate()

        self.assertEqual(p.name, "f")
        self.assertEqual(p.description, "d")
        self.assertEqual(p.valueValid()[0], True)

        self.assertTrue(isinstance(p.getTypedValue().translate, imath.V3f))
        self.assertEqual(p.getTypedValue().translate, imath.V3f(0, 0, 0))
        self.assertEqual(p.getTypedValue().rotate, imath.Eulerf(0, 0, 0))
        self.assertEqual(p.getTypedValue().rotationOrientation,
                         imath.Quatf(1, 0, 0, 0))
        self.assertEqual(p.getTypedValue().scale, imath.V3f(1, 1, 1))
        self.assertEqual(p.getTypedValue().shear, imath.V3f(0, 0, 0))
        self.assertEqual(p.getTypedValue().rotatePivot, imath.V3f(0, 0, 0))
        self.assertEqual(p.getTypedValue().rotatePivotTranslation,
                         imath.V3f(0, 0, 0))
        self.assertEqual(p.getTypedValue().scalePivot, imath.V3f(0, 0, 0))
        self.assertEqual(p.getTypedValue().scalePivotTranslation,
                         imath.V3f(0, 0, 0))

        tm = IECore.TransformationMatrixdData()
        p = IECore.TransformationMatrixdParameter(
            name="f",
            description="d",
            defaultValue=tm,
        )
        p.validate()

        self.assertEqual(p.name, "f")
        self.assertEqual(p.description, "d")
        self.assertEqual(p.valueValid()[0], True)

        self.assertTrue(isinstance(p.getTypedValue().translate, imath.V3d))
        self.assertEqual(p.getTypedValue().translate, imath.V3d(0, 0, 0))
        self.assertEqual(p.getTypedValue().rotate, imath.Eulerd(0, 0, 0))
        self.assertEqual(p.getTypedValue().rotationOrientation,
                         imath.Quatd(1, 0, 0, 0))
        self.assertEqual(p.getTypedValue().scale, imath.V3d(1, 1, 1))
        self.assertEqual(p.getTypedValue().shear, imath.V3d(0, 0, 0))
        self.assertEqual(p.getTypedValue().rotatePivot, imath.V3d(0, 0, 0))
        self.assertEqual(p.getTypedValue().rotatePivotTranslation,
                         imath.V3d(0, 0, 0))
        self.assertEqual(p.getTypedValue().scalePivot, imath.V3d(0, 0, 0))
        self.assertEqual(p.getTypedValue().scalePivotTranslation,
                         imath.V3d(0, 0, 0))
示例#6
0
	def testTransform( self ) :

		point = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( 4, 0, 0 ) ] ) )
		point["orientation"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.QuatfVectorData( [ imath.Quatf().setAxisAngle( imath.V3f( 0, 1, 0 ), math.pi / 2.0 ) ] )
		)
		point["scale"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.V3fVectorData( [ imath.V3f( 2, 3, 4 ) ] )
		)
		point["uniformScale"] = IECoreScene.PrimitiveVariable(
			IECoreScene.PrimitiveVariable.Interpolation.Vertex,
			IECore.FloatVectorData( [ 10 ] )
		)

		objectToScene = GafferScene.ObjectToScene()
		objectToScene["object"].setValue( point )

		sphere = GafferScene.Sphere()

		instancer = GafferScene.Instancer()
		instancer["in"].setInput( objectToScene["out"] )
		instancer["instances"].setInput( sphere["out"] )
		instancer["parent"].setValue( "/object" )

		self.assertEqual( instancer["out"].transform( "/object/instances/sphere/0" ), imath.M44f().translate( imath.V3f( 4, 0, 0 ) ) )

		instancer["orientation"].setValue( "orientation" )
		self.assertTrue(
			imath.V3f( 4, 0, -1 ).equalWithAbsError(
				imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ),
				0.00001
			)
		)

		instancer["scale"].setValue( "scale" )
		self.assertTrue(
			imath.V3f( 4, 0, -2 ).equalWithAbsError(
				imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ),
				0.00001
			)
		)

		instancer["scale"].setValue( "uniformScale" )
		self.assertTrue(
			imath.V3f( 4, 0, -10 ).equalWithAbsError(
				imath.V3f( 1, 0, 0 ) * instancer["out"].transform( "/object/instances/sphere/0" ),
				0.00001
			)
		)
示例#7
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()
示例#8
0
 def testAttributes(self):
     """Test TransformationMatrixf attributes"""
     a = IECore.TransformationMatrixf()
     self.assertEqual(a.scalePivot, imath.V3f(0, 0, 0))
     self.assertEqual(a.scale, imath.V3f(1, 1, 1))
     self.assertEqual(a.shear, imath.V3f(0, 0, 0))
     self.assertEqual(a.scalePivotTranslation, imath.V3f(0, 0, 0))
     self.assertEqual(a.rotatePivot, imath.V3f(0, 0, 0))
     self.assertEqual(a.rotationOrientation, imath.Quatf())
     self.assertEqual(a.rotate, imath.Eulerf())
     self.assertEqual(a.rotatePivotTranslation, imath.V3f(0, 0, 0))
     self.assertEqual(a.translate, imath.V3f(0, 0, 0))
     try:
         a.transform = 1
     except:
         pass
     else:
         raise Exception("Should not be able to set transform.")
示例#9
0
    def testCanWriteVariousPrimVarTypes(self):

        fileName = self.getOutputPath("usd_various_primvars.usdc")

        sceneWrite = IECoreScene.SceneInterface.create(
            fileName, IECore.IndexedIO.OpenMode.Write)
        root = sceneWrite.createChild("root")
        child = root.createChild("child")

        positions = IECore.V3fVectorData([imath.V3f(0, 0, 0)])
        c3f = IECore.Color3fVectorData([imath.Color3f(0, 0, 0)])
        intStr = IECore.InternedStringVectorData([IECore.InternedString("a")])
        quat = IECore.QuatfVectorData([imath.Quatf(0, 1, 2, 3)])

        pointsPrimitive = IECoreScene.PointsPrimitive(positions)
        pointsPrimitive["c3f"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, c3f)
        pointsPrimitive["token"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, intStr)
        pointsPrimitive["quat"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, quat)

        child.writeObject(pointsPrimitive, 0.0)

        del root
        del sceneWrite

        sceneRead = IECoreScene.SceneInterface.create(
            fileName, IECore.IndexedIO.OpenMode.Read)
        self.assertEqual(sceneRead.childNames(), ["root"])
        readRoot = sceneRead.child("root")
        readChild = readRoot.child("child")

        readObject = readChild.readObject(0.0)

        self.assertTrue("c3f" in readObject)
        self.assertIsInstance(readObject["c3f"].data, IECore.Color3fVectorData)

        self.assertTrue("token" in readObject)
        self.assertIsInstance(readObject["token"].data,
                              IECore.InternedStringVectorData)

        self.assertTrue("quat" in readObject)
        self.assertIsInstance(readObject["quat"].data, IECore.QuatfVectorData)
示例#10
0
def buildTestPoints():
    positions = [
        imath.V3f(1, 0, 0),
        imath.V3f(1, 0, 1),
        imath.V3f(0, 0, 1),
        imath.V3f(0, 0, 0)
    ]
    agent_id = [0, 1, 2, 3]
    agent_type = ["atomsRobot", "atomsRobot", "atoms2Robot", "atoms2Robot"]
    agent_variation = ["Robot1", "Robot2", "RedRobot", "PurpleRobot"]
    agent_lod = ["", "B", "A", ""]
    agent_velocity = [
        imath.V3f(1, 0, 0),
        imath.V3f(1, 0, 0),
        imath.V3f(0, 0, 0),
        imath.V3f(1, 0, 0)
    ]
    agent_direction = [
        imath.V3f(1, 0, 0),
        imath.V3f(1, 0, 0),
        imath.V3f(1, 0, 0),
        imath.V3f(1, 0, 0)
    ]
    agent_scale = [
        imath.V3f(1, 1, 1),
        imath.V3f(1, 1, 1),
        imath.V3f(1, 1, 1),
        imath.V3f(1, 1, 1)
    ]
    agent_orientation = [
        imath.Quatf(),
        imath.Quatf(),
        imath.Quatf(),
        imath.Quatf()
    ]
    points = IECoreScene.PointsPrimitive(IECore.V3fVectorData(positions))

    points["atoms:agentId"] = IECoreScene.PrimitiveVariable(
        IECoreScene.PrimitiveVariable.Interpolation.Vertex,
        IECore.IntVectorData(agent_id))

    points["atoms:agentType"] = IECoreScene.PrimitiveVariable(
        IECoreScene.PrimitiveVariable.Interpolation.Vertex,
        IECore.StringVectorData(agent_type))
    points["atoms:variation"] = IECoreScene.PrimitiveVariable(
        IECoreScene.PrimitiveVariable.Interpolation.Vertex,
        IECore.StringVectorData(agent_variation))
    points["atoms:lod"] = IECoreScene.PrimitiveVariable(
        IECoreScene.PrimitiveVariable.Interpolation.Vertex,
        IECore.StringVectorData(agent_lod))
    points["atoms:velocity"] = IECoreScene.PrimitiveVariable(
        IECoreScene.PrimitiveVariable.Interpolation.Vertex,
        IECore.V3fVectorData(agent_velocity))
    points["atoms:direction"] = IECoreScene.PrimitiveVariable(
        IECoreScene.PrimitiveVariable.Interpolation.Vertex,
        IECore.V3fVectorData(agent_direction))
    points["atoms:scale"] = IECoreScene.PrimitiveVariable(
        IECoreScene.PrimitiveVariable.Interpolation.Vertex,
        IECore.V3fVectorData(agent_scale))
    points["atoms:orientation"] = IECoreScene.PrimitiveVariable(
        IECoreScene.PrimitiveVariable.Interpolation.Vertex,
        IECore.QuatfVectorData(agent_orientation))
    return points
示例#11
0
    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)
示例#12
0
    def testMiscMethods(self):
        """Test Quatf miscellaneous methods"""

        q1 = imath.Quatf(1, 2, 3, 4)
        self.assertAlmostEqual(q1.length(),
                               math.sqrt(q1.r() * q1.r() + (q1.v() ^ q1.v())),
                               3)

        # axis/angle
        axis = imath.V3f(1, 2, 3)
        axis.normalize()

        q1.setAxisAngle(axis, 0.5)
        self.assertAlmostEqual(q1.axis().x, axis.x, 3)
        self.assertAlmostEqual(q1.axis().y, axis.y, 3)
        self.assertAlmostEqual(q1.axis().z, axis.z, 3)

        self.assertAlmostEqual(q1.angle(), 0.5, 3)

        # Rotate x axis onto y axis
        q1.setRotation(imath.V3f(1, 0, 0), imath.V3f(0, 1, 0))

        #We should have gone 90 degrees about the +ve z-axis
        self.assertAlmostEqual(q1.angle(), 90.0 * math.pi / 180.0, 3)

        self.assertAlmostEqual(q1.axis().x, 0.0, 3)
        self.assertAlmostEqual(q1.axis().y, 0.0, 3)
        self.assertAlmostEqual(q1.axis().z, 1.0, 3)

        #inversion
        q1 = imath.Quatf(1, 2, 3, 4)
        qdot = q1 ^ q1
        qi_test = imath.Quatf(q1.r() / qdot, -q1.v() / qdot)
        qi = q1.inverse()

        self.assertAlmostEqual(qi.r(), qi_test.r(), 3)
        self.assertAlmostEqual(qi.v()[0], qi_test.v()[0], 3)
        self.assertAlmostEqual(qi.v()[1], qi_test.v()[1], 3)
        self.assertAlmostEqual(qi.v()[2], qi_test.v()[2], 3)

        q1.invert()
        self.assertAlmostEqual(qi.r(), qi_test.r(), 3)
        self.assertAlmostEqual(qi.v()[0], qi_test.v()[0], 3)
        self.assertAlmostEqual(qi.v()[1], qi_test.v()[1], 3)
        self.assertAlmostEqual(qi.v()[2], qi_test.v()[2], 3)

        #slerp
        q2 = imath.Quatf(0.5, 0.6, 0.7, 0.8)
        qs = q1.slerp(q2, 0.5)

        # normalization
        qn = qi.normalized()
        qn_test = imath.Quatf(qi.r() / qi.length(), qi.v() / qi.length())

        self.assertAlmostEqual(qn.r(), qn_test.r(), 3)
        self.assertAlmostEqual(qn.v()[0], qn_test.v()[0], 3)
        self.assertAlmostEqual(qn.v()[1], qn_test.v()[1], 3)
        self.assertAlmostEqual(qn.v()[2], qn_test.v()[2], 3)

        qn = qi.normalize()
        self.assertAlmostEqual(qn.r(), qn_test.r(), 3)
        self.assertAlmostEqual(qn.v()[0], qn_test.v()[0], 3)
        self.assertAlmostEqual(qn.v()[1], qn_test.v()[1], 3)
        self.assertAlmostEqual(qn.v()[2], qn_test.v()[2], 3)

        #matrix conversion
        fromDir = imath.V3f(1, 0, 0)
        toDir = imath.V3f(0, 1, 0)
        q1.setRotation(fromDir, toDir)
        m = q1.toMatrix33()
        m = q1.toMatrix44()
示例#13
0
def createQuatf(value):
    return imath.Quatf(value, 0, 0, 0)
示例#14
0
    def testOperators(self):
        """Test Quatf operators"""

        q1 = imath.Quatf(1, 2, 3, 4)
        q2 = imath.Quatf(5, 6, 7, 8)
        self.assertAlmostEqual(q1 ^ q2, q1.r() * q2.r() + (q1.v() ^ q2.v()), 3)
示例#15
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
示例#16
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)),
            }
        }
        if IECoreImage.OpenImageIOAlgo.version() >= 20206:
            headerValues["sixteen"] = IECore.FloatVectorData([0, 1, 2, 3, 4])

        imgOrig = self.__makeFloatImage(dataWindow, dataWindow)
        imgOrig.blindData().update(headerValues.copy())
        # now add some unsupported types
        imgOrig.blindData()['notSupported1'] = IECore.QuatfVectorData(
            [imath.Quatf(x, imath.V3f(x)) for x in [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.assertIsInstance(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']
        if IECoreImage.OpenImageIOAlgo.version() >= 20206:
            del imgBlindData['oiio:subimages']
        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))
def save_pos_cache(path=None, start_frame=0, end_frame=1, fps=24.0, objA=[]):
    """

    :param path:
    :param objA:
    :return:
    """

    if not objA:
        return

    idA = get_idA(objA=objA)
    # print idA

    if not idA:
        return

    if len(objA) != len(idA):
        return

    cmds.currentTime(start_frame, update=True)

    arch = alembic.Abc.OArchive(path)

    root = arch.getTop()

    timesamp = alembic.AbcCoreAbstract.TimeSampling(1.0 / fps,
                                                    start_frame / fps)

    # print timesamp

    index = arch.addTimeSampling(timesamp)
    opoints = alembic.AbcGeom.OPoints(root, "position_cache", index)

    # Export Extra
    myCrazyDataContainer = opoints.getSchema().getArbGeomParams()

    # Export Shotgun IDs
    prop_sg_id = alembic.Abc.OUInt64ArrayProperty(myCrazyDataContainer,
                                                  "sg_id")
    # Export Rotation
    prop_rot = alembic.Abc.OQuatfArrayProperty(myCrazyDataContainer,
                                               "rotation")
    # Export Scale
    prop_scale = alembic.Abc.OV3fArrayProperty(myCrazyDataContainer, "scale")

    prop_rot.setTimeSampling(timesamp)
    prop_scale.setTimeSampling(timesamp)

    for i in range(start_frame, end_frame + 1):

        sg_idA = imath.IntArray(len(objA))
        posA = imath.V3fArray(len(objA))
        rotA = imath.QuatfArray(len(objA))
        sclA = imath.V3fArray(len(objA))

        cmds.currentTime(i, update=True)
        opoints_sample = alembic.AbcGeom.OPointsSchemaSample()
        ids = imath.IntArray(len(objA))

        for y in range(0, len(objA)):
            ids[y] = y

            tr = cmds.xform(objA[y], query=True, translation=True)
            rt = cmds.xform(objA[y], query=True, rotation=True)
            scl = cmds.xform(objA[y], query=True, r=True, scale=True)

            quat = euler_to_quat(rt)

            sg_idA[y] = idA[y]
            posA[y] = imath.V3f(tr[0], tr[1], tr[2])

            rotA[y] = imath.Quatf(quat[0], quat[1], quat[2], quat[3])
            sclA[y] = imath.V3f(scl[0], scl[1], scl[2])

            # print sclA[y]

        opoints_sample.setPositions(posA)
        opoints_sample.setIds(ids)
        opoints.getSchema().set(opoints_sample)

        prop_sg_id.setValue(sg_idA)
        prop_rot.setValue(rotA)
        prop_scale.setValue(sclA)

    arch = None
    del arch

    print 'Done...'