コード例 #1
0
    def saveReport(self, currentValuesDict):
        """ Save a JSON text file with the current values of the GUI stored in a dictionary.
        It also saves the current enhanced and labelmap volumes
        :param currentValuesDict: dictionary of values
        :return: file where the report was stored
        """
        p = os.path.join(self.getCurrentDataFolder(), "report.json")
        with open(p, "w+b") as f:
            json.dump(currentValuesDict, f)

        # Save the labelmap
        if self.currentLabelmapVolume.GetStorageNode() is None:
            SlicerUtil.saveNewNode(
                self.currentLabelmapVolume,
                os.path.join(self.getCurrentDataFolder(),
                             self.currentLabelmapVolume.GetName() + ".nrrd"))
        else:
            self.currentLabelmapVolume.GetStorageNode().WriteData(
                self.currentLabelmapVolume)

        # Save the enhanced volume
        if self.getEnhancedVolume().GetStorageNode() is None:
            SlicerUtil.saveNewNode(
                self.currentEnhancedVolume,
                os.path.join(self.getCurrentDataFolder(),
                             self.currentEnhancedVolume.GetName() + ".nrrd"))
        else:
            self.currentEnhancedVolume.GetStorageNode().WriteData(
                self.currentEnhancedVolume)

        self.isCurrentReportSaved = True
        return p
コード例 #2
0
    def refreshUI(self):
        SlicerUtil.showToolbars(self.isExpertMode)
        lm = slicer.app.layoutManager()
        for key in ("Red", "Yellow"):
            sliceWidget = lm.sliceWidget(key)
            controller = sliceWidget.sliceController()
            controller.showLabelOutline(True)
            controller.visible = self.isExpertMode

        # Hide DataProbe module
        dataProbeCollapsibleButton = [
            b for b in slicer.util.mainWindow().findChildren(
                "ctkCollapsibleButton") if b.text == "Data Probe"
        ][0]
        dataProbeCollapsibleButton.setVisible(self.isExpertMode)

        # Link windows
        compNodes = slicer.util.getNodes("vtkMRMLSliceCompositeNode*")
        for compNode in compNodes.itervalues():
            compNode.SetLinkedControl(True)

        self.resetButton.visible = self.caseInfoFrame.visible = \
            self.editorCollapsibleButton.visible = self.diagnosisCollapsibleButton.visible = \
            self.isCaseLoaded or self.isExpertMode

        if self.isCaseLoaded:
            self.caseIdLabel.text = "Case Id: " + self.logic.current2DVectorVolume.GetName(
            )

            for button in self.showEnhancementCheckboxGroup.buttons():
                button.setEnabled(self.logic.current2DVectorVolume is not None)

            if self.showEnhancementCheckboxGroup.checkedId() == 0:
                # Just original. Red Slice only
                SlicerUtil.changeLayout(6)
                # Hide enhancement fine tuning controls
                self.vascularFactorLabel.visible = self.vascularFactorSlider.visible = \
                    self.enhancementFactorLabel.visible = self.enhancementFactorSlider.visible = \
                    False
            elif self.showEnhancementCheckboxGroup.checkedId() == 1:
                # Original + Enhanced
                SlicerUtil.changeLayout(29)
                # Show enhancement fine tuning controls
                self.vascularFactorLabel.visible = self.vascularFactorSlider.visible = \
                    self.enhancementFactorLabel.visible = self.enhancementFactorSlider.visible = \
                    True
            elif self.showEnhancementCheckboxGroup.checkedId() == 2:
                # Just enhanced. Yellow Slice
                SlicerUtil.changeLayout(7)
                # Show enhancement fine tuning controls
                self.vascularFactorLabel.visible = self.vascularFactorSlider.visible = \
                    self.enhancementFactorLabel.visible = self.enhancementFactorSlider.visible = \
                    True
