https://github.com/jefferis/AnalysisSuite
Revision 1fbadb65493c933f25e719b67a64723e318658c4 authored by Gregory Jefferis on 30 January 2014, 21:35:04 UTC, committed by Gregory Jefferis on 30 January 2014, 21:35:04 UTC
1 parent fccf6f6
Tip revision: 1fbadb65493c933f25e719b67a64723e318658c4 authored by Gregory Jefferis on 30 January 2014, 21:35:04 UTC
Deprecate Read/WriteAmiraLandmarks in favour of nat
Deprecate Read/WriteAmiraLandmarks in favour of nat
Tip revision: 1fbadb6
ShowClones.scro
# Amira-Script-Object V3.0
# Master script object to load density files (amiramesh) for different clones
# To use this:
# 1) Prepare a directory containing density files for the clones
# Give them short names (eg aSP3g_F.am)
# and make sure they all have the same suffix
# 2) Load in a copy of the script which makes a little object
# 3) Specify a filename - one of the density files in your directory
# 4) Click LoadAll
# 5) HideAll/ShowAll will show hide the volume renderings
# 6) You can also use the checkboxes
# 7) You can use the setCloneColour function in the TCL window
# e.g. ShowClones.scro setCloneColour "aSP3-c_F" 0 1 0.843137254901961
# 8) you can put a bunch of these commands into a tcl script (name ends in .hx)
# See: setCloneColourExampleScript.hx for an example
# 9) You can also use R to set colours, see RainbowColourCloneScript() in FruMARCMCode
# R can even do the equivalent of dragging and dropping the script onto Amira
# for you by system(paste("open",hxscriptfilename))
# 10) You can have multiple script objects referring to multiple directories if you want
# so long as none of the density files have the same name
# 11) You may want to change the name of each script object if you have more than 1 eg
# ShowClones.scro setLabel "Dimorphic"
# ShowClones2.scro setLabel "Regular"
$this proc constructor { } {
global this
$this newPortFilename filename
$this filename setValue /Volumes/JData/JPeople/Sebastian/fruitless/Registration/IS2Reg/CanonicalClones-resampled/M/AL-a_M.am
$this newPortButtonList Action 5
$this Action setLabel Action:
$this Action setLabel 0 LoadAll
$this Action setLabel 1 Remove
$this Action setLabel 2 Flip
$this Action setLabel 3 HideAll
$this Action setLabel 4 Male
$this newPortFloatSlider red
$this red setMinMax 0 1
$this newPortFloatSlider green
$this green setMinMax 0 1
$this newPortFloatSlider blue
$this blue setMinMax 0 1
# $this newPortFloatSlider width
# $this width setMinMax 0 2.5
# $this width setValue 1
#
# $this newPortIntSlider ScoreThreshold
# $this ScoreThreshold setMinMax 0 4
# $this ScoreThreshold setValue 4
$this setVar dirName ""
$this setVar lafObjectList ""
$this setVar fileList ""
$this setVar glomTogList ""
$this setVar glomActive ""
# the default axis to flip over (0=X, 1=Y ...)
$this setVar flipAxis 0
# $this setVar thresholds ""
# $this setVar widths ""
# $this newPortInfo numObjects
# $this updateNumObjects
}
$this proc compute { } {
if { [ $this Action isNew ] && [$this Action getValue]==0 } {
$this makeFileListFromDir
$this loadFiles
# $this updateNumObjects
}
if { [ $this Action isNew ] && [$this Action getValue]==1} {
$this removeAllData
}
if { [ $this Action isNew ] && [$this Action getValue]==2} {
# flip
$this flipActiveClones [$this getVar flipAxis]
}
if { [ $this Action isNew ] && [$this Action getValue]==3} {
if { [ $this Action getLabel 3]=="ShowAll" } {
$this showLineViews 1
} elseif {[ $this Action getLabel 3]=="HideAll" } {
$this showLineViews 0
}
# $this updateNumObjects
}
if { [ $this Action isNew ] && [$this Action getValue]==4} {
if { [ $this Action getLabel 4]=="Male" } {
$this showMale 1
$this Action setLabel 4 Female
} elseif {[ $this Action getLabel 4]=="Female" } {
$this showMale 0
$this Action setLabel 4 Male
}
}
# if { [ $this ScoreThreshold isNew ] } {
# # $this updateLafObjectsThreshold
# $this updateNumObjects
# }
if { [ $this red isNew ] || [ $this green isNew ] || [ $this blue isNew ] } {
$this updateLafObjectsColor
}
if {[$this Action getValue] != 4} {
set glomActive ""
foreach glomTog [$this getVar glomTogList] {
for {set i 0} {$i < 6} {incr i} {
set obj [$this $glomTog getLabel $i]
#echo "checking obj $obj"
if {[exists $obj]} {
#echo "obj $obj exists"
if {[ $this $glomTog isNew ]} {
$obj setViewerMask [$this $glomTog getValue $i]
}
if {[$this $glomTog getValue $i]} {
lappend glomActive [$this $glomTog getLabel $i]
#echo [concat "added " [$this $glomTog getLabel $i]]
}
}
}
}
$this setVar glomActive $glomActive
}
# echo $glomActive
# uncomment to turn on continuous update
# $this myupdate
}
$this proc showLineViews {mask} {
set glomActive ""
foreach glomTog [$this getVar glomTogList] {
for {set i 0} {$i < 6} {incr i} {
set obj [$this $glomTog getLabel $i]
#echo "checking obj $obj"
if {[exists $obj]} {
#echo "obj $obj exists"
$this $glomTog setValue $i $mask
if {$mask} {
lappend glomActive [$this $glomTog getLabel $i]
#echo [concat "added " [$this $glomTog getLabel $i]]
}
}
}
}
$this setVar glomActive $glomActive
if {$mask == 0} { $this Action setLabel 3 ShowAll}
if {$mask == 1} { $this Action setLabel 3 HideAll}
}
# $this proc updateNumObjects {} {
# set numObjects 0
# foreach lafObject [$this getVar lafObjectList] {
# if {[exists $lafObject]} {
# set numObjects [expr $numObjects + 1]
# }
# }
# $this setVar numObjects $numObjects
# }
# $this proc updateLafObjectsThreshold {} {
# foreach glom [$this getVar glomActive] {
# if {[exists $glom]} {
# $glom ScoreThreshold setValue [$this ScoreThreshold getValue]
# $glom fire
# }
# }
# }
$this proc updateLafObjectsColor {} {
foreach clone [$this getVar glomActive] {
$this setCloneColour $clone [$this red getValue] [$this green getValue] [$this blue getValue]
}
}
$this proc setCloneColour { clone r g b } {
if {[exists $clone]} {
# change upper range to trick amira into updating colours
set upperrange [$clone range getValue 1]
$clone range setValue 1 [expr $upperrange - 1]
$clone range setValue 1 $upperrange
$clone colormap setDefaultColor $r $g $b
$clone colormap setDefaultAlpha 0.35
$clone fire
}
}
$this proc flipClone { clone axis } {
set data [$clone data source]
if {[exists $data]} {
$data flip $axis
$clone doIt hit
$clone fire
}
}
$this proc flipActiveClones { axis } {
set glomActive ""
foreach clone [$this getVar glomActive] {
$this flipClone $clone $axis
}
}
$this proc setCloneVoltexRange { clone lower upper } {
if {[exists $clone]} {
$clone range setValue 0 $lower
$clone range setValue 1 $upper
$clone fire
}
}
$this proc setAllCloneVoltexRanges { lower upper } {
set glomActive ""
foreach clone [$this getVar glomActive] {
$this setCloneVoltexRange $clone $lower $upper
}
}
$this proc setCloneAlphaScale { clone alpha } {
if {[exists $clone]} {
$clone setAlphaScale $alpha
$clone fire
}
}
$this proc setAllCloneAlphaScales { alpha } {
set glomActive ""
foreach clone [$this getVar glomActive] {
$this setCloneAlphaScale $clone $alpha
}
}
$this proc setCloneColormapAlpha { clone alpha } {
if {[exists $clone]} {
$clone colormap setDefaultAlpha $alpha
$clone fire
}
}
$this proc setAllCloneColormapAlphas { alpha } {
set glomActive ""
foreach clone [$this getVar glomActive] {
$this setCloneColormapAlpha $clone $alpha
}
}
$this proc showClone { clone mask } {
if {[exists $clone]} {
$clone setViewerMask $mask
}
}
$this proc updateTogglesFromList {glomActive} {
foreach glomTog [$this getVar glomTogList] {
for {set i 0} {$i < 6} {incr i} {
set obj [$this $glomTog getLabel $i]
if {[exists $obj]} {
if {[lsearch -exact $glomActive $obj] > -1} {
# echo "found $obj, turning it on"
$obj setViewerMask 1
$this $glomTog setValue $i 1
} else {
# echo "Didn't find $obj, turning it off"
$obj setViewerMask 0
$this $glomTog setValue $i 0
}
}
}
}
}
$this proc showMale {mask} {
# mask = 1 for male, 0 for female
set glomActive ""
foreach clone [$this getVar glomActive] {
if {[exists $clone]} {
set cloneToAdd $clone
set sex [string index $clone end]
# echo "clone $clone exists with sex $sex"
if {$sex eq "M"} {
# echo "clone $clone is male"
if {$mask == 0} {
# we want to change to the female version
set trimmedName [string trimright $clone "M"]
append trimmedName "F"
set cloneToAdd $trimmedName
}
} elseif {$sex eq "F"} {
# echo "clone $clone is female"
if {$mask == 1} {
# we want to change to the male version
set trimmedName [string trimright $clone "F"]
append trimmedName "M"
set cloneToAdd $trimmedName
}
}
lappend glomActive $cloneToAdd
# echo "Appending $cloneToAdd"
}
}
$this updateTogglesFromList $glomActive
$this setVar glomActive $glomActive
}
$this proc removeAllData {} {
# remove all data files and viewers that we actually loaded/made
foreach datafile [$this getVar fileList] {
if {[exists $datafile]} { remove $datafile }
set glom [file rootname datafile]
if {[exists $glom]} { remove $glom }
}
# Delete toggles and list of active clones
$this setVar glomActive ""
foreach glomTog [$this getVar glomTogList] {
$this deletePort $glomTog
}
# Clear state variables
$this setVar lafObjectList ""
$this setVar fileList ""
$this setVar glomTogList ""
$this setVar glomActive ""
}
$this proc makeFileListFromDir {} {
set filename [ $this filename getValue ]
set fileList [glob [file dirname $filename]/*[file extension $filename]]
# set the instance variable fileList to the value of the local fileList
$this setVar fileList $fileList
$this setVar dirName [file dirname $filename]
}
$this proc loadFiles {} {
set fileList [$this getVar fileList]
set filesActuallyLoaded ""
set lafObjectList [$this getVar lafObjectList]
# set thresholds [$this getVar thresholds]
# set widths [$this getVar widths]
set xstart [lindex [$this getIconPosition] 0]
set ystart [lindex [$this getIconPosition] 1]
#echo $fileList
foreach file $fileList {
if {[file size $file] > 0} {
set splitFile [file split $file]
set justfilename [lindex $splitFile [expr [llength $splitFile]-1]]
if { [file isfile $file] == 0 } { continue }
set glom [file rootname $justfilename]
lappend lafObjectList $glom
set ypos [expr $ystart + [expr [llength $filesActuallyLoaded] * 20 ] + 20]
if { ![exists $justfilename] } {
set newModule [load $file]
# $newModule Action setValue 4
lappend filesActuallyLoaded $newModule
$newModule hideIcon
$newModule setIconPosition [expr $xstart + 50 ] $ypos
$newModule fire
}
if { ![exists $glom] } {
set lineView [create HxVoltex]
$lineView setIconPosition [expr $xstart] $ypos
$lineView data connect $newModule
# this removes the volume rendering type colour map (which is always attached)
$lineView colormap disconnect
$lineView doIt hit
$lineView fire
# this sets the constant colour settings (in the absence of attached colormap)
$lineView colormap disconnect
$lineView slices setValue 256
$lineView range setValue 0 15
$lineView range setValue 1 255
$lineView colormap setDefaultColor [$this red getValue] [$this green getValue] [$this blue getValue]
$lineView colormap setDefaultAlpha 0.35
# this is required to update the Voltex
$lineView doIt hit
$lineView fire
$lineView setLabel "$glom"
# lappend widths [$this width getValue]
}
}
}
#set hideNewModules 0
$this setVar lafObjectList $lafObjectList
# replace input file list with the ones that we actually loaded
$this setVar fileList $filesActuallyLoaded
$this makeCloneToggles
}
$this proc makeCloneToggles {} {
set lafObjectList [$this getVar lafObjectList]
set glomTogList ""
for {set i 0} {$i<[llength $lafObjectList]} { set i [expr $i + 6]} {
set j [expr $i / 6]
$this newPortToggleList "Clone$j" 6
lappend glomTogList "Clone$j"
for {set k 0} {[expr $k + $i] < [llength $lafObjectList]} { incr k} {
$this "Clone$j" setLabel $k [lindex $lafObjectList [expr $k + $i]]
$this "Clone$j" setValue $k 1
}
}
$this setVar glomTogList $glomTogList
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...