1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
41
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
43
// This workaround code was taken from PCL library(www.pointclouds.org)
45
// Modified by Jasper Shemilt to work with VTK 6.2
46
// The fix was needed because GetCocoaServer has been moved from
47
// vtkCocoaRenderWindowInteractor to vtkCocoaRenderWindow in VTK 6.2.
48
// This alteration to VTK happened almost a year ago according to the gitHub
53
#import <Cocoa/Cocoa.h>
54
#include <vtkCocoaRenderWindow.h>
55
#include <vtkCocoaRenderWindowInteractor.h>
56
#include <vtkObjectFactory.h>
57
#include <vtkSmartPointer.h>
59
//----------------------------------------------------------------------------
60
@interface vtkCocoaServerFix : NSObject
62
vtkCocoaRenderWindow* renWin;
65
+ (id)cocoaServerWithRenderWindow:(vtkCocoaRenderWindow*)inRenderWindow;
69
- (void)breakEventLoop;
73
//----------------------------------------------------------------------------
74
@implementation vtkCocoaServerFix
76
//----------------------------------------------------------------------------
77
- (id)initWithRenderWindow:(vtkCocoaRenderWindow *)inRenderWindow
81
renWin = inRenderWindow;
85
//----------------------------------------------------------------------------
86
+ (id)cocoaServerWithRenderWindow:(vtkCocoaRenderWindow *)inRenderWindow
88
vtkCocoaServerFix *server = [[[vtkCocoaServerFix alloc] initWithRenderWindow:inRenderWindow] autorelease];
92
//----------------------------------------------------------------------------
95
// Retrieve the NSWindow.
99
win = reinterpret_cast<NSWindow*> (renWin->GetRootWindow ());
101
// We don't want to be informed of every window closing, so check for nil.
104
// Register for the windowWillClose notification in order to stop the run loop if the window closes.
105
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
106
[nc addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:win];
109
// Start the NSApplication's run loop
110
NSApplication* application = [NSApplication sharedApplication];
114
//----------------------------------------------------------------------------
117
[self breakEventLoop];
120
//----------------------------------------------------------------------------
121
- (void)breakEventLoop
123
NSApplication* application = [NSApplication sharedApplication];
124
[application stop:application];
126
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
127
location:NSMakePoint(0.0,0.0)
135
[application postEvent:event atStart:YES];
138
//----------------------------------------------------------------------------
139
- (void)windowWillClose:(NSNotification*)aNotification
143
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
144
[nc removeObserver:self name:NSWindowWillCloseNotification object:nil];
148
int windowCreated = renWin->GetWindowCreated ();
151
[self breakEventLoop];
153
// The NSWindow is closing, so prevent anyone from accidently using it
154
renWin->SetRootWindow(NULL);
161
//----------------------------------------------------------------------------
163
#if VTK_MAJOR_VERSION >= 6 && VTK_MINOR_VERSION >=2
165
namespace cv { namespace viz
167
class vtkCocoaRenderWindowInteractorFix : public vtkCocoaRenderWindowInteractor
170
static vtkCocoaRenderWindowInteractorFix *New ();
171
vtkTypeMacro (vtkCocoaRenderWindowInteractorFix, vtkCocoaRenderWindowInteractor)
173
virtual void Start ();
174
virtual void TerminateApp ();
177
vtkCocoaRenderWindowInteractorFix () {}
178
~vtkCocoaRenderWindowInteractorFix () {}
181
vtkCocoaRenderWindowInteractorFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
182
void operator = (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
185
vtkStandardNewMacro (vtkCocoaRenderWindowInteractorFix)
187
vtkSmartPointer<vtkRenderWindowInteractor> vtkCocoaRenderWindowInteractorNew();
189
class vtkCocoaRenderWindowFix : public vtkCocoaRenderWindow
192
static vtkCocoaRenderWindowFix *New ();
193
vtkTypeMacro ( vtkCocoaRenderWindowFix, vtkCocoaRenderWindow)
195
virtual vtkCocoaServerFix * GetCocoaServer ();
196
virtual void SetCocoaServer (void* );
199
vtkCocoaRenderWindowFix () {}
200
~vtkCocoaRenderWindowFix () {}
203
vtkCocoaRenderWindowFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
204
void operator = (const vtkCocoaRenderWindowFix&); // Not implemented.
207
vtkStandardNewMacro (vtkCocoaRenderWindowFix)
209
vtkSmartPointer<vtkRenderWindow> vtkCocoaRenderWindowNew();
212
vtkCocoaServerFix * cv::viz::vtkCocoaRenderWindowFix::GetCocoaServer ()
214
return reinterpret_cast<vtkCocoaServerFix*> (this->GetCocoaServer ());
217
void cv::viz::vtkCocoaRenderWindowFix::SetCocoaServer (void* server)
219
this->SetCocoaServer (server);
222
void cv::viz::vtkCocoaRenderWindowInteractorFix::Start ()
224
vtkCocoaRenderWindowFix* renWin = vtkCocoaRenderWindowFix::SafeDownCast(this->GetRenderWindow ());
227
vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (renWin->GetCocoaServer ());
228
if (!renWin->GetCocoaServer ())
230
server = [vtkCocoaServerFix cocoaServerWithRenderWindow:renWin];
231
renWin->SetCocoaServer (reinterpret_cast<void*> (server));
238
void cv::viz::vtkCocoaRenderWindowInteractorFix::TerminateApp ()
240
vtkCocoaRenderWindowFix *renWin = vtkCocoaRenderWindowFix::SafeDownCast (this->RenderWindow);
243
vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (renWin->GetCocoaServer ());
248
vtkSmartPointer<vtkRenderWindowInteractor> cv::viz::vtkCocoaRenderWindowInteractorNew()
250
return vtkSmartPointer<vtkCocoaRenderWindowInteractorFix>::New();
254
namespace cv { namespace viz
256
class vtkCocoaRenderWindowInteractorFix : public vtkCocoaRenderWindowInteractor
259
static vtkCocoaRenderWindowInteractorFix *New ();
260
vtkTypeMacro (vtkCocoaRenderWindowInteractorFix, vtkCocoaRenderWindowInteractor)
262
virtual void Start ();
263
virtual void TerminateApp ();
266
vtkCocoaRenderWindowInteractorFix () {}
267
~vtkCocoaRenderWindowInteractorFix () {}
270
vtkCocoaRenderWindowInteractorFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
271
void operator = (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
274
vtkStandardNewMacro (vtkCocoaRenderWindowInteractorFix)
276
vtkSmartPointer<vtkRenderWindowInteractor> vtkCocoaRenderWindowInteractorNew();
279
void cv::viz::vtkCocoaRenderWindowInteractorFix::Start ()
281
vtkCocoaRenderWindow* renWin = vtkCocoaRenderWindow::SafeDownCast(this->GetRenderWindow ());
284
vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (this->GetCocoaServer ());
285
if (!this->GetCocoaServer ())
287
server = [vtkCocoaServerFix cocoaServerWithRenderWindow:renWin];
288
this->SetCocoaServer (reinterpret_cast<void*> (server));
295
void cv::viz::vtkCocoaRenderWindowInteractorFix::TerminateApp ()
297
vtkCocoaRenderWindow *renWin = vtkCocoaRenderWindow::SafeDownCast (this->RenderWindow);
300
vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (this->GetCocoaServer ());
305
vtkSmartPointer<vtkRenderWindowInteractor> cv::viz::vtkCocoaRenderWindowInteractorNew()
307
return vtkSmartPointer<vtkCocoaRenderWindowInteractorFix>::New();