Text overlayed on slice

Is it possible to add Python code to your scripted module that displays custom text on top of the slice view? In particular, I’m interested in displaying the slice position in a user-friendly way. I created an example of what I want to add to my scripted module in MS Paint; it is shown in the image below

Slice viewers have corner annotations, so you can easily add text in any corner. In case you want to add text to any other location, you need to add a VTK text actor (preferably in a displayable manager).

I tried the method in the link and it worked, but the text permanently disappears as soon as you move the slider. What is the easiest way to make sure that the text gets printed to upper right corner again every time the slice slider position is moved?

DataProbe module already uses corner annotations to display text, which erases any previous content. You can hide slice view annotations, as you can display any information you need anyway.

Thanks for all your help so far.
Last question: What is the syntax for calling a function every time the user scrolls to a different slice in red slice view using slider or mouse scroll? I want to do something analogous to this:


Except that it detects a change in axial position viewed in red slice, instead of checkbox being checked or unchecked.

You can get notification of slice position changes using standard VTK observations. See how AddObserver is used to observe a slice in this example.

Great, thanks. I understand how to do what I need now.

1 Like