コード例 #3
0
    def __printSnapshots__(self):
        """ Generate snapshots of all the volumes to be displayed in the report
        """
        # Save a png file from different images.
        # We manipulate the widget to have the aspect that we want for the screenshot
        lm = slicer.app.layoutManager()

        # Take original image with Labelmap
        # Change to Red
        SlicerUtil.changeLayoutRedSingle()
        sliceWidget = lm.sliceWidget("Red")
        controller = sliceWidget.sliceController()
        controller.fitSliceToBackground()
        # Hide the slider bar (just show the picture)
        controller.hide()
        sliceView = sliceWidget.sliceView()
        sliceView.cornerAnnotation().ClearAllTexts()
        sliceView.scheduleRender()
        # Take the snapshot
        SlicerUtil.takeSnapshot(os.path.join(self.getCurrentDataFolder(),
                                             self.__getReportImagePath__(1)),
                                type=slicer.qMRMLScreenShotDialog.Red,
                                hideAnnotations=True)

        # Restore the regular controller
        controller.show()

        # Enhanced (with and without labelmap)
        SlicerUtil.changeLayoutYellowSingle()

        # If the user didn't open the enhanced volume yet, force it
        enhancedVol = self.getEnhancedVolume()
        yellowCompositeNode = slicer.mrmlScene.GetNodeByID(
            'vtkMRMLSliceCompositeNodeYellow')
        if yellowCompositeNode.GetBackgroundVolumeID() != enhancedVol.GetID():
            yellowCompositeNode.SetBackgroundVolumeID(enhancedVol.GetID())
            yellowSliceNode = slicer.mrmlScene.GetNodeByID(
                'vtkMRMLSliceNodeYellow')
            yellowSliceNode.SetOrientationToAxial()
            # Assign the labelmap
            yellowCompositeNode.SetLabelVolumeID(
                self.currentLabelmapVolume.GetID())

        controller = lm.sliceWidget("Yellow").sliceController()
        controller.fitSliceToBackground()
        # Hide the slider bar (just show the picture)
        controller.hide()
        # Take the snapshot
        SlicerUtil.takeSnapshot(os.path.join(self.getCurrentDataFolder(),
                                             self.__getReportImagePath__(3)),
                                type=slicer.qMRMLScreenShotDialog.Yellow,
                                hideAnnotations=True)

        # Remove the labelmap
        controller.setLabelMapHidden(True)
        # Take the snapshot
        SlicerUtil.takeSnapshot(os.path.join(self.getCurrentDataFolder(),
                                             self.__getReportImagePath__(2)),
                                type=slicer.qMRMLScreenShotDialog.Yellow,
                                hideAnnotations=True)

        # Restore the regular controller
        controller.show()
        controller.setLabelMapHidden(False)
