# -*- coding: utf-8 -*- """ GEPARD - Gepard-Enabled PARticle Detection Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für Polymerforschung Dresden e. V. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program, see COPYING. If not, see . """ #import numpy as np from PyQt5 import QtCore, QtWidgets, QtGui from analysis.particleeditor import ParticleContextMenu class SegmentationContour(QtWidgets.QGraphicsItem): def __init__(self, parent, contourData, pos=(0,0)): super().__init__() self.parent = parent self.setZValue(1) self.setPos(pos[0], pos[1]) self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable) self.setAcceptedMouseButtons(QtCore.Qt.AllButtons) self.brect = QtCore.QRectF(0,0,1,1) self.contourData = contourData self.polygon = None self.hidden = False self.color = QtGui.QColor(50, 255, 50, 200) self.particleIndex = None self.isSelected = False self.getBrectAndPolygon() def getBrectAndPolygon(self): polygon = QtGui.QPolygonF() x0 = self.contourData[:,0,0].min() x1 = self.contourData[:,0,0].max() y0 = self.contourData[:,0,1].min() y1 = self.contourData[:,0,1].max() for point in self.contourData: polygon.append(QtCore.QPointF(point[0,0], point[0,1])) self.brect.setCoords(x0, y0, x1, y1) self.polygon = polygon def boundingRect(self): return self.brect def setIndex(self, index): self.particleIndex = index def setColor(self, color): self.color = color def setHidden(self, hidden): self.hidden = hidden def paint(self, painter, option, widget): if self.polygon is not None and not self.hidden: painter.setPen(QtCore.Qt.green) if self.isSelected: alpha = 200 if not self.hidden: painter.setBrush(QtGui.QColor(200, 200, 200, alpha)) painter.setPen(QtCore.Qt.white) else: painter.setPen(QtGui.QColor(int(self.color.red()*0.7), int(self.color.green()*0.7), int(self.color.blue()*0.7), self.color.alpha())) if not self.hidden: painter.setBrush(self.color) painter.drawPolygon(self.polygon) def contextMenuEvent(self, event): if self.isSelected: self.contextMenu = ParticleContextMenu(self.parent) self.parent.particleEditor.connectToSignals(self.contextMenu) self.contextMenu.executeAtScreenPos(event.screenPos()) class FitPosIndicator(QtWidgets.QGraphicsItem): indicatorSize = 80 def __init__(self, number, pos=(0,0)): super().__init__() self.setPos(pos[0], pos[1]) self.number = number self.setAcceptedMouseButtons(QtCore.Qt.NoButton) def boundingRect(self): return QtCore.QRectF(-self.indicatorSize-1,-self.indicatorSize-1, 2*self.indicatorSize+2,2*self.indicatorSize+2) def paint(self, painter, option, widget): painter.setPen(QtCore.Qt.green) painter.setBrush(QtGui.QColor(250,250,0,150)) rect = QtCore.QRectF(-self.indicatorSize,-self.indicatorSize, 2*self.indicatorSize,2*self.indicatorSize) font = painter.font() font.setPointSize(40) painter.setFont(font) painter.drawText(rect, QtCore.Qt.AlignCenter, str(self.number)) painter.drawEllipse(rect) def shape(self): path = QtGui.QPainterPath() path.addEllipse(self.boundingRect()) return path class RamanScanIndicator(QtWidgets.QGraphicsItem): def __init__(self, view, number, radius, pos=(0,0)): super().__init__() # self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable) self.setAcceptedMouseButtons(QtCore.Qt.NoButton) self.setZValue(100) #higher numbers will be in foreground. Shall always be in foreground! self.view = view self.number = number self.radius = radius self.highlight = False self.hidden = False self.setPos(pos[0], pos[1]) def setHighLight(self, highlight): if highlight!=self.highlight: self.highlight = highlight self.update() def boundingRect(self): return QtCore.QRectF(-self.radius-1,-self.radius-1, 2*self.radius+2,2*self.radius+2) def shape(self): path = QtGui.QPainterPath() path.addEllipse(self.boundingRect()) return path def paint(self, painter, option, widget): if not self.hidden: if self.highlight: painter.setPen(QtCore.Qt.red) painter.setBrush(QtGui.QColor(100,250,100,150)) else: painter.setPen(QtCore.Qt.green) painter.setBrush(QtGui.QColor(50,50,250,150)) rect = QtCore.QRectF(-self.radius, -self.radius, 2*self.radius, 2*self.radius) painter.drawEllipse(rect) font = painter.font() font.setPointSize(10) painter.setFont(font) painter.drawText(rect, QtCore.Qt.AlignCenter, str(self.number)) # def mousePressEvent(self, event): # p = event.pos() # x, y = p.x(), p.y() # r = np.sqrt(x**2+y**2) # if r