Skip to content

Commit f45da98

Browse files
author
Jasper
committed
Fix for VTK6.2 issue.
1 parent 6a94862 commit f45da98

File tree

1 file changed

+167
-68
lines changed

1 file changed

+167
-68
lines changed

modules/viz/src/vtk/vtkCocoaInteractorFix.mm

Lines changed: 167 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,54 @@
11
/*M///////////////////////////////////////////////////////////////////////////////////////
2-
//
3-
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4-
//
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.
8-
//
9-
//
10-
// License Agreement
11-
// For Open Source Computer Vision Library
12-
//
13-
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14-
// Third party copyrights are property of their respective owners.
15-
//
16-
// Redistribution and use in source and binary forms, with or without modification,
17-
// are permitted provided that the following conditions are met:
18-
//
19-
// * Redistribution's of source code must retain the above copyright notice,
20-
// this list of conditions and the following disclaimer.
21-
//
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.
25-
//
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.
28-
//
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.
39-
//
40-
// Authors:
41-
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
42-
//
43-
// This workaround code was taken from PCL library(www.pointclouds.org)
44-
//
45-
//M*/
2+
//
3+
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4+
//
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.
8+
//
9+
//
10+
// License Agreement
11+
// For Open Source Computer Vision Library
12+
//
13+
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14+
// Third party copyrights are property of their respective owners.
15+
//
16+
// Redistribution and use in source and binary forms, with or without modification,
17+
// are permitted provided that the following conditions are met:
18+
//
19+
// * Redistribution's of source code must retain the above copyright notice,
20+
// this list of conditions and the following disclaimer.
21+
//
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.
25+
//
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.
28+
//
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.
39+
//
40+
// Authors:
41+
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
42+
//
43+
// This workaround code was taken from PCL library(www.pointclouds.org)
44+
//
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
49+
// commit a3e9fc9.
50+
//
51+
//M*/
4652

4753
#import <Cocoa/Cocoa.h>
4854
#include <vtkCocoaRenderWindow.h>
@@ -118,14 +124,14 @@ - (void)breakEventLoop
118124
[application stop:application];
119125

120126
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
121-
location:NSMakePoint(0.0,0.0)
122-
modifierFlags:0
123-
timestamp:0
124-
windowNumber:-1
125-
context:nil
126-
subtype:0
127-
data1:0
128-
data2:0];
127+
location:NSMakePoint(0.0,0.0)
128+
modifierFlags:0
129+
timestamp:0
130+
windowNumber:-1
131+
context:nil
132+
subtype:0
133+
data1:0
134+
data2:0];
129135
[application postEvent:event atStart:YES];
130136
}
131137

@@ -154,30 +160,121 @@ - (void)windowWillClose:(NSNotification*)aNotification
154160

155161
//----------------------------------------------------------------------------
156162

