Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

SUMA_3dSurf2Vol.h File Reference

Go to the source code of this file.


Data Structures

struct  node_list_t
struct  opts_t
struct  param_t
struct  parser_t
struct  s2v_opts_t

Defines

#define PROG_NAME   "3dSurf2Vol"
#define S2V_USE_LONG   1
#define S2V_USE_SHORT   2
#define S2V_USE_HIST   3
#define S2V_USE_VERSION   4
#define S2V_F_STEPS_MIN   1
#define S2V_F_INDEX_VOXEL   0
#define S2V_F_INDEX_POINT   1
#define S2V_MAX_SURFS   2
#define S2V_DEBUG_MAX_LEV   5
#define S2V_DEBUG_TEST_NODE   7
#define CHECK_NULL_STR(str)   ((str) ? (str) : "(NULL)")

Enumerations

enum  s2v_map_num {
  E_SMAP_INVALID = -1, E_SMAP_NONE, E_SMAP_MASK, E_SMAP_MASK2,
  E_SMAP_AVE, E_SMAP_COUNT, E_SMAP_MIN, E_SMAP_MAX,
  E_SMAP_MAX_ABS, E_SMAP_FINAL
}

Functions

float dist_f3mm (THD_fvec3 *p1, THD_fvec3 *p2)
int s2v_map_type (char *map_str)
int compute_results (param_t *p, node_list_t *N, s2v_opts_t *sopt, double *ddata, int *idata, THD_fvec3 *pary)
THD_3dim_datasets2v_nodes2volume (node_list_t *N, param_t *p, s2v_opts_t *sopt)
int adjust_endpts (s2v_opts_t *sopt, THD_fvec3 *p1, THD_fvec3 *pn)
int check_datum_type (char *datum_str, int default_type)
int check_map_func (char *map_str)
int disp_node_list_t (char *info, node_list_t *d)
int disp_opts_t (char *info, opts_t *opts)
int disp_param_t (char *info, param_t *p)
int disp_parser_t (char *info, parser_t *d)
int disp_s2v_opts_t (char *info, s2v_opts_t *sopt)
int f3mm_out_of_bounds (THD_fvec3 *cp, THD_fvec3 *min, THD_fvec3 *max)
int fill_node_list (opts_t *opts, param_t *p, node_list_t *N)
int fill_SUMA_structs (opts_t *opts, SUMA_SurfSpecFile *spec)
int final_clean_up (node_list_t *N)
int final_computations (double *ddata, int *idata, s2v_opts_t *sopt, int nvox)
int get_mappable_surfs (SUMA_SurfaceObject **slist, int how_many, int debug)
int init_node_list (opts_t *opts, param_t *p, s2v_opts_t *sopt, node_list_t *N)
int init_options (opts_t *opts, int argc, char *argv[])
int insert_list (node_list_t *N, param_t *p, s2v_opts_t *sopt, THD_fvec3 *pary, int nindex, double *ddata, int *idata)
int insert_value (s2v_opts_t *sopt, double *dv, int *iv, int vox, int node, float value)
int integral_doubles (double *dp, int nvals)
int make_point_list (THD_fvec3 *list, THD_fvec3 *p1, THD_fvec3 *pn, s2v_opts_t *sopt)
int read_surf_files (opts_t *opts, param_t *p, SUMA_SurfSpecFile *spec, s2v_opts_t *sopt, node_list_t *N)
int read_sxyz_1D (opts_t *opts, param_t *p)
int sdata_from_1D (opts_t *opts, param_t *p, node_list_t *N)
int sdata_from_default (node_list_t *N)
int set_3dmm_bounds (THD_3dim_dataset *dset, THD_fvec3 *min, THD_fvec3 *max)
int set_node_list_data (node_list_t *N, param_t *p, s2v_opts_t *sopt, int col)
int set_smap_opts (opts_t *opts, param_t *p, s2v_opts_t *sopt)
int surf_to_node_list (s2v_opts_t *sopt, node_list_t *N, int nsurf)
int sxyz_1D_to_nlist (opts_t *opts, s2v_opts_t *sopt, param_t *p, node_list_t *N, int *nsurf)
int usage (char *prog, int level)
int validate_datasets (opts_t *opts, param_t *p)
int validate_options (opts_t *opts, param_t *p)
int validate_surface (opts_t *opts, param_t *p)
int verify_node_list (node_list_t *N)
int verify_parser_expr (opts_t *opts, param_t *p)
int write_output (s2v_opts_t *sopt, opts_t *opts, param_t *p, node_list_t *N, int argc, char *argv[])

Define Documentation

#define CHECK_NULL_STR str       ((str) ? (str) : "(NULL)")
 

Definition at line 21 of file SUMA_3dSurf2Vol.h.

#define PROG_NAME   "3dSurf2Vol"
 

Definition at line 4 of file SUMA_3dSurf2Vol.h.

#define S2V_DEBUG_MAX_LEV   5
 

Definition at line 18 of file SUMA_3dSurf2Vol.h.

Referenced by init_options().

#define S2V_DEBUG_TEST_NODE   7
 

Definition at line 19 of file SUMA_3dSurf2Vol.h.

#define S2V_F_INDEX_POINT   1
 

Definition at line 14 of file SUMA_3dSurf2Vol.h.

Referenced by set_smap_opts().

#define S2V_F_INDEX_VOXEL   0
 

Definition at line 13 of file SUMA_3dSurf2Vol.h.

Referenced by insert_list(), and set_smap_opts().

#define S2V_F_STEPS_MIN   1
 

Definition at line 11 of file SUMA_3dSurf2Vol.h.

Referenced by set_smap_opts().

#define S2V_MAX_SURFS   2
 

Definition at line 16 of file SUMA_3dSurf2Vol.h.

Referenced by fill_SUMA_structs(), init_node_list(), init_options(), and set_smap_opts().

#define S2V_USE_HIST   3
 

Definition at line 8 of file SUMA_3dSurf2Vol.h.

Referenced by init_options(), and usage().

#define S2V_USE_LONG   1
 

Definition at line 6 of file SUMA_3dSurf2Vol.h.

Referenced by init_options(), and usage().

#define S2V_USE_SHORT   2
 

Definition at line 7 of file SUMA_3dSurf2Vol.h.

Referenced by init_options(), and usage().

#define S2V_USE_VERSION   4
 

Definition at line 9 of file SUMA_3dSurf2Vol.h.

Referenced by init_options(), and usage().


Enumeration Type Documentation

enum s2v_map_num
 

Enumeration values:
E_SMAP_INVALID 
E_SMAP_NONE 
E_SMAP_MASK 
E_SMAP_MASK2 
E_SMAP_AVE 
E_SMAP_COUNT 
E_SMAP_MIN 
E_SMAP_MAX 
E_SMAP_MAX_ABS 
E_SMAP_FINAL 

Definition at line 24 of file SUMA_3dSurf2Vol.h.

Referenced by s2v_map_type().

00025 {
00026     E_SMAP_INVALID = -1,
00027     E_SMAP_NONE,                        /* do not change INVALID or NONE */
00028     E_SMAP_MASK, E_SMAP_MASK2,
00029     E_SMAP_AVE,  E_SMAP_COUNT,
00030     E_SMAP_MIN,  E_SMAP_MAX,
00031     E_SMAP_MAX_ABS,
00032     E_SMAP_FINAL                        /* do not change FINAL */
00033 } s2v_map_num;

Function Documentation

int adjust_endpts s2v_opts_t   sopt,
THD_fvec3   p1,
THD_fvec3   pn
 

Definition at line 747 of file SUMA_3dSurf2Vol.c.

References dist_f3mm(), ENTRY, s2v_opts_t::f_p1_fr, s2v_opts_t::f_p1_mm, s2v_opts_t::f_pn_fr, s2v_opts_t::f_pn_mm, s2v_opts_t::map, RETURN, and THD_fvec3::xyz.

Referenced by compute_results().

00748 {
00749     THD_fvec3 f3_diff;
00750     float     dist, factor;
00751 
00752 ENTRY("adjust_endpts");
00753 
00754     if ( !sopt || !p1 || !pn )
00755     {
00756         fprintf(stderr,"** ae: invalid params (%p,%p,%p)\n", sopt, p1, pn);
00757         RETURN(-1);
00758     }
00759 
00760     /* first, get the difference, and distance */
00761     f3_diff.xyz[0] = pn->xyz[0] - p1->xyz[0];
00762     f3_diff.xyz[1] = pn->xyz[1] - p1->xyz[1];
00763     f3_diff.xyz[2] = pn->xyz[2] - p1->xyz[2];
00764 
00765     dist = dist_f3mm( p1, pn );
00766 
00767     if ( (sopt->f_p1_fr != 0.0) || (sopt->f_p1_mm != 0.0) )
00768     {
00769         if ( sopt->f_p1_fr != 0.0 )     /* what the heck, choose fr if both */
00770             factor = sopt->f_p1_fr;
00771         else
00772             factor = (dist == 0.0) ? 0.0 : sopt->f_p1_mm / dist;
00773 
00774         p1->xyz[0] += factor * f3_diff.xyz[0];
00775         p1->xyz[1] += factor * f3_diff.xyz[1];
00776         p1->xyz[2] += factor * f3_diff.xyz[2];
00777     }
00778 
00779     if ( (sopt->f_pn_fr != 0.0) || (sopt->f_pn_mm != 0.0) )
00780     {
00781         if ( sopt->f_pn_fr != 0.0 )
00782             factor = sopt->f_pn_fr;
00783         else
00784             factor = (dist == 0.0) ? 0.0 : sopt->f_pn_mm / dist;
00785 
00786         pn->xyz[0] += factor * f3_diff.xyz[0];
00787         pn->xyz[1] += factor * f3_diff.xyz[1];
00788         pn->xyz[2] += factor * f3_diff.xyz[2];
00789     }
00790 
00791     switch ( sopt->map )
00792     {
00793         default:
00794             fprintf(stderr,"** ae: mapping %d not ready\n", sopt->map );
00795             RETURN(-1);
00796 
00797         case E_SMAP_AVE:
00798         case E_SMAP_COUNT:
00799         case E_SMAP_MAX_ABS:
00800         case E_SMAP_MAX:
00801         case E_SMAP_MIN:
00802         case E_SMAP_MASK:
00803         case E_SMAP_MASK2:
00804             break;
00805     }
00806 
00807     RETURN(0);
00808 }

int check_datum_type char *    datum_str,
int    default_type
 

Definition at line 2092 of file SUMA_3dSurf2Vol.c.

02093 {
02094     int c, dt = -1;
02095     
02096 ENTRY("check_datum_type");
02097 
02098     if ( datum_str )
02099     {
02100         for ( c = 0; c <= MRI_rgba; c++ )
02101             if ( ! strcmp( datum_str, MRI_TYPE_name[c] ) )
02102             {
02103                 dt = c;
02104                 break;
02105             }
02106 
02107         /* if we didn't find the requested type, inform the user and quit */
02108         if ( c > MRI_rgba )
02109         {
02110             fprintf( stderr, "** invalid datum type name '%s'\n",
02111                      datum_str );
02112             RETURN(-1);
02113         }
02114     }
02115     else
02116     {
02117         dt = default_type;
02118     }
02119 
02120     if ( ( dt != MRI_byte   ) &&
02121          ( dt != MRI_short  ) &&
02122          ( dt != MRI_float  ) &&
02123          ( dt != MRI_double ) )
02124     {
02125         fprintf( stderr, "** data type '%s' is not supported\n",
02126                  MRI_TYPE_name[dt] );
02127         RETURN(-1);
02128     }
02129 
02130     RETURN(dt);
02131 }

int check_map_func char *    map_str
 

Definition at line 1489 of file SUMA_3dVol2Surf.c.

01490 {
01491     int map;
01492 
01493 ENTRY("check_map_func");
01494 
01495     if ( map_str == NULL )
01496     {
01497         fprintf( stderr, "** missing option: '-map_func FUNCTION'\n" );
01498         RETURN(E_SMAP_INVALID);
01499     }
01500 
01501     map = v2s_map_type( map_str );
01502 
01503     switch ( map )
01504     {
01505         default:
01506             map = E_SMAP_INVALID;
01507             break;
01508 
01509         case E_SMAP_COUNT:
01510         case E_SMAP_MASK2:
01511             fprintf( stderr, "** function '%s' coming soon ...\n",
01512                      gv2s_map_names[map] );
01513             RETURN(E_SMAP_INVALID);
01514             break;
01515 
01516         case E_SMAP_AVE:
01517         case E_SMAP_MASK:
01518         case E_SMAP_MAX:
01519         case E_SMAP_MAX_ABS:
01520         case E_SMAP_MIN:
01521         case E_SMAP_MIDPT:
01522         case E_SMAP_SEG_VALS:
01523         case E_SMAP_MEDIAN:
01524         case E_SMAP_MODE:
01525             break;
01526     }
01527 
01528     if ( map == E_SMAP_INVALID )
01529         fprintf( stderr, "** invalid map string '%s'\n", map_str );
01530 
01531     RETURN(map);
01532 }

int compute_results param_t   p,
node_list_t   N,
s2v_opts_t   sopt,
double *    ddata,
int *    idata,
THD_fvec3   pary
 

Definition at line 408 of file SUMA_3dSurf2Vol.c.

References adjust_endpts(), s2v_opts_t::debug, node_list_t::depth, dist_f3mm(), s2v_opts_t::dnode, DSET_NVOX, ENTRY, param_t::f3mm_max, param_t::f3mm_min, f3mm_out_of_bounds(), final_computations(), param_t::gpar, node_list_t::ilen, node_list_t::ilist, insert_list(), make_point_list(), node_list_t::nnodes, node_list_t::nodes, p, RETURN, s2v_opts_t::sxyz_ori_gpar, THD_dicomm_to_3dmm(), and THD_fvec3::xyz.

Referenced by s2v_nodes2volume().

00410 {
00411     THD_fvec3          p1, pn;
00412     float              dist, min_dist, max_dist;
00413     int                nindex, node;
00414     int                oobc;
00415 
00416 ENTRY("compute_results");
00417 
00418     if ( !p || !N || !sopt || !ddata || !cdata )
00419     {
00420         fprintf(stderr,"** cr: bad params (%p,%p,%p,%p,%p)\n",
00421                 p, N, sopt, ddata, cdata);
00422         RETURN(-1);
00423     }
00424 
00425     min_dist = 9999.9;
00426     max_dist = -1.0;
00427     oobc     = 0;               /* init out-of-bounds counter */
00428 
00429     for ( nindex = 0; nindex < N->ilen; nindex++ )
00430     {
00431         node = N->ilist[nindex];
00432         if ( node < 0 || node >= N->nnodes )
00433         {
00434             fprintf(stderr,"** node %d (%d) out-of-range [0,%d]\n",
00435                     nindex, node, N->nnodes);
00436             RETURN(-1);
00437         }
00438 
00439         /* initiate the endpoints */
00440         p1 = N->nodes[node];
00441 
00442         if ( N->depth > 1 )
00443             pn = N->nodes[node+N->nnodes];
00444         else
00445             pn = p1;
00446 
00447         if ( ! sopt->sxyz_ori_gpar ) /* if orient is not as gpar it is Dicom */
00448         {
00449             p1 = THD_dicomm_to_3dmm(p->gpar, p1);
00450             pn = THD_dicomm_to_3dmm(p->gpar, pn);
00451         }
00452 
00453         if ( sopt->debug > 0 && sopt->dnode == node )
00454         {
00455             fprintf(stderr,"-- debug node: %d\n", node );
00456             fprintf(stderr,"-- orig endpts: (%f, %f, %f)\n"
00457                            "                (%f, %f, %f)\n",
00458                     p1.xyz[0], p1.xyz[1], p1.xyz[2],
00459                     pn.xyz[0], pn.xyz[1], pn.xyz[2]);
00460         }
00461 
00462         adjust_endpts( sopt, &p1, &pn );        /* per user options */
00463 
00464         /* if both points are outside gpar box, skip the node */
00465         if ( f3mm_out_of_bounds( &p1, &p->f3mm_min, &p->f3mm_max ) &&
00466              f3mm_out_of_bounds( &pn, &p->f3mm_min, &p->f3mm_max ) )
00467         {
00468             oobc++;
00469             continue;
00470         }
00471 
00472         dist = dist_f3mm( &p1, &pn );
00473         if ( dist < min_dist ) min_dist = dist;
00474         if ( dist > max_dist ) max_dist = dist;
00475 
00476         make_point_list( pary, &p1, &pn, sopt );
00477 
00478         /* do all the work to insert data */
00479         if ( insert_list(N, p, sopt, pary, nindex, ddata, cdata) )
00480             RETURN(-1);
00481     }
00482 
00483     if ( sopt->debug > 0 )
00484         fprintf(stderr, "-- (min_dist, max_dist) = (%f, %f)\n"
00485                         "   %d of %d nodes were out of bounds\n",
00486                 min_dist, max_dist, oobc, N->ilen);
00487 
00488     if ( final_computations(ddata, cdata, sopt, DSET_NVOX(p->gpar)) )
00489         RETURN(-1);
00490 
00491     RETURN(0);
00492 }

int disp_node_list_t char *    info,
node_list_t   d
 

Definition at line 3045 of file SUMA_3dSurf2Vol.c.

References node_list_t::depth, ENTRY, node_list_t::fdata, node_list_t::ilen, node_list_t::ilist, node_list_t::nnodes, node_list_t::nodes, and RETURN.

Referenced by fill_node_list(), and verify_node_list().

03046 {
03047 ENTRY("disp_node_list_t");
03048 
03049     if ( info )
03050         fputs( info, stderr );
03051 
03052     if ( d == NULL )
03053     {
03054         fprintf(stderr,"disp_node_list_t: d == NULL\n");
03055         RETURN(-1);
03056     }
03057 
03058     fprintf(stderr,
03059             "node_list_t struct at %p :\n"
03060             "    nodes         = %p\n"
03061             "    depth, nnodes = %d, %d\n"
03062             "    fdata, ilist  = %p, %p\n"
03063             "    ilen          = %d\n"
03064             , d,
03065             d->nodes, d->depth, d->nnodes,
03066             d->fdata, d->ilist, d->ilen
03067             );
03068 
03069     RETURN(0);
03070 }

int disp_opts_t char *    info,
opts_t   opts
 

Definition at line 2509 of file SUMA_3dVol2Surf.c.

