如何使用自定义功能与vtkplotter进行交互?

问题描述 投票:0回答:1

我正在尝试按固定的时间间隔在vtkplotter 3D图中更改平面的位置。我找不到添加此功能的内置方法。

我尝试使用线程来实现它,但是位置更新仅发生在mouseclick事件上。

import threading
import time
from vtkplotter import Plane, show

class Vol:
    def __init__(self):
        self.a = Plane(normal=(0, 0, 1), sx=10, sy=10)
        self.b = Plane(normal=(0, 1, 0), sx=10, sy=10)
        self.c = Plane(normal=(1, 0, 0), sx=10, sy=10)
        self.thread = threading.Thread(target=self.background)
        self.thread.start()
        show(self.a, self.b, self.c, bg="w")

    def background(self):
        while True:
            if hasattr(self, "a"):
                for i in range(-5, 6):
                    self.a.SetPosition(0, 0, i)
                    time.sleep(0.5)

if __name__ == "__main__":
    Vol()

如何正确实现?

python vtk
1个回答
0
投票

您需要在循环中渲染场景。我会尝试一些更简单的方法:

import time
from vtkplotter import *

a = Plane(normal=(0, 0, 1), sx=10, sy=10)
b = Plane(normal=(0, 1, 0), sx=10, sy=10)
c = Plane(normal=(1, 0, 0), sx=10, sy=10)

vp = show(a, b, c, bg="w", viewup='z', interactive=False)

for i in range(-5, 6):
    a.z(i).color(i)
    time.sleep(0.5)
    #show() # or just:
    vp.interactor.Render()

interactive()
© www.soinside.com 2019 - 2024. All rights reserved.