def setup(self): """This is called one time when the module GUI is initialized """ ScriptedLoadableModuleWidget.setup(self) # Create objects that can be used anywhere in the module. Example: in most cases there should be just one # object of the logic class self.logic = CIP_PAARatioLogic() # # Create all the widgets. Example Area mainAreaCollapsibleButton = ctk.ctkCollapsibleButton() mainAreaCollapsibleButton.text = "Main parameters" self.layout.addWidget(mainAreaCollapsibleButton) self.mainAreaLayout = qt.QGridLayout(mainAreaCollapsibleButton) self.label = qt.QLabel("Select the volume") self.label.setStyleSheet("margin:10px 0 20px 7px") self.mainAreaLayout.addWidget(self.label, 0, 0) self.volumeSelector = slicer.qMRMLNodeComboBox() self.volumeSelector.nodeTypes = ("vtkMRMLScalarVolumeNode", "") self.volumeSelector.name = "paa_volumeSelector" self.volumeSelector.selectNodeUponCreation = True self.volumeSelector.autoFillBackground = True self.volumeSelector.addEnabled = True self.volumeSelector.noneEnabled = False self.volumeSelector.removeEnabled = False self.volumeSelector.showHidden = False self.volumeSelector.showChildNodeTypes = False self.volumeSelector.setMRMLScene(slicer.mrmlScene) self.volumeSelector.setStyleSheet( "margin:0px 0 0px 0; padding:2px 0 2px 5px") self.mainAreaLayout.addWidget(self.volumeSelector, 0, 1) self.jumptToTemptativeSliceButton = ctk.ctkPushButton() self.jumptToTemptativeSliceButton.name = "jumptToTemptativeSliceButton" self.jumptToTemptativeSliceButton.text = "Jump to temptative slice" self.jumptToTemptativeSliceButton.toolTip = "Jump to the best estimated slice to place the rulers" self.jumptToTemptativeSliceButton.setIcon( qt.QIcon("{0}/ruler.png".format(SlicerUtil.CIP_ICON_DIR))) self.jumptToTemptativeSliceButton.setIconSize(qt.QSize(20, 20)) self.jumptToTemptativeSliceButton.setStyleSheet("font-weight: bold;") # self.jumptToTemptativeSliceButton.setFixedWidth(140) self.mainAreaLayout.addWidget(self.jumptToTemptativeSliceButton, 1, 1) ### Structure Selector self.structuresGroupbox = qt.QGroupBox("Select the structure") self.groupboxLayout = qt.QVBoxLayout() self.structuresGroupbox.setLayout(self.groupboxLayout) self.mainAreaLayout.addWidget(self.structuresGroupbox, 2, 0) self.structuresButtonGroup = qt.QButtonGroup() # btn = qt.QRadioButton("None") # btn.visible = False # self.structuresButtonGroup.addButton(btn) # self.groupboxLayout.addWidget(btn) btn = qt.QRadioButton("Both") btn.name = "paaButton" btn.checked = True self.structuresButtonGroup.addButton(btn, 0) self.groupboxLayout.addWidget(btn) btn = qt.QRadioButton("Pulmonary Arterial") btn.name = "paRadioButton" self.structuresButtonGroup.addButton(btn, 1) self.groupboxLayout.addWidget(btn) btn = qt.QRadioButton("Aorta") btn.name = "aortaRadioButton" self.structuresButtonGroup.addButton(btn, 2) self.groupboxLayout.addWidget(btn) ### Buttons toolbox self.buttonsToolboxFrame = qt.QFrame() self.buttonsToolboxLayout = qt.QGridLayout() self.buttonsToolboxFrame.setLayout(self.buttonsToolboxLayout) self.mainAreaLayout.addWidget(self.buttonsToolboxFrame, 2, 1) self.placeRulersButton = ctk.ctkPushButton() self.placeRulersButton.text = "Place ruler/s" self.placeRulersButton.name = "placeRulersButton" self.placeRulersButton.toolTip = "Place the ruler/s for the selected structure/s in the current slice" self.placeRulersButton.setIcon( qt.QIcon("{0}/ruler.png".format(SlicerUtil.CIP_ICON_DIR))) self.placeRulersButton.setIconSize(qt.QSize(20, 20)) self.placeRulersButton.setFixedWidth(105) self.placeRulersButton.setStyleSheet("font-weight:bold") self.buttonsToolboxLayout.addWidget(self.placeRulersButton, 0, 0) self.moveUpButton = ctk.ctkPushButton() self.moveUpButton.text = "Move up" self.moveUpButton.toolTip = "Move the selected ruler/s one slice up" self.moveUpButton.setIcon( qt.QIcon("{0}/move_up.png".format(SlicerUtil.CIP_ICON_DIR))) self.moveUpButton.setIconSize(qt.QSize(20, 20)) self.moveUpButton.setFixedWidth(95) self.buttonsToolboxLayout.addWidget(self.moveUpButton, 0, 1) self.moveDownButton = ctk.ctkPushButton() self.moveDownButton.text = "Move down" self.moveDownButton.toolTip = "Move the selected ruler/s one slice down" self.moveDownButton.setIcon( qt.QIcon("{0}/move_down.png".format(SlicerUtil.CIP_ICON_DIR))) self.moveDownButton.setIconSize(qt.QSize(20, 20)) self.moveDownButton.setFixedWidth(95) self.buttonsToolboxLayout.addWidget(self.moveDownButton, 0, 2) self.removeButton = ctk.ctkPushButton() self.removeButton.text = "Remove ALL rulers" self.removeButton.toolTip = "Remove all the rulers for this volume" self.removeButton.setIcon( qt.QIcon("{0}/delete.png".format(SlicerUtil.CIP_ICON_DIR))) self.removeButton.setIconSize(qt.QSize(20, 20)) self.buttonsToolboxLayout.addWidget(self.removeButton, 1, 1, 1, 2, 2) ### Textboxes self.textboxesFrame = qt.QFrame() self.textboxesLayout = qt.QFormLayout() self.textboxesFrame.setLayout(self.textboxesLayout) self.textboxesFrame.setFixedWidth(190) self.mainAreaLayout.addWidget(self.textboxesFrame, 3, 0) self.paTextBox = qt.QLineEdit() self.paTextBox.setReadOnly(True) self.textboxesLayout.addRow("PA (mm): ", self.paTextBox) self.aortaTextBox = qt.QLineEdit() self.aortaTextBox.setReadOnly(True) self.textboxesLayout.addRow("Aorta (mm): ", self.aortaTextBox) self.ratioTextBox = qt.QLineEdit() self.ratioTextBox.name = "ratioTextBox" self.ratioTextBox.setReadOnly(True) self.textboxesLayout.addRow("Ratio PA/A: ", self.ratioTextBox) # Save case data self.reportsCollapsibleButton = ctk.ctkCollapsibleButton() self.reportsCollapsibleButton.text = "Reporting" self.layout.addWidget(self.reportsCollapsibleButton) self.reportsLayout = qt.QHBoxLayout(self.reportsCollapsibleButton) self.storedColumnNames = [ "caseId", "paDiameterMm", "aortaDiameterMm", "pa1r", "pa1a", "pa1s", "pa2r", "pa2a", "pa2s", "a1r", "a1a", "a1s", "a2r", "a2a", "a2s" ] columns = CaseReportsWidget.getColumnKeysNormalizedDictionary( self.storedColumnNames) self.reportsWidget = CaseReportsWidget( self.moduleName, columns, parentWidget=self.reportsCollapsibleButton) self.reportsWidget.setup() # Init state self.resetModuleState() self.preventSavingState = False self.saveStateBeforeEnteringModule() self.preventSavingState = True self.switchToRedView() ##### # Case navigator if SlicerUtil.isSlicerACILLoaded(): caseNavigatorAreaCollapsibleButton = ctk.ctkCollapsibleButton() caseNavigatorAreaCollapsibleButton.text = "Case navigator" self.layout.addWidget(caseNavigatorAreaCollapsibleButton, 0x0020) # caseNavigatorLayout = qt.QVBoxLayout(caseNavigatorAreaCollapsibleButton) # Add a case list navigator from ACIL.ui import CaseNavigatorWidget self.caseNavigatorWidget = CaseNavigatorWidget( self.moduleName, caseNavigatorAreaCollapsibleButton) self.caseNavigatorWidget.setup() self.layout.addStretch() # Connections self.observers = [] self.volumeSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onVolumeSelectorChanged) self.jumptToTemptativeSliceButton.connect( 'clicked()', self.onJumpToTemptativeSliceButtonClicked) self.placeRulersButton.connect('clicked()', self.onPlaceRulersClicked) self.moveUpButton.connect('clicked()', self.onMoveUpRulerClicked) self.moveDownButton.connect('clicked()', self.onMoveDownRulerClicked) self.removeButton.connect('clicked()', self.onRemoveRulerClicked) self.reportsWidget.addObservable( self.reportsWidget.EVENT_SAVE_BUTTON_CLICKED, self.onSaveReport) # Init state self.resetModuleState() self.preventSavingState = False self.saveStateBeforeEnteringModule() self.preventSavingState = True
def setup(self): ScriptedLoadableModuleWidget.setup(self) # # the inps volume selector # parametersCollapsibleButton = ctk.ctkCollapsibleButton() parametersCollapsibleButton.text = "IO Volumes" self.parent.layout().addWidget(parametersCollapsibleButton) # Layout within the dummy collapsible button parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton) parametersFormLayout.setVerticalSpacing(5) self.CTSelector = slicer.qMRMLNodeComboBox() self.CTSelector.nodeTypes = (("vtkMRMLScalarVolumeNode"), "") self.CTSelector.addAttribute("vtkMRMLScalarVolumeNode", "LabelMap", 0) self.CTSelector.selectNodeUponCreation = False self.CTSelector.addEnabled = False self.CTSelector.removeEnabled = False self.CTSelector.noneEnabled = True self.CTSelector.showHidden = False self.CTSelector.showChildNodeTypes = False self.CTSelector.setMRMLScene(slicer.mrmlScene) self.CTSelector.setToolTip("Pick the CT image to work on.") parametersFormLayout.addRow("Input CT Volume: ", self.CTSelector) # # the label map volume selector # self.labelSelector = slicer.qMRMLNodeComboBox() # self.labelSelector.nodeTypes = ( ("vtkMRMLScalarVolumeNode"), "" ) # self.labelSelector.addAttribute( "vtkMRMLScalarVolumeNode", "LabelMap", 1 ) self.labelSelector.nodeTypes = (("vtkMRMLLabelMapVolumeNode"), "") self.labelSelector.selectNodeUponCreation = True self.labelSelector.addEnabled = False self.labelSelector.removeEnabled = False self.labelSelector.noneEnabled = True self.labelSelector.showHidden = False self.labelSelector.showChildNodeTypes = False self.labelSelector.setMRMLScene(slicer.mrmlScene) self.labelSelector.setToolTip("Pick the label map to the algorithm.") parametersFormLayout.addRow("Label Map Volume: ", self.labelSelector) # Image filtering section self.preProcessingWidget = PreProcessingWidget( self.moduleName, parentWidget=self.parent) self.preProcessingWidget.setup() # # self.splitRadioButton = qt.QRadioButton() # self.splitRadioButton.setText('Split Label Map') # self.splitRadioButton.setChecked(0) # self.parent.layout().addWidget(self.splitRadioButton, 0, 3) # Apply button self.applyButton = qt.QPushButton("Apply") self.applyButton.toolTip = "Calculate Parenchyma Phenotypes." self.applyButton.enabled = False self.applyButton.setFixedSize(300, 30) self.parent.layout().addWidget(self.applyButton, 0, 4) # model and view for stats table self.view = qt.QTableView() self.view.sortingEnabled = True self.parent.layout().addWidget(self.view) # model and view for EXP stats table """self.viewexp = qt.QTableView() self.viewexp.sortingEnabled = True self.parent.layout().addWidget(self.viewexp)""" # Histogram Selection self.HistSection = qt.QFrame() self.HistSection.setLayout(qt.QVBoxLayout()) self.parent.layout().addWidget(self.HistSection) self.HistSection.setObjectName('HistSection') self.HistSection.setStyleSheet( '#HistSection {border: 0.5px solid lightGray; }') HistSectionTitle = qt.QLabel() HistSectionTitle.setText('Histogram Section') # HistSectionTitle.setStyleSheet('border: 1px solid white; color: black') self.HistSection.layout().addWidget(HistSectionTitle) self.histogramCheckBoxes = [] self.histFrame = qt.QFrame() # self.histFrame.setStyleSheet('border: 1px solid white') self.histFrame.setLayout(qt.QHBoxLayout()) self.GlobalHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.GlobalHistCheckBox) self.histFrame.layout().addWidget(self.GlobalHistCheckBox) self.RightHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.RightHistCheckBox) self.histFrame.layout().addWidget(self.RightHistCheckBox) self.LeftHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.LeftHistCheckBox) self.histFrame.layout().addWidget(self.LeftHistCheckBox) self.RULHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.RULHistCheckBox) self.histFrame.layout().addWidget(self.RULHistCheckBox) self.RLLHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.RLLHistCheckBox) self.histFrame.layout().addWidget(self.RLLHistCheckBox) self.RMLHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.RMLHistCheckBox) self.histFrame.layout().addWidget(self.RMLHistCheckBox) self.LULHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.LULHistCheckBox) self.histFrame.layout().addWidget(self.LULHistCheckBox) self.LLLHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.LLLHistCheckBox) self.histFrame.layout().addWidget(self.LLLHistCheckBox) self.LUTHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.LUTHistCheckBox) self.histFrame.layout().addWidget(self.LUTHistCheckBox) self.LMTHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.LMTHistCheckBox) self.histFrame.layout().addWidget(self.LMTHistCheckBox) self.LLTHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.LLTHistCheckBox) self.histFrame.layout().addWidget(self.LLTHistCheckBox) self.RUTHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.RUTHistCheckBox) self.histFrame.layout().addWidget(self.RUTHistCheckBox) self.RMTHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.RMTHistCheckBox) self.histFrame.layout().addWidget(self.RMTHistCheckBox) self.RLTHistCheckBox = qt.QCheckBox() self.histogramCheckBoxes.append(self.RLTHistCheckBox) self.histFrame.layout().addWidget(self.RLTHistCheckBox) for i in xrange(len(self.histogramCheckBoxes)): self.histogramCheckBoxes[i].setText(self.rTags[i]) self.histogramCheckBoxes[i].hide() self.HistSection.layout().addWidget(self.histFrame) self.HistSection.enabled = False # Chart button self.chartBox = qt.QFrame() self.chartBox.setObjectName("chartBox") self.chartBox.setStyleSheet( '#chartBox {border: 0.5px solid lightGray;}') self.chartBox.setLayout(qt.QVBoxLayout()) self.parent.layout().addWidget(self.chartBox) chartSectionTitle = qt.QLabel() chartSectionTitle.setText('Chart Section') self.chartBox.layout().addWidget(chartSectionTitle) chartFrame = qt.QFrame() chartFrame.setLayout(qt.QHBoxLayout()) self.chartBox.layout().addWidget(chartFrame) self.chartButton = qt.QPushButton("Chart") self.chartButton.toolTip = "Make a chart from the current statistics." chartFrame.layout().addWidget(self.chartButton) self.chartOption = qt.QComboBox() self.chartOption.addItems(self.chartOptions) chartFrame.layout().addWidget(self.chartOption) self.chartBox.enabled = False self.reportsWidget = CaseReportsWidget(self.moduleName, self.columnsDict, parentWidget=self.parent) self.reportsWidget.setup() self.reportsWidget.showPrintButton(True) # self.reportsWidget.saveButton.enabled = False # self.reportsWidget.openButton.enabled = False # self.reportsWidget.exportButton.enabled = False # self.reportsWidget.removeButton.enabled = False # By default, the Print button is hidden # self.reportsWidget.showPrintButton.enabled = False # Add vertical spacer self.parent.layout().addStretch(1) # connections self.applyButton.connect('clicked()', self.onApply) self.chartButton.connect('clicked()', self.onChart) self.reportsWidget.addObservable( self.reportsWidget.EVENT_SAVE_BUTTON_CLICKED, self.onSaveReport) self.reportsWidget.addObservable( self.reportsWidget.EVENT_PRINT_BUTTON_CLICKED, self.onPrintReport) self.CTSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onCTSelect) self.labelSelector.connect('currentNodeChanged(vtkMRMLNode*)', self.onLabelSelect) self.GlobalHistCheckBox.connect('clicked()', self.onHistogram) self.RightHistCheckBox.connect('clicked()', self.onHistogram) self.LeftHistCheckBox.connect('clicked()', self.onHistogram) self.RULHistCheckBox.connect('clicked()', self.onHistogram) self.RLLHistCheckBox.connect('clicked()', self.onHistogram) self.RMLHistCheckBox.connect('clicked()', self.onHistogram) self.LULHistCheckBox.connect('clicked()', self.onHistogram) self.LLLHistCheckBox.connect('clicked()', self.onHistogram) self.LUTHistCheckBox.connect('clicked()', self.onHistogram) self.LMTHistCheckBox.connect('clicked()', self.onHistogram) self.LLTHistCheckBox.connect('clicked()', self.onHistogram) self.RUTHistCheckBox.connect('clicked()', self.onHistogram) self.RMTHistCheckBox.connect('clicked()', self.onHistogram) self.RLTHistCheckBox.connect('clicked()', self.onHistogram)
def setup(self): # Instantiate and connect widgets ... ScriptedLoadableModuleWidget.setup(self) #self.logic = CIP_CalciumScoringLogic() # # Parameters Area # parametersCollapsibleButton = ctk.ctkCollapsibleButton() parametersCollapsibleButton.text = "Parameters" self.layout.addWidget(parametersCollapsibleButton) # Layout within the dummy collapsible button parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton) # # target volume selector # self.inputSelector = slicer.qMRMLNodeComboBox() self.inputSelector.nodeTypes = ( ("vtkMRMLScalarVolumeNode"), "" ) self.inputSelector.addEnabled = False self.inputSelector.removeEnabled = False self.inputSelector.noneEnabled = False self.inputSelector.showHidden = False self.inputSelector.showChildNodeTypes = False self.inputSelector.setMRMLScene( slicer.mrmlScene ) self.inputSelector.setToolTip( "Pick the input to the algorithm." ) parametersFormLayout.addRow("Target Volume: ", self.inputSelector) self.inputSelector.connect("currentNodeChanged(vtkMRMLNode*)", self.onVolumeChanged) self.volumeNode = self.inputSelector.currentNode() # # calcification type # # self.calcificationTypeBox = qt.QComboBox() # self.calcificationTypeBox.addItem("Heart") # self.calcificationTypeBox.addItem("Aorta") # parametersFormLayout.addRow("Region", self.calcificationTypeBox) # self.calcificationTypeBox.connect("currentIndexChanged(int)", self.onTypeChanged) self.ThresholdRange = ctk.ctkRangeWidget() self.ThresholdRange.minimum = 0 self.ThresholdRange.maximum = 2000 self.ThresholdRange.setMinimumValue(self.ThresholdMin) self.ThresholdRange.setMaximumValue(self.ThresholdMax) self.ThresholdRange.connect("minimumValueChanged(double)", self.onThresholdMinChanged) self.ThresholdRange.connect("maximumValueChanged(double)", self.onThresholdMaxChanged) parametersFormLayout.addRow("Threshold Value", self.ThresholdRange) self.ThresholdRange.setMinimumValue(self.ThresholdMin) self.ThresholdRange.setMaximumValue(self.ThresholdMax) self.LesionSizeRange= ctk.ctkRangeWidget() self.LesionSizeRange.minimum = 0.5 self.LesionSizeRange.maximum = 1000 self.LesionSizeRange.setMinimumValue(self.MinimumLesionSize) self.LesionSizeRange.setMaximumValue(self.MaximumLesionSize) self.LesionSizeRange.connect("minimumValueChanged(double)", self.onMinSizeChanged) self.LesionSizeRange.connect("maximumValueChanged(double)", self.onMaxSizeChanged) parametersFormLayout.addRow("Lesion Size (mm^3)", self.LesionSizeRange) self.LesionSizeRange.setMinimumValue(self.MinimumLesionSize) self.LesionSizeRange.setMaximumValue(self.MaximumLesionSize) self.scoreField=dict() for sr in self.summary_reports: self.scoreField[sr] = qt.QLineEdit() self.scoreField[sr].setText(0) parametersFormLayout.addRow("Total "+sr, self.scoreField[sr]) # # Update button and Select Table # self.updateButton = qt.QPushButton("Update") self.updateButton.toolTip = "Update calcium score computation" self.updateButton.enabled = True self.updateButton.setFixedSize(100, 50) #parametersFormLayout.addRow("", self.updateButton) self.updateButton.connect('clicked()', self.onUpdate) # # Select table # self.selectLabels = qt.QTableWidget() #self.selectLabels.horizontalHeader().hide() self.selectLabels.verticalHeader().hide() self.selectLabels.setColumnCount(6) self.selectLabels.itemClicked.connect(self.handleItemClicked) #Add row with columns name col_names=["","Agatston Score","Mass Score","Volume (mm^3)","Mean HU","Max HU"] self.selectLabels.setHorizontalHeaderLabels(col_names) parametersFormLayout.addRow(self.updateButton, self.selectLabels) # # Save Widget Area # #self.saveCollapsibleButton = ctk.ctkCollapsibleButton() #self.saveCollapsibleButton.text = "Saving" #self.layout.addWidget(self.saveCollapsibleButton) self.reportsWidget = CaseReportsWidget(self.moduleName, self.columnsDict, parentWidget=self.parent) self.reportsWidget.setup() self.reportsWidget.showPrintButton(False) self.reportsWidget.addObservable(self.reportsWidget.EVENT_SAVE_BUTTON_CLICKED, self.onSaveReport) # # ROI Area # self.roiCollapsibleButton = ctk.ctkCollapsibleButton() self.roiCollapsibleButton.text = "ROI" self.roiCollapsibleButton.setChecked(False) self.layout.addWidget(self.roiCollapsibleButton) # Layout within the dummy collapsible button roiFormLayout = qt.QFormLayout(self.roiCollapsibleButton) # # ROI # self.ROIWidget = slicer.qMRMLAnnotationROIWidget() self.roiNode = slicer.vtkMRMLAnnotationROINode() slicer.mrmlScene.AddNode(self.roiNode) self.ROIWidget.setMRMLAnnotationROINode(self.roiNode) roiFormLayout.addRow("", self.ROIWidget) #self.roiNode.AddObserver("ModifiedEvent", self.onROIChangedEvent, 1) # Add vertical spacer self.layout.addStretch(1) # Add temp nodes self.croppedNode=slicer.vtkMRMLScalarVolumeNode() self.croppedNode.SetHideFromEditors(1) slicer.mrmlScene.AddNode(self.croppedNode) self.labelsNode=slicer.vtkMRMLLabelMapVolumeNode() slicer.mrmlScene.AddNode(self.labelsNode) if self.inputSelector.currentNode(): self.onVolumeChanged(self.inputSelector.currentNode())