02510 {
02511 ENTRY("disp_opts_t");
02512 
02513     if ( info )
02514         fputs( info, stderr );
02515 
02516     if ( opts == NULL )
02517     {
02518         fprintf( stderr, "disp_opts_t: opts == NULL\n" );
02519         RETURN(-1);
02520     }
02521 
02522     fprintf(stderr,
02523             "options struct at %p :\n"
02524             "    gpar_file              = %s\n"
02525             "    outfile_1D             = %s\n"
02526             "    outfile_niml           = %s\n"
02527             "    spec_file              = %s\n"
02528             "    sv_file                = %s\n"
02529             "    cmask_cmd              = %s\n"
02530             "    map_str                = %s\n"
02531             "    snames[0,1]            = %s, %s\n"
02532             "    gp_index, no_head      = %d, %d\n"
02533             "    first_node, last_node  = %d, %d\n"
02534             "    use_norms, norm_len    = %d, %f\n"
02535             "    norm_dir, debug, dnode = %d, %d, %d\n"
02536             "    f_index_str            = %s\n"
02537             "    f_steps                = %d\n"
02538             "    f_p1_fr, f_pn_fr       = %f, %f\n"
02539             "    f_p1_mm, f_pn_mm       = %f, %f\n"
02540             , opts,
02541             CHECK_NULL_STR(opts->gpar_file), CHECK_NULL_STR(opts->outfile_1D),
02542             CHECK_NULL_STR(opts->outfile_niml),
02543             CHECK_NULL_STR(opts->spec_file), CHECK_NULL_STR(opts->sv_file),
02544             CHECK_NULL_STR(opts->cmask_cmd), CHECK_NULL_STR(opts->map_str),
02545             CHECK_NULL_STR(opts->snames[0]), CHECK_NULL_STR(opts->snames[1]),
02546             opts->gp_index, opts->no_head, opts->first_node, opts->last_node,
02547             opts->use_norms, opts->norm_len, opts->norm_dir, opts->debug,
02548             opts->dnode, CHECK_NULL_STR(opts->f_index_str), opts->f_steps,
02549             opts->f_p1_fr, opts->f_pn_fr, opts->f_p1_mm, opts->f_pn_mm
02550             );
02551 
02552     RETURN(0);
02553 }

int disp_param_t char *    info,
param_t   p
 

Definition at line 2416 of file SUMA_SurfMeasures.c.

02417 {
02418     if ( info )
02419         fputs( info, stderr );
02420 
02421     if ( ! d )
02422     {
02423         fprintf(stderr,"** disp_param_t: d == NULL\n");
02424         return -1;
02425     }
02426 
02427     fprintf(stderr,
02428             "param_t struct at %p:\n"
02429             "    F, outfp       = %p, %p\n"
02430             "    nodes, nnodes  = %p, %d\n"
02431             "    cmask          = %p\n"
02432             "    ncmask, ccount = %d, %d\n",
02433             d,
02434             d->F, d->outfp, d->nodes, d->nnodes,
02435             d->cmask, d->ncmask, d->ccount );
02436 
02437     return 0;
02438 }

int disp_parser_t char *    info,
parser_t   d
 

Definition at line 3114 of file SUMA_3dSurf2Vol.c.

References c, PARSER_code::c_code, ENTRY, parser_t::has_sym, parser_t::max_sym, PARSER_code::num_code, parser_t::pcode, and RETURN.

Referenced by validate_options().

03115 {
03116     int c;
03117 
03118 ENTRY("disp_parser_t");
03119 
03120     if ( info )
03121         fputs( info, stderr );
03122 
03123     if ( d == NULL )
03124     {
03125         fprintf(stderr,"disp_parser_t: d == NULL\n" );
03126         RETURN(-1);
03127     }
03128 
03129     fprintf(stderr, "parser_t struct at %p :\n"
03130                     "    pcode    = %p\n"
03131                     "    max_sym  = %d\n",
03132                     d, d->pcode, d->max_sym );
03133 
03134     if ( d->pcode )
03135     {
03136         fprintf(stderr, "    num_code = %d\n"
03137                         "    c_code   = %s\n",
03138                 d->pcode->num_code, d->pcode->c_code );
03139 
03140         fprintf(stderr, "    has_sym  =");
03141         for ( c = 0; c < 26; c++ )
03142             fprintf(stderr, " %d", d->has_sym[c]);
03143         fputc('\n', stderr);
03144     }
03145 
03146     RETURN(0);
03147 }

int disp_s2v_opts_t char *    info,
s2v_opts_t   sopt
 

Definition at line 3077 of file SUMA_3dSurf2Vol.c.

References s2v_opts_t::cmask, s2v_opts_t::datum, s2v_opts_t::debug, s2v_opts_t::dnode, s2v_opts_t::dvox, ENTRY, s2v_opts_t::f_index, s2v_opts_t::f_p1_fr, s2v_opts_t::f_p1_mm, s2v_opts_t::f_pn_fr, s2v_opts_t::f_pn_mm, s2v_opts_t::f_steps, s2v_opts_t::map, s2v_opts_t::noscale, RETURN, and s2v_opts_t::sxyz_ori_gpar.

Referenced by set_smap_opts().

03078 {
03079 ENTRY("disp_s2v_opts_t");
03080 
03081     if ( info )
03082         fputs( info, stderr );
03083 
03084     if ( sopt == NULL )
03085     {
03086         fprintf(stderr,"disp_s2v_opts_t: sopt == NULL\n" );
03087         RETURN(-1);
03088     }
03089 
03090     fprintf(stderr,
03091             "s2v_opts_t struct at %p :\n"
03092             "    map, datum, noscale = %d, %d, %d\n"
03093             "    debug, dnode, dvox  = %d, %d, %d\n"
03094             "    sxyz_ori_gpar       = %d\n"
03095             "    cmask               = %p\n"
03096             "    f_steps, f_index    = %d, %d\n"
03097             "    f_p1_fr, f_pn_fr    = %f, %f\n"
03098             "    f_p1_mm, f_pn_mm    = %f, %f\n"
03099             , sopt,
03100             sopt->map, sopt->datum, sopt->noscale,
03101             sopt->debug, sopt->dnode, sopt->dvox, sopt->sxyz_ori_gpar,
03102             sopt->cmask, sopt->f_steps, sopt->f_index,
03103             sopt->f_p1_fr, sopt->f_pn_fr, sopt->f_p1_mm, sopt->f_pn_mm 
03104             );
03105 
03106     RETURN(0);
03107 }

float dist_f3mm THD_fvec3   p1,
THD_fvec3   p2
 

Definition at line 1627 of file vol2surf.c.

01628 {
01629     double d0, d1, d2;
01630 
01631     if ( p1 == NULL || p2 == NULL )
01632     {
01633         fprintf( stderr, "** dist_f3mm: invalid params (%p,%p)\n", p1, p2 );
01634         return(0.0);
01635     }
01636 
01637     d0 = p1->xyz[0] - p2->xyz[0];
01638     d1 = p1->xyz[1] - p2->xyz[1];
01639     d2 = p1->xyz[2] - p2->xyz[2];
01640 
01641     return(sqrt(d0*d0 + d1*d1 + d2*d2));
01642 }

int f3mm_out_of_bounds THD_fvec3   cp,
THD_fvec3   min,
THD_fvec3   max
 

Definition at line 792 of file vol2surf.c.

00793 {
00794     int c;
00795 
00796     if ( !cp || !min || !max )
00797         return(-1);
00798 
00799     for ( c = 0; c < 3; c++ )
00800     {
00801         if ( ( cp->xyz[c] < min->xyz[c] ) ||
00802              ( cp->xyz[c] > max->xyz[c] ) )
00803             return(-1);
00804     }
00805 
00806     return(0);
00807 }

int fill_node_list opts_t   opts,
param_t   p,
node_list_t   N
 

Definition at line 1394 of file SUMA_3dSurf2Vol.c.

References opts_t::debug, disp_node_list_t(), ENTRY, param_t::nsubs, MRI_IMAGE::nx, p, param_t::parser, parser_t::pcode, RETURN, opts_t::sdata_file_1D, sdata_from_1D(), sdata_from_default(), param_t::sdata_im, and verify_node_list().

Referenced by read_surf_files().

01395 {
01396     int rv;
01397 
01398 ENTRY("fill_node_list");
01399 
01400     if ( !opts || !p || !N )
01401     {
01402         fprintf(stderr,"** fill_node_list: bad params (%p,%p,%p)\n",opts,p,N);
01403         RETURN(-1);
01404     }
01405 
01406     p->nsubs = 1;               /* unless we get additional surface data */
01407 
01408     if ( opts->sdata_file_1D )
01409     {
01410         if ( (rv = sdata_from_1D( opts, p, N )) != 0 )
01411             RETURN(rv);
01412         if ( ! p->parser.pcode )
01413             p->nsubs = p->sdata_im->nx - 1;
01414     }
01415     else
01416     {
01417         if ( (rv = sdata_from_default( N )) != 0 )
01418             RETURN(rv);
01419     }
01420 
01421     if ( (rv = verify_node_list( N )) != 0 )
01422         RETURN(rv);
01423 
01424     if ( opts->debug > 1 )
01425         disp_node_list_t( "++ node list filled: ", N );
01426 
01427     RETURN(0);
01428 }

int fill_SUMA_structs opts_t   opts,
SUMA_SurfSpecFile   spec
 

Definition at line 1628 of file SUMA_3dSurf2Vol.c.

References opts_t::debug, SUMA_CommonFields::DsetList, ENTRY, SUMA_CommonFields::InOut_Notify, SUMA_CommonFields::MemTrace, SUMA_SurfSpecFile::N_Groups, SUMA_SurfSpecFile::N_Surfs, RETURN, S2V_MAX_SURFS, opts_t::snames, opts_t::spec_file, SUMA_Alloc_DisplayObject_Struct(), SUMA_Create_CommonFields(), SUMA_LoadSpec_eng(), SUMA_MAX_DISPLAYABLE_OBJECTS, SUMA_Read_SpecFile(), SUMA_ShowSpecStruct(), SUMA_spec_select_surfs(), SUMA_spec_set_map_refs(), SUMAg_N_DOv, and opts_t::sv_file.

Referenced by read_surf_files().

01629 {
01630     int debug = 0, rv;
01631 ENTRY("fill_SUMA_structs");
01632 
01633     if ( opts->debug > 2 )
01634         debug = 1;
01635 
01636     if ( debug )
01637         fputs( "-- SUMA_Create_CommonFields()...\n", stderr );
01638 
01639     if ( opts->spec_file == NULL )
01640         RETURN(-1);
01641 
01642     /* initialize common fields struct */
01643     SUMAg_CF = SUMA_Create_CommonFields();
01644 
01645     if ( SUMAg_CF == NULL )
01646     {
01647         fprintf( stderr, "** failed SUMA_Create_CommonFields(), exiting...\n" );
01648         RETURN(-1);
01649     }
01650 
01651     /* for SUMA type notifications */
01652     if ( opts->debug > 3 )
01653     {
01654         SUMAg_CF->MemTrace = 1;
01655 
01656         if ( opts->debug > 4 )
01657             SUMAg_CF->InOut_Notify = 1;
01658     }
01659 
01660     if ( debug )
01661         fputs( "-- SUMA_Alloc_DisplayObject_Struct()...\n", stderr );
01662 
01663     SUMAg_DOv = SUMA_Alloc_DisplayObject_Struct(SUMA_MAX_DISPLAYABLE_OBJECTS);
01664 
01665     if ( debug )
01666         fputs( "-- SUMA_Read_SpecFile()...\n", stderr );
01667 
01668     if ( SUMA_Read_SpecFile( opts->spec_file, spec) == 0 )
01669     {
01670         fprintf( stderr, "** failed SUMA_Read_SpecFile(), exiting...\n" );
01671         RETURN(-1);
01672     }
01673 
01674     if ( debug )
01675         SUMA_ShowSpecStruct(spec, stderr, 1);
01676 
01677     rv = SUMA_spec_select_surfs(spec, opts->snames, S2V_MAX_SURFS, opts->debug);
01678     if ( rv < 1 )
01679     {
01680         if ( rv == 0 )
01681             fprintf(stderr,"** no named surfaces found in spec file\n");
01682         RETURN(-1);
01683     }
01684 
01685     if ( opts->debug > 0 )
01686         SUMA_ShowSpecStruct(spec, stderr, 1);
01687 
01688     if ( SUMA_spec_set_map_refs(spec, opts->debug) != 0 )
01689         RETURN(-1);
01690 
01691     /* make sure only group was read from spec file */
01692     if ( spec->N_Groups != 1 )
01693     {
01694         fprintf( stderr,"** error: N_Groups <%d> must be 1 in spec file <%s>\n",
01695                  spec->N_Groups, opts->spec_file );
01696         RETURN(-1);
01697     }
01698 
01699     if ( debug )
01700         fputs( "-- SUMA_LoadSpec_eng()...\n", stderr );
01701 
01702     /* actually load the surface(s) from the spec file */
01703     if (SUMA_LoadSpec_eng(spec,SUMAg_DOv,&SUMAg_N_DOv,opts->sv_file,debug,
01704              SUMAg_CF->DsetList) == 0)     /* DsetList - 26 Mar 2004 [ziad] */
01705     {
01706         fprintf( stderr, "** error: failed SUMA_LoadSpec_eng(), exiting...\n" );
01707         RETURN(-1);
01708     }
01709 
01710     if ( opts->debug > 1 )
01711         fprintf(stderr, "++ %d surfaces loaded.\n", spec->N_Surfs );
01712 
01713     RETURN(0);
01714 }

int final_clean_up node_list_t   N
 

Definition at line 1277 of file SUMA_3dSurf2Vol.c.

References ENTRY, node_list_t::fdata, free, node_list_t::ilist, node_list_t::nodes, RETURN, SUMA_Free_CommonFields(), SUMA_Free_Displayable_Object_Vect(), SUMA_Free_SurfaceViewer_Struct_Vect(), SUMAg_N_DOv, and SUMAg_N_SVv.

01278 {
01279 ENTRY("final_clean_up");
01280 
01281     if ( ( SUMAg_DOv != NULL ) &&
01282          ( SUMA_Free_Displayable_Object_Vect(SUMAg_DOv, SUMAg_N_DOv) == 0 ) )
01283         fprintf(stderr, "** failed SUMA_Free_Displayable_Object_Vect()\n" );
01284 
01285     if ( ( SUMAg_SVv != NULL ) &&
01286          ( SUMA_Free_SurfaceViewer_Struct_Vect(SUMAg_SVv, SUMAg_N_SVv) == 0 ) )
01287         fprintf( stderr, "** failed SUMA_Free_SurfaceViewer_Struct_Vect()\n" );
01288 
01289     if ( ( SUMAg_CF != NULL ) && ( SUMA_Free_CommonFields(SUMAg_CF) == 0 ) )
01290         fprintf( stderr, "** failed SUMA_Free_CommonFields()\n" );
01291 
01292     if ( N )
01293     {
01294         if ( N->nodes )  free( N->nodes );
01295         if ( N->fdata )  free( N->fdata );
01296         if ( N->ilist )  free( N->ilist );
01297     }
01298 
01299     RETURN(0);
01300 }

int final_computations double *    ddata,
int *    idata,
s2v_opts_t   sopt,
int    nvox
 

Definition at line 499 of file SUMA_3dSurf2Vol.c.

References s2v_opts_t::debug, s2v_opts_t::dvox, ENTRY, s2v_opts_t::map, and RETURN.

Referenced by compute_results().

00500 {
00501     int index;
00502 
00503 ENTRY("final_computations");
00504 
00505     if ( (sopt->debug > 1) && (sopt->dvox >= 0) && (sopt->dvox < nvox) )
00506         fprintf(stderr,"++ final: voxel %d, from values (%d, %f) ",
00507                 sopt->dvox,cdata[sopt->dvox],ddata[sopt->dvox]);
00508 
00509     switch ( sopt->map )
00510     {
00511         default:
00512             fprintf(stderr,"** fc: mapping %d not ready\n", sopt->map );
00513             RETURN(-1);
00514 
00515         case E_SMAP_AVE:
00516             /* we have sum, divide for average */
00517             for ( index = 0; index < nvox; index++ )
00518                 if ( cdata[index] > 0 )
00519                     ddata[index] /= cdata[index];
00520             break;
00521 
00522         case E_SMAP_COUNT:
00523         case E_SMAP_MAX_ABS:
00524         case E_SMAP_MAX:
00525         case E_SMAP_MIN:
00526         case E_SMAP_MASK:
00527         case E_SMAP_MASK2:
00528             break;
00529     }
00530 
00531     if ( (sopt->debug > 1) && (sopt->dvox >= 0) && (sopt->dvox < nvox) )
00532         fprintf(stderr,"to values (%d, %f)\n",
00533                 cdata[sopt->dvox],ddata[sopt->dvox]);
00534 
00535     RETURN(0);
00536 }

int get_mappable_surfs SUMA_SurfaceObject **    slist,
int    how_many,
int    debug
 

Definition at line 710 of file SUMA_3dVol2Surf.c.

00711 {
00712     SUMA_SurfaceObject * so;
00713     int                  count, socount = 0;
00714 
00715 ENTRY("get_mappable_surfs");
00716 
00717     if ( slist == NULL )
00718     {
00719         fprintf( stderr, "** gms: missing slist!\n" );
00720         RETURN(-1);
00721     }
00722 
00723     for ( count = 0; count < SUMAg_N_DOv; count++ )
00724     {
00725         if ( ! SUMA_isSO(SUMAg_DOv[count]) )
00726             continue;
00727 
00728         so = (SUMA_SurfaceObject *)SUMAg_DOv[count].OP;
00729 
00730         if ( ! so->AnatCorrect )
00731         {
00732             if ( debug )
00733                 fprintf(stderr,"-- surf #%d '%s', anat not correct, skipping\n",
00734                         socount, CHECK_NULL_STR(so->Label));
00735             if ( debug > 1 )
00736                 fprintf(stderr,"** consider adding the following to the "
00737                                "surface definition in the spec file:\n"
00738                                "       Anatomical = Y\n");
00739             continue;
00740         }
00741 
00742         if ( debug > 1 )
00743             fprintf( stderr, "\n---------- surface #%d '%s' -----------\n",
00744                      socount, CHECK_NULL_STR(so->Label) );
00745         if ( debug > 2 ) SUMA_Print_Surface_Object( so, stderr );
00746 
00747         if ( socount < how_many )       /* store a good surface */
00748             slist[socount] = so;
00749 
00750         socount++;
00751     }
00752 
00753     if ( debug > 1 )
00754         fprintf( stderr, "++ found %d mappable surfaces\n", socount );
00755 
00756     RETURN(socount);
00757 }

int init_node_list opts_t   opts,
param_t   p,
s2v_opts_t   sopt,
node_list_t   N
 

Definition at line 906 of file SUMA_3dSurf2Vol.c.

References s2v_opts_t::debug, ENTRY, node_list_t::fdata, gs2v_map_names, node_list_t::ilist, s2v_opts_t::map, node_list_t::nodes, p, RETURN, S2V_MAX_SURFS, SUMAg_N_DOv, surf_to_node_list(), sxyz_1D_to_nlist(), and param_t::sxyz_im.

Referenced by read_surf_files().

00907 {
00908     int nsurf, rv;
00909 
00910 ENTRY("init_node_list");
00911 
00912     if ( opts == NULL || p == NULL || sopt == NULL || N == NULL )
00913     {
00914         fprintf(stderr, "** inl - bad params (%p,%p,%p,%p)\n",opts,p,sopt,N);
00915         RETURN(-1);
00916     }
00917 
00918     memset(N,0,sizeof(*N));     /* first, clear it out - have care w/pointers */
00919     N->nodes = NULL;  N->fdata = NULL;  N->ilist = NULL;
00920 
00921     nsurf = SUMAg_N_DOv;        /* verify, as long as there is no sxyz_im */
00922     if ( !p->sxyz_im && ((nsurf < 1) || (nsurf > S2V_MAX_SURFS)) )
00923     {
00924         fprintf(stderr,"** inl: SUMAg_N_DOv has invalid value of %d\n", nsurf);
00925         RETURN(-1);
00926     }
00927 
00928 #if 0           /* remove requrement of 2 surfaces for functions [v3.0] */
00929 
00930     if ( sopt->map == E_SMAP_MASK )
00931         nsurf = 1;
00932     else
00933     {
00934         /* do a quick check before slow reading action */
00935         if ( ! p->sxyz_im && (SUMAg_N_DOv < 2) )
00936         {
00937             fprintf(stderr,"** function '%s' requires 2 surfaces\n",
00938                     gs2v_map_names[sopt->map]);
00939             RETURN(-1);
00940         }
00941 
00942         nsurf = 2;
00943     }
00944 #endif
00945 
00946     if ( p->sxyz_im )
00947         rv = sxyz_1D_to_nlist( opts, sopt, p, N, &nsurf );
00948     else
00949         rv = surf_to_node_list( sopt, N, nsurf );
00950 
00951     if ( sopt->debug > 1 && rv == 0 )         /* errors reported separately */
00952         fprintf(stderr,"++ node list initialized\n");
00953 
00954     RETURN(rv);
00955 }

int init_options opts_t   opts,
int    argc,
char *    argv[]
 

Definition at line 1003 of file SUMA_3dVol2Surf.c.

01004 {
01005     int ac, ind;
01006 
01007 ENTRY("init_options");
01008 
01009     if ( argc < 2 )
01010     {
01011         usage( PROG_NAME, V2S_USE_LONG );
01012         RETURN(-1);
01013     }
01014 
01015     /* clear out the options structure */
01016     memset( opts, 0, sizeof( opts_t) );
01017     opts->gpar_file    = NULL;
01018     opts->outfile_1D   = NULL;
01019     opts->outfile_niml = NULL;
01020     opts->spec_file    = NULL;
01021     opts->sv_file      = NULL;
01022     opts->cmask_cmd    = NULL;
01023     opts->map_str      = NULL;
01024     opts->snames[0]    = NULL;
01025     opts->snames[1]    = NULL;
01026     opts->f_index_str  = NULL;
01027 
01028     opts->gp_index     = -1;            /* means none: use all       */
01029     opts->norm_len     = 1.0;           /* init to 1.0 millimeter    */
01030     opts->dnode        = -1;            /* init to something invalid */
01031 
01032     for ( ac = 1; ac < argc; ac++ )
01033     {
01034         /* alphabetical... */
01035         if ( ! strncmp(argv[ac], "-cmask", 6) )
01036         {
01037             if ( (ac+1) >= argc )
01038             {
01039                 fputs( "option usage: -cmask COMMAND\n\n", stderr );
01040                 usage( PROG_NAME, V2S_USE_SHORT );
01041                 RETURN(-1);
01042             }
01043 
01044             opts->cmask_cmd = argv[++ac];
01045         }
01046         else if ( ! strncmp(argv[ac], "-debug", 6) )
01047         {
01048             if ( (ac+1) >= argc )
01049             {
01050                 fputs( "option usage: -debug LEVEL\n\n", stderr );
01051                 usage( PROG_NAME, V2S_USE_SHORT );
01052                 RETURN(-1);
01053             }
01054 
01055             opts->debug = atoi(argv[++ac]);
01056             if ( opts->debug < 0 || opts->debug > V2S_DEBUG_MAX_LEV )
01057             {
01058                 fprintf( stderr, "bad debug level <%d>, should be in [0,%d]\n",
01059                         opts->debug, V2S_DEBUG_MAX_LEV );
01060                 usage( PROG_NAME, V2S_USE_SHORT );
01061                 RETURN(-1);
01062             }
01063         }
01064         else if ( ! strncmp(argv[ac], "-dnode", 6) )
01065         {
01066             if ( (ac+1) >= argc )
01067             {
01068                 fputs( "option usage: -dnode NODE_NUM\n\n", stderr );
01069                 usage( PROG_NAME, V2S_USE_SHORT );
01070                 RETURN(-1);
01071             }
01072 
01073             opts->dnode = atoi(argv[++ac]);
01074         }
01075         else if ( ! strncmp(argv[ac], "-f_index", 7) )
01076         {
01077             if ( (ac+1) >= argc )
01078             {
01079                 fputs( "option usage: -f_index INDEX_TYPE\n\n", stderr );
01080                 usage( PROG_NAME, V2S_USE_SHORT );
01081                 RETURN(-1);
01082             }
01083 
01084             opts->f_index_str = argv[++ac];
01085         }
01086         else if ( ! strncmp(argv[ac], "-f_keep_surf_order", 9) )
01087         {
01088             /*  opts->f_kso = 1;                v3.8 */
01089 
01090             fprintf(stderr,"** the -f_keep_surf_order option is depreciated\n"
01091                     "   in favor of -surf_A and -surf_B (version 3.8)\n");
01092             RETURN(-1);
01093         }
01094         else if ( ! strncmp(argv[ac], "-f_p1_fr", 9) )
01095         {
01096             if ( (ac+1) >= argc )
01097             {
01098                 fputs( "option usage: -f_p1_fr FRACTION\n\n", stderr );
01099                 usage( PROG_NAME, V2S_USE_SHORT );
01100                 RETURN(-1);
01101             }
01102 
01103             opts->f_p1_fr = atof(argv[++ac]);
01104         }
01105         else if ( ! strncmp(argv[ac], "-f_pn_fr", 9) )
01106         {
01107             if ( (ac+1) >= argc )
01108             {
01109                 fputs( "option usage: -f_pn_fr FRACTION\n\n", stderr );
01110                 usage( PROG_NAME, V2S_USE_SHORT );
01111                 RETURN(-1);
01112             }
01113 
01114             opts->f_pn_fr = atof(argv[++ac]);
01115         }
01116         else if ( ! strncmp(argv[ac], "-f_p1_mm", 9) )
01117         {
01118             if ( (ac+1) >= argc )
01119             {
01120                 fputs( "option usage: -f_p1_mm DISTANCE\n\n", stderr );
01121                 usage( PROG_NAME, V2S_USE_SHORT );
01122                 RETURN(-1);
01123             }
01124 
01125             opts->f_p1_mm = atof(argv[++ac]);
01126         }
01127         else if ( ! strncmp(argv[ac], "-f_pn_mm", 9) )
01128         {
01129             if ( (ac+1) >= argc )
01130             {
01131                 fputs( "option usage: -f_pn_mm DISTANCE\n\n", stderr );
01132                 usage( PROG_NAME, V2S_USE_SHORT );
01133                 RETURN(-1);
01134             }
01135 
01136             opts->f_pn_mm = atof(argv[++ac]);
01137         }
01138         else if ( ! strncmp(argv[ac], "-f_steps", 7) )
01139         {
01140             if ( (ac+1) >= argc )
01141             {
01142                 fputs( "option usage: -f_steps NUM_STEPS\n\n", stderr );
01143                 usage( PROG_NAME, V2S_USE_SHORT );
01144                 RETURN(-1);
01145             }
01146 
01147             opts->f_steps = atoi(argv[++ac]);
01148         }
01149         else if ( ! strncmp(argv[ac], "-first_node", 11) )
01150         {
01151             if ( (ac+1) >= argc )
01152             {
01153                 fputs( "option usage: -first_node NODE_INDEX\n\n", stderr );
01154                 usage( PROG_NAME, V2S_USE_SHORT );
01155                 RETURN(-1);
01156             }
01157 
01158             opts->first_node = atoi(argv[++ac]);
01159         }
01160         else if ( ! strncmp(argv[ac], "-gp_index", 7) )
01161         {
01162             if ( (ac+1) >= argc )
01163             {
01164                 fputs( "option usage: -gp_index BRICK_INDEX\n\n", stderr );
01165                 usage( PROG_NAME, V2S_USE_SHORT );
01166                 RETURN(-1);
01167             }
01168 
01169             opts->gp_index = atoi(argv[++ac]);
01170         }
01171         else if ( ! strncmp(argv[ac], "-help", 5) )
01172         {
01173             usage( PROG_NAME, V2S_USE_LONG );
01174             RETURN(-1);
01175         }
01176         else if ( ! strncmp(argv[ac], "-hist", 5) )
01177         {
01178             usage( PROG_NAME, V2S_USE_HIST );
01179             RETURN(-1);
01180         }
01181         else if ( ! strncmp(argv[ac], "-v2s_hist", 9) )
01182         {
01183             usage( PROG_NAME, V2S_USE_LIB_HIST );
01184             RETURN(-1);
01185         }
01186         else if ( ! strncmp(argv[ac], "-grid_parent", 5) ||
01187                   ! strncmp(argv[ac], "-inset", 6)       ||
01188                   ! strncmp(argv[ac], "-input", 6) )
01189         {
01190             if ( (ac+1) >= argc )
01191             {
01192                 fputs( "option usage: -grid_parent INPUT_DSET\n\n", stderr );
01193                 usage( PROG_NAME, V2S_USE_SHORT );
01194                 RETURN(-1);
01195             }
01196 
01197             opts->gpar_file = argv[++ac];
01198         }
01199         else if ( ! strncmp(argv[ac], "-keep_norm_dir", 14) )
01200         {
01201             opts->norm_dir = V2S_NORM_KEEP;
01202         }
01203         else if ( ! strncmp(argv[ac], "-last_node", 11) )
01204         {
01205             if ( (ac+1) >= argc )
01206             {
01207                 fputs( "option usage: -last_node NODE_INDEX\n\n", stderr );
01208                 usage( PROG_NAME, V2S_USE_SHORT );
01209                 RETURN(-1);
01210             }
01211 
01212             opts->last_node = atoi(argv[++ac]);
01213         }
01214         else if ( ! strncmp(argv[ac], "-map_func", 4) )  /* mapping function */
01215         {
01216             if ( (ac+1) >= argc )
01217             {
01218                 fputs( "option usage: -map_func FUNCTION\n\n", stderr );
01219                 RETURN(-1);
01220             }
01221 
01222             opts->map_str = argv[++ac];     /* store user string for now */
01223         }
01224         else if ( ! strncmp(argv[ac], "-no_headers", 5) )
01225         {
01226             opts->no_head = 1;
01227         }
01228         else if ( ! strncmp(argv[ac], "-norm_len", 9) )
01229         {
01230             if ( (ac+1) >= argc )
01231             {
01232                 fputs( "option usage: -norm_len LENGTH\n\n", stderr );
01233                 usage( PROG_NAME, V2S_USE_SHORT );
01234                 RETURN(-1);
01235             }
01236 
01237             opts->norm_len = atof(argv[++ac]);
01238         }
01239         else if ( ! strncmp(argv[ac], "-oob_index", 8) )
01240         {
01241             if ( (ac+1) >= argc )
01242             {
01243                 fputs( "option usage: -oob_index INDEX_VALUE\n\n", stderr );
01244                 usage( PROG_NAME, V2S_USE_SHORT );
01245                 RETURN(-1);
01246             }
01247 
01248             opts->oob.show  = 1;
01249             opts->oob.index = atoi(argv[++ac]);
01250         }
01251         else if ( ! strncmp(argv[ac], "-oob_value", 8) )
01252         {
01253             if ( (ac+1) >= argc )
01254             {
01255                 fputs( "option usage: -oob_value VALUE\n\n", stderr );
01256                 usage( PROG_NAME, V2S_USE_SHORT );
01257                 RETURN(-1);
01258             }
01259 
01260             opts->oob.show  = 1;
01261             opts->oob.value = atof(argv[++ac]);
01262         }
01263         else if ( ! strncmp(argv[ac], "-oom_value", 8) )
01264         {
01265             if ( (ac+1) >= argc )
01266             {
01267                 fputs( "option usage: -oob_value VALUE\n\n", stderr );
01268                 usage( PROG_NAME, V2S_USE_SHORT );
01269                 RETURN(-1);
01270             }
01271 
01272             opts->oom.show  = 1;
01273             opts->oom.value = atof(argv[++ac]);
01274         }
01275         else if ( ! strncmp(argv[ac], "-out_1D", 7) )
01276         {
01277             if ( (ac+1) >= argc )
01278             {
01279                 fputs( "option usage: -out_1D OUTPUT_FILE\n\n", stderr );
01280                 usage( PROG_NAME, V2S_USE_SHORT );
01281                 RETURN(-1);
01282             }
01283 
01284             opts->outfile_1D = argv[++ac];
01285         }
01286         else if ( ! strncmp(argv[ac], "-out_niml", 7) )
01287         {
01288             if ( (ac+1) >= argc )
01289             {
01290                 fputs( "option usage: -out_niml OUTPUT_FILE\n\n", stderr );
01291                 usage( PROG_NAME, V2S_USE_SHORT );
01292                 RETURN(-1);
01293             }
01294 
01295             opts->outfile_niml = argv[++ac];
01296         }
01297         else if ( ! strncmp(argv[ac], "-reverse_norm_dir", 8) )
01298         {
01299             opts->norm_dir = V2S_NORM_REVERSE;
01300         }
01301         else if ( ! strncmp(argv[ac], "-skip_col_non_results", 15) )
01302             opts->skip_cols |= (V2S_SKIP_ALL & ~V2S_SKIP_VALS);
01303         else if ( ! strncmp(argv[ac], "-skip_col_nodes", 13) )
01304             opts->skip_cols |= V2S_SKIP_NODES;
01305         else if ( ! strncmp(argv[ac], "-skip_col_1dindex", 12) )
01306             opts->skip_cols |= V2S_SKIP_VOLIND;
01307         else if ( ! strncmp(argv[ac], "-skip_col_i", 11) )
01308             opts->skip_cols |= V2S_SKIP_I;
01309         else if ( ! strncmp(argv[ac], "-skip_col_j", 11) )
01310             opts->skip_cols |= V2S_SKIP_J;
01311         else if ( ! strncmp(argv[ac], "-skip_col_k", 11) )
01312             opts->skip_cols |= V2S_SKIP_K;
01313         else if ( ! strncmp(argv[ac], "-skip_col_vals", 13) )
01314             opts->skip_cols |= V2S_SKIP_NVALS;
01315         else if ( ! strncmp(argv[ac], "-skip_col_results", 13) )
01316             opts->skip_cols |= V2S_SKIP_VALS;
01317         else if ( ! strncmp(argv[ac], "-spec", 3) )
01318         {
01319             if ( (ac+1) >= argc )
01320             {
01321                 fputs( "option usage: -spec SPEC_FILE\n\n", stderr );
01322                 usage( PROG_NAME, V2S_USE_SHORT );
01323                 RETURN(-1);
01324             }
01325 
01326             opts->spec_file = argv[++ac];
01327         }
01328         else if ( ! strncmp(argv[ac], "-surf_", 6) )
01329         {
01330             if ( (ac+1) >= argc )
01331             {
01332                 fputs( "option usage: -surf_X SURF_NAME\n\n", stderr );
01333                 usage( PROG_NAME, V2S_USE_SHORT );
01334                 RETURN(-1);
01335             }
01336             ind = argv[ac][6] - 'A';
01337             if ( (ind < 0) || (ind >= V2S_MAX_SURFS) )
01338             {
01339                 fprintf(stderr,"** -surf_X option: '%s' out of range,\n"
01340                         "   use one of '-surf_A' through '-surf_%c'\n",
01341                         argv[ac], 'A'+V2S_MAX_SURFS-1);
01342                 RETURN(-1);
01343             }
01344 
01345             opts->snames[ind] = argv[++ac];
01346         }
01347         else if ( ! strncmp(argv[ac], "-sv", 3) )
01348         {
01349             if ( (ac+1) >= argc )
01350             {
01351                 fputs( "option usage: -sv SURFACE_VOLUME\n\n", stderr );
01352                 usage( PROG_NAME, V2S_USE_SHORT );
01353                 RETURN(-1);
01354             }
01355 
01356             opts->sv_file = argv[++ac];
01357         }
01358         else if ( ! strncmp(argv[ac], "-use_norms", 5) )
01359         {
01360             opts->use_norms = 1;
01361         }
01362         else if ( ! strncmp(argv[ac], "-version", 2) )
01363         {
01364             usage( PROG_NAME, V2S_USE_VERSION );
01365             RETURN(-1);
01366         }
01367         else     /* invalid option */
01368         {
01369             fprintf( stderr, "invalid option <%s>\n", argv[ac] );
01370             usage( PROG_NAME, V2S_USE_SHORT );
01371             RETURN(-1);
01372         }
01373     }
01374 
01375     RETURN(0);
01376 }

int insert_list node_list_t   N,
param_t   p,
s2v_opts_t   sopt,
THD_fvec3   pary,
int    nindex,
double *    ddata,
int *    idata
 

Definition at line 552 of file SUMA_3dSurf2Vol.c.

References s2v_opts_t::cmask, s2v_opts_t::debug, s2v_opts_t::dnode, DSET_NX, DSET_NY, ENTRY, param_t::f3mm_max, param_t::f3mm_min, f3mm_out_of_bounds(), s2v_opts_t::f_index, s2v_opts_t::f_steps, node_list_t::fdata, param_t::gpar, THD_ivec3::ijk, node_list_t::ilist, insert_value(), p, RETURN, S2V_F_INDEX_VOXEL, THD_3dmm_to_3dind(), and THD_fvec3::xyz.

