How to do custom rotation sliders and transformation buttons with python?

Hi all,

I am currently working on a scripted module that requires a user to rotate segments beforehand (currently done in the transforms module). To improve user accessibility, I would like to implement 1 or 2 feature into my module directly. The first option is to create custom transformation sliders that will rotate a segment around its centroid. There is a nice guide for how to initialize rotation around a point here. However, I don’t think I can reasonable expect users to set this up themselves and would like to have custom rotation sliders in my module’s GUI that’ll do this. However, I cannot find much documentation on how I would actually implement this. The Room’s Eye View module in SlicerRT does essentially what I want (and way more) but I cannot decipher the source code.

I understand that transformation chains can be complicated so the alternative feature I’d like to add is a button that can access the transforms “interaction in 3D view” feature and toggle it on and off. The only difference I’d want to make is have it initialize the bounds based on a specific node and not all of the nodes for which the transformation is applied (e.g., initialize based on the segment but not the volume node). When initialized based on a segmentation node with a single segment, the interactive 3D box effectively allows the user to rotate the segment around its centroid.

So, I am wondering if there are any resources or python scripted examples with something similar that will point me in the right direction? I would greatly appreciate any help.


This topic may serve as a good starting point:

There is an interesting script and video at the end.

Thanks @rbumm

I had not see this video but unfortunately, it only demonstrates the code use to rotate around a point. I am stuck trying to create sliders that will do this automatically.

I did however, manage to implement the second feature I had outlined by following these instructions to call the widget from the transforms node. Maybe that’ll also help me figure out how the sliders work.

You may want to look at the 3D Slicer script repository,
maybe this snippet helps …

Would this be of help to you ?

Unless I misunderstood your requirement, this example connects a slider bar to a function, and forwards the cursor’s position to said function.

1 Like

Thanks you for your suggestion! However, I don’t think I have been clear with my problem. The issue I’m having is making custom GUI sliders that will apply a rotation to a segment. I understand how the transformation around a point works and it works great when I use the python console and transforms module. However, I am basically trying to make copies of those transforms rotation sliders in my own module that can rotate a segment around its centroid. This is to make it so the user does not need to keep going back and forth between my module and the transforms module or deal with using python to initialize the rotation around a point.

This is definitely helpful! Now I just have to figure out how to actually execute the function that I want to link up with the slider

I figured out how to add the sliders I wanted using the qMRMLTransformSliders widget. Here is the documentation. Slicer: qMRMLTransformSliders Class Reference