コード例 #4
0
    def setup(self):
        ScriptedLoadableModuleWidget.setup(self)

        self.caseInfoCollapsibleButton = ctk.ctkCollapsibleButton()
        self.caseInfoCollapsibleButton.text = "Case information"
        self.caseInfoCollapsibleButton.collapsed = False
        self.layout.addWidget(self.caseInfoCollapsibleButton)
        self.caseAreaLayout = qt.QGridLayout(self.caseInfoCollapsibleButton)
        # Select case
        row = 0
        self.loadCaseButton = ctk.ctkPushButton()
        self.loadCaseButton.text = "Load case"
        self.loadCaseButton.toolTip = "Load a case folder"
        self.caseAreaLayout.addWidget(self.loadCaseButton, row, 0)

        # Reset button
        self.resetButton = ctk.ctkPushButton()
        self.resetButton.text = "Close case"
        self.resetButton.toolTip = "Close the current case"
        self.caseAreaLayout.addWidget(self.resetButton, row, 1)

        # Case info
        row += 1
        self.caseInfoFrame = qt.QFrame()
        self.caseInfoFrame.setFrameStyle(0x0002 | 0x0010)
        self.caseInfoFrame.lineWidth = 2
        self.caseInfoFrame.setStyleSheet(
            "background-color: #EEEEEE; margin: 10px")
        self.caseAreaLayout.addWidget(self.caseInfoFrame, row, 0, 1, 2)

        self.caseInfoFrameLayout = qt.QGridLayout()
        self.caseInfoFrame.setLayout(self.caseInfoFrameLayout)

        self.caseIdLabel = qt.QLabel("Case id: ")
        self.caseIdLabel.setStyleSheet("font-weight: bold")
        self.caseInfoFrameLayout.addWidget(self.caseIdLabel, 0, 0)

        self.showEnhancementCheckboxGroup = qt.QButtonGroup()
        self.showJustOriginalButton = qt.QRadioButton("Original only")
        self.showJustOriginalButton.setChecked(True)
        self.showEnhancementCheckboxGroup.addButton(
            self.showJustOriginalButton, 0)
        self.caseInfoFrameLayout.addWidget(self.showJustOriginalButton, 1, 0)

        self.showOriginalPlusEnhancedButton = qt.QRadioButton(
            "Original and enhanced")
        self.showEnhancementCheckboxGroup.addButton(
            self.showOriginalPlusEnhancedButton, 1)
        self.caseInfoFrameLayout.addWidget(self.showOriginalPlusEnhancedButton,
                                           2, 0)

        self.showJustEnhancedButton = qt.QRadioButton("Enhanced only")
        self.showEnhancementCheckboxGroup.addButton(
            self.showJustEnhancedButton, 2)
        self.caseInfoFrameLayout.addWidget(self.showJustEnhancedButton, 3, 0)

        # Center Volumes button
        self.centerVolumesButton = ctk.ctkPushButton()
        self.centerVolumesButton.text = "Center image/s"
        self.centerVolumesButton.toolTip = "Center all the current visible images"
        self.centerVolumesButton.setFixedWidth(200)
        # self.centerVolumesButton.toolTip = "Load a case folder"
        self.caseInfoFrameLayout.addWidget(self.centerVolumesButton, 4, 0)

        # Enhancement fine tuning
        self.vascularFactorLabel = qt.QLabel("Vascular factor")
        self.vascularFactorLabel.setStyleSheet("font-weight: bold")
        self.caseInfoFrameLayout.addWidget(self.vascularFactorLabel, 0, 1)
        self.vascularFactorSlider = qt.QSlider()
        self.vascularFactorSlider.orientation = 2  # Vertical
        self.vascularFactorSlider.value = 5
        self.vascularFactorSlider.minimum = 0
        self.vascularFactorSlider.maximum = 10
        # self.vascularFactorSlider.setStyleSheet("margin-top:10px;padding-top:20px")
        # self.vascularFactorSlider.setToolTip("Move the slider for a fine tuning segmentation")
        self.caseInfoFrameLayout.addWidget(self.vascularFactorSlider, 1, 1, 4,
                                           1, 0x0004)

        self.enhancementFactorLabel = qt.QLabel("Enhancement factor")
        self.enhancementFactorLabel.setStyleSheet("font-weight: bold")
        self.caseInfoFrameLayout.addWidget(self.enhancementFactorLabel, 0, 2)
        self.enhancementFactorSlider = qt.QSlider()
        self.enhancementFactorSlider.orientation = 2  # Vertical
        self.enhancementFactorSlider.minimum = 0
        self.enhancementFactorSlider.maximum = 10
        self.enhancementFactorSlider.value = 5
        # self.vascularFactorSlider.setStyleSheet("margin-top:10px;padding-top:20px")
        # self.vascularFactorSlider.setToolTip("Move the slider for a fine tuning segmentation")
        self.caseInfoFrameLayout.addWidget(self.enhancementFactorSlider, 1, 2,
                                           4, 1, 0x0004)

        # Editor
        row += 1
        self.editorWidget = ui.CustomEditorWidget(self.parent)
        self.editorWidget.setup()
        self.editorCollapsibleButton = self.editorWidget.editLabelMapsFrame
        self.editorCollapsibleButton.text = "Edit the current eye image"
        self.editorCollapsibleButton.collapsed = False
        self.editorWidget.toolsColor.terminologyCollapsibleButton.setVisible(
            False)
        self.layout.addWidget(self.editorCollapsibleButton)

        ### DIAGNOSIS
        self.diagnosisCollapsibleButton = ctk.ctkCollapsibleButton()
        self.diagnosisCollapsibleButton.text = "Diagnosis"
        self.diagnosisCollapsibleButton.collapsed = False
        self.layout.addWidget(self.diagnosisCollapsibleButton)
        self.diagnosisAreaLayout = qt.QVBoxLayout(
            self.diagnosisCollapsibleButton)

        # Visual Acuity
        label = qt.QLabel("Visual acuity (VA): ")
        label.setStyleSheet("margin: 10px 0 0 10px; font-weight: bold")
        self.diagnosisAreaLayout.addWidget(label)
        self.vaFrame = qt.QFrame()
        self.vaFrame.setFrameStyle(0x0002 | 0x0010)
        self.vaFrame.lineWidth = 2
        self.vaFrame.setStyleSheet("background-color: #EEEEEE; margin: 10px")
        self.vaFrame.setFixedWidth(240)
        self.diagnosisAreaLayout.addWidget(self.vaFrame)

        self.vaFrameLayout = qt.QGridLayout(self.vaFrame)
        self.vaFrameLayout.addWidget(qt.QLabel("OS"), 0, 0)
        self.osLineEdit = qt.QLineEdit()
        self.osLineEdit.setFixedWidth(80)
        self.osLineEdit.setStyleSheet("background-color: white")
        self.vaFrameLayout.addWidget(self.osLineEdit, 0, 1)

        self.vaFrameLayout.addWidget(qt.QLabel("OD"), 1, 0)
        self.odLineEdit = qt.QLineEdit()
        self.odLineEdit.setFixedWidth(80)
        self.odLineEdit.setStyleSheet("background-color: white")
        self.vaFrameLayout.addWidget(self.odLineEdit, 1, 1)

        self.vaModalityButtonGroup = qt.QButtonGroup()
        self.scvaRadioButton = qt.QRadioButton()
        self.scvaRadioButton.setText("SCVA")
        self.vaFrameLayout.addWidget(self.scvaRadioButton, 0, 2)
        self.vaModalityButtonGroup.addButton(self.scvaRadioButton)

        self.bcvaRadioButton = qt.QRadioButton()
        self.bcvaRadioButton.setText("BCVA")
        self.vaFrameLayout.addWidget(self.bcvaRadioButton, 1, 2)
        self.vaModalityButtonGroup.addButton(self.bcvaRadioButton)

        self.ucvaRadioButton = qt.QRadioButton()
        self.ucvaRadioButton.setText("UCVA")
        self.vaFrameLayout.addWidget(self.ucvaRadioButton, 2, 2)
        self.vaModalityButtonGroup.addButton(self.ucvaRadioButton)

        # Problems detected
        label = qt.QLabel("Problems detected: ")
        label.setStyleSheet("margin: 10px 0 0 10px; font-weight: bold")
        self.diagnosisAreaLayout.addWidget(label)

        self.problemsFrame = qt.QFrame()
        self.problemsFrame.setFrameStyle(0x0002 | 0x0010)
        self.problemsFrame.lineWidth = 2
        self.problemsFrame.setStyleSheet(
            "background-color: #EEEEEE; margin: 10px")
        self.diagnosisAreaLayout.addWidget(self.problemsFrame)

        self.problemsFrameLayout = qt.QGridLayout()
        self.problemsFrame.setLayout(self.problemsFrameLayout)
        self.problemsButtons = []

        self.microaneurysmsCheckbox = qt.QCheckBox()
        self.microaneurysmsCheckbox.setText("Microaneurysms")
        self.problemsFrameLayout.addWidget(self.microaneurysmsCheckbox, 0, 0)
        self.problemsButtons.append(self.microaneurysmsCheckbox)

        self.exudatesCheckbox = qt.QCheckBox()
        self.exudatesCheckbox.setText("Exudates")
        self.problemsFrameLayout.addWidget(self.exudatesCheckbox, 0, 1)
        self.problemsButtons.append(self.exudatesCheckbox)

        self.haemorrhagesCheckbox = qt.QCheckBox()
        self.haemorrhagesCheckbox.setText("Haemorrhages")
        self.problemsFrameLayout.addWidget(self.haemorrhagesCheckbox, 0, 2)
        self.problemsButtons.append(self.haemorrhagesCheckbox)

        self.cottonWoolSpotsCheckbox = qt.QCheckBox()
        self.cottonWoolSpotsCheckbox.setText("Cotton wool spots")
        self.problemsFrameLayout.addWidget(self.cottonWoolSpotsCheckbox, 1, 0)
        self.problemsButtons.append(self.cottonWoolSpotsCheckbox)

        self.NeovascularisationCheckbox = qt.QCheckBox()
        self.NeovascularisationCheckbox.setText("Neovascularisation")
        self.problemsFrameLayout.addWidget(self.NeovascularisationCheckbox, 1,
                                           1)
        self.problemsButtons.append(self.NeovascularisationCheckbox)

        label = qt.QLabel("Diabetic retinopathy diagnosis: ")
        label.setStyleSheet("margin: 10px 0 0 10px; font-weight: bold")
        self.diagnosisAreaLayout.addWidget(label)

        # Diabetic Retinopathy diagnosis
        self.diabeticRetinopathyDiagnosisFrame = qt.QFrame()
        self.diabeticRetinopathyDiagnosisFrame.setFrameStyle(0x0002 | 0x0010)
        self.diabeticRetinopathyDiagnosisFrame.lineWidth = 2
        self.diabeticRetinopathyDiagnosisFrame.setStyleSheet(
            "background-color: #EEEEEE; margin: 10px")
        self.diagnosisAreaLayout.addWidget(
            self.diabeticRetinopathyDiagnosisFrame)

        self.diabeticRetinopathyDiagnosisFrameLayout = qt.QHBoxLayout()
        self.diabeticRetinopathyDiagnosisFrame.setLayout(
            self.diabeticRetinopathyDiagnosisFrameLayout)

        self.diagnosisRadioButtonGroup = qt.QButtonGroup()
        for i in range(5):
            rb = qt.QRadioButton(str(i))
            self.diagnosisRadioButtonGroup.addButton(rb, i)
            self.diabeticRetinopathyDiagnosisFrameLayout.addWidget(rb)
        self.diagnosisRadioButtonGroup.buttons()[0].setChecked(True)

        # Additional comments
        label = qt.QLabel("Additional comments:")
        label.setStyleSheet("margin: 10px 0 0 10px; font-weight: bold")
        self.diagnosisAreaLayout.addWidget(label)
        row += 1

        self.additionalCommentsText = qt.QTextEdit()
        self.additionalCommentsText.setStyleSheet("margin: 10px")
        self.diagnosisAreaLayout.addWidget(self.additionalCommentsText)

        self.saveReportButton = ctk.ctkPushButton()
        self.saveReportButton.text = "Save report"
        self.saveReportButton.setFixedWidth(300)
        self.diagnosisAreaLayout.addWidget(self.saveReportButton)

        self.printReportButton = ctk.ctkPushButton()
        self.printReportButton.text = "Save and generate PDF"
        self.printReportButton.setFixedWidth(300)
        self.diagnosisAreaLayout.addWidget(self.printReportButton)

        self.expertModeCollapsibleButton = ctk.ctkCollapsibleButton()
        self.expertModeCollapsibleButton.text = "Expert mode"
        self.expertModeCollapsibleButton.collapsed = True
        self.layout.addWidget(self.expertModeCollapsibleButton)
        self.expertModeLayout = qt.QVBoxLayout(
            self.expertModeCollapsibleButton)
        self.expertModeCheckbox = qt.QCheckBox("Activate expert mode")
        self.expertModeCheckbox.checked = False
        self.expertModeLayout.addWidget(self.expertModeCheckbox)
        self.layout.addStretch(1)

        # Connections
        self.loadCaseButton.connect('clicked()', self.__onLoadCaseClicked__)
        # self.loadReportButton.connect('clicked()', self.__onLoadReportClicked__)
        self.showEnhancementCheckboxGroup.connect(
            "buttonClicked (int)", self.__onEnhancementButtonGroupClicked__)
        self.centerVolumesButton.connect('clicked()',
                                         SlicerUtil.centerAllVolumes)
        self.vascularFactorSlider.connect('sliderReleased()',
                                          self.__onEnhancementFineTuning__)
        self.enhancementFactorSlider.connect('sliderReleased()',
                                             self.__onEnhancementFineTuning__)
        self.saveReportButton.connect('clicked()',
                                      self.__onSaveReportClicked__)
        self.printReportButton.connect('clicked()',
                                       self.__onPrintReportClicked__)
        self.resetButton.connect('clicked()', self.reset)
        self.expertModeCheckbox.connect("stateChanged(int)",
                                        self.__onExpertModeStateChanged__)
        slicer.mrmlScene.AddObserver(slicer.vtkMRMLScene.EndCloseEvent,
                                     self.__onSceneClosed__)

        # Set default layout Red
        SlicerUtil.changeLayoutRedSingle()

        self.refreshUI()
コード例 #5
0
 def enter(self):
     """This is invoked every time that we select this module as the active module in Slicer (not only the first time)"""
     self.__setLabelmapOutlines__()
     SlicerUtil.showToolbars(SlicerUtil.IsDevelopment)