-
Notifications
You must be signed in to change notification settings - Fork 0
/
tform_export.rc
158 lines (106 loc) · 3.87 KB
/
tform_export.rc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#
# export Transformation of a data object to a text file
proc onKeyF3 { } {
# echo "Key F3 was hit"
# find currently selected object
#set current [join [all -selected]]
# create a file listing all transforms
set home $::env(HOME)
set desktop [append home "/Desktop/"]
set time [clock seconds]
set timestamp [clock format $time -format %y%m%d-%H%M%S]
set outfile_list [append timestamp "_amira2bdv.list"]
set file0 $desktop$outfile_list
set fileid0 [open $file0 w]
# run through Amira Objects
#run over all objects
set objects [all]
foreach current $objects {
# find its type (needs to be data)
set type [$current getTypeId]
# check object type
if {$type == "HxUniformScalarField3"} {
# find out if it is a data object loaded from a file or derived/processed data
if { [$current parameters hasParameter LoadCmd] } {
set loadp [$current parameters LoadCmd getValue]
} else {
continue
}
$current select
$current deselect
set flist [lrange $loadp 12 end]
set files_str [lindex $loadp 11]
set sin [string range $files_str 0 2]
foreach chunk $flist {
if { [string equal [string range $chunk 0 2] $sin] } {
set files_str [concat $files_str , $chunk]
} else {
set files_str [concat $files_str $chunk]
}
}
# fix file name
if { [$current parameters hasParameter Filename] } {
set filename [$current parameters Filename getValue]
if { [string first " " $filename 0] > 0} {
theMsg warning [concat "File name(s) " $filename "contains spaces. Try avoiding this!!!"]
#continue
} else {
# find working directory and change to it (not needed if using absolute filenames lateron...)
set lastfile [string range $files_str [string last $sin $files_str ] end]
set wdir [string range $lastfile 0 [string last / $lastfile]]
if { [string first " " $wdir 0] > 0} {
theMsg warning [concat "Folder name(s) " $wdir "contains spaces. Try avoiding this!!!"]
# continue
}
#cd $wdir
set filebase [string range $filename [expr [string last / $filename] + 1] end]
set file1 $wdir$filebase
set file1 [append file1 .tform]
}
}
# find working directory and change to it (not needed if using absolute filenames lateron...)
#set sfile [split $file "/"]
#set wdir [lindex $sfile 0]
#for {set i 1} {$i < [expr [llength $sfile] - 1] } {incr i} {append wdir "\/" [lindex $sfile $i]}
#cd $wdir
set tfm [$current getTransform]
set voxs [$current getVoxelSize]
set bbox [$current getBoundingBox]
set transl [$current getTranslation]
# adjust for Voxel Size differences (binning...)
#for {set j 0} {$j < 16} {set j [expr $j + 4]} { lset tfm $j [expr [lindex $tfm $j] * [lindex $voxs 0]] }
#for {set j 1} {$j < 16} {set j [expr $j + 4]} { lset tfm $j [expr [lindex $tfm $j] * [lindex $voxs 1]] }
#for {set j 2} {$j < 16} {set j [expr $j + 4]} { lset tfm $j [expr [lindex $tfm $j] * [lindex $voxs 2]] }
# adjust for offset when loading data
lset tfm 12 [expr [lindex $tfm 12] * [lindex $bbox 0]]
lset tfm 13 [expr [lindex $tfm 13] * [lindex $bbox 2]]
lset tfm 14 [expr [lindex $tfm 14] * [lindex $bbox 4]]
#echo $voxs
#echo $tfm
# export transformation to text file
set tfmout [join $tfm ","]
if { [file writable $file1] } {
echo continue in current directory.
} else {
set file1 $desktop$filebase
set file1 [append file1 .tform]
}
set fileid1 [open $file1 w]
puts $fileid1 $tfmout
puts $fileid1 [join $bbox ","]
puts $fileid1 [join $voxs ","]
puts $fileid1 [join $transl ","]
puts $fileid1 [$current LatticeInfo getValue]
puts $fileid1 $files_str
close $fileid1
# theMsg warning [concat "Transformation written to " $file1]
puts $fileid0 $file1
} else {
continue
#theMsg warning "Wrong object selected! Please select a data object."
}
viewer 0 viewAll
}
close $fileid0
theMsg warning [concat "Transformation data written to " $file0]
}