From 5731bb69e450b703fe3dcc29627fe0873bbcb05d Mon Sep 17 00:00:00 2001 From: Christian Herz Date: Mon, 18 Sep 2017 12:11:58 -0400 Subject: [PATCH 1/2] BUG: fixes wrong api calls caused by Slicer Core changes (issue #197) --- DICOMPlugins/DICOMSegmentationPlugin.py | 34 ++++++++++++------------- QuantitativeReporting.py | 10 +------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/DICOMPlugins/DICOMSegmentationPlugin.py b/DICOMPlugins/DICOMSegmentationPlugin.py index 90a0aa7..354defd 100644 --- a/DICOMPlugins/DICOMSegmentationPlugin.py +++ b/DICOMPlugins/DICOMSegmentationPlugin.py @@ -177,15 +177,14 @@ def load(self,loadable): regionModCode, regionModCodingScheme, regionModCodeMeaning = \ self.getValuesFromCodeSequence(segment, "AnatomicRegionModifierSequence") - dummyTerminologyWidget = slicer.qSlicerTerminologyNavigatorWidget() # Still cannot call static methods from python - segmentTerminologyTag = dummyTerminologyWidget.serializeTerminologyEntry( - loadable.name, - categoryCode, categoryCodingScheme, categoryCodeMeaning, - typeCode, typeCodingScheme, typeCodeMeaning, - typeModCode, typeModCodingScheme, typeModCodeMeaning, - loadable.name, - regionCode, regionCodingScheme, regionCodeMeaning, - regionModCode, regionModCodingScheme, regionModCodeMeaning) + segmentTerminologyTag = terminologiesLogic.SerializeTerminologyEntry( + loadable.name, + categoryCode, categoryCodingScheme, categoryCodeMeaning, + typeCode, typeCodingScheme, typeCodeMeaning, + typeModCode, typeModCodingScheme, typeModCodeMeaning, + loadable.name, + regionCode, regionCodingScheme, regionCodeMeaning, + regionModCode, regionModCodingScheme, regionModCodeMeaning) # end of processing a line of terminology # TODO: Create logic class that both CLI and this plugin uses so that we don't need to have temporary NRRD @@ -334,6 +333,15 @@ class EmptySegmentsFoundError(ValueError): class NoNonEmptySegmentsFoundError(ValueError): pass + @staticmethod + def getDeserializedTerminologyEntry(vtkSegment): + terminologyEntry = slicer.vtkSlicerTerminologyEntry() + tag = vtk.mutable("") + vtkSegment.GetTag(vtkSegment.GetTerminologyEntryTagName(), tag) + terminologyLogic = slicer.modules.terminologies.logic() + terminologyLogic.DeserializeTerminologyEntry(tag, terminologyEntry) + return terminologyEntry + @staticmethod def saveJSON(data, destination): with open(os.path.join(destination), 'w') as outfile: @@ -551,14 +559,6 @@ def checkTerminologyOfSegments(self, segmentIDs): if any(v is None for v in [category, propType]): raise ValueError("Segment {} has missing attributes. Make sure to set terminology.".format(segment.GetName())) - def getDeserializedTerminologyEntry(self, vtkSegment): - terminologyWidget = slicer.qSlicerTerminologyNavigatorWidget() - terminologyEntry = slicer.vtkSlicerTerminologyEntry() - tag = vtk.mutable("") - vtkSegment.GetTag(vtkSegment.GetTerminologyEntryTagName(), tag) - terminologyWidget.deserializeTerminologyEntry(tag, terminologyEntry) - return terminologyEntry - def createJSONFromTerminologyContext(self, terminologyEntry): segmentData = dict() diff --git a/QuantitativeReporting.py b/QuantitativeReporting.py index 0533fb9..5fcde9b 100644 --- a/QuantitativeReporting.py +++ b/QuantitativeReporting.py @@ -973,7 +973,7 @@ def generateJSON4DcmSR(self, dcmSegmentationFile, sourceVolumeNode): data["segmentationSOPInstanceUID"] = segmentationSOPInstanceUID segment = self.segmentationNode.GetSegmentation().GetSegment(segmentID) - terminologyEntry = self.getDeserializedTerminologyEntry(segment) + terminologyEntry = DICOMSegmentationExporter.getDeserializedTerminologyEntry(segment) data["Finding"] = self.createJSONFromTerminologyContext(terminologyEntry)["SegmentedPropertyTypeCodeSequence"] anatomicContext = self.createJSONFromAnatomicContext(terminologyEntry) @@ -1005,14 +1005,6 @@ def _createCodeSequence(self, vtkStringifiedCodedEntry): codeSequence[key] = value return codeSequence - def getDeserializedTerminologyEntry(self, segment): - terminologyWidget = slicer.qSlicerTerminologyNavigatorWidget() - terminologyEntry = slicer.vtkSlicerTerminologyEntry() - tag = vtk.mutable("") - segment.GetTag(segment.GetTerminologyEntryTagName(), tag) - terminologyWidget.deserializeTerminologyEntry(tag, terminologyEntry) - return terminologyEntry - class CustomDICOMDetailsWidget(DICOMDetailsWidget, ParameterNodeObservationMixin): From 151ddc46e61502853a99976aa80f287419988055 Mon Sep 17 00:00:00 2001 From: Christian Herz Date: Mon, 18 Sep 2017 14:43:04 -0400 Subject: [PATCH 2/2] ENH: hiding Segmentations... button --- QuantitativeReporting.py | 1 + 1 file changed, 1 insertion(+) diff --git a/QuantitativeReporting.py b/QuantitativeReporting.py index 5fcde9b..6200f74 100644 --- a/QuantitativeReporting.py +++ b/QuantitativeReporting.py @@ -760,6 +760,7 @@ def setup(self): super(QuantitativeReportingSegmentEditorWidget, self).setup() if self.developerMode: self.reloadCollapsibleButton.hide() + self.editor.switchToSegmentationsButtonVisible = False self.editor.segmentationNodeSelectorVisible = False self.editor.setEffectButtonStyle(qt.Qt.ToolButtonIconOnly) self.clearSegmentationEditorSelectors()