SimpleCocoaVTK 1.4
2007-12-14
by: Sean McBride and Mike Jackson
This project is public domain.

Pre-Requisites:

1) you need Mac OS X 10.4 and Xcode 2.4 or later installed on your Mac.
2) you need to know the very basics of VTK & Cocoa already.
3) you have to build VTK 5.1 seperately.  This project expects VTK to be built with certain options, see below.

Purpose of Example:

This simple example is intended to show how to use VTK in a Mac-only Cocoa application.  The class vtkCocoaGLView is a subclass of NSView and you can use it like pretty much any other NSView!

This example is an NSDocument-based application, and has two independent vtkCocoaGLViews in the document's NIB.  One shows a cone, and one shows a cylinder.

See the screenshot adjacent to this read me to see what the app looks like.

Instructions:

First, you need to build VTK.  SimpleCocoaVTK requires that you build VTK with the following options:
	BUILD_SHARED_LIBS				OFF                                                                                                                                         
	VTK_USE_CARBON					OFF                                                                                                                                         
	VTK_USE_COCOA					ON                                                                                                                                          
	CMAKE_BUILD_TYPE				Debug                                                                                                                                       
	VTK_USE_SYSTEM_ZLIB			ON                                                                                                                                          	CMAKE_OSX_ARCHITECTURES	ppc;i386
	CMAKE_OSX_SYSROOT				/Developer/SDKs/MacOSX10.4u.sdk

The other settings are not so relevant.  If you've never built VTK before, please see Ryan Glover's excellent document here: <http://www.vtk.org/Wiki/Cocoa_VTK>.  Make sure you build and 'install' VTK!

Next, you have to create a Source Tree in Xcode named "vtk-debug".  Do this from Preferences > Source Trees.  Point "vtk-debug" to the folder on your disk that contains your built and 'installed' VTK.  Using the example in the VTK Wiki, "vtk-debug" would point to "~/Development/VTKBuild".  Basically, you want the source tree to match your CMAKE_INSTALL_PREFIX setting.

All the vtk files in the Xcode project are referenced relative to the source tree.  This allows you to have your vtk files anywhere without changing the project itself.

Now you should be able to build the project!

Note: VTK 5.1 is required.  At the time of this writing, that means you have to get the code from CVS.  5.1 is recommended because there have been many Mac-related fixes since 5.0.3, the current release.  You could probably use 5.0.3 actually, but you would need to change the Xcode project, specifically, change HEADER_SEARCH_PATHS from "$(vtk-debug)/include/vtk-5.1" to "$(vtk-debug)/include/vtk-5.0.3".

The code has many comments, and hopefully they will answer any questions you may have.

If you have any problems, please post to the vtk mailing list.
<http://public.kitware.com/mailman/listinfo/vtkusers>

Version History:

Changes in 1.4beta (since 1.3) (IN PROGRESS)
- removed prefix file
- renamed main.m to main.mm
- converted tabs to spaces

Changes in 1.3 (since 1.2)
- switched to using just one Source Tree
- tested in Mac OS X 10.5 and Xcode 3
- improved these instructions

Changes in 1.2 (since 1.1)
- using smart pointers

Changes in 1.1 (since 1.0)
- fixed some memory leaks
- minor code cleanup
- added call to print out any leaking vtk objects
- linked to Ryan Glover's great instructions on how to build vtk