Referenced by compute_results().

00554 {
00555     THD_ivec3 i3;
00556     int       vindex, prev_vind;
00557     int       step, node;
00558     int       nx, ny, debug;
00559 
00560 ENTRY("insert_list");
00561 
00562     if ( !N || !p || !sopt || !pary || nindex < 0 || !ddata || !cdata )
00563     {
00564         fprintf(stderr,"** ID params (%p,%p,%p,%p,%d,%p,%p)\n",
00565                 N, p, sopt, pary, nindex, ddata, cdata);
00566         RETURN(-1);
00567     }
00568 
00569     node = N->ilist[nindex];
00570 
00571     debug = sopt->debug && node == sopt->dnode;
00572 
00573     if ( debug )    /* show xyz coords? */
00574         fprintf(stderr,"++ point list for N[%d] = %d:\n", nindex, node);
00575 
00576     nx        = DSET_NX(p->gpar);
00577     ny        = DSET_NY(p->gpar);
00578     prev_vind = -1;
00579     for ( step = 0; step < sopt->f_steps; step++ )
00580     {
00581         if ( f3mm_out_of_bounds( pary+step, &p->f3mm_min, &p->f3mm_max ) )
00582             continue;
00583 
00584         i3 = THD_3dmm_to_3dind(p->gpar, pary[step]);
00585         vindex = i3.ijk[0] + nx * (i3.ijk[1] + ny * i3.ijk[2]);
00586 
00587         if ( debug )
00588             fprintf(stderr,"   %3d, vox %d, [%3d,%3d,%3d]: %f, %f, %f",
00589                     step, vindex, i3.ijk[0], i3.ijk[1], i3.ijk[2],
00590                     pary[step].xyz[0], pary[step].xyz[1], pary[step].xyz[2]);
00591 
00592         if ( sopt->cmask && !sopt->cmask[vindex] )
00593         {
00594             if ( debug ) fprintf(stderr, " : skip (mask)\n");
00595             continue;
00596         }
00597 
00598         if ( (vindex == prev_vind) && (sopt->f_index == S2V_F_INDEX_VOXEL) )
00599         {
00600             if ( debug ) fprintf(stderr, " : skip (repeat voxel)\n");
00601             continue;
00602         }
00603 
00604         /* hey, we finally have a new voxel to add */
00605 
00606         prev_vind = vindex;
00607 
00608         if ( debug )
00609             fprintf( stderr, " : (old) %d %f", cdata[vindex],ddata[vindex]);
00610 
00611         if (insert_value(sopt, ddata, cdata, vindex, node, N->fdata[nindex]))
00612             RETURN(-1);
00613 
00614         if ( debug )
00615             fprintf( stderr, " : (new) %d %f\n", cdata[vindex],ddata[vindex]);
00616     }
00617 
00618     RETURN(0);
00619 }

int insert_value s2v_opts_t   sopt,
double *    dv,
int *    iv,
int    vox,
int    node,
float    value
 

Definition at line 629 of file SUMA_3dSurf2Vol.c.

References s2v_opts_t::debug, s2v_opts_t::dvox, ENTRY, s2v_opts_t::map, and RETURN.

Referenced by insert_list().

00631 {
00632 ENTRY("insert_value");
00633 
00634     if ( !sopt || !dv || !cv || vox < 0 )
00635     {
00636         fprintf(stderr, "** IV: bad params (%p,%p,%p,%d)\n",sopt,dv,cv,vox);
00637         RETURN(-1);
00638     }
00639 
00640     if ( (sopt->debug > 1) && (vox == sopt->dvox) )
00641         fprintf(stderr,"++ voxel %d, node %d, values (%d, %f) ",
00642                 vox, node, cv[vox], dv[vox]);
00643 
00644     switch ( sopt->map )
00645     {
00646         default:
00647             fprintf(stderr,"** IV: mapping %d not ready\n", sopt->map );
00648             RETURN(-1);
00649 
00650         case E_SMAP_AVE:
00651             if ( cv[vox] == 0 )
00652                 dv[vox] = value;
00653             else
00654                 dv[vox] += value;               /* divide by count later */
00655             break;
00656 
00657         case E_SMAP_COUNT:
00658             if ( cv[vox] == 0 )
00659                 dv[vox] = 1.0;
00660             else
00661                 dv[vox]++;
00662             break;
00663 
00664         case E_SMAP_MAX:
00665             if ( cv[vox] == 0 )
00666                 dv[vox] = value;
00667             else if (value > dv[vox])
00668                 dv[vox] = value;
00669 
00670             break;
00671 
00672         case E_SMAP_MAX_ABS:
00673             if ( cv[vox] == 0 )
00674                 dv[vox] = value;
00675             else if (fabs(value) > fabs(dv[vox]))
00676                 dv[vox] = value;
00677 
00678             break;
00679 
00680         case E_SMAP_MIN:
00681             if ( cv[vox] == 0 )
00682                 dv[vox] = value;
00683             else if (value < dv[vox])
00684                 dv[vox] = value;
00685 
00686             break;
00687 
00688         case E_SMAP_MASK:
00689         case E_SMAP_MASK2:
00690             dv[vox] = 1.0;
00691             break;
00692     }
00693 
00694     cv[vox]++;          /* in any case, increment the counter */
00695 
00696     if ( (sopt->debug > 1) && (vox == sopt->dvox) )
00697         fprintf(stderr,"to (%d, %f)\n",cv[vox],dv[vox]);
00698 
00699     RETURN(0);
00700 }

int integral_doubles double *    dp,
int    nvals
 

Definition at line 3246 of file SUMA_3dSurf2Vol.c.

References ENTRY, and RETURN.

Referenced by s2v_nodes2volume().

03247 {
03248 ENTRY("integral_doubles");
03249 
03250     while ( nvals > 0 )
03251     {
03252         if ( ((double)(int)*dp) != *dp )
03253             RETURN(0);
03254 
03255         dp++;
03256         nvals--;
03257     }
03258 
03259     RETURN(1);
03260 }

int make_point_list THD_fvec3   list,
THD_fvec3   p1,
THD_fvec3   pn,
s2v_opts_t   sopt
 

Definition at line 710 of file SUMA_3dSurf2Vol.c.

References ENTRY, s2v_opts_t::f_steps, RETURN, and THD_fvec3::xyz.

Referenced by compute_results().

00712 {
00713     float rat1, ratn;
00714     int   step;
00715 
00716 ENTRY("make_point_list");
00717 
00718     if ( !list || !p1 || !pn || !sopt )
00719     {
00720         fprintf(stderr,"** mpl: bad params (%p,%p,%p,%p)\n", list,p1,pn,sopt);
00721         RETURN(-1);
00722     }
00723 
00724     list[0] = *p1;
00725 
00726     for ( step = 1; step < sopt->f_steps; step++ )
00727     {
00728         ratn = step / (sopt->f_steps - 1.0);
00729         rat1 = 1.0 - ratn;
00730 
00731         list[step].xyz[0] = rat1 * p1->xyz[0] + ratn * pn->xyz[0];
00732         list[step].xyz[1] = rat1 * p1->xyz[1] + ratn * pn->xyz[1];
00733         list[step].xyz[2] = rat1 * p1->xyz[2] + ratn * pn->xyz[2];
00734     }
00735 
00736     RETURN(0);
00737 }

int read_surf_files opts_t   opts,
param_t   p,
SUMA_SurfSpecFile   spec,
s2v_opts_t   sopt,
node_list_t   N
 

Definition at line 1307 of file SUMA_3dSurf2Vol.c.

References ENTRY, fill_node_list(), fill_SUMA_structs(), init_node_list(), p, read_sxyz_1D(), RETURN, opts_t::spec_file, opts_t::surf_xyz_1D_file, and verify_parser_expr().

01309 {
01310     int rv;
01311 
01312 ENTRY("read_surf_files");
01313 
01314     /* get surface coordinates */
01315     if ( opts->spec_file )
01316     {
01317         if ( (rv = fill_SUMA_structs(opts, spec)) != 0 )
01318             RETURN(rv);
01319     }
01320     else if ( opts->surf_xyz_1D_file )
01321     {
01322         if ( (rv = read_sxyz_1D( opts, p )) != 0 )
01323             RETURN(rv);
01324     }
01325     else
01326     {
01327         fprintf(stderr,"** missing spec or sdata file, exiting...\n");
01328         RETURN(-1);
01329     }
01330 
01331     /* assign node list nodes (xyz coords) */
01332     if ( (rv = init_node_list(opts, p, sopt, N)) != 0 )
01333         RETURN(rv);
01334 
01335     /* check status and allocate memory in node list */
01336     if ( (rv = fill_node_list(opts, p, N)) != 0 )
01337         RETURN(rv);
01338 
01339     if ( (rv = verify_parser_expr(opts, p)) != 0 )
01340         RETURN(rv);
01341 
01342     RETURN(0);
01343 }

int read_sxyz_1D opts_t   opts,
param_t   p
 

Definition at line 1350 of file SUMA_3dSurf2Vol.c.

References opts_t::debug, ENTRY, mri_free(), mri_read_1D(), mri_transpose(), MRI_IMAGE::nx, MRI_IMAGE::ny, p, RETURN, opts_t::surf_xyz_1D_file, and param_t::sxyz_im.

Referenced by read_surf_files().

01351 {
01352     MRI_IMAGE * im;
01353 
01354 ENTRY("read_sxyz_1D");
01355 
01356     if ( !opts || !p )
01357     {
01358         fprintf(stderr,"** rsxyz1D: bad params (%p,%p)\n", opts, p);
01359         RETURN(-1);
01360     }
01361 
01362     if ( (im = mri_read_1D(opts->surf_xyz_1D_file)) == NULL )
01363     {
01364         fprintf(stderr,"** failed to read sxyz 1D file '%s'\n",
01365                 opts->surf_xyz_1D_file);
01366         RETURN(-1);
01367     }
01368     if ( im->nx < 1 || im->ny < 3 )     /* must have xyz coords, at least */
01369     {
01370         fprintf(stderr,"** bad sxyz file '%s'?\n", opts->surf_xyz_1D_file);
01371         RETURN(-1);
01372     }
01373 
01374     /* transpose list to node-major order, and lose temp image */
01375     p->sxyz_im = mri_transpose(im);
01376     mri_free(im);
01377 
01378     if ( opts->debug > 0 )
01379         fprintf(stderr,"++ read 1D xyz surface file '%s' (nx = %d, ny = %d)\n",
01380                 opts->surf_xyz_1D_file, p->sxyz_im->nx, p->sxyz_im->ny );
01381 
01382     RETURN(0);
01383 }

int s2v_map_type char *    map_str
 

Definition at line 2172 of file SUMA_3dSurf2Vol.c.

References ENTRY, gs2v_map_names, RETURN, and s2v_map_num.

Referenced by check_map_func().

02173 {
02174     s2v_map_num map;
02175 
02176 ENTRY("s2v_map_type");
02177 
02178     if ( map_str == NULL )
02179     {
02180         fprintf( stderr, "** s2v_map_type: missing map_str parameter\n" );
02181         RETURN((int)E_SMAP_INVALID);
02182     }
02183 
02184     if ( sizeof(gs2v_map_names) / sizeof(char *) != (int)E_SMAP_FINAL )
02185     {
02186         fprintf( stderr, "** error:  gs2v_map_names/s2v_map_num mis-match\n");
02187         RETURN((int)E_SMAP_INVALID);
02188     }
02189 
02190     for ( map = E_SMAP_MASK; map < E_SMAP_FINAL; map++ )
02191         if ( !strcmp( map_str, gs2v_map_names[map] ) )
02192             RETURN((int)map);
02193 
02194     RETURN((int)E_SMAP_INVALID);
02195 }

THD_3dim_dataset* s2v_nodes2volume node_list_t   N,
param_t   p,
s2v_opts_t   sopt
 

Definition at line 254 of file SUMA_3dSurf2Vol.c.

References ADN_datum_all, ADN_func_type, ADN_none, ADN_ntt, ADN_nvals, ADN_type, amax, compute_results(), s2v_opts_t::datum, s2v_opts_t::debug, DSET_BRICK_FACTOR, DSET_delete, DSET_HEADNAME, DSET_NVOX, EDIT_coerce_scale_type(), EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), ENTRY, s2v_opts_t::f_steps, free, FUNC_BUCK_TYPE, param_t::gpar, HEAD_FUNC_TYPE, integral_doubles(), ISVALID_3DIM_DATASET, ISVALID_DSET, malloc, MCW_vol_amax(), mri_datum_size(), MRI_IS_INT_TYPE, s2v_opts_t::noscale, param_t::nsubs, p, RETURN, and set_node_list_data().

Referenced by write_output().

00256 {
00257     THD_3dim_dataset * dout;
00258     THD_fvec3        * pary;
00259     double           * ddata;
00260     void             * vdata = NULL;
00261     int              * cdata;
00262     float              fac;
00263     int                nvox, dsize, valid;
00264     int                sub;
00265 
00266 ENTRY("s2v_nodes2volume");
00267 
00268     if ( N == NULL || ! ISVALID_DSET(p->gpar) )
00269     {
00270         fprintf(stderr,"** s2v_nodes2volume: bad params (%p,%p)\n", N, p->gpar);
00271         RETURN(NULL);
00272     }
00273 
00274     dout = EDIT_empty_copy( p->gpar );
00275     if ( ! ISVALID_3DIM_DATASET( dout ) )
00276     {
00277         fprintf( stderr, "** failed EDIT_empty_copy()\n" );
00278         RETURN(NULL);
00279     }
00280 
00281     /* output dataset will have nsubs sub-bricks */
00282     EDIT_dset_items( dout, ADN_nvals,     p->nsubs,
00283                            ADN_type,      HEAD_FUNC_TYPE,
00284                            ADN_func_type, FUNC_BUCK_TYPE,
00285                            ADN_datum_all, sopt->datum,
00286                            ADN_ntt,       0,
00287                      ADN_none );
00288 
00289     if ( sopt->debug > 1 )
00290         fprintf( stderr, "++ creating dataset '%s' of type '%s', nvals = %d\n",
00291                  DSET_HEADNAME(dout), MRI_TYPE_name[sopt->datum], p->nsubs );
00292 
00293     nvox  = DSET_NVOX(p->gpar);
00294 
00295     /* allocate a computational array of doubles */
00296     if ( (ddata = (double *)malloc(nvox * sizeof(double))) == NULL )
00297     {
00298         fprintf( stderr, "** n2v: failed to allocate %d doubles\n", nvox );
00299         DSET_delete( dout );
00300         RETURN(NULL);
00301     }
00302     
00303     /* allocate an array of ints for functional counting */
00304     if ( (cdata = (int *)malloc(nvox * sizeof(int))) == NULL )
00305     {
00306         fprintf( stderr, "** n2v: failed to allocate %d ints\n", nvox );
00307         DSET_delete( dout );  free( ddata );
00308         RETURN(NULL);
00309     }
00310 
00311     /* allocate space for the point list */
00312     if ( (pary = (THD_fvec3 *)malloc(sopt->f_steps*sizeof(THD_fvec3))) == NULL )
00313     {
00314         fprintf(stderr,"** n2v: cannot allocate %d THD_fvec3s\n",sopt->f_steps);
00315         DSET_delete( dout );  free( ddata );  free( cdata );
00316         RETURN(NULL);
00317     }
00318     
00319     dsize = mri_datum_size(sopt->datum);
00320     /* create the sub-brick data for output */
00321     for ( sub = 0; sub < p->nsubs; sub++ )
00322     {
00323         valid = 0;
00324 
00325         /* need new data after each sub-brick is attached to the dset */
00326         if ( (vdata = malloc( nvox * dsize )) == NULL )
00327         {
00328             fprintf( stderr, "** failed to allocate %d bytes for vdata\n",
00329                      nvox * dsize );
00330             DSET_delete( dout );  free( ddata );  free( cdata );
00331             RETURN(NULL);
00332         }
00333 
00334         /* init data to zeros */
00335         memset(cdata, 0, nvox*sizeof(int));
00336         memset(ddata, 0, nvox*sizeof(double));
00337 
00338         /* set node_list data */
00339         if ( set_node_list_data( N, p, sopt, sub ) != 0 )
00340         {
00341             DSET_delete(dout);
00342             free(ddata);
00343             free(cdata);
00344             free(vdata);
00345 
00346             RETURN(NULL);
00347         }
00348 
00349         if ( compute_results( p, N, sopt, ddata, cdata, pary ) == 0 )
00350             valid = 1;
00351 
00352         if ( ! valid )  /* then clean up memory */
00353         {
00354             free( ddata );
00355             free( vdata );
00356             DSET_delete( dout );
00357             RETURN(NULL);
00358         }
00359 
00360         /* convert to output data type */
00361         fac = 0.0;
00362 
00363         if ( sopt->debug > 1 )
00364             fprintf(stderr,"++ sub-brick %d, integral_doubles = %d\n",
00365                     sub, integral_doubles( ddata, nvox ));
00366 
00367         /* for int output and scaling, fac is maxval/maxabs */
00368         if ( MRI_IS_INT_TYPE( sopt->datum ) && !sopt->noscale )
00369         {
00370             float amax = MCW_vol_amax( nvox, 1, 1, MRI_double, ddata );
00371 
00372             if ( amax > MRI_TYPE_maxval[sopt->datum] )      /* we must scale */
00373                 fac = MRI_TYPE_maxval[sopt->datum]/amax;
00374             else if ( integral_doubles( ddata, nvox ) )  /* don't need scale */
00375                 fac = 0.0;
00376             else if ( amax != 0.0 )
00377                 fac = MRI_TYPE_maxval[sopt->datum]/amax;
00378 
00379             if ( sopt->debug > 1 )
00380                 fprintf(stderr,"++ fac = %f, amax = %f \n", fac, amax);
00381         }
00382 
00383         EDIT_coerce_scale_type(nvox, fac, MRI_double,ddata, sopt->datum,vdata);
00384 
00385         /* attach the final vdata to the dataset */
00386         EDIT_substitute_brick( dout, sub, sopt->datum, vdata );
00387         DSET_BRICK_FACTOR( dout, sub ) = (fac != 0.0) ? 1.0/fac : 0.0;
00388     }
00389 
00390     if (sopt->debug > 0)
00391         fprintf(stderr,"++ %d sub-brick(s) computed\n", p->nsubs);
00392 
00393     free(ddata);
00394     free(cdata);
00395     free(pary);
00396 
00397     RETURN(dout);
00398 }

int sdata_from_1D opts_t   opts,
param_t   p,
node_list_t   N
 

