From: Masato A. <as...@so...> - 2014-09-19 10:51:13
|
From: Masato Asou <as...@so...> Date: Fri, 19 Sep 2014 09:58:48 +0900 (JST) > I am using VTK and SWIG in my application. My class have one method > SetUSG(vtkUnstructuredGrid *) and two overloaded method > SetUSG2(vtkUnstructuredGrid *) and SetUSG2(vtkUnstructuredGrid *, int). > I wrote %typename in my .i file. Then, I can call SetUSG() from > Python. However, I can't call SetUSG2() from Python. I have fixed this problem by myself. Insert following code in my A.i. $ git diff diff --git a/A.i b/A.i index 6abed10..542bd30 100644 --- a/A.i +++ b/A.i @@ -15,4 +15,12 @@ if ($1 == NULL) {SWIG_fail;} } +%typecheck(SWIG_TYPECHECK_POINTER) vtkUnstructuredGrid * { + vtkUnstructuredGrid *usg; + usg = (vtkUnstructuredGrid*)vtkPythonUtil::GetPointerFromObject($input, "vt + if (usg == NULL) {SWIG_fail;} +} + +%typemap(typecheck) vtkPythonUtil::GetObjectFromPointer = vtkUnstructuredGrid * + %include "A.h" $ python <snip> >>> from vtk import * >>> import A >>> a = A.A() >>> usg = vtkUnstructuredGrid() >>> a.SetUSG(usg) >>> a.SetUSG2(usg) >>> a.SetUSG2(usg, 3) Thanks. -- ASOU Masato |