SimpleCocoaVTK 1.7
2010-06-17
by: Sean McBride and Mike Jackson
This project is public domain.

Pre-Requisites:

1) you need Mac OS X 10.5 and Xcode 3.1 or later installed on your Mac.
2) you need CMake 2.8 or later.
3) you need to know the basics of Xcode, CMake, VTK, and Cocoa already.
4) you have to build VTK 5.4 (or later) separately.  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.  VTK's 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 (in the same folder as this file) 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                                                                                                                                       

It is recommended to also use these options, but if you don't you can change SimpleCocoaVTK easily enough by editing it's SimpleCocoaVTK.xcconfig file:
	VTK_USE_SYSTEM_ZLIB					ON                                                                                                                                          	CMAKE_OSX_ARCHITECTURES			i386
	CMAKE_OSX_SYSROOT						/Developer/SDKs/MacOSX10.5.sdk
	CMAKE_OSX_DEPLOYMENT_TARGET		10.5

The other settings are not so relevant or their defaults are fine.  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 both build and install VTK!

Next, you have to create two Source Trees in Xcode, named "vtk-debug-include" and "vtk-debug-lib".  Do this from Preferences > Source Trees.  Both should point to subfolders of where your built and installed VTK is.  The example in the VTK Wiki installs to "~/Development/VTKBuild".  So you would set them like so:

	vtk-debug-include			~/Development/VTKBuild/include/vtk-5.4
	vtk-debug-lib				~/Development/VTKBuild/lib/vtk-5.4

Note that the path changes depending on your version of VTK.  Basically, you want the source trees 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. If they appear in red in Xcode, it's probably because your source trees are missing or wrong.

Now you should be able to build the project!

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.7 (since 1.6)
- this example can now be built by CMake.

Changes in 1.6 (since 1.5)
- converted all nibs to xibs.
- the Xcode project had a reference to a path on my disk, removed.

Changes in 1.5 (since 1.4)
- now use two source trees instead of one.
- updated example to better reflect current versions of VTK, Mac OS, and Xcode.

Changes in 1.4 (since 1.3)
- 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