163+
#if VTK_MAJOR_VERSION >= 6 && VTK_MINOR_VERSION >=2
164+
157165
namespace cv { namespace viz
166+
{
167+
class vtkCocoaRenderWindowInteractorFix : public vtkCocoaRenderWindowInteractor
168+
{
169+
public:
170+
static vtkCocoaRenderWindowInteractorFix *New ();
171+
vtkTypeMacro (vtkCocoaRenderWindowInteractorFix, vtkCocoaRenderWindowInteractor)
172+
173+
virtual void Start ();
174+
virtual void TerminateApp ();
175+
176+
protected:
177+
vtkCocoaRenderWindowInteractorFix () {}
178+
~vtkCocoaRenderWindowInteractorFix () {}
179+
180+
private:
181+
vtkCocoaRenderWindowInteractorFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
182+
void operator = (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
183+
};
184+
185+
vtkStandardNewMacro (vtkCocoaRenderWindowInteractorFix)
186+
187+
vtkSmartPointer<vtkRenderWindowInteractor> vtkCocoaRenderWindowInteractorNew();
188+
189+
class vtkCocoaRenderWindowFix : public vtkCocoaRenderWindow
190+
{
191+
public:
192+
static vtkCocoaRenderWindowFix *New ();
193+
vtkTypeMacro ( vtkCocoaRenderWindowFix, vtkCocoaRenderWindow)
194+
195+
virtual vtkCocoaServerFix * GetCocoaServer ();
196+
virtual void SetCocoaServer (void* );
197+
198+
protected:
199+
vtkCocoaRenderWindowFix () {}
200+
~vtkCocoaRenderWindowFix () {}
201+
202+
private:
203+
vtkCocoaRenderWindowFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
204+
void operator = (const vtkCocoaRenderWindowFix&); // Not implemented.
205+
};
206+
207+
vtkStandardNewMacro (vtkCocoaRenderWindowFix)
208+
209+
vtkSmartPointer<vtkRenderWindow> vtkCocoaRenderWindowNew();
210+
}}
211+
212+
vtkCocoaServerFix * cv::viz::vtkCocoaRenderWindowFix::GetCocoaServer ()
213+
{
214+
return reinterpret_cast<vtkCocoaServerFix*> (this->GetCocoaServer ());
215+
}
216+
217+
void cv::viz::vtkCocoaRenderWindowFix::SetCocoaServer (void* server)
158218
{
159-
class vtkCocoaRenderWindowInteractorFix : public vtkCocoaRenderWindowInteractor
219+
this->SetCocoaServer (server);
220+
}
221+
222+
void cv::viz::vtkCocoaRenderWindowInteractorFix::Start ()
223+
{
224+
vtkCocoaRenderWindowFix* renWin = vtkCocoaRenderWindowFix::SafeDownCast(this->GetRenderWindow ());
225+
if (renWin != NULL)
160226
{
161-
public:
162-
static vtkCocoaRenderWindowInteractorFix *New ();
163-
vtkTypeMacro (vtkCocoaRenderWindowInteractorFix, vtkCocoaRenderWindowInteractor)
227+
vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (renWin->GetCocoaServer ());
228+
if (!renWin->GetCocoaServer ())
229+
{
230+
server = [vtkCocoaServerFix cocoaServerWithRenderWindow:renWin];
231+
renWin->SetCocoaServer (reinterpret_cast<void*> (server));
232+
}
233+
234+
[server start];
235+
}
236+
}
237+
238+
void cv::viz::vtkCocoaRenderWindowInteractorFix::TerminateApp ()
239+
{
240+
vtkCocoaRenderWindowFix *renWin = vtkCocoaRenderWindowFix::SafeDownCast (this->RenderWindow);
241+
if (renWin)
242+
{
243+
vtkCocoaServerFix *server = reinterpret_cast<vtkCocoaServerFix*> (renWin->GetCocoaServer ());
244+
[server stop];
245+
}
246+
}
247+
248+
vtkSmartPointer<vtkRenderWindowInteractor> cv::viz::vtkCocoaRenderWindowInteractorNew()
249+
{
250+
return vtkSmartPointer<vtkCocoaRenderWindowInteractorFix>::New();
251+
}
252+
253+
#else
254+
namespace cv { namespace viz
255+
{
256+
class vtkCocoaRenderWindowInteractorFix : public vtkCocoaRenderWindowInteractor
257+
{
258+
public:
259+
static vtkCocoaRenderWindowInteractorFix *New ();
260+
vtkTypeMacro (vtkCocoaRenderWindowInteractorFix, vtkCocoaRenderWindowInteractor)
164261

165-
virtual void Start ();
166-
virtual void TerminateApp ();
262+
virtual void Start ();
263+
virtual void TerminateApp ();
167264

168-
protected:
169-
vtkCocoaRenderWindowInteractorFix () {}
170-
~vtkCocoaRenderWindowInteractorFix () {}
265+
protected:
266+
vtkCocoaRenderWindowInteractorFix () {}
267+
~vtkCocoaRenderWindowInteractorFix () {}
171268

172-
private:
173-
vtkCocoaRenderWindowInteractorFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
174-
void operator = (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
175-
};
269+
private:
270+
vtkCocoaRenderWindowInteractorFix (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
271+
void operator = (const vtkCocoaRenderWindowInteractorFix&); // Not implemented.
272+
};
176273

177-
vtkStandardNewMacro (vtkCocoaRenderWindowInteractorFix)
274+
vtkStandardNewMacro (vtkCocoaRenderWindowInteractorFix)
178275

179-
vtkSmartPointer<vtkRenderWindowInteractor> vtkCocoaRenderWindowInteractorNew();
180-
}}
276+
vtkSmartPointer<vtkRenderWindowInteractor> vtkCocoaRenderWindowInteractorNew();
277+
}}
181278

182279
void cv::viz::vtkCocoaRenderWindowInteractorFix::Start ()
183280
{
@@ -209,3 +306,5 @@ - (void)windowWillClose:(NSNotification*)aNotification
209306
{
210307
return vtkSmartPointer<vtkCocoaRenderWindowInteractorFix>::New();
211308
}
309+
310+
#endif

0 commit comments

Comments
 (0)