Esempio n. 1
0
    def setWedgeGizmo(self, neighbor_virtual_helix: int,
                            neighbor_virtual_helix_item: GridVirtualHelixItemT):
        """Adds a WedgeGizmo to oriented toward the specified neighbor vhi.

        Called by NucleicAcidPartItem _refreshVirtualHelixItemGizmos, in between
        with beginAddWedgeGizmos and endAddWedgeGizmos.

        Args:
            neighbor_virtual_helix: the id_num of neighboring virtual helix
            neighbor_virtual_helix_item:
            the neighboring virtual helix item
        """
        wg_dict = self.wedge_gizmos
        nvhi = neighbor_virtual_helix_item

        nvhi_name = nvhi.getProperty('name')
        pos = self.scenePos()
        line = QLineF(pos, nvhi.scenePos())
        line.translate(_RADIUS, _RADIUS)
        if line.length() > (_RADIUS*1.99):
            color = '#5a8bff'
        else:
            color = '#cc0000'
            nvhi_name = nvhi_name + '*'  # mark as invalid
        line.setLength(_RADIUS)
        if neighbor_virtual_helix in wg_dict:
            wedge_item = wg_dict[neighbor_virtual_helix]
        else:
            wedge_item = WedgeGizmo(_RADIUS, WEDGE_RECT, self)
            wg_dict[neighbor_virtual_helix] = wedge_item
        wedge_item.showWedge(line.angle(), color, outline_only=False)
        self._added_wedge_gizmos.add(neighbor_virtual_helix)
Esempio n. 2
0
    def setWedgeGizmo(self, neighbor_virtual_helix,
                      neighbor_virtual_helix_item):
        """Adds a WedgeGizmo to oriented toward the specified neighbor vhi.

        Called by NucleicAcidPartItem _refreshVirtualHelixItemGizmos, in between
        with beginAddWedgeGizmos and endAddWedgeGizmos.

        Args:
            neighbor_virtual_helix (int): the id_num of neighboring virtual helix
            neighbor_virtual_helix_item (cadnano.views.sliceview.virtualhelixitem.VirtualHelixItem):
            the neighboring virtual helix item
        """
        wg_dict = self.wedge_gizmos
        nvhi = neighbor_virtual_helix_item

        pos = self.scenePos()
        line = QLineF(pos, nvhi.scenePos())
        line.translate(_RADIUS, _RADIUS)
        if line.length() > (_RADIUS * 1.99):
            color = '#5a8bff'
        else:
            color = '#cc0000'
        line.setLength(_RADIUS)
        if neighbor_virtual_helix in wg_dict:
            wedge_item = wg_dict[neighbor_virtual_helix]
        else:
            wedge_item = WedgeGizmo(_RADIUS, WEDGE_RECT, self)
            wg_dict[neighbor_virtual_helix] = wedge_item
        wedge_item.showWedge(line.angle(), color, outline_only=False)
        self._added_wedge_gizmos.add(neighbor_virtual_helix)
    def setWedgeGizmo(self, neighbor_virtual_helix: int,
                      neighbor_virtual_helix_item: SliceVirtualHelixItemT):
        """Adds a :class:`WedgeGizmo` to oriented toward the specified neighbor vhi.

        Called by :meth:`SliceNucleicAcidPartItem._refreshVirtualHelixItemGizmos`,
        before :meth:`setWedgeGizmo` and :meth:`endAddWedgeGizmos`.

        Args:
            neighbor_virtual_helix: the id_num of neighboring virtual helix
            neighbor_virtual_helix_item: the neighboring virtual helix item
        """
        wg_dict = self.wedge_gizmos
        nvhi = neighbor_virtual_helix_item
        pos = self.scenePos()
        line = QLineF(pos, nvhi.scenePos())
        line.translate(_RADIUS, _RADIUS)
        if line.length() > (_RADIUS * 1.99):
            color = '#5a8bff'
        else:
            color = '#cc0000'
        line.setLength(_RADIUS)
        if neighbor_virtual_helix in wg_dict:
            wedge_item = wg_dict[neighbor_virtual_helix]
        else:
            wedge_item = WedgeGizmo(_RADIUS, WEDGE_RECT, self)
            wg_dict[neighbor_virtual_helix] = wedge_item
        wedge_item.showWedge(line.angle(), color, outline_only=False)
        self._added_wedge_gizmos.add(neighbor_virtual_helix)
