Advertisement
Guest User

__init__.py

a guest
Sep 26th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. try:
  2.     import numpy
  3.     import SofaPython.SofaNumpy
  4.  
  5.     def mat_as_numpy(img):
  6.         '''maps image content as a numpy array with shared memory'''
  7.  
  8.         ptrs, shape, typename = img.getPtr() ## << Cause of the python error message: getPtr() cannot be called on a python string...
  9.  
  10.  
  11.         ## what does that ctypeFromName function do? where is it defined, and what exactly does the POINTER(type) method do?
  12.         type = SofaPython.SofaNumpy.ctypeFromName.get(typename,None)
  13.         if not type: raise Exception("can't map image of type " + typename)
  14.  
  15.  
  16.         array = SofaPython.SofaNumpy.ctypes.cast( SofaPython.SofaNumpy.ctypes.c_void_p(ptrs[0]), SofaPython.SofaNumpy.ctypes.POINTER(type))
  17.         return numpy.ctypeslib.as_array( array, shape )
  18.  
  19.     pass
  20. except ImportError: # numpy is not mandatory
  21.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement