混合 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 中调用我的函数:
import VTKUtilities
import vtk
pd = vtk.vtkPolyData()
VTKUtilities.MeshfromVTKPolyData(pd)
我收到这样的错误:
NotImplementedError: Wrong number of arguments... for VTKUtilities_MeshfromVTKPolyData
...
Possible prototypes are VTKUtilities::MeshfromVTKPolyData(vtkPolyData *);
我一直在阅读有关类型映射的内容,但我认为我不必搞乱它,因为 SWIG 应该为我处理这个问题?
有人可以告诉我我的流量广告中缺少什么吗?可能需要一些修复吗?
Here is my class:
#include <vtkPolyData>
class VTKUtilities
Mesh3D MeshfromVTKPolyData(vtkPolyData* pdmesh)
{
Mesh3D mesh;
//...
//my conversion code to do the actual conversion
//...
return mesh;
}
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)
I get errors like :
NotImplementedError: Wrong number of arguments... for VTKUtilities_MeshfromVTKPolyData
...
Possible prototypes are VTKUtilities::MeshfromVTKPolyData(vtkPolyData *);
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过以下方式成功包装了参数为 vtkPolyData 的函数:
首先,您必须在 swig
.i
文件中包含 vtkPythonUtil:然后,您必须在 swig
.i 中映射 vtkPolydata
文件:我在 ITK itkVTKGlue 中找到了该文件。
最后,您需要将您的模块与库
vtkPythonCore
链接I succeed to wrapping functions whose arguments are vtkPolyData by doing this way:
First, you have to include vtkPythonUtil in swig
.i
file:Then, you have to map the vtkPolydata in the swig
.i
file:I find that in ITK itkVTKGlue.
Finally, you need to link your module with the library
vtkPythonCore
这是 vtk.i 为 VTK 的类提供 SWIG 类型映射项目中定义的类的内存管理挂钩,这些类派生自 SWIG 包装的 VTK 对象。
这里的代码
是完整的代码。这是使用 VTK 8 和 SWIG 3.7 进行测试的。请注意,上述链接包含示例,并且可能包含未来的更新。
如果您的 API 使用 vtkObjectBase 和 vtkDataObject,您的 SWIG .i 文件将包括:
您的 API 中将出现每个 VTK 类一个宏调用。
用法示例
如果您定义一个从 vtkObject 派生的类或其名为 DataAdaptor 的子类之一,您的 SWIG .i 文件将包括:
请注意,您还需要为您的类 API 中的任何 VTK 类(包括 vtkObjectBase)调用 VTK_SWIG_INTEROP。
Here is a vtk.i providing SWIG typemaps for VTK's classes and memory management hooks for classes defined within your project derived from VTK Objects wrapped by SWIG.
Code
here is the code in its entirety. this is tested with VTK 8 and SWIG 3.7. Note that the above link includes examples and may include future updates.
If your API makes use of vtkObjectBase and vtkDataObject your SWIG .i file would include:
There will be one macro invocation per VTK class appearing in your API.
Example usage
If you define a class derived from vtkObject or one of its subclasses called DataAdaptor your SWIG .i file would include:
Note that you will also need to call VTK_SWIG_INTEROP for any VTK classes in your class's API including vtkObjectBase.