Commit d91bcf42 authored by Josef Brandt's avatar Josef Brandt

Instant Particle Detection in DetectWindow

Plus: Fix in loading dataset
parent 51f6d7cb
......@@ -48,6 +48,7 @@ def loadData(fname):
legacyConversion(retds)
elif retds.zvalimg=="saved":
retds.loadZvalImg()
retds.particleContainer.datasetParent = retds #TODO: This is mainly a workaround to update the ref in particleContainer. It probably should be handled differently anyways...
return retds
def saveData(dataset, fname):
......
......@@ -384,6 +384,14 @@ class ParticleDetectionView(QtWidgets.QWidget):
grid.addWidget(QtWidgets.QLabel("Click+Alt removes seeds near cursor"), i+4, 0, 1, 2, QtCore.Qt.AlignLeft)
group.setLayout(grid)
vbox.addWidget(group)
self.updateSeedsInSampleViewBtn = QtWidgets.QPushButton("Update Seedpoints in fullimage view", self)
self.updateSeedsInSampleViewBtn.released.connect(self.updateSeedsInSampleview)
self.hideSeedsInSampleViewBtn = QtWidgets.QPushButton("Hide Seedpoints in fullimage view", self)
self.hideSeedsInSampleViewBtn.released.connect(self.removeSeedsInSampleView)
vbox.addWidget(self.updateSeedsInSampleViewBtn)
vbox.addWidget(self.hideSeedsInSampleViewBtn)
self.slider = QtWidgets.QSlider(self)
self.slider.setRange(0,100)
......@@ -514,6 +522,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
if self.drag:
self.lastcenter = self.lastmove
self.drag = False
self.detectShow(None)
def setDataSet(self, ds):
self.dataset = ds
......@@ -690,4 +699,10 @@ class ParticleDetectionView(QtWidgets.QWidget):
print('invalid contour in detection, skipping partile. Contour is:', contour)
continue
return particlestats
\ No newline at end of file
return particlestats
def updateSeedsInSampleview(self):
self.view.updateSeedPointMarkers()
def removeSeedsInSampleView(self):
self.view.removeSeedPointMarkers()
\ No newline at end of file
......@@ -30,7 +30,7 @@ from .ramanscanui import RamanScanUI
from .detectionview import ParticleDetectionView
from .analysis.analysisview import ParticleAnalysis
from .zeissimporter import ZeissImporter
from .viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContour, ParticleInfo
from .viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContour, ParticleInfo, SeedPoint
from .helperfunctions import polygoncovering, cv2imread_fix
from .analysis.colorlegend import getColorFromNameWithSeed
from .analysis.particleEditor import ParticleEditor
......@@ -87,6 +87,7 @@ class SampleView(QtWidgets.QGraphicsView):
self.isblocked = False
self.contourItems = []
self.selectedParticleIndices = []
self.seedPoints = []
self.particlePainter = None
self.detectionwidget = None
......@@ -193,9 +194,9 @@ class SampleView(QtWidgets.QGraphicsView):
assert mode in ["OpticalScan", "ParticleDetection", "RamanScan", "ParticleAnalysis"]
print("switching to mode:", mode, flush=True)
self.oscanwidget.setVisible(False)
if self.detectionwidget is not None:
self.detectionwidget.close()
self.detectionwidget = None
# if self.detectionwidget is not None:
# self.detectionwidget.close()
# self.detectionwidget = None
self.ramanwidget.setVisible(False)
self.mode = mode
self.loadPixmap(self.microscopeMode)
......@@ -205,16 +206,20 @@ class SampleView(QtWidgets.QGraphicsView):
elif mode == "ParticleDetection":
if self.detectionwidget is None:
print('creating new detect window')
self.detectionwidget = ParticleDetectionView(self.imgdata, self.dataset, self)
self.detectionwidget.imageUpdate.connect(self.detectionUpdate)
self.detectionwidget.detectionFinished.connect(self.activateMaxMode)
self.updateSeedPointMarkers()
self.detectionwidget.show()
elif mode == "RamanScan":
self.removeSeedPointMarkers()
self.ramanwidget.resetDataset(self.dataset)
self.ramanwidget.setVisible(True)
elif mode == "ParticleAnalysis":
self.removeSeedPointMarkers()
if self.ramanwidget.isVisible():
self.ramanwidget.setVisible(False)
if self.analysiswidget is None:
......@@ -797,5 +802,24 @@ class SampleView(QtWidgets.QGraphicsView):
item.setHighLight(False)
def updateSeedPointMarkers(self):
self.removeSeedPointMarkers()
for addPoint in self.dataset.seedpoints:
x, y, radius = addPoint
newPoint = SeedPoint(radius, 'add', pos=(x, y))
self.seedPoints.append(newPoint)
self.scene().addItem(newPoint)
for removePoint in self.dataset.seeddeletepoints:
x, y, radius = removePoint
newPoint = SeedPoint(radius, 'remove', pos=(x, y))
self.seedPoints.append(newPoint)
self.scene().addItem(newPoint)
def removeSeedPointMarkers(self):
for seedpoint in self.seedPoints:
self.scene().removeItem(seedpoint)
self.seedPoints = []
\ No newline at end of file
......@@ -76,7 +76,7 @@ class Segmentation(object):
'enableMaxArea': False,
'maxparticlearea': 100000,
'minparticledistance': 20,
'closeBackground': True,
'closeBackground': False,
'measurefrac': 1,
'compactness': 0.0,
'seedRad': 3}
......
......@@ -106,20 +106,49 @@ class FitPosIndicator(QtWidgets.QGraphicsItem):
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)
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 SeedPoint(QtWidgets.QGraphicsItem):
def __init__(self, radius, seedtype, pos=(0,0)):
super().__init__()
self.setPos(pos[0], pos[1])
self.seedtype = seedtype
self.radius = radius
def boundingRect(self):
return QtCore.QRectF(-self.radius-1,-self.radius-1,
2*self.radius+2,2*self.radius+2)
def paint(self, painter, option, widget):
if self.seedtype == 'add':
painter.setPen(QtCore.Qt.white)
painter.setBrush(QtCore.Qt.white)
elif self.seedtype == 'remove':
painter.setPen(QtCore.Qt.magenta)
painter.setBrush(QtCore.Qt.magenta)
rect = QtCore.QRectF(-self.radius,-self.radius,
2*self.radius,2*self.radius)
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)):
......
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