Move 3D focal point using mouse or keyboard

I would like to know how to use the mouse or keyboard in the 3D view to move the focal point of the camera away from me or closer to me. I know how to move it sideways by using the mouse middle-click + drag. I also know how to rotate around the focal point using the mouse left-click and drag.

But whenever I use the mouse wheel to “travel” through a structure (or mouse right-click + drag), the movement stops as I approach the focal point, so it is not possible to travel through a 3D structure if the focal point is in the structure’s interior (since I’m just zooming without actually moving the focal point).

So: how to I move the focal point away from me or towards me in a continuous manner, using the keyboard or mouse?

Yes, zooming just moves the camera towards or away from the focal point, but not changes the focal point position, so this is not suitable for exploring a volume, but it is for inspecting what is in the camera’s focal point.

There are many options for exploring navigating in space, for example to move through vasculature, airways, or intestines.

  1. Virtual reality

The most natural and effective way of navigating through a volume is via virtual reality, using SlicerVirtualReality extension (you will get inside the Slicer scene by a single click). You can use any OpenVR compatible headsets (Oculus Rift, HTC Vive, any Windows MR devices) and fly through the volume; or grab the scene with two hands and pull yourself through it; or grab any object in your hand and move/rotate to inspect it.

  1. Use camera manouver

You can change the focal point position by rotating the camera by approximately 90 degrees, and pan the camera (Shift+Left-click-and-drag into any direction), and rotate it back by 90 degrees.

  1. Enable keyboard or mouse shortcuts to translate the focal point along with the camera

For example, you can add a keyboard shortcut “Ctrl-Up” and “Ctrl-Down” and “Ctrl+Mousewheel” to move forward and backward by copy-pasting this code into the Python console:

threeDViewWidget =
cameraDisplayableManager = threeDViewWidget.threeDView().displayableManagerByClassName('vtkMRMLCameraDisplayableManager')
cameraWidget = cameraDisplayableManager.GetCameraWidget()

# Make Ctrl + Arrow Up/Down key translate forward/backward
cameraWidget.SetKeyboardEventTranslation(cameraWidget.WidgetStateIdle, vtk.vtkEvent.ControlModifier, '\0', 0, "Down", cameraWidget.WidgetEventCameraTranslateBackwardZ)
cameraWidget.SetKeyboardEventTranslation(cameraWidget.WidgetStateIdle, vtk.vtkEvent.ControlModifier, '\0', 0, "Up", cameraWidget.WidgetEventCameraTranslateForwardZ)

# Make Ctrl + Mousewheel translate forward/backward
cameraWidget.SetEventTranslation(cameraWidget.WidgetStateIdle, vtk.vtkCommand.MouseWheelForwardEvent, vtk.vtkEvent.ControlModifier, cameraWidget.WidgetEventCameraTranslateBackwardZ)
cameraWidget.SetEventTranslation(cameraWidget.WidgetStateIdle, vtk.vtkCommand.MouseWheelBackwardEvent, vtk.vtkEvent.ControlModifier, cameraWidget.WidgetEventCameraTranslateForwardZ)
  1. Use Endoscopy module

Endoscopy module can move the camera along a curve. You can generate the curve by manually dropping points, or automatically using VMTK extension’s Extract Centerline module. Centerline extraction works very well for vasculature, intestines, etc. This method can be used alone or in combination with the above described methods.

  1. Focus on markup control point

You can focus the camera on any control point of a markups node by going to Markups module / Control points, right-click on the control point, and choose “Refocus all cameras”.

Would these options work for you? What kind of data are you visualizing?

Thanks! At the moment, method 1 is out because it needs special hardware. Method 2 is what I was already doing as a workaround. But I am very pleased with method 3 with the mousewheel. I have put the code into ~/ to load it automatically.

The data I’m looking at are CT images of human cochleas with surroundings.