[vtkusers] SimpleCocoaVTK link dead?

Mike Jackson imikejackson at gmail.com
Sun Oct 21 09:10:57 EDT 2007


This is very possible. Both Sean and I have done this type of program  
in the past. You will have to learn some Objective-C in order to  
program the GUI. But all the core algorithms can be done in C++.  
There are some caveats with using C++ with Objective-C if you are  
targeting 10.3.9. Things are better in 10.4. You will end up writing  
some bridge code to bridge between the Observer pattern that is used  
in VTK with Patterns that are used in Objective-C.
   Some things that helped me out was:
     In both Objective-C and C++, everything is a pointer. use "new"  
for vtk classes (or a smart pointer) and the memory management will  
go easier.
	Return C++ pointers to vtk objects
	If your code has BOTH objective-C and C++ the file extension MUST  
BE .mm
	
Here are some examples:
   This uses the VTKCocoa class. We are using Obj-C to ask for the  
VTKRenderer object, then using C++ to set the view.
	[vtkView renderer]->GetActiveCamera()->SetViewUp(up);

Here I am getting the File path from an NSSavePanel then using C++  
streams to write some data to the file. Note how I use NSStrings  
UTF8String to create a "c_str()".
- (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int) 
returnCode contextInfo:(void *)contextInfo
{
   if( returnCode != NSFileHandlingPanelOKButton ){
     return;
   }
   NSString *path = [sheet filename];
   std::ofstream fout;
   fout.open( [path UTF8String],std::ios_base::trunc);

   fout << _particleInfos->GetNumberOfItems() << endl;
   int i = 0;
   int size = _particleInfos->GetNumberOfItems();
   for (i = 0; i < size; ++i) {
       _particleInfos->GetPFVParticleInfo(i)->PrintRecord(fout);
   }
   fout.close();
}

Hope some of this helps. The Cocoa API is very rich but VERY large.  
Don't get discouraged and keep plugging away.

We use Qt everyday and the apps look pretty nice. If you are _really_  
picky there are a few things that don't quite look right but those  
can be fixed with some patience. Just look at the latest Adobe  
Reader. It was done with Qt (I think). I think also Abode LightRoom  
and/or Adobe Photoshop elements were also done using Qt.

Objective-C is a really nice language and easy to learn, but you have  
to leave most things you know about C++ "at the door" as they do NOT  
apply with Objective-C. If you have ever used Java, then Objective-C  
is most like Java.

Cheers
-- 
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services


On Oct 21, 2007, at 8:01 AM, Feng Ding wrote:

> I'm going to develop native OSX-based VTK applications, and I'm using
> C++. Possible to mix obj-c and C++ in programming? Let's say, using
> obj-c for the interface, and C++ for the core algorithm. I hope that
> the application looks more mac-like, so I'm not going to use cross
> platform libraries such as QT, FLTK, etc.
>
> On 10/20/07, Mike Jackson <imikejackson at gmail.com> wrote:
>> I do not have any examples of using pure Carbon. If you are trying to
>> stick with C++ I would look into Qt from TrollTech as that is a Cross
>> platform C++ Gui toolkit. VTK Provides a prebuilt plugin for Qt to
>> render VTK scenes. To create a Qt/VTK example is easy and straight
>> forward to accomplish.
>>
>> What exactly are you trying to do? Port an existing VTK app to OS X?
>> Use OS X to develop VTK based Apps? Use OS X to just visualize some
>> data using VTK? Learn VTK using OS X as the development environment?
>>
>> More information would help us help you.
>>
>> cheers
>> --
>> Mike Jackson   Senior Research Engineer
>> Innovative Management & Technology Services
>>
>>
>> On Oct 20, 2007, at 9:20 AM, Feng Ding wrote:
>>
>>> Yes, please. I really hope I can have a C++ example. Thank you!
>>>
>>> On 10/19/07, Mike Jackson <imikejackson at gmail.com> wrote:
>>>> Right. Cocoa _is_ Objective-C. The purpose of the example is to  
>>>> show
>>>> how to use VTK in a Cocoa Window. Are you wanting an example of how
>>>> to use VTK in a Carbon window? (which is C++).
>>>>
>>>> I helped write the example.
>>>>
>>>> --
>>>> Mike Jackson   Senior Research Engineer
>>>> Innovative Management & Technology Services
>>>>
>>>>
>>>> On Oct 19, 2007, at 3:55 AM, Feng Ding wrote:
>>>>
>>>>> Thank you! It seems to be written in Obj-C, do you have a C++
>>>>> version?
>>>>>
>>>>> Best regards,
>>>>> DING Feng
>>>>>
>>>>> On 10/18/07, Sean McBride <sean at rogue-research.com> wrote:
>>>>>> On 10/18/07 5:22 PM, Feng Ding said:
>>>>>>
>>>>>>> The SimpleCocoaVTK link
>>>>>>> (http://www.rogue-research.com/vtk/SimpleCocoaVTK1.1.zip) seems
>>>>>>> dead.
>>>>>>> Could you please email me a copy? Thanks!
>>>>>>
>>>>>> Ack!  So it is, I'll try to get it restored soon.  Here's the  
>>>>>> file.
>>>>>>
>>>>>> --
>>>>>> ____________________________________________________________
>>>>>> Sean McBride, B. Eng                 sean at rogue-research.com
>>>>>> Rogue Research                        www.rogue-research.com
>>>>>> Mac Software Developer              Montréal, Québec, Canada
>>>>>>
>>>>>>
>>>>> _______________________________________________
>>>>> This is the private VTK discussion list.
>>>>> Please keep messages on-topic. Check the FAQ at: http:// 
>>>>> www.vtk.org/
>>>>> Wiki/VTK_FAQ
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>>>
>>
>>




More information about the vtkusers mailing list