Definition at line 1573 of file SUMA_3dSurf2Vol.c.

References c, opts_t::debug, ENTRY, fim, node_list_t::ilen, node_list_t::ilist, malloc, MRI_FLOAT_PTR, mri_free(), mri_read_1D(), mri_transpose(), MRI_IMAGE::nx, MRI_IMAGE::ny, p, RETURN, opts_t::sdata_file_1D, and param_t::sdata_im.

Referenced by fill_node_list().

01574 {
01575     MRI_IMAGE * im;
01576     float     * fim;
01577     int         c;
01578 
01579 ENTRY("sdata_from_1D");
01580 
01581     if ( !opts || !N || !p )
01582         RETURN(-1);
01583 
01584     if ( (im = mri_read_1D(opts->sdata_file_1D)) == NULL )
01585     {
01586         fprintf(stderr,"** failed to read 1D file '%s'\n", opts->sdata_file_1D);
01587         RETURN(-2);
01588     }
01589     /* transpose list to node-major order, and lose temp image */
01590     p->sdata_im = mri_transpose(im);
01591     mri_free(im);
01592 
01593     if ( p->sdata_im->nx < 2 || p->sdata_im->ny < 1 )
01594     {
01595         fprintf(stderr,"** bad (%d x %d) surf data 1D file '%s'\n",
01596                 p->sdata_im->ny, p->sdata_im->nx, opts->sdata_file_1D);
01597         RETURN(-3);
01598     }
01599 
01600     N->ilen = p->sdata_im->ny;
01601 
01602     if ( opts->debug > 0 )
01603         fprintf(stderr,"++ read 1D surface file '%s' (nx = %d, ny = %d)\n",
01604                 opts->sdata_file_1D, p->sdata_im->nx, p->sdata_im->ny );
01605 
01606     /* only allocate space ilist */
01607     if ( (N->ilist = (int *)malloc(N->ilen*sizeof(int))) == NULL )
01608     {
01609         fprintf(stderr,"** sf1D a: failed to allocate %d ints\n", N->ilen);
01610         RETURN(-1);
01611     }
01612 
01613     /* first set the node index values */
01614     fim = MRI_FLOAT_PTR( p->sdata_im );
01615     for ( c = 0; c < N->ilen; c++, fim += p->sdata_im->nx )
01616         N->ilist[c] = (int)*fim;                          /* set node index */
01617 
01618     RETURN(0);
01619 }

int sdata_from_default node_list_t   N
 

Definition at line 1544 of file SUMA_3dSurf2Vol.c.

References c, ENTRY, node_list_t::ilen, node_list_t::ilist, malloc, node_list_t::nnodes, and RETURN.

Referenced by fill_node_list().

01545 {
01546     int c;
01547 
01548 ENTRY("sdata_from_default");
01549 
01550     if ( !N )
01551         RETURN(-1);
01552 
01553     if ( (N->ilist = (int *)malloc(N->nnodes * sizeof(int))) == NULL )
01554     {
01555         fprintf(stderr,"** failed to allocate %d ints for ilist\n",N->nnodes);
01556         RETURN(-1);
01557     }
01558 
01559     N->ilen   = N->nnodes;
01560 
01561     /* now fill ilist with default node indices */
01562     for ( c = 0; c < N->ilen; c++ )
01563         N->ilist[c] = c;
01564 
01565     RETURN(0);
01566 }

int set_3dmm_bounds THD_3dim_dataset   dset,
THD_fvec3   min,
THD_fvec3   max
 

Definition at line 1278 of file vol2surf.c.

01279 {
01280     float tmp;
01281     int   c;
01282                                                                                 
01283 ENTRY("set_3dmm_bounds");
01284                                                                                 
01285     if ( !dset || !min || !max )
01286     {
01287         fprintf(stderr, "** invalid params to set_3dmm_bounds: (%p,%p,%p)\n",
01288                 dset, min, max );
01289         RETURN(-1);
01290     }
01291                                                                                 
01292     /* get undirected bounds */
01293     min->xyz[0] = DSET_XORG(dset) - 0.5 * DSET_DX(dset);
01294     max->xyz[0] = min->xyz[0] + DSET_NX(dset) * DSET_DX(dset);
01295                                                                                 
01296     min->xyz[1] = DSET_YORG(dset) - 0.5 * DSET_DY(dset);
01297     max->xyz[1] = min->xyz[1] + DSET_NY(dset) * DSET_DY(dset);
01298                                                                                 
01299     min->xyz[2] = DSET_ZORG(dset) - 0.5 * DSET_DZ(dset);
01300     max->xyz[2] = min->xyz[2] + DSET_NZ(dset) * DSET_DZ(dset);
01301                                                                                 
01302     for ( c = 0; c < 3; c++ )
01303         if ( min->xyz[c] > max->xyz[c] )
01304         {
01305             tmp = min->xyz[c];
01306             min->xyz[c] = max->xyz[c];
01307             max->xyz[c] = tmp;
01308         }
01309                                                                                 
01310     RETURN(0);
01311 }

int set_node_list_data node_list_t   N,
param_t   p,
s2v_opts_t   sopt,
int    col
 

Definition at line 817 of file SUMA_3dSurf2Vol.c.

References parser_t::atoz, c, s2v_opts_t::debug, ENTRY, node_list_t::fdata, node_list_t::ilen, parser_t::max_sym, MRI_FLOAT_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, p, param_t::parser, PARSER_evaluate_one(), parser_t::pcode, RETURN, and param_t::sdata_im.

Referenced by s2v_nodes2volume().

00818 {
00819     float * fp, fval;
00820     int     c, lposn;
00821 
00822 ENTRY("set_node_list_data");
00823 
00824     if ( !N || !p || !sopt || col < 0 )
00825     {
00826         fprintf(stderr,"** snld: bad params (%p,%p,%p,%d)\n", N, p, sopt, col);
00827         RETURN(-1);
00828     }
00829 
00830     if ( sopt->debug > 1 )
00831         fprintf(stderr, "-- setting fdata for column %d\n", col);
00832 
00833     /* if sdata_im does not exist, fill as mask and return */
00834     if ( !p->sdata_im )
00835     {
00836         fval = 1.0;     /* init to mask value */
00837 
00838         /* if we have a PARSER_code (presumably without symbols), use it */
00839         if ( p->parser.pcode )
00840         {
00841             for ( c = 0; c < 26; c++ )
00842                 p->parser.atoz[c] = 0.0;
00843             fval = PARSER_evaluate_one( p->parser.pcode, p->parser.atoz );
00844         }
00845 
00846         for ( c = 0; c < N->ilen; c++ )
00847             N->fdata[c] = fval;
00848 
00849         RETURN(0);
00850     }
00851     
00852     /* else sdata exists: check column, and copy data from sdata_im */
00853     if ( col > (p->sdata_im->nx - 2) && !p->parser.pcode )
00854     {
00855         fprintf(stderr,"** snld error: col > nx-2 (%d > %d)\n",
00856                 col, p->sdata_im->nx-2);
00857         RETURN(-1);
00858     }
00859     else if ( p->sdata_im->ny < N->ilen )
00860     {
00861         fprintf(stderr,"** snld error: ny < ilen (%d < %d)\n",
00862                 p->sdata_im->ny, N->ilen);
00863         RETURN(-1);
00864     }
00865     else if ( !N->fdata )
00866     {
00867         fprintf(stderr,"** snld error: missing idata\n");
00868         RETURN(-1);
00869     }
00870     else if ( p->parser.pcode && col != 0 )             /* let's be safe */
00871     {
00872         fprintf(stderr,"** snld error: cannot use parser with col = %d\n", col);
00873         RETURN(-1);
00874     }
00875 
00876     /* hmmmm, we're still missing something...  oh yes, data! */
00877 
00878     fp = MRI_FLOAT_PTR( p->sdata_im ) + col+1;  /* offset by column number */
00879 
00880     for ( c = 0; c < N->ilen; c++ )
00881     {
00882         if ( p->parser.pcode )
00883         {
00884             /* fill atoz with surface node data */
00885             for ( lposn = 0; lposn < p->parser.max_sym; lposn++ )
00886                 p->parser.atoz[lposn] = fp[lposn];
00887 
00888             N->fdata[c] = PARSER_evaluate_one(p->parser.pcode, p->parser.atoz);
00889         }
00890         else
00891             N->fdata[c] = *fp;
00892 
00893         fp += p->sdata_im->nx;
00894     }
00895 
00896     RETURN(0);
00897 }

int set_smap_opts opts_t   opts,
param_t   p,
s2v_opts_t   sopt
 

Definition at line 1197 of file SUMA_3dSurf2Vol.c.

References check_datum_type(), check_map_func(), param_t::cmask, s2v_opts_t::cmask, s2v_opts_t::datum, opts_t::datum_str, opts_t::debug, s2v_opts_t::debug, disp_s2v_opts_t(), opts_t::dnode, s2v_opts_t::dnode, DSET_BRICK_TYPE, opts_t::dvox, s2v_opts_t::dvox, ENTRY, s2v_opts_t::f_index, opts_t::f_index_str, opts_t::f_p1_fr, s2v_opts_t::f_p1_fr, opts_t::f_p1_mm, s2v_opts_t::f_p1_mm, opts_t::f_pn_fr, s2v_opts_t::f_pn_fr, opts_t::f_pn_mm, s2v_opts_t::f_pn_mm, s2v_opts_t::f_steps, opts_t::f_steps, param_t::gpar, s2v_opts_t::map, opts_t::map_str, s2v_opts_t::noscale, opts_t::noscale, p, RETURN, S2V_F_INDEX_POINT, S2V_F_INDEX_VOXEL, S2V_F_STEPS_MIN, S2V_MAX_SURFS, opts_t::snames, opts_t::sxyz_ori_gpar, and s2v_opts_t::sxyz_ori_gpar.

01198 {
01199     int nsurf;
01200 
01201 ENTRY("set_smap_opts");
01202 
01203     memset( sopt, 0, sizeof(*sopt) );   /* clear the sopt struct */
01204     sopt->cmask = NULL;
01205 
01206     if ( (sopt->map = check_map_func( opts->map_str )) == E_SMAP_INVALID )
01207         RETURN(-1);
01208 
01209     sopt->datum = check_datum_type(opts->datum_str, DSET_BRICK_TYPE(p->gpar,0));
01210     if (sopt->datum < 0)
01211         RETURN(-1);
01212 
01213     if ( opts->noscale == 1 )
01214         sopt->noscale = 1;
01215 
01216     sopt->debug         = opts->debug;  /* for output in library functions */
01217     sopt->dnode         = opts->dnode;
01218     sopt->dvox          = opts->dvox;
01219     sopt->sxyz_ori_gpar = opts->sxyz_ori_gpar;
01220     sopt->cmask         = p->cmask;
01221 
01222     if ( opts->f_steps < S2V_F_STEPS_MIN )             /* minimum is 1    */
01223     {
01224         /* if f_steps was not given, init to the number of surfaces  - v3.6 */
01225         for ( nsurf = 0; nsurf < S2V_MAX_SURFS && opts->snames[nsurf]; nsurf++ )
01226             ;
01227         if ( nsurf <= 0 )
01228         {
01229             fprintf(stderr,"** error: sso: no input surfaces\n");
01230             RETURN(-1);
01231         }
01232         sopt->f_steps = nsurf;
01233     }
01234     else
01235         sopt->f_steps = opts->f_steps;
01236 
01237     sopt->f_index = S2V_F_INDEX_VOXEL;
01238     if ( (opts->f_index_str != NULL) &&
01239          ( !strncmp(opts->f_index_str, "point", 5) ||
01240            !strncmp(opts->f_index_str, "node",  4) ) ) /* preserve old use */
01241         sopt->f_index = S2V_F_INDEX_POINT;
01242 
01243     sopt->f_p1_fr = opts->f_p1_fr;         /* copy fractions & distances */
01244     sopt->f_pn_fr = opts->f_pn_fr;
01245     sopt->f_p1_mm = opts->f_p1_mm;
01246     sopt->f_pn_mm = opts->f_pn_mm;
01247 
01248 
01249     switch (sopt->map)
01250     {
01251         default:
01252 
01253         case E_SMAP_AVE:
01254         case E_SMAP_MAX:
01255         case E_SMAP_MIN:
01256         case E_SMAP_MAX_ABS:
01257             break;
01258 
01259         case E_SMAP_COUNT:
01260         case E_SMAP_MASK:
01261         case E_SMAP_MASK2:
01262             sopt->noscale = 1;
01263             break;
01264     }
01265 
01266     if ( opts->debug > 1 )
01267         disp_s2v_opts_t( "++ s2v_opts_set :", sopt );
01268 
01269     RETURN(0);
01270 }

int surf_to_node_list s2v_opts_t   sopt,
node_list_t   N,
int    nsurf
 

Definition at line 1055 of file SUMA_3dSurf2Vol.c.

References calloc, s2v_opts_t::debug, node_list_t::depth, ENTRY, free, get_mappable_surfs(), malloc, SUMA_SurfaceObject::N_Node, node_list_t::nnodes, SUMA_SurfaceObject::NodeList, node_list_t::nodes, RETURN, and THD_fvec3::xyz.

Referenced by init_node_list().

01056 {
01057     SUMA_SurfaceObject ** so;
01058     THD_fvec3          *  fvp;
01059     float              *  fp;
01060     int                   rv, nindex, sindex;
01061 
01062 ENTRY("surf_to_node_list");
01063 
01064     if ( sopt == NULL || N == NULL || nsurf < 0 || nsurf > 2 )
01065     {
01066         fprintf( stderr, "** anl: bad params (%p,%p,%d)\n",
01067                  sopt, N, nsurf );
01068         RETURN(-1);
01069     }
01070 
01071     /* create a temporary list of surface pointers */
01072     so = (SUMA_SurfaceObject **)calloc(nsurf, sizeof(SUMA_SurfaceObject *));
01073     if ( so == NULL )
01074     {
01075         fprintf( stderr, "** anl: failed to alloc %d surf pointers\n", nsurf );
01076         RETURN(-1);
01077     }
01078 
01079     if ( (rv = get_mappable_surfs( so, nsurf, sopt->debug )) != nsurf )
01080     {
01081         fprintf( stderr, "** error: found %d (of %d) mappable surfaces\n",
01082                 rv, nsurf );
01083         RETURN(-1);
01084     }
01085 
01086     /* fill node list struct */
01087     N->depth  = nsurf;
01088     N->nnodes = so[0]->N_Node;
01089     N->nodes  = (THD_fvec3 *)malloc(N->depth * N->nnodes * sizeof(THD_fvec3));
01090     if ( N->nodes == NULL )
01091     {
01092         fprintf( stderr, "** cnlm: failed to allocate %d THD_fvec3 structs\n",
01093                  N->depth * N->nnodes );
01094         free(so);
01095         RETURN(-1);
01096     }
01097 
01098     /* copy the xyz coordinates for each node */
01099 
01100     fvp = N->nodes;     /* linear coverage of all nodes */
01101     for ( sindex = 0; sindex < N->depth; sindex++ )
01102     {
01103         if ( so[sindex]->N_Node != N->nnodes )
01104         {
01105             fprintf(stderr, "** surf #%d (%s) has %d nodes (but expected %d)\n",
01106                     sindex,
01107                     so[sindex]->Label ? so[sindex]->Label : "<unnamed>",
01108                     so[sindex]->N_Node, N->nnodes );
01109             free( N->nodes );  N->nodes = NULL;
01110             free(so);
01111             RETURN(-1);
01112         }
01113 
01114         for ( nindex = 0, fp = so[sindex]->NodeList;
01115               nindex < N->nnodes;
01116               nindex++, fp += 3 )
01117         {
01118             memcpy( fvp->xyz, fp, 3*sizeof(float) );
01119             fvp++;
01120         }
01121     }
01122 
01123     if ( sopt->debug > 1 )
01124         fprintf( stderr, "++ allocated %d x %d (x %d) node list\n",
01125                  N->depth, N->nnodes, (int)sizeof(THD_fvec3) );
01126 
01127     free(so);
01128     RETURN(0);
01129 }

int sxyz_1D_to_nlist opts_t   opts,
s2v_opts_t   sopt,
param_t   p,
node_list_t   N,
int *    nsurf
 

Definition at line 963 of file SUMA_3dSurf2Vol.c.

References c, s2v_opts_t::debug, node_list_t::depth, s2v_opts_t::dnode, ENTRY, malloc, MRI_FLOAT_PTR, node_list_t::nnodes, node_list_t::nodes, MRI_IMAGE::nx, MRI_IMAGE::ny, p, RETURN, opts_t::surf_xyz_1D_file, param_t::sxyz_im, and THD_fvec3::xyz.

Referenced by init_node_list().

00965 {
00966     THD_fvec3 * fvp;
00967     float     * fp;
00968     int         c, sc;
00969 
00970 ENTRY("sxyz_1D_to_nlist");
00971 
00972     if ( !sopt || !p || !N )
00973     {
00974         fprintf(stderr,"** sxyz2nl: bad params (%p,%p,%p)\n",sopt,p,N);
00975         RETURN(-1);
00976     }
00977 
00978     if ( !p->sxyz_im )
00979     {
00980         fprintf(stderr,"** missing sxyz_im for sxyz surf '%s'\n",
00981                 opts->surf_xyz_1D_file);
00982         RETURN(-1);
00983     }
00984 
00985     *nsurf = p->sxyz_im->nx / 3;
00986 
00987     if ( p->sxyz_im->nx != 3 * *nsurf )
00988     {
00989         fprintf(stderr,"** sxyz surf '%s' has %d columns (%d expected)\n",
00990                 opts->surf_xyz_1D_file, p->sxyz_im->nx, 3**nsurf);
00991         RETURN(-1);
00992     }
00993     else if ( p->sxyz_im->ny <= 0 )
00994     {
00995         fprintf(stderr,"** sxyz surf '%s': bad sxyz dimensions (%d,%d)\n",
00996                 opts->surf_xyz_1D_file, p->sxyz_im->nx, p->sxyz_im->ny);
00997         RETURN(-1);
00998     }
00999 
01000     N->depth = *nsurf;
01001     N->nnodes = p->sxyz_im->ny;
01002 
01003     N->nodes = (THD_fvec3 *)malloc(N->depth*N->nnodes*sizeof(THD_fvec3));
01004     if ( N->nodes == NULL )
01005     {
01006         fprintf(stderr,"** failed to allocate %dx%d THD_fvec3's for nodes\n",
01007                 N->nnodes, N->depth);
01008         RETURN(-1);
01009     }
01010 
01011     fvp = N->nodes;
01012     for ( sc = 0; sc < *nsurf; sc++ )
01013     {
01014         fp = MRI_FLOAT_PTR( p->sxyz_im ) + sc * 3;      /* offset for surf */
01015         for ( c = 0; c < N->nnodes; c++ )
01016         {
01017             fvp->xyz[0] = fp[0];
01018             fvp->xyz[1] = fp[1];
01019             fvp->xyz[2] = fp[2];
01020 
01021             fp += p->sxyz_im->nx;
01022             fvp++;
01023         }
01024     }
01025 
01026     if ( sopt->debug > 0 )
01027     {
01028         fprintf(stderr, "++ sxyz_1D nodes from '%s': nxyz = %d, nsurf = %d\n",
01029                 opts->surf_xyz_1D_file, N->nnodes, N->depth);
01030         if ( sopt->dnode >= 0 && sopt->dnode <= p->sxyz_im->ny )
01031         {
01032             fprintf(stderr,"   debug node (%d) loc", sopt->dnode);
01033             for ( sc = 0; sc < *nsurf; sc++ )
01034                 fprintf(stderr," : (%f, %f, %f)",
01035                     N->nodes[sopt->dnode + sc*N->nnodes].xyz[0],
01036                     N->nodes[sopt->dnode + sc*N->nnodes].xyz[1],
01037                     N->nodes[sopt->dnode + sc*N->nnodes].xyz[2]);
01038             fputc('\n', stderr);
01039         }
01040     }
01041 
01042     RETURN(0);
01043 }

int usage char *    prog,
int    level
 

Definition at line 1634 of file SUMA_3dVol2Surf.c.

01635 {
01636 ENTRY("usage");
01637 
01638     if ( level == V2S_USE_SHORT )
01639     {
01640         fprintf( stderr,
01641                  "usage: %s [options] -spec SPEC_FILE -sv SURF_VOL "
01642                                     " -grid_parent AFNI_DSET\n"
01643                  "usage: %s -help\n",
01644                  prog, prog );
01645     }
01646     else if ( level == V2S_USE_LONG )
01647     {
01648         printf(
01649             "\n"
01650             "%s - map data from a volume domain to a surface domain\n"
01651             "\n"
01652             "  usage: %s [options] -spec SPEC_FILE -sv SURF_VOL \\\n"
01653             "                    -grid_parent AFNI_DSET -map_func MAP_FUNC\n"
01654             "\n"
01655             "This program is used to map data values from an AFNI volume\n"
01656             "dataset to a surface dataset.  A filter may be applied to the\n"
01657             "volume data to produce the value(s) for each surface node.\n"
01658             "\n"
01659             "The surface and volume domains are spacially matched via the\n"
01660             "'surface volume' AFNI dataset.  This gives each surface node xyz\n"
01661             "coordinates, which are then matched to the input 'grid parent'\n"
01662             "dataset.  This grid parent is an AFNI dataset containing the\n"
01663             "data values destined for output.\n"
01664             "\n"
01665             "Typically, two corresponding surfaces will be input (via the\n"
01666             "spec file and the '-surf_A' and '-surf_B' options), along with\n"
01667             "a mapping function and relevant options.  The mapping function\n"
01668             "will act as a filter over the values in the AFNI volume.\n"
01669             "\n"
01670             "Note that an alternative to using a second surface with the\n"
01671             "'-surf_B' option is to define the second surface by using the\n"
01672             "normals from the first surface.  By default, the second surface\n"
01673             "would be defined at a distance of 1mm along the normals, but the\n"
01674             "user may modify the applied distance (and direction).  See the\n"
01675             "'-use_norms' and '-norm_len' options for more details.\n"
01676             "\n"
01677             "For each pair of corresponding surface nodes, let NA be the node\n"
01678             "on surface A (such as a white/grey boundary) and NB be the\n"
01679             "corresponding node on surface B (such as a pial surface).  The\n"
01680             "filter is applied to the volume data values along the segment\n"
01681             "from NA to NB (consider the average or maximum as examples of\n"
01682             "filters).\n"
01683             "\n"
01684             "Note: if either endpoint of a segment is outside the grid parent\n"
01685             "      volume, that node (pair) will be skipped.\n"
01686             "\n"
01687             "Note: surface A corresponds to the required '-surf_A' argument,\n"
01688             "      while surface B corresponds to '-surf_B'.\n"
01689             "\n",
01690             prog, prog);
01691 
01692         printf(
01693             "By default, this segment only consists of the endpoints, NA and\n"
01694             "NB (the actual nodes on the two surfaces).  However the number\n"
01695             "of evenly spaced points along the segment may be specified with\n"
01696             "the -f_steps option, and the actual locations of NA and NB may\n"
01697             "be altered with any of the -f_pX_XX options, covered below.\n"
01698             "\n"
01699             "As an example, for each node pair, one could output the average\n"
01700             "value from some functional dataset along a segment of 10 evenly\n"
01701             "spaced points, where the segment endpoints are defined by the\n"
01702             "xyz coordinates of the nodes.  This is example 3, below.\n"
01703             "\n"
01704             "The mapping function (i.e. filter) is a required parameter to\n"
01705             "the program.\n"
01706             "\n"
01707             "Brief descriptions of the current mapping functions are as\n"
01708             "follows.  These functions are defined over a segment of points.\n"
01709             "\n"
01710             "    ave       : output the average of all voxel values along the\n"
01711             "                segment\n"
01712             "    mask      : output the voxel value for the trivial case of a\n"
01713             "                segment - defined by a single surface point\n"
01714             "    median    : output the median value from the segment\n"
01715             "    midpoint  : output the dataset value at the segment midpoint\n"
01716             "    mode      : output the mode of the values along the segment\n"
01717             "    max       : output the maximum volume value over the segment\n"
01718             "    max_abs   : output the dataset value with max abs over seg\n"
01719             "    min       : output the minimum volume value over the segment\n"
01720             "    seg_vals  : output _all_ volume values over the segment (one\n"
01721             "                sub-brick only)\n"
01722             "\n"
01723             );
01724 
01725         printf(
01726             "  --------------------------------------------------\n"
01727             "\n"
01728             "  examples:\n"
01729             "\n"
01730             "    1. Apply a single surface mask to output volume values over\n"
01731             "       each surface node.  Output is one value per sub-brick\n"
01732             "       (per surface node).\n"
01733             "\n"
01734             "    %s                                \\\n"
01735             "       -spec         fred.spec                \\\n"
01736             "       -surf_A       smoothwm                 \\\n"
01737             "       -sv           fred_anat+orig           \\\n"
01738             "       -grid_parent  fred_anat+orig           \\\n"
01739             "       -map_func     mask                     \\\n"
01740             "       -out_1D       fred_anat_vals.1D\n"
01741             "\n"
01742             "    2. Apply a single surface mask to output volume values over\n"
01743             "       each surface node.  In this case restrict input to the\n"
01744             "       mask implied by the -cmask option.  Supply additional\n"
01745             "       debug output, and more for surface node 1874\n"
01746             "\n"
01747             "    %s                                                \\\n"
01748             "       -spec         fred.spec                                \\\n"
01749             "       -surf_A       smoothwm                                 \\\n"
01750             "       -sv           fred_anat+orig                           \\\n"
01751             "       -grid_parent 'fred_epi+orig[0]'                        \\\n"
01752             "       -cmask       '-a fred_func+orig[2] -expr step(a-0.6)'  \\\n"
01753             "       -map_func     mask                                     \\\n"
01754             "       -debug        2                                        \\\n"
01755             "       -dnode        1874                                     \\\n"
01756             "       -out_niml     fred_epi_vals.niml\n"
01757             "\n"
01758             "    3. Given a pair of related surfaces, for each node pair,\n"
01759             "       break the connected line segment into 10 points, and\n"
01760             "       compute the average dataset value over those points.\n"
01761             "       Since the index is nodes, each of the 10 points will be\n"
01762             "       part of the average.  This could be changed so that only\n"
01763             "       values from distinct volume nodes are considered (by\n"
01764             "       changing the -f_index from nodes to voxels).  Restrict\n"
01765             "       input voxels to those implied by the -cmask option\n"
01766             "       Output is one average value per sub-brick (per surface\n"
01767             "       node).\n"
01768             "\n"
01769             "    %s                                                \\\n"
01770             "       -spec         fred.spec                                \\\n"
01771             "       -surf_A       smoothwm                                 \\\n"
01772             "       -surf_B       pial                                     \\\n"
01773             "       -sv           fred_anat+orig                           \\\n"
01774             "       -grid_parent  fred_func+orig                           \\\n"
01775             "       -cmask        '-a fred_func+orig[2] -expr step(a-0.6)' \\\n"
01776             "       -map_func     ave                                      \\\n"
01777             "       -f_steps      10                                       \\\n"
01778             "       -f_index      nodes                                    \\\n"
01779             "       -out_1D       fred_func_ave.1D\n"
01780             "\n"
01781             "    4. Similar to example 3, but restrict the output columns to\n"
01782             "       only node indices and values (i.e. skip 1dindex, i, j, k\n"
01783             "       and vals).\n"
01784             "\n"
01785             "    %s                                                \\\n"
01786             "       -spec         fred.spec                                \\\n"
01787             "       -surf_A       smoothwm                                 \\\n"
01788             "       -surf_B       pial                                     \\\n"
01789             "       -sv           fred_anat+orig                           \\\n"
01790             "       -grid_parent  fred_func+orig                           \\\n"
01791             "       -cmask        '-a fred_func+orig[2] -expr step(a-0.6)' \\\n"
01792             "       -map_func     ave                                      \\\n"
01793             "       -f_steps      10                                       \\\n"
01794             "       -f_index      nodes                                    \\\n"
01795             "       -skip_col_1dindex                                      \\\n"
01796             "       -skip_col_i                                            \\\n"
01797             "       -skip_col_j                                            \\\n"
01798             "       -skip_col_k                                            \\\n"
01799             "       -skip_col_vals                                         \\\n"
01800             "       -out_1D       fred_func_ave_short.1D\n"
01801             "\n"
01802             "    5. Similar to example 3, but each of the node pair segments\n"
01803             "       has grown by 10%% on the inside of the first surface,\n"
01804             "       and 20%% on the outside of the second.  This is a 30%%\n"
01805             "       increase in the length of each segment.  To shorten the\n"
01806             "       node pair segment, use a '+' sign for p1 and a '-' sign\n"
01807             "       for pn.\n"
01808             "       As an interesting side note, '-f_p1_fr 0.5 -f_pn_fr -0.5'\n"
01809             "       would give a zero length vector identical to that of the\n"
01810             "       'midpoint' filter.\n"
01811             "\n"
01812             "    %s                                                \\\n"
01813             "       -spec         fred.spec                                \\\n"
01814             "       -surf_A       smoothwm                                 \\\n"
01815             "       -surf_B       pial                                     \\\n"
01816             "       -sv           fred_anat+orig                           \\\n"
01817             "       -grid_parent  fred_func+orig                           \\\n"
01818             "       -cmask        '-a fred_func+orig[2] -expr step(a-0.6)' \\\n"
01819             "       -map_func     ave                                      \\\n"
01820             "       -f_steps      10                                       \\\n"
01821             "       -f_index      voxels                                   \\\n"
01822             "       -f_p1_fr      -0.1                                     \\\n"
01823             "       -f_pn_fr      0.2                                      \\\n"
01824             "       -out_1D       fred_func_ave2.1D\n"
01825             "\n"
01826             "    6. Similar to example 3, instead of computing the average\n"
01827             "       across each segment (one average per sub-brick), output\n"
01828             "       the volume value at _every_ point across the segment.\n"
01829             "       The output here would be 'f_steps' values per node pair,\n"
01830             "       though the output could again be restricted to unique\n"
01831             "       voxels along each segment with '-f_index voxels'.\n"
01832             "       Note that only sub-brick 0 will be considered here.\n"
01833             "\n"
01834             "    %s                                                \\\n"
01835             "       -spec         fred.spec                                \\\n"
01836             "       -surf_A       smoothwm                                 \\\n"
01837             "       -surf_B       pial                                     \\\n"
01838             "       -sv           fred_anat+orig                           \\\n"
01839             "       -grid_parent  fred_func+orig                           \\\n"
01840             "       -cmask        '-a fred_func+orig[2] -expr step(a-0.6)' \\\n"
01841             "       -map_func     seg_vals                                 \\\n"
01842             "       -f_steps      10                                       \\\n"
01843             "       -f_index      nodes                                    \\\n"
01844             "       -out_1D       fred_func_segvals_10.1D\n"
01845             "\n"
01846             "    7. Similar to example 6, but make sure there is output for\n"
01847             "       every node pair in the surfaces.  Since it is expected\n"
01848             "       that some nodes are out of bounds (meaning that they lie\n"
01849             "       outside the domain defined by the grid parent dataset),\n"
01850             "       the '-oob_value' option is added to include a default\n"
01851             "       value of 0.0 in such cases.  And since it is expected\n"
01852             "       that some node pairs are \"out of mask\" (meaning that\n"
01853             "       their resulting segment lies entirely outside the cmask),\n"
01854             "       the '-oom_value' was added to output the same default\n"
01855             "       value of 0.0.\n"
01856             "\n"
01857             "    %s                                                \\\n"
01858             "       -spec         fred.spec                                \\\n"
01859             "       -surf_A       smoothwm                                 \\\n"
01860             "       -surf_B       pial                                     \\\n"
01861             "       -sv           fred_anat+orig                           \\\n"
01862             "       -grid_parent  fred_func+orig                           \\\n"
01863             "       -cmask        '-a fred_func+orig[2] -expr step(a-0.6)' \\\n"
01864             "       -map_func     seg_vals                                 \\\n"
01865             "       -f_steps      10                                       \\\n"
01866             "       -f_index      nodes                                    \\\n"
01867             "       -oob_value    0.0                                      \\\n"
01868             "       -oom_value    0.0                                      \\\n"
01869             "       -out_1D       fred_func_segvals_10_all.1D\n"
01870             "\n"
01871             "    8. This is a basic example of calculating the average along\n"
01872             "       each segment, but where the segment is produced by only\n"
01873             "       one surface, along with its set of surface normals.  The\n"
01874             "       segments will be 2.5 mm in length.\n"
01875             "\n"
01876             "    %s                                                \\\n"
01877             "       -spec         fred.spec                                \\\n"
01878             "       -surf_A       smoothwm                                 \\\n"
01879             "       -sv           fred_anat+orig                           \\\n"
01880             "       -grid_parent  fred_anat+orig                           \\\n"
01881             "       -use_norms                                             \\\n"
01882             "       -norm_len     2.5                                      \\\n"
01883             "       -map_func     ave                                      \\\n"
01884             "       -f_steps      10                                       \\\n"
01885             "       -f_index      nodes                                    \\\n"
01886             "       -out_1D       fred_anat_norm_ave.2.5.1D\n"
01887             "\n"
01888             "    9. This is the same as example 8, but where the surface\n"
01889             "       nodes are restricted to the range 1000..1999 via the\n"
01890             "       options '-first_node' and '-last_node'.\n"
01891             "\n"
01892             "    %s                                                \\\n"
01893             "       -spec         fred.spec                                \\\n"
01894             "       -surf_A       smoothwm                                 \\\n"
01895             "       -sv           fred_anat+orig                           \\\n"
01896             "       -grid_parent  fred_anat+orig                           \\\n"
01897             "       -first_node   1000                                     \\\n"
01898             "       -last_node    1999                                     \\\n"
01899             "       -use_norms                                             \\\n"
01900             "       -norm_len     2.5                                      \\\n"
01901             "       -map_func     ave                                      \\\n"
01902             "       -f_steps      10                                       \\\n"
01903             "       -f_index      nodes                                    \\\n"
01904             "       -out_1D       fred_anat_norm_ave.2.5.1D\n"
01905             "\n"
01906             "  --------------------------------------------------\n",
01907             prog, prog, prog, prog, prog, prog, prog, prog, prog );
01908 
01909         printf(
01910             "\n"
01911             "  REQUIRED COMMAND ARGUMENTS:\n"
01912             "\n"
01913             "    -spec SPEC_FILE        : SUMA spec file\n"
01914             "\n"
01915             "        e.g. -spec fred.spec\n"
01916             "\n"
01917             "        The surface specification file contains the list of\n"
01918             "        mappable surfaces that are used.\n"
01919             "\n"
01920             "        See @SUMA_Make_Spec_FS and @SUMA_Make_Spec_SF.\n"
01921             "\n"
01922             "    -surf_A SURF_NAME      : name of surface A (from spec file)\n"
01923             "    -surf_B SURF_NAME      : name of surface B (from spec file)\n"
01924             "\n"
01925             "        e.g. -surf_A smoothwm\n"
01926             "        e.g. -surf_A lh.smoothwm\n"
01927             "        e.g. -surf_B lh.pial\n"
01928             "\n"
01929             "        This is used to specify which surface(s) will be used by\n"
01930             "        the program.  The '-surf_A' parameter is required, as it\n"
01931             "        specifies the first surface, whereas since '-surf_B' is\n"
01932             "        used to specify an optional second surface, it is not\n"
01933             "        required.\n"
01934             "\n"
01935             "        Note that any need for '-surf_B' may be fulfilled using\n"
01936             "        the '-use_norms' option.\n"
01937             "\n"
01938             "        Note that any name provided must be in the spec file,\n"
01939             "        uniquely matching the name of a surface node file (such\n"
01940             "        as lh.smoothwm.asc, for example).  Note that if both\n"
01941             "        hemispheres are represented in the spec file, then there\n"
01942             "        may be both lh.pial.asc and rh.pial.asc, for instance.\n"
01943             "        In such a case, 'pial' would not uniquely determine a\n"
01944             "        a surface, but the name 'lh.pial' would.\n"
01945             "\n"
01946             "    -sv SURFACE_VOLUME     : AFNI volume dataset\n"
01947             "\n"
01948             "        e.g. -sv fred_anat+orig\n"
01949             "\n"
01950             "        This is the AFNI dataset that the surface is mapped to.\n"
01951             "        This dataset is used for the initial surface node to xyz\n"
01952             "        coordinate mapping, in the Dicom orientation.\n"
01953             "\n"
01954             "    -grid_parent AFNI_DSET : AFNI volume dataset\n"
01955             "\n"
01956             "        e.g. -grid_parent fred_function+orig\n"
01957             "\n"
01958             "        This dataset is used as a grid and orientation master\n"
01959             "        for the output (i.e. it defines the volume domain).\n"
01960             "        It is also the source of the output data values.\n"
01961             "\n"
01962             "    -map_func MAP_FUNC     : filter for values along the segment\n"
01963             "\n"
01964             "        e.g. -map_func ave\n"
01965             "        e.g. -map_func ave -f_steps 10\n"
01966             "        e.g. -map_func ave -f_steps 10 -f_index nodes\n"
01967             "\n"
01968             "        The current mapping function for 1 surface is:\n"
01969             "\n"
01970             "          mask     : For each surface xyz location, output the\n"
01971             "                     dataset values of each sub-brick.\n"
01972             "\n"
01973             "        Most mapping functions are defined for 2 related input\n"
01974             "        surfaces (such as white/grey boundary and pial).  For\n"
01975             "        each node pair, the function will be performed on the\n"
01976             "        values from the 'grid parent dataset', and along the\n"
01977             "        segment connecting the nodes.\n"
01978             "\n"
01979             "          ave      : Output the average of the dataset values\n"
01980             "                     along the segment.\n"
01981             "\n"
01982             "          max      : Output the maximum dataset value along the\n"
01983             "                     connecting segment.\n"
01984             "\n"
01985             "          max_abs  : Output the dataset value with the maximum\n"
01986             "                     absolute value along the segment.\n"
01987             "\n"
01988             "          median   : Output the median of the dataset values\n"
01989             "                     along the connecting segment.\n"
01990             "\n"
01991             "          midpoint : Output the dataset value with xyz\n"
01992             "                     coordinates at the midpoint of the nodes.\n"
01993             "\n"
01994             "          min      : Output the minimum dataset value along the\n"
01995             "                     connecting segment.\n"
01996             "\n"
01997             "          mode     : Output the mode of the dataset values along\n"
01998             "                     the connecting segment.\n"
01999             "\n"
02000             "          seg_vals : Output all of the dataset values along the\n"
02001             "                     connecting segment.  Here, only sub-brick\n"
02002             "                     number 0 will be considered.\n"
02003             "\n"
02004             "  ------------------------------\n"
02005             "\n"
02006             "  options specific to functions on 2 surfaces:\n"
02007             "\n"
02008             "          -f_steps NUM_STEPS :\n"
02009             "\n"
02010             "                     Use this option to specify the number of\n"
02011             "                     evenly spaced points along each segment.\n"
02012             "                     The default is 2 (i.e. just use the two\n"
02013             "                     surface nodes as endpoints).\n"
02014             "\n"
02015             "                     e.g.     -f_steps 10\n"
02016             "                     default: -f_steps 2\n"
02017             "\n"
02018             "          -f_index TYPE :\n"
02019             "\n"
02020             "                     This option specifies whether to use all\n"
02021             "                     segment point values in the filter (using\n"
02022             "                     the 'nodes' TYPE), or to use only those\n"
02023             "                     corresponding to unique volume voxels (by\n"
02024             "                     using the 'voxel' TYPE).\n"
02025             "\n"
02026             "                     For instance, when taking the average along\n"
02027             "                     one node pair segment using 10 node steps,\n"
02028             "                     perhaps 3 of those nodes may occupy one\n"
02029             "                     particular voxel.  In this case, does the\n"
02030             "                     user want the voxel counted only once, or 3\n"            "                     times?  Each way makes sense.\n"
02031             "                     \n"
02032             "                     Note that this will only make sense when\n"
02033             "                     used along with the '-f_steps' option.\n"
02034             "                     \n"
02035             "                     Possible values are \"nodes\", \"voxels\".\n"
02036             "                     The default value is voxels.  So each voxel\n"
02037             "                     along a segment will be counted only once.\n"
02038             "                     \n"
02039             "                     e.g.  -f_index nodes\n"
02040             "                     e.g.  -f_index voxels\n"
02041             "                     default: -f_index voxels\n"
02042             "\n"
02043             "          -f_keep_surf_order :\n"
02044             "\n"
02045             "                     Depreciated.\n"
02046             "\n"
02047             "                     See required arguments -surf_A and -surf_B,\n"
02048             "                     above.\n"
02049             "\n"
02050             "          Note: The following -f_pX_XX options are used to alter\n"
02051             "                the lengths and locations of the computational\n"
02052             "                segments.  Recall that by default, segments are\n"
02053             "                defined using the node pair coordinates as\n"
02054             "                endpoints.  And the direction from p1 to pn is\n"
02055             "                from the inner surface to the outer surface.\n"
02056             "\n"
02057             "          -f_p1_mm DISTANCE :\n"
02058             "\n"
02059             "                     This option is used to specify a distance\n"
02060             "                     in millimeters to add to the first point of\n"
02061             "                     each line segment (in the direction of the\n"
02062             "                     second point).  DISTANCE can be negative\n"
02063             "                     (which would set p1 to be farther from pn\n"
02064             "                     than before).\n"
02065             "\n"
02066             "                     For example, if a computation is over the\n"
02067             "                     grey matter (from the white matter surface\n"
02068             "                     to the pial), and it is wished to increase\n"
02069             "                     the range by 1mm, set this DISTANCE to -1.0\n"
02070             "                     and the DISTANCE in -f_pn_mm to 1.0.\n"
02071             "\n"
02072             "                     e.g.  -f_p1_mm -1.0\n"
02073             "                     e.g.  -f_p1_mm -1.0 -f_pn_mm 1.0\n"
02074             "\n"
02075             "          -f_pn_mm DISTANCE :\n"
02076             "\n"
02077             "                     Similar to -f_p1_mm, this option is used\n"
02078             "                     to specify a distance in millimeters to add\n"
02079             "                     to the second point of each line segment.\n"
02080             "                     Note that this is in the same direction as\n"
02081             "                     above, from point p1 to point pn.\n"
02082             "                     \n"
02083             "                     So a positive DISTANCE, for this option,\n"
02084             "                     would set pn to be farther from p1 than\n"
02085             "                     before, and a negative DISTANCE would set\n"
02086             "                     it to be closer.\n"
02087             "\n"
02088             "                     e.g.  -f_pn_mm 1.0\n"
02089             "                     e.g.  -f_p1_mm -1.0 -f_pn_mm 1.0\n"
02090             "\n"
02091             "          -f_p1_fr FRACTION :\n"
02092             "\n"
02093             "                     Like the -f_pX_mm options above, this\n"
02094             "                     is used to specify a change to point p1, in\n"
02095             "                     the direction of point pn, but the change\n"
02096             "                     is a fraction of the original distance,\n"
02097             "                     not a pure change in millimeters.\n"
02098             "                     \n"
02099             "                     For example, suppose one wishes to do a\n"
02100             "                     computation based on the segments spanning\n"
02101             "                     the grey matter, but to add 20%% to either\n"
02102             "                     side.  Then use -0.2 and 0.2:\n"
02103             "\n"
02104             "                     e.g.  -f_p1_fr -0.2\n"
02105             "                     e.g.  -f_p1_fr -0.2 -f_pn_fr 0.2\n"
02106             "\n"
02107             "          -f_pn_fr FRACTION :\n"
02108             "\n"
02109             "                     See -f_p1_fr above.  Note again that the\n"
02110             "                     FRACTION is in the direction from p1 to pn.\n"
02111             "                     So to extend the segment past pn, this\n"
02112             "                     FRACTION will be positive (and to reduce\n"
02113             "                     the segment back toward p1, this -f_pn_fr\n"
02114             "                     FRACTION will be negative).\n"
02115             "\n"
02116             "                     e.g.  -f_pn_fr 0.2\n"
02117             "                     e.g.  -f_p1_fr -0.2 -f_pn_fr 0.2\n"
02118             "\n"
02119             "                     Just for entertainment, one could reverse\n"
02120             "                     the order that the segment points are\n"
02121             "                     considered by adjusting p1 to be pn, and\n"
02122             "                     pn to be p1.  This could be done by adding\n"
02123             "                     a fraction of 1.0 to p1 and by subtracting\n"
02124             "                     a fraction of 1.0 from pn.\n"
02125             "\n"
02126             "                     e.g.  -f_p1_fr 1.0 -f_pn_fr -1.0\n"
02127             "\n"
02128             "  ------------------------------\n"
02129         );
02130 
02131         printf(
02132             "\n"
02133             "  options specific to use of normals:\n"
02134             "\n"
02135             "    Notes:\n"
02136             "\n"
02137             "      o Using a single surface with its normals for segment\n"
02138             "        creation can be done in lieu of using two surfaces.\n"
02139             "\n"
02140             "      o Normals at surface nodes are defined by the average of\n"
02141             "        the normals of the triangles including the given node.\n"
02142             "\n"
02143             "      o The default normals have a consistent direction, but it\n"
02144             "        may be opposite of what is should be.  For this reason,\n"
02145             "        the direction is verified by default, and may be negated\n"
02146             "        internally.  See the '-keep_norm_dir' option for more\n"
02147             "        information.\n"
02148             "\n"
02149             "    -use_norms             : use normals for second surface\n"
02150             "\n"
02151             "        Segments are usually defined by connecting corresponding\n"
02152             "        node pairs from two surfaces.  With this options the\n"
02153             "        user can use one surface, along with its normals, to\n"
02154             "        define the segments.\n"
02155             "\n"
02156             "        By default, each segment will be 1.0 millimeter long, in\n"
02157             "        the direction of the normal.  The '-norm_len' option\n"
02158             "        can be used to alter this default action.\n"
02159             "\n"
02160             "    -keep_norm_dir         : keep the direction of the normals\n"
02161             "\n"
02162             "        Normal directions are verified by checking that the\n"
02163             "        normals of the outermost 6 points point away from the\n"
02164             "        center of mass.  If they point inward instead, then\n"
02165             "        they are negated.\n"
02166             "\n"
02167             "        This option will override the directional check, and\n"
02168             "        use the normals as they come.\n"
02169             "\n"
02170             "        See also -reverse_norm_dir, below.\n"
02171             "\n"
02172             "    -norm_len LENGTH       : use LENGTH for node normals\n"
02173             "\n"
02174             "        e.g.     -norm_len  3.0\n"
02175             "        e.g.     -norm_len -3.0\n"
02176             "        default: -norm_len  1.0\n"
02177             "\n"
02178             "        For use with the '-use_norms' option, this allows the\n"
02179             "        user to specify a directed distance to use for segments\n"
02180             "        based on the normals.  So for each node on a surface,\n"
02181             "        the computation segment will be from the node, in the\n"
02182             "        direction of the normal, a signed distance of LENGTH.\n"
02183             "\n"
02184             "        A negative LENGTH means to use the opposite direction\n"
02185             "        from the normal.\n"
02186             "\n"
02187             "        The '-surf_B' option is not allowed with the use of\n"
02188             "        normals.\n"
02189             "\n"
02190             "    -reverse_norm_dir      : reverse the normal directions\n"
02191             "\n"
02192             "        Normal directions are verified by checking that the\n"
02193             "        normals of the outermost 6 points point away from the\n"
02194             "        center of mass.  If they point inward instead, then\n"
02195             "        they are negated.\n"
02196             "\n"
02197             "        This option will override the directional check, and\n"
02198             "        reverse the direction of the normals as they come.\n"
02199             "\n"
02200             "        See also -keep_norm_dir, above.\n"
02201             "\n"
02202             "  ------------------------------\n"
02203             "\n"
02204             "  general options:\n"
02205             "\n"
02206             "    -cmask MASK_COMMAND    : (optional) command for dataset mask\n"
02207             "\n"
02208             "        e.g. -cmask '-a fred_func+orig[2] -expr step(a-0.8)'\n"
02209             "\n"
02210             "        This option will produce a mask to be applied to the\n"
02211             "        input AFNI dataset.  Note that this mask should form a\n"
02212             "        single sub-brick.\n"
02213             "\n"
02214             "        This option follows the style of 3dmaskdump (since the\n"
02215             "        code for it was, uh, borrowed from there (thanks Bob!)).\n"
02216             "\n"
02217             "        See '3dmaskdump -help' for more information.\n"
02218             "\n"
02219             "    -debug LEVEL           :  (optional) verbose output\n"
02220             "\n"
02221             "        e.g. -debug 2\n"
02222             "\n"
02223             "        This option is used to print out status information \n"
02224             "        during the execution of the program.  Current levels are\n"
02225             "        from 0 to 5.\n"
02226             "\n"
02227             "    -first_node NODE_NUM   : skip all previous nodes\n"
02228             "\n"
02229             "        e.g. -first_node 1000\n"
02230             "        e.g. -first_node 1000 -last_node 1999\n"
02231             "\n"
02232             "        Restrict surface node output to those with indices as\n"
02233             "        large as NODE_NUM.  In the first example, the first 1000\n"
02234             "        nodes are ignored (those with indices from 0 through\n"
02235             "        999).\n"
02236             "\n"
02237             "        See also, '-last_node'.\n"
02238             "\n"
02239             "    -dnode NODE_NUM        :  (optional) node for debug\n"
02240             "\n"
02241             "        e.g. -dnode 1874\n"
02242             "\n"
02243             "        This option is used to print out status information \n"
02244             "        for node NODE_NUM.\n"
02245             "\n"
02246             "    -gp_index SUB_BRICK    : choose grid_parent sub-brick\n"
02247             "\n"
02248             "        e.g. -gp_index 3\n"
02249             "\n"
02250             "        This option allows the user to choose only a single\n"
02251             "        sub-brick from the grid_parent dataset for computation.\n"
02252             "        Note that this option is virtually useless when using\n"
02253             "        the command-line, as the user can more directly do this\n"
02254             "        via brick selectors, e.g. func+orig'[3]'.\n"
02255             "        \n"
02256             "        This option was written for the afni interface.\n"
02257             "\n"
02258             "    -help                  : show this help\n"
02259             "\n"
02260             "        If you can't get help here, please get help somewhere.\n"
02261             "\n"
02262             "    -hist                  : show revision history\n"
02263             "\n"
02264             "        Display module history over time.\n"
02265             "\n"
02266             "        See also, -v2s_hist\n"
02267             "\n"
02268             "    -last_node NODE_NUM    : skip all following nodes\n"
02269             "\n"
02270             "        e.g. -last_node 1999\n"
02271             "        e.g. -first_node 1000 -last_node 1999\n"
02272             "\n"
02273             "        Restrict surface node output to those with indices no\n"
02274             "        larger than NODE_NUM.  In the first example, nodes above\n"
02275             "        1999 are ignored (those with indices from 2000 on up).\n"
02276             "\n"
02277             "        See also, '-first_node'.\n"
02278             "\n"
02279             "    -no_headers            : do not output column headers\n"
02280             "\n"
02281             "        Column header lines all begin with the '#' character.\n"
02282             "        With the '-no_headers' option, these lines will not be\n"
02283             "        output.\n"
02284             "\n"
02285             "    -oob_index INDEX_NUM   : specify default index for oob nodes\n"
02286             "\n"
02287             "        e.g.     -oob_index -1\n"
02288             "        default: -oob_index  0\n"
02289             "\n"
02290             "        By default, nodes which lie outside the box defined by\n"
02291             "        the -grid_parent dataset are considered out of bounds,\n"
02292             "        and are skipped.  If an out of bounds index is provided,\n"
02293             "        or an out of bounds value is provided, such nodes will\n"
02294             "        not be skipped, and will have indices and values output,\n"
02295             "        according to the -oob_index and -oob_value options.\n"
02296             "        \n"
02297             "        This INDEX_NUM will be used for the 1dindex field, along\n"
02298             "        with the i, j and k indices.\n"
02299             "        \n"
02300             "\n"
02301             "    -oob_value VALUE       : specify default value for oob nodes\n"
02302             "\n"
02303             "        e.g.     -oob_value -999.0\n"
02304             "        default: -oob_value    0.0\n"
02305             "\n"
02306             "        See -oob_index, above.\n"
02307             "        \n"
02308             "        VALUE will be output for nodes which are out of bounds.\n"
02309             "\n"
02310             "    -oom_value VALUE       : specify default value for oom nodes\n"
02311             "\n"
02312             "        e.g. -oom_value -999.0\n"
02313             "        e.g. -oom_value    0.0\n"
02314             "\n"
02315             "        By default, node pairs defining a segment which gets\n"
02316             "        completely obscured by a command-line mask (see -cmask)\n"
02317             "        are considered \"out of mask\", and are skipped.\n"
02318             "\n"
02319             "        If an out of mask value is provided, such nodes will not\n"
02320             "        be skipped.  The output indices will come from the first\n"
02321             "        segment point, mapped to the AFNI volume.  All output vN\n"
02322             "        values will be the VALUE provided with this option.\n"
02323             "\n"
02324             "        This option is meaningless without a '-cmask' option.\n"
02325             "\n"
02326             "    -out_1D OUTPUT_FILE    : specify a 1D file for the output\n"
02327             "\n"
02328             "        e.g. -out_1D mask_values_over_dataset.1D\n"
02329             "\n"
02330             "        This is where the user will specify which file they want\n"
02331             "        the output to be written to.  In this case, the output\n"
02332             "        will be in readable, column-formatted ASCII text.\n"
02333             "\n"
02334             "        Note : the output file should not yet exist.\n"
02335             "             : -out_1D or -out_niml must be used\n"
02336             "\n"
02337             "    -out_niml OUTPUT_FILE  : specify a niml file for the output\n"
02338             "\n"
02339             "        e.g. -out_niml mask_values_over_dataset.niml\n"
02340             "\n"
02341             "        The user may use this option to get output in the form\n"
02342             "        of a niml element, with binary data.  The output will\n"
02343             "        contain (binary) columns of the form:\n"
02344             "\n"
02345             "            node_index  value_0  value_1  value_2  ...\n"
02346             "\n"
02347             "        A major difference between 1D output and niml output is\n"
02348             "        that the value_0 column number will be 6 in the 1D case,\n"
02349             "        but will be 2 in the niml case.  The index columns will\n"
02350             "        not be used for niml output.\n"
02351             "\n"
02352             "        Note : the output file should not yet exist.\n"
02353             "             : -out_1D or -out_niml must be used\n"
02354             "\n"
02355             "    -skip_col_nodes        : do not output node column\n"
02356             "    -skip_col_1dindex      : do not output 1dindex column\n"
02357             "    -skip_col_i            : do not output i column\n"
02358             "    -skip_col_j            : do not output j column\n"
02359             "    -skip_col_k            : do not output k column\n"
02360             "    -skip_col_vals         : do not output vals column\n"
02361             "    -skip_col_results      : only output ONE result column\n"
02362             "                             (seems to make the most sense)\n"
02363             "    -skip_col_non_results  : skip everything but the results\n"
02364             "                             (i.e. only output result columns)\n"
02365             "\n"
02366             "        These options are used to restrict output.  Each option\n"
02367             "        will prevent the program from writing that column of\n"
02368             "        output to the 1D file.\n"
02369             "\n"
02370             "        For now, the only effect that these options can have on\n"
02371             "        the niml output is by skipping nodes or results (all\n"
02372             "        other columns are skipped by default).\n"
02373             "\n"
02374             "    -v2s_hist              : show revision history for library\n"
02375             "\n"
02376             "        Display vol2surf library history over time.\n"
02377             "\n"
02378             "        See also, -hist\n"
02379             "\n"
02380             "    -version               : show version information\n"
02381             "\n"
02382             "        Show version and compile date.\n"
02383             "\n"
02384             "  --------------------------------------------------\n"
02385             "\n"
02386             "Output from the program defaults to 1D format, in ascii text.\n"
02387             "For each node (pair) that results in output, there will be one\n"
02388             "line, consisting of:\n"
02389             "\n"
02390             "    node    : the index of the current node (or node pair)\n"
02391             "\n"
02392             "    1dindex : the global index of the AFNI voxel used for output\n"
02393             "\n"
02394             "              Note that for some filters (min, max, midpoint,\n"
02395             "              median and mode) there is a specific location (and\n"
02396             "              therefore voxel) that the result comes from.  It\n"
02397             "              will be accurate (though median may come from one\n"
02398             "              of two voxels that are averaged).\n"
02399             "\n"
02400             "              For filters without a well-defined source (such as\n"
02401             "              average or seg_vals), the 1dindex will come from\n"
02402             "              the first point on the corresponding segment.\n"
02403             "\n"
02404             "              Note: this will _not_ be output in the niml case.\n"
02405             "\n"
02406             "    i j k   : the i j k indices matching 1dindex\n"
02407             "\n"
02408             "              These indices are based on the orientation of the\n"
02409             "              grid parent dataset.\n"
02410             "\n"
02411             "              Note: these will _not_ be output in the niml case.\n"
02412             "\n"
02413             "    vals    : the number of segment values applied to the filter\n"
02414             "\n"
02415             "              Note that when -f_index is 'nodes', this will\n"
02416             "              always be the same as -f_steps, except when using\n"
02417             "              the -cmask option.  In that case, along a single \n"
02418             "              segment, some points may be in the mask, and some\n"
02419             "              may not.\n"
02420             "\n"
02421             "              When -f_index is 'voxels' and -f_steps is used,\n"
02422             "              vals will often be much smaller than -f_steps.\n"
02423             "              This is because many segment points may in a\n"
02424             "              single voxel.\n"
02425             "\n"
02426             "              Note: this will _not_ be output in the niml case.\n"
02427             "\n"
02428             "    v0, ... : the requested output values\n"
02429             "\n"
02430             "              These are the filtered values, usually one per\n"
02431             "              AFNI sub-brick.  For example, if the -map_func\n"
02432             "              is 'ave', then there will be one segment-based\n"
02433             "              average output per sub-brick of the grid parent.\n"
02434             "\n"
02435             "              In the case of the 'seg_vals' filter, however,\n"
02436             "              there will be one output value per segment point\n"
02437             "              (possibly further restricted to voxels).  Since\n"
02438             "              output is not designed for a matrix of values,\n"
02439             "              'seg_vals' is restricted to a single sub-brick.\n"
02440             "\n"
02441             "\n"
02442             "  Author: R. Reynolds  - %s\n"
02443             "\n"
02444             "                (many thanks to Z. Saad and R.W. Cox)\n"
02445             "\n",
02446             VERSION );
02447     }
02448     else if ( level == V2S_USE_HIST )
02449         fputs(g_history, stdout);
02450     else if ( level == V2S_USE_LIB_HIST )
02451         fputs(gv2s_history, stdout);
02452     else if ( level == V2S_USE_VERSION )
02453         fprintf(stderr,"%s : %s, compile date: %s\n", prog, VERSION, __DATE__);
02454     else 
02455         fprintf( stderr, "usage called with illegal level <%d>\n", level );
02456 
02457     RETURN(-1);
02458 }

int validate_datasets opts_t   opts,
param_t   p
 

Definition at line 2269 of file SUMA_3dSurf2Vol.c.

References param_t::ccount, param_t::cmask, opts_t::cmask_cmd, opts_t::debug, DSET_BRICK_TYPE, DSET_NVALS, DSET_NVOX, EDT_calcmask(), ENTRY, param_t::f3mm_max, param_t::f3mm_min, free, param_t::gpar, opts_t::gpar_file, ISVALID_DSET, malloc, param_t::ncmask, param_t::nvox, opts_t::oset_file, p, RETURN, set_3dmm_bounds(), THD_countmask(), THD_filename_ok(), and THD_open_dataset().

02270 {
02271 ENTRY("validate_datasets");
02272 
02273     p->gpar = THD_open_dataset( opts->gpar_file );
02274 
02275     if ( !ISVALID_DSET(p->gpar) )
02276     {
02277         if ( opts->gpar_file == NULL )
02278             fprintf( stderr, "** error: missing '-grid_parent DSET' option\n" );
02279         else
02280             fprintf( stderr, "** error: invalid input dataset '%s'\n",
02281                      opts->gpar_file);
02282         RETURN(-1);
02283     }
02284     else if ( DSET_BRICK_TYPE(p->gpar, 0) == MRI_complex )
02285     {
02286         fprintf(stderr,
02287                 "** failure: cannot deal with complex-valued dataset, '%s'\n",
02288                 opts->gpar_file);
02289         RETURN(-1);
02290     }
02291 
02292     p->nvox = DSET_NVOX( p->gpar );
02293     set_3dmm_bounds( p->gpar, &p->f3mm_min, &p->f3mm_max );
02294 
02295     if ( ! THD_filename_ok( opts->oset_file ) )
02296     {
02297         fprintf( stderr, "** illegal output prefix: '%s'\n",
02298                  opts->oset_file ? opts->oset_file : "<none>" );
02299         RETURN(-1);
02300     }
02301 
02302     /* -------------------------------------------------------------------- */
02303     /* check for cmask - casually stolen from 3dmaskdump.c (thanks, Bob! :) */
02304 
02305     if ( opts->cmask_cmd != NULL )
02306     {
02307         int    clen = strlen( opts->cmask_cmd );
02308         char * cmd;
02309 
02310         /* save original cmask command, as EDT_calcmask() is destructive */
02311         cmd = (char *)malloc((clen + 1) * sizeof(char));
02312         strcpy( cmd, opts->cmask_cmd );
02313 
02314         p->cmask = EDT_calcmask( cmd, &p->ncmask );
02315 
02316         free( cmd );                       /* free EDT_calcmask() string */
02317 
02318         if ( p->cmask == NULL )
02319         {
02320             fprintf( stderr, "** failure: cannot compute mask from option:\n"
02321                      "   -cmask '%s'\n", opts->cmask_cmd );
02322             RETURN(-1);
02323         }
02324         if ( p->ncmask != p->nvox )
02325         {
02326             fprintf( stderr, "** error: input and cmask datasets do not have "
02327                      "the same dimensions\n" );
02328             RETURN(-1);
02329         }
02330         if ( ( p->ccount = THD_countmask( p->ncmask, p->cmask ) ) <= 0 )
02331         {
02332             fprintf( stderr, "** Warning!  No voxels in computed cmask!\n" );
02333             /* return -1;   continue, and let the user deal with it...  */
02334         }
02335     }
02336 
02337     if ( opts->debug > 0 )
02338     {
02339         fprintf( stderr, "++ input dset has nvox = %d, nvals = %d",
02340                  p->nvox, DSET_NVALS(p->gpar) );
02341         if ( p->cmask == NULL )
02342             fputc( '\n', stderr );
02343         else
02344             fprintf( stderr, " (%d voxels in mask)\n", p->ccount );
02345     }
02346 
02347     RETURN(0);
02348 }

int validate_options opts_t   opts,
param_t   p
 

Definition at line 1507 of file SUMA_SurfMeasures.c.

01508 {
01509     int errs = 0;
01510 
01511 ENTRY("validate_options");    
01512 
01513     if ( !opts || !p )
01514     {
01515         fprintf(stderr,"** vo: bad params (%p,%p)\n", opts, p);
01516         RETURN(-1);
01517     }
01518 
01519     if ( opts->F.nused <= 0 )
01520     {
01521         fprintf(stderr,"** must specify at least one '-func' option\n");
01522         errs++;
01523     }
01524 
01525     if ( ! opts->spec_file )
01526     {
01527         fprintf(stderr,"** missing argument: -spec\n");
01528         errs++;
01529     }
01530 
01531     if ( ! opts->surf_names[0] )
01532     {
01533         fprintf(stderr,"** missing argument -surf_A\n");
01534         errs++;
01535     }
01536 
01537     /* we don't necessarily need an sv_file ... do not check */
01538 
01539     /* verify output file, and open for writing */
01540     if ( ! opts->out_1D_file )
01541     {
01542         fprintf(stderr,"** missing argument: -out_1D\n");
01543         errs++;
01544     }
01545     else if ( THD_is_file(opts->out_1D_file) )
01546     {
01547         fprintf(stderr,"** output file already exists: %s\n",opts->out_1D_file);
01548         errs++;
01549     }
01550 
01551     if ( errs > 0 )
01552         RETURN(-1);
01553 
01554     if ( opts->debug > 1 )
01555     {
01556         disp_opts_t( "-- opts okay: ", opts );
01557         disp_func_t( "-- opts okay: ", &opts->F );
01558     }
01559 
01560 
01561     /* options look good, now fill the param_t struct */
01562     memset(p, 0, sizeof(param_t));      /* clear params    */
01563 
01564     p->S.slist    = NULL;                       /* to be safe...   */
01565     p->S.narea[0] = NULL;
01566     p->S.narea[1] = NULL;
01567     p->S.nvol     = NULL;
01568     p->S.fvol     = NULL;
01569 
01570     p->F          = &opts->F;                   /* point to struct */
01571 
01572     if ( (p->outfp = fopen(opts->out_1D_file, "w")) == NULL )
01573     {
01574         fprintf(stderr,"** cannot open output file '%s'\n",opts->out_1D_file);
01575         RETURN(-1);
01576     }
01577 
01578     /* init before filling */
01579     p->nodes  = NULL;
01580     p->nnodes = 0;
01581     p->cmask  = NULL;
01582     p->ncmask = 0;
01583 
01584     if ( opts->nodes_1D_file )
01585     {
01586         if ( read_nodes_file(opts, p) != 0 )
01587             RETURN(-1);
01588     }
01589 
01590     if ( opts->cmask_cmd )
01591     {
01592         if ( get_cmask(opts, p) != 0 )
01593             RETURN(-1);
01594     }
01595 
01596     RETURN(0);
01597 }

int validate_surface opts_t   opts,
param_t   p
 

Definition at line 2205 of file SUMA_3dSurf2Vol.c.

References ENTRY, p, RETURN, opts_t::sdata_file_1D, opts_t::sdata_file_niml, opts_t::snames, opts_t::spec_file, opts_t::surf_xyz_1D_file, and opts_t::sv_file.

02206 {
02207     int errs = 0;
02208 
02209 ENTRY("validate_surface");
02210 
02211     if ( ! opts->surf_xyz_1D_file )  /* then check the surface input */
02212     {
02213         if ( opts->spec_file == NULL )
02214         {
02215             fprintf( stderr, "** missing '-spec_file SPEC_FILE' option\n" );
02216             errs++;
02217         }
02218 
02219         if ( opts->sv_file == NULL )
02220         {
02221             fprintf( stderr, "** missing '-sv SURF_VOL' option\n" );
02222             errs++;
02223         }
02224 
02225         if ( opts->snames[0] == NULL )
02226         {
02227             fprintf( stderr, "** missing '-surf_A SURF_NAME' option\n" );
02228             errs++;
02229         }
02230     }
02231     else if ( opts->spec_file != NULL )
02232     {
02233         fprintf(stderr,
02234                 "** cannot use both spec and xyz surface files, %s and %s\n",
02235                 opts->spec_file, opts->surf_xyz_1D_file);
02236         errs++;
02237     }
02238 
02239     if ( opts->sdata_file_1D && opts->sdata_file_niml )
02240     {
02241         fprintf(stderr,"** cannot use both NIML and 1D surface files\n");
02242         errs++;
02243     }
02244 
02245     /* rcr - hopefully this will disappear someday */
02246     if ( opts->sdata_file_niml )
02247     {
02248         fprintf(stderr,"** sorry, the niml feature is coming soon...\n");
02249         errs++;
02250     }
02251 
02252     if ( errs > 0 )
02253         RETURN(-1);
02254 
02255     RETURN(0);
02256 }

int verify_node_list node_list_t   N
 

Definition at line 1488 of file SUMA_3dSurf2Vol.c.

References node_list_t::depth, disp_node_list_t(), ENTRY, node_list_t::fdata, free, node_list_t::ilen, node_list_t::ilist, malloc, node_list_t::nnodes, node_list_t::nodes, and RETURN.

Referenced by fill_node_list().

01489 {
01490     int icount, errs = 0;
01491 
01492 ENTRY("verify_node_list");
01493 
01494     if ( !N )
01495     {
01496         fprintf(stderr, "** vnl - no node list\n" );
01497         RETURN(-1);
01498     }
01499 
01500     if ( !N->nodes || !N->ilist )
01501     {
01502         fprintf(stderr,"** missing nodes or ilist\n" );
01503         errs++;
01504     }
01505 
01506     if ( N->depth < 1 || N->nnodes < 1 || N->ilen < 1 )
01507     {
01508         fprintf(stderr,"** invalid depth, nnodes or ilen" );
01509         errs++;
01510     }
01511 
01512     if ( errs )
01513     {
01514         disp_node_list_t("** invalid data : ", N );
01515         RETURN(-errs);
01516     }
01517 
01518     /* now check that the indices are within nnodes range */
01519     for ( icount = 0; icount < N->ilen; icount++ )
01520         if ( N->ilist[icount] < 0 || N->ilist[icount] >= N->nnodes )
01521         {
01522             fprintf(stderr,"** surf data index number %d is out of range:\n"
01523                            "   index = %d, range is [%d,%d]\n",
01524                            icount, N->ilist[icount], 0, N->nnodes-1);
01525             RETURN(-10);
01526         }
01527 
01528     /* node_list is okay, so make space for the actual data */
01529     if ( (N->fdata = (float *)malloc(N->ilen*sizeof(float))) == NULL )
01530     {
01531         fprintf(stderr,"** vnl: failed to allocate %d floats\n",N->ilen);
01532         free(N->ilist);
01533         RETURN(-20);
01534     }
01535 
01536     RETURN(0);
01537 }

int verify_parser_expr opts_t   opts,
param_t   p
 

Definition at line 1435 of file SUMA_3dSurf2Vol.c.

References opts_t::data_expr, opts_t::debug, ENTRY, parser_t::has_sym, parser_t::max_sym, MRI_IMAGE::nx, p, param_t::parser, parser_t::pcode, RETURN, and param_t::sdata_im.

Referenced by read_surf_files().

01436 {
01437     int max_used;
01438 
01439 ENTRY("verify_parser_expr");
01440 
01441     if ( !opts || !p )
01442     {
01443         fprintf(stderr,"** vpe: invalid params (%p,%p)\n", opts, p);
01444         RETURN(-1);
01445     }
01446 
01447     /* if no parser code, there is nothing to do */
01448     if ( ! p->parser.pcode )
01449         RETURN(0);
01450 
01451     for ( max_used = 25; max_used >= 0; max_used-- )
01452         if ( p->parser.has_sym[max_used] )
01453             break;
01454     max_used++;         /* this is the number of surface values needed */
01455     p->parser.max_sym = max_used;
01456 
01457     /* if the expression is not constant, we need some data */
01458     if ( max_used > 0 )
01459     {
01460         if ( !p->sdata_im )
01461         {
01462             fprintf(stderr, "** parser expression requires surface data\n"
01463                             "   (see '-sdata_1D')\n");
01464             RETURN(-1);
01465         }
01466         else if ( max_used > p->sdata_im->nx - 1 )
01467         {
01468             fprintf(stderr,
01469                     "** error: not enough surface values for expression\n"
01470                     "          svals = %d, exp_vals = %d, expr = '%s'\n",
01471                     p->sdata_im->nx - 1, max_used, opts->data_expr);
01472             RETURN(-1);
01473         }
01474     }
01475 
01476     if ( opts->debug > 1 )
01477         fprintf(stderr,"-- surf_vals = %d, expr_vals = %d\n",
01478                 p->sdata_im ? (p->sdata_im->nx - 1) : 0, max_used);
01479 
01480     RETURN(0);
01481 }

int write_output s2v_opts_t   sopt,
opts_t   opts,
param_t   p,
node_list_t   N,
int    argc,
char *    argv[]
 

Definition at line 200 of file SUMA_3dSurf2Vol.c.

References ADN_none, ADN_prefix, argc, DSET_delete, DSET_HEADNAME, DSET_write, EDIT_dset_items(), ENTRY, param_t::gpar, param_t::oset, opts_t::oset_file, p, RETURN, s2v_nodes2volume(), THD_is_file(), tross_Copy_History(), and tross_Make_History().

00202 {
00203 ENTRY("write_output");
00204 
00205     if ( sopt == NULL || opts == NULL || p == NULL || N == NULL )
00206     {
00207         fprintf( stderr, "** s2v_wo - bad params (%p,%p,%p,%p)\n",
00208                  sopt, opts, p, N );
00209         RETURN(-1);
00210     }
00211 
00212     p->oset = s2v_nodes2volume( N, p, sopt );
00213 
00214     if ( p->oset == NULL )
00215         RETURN(-1);
00216 
00217     EDIT_dset_items( p->oset, ADN_prefix, opts->oset_file, ADN_none );
00218 
00219     if ( THD_is_file(DSET_HEADNAME(p->oset)) )
00220     {
00221         fprintf( stderr, "** cannot overwrite existing dataset '%s'\n",
00222                  DSET_HEADNAME(p->oset) );
00223         DSET_delete( p->oset );
00224         RETURN(-1);
00225     }
00226 
00227     tross_Copy_History( p->gpar, p->oset );
00228     tross_Make_History( PROG_NAME, argc, argv, p->oset );
00229 
00230     if ( DSET_write( p->oset ) != True )
00231     {
00232         fprintf( stderr, "** failed to write dataset '%s', exiting...\n",
00233                  opts->oset_file );
00234         RETURN(-1);
00235     }
00236 
00237     RETURN(0);
00238 }
 

Powered by Plone

This site conforms to the following standards: