简体   繁体   English

Python中的vtk用户类

[英]vtk user class in Python

I'd like to extend vtkActor with my own stuff in Python. 我想在Python中用自己的东西扩展vtkActor I cannot find the way to call the base class __init__ , it looks there is no __init__ . 我找不到调用基类__init__ ,它看起来没有__init__ Maybe the vtk/Python wrapping does not allow such a user specialization, the super fails saying vtkActor is not a type... hmmm ... 也许vtk / Python包装不允许这样的用户专业化, super失败说vtkActor不是一个类型...... ......

how can I do something like : 我怎么能这样做:

class MyVtkActor(vtk.vtkActor):
  def __init__(self,*args):
    vtk.vtkActor.__init__(self,*args)
    # my stuff here

?

The Python-wrappers for VTK-classes are somewhat different. VTK类的Python包装器有些不同。 Have a look at this ipython-session: 看看这个ipython会话:

In [1]: import vtk

In [2]: type(vtk.vtkActor)
Out[2]: <type 'vtkclass'>

In [3]: type(vtk.vtkActor())
Out[3]: vtkobject

Basically, you can still inherit from vtkActor, but you cannot depend on the object-initialization that is used in Python. 基本上,您仍然可以从vtkActor继承,但您不能依赖于Python中使用的对象初始化。 You can still call the "normal" methods of this super-class explicitly, with self as first argument. 您仍然可以显式调用此超类的“正常”方法,将self作为第一个参数。

You must set all properties manually that a call to the contructor (in a C-meaning) would do. 您必须手动设置所有属性,以便调用contructor(以C语言表示)。

Remember: object construction is performed before initialization, so if you inherit from vtkActor, the normal vtkActor constructor is being called. 请记住:对象构造是在初始化之前执行的,因此如果从vtkActor继承,则会调用普通的vtkActor构造函数。 So by defining 所以通过定义

class MyActor(vtk.vtkActor):
    pass

you also get an vtkobject: 你也得到一个vtkobject:

In [8]: type(MyActor())
Out[9]: vtkobject

If you are in need of a real-life sample, you could look at this class . 如果你需要一个真实的样本,你可以看看这个课程 It's part of my PyLocator program. 这是我的PyLocator程序的一部分。 Each marker (blue/green balls on the screenshots) is such an object. 每个标记(屏幕截图上的蓝色/绿色球)都是这样的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM