我正在尝试在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()
如何正确实施?
答案 0 :(得分: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()