Commit 5fd1cb0c authored by Lars Bittrich's avatar Lars Bittrich

Zeissimporter initial commit with coordinate transfer

parent eb5a3c56
...@@ -85,6 +85,16 @@ class MeasureParticleWindow(QtWidgets.QMainWindow): ...@@ -85,6 +85,16 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.view.open(self.fname) self.view.open(self.fname)
self.scalingChanged(1.) self.scalingChanged(1.)
@QtCore.pyqtSlot()
def importProject(self, fileName=False):
if fileName is False:
fileName = QtWidgets.QFileDialog.getOpenFileName(self, "Import Zeiss Zen Project",
defaultPath, "*.xml")[0]
if fileName:
self.fname = str(fileName)
self.view.importProject(self.fname)
self.scalingChanged(1.)
@QtCore.pyqtSlot() @QtCore.pyqtSlot()
def new(self, fileName=False): def new(self, fileName=False):
if fileName is False: if fileName is False:
...@@ -115,6 +125,10 @@ class MeasureParticleWindow(QtWidgets.QMainWindow): ...@@ -115,6 +125,10 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.openAct.setShortcut("Ctrl+O") self.openAct.setShortcut("Ctrl+O")
self.openAct.triggered.connect(self.open) self.openAct.triggered.connect(self.open)
self.importAct = QtWidgets.QAction("&Import Project...", self)
self.importAct.setShortcut("Ctrl+I")
self.importAct.triggered.connect(self.importProject)
self.newAct = QtWidgets.QAction("&New Measurement...", self) self.newAct = QtWidgets.QAction("&New Measurement...", self)
self.newAct.setShortcut("Ctrl+N") self.newAct.setShortcut("Ctrl+N")
self.newAct.triggered.connect(self.new) self.newAct.triggered.connect(self.new)
...@@ -211,12 +225,14 @@ class MeasureParticleWindow(QtWidgets.QMainWindow): ...@@ -211,12 +225,14 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
def unblockUI(self, connected): def unblockUI(self, connected):
self.openAct.setEnabled(True) self.openAct.setEnabled(True)
self.importAct.setEnabled(True)
self.newAct.setEnabled(True) self.newAct.setEnabled(True)
self.updateConnected(connected) self.updateConnected(connected)
self.exitAct.setEnabled(True) self.exitAct.setEnabled(True)
def blockUI(self): def blockUI(self):
self.openAct.setEnabled(False) self.openAct.setEnabled(False)
self.importAct.setEnabled(False)
self.newAct.setEnabled(False) self.newAct.setEnabled(False)
self.connectRamanAct.setEnabled(False) self.connectRamanAct.setEnabled(False)
self.disconnectRamanAct.setEnabled(False) self.disconnectRamanAct.setEnabled(False)
...@@ -237,6 +253,7 @@ class MeasureParticleWindow(QtWidgets.QMainWindow): ...@@ -237,6 +253,7 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
def createMenus(self): def createMenus(self):
self.fileMenu = QtWidgets.QMenu("&File", self) self.fileMenu = QtWidgets.QMenu("&File", self)
self.fileMenu.addAction(self.newAct) self.fileMenu.addAction(self.newAct)
self.fileMenu.addAction(self.importAct)
self.fileMenu.addAction(self.openAct) self.fileMenu.addAction(self.openAct)
self.fileMenu.addSeparator() self.fileMenu.addSeparator()
self.fileMenu.addAction(self.exitAct) self.fileMenu.addAction(self.exitAct)
...@@ -272,6 +289,7 @@ class MeasureParticleWindow(QtWidgets.QMainWindow): ...@@ -272,6 +289,7 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.toolbar.setIconSize(QtCore.QSize(100,50)) self.toolbar.setIconSize(QtCore.QSize(100,50))
self.toolbar.addAction(self.aboutAct) self.toolbar.addAction(self.aboutAct)
self.toolbar.addAction(self.newAct) self.toolbar.addAction(self.newAct)
self.toolbar.addAction(self.importAct)
self.toolbar.addAction(self.openAct) self.toolbar.addAction(self.openAct)
self.toolbar.addSeparator() self.toolbar.addSeparator()
self.toolbar.addAction(self.connectRamanAct) self.toolbar.addAction(self.connectRamanAct)
...@@ -295,6 +313,7 @@ if __name__ == '__main__': ...@@ -295,6 +313,7 @@ if __name__ == '__main__':
logpath = QtCore.QStandardPaths.writableLocation( logpath = QtCore.QStandardPaths.writableLocation(
QtCore.QStandardPaths.AppLocalDataLocation) QtCore.QStandardPaths.AppLocalDataLocation)
fp = None
if logpath != "": if logpath != "":
if not os.path.exists(logpath): if not os.path.exists(logpath):
os.mkdir(logpath) os.mkdir(logpath)
...@@ -310,3 +329,5 @@ if __name__ == '__main__': ...@@ -310,3 +329,5 @@ if __name__ == '__main__':
meas = MeasureParticleWindow(logpath) meas = MeasureParticleWindow(logpath)
meas.showMaximized() meas.showMaximized()
ret = app.exec_() ret = app.exec_()
if fp is not None:
fp.close()
\ No newline at end of file
...@@ -113,11 +113,12 @@ def loadAndPasteImage(srcnames, fullimage, fullzval, width, height, ...@@ -113,11 +113,12 @@ def loadAndPasteImage(srcnames, fullimage, fullzval, width, height,
class PointCoordinates(QtWidgets.QGridLayout): class PointCoordinates(QtWidgets.QGridLayout):
readPoint = QtCore.pyqtSignal(float, float, float, name='readPoint') readPoint = QtCore.pyqtSignal(float, float, float, name='readPoint')
def __init__(self, N, ramanctrl, parent=None): def __init__(self, N, ramanctrl, parent=None, names=None):
super().__init__(parent) super().__init__(parent)
self.dswidgets = [] self.dswidgets = []
self.N = 0 self.N = 0
self.ramanctrl = ramanctrl self.ramanctrl = ramanctrl
self.names = names
self.pimageOnly = QtWidgets.QPushButton("Image") self.pimageOnly = QtWidgets.QPushButton("Image")
self.addWidget(self.pimageOnly, 0, 6, QtCore.Qt.AlignRight) self.addWidget(self.pimageOnly, 0, 6, QtCore.Qt.AlignRight)
self.pimageOnly.released.connect(QtCore.pyqtSlot()(lambda : self.read(-1))) self.pimageOnly.released.connect(QtCore.pyqtSlot()(lambda : self.read(-1)))
...@@ -140,6 +141,9 @@ class PointCoordinates(QtWidgets.QGridLayout): ...@@ -140,6 +141,9 @@ class PointCoordinates(QtWidgets.QGridLayout):
self.itemAtPosition(i+1,5).setVisible(True) self.itemAtPosition(i+1,5).setVisible(True)
self.itemAtPosition(i+1,6).setVisible(True) self.itemAtPosition(i+1,6).setVisible(True)
for i in range(self.N, N): for i in range(self.N, N):
if self.names is not None:
lx = QtWidgets.QLabel(f"{self.names[i]} -> x:")
else:
lx = QtWidgets.QLabel(f"{i+1} -> x:") lx = QtWidgets.QLabel(f"{i+1} -> x:")
ly = QtWidgets.QLabel("y:") ly = QtWidgets.QLabel("y:")
lz = QtWidgets.QLabel("z:") lz = QtWidgets.QLabel("z:")
......
...@@ -27,6 +27,7 @@ from opticalscan import OpticalScan ...@@ -27,6 +27,7 @@ from opticalscan import OpticalScan
from ramanscanui import RamanScanUI from ramanscanui import RamanScanUI
from detectionview import ParticleDetectionView from detectionview import ParticleDetectionView
from analysis.analysisview import ParticleAnalysis from analysis.analysisview import ParticleAnalysis
from zeissimporter import ZeissImporter
from viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContours from viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContours
from helperfunctions import polygoncovering, cv2imread_fix from helperfunctions import polygoncovering, cv2imread_fix
import cv2 import cv2
...@@ -84,7 +85,7 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -84,7 +85,7 @@ class SampleView(QtWidgets.QGraphicsView):
self.oscanwidget.imageUpdate.connect(self.loadPixmap) self.oscanwidget.imageUpdate.connect(self.loadPixmap)
self.oscanwidget.boundaryUpdate.connect(self.resetBoundary) self.oscanwidget.boundaryUpdate.connect(self.resetBoundary)
self.analysiswidget = None self.analysiswidget = None
self.setMinimumSize(600,600) self.setMinimumSize(600, 600)
self.darkenPixmap = False self.darkenPixmap = False
self.microscopeMode = None self.microscopeMode = None
self.coordTestMode = False self.coordTestMode = False
...@@ -237,6 +238,13 @@ class SampleView(QtWidgets.QGraphicsView): ...@@ -237,6 +238,13 @@ class SampleView(QtWidgets.QGraphicsView):
self.activateMaxMode(loadnew=True) self.activateMaxMode(loadnew=True)
self.imparent.snapshotAct.setEnabled(True) self.imparent.snapshotAct.setEnabled(True)
def importProject(self, fname):
zimp = ZeissImporter(fname, self.ramanctrl, self)
if zimp.validimport:
zimp.exec()
if zimp.result() == QtWidgets.QDialog.Accepted:
self.open(zimp.gepardname)
def new(self, fname): def new(self, fname):
self.saveDataSet() self.saveDataSet()
if self.dataset is not None: if self.dataset is not None:
......
This diff is collapsed.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
GEPARD - Gepard-Enabled PARticle Detection
Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für
Polymerforschung Dresden e. V. <bittrich-lars@ipfdd.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>.
"""
from xml.sax import make_parser, handler
class Marker:
def __init__(self, name, x, y, z):
self.name, self.x, self.y, self.z = name, x, y, z
def getPos(self):
return self.x, self.y, self.z
def __repr__(self):
return str(self)
def __str__(self):
return f'Marker: "{self.name}" at: {self.getPos()} µm'
class Region:
def __init__(self):
self.centerx, self.centery = None, None
self.width, self.height = None, None
def __repr__(self):
return str(self)
def __str__(self):
return f'Region center: {self.centerx, self.centery} µm\n' + \
f'Region size: {self.width, self.height} µm'
class ZRange:
def __init__(self):
self.z0, self.zn = None, None
self.dz = None
def __repr__(self):
return str(self)
def __str__(self):
return f'Z-range in: {self.z0, self.zn} µm at step size: {self.dz} µm'
class ZeissHandler(handler.ContentHandler):
def __init__(self):
self.markers = []
self.region = Region()
self.zrange = ZRange()
self.intag = False
self.subtag = ''
def characters(self, content):
if self.intag:
self.content += content.strip()
def startElement(self, name, attrs):
if name == 'Marker':
self.markers.append(Marker(attrs['Id'], attrs['StageXPosition'],
attrs['StageYPosition'],
attrs['FocusPosition']))
elif name == 'TileRegion' or name == 'ZStackSetup':
self.intag = True
if self.intag:
self.content = ''
if name in ['First','Last','Interval']:
self.subtag = name
def endElement(self, name):
if name == 'TileRegion' or name == 'ZStackSetup':
self.intag = False
if self.intag and name == 'CenterPosition':
self.region.centerx, self.region.centery = map(float, self.content.split(','))
elif self.intag and name == 'ContourSize':
self.region.width, self.region.height = map(float, self.content.split(','))
elif self.intag and name == 'Value' and \
self.subtag in ['First','Last','Interval']:
attrmap = {'First':'z0','Last':'zn','Interval':'dz'}
# values a given in meter even though µm are set as units?
# -> we convert to µm
self.zrange.__setattr__(attrmap[self.subtag],
float(self.content)*1.0e6)
self.subtag = ''
\ No newline at end of file
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