コード例 #1
0
def testBuf():

    # test1
    b = n.IntBuffer()
    assert (len(b) == 0)

    # test2
    b = n.IntBuffer(10, 7)
    assert (b[3] == 7)

    # test3
    b = n.IntBuffer(3, 2)
    assert (b.contents == [2, 2, 2])

    # test4
    b = n.IntBuffer(4, 6)
    b2 = b.clone()
    assert (b2.contents == [6, 6, 6, 6])
    b2[0] = 7
    assert (b2.contents == [7, 6, 6, 6])

    # test5
    b = n.IntBuffer(10)
    assert (len(b) == 10)
    b[9] = 100
    assert (b[9] == 100)

    fail = False
    try:
        b[10]
    except IndexError:
        fail = True
    assert (fail)
コード例 #2
0
def testBufCloning():
    sz = 10
    b = n.IntBuffer(sz)
    b[4] = 40
    b2 = b.clone()
    assert (b.hasSharedStore(b2))
    assert (not b.uniqueStore())
    assert (not b2.uniqueStore())
    assert (b.storeUseCount() == 2)
    assert (b2.storeUseCount() == 2)

    b3 = b2.clone()
    assert (b3.hasSharedStore(b))
    assert (not b.uniqueStore())
    assert (not b2.uniqueStore())
    assert (not b3.uniqueStore())
    assert (b.storeUseCount() == 3)
    assert (b2.storeUseCount() == 3)
    assert (b3.storeUseCount() == 3)

    b[6] = 66  # will cause copy-on-write
    assert (b.uniqueStore())
    assert (b2.hasSharedStore(b3))
    assert (not b2.uniqueStore())
    assert (not b3.uniqueStore())
    assert (b.storeUseCount() == 1)
    assert (b2.storeUseCount() == 2)
    assert (b3.storeUseCount() == 2)

    b3[2] = 22  # will cause copy-on-write
    assert (b2.uniqueStore())
    assert (b3.uniqueStore())
    assert (not b2.hasSharedStore(b3))
コード例 #3
0
def testDelayLoadAndPostCloning(ext):
    # create test data on disk
    filepath = "/tmp/clpost." + ext
    sz = 1000
    b_ = n.IntBuffer(sz)
    b_[60] = 600
    assert (b_.clientSize() == sz)
    n.save(b_, filepath)

    # test1: Make sure that cloning a buffer doesn't force any data resident. Also make
    # sure that if either buffer forces data resident via a read, both buffers get the
    # same resident data.
    b = n.load(filepath)
    assert (b.clientSize() == 0)
    b2 = b.clone()
    assert (b.clientSize() == 0)
    assert (b2.clientSize() == 0)

    assert (b[60] == 600)  # will cause buffer to load into mem
    assert (b.clientSize() == sz)
    assert (b2.clientSize() == sz)
    assert (b.hasSharedStore(b2))

    # test2: Make sure that if a buffer's data is non-resident, and then it is cloned,
    # then the clone is accessed for writing, that the original buffer's data is NOT
    # made resident.
    c = n.load(filepath)
    assert (c.uniqueStore())
    assert (c.clientSize() == 0)

    c2 = c.clone()
    assert (c2.clientSize() == 0)
    c2[6] = 66  # will cause data to load for c2, but still not for c...!
    assert (c.clientSize() == 0)
    assert (c2.clientSize() == sz)
コード例 #4
0
def testTableCloning():
    t = n.ObjectTable()
    t[1] = 1
    t["two"] = "222"
    t[3] = n.IntBuffer(100)
    t[4] = t[3]
    t[5] = t[3].clone()
    assert (t[3].storeUseCount() == 2)

    t2 = t.clone()
    assert (t.keys() == t2.keys())
    assert (t2[1] == 1)
    assert (t2["two"] == "222")
    assert (t2[3] != t[3])
    assert (t2[3].hasSharedStore(t[3]))
    assert (t2[4] == t2[3])
    assert (t[3].storeUseCount() == 4)
コード例 #5
0
def testDelayLoadAndPreCloning(ext):
    # create test data on disk
    filepath = "/tmp/clpre." + ext
    sz = 13
    t_ = n.ObjectTable()
    b_ = n.IntBuffer(sz)
    b2_ = b_.clone()
    t_[1] = b_
    t_[2] = b2_
    n.save(t_, filepath)

    # test1: Make sure that when buffers are loaded, their cloned relationships are kept intact
    t = n.load(filepath)
    assert (t.keys() == t_.keys())
    assert (t[1].hasSharedStore(t[2]))
    t[2][0]  # force resident via zeroeth element read
    assert (t[1].clientSize() == sz)
    assert (t[1].hasSharedStore(t[2]))
コード例 #6
0
def testDelayLoad(ext):
    # create test data on disk
    filepath = "/tmp/dl1." + ext
    sz = 100
    t_ = n.ObjectTable()
    for i in range(10):
        t_[i] = n.IntBuffer(sz)
    n.save(t_, filepath)

    # test1: make sure a buffer's data isn't made resident until it's accessed
    t = n.load(filepath)
    expected_count = sz
    for i in t.iteritems():
        i[1][0]  # force resident via zeroeth element read
        count = 0
        for j in t.iteritems():
            count += j[1].clientSize()
        assert (count == expected_count)
        expected_count += sz
