Commit 9ae5cb90 authored by JosefBrandt's avatar JosefBrandt

First Step for ParticlePainter

parent c5d0ae61
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
GEPARD - Gepard-Enabled PARticle Detection
Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für
Polymerforschung Dresden e. V. <bittrich-lars@ipfdd.de>
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 <https://www.gnu.org/licenses/>.
"""
from PyQt5 import QtWidgets, QtCore, QtGui
import numpy as np
class ParticlePainter(QtWidgets.QGraphicsItem):
def __init__(self, particleContour, pos=(0,0)):
super().__init__()
self.setZValue(1)
self.setPos(pos[0], pos[1])
self.polygon = None
self.particleContour = particleContour
self.mousePos = None
self.minRadius = 1
self.maxRadius = 500
self.radius = 20
self.brect = QtCore.QRectF(0,0,1,1)
# self.getBrectAndPolygon()
# def getBrectAndPolygon(self):
# polygon = QtGui.QPolygonF()
# x0 = self.particleContour[:,0,0].min()
# x1 = self.particleContour[:,0,0].max()
# y0 = self.particleContour[:,0,1].min()
# y1 = self.particleContour[:,0,1].max()
# for point in self.particleContour:
# 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 mouseMoveEvent(self, event):
p = event.pos()
self.brect.setCoords(p.x()-self.radius/2, p.y()-self.radius/2, p.x()+self.radius/2, p.y()+self.radius/2)
self.mousePos = p
def wheelEvent(self, event):
if event.angleDelta().y() > 0:
self.radius = np.clip(self.radius+1, self.minRadius, self.maxRadius)
else:
self.radius = np.clip(self.radius-1, self.minRadius, self.maxRadius)
def paint(self, painter, option, widget):
if self.mousePos is not None:
p = [self.mousePos.x(), self.mousePos.y(), self.radius]
painter.drawEllipse(p[0]-p[2], p[1]-p[2], 2*p[2], 2*p[2])
# if self.polygon is not None:
# painter.setPen(QtCore.Qt.white)
# painter.setBrush(QtGui.QColor(200, 200, 200, 128))
# painter.drawPolygon(self.polygon)
\ No newline at end of file
......@@ -208,10 +208,6 @@ class ImageView(QtWidgets.QLabel):
self.overlay = None
def updateSeedPoints(self, seedpoints=[], seeddeletepoints=[]):
# if len(seedpoints) > 0 and len(self.seedpoints) > 0:
# print(seedpoints[0, :], self.seedpoints[0, :])
# else:
# print('else...', len(seedpoints), len(self.seedpoints))
self.seedpoints = seedpoints
self.seeddeletepoints = seeddeletepoints
......
......@@ -38,6 +38,9 @@ from helperfunctions import polygoncovering, cv2imread_fix
from ramancom.configRaman import RamanConfigWin
from analysis.particleeditor import ParticleEditor
from analysis.particlePainter import ParticlePainter
class SampleView(QtWidgets.QGraphicsView):
ScalingChanged = QtCore.pyqtSignal(float)
......@@ -98,6 +101,10 @@ class SampleView(QtWidgets.QGraphicsView):
self.darkenPixmap = False
self.microscopeMode = None
self.painter = ParticlePainter([])
self.scene().addItem(self.painter)
def takeScreenshot(self):
#TODO:
#LIMIT SCREENSHOT TO ACTUAL VIEWSIZE OF LOADED IMAGE...
......
......@@ -86,141 +86,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
self.parent.particleEditor.connectToSignals(self.contextMenu)
self.contextMenu.executeAtScreenPos(event.screenPos())
#class SegmentationContours(QtWidgets.QGraphicsItem):
# def __init__(self, parent, contours=[], pos=(0,0)):
# super().__init__()
# self.parent = parent
# 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.resetContours(contours)
# self.colorList = []
# self.selectedContours = []
#
# def boundingRect(self):
# return self.brect
#
# def resetContours(self, contours=[]):
# cp = []
# x0 = None
# for c in contours:
# polygon = QtGui.QPolygonF()
# if x0 is None:
# x0 = c[:,0,0].min()
# x1 = c[:,0,0].max()
# y0 = c[:,0,1].min()
# y1 = c[:,0,1].max()
# else:
# x0 = min(x0, c[:,0,0].min())
# x1 = max(x1, c[:,0,0].max())
# y0 = min(y0, c[:,0,1].min())
# y1 = max(y1, c[:,0,1].max())
# for ci in c:
# polygon.append(QtCore.QPointF(ci[0,0],ci[0,1]))
# cp.append(polygon)
# if x0 is None:
# self.brect = QtCore.QRectF(0,0,1,1)
# else:
# self.brect.setCoords(x0,y0,x1,y1)
# self.contours = cp
# self.update()
#
# def paint(self, painter, option, widget):
# painter.setPen(QtCore.Qt.green)
# lenColorList = len(self.colorList)
# if self.parent.analysiswidget is not None:
# nonePaintMode = self.parent.analysiswidget.noOverlayAct.isChecked()
# else:
# nonePaintMode = False
# for index, c in enumerate(self.contours):
# if index not in self.selectedContours:
# if lenColorList > 0:
# color = self.colorList[index]
# painter.setPen(QtGui.QColor(int(color.red()*0.7), int(color.green()*0.7), int(color.blue()*0.7), color.alpha()))
# else:
# color = QtCore.Qt.green
# painter.setPen(color)
# if not nonePaintMode:
# painter.setBrush(color)
# painter.drawPolygon(c)
# else:
# if lenColorList > 0:
# alpha = self.colorList[index].alpha()
# else:
# alpha = 255
# if not nonePaintMode:
# painter.setBrush(QtGui.QColor(200, 200, 200, alpha))
# painter.setPen(QtCore.Qt.white)
# painter.drawPolygon(c)
#
# def mousePressEvent(self, event):
# if event.button()==QtCore.Qt.LeftButton:
# p = event.pos()
# p = QtCore.QPointF(p.x(), p.y())
# for index, cnt in enumerate(self.contours):
# if cnt.containsPoint(p, QtCore.Qt.OddEvenFill):
#
# if event.modifiers()==QtCore.Qt.ShiftModifier:
# if index not in self.selectedContours:
# self.selectedContours.append(index)
# else:
# self.selectedContours.remove(index)
# else:
# self.selectedContours = [index]
#
# self.parent.selectContour(index, centerOn=False)
#
# self.update()
# return
# self.selectedContours = [] #reset selection, if nothing was hit...
# self.update()
#
# def contextMenuEvent(self, event):
# contextMenu = QtWidgets.QMenu("Particle options")
#
# combineMenu = QtWidgets.QMenu("Combine Particles into")
#
# combineActs = []
# assignments = []
# for index in self.selectedContours:
# partIndex = index
# assignments.append(self.parent.dataset.particleContainer.particles[partIndex].getParticleAssignment()) #TODO: Entangle...
# assignments.append("other")
#
# for assignment in np.unique(np.array(assignments)):
# combineActs.append(combineMenu.addAction(assignment))
#
# reassignActs = []
# reassignMenu = QtWidgets.QMenu("Reassign particle(s) into")
# for polymer in self.parent.analysiswidget.datastats.getUniquePolymers():
# reassignActs.append(reassignMenu.addAction(polymer))
# reassignActs.append(reassignMenu.addAction("other"))
#
# contextMenu.addMenu(combineMenu)
# contextMenu.addMenu(reassignMenu)
# deleteAct = contextMenu.addAction("Delete Particle(s)")
#
# numParticles = len(self.selectedContours)
# if numParticles == 0:
# reassignMenu.setDisabled(True)
# combineMenu.setDisabled(True)
# deleteAct.setDisabled(True)
# elif numParticles == 1:
# combineMenu.setDisabled(True)
#
# action = contextMenu.exec_(event.screenPos())
#
# if action == deleteAct:
# print('deleting')
# elif action in combineActs:
# newAssignment = action.text()
# self.parent.analysiswidget.editor.combineParticles(self.selectedContours, newAssignment)
#
# elif action in reassignActs:
# newAssignment = action.text()
# self.parent.analysiswidget.editor.reassignParticles(self.selectedContours, newAssignment)
#
class FitPosIndicator(QtWidgets.QGraphicsItem):
indicatorSize = 80
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment