Commit f6214343 authored by Josef Brandt's avatar Josef Brandt

Bugfixes

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