Exemplo n.º 1
0
    def image_display(self):
        """
        Update the ct_image to be displayed on the DICOM View.
        """
        # Lead CT
        ct_pixmaps = self.pt_ct_dict_container.get(
            "ct_pixmaps_" + self.slice_view)
        slider_id = self.slider.value()
        ct_image = ct_pixmaps[slider_id].toImage()

        # Load PT
        pt_pixmaps = self.pt_ct_dict_container.get(
            "pt_pixmaps_" + self.slice_view)
        m = float(len(pt_pixmaps)) / len(ct_pixmaps)
        pt_image = pt_pixmaps[int(m * slider_id)].toImage()

        # Get alpha
        alpha = float(self.alpha_slider.value() / 100)

        # Merge Images
        painter = QPainter()
        painter.begin(ct_image)
        painter.setOpacity(alpha)
        painter.drawImage(0, 0, pt_image)
        painter.end()

        # Load merged images
        merged_pixmap = QtGui.QPixmap.fromImage(ct_image)
        label = QtWidgets.QGraphicsPixmapItem(merged_pixmap)
        self.scene = QtWidgets.QGraphicsScene()
        self.scene.addItem(label)
Exemplo n.º 2
0
    def paintEvent(self, event):
        size = self.size()

        # draw background
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(QColor(255, 255, 255, 255))
        painter.setBrush(self.fill_color)
        painter.drawRect(0, 0, size.width(), size.height())
        painter.end()
Exemplo n.º 3
0
 def export_arr(self, frame_index: int):
     self.scene.update_frame(frame_index)
     img = QImage(self.video_data.width, self.video_data.height,
                  QImage.Format_ARGB32)
     painter = QPainter()
     painter.begin(img)
     self.scene.render(painter)
     painter.end()
     shape = (img.height(), img.bytesPerLine() * 8 // img.depth(), 4)
     ptr = img.bits()
     arr = np.array(ptr, dtype=np.uint8).reshape(shape)
     arr = arr[..., :3]
     return arr
Exemplo n.º 4
0
	def __init__(self):
		# Sidebar icons are 28x28 points. Should be at least 56x56 pixels for
		# HiDPI display compatibility. They will be automatically made theme
		# aware, so you need only provide a grayscale image, where white is
		# the color of the shape.
		icon = QImage(56, 56, QImage.Format_RGB32)
		icon.fill(0)

		# Render an "H" as the example icon
		p = QPainter()
		p.begin(icon)
		p.setFont(QFont("Open Sans", 56))
		p.setPen(QColor(255, 255, 255, 255))
		p.drawText(QRectF(0, 0, 56, 56), Qt.AlignCenter, "H")
		p.end()

		SidebarWidgetType.__init__(self, icon, "Hello")
Exemplo n.º 5
0
class ScreenSelection(QtWidgets.QGroupBox):
    def __init__(self, parent: DisplayCalibration):
        QtWidgets.QGroupBox.__init__(self,
                                     'Fullscreen selection (double click)')
        self.main = parent

        self.setSizePolicy(QtWidgets.QSizePolicy.Policy.Expanding,
                           QtWidgets.QSizePolicy.Policy.Expanding)

        self.painter = QPainter()

    def mouseDoubleClickEvent(self, ev, *args, **kwargs):
        for screen_id, screen_coords in enumerate(
                self._get_widget_screen_coords()):
            rect = QtCore.QRectF(*screen_coords)

            if not rect.contains(QtCore.QPoint(ev.pos().x(), ev.pos().y())):
                continue

            print(f'Set display to fullscreen on screen {screen_id}')

            screen = access.application.screens()[screen_id]
            px_ratio = screen.devicePixelRatio()
            self.main.global_settings.screen_id.set_value(screen_id)
            self.main.global_settings.win_x_pos.set_value(
                screen.geometry().x())
            self.main.global_settings.win_y_pos.set_value(
                screen.geometry().y())
            self.main.global_settings.win_width.set_value(
                int(screen.geometry().width() * px_ratio))
            self.main.global_settings.win_height.set_value(
                int(screen.geometry().height() * px_ratio))

            access.application.processEvents()

    @staticmethod
    def _get_norm_screen_coords() -> np.ndarray:

        # Get connected screens
        avail_screens = access.application.screens()

        # Calculate total display area bounding box
        area = [[
            s.geometry().width() * s.devicePixelRatio(),
            s.geometry().height() * s.devicePixelRatio()
        ] for s in avail_screens]
        area = np.sum(area, axis=0)

        xmin = np.min([s.geometry().x() for s in avail_screens])
        ymin = np.min([s.geometry().y() for s in avail_screens])

        # Define normalization functions
        xnorm = lambda x: (x - xmin) / area[0]
        ynorm = lambda y: (y - ymin) / area[1]

        # Add screen dimensions
        screens = []
        for s in avail_screens:
            g = s.geometry()
            screens.append([
                xnorm(g.x() * s.devicePixelRatio()),  # x
                ynorm(g.y() * s.devicePixelRatio()),  # y
                xnorm(g.width() * s.devicePixelRatio()),  # width
                ynorm(g.height() * s.devicePixelRatio())
            ])  # height

        return np.array(screens)

    def _get_widget_screen_coords(self):
        s = self._get_norm_screen_coords()
        s[:, 0] *= self.size().width()
        s[:, 1] *= self.size().height()
        s[:, 2] *= self.size().width()
        s[:, 3] *= self.size().height()

        return s.astype(int)

    def paintEvent(self, QPaintEvent):

        for i, screen in enumerate(self._get_widget_screen_coords()):

            rect = QtCore.QRect(*screen)

            self.painter.begin(self)

            self.painter.setBrush(QtCore.Qt.BrushStyle.Dense4Pattern)
            self.painter.drawRect(rect)

            self.painter.setPen(QColor(168, 34, 3))
            self.painter.setFont(QFont('Decorative', 30))
            self.painter.drawText(rect, QtCore.Qt.AlignmentFlag.AlignCenter,
                                  str(i))

            self.painter.end()
Exemplo n.º 6
0
    def paintEvent(self, event):

        paint = QPainter()
        paint.begin(self)
        paint.save()

        size = self.size()
        width = size.width()
        height = size.height()
        units = self.data.get('units')

        proportion = self.getProportion()

        horizontalOrientation = self.data.get('horizontal_orientation')

        if horizontalOrientation:

            rulerLength = width
            traceLengthLimit = height

        else:  # vertical orientation
            rulerLength = height
            traceLengthLimit = width

            paint.translate(width, 0)
            paint.rotate(90)

            # the length of the traces (lines)
        small = traceLengthLimit / 6
        medium = traceLengthLimit / 4
        large = traceLengthLimit / 3

        limit = rulerLength / proportion

        # draw less lines for centimeters
        if units == 'cm':
            step = 10

        else:
            step = 5

        # begin drawing
        fontSize = 10
        font = QFont('Serif', fontSize)
        fontMetrics = QFontMetrics(font)

        # draw background
        background = self.data.get('background_color')
        paint.fillRect(0, 0, rulerLength, traceLengthLimit, background)

        # draw the lines
        paint.setPen(self.data.get('lines_color'))
        paint.setFont(font)

        # the builtin range() doesn't support floats
        def float_range(current, end, rangeStep):
            while current < end:
                yield current
                current += rangeStep

            # we skip 0 and start in the first step, since there's no point in drawing the first line/text (it would appear cut off, since we're at the limit)

        for a in float_range(step, limit, step):

            position = a * proportion

            if (a % 100) == 0:
                lineLength = large

                if units == 'px':
                    text = '{}{}'.format(str(a), units)
                else:
                    text = '{}{}'.format(str(int(a / 100)), units)

                textWidth = fontMetrics.boundingRect(text).width()

                paint.drawText(position - textWidth / 2,
                               traceLengthLimit / 2 + fontSize / 2, text)

            elif (a % 50) == 0:
                lineLength = large

                # since 'cm' has a different step compared to the other units
                if units == 'cm':
                    lineLength = medium

            elif (a % 25) == 0:
                lineLength = medium

            else:
                lineLength = small

            paint.drawLine(position, 0, position, lineLength)
            paint.drawLine(position, traceLengthLimit, position,
                           traceLengthLimit - lineLength)

        # paint the division lines

        if self.data.get('division_lines'):
            paint.setPen(self.data.get('divisions_color'))
            halfPoint = rulerLength / 2
            quarterPoint = rulerLength / 4
            threeQuarterPoint = 3 / 4 * rulerLength

            paint.drawLine(quarterPoint, 0, quarterPoint, traceLengthLimit)
            paint.drawLine(halfPoint, 0, halfPoint, traceLengthLimit)
            paint.drawLine(threeQuarterPoint, 0, threeQuarterPoint,
                           traceLengthLimit)

        paint.restore()
        paint.end()