@@ -80,7 +80,7 @@ def add_image(self, img, **kwargs):
80
80
# configure the corresponding freeview argument
81
81
self .arguments .append ('-v ' + filename + _convert_kwargs_to_tags (kwargs ))
82
82
83
- def add_mesh (self , mesh , overlay = None , annot = None , ** kwargs ):
83
+ def add_mesh (self , mesh , curvature = None , overlay = None , annot = None , name = None , ** kwargs ):
84
84
"""
85
85
Adds an image to the freeview window. Any key/value tags allowed as a `-v` option
86
86
in the freeview command line can be provided as an additional argument.
@@ -113,6 +113,17 @@ def add_mesh(self, mesh, overlay=None, annot=None, **kwargs):
113
113
# extra tags for the mesh
114
114
tags = ''
115
115
116
+ # configure any curvatures
117
+ if curvature is not None :
118
+ curvature = [curvature ] if not isinstance (curvature , (list , tuple )) else curvature
119
+ for c in curvature :
120
+ c = FreeviewCurvature (c ) if not isinstance (c , FreeviewCurvature ) else c
121
+ filename = _unique_filename (c .name , '.mgz' , self .tempdir )
122
+ c .arr .save (filename )
123
+ if self .debug :
124
+ print (f'wrote curvature to { filename } ' )
125
+ tags += f':curvature={ filename } ' + c .tags ()
126
+
116
127
# configure any overlays
117
128
if overlay is not None :
118
129
overlay = [overlay ] if not isinstance (overlay , (list , tuple )) else overlay
@@ -135,6 +146,9 @@ def add_mesh(self, mesh, overlay=None, annot=None, **kwargs):
135
146
print (f'wrote annotation to { filename } ' )
136
147
tags += f':annot={ filename } '
137
148
149
+ if name is not None :
150
+ tags += f':name={ name } '
151
+
138
152
# configure the corresponding freeview argument
139
153
self .arguments .append ('-f ' + mesh_filename + tags + _convert_kwargs_to_tags (kwargs ))
140
154
@@ -193,21 +207,41 @@ def show(self, background=True, threads=None):
193
207
run (command , background = background )
194
208
195
209
210
+ class FreeviewCurvature :
211
+
212
+ def __init__ (self , arr , name = 'curvature' , method = 'binary' ):
213
+ """
214
+ Configuration for freeview curvature.
215
+ """
216
+ self .arr = cast_overlay (arr , allow_none = False )
217
+ self .name = name
218
+ self .method = method
219
+
220
+ def tags (self ):
221
+ tags = ''
222
+ tags += '' if self .method is None else f':curvature_method={ self .method } '
223
+ return tags
224
+
225
+
196
226
class FreeviewOverlay :
197
227
198
- def __init__ (self , arr , name = 'overlay' , threshold = None , opacity = None ):
228
+ def __init__ (self , arr , name = 'overlay' , threshold = None , opacity = None , color = None , custom = None ):
199
229
"""
200
230
Configuration for freeview overlays.
201
231
"""
202
232
self .arr = cast_overlay (arr , allow_none = False )
203
233
self .name = name
204
234
self .threshold = threshold
205
235
self .opacity = opacity
236
+ self .color = color
237
+ self .custom = custom
206
238
207
239
def tags (self ):
208
240
tags = ''
209
- tags += '' if self .threshold is None else f':overlay_threshold=' + ',' .join (str (x ) for x in config .threshold )
241
+ tags += '' if self .threshold is None else f':overlay_threshold=' + ',' .join (str (x ) for x in self .threshold )
210
242
tags += '' if self .opacity is None else f':overlay_opacity={ self .opacity } '
243
+ tags += '' if self .color is None else f':overlay_color={ self .color } '
244
+ tags += '' if self .custom is None else f':overlay_custom={ self .custom } '
211
245
return tags
212
246
213
247
0 commit comments