Animate, StartViewAnimation and StopViewAnimation: what are they in vtk.js?

Hi, I’m try to understand the VTK events system a little bit better.
I’m focusing on the animate method, which is enabled by the startViewAnimation method.

I’m struggling to understand what is its purpose, because, looking at the code, it seems to create a kind of “infinite rendering loop” as you can see below:

def animate(self, localTime = 0):
    #print("03")

    if len(self.viewsInAnimations) == 0:
        return

    nextAnimateTime = time.time() + 1.0 /  self.targetFrameRate
    
    for vId in self.viewsInAnimations:
        self.pushRender(vId, True, localTime)

    nextAnimateTime -= time.time()

    if self.targetFrameRate > self.maxFrameRate:
        self.targetFrameRate = self.maxFrameRate

    # HERE THE RECURSION STARTS
    if nextAnimateTime < 0:
        if nextAnimateTime < -1.0:
            self.targetFrameRate = 1
        if self.targetFrameRate > self.minFrameRate:
            self.targetFrameRate -= 1.0
        reactor.callLater(0.001, lambda: self.animate(localTime)) # << = **RECURSION**
    else:
        if self.targetFrameRate < self.maxFrameRate and nextAnimateTime > 0.005:
            self.targetFrameRate += 1.0
        reactor.callLater(nextAnimateTime, lambda: self.animate(localTime)) # << = **RECURSION**

So at the end the server is always busy in rendering… the same image.
Did I mess up with the code? Maybe the loop is supposed to break when the user release the left mouse button?

Thanks and regards,
Ennio

Yes the idea is to start the infinite loop on the mouse press and stop it at release. This allow us to control the rate at which we push images to the client rather than doing a regular render/push at mouse interaction rate which could hit more than 120 fps.

That is why we disable the render on interaction as a very first step.

Hi Sebastien,
thanks for your reply.
I’m looking into Start\Stop Animation.

I only have one concern: I tryed to print the stacktrace, and the console was forever writing the following output (also when the mouse was released (not clicked)):



pushRender
stillRender
pushRender
stillRender
pushRender
stillRender
pushRender
stillRender
pushRender
stillRender
pushRender
stillRender
pushRender
stillRender
pushRender

So, at the line number 372 (into the “startViewAnimation()”) I added these two lines:

    @exportRpc("viewport.image.animation.start")
    def startViewAnimation(self, viewId = '-1'):

        sView = self.getView(viewId)
        realViewId = str(self.getGlobalId(sView))

        isThere = realViewId in self.viewsInAnimations #   <=== THIS LINE...
        if isThere == False:                           #   <=== ...AND THAT ONE
            self.viewsInAnimations.append(realViewId)

        if len(self.viewsInAnimations) == 1:
            self.animate()

In that way, the 3 methods: animate(), pushRender() and stillRender() are called while the “mouse button” is pressed.
Otherwise I will have an infinite loop (as explained above).

Just because I’m trying to improve the performance, I’m wondering if there is a way to scale down the “quality” of the image, while the user is dragging the 3D model.

I’m not sure if the code was designed to work in another way.
Thanks and regards,
Ennio

Oh, I think I know why. You are using VTK and not ParaView. The ParaView may have been fixed but not the VTK protocol. I think we are using a set rather than a list so we never get a duplicate. Good catch, but you should compare with the PV one just in case as more fix may have been pushed to the protocol which should allow you to fix them back on the vtk side.

It will be a pleasure to compare both the protocol VTK and PV (which stand for Paraview I guess).
The problem here is: I don’t know where to find the Paraview part.
Actually I have the ParaviewWeb solution, but I didn’t find any reference to (e.g.) “startViewAnimation” method.

So I guess the methods names are different or maybe PV is related to something else.

Sorry for all these questions, but I’m to get confident with this framework.
Thanks,
bye
Ennio

The protocol in question are linked below: