def onSegmentationNodeChanged(self): Helper.Debug('onSegmentationNodeChanged()') if self.__vNode == None: Helper.Error( 'Should not be possible to select segmentation unless annotated volume is initialized!' ) return # get the current segmentation (label) node sNode = self.__segmentationSelector.currentNode() if sNode == None: self.updateWidgets() return # if it's a new label, it should have/will be added to the report # automatically image = sNode.GetImageData() if image == None: Helper.initializeNewLabel(sNode, self.__vNode) else: # if it's an existing label, we need to check that the geometry matches # the annotated label geometry, and if so, add it to the hierarchy if Helper.GeometriesMatch(sNode, self.__vNode) == False: Helper.ErrorPopup( 'The geometry of the segmentation label you attempted to select does not match the geometry of the volume being annotated! Please select a different label or create a new one.' ) self.__segmentationSelector.setCurrentNode(None) self.updateWidgets() return # assign the color LUT we use dNode = sNode.GetDisplayNode() dNode.SetAndObserveColorNodeID(self.__defaultColorNode.GetID()) sNode.SetAttribute('AssociatedNodeID', self.__vNode.GetID()) self.__logic.AddNodeToReport(sNode) # assign the volume and the selected color to the editor parameter node Helper.SetLabelVolume(sNode.GetID()) # TODO: disable adding new label node to the hierarchy if it was added # outside the reporting module self.__segmentationSelector.setCurrentNode(sNode) self.__editorWidget.setMasterNode(self.__vNode) self.__editorWidget.setMergeNode(sNode) self.__editorParameterNode.Modified() self.updateWidgets()
def onAnnotatedVolumeNodeChanged(self): Helper.Debug("onAnnotatedVolumeNodeChanged()") # get the current volume node selectedVolume = self.__volumeSelector.currentNode() # do the error checks if selectedVolume == None or self.__rNode == None: self.__volumeSelector.setCurrentNode(None) return uids = selectedVolume.GetAttribute('DICOM.instanceUIDs') if uids == None: Helper.ErrorPopup( "Volume \"" + selectedVolume.GetName() + "\" was not loaded from DICOM. Only volumes loaded from DICOM data can be annotated in the Reporting module." ) self.__volumeSelector.setCurrentNode(None) return nSlices = selectedVolume.GetImageData().GetExtent()[-1] + 1 if nSlices != len(string.split(uids)): Helper.ErrorPopup( "Volume \"" + selectedVolume.GetName() + "\" was loaded from multi-frame DICOM. Multi-frame DICOM is currently not supported by the Reporting module" ) self.__volumeSelector.setCurrentNode(None) return # volume node is valid! self.__vNode = selectedVolume # update the report node if self.__rNode != None: self.__rNode.SetVolumeNodeID(self.__vNode.GetID()) self.__rNode.SetName('Report for Volume ' + self.__vNode.GetName()) Helper.SetBgFgVolumes(self.__vNode.GetID(), '') Helper.RotateToVolumePlanes() # go over all label nodes in the scene # if there is a label that has the selected volume as associated node, # initialize label selector to show that label volumeNodes = slicer.mrmlScene.GetNodesByClass( 'vtkMRMLScalarVolumeNode') volumeNodes.SetReferenceCount(volumeNodes.GetReferenceCount() - 1) associatedLabelFound = False for i in range(volumeNodes.GetNumberOfItems()): vol = volumeNodes.GetItemAsObject(i) associatedNodeID = vol.GetAttribute('AssociatedNodeID') label = vol.GetAttribute('LabelMap') if associatedNodeID == self.__vNode.GetID() and label == '1': Helper.SetLabelVolume(vol.GetID()) associatedLabelFound = True # if there is no associated label node, set the selector to none if associatedLabelFound == False: Helper.SetLabelVolume("") orientation = Helper.GetScanOrderSliceName(self.__vNode) message = "Slice viewers to be used for markup: " for sliceViewer in orientation: message = message + sliceViewer if orientation.index(sliceViewer) < (len(orientation) - 1): message = message + ", " Helper.Debug(message) self.__markupSliceText.text = message # take the first one self.__parameterNode.SetParameter('acquisitionSliceViewer', orientation[0]) # print "Calling logic to set up hierarchy" self.__logic.InitializeHierarchyForVolume(self.__vNode) self.updateTreeView()
def onSegmentationNodeChanged(self): Helper.Debug('onSegmentationNodeChanged()') if self.__vNode == None: Helper.Error('Should not be possible to select segmentation unless annotated volume is initialized!') return # get the current segmentation (label) node sNode = self.segmentationSelector.currentNode() if sNode == None: self.updateWidgets() return # if it's a new label, it should have/will be added to the report # automatically image = sNode.GetImageData() if image == None: Helper.initializeNewLabel(sNode, self.__vNode) else: # if it's an existing label, we need to check that the geometry matches # the annotated label geometry, and if so, add it to the hierarchy volumesLogic = slicer.modules.volumes.logic() geometryCheckString = volumesLogic.CheckForLabelVolumeValidity(self.__vNode, sNode) if geometryCheckString != "": newNodeAnswer = Helper.QuestionPopup('The geometry of the segmentation label you selected does not match the geometry of the volume being annotated!\nDo you want to create a new label to match the geometry, resampling data to fit?\n' + geometryCheckString) if newNodeAnswer == True: # create a new resampled label node from the input image resampledSegmentationNode = volumesLogic.ResampleVolumeToReferenceVolume(sNode, self.__vNode) # reselect it self.segmentationSelector.setCurrentNode(resampledSegmentationNode) # reset vars sNode = self.segmentationSelector.currentNode() Helper.InfoPopup('Created a new segmentation label named ' + sNode.GetName() + ' resampled from the input label map') image = sNode.GetImageData() else: self.segmentationSelector.setCurrentNode(None) self.updateWidgets() return # assign the color LUT we use dNode = sNode.GetDisplayNode() dNode.SetAndObserveColorNodeID(self.__defaultColorNode.GetID()) sNode.SetAttribute('AssociatedNodeID',self.__vNode.GetID()) self.__logic.AddNodeToReport(sNode) # assign the volume and the selected color to the editor parameter node Helper.SetLabelVolume(sNode.GetID()) # TODO: disable adding new label node to the hierarchy if it was added # outside the reporting module self.segmentationSelector.setCurrentNode(sNode) self.__editorWidget.setMasterNode(self.__vNode) self.__editorWidget.setMergeNode(sNode) self.__editorParameterNode.Modified() self.updateWidgets() self.updateTreeView()