From c90f7b26bf35f94f83b0ea224eda532892a08a8e Mon Sep 17 00:00:00 2001 From: JosefBrandt Date: Thu, 22 Aug 2019 14:01:42 +0200 Subject: [PATCH] Several Bugfixes --- analysis/analysisplots.py | 2 +- analysis/particleCharacterization.py | 14 ++++++++++++- analysis/particleEditor.py | 10 ++++++++-- gepard.py | 4 ++-- legacyConvert.py | 5 +++++ sampleview.py | 30 +++++++++++++++------------- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/analysis/analysisplots.py b/analysis/analysisplots.py index c13e299..312c592 100644 --- a/analysis/analysisplots.py +++ b/analysis/analysisplots.py @@ -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) diff --git a/analysis/particleCharacterization.py b/analysis/particleCharacterization.py index 5c42075..f399ca1 100644 --- a/analysis/particleCharacterization.py +++ b/analysis/particleCharacterization.py @@ -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) diff --git a/analysis/particleEditor.py b/analysis/particleEditor.py index 9282e3a..6442238 100644 --- a/analysis/particleEditor.py +++ b/analysis/particleEditor.py @@ -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): diff --git a/gepard.py b/gepard.py index da206ec..a53e9ac 100644 --- a/gepard.py +++ b/gepard.py @@ -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) diff --git a/legacyConvert.py b/legacyConvert.py index da951a0..34fb386 100644 --- a/legacyConvert.py +++ b/legacyConvert.py @@ -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) diff --git a/sampleview.py b/sampleview.py index 641f1c4..af72e6a 100644 --- a/sampleview.py +++ b/sampleview.py @@ -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: -- GitLab