[vtkusers] Re: CocoaWindow.h/mm incomplete

Mike Jackson maillist at bluequartz.net
Mon Dec 12 18:28:36 EST 2005


On Dec 12, 2005, at 2:35 PM, Scott Harris wrote:

> Did you ever come up with a bare bones Xcode project that uses Cocoa
> and VTK? It would be super-useful to see a Cocoa Xcode project that
> opens up a window and display a cone or something simple like that.
>
> I tried to build the start of of Cocoa/VTK app last night by following
> what was in this thread.
> I dragged a custom view into my window and set its custom class to
> vtkCocoaGLView and then I added libvtk-Rendering,Common,Graphics.a to
> my projects. It links and runs, but I get a complaint in the log that
> it can't find vtkCocoaGLView in the Nib so it defaults to a plain
> NSView.
>
> I've done a lot of VTK work with Python and wxWindows, but I'm just
> getting going with Cocoa on the Mac so there are a lot of holes in my
> understanding including how libraries get linked with Cocoa apps. I'm
> unsure if I should be using dylibs or static libraries. Is dragging a
> .h file into interface builder and linking with a .a file enough for
> Cocoa to hook everything up properly? Apparently not.
>
> Any help would be appreciated!
>
> -Scott
>
[snip lots of stuff... see the other posts]

You are probably going to want to subclass vtkCocoaGLView for your  
own purposes. Even if you don't think you have to, do it. Eventually  
you will need to over ride something in vtkCocoaGLView. I named my  
subclass VTKView.h/mm

I have created a small Cocoa Xcode App that brings up a Cocoa Window  
with an NSView and a button that will create a sphere in the window.

Some notes about the code. Most of it is Objective-C++, which is a  
bit odd to look at. Since VTK and Objective-C both use Ref Counting  
things actually work out rather well.

I have not fully tested the code. I ran it from Xcode and it seemed  
to build and run.

I am running OS X 10.4.3 and XCode 2.2. I make no guarantees it will  
compile/run on anything else. I am also using VTK 5.x from CVS about  
a month ago.

There are some methods that I over rode from vtkCocoaGLView in  
VTKView. Things like mouse zooming and rotation. I also over road the  
drawRect: method to make sure there is a TrackBall interactor on the  
renderer instead of the default flight control.

I did not finish up the IB related stuff like menus and all that.

  You will have to reset your search paths as I do not have VTK  
Installed in a "normal" location so before you build you will need to  
reset the location of the header files and the VTK libraries. I used  
DyLibs from VTK. I have used Static libs in the past and had those  
work just fine. Your Choice.

Last note that gets developers new to Objective-C++, the actual  
source file MUST HAVE ".mm" as the extension. If you do not have  
this .mm extension, gcc will not compile your code.

I did not write most of this code, it is take from other sources  
including Kitware and Drew McCormack
  (drewmccormack at mac.com)

I currently use VTK in a Cocoa-NSDocument based application, which  
has a slightly different setup, but nothing difficult.

The project is attaced to the end of this email. The code is  
commented some what. The best I could do with 2 small kids running  
around the office ;-)

If you have any questions/comments/corrections please send those  
through.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Test.zip
Type: application/zip
Size: 29171 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051212/d9d26fa8/attachment.zip>
-------------- next part --------------
---
Mike Jackson
mike _at_ bluequartz dot net



More information about the vtkusers mailing list