[vtkusers] vtk on osx with Tk/tcl

Dr. Daniel James White PhD dan at chalkie.org.uk
Sun Jan 18 07:07:46 EST 2004


Hi ,
here is a document that descries a native Tk/tcl and python wrapping 
enabled native aqua build
for VTK on a 10.2 system, to get MayaVi working on OSX
It worked for me this way.

a few alterations  should make it work on a 10.3

NOTE: No need to do the VTK hack in Step 5, it is fixed in VTK CVS

good luck,

cheers

Dan




How to get Mayavi working on MacOSX 10.2 with the native Aqua interface 
(not X11)
MayaVi is a data visualization tool written in Python that uses VTK
for the graphics.
This document is mutated from instructions by Karl Garsha on the MayaVi 
users list 5th Sept 2003, with additional information from Adrian 
Umpleby, and written up after some trial and error by Dan White 21st 
October 2003.

This guide intends to enable the novice UNIX and VTK user to get MayaVi 
working on MacOSX 10.2 Jaguar (who knows what 10.3 panther will 
bring...)

Step1)
Update your operating system to 10.2.8 (just for good measure). Find 
the MaoOSX 10.2 Jaguar Developer tools cd that came with your MacOSX 
10.2 Jaguar operating system. Or go to the apple website, click on 
developer, register, then go to downloads, then developer, and download 
the Dec 2002 developer tools.
(You could also get the august 2003 gcc 3.3 updater for G5 support, but 
I have used the gcc3.1 compiler on the Dec 2002 developer tools on a G4 
and a G3, no problem).
Read the instructions and install the developer tools (and the gcc3.3 
updater, not tested though).

Step2) MayaVi uses the Python virtual machine and a graphical user 
interface
system for Python called Tkinter. You also need Tcl/tk for scripting 
and the GUI etc.

You can get the latest Tcl/Tk8.4.4
installation package from (download and install the TclTkBI-8.4.4.0.dmg)
http://www.maths.mq.edu.au/~steffen/tcltk/TclTkAqua/
You need the Batteries Included TclTkBI version, not the other ones.

The latest macPython installation (2.3 binary installer for OSX 10.2) 
available at
http://homepages.cwi.nl/~jack/macpython/download.html
(the Apple version of python won't do, nor probably the fink version)

Install both the MacPython2.3 and TclTkBI packages.

After installing Tcl/Tk and macPython2.3 you will need to edit your 
~/.cshrc file to add
/usr/local/bin
to your $PATH environment variable.  If you don't know what I'm talking 
about, do this:
In Finder go to Applications/Utilities. There is an application caller 
Terminal. Double click it, and behold the wonderful world of the UNIX 
command line interface. A whole new and exciting world awaits you.....
In your home directory, the one where you are when the terminal starts 
up (probably something like /Users/yourname/  you can check by typing 
pwd),
type pico .cshrc
This enters the pico text editor, you can move around with the cursor 
keys, and type stuff.
Add a line like setenv PATH 
/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:$PATH
Add another line: setenv MACOSX_DEPLOYMENT_TARGET 10.2
press ctrl-X and then y to save and exit.
Type
source .cshrc
This reads the file you just edited and executes the commands that are 
in it.
The .cshrc file is where you can keep things like your personal aliases 
and environment variables.

Next, you'll need to get Tkinter. Using the Finder, go into
/Applications/MacPython-2.3 and double click the PackageManager.  This 
will open
an interface through which you can simply download the Tkinter module.
(I installed all the other binaries too, except wxPython.)
highlight _tkinter and click on install.

Step4)
After this, all the dependencies (stuff you need) should be in place to 
download and install VTK.
You will need to get the latest development version of VTK from CVS.
The normal archived VTK package won't work on OS X with Python2.3, yet.

To do this, go to the command line in Terminal (you need to be
connected to the internet), cd to the directory you want to download VTK
to (eg. mkdir /Applications/VTK , cd /Applications/VTK) and then follow 
the
instructions at

http://public.kitware.com/VTK/get-software.php#cvs

Step5)
A VTK hack!
(Information from Adrian Umpleby on 9th Oct 2003)
".......the glLight problem in VTK...
If you go into the VTK source code, into the Rendering directory, and 
edit the file vtkOpenGLRenderer.cxx (use pico or TextEdit), you will 
see a line like this:

void vtkOpenGLRenderer::ClearLights (void)

Just below there you will see a line that contains glLightModelfv, two 
more that contain glLightModeli, and finally one that contains 
glDisable.

See the /* and */ which enclose some of the code below.
Insert these /* and */ into vtkOpenGLRenderer.cxx as shown below.
This comments out this bit of code. Save the edited file,
replacing the original one.

// update the ambient light
   Info[0] = this->Ambient[0];
   Info[1] = this->Ambient[1];
   Info[2] = this->Ambient[2];
   Info[3] = 1.0;
/*
   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Info);

   if ( this->TwoSidedLighting )
     {
     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
     }
   else
     {
     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
     }

   // now delete all the old lights
   for (curLight = GL_LIGHT0; curLight < GL_LIGHT0 + VTK_MAX_LIGHTS; 
curLight++)
     {
     glDisable((GLenum)curLight);
     }
*/
   this->NumberOfLightsBound = 0;
}

"No doubt this means something somewhere (to do with lighting) will not 
quite work correctly, but it doesn't seem to be a major issue (I don't 
even know if MayaVi actually uses it...?)" Cheers Adrian!


Step6)
At the VTK site you were told to get cmake...
so...
Note, Firstly I used the Darwin command line version of cmake, but then 
realised that the interactive version
ccmake is of course much better!  So use ccmake.

You need
cmake-1.8.1-darwin.tar, download this from
http://www.cmake.org/HTML/Download.html
double click on it to decompress it.
read the README in the newly created folder, then
double click on the archive in the new folder to extract the cmake 
stuff with Stuffit expander..
Stuffit annoyingly adds "Folder" to the end of the new directory name. 
Rename the extracted folder in Finder to get rid of the "Folder" on the 
end.
Move the renamed "cmake-1.8.1-darwin-files" folder to /usr/local.
(You might not be able to do it in the finder, as unless you have 
played with your system these directories do not show up in the 
finder).
In Terminal:
sudo mv cmake-1.8.1-darwin-files /usr/local
you will be prompted for the admin/login/root password, enter it, press 
return.

cd to the VTK directory you just did the VTK CVS download, and type 
"ccmake ." at the
command line in the terminal (yes that is 2 "c"s, and the . is 
required, as it will tell you if you don't use it!).
A bunch of checks are done and some files are written.

Now to use the arrow keys and enter (to toggle ON / OFF) for
shared ON, hybrid ON, Tcl ON and Python ON. Use X11 should be OFF (this 
is an Aqua build)

Now press c to configure. Keep pressing c until the lines at the top of 
the window no longer have an * before them. (this should only take 2 or 
3 times)
Again, more compiler checks, and more files are written which will 
guide the compilation process.
When you have no more lines starting with *
press g to generate all the make files etc. the ccmake prog will exit.

Now you type
make
and all the VTK stuff is compiled/built etc.
when it has finished (it takes a long time, several hours, go for a 
walk or perhaps to the pub) and there are no errors, type
sudo make install
and then give your admin/root password to continue.

Now the compiled libraries and executables are being put in the correct 
places (well.. most of them, see later)

After the VTK libraries are installed, you need to install the python 
wrapped
modules.  Go into the Wrapping/Python directory (cd Wrapping/Python).
Type
sudo python2.3 setup.py install
this will install the python wrapping stuff necessary to run MayaVi.

Step7)
Finally, you'll need to download MayaVi from the CVS snapshot, 
decompress it using stuffit expander, and cd to the mayavi directory. 
You must use the CVS snapshot version.
URL???????!!!!!!!

(or for the CVS version Quote MayaVi sourceforge CVS "This project's 
SourceForge.net CVS repository can be checked out through anonymous 
(pserver) CVS with the following instruction set. The module you wish 
to check out must be specified as the modulename. When prompted for a 
password for anonymous, simply press the Enter key.  To determine the 
names of the modules created by this project, you may examine their CVS 
repository via the provided web-based CVS repository viewer."
So, In the terminal,
mkdir MayaVi
in /usr/local or /Application or where ever you want to put the MayaVi 
download.
then do
cvs -d:pserver:anonymous at cvs.sourceforge.net:/cvsroot/mayavi login
(password is "anonymous")
then
cvs -z3 -d:pserver:anonymous at cvs.sourceforge.net:/cvsroot/mayavi co 
mayavi)

cd into the newly downloaded MayaVi source tree, where you can find the 
mayavi file (use ls to see directory contents),
in the terminal type
sudo python2.3 setup.py install
give your admin/root password
and you should be all set.

Step8)
To run Tkinter apps on OSX Aqua, you need to
use the special pythonw script (which uses the GUI version of python).

Also at the moment VTK will only work if you launch some application
using it from the VTK/bin directory. This will be fixed one day.
So cd to the VTK/bin directory in your terminal.
To test things out type something like
pythonw /Applications/MayaVi/doc/test_vtk.py
use the correct path for wherever your MayaVi was downloaded to.
Note! Use "pythonw" (not "python" or "python2.3")

Some dialog boxes should pop up, click OK on them.
Then a window will appear with a blue cone in it, which you can 
interact with
using the mouse. (If the cone doesn't appear click and drag in the 
window and it should suddenly appear)
Now is a good time to find a 3 button USB mouse. (Note, logitech mouse 
wheel
buttons don't seem to work as middle buttons on Mac OSX 10.2). Press q 
to quit. You might need to force quit python (alt-ctrl-esc) as it 
doesn't seem to quit cleanly.

Step9)
Run MayaVi from your /VTK/bin directory with a command like this (use 
the correct mayavi path)
pythonw /Applications/MayaVi/mayavi

The MayaVi GUI should launch and you can now load your data and 
visualise it.

Good luck!




Dr. Daniel James White BSc. (Hons.) PhD
Cell Biology
Department of biological and environmental science
PO Box  35
University of Jyväskylä
Jyväskylä FIN 40014
Finland
+358 (0)14 260 4183 (work)
+358 (0)414740463 (mob)

http://www.chalkie.org.uk
dan at chalkie.org.uk
white at cc.jyu.fi



More information about the vtkusers mailing list