I am using ctypes in Python and I need to pass a pointer to an array of pointers to structs to some C function. This is struct:
typedef struct {
float x;
float y;
float z;
float radius;
} Sphere;
And I have function with the following prototype:
void render(Sphere** spheres);
In Python I declared a class for the Sphere struct and I need to set argtypes to the render function:
lib_render = ctypes.cdll.LoadLibrary('librender.so')
class Sphere(ctypes.Structure):
_fields_ = [('x', ctypes.c_float),
('y', ctypes.c_float),
('z', ctypes.c_float),
('radius', ctypes.c_float)]
render = lib_render.render
render.argtypes = [<cannot find out what needs to be here>]
spheres = numpy.array([Sphere(1, 2.8, 3, 0.5),
Sphere(4.2, 2, 1, 3.2)])
render(spheres)
How to pass that array correctly?
ctypes.POINTER(ctypes.POINTER(Sphere))LP_LP_Sphereautomatically and if I'm passing to the functionspheres.ctypes.data_as(POINTER(POINTER(Sphere)))the function receives unknown garbage, all different for each time.numpy.ctypeslib.ndpointer?np.ctypeslib.ndpointer(dtype = np.int32, ndim = 1, flags = 'C_CONTIGUOUS')But I had no idea how to apply this for array of pointers to structs.