Commit 972b9e4f authored by Thomas Dowrick's avatar Thomas Dowrick

Issue #90: Example script moved to surgeryutils. Example usage added to class docstrings

parent f4a35633
""" Example usage of using the vtk reslice widgets.
`python vtk_reslice.py` - loads Viewer with mouse wheel scrolling.
'python vtk_reslice.py tracked' - loads Viewer with ArUco tracker for
slice control.
NB: scikit-surgeryaruco is not installed by default with scikit-surgeryvtk
You should pip install it manually to run the tracked demo.
"""
import sys
from PySide2 import QtWidgets
from sksurgeryvtk.widgets.vtk_reslice_widget import TrackedSliceViewer, \
MouseWheelSliceViewer
try:
from sksurgeryarucotrackers.arucotracker import ArUcoTracker
except:
print("scikit-surgeryarucotracker not installed, \
please install if you want to run the tracker example.")
qApp = QtWidgets.QApplication([])
dicom_path = 'tests/data/dicom/LegoPhantom_10slices'
n_args = len(sys.argv)
if n_args > 1 and sys.argv[1] == "tracked":
tracker = ArUcoTracker({})
tracker.start_tracking()
slice_viewer = TrackedSliceViewer(dicom_path, tracker)
else:
slice_viewer = MouseWheelSliceViewer(dicom_path)
slice_viewer.start()
qApp.exec_()
......@@ -74,7 +74,7 @@ class VTKResliceWidget(QVTKRenderWindowInteractor):
self.GetRenderWindow().AddRenderer(self.renderer)
# Remove unwanted mouse interaction behaviours
actions = ['MouseWheelForwardEvent', 'MouseWheeBackwardEvent', \
actions = ['MouseWheelForwardEvent', 'MouseWheelBackwardEvent', \
'LeftButtonPressEvent', 'RightButtonPressEvent']
for action in actions:
self._Iren.RemoveObservers(action)
......@@ -208,7 +208,18 @@ class VTKSliceViewer(QtWidgets.QWidget):
class MouseWheelSliceViewer(VTKSliceViewer):
""" Orthogonal slice viewer using mouse wheel to
control slice position. """
control slice position.
Example usage:
qApp = QtWidgets.QApplication([])
dicom_path = 'tests/data/dicom/LegoPhantom_10slices'
slice_viewer = MouseWheelSliceViewer(dicom_path)
slice_viewer.start()
qApp.exec_()
"""
def __init__(self, dicom_dir):
......@@ -242,7 +253,19 @@ class TrackedSliceViewer(VTKSliceViewer):
control slice position.
:param dicom_dir: Path to folder containing dicom data.
:param tracker: scikit-surgery tracker object,
used to control slice positions """
used to control slice positions.
Example usage:
qApp = QtWidgets.QApplication([])
dicom_path = 'tests/data/dicom/LegoPhantom_10slices'
tracker = ArUcoTracker()
slice_viewer = MouseWheelSliceViewer(dicom_path, tracker)
slice_viewer.start()
qApp.exec_()
"""
def __init__(self, dicom_dir, tracker):
super().__init__(dicom_dir)
......
......@@ -3,7 +3,7 @@ from sksurgeryvtk.widgets import vtk_reslice_widget
def test_slice_viewer(qtbot):
dicom_path = 'tests/data/dicom/LegoPhantom_3slices'
dicom_path = 'tests/data/dicom/LegoPhantom_10slices'
reslice = vtk_reslice_widget.VTKSliceViewer(dicom_path)
qtbot.addWidget(reslice)
......@@ -12,7 +12,7 @@ def test_slice_viewer(qtbot):
def test_mouse_scroll_slice_viewer(qtbot):
dicom_path = 'tests/data/dicom/LegoPhantom_3slices'
dicom_path = 'tests/data/dicom/LegoPhantom_10slices'
reslice = vtk_reslice_widget.MouseWheelSliceViewer(dicom_path)
qtbot.addWidget(reslice)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment