Esempio n. 1
0
    def doOperation(self, args):

        assert args["a"].value == 10
        assert abs(args["b"].value - 20.2) < 0.0001
        assert args["c"].value == 40.5
        assert args["d"].value == "hello"
        assert args["e"] == IECore.IntVectorData([2, 4, 5])
        assert args["f"] == IECore.StringVectorData([
            "one", "two", "three", "-1", "-dash", "\\-slashDash",
            "\\\\-slashSlashDash", "inline-dash"
        ])
        assert args["g"] == IECore.V2fData(imath.V2f(2, 4))
        assert args["h"] == IECore.V3fData(imath.V3f(1, 4, 8))
        assert args["i"] == IECore.V2dData(imath.V2d(2, 4))
        assert args["compound"]["j"] == IECore.V3dData(imath.V3d(1, 4, 8))
        assert args["compound"]["k"] == IECore.M44fData(
            imath.M44f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16))
        assert args["l"] == IECore.Color3fData(imath.Color3f(1, 0, 0))
        assert args["m"] == IECore.Color4fData(imath.Color4f(1, 1, 0, 1))
        assert args["o"] == IECore.StringData("myFile.tif")
        assert args["p"] == IECore.StringData("test")
        assert args["q"] == IECore.BoolData(True)
        assert args["r"] == IECore.StringData("mySequence.####.tif")
        assert args["s"] == IECore.Box2dData(
            imath.Box2d(imath.V2d(-1, -2), imath.V2d(10, 20)))
        assert args["t"] == IECore.Box3fData(
            imath.Box3f(imath.V3f(-1, -2, -3), imath.V3f(10, 20, 30)))
        assert args["u"] == IECore.V2iData(imath.V2i(64, 128))
        assert args["v"] == IECore.V3iData(imath.V3i(25, 26, 27))
        assert self["w"].getFrameListValue().asList() == IECore.FrameRange(
            0, 500, 250).asList()
        assert args["x"] == IECore.TransformationMatrixfData()
        assert args["y"] == IECore.TransformationMatrixdData()

        return IECore.IntData(1)
Esempio n. 2
0
	def testSerialisationOnlyUsesDataWhenNecessary( self ) :

		s = Gaffer.ScriptNode()
		s["n"] = Gaffer.Node()
		s["n"]["p"] = Gaffer.Plug( flags = Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic )

		for value in [
			"s",
			1,
			2.0,
			True,
			imath.Color3f( 0 ),
			imath.V2f( 0 ),
			imath.V2i( 0 ),
			imath.V3i( 0 ),
			IECore.StringVectorData( [ "one", "two" ] ),
			IECore.IntVectorData( [ 1, 2, 3 ] ),
		] :

			Gaffer.Metadata.registerValue( s["n"], "test", value )
			Gaffer.Metadata.registerValue( s["n"]["p"], "test", value )

			self.assertEqual( Gaffer.Metadata.value( s["n"], "test" ), value )
			self.assertEqual( Gaffer.Metadata.value( s["n"]["p"], "test" ), value )

			ss = s.serialise()
			if not isinstance( value, IECore.Data ) :
				self.assertTrue( "Data" not in ss )

			s2 = Gaffer.ScriptNode()
			s2.execute( ss )

			self.assertEqual( Gaffer.Metadata.value( s2["n"], "test" ), value )
			self.assertEqual( Gaffer.Metadata.value( s2["n"]["p"], "test" ), value )
Esempio n. 3
0
    def testConstantPrimVarTemporarilyOverridesShaderParameter(self):

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

        c2 = c1.copy()
        c1.state()[0].parameters["rgbF"] = IECore.V3iData(imath.V3i(0, 1, 1))
        c1.children()[0]["rgbF"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Constant,
            IECore.V3fData(imath.V3f(1, 1, 0)))

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

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

        image = self.renderImage(g)

        self.assertImageValues(image, [
            (imath.V2f(0.7, 0.5), imath.Color4f(1, 1, 0, 1)),
            (imath.V2f(0.3, 0.5), imath.Color4f(0, 0, 0, 1)),
        ])
Esempio n. 4
0
    def testCanReadV3iArrayUserData(self):

        s = self.compileShader(
            os.path.dirname(__file__) + "/shaders/V3iArrayAttributeRead.osl")

        e = GafferOSL.ShadingEngine(
            IECore.ObjectVector([IECoreScene.Shader(s, "osl:surface")]))

        p = self.rectanglePoints()

        numPoints = len(p["P"])
        p["v3i"] = IECore.V3iVectorData(numPoints)

        for i in range(numPoints):
            p["v3i"][i] = imath.V3i([i, i + 1, i + 2])

        r = e.shade(p)

        for i, c in enumerate(r["Ci"]):
            if i < 50:
                expected = imath.Color3f(0.0, i / 100.0, i / 200.0)
            else:
                expected = imath.Color3f(1.0, 0.0, 0.0)

            self.assertEqual(c, expected)
