Пример #1
0
    def paintEvent(self, event):
        """
        On paint event

        @param txt: 
        @type txt:
        """
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        size = QSize(1, 1)
        size.scale(self.width() - 1, self.height() - 1, Qt.KeepAspectRatio)

        matrix = QTransform()
        matrix.translate((self.width() - size.width()) / 2,
                         (self.height() - size.height()) / 2)
        painter.setWorldTransform(matrix)

        self.__startAngle = 0
        for __data in self.__datas:
            self.drawData(painter, size, __data[0], __data[1], __data[2])
        self.__startAngle = 0
        for __data in self.__datas:
            self.drawText(painter, size, __data[0], __data[1], __data[2])
Пример #2
0
 def drawImage(self, imageid):
     cache = image_cache.cache
     cellColoring = self.cellColoring
     wallColoring = self.wallColoring
     pointColoring = self.pointColoring
     ellipsisDraw = self.ellipsisDraw
     overSampling = self.overSampling
     extraDrawing = self.extraDrawing
     bgColor = self.bgColor.rgb()
     result = self.result
     if self.result_type == "Data":
         data = result
         img_name = result.images_name[imageid]
     else:
         data = result.data
         img_name = result.images[imageid]
     #scale = data.images_scale[img_name]
     min_scale = data.minScale()
     img = cache.image(data.image_path(img_name))
     img_data = data[img_name]
     size = self._crop.size()
     pix = QImage(size*overSampling, QImage.Format_ARGB32)
     pix.fill(bgColor)
     painter = QPainter()
     if not painter.begin(pix):
         self.abort("Cannot create painter on QImage")
         return None, None, None
     painter.setRenderHints(QPainter.SmoothPixmapTransform, True)
     painter.setRenderHints(QPainter.Antialiasing, True)
     if overSampling > 1:
         painter.scale(overSampling, overSampling)
     painter.translate(-self._crop.topLeft())
     painter.save()
     painter.translate(self.translate)
     log_debug("Translating: %gx%g" % (self.translate.x(), self.translate.y()) )
     painter.scale(1/min_scale, 1/min_scale)
     painter.save()
     matrix = img_data.matrix()
     painter.setWorldTransform(matrix, True)
     painter.drawImage(QPoint(0,0), img)
     painter.restore()
     #pt_matrix = QTransform()
     #pt_matrix.scale(1/min_scale, 1/min_scale)
     #painter.setTransform(pt_matrix, True)
     cellColoring.startImage(painter, imageid)
     wallColoring.startImage(painter, imageid)
     for ed in extraDrawing:
         ed.startImage(painter, imageid)
     if self.result_type == "Growth":
         cells = result.cells[imageid]
         walls = result.walls[imageid]
     else:
         cells = img_data.cells
         walls = set()
         for cid in img_data.cells:
             pts = [ pt for pt in data.cells[cid] if pt in img_data ]
             if len(pts) > 1:
                 for i in range(len(pts)):
                     walls.add(data.wallId(pts[i-1], pts[i]))
     # Now, draw the cells and the ellipsis
     for cid in cells:
         painter.setPen(Qt.NoPen)
         color = cellColoring(imageid, cid)
         painter.setBrush(color)
         pts = data.cellAtTime(cid, img_data.index)
         if pts:
             pts.append(pts[0])
             ppts = []
             for p1,p2 in zip(pts[:-1], pts[1:]):
                 ppts.append(img_data[p1])
                 ppts.extend(img_data.walls[p1,p2])
             ppts.append(ppts[0])
             poly = QPolygonF(ppts)
             painter.drawPolygon(poly)
     # And draw the walls
     wallThickness = self.wallThickness*min_scale
     for wid in walls:
         color = wallColoring(imageid, wid)
         if color.alpha() > 0:
             pen = QPen(color)
             pen.setWidthF(wallThickness)
             painter.setPen(pen)
             pts = [img_data[wid[0]]] + img_data.walls[wid[0], wid[1]] + [img_data[wid[1]]]
             #painter.drawLine(img_data[wid[0]], img_data[wid[1]])
             painter.drawPolyline(*pts)
     # Then, draw the points
     pointSize = self.pointSize*min_scale
     pointLineColor = self.pointLineColor
     pointLineThickness = self.pointLineThickness*min_scale
     log_debug("pointSize = %g" % pointSize)
     for pid in img_data:
         color = pointColoring(imageid, pid)
         if color.alpha() > 0:
             pen = QPen(pointLineColor)
             pen.setWidthF(pointLineThickness)
             brush = QBrush(color)
             painter.setPen(pen)
             painter.setBrush(brush)
             pos = img_data[pid]
             rect = QRectF(pos.x()-pointSize, pos.y()-pointSize, 2*pointSize, 2*pointSize)
             painter.drawEllipse(rect)
     if ellipsisDraw.plot:
         for cid in cells:
             pts = data.cellAtTime(cid, img_data.index)
             if pts:
                 pts.append(pts[0])
                 ppts = []
                 for p1,p2 in zip(pts[:-1], pts[1:]):
                     ppts.append(img_data[p1])
                     ppts.extend(img_data.walls[p1,p2])
                 ppts.append(ppts[0])
                 #poly = QPolygonF(ppts)
                 #painter.drawPolygon(poly)
                 ellipsisDraw(painter, imageid, cid, ppts, min_scale)
     # At last, draw the extra data
     for ed in extraDrawing:
         ed(painter, imageid)
     tr = painter.worldTransform()
     painter.restore()
     pic_w = wallColoring.finalizeImage(painter, imageid, tr, self.crop)
     pic_c = cellColoring.finalizeImage(painter, imageid, tr, self.crop)
     for ed in extraDrawing:
         ed.finalizeImage(painter, imageid, tr, self.crop)
     painter.end()
     return pix, pic_w, pic_c
Пример #3
0
 def drawImage(self, imageid):
     cache = image_cache.cache
     cellColoring = self.cellColoring
     wallColoring = self.wallColoring
     pointColoring = self.pointColoring
     ellipsisDraw = self.ellipsisDraw
     overSampling = self.overSampling
     extraDrawing = self.extraDrawing
     bgColor = self.bgColor.rgb()
     result = self.result
     if self.result_type == "Data":
         data = result
         img_name = result.images_name[imageid]
     else:
         data = result.data
         img_name = result.images[imageid]
     #scale = data.images_scale[img_name]
     min_scale = data.minScale()
     img = cache.image(data.image_path(img_name))
     img_data = data[img_name]
     size = self._crop.size()
     pix = QImage(size * overSampling, QImage.Format_ARGB32)
     pix.fill(bgColor)
     painter = QPainter()
     if not painter.begin(pix):
         self.abort("Cannot create painter on QImage")
         return None, None, None
     painter.setRenderHints(QPainter.SmoothPixmapTransform, True)
     painter.setRenderHints(QPainter.Antialiasing, True)
     if overSampling > 1:
         painter.scale(overSampling, overSampling)
     painter.translate(-self._crop.topLeft())
     painter.save()
     painter.translate(self.translate)
     log_debug("Translating: %gx%g" %
               (self.translate.x(), self.translate.y()))
     painter.scale(1 / min_scale, 1 / min_scale)
     painter.save()
     matrix = img_data.matrix()
     painter.setWorldTransform(matrix, True)
     painter.drawImage(QPoint(0, 0), img)
     painter.restore()
     #pt_matrix = QTransform()
     #pt_matrix.scale(1/min_scale, 1/min_scale)
     #painter.setTransform(pt_matrix, True)
     cellColoring.startImage(painter, imageid)
     wallColoring.startImage(painter, imageid)
     for ed in extraDrawing:
         ed.startImage(painter, imageid)
     if self.result_type == "Growth":
         cells = result.cells[imageid]
         walls = result.walls[imageid]
     else:
         cells = img_data.cells
         walls = set()
         for cid in img_data.cells:
             pts = [pt for pt in data.cells[cid] if pt in img_data]
             if len(pts) > 1:
                 for i in range(len(pts)):
                     walls.add(data.wallId(pts[i - 1], pts[i]))
     # Now, draw the cells and the ellipsis
     for cid in cells:
         painter.setPen(Qt.NoPen)
         color = cellColoring(imageid, cid)
         painter.setBrush(color)
         pts = data.cellAtTime(cid, img_data.index)
         if pts:
             pts.append(pts[0])
             ppts = []
             for p1, p2 in zip(pts[:-1], pts[1:]):
                 ppts.append(img_data[p1])
                 ppts.extend(img_data.walls[p1, p2])
             ppts.append(ppts[0])
             poly = QPolygonF(ppts)
             painter.drawPolygon(poly)
     # And draw the walls
     wallThickness = self.wallThickness * min_scale
     for wid in walls:
         color = wallColoring(imageid, wid)
         if color.alpha() > 0:
             pen = QPen(color)
             pen.setWidthF(wallThickness)
             painter.setPen(pen)
             pts = [img_data[wid[0]]
                    ] + img_data.walls[wid[0], wid[1]] + [img_data[wid[1]]]
             #painter.drawLine(img_data[wid[0]], img_data[wid[1]])
             painter.drawPolyline(*pts)
     # Then, draw the points
     pointSize = self.pointSize * min_scale
     pointLineColor = self.pointLineColor
     pointLineThickness = self.pointLineThickness * min_scale
     log_debug("pointSize = %g" % pointSize)
     for pid in img_data:
         color = pointColoring(imageid, pid)
         if color.alpha() > 0:
             pen = QPen(pointLineColor)
             pen.setWidthF(pointLineThickness)
             brush = QBrush(color)
             painter.setPen(pen)
             painter.setBrush(brush)
             pos = img_data[pid]
             rect = QRectF(pos.x() - pointSize,
                           pos.y() - pointSize, 2 * pointSize,
                           2 * pointSize)
             painter.drawEllipse(rect)
     if ellipsisDraw.plot:
         for cid in cells:
             pts = data.cellAtTime(cid, img_data.index)
             if pts:
                 pts.append(pts[0])
                 ppts = []
                 for p1, p2 in zip(pts[:-1], pts[1:]):
                     ppts.append(img_data[p1])
                     ppts.extend(img_data.walls[p1, p2])
                 ppts.append(ppts[0])
                 #poly = QPolygonF(ppts)
                 #painter.drawPolygon(poly)
                 ellipsisDraw(painter, imageid, cid, ppts, min_scale)
     # At last, draw the extra data
     for ed in extraDrawing:
         ed(painter, imageid)
     tr = painter.worldTransform()
     painter.restore()
     pic_w = wallColoring.finalizeImage(painter, imageid, tr, self.crop)
     pic_c = cellColoring.finalizeImage(painter, imageid, tr, self.crop)
     for ed in extraDrawing:
         ed.finalizeImage(painter, imageid, tr, self.crop)
     painter.end()
     return pix, pic_w, pic_c