Commit c90f7b26 authored by JosefBrandt's avatar JosefBrandt

Several Bugfixes

parent 2026524b
......@@ -113,7 +113,7 @@ class SpectraPlot(QtWidgets.QGroupBox):
layout = QtWidgets.QHBoxLayout()
self.canvas = FigureCanvas(Figure())
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)
specNavigation = NavigationToolbar(self.canvas, self)
specNavigation.setOrientation(QtCore.Qt.Vertical)
......
......@@ -60,12 +60,24 @@ def getParticleStatsWithPixelScale(cnt, fullimage, dataset):
newStats.height = getParticleHeight(cnt, dataset)
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)
newStats.color = getParticleColor(partImg)
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):
img = cv2.cvtColor(imgRGB, cv2.COLOR_RGB2HSV_FULL)
meanHSV = cv2.mean(img)
......
......@@ -171,7 +171,7 @@ class ParticleEditor(QtCore.QObject):
'Particle contours are not connected.\nThat is currently not supported!')
return
self.mergeParticlesInParticleContainerAndSampleView(contourIndices,newContour, newAssignment)
self.mergeParticlesInParticleContainerAndSampleView(contourIndices, newContour, newAssignment)
@QtCore.pyqtSlot(list, str)
def reassignParticles(self, contourindices, newAssignment):
......@@ -179,13 +179,15 @@ class ParticleEditor(QtCore.QObject):
print(f'reassigning indices {contourindices} into {newAssignment}')
for partIndex in contourindices:
self.particleContainer.reassignParticleToAssignment(partIndex, newAssignment)
self.viewparent.updateParticleInfoBox(partIndex)
self.particleAssignmentChanged.emit()
@QtCore.pyqtSlot(list, str)
def paintParticles(self, contourIndices, newAssignment):
print(f'painting indices {contourIndices} into {newAssignment}')
self.createSafetyBackup()
self.viewparent.removeParticleInfoBox()
self.storedIndices = contourIndices
self.storedAssignmend = newAssignment
......@@ -208,6 +210,7 @@ class ParticleEditor(QtCore.QObject):
except NotConnectedContoursError:
QtWidgets.QMessageBox.critical(self.viewparent, 'ERROR!',
'Particle contours are not connected.\nThat is currently not supported!')
self.viewparent.updateParticleInfoBox(self.storedIndices[-1])
self.storedIndices = []
self.storedAssignmend = None
self.destroyParticlePainter()
......@@ -238,6 +241,7 @@ class ParticleEditor(QtCore.QObject):
self.viewparent.resetContourIndices()
self.particleContainer.resetParticleIndices()
self.viewparent.updateParticleInfoBox(self.particleContainer.getNumberOfParticles()-1)
self.particleAssignmentChanged.emit()
@QtCore.pyqtSlot(list, str)
......@@ -245,12 +249,14 @@ class ParticleEditor(QtCore.QObject):
print(f'changing color of particles {contourIndices} into {newColor}')
for partIndex in contourIndices:
self.particleContainer.changeParticleColor(partIndex, newColor)
self.viewparent.updateParticleInfoBox(partIndex)
@QtCore.pyqtSlot(list, str)
def changeParticleShapes(self, contourIndices, newShape):
print(f'changing shape of particles {contourIndices} into {newShape}')
for partIndex in contourIndices:
self.particleContainer.changeParticleShape(partIndex, newShape)
self.viewparent.updateParticleInfoBox(partIndex)
@QtCore.pyqtSlot(list)
def deleteParticles(self, contourIndices):
......
......@@ -352,8 +352,8 @@ if __name__ == '__main__':
logname = os.path.join(logpath, 'logfile.txt')
fp = open(logname, "a")
# sys.stderr = fp
# sys.stdout = fp
sys.stderr = fp
sys.stdout = fp
print("starting GEPARD at: " + strftime("%d %b %Y %H:%M:%S", localtime()), flush=True)
gepard = GEPARDMainWindow(logpath)
......
......@@ -191,6 +191,11 @@ def updateParticleStats(dset):
except InvalidParticleError:
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')
for index in sorted(deleteIndices, reverse=True):
dset.particleContainer.removeParticle(index)
......
......@@ -129,7 +129,7 @@ class SampleView(QtWidgets.QGraphicsView):
def closeEvent(self, event):
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)
if reply == QtWidgets.QMessageBox.Yes:
......@@ -394,12 +394,6 @@ class SampleView(QtWidgets.QGraphicsView):
cnt.update()
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 = QtCore.QPointF(p.x(), p.y())
......@@ -422,10 +416,9 @@ class SampleView(QtWidgets.QGraphicsView):
self.selectedParticleIndices.remove(cnt.particleIndex)
if len(self.selectedParticleIndices) > 0:
updateParticleInfoBox(self.selectedParticleIndices[-1])
self.updateParticleInfoBox(self.selectedParticleIndices[-1])
else:
self.scene().removeItem(self.particleInfoBox)
self.particleInfoBox = None
self.removeParticleInfoBox()
self.update()
......@@ -614,13 +607,22 @@ class SampleView(QtWidgets.QGraphicsView):
self.contourItems[index].isSelected = True
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:
self.scene().removeItem(self.particleInfoBox)
self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(index))
self.particleInfoBox = None
def addParticleInfoBox(self, particleIndex):
self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(particleIndex))
self.scene().addItem(self.particleInfoBox)
self.update()
def centerOnRamanIndex(self, index, centerOn=True, highlightIndex=True):
if centerOn:
for scanItem in self.ramanscanitems:
......
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