1 /*=========================================================================
2 
3   Program: GDCM (Grassroots DICOM). A DICOM library
4 
5   Copyright (c) 2006-2011 Mathieu Malaterre
6   All rights reserved.
7   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 
9      This software is distributed WITHOUT ANY WARRANTY; without even
10      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11      PURPOSE.  See the above copyright notice for more information.
12 
13 =========================================================================*/
14 %module(docstring="A VTK/GDCM binding") vtkgdcm
15 #pragma SWIG nowarn=504,510
16 
17 //%pragma(csharp) moduleimports=%{
18 //using Kitware.VTK;
19 //%}
20 
21 #if defined(SWIGCSHARP)
22 %{
23 #define SWIGCSHARP
24 %}
25 #endif
26 
27 #if defined(SWIGPHP)
28 %{
29 #define SWIGPHP
30 %}
31 #endif
32 
33 %{
34 //#define VTK_MAJOR_VERSION 7
35 //#define VTK_MINOR_VERSION 1
36 //#define VTK_BUILD_VERSION 1
37 //#define VTK_VERSION "7.1.1"
38 %}
39 
40 #define VTK_OVERRIDE override
41 #define VTK_FINAL final
42 #define VTK_DELETE_FUNCTION = delete
43 #define VTK_NEWINSTANCE
44 #define VTK_LEGACY(X)
45 
46 %{
47 // Let's reproduce the stack of include, when one would include vtkSetGet:
48 #include "vtkConfigure.h"
49 #include "vtkType.h"
50 #include "vtkSystemIncludes.h"
51 #include "vtkSetGet.h"
52 #include <sstream>
53 
54 // Common stuff
55 #include "vtkObjectBase.h"
56 #include "vtkObject.h"
57 
58 #include "vtkStringArray.h"
59 #include "vtkMatrix4x4.h"
60 #include "vtkMedicalImageProperties.h"
61 
62 // Wrap vtkImageData
63 #include "vtkDataObject.h"
64 #include "vtkDataSet.h"
65 #include "vtkImageData.h"
66 #include "vtkPointSet.h"
67 #include "vtkPolyData.h"
68 
69 #include "vtkGDCMTesting.h"
70 
71 // same for vtkGDCMImageReader / vtkGDCMImageWriter so that we get all
72 // parent's member class functions properly wrapped. (Update, SetFileName ...)
73 #include "vtkAlgorithm.h"
74 #include "vtkImageAlgorithm.h"
75 #include "vtkThreadedImageAlgorithm.h"
76 #include "vtkImageWriter.h"
77 #include "vtkImageReader2.h"
78 #include "vtkMedicalImageReader2.h"
79 #include "vtkGDCMImageReader.h"
80 #include "vtkGDCMImageWriter.h"
81 
82 #include "vtkImageExport.h"
83 #include "vtkImageImport.h"
84 #include "vtkImageCast.h"
85 #include "vtkVolumeReader.h"
86 #include "vtkVolume16Reader.h"
87 
88 #include "vtkWindowToImageFilter.h"
89 
90 #include "vtkToolkits.h" // VTK_DATA_ROOT
91 %}
92 
93 //%typemap(csimports) vtkGDCMImageWriter %{
94 //%typemap(csimports) SWIGTYPE %{
95 //// I need to duplicate those also:
96 //using System;
97 //using System.Runtime.InteropServices;
98 //// my special import:
99 //using Kitware.VTK;
100 //using Kitware.mummy.Runtime;
101 //%}
102 
103 //%pragma(csharp) imclassimports=%{
104 //using System;
105 //using System.Runtime.InteropServices;
106 //using My.Own.Namespace;
107 //%}
108 
109 #if defined( USEACTIVIZ ) || defined (SWIGCSHARP)
110 %typemap(csimports) SWIGTYPE %{
111 // I need to duplicate those also:
112 using System;
113 using System.Runtime.InteropServices;
114 %}
115 #endif
116 
117 #if defined( USEACTIVIZ )
118 %typemap(csimports) SWIGTYPE %{
119 // my special import:
120 using Kitware.VTK;
121 //using Kitware.mummy.Runtime;
122 %}
123 #endif
124 
125 
126 
127 #define GDCM_EXPORT
128 #define VTK_EXPORT
129 #define VTK_COMMON_EXPORT
130 #define VTK_FILTERING_EXPORT
131 #define VTK_IO_EXPORT
132 #define VTK_IMAGING_EXPORT
133 #define VTK_RENDERING_EXPORT
134 #define VTKCOMMONCORE_EXPORT
135 #define VTKCOMMONMATH_EXPORT
136 #define VTKIOIMAGE_EXPORT
137 #define VTKCOMMONDATAMODEL_EXPORT
138 #define VTKCOMMONEXECUTIONMODEL_EXPORT
139 #define VTKRENDERINGCORE_EXPORT
140 #define VTKIMAGINGCORE_EXPORT
141 
142 
143 // FIXME. Including #include vtkSetGet would not work on siwg 1.3.33 ...
144 #define vtkGetMacro(name,type) virtual type Get##name ();
145 #define vtkSetMacro(name,type) virtual void Set##name (type _arg);
146 #define vtkBooleanMacro(name,type) \
147   virtual void name##On (); \
148   virtual void name##Off ();
149 #define vtkGetVector3Macro(name,type) virtual type *Get##name ();
150 #define vtkGetVector6Macro(name,type) virtual type *Get##name ();
151 #define vtkGetObjectMacro(name,type)  virtual type *Get##name ();
152 #define vtkSetClampMacro(name,type,min,max) virtual void Set##name (type _arg);
153 #define vtkSetStringMacro(name) virtual void Set##name (const char* _arg);
154 #define vtkGetStringMacro(name) virtual char* Get##name ();
155 #define vtkGetVectorMacro(name,type,count) virtual type *Get##name ();
156 #define vtkNotUsed(x) x
157 #define vtkGetVector2Macro(name,type) virtual type *Get##name ();
158 #define vtkSetVector2Macro(name,type) virtual void Set##name (type _arg1, type _arg2);
159 #define vtkSetVector3Macro(name,type) virtual void Set##name (type _arg1, type _arg2, type _arg3);
160 
161 
162 //%include "vtkConfigure.h"
163 
164 //%ignore vtkGDCMImageReader::GetOverlay;
165 //%ignore vtkGDCMImageReader::GetIconImage;
166 //
167 //%ignore vtkAlgorithm::GetOutputDataObject;
168 //%ignore vtkAlgorithm::GetInputDataObject;
169 //
170 //%ignore vtkImageAlgorithm::GetOutput;
171 //%ignore vtkImageAlgorithm::GetInput;
172 //%ignore vtkImageAlgorithm::GetImageDataInput;
173 
174 %ignore operator<<(ostream& os, vtkObjectBase& o);
175 
176 %ignore vtkMatrix4x4::operator[];
177 %ignore vtkMatrix4x4::Determinant(vtkMatrix4x4 &);
178 %ignore vtkMatrix4x4::Adjoint(vtkMatrix4x4 *in, vtkMatrix4x4 *out);
179 %ignore vtkMatrix4x4::Invert(vtkMatrix4x4 *in, vtkMatrix4x4 *out);
180 %ignore vtkMatrix4x4::Transpose(vtkMatrix4x4 *in, vtkMatrix4x4 *out);
181 // In VTK 5.8 we have to ignore the const variant:
182 %ignore vtkMatrix4x4::Invert(const vtkMatrix4x4 *in, vtkMatrix4x4 *out);
183 %ignore vtkMatrix4x4::Transpose(const vtkMatrix4x4 *in, vtkMatrix4x4 *out);
184 
185 %ignore vtkImageWriter::GetInput; // I am getting a warning on swig 1.3.33 because of vtkImageAlgorithm.GetInput
186 
187 // Let's wrap the following constants:
188 // this is only a subset of vtkSystemIncludes.h :
189 #define VTK_LUMINANCE       1
190 #define VTK_LUMINANCE_ALPHA 2
191 #define VTK_RGB             3
192 #define VTK_RGBA            4
193 
194 //#include "vtkConfigure.h"
195 //#define VTK_USE_64BIT_IDS
196 //
197 //#ifdef VTK_USE_64BIT_IDS
198 //typedef long long vtkIdType;
199 //#else
200 //typedef int vtkIdType;
201 //#endif
202 //typedef vtkIdType2 vtkIdType;
203 //%apply vtkIdType { vtkIdType }
204 //#define vtkIdType vtkIdType;
205 //%include "vtkType.h"
206 
207 #ifdef USEACTIVIZ
208 
209 %typemap(cstype) vtkDataObject * "vtkDataObject"
210 %typemap(csin) vtkDataObject * "$csinput.GetCppThis()"
211 /*
212   public vtkDataObject GetOutputDataObject(int port) {
213     IntPtr cPtr = vtkgdcmPINVOKE.vtkAlgorithm_GetOutputDataObject(swigCPtr, port);
214     SWIGTYPE_p_vtkDataObject ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_vtkDataObject(cPtr, false);
215     return ret;
216   }
217 */
218 %typemap(csout) (vtkDataObject*) {
219   IntPtr rawCppThisSwig = $imcall;
220   vtkDataObject data = new vtkDataObject( rawCppThisSwig, false, false );
221   return data;
222 }
223 
224 %typemap(cstype) vtkStringArray * "vtkStringArray"
225 %typemap(csin) vtkStringArray * "$csinput.GetCppThis()"
226 %typemap(csout) (vtkStringArray*) {
227   IntPtr rawCppThisSwig = $imcall;
228   vtkStringArray data = new vtkStringArray( rawCppThisSwig, false, false );
229   return data;
230 }
231 
232 %typemap(cstype) vtkPolyData * "vtkPolyData"
233 %typemap(csin) vtkPolyData * "$csinput.GetCppThis()"
234 %typemap(csout) (vtkPolyData*) {
235   IntPtr rawCppThisSwig = $imcall;
236   vtkPolyData data = new vtkPolyData( rawCppThisSwig, false, false );
237   return data;
238 }
239 
240 %typemap(cstype) vtkMatrix4x4 * "vtkMatrix4x4"
241 %typemap(csin) vtkMatrix4x4 * "$csinput.GetCppThis()"
242 %typemap(csout) (vtkMatrix4x4*) {
243   IntPtr rawCppThisSwig = $imcall;
244   vtkMatrix4x4 data = new vtkMatrix4x4( rawCppThisSwig, false, false );
245   return data;
246 }
247 
248 %typemap(cstype) vtkMedicalImageProperties * "vtkMedicalImageProperties"
249 %typemap(csin) vtkMedicalImageProperties * "$csinput.GetCppThis()"
250 %typemap(csout) (vtkMedicalImageProperties*) {
251   IntPtr rawCppThisSwig = $imcall;
252   vtkMedicalImageProperties data = new vtkMedicalImageProperties( rawCppThisSwig, false, false );
253   return data;
254 }
255 
256 %typemap(cstype) vtkImageData * "vtkImageData"
257 %typemap(csin) vtkImageData * "$csinput.GetCppThis()"
258 %typemap(csout) (vtkImageData *) {
259   IntPtr rawCppThisSwig = $imcall;
260   vtkImageData data = new vtkImageData( rawCppThisSwig, false, false );
261   //vtkImageData data = null;
262   //bool created;
263   //if( IntPtr.Zero != rawCppThisSwig )
264   //  {
265   //  data = (vtkImageData) Kitware.mummy.Runtime.Methods.CreateWrappedObject(
266   //    vtkImageData.MRClassNameKey, rawCppThisSwig, false, out created);
267   //  // created is true if the C# object was created by this call, false if it was already cached in the table
268   //  }
269   return data;
270 }
271 //
272 //%typemap(csout) (vtkDataObject *) {
273 //    vtkImageData data = null;
274 ////    uint mteStatus = 0;
275 ////    uint maxValue = uint.MaxValue;
276 ////    uint rawRefCount = 0;
277 ////    IntPtr rawCppThis =
278 ////vtkImageAlgorithm_GetOutput_06(base.GetCppThis(), ref mteStatus, ref
279 ////maxValue, ref rawRefCount);
280 ////    IntPtr rawCppThisSwig = $imcall;
281 ////    if (IntPtr.Zero != rawCppThisSwig)
282 ////    {
283 ////        bool flag;
284 ////        data = (vtkImageData) Methods.CreateWrappedObject(mteStatus,
285 ////maxValue, rawRefCount, rawCppThisSwig, true, out flag);
286 ////        if (flag)
287 ////        {
288 ////            data.Register(null);
289 ////        }
290 ////    }
291 //    return data;
292 //}
293 //
294 #endif //USEACTIVIZ
295 
296 #ifdef USEACTIVIZ
297 // By hiding all New operator I make sure that no-one will ever be
298 // able to create a swig wrap object I did not decide to allow.
299 // For instance the only two objects allowed for now are:
300 // - vtkGDCMImageReader
301 // - vtkGDCMImageWriter
302 // BUG:
303 // when using %ignore vtkObjectBase::New()
304 // the vtkObjectBase_New() function is not generated, which is used
305 // internally in the new cstor that I provide
306 %csmethodmodifiers vtkObjectBase::New() "internal new"
307 %csmethodmodifiers vtkObject::New() "internal new"
308 %csmethodmodifiers vtkAlgorithm::New() "internal new"
309 %csmethodmodifiers vtkImageAlgorithm::New() "internal new"
310 %csmethodmodifiers vtkImageWriter::New() "internal new"
311 %csmethodmodifiers vtkImageReader2::New() "internal new"
312 %csmethodmodifiers vtkMedicalImageReader2::New() "internal new"
313 
314 %csmethodmodifiers vtkGDCMImageReader::New() "public new"
315 %csmethodmodifiers vtkGDCMImageWriter::New() "public new"
316 %csmethodmodifiers vtkGDCMTesting::New() "public new"
317 
318 #endif
319 
320 %newobject vtkGDCMTesting::New();
321 %newobject vtkGDCMImageWriter::New();
322 %newobject vtkGDCMImageReader::New();
323 
324 %delobject vtkObjectBase::Delete();
325 
326 // TODO: I need to fix Delete and make sure SWIG owns the C++ ptr (call ->Delete in the Dispose layer)
327 //%ignore vtkObjectBase::Delete;
328 %ignore vtkObjectBase::FastDelete;
329 %ignore vtkObjectBase::PrintSelf;
330 %ignore vtkObjectBase::PrintHeader;
331 %ignore vtkObjectBase::PrintTrailer;
332 %ignore vtkObjectBase::Print;
333 %ignore vtkObjectBase::PrintRevisions;
334 %ignore vtkObject::PrintSelf;
335 %ignore vtkAlgorithm::PrintSelf;
336 %ignore vtkImageAlgorithm::PrintSelf;
337 %ignore vtkImageAlgorithm::ProcessRequest;
338 %ignore vtkImageWriter::PrintSelf;
339 %ignore vtkImageReader2::PrintSelf;
340 %ignore vtkMedicalImageReader2::PrintSelf;
341 %ignore vtkGDCMImageReader::PrintSelf;
342 %ignore vtkGDCMImageWriter::PrintSelf;
343 
344 %typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") vtkGDCMTesting {
lock(this)345   lock(this) {
346     if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
347       swigCMemOwn = false;
348       vtkgdcmPINVOKE.vtkObjectBase_Delete(swigCPtr);
349     }
350     swigCPtr = new HandleRef(null, IntPtr.Zero);
351     base.Dispose(disposing);
352   }
353 }
354 %typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") vtkGDCMImageReader {
lock(this)355   lock(this) {
356     if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
357       swigCMemOwn = false;
358       vtkgdcmPINVOKE.vtkObjectBase_Delete(swigCPtr);
359     }
360     swigCPtr = new HandleRef(null, IntPtr.Zero);
361     base.Dispose(disposing);
362   }
363 }
364 %typemap(csdisposing_derived, methodname="Dispose", methodmodifiers="protected", parameters="bool disposing") vtkGDCMImageWriter {
lock(this)365   lock(this) {
366     if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
367       swigCMemOwn = false;
368       vtkgdcmPINVOKE.vtkObjectBase_Delete(swigCPtr);
369     }
370     swigCPtr = new HandleRef(null, IntPtr.Zero);
371     base.Dispose(disposing);
372   }
373 }
374 
375 %include "vtkObjectBase.h"
376 #ifdef SWIGCSHARP
377 %csmethodmodifiers vtkObjectBase::ToString() "public override"
378 #endif
379 %extend vtkObjectBase
380 {
ToString()381   const char *ToString()
382     {
383     static std::string buffer;
384     std::ostringstream os;
385     self->Print( os );
386     buffer = os.str();
387     return buffer.c_str();
388     }
389 };
390 
391 %include "vtkObject.h"
392 
393 %defaultdtor vtkGDCMTesting; // FIXME does not seems to be working
394 %include "vtkGDCMTesting.h"
395 
396 #ifndef USEACTIVIZ
397 %include "vtkStringArray.h"
398 %include "vtkMatrix4x4.h"
399 %include "vtkMedicalImageProperties.h"
400 %include "vtkDataObject.h"
401 %include "vtkDataSet.h"
402 %include "vtkImageData.h"
403 %include "vtkPointSet.h"
404 %include "vtkPolyData.h"
405 #endif
406 
407 %include "vtkAlgorithm.h"
408 %include "vtkImageAlgorithm.h"
409 #ifndef USEACTIVIZ
410 %include "vtkThreadedImageAlgorithm.h"
411 #endif
412 %include "vtkImageWriter.h"
413 
414 /*
415 By default swig generates:
416   public virtual SWIGTYPE_p_double GetImageOrientationPatient() {
417     IntPtr cPtr = vtkgdcmPINVOKE.vtkGDCMImageReader_GetImageOrientationPatient(swigCPtr);
418     SWIGTYPE_p_double ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_double(cPtr, false);
419     return ret;
420   }
421 while we would want:
422   public virtual double[] GetImageOrientationPatient() {
423     IntPtr source = vtkgdcmPINVOKE.vtkGDCMImageReader_GetImageOrientationPatient(swigCPtr);
424     double[] ret = null;
425     if (IntPtr.Zero != source)
426     {
427         ret = new double[6];
428         Marshal.Copy(source, destination, 0, destination.Length);
429     }
430     return ret;
431   }
432 
433 */
434 
435 //%typemap(ctype) double[] "double*"
436 %typemap(cstype) double * "double[]"
437 %typemap(csout) double* GetImagePositionPatient() {
438     IntPtr source = $imcall;
439     double[] destination = null;
440     if (IntPtr.Zero != source) {
441       destination = new double[3];
442       Marshal.Copy(source, destination, 0, destination.Length);
443     }
444     return destination;
445   }
446 
447 %typemap(csout) double* GetImageOrientationPatient() {
448     IntPtr source = $imcall;
449     double[] destination = null;
450     if (IntPtr.Zero != source) {
451       destination = new double[6];
452       Marshal.Copy(source, destination, 0, destination.Length);
453     }
454     return destination;
455   }
456 
457 %typemap(csout) double* GetDataSpacing() {
458     IntPtr source = $imcall;
459     double[] destination = null;
460     if (IntPtr.Zero != source) {
461       destination = new double[3];
462       Marshal.Copy(source, destination, 0, destination.Length);
463     }
464     return destination;
465   }
466 
467 %typemap(csout) double* GetDataOrigin() {
468     IntPtr source = $imcall;
469     double[] destination = null;
470     if (IntPtr.Zero != source) {
471       destination = new double[3];
472       Marshal.Copy(source, destination, 0, destination.Length);
473     }
474     return destination;
475   }
476 
477 %include "vtkImageReader2.h"
478 %include "vtkMedicalImageReader2.h"
479 
480 //%rename (vtkGDCMImageReaderInternal) vtkGDCMImageReader;
481 //%rename (vtkGDCMImageWriterInternal) vtkGDCMImageWriter;
482 
483 %include "vtkGDCMImageReader.h"
484 %include "vtkGDCMImageWriter.h"
485 %extend vtkGDCMTesting
486 {
487 %typemap(cscode) vtkGDCMTesting
488 %{
vtkGDCMTesting()489   public vtkGDCMTesting() : this(vtkgdcmPINVOKE.vtkGDCMTesting_New(), true) {
490   }
~vtkGDCMTesting()491   ~vtkGDCMTesting() {
492     Dispose();
493   }
494 %}
495 };
496 
497 %extend vtkGDCMImageReader
498 {
499 %typemap(cscode) vtkGDCMImageReader
500 %{
vtkGDCMImageReader()501   public vtkGDCMImageReader() : this(vtkgdcmPINVOKE.vtkGDCMImageReader_New(), true) {
502   }
~vtkGDCMImageReader()503   ~vtkGDCMImageReader() {
504     Dispose();
505   }
506 %}
507 };
508 
509 #ifdef SWIGPHP
510 %extend vtkGDCMImageReader
511 {
512 //public function __construct2($res=null) {
513 //  $this->_cPtr=vtkGDCMImageReader_Create();
514 //}
515 
516 //%typemap(out) vtkGDCMImageReader* (vtkGDCMImageReader::New)
517 //%{
518 //public function __construct($res=null) {
519 //  $this->_cPtr=vtkGDCMImageReader_Create();
520 //}
521 //%}
522 };
523 #endif
524 
525 %extend vtkGDCMImageWriter
526 {
527 %typemap(cscode) vtkGDCMImageWriter
528 %{
vtkGDCMImageWriter()529   public vtkGDCMImageWriter() : this(vtkgdcmPINVOKE.vtkGDCMImageWriter_New(), true) {
530   }
~vtkGDCMImageWriter()531   ~vtkGDCMImageWriter() {
532     Dispose();
533   }
534 %}
535 };
536 %clear double*;
537 %clear double* GetDataSpacing();
538 %clear double* GetDataOrigin();
539 
540 #ifdef SWIGPHP
541 %include "vtkWindowToImageFilter.h"
542 #endif
543 
544 #ifndef USEACTIVIZ
545 %include "vtkImageExport.h"
546 %include "vtkImageImport.h"
547 %include "vtkImageCast.h"
548 %include "vtkVolumeReader.h"
549 %include "vtkVolume16Reader.h"
550 #endif
551