VTK on OSX with Mayavi (was: Re: [vtkusers] new user attempting install on mac OSX)

Adrian Umpleby a.umpleby at imperial.ac.uk
Fri Apr 18 08:35:21 EDT 2003


Hi again,

>     AU> While this subject is around on-list, I thought it would be
>     AU> worth recounting my own experiences with VTK on OSX.
>
> I have no clue about Mac's but do have some idea about MayaVi.

<grin>
BTW, you've reminded me that I should let you know about the 
rough-and-ready Hyperstreamlines module I've cobbled together - I think 
Gerard Gorman (gormo at ic.ac.uk) mentioned it to you a while back on the 
Mayavi users list... If you're interested let me know (it's basically a 
rip-off of the streamlines module, but still needs huge work to make it 
more consistent and remove defunct parts). I've also added a few extra 
buttons to the bottom row to manipulate the view more easily in small 
'jumps', and to snap the it back so the Z axis is oriented upwards 
(simple stuff, but quite useful...)

Actually, while on that subject, and bringing this back on-topic, I was 
using a package recently which had very similar manipulation controls to 
VTK - the left mouse button rotates, while the others zoom and drag the 
view. However, it had an extra feature... The right mouse button for 
zoom in VTK only increases/decreases the zoom as the cursor is moved up 
and down, and does nothing side-to-side. This package, though, also 
*rolled* the view (about an axis from the viewer through the center of 
the view) as the cursor moved left/right with right-button down. I found 
this helped a great deal in manipulating an object. Any chance this sort 
of thing could be added to VTK? (Or does it already allow this somehow?)


>     AU> 3) Running Mayavi has to be done interactively through the
>     AU> python command-line...
>
> Ugh, how come?  This looks like Tkinter is broken.

That's an understatement...

>   Can you run this:
>  python /usr/lib/python2.1/lib-tk/tkFileDialog.py

Once I change the paths appropriately, that appears to work fine!

Here's what happens in mayavi:

Exception in Tkinter callback
Traceback (most recent call last):
   File "Python.framework/Versions/2.2/lib/python2.2/lib-tk/Tkinter.py", 
line 1292, in __call__
     return apply(self.func, args)
   File 
"/Library/Frameworks/Python.framework/Versions/2.2/lib/python2.2/site-packages/
mayavi/Main.py", line 1074, in open_vtk
     filetypes=[("VTK files", "*.vtk"),
   File 
"/Library/Frameworks/Python.framework/Versions/2.2/lib/python2.2/lib-
tk/tkFileDialog.py", line 94, in askopenfilename
     return Open(**options).show()
   File 
"/Library/Frameworks/Python.framework/Versions/2.2/lib/python2.2/lib-
tk/tkCommonDialog.py", line 53, in show
     s = apply(w.tk.call, (self.command,) + w._options(self.options))
TclError: bad directory ""

Looks like some silly little error to me, that I could probably fix if I 
dig around a bit...
(Anyway, it's not VTK, so not really relevant to this list...)

>     AU> 4) Once a file has opened, Mayavi crashes in
>     AU> vtkOpenGLRenderer::ClearLights (well, when that calls
>     AU> glLightModeli, anyway). I guess this is a VTK problem...?
>     AU> Commenting out the gl calls there allows it to work. Any ideas
>     AU> what's going on here? (Had this problem back in July, too...)
>
> A traceback or more info would help.  Of course, if this is not
> important (since everything works under X11) don't bother.

This, however, does look like something weird in VTK - perhaps some 
incompatibility with Apple's OpenGL? - since it obviously works fine 
with XGL...

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x709ca8e8 in glLightModelfv ()
(gdb) bt
#0  0x709ca8e8 in glLightModelfv ()
#1  0x03beddd4 in ClearLights__17vtkOpenGLRenderer ()
#2  0x036c420c in PyvtkOpenGLRenderer_ClearLights__FP7_objectn1 ()
#3  0x00638484 in PyCFunction_Call (func=0x4030bb0, arg=0x2af420, 
kw=0xbfffe028) at Objects/methodobject.c:101
#4  0x006663cc in eval_frame (f=0x4bbad0) at Python/ceval.c:2004
#5  0x006678ac in PyEval_EvalCodeEx (co=0x3a7abe0, globals=0xbfffe16c, 
locals=0x3beddd4, args=0x4052ee0, argcount=1, kws=0x4052ee4, kwcount=0, 
defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2585
#6  0x00668e94 in fast_function (func=0xb53, pp_stack=0xbfffe41c, n=40, 
na=1, nk=-1073749976) at Python/ceval.c:3161
#7  0x006664d0 in eval_frame (f=0x4052d80) at Python/ceval.c:2024
#8  0x006678ac in PyEval_EvalCodeEx (co=0x3a7a970, globals=0xbfffe16c, 
locals=0x3beddd4, args=0x3a7e4e0, argcount=4, kws=0x2c9760, kwcount=1, 
defs=0x3a7e4dc, defcount=1, closure=0x0) at Python/ceval.c:2585
#9  0x0062a874 in function_call (func=0x3a7e090, arg=0x2b89b0, 
kw=0x4061490) at Objects/funcobject.c:374
#10 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#11 0x0061fe08 in instancemethod_call (func=0x3a7e090, arg=0x2b89b0, 
kw=0x4061490) at Objects/classobject.c:2276
#12 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#13 0x00668af8 in PyEval_CallObjectWithKeywords (func=0x4061520, 
arg=0x40306c0, kw=0x4061490) at Python/ceval.c:3049
#14 0x0061b42c in PyInstance_New (klass=0xb53, arg=0x40306c0, 
kw=0x4061490) at Objects/classobject.c:557
#15 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#16 0x006692a0 in do_call (func=0x3a7e050, pp_stack=0xbfffe83c, na=3, 
nk=0) at Python/ceval.c:3262
#17 0x006664e8 in eval_frame (f=0x4028f60) at Python/ceval.c:2027
#18 0x006678ac in PyEval_EvalCodeEx (co=0x3a4ff60, globals=0xbfffe16c, 
locals=0x3beddd4, args=0x40294bc, argcount=2, kws=0x0, kwcount=0, 
defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2585
#19 0x0062a874 in function_call (func=0x3a7a1b0, arg=0x40294b0, kw=0x0) 
at Objects/funcobject.c:374
#20 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#21 0x0061fe08 in instancemethod_call (func=0x3a7a1b0, arg=0x40294b0, 
kw=0x0) at Objects/classobject.c:2276
#22 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#23 0x00668af8 in PyEval_CallObjectWithKeywords (func=0x4029cb0, 
arg=0x3a1c590, kw=0x0) at Python/ceval.c:3049
#24 0x0061b42c in PyInstance_New (klass=0xb53, arg=0x3a1c590, kw=0x0) at 
Objects/classobject.c:557
#25 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#26 0x006692a0 in do_call (func=0x3a74fb0, pp_stack=0xbfffec5c, na=1, 
nk=0) at Python/ceval.c:3262
#27 0x006664e8 in eval_frame (f=0x40e670) at Python/ceval.c:2027
#28 0x006678ac in PyEval_EvalCodeEx (co=0x3a0e440, globals=0xbfffe16c, 
locals=0x3beddd4, args=0x402899c, argcount=2, kws=0x0, kwcount=0, 
defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2585
#29 0x0062a874 in function_call (func=0x3e9d0a0, arg=0x4028990, kw=0x0) 
at Objects/funcobject.c:374
#30 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#31 0x0061fe08 in instancemethod_call (func=0x3e9d0a0, arg=0x4028990, 
kw=0x0) at Objects/classobject.c:2276
#32 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#33 0x00668af8 in PyEval_CallObjectWithKeywords (func=0x57f1c0, 
arg=0x2c5a60, kw=0x0) at Python/ceval.c:3049
#34 0x0061b42c in PyInstance_New (klass=0xb53, arg=0x2c5a60, kw=0x0) at 
Objects/classobject.c:557
#35 0x00618204 in PyObject_Call (func=0xb53, arg=0xbfffe16c, 
kw=0xbfffe028) at Objects/abstract.c:1684
#36 0x006692a0 in do_call (func=0x3e9e810, pp_stack=0xbffff07c, na=1, 
nk=0) at Python/ceval.c:3262
#37 0x006664e8 in eval_frame (f=0x2c3710) at Python/ceval.c:2027
#38 0x006678ac in PyEval_EvalCodeEx (co=0x3a1b7c0, globals=0xbfffe16c, 
locals=0x3beddd4, args=0x43d190, argcount=0, kws=0x43d190, kwcount=0, 
defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:2585
#39 0x00668e94 in fast_function (func=0xb53, pp_stack=0xbffff21c, n=40, 
na=0, nk=-1073749976) at Python/ceval.c:3161
#40 0x006664d0 in eval_frame (f=0x43d040) at Python/ceval.c:2024
#41 0x006678ac in PyEval_EvalCodeEx (co=0x39e92e0, globals=0xbfffe16c, 
locals=0x3beddd4, args=0x0, argcount=0, kws=0x0, kwcount=0, defs=0x0, 
defcount=0, closure=0x0) at Python/ceval.c:2585
#42 0x00662a90 in PyEval_EvalCode (co=0xb53, globals=0xbfffe16c, 
locals=0xbfffe028) at Python/ceval.c:483
#43 0x0068595c in run_node (n=0x43c950, filename=0xbfffe16c "?\200", 
globals=0x2c35a0, locals=0x2c35a0, flags=0x40626c0) at 
Python/pythonrun.c:1079
#44 0x006846c8 in PyRun_InteractiveOneFlags (fp=0x800017a0, 
filename=0x375c "<stdin>", flags=0xbffff488) at Python/pythonrun.c:590
#45 0x00684490 in PyRun_InteractiveLoopFlags (fp=0x800017a0, 
filename=0x375c "<stdin>", flags=0xbffff488) at Python/pythonrun.c:526
#46 0x00684330 in PyRun_AnyFileExFlags (fp=0x800017a0, filename=0x375c 
"<stdin>", closeit=0, flags=0x0) at Python/pythonrun.c:489
#47 0x000031e8 in Py_Main (argc=0, argv=0xbffff67c, filename=0x0) at 
../../Mac/Python/macmain.c:667
#48 0x00003058 in main (argc=1, argv=0xbffff678) at 
../../Mac/Python/macmain.c:568
#49 0x00002468 in _start ()
#50 0x00002298 in start ()


>     AU> 5) There are numerous issues which I presume are to do with tk
>     AU> (or python?), such as errors trying to view the pipeline...
>
> This all looks like some serious problems with Tkinter under Aqua

Certainly does - I expect that's why the standard Python framework did 
not have Tkinter, and I had to compile it specially. But that was quite 
while ago, and I really ought to try doing it again on a more recent 
version.


Back to VTK, though, there are a couple of other problems that I forgot 
to mention (when using mayavi via VTK compiled for Aqua under OSX).

The first is with finding libvtkRenderingPythonTkWidgets.dylib. - it has 
to be in the current directory where I start python (or where the python 
script is that is run when sent as an argument to the python command) 
otherwise it stops with an error:

dyld: /Applications/Python.app/Contents/MacOS/python can't open library: 
/Users/adrian/libvtkRenderingPythonTkWidgets.dylib  (No such file or 
directory, errno = 2)

Tried setting VTK_TK_WIDGET_PATH and (DY)LD_LIBRARY_PATH etc., but that 
doesn't help. I just 'cd /usr/local/VTK-aqua/lib' (which contains that 
lib - or I can make a copy/symlink in the current directory) before I 
start python. Obviously, I don't have this problem with the X11 version.

The second problem was with Vtkrenderingpythontkwidgets_SafeInit. It 
complains it's undefined when it tries to open the mayavi window:

 >>> m=mayavi.mayavi()
dyld: /Applications/Python.app/Contents/MacOS/python Undefined symbols:
_Vtkrenderingpythontkwidgets_SafeInit

The way I fixed this was to edit vtkTkWidgetsInit.cxx to create a 
'wrapper' for the standard Vtkrenderingpythontkwidgets_Init. i.e. just 
after these lines...

//----------------------------------------------------------------------------
// Vtkrenderingpythontkwidgets_Init
// Called upon system startup to create the widget commands.
extern "C" {VTK_TK_EXPORT int 
Vtkrenderingpythontkwidgets_Init(Tcl_Interp *interp);}


...I added the following...

extern "C" {VTK_TK_EXPORT int 
Vtkrenderingpythontkwidgets_SafeInit(Tcl_Interp *interp);}

int Vtkrenderingpythontkwidgets_SafeInit(Tcl_Interp *interp)
{
         return Vtkrenderingpythontkwidgets_Init(interp);
}

Seems like a very simple little bit of code that would not really be 
overlooked, so I wouldn't be surprised if there's something I'm missing 
somewhere that's causing this...

Anyway, that's enough for now!

Adrian




More information about the vtkusers mailing list