Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try:
- import numpy
- import SofaPython.SofaNumpy
- def mat_as_numpy(img):
- '''maps image content as a numpy array with shared memory'''
- ptrs, shape, typename = img.getPtr() ## << Cause of the python error message: getPtr() cannot be called on a python string...
- ## what does that ctypeFromName function do? where is it defined, and what exactly does the POINTER(type) method do?
- type = SofaPython.SofaNumpy.ctypeFromName.get(typename,None)
- if not type: raise Exception("can't map image of type " + typename)
- array = SofaPython.SofaNumpy.ctypes.cast( SofaPython.SofaNumpy.ctypes.c_void_p(ptrs[0]), SofaPython.SofaNumpy.ctypes.POINTER(type))
- return numpy.ctypeslib.as_array( array, shape )
- pass
- except ImportError: # numpy is not mandatory
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement