Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
GEPARD
GEPARD
Commits
a974f0be
Commit
a974f0be
authored
Jul 17, 2019
by
JosefBrandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfix in selection
parent
fcca6561
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
84 deletions
+88
-84
analysis/analysisview.py
analysis/analysisview.py
+2
-5
analysis/analysiswidgets.py
analysis/analysiswidgets.py
+4
-5
analysis/particleInfo.py
analysis/particleInfo.py
+10
-20
analysis/particleeditor.py
analysis/particleeditor.py
+56
-43
sampleview.py
sampleview.py
+9
-7
viewitems.py
viewitems.py
+7
-4
No files found.
analysis/analysisview.py
View file @
a974f0be
...
...
@@ -149,7 +149,6 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
navigationLayout
.
addWidget
(
QtWidgets
.
QLabel
(
'Select Spectrum'
))
navigationLayout
.
addWidget
(
self
.
spectrumSelector
)
navigationLayout
.
addWidget
(
self
.
spectrumNumberLabel
)
# navigationLayout.addStretch()
self
.
navigationGroup
.
setLayout
(
navigationLayout
)
...
...
@@ -579,14 +578,12 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
currentSpectrumIndex
=
self
.
specNumberSelector
.
value
()
-
1
self
.
currentParticleIndex
=
self
.
particleContainer
.
getParticleIndexContainingSpecIndex
(
self
.
currentSpectrumIndex
)
self
.
centerOnSpecIndex
(
self
.
currentSpectrumIndex
)
self
.
highLightContour
(
self
.
currentParticleIndex
)
self
.
viewparent
.
highLightContour
(
self
.
currentParticleIndex
)
self
.
updateSpecPlot
()
def
centerOnSpecIndex
(
self
,
index
):
self
.
viewparent
.
centerOnRamanIndex
(
index
)
def
highLightContour
(
self
,
index
):
self
.
viewparent
.
highLightContour
(
index
)
def
darkenBackground
(
self
):
self
.
viewparent
.
darkenPixmap
=
self
.
darkenAct
.
isChecked
()
...
...
analysis/analysiswidgets.py
View file @
a974f0be
...
...
@@ -37,7 +37,6 @@ class ExpExcelDialog(QtWidgets.QDialog):
self
.
dataset
=
dataset
self
.
particleContainer
=
particleContainer
# self.particles = self.datastats.getParticleStats()
self
.
polymers
=
self
.
particleContainer
.
getListOfParticleAssignments
# self.additives = self.datastats.currentAdditives
self
.
hqis
=
self
.
particleContainer
.
getListOfHighestHQIs
...
...
@@ -62,10 +61,10 @@ class ExpExcelDialog(QtWidgets.QDialog):
if
option
==
'Polymer Type (mandatory)'
:
self
.
checkBoxes
[
-
1
].
setEnabled
(
False
)
#is mandatory!!!
if
option
==
'Additives'
:
if
self
.
additives
is
None
:
self
.
checkBoxes
[
-
1
].
setEnabled
(
False
)
self
.
checkBoxes
[
-
1
].
setChecked
(
False
)
#
if option == 'Additives':
#
if self.additives is None:
#
self.checkBoxes[-1].setEnabled(False)
#
self.checkBoxes[-1].setChecked(False)
excelvbox
.
addWidget
(
self
.
checkBoxes
[
-
1
])
...
...
analysis/particleInfo.py
View file @
a974f0be
...
...
@@ -18,21 +18,13 @@ 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/>.
"""
#import os
import
numpy
as
np
import
operator
#from PyQt5 import QtWidgets, QtCore
#try:
# from dataset import loadData, recursiveDictCompare
# print('exported dataset methods from datastats')
#except:
# print('failed exported dataset methods from datastats')
class
ParticleContainer
(
object
):
def
__init__
(
self
,
p
arent
):
def
__init__
(
self
,
datasetP
arent
):
super
(
ParticleContainer
,
self
).
__init__
()
self
.
parent
=
p
arent
self
.
datasetParent
=
datasetP
arent
self
.
particles
=
[]
self
.
spectra
=
None
self
.
inconsistentParticles
=
[]
...
...
@@ -223,7 +215,7 @@ class ParticleContainer(object):
final_typehistogram
=
{
i
[
0
]:
i
[
1
]
for
i
in
sorted_typehistogram
}
return
final_typehistogram
def
m
ergeParticle
s
(
self
,
particleIndices
,
newContour
,
newStats
,
newAssignment
=
None
):
def
addM
erge
d
Particle
(
self
,
particleIndices
,
newContour
,
newStats
,
newAssignment
=
None
):
newParticle
=
Particle
()
#copy Measurements
for
index
in
particleIndices
:
...
...
@@ -243,22 +235,16 @@ class ParticleContainer(object):
newParticle
.
area
=
area
newParticle
.
contour
=
newContour
self
.
removeParticles
(
particleIndices
)
print
(
'removed particles'
)
self
.
particles
.
append
(
newParticle
)
print
(
'added new particle'
)
self
.
resetParticleIndices
()
print
(
'resetted indices'
)
def
removeParticles
(
self
,
indexList
):
for
index
in
sorted
(
indexList
,
reverse
=
True
):
particle
=
self
.
getParticleOfIndex
(
index
)
#just for asserting to have the correct particle!
del
self
.
particles
[
index
]
def
removeParticle
(
self
,
index
):
particle
=
self
.
getParticleOfIndex
(
index
)
#just for asserting to have the correct particle!
del
self
.
particles
[
index
]
def
resetParticleIndices
(
self
):
for
newIndex
,
particle
in
enumerate
(
self
.
particles
):
particle
.
index
=
newIndex
class
Particle
(
object
):
def
__init__
(
self
):
...
...
@@ -271,6 +257,7 @@ class Particle(object):
self
.
area
=
None
self
.
contour
=
None
self
.
measurements
=
[]
self
.
viewItem
=
None
def
addExistingMeasurement
(
self
,
meas
):
self
.
measurements
.
append
(
meas
)
...
...
@@ -362,6 +349,9 @@ class Particle(object):
for
measurement
in
self
.
measurements
:
measurement
.
applyHQIThreshold
(
minHQI
)
# def recreateViewItem(self):
# pass
class
Measurement
(
object
):
def
__init__
(
self
):
...
...
analysis/particleeditor.py
View file @
a974f0be
...
...
@@ -29,7 +29,27 @@ import numpy as np
import
cv2
from
PyQt5
import
QtWidgets
,
QtCore
from
analysis.particlePainter
import
ParticlePainter
from
.particlePainter
import
ParticlePainter
def
getContourStatsWithPixelScale
(
contours
,
pixelscale
):
##characterize particle
longellipse
,
shortellipse
=
np
.
nan
,
np
.
nan
cnt
=
contours
if
cnt
.
shape
[
0
]
>=
5
:
##at least 5 points required for ellipse fitting...
ellipse
=
cv2
.
fitEllipse
(
cnt
)
shortellipse
,
longellipse
=
ellipse
[
1
]
rect
=
cv2
.
minAreaRect
(
cnt
)
long
,
short
=
rect
[
1
]
if
short
>
long
:
long
,
short
=
short
,
long
area
=
cv2
.
contourArea
(
cnt
)
return
long
*
pixelscale
,
short
*
pixelscale
,
longellipse
*
pixelscale
,
shortellipse
*
pixelscale
,
area
*
pixelscale
**
2
class
ParticleContextMenu
(
QtWidgets
.
QMenu
):
combineParticlesSignal
=
QtCore
.
pyqtSignal
(
list
,
str
)
...
...
@@ -110,7 +130,6 @@ class ParticleContextMenu(QtWidgets.QMenu):
class
ParticleEditor
(
QtCore
.
QObject
):
# particleContoursChanged = QtCore.pyqtSignal()
particleAssignmentChanged
=
QtCore
.
pyqtSignal
()
def
__init__
(
self
,
viewparent
,
particleContainer
):
super
(
ParticleEditor
,
self
).
__init__
()
...
...
@@ -142,19 +161,15 @@ class ParticleEditor(QtCore.QObject):
self
.
createSafetyBackup
()
print
(
f
'Combining particles
{
contourIndices
}
into
{
newAssignment
}
'
)
contours
=
self
.
particleContainer
.
getParticleContoursByIndex
(
contourIndices
)
newContour
=
self
.
mergeContours
(
contours
.
copy
())
try
:
newContour
=
self
.
mergeContours
(
contours
.
copy
())
except
NotConnectedContoursError
:
return
pixelscale
=
self
.
viewparent
.
dataset
.
getPixelScale
()
stats
=
self
.
characterizePartic
le
(
newContour
,
pixelscale
)
stats
=
getContourStatsWithPixelSca
le
(
newContour
,
pixelscale
)
self
.
particleContainer
.
mergeParticles
(
contourIndices
,
newContour
,
stats
,
newAssignment
=
newAssignment
)
for
ind
in
contourIndices
:
self
.
viewparent
.
removeParticleContour
(
ind
)
self
.
viewparent
.
resetContourIndices
()
self
.
viewparent
.
addParticleContour
(
newContour
,
len
(
self
.
viewparent
.
contourItems
))
self
.
particleAssignmentChanged
.
emit
()
#TODO: INCLUDE SANITY CHECK!!!!!!!!!
self
.
mergeParticlesInParticleContainerAndSampleView
(
contourIndices
,
newContour
,
stats
,
newAssignment
)
@
QtCore
.
pyqtSlot
(
list
,
str
)
def
reassignParticles
(
self
,
contourindices
,
newAssignment
):
...
...
@@ -167,7 +182,8 @@ class ParticleEditor(QtCore.QObject):
@
QtCore
.
pyqtSlot
(
list
,
str
)
def
paintParticles
(
self
,
contourIndices
,
newAssignment
):
self
.
createSafetyBackup
print
(
f
'painting indices
{
contourIndices
}
into
{
newAssignment
}
'
)
self
.
createSafetyBackup
()
self
.
storedIndices
=
contourIndices
self
.
storedAssignmend
=
newAssignment
contours
=
self
.
particleContainer
.
getParticleContoursByIndex
(
contourIndices
)
...
...
@@ -178,19 +194,19 @@ class ParticleEditor(QtCore.QObject):
self
.
viewparent
.
update
()
def
acceptPaintedResult
(
self
):
newContour
=
self
.
mergeContours
(
self
.
particlePainter
.
contours
.
copy
())
pixelscale
=
self
.
viewparent
.
dataset
.
getPixelScale
()
stats
=
self
.
characterizeParticle
(
newContour
,
pixelscale
)
try
:
newContour
=
self
.
mergeContours
(
self
.
particlePainter
.
contours
.
copy
())
except
NotConnectedContoursError
:
self
.
storedIndices
=
[]
self
.
storedAssignmend
=
None
self
.
destroyParticlePainter
()
return
self
.
particleContainer
.
mergeParticles
(
self
.
storedIndices
,
newContour
,
stats
,
newAssignment
=
self
.
storedAssignmend
)
for
ind
in
self
.
storedIndices
:
self
.
viewparent
.
removeParticleContour
(
ind
)
pixelscale
=
self
.
viewparent
.
dataset
.
getPixelScale
()
stats
=
getContourStatsWithPixelScale
(
newContour
,
pixelscale
)
self
.
particleAssignmentChanged
.
emit
()
self
.
viewparent
.
resetContourIndices
()
self
.
viewparent
.
addParticleContour
(
newContour
,
len
(
self
.
viewparent
.
contourItems
))
self
.
mergeParticlesInParticleContainerAndSampleView
(
self
.
storedIndices
,
newContour
,
stats
,
self
.
storedAssignmend
)
#TODO: INCLUDE SANITY CHECK!!!!!!!!!
self
.
storedIndices
=
[]
self
.
storedAssignmend
=
None
self
.
destroyParticlePainter
()
...
...
@@ -230,7 +246,7 @@ class ParticleEditor(QtCore.QObject):
if
len
(
contours
)
>
1
:
QtWidgets
.
QMessageBox
.
critical
(
self
.
viewparent
,
'ERROR!'
,
'Particle contours are not connected and cannot be combined!'
)
r
eturn
r
aise
NotConnectedContoursError
newContour
=
contours
[
0
]
for
i
in
range
(
len
(
newContour
)):
...
...
@@ -238,26 +254,20 @@ class ParticleEditor(QtCore.QObject):
newContour
[
i
][
0
][
1
]
+=
ymin
-
padding
return
newContour
def
mergeParticlesInParticleContainerAndSampleView
(
self
,
indices
,
newContour
,
stats
,
assignment
):
self
.
viewparent
.
addParticleContourToIndex
(
newContour
,
len
(
self
.
viewparent
.
contourItems
)
-
1
)
self
.
particleContainer
.
addMergedParticle
(
indices
,
newContour
,
stats
,
newAssignment
=
assignment
)
def
characterizeParticle
(
self
,
contours
,
pixelscale
):
##characterize particle
longellipse
,
shortellipse
=
np
.
nan
,
np
.
nan
cnt
=
contours
if
cnt
.
shape
[
0
]
>=
5
:
##at least 5 points required for ellipse fitting...
ellipse
=
cv2
.
fitEllipse
(
cnt
)
shortellipse
,
longellipse
=
ellipse
[
1
]
rect
=
cv2
.
minAreaRect
(
cnt
)
long
,
short
=
rect
[
1
]
if
short
>
long
:
long
,
short
=
short
,
long
for
ind
in
sorted
(
indices
,
reverse
=
True
):
self
.
viewparent
.
removeParticleContour
(
ind
)
self
.
particleContainer
.
removeParticle
(
ind
)
area
=
cv2
.
contourArea
(
cnt
)
self
.
viewparent
.
resetContourIndices
()
self
.
particleContainer
.
resetParticleIndices
()
self
.
particleAssignmentChanged
.
emit
()
#TODO: INCLUDE SANITY CHECK!!!!!!!!!
return
long
*
pixelscale
,
short
*
pixelscale
,
longellipse
*
pixelscale
,
shortellipse
*
pixelscale
,
area
*
pixelscale
**
2
@
QtCore
.
pyqtSlot
(
list
)
def
deleteParticles
(
self
,
contourIndices
):
reply
=
QtWidgets
.
QMessageBox
.
question
(
self
,
f
'About to delete
{
len
(
contourIndices
)
}
particles.'
,
...
...
@@ -272,6 +282,9 @@ class ParticleEditor(QtCore.QObject):
self
.
viewparent
.
dataset
.
particleContainer
.
resetParticleIndices
()
self
.
viewparent
.
resetContourIndices
()
self
.
viewparent
.
analysiswidget
.
updateHistogramsAndContours
()
class
NotConnectedContoursError
(
Exception
):
pass
\ No newline at end of file
sampleview.py
View file @
a974f0be
...
...
@@ -422,10 +422,12 @@ class SampleView(QtWidgets.QGraphicsView):
removeContourFromSelection
(
cnt
)
else
:
#not clicked on particle
if
event
.
modifiers
()
!=
QtCore
.
Qt
.
ShiftModifier
and
cnt
.
particleIndex
in
self
.
selectedParticleIndices
:
removeContourFromSelection
(
cnt
)
if
event
.
modifiers
()
!=
QtCore
.
Qt
.
ShiftModifier
:
cnt
.
isSelected
=
False
cnt
.
update
()
if
cnt
.
particleIndex
in
self
.
selectedParticleIndices
:
self
.
selectedParticleIndices
.
remove
(
cnt
.
particleIndex
)
self
.
update
()
def
scaleImage
(
self
,
factor
):
...
...
@@ -584,11 +586,11 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
contourItems
=
[]
if
self
.
dataset
is
not
None
:
for
particleIndex
,
contour
in
enumerate
(
self
.
dataset
.
particleContainer
.
getParticleContours
()):
self
.
addParticleContour
(
contour
,
particleIndex
)
self
.
addParticleContour
ToIndex
(
contour
,
particleIndex
)
self
.
update
()
print
(
'resetted contours: {} ms'
.
format
(
round
((
time
.
time
()
-
t0
)
*
1000
)))
def
addParticleContour
(
self
,
contour
,
index
):
def
addParticleContour
ToIndex
(
self
,
contour
,
index
):
newCnt
=
SegmentationContour
(
self
,
contour
)
newCnt
.
setIndex
(
index
)
assignment
=
self
.
dataset
.
particleContainer
.
getParticleAssignmentByIndex
(
index
)
...
...
@@ -616,10 +618,10 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
ramanscanitems
[
index
].
setHighLight
(
True
)
def
highLightContour
(
self
,
index
):
print
(
'highlighting contour'
,
index
)
for
contour
in
self
.
contourItems
:
contour
.
isSelected
=
False
self
.
contourItems
[
index
].
isSelected
=
True
self
.
selectedParticleIndices
=
[
index
]
def
centerOnRamanIndex
(
self
,
index
,
centerOn
=
True
,
highlightIndex
=
True
):
if
centerOn
:
...
...
viewitems.py
View file @
a974f0be
...
...
@@ -23,9 +23,9 @@ from PyQt5 import QtCore, QtWidgets, QtGui
from
analysis.particleeditor
import
ParticleContextMenu
class
SegmentationContour
(
QtWidgets
.
QGraphicsItem
):
def
__init__
(
self
,
parent
,
contourData
,
pos
=
(
0
,
0
)):
def
__init__
(
self
,
view
parent
,
contourData
,
pos
=
(
0
,
0
)):
super
().
__init__
()
self
.
parent
=
parent
self
.
view
parent
=
view
parent
self
.
setZValue
(
1
)
self
.
setPos
(
pos
[
0
],
pos
[
1
])
self
.
setFlag
(
QtWidgets
.
QGraphicsItem
.
ItemIsSelectable
)
...
...
@@ -56,6 +56,9 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
def
boundingRect
(
self
):
return
self
.
brect
# def createRamanScanIndices(self):
def
setIndex
(
self
,
index
):
self
.
particleIndex
=
index
...
...
@@ -89,8 +92,8 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
def
contextMenuEvent
(
self
,
event
):
if
self
.
isSelected
:
self
.
contextMenu
=
ParticleContextMenu
(
self
.
parent
)
self
.
parent
.
particleEditor
.
connectToSignals
(
self
.
contextMenu
)
self
.
contextMenu
=
ParticleContextMenu
(
self
.
view
parent
)
self
.
view
parent
.
particleEditor
.
connectToSignals
(
self
.
contextMenu
)
self
.
contextMenu
.
executeAtScreenPos
(
event
.
screenPos
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment