Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
92010646
Commit
92010646
authored
9 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
MelodicComponentGrid refactorings.
parent
013e9de8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/data/melodicresults.py
+3
-3
3 additions, 3 deletions
fsl/data/melodicresults.py
fsl/fsleyes/controls/melodicclassificationgrid.py
+65
-35
65 additions, 35 deletions
fsl/fsleyes/controls/melodicclassificationgrid.py
with
68 additions
and
38 deletions
fsl/data/melodicresults.py
+
3
−
3
View file @
92010646
...
@@ -240,7 +240,7 @@ class MelodicClassification(props.HasProperties):
...
@@ -240,7 +240,7 @@ class MelodicClassification(props.HasProperties):
def
addLabel
(
self
,
component
,
label
):
def
addLabel
(
self
,
component
,
label
):
labels
=
list
(
self
.
labels
[
component
])
labels
=
list
(
self
.
labels
[
component
])
comps
=
self
.
__components
.
get
(
label
,
[])
comps
=
list
(
self
.
__components
.
get
(
label
,
[])
)
if
label
in
labels
:
if
label
in
labels
:
return
return
...
@@ -258,7 +258,7 @@ class MelodicClassification(props.HasProperties):
...
@@ -258,7 +258,7 @@ class MelodicClassification(props.HasProperties):
def
removeLabel
(
self
,
component
,
label
):
def
removeLabel
(
self
,
component
,
label
):
labels
=
list
(
self
.
labels
[
component
])
labels
=
list
(
self
.
labels
[
component
])
comps
=
self
.
__components
.
get
(
label
,
[])
comps
=
list
(
self
.
__components
.
get
(
label
,
[])
)
if
label
not
in
labels
:
if
label
not
in
labels
:
return
return
...
@@ -270,7 +270,7 @@ class MelodicClassification(props.HasProperties):
...
@@ -270,7 +270,7 @@ class MelodicClassification(props.HasProperties):
self
.
__components
[
label
]
=
comps
self
.
__components
[
label
]
=
comps
log
.
debug
(
'
Label removed from component: {} <-> {}
'
.
format
(
component
,
log
.
debug
(
'
Label removed from component: {} <-> {}
'
.
format
(
component
,
label
))
label
))
def
clearLabels
(
self
,
component
):
def
clearLabels
(
self
,
component
):
...
...
This diff is collapsed.
Click to expand it.
fsl/fsleyes/controls/melodicclassificationgrid.py
+
65
−
35
View file @
92010646
...
@@ -101,7 +101,6 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
...
@@ -101,7 +101,6 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
if
not
isinstance
(
overlay
,
fslmelimage
.
MelodicImage
):
if
not
isinstance
(
overlay
,
fslmelimage
.
MelodicImage
):
return
return
self
.
__overlay
=
overlay
self
.
__overlay
=
overlay
display
=
self
.
_displayCtx
.
getDisplay
(
overlay
)
display
=
self
.
_displayCtx
.
getDisplay
(
overlay
)
opts
=
display
.
getDisplayOpts
()
opts
=
display
.
getDisplayOpts
()
...
@@ -128,29 +127,8 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
...
@@ -128,29 +127,8 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
"""
"""
overlay
=
self
.
__overlay
overlay
=
self
.
__overlay
lut
=
self
.
__lut
melclass
=
overlay
.
getICClassification
()
numComps
=
overlay
.
numComponents
()
numComps
=
overlay
.
numComponents
()
labels
=
[
l
.
name
()
for
l
in
lut
.
labels
]
colours
=
[
l
.
colour
()
for
l
in
lut
.
labels
]
# Compile lists of all the existing
# labels, and the colours for each one
for
i
in
range
(
numComps
):
for
label
in
melclass
.
getLabels
(
i
):
if
label
in
labels
:
continue
colour
=
self
.
__addNewLutLabel
(
label
).
colour
()
labels
.
append
(
label
)
colours
.
append
(
colour
)
for
i
in
range
(
len
(
colours
)):
colours
[
i
]
=
[
int
(
round
(
c
*
255
))
for
c
in
colours
[
i
]]
for
i
in
range
(
numComps
):
for
i
in
range
(
numComps
):
tags
=
texttag
.
TextTagPanel
(
self
.
__grid
,
tags
=
texttag
.
TextTagPanel
(
self
.
__grid
,
...
@@ -159,8 +137,6 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
...
@@ -159,8 +137,6 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
texttag
.
TTP_NO_DUPLICATES
|
texttag
.
TTP_NO_DUPLICATES
|
texttag
.
TTP_KEYBOARD_NAV
))
texttag
.
TTP_KEYBOARD_NAV
))
tags
.
SetOptions
(
labels
,
colours
)
# Store the component number on the tag
# Store the component number on the tag
# panel, so we know which component we
# panel, so we know which component we
# are dealing with in the __onTagAdded
# are dealing with in the __onTagAdded
...
@@ -170,19 +146,54 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
...
@@ -170,19 +146,54 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
self
.
__grid
.
SetText
(
i
,
0
,
str
(
i
))
self
.
__grid
.
SetText
(
i
,
0
,
str
(
i
))
self
.
__grid
.
SetWidget
(
i
,
1
,
tags
)
self
.
__grid
.
SetWidget
(
i
,
1
,
tags
)
for
label
in
melclass
.
getLabels
(
i
):
tags
.
AddTag
(
label
)
tags
.
Bind
(
texttag
.
EVT_TTP_TAG_ADDED_EVENT
,
self
.
__onTagAdded
)
tags
.
Bind
(
texttag
.
EVT_TTP_TAG_ADDED_EVENT
,
self
.
__onTagAdded
)
tags
.
Bind
(
texttag
.
EVT_TTP_TAG_REMOVED_EVENT
,
self
.
__onTagRemoved
)
tags
.
Bind
(
texttag
.
EVT_TTP_TAG_REMOVED_EVENT
,
self
.
__onTagRemoved
)
self
.
__refreshTags
()
self
.
Layout
()
self
.
Layout
()
def
__refreshTags
(
self
):
overlay
=
self
.
__overlay
melclass
=
overlay
.
getICClassification
()
numComps
=
overlay
.
numComponents
()
lut
=
self
.
__lut
labels
=
[
l
.
name
()
for
l
in
lut
.
labels
]
colours
=
[
l
.
colour
()
for
l
in
lut
.
labels
]
# Compile lists of all the existing
# labels, and the colours for each one
for
i
in
range
(
numComps
):
for
label
in
melclass
.
getLabels
(
i
):
if
label
in
labels
:
continue
colour
=
self
.
__addNewLutLabel
(
label
).
colour
()
labels
.
append
(
label
)
colours
.
append
(
colour
)
for
i
in
range
(
len
(
colours
)):
colours
[
i
]
=
[
int
(
round
(
c
*
255
))
for
c
in
colours
[
i
]]
for
row
in
range
(
numComps
):
tags
=
self
.
__grid
.
GetWidget
(
row
,
1
)
tags
.
ClearTags
()
tags
.
SetOptions
(
labels
,
colours
)
for
label
in
melclass
.
getLabels
(
row
):
tags
.
AddTag
(
label
)
def
__addNewLutLabel
(
self
,
label
,
colour
=
None
):
def
__addNewLutLabel
(
self
,
label
,
colour
=
None
):
"""
"""
"""
"""
lut
=
self
.
__lut
lut
=
self
.
__lut
value
=
lut
.
max
()
+
1
value
=
lut
.
max
()
+
1
...
@@ -193,8 +204,10 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
...
@@ -193,8 +204,10 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
lut
.
set
(
value
,
name
=
label
,
colour
=
colour
)
lut
.
set
(
value
,
name
=
label
,
colour
=
colour
)
lut
.
enableListener
(
'
labels
'
,
self
.
_name
)
lut
.
enableListener
(
'
labels
'
,
self
.
_name
)
return
lut
.
get
(
value
)
self
.
__refreshTags
(
)
return
lut
.
get
(
value
)
def
__onTagAdded
(
self
,
ev
):
def
__onTagAdded
(
self
,
ev
):
"""
"""
...
@@ -207,15 +220,25 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
...
@@ -207,15 +220,25 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
lut
=
self
.
__lut
lut
=
self
.
__lut
melclass
=
overlay
.
getICClassification
()
melclass
=
overlay
.
getICClassification
()
# Add the new label to the melodic component
melclass
.
disableListener
(
'
labels
'
,
self
.
_name
)
melclass
.
addLabel
(
component
,
label
)
# If the tag panel previously just contained
# the 'Unknown' tag, remove that tag
if
tags
.
TagCount
()
==
2
and
tags
.
HasTag
(
'
Unknown
'
):
melclass
.
removeLabel
(
component
,
'
Unknown
'
)
tags
.
RemoveTag
(
'
Unknown
'
)
melclass
.
enableListener
(
'
labels
'
,
self
.
_name
)
# If the newly added tag is not in
# the lookup table, add it in
if
lut
.
getByName
(
label
)
is
None
:
if
lut
.
getByName
(
label
)
is
None
:
colour
=
tags
.
GetTagColour
(
label
)
colour
=
tags
.
GetTagColour
(
label
)
colour
=
[
c
/
255.0
for
c
in
colour
]
colour
=
[
c
/
255.0
for
c
in
colour
]
self
.
__addNewLutLabel
(
label
,
colour
)
self
.
__addNewLutLabel
(
label
,
colour
)
melclass
.
disableListener
(
'
labels
'
,
self
.
_name
)
melclass
.
addLabel
(
component
,
label
)
melclass
.
enableListener
(
'
labels
'
,
self
.
_name
)
self
.
__grid
.
FitInside
()
self
.
__grid
.
FitInside
()
...
@@ -229,9 +252,16 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
...
@@ -229,9 +252,16 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
overlay
=
self
.
__overlay
overlay
=
self
.
__overlay
melclass
=
overlay
.
getICClassification
()
melclass
=
overlay
.
getICClassification
()
# Remove the label from
# the melodic component
melclass
.
disableListener
(
'
labels
'
,
self
.
_name
)
melclass
.
disableListener
(
'
labels
'
,
self
.
_name
)
melclass
.
removeLabel
(
component
,
label
)
melclass
.
removeLabel
(
component
,
label
)
melclass
.
enableListener
(
'
labels
'
,
self
.
_name
)
melclass
.
enableListener
(
'
labels
'
,
self
.
_name
)
# If the tag panel now has no tags,
# add the 'Unknown' tag back in.
if
tags
.
TagCount
()
==
0
:
tags
.
AddTag
(
'
Unknown
'
)
self
.
__grid
.
FitInside
()
self
.
__grid
.
FitInside
()
...
@@ -260,11 +290,11 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
...
@@ -260,11 +290,11 @@ class ComponentGrid(fslpanel.FSLEyesPanel):
def
__labelsChanged
(
self
,
*
a
):
def
__labelsChanged
(
self
,
*
a
):
self
.
__re
c
re
ate
Tags
()
self
.
__re
f
re
sh
Tags
()
def
__lutChanged
(
self
,
*
a
):
def
__lutChanged
(
self
,
*
a
):
self
.
__re
c
re
ate
Tags
()
self
.
__re
f
re
sh
Tags
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment