Esempio n. 1
0
    def loadSingleInput(self, key, filename, objecttype):

        if (objecttype == 'image'):
            self.inputs[key] = bis_objects.bisImage()
        elif (objecttype == 'matrix' or objecttype == 'vector'):
            self.inputs[key] = bis_objects.bisMatrix()
        elif (objecttype == 'transformation' or objecttype == 'transform'):
            self.inputs[key] = bis_objects.loadTransformation(filename)
            if (self.inputs[key] == None):
                return False
            return True

        try:
            ok = self.inputs[key].load(filename)
            if (ok != False):
                sz = self.inputs[key].data_array.shape
                if (sz[1] == 1 and objecttype == 'vector'):
                    tmp = self.inputs[key]
                    self.inputs[key] = bis_objects.bisVector()
                    self.inputs[key].create(tmp.data_array.flatten())
                    ok = self.inputs[key]

        except:
            return False

        print('++++ \t loaded ' + objecttype + ' ' + key + ' from ' + filename)
        if (ok != False):
            return True
        return ok
Esempio n. 2
0
def deserialize_object(ptr, datatype='', offset=0, first_input=0):

    if datatype == '':
        datatype = getNameFromMagicCode(magic_code)

    if datatype == 'String':
        output = bis.bisVector()
        output.deserializeWasm(ptr, offset)
        return output.getString()

    if datatype == 'Matrix':
        output = bis.bisMatrix()
        output.deserializeWasm(ptr, offset)
        return output.get_data()

    if datatype == 'Vector':
        output = bis.bisVector()
        output.deserializeWasm(ptr, offset)
        return output.get_data()

    if datatype == 'bisComboTransformation':
        output = bis.bisComboTransformation()
        output.deserializeWasm(ptr, offset)
        return output

    if datatype == 'bisGridTransformation':
        output = bis.bisGridTransformation()
        output.deserializeWasm(ptr, offset)
        return output

    if datatype == 'bisLinearTransformation':
        output = bis.bisLinearTransformation()
        output.deserializeWasm(ptr, offset)
        return output.get_data()

    if datatype != 'bisImage':
        raise ValueError('Unknown datatype ', datatype)

    # Image from here
    output = bis.bisImage()
    output.deserializeWasm(ptr, offset)
    if type(first_input) is bis.bisImage:
        output.affine = first_input.affine

    return output
Esempio n. 3
0
    def test_bis_matlab_import(self):
        print(' --------------------------------------------------')
        print('test_matlab_import')

        filename = os.path.abspath(my_path + "/../test/testdata/small.mat")
        print("reading ", filename)

        with open(filename, mode='rb') as file:  # b is important -> binary
            fileContent = file.read()

        vect = bis.bisVector().create_from_bytes(fileContent)

        matr = libbiswasm.parseMatlabV6WASM(vect, {'name': 'a'}, 1)

        print(matr)
        self.assertEqual(0, 0)
Esempio n. 4
0
    def test_bis_eigenutils(self):
        print('test_eigenUtils')

        m = np.identity(4, dtype=np.float32)
        for row in range(0, 4):
            for col in range(0, 4):
                m[row][col] = (1.0 + row) * 10.0 + col * col * 5.0

        xform = bis.bisLinearTransformation().create(m)
        print('First print to check ...\n', xform.get_data())

        vect = bis.bisVector().create(np.array([1, 2, 3, 5, 7, 11.0]))

        numfailed = libbiswasm.test_eigenUtils(xform, vect, 1)
        print('\t From JS to C++, numfailed=', numfailed)

        self.assertEqual(numfailed, 0)