Esempio n. 5
0
	def testDetailAttributes( self ) :
		attr = self.testSetupAttributes()
		attr.parm("class").set(0) # detail attribute

		result = IECoreHoudini.FromHoudiniPolygonsConverter( attr ).convert()
		attr.parm("value1").set(123.456)
		self.assertEqual( result["test_attribute"].data.typeId(), IECore.TypeId.FloatData )
		self.assertTrue( result["test_attribute"].data > IECore.FloatData( 123.0 ) )
		self.assertEqual( result["test_attribute"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Constant )
		self.assertTrue( result.arePrimitiveVariablesValid() )

		attr.parm("type").set(1) # integer
		result = IECoreHoudini.FromHoudiniPolygonsConverter( attr ).convert()
		self.assertEqual( result["test_attribute"].data.typeId(), IECore.TypeId.IntData )
		self.assertEqual( result["test_attribute"].data, IECore.IntData( 123 ) )
		self.assertEqual( result["test_attribute"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Constant )
		self.assertTrue( result.arePrimitiveVariablesValid() )

		attr.parm("type").set(0) # float
		attr.parm("size").set(2) # 2 elementS
		attr.parm("value2").set(456.789)
		result = IECoreHoudini.FromHoudiniPolygonsConverter( attr ).convert()
		self.assertEqual( result["test_attribute"].data.typeId(), IECore.TypeId.V2fData )
		self.assertEqual( result["test_attribute"].data.value, imath.V2f( 123.456, 456.789 ) )
		self.assertEqual( result["test_attribute"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Constant )
		self.assertTrue( result.arePrimitiveVariablesValid() )

		attr.parm("type").set(1) # int
		result = IECoreHoudini.FromHoudiniPolygonsConverter( attr ).convert()
		self.assertEqual( result["test_attribute"].data.typeId(), IECore.TypeId.V2iData )
		self.assertEqual( result["test_attribute"].data.value, imath.V2i( 123, 456 ) )
		self.assertEqual( result["test_attribute"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Constant )
		self.assertTrue( result.arePrimitiveVariablesValid() )

		attr.parm("type").set(0) # float
		attr.parm("size").set(3) # 3 elements
		attr.parm("value3").set(999.999)
		result = IECoreHoudini.FromHoudiniPolygonsConverter( attr ).convert()
		self.assertEqual( result["test_attribute"].data.typeId(), IECore.TypeId.V3fData )
		self.assertEqual( result["test_attribute"].data.value, imath.V3f( 123.456, 456.789, 999.999 ) )
		self.assertEqual( result["test_attribute"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Constant )
		self.assertTrue( result.arePrimitiveVariablesValid() )

		attr.parm("type").set(1) # int
		result = IECoreHoudini.FromHoudiniPolygonsConverter( attr ).convert()
		self.assertEqual( result["test_attribute"].data.typeId(), IECore.TypeId.V3iData )
		self.assertEqual( result["test_attribute"].data.value, imath.V3i( 123, 456, 999 ) )
		self.assertEqual( result["test_attribute"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Constant )
		self.assertTrue( result.arePrimitiveVariablesValid() )

		attr.parm("type").set( 3 ) # string
		attr.parm( "string" ).set( "string!" )
		result = IECoreHoudini.FromHoudiniPointsConverter( attr ).convert()
		self.assertEqual( result["test_attribute"].data.typeId(), IECore.TypeId.StringData )
		self.assertEqual( result["test_attribute"].data.value, "string!" )
		self.assertEqual( result["test_attribute"].interpolation, IECoreScene.PrimitiveVariable.Interpolation.Constant )
		self.assertTrue( result.arePrimitiveVariablesValid() )
Esempio n. 6
0
    def testCube(self):

        m = IECore.Reader.create(
            "test/IECore/data/cobFiles/pCubeShape1.cob").read()

        op = IECoreScene.MeshVertexReorderOp()

        result = op(input=m, startingVertices=imath.V3i(0, 1, 3))

        self.assert_(result.arePrimitiveVariablesValid())
Esempio n. 7
0
    def testBoxTypes(self):

        p = Gaffer.CompoundDataPlug()

        for name, value in [
            ("b2f",
             IECore.Box2fData(imath.Box2f(imath.V2f(0, 1), imath.V2f(1, 2)))),
            ("b2i",
             IECore.Box2iData(imath.Box2i(imath.V2i(-1, 10), imath.V2i(11,
                                                                       20)))),
            ("b3f",
             IECore.Box3fData(
                 imath.Box3f(imath.V3f(0, 1, 2), imath.V3f(3, 4, 5)))),
            ("b3i",
             IECore.Box3iData(
                 imath.Box3i(imath.V3i(0, 1, 2), imath.V3i(3, 4, 5)))),
        ]:
            p.addChild(Gaffer.NameValuePlug(name, value))
            self.assertEqual(p.memberDataAndName(p[-1]), (value, name))
	def testInterleaveIntoV3( self ) :

		i = IECore.ObjectVector(

			[
				IECore.IntVectorData( [ 1, 2 ] ),
				IECore.IntVectorData( [ 11, 12 ] ),
				IECore.IntVectorData( [ 21, 22 ] ),
			]

		)

		o = IECore.DataInterleaveOp()( data=i, targetType = IECore.V3iVectorData.staticTypeId() )

		self.assertEqual(

			o,
			IECore.V3iVectorData( [ imath.V3i( 1, 11, 21 ), imath.V3i( 2, 12, 22 ), ] )

		)
Esempio n. 9
0
	def testVectorIntData( self ) :

		with IECoreArnold.UniverseBlock( writable = True ) as universe :

			n = arnold.AiNode( universe, "standard_surface" )

			IECoreArnold.ParameterAlgo.setParameter( n, "customV2i", IECore.V2iData( imath.V2i( 3, 4 ) ) )
			self.assertEqual( arnold.AiNodeGetVec2( n, "customV2i" ), arnold.AtVector2( 3, 4 ) )

			IECoreArnold.ParameterAlgo.setParameter( n, "customV3i", IECore.V3iData( imath.V3i( 3, 4, 5 ) ) )
			self.assertEqual( arnold.AiNodeGetVec( n, "customV3i" ), arnold.AtVector( 3, 4, 5 ) )
Esempio n. 10
0
    def testDefaultValueSerialisation(self):

        s = Gaffer.ScriptNode()
        s["s"] = Gaffer.Spreadsheet()
        s["s"]["rows"].addColumn(
            Gaffer.V3iPlug("c1", defaultValue=imath.V3i(1, 2, 3)))
        s["s"]["rows"].addColumn(
            Gaffer.Box2iPlug("c2",
                             defaultValue=imath.Box2i(imath.V2i(0),
                                                      imath.V2i(1))))
        s["s"]["rows"].addRows(3)

        # Change defaults for some plugs

        s["s"]["rows"][1]["name"].setValue("testName")
        s["s"]["rows"][1]["cells"]["c1"]["value"].setValue(imath.V3i(4, 5, 6))
        s["s"]["rows"][2]["enabled"].setValue(False)
        s["s"]["rows"][2]["cells"]["c1"]["value"]["x"].setValue(10)
        s["s"]["rows"][3]["cells"]["c1"]["enabled"].setValue(False)
        s["s"]["rows"][3]["cells"]["c2"]["value"].setValue(
            imath.Box2i(imath.V2i(10), imath.V2i(11)))
        s["s"]["rows"][1]["name"].resetDefault()

        # Change values for some plugs, some of which also had their
        # defaults changed.

        s["s"]["rows"][1]["name"].setValue("testName2")
        s["s"]["rows"][1]["cells"]["c1"]["value"]["x"].setValue(7)
        s["s"]["rows"][3]["enabled"].setValue(False)

        # Check that everything round-trips correctly through a serialisation and load.

        s2 = Gaffer.ScriptNode()
        s2.execute(s.serialise())

        self.assertEqual(s["s"]["rows"].defaultHash(),
                         s2["s"]["rows"].defaultHash())
        self.assertEqual(s["s"]["rows"].hash(), s2["s"]["rows"].hash())
Esempio n. 11
0
    def testCanReadDoubleMetadata(self):
        sourcePath = os.path.join(self.dataDir, "sphere.vdb")
        vdb = IECoreVDB.VDBObject(sourcePath)

        grid = vdb.findGrid("ls_sphere")
        grid.updateMetadata({"test": 0.0})
        vdb.insertGrid(grid)

        metadata = vdb.metadata("ls_sphere")

        # skip the file size
        del metadata['file_mem_bytes']

        expected = IECore.CompoundObject({
            'name':
            IECore.StringData('ls_sphere'),
            'file_voxel_count':
            IECore.Int64Data(270638),
            'file_bbox_min':
            IECore.V3iData(imath.V3i(-62, -62, -62)),
            'file_bbox_max':
            IECore.V3iData(imath.V3i(62, 62, 62)),
            'is_local_space':
            IECore.BoolData(0),
            'is_saved_as_half_float':
            IECore.BoolData(1),
            'value_type':
            IECore.StringData('float'),
            'class':
            IECore.StringData('level set'),
            #'file_mem_bytes': IECore.Int64Data( 2643448 ),
            'vector_type':
            IECore.StringData('invariant'),
            'test':
            IECore.DoubleData(0.0)
        })

        self.assertEqual(metadata, expected)
Esempio n. 12
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.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() )
Esempio n. 13
0
    def testSphere(self):

        m = IECore.Reader.create(
            "test/IECore/data/cobFiles/pSphereShape1.cob").read()

        op = IECoreScene.MeshVertexReorderOp()

        result = op(input=m, startingVertices=imath.V3i(20, 1, 21))

        self.assert_(result.arePrimitiveVariablesValid())

        expected = IECore.Reader.create(
            "test/IECore/data/expectedResults/meshVertexReorderSphere.cob"
        ).read()

        self.assertEqual(result, expected)
Esempio n. 14
0
    def testConstructors(self):
        """Test V2f constructors"""
        v = imath.V2f()
        v = imath.V2f(1)
        self.assertEqual(v.x, 1)
        self.assertEqual(v.y, 1)
        v = imath.V2f(2, 3)
        self.assertEqual(v.x, 2)
        self.assertEqual(v.y, 3)

        self.assertEqual(imath.V2f(imath.V2i(1, 2)), imath.V2f(1, 2))
        self.assertEqual(imath.V2f(imath.V2f(1, 2)), imath.V2f(1, 2))
        self.assertEqual(imath.V2f(imath.V2d(1, 2)), imath.V2f(1, 2))

        self.assertEqual(imath.V2d(imath.V2i(1, 2)), imath.V2d(1, 2))
        self.assertEqual(imath.V2d(imath.V2f(1, 2)), imath.V2d(1, 2))
        self.assertEqual(imath.V2d(imath.V2d(1, 2)), imath.V2d(1, 2))

        self.assertEqual(imath.V2i(imath.V2i(1, 2)), imath.V2i(1, 2))
        self.assertEqual(imath.V2i(imath.V2f(1, 2)), imath.V2i(1, 2))
        self.assertEqual(imath.V2i(imath.V2d(1, 2)), imath.V2i(1, 2))

        self.assertEqual(imath.V3f(imath.V3i(1, 2, 3)), imath.V3f(1, 2, 3))
        self.assertEqual(imath.V3f(imath.V3f(1, 2, 3)), imath.V3f(1, 2, 3))
        self.assertEqual(imath.V3f(imath.V3d(1, 2, 3)), imath.V3f(1, 2, 3))

        self.assertEqual(imath.V3d(imath.V3i(1, 2, 3)), imath.V3d(1, 2, 3))
        self.assertEqual(imath.V3d(imath.V3f(1, 2, 3)), imath.V3d(1, 2, 3))
        self.assertEqual(imath.V3d(imath.V3d(1, 2, 3)), imath.V3d(1, 2, 3))

        self.assertEqual(imath.V3i(imath.V3i(1, 2, 3)), imath.V3i(1, 2, 3))
        self.assertEqual(imath.V3i(imath.V3f(1, 2, 3)), imath.V3i(1, 2, 3))
        self.assertEqual(imath.V3i(imath.V3d(1, 2, 3)), imath.V3i(1, 2, 3))

        v = imath.V2f([1, 1])
        self.assertEqual(v.x, 1)
        self.assertEqual(v.y, 1)

        self.assertRaises(RuntimeError, imath.V2f, [1])
        self.assertRaises(RuntimeError, imath.V2f, [1, 2, 3])
Esempio n. 15
0
    def test(self):

        for v in [
                imath.V2i(1),
                imath.V2f(1),
                imath.V2d(1.5),
                imath.V3i(1),
                imath.V3f(1),
                imath.V3d(1.5),
                imath.Box2i(),
                imath.Box2i(imath.V2i(1), imath.V2i(1)),
                imath.Box2f(imath.V2f(-1), imath.V2f(1)),
                imath.Box2f(),
                imath.Box3f(imath.V3f(-1), imath.V3f(1)),
                imath.Box3f(), "test", 10, 10.5
        ]:
            self.assertTrue(type(v) is type(eval(IECore.repr(v))))
            self.assertEqual(v, eval(IECore.repr(v)))
	def testVectors( self ) :

		fileName = os.path.join( self.temporaryDirectory(), "attributes.scc" )
		scene = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.Write )
		child = scene.createChild( "child" )
		for name, value in [
			( "v2f", IECore.V2fData( imath.V2f( 1, 2 ) ) ),
			( "v3f", IECore.V3fData( imath.V3f( 3, 4, 5 ) ) ),
			( "v2i", IECore.V2iData( imath.V2i( 6, 7 ) ) ),
			( "v3i", IECore.V3iData( imath.V3i( 8, 9, 10 ) ) ),
			( "v2d", IECore.V2dData( imath.V2d( 11, 12 ) ) ),
			( "v3d", IECore.V3dData( imath.V3d( 13, 14, 15 ) ) ),
		] :
			child.writeAttribute( name, value, 1 )
		del scene, child

		sceneReader = GafferScene.SceneReader()
		sceneReader["fileName"].setValue( fileName )

		childFilter = GafferScene.PathFilter()
		childFilter["paths"].setValue( IECore.StringVectorData( [ "/child" ] ) )

		visualiser = GafferScene.AttributeVisualiser()
		visualiser["in"].setInput( sceneReader["out"] )
		visualiser["filter"].setInput( childFilter["out"] )

		for name, value in [
			( "v2f", imath.Color3f( 1, 2, 0 ) ),
			( "v3f", imath.Color3f( 3, 4, 5 ) ),
			( "v2i", imath.Color3f( 6, 7, 0 ) ),
			( "v3i", imath.Color3f( 8, 9, 10 ) ),
			( "v2d", imath.Color3f( 11, 12, 0 ) ),
			( "v3d", imath.Color3f( 13, 14, 15 ) ),
		] :

			visualiser["attributeName"].setValue( name )
			self.assertEqual(
				visualiser["out"].attributes( "/child" )["gl:surface"].outputShader().parameters["Cs"].value,
				value,
			)
Esempio n. 17
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
	def mesh( self ) :
		vertsPerFace = IECore.IntVectorData( [ 4, 4, 4, 4, 4, 4 ] )
		vertexIds = IECore.IntVectorData( [ 1, 5, 4, 0, 2, 6, 5, 1, 3, 7, 6, 2, 0, 4, 7, 3, 2, 1, 0, 3, 5, 6, 7, 4 ] )
		mesh = IECoreScene.MeshPrimitive( vertsPerFace, vertexIds )

		floatData = IECore.FloatData( 1.5 )
		v2fData = IECore.V2fData( imath.V2f( 1.5, 2.5 ), IECore.GeometricData.Interpretation.Vector )
		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" )

		intRange = range( 1, 25 )
		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 ], IECore.GeometricData.Interpretation.Normal )
		color3fVectorData = IECore.Color3fVectorData( [ imath.Color3f( x, 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 ] )

		detailInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Constant
		pointInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Vertex
		primitiveInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Uniform
		vertexInterpolation = IECoreScene.PrimitiveVariable.Interpolation.FaceVarying

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

		# add all valid point attrib types
		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 ),
		], IECore.GeometricData.Interpretation.Point )
		mesh["P"] = IECoreScene.PrimitiveVariable( pointInterpolation, pData )
		mesh["floatPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, floatVectorData[:8] )
		mesh["v2fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v2fVectorData[:8] )
		mesh["v3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3fVectorData[:8] )
		mesh["color3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, color3fVectorData[:8] )
		mesh["intPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, intVectorData[:8] )
		mesh["v2iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v2iVectorData[:8] )
		mesh["v3iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3iVectorData[:8] )
		mesh["stringPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, stringVectorData[:8], IECore.IntVectorData( range( 0, 8 ) ) )

		# add all valid primitive attrib types
		mesh["floatPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, floatVectorData[:6] )
		mesh["v2fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v2fVectorData[:6] )
		mesh["v3fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v3fVectorData[:6] )
		mesh["color3fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, color3fVectorData[:6] )
		mesh["intPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, intVectorData[:6] )
		mesh["v2iPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v2iVectorData[:6] )
		mesh["v3iPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v3iVectorData[:6] )
		mesh["stringPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, stringVectorData[:6], IECore.IntVectorData( range( 0, 6 ) ) )

		# add all valid vertex attrib types
		mesh["floatVert"] = IECoreScene.PrimitiveVariable( vertexInterpolation, floatVectorData )
		mesh["v2fVert"] = IECoreScene.PrimitiveVariable( vertexInterpolation, v2fVectorData )
		mesh["v3fVert"] = IECoreScene.PrimitiveVariable( vertexInterpolation, v3fVectorData )
		mesh["color3fVert"] = IECoreScene.PrimitiveVariable( vertexInterpolation, color3fVectorData )
		mesh["intVert"] = IECoreScene.PrimitiveVariable( vertexInterpolation, intVectorData )
		mesh["v2iVert"] = IECoreScene.PrimitiveVariable( vertexInterpolation, v2iVectorData )
		mesh["v3iVert"] = IECoreScene.PrimitiveVariable( vertexInterpolation, v3iVectorData )
		mesh["stringVert"] = IECoreScene.PrimitiveVariable( vertexInterpolation, stringVectorData, IECore.IntVectorData( range( 0, 24 ) ) )

		return mesh
Esempio n. 19
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))
        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")

        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])
        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 %d!" % x for x in intRange])

        detailInterpolation = IECoreScene.PrimitiveVariable.Interpolation.Constant
        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)

        # 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["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.blindData()['name'] = "pointsGroup"

        return points
Esempio n. 20
0
    def testContextChangedAndGIL(self):

        script = Gaffer.ScriptNode()

        script["plane"] = GafferScene.Plane()
        script["plane"]["divisions"].setValue(imath.V2i(20))

        script["sphere"] = GafferScene.Sphere()

        script["expression"] = Gaffer.Expression()
        script["expression"].setExpression(
            "parent['sphere']['radius'] = context.get( 'minRadius', 0.1 ) + context.getFrame()"
        )

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

        context = Gaffer.Context()
        traverseConnection = Gaffer.ScopedConnection(
            GafferSceneTest.connectTraverseSceneToContextChangedSignal(
                script["instancer"]["out"], context))
        with context:

            context.setFrame(10)
            context.setFramesPerSecond(50)
            context.setTime(1)

            context.set("a", 1)
            context.set("a", 2.0)
            context.set("a", "a")
            context.set("a", imath.V2i())
            context.set("a", imath.V3i())
            context.set("a", imath.V2f())
            context.set("a", imath.V3f())
            context.set("a", imath.Color3f())
            context.set("a", IECore.BoolData(True))

            context["b"] = 1
            context["b"] = 2.0
            context["b"] = "b"
            context["b"] = imath.V2i()
            context["b"] = imath.V3i()
            context["b"] = imath.V2f()
            context["b"] = imath.V3f()
            context["b"] = imath.Color3f()
            context["b"] = IECore.BoolData(True)

            with Gaffer.BlockedConnection(traverseConnection):
                # Must add it with the connection disabled, otherwise
                # the addition causes a traversal, and then remove() gets
                # all its results from the cache.
                context["minRadius"] = 0.2

            context.remove("minRadius")

            with Gaffer.BlockedConnection(traverseConnection):
                context["minRadius"] = 0.3

            del context["minRadius"]
Esempio n. 21
0
    def testPlane(self):

        verticesPerFace = IECore.IntVectorData()

        vertexIds = IECore.IntVectorData()

        verticesPerFace.append(3)
        vertexIds.append(0)
        vertexIds.append(1)
        vertexIds.append(2)

        verticesPerFace.append(3)
        vertexIds.append(1)
        vertexIds.append(3)
        vertexIds.append(2)

        m = IECoreScene.MeshPrimitive(verticesPerFace, vertexIds)

        p = IECore.V3fVectorData()
        p.append(imath.V3f(-1, -1, 0))
        p.append(imath.V3f(1, -1, 0))
        p.append(imath.V3f(-1, 1, 0))
        p.append(imath.V3f(1, 1, 0))

        s = IECore.FloatVectorData()
        s.append(0)
        s.append(1)
        s.append(0)

        s.append(1)
        s.append(1)
        s.append(0)

        t = IECore.FloatVectorData()
        t.append(0)
        t.append(0)
        t.append(1)

        t.append(0)
        t.append(1)
        t.append(1)

        uni = IECore.IntVectorData()
        uni.append(0)
        uni.append(1)

        m["P"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Vertex, p)
        m["s"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying, s)
        m["t"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.FaceVarying, t)
        m["uni"] = IECoreScene.PrimitiveVariable(
            IECoreScene.PrimitiveVariable.Interpolation.Uniform, uni)

        self.assert_(m.arePrimitiveVariablesValid())

        op = IECoreScene.MeshVertexReorderOp()

        result = op(input=m, startingVertices=imath.V3i(2, 3, 1))

        expectedVerticesPerFace = IECore.IntVectorData()
        expectedVerticesPerFace.append(3)
        expectedVerticesPerFace.append(3)

        self.assertEqual(result.verticesPerFace, expectedVerticesPerFace)

        expectedVertexIds = IECore.IntVectorData()
        expectedVertexIds.append(0)
        expectedVertexIds.append(1)
        expectedVertexIds.append(2)
        expectedVertexIds.append(0)
        expectedVertexIds.append(2)
        expectedVertexIds.append(3)

        self.assertEqual(result.vertexIds, expectedVertexIds)

        expectedP = IECore.V3fVectorData()
        expectedP.append(imath.V3f(-1, 1, 0))
        expectedP.append(imath.V3f(1, 1, 0))
        expectedP.append(imath.V3f(1, -1, 0))
        expectedP.append(imath.V3f(-1, -1, 0))

        self.assertEqual(result["P"].data, expectedP)

        expectedS = IECore.FloatVectorData()
        expectedS.append(0)
        expectedS.append(1)
        expectedS.append(1)

        expectedS.append(0)
        expectedS.append(1)
        expectedS.append(0)

        self.assertEqual(result["s"].data, expectedS)

        expectedT = IECore.FloatVectorData()
        expectedT.append(1)
        expectedT.append(1)
        expectedT.append(0)

        expectedT.append(1)
        expectedT.append(0)
        expectedT.append(0)

        self.assertEqual(result["t"].data, expectedT)

        expectedUni = IECore.IntVectorData()
        expectedUni.append(1)
        expectedUni.append(0)

        self.assertEqual(result["uni"].data, expectedUni)

        self.assert_(result.arePrimitiveVariablesValid())
Esempio n. 22
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)
Esempio n. 23
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))
    def testBoxTypes(self):

        p = IECore.Parameterised("")

        p.parameters().addParameters([
            IECore.Box3iParameter(
                "b",
                "",
                imath.Box3i(
                    imath.V3i(-1, -2, -3),
                    imath.V3i(2, 1, 3),
                ),
            )
        ])

        ph = GafferCortex.ParameterisedHolderNode()
        ph.setParameterised(p)

        self.assertIsInstance(ph["parameters"]["b"], Gaffer.Box3iPlug)
        self.assertIsInstance(ph["parameters"]["b"]["min"], Gaffer.V3iPlug)
        self.assertIsInstance(ph["parameters"]["b"]["max"], Gaffer.V3iPlug)

        self.assertEqual(ph["parameters"]["b"]["min"].getValue(),
                         imath.V3i(-1, -2, -3))
        self.assertEqual(ph["parameters"]["b"]["max"].getValue(),
                         imath.V3i(2, 1, 3))

        ph["parameters"]["b"]["min"].setValue(imath.V3i(-10, -20, -30))
        ph["parameters"]["b"]["max"].setValue(imath.V3i(10, 20, 30))

        ph.parameterHandler().setParameterValue()

        self.assertEqual(
            p["b"].getTypedValue(),
            imath.Box3i(imath.V3i(-10, -20, -30), imath.V3i(10, 20, 30)))

        with ph.parameterModificationContext():

            p["b"].setTypedValue(
                imath.Box3i(imath.V3i(-2, -4, -6), imath.V3i(2, 4, 6)))

        self.assertEqual(ph["parameters"]["b"]["min"].getValue(),
                         imath.V3i(-2, -4, -6))
        self.assertEqual(ph["parameters"]["b"]["max"].getValue(),
                         imath.V3i(2, 4, 6))
    def __addMenuDefinition(self):

        result = IECore.MenuDefinition()
        result.append(
            "/Add/Bool", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.BoolData(False))
            })
        result.append(
            "/Add/Float", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.FloatData(0))
            })
        result.append(
            "/Add/Int", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.IntData(0))
            })
        result.append("/Add/NumericDivider", {"divider": True})

        result.append(
            "/Add/String", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.StringData(""))
            })
        result.append("/Add/StringDivider", {"divider": True})

        result.append(
            "/Add/V2i/Vector", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2iData(imath.V2i(0),
                                   IECore.GeometricData.Interpretation.Vector))
            })
        result.append(
            "/Add/V2i/Normal", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2iData(imath.V2i(0),
                                   IECore.GeometricData.Interpretation.Normal))
            })
        result.append(
            "/Add/V2i/Point", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2iData(imath.V2i(0),
                                   IECore.GeometricData.Interpretation.Point))
            })

        result.append(
            "/Add/V3i/Vector", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3iData(imath.V3i(0),
                                   IECore.GeometricData.Interpretation.Vector))
            })
        result.append(
            "/Add/V3i/Normal", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3iData(imath.V3i(0),
                                   IECore.GeometricData.Interpretation.Normal))
            })
        result.append(
            "/Add/V3i/Point", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3iData(imath.V3i(0),
                                   IECore.GeometricData.Interpretation.Point))
            })

        result.append(
            "/Add/V2f/Vector", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2fData(imath.V2f(0),
                                   IECore.GeometricData.Interpretation.Vector))
            })
        result.append(
            "/Add/V2f/Normal", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2fData(imath.V2f(0),
                                   IECore.GeometricData.Interpretation.Normal))
            })
        result.append(
            "/Add/V2f/Point", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V2fData(imath.V2f(0),
                                   IECore.GeometricData.Interpretation.Point))
            })

        result.append(
            "/Add/V3f/Vector", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3fData(imath.V3f(0),
                                   IECore.GeometricData.Interpretation.Vector))
            })
        result.append(
            "/Add/V3f/Normal", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3fData(imath.V3f(0),
                                   IECore.GeometricData.Interpretation.Normal))
            })
        result.append(
            "/Add/V3f/Point", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.V3fData(imath.V3f(0),
                                   IECore.GeometricData.Interpretation.Point))
            })

        result.append("/Add/VectorDivider", {"divider": True})

        result.append(
            "/Add/Color3f", {
                "command":
                functools.partial(Gaffer.WeakMethod(self.__addItem), "",
                                  IECore.Color3fData(imath.Color3f(0)))
            })
        result.append(
            "/Add/Color4f", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Color4fData(imath.Color4f(0, 0, 0, 1)))
            })

        result.append("/Add/BoxDivider", {"divider": True})

        result.append(
            "/Add/Box2i", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Box2iData(imath.Box2i(imath.V2i(0), imath.V2i(1))))
            })
        result.append(
            "/Add/Box2f", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Box2fData(imath.Box2f(imath.V2f(0), imath.V2f(1))))
            })
        result.append(
            "/Add/Box3i", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Box3iData(imath.Box3i(imath.V3i(0), imath.V3i(1))))
            })
        result.append(
            "/Add/Box3f", {
                "command":
                functools.partial(
                    Gaffer.WeakMethod(self.__addItem), "",
                    IECore.Box3fData(imath.Box3f(imath.V3f(0), imath.V3f(1))))
            })

        result.append("/Add/BoxDivider", {"divider": True})

        for label, plugType in [
            ("Float", Gaffer.FloatVectorDataPlug),
            ("Int", Gaffer.IntVectorDataPlug),
            ("NumericDivider", None),
            ("String", Gaffer.StringVectorDataPlug),
        ]:
            if plugType is not None:
                result.append(
                    "/Add/Array/" + label, {
                        "command":
                        IECore.curry(Gaffer.WeakMethod(self.__addItem), "",
                                     plugType.ValueType())
                    })
            else:
                result.append("/Add/Array/" + label, {"divider": True})

        return result
