[vtkusers] Re: CocoaWindow.h/mm incomplete
Mike Jackson
maillist at bluequartz.net
Mon Dec 5 11:21:25 EST 2005
On Nov 29, 2005, at 10:28 AM, Sean McBride wrote:
> On 2005-11-28 19:35, Mike Jackson said:
>
>> I implemented what you have above but there seems to be a problem.
>> In my NSDocument Subclass, PFDocument, in the
>> windowControllerDidLoadNib method I call:
>>
>> [vtkView finalInit];
>>
>> Except that vtkView is still nill at that point. Which is kinda weird
>> since I know the constructor has already been called so the reference
>> in my PFDocument must not have been set yet. Are you over riding some
>> other method in your NSDocument Subclass? Or maybe I am missing some
>> hook up in Interface builder?
>
> Is 'vtkView' an IBOutlet? Have you connected it up in IB?
There were a couple things in IB that I was not hooking up correctly.
I now have that part working correctly.
>
>> If I put everything in the vtkCocoaGLView Subclass constructor then I
>> get a warning "invalid drawable" when _interactor->Initialize
>> (); is called. The warning seems to be harmless, but I would like
>> something that didn't produce warnings.
>
> If you look in vtkCocoaRenderWindow.mm, you'll see I added a comment
> about seeing that warning too. I never understood why, and agree it
> appears harmless.
>
> --
> ____________________________________________________________
> Sean McBride, B. Eng sean at rogue-research.com
> Rogue Research www.rogue-research.com
> Mac Software Developer Montréal, Québec, Canada
The reason that warning is appearing is that the window that contains
the NSView is not on screen yet, so there is no GL Context to draw
into. I got around the warning in the following ways.
In my VTKView class, which is a subclass of vtkCocoaGLView, I over
rode NSView:drawRect in the following way:
- (void)drawRect:(NSRect)theRect
{
NSLog(@"drawRect");
if ( _interactor->GetEnabled() == NO )
{
_interactor->Initialize();
vtkInteractorStyleTrackballCamera *trackball =
vtkInteractorStyleTrackballCamera::New();
[self getInteractor]->SetInteractorStyle(trackball);
trackball->Delete();
}
[super drawRect:theRect];
}
This method only gets called when the NSView needs to update itself,
not every time OpenGL is rendering, so this is low impact.
Also, in the constructor for VTKView I have the following:
-(id)initWithFrame:(NSRect)frame {
//NSLog(@"VTKView::initWithFrame");
if ( self = [super initWithFrame:frame] ) {
_renderer = vtkRenderer::New();
_cocoaRenderWindow = vtkRenderWindow::New();
_interactor = vtkRenderWindowInteractor::New();
_cocoaRenderWindow->SetWindowId([self window]);
_cocoaRenderWindow->SetDisplayId(self);
_cocoaRenderWindow->AddRenderer(_renderer);
_interactor->SetRenderWindow(_cocoaRenderWindow);
_interactor->Disable(); //Stops the Warning.
[self setVTKRenderWindow:(vtkCocoaRenderWindow*)
_cocoaRenderWindow];
}
// NSLog(@"Done with initWithFrame");
return self;
}
I am sure that there are certain circumstances where this may _not_
be the preferable way to do this, but this seems to work.
The type of App that I am writing is an NSDocument based Cocoa app
just in case anyone is interested in the basic design.
---
Mike Jackson
mike _at_ bluequartz dot net
More information about the vtkusers
mailing list