Esempio n. 4
0
    def paint(self, painter, option, widget=None):
        if self.start_item.collidesWithItem(self.end_item):
            return

        start_item = self.start_item
        end_item = self.end_item
        color = self.color
        pen = self.pen()
        pen.setColor(color)
        arrow_size = 10.0
        painter.setPen(pen)
        painter.setBrush(color)

        center_line = QLineF(start_item.pos(), end_item.pos())
        end_polygon = end_item.polygon
        p1 = end_polygon.first() + end_item.pos()

        intersect_point = QPointF()
        for i in end_polygon:
            p2 = i + end_item.pos()
            poly_line = QLineF(p1, p2)
            intersect_type = poly_line.intersect(center_line, intersect_point)
            if intersect_type == QLineF.BoundedIntersection:
                break
            p1 = p2

        self.setLine(QLineF(intersect_point, start_item.pos()))
        line = self.line()

        angle = math.acos(line.dx() / max(1, line.length()))
        if line.dy() >= 0:
            angle = (math.pi * 2.0) - angle

        arrow_p1 = (line.p1() + QPointF(
            math.sin(angle + math.pi / 3.0) * arrow_size,
            math.cos(angle + math.pi / 3.0) * arrow_size,
        ))

        arrow_p2 = (line.p1() + QPointF(
            math.sin(angle + math.pi - math.pi / 3.0) * arrow_size,
            math.cos(angle + math.pi - math.pi / 3.0) * arrow_size,
        ))

        self.arrow_head.clear()
        for point in [line.p1(), arrow_p1, arrow_p2]:
            self.arrow_head.append(point)

        painter.drawLine(line)
        painter.drawPolygon(self.arrow_head)

        if self.isSelected():
            painter.setPen(QPen(color, 1, Qt.DashLine))
            line = QLineF(line)
            line.translate(0, 4.0)
            painter.drawLine(line)
            line.translate(0, -8.0)
            painter.drawLine(line)
Esempio n. 5
0
    def paint(self, painter, option, widget=None):
        if self.myStartItem.collidesWithItem(self.myEndItem):
            return

        myStartItem = self.myStartItem
        myEndItem = self.myEndItem
        myColor = self.myColor
        myPen = self.pen()
        myPen.setColor(self.myColor)
        arrowSize = 20.0
        painter.setPen(myPen)
        painter.setBrush(self.myColor)

        centerLine = QLineF(myStartItem.pos(), myEndItem.pos())
        endPolygon = myEndItem.polygon()
        p1 = endPolygon.first() + myEndItem.pos()

        intersectPoint = QPointF()
        for i in endPolygon:
            p2 = i + myEndItem.pos()
            polyLine = QLineF(p1, p2)
            intersectType = polyLine.intersect(centerLine, intersectPoint)
            if intersectType == QLineF.BoundedIntersection:
                break
            p1 = p2

        self.setLine(QLineF(intersectPoint, myStartItem.pos()))
        line = self.line()

        angle = math.acos(line.dx() / line.length())
        if line.dy() >= 0:
            angle = (math.pi * 2.0) - angle

        arrowP1 = line.p1() + QPointF(
            math.sin(angle + math.pi / 3.0) * arrowSize,
            math.cos(angle + math.pi / 3) * arrowSize,
        )
        arrowP2 = line.p1() + QPointF(
            math.sin(angle + math.pi - math.pi / 3.0) * arrowSize,
            math.cos(angle + math.pi - math.pi / 3.0) * arrowSize,
        )

        self.arrowHead.clear()
        for point in [line.p1(), arrowP1, arrowP2]:
            self.arrowHead.append(point)

        painter.drawLine(line)
        painter.drawPolygon(self.arrowHead)
        if self.isSelected():
            painter.setPen(QPen(myColor, 1, Qt.DashLine))
            myLine = QLineF(line)
            myLine.translate(0, 4.0)
            painter.drawLine(myLine)
            myLine.translate(0, -8.0)
            painter.drawLine(myLine)
Esempio n. 6
0
class LineWidget(CoordWidget):
    def __init__(self):
        super(LineWidget, self).__init__()
        self.line1 = QLineF(QPointF(-0.4, -0.2), QPointF(-0.1, 0.3))
        self.line2 = QLineF(QPointF(0.2, 0.1), QPointF(0.4, -0.3))
        self.lastPos = QtCore.QPoint()

        self.intersected = False
        self.crossPoint = None

    def mouseMoveEvent(self, e):
        newPos = e.pos()
        if (self.lastPos - newPos).manhattanLength() < 1:
            self.lastPos = newPos
            return
        if e.buttons() & Qt.LeftButton:
            translation = self.screenToWorld(newPos) - self.screenToWorld(
                self.lastPos)  # QPointF
            self.line2.translate(translation)
            p = lineIntersectTest(self.line1, self.line2)
            if None != p:
                self.crossPoint = p
            else:
                self.crossPoint = None
                self.intersected = False
        super(LineWidget, self).mouseMoveEvent(e)

    def drawInWorld(self, qPainter):
        pen = qPainter.pen()
        pen.setColor(QColor.fromRgb(255, 0, 0))
        qPainter.setPen(pen)
        qPainter.drawLine(self.line1)
        qPainter.drawLine(self.line2)

    def drawInScreen(self, qPainter):
        self.msgCnt = 0
        self.showInfo(qPainter, "Blue point: the intersection point")
        self.showInfo(qPainter,
                      "Green point: the projected point of the the mouse")
        pen = qPainter.pen()
        pen.setWidth(5)
        pen.setColor(QColor.fromRgb(0, 255, 0))
        qPainter.setPen(pen)
        qPainter.drawLine(self.line2)
        projectedPointWorld = pointInLine(self.screenToWorld(self.lastPos),
                                          self.line1)
        qPainter.drawPoint(self.worldToScreen(projectedPointWorld))
        if None != self.crossPoint:
            pen.setColor(QColor.fromRgb(0, 0, 255))
            qPainter.setPen(pen)
            qPainter.drawPoint(self.worldToScreen(self.crossPoint))
            self.intersected = pointInSegment(self.crossPoint, self.line1)
            if self.intersected:
                self.showInfo(qPainter, "intersected ")
Esempio n. 7
0
    def paint(self, painter, option, widget=None):
        if self.my_start_item.collidesWithItem(self.my_end_item):
            return

        my_start_item = self.my_start_item
        my_end_item = self.my_end_item
        my_color = self.my_color
        my_pen = self.pen()
        my_pen.setColor(self.my_color)
        arrow_size = 20.0
        painter.setPen(my_pen)
        painter.setBrush(my_color)

        center_line = QLineF(my_start_item.pos(), my_end_item.pos())
        end_polygon = my_end_item.polygon

        p1 = end_polygon.first() + my_end_item.pos()

        intersect_point = QPointF()
        for i in end_polygon:
            p2 = i + my_end_item.pos()
            poly_line = QLineF(p1, p2)
            intersect_type = poly_line.intersect(center_line, intersect_point)
            if intersect_type == QLineF.BoundedIntersection:
                break
            p1 = p2

        self.setLine(QLineF(intersect_point, my_start_item.pos()))
        line = self.line()

        angle = math.acos(line.dx() / line.length())

        if line.dy() >= 0:
            angle = (math.pi * 2) - angle

        arrow_p1 = line.p1() + QPointF(math.sin(angle + math.pi / 3.0) * arrow_size,
                                       math.cos(angle + math.pi / 3) * arrow_size)
        arrow_p2 = line.p1() + QPointF(math.sin(angle + math.pi - math.pi / 3.0) * arrow_size,
                                       math.cos(angle + math.pi - math.pi / 3.0) * arrow_size)

        self.arrowHead.clear()
        for point in [line.p1(), arrow_p1, arrow_p2]:
            self.arrowHead.append(point)

        painter.drawLine(line)
        painter.drawPolygon(self.arrowHead)
        if self.isSelected():
            painter.setPen(QPen(my_color, 1, Qt.DashLine))
            my_line = QLineF(line)
            my_line.translate(0, 4.0)
            painter.drawLine(my_line)
            my_line.translate(0, -8.0)
            painter.drawLine(my_line)
Esempio n. 8
0
def shiftLineOnObject(imageModel, edgeModel):
    """
    Shift edge onto object.
    Imagemodel: Working Image
    EdgeModel: Current Edge that is being shift
    """
    if edgeModel.getAttribute("edge_clasification") != EdgeAttributes.EDGE_TYPE_DD1:
        log.info("Edge Object {} has a edge classification of {} will not be shfited:".format(edgeModel.getID(), edgeModel.getAttribute("edge_clasification")))
        return -1

    if edgeModel.getAttribute("object_direction") == EdgeAttributes.OBJECT_CENTERED:
        log.info("Edge Object {} is centered: will not be shifted.".format(edgeModel.getID()))
        return 0

    if edgeModel.getAttribute("points_shifted") == True:
        log.info("Edge Object {} is already shifted.".format(edgeModel.getID()))
        return 0


    gradientBorder = 1
    depthImage = imageModel.getCroppedDepthImage()
    # Get Line Orientation
    startPos = (edgeModel.x1(), edgeModel.y1())
    endPos = (edgeModel.x2(), edgeModel.y2())
    edgeLength = edgeModel.length()
    pointList = edgeModel.getEdgePointCloudIndexes()
    pointCloud = imageModel.getPointCloudFromCrop()


    perpendicularSampleLength = 25
    perpendicularVector = edgeModel.normalVector().unitVector()

    if edgeModel.getAttribute("object_direction") == 2:
        perpendicularVector.setAngle(perpendicularVector.angle() + 180)
    else:
        perpendicularVector.setAngle(perpendicularVector.angle() + 180)
        # perpendicularVector.setP2(Point2D(-1*perpendicularVector.dx(), -1*perpendicularVector.dy()))
    
    perpendicularVector1 = QLineF(0, 0, perpendicularVector.dx() * perpendicularSampleLength, 
        perpendicularVector.dy() * perpendicularSampleLength)


    gradientData = []
    renderGradient = []

    # append start and end Positons to be shifted also
    # pointList.append(startPos)
    # pointList.append(endPos)

    # Obtain a sample values of all pixels on the line and add the array to gradientdata
    initialValues = 5
    for i in  range(len(pointList)):
        point = pointList[i]
        sampleLine = QLineF(perpendicularVector1)             
        sampleLine.translate(point[0] - perpendicularVector.dx()*initialValues, point[1] - perpendicularVector.dy()*initialValues)
        sampleData = sampleLineFromImage(depthImage, sampleLine, perpendicularSampleLength)
        sampleData = fixLineSample(sampleData)

        gradientData.append(sampleData)
    ## Shift values
    newPointList = []
    for index in range(len(gradientData)):
        x, y = pointList[index]
        lineSample = gradientData[index]
        grad = np.diff(lineSample)

        # print("Sample data\n")
        # print(gradientData[index])
        # print("Gradient\n")
        # print(grad)
        # print("\n")
        absoluteGrad = abs(grad)
        absoluteGrad = np.gradient(absoluteGrad)        
        renderGradient.append(np.diff(absoluteGrad)/np.amax(np.diff(absoluteGrad)))

        deltaIndex = np.argmin(absoluteGrad) - initialValues + 3

        # maxDelta = 0
        # deltaIndex = 5
        # thresHold = 200        
        # for i in range(1, len(gradientData[index])):
        #     delta = abs(gradientData[index][i] - gradientData[index][i - 1])
        #     if delta > thresHold and delta > maxDelta:
        #         maxDelta = delta
        #         deltaIndex = i
        if deltaIndex > 0:
            x = int(x + perpendicularVector.dx() * deltaIndex)
            y = int(y + perpendicularVector.dy() * deltaIndex)
        finalIndex = (x, y)
        newPointList.append(finalIndex)

    # edgeModel.setAttribute("old_edgePointList", pointList)
    # pointListSize = len(newPointList) - 2
    edgeModel.setAttribute("perpendicularVector", perpendicularVector)
    edgeModel.setAttribute("perpendicularVectorOffset", initialValues)
    edgeModel.setAttribute("line_shift_gradient", renderGradient)
    edgeModel.setAttribute("oldPointList", pointList)
    edgeModel.setEdgePoint(newPointList)
    edgeModel.setAttribute("points_shifted", True)