Esempio n. 26
0
	def curves( self, basis=IECore.CubicBasisf.linear(), periodic=False, numCurves=4 ) :
		vertsPerCurve = IECore.IntVectorData()
		pData = IECore.V3fVectorData()
		pData.setInterpretation( IECore.GeometricData.Interpretation.Point )

		for i in range( 0, numCurves ) :
			p = TestToHoudiniCurvesConverter.__curveCoordinates[i%4]

			if not periodic and basis == IECore.CubicBasisf.bSpline() :
				vertsPerCurve.append( len(p) + 4 )
			else :
				vertsPerCurve.append( len(p) )

			pData.extend( p )

		curves = IECoreScene.CurvesPrimitive( vertsPerCurve, basis, periodic )

		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 ) )
		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" )

		intRange = range( 1, pData.size()+1 )
		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 ] )
		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 ] )

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

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

		# add all valid point attrib types
		if not periodic and basis == IECore.CubicBasisf.bSpline() :

			modPData = IECore.V3fVectorData()
			modPData.setInterpretation( IECore.GeometricData.Interpretation.Point )
			floatPointData = IECore.FloatVectorData()
			v2fPointData = IECore.V2fVectorData()
			v3fPointData = IECore.V3fVectorData()
			color3fPointData = IECore.Color3fVectorData()
			intPointData = IECore.IntVectorData()
			v2iPointData = IECore.V2iVectorData()
			v3iPointData = IECore.V3iVectorData()
			stringPointData = IECore.StringVectorData()

			datas = [ modPData, floatPointData, v2fPointData, v3fPointData, color3fPointData, intPointData, v2iPointData, v3iPointData, stringPointData ]
			rawDatas = [ pData, floatVectorData, v2fVectorData, v3fVectorData, color3fVectorData, intVectorData, v2iVectorData, v3iVectorData, stringVectorData ]

			pIndex = 0
			for i in range( 0, numCurves ) :
				for j in range( 0, len(datas) ) :
					index = 8*i
					datas[j].extend( [ rawDatas[j][index], rawDatas[j][index] ] )
					datas[j].extend( rawDatas[j][index:index+8] )
					datas[j].extend( [ rawDatas[j][index+7], rawDatas[j][index+7] ] )

			curves["P"] = IECoreScene.PrimitiveVariable( pointInterpolation, modPData )
			curves["floatPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, floatPointData )
			curves["v2fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation,v2fPointData )
			curves["v3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3fPointData )
			curves["color3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, color3fPointData )
			curves["intPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, intPointData )
			curves["v2iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v2iPointData )
			curves["v3iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3iPointData )
		else :
			curves["P"] = IECoreScene.PrimitiveVariable( pointInterpolation, pData )
			curves["floatPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, floatVectorData[:8*numCurves] )
			curves["v2fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v2fVectorData[:8*numCurves] )
			curves["v3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3fVectorData[:8*numCurves] )
			curves["color3fPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, color3fVectorData[:8*numCurves] )
			curves["intPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, intVectorData[:8*numCurves] )
			curves["v2iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v2iVectorData[:8*numCurves] )
			curves["v3iPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, v3iVectorData[:8*numCurves] )
			curves["stringPoint"] = IECoreScene.PrimitiveVariable( pointInterpolation, stringVectorData[:8*numCurves], IECore.IntVectorData( range( 0, 8*numCurves ) ) )

		# add all valid primitive attrib types
		curves["floatPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, floatVectorData[:numCurves] )
		curves["v2fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v2fVectorData[:numCurves] )
		curves["v3fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v3fVectorData[:numCurves] )
		curves["color3fPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, color3fVectorData[:numCurves] )
		curves["intPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, intVectorData[:numCurves] )
		curves["v2iPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v2iVectorData[:numCurves] )
		curves["v3iPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, v3iVectorData[:numCurves] )
		curves["stringPrim"] = IECoreScene.PrimitiveVariable( primitiveInterpolation, stringVectorData[:numCurves], IECore.IntVectorData( range( 0, numCurves ) ) )

		self.assertTrue( curves.arePrimitiveVariablesValid() )

		return curves
Esempio n. 27
0
    def testPointAttributes(self):
        attr = self.testSetupAttributes()

        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        attr.parm("value1").set(123.456)
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.FloatVectorData)
        self.assert_(result["test_attribute"].data[0] > 123.0)
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # integer
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.IntVectorData)
        self.assertEqual(result["test_attribute"].data[0], 123)
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(0)  # float
        attr.parm("size").set(2)  # 2 elementS
        attr.parm("value2").set(456.789)
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V2fVectorData)
        self.assertEqual(result["test_attribute"].data[0],
                         imath.V2f(123.456, 456.789))
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # int
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V2iVectorData)
        self.assertEqual(result["test_attribute"].data[0], imath.V2i(123, 456))
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(0)  # float
        attr.parm("size").set(3)  # 3 elements
        attr.parm("value3").set(999.999)
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V3fVectorData)
        self.assertEqual(result["test_attribute"].data[0],
                         imath.V3f(123.456, 456.789, 999.999))
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(1)  # int
        result = IECoreHoudini.FromHoudiniPolygonsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.V3iVectorData)
        self.assertEqual(result["test_attribute"].data[0],
                         imath.V3i(123, 456, 999))
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assert_(result.arePrimitiveVariablesValid())

        attr.parm("type").set(3)  # string
        attr.parm("string").setExpression(
            "'string %06d!' % pwd().curPoint().number()",
            hou.exprLanguage.Python)
        result = IECoreHoudini.FromHoudiniPointsConverter(attr).convert()
        self.assertEqual(result["test_attribute"].data.typeId(),
                         IECore.TypeId.StringVectorData)
        self.assertEqual(result["test_attribute"].data[10], "string 000010!")
        self.assertEqual(result["test_attribute"].data.size(), 100)
        self.assertEqual(result["test_attribute"].interpolation,
                         IECoreScene.PrimitiveVariable.Interpolation.Vertex)
        self.assertEqual(result["test_attribute"].indices[10], 10)
        self.assertEqual(result["test_attribute"].indices.size(), 100)
        self.assert_(result.arePrimitiveVariablesValid())
Esempio n. 28
0
    def testResetDefault(self):

        script = Gaffer.ScriptNode()

        script["node"] = Gaffer.Node()
        script["node"]["user"]["i"] = Gaffer.IntPlug(
            defaultValue=1,
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)
        script["node"]["user"]["v"] = Gaffer.V3iPlug(
            defaultValue=imath.V3i(1, 2, 3),
            flags=Gaffer.Plug.Flags.Default | Gaffer.Plug.Flags.Dynamic)

        def assertPreconditions(script):

            self.assertTrue(script["node"]["user"]["i"].isSetToDefault())
            self.assertEqual(script["node"]["user"]["i"].defaultValue(), 1)
            self.assertEqual(script["node"]["user"]["i"].getValue(), 1)

            self.assertTrue(script["node"]["user"]["v"].isSetToDefault())
            self.assertEqual(script["node"]["user"]["v"].defaultValue(),
                             imath.V3i(1, 2, 3))
            self.assertEqual(script["node"]["user"]["v"].getValue(),
                             imath.V3i(1, 2, 3))

        assertPreconditions(script)

        with Gaffer.UndoScope(script):

            script["node"]["user"]["i"].setValue(2)
            script["node"]["user"]["i"].resetDefault()

            script["node"]["user"]["v"].setValue(imath.V3i(10, 11, 12))
            script["node"]["user"]["v"].resetDefault()

        def assertPostconditions(script):

            self.assertTrue(script["node"]["user"]["i"].isSetToDefault())
            self.assertEqual(script["node"]["user"]["i"].defaultValue(), 2)
            self.assertEqual(script["node"]["user"]["i"].getValue(), 2)

            self.assertTrue(script["node"]["user"]["v"].isSetToDefault())
            self.assertEqual(script["node"]["user"]["v"].defaultValue(),
                             imath.V3i(10, 11, 12))
            self.assertEqual(script["node"]["user"]["v"].getValue(),
                             imath.V3i(10, 11, 12))

        script.undo()
        assertPreconditions(script)

        script.redo()
        assertPostconditions(script)

        script.undo()
        assertPreconditions(script)

        script.redo()
        assertPostconditions(script)

        script2 = Gaffer.ScriptNode()
        script2.execute(script.serialise())
        assertPostconditions(script2)
Esempio n. 29
0
    def testTypes(self):

        c = Gaffer.Context()

        c["int"] = 1
        self.assertEqual(c["int"], 1)
        self.assertEqual(c.get("int"), 1)
        compare = c.hash()
        c.set("int", 2)
        self.assertEqual(c["int"], 2)
        self.assertIsInstance(c["int"], int)
        self.assertNotEqual(compare, c.hash())

        c["float"] = 1.0
        self.assertEqual(c["float"], 1.0)
        self.assertEqual(c.get("float"), 1.0)
        compare = c.hash()
        c.set("float", 2.0)
        self.assertEqual(c["float"], 2.0)
        self.assertIsInstance(c["float"], float)
        self.assertNotEqual(compare, c.hash())

        c["string"] = "hi"
        self.assertEqual(c["string"], "hi")
        self.assertEqual(c.get("string"), "hi")
        compare = c.hash()
        c.set("string", "bye")
        self.assertEqual(c["string"], "bye")
        self.assertIsInstance(c["string"], str)
        self.assertNotEqual(compare, c.hash())

        c["v2i"] = imath.V2i(1, 2)
        self.assertEqual(c["v2i"], imath.V2i(1, 2))
        self.assertEqual(c.get("v2i"), imath.V2i(1, 2))
        compare = c.hash()
        c.set("v2i", imath.V2i(3, 4))
        self.assertEqual(c["v2i"], imath.V2i(3, 4))
        self.assertIsInstance(c["v2i"], imath.V2i)
        self.assertNotEqual(compare, c.hash())

        c["v3i"] = imath.V3i(1, 2, 3)
        self.assertEqual(c["v3i"], imath.V3i(1, 2, 3))
        self.assertEqual(c.get("v3i"), imath.V3i(1, 2, 3))
        compare = c.hash()
        c.set("v3i", imath.V3i(4, 5, 6))
        self.assertEqual(c["v3i"], imath.V3i(4, 5, 6))
        self.assertIsInstance(c["v3i"], imath.V3i)
        self.assertNotEqual(compare, c.hash())

        c["v2f"] = imath.V2f(1, 2)
        self.assertEqual(c["v2f"], imath.V2f(1, 2))
        self.assertEqual(c.get("v2f"), imath.V2f(1, 2))
        compare = c.hash()
        c.set("v2f", imath.V2f(3, 4))
        self.assertEqual(c["v2f"], imath.V2f(3, 4))
        self.assertIsInstance(c["v2f"], imath.V2f)
        self.assertNotEqual(compare, c.hash())

        c["v3f"] = imath.V3f(1, 2, 3)
        self.assertEqual(c["v3f"], imath.V3f(1, 2, 3))
        self.assertEqual(c.get("v3f"), imath.V3f(1, 2, 3))
        compare = c.hash()
        c.set("v3f", imath.V3f(4, 5, 6))
        self.assertEqual(c["v3f"], imath.V3f(4, 5, 6))
        self.assertIsInstance(c["v3f"], imath.V3f)
        self.assertNotEqual(compare, c.hash())
Esempio n. 30
0
    def __init__(self):

        IECore.Op.__init__(
            self, "test all parameter types.",
            IECore.IntParameter(
                name="result",
                description="one if everything is ok",
                defaultValue=0,
            ))

        self.parameters().addParameters([
            IECore.IntParameter(
                name="a",
                description=
                "An int which has a very long description to help test the help formatting. i wonder if there's anything more interesting i could write here.",
                defaultValue=1,
            ),
            IECore.FloatParameter(
                name="b",
                description=
                "A float which has a very long description to help test the help formatting. i wonder if there's anything more interesting i could write here.",
                defaultValue=2,
            ),
            IECore.DoubleParameter(
                name="c",
                description="A double",
                defaultValue=3,
            ),
            IECore.StringParameter(
                name="d",
                description="A string",
                defaultValue="ssss",
            ),
            IECore.IntVectorParameter(
                name="e",
                description="An array of ints",
                defaultValue=IECore.IntVectorData([4, -1, 2]),
            ),
            IECore.StringVectorParameter(
                name="f",
                description="An array of strings",
                defaultValue=IECore.StringVectorData(["one", "two", "three"]),
            ),
            IECore.V2fParameter(
                name="g",
                description="A v2f",
                defaultValue=IECore.V2fData(imath.V2f(1, 2)),
            ),
            IECore.V3fParameter(name="h",
                                description="a v3f",
                                defaultValue=IECore.V3fData(imath.V3f(1, 1,
                                                                      1)),
                                presets=(("x", imath.V3f(1, 0, 0)),
                                         ("y", imath.V3f(0, 1, 0)),
                                         ("z", imath.V3f(0, 0, 1)))),
            IECore.V2dParameter(
                name="i",
                description="a v2d",
                defaultValue=IECore.V2dData(imath.V2d(1, 1)),
            ),
            IECore.CompoundParameter(
                name="compound",
                description="a compound parameter",
                members=[
                    IECore.V3dParameter(name="j",
                                        description="a v3d",
                                        defaultValue=IECore.V3dData(
                                            imath.V3d(8, 16, 32)),
                                        presets=(("one", imath.V3d(1)),
                                                 ("two", imath.V3d(2)))),
                    IECore.M44fParameter(name="k",
                                         description="an m44f",
                                         defaultValue=IECore.M44fData(),
                                         presets=(("one", imath.M44f(1)),
                                                  ("two", imath.M44f(2)))),
                ]),
            IECore.Color3fParameter(
                name="l",
                description="a color3f",
                defaultValue=IECore.Color3fData(imath.Color3f(1, 0, 1)),
            ),
            IECore.Color4fParameter(
                name="m",
                description="a color4f",
                defaultValue=IECore.Color4fData(imath.Color4f(1, 0, 1, 0.5)),
            ),
            IECore.FileNameParameter(
                name="o",
                description="tif file please!",
                defaultValue="",
                extensions="tif",
                allowEmptyString=True,
            ),
            IECore.DirNameParameter(
                name="p",
                description="directory please!",
                defaultValue="",
                check=IECore.DirNameParameter.CheckType.MustExist,
                allowEmptyString=True,
            ),
            IECore.BoolParameter(
                name="q",
                description="blah",
                defaultValue=False,
            ),
            IECore.FileSequenceParameter(name="r",
                                         description="File sequence please!",
                                         defaultValue=""),
            IECore.Box2dParameter(name="s",
                                  description="boxboxbox",
                                  defaultValue=imath.Box2d(
                                      imath.V2d(-1), imath.V2d(1))),
            IECore.Box3fParameter(name="t",
                                  description="boxboxbox",
                                  defaultValue=imath.Box3f(
                                      imath.V3f(-1), imath.V3f(1))),
            IECore.V2iParameter(
                name="u",
                description="A v2i",
                defaultValue=IECore.V2iData(imath.V2i(2, 2)),
            ),
            IECore.V3iParameter(
                name="v",
                description="A v3i",
                defaultValue=IECore.V3iData(imath.V3i(5, 5, 5)),
            ),
            IECore.FrameListParameter(
                name="w",
                description="A FrameList",
                defaultValue="",
            ),
            IECore.TransformationMatrixfParameter(
                name="x",
                description="",
                defaultValue=IECore.TransformationMatrixf(),
            ),

            # We'd like to have one with a non-standard rotation order
            # here, but they're not currently supported in Maya.
            IECore.TransformationMatrixdParameter(
                name="y",
                description="",
                defaultValue=IECore.TransformationMatrixd(),
            ),
            IECore.ObjectParameter(name="p1",
                                   description="",
                                   defaultValue=IECore.CompoundObject(),
                                   types=[IECore.TypeId.CompoundObject]),
            IECore.LineSegment3fParameter(name="p2",
                                          description="",
                                          defaultValue=IECore.LineSegment3f(
                                              imath.V3f(1), imath.V3f(2))),
            IECore.LineSegment3dParameter(name="p3",
                                          description="",
                                          defaultValue=IECore.LineSegment3d(
                                              imath.V3d(1), imath.V3d(2))),
            IECore.DateTimeParameter(name="p4",
                                     description="",
                                     defaultValue=datetime.datetime.now()),
        ])