混合 VTK 和 SWIG Python [英] mix VTK and SWIG Python

查看:40
本文介绍了混合 VTK 和 SWIG Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的课:

#include <vtkPolyData>

class VTKUtilities

Mesh3D MeshfromVTKPolyData(vtkPolyData* pdmesh)
{
   Mesh3D mesh;
   //...
   //my conversion code to do the actual conversion
   //...
   return mesh;
}

我尝试通过 SWIG 将其包装到 python但我尝试像这样在 python 中调用我的函数:

I tried wrapping this to python by SWIG but I try to call my function in python like this:

import VTKUtilities
import vtk

pd = vtk.vtkPolyData()
VTKUtilities.MeshfromVTKPolyData(pd)

我收到如下错误:

NotImplementedError: Wrong number of arguments... for VTKUtilities_MeshfromVTKPolyData
...
Possible prototypes are VTKUtilities::MeshfromVTKPolyData(vtkPolyData *);

我一直在阅读有关 typemaps 的一些内容,但我认为我不必纠结于此,因为 SWIG 应该为我处理这个问题?
有人可以告诉我我的流程广告中缺少什么可能有一些修复吗?

I have been reading something about typemaps but I thought I didn't have to mess with that as SWIG should handle this for me ?
Can someone tell me what is missing in my flow ad possibly some fix ?

推荐答案

我通过这样做成功地包装了参数为 vtkPolyData 的函数:

I succeed to wrapping functions whose arguments are vtkPolyData by doing this way:

首先,您必须在 swig .i 文件中包含 vtkPythonUtil:

First, you have to include vtkPythonUtil in swig .i file:

%{

#include <vtkPythonUtil.h>

}%

然后,您必须在 swig .i 文件中映射 vtkPolydata:

Then, you have to map the vtkPolydata in the swig .i file:

 %typemap(out) vtkPolyData* {

    PyImport_ImportModule("vtk");

    $result = vtkPythonUtil::GetObjectFromPointer ( (vtkPolyData*)$1 );
 }

%typemap(in) vtkPolyData* {

    $1 = (vtkPolyData*) vtkPythonUtil::GetPointerFromObject ( $input, "vtkPolyData" );

    if ( $1 == NULL ) { SWIG_fail; }
}

我在 ITK itkVTKGlue 中发现了这一点.

I find that in ITK itkVTKGlue.

最后,您需要将您的模块与库 vtkPythonCore

Finally, you need to link your module with the library vtkPythonCore

这篇关于混合 VTK 和 SWIG Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