コード例 #7
0
def testIntBufSerialize(ext):
    # create test data on disk
    filepath = "/tmp/intbuf." + ext
    sz = 50
    b = n.IntBuffer(sz)
    b[5] = 5
    n.save(b, filepath)
    b2 = n.load(filepath)

    if ext in delayLoadableFileTypes:
        assert (b2.clientSize() == 0)
    else:
        assert (b2.clientSize() == sz)

    assert (type(b) == type(b2))
    assert (len(b) == len(b2))
    assert (b2[5] == b[5])

    if ext in delayLoadableFileTypes:
        assert (b2.clientSize() == sz)
コード例 #8
0
def testTable():
    t = n.ObjectTable()
    assert (len(t) == 0)

    fail = False
    try:
        t["foo"]
    except KeyError:
        fail = True
    assert (fail)

    t[1] = 1.111
    t["two"] = 68
    t[3] = p.V3f(5, 6, 7)
    t["four"] = 'Q'

    assert (len(t) == 4)
    assert ("two" in t)
    assert ("blah" not in t)
    assert (t["two"] == 68)
    assert (t["four"] == 'Q')
    vdiff = t[3] - p.V3f(5, 6, 7)
    assert (vdiff.length() < 0.0001)

    t["buf"] = n.IntBuffer(100)
    t["buf"][50] = 50
    assert (t["buf"][50] == 50)

    del t["four"]
    del t[3]
    assert (len(t) == 3)
    assert (3 not in t)

    keys = t.keys()
    keys2 = []
    for k in t:
        keys2.append(k)
    assert (keys == keys2)
コード例 #9
0
def createUberTable():
    t = n.ObjectTable()
    t[1] = 1  # this is interpreted as an int
    t[2] = 2.2  # this is interpreted as a float
    t[3] = n.Double(3.333)
    t[4] = "hello"
    t[5] = n.Char(-10)  # in napalm, a char is interpreted as a number
    t[6] = n.UChar(200)  # as is an unsigned char
    t[7] = n.Short(-30000)
    t[8] = n.UShort(60000)
    t[9] = n.UInt(2000000000)

    # todo add the new imath types inc half
    t[10] = p.V3f()
    t[11] = p.V3d()
    t[12] = p.M33f()
    t[13] = p.M33d()
    t[14] = p.M44f()
    t[15] = p.M44d()

    sz = 100
    t[16] = n.CharBuffer(sz)
    t[17] = n.FloatBuffer(sz)
    t[18] = n.DoubleBuffer(sz)
    t[19] = n.IntBuffer(sz)
    t[20] = n.V3fBuffer(sz)
    t[21] = n.V3dBuffer(sz)
    t[22] = n.M33fBuffer(sz)
    t[23] = n.M33dBuffer(sz)
    t[24] = n.M44fBuffer(sz)
    t[25] = n.M44dBuffer(sz)

    t[16].attribs["a1"] = "aaa1"
    t["hey"] = "ho"

    return t
コード例 #10
0
    def render(self, detailSize):

        # set up some buffers
        count = 200

        P = []
        Cs = []
        w = []
        nvertices = []

        random.seed(997)
        for i in range(count):
            cv_count = random.randint(5, 20)
            nvertices.append(cv_count)
            p0 = pimath.V3f(random.uniform(-self.dim, self.dim),
                            random.uniform(-self.dim, self.dim),
                            random.uniform(-self.dim, self.dim))
            for cv in range(cv_count):
                p0 = p0 + pimath.V3f(random.uniform(-self.dim, self.dim),
                                     random.uniform(-self.dim, self.dim),
                                     random.uniform(-self.dim, self.dim)) * 0.1
                P.append(p0)
                Cs.append(
                    pimath.V3f(random.uniform(0.05,
                                              1), random.uniform(0.05, 1),
                               random.uniform(0.05, 1)))
                w.append(
                    random.uniform(0.1 * self.curve_width, self.curve_width))

        # form a table from our buffers with required renderman info
        t = n.ObjectTable()

        #t['type'] = 'linear'
        t['type'] = 'cubic'
        #t['wrap'] = 'periodic'
        t['wrap'] = 'nonperiodic'

        t['nvertices'] = n.IntBuffer(count, len(nvertices))
        t['nvertices'].contents = nvertices
        #        t['nvertices'].attribs['to]

        t['P'] = n.V3fBuffer(count, pimath.V3f(0, 0, 0))
        t['P'].contents = P
        t['P'].attribs['token'] = 'P'

        if 1:
            # colour per point
            t['Cs'] = n.V3fBuffer(count, pimath.V3f(0, 0, 0))
            t['Cs'].contents = Cs
            t['Cs'].attribs['token'] = 'vertex color Cs'
        else:
            # constant colour across all points
            t['Cs'] = n.AttribTable()
            t['Cs']['value'] = pimath.V3f(1, 0, 0)
            t['Cs']['token'] = 'constant color Cs'

        if 1:
            # varying width
            t['width'] = n.FloatBuffer(count, 0.0)
            t['width'].contents = w
            t['width'].attribs['token'] = 'vertex float width'
        else:
            if 1:
                # constants either as attrib table
                t['width'] = n.AttribTable()
                t['width']['value'] = 0.05
                t['width']['token'] = 'constant float constantwidth'
            else:
                # or buffer of length 1
                t['width'] = n.FloatBuffer(1, 0.03)
                t['width'].attribs['token'] = 'constant float constantwidth'

        # render
        ri.TransformBegin()
        ri.Translate(self.centre[0], self.centre[1], self.centre[2])
        nd.curves(t)
        ri.TransformEnd()