How to pull Position and Focal Point data from default scene camera for camera angle extension

Hi folks,

I’m trying to create an extension which will calculate the angle of the default scene camera w.r.t. the subject in the slicer 3D scene. This would be analogous determining the C-Arm LAO/RAO and CRA/CAU angles for proper image orientation.

The calculation is pretty straightforward and can be done with nothing but the camera position and focal point, but I can’t seem to obtain these values using GetPosition and GetFocalPoint. Here are some code snips:

>>> defaultCam = slicer.mrmlScene.GetNodeByID('vtkMRMLCameraNode1')
>>> defaultCamPosition = defaultCam.GetPosition()
>>> print(defaultCamPosition)
_000001eb844fabd8_p_void

On the other hand, GetCameraAngle does function as expected:

>>> viewAngle1 = defaultCam.GetViewAngle()
>>> print(viewAngle1)
30.0

Additionally, both SetPosition and SetFocalPoint function as expected. In fact, all of these are listed as valid member functions for the vtkMRMLCameraNode Class:

Finally, if I browse to this node in the slicer data module, all of these values are listed in the node information.

image

Any ideas on how to programmatically obtain the default scene camera position and focal point values?

Thanks for the help.

You can use GetPosition(double*) variant:

>>> defaultCam = slicer.mrmlScene.GetNodeByID('vtkMRMLCameraNode1')
>>> pos=[0,0,0]
>>> defaultCam.GetPosition(pos)
>>> pos
[54.62253179056516, 118.36363864842811, 61.73342989137638]
1 Like

Thanks Andras, I suppose I misunderstood the *double variant of this function. It’s a void function which assigns ‘None’ to the output, but changes the input argument to the position. For example:

>>> pos = [0,0,0]
>>> cameraPosition = defaultCam.GetPosition(pos)
>>> print(cameraPosition)
None
>>> pos
[3.0, 3.0, 3.0]