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

Zeissimporter initial commit with coordinate transfer

parent eb5a3c56
......@@ -84,6 +84,16 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.fname = str(fileName)
self.view.open(self.fname)
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()
def new(self, fileName=False):
......@@ -115,6 +125,10 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.openAct.setShortcut("Ctrl+O")
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.setShortcut("Ctrl+N")
self.newAct.triggered.connect(self.new)
......@@ -211,12 +225,14 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
def unblockUI(self, connected):
self.openAct.setEnabled(True)
self.importAct.setEnabled(True)
self.newAct.setEnabled(True)
self.updateConnected(connected)
self.exitAct.setEnabled(True)
def blockUI(self):
self.openAct.setEnabled(False)
self.importAct.setEnabled(False)
self.newAct.setEnabled(False)
self.connectRamanAct.setEnabled(False)
self.disconnectRamanAct.setEnabled(False)
......@@ -237,6 +253,7 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
def createMenus(self):
self.fileMenu = QtWidgets.QMenu("&File", self)
self.fileMenu.addAction(self.newAct)
self.fileMenu.addAction(self.importAct)
self.fileMenu.addAction(self.openAct)
self.fileMenu.addSeparator()
self.fileMenu.addAction(self.exitAct)
......@@ -272,6 +289,7 @@ class MeasureParticleWindow(QtWidgets.QMainWindow):
self.toolbar.setIconSize(QtCore.QSize(100,50))
self.toolbar.addAction(self.aboutAct)
self.toolbar.addAction(self.newAct)
self.toolbar.addAction(self.importAct)
self.toolbar.addAction(self.openAct)
self.toolbar.addSeparator()
self.toolbar.addAction(self.connectRamanAct)
......@@ -295,6 +313,7 @@ if __name__ == '__main__':
logpath = QtCore.QStandardPaths.writableLocation(
QtCore.QStandardPaths.AppLocalDataLocation)
fp = None
if logpath != "":
if not os.path.exists(logpath):
os.mkdir(logpath)
......@@ -309,4 +328,6 @@ if __name__ == '__main__':
meas = MeasureParticleWindow(logpath)
meas.showMaximized()
ret = app.exec_()
\ No newline at end of file
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,
class PointCoordinates(QtWidgets.QGridLayout):
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)
self.dswidgets = []
self.N = 0
self.ramanctrl = ramanctrl
self.names = names
self.pimageOnly = QtWidgets.QPushButton("Image")
self.addWidget(self.pimageOnly, 0, 6, QtCore.Qt.AlignRight)
self.pimageOnly.released.connect(QtCore.pyqtSlot()(lambda : self.read(-1)))
......@@ -140,7 +141,10 @@ class PointCoordinates(QtWidgets.QGridLayout):
self.itemAtPosition(i+1,5).setVisible(True)
self.itemAtPosition(i+1,6).setVisible(True)
for i in range(self.N, N):
lx = QtWidgets.QLabel(f"{i+1} -> x:")
if self.names is not None:
lx = QtWidgets.QLabel(f"{self.names[i]} -> x:")
else:
lx = QtWidgets.QLabel(f"{i+1} -> x:")
ly = QtWidgets.QLabel("y:")
lz = QtWidgets.QLabel("z:")
wx = QtWidgets.QDoubleSpinBox()
......
......@@ -27,6 +27,7 @@ from opticalscan import OpticalScan
from ramanscanui import RamanScanUI
from detectionview import ParticleDetectionView
from analysis.analysisview import ParticleAnalysis
from zeissimporter import ZeissImporter
from viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContours
from helperfunctions import polygoncovering, cv2imread_fix
import cv2
......@@ -84,7 +85,7 @@ class SampleView(QtWidgets.QGraphicsView):
self.oscanwidget.imageUpdate.connect(self.loadPixmap)
self.oscanwidget.boundaryUpdate.connect(self.resetBoundary)
self.analysiswidget = None
self.setMinimumSize(600,600)
self.setMinimumSize(600, 600)
self.darkenPixmap = False
self.microscopeMode = None
self.coordTestMode = False
......@@ -237,6 +238,13 @@ class SampleView(QtWidgets.QGraphicsView):
self.activateMaxMode(loadnew=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):
self.saveDataSet()
if self.dataset is not None:
......@@ -347,7 +355,7 @@ class SampleView(QtWidgets.QGraphicsView):
self.announceScaling()
def announceScaling(self):
pixelscale = (self.dataset.pixelscale_df if self.microscopeMode == 'df' else self.dataset.pixelscale_bf)
pixelscale = (self.dataset.pixelscale_df if self.microscopeMode == 'df' else self.dataset.pixelscale_bf)
if self.dataset is None or pixelscale is None:
self.ScalingChanged.emit(-1.0)
else:
......@@ -445,10 +453,10 @@ class SampleView(QtWidgets.QGraphicsView):
if len(p2)<len(p1):
p1 = [[pi[1],pi[0]] for pi in p2]
self.dataset.grid = p1
if self.microscopeMode == 'df':
wxs, wys = width/self.dataset.pixelscale_df, height/self.dataset.pixelscale_df
else:
wxs, wys = width/self.dataset.pixelscale_bf, height/self.dataset.pixelscale_bf
if self.microscopeMode == 'df':
wxs, wys = width/self.dataset.pixelscale_df, height/self.dataset.pixelscale_df
else:
wxs, wys = width/self.dataset.pixelscale_bf, height/self.dataset.pixelscale_bf
self.scanitems = []
for i, p in enumerate(p1):
......@@ -481,46 +489,46 @@ class SampleView(QtWidgets.QGraphicsView):
@QtCore.pyqtSlot(int, bool)
def selectContour(self, index, centerOn=True):
if self.analysiswidget is not None:
if self.analysiswidget.uniquePolymers is not None:
#the index is the contour index, find particle index:
specIndex = self.analysiswidget.particles2spectra[index][0] #select first spectrum of partoicle
self.analysiswidget.currentParticleIndex = index
self.analysiswidget.currentSpectrumIndex = specIndex
selectedPolymer = self.analysiswidget.currentPolymers[specIndex]
try:
self.analysiswidget.polymerIndex = self.analysiswidget.uniquePolymers.index(selectedPolymer)
except:
print(selectedPolymer)
raise
#subparticleIndex
partIndicesOfThatPolymer = self.analysiswidget.indices[self.analysiswidget.polymerIndex]
subPartInd = partIndicesOfThatPolymer.index(index)
#disconnect analysis widgets:
self.analysiswidget.particleSelector.valueChanged.disconnect()
self.analysiswidget.spectrumSelector.valueChanged.disconnect()
self.analysiswidget.polymerComboBox.currentIndexChanged.disconnect()
#set widgets...
self.analysiswidget.particleSelector.setValue(subPartInd+1)
self.analysiswidget.particleSelector.setMaximum(len(partIndicesOfThatPolymer))
self.analysiswidget.spectrumSelector.setValue(1)
self.analysiswidget.spectrumSelector.setMaximum(len(self.analysiswidget.particles2spectra[index]))
selectedPolymer = self.analysiswidget.currentPolymers[specIndex]
self.analysiswidget.polymerIndex = self.analysiswidget.uniquePolymers.index(selectedPolymer)
self.analysiswidget.polymerComboBox.setCurrentIndex(self.analysiswidget.polymerIndex)
#reconnect all widgets:
self.analysiswidget.particleSelector.valueChanged.connect(self.analysiswidget.selectParticle)
self.analysiswidget.spectrumSelector.valueChanged.connect(self.analysiswidget.selectSpectrum)
self.analysiswidget.polymerComboBox.currentIndexChanged.connect(self.analysiswidget.displayNewPolymerType)
self.analysiswidget.updateSpecPlot(centerOn=centerOn)
if self.analysiswidget.uniquePolymers is not None:
#the index is the contour index, find particle index:
specIndex = self.analysiswidget.particles2spectra[index][0] #select first spectrum of partoicle
self.analysiswidget.currentParticleIndex = index
self.analysiswidget.currentSpectrumIndex = specIndex
selectedPolymer = self.analysiswidget.currentPolymers[specIndex]
try:
self.analysiswidget.polymerIndex = self.analysiswidget.uniquePolymers.index(selectedPolymer)
except:
print(selectedPolymer)
raise
#subparticleIndex
partIndicesOfThatPolymer = self.analysiswidget.indices[self.analysiswidget.polymerIndex]
subPartInd = partIndicesOfThatPolymer.index(index)
#disconnect analysis widgets:
self.analysiswidget.particleSelector.valueChanged.disconnect()
self.analysiswidget.spectrumSelector.valueChanged.disconnect()
self.analysiswidget.polymerComboBox.currentIndexChanged.disconnect()
#set widgets...
self.analysiswidget.particleSelector.setValue(subPartInd+1)
self.analysiswidget.particleSelector.setMaximum(len(partIndicesOfThatPolymer))
self.analysiswidget.spectrumSelector.setValue(1)
self.analysiswidget.spectrumSelector.setMaximum(len(self.analysiswidget.particles2spectra[index]))
selectedPolymer = self.analysiswidget.currentPolymers[specIndex]
self.analysiswidget.polymerIndex = self.analysiswidget.uniquePolymers.index(selectedPolymer)
self.analysiswidget.polymerComboBox.setCurrentIndex(self.analysiswidget.polymerIndex)
#reconnect all widgets:
self.analysiswidget.particleSelector.valueChanged.connect(self.analysiswidget.selectParticle)
self.analysiswidget.spectrumSelector.valueChanged.connect(self.analysiswidget.selectSpectrum)
self.analysiswidget.polymerComboBox.currentIndexChanged.connect(self.analysiswidget.displayNewPolymerType)
self.analysiswidget.updateSpecPlot(centerOn=centerOn)
def prepareAnalysis(self):
self.clearItems()
......
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