Commit daaeb95e authored by Thomas Dowrick's avatar Thomas Dowrick

Issue #90: Fix linting

parent ba2745a6
......@@ -15,4 +15,3 @@ slice_viewer = TrackedSliceViewer(dicom_path, tracker)
slice_viewer.start()
qApp.exec_()
"""
Module to show slice views of volumetric data.
"""
import os
import vtk
import numpy as np
from PySide2 import QtWidgets
from PySide2.QtCore import QTimer
from sksurgeryvtk.widgets.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from sksurgeryvtk.widgets.QVTKRenderWindowInteractor \
import QVTKRenderWindowInteractor
import cv2
import cv2.aruco as aruco
#pylint:disable=too-many-instance-attributes
class VTKResliceWidget(QVTKRenderWindowInteractor):
""" Widget to show a single slice of DICOM Data.
:param reader: vtkDICOMImageReader
:param axis: x/y/z axis selection
:param parent: parent QWidget.
"""
def __init__(self, reader, axis, parent):
if axis not in ['x', 'y', 'z']:
......@@ -23,16 +26,19 @@ class VTKResliceWidget(QVTKRenderWindowInteractor):
self.axis = axis
# Calculate the center of the volume
self.xMin, self.xMax, self.yMin, self.yMax, self.zMin, self.zMax = \
reader.GetExecutive().GetWholeExtent(reader.GetOutputInformation(0))
self.x_min, self.x_max, self.y_min, self.y_max, self.z_min, self.z_max \
= reader.GetExecutive().GetWholeExtent(
reader.GetOutputInformation(0))
self.xSpacing, self.ySpacing, self.zSpacing = reader.GetOutput().GetSpacing()
self.x0, self.y0, self.z0 = reader.GetOutput().GetOrigin()
self.center = [self.x0 + self.xSpacing * 0.5 * (self.xMin + self.xMax),
self.y0 + self.ySpacing * 0.5 * (self.yMin + self.yMax),
self.z0 + self.zSpacing * 0.5 * (self.zMin + self.zMax)]
self.x_spacing, self.y_spacing, self.z_spacing = \
reader.GetOutput().GetSpacing()
self._x0, self.y_0, self.z_0 = reader.GetOutput().GetOrigin()
self.center =\
[self.x_0 + self.x_spacing * 0.5 * (self.x_min + self.x_max),
self.y_0 + self.y_spacing * 0.5 * (self.y_min + self.y_max),
self.z_0 + self.z_spacing * 0.5 * (self.z_min + self.z_max)]
self.lut = vtk.vtkLookupTable()
self.lut.SetTableRange(-1000, 1000)
......@@ -66,22 +72,25 @@ class VTKResliceWidget(QVTKRenderWindowInteractor):
self.renderer.ResetCamera(self.actor.GetBounds())
self.GetRenderWindow().AddRenderer(self.renderer)
def set_slice_position(self, position):
def set_slice_position(self, pos):
""" Set the slice position in the volume """
position = int(position)
pos = int(pos)
if self.axis == 'x':
position = np.clip(position, self.xMin, self.xMax)
self.actor.SetDisplayExtent(position, position, self.yMin, self.yMax, self.zMin, self.zMax)
pos = np.clip(pos, self.x_min, self.x_max)
self.actor.SetDisplayExtent(
pos, pos, self.y_min, self.y_max, self.z_min, self.z_max)
if self.axis == 'y':
position = np.clip(position, self.yMin, self.yMax)
self.actor.SetDisplayExtent(self.xMin, self.xMax, position, position, self.zMin, self.zMax)
pos = np.clip(pos, self.y_min, self.y_max)
self.actor.SetDisplayExtent(
self.x_min, self.x_max, pos, pos, self.z_min, self.z_max)
if self.axis == 'z':
position = np.clip(position, self.zMin, self.zMax)
self.actor.SetDisplayExtent(self.xMin, self.xMax, self.yMin, self.yMax, position, position)
pos = np.clip(pos, self.z_min, self.z_max)
self.actor.SetDisplayExtent(
self.x_min, self.x_max, self.y_min, self.y_max, pos, pos)
# Fill widget with slice by moving camera
self.renderer.ResetCamera(self.actor.GetBounds())
......@@ -91,7 +100,7 @@ class VTKSliceViewer(QtWidgets.QWidget):
""" Othrogonal slice viewer showing Axial/Sagittal/Coronal views
:param dicom_dir: path to folder containig dicom data """
def __init__(self, dicom_dir):
def __init__(self, dicom_dir):
super().__init__()
......@@ -109,23 +118,23 @@ class VTKSliceViewer(QtWidgets.QWidget):
self.fourth_panel_renderer.SetBackground(.1, .2, .1)
self.x = VTKResliceWidget(self.reader, 'x', self.frame)
self.y = VTKResliceWidget(self.reader, 'y', self.frame)
self.z = VTKResliceWidget(self.reader, 'z', self.frame)
self.x_view = VTKResliceWidget(self.reader, 'x', self.frame)
self.y_view = VTKResliceWidget(self.reader, 'y', self.frame)
self.z_view = VTKResliceWidget(self.reader, 'z', self.frame)
self.layout.addWidget(self.x, 0, 0)
self.layout.addWidget(self.y, 0, 1)
self.layout.addWidget(self.z, 1, 0)
self.layout.addWidget(self.x_view, 0, 0)
self.layout.addWidget(self.y_view, 0, 1)
self.layout.addWidget(self.z_view, 1, 0)
self.x.GetRenderWindow().Render()
self.y.GetRenderWindow().Render()
self.z.GetRenderWindow().Render()
self.x_view.GetRenderWindow().Render()
self.y_view.GetRenderWindow().Render()
self.z_view.GetRenderWindow().Render()
self.fourth_panel = QVTKRenderWindowInteractor(self.frame)
self.fourth_panel.GetRenderWindow().AddRenderer(
self.fourth_panel_renderer)
for view in [self.x, self.y, self.z]:
for view in [self.x_view, self.y_view, self.z_view]:
self.fourth_panel_renderer.AddActor(view.actor)
self.layout.addWidget(self.fourth_panel, 1, 1)
......@@ -137,9 +146,9 @@ class VTKSliceViewer(QtWidgets.QWidget):
:param y: slice 2 position
:param z: slice 3 position
"""
self.x.set_slice_position(x_pos)
self.y.set_slice_position(y_pos)
self.z.set_slice_position(z_pos)
self.x_view.set_slice_position(x_pos)
self.y_view.set_slice_position(y_pos)
self.z_view.set_slice_position(z_pos)
self.fourth_panel.GetRenderWindow().Render()
......@@ -150,6 +159,7 @@ class VTKSliceViewer(QtWidgets.QWidget):
class TrackedSliceViewer(VTKSliceViewer):
#pylint:disable=invalid-name
""" Orthogonal slice viewer combined with tracker to
control slice position.
:param dicom_dir: Path to folder containing dicom data.
......@@ -174,6 +184,7 @@ class TrackedSliceViewer(VTKSliceViewer):
self.update_slice_positions(x, y, z)
def start(self):
#pylint:disable=attribute-defined-outside-init, no-member
"""Show the overlay widget and
set a timer running"""
......
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