Exemple #1
0
    def onApplyParameters(self):
        segmentationParameters = self.getPETTumorSegmentationParameterNode()
        if not segmentationParameters: return

        paramsNode = self.scriptedEffect.parameterSetNode()
        volumeID = paramsNode.GetMasterVolumeNode().GetID()
        segmentationID = paramsNode.GetSegmentationNode().GetID()
        selectedSegmentID = paramsNode.GetSelectedSegmentID()
        segment = paramsNode.GetSegmentationNode().GetSegmentation(
        ).GetSegment(selectedSegmentID)
        priorSegmentationExists = segment.HasTag(
            'PETTumorSegmentation.SegmentationId')
        oldVolumeID = segmentationParameters.GetPETVolumeReference()
        oldSegmentationID = segmentationParameters.GetSegmentationReference()
        oldSelectedSegmentID = segmentationParameters.GetSelectedSegmentID()

        if (volumeID != oldVolumeID or segmentationID != oldSegmentationID):
            self.reset()
        segmentationParameters = self.getPETTumorSegmentationParameterNode()
        if not segmentationParameters: return
        if not self.vtkSegmentationLogic:
            self.vtkSegmentationLogic = slicer.vtkSlicerPETTumorSegmentationLogic(
            )

        centerPointFiducialsNode = self.scene.GetNodeByID(
            str(segmentationParameters.GetCenterPointIndicatorListReference()))
        centerPointFiducials = slicer.vtkMRMLFiducialListNode.SafeDownCast(
            centerPointFiducialsNode)
        if (centerPointFiducials.GetNumberOfFiducials() == 0
                or selectedSegmentID != oldSelectedSegmentID):
            # there is no segmentation which could be changed by updated paramters
            return

        self.saveStateForUndo()
        # run segmentation algorithm with changed parameters
        self.updateMRMLFromGUI()
        self._showDebugInfo(segmentationParameters)
        self.vtkSegmentationLogic.Apply(segmentationParameters, None)
        self.updateCurrentSegmentationID()
Exemple #2
0
    def onApplyMouseClick(self, rasCoorinate):
        segmentationParameters = self.getPETTumorSegmentationParameterNode()
        if not segmentationParameters: return

        paramsNode = self.scriptedEffect.parameterSetNode()
        volumeID = paramsNode.GetMasterVolumeNode().GetID()
        segmentationID = paramsNode.GetSegmentationNode().GetID()
        selectedSegmentID = paramsNode.GetSelectedSegmentID()
        segment = paramsNode.GetSegmentationNode().GetSegmentation(
        ).GetSegment(selectedSegmentID)
        priorSegmentationExists = segment.HasTag(
            'PETTumorSegmentation.SegmentationId')
        oldVolumeID = segmentationParameters.GetPETVolumeReference()
        oldSegmentationID = segmentationParameters.GetSegmentationReference()
        oldSelectedSegmentID = segmentationParameters.GetSelectedSegmentID()

        if (volumeID != oldVolumeID or segmentationID != oldSegmentationID):
            self.reset()
        segmentationParameters = self.getPETTumorSegmentationParameterNode()
        if not segmentationParameters: return
        if not self.vtkSegmentationLogic:
            self.vtkSegmentationLogic = slicer.vtkSlicerPETTumorSegmentationLogic(
            )

        self.saveStateForUndo()
        self.updateMRMLFromGUI()

        #Get the fiducial nodes
        centerPointFiducialsNode = self.scene.GetNodeByID(
            str(segmentationParameters.GetCenterPointIndicatorListReference()))
        centerPointFiducials = slicer.vtkMRMLFiducialListNode.SafeDownCast(
            centerPointFiducialsNode)
        globalRefinementFiducialNode = self.scene.GetNodeByID(
            str(segmentationParameters.
                GetGlobalRefinementIndicatorListReference()))
        globalRefinementFiducial = slicer.vtkMRMLFiducialListNode.SafeDownCast(
            globalRefinementFiducialNode)
        localRefinementFiducialNode = self.scene.GetNodeByID(
            str(segmentationParameters.
                GetLocalRefinementIndicatorListReference()))
        localRefinementFiducial = slicer.vtkMRMLFiducialListNode.SafeDownCast(
            localRefinementFiducialNode)

        #Set the current segment information and volumes
        segmentationParameters.SetPETVolumeReference(volumeID)
        segmentationParameters.SetSegmentationReference(segmentationID)
        segmentationParameters.SetSelectedSegmentID(selectedSegmentID)

        #If there are no center points, then the click should make a new center point and segmentation.
        #If the label has changed, go with this and remove center points to start a new segmentation.
        #If no refinement mode is on, remove points and start a new segmentation.
        if (centerPointFiducials.GetNumberOfFiducials() == 0
                or selectedSegmentID != oldSelectedSegmentID
                or segmentationParameters.GetNoRefinementOn()
            ):  # initialize segmentation
            # clear old data
            segmentationParameters.ClearInitialLabelMap()
            if (centerPointFiducials.GetNumberOfFiducials() != 0):
                globalRefinementFiducial.RemoveAllFiducials()
                localRefinementFiducial.RemoveAllFiducials()
                centerPointFiducials.RemoveAllFiducials()
            #add the new center point
            centerPointFiducials.AddFiducialWithXYZ(rasCoorinate[0],
                                                    rasCoorinate[1],
                                                    rasCoorinate[2], False)
            self.vtkSegmentationLogic.Apply(segmentationParameters, None)
        else:
            #If global refinement is active, then the existing segmentation should be refined globally.
            if (segmentationParameters.GetGlobalRefinementOn()
                ):  # perform global refinement, unless new label
                #Only one global refinement point at a time
                globalRefinementFiducial.RemoveAllFiducials()
                globalRefinementFiducial.AddFiducialWithXYZ(
                    rasCoorinate[0], rasCoorinate[1], rasCoorinate[2], False)
                self.vtkSegmentationLogic.ApplyGlobalRefinement(
                    segmentationParameters, None)
            #If local refinement is active, then the existing segmentation should be refined localy.
            elif (segmentationParameters.GetLocalRefinementOn()
                  ):  # perform local refinement, unless new label
                localRefinementFiducial.AddFiducialWithXYZ(
                    rasCoorinate[0], rasCoorinate[1], rasCoorinate[2], False)
                self.vtkSegmentationLogic.ApplyLocalRefinement(
                    segmentationParameters, None)

        # run segmentation algorithm
        #self._showDebugInfo(segmentationParameters)
        #self.vtkSegmentationLogic.Apply( segmentationParameters, None )
        self.updateCurrentSegmentationID()