def takeScreenshot(self, name, description, type=-1): # show the message even if not taking a screen shot slicer.util.delayDisplay( 'Take screenshot: ' + description + '.\nResult is available in the Annotations module.', 3000) lm = slicer.app.layoutManager() # switch on the type to get the requested window widget = 0 if type == slicer.qMRMLScreenShotDialog.FullLayout: # full layout widget = lm.viewport() elif type == slicer.qMRMLScreenShotDialog.ThreeD: # just the 3D window widget = lm.threeDWidget(0).threeDView() elif type == slicer.qMRMLScreenShotDialog.Red: # red slice window widget = lm.sliceWidget("Red") elif type == slicer.qMRMLScreenShotDialog.Yellow: # yellow slice window widget = lm.sliceWidget("Yellow") elif type == slicer.qMRMLScreenShotDialog.Green: # green slice window widget = lm.sliceWidget("Green") else: # default to using the full window widget = slicer.util.mainWindow() # reset the type so that the node is set correctly type = slicer.qMRMLScreenShotDialog.FullLayout # grab and convert to vtk image data qpixMap = qt.QPixmap().grabWidget(widget) qimage = qpixMap.toImage() imageData = vtk.vtkImageData() slicer.qMRMLUtils().qImageToVtkImageData(qimage, imageData) annotationLogic = slicer.modules.annotations.logic() annotationLogic.CreateSnapShot(name, description, type, 1, imageData)
def takeScreenshot(self, name, description, type=-1): # show the message even if not taking a screen shot self.delayDisplay(description) if self.enableScreenshots == 0: return lm = slicer.app.layoutManager() # switch on the type to get the requested window widget = 0 if type == -1: # full window widget = slicer.util.mainWindow() elif type == slicer.qMRMLScreenShotDialog().FullLayout: # full layout widget = lm.viewport() elif type == slicer.qMRMLScreenShotDialog().ThreeD: # just the 3D window widget = lm.threeDWidget(0).threeDView() elif type == slicer.qMRMLScreenShotDialog().Red: # red slice window widget = lm.sliceWidget("Red") elif type == slicer.qMRMLScreenShotDialog().Yellow: # yellow slice window widget = lm.sliceWidget("Yellow") elif type == slicer.qMRMLScreenShotDialog().Green: # green slice window widget = lm.sliceWidget("Green") # grab and convert to vtk image data qpixMap = qt.QPixmap().grabWidget(widget) qimage = qpixMap.toImage() imageData = vtk.vtkImageData() slicer.qMRMLUtils().qImageToVtkImageData(qimage, imageData) annotationLogic = slicer.modules.annotations.logic() annotationLogic.CreateSnapShot(name, description, type, self.screenshotScaleFactor, imageData)
def display_output(self): # Update output text self.outputLabel.setText( "The needle has a probability of %0.1f%% to %s \nthe target, a probability of %0.1f%% to deflect %s," "\nand a probability of %0.1f%% to deflect to the %s." % (self.below5dot76Accuracy, self.hitMiss, self.inRightAccuracy, self.rightLeft, self.inTopAccuracy, self.topBottom)) # Get predicted quadrant that needle will deviate towards unless insertion error <5mm if self.below5dot76 > 0.5: quarter = "" elif self.rightLeft == "right" and self.topBottom == "top": quarter = "Q1" elif self.rightLeft == "right" and self.topBottom == "bottom": quarter = "Q2" elif self.rightLeft == "left" and self.topBottom == "bottom": quarter = "Q3" else: quarter = "Q4" # Update output visual image = qt.QPixmap(self.dir + ("/NeedleDeviationPredictor GUI/%s%s.png" % (str(quarter), str(self.hitMiss)))) self.label1.setPixmap(image)
def createUserInterface(self): """ This method uses qt to create a user interface. qMRMLNodeComboBox is a drop down menu for picking MRML files. MRML files have to be added to a "scene," i.e. the main Slicer container, hence setMRMLScene. """ self.__layout = self.__parent.createUserInterface() image_label = qt.QLabel('Test label') image = qt.QPixmap( 'C:/Users/azb22/Documents/GitHub/Public_qtim_tools/SlicerGBMWizard/GBMWizard/GBMWizard_Lib/VolumeSelect.png' ) image_label.setPixmap(image) image_label.alignment = 4 self.__layout.addRow(image_label) step_label = qt.QLabel( 'This module requires four MRI volumes for GBM cases. Please select pre- and post-contrast T1 images, a T2 image, and a FLAIR image from a single patient visit. The ability to use multiple cases will be added in future versions.' ) step_label.setWordWrap(True) self.__informationGroupBox = qt.QGroupBox() self.__informationGroupBox.setTitle('Information') self.__informationGroupBoxLayout = qt.QFormLayout( self.__informationGroupBox) self.__volumeSelectionGroupBox = qt.QGroupBox() self.__volumeSelectionGroupBox.setTitle('Volume Selection') self.__volumeSelectionGroupBoxLayout = qt.QFormLayout( self.__volumeSelectionGroupBox) t1PreScanLabel = qt.QLabel('Pre-Contrast T1 Image:') self.__t1PreVolumeSelector = slicer.qMRMLNodeComboBox() self.__t1PreVolumeSelector.toolTip = "Select a pre-contrast T1 image." self.__t1PreVolumeSelector.nodeTypes = ['vtkMRMLScalarVolumeNode'] self.__t1PreVolumeSelector.setMRMLScene(slicer.mrmlScene) self.__t1PreVolumeSelector.addEnabled = 0 t1PostScanLabel = qt.QLabel('Post-Contrast T1 Image:') self.__t1PostVolumeSelector = slicer.qMRMLNodeComboBox() self.__t1PostVolumeSelector.toolTip = "Select a post-contrast T1 image." self.__t1PostVolumeSelector.nodeTypes = ['vtkMRMLScalarVolumeNode'] self.__t1PostVolumeSelector.setMRMLScene(slicer.mrmlScene) self.__t1PostVolumeSelector.addEnabled = 0 t2ScanLabel = qt.QLabel('T2 Image:') self.__t2VolumeSelector = slicer.qMRMLNodeComboBox() self.__t2VolumeSelector.toolTip = "Select a T2 image." self.__t2VolumeSelector.nodeTypes = ['vtkMRMLScalarVolumeNode'] self.__t2VolumeSelector.setMRMLScene(slicer.mrmlScene) self.__t2VolumeSelector.addEnabled = 0 flairScanLabel = qt.QLabel('FLAIR Image:') self.__flairVolumeSelector = slicer.qMRMLNodeComboBox() self.__flairVolumeSelector.toolTip = "Select a FLAIR image." self.__flairVolumeSelector.nodeTypes = ['vtkMRMLScalarVolumeNode'] self.__flairVolumeSelector.setMRMLScene(slicer.mrmlScene) self.__flairVolumeSelector.addEnabled = 0 self.__layout.addRow(self.__informationGroupBox) self.__informationGroupBoxLayout.addRow(step_label) self.__layout.addRow(self.__volumeSelectionGroupBox) self.__volumeSelectionGroupBoxLayout.addRow(t1PreScanLabel, self.__t1PreVolumeSelector) self.__volumeSelectionGroupBoxLayout.addRow( t1PostScanLabel, self.__t1PostVolumeSelector) self.__volumeSelectionGroupBoxLayout.addRow(t2ScanLabel, self.__t2VolumeSelector) self.__volumeSelectionGroupBoxLayout.addRow(flairScanLabel, self.__flairVolumeSelector) self.volumeNodes = [ self.__t1PostVolumeSelector.currentNode(), self.__t1PostVolumeSelector.currentNode(), self.__t2VolumeSelector.currentNode(), self.__flairVolumeSelector.currentNode() ] self.updateWidgetFromParameters(self.parameterNode()) # This timer is a trick to wait for buttons to load BEFORE deleting them. qt.QTimer.singleShot(0, self.killButton)
def setup(self): self.dir = os.path.dirname(os.path.realpath(__file__)) # # Setup # setupWindow = ctk.ctkCollapsibleButton() setupWindow.text = 'Setup' self.layout.addWidget(setupWindow) self.setupLayout = qt.QFormLayout(setupWindow) # Input box inputBox = ctk.ctkCollapsibleGroupBox() inputBox.setTitle('Input:') self.setupLayout.addRow(inputBox) self.inputBoxLayout = qt.QFormLayout(inputBox) # Bevel angle slider self.bevelAngleSlider = ctk.ctkSliderWidget() self.bevelAngleSlider.connect('valueChanged(double)', self.bevel_angle_changed) self.bevelAngleSlider.decimals = 0 self.bevelAngleSlider.minimum = 0 self.bevelAngleSlider.maximum = 360 self.inputBoxLayout.addRow("Bevel Angle:", self.bevelAngleSlider) # R-Axis Entry Error self.entryErrR = qt.QLineEdit() self.entryErrR.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("R-Axis Entry Error:", self.entryErrR) # A-Axis Entry Error self.entryErrA = qt.QLineEdit() self.entryErrA.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("A-Axis Entry Error:", self.entryErrA) # S-Axis Entry Error self.entryErrS = qt.QLineEdit() self.entryErrS.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("S-Axis Entry Error:", self.entryErrS) # Curve Radius self.curveRadius = qt.QLineEdit() self.curveRadius.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("Curve Radius:", self.curveRadius) # Insertion Length self.insertionLength = qt.QLineEdit() self.insertionLength.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("Insertion Length:", self.insertionLength) # Needle length in prostate self.len1 = qt.QLineEdit() self.len1.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("Needle length in prostate:", self.len1) # Needle Length in pelvic diaphragm self.len2 = qt.QLineEdit() self.len2.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("Needle length in pelvic diaphragm:", self.len2) # Needle length in bulbospongiosus self.len3 = qt.QLineEdit() self.len3.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("Needle length in bulbospongiousus:", self.len3) # Needle length in ischiocavernosus self.len4 = qt.QLineEdit() self.len4.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("Needle length in ischiocavernosus:", self.len4) # Needle length in unsegmented tissue self.len5 = qt.QLineEdit() self.len5.setPlaceholderText("Enter length (mm)") self.inputBoxLayout.addRow("Needle length in unsegmented tissue:", self.len5) # Calculate Error self.calculateError = qt.QPushButton("Calculate Error") self.calculateError.clicked.connect(self.run_regressions) self.setupLayout.addWidget(self.calculateError) # Disable calculation until data is entered self.calculateError.setEnabled(0) self.calculateError.setText('Enter all data first!') # # Output # outputWindow = ctk.ctkCollapsibleButton() outputWindow.text = 'Output' self.layout.addWidget(outputWindow) self.outputLayout = qt.QFormLayout(outputWindow) # Output box outputBoxCollapsible = ctk.ctkCollapsibleGroupBox() outputBoxCollapsible.setTitle('Output') self.outputLayout.addRow(outputBoxCollapsible) self.outputBox = qt.QFormLayout(outputBoxCollapsible) # Initial output text self.outputLabel = qt.QLabel("") self.outputBox.addRow(self.outputLabel) self.outputLabel.setText("The needle has a probability of 00.00% to hit the \ntarget, a probability of 00.00% " "to deflect to the right,\nand a probability of 00.00% to deflect to the top.") # Initial visual output image = qt.QPixmap(self.dir + "/NeedleDeviationPredictor GUI/empty.png") self.label1 = qt.QLabel("") # Scaling and sizing self.label1.setScaledContents(True) self.label1.setMargin(0) self.label1.setPixmap(image) qSize = qt.QSizePolicy() self.label1.setSizePolicy(qSize) self.outputBox.addRow(self.label1) # Vertical spacer self.layout.addStretch(1) # Check all entered values are floats values = [self.entryErrR, self.entryErrA, self.entryErrS, self.curveRadius, self.insertionLength, self.len1, self.len2, self.len3, self.len4, self.len5] for value in values: value.textChanged.connect(self.check_inputs)
def revealPixmap(self, xy): """fill a pixmap with an image that has a reveal pattern at xy with the fg drawn over the bg""" # Get QImages for the two layers bgVTKImage = self.layerLogics['B'].GetImageData() fgVTKImage = self.layerLogics['F'].GetImageData() bgQImage = qt.QImage() fgQImage = qt.QImage() slicer.qMRMLUtils().vtkImageDataToQImage(bgVTKImage, bgQImage) slicer.qMRMLUtils().vtkImageDataToQImage(fgVTKImage, fgQImage) # get the geometry of the focal point (xy) and images # noting that vtk has the origin at the bottom left and qt has # it at the top left. yy is the flipped version of y imageWidth = bgQImage.width() imageHeight = bgQImage.height() x, y = xy yy = imageHeight - y # # make a generally transparent image, # then fill quadrants with the fg image # overlayImage = qt.QImage(imageWidth, imageHeight, qt.QImage().Format_ARGB32) overlayImage.fill(0) halfWidth = imageWidth / 2 halfHeight = imageHeight / 2 topLeft = qt.QRect(0, 0, x, yy) bottomRight = qt.QRect(x, yy, imageWidth - x - 1, imageHeight - yy - 1) self.painter.begin(overlayImage) self.painter.drawImage(topLeft, fgQImage, topLeft) self.painter.drawImage(bottomRight, fgQImage, bottomRight) self.painter.end() # draw the bg and fg on top of gray background compositePixmap = qt.QPixmap(self.width, self.height) compositePixmap.fill(self.gray) self.painter.begin(compositePixmap) self.painter.drawImage(-1 * (x - self.width / 2), -1 * (yy - self.height / 2), bgQImage) self.painter.drawImage(-1 * (x - self.width / 2), -1 * (yy - self.height / 2), overlayImage) self.painter.end() if self.scale: compositePixmap = self.scalePixmap(compositePixmap) # draw a border around the pixmap self.painter.begin(compositePixmap) self.pen = qt.QPen() self.color = qt.QColor("#FF0") self.color.setAlphaF(0.3) self.pen.setColor(self.color) self.pen.setWidth(5) self.pen.setStyle(3) # dotted line (Qt::DotLine) self.painter.setPen(self.pen) rect = qt.QRect(1, 1, self.width - 2, self.height - 2) self.painter.drawRect(rect) self.painter.end() return compositePixmap