Re: [Pyobjc-dev] VTK bindings
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-12-06 19:18:59
|
On 6 dec 2003, at 18:04, Carlos Phillips wrote: > > On Dec 2, 2003, at 1:13 PM, Bob Ippolito wrote: > >> >> On Dec 2, 2003, at 12:38 PM, Ronald Oussoren wrote: >> >>> >>> On 2 dec 2003, at 16:23, b.bum wrote: >>> >>>> On Dec 2, 2003, at 1:12 AM, Carlos Phillips wrote: >>>>> 2003-12-02 03:30:46.165 Simple1[1541] PyObjCPointer created: at >>>>> 0x6d16080 of type >>>>> {vtkRenderer={?={?={?=^^?i}C{vtkTimeStamp=^^? >>>>> L}^{vtkSubjectHelper}}^{vtkAssemblyPath}^{vtkPropCollection}iIff^{v >>>>> tkPropCollection}^{vtkActor2DCollection}^{vtkWindow}[3f][4f][2f][2f >>>>> ][2f][2i][2i][3f][3f][4f]}^{vtkCamera}^{vtkLight}^{vtkLightCollecti >>>>> on}^{vtkCullerCollection}^{vtkActorCollection}^{vtkVolumeCollection >>>>> }[3f]^{vtkRenderWindow}ffiii*{vtkTimeStamp=^^? >>>>> L}fii^^{vtkProp}i^^{vtkAssemblyPath}iii[6f]f}8@0:4 >>>> >>>> Like Bob said, once a PyObjCPointer is created, you are generally >>>> out of luck. PyObjC transparently bridged Objective-C. In this >>>> case, you are asking it to transparently bridge a relatively >>>> complex C data type. >>> >>> The problem is that PyObjCPointer is a not really a wrapped pointer, >>> when the PyObjCPointer object is created the value pointed-to is >>> copied into an internal buffer. Most of the time that doesn't work, >>> vtkRenderer is probably a C++ class and the copied value is invalid. >>> >>> I'll put creation of a real pointer wrapper on my todo-list, a >>> generic version of the types used to wrapped some other pointer >>> types (see pointer-support.m). >>> >>> Is VTK itself wrapped? If so, you could use the functions in >>> pointer-support.m to convert vtkRenderer* to the Python wrapper from >>> the VTK wrapper. >> >> VTK itself does have python wrappers.. they probably work on OS X by >> now, but there were problems last time I tried (a long while ago, due >> to linking issues). >> >> -bob >> > > I am trying to create a wrapper for the following methods in VTKView. > -(vtkRenderer *)renderer; > -(vtkRenderWindow *)renderWindow; > -(vtkRenderWindowInteractor *)renderWindowInteractor; > > Each return value is a C++ class which has a VTK python wrapper. In > VTK, there is a function available to convert pointers along with type > descriptions into python objects. Thus all I need to do is create a > wrapper for these methods which returns the appropriate python object > instead of the C++ object. > > To do this, I have created a module similar to the AppKit module which > installs a wrapper method with the following call. > > if (PyObjC_RegisterMethodMapping( classVTKView, > @selector(renderer), > call_VTKView_renderer, > PyObjCUnsupportedMethod_IMP) < 0) > > call_VTKView_renderer does the following: > 1) Unwrap the VTKView python proxy. Call the unwrapped objc object > self_objc. > 2) rend = [self_objc renderer] > 3) Wrap rend using VTK function. > 4) Return wrapped rend > > I use PyObjCUnsupportedMethod_IMP as the fourth argument to > PyObjC_RegisterMethodMapping but I'm not sure what this argument is > for. > > When I compile the new module and load it into python. I gain access > to the VTKView class and can instantiate it. When I call renderer() on > an instance, I get the following python error: > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: argument list must be a tuple Do you parse the method arguments using PyArg_ParseTuple? See one of the method mappings in the Foundation and AppKit wrappers for an example of argument parsing. > > Is this because I don't have a callPython argument in my > PyObjCUnsupportedMethod_IMP call? If so what needs to be put there? You can leave the PyObjCUnsupportedMethod_IMP as it is, you only have to change that when you want to be able to override the method in Python. Ronald |