Commit c90f7b26 authored by JosefBrandt's avatar JosefBrandt

Several Bugfixes

parent 2026524b
...@@ -113,7 +113,7 @@ class SpectraPlot(QtWidgets.QGroupBox): ...@@ -113,7 +113,7 @@ class SpectraPlot(QtWidgets.QGroupBox):
layout = QtWidgets.QHBoxLayout() layout = QtWidgets.QHBoxLayout()
self.canvas = FigureCanvas(Figure()) self.canvas = FigureCanvas(Figure())
self.spec_axis = self.canvas.figure.subplots() self.spec_axis = self.canvas.figure.subplots()
self.reference_ax = self.spec_axis.twinx() self.reference_axis = self.spec_axis.twinx()
self.canvas.figure.subplots_adjust(left=0.1, top=0.93, bottom=0.15, right=0.9) self.canvas.figure.subplots_adjust(left=0.1, top=0.93, bottom=0.15, right=0.9)
specNavigation = NavigationToolbar(self.canvas, self) specNavigation = NavigationToolbar(self.canvas, self)
specNavigation.setOrientation(QtCore.Qt.Vertical) specNavigation.setOrientation(QtCore.Qt.Vertical)
......
...@@ -60,12 +60,24 @@ def getParticleStatsWithPixelScale(cnt, fullimage, dataset): ...@@ -60,12 +60,24 @@ def getParticleStatsWithPixelScale(cnt, fullimage, dataset):
newStats.height = getParticleHeight(cnt, dataset) newStats.height = getParticleHeight(cnt, dataset)
newStats.shape = getParticleShape(cnt, newStats.height) newStats.shape = getParticleShape(cnt, newStats.height)
if newStats.shape == 'fibre':
newStats.longSize, newStats.shortSize = getFibreDimension(cnt)
newStats.longSize *= pixelscale
newStats.shortSize *= pixelscale
partImg = getParticleImageFromFullimage(cnt, fullimage) partImg = getParticleImageFromFullimage(cnt, fullimage)
newStats.color = getParticleColor(partImg) newStats.color = getParticleColor(partImg)
return newStats return newStats
def getFibreDimension(contour):
longSize = cv2.arcLength(contour, True)/2
img = contoursToImg([contour])[0]
dist = cv2.distanceTransform(img, cv2.DIST_L2, 3)
maxThickness = np.max(dist)*2
return longSize, maxThickness
def getParticleColor(imgRGB, colorClassifier=None): def getParticleColor(imgRGB, colorClassifier=None):
img = cv2.cvtColor(imgRGB, cv2.COLOR_RGB2HSV_FULL) img = cv2.cvtColor(imgRGB, cv2.COLOR_RGB2HSV_FULL)
meanHSV = cv2.mean(img) meanHSV = cv2.mean(img)
......
...@@ -171,7 +171,7 @@ class ParticleEditor(QtCore.QObject): ...@@ -171,7 +171,7 @@ class ParticleEditor(QtCore.QObject):
'Particle contours are not connected.\nThat is currently not supported!') 'Particle contours are not connected.\nThat is currently not supported!')
return return
self.mergeParticlesInParticleContainerAndSampleView(contourIndices,newContour, newAssignment) self.mergeParticlesInParticleContainerAndSampleView(contourIndices, newContour, newAssignment)
@QtCore.pyqtSlot(list, str) @QtCore.pyqtSlot(list, str)
def reassignParticles(self, contourindices, newAssignment): def reassignParticles(self, contourindices, newAssignment):
...@@ -180,12 +180,14 @@ class ParticleEditor(QtCore.QObject): ...@@ -180,12 +180,14 @@ class ParticleEditor(QtCore.QObject):
for partIndex in contourindices: for partIndex in contourindices:
self.particleContainer.reassignParticleToAssignment(partIndex, newAssignment) self.particleContainer.reassignParticleToAssignment(partIndex, newAssignment)
self.viewparent.updateParticleInfoBox(partIndex)
self.particleAssignmentChanged.emit() self.particleAssignmentChanged.emit()
@QtCore.pyqtSlot(list, str) @QtCore.pyqtSlot(list, str)
def paintParticles(self, contourIndices, newAssignment): def paintParticles(self, contourIndices, newAssignment):
print(f'painting indices {contourIndices} into {newAssignment}') print(f'painting indices {contourIndices} into {newAssignment}')
self.createSafetyBackup() self.createSafetyBackup()
self.viewparent.removeParticleInfoBox()
self.storedIndices = contourIndices self.storedIndices = contourIndices
self.storedAssignmend = newAssignment self.storedAssignmend = newAssignment
...@@ -208,6 +210,7 @@ class ParticleEditor(QtCore.QObject): ...@@ -208,6 +210,7 @@ class ParticleEditor(QtCore.QObject):
except NotConnectedContoursError: except NotConnectedContoursError:
QtWidgets.QMessageBox.critical(self.viewparent, 'ERROR!', QtWidgets.QMessageBox.critical(self.viewparent, 'ERROR!',
'Particle contours are not connected.\nThat is currently not supported!') 'Particle contours are not connected.\nThat is currently not supported!')
self.viewparent.updateParticleInfoBox(self.storedIndices[-1])
self.storedIndices = [] self.storedIndices = []
self.storedAssignmend = None self.storedAssignmend = None
self.destroyParticlePainter() self.destroyParticlePainter()
...@@ -238,6 +241,7 @@ class ParticleEditor(QtCore.QObject): ...@@ -238,6 +241,7 @@ class ParticleEditor(QtCore.QObject):
self.viewparent.resetContourIndices() self.viewparent.resetContourIndices()
self.particleContainer.resetParticleIndices() self.particleContainer.resetParticleIndices()
self.viewparent.updateParticleInfoBox(self.particleContainer.getNumberOfParticles()-1)
self.particleAssignmentChanged.emit() self.particleAssignmentChanged.emit()
@QtCore.pyqtSlot(list, str) @QtCore.pyqtSlot(list, str)
...@@ -245,12 +249,14 @@ class ParticleEditor(QtCore.QObject): ...@@ -245,12 +249,14 @@ class ParticleEditor(QtCore.QObject):
print(f'changing color of particles {contourIndices} into {newColor}') print(f'changing color of particles {contourIndices} into {newColor}')
for partIndex in contourIndices: for partIndex in contourIndices:
self.particleContainer.changeParticleColor(partIndex, newColor) self.particleContainer.changeParticleColor(partIndex, newColor)
self.viewparent.updateParticleInfoBox(partIndex)
@QtCore.pyqtSlot(list, str) @QtCore.pyqtSlot(list, str)
def changeParticleShapes(self, contourIndices, newShape): def changeParticleShapes(self, contourIndices, newShape):
print(f'changing shape of particles {contourIndices} into {newShape}') print(f'changing shape of particles {contourIndices} into {newShape}')
for partIndex in contourIndices: for partIndex in contourIndices:
self.particleContainer.changeParticleShape(partIndex, newShape) self.particleContainer.changeParticleShape(partIndex, newShape)
self.viewparent.updateParticleInfoBox(partIndex)
@QtCore.pyqtSlot(list) @QtCore.pyqtSlot(list)
def deleteParticles(self, contourIndices): def deleteParticles(self, contourIndices):
......
...@@ -352,8 +352,8 @@ if __name__ == '__main__': ...@@ -352,8 +352,8 @@ if __name__ == '__main__':
logname = os.path.join(logpath, 'logfile.txt') logname = os.path.join(logpath, 'logfile.txt')
fp = open(logname, "a") fp = open(logname, "a")
# sys.stderr = fp sys.stderr = fp
# sys.stdout = fp sys.stdout = fp
print("starting GEPARD at: " + strftime("%d %b %Y %H:%M:%S", localtime()), flush=True) print("starting GEPARD at: " + strftime("%d %b %Y %H:%M:%S", localtime()), flush=True)
gepard = GEPARDMainWindow(logpath) gepard = GEPARDMainWindow(logpath)
......
...@@ -191,6 +191,11 @@ def updateParticleStats(dset): ...@@ -191,6 +191,11 @@ def updateParticleStats(dset):
except InvalidParticleError: except InvalidParticleError:
markForDeletion(particle) markForDeletion(particle)
if particle.shape == 'fibre':
particle.longSize, particle.shortSize = pc.getFibreDimension(particle.contour)
particle.longSize *= dset.getPixelScale()
particle.shortSize *= dset.getPixelScale()
print(f'deleting {len(deleteIndices)} particles') print(f'deleting {len(deleteIndices)} particles')
for index in sorted(deleteIndices, reverse=True): for index in sorted(deleteIndices, reverse=True):
dset.particleContainer.removeParticle(index) dset.particleContainer.removeParticle(index)
......
...@@ -129,7 +129,7 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -129,7 +129,7 @@ class SampleView(QtWidgets.QGraphicsView):
def closeEvent(self, event): def closeEvent(self, event):
reply = QtWidgets.QMessageBox.question(self, 'Message', reply = QtWidgets.QMessageBox.question(self, 'Message',
"Are you sure to quit?", QtWidgets.QMessageBox.Yes | "Do you really want to quit?", QtWidgets.QMessageBox.Yes |
QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if reply == QtWidgets.QMessageBox.Yes: if reply == QtWidgets.QMessageBox.Yes:
...@@ -394,12 +394,6 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -394,12 +394,6 @@ class SampleView(QtWidgets.QGraphicsView):
cnt.update() cnt.update()
self.selectedParticleIndices.remove(cnt.particleIndex) self.selectedParticleIndices.remove(cnt.particleIndex)
def updateParticleInfoBox(index):
if self.particleInfoBox is not None:
self.scene().removeItem(self.particleInfoBox)
self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(index))
self.scene().addItem(self.particleInfoBox)
p = self.mapToScene(event.pos()) p = self.mapToScene(event.pos())
p = QtCore.QPointF(p.x(), p.y()) p = QtCore.QPointF(p.x(), p.y())
...@@ -422,10 +416,9 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -422,10 +416,9 @@ class SampleView(QtWidgets.QGraphicsView):
self.selectedParticleIndices.remove(cnt.particleIndex) self.selectedParticleIndices.remove(cnt.particleIndex)
if len(self.selectedParticleIndices) > 0: if len(self.selectedParticleIndices) > 0:
updateParticleInfoBox(self.selectedParticleIndices[-1]) self.updateParticleInfoBox(self.selectedParticleIndices[-1])
else: else:
self.scene().removeItem(self.particleInfoBox) self.removeParticleInfoBox()
self.particleInfoBox = None
self.update() self.update()
...@@ -614,12 +607,21 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -614,12 +607,21 @@ class SampleView(QtWidgets.QGraphicsView):
self.contourItems[index].isSelected = True self.contourItems[index].isSelected = True
self.selectedParticleIndices =[index] self.selectedParticleIndices =[index]
self.updateParticleInfoBox(index)
self.update()
def updateParticleInfoBox(self, particleIndex):
self.removeParticleInfoBox()
self.addParticleInfoBox(particleIndex)
def removeParticleInfoBox(self):
if self.particleInfoBox is not None: if self.particleInfoBox is not None:
self.scene().removeItem(self.particleInfoBox) self.scene().removeItem(self.particleInfoBox)
self.particleInfoBox = None
self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(index)) def addParticleInfoBox(self, particleIndex):
self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(particleIndex))
self.scene().addItem(self.particleInfoBox) self.scene().addItem(self.particleInfoBox)
self.update()
def centerOnRamanIndex(self, index, centerOn=True, highlightIndex=True): def centerOnRamanIndex(self, index, centerOn=True, highlightIndex=True):
if centerOn: if centerOn:
......
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