如何使用自定义函数与 vtkplotter 交互?
How to interact with vtkplotter using custom functions?
我正在尝试在 vtkplotter
3D 绘图中以固定时间间隔更改平面的位置。我找不到添加此功能的内置方法。
我尝试使用线程实现它,但位置更新似乎只发生在鼠标点击事件上。
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()
如何正确实施?
您需要在循环中渲染场景。我会尝试更简单的方法,例如:
import time
from vedo 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()
interactive()
我正在尝试在 vtkplotter
3D 绘图中以固定时间间隔更改平面的位置。我找不到添加此功能的内置方法。
我尝试使用线程实现它,但位置更新似乎只发生在鼠标点击事件上。
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()
如何正确实施?
您需要在循环中渲染场景。我会尝试更简单的方法,例如:
import time
from vedo 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()
interactive()