Commit f6214343 authored by Josef Brandt's avatar Josef Brandt

Bugfixes

parent 672f17f6
...@@ -589,6 +589,7 @@ class OpticalScanUI(QtWidgets.QWidget): ...@@ -589,6 +589,7 @@ class OpticalScanUI(QtWidgets.QWidget):
self.dataset.lastpos = p0 self.dataset.lastpos = p0
self.dataset.maxdim = p0 + p1 self.dataset.maxdim = p0 + p1
self.dataset.readin = False self.dataset.readin = False
self.boundaryUpdate.emit()
self.imageUpdate.emit(self.view.microscopeMode) self.imageUpdate.emit(self.view.microscopeMode)
@QtCore.pyqtSlot(int) @QtCore.pyqtSlot(int)
......
...@@ -403,6 +403,7 @@ class SpecScanUI(QtWidgets.QWidget): ...@@ -403,6 +403,7 @@ class SpecScanUI(QtWidgets.QWidget):
self.instrctrl.connect() self.instrctrl.connect()
results: list = self.instrctrl.evaluateSpectra() results: list = self.instrctrl.evaluateSpectra()
QtWidgets.QMessageBox.about(self, "Scan completed", "Spectrum Scan was completed successfully.")
self.close() self.close()
return return
self.timer.start(100) self.timer.start(100)
......
...@@ -25,6 +25,7 @@ from .viewItems.detectItems import SeedPoint, SegmentationContour, FTIRApertureI ...@@ -25,6 +25,7 @@ from .viewItems.detectItems import SeedPoint, SegmentationContour, FTIRApertureI
from .viewItems.specscanItems import SpecScanIndicator, ParticleInfo from .viewItems.specscanItems import SpecScanIndicator, ParticleInfo
from .colorlegend import ColorLegend, getColorFromNameWithSeed from .colorlegend import ColorLegend, getColorFromNameWithSeed
if TYPE_CHECKING: if TYPE_CHECKING:
from ..dataset import DataSet
from ..sampleview import SampleView from ..sampleview import SampleView
from ..analysis.particleContainer import ParticleContainer from ..analysis.particleContainer import ParticleContainer
from ..__main__ import GEPARDMainWindow from ..__main__ import GEPARDMainWindow
...@@ -69,31 +70,16 @@ class ViewItemHandler(QtCore.QObject): ...@@ -69,31 +70,16 @@ class ViewItemHandler(QtCore.QObject):
self.viewparent.forceSceneUpdate() self.viewparent.forceSceneUpdate()
def addParticleInfoBox(self, particleIndex: int): def clearAll(self):
self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(particleIndex))
self.scene().addItem(self.particleInfoBox)
def addOptScanItem(self, number, x, y, pos) -> None:
newIndicator: ScanIndicator = ScanIndicator(number, x, y, pos)
self.oscanItems.append(newIndicator)
self.viewparentscene.addItem(newIndicator)
def addEdge(self, node1: Node, node2: Node) -> None:
newEdge: Edge = Edge(node1, node2)
self.edges.append(newEdge)
self.viewparentscene.addItem(newEdge)
def addNode(self, pos) -> None:
newNode: Node = Node(pos, self.viewparent)
self.nodes.append(newNode)
self.viewparentscene.addItem(newNode)
def clearAll(self) -> None:
self._removeItemsFromOpticalScan() self._removeItemsFromOpticalScan()
self._removeItemsFromDetection() self._removeItemsFromDetection()
self._removeItemsFromSpecScan() self._removeItemsFromSpecScan()
self.legend.hide() self.legend.hide()
def addParticleInfoBox(self, particleIndex: int):
self.particleInfoBox = ParticleInfo(self.dataset.particleContainer.getParticleOfIndex(particleIndex))
self.scene().addItem(self.particleInfoBox)
def resetParticleViewItems(self) -> None: def resetParticleViewItems(self) -> None:
self._removeContoursFromScene() self._removeContoursFromScene()
self._removeAperturesFromScene() self._removeAperturesFromScene()
...@@ -105,11 +91,6 @@ class ViewItemHandler(QtCore.QObject): ...@@ -105,11 +91,6 @@ class ViewItemHandler(QtCore.QObject):
self._addAperturesToScene() self._addAperturesToScene()
self._updateColorLegend() self._updateColorLegend()
def resetSpecScanItems(self) -> None:
self._removeItemsFromSpecScan()
self._updateSpecScanIndicatorsFromDS()
self._addItemsForSpecScan()
def _addContoursToScene(self) -> None: def _addContoursToScene(self) -> None:
for item in self.contourItems: for item in self.contourItems:
self.viewparentscene.addItem(item) self.viewparentscene.addItem(item)
...@@ -126,16 +107,50 @@ class ViewItemHandler(QtCore.QObject): ...@@ -126,16 +107,50 @@ class ViewItemHandler(QtCore.QObject):
for item in self.apertureItems: for item in self.apertureItems:
self.viewparentscene.removeItem(item) self.viewparentscene.removeItem(item)
def resetOptScanItems(self) -> None: def resetOpticalScanSetupItems(self) -> None:
dset: DataSet = self.viewparent.dataset
micMode = self.viewparent.microscopeMode
for item in self.fititems + self.edges + self.nodes:
self.viewparentscene.removeItem(item)
self.fititems = []
self.edges = []
self.nodes = []
for i, p in zip(dset.fitindices, dset.fitpoints):
pos = dset.mapToPixel(p, mode=micMode, force=True)
newFitPosInd: FitPosIndicator = FitPosIndicator(i+1, pos=pos)
self.fititems.append(newFitPosInd)
self.viewparentscene.addItem(newFitPosInd)
for p in dset.boundary:
pos = dset.mapToPixel(p, micMode, force=True)
newNode: Node = Node(pos, self.viewparent)
self.nodes.append(newNode)
self.viewparentscene.addItem(newNode)
for i in range(len(self.nodes)):
newEdge: Edge = Edge(self.nodes[i-1], self.nodes[i])
self.edges.append(newEdge)
self.viewparentscene.addItem(newEdge)
def resetOpticalScanIndicators(self, x, y) -> None:
for item in self.oscanItems: for item in self.oscanItems:
self.viewparentscene.removeItem(item) self.viewparentscene.removeItem(item)
self.oscanItems = [] self.oscanItems = []
def resetOptScanBoundary(self) -> None: micMode = self.viewparent.microscopeMode
for edge, node in zip(self.edges, self.nodes): dset: DataSet = self.viewparent.dataset
self.viewparentscene.remove(edge) for i, p in enumerate(dset.grid):
self.viewparentscene.remove(node) pos = dset.mapToPixel(p, micMode, force=True)
self.edges, self.nodes = [], [] newIndicator: ScanIndicator = ScanIndicator(i+1, x, y, pos)
self.oscanItems.append(newIndicator)
self.viewparentscene.addItem(newIndicator)
def resetSpecScanItems(self) -> None:
self._removeItemsFromSpecScan()
self._updateSpecScanIndicatorsFromDS()
self._addItemsForSpecScan()
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def adjustParticleViewItemsVisibility(self) -> None: def adjustParticleViewItemsVisibility(self) -> None:
...@@ -173,6 +188,10 @@ class ViewItemHandler(QtCore.QObject): ...@@ -173,6 +188,10 @@ class ViewItemHandler(QtCore.QObject):
else: else:
item.setHighLight(False) item.setHighLight(False)
def updateAndShowScanIndicators(self) -> None:
self._updateSpecScanIndicatorsFromDS()
self._addItemsForSpecScan()
def _updateColorLegend(self) -> None: def _updateColorLegend(self) -> None:
legendItems = [] legendItems = []
for polymer in self.particleContainer.getUniquePolymers(): for polymer in self.particleContainer.getUniquePolymers():
...@@ -254,9 +273,7 @@ class ViewItemHandler(QtCore.QObject): ...@@ -254,9 +273,7 @@ class ViewItemHandler(QtCore.QObject):
self.legend.show() self.legend.show()
def _getOptScanItems(self) -> list: def _getOptScanItems(self) -> list:
return self.fititems + self.edges + self.nodes + self.oscanItems return self.fititems + self.oscanItems + self.edges + self.nodes
def _getSpecScanItems(self) -> list: def _getSpecScanItems(self) -> list:
return self.specscanItems + self.contourItems + self.apertureItems return self.specscanItems + self.contourItems + self.apertureItems
...@@ -38,7 +38,7 @@ from logging import Logger ...@@ -38,7 +38,7 @@ from logging import Logger
def cv2imread_fix(fname, flags=cv2.IMREAD_COLOR): def cv2imread_fix(fname, flags=cv2.IMREAD_COLOR):
if skimread is not None: if skimread is not None:
return skimread(fname, as_gray=(flags==cv2.IMREAD_GRAYSCALE)) return skimread(fname, as_gray=(flags == cv2.IMREAD_GRAYSCALE))
with open(fname, "rb") as fp: with open(fname, "rb") as fp:
cont = fp.read() cont = fp.read()
img = cv2.imdecode(np.fromstring(cont, dtype=np.uint8), flags) img = cv2.imdecode(np.fromstring(cont, dtype=np.uint8), flags)
...@@ -64,43 +64,43 @@ def cv2imwrite_fix(fname, img, params=None): ...@@ -64,43 +64,43 @@ def cv2imwrite_fix(fname, img, params=None):
def polygoncovering(boundary, wx, wy): def polygoncovering(boundary, wx, wy):
poslist = [] poslist = []
ymin, ymax = boundary[:,1].min(), boundary[:,1].max() ymin, ymax = boundary[:, 1].min(), boundary[:, 1].max()
Ny = max(int(np.ceil((ymax-ymin)/wy)),1) Ny = max(int(np.ceil((ymax - ymin) / wy)), 1)
dyi = wy*Ny - (ymax-ymin) dyi = wy * Ny - (ymax - ymin)
y = ymin - .5*dyi + wy*np.arange(Ny) y = ymin - .5 * dyi + wy * np.arange(Ny)
dx = np.roll(boundary[:,0],-1)-boundary[:,0] dx = np.roll(boundary[:, 0], -1) - boundary[:, 0]
dy = np.roll(boundary[:,1],-1)-boundary[:,1] dy = np.roll(boundary[:, 1], -1) - boundary[:, 1]
x0c, x1c = boundary[:,0].min(), boundary[:,0].max() x0c, x1c = boundary[:, 0].min(), boundary[:, 0].max()
x0clast, x1clast = x0c, x1c x0clast, x1clast = x0c, x1c
for i, yi in enumerate(y): for i, yi in enumerate(y):
if i==0: if i == 0:
if Ny>1: if Ny > 1:
ind = boundary[:,1]<y[1] ind = boundary[:, 1] < y[1]
else: else:
ind = np.ones(boundary.shape[0], dtype=np.bool) ind = np.ones(boundary.shape[0], dtype=np.bool)
elif i==Ny-1: elif i == Ny - 1:
ind = boundary[:,1]>yi ind = boundary[:, 1] > yi
else: else:
ind = (boundary[:,1]>yi)&(boundary[:,1]<y[i+1]) ind = (boundary[:, 1] > yi) & (boundary[:, 1] < y[i + 1])
if i<Ny-1: if i < Ny - 1:
dyc = y[i+1]-boundary[:,1] dyc = y[i + 1] - boundary[:, 1]
with np.errstate(divide='ignore'): with np.errstate(divide='ignore'):
ti = dyc/dy # some elements in dy may be zero, but ti will be inf or -inf in this case -> results are ok ti = dyc / dy # some elements in dy may be zero, but ti will be inf or -inf in this case -> results are ok
indc = (ti>=0.)&(ti<1) indc = (ti >= 0.) & (ti < 1)
xi = boundary[indc,0] + ti[indc]*dx[indc] xi = boundary[indc, 0] + ti[indc] * dx[indc]
x0c, x1c = xi.min(), xi.max() x0c, x1c = xi.min(), xi.max()
if i==0: if i == 0:
x0clast, x1clast = x0c, x1c x0clast, x1clast = x0c, x1c
if np.any(ind): if np.any(ind):
x0n, x1n = boundary[ind,0].min(), boundary[ind,0].max() x0n, x1n = boundary[ind, 0].min(), boundary[ind, 0].max()
else: else:
x0n, x1n = x0c, x1c x0n, x1n = x0c, x1c
x0 = min([x0n,x0c,x0clast]) x0 = min([x0n, x0c, x0clast])
x1 = max([x1n,x1c,x1clast]) x1 = max([x1n, x1c, x1clast])
Nx = int(np.ceil((x1-x0)/wx)) Nx = int(np.ceil((x1 - x0) / wx))
dxi = wx*Nx - (x1-x0) dxi = wx * Nx - (x1 - x0)
x = x0 - .5*dxi + .5*wx + wx*np.arange(Nx) x = x0 - .5 * dxi + .5 * wx + wx * np.arange(Nx)
poslist.extend([[xi,yi+.5*wy] for xi in (x if i%2==0 else x[::-1])]) poslist.extend([[xi, yi + .5 * wy] for xi in (x if i % 2 == 0 else x[::-1])])
x0clast, x1clast = x0c, x1c x0clast, x1clast = x0c, x1c
return poslist return poslist
......
...@@ -226,10 +226,13 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -226,10 +226,13 @@ class SampleView(QtWidgets.QGraphicsView):
pass pass
if self.particleEditor is None: if self.particleEditor is None:
self.particleEditor = ParticleEditor(self, self.dataset.particleContainer) self.particleEditor = ParticleEditor(self, self.dataset)
tryDisconnectingSignal(self.particleEditor.particleAssignmentChanged) tryDisconnectingSignal(self.particleEditor.particleAssignmentChanged)
def getScenePyramid(self) -> ScenePyramid:
return self.pyramid
def setMicroscopeMode(self): def setMicroscopeMode(self):
""" """
The opical microscope can be in either Brightfield (bf) or Darkfield (df) mode. In the case of the Renishaw instrument The opical microscope can be in either Brightfield (bf) or Darkfield (df) mode. In the case of the Renishaw instrument
...@@ -450,29 +453,30 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -450,29 +453,30 @@ class SampleView(QtWidgets.QGraphicsView):
for n in nodes: for n in nodes:
p = n.pos().x(), n.pos().y() p = n.pos().x(), n.pos().y()
boundary.append(self.dataset.mapToLength(p, self.microscopeMode, force=True)) boundary.append(self.dataset.mapToLength(p, self.microscopeMode, force=True))
boundary = np.array(boundary) if len(boundary) > 0:
self.dataset.boundary = boundary boundary = np.array(boundary)
if micMode == 'df': self.dataset.boundary = boundary
width, height, angle = self.dataset.imagedim_df if micMode == 'df':
else: width, height, angle = self.dataset.imagedim_df
width, height, angle = self.dataset.imagedim_bf else:
width, height, angle = self.dataset.imagedim_bf
margin = min(width, height)*0.02
wx, wy = width-margin, height-margin margin = min(width, height)*0.02
p1 = polygoncovering(boundary, wx, wy) wx, wy = width-margin, height-margin
b2 = boundary.copy() p1 = polygoncovering(boundary, wx, wy)
b2 = b2[:, [1, 0]] b2 = boundary.copy()
p2 = polygoncovering(b2, wy, wx) b2 = b2[:, [1, 0]]
if len(p2) < len(p1): p2 = polygoncovering(b2, wy, wx)
p1 = [[pi[1], pi[0]] for pi in p2] if len(p2) < len(p1):
self.dataset.grid = p1 p1 = [[pi[1], pi[0]] for pi in p2]
pixelscale = self.dataset.getPixelScale(self.microscopeMode) self.dataset.grid = p1
wxs, wys = width/pixelscale, height/pixelscale pixelscale = self.dataset.getPixelScale(self.microscopeMode)
wxs, wys = width/pixelscale, height/pixelscale
self.viewItemHandler.resetOptScanItems() self.viewItemHandler.resetOpticalScanIndicators(wxs, wys)
for i, p in enumerate(p1): # self.viewItemHandler.resetOptScanItems()
p = self.dataset.mapToPixel(p, self.microscopeMode, force=True) # for i, p in enumerate(p1):
self.viewItemHandler.addOptScanItem(i+1, wxs, wys, p) # p = self.dataset.mapToPixel(p, self.microscopeMode, force=True)
# self.viewItemHandler.addOptScanItem(i+1, wxs, wys, p)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def resetBoundary(self): def resetBoundary(self):
...@@ -480,14 +484,14 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -480,14 +484,14 @@ class SampleView(QtWidgets.QGraphicsView):
Resets the Boundary Items in the GraphicsView. Resets the Boundary Items in the GraphicsView.
:return: :return:
""" """
micMode = self.microscopeMode # micMode = self.microscopeMode
self.viewItemHandler.resetOptScanBoundary() # self.viewItemHandler.resetOptScanBoundary()
for p in self.dataset.boundary: # for p in self.dataset.boundary:
p = self.dataset.mapToPixel(p, micMode, force=True) # p = self.dataset.mapToPixel(p, micMode, force=True)
self.viewItemHandler.addNode(p) # self.viewItemHandler.addNode(p)
for i in range(len(self.viewItemHandler.nodes)): # for i in range(len(self.viewItemHandler.nodes)):
self.viewItemHandler.addEdge(self.viewItemHandler.nodes[i-1], self.viewItemHandler.nodes[i]) # self.viewItemHandler.addEdge(self.viewItemHandler.nodes[i-1], self.viewItemHandler.nodes[i])
self.viewItemHandler.resetOpticalScanSetupItems()
self.resetScanPositions() self.resetScanPositions()
def removeParticleContour(self, contourIndex): def removeParticleContour(self, contourIndex):
......
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