Commit 2c03c3ce authored by Josef Brandt's avatar Josef Brandt

Preparation for reorganizing contours and scanIndices

Have it managed by the particle!
parent ca5e6bad
......@@ -23,10 +23,6 @@ from PyQt5 import QtWidgets, QtGui, QtCore
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import os
import numpy as np
from analysis import importSpectra
class ParticleIndicator(QtWidgets.QPushButton):
......@@ -132,31 +128,8 @@ class SpectraPlot(QtWidgets.QGroupBox):
self.setLayout(layout)
def loadSpectraAndInitializeSpecPlot(self): #formerly updateData(self)....
# def tryLoadingNumpySpecFile():
# specPath = self.dataset.getSpectraFileName()
# if os.path.exists(specPath):
# return np.load(specPath)
# else:
# raise ImportError
# try:
# self.spectra = tryLoadingNumpySpecFile()
# except ImportError:
#
# fname = QtWidgets.QFileDialog.getOpenFileName(QtWidgets.QWidget(), 'Select Spectra File', self.dataset.path, 'text file (*.txt)')[0]
#
# try:
# self.spectra, spectraNames = importSpectra.importWITecSpectra(fname)
# except ImportError:
# try:
# self.spectra, spectraNames = importSpectra.importRenishawSpectra(fname)
# except ImportError:
# self.spectra, spectraNames = importSpectra.importPerkinElmerSpectra(fname)
#
# if self.spectra is None:
# raise ImportError
# else:
# np.save(self.dataset.getSpectraFileName(), self.spectra)
self.spectra = self.dataset.particleContainer.spectra
assert self.spectra is not None
self.canvas.draw()
def updateParticleSpectrum(self, specIndex, particleSize, hqi):
......
......@@ -32,7 +32,6 @@ from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as Navigatio
from .analysiswidgets import ExpExcelDialog
from .analysisplots import TypeHistogramView, SpectraPlot
from .loadresults import LoadTrueMatchResults
from .particleeditor import ParticleEditor
from .database import DataBaseWindow
from .colorlegend import getColorFromNameWithSeed
......@@ -56,7 +55,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.viewparent = viewparent
self.dataset = dataset
self.particleContainer = dataset.particleContainer
self.editor = ParticleEditor(self.particleContainer, self)
# self.additivePlot = None
self.importWindow = None
......@@ -221,6 +219,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.createMenus()
self.applyHQIThresholdToResults()
self.createHistogramData()
self.particleContainer.loadSpectra()
self.initializeSpecPlot()
self.setTypeSelector()
self.updateHistogramsAndContours()
......@@ -556,7 +555,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self.currentParticleIndex = particleIndex
partIndices = self.particleContainer.getIndicesOfParticleType(assignment)
self.particleSelector.setMaximum(len(partIndices))
self.particleNumberLabel.setText(f'of {len(partIndices)} particles; ')
self.particleSelector.setValue(partIndices.index(particleIndex)+1)
......
......@@ -19,7 +19,7 @@ along with this program, see COPYING.
If not, see <https://www.gnu.org/licenses/>.
"""
import numpy as np
from viewitems import SegmentationContour, RamanScanIndicator
class Particle(object):
def __init__(self):
......@@ -35,23 +35,9 @@ class Particle(object):
self.viewItem = None
def addMeasurement(self, refToMeasurement):
refToMeasurement.assignedParticle = self
self.measurements.append(refToMeasurement)
# def addExistingMeasurement(self, meas):
# self.measurements.append(meas)
#
# def addEmptyMeasurement(self):
# self.measurements.append(Measurement())
# indexOfNewMeasurment = len(self.measurements)-1
# return indexOfNewMeasurment
# def setMeasurementScanIndex(self, indexOfMeasurment, scanIndex):
# self.measurements[indexOfMeasurment].ramanScanIndex = scanIndex
#
# def setMeasurementPixelCoords(self, indexOfMeasurment, x, y):
# self.measurements[indexOfMeasurment].pixelcoord_x= x
# self.measurements[indexOfMeasurment].pixelcoord_y = y
#
def setAllSpectraToNewAssignment(self, newAssignment):
for meas in self.measurements:
meas.setAssignment(newAssignment)
......@@ -127,8 +113,8 @@ class Particle(object):
for measurement in self.measurements:
measurement.applyHQIThreshold(minHQI)
# def recreateViewItem(self):
# pass
def recreateViewItem(self):
self.viewItem = SegmentationContour()
class Measurement(object):
......@@ -141,6 +127,8 @@ class Measurement(object):
self.assignment_orig = 'Not Evaluated'
self.assignment_afterHQI = None
self.hqi = None
self.assignedParticle = None
def setAssignment(self, assignment):
self.assignment_orig = assignment
......
......@@ -178,9 +178,10 @@ class ParticleContainer(object):
def getMeasurementPixelCoords(self):
coords = []
for particle in self.particles:
for measurement in particle.getMeasurements():
coords.append([measurement.pixelcoord_x, measurement.pixelcoord_y])
# for particle in self.particles:
# for measurement in particle.getMeasurements():
for meas in self.measurements:
coords.append([meas.pixelcoord_x, meas.pixelcoord_y])
return coords
def getNumberOfParticlesOfAssignment(self, assignment):
......@@ -269,7 +270,7 @@ class ParticleContainer(object):
if newAssignment is not None:
meas.setAssignment(newAssignment)
meas.setHQI(100)
newParticle.addExistingMeasurement(meas)
newParticle.addMeasurement(meas)
#set Particle Stats
long, short, longellipse, shortellipse, area = newStats
......
......@@ -24,7 +24,7 @@ import numpy as np
import cv2
from helperfunctions import cv2imread_fix, cv2imwrite_fix
from copy import copy
from analysis.particleInfo import ParticleContainer
from analysis.particleContainer import ParticleContainer
currentversion = 3
......
......@@ -677,7 +677,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
self.dataset.ramanpoints = measurementPoints #consider moving that to particleContainer
# self.dataset.ramanpoints = measurementPoints #consider moving that to particleContainer
# self.dataset.particlecontours = contours
# self.dataset.particlestats = particlestats
# self.dataset.ramanscansortindex = []
......
......@@ -100,13 +100,23 @@ class GEPARDMainWindow(QtWidgets.QMainWindow):
fileName = QtWidgets.QFileDialog.getSaveFileName(self, "Create New Project",
defaultPath, "*.pkl")[0]
if fileName:
# if fileName.find(' ') < 0:
self.fname = str(fileName) #TODO: No spaces for Renishaw Interface!!
self.view.new(self.fname)
self.scalingChanged(1.)
# else:
# QtWidgets.QMessageBox.critical(self, "Error", "File path must not contain spaces.")
isValid, msg = self.testFilename(fileName)
if isValid:
self.fname = str(fileName) #TODO: No spaces for Renishaw Interface!!
self.view.new(self.fname)
self.scalingChanged(1.)
else:
QtWidgets.QMessageBox.critical(self, "Error", msg)
def testFilename(self, fileName):
if self.view.ramanctrl.name == 'RenishawCOM': #the renishawCom does not allow Spaces within filePath
if fileName.find(' ') == 0:
return False, "File path must not contain spaces."
else:
return True, ""
else:
return True, ""
@QtCore.pyqtSlot()
def about(self):
QtWidgets.QMessageBox.about(self, 'GEPARD',
......
......@@ -47,6 +47,7 @@ class WITecCOM(RamanBase):
def __init__(self, hostname=None):
super().__init__()
self.name = 'WITecCOM'
if hostname is None:
hostname = gethostname()
self.IBUCSAccess = win32com.client.DispatchEx(self.CLSID, machine=hostname,
......
......@@ -21,6 +21,7 @@ If not, see <https://www.gnu.org/licenses/>.
class RamanBase(object):
def __init__(self):
self.name = None
self.connected = False
self.timeseries = False
......
......@@ -32,6 +32,7 @@ class SimulatedRaman(RamanBase):
ramanParameters = {}
def __init__(self):
super().__init__()
self.name = 'SimulatedRaman'
self.currentpos = None, 0., 0.
self.currentZ = 0.
# some plausible data to simulate consecutively changing positions
......
......@@ -232,16 +232,8 @@ class RamanScanUI(QtWidgets.QWidget):
if reply == QtWidgets.QMessageBox.Yes:
self.dataset.mode = "ramanscan"
measurements2particles = [[int(np.where(cmin == i)[0])] for i in range(len(cmin))] #i.e., list of scanIndicesPerParticle
for particleIndex, listOfScanIndices in enumerate(measurements2particles):
# curParticle = self.particleContainer.getParticleOfIndex(particleIndex)
for scanIndex in listOfScanIndices:
self.particleContainer.setMeasurementScanIndex(indexOfNewMeas, scanIndex)
for measIndex, ramanScanIndex in enumerate(cmin):
self.particleContainer.setMeasurementScaneIndex(measIndex, ramanScanIndex)
# self.dataset.ramanscansortindex = cmin
self.dataset.saveParticleData()
......
......@@ -34,9 +34,8 @@ from zeissimporter import ZeissImporter
from viewitems import FitPosIndicator, Node, Edge, ScanIndicator, RamanScanIndicator, SegmentationContour
from analysis.colorlegend import getColorFromNameWithSeed
from helperfunctions import polygoncovering, cv2imread_fix
from ramancom.configRaman import RamanConfigWin
from analysis.particleeditor import ParticleEditor
from analysis.particleEditor import ParticleEditor
class SampleView(QtWidgets.QGraphicsView):
......@@ -412,6 +411,7 @@ class SampleView(QtWidgets.QGraphicsView):
p = QtCore.QPointF(p.x(), p.y())
for index, cnt in enumerate(self.contourItems):
if cnt.polygon.containsPoint(p, QtCore.Qt.OddEvenFill): #clicked on particle
if not event.modifiers()==QtCore.Qt.ShiftModifier:
acceptSelection(cnt)
......
......@@ -20,7 +20,7 @@ If not, see <https://www.gnu.org/licenses/>.
"""
#import numpy as np
from PyQt5 import QtCore, QtWidgets, QtGui
from analysis.particleeditor import ParticleContextMenu
from analysis.particleEditor import ParticleContextMenu
class SegmentationContour(QtWidgets.QGraphicsItem):
def __init__(self, viewparent, contourData, pos=(0,0)):
......@@ -128,15 +128,15 @@ class FitPosIndicator(QtWidgets.QGraphicsItem):
class RamanScanIndicator(QtWidgets.QGraphicsItem):
def __init__(self, view, number, radius, pos=(0,0)):
super().__init__()
# self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
self.setZValue(100) #higher numbers will be in foreground. Shall always be in foreground!
self.setZValue(100) #higher zValues will be in foreground. Shall always be in foreground!
self.view = view
self.number = number
self.radius = radius
self.highlight = False
self.hidden = False
self.setPos(pos[0], pos[1])
self.hasNoParticleAssigned = False
def setHighLight(self, highlight):
if highlight!=self.highlight:
......@@ -157,6 +157,9 @@ class RamanScanIndicator(QtWidgets.QGraphicsItem):
if self.highlight:
painter.setPen(QtCore.Qt.red)
painter.setBrush(QtGui.QColor(100,250,100,150))
elif self.hasNoParticleAssigned:
painter.setPen(QtCore.Qt.black)
painter.setBrush(QtCore.Qt.red)
else:
painter.setPen(QtCore.Qt.green)
painter.setBrush(QtGui.QColor(50,50,250,150))
......
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