简体   繁体   中英

How to interact with vtkplotter using custom functions?

I am trying to change the position of a plane at regular time interval in vtkplotter 3D plot. I could not find a builtin method to add this functionality.

I tried implementing it using threads but it appears that the position update only happens on mouseclick events.

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()

How to implement this correctly ?

You need to render the scene in the loop. I would try something easier like:

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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