36
36
#include " const.h"
37
37
#include " timer.h"
38
38
#include " version.h"
39
+ #include " randomfields.h"
39
40
40
41
int main (int argc, char *argv[]) ;
41
42
static int get_option (int argc, char *argv[]) ;
@@ -47,7 +48,12 @@ static int use_thickness = 0 ;
47
48
static int nsurfaces = 1 ;
48
49
static const char *thickness_name = " thickness" ;
49
50
static const char *pial_name = " pial" ;
50
- static const char *tmap_fname = NULL ;
51
+ static char *tmap_fname = NULL ;
52
+ static char *tmap_write_fname = NULL ;
53
+ static float tmap_std = 0.0 ;
54
+ static float tmap_min = .25 ;
55
+ static float tmap_max = .75 ;
56
+ static int tmap_avgs = 0 ;
51
57
static int nbrs = 2 ;
52
58
53
59
static char *orig_name = NULL ;
@@ -173,12 +179,50 @@ main(int argc, char *argv[])
173
179
parms.mri_dtrans = MRIread (tmap_fname);
174
180
if (parms.mri_dtrans == NULL )
175
181
ErrorExit (ERROR_NOFILE,
176
- " %s: could not tmap vertex percentages from %s\n " , Progname, tmap_fname) ;
182
+ " %s: could not read tmap vertex percentages from %s\n " , Progname, tmap_fname) ;
177
183
if (parms.mri_dtrans ->width != mris->nvertices )
178
184
ErrorExit (ERROR_NOFILE,
179
- " %s: could not tmap width %d != mris->nvertices %d in %s\n " ,
185
+ " %s: tmap width %d != mris->nvertices %d in %s\n " ,
180
186
Progname, parms.mri_dtrans ->width , mris->nvertices , tmap_fname) ;
181
- printf (" setting vno distance to %f\n " , MRIgetVoxVal (parms.mri_dtrans , 0 , 0 , 0 , 0 ));
187
+ }
188
+ else if (!FZERO (tmap_std)) // create a random map of distances
189
+ {
190
+ RFS *rfs = RFspecInit (0 , NULL );
191
+ int vno ;
192
+
193
+ parms.mri_dtrans = MRIalloc (mris->nvertices , 1 , 1 , MRI_FLOAT) ;
194
+ if (parms.mri_dtrans == NULL )
195
+ ErrorExit (ERROR_NOFILE,
196
+ " %s: could not allocate tmap vertex percentages from %s\n " , Progname, tmap_fname) ;
197
+
198
+ printf (" creating random tmap distances\n " ) ;
199
+ rfs->name = strcpyalloc (" gaussian" );
200
+ rfs->params [0 ] = mm_out ; // mean is halfway through the ribbon
201
+ rfs->params [1 ] = tmap_std; // std
202
+
203
+ for (vno = 0 ; vno < mris->nvertices ; vno++)
204
+ mris->vertices [vno].val = RFdrawVal (rfs);
205
+
206
+ MRISaverageVals (mris, tmap_avgs) ;
207
+ for (vno = 0 ; vno < mris->nvertices ; vno++)
208
+ {
209
+ float dist = mris->vertices [vno].val ;
210
+
211
+ dist = MIN (MAX (dist, tmap_min), tmap_max) ;
212
+ if (mris->vertices [vno].ripflag )
213
+ dist = 0 ;
214
+
215
+ if (vno == Gdiag_no)
216
+ printf (" vno %d: val %f, ripflag %d\n " , vno, dist, mris->vertices [vno].ripflag ) ;
217
+
218
+ mris->vertices [vno].val = dist ;
219
+ MRIsetVoxVal (parms.mri_dtrans , vno, 0 , 0 , 0 , dist) ;
220
+ }
221
+ if (tmap_write_fname != NULL )
222
+ {
223
+ printf (" writing random tmap to %s\n " , tmap_write_fname) ;
224
+ MRISwriteValues (mris, tmap_write_fname) ;
225
+ }
182
226
}
183
227
else
184
228
parms.mri_dtrans = NULL ;
@@ -329,6 +373,12 @@ get_option(int argc, char *argv[])
329
373
nargs = 1 ;
330
374
fprintf (stderr, " l_surf_repulse = %2.3f\n " , parms.l_surf_repulse ) ;
331
375
}
376
+ else if (!stricmp (option, " wd" ))
377
+ {
378
+ tmap_write_fname = argv[2 ] ;
379
+ nargs = 1 ;
380
+ fprintf (stderr, " writing random tmap to %s\n " , tmap_write_fname) ;
381
+ }
332
382
else if (!stricmp (option, " pial" ))
333
383
{
334
384
pial_name = argv[2 ] ;
@@ -338,9 +388,22 @@ get_option(int argc, char *argv[])
338
388
else if (!stricmp (option, " tmap" ))
339
389
{
340
390
use_thickness = -1 ;
341
- tmap_fname = argv[2 ] ;
342
- printf (" reading thickness target percent map from %s\n " , tmap_fname) ;
343
- nargs = 1 ;
391
+ if (!stricmp (argv[2 ], " random" ))
392
+ {
393
+ tmap_std = atof (argv[3 ]);
394
+ tmap_min = atof (argv[4 ]);
395
+ tmap_max = atof (argv[5 ]);
396
+ tmap_avgs = atoi (argv[6 ]);
397
+ printf (" creating random tmap in [%2.2f, %2.2f] with std %2.2f and %d averages\n " ,
398
+ tmap_min, tmap_max, tmap_std, tmap_avgs) ;
399
+ nargs = 5 ;
400
+ }
401
+ else
402
+ {
403
+ tmap_fname = argv[2 ] ;
404
+ printf (" reading thickness target percent map from %s\n " , tmap_fname) ;
405
+ nargs = 1 ;
406
+ }
344
407
}
345
408
else switch (toupper (*option))
346
409
{
@@ -414,5 +477,10 @@ usage_exit(int code)
414
477
printf (" Example: mris_expand -thickness lh.white 0.5 lh.graymid\n " );
415
478
printf (" Example: mris_expand -label labelfile lh.white 0.5 lh.graymid\n " );
416
479
printf (" Example: mris_expand -tmap thickness_pct_target.mgz lh.white 0.5 lh.graymid\n " );
480
+ printf (" use a prespecified map of percent thickness to compute the target locations for expansion\n " );
481
+ printf (" Example: mris_expand -tmap random 2 .25 .75 100 -wd tmap.mgz lh.white 0.5 lh.graymid\n " );
482
+ printf (" creates a random target distance map with gaussian sampling (mean=.5, std=2) and cropping to .25/.75\n " );
483
+ printf (" and spatial averaging 100 times (cropping is average averaging). The map will be written to \n " );
484
+ printf (" file tmap.mgz\n " );
417
485
exit (code) ;
418
486
}
0 commit comments