Esempio n. 9
0
    def paintEvent(self, event):
        scale = ZOOM_OUT_SCALE if self.out_zoom else 1
        x_offset = WINDOW_WIDTH * (1 -
                                   ZOOM_OUT_SCALE) / 2 if self.out_zoom else 0
        y_offset = WINDOW_HEIGHT * (1 -
                                    ZOOM_OUT_SCALE) / 2 if self.out_zoom else 0
        offset_point = QPoint(x_offset, y_offset)

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        if not self.out_zoom:
            for bullet_line in self.bullet_lines[:-len(self.ships)]:
                if len(bullet_line) > 0:
                    painter.setPen(
                        QPen(QColor(255, 255, 255, 60), 1, Qt.SolidLine))
                    painter.drawPolyline(*bullet_line)
            for bullet_line in self.bullet_lines[-len(self.ships):]:
                if len(bullet_line) > 0:
                    painter.setPen(
                        QPen(QColor(255, 255, 255, 160), 1, Qt.SolidLine))
                    painter.drawPolyline(*bullet_line)

        painter.setBrush(Qt.white)
        painter.setPen(QPen(Qt.white, 5, Qt.SolidLine))

        for planet in self.planets:
            painter.drawEllipse(
                (planet.x - planet.size / 2) * scale + x_offset,
                (planet.y - planet.size / 2) * scale + y_offset,
                planet.size * scale, planet.size * scale)

        painter.setPen(QPen(Qt.white, 1, Qt.SolidLine))
        for ship in self.ships:
            line = QLineF(*ship.get_line_coordinates(scale))
            line.translate(offset_point)
            painter.drawLine(line)

        for i, ship in enumerate(self.ships):
            painter.setBrush(PLAYER_COLORS[i])
            painter.setPen(QPen(PLAYER_COLORS[i], 5, Qt.SolidLine))

            polygon = QPolygon(ship.get_coordinates(scale))
            polygon.translate(offset_point)
            painter.drawPolygon(polygon)

        if self.bullet is not None:
            painter.setPen(QPen(Qt.white, 5, Qt.SolidLine))
            painter.drawPoint(
                QPointF(self.bullet.x, self.bullet.y) * scale + offset_point)

        if self.out_zoom:
            painter.setPen(QPen(QColor(255, 255, 255, 100), 1, Qt.SolidLine))
            painter.setBrush(False)
            painter.drawRect(x_offset, y_offset, WINDOW_WIDTH * ZOOM_OUT_SCALE,
                             WINDOW_HEIGHT * ZOOM_OUT_SCALE)

        if self.bullet_time is not None:
            painter.setPen(QPen(Qt.white, 5, Qt.SolidLine))
            painter.drawText(QPoint(WINDOW_WIDTH - 30, 20),
                             str(self.bullet_time))

        for i, ship in enumerate(self.ships):
            painter.setPen(QPen(PLAYER_COLORS[i], 5, Qt.SolidLine))
            painter.drawText(QPoint(10, 20 + 20 * i), str(ship.points))