I am currently able to get yaw orientation manipulation working using python for the 3D view. When I try and implement Pitch or Roll the code breaks and gives an error when I try and run it in 3D slicer. The current code I have is:
import random
import slicer
# Define the number of updates and the interval in seconds
update_count = 5
update_interval = 2 # seconds
# Create a function to update the 3D view
def update_3d_view():
if update_3d_view.counter < update_count:
yaw1 = random.uniform(-90, 90)
threeDWidget = slicer.app.layoutManager().threeDWidget(0)
threeDView = threeDWidget.threeDView()
threeDView.resetFocalPoint()
threeDView.yawDirection = threeDView.YawRight
threeDView.setPitchRollYawIncrement(yaw1)
threeDView.yaw()
print(f"Yaw Rotation: {yaw1} degrees")
update_3d_view.counter += 1
else:
slicer.app.processEvents() # Ensure any pending events are processed
update_3d_view.counter = 0
# Create a timer to trigger the updates
update_timer = qt.QTimer()
update_timer.timeout.connect(update_3d_view)
update_timer.start(update_interval * 1000)
My updated code looks like:
def update_3d_view():
if update_3d_view.counter < update_count:
yaw = random.uniform(-90, 90)
pitch = random.uniform(-45, 45) # Add pitch rotation
threeDWidget = slicer.app.layoutManager().threeDWidget(0)
threeDView = threeDWidget.threeDView()
threeDView.resetFocalPoint()
threeDView.yawDirection = threeDView.YawRight
threeDView.setPitchRollYawIncrement(pitch, 0, yaw) # Set pitch, roll, and yaw
threeDView.yaw()
print(f"Yaw Rotation: {yaw} degrees, Pitch Rotation: {pitch} degrees")
update_3d_view.counter += 1
else:
slicer.app.processEvents()
the error I get when I add pitch to the code is:
ValueError: Called setPitchRollYawIncrement(double newPitchRollYawIncrement) → void with wrong number of arguments: (-19.14680338362855, 0, 61.92372516991415)
It looks like its not accepting setPitchRollYawIncrement as all three just for yaw.
Any help or guidance in the right direction would be appreciated
Thanks