Python code for aligning the camera or 3D view at specific angle

Can I have code for aligning the camera node or 3D view at specific angle. More specific, I have three points and want to align the camera node or 3D view such that the plane created through those three points should be visible just as line in 3D view or those three points should be visible colinear.

@uday_15 You can access the camera and change it’s position like this:

layoutManager = slicer.app.layoutManager()
threeDWidget = layoutManager.threeDWidget(0)
threeDView = threeDWidget.threeDView()
camera = threeDView.cameraNode()
camera.SetPosition( yourCamCoord  )
camera.SetFocalPoint( yourCamTargetCoord )

You could SetFocalPoint to one of your points and use the vector to a second point for the camera position, just modify the magnitude for your preferred camera distance.

More info on camera API:
https://apidocs.slicer.org/v4.8/classvtkMRMLCameraNode.html

3 Likes