diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c29cbc2..a1c43d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog ## vx.x.x +- Add method to edit axes label text & tests, hide one label on 2D viewer #389 - Fix failing unit test #394 - Add slider widget #365 - Removed VTK 8 variants from conda recipe. diff --git a/Wrappers/Python/ccpi/viewer/CILViewer.py b/Wrappers/Python/ccpi/viewer/CILViewer.py index aad89a13..ffbca441 100644 --- a/Wrappers/Python/ccpi/viewer/CILViewer.py +++ b/Wrappers/Python/ccpi/viewer/CILViewer.py @@ -1072,4 +1072,4 @@ def remove_clipping_plane(self): self.clipping_plane_initialised = False self.getRenderer().Render() - self.updatePipeline() + self.updatePipeline() \ No newline at end of file diff --git a/Wrappers/Python/ccpi/viewer/CILViewer2D.py b/Wrappers/Python/ccpi/viewer/CILViewer2D.py index b7fbcc82..a5e996d0 100644 --- a/Wrappers/Python/ccpi/viewer/CILViewer2D.py +++ b/Wrappers/Python/ccpi/viewer/CILViewer2D.py @@ -329,13 +329,17 @@ def ChangeOrientation(self, new_slice_orientation): self.UpdatePipeline(True) def OnKeyPress(self, interactor, event): + al = self._viewer.axisLabelsText if self.GetInputData() is None: return if self.reslicing_enabled and interactor.GetKeyCode() == "x": + self._viewer.setAxisLabels(['', al[1], al[2]], False) self.ChangeOrientation(SLICE_ORIENTATION_YZ) elif self.reslicing_enabled and interactor.GetKeyCode() == "y": + self._viewer.setAxisLabels([al[0], '', al[2]], False) self.ChangeOrientation(SLICE_ORIENTATION_XZ) elif self.reslicing_enabled and interactor.GetKeyCode() == "z": + self._viewer.setAxisLabels([al[0], al[1], ''], False) self.ChangeOrientation(SLICE_ORIENTATION_XY) elif interactor.GetKeyCode() == "a": self._viewer.autoWindowLevelOnSliceRange() diff --git a/Wrappers/Python/ccpi/viewer/CILViewerBase.py b/Wrappers/Python/ccpi/viewer/CILViewerBase.py index bcd52bb5..2f16553c 100644 --- a/Wrappers/Python/ccpi/viewer/CILViewerBase.py +++ b/Wrappers/Python/ccpi/viewer/CILViewerBase.py @@ -106,6 +106,8 @@ def __init__(self, dimx=600, dimy=600, renWin=None, iren=None, ren=None, debug=F ori.SetEnabled(1) ori.InteractiveOff() self.orientation_marker = ori + # axes labels + self.axisLabelsText = self.getCurrentAxisLabelsText() # holder for list of actors and widgets self.actors = {} @@ -394,3 +396,25 @@ def setVisualisationDownsampling(self, value): def getVisualisationDownsampling(self): return self.visualisation_downsampling + + def getCurrentAxisLabelsText(self): + '''Returns the current labels on the axis widget.''' + om = self.orientation_marker.GetOrientationMarker() + return [om.GetXAxisLabelText(), om.GetYAxisLabelText(), om.GetZAxisLabelText()] + + def setAxisLabels(self, labels=['x', 'y', 'z'], overwrite_flag=True): + '''Sets the axes widget labels. + + Parameters + ---------- + labels : list of str + overwrite_flag : bool + If True the attribute 'axisLabelText' is overwritten, if False it is not overwritten''' + if type(labels) != list: + raise TypeError("Labels must be a list of strings") + if overwrite_flag is True: + self.axisLabelsText = labels + om = self.orientation_marker.GetOrientationMarker() + om.SetXAxisLabelText(labels[0]) + om.SetYAxisLabelText(labels[1]) + om.SetZAxisLabelText(labels[2]) diff --git a/Wrappers/Python/ccpi/viewer/standalone_viewer.py b/Wrappers/Python/ccpi/viewer/standalone_viewer.py index 302495d2..a2102da2 100644 --- a/Wrappers/Python/ccpi/viewer/standalone_viewer.py +++ b/Wrappers/Python/ccpi/viewer/standalone_viewer.py @@ -113,7 +113,6 @@ def __init__(self, title="", viewer1_type='2D', viewer2_type='3D', *args, **kwar self.app = app self.set_up(title, viewer1_type, viewer2_type, *args, **kwargs) - self.show() def set_up(self, title, viewer1_type, viewer2_type=None, *args, **kwargs): ''' @@ -154,8 +153,8 @@ def main(): err = vtk.vtkFileOutputWindow() err.SetFileName("viewer.log") vtk.vtkOutputWindow.SetInstance(err) - standalone_viewer("Standalone Viewer", viewer1_type='2D', viewer2_type='3D') - + standalone_viewer_instance = standalone_viewer("Standalone Viewer", viewer1_type='2D', viewer2_type='3D') + standalone_viewer_instance.show() return 0 diff --git a/Wrappers/Python/test/test_CILViewerBase.py b/Wrappers/Python/test/test_CILViewerBase.py index e308fc95..75022588 100644 --- a/Wrappers/Python/test/test_CILViewerBase.py +++ b/Wrappers/Python/test/test_CILViewerBase.py @@ -29,6 +29,29 @@ print("skip_test is set to ", skip_test) +@unittest.skipIf(skip_test, "Skipping tests on GitHub Actions") +class CILViewerBaseTest(unittest.TestCase): + + def setUp(self): + '''Creates an instance of the CIL viewer base class.''' + self.CILViewerBase_instance = CILViewerBase() + + def test_setAxisLabels(self): + '''Edits the labels in the axes widget and checks they have been set correctly. + The test is performed with overwrite flag set to default, True, or False.''' + labels = ['a', 'b', 'c'] + self.CILViewerBase_instance.setAxisLabels(labels) + new_labels = self.CILViewerBase_instance.getCurrentAxisLabelsText() + self.assertEqual(new_labels, labels) + self.assertEqual(self.CILViewerBase_instance.axisLabelsText, labels) + + labels_2 = ['c', 'd', 'e'] + self.CILViewerBase_instance.setAxisLabels(labels_2, False) + new_labels = self.CILViewerBase_instance.getCurrentAxisLabelsText() + self.assertEqual(new_labels, labels_2) + self.assertEqual(self.CILViewerBase_instance.axisLabelsText, labels) + + @unittest.skipIf(skip_test, "Skipping tests on GitHub Actions") class CILViewer3DTest(unittest.TestCase):