Adding some model motion to overlay

For image guided interventions we typically need some control over the position of model elements. Here we add a few lines of code to our update function to make the overlaid model move. You should end up with something like this …

01 - Add some movement to the models

Create a copy of and call it or similar.

Edit the update method for the OverlayApp class, to call a new method called _move_model.

def update(self):
     _, image =

     #add a method to move the rendered models


Then add a new method called _move_model to the class.

def _move_model(self):
     #Iterate through the rendered models
     for actor in self.vtk_overlay_window.get_foreground_renderer().GetActors():
         #get the current orientation
         orientation = actor.GetOrientation()
         #increase the rotation around the z-axis by 1.0 degrees
         orientation = [orientation[0] , orientation[1], orientation[2] + 1.0]
         #add update the model's orientation

Leave the rest of the file as is, and try running the application with


or similar. If successful you should see a live video stream overlaid with a rendered surface model. The surface model should slowly rotate, like in the video at the top of the page. Congratulations. Note that you can still use the VTK interactor to move the camera around or change the model representation. Have a play around and see how it interacts with the model rotation.

You can download a finished example and compare. Play around with it, experiment with different ways to move the model or to change the opacity etc.

Next we will add some code to detect an ArUco marker and “pin” the model to it