Title: Installing vtk on OSX 10.4
Some time ago I commissioned a colleague who was Mac/Unix expert to write an ‘idiots’ guide to installing vtk on OSX 10.2.8 and he came up with these detailed instructions (see below) which worked perfectly until I upgraded to 10.4

If any one can, or knows of somebody else, who could update the instuctions so that it work on the bourne shell I would be very grateful.  I’ve been trying to learn vtk to generate objects that I can then make into sculptures (hence the lack of Unix expertise) and I’ve feel that I was getting somewhere but have now ground to a full stop.  I can do a limited amount working though the fink version but there are several gaps which I can’t solve.

Roger Clarke

Installing VTK on an OSX Mac - a guide complete with source downloads.

Firstly none of what follows would be possible without Michael J Norton’s excellent VTK installation guide on oreillynet.com. What is written below is merely his words and procedures translated into an even easier step-by-step guide for the (almost) complete novice. I have also drawn from Drew McCormack’s excellent pages, also from O’Reilly. To these two gentlemen I offer my thanks. Also I have included here several downloads that work with the instructions below. By the time you read this there will be newer versions of almost all the elements included. You may therefore wish to alter the commands listed below to take account of this - and it’ll take a modicum (but little more than that) of UNIX knowledge to do so. If you are however a complete novice then verbatim following of everything listed below should get you a fairly functional version of VTK. After that however you’re on your own!
 
Installing the Visual Tool Kit is not a difficult task, but for the die-hard Mac-user it may appear to present some rather technical challenges. Mac users have in the past always relied on Apple's infamous ease-of-use and user-friendliness. However as the Apple OS has developed, it has become possible to install and run a wider variety of applications and utilities than ever before, due not least in part to Apple's adoption of the UNIX operating system that forms the basis of OS X.  With this increased gamut of available applications and code comes a greater requirement for technical acumen on the part of the average user. However, we should not be alarmed at this development, as the results of, installing and running VTK far outweigh the inconvenience of our learning a handful of new (at least to us; UNIX is over 30 years old - in Internet Years, that's aeons old!) technologies.
 
Firstly, check your system. You must be running Mac OS X 10.2.5 or later. You must also have installed the Apple Software Developer's Kit, which is available for (enormous) download from sdk.apple.com [you need to sign up for as an Apple Developer] - or it is available on CD with most new Macs. If you don't have a copy of the latest SDK and do not fancy the interminable download from Apple, enquire at your local Apple reseller who may be able to help you acquire a copy. The installation of the SDK is an easy double-click and follow the instructions affair.
 
The Apple SDK contains many development tools - the ones we'll need here are the compilers, which are used to create and install code from the source files, or source binaries as they're often called. There's a whole bundle of other stuff too, which you can install at your leisure.
 
You also need to download and install cmake, from cmake.org (or use cmake-1.6.6-osx.dmg in the downloads folder). Again this is a simple double click and follow the instructions install. CMake is a utility that allows your computer to compile (that is, assemble) from raw C code, a working application suite. The CMake intsaller is a standard Mac OSX affair. Double click the installer and follow the instructions.
 
It would also be useful at this point for you to know a little about the UNIX operating system. The areas you need to know are quite simple - changing directories, basic text editing using pico, copying and moving files and so forth. We'd recommend "Learning the UNIX operating system", by Peek, Todino and Strang. ISBN 1-56592-390-1. Also useful from a more general OSX point of view is "Mac OS X Unleashed" by Ray and Ray.
 
You'll find a lot of what appears next a lot more simple if you have some working knowledge of the UNIX underpinnings of OSX.
 
 
The Installation

Launch the Terminal - the application (in the Utilities folder) that allows access to Mac OS X's inner UNIX core. We'll be typing a lot of commands into the Terminal. They'll appear
 
set in like this

which should differentiate them from the rest of the text.

First we're going to add /usr/local/bin to the PATH variable. This means that when you type a command into the Terminal that the raw Mac OS doesn't recognise, it'll also look in the /usr/local/bin directory as well as all the other normal places it'll look. It's in the /usr/local/bin directory we'll store a lot of our stuff...
 
First, in the Terminal type
 
echo $PATH

[that is, print the PATH variable]. Mine says something like:
 
/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
 
That's telling the OSX system to look in the following directories every time a command is entered: /bin, /sbin, and so forth. Note that the places to look are separated by colons.
 
Drag the cursor over your results from "echo $PATH" and hit APPLE C to copy the text.  Note that this is a really useful element of Terminal: although it's basically a UNIX terminal, many of the rules of the Mac OS apply, including Cut, Paste and Copy, as well as many of the application's display characteristics.
 
Now we'll set up the computer so that every time you the user launched the Terminal, the computer will be reminded of this "where to look for applications and utilities" - which is called the PATH variable - we saw this above. The .tcshrc file contains this reminder
 
pico ~/.tcshrc

This opens the text editor pico, and either creates, or edits if already existing, the file .tcshrc
 
now type (or add to the existing text if there is any) this in a new line:
 
setenv PATH

Now Paste so that the line [in my case] reads:
 
setenv PATH/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin

Now use the cursor keys and type
:/usr/local/bin

so that your line now reads
 
setenv PATH/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin

or somesuch.
 
Control X to quit. You'll be asked to save the buffer.
Confirm (and confirm overwrite if prompted).
 
Now source that file - this gives your computer a nudge.
 
source ~/.tcshrc

Now create the directory /Develop
 
mkdir /Develop

Leave the Terminal and download to the Desktop "VTK-4.2-LatestRelease.tar.gz" from www.vtk.org
 
Make sure the package is fully unstuffed, so the unpacked folder is on your Desktop.
 
Now copy this folder and its contents to your newly created /Develop folder - you may need to change the folder’s name if you’ve downloaded a newer version.
 
cp -r ~/Desktop/VTK-4.2.2 /Develop

Note that the spaces are important!
 
In the Develop directory, let's make a new directory called VTKBuild
 
mkdir /Develop/VTKBuild

Now move to that directory
 
cd /Develop/VTKBuild

and cmake VTK:
 
cmake ../VTK-4.2.2      ??????

Now make a copy of a text file used by CMake, for safe keeping:
 
cp CMakeCache.txt CMakeCache.txt.bak

Now let's change the original file, the one we've just made a copy of:
 
pico CMakeCache.txt

Scroll down using the arrow keys and find the following text:
 
//Build VTK with shared libraries.
BUILD_SHARED_LIBS:BOOL=OFF

and change to
 
//Build VTK with shared libraries.
BUILD_SHARED_LIBS:BOOL=ON

Hit CTRL X to quit, and confirm the save and overwrite.
 
Run cmake again:
 
cmake ../VTK-4.2.2

and make the application, thus:
 
make

This process takes about 30-50 minutes...
 
Check a good install with:
 
cd /Develop/VTKBuild/bin

Then
 
./TimeRenderer

and
 
./TimeRenderer2

These run and then quit after a few seconds - catch a glimpse while you can! If you see a window open and something appear then you're on the right tracks.
 
Test various things, thus:
 
./GraphicsCxxTests

and select a number from 0 to 5 for a further fleeting glimpse.
 
Next we need to download VTKData to the Desktop, which is downloadable from VTK.org. The download will typically, after being unzipped and so forth, be called "VTKData-release-4-4" or somesuch, so rename it (in the Finder) to "VTKData".
 
Copy this folder from the Desktop to /Develop, thus:
 
cp -R ~/Desktop/VTKData /Develop

Now we're going to add the tcl framework, which plays an intrinsic part in allowing OSX to run VTK. Download the data from http://www.atamai.com/atamai_VTKonOSX.html. Thanks are belatedly due here to Yves Starreveld , who always appreciates an email from those who are successful in installing VTK and tcl.
 
The tcl download appears as a disk image. Using the Finder, copy the two folders therein to the /Library/Frameworks folder - not the /Users/<username>/Library/Frameworks folder, if such a folder exists!.
 
Now let's edit the .tcshrc file again:
 
pico ~/.tcshrc

and add the following text
 
setenv TCLLIBPATH "/Develop/VTKBuild/Wrapping/Tcl"
setenv VTK_ROOT_DATA "/Develop/VTKData"
 
Then CTRL X to quit, confirm the save and overwrite.
 
Again we'll use the source command:
 
source ~/.tcshrc

We'll edit the CMakeCache.txt file to take account of the tcl framework:
 
pico /Develop/VTKBuild/CMakeCache.txt

hit CTRL W and type in "
VTK_WRAP_TCL" [ quotes for edification only!] to find the following text;

VTK_WRAP_TCL:BOOL=OFF

Change OFF to ON, so that the line now reads:
 
VTK_WRAP_TCL:BOOL=ON

Now add the following lines to the text - you can more or less stick them in anywhere, but after the lines you've just edited will be fine:
 
// set path to the tcl header files
TCL_INCLUDE_PATH:PATH=/Library/Frameworks/Tcl.framework/Headers
 
// set path to Tcl libraries
TCL_LIBRARY:FILEPATH=-framework Tcl
 
// set to the tclsh file.
TCL_TCLSH:FILEPATH=/Applications/Wish\ Shell.app/Contents/MacOS/Wish\ Shell
 
// set the path to the tk.h header file
TK_INCLUDE_PATH:PATH=/Library/Frameworks/Tk.framework/Headers
 
// set the path to the Tk libraries
TK_LIBRARY:FILEPATH=-framework Tk

Then the usual CTRL X, plus save and confirm. Then we'll run cmake twice again
 
cd /Develop/VTKBuild

and then

cmake ../VTK-4.2.2

Ignore the errors! Do it again:
 
cmake ../VTK-4.2.2

Then make it again - thus:
 
make

Wait a while.  Full recompile - takes about 30-50 mins again!
 
To make sure everything's OK, try the following test:
 
cd /Develop/VTKBuild/bin

./vtk -f /Develop/VTK-4.2.2/Examples/Modelling/Tcl/expCos.tcl

Note that tcl creates an application that displays normally in the Dock, and can be Quit as normal. Alternatively to quit your application, you can type CTRL C in the Terminal which will terminate the process.
 
Another test - thus
 
./vtk -f /Develop/VTK-4.2.2/Examples/VisualizationAlgorithms/Tcl/bandContourterrain.tcl

 
 
And that’s about as far as we go here. From now on in, you’re on your own. There are some books you should read - among them the OSX and UNIX tomes that you should begin to get your head around. Plus of course for VTK there’s The Visualization Toolkit, An Object-Oriented Approach to 3D Graphics, 2nd Edition , by Schroeder, Martin, and Lorensen .
 
You can unpack the manual pages (available from vtk.org), which are nicely in .html format - and included in the programme folder.  They’re more of a reference than a beginner’s guide, so novices beware!
 
 

Reply via email to