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_3dSurfMask.c File Reference

#include "SUMA_suma.h"

Go to the source code of this file.


Functions

void usage_3dSurfMask (SUMA_GENERIC_ARGV_PARSE *ps)
SUMA_GENERIC_PROG_OPTIONS_STRUCTSUMA_3dSurfMask_ParseInput (char *argv[], int argc, SUMA_GENERIC_ARGV_PARSE *ps)
int main (int argc, char *argv[])

Variables

SUMA_SurfaceViewerSUMAg_cSV = NULL
SUMA_SurfaceViewerSUMAg_SVv = NULL
int SUMAg_N_SVv = 0
SUMA_DOSUMAg_DOv = NULL
int SUMAg_N_DOv = 0
SUMA_CommonFieldsSUMAg_CF = NULL

Function Documentation

int main int    argc,
char *    argv[]
 

\** File : SUMA.c

Author:
: Ziad Saad Date : Thu Dec 27 16:21:01 EST 2001
Purpose :

Input paramters :

Parameters:
param  Usage : SUMA ( )
Returns :
Returns:
Support :
See also:
OpenGL prog. Guide 3rd edition , varray.c from book's sample code
Side effects :

Definition at line 138 of file SUMA_3dSurfMask.c.

References argc, SUMA_FORM_AFNI_DSET_STRUCT::datum, SUMA_GENERIC_PROG_OPTIONS_STRUCT::debug, DSET_delete, DSET_write, SUMA_FileName::FileName, SUMA_FORM_AFNI_DSET_STRUCT::full_list, i, SUMA_GENERIC_ARGV_PARSE::i_N_surfnames, LocalHead, SUMA_FORM_AFNI_DSET_STRUCT::master, SUMA_FORM_AFNI_DSET_STRUCT::mset, SUMA_VOLPAR::nx, SUMA_VOLPAR::ny, SUMA_VOLPAR::nz, SUMA_GENERIC_PROG_OPTIONS_STRUCT::obj_type, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_grid_exists, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_grid_prefix, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_grid_view, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_vol_exists, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_vol_prefix, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_vol_view, SUMA_FileName::Path, SUMA_FORM_AFNI_DSET_STRUCT::prefix, SUMA_FORM_AFNI_DSET_STRUCT::prefix_path, SUMA_GENERIC_ARGV_PARSE::s_N_surfnames, SUMA_3dSurfMask_ParseInput(), SUMA_AfniExistsView(), SUMA_AfniPrefix(), SUMA_AfniView(), SUMA_Alloc_DisplayObject_Struct(), SUMA_append_string(), SUMA_Boolean, SUMA_copy_string(), SUMA_error_message(), SUMA_FindVoxelsInSurface(), SUMA_FormAfnidset(), SUMA_free, SUMA_Free_CommonFields(), SUMA_Free_FormAfniDset_Opt(), SUMA_Free_Generic_Prog_Options_Struct(), SUMA_Free_Surface_Object(), SUMA_Free_VolPar(), SUMA_FreeGenericArgParse(), SUMA_IO_args_2_spec(), SUMA_Load_Spec_Surf(), SUMA_mainENTRY, SUMA_malloc, SUMA_MAX_DISPLAYABLE_OBJECTS, SUMA_New_FormAfniDset_Opt(), SUMA_Parse_IO_Args(), SUMA_S_Err, SUMA_SL_Crit, SUMA_SL_Err, SUMA_STANDALONE_INIT, SUMA_StripPath(), SUMA_VolPar_Attr(), SUMA_GENERIC_ARGV_PARSE::sv, SUMA_GENERIC_ARGV_PARSE::t_N_surfnames, tross_Make_History(), usage_3dSurfMask(), and SUMA_SurfaceObject::VolPar.

00139 {/* Main */    
00140    static char FuncName[]={"3dSurfMask"}; 
00141    SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt;  
00142    SUMA_GENERIC_ARGV_PARSE *ps=NULL;
00143    SUMA_SurfSpecFile *Spec = NULL;
00144    int N_Spec=0;
00145    short *isin = NULL;
00146    int N_in = 0, i;
00147    SUMA_FORM_AFNI_DSET_STRUCT *OptDs = NULL;
00148    SUMA_SurfaceObject *SO = NULL;
00149    SUMA_VOLPAR *vp = NULL;
00150    THD_3dim_dataset *dset = NULL;
00151    char *vpname=NULL;
00152    SUMA_Boolean LocalHead = NOPE;
00153 
00154         SUMA_mainENTRY;
00155    SUMA_STANDALONE_INIT;
00156 
00157    /* Allocate space for DO structure */
00158         SUMAg_DOv = SUMA_Alloc_DisplayObject_Struct (SUMA_MAX_DISPLAYABLE_OBJECTS);
00159    ps = SUMA_Parse_IO_Args(argc, argv, "-i;-t;-spec;-sv;");
00160    
00161    if (argc < 2) {
00162       usage_3dSurfMask(ps);
00163       exit (1);
00164    }
00165    
00166    Opt = SUMA_3dSurfMask_ParseInput (argv, argc, ps);
00167 
00168    if (Opt->debug > 2) LocalHead = YUP;
00169    
00170    /* check on inputs */
00171    if (ps->s_N_surfnames + ps->i_N_surfnames + ps->t_N_surfnames != 1) {
00172       SUMA_S_Err("Multiple surface specifications used. Only one surface allowed.");
00173       exit(1);
00174    }
00175 
00176    Spec = SUMA_IO_args_2_spec(ps, &N_Spec);
00177    if (N_Spec != 1) {
00178       SUMA_S_Err("Multiple spec at input.");
00179       exit(1);
00180    }
00181 
00182    SO = SUMA_Load_Spec_Surf(Spec, 0, ps->sv[0], 0);
00183    if (!SO) {
00184          fprintf (SUMA_STDERR,"Error %s:\n"
00185                               "Failed to find surface\n"
00186                               "in spec file. \n",
00187                               FuncName );
00188          exit(1);
00189       
00190    }   
00191    
00192    if (Opt->out_grid_prefix) {
00193       vpname = SUMA_append_string(Opt->out_grid_prefix, Opt->out_grid_view);
00194       vp = SUMA_VolPar_Attr(vpname);
00195    } else { 
00196       vp = SO->VolPar;
00197       if (!vp) {
00198          fprintf (SUMA_STDERR,"Error %s:\n"
00199                                  "Need a grid parent.\n",
00200                                  FuncName );
00201             exit(1);
00202       }
00203       vpname = SUMA_copy_string(ps->sv[0]);
00204       if (!SUMA_AfniView(ps->sv[0], Opt->out_grid_view)) {
00205          fprintf (SUMA_STDERR,"Error %s:\n"
00206                                  "Failed to get view!!!\n",
00207                                  FuncName );
00208             exit(1);
00209          
00210       }
00211    }
00212    if (LocalHead) {
00213       fprintf(SUMA_STDERR,"%s: Using %s for grid\n", FuncName, vpname);
00214    }
00215    /* some checks ...*/
00216    if (!Opt->out_vol_prefix) { 
00217       Opt->out_vol_prefix = SUMA_AfniPrefix("3dSurfMask", NULL, NULL, &(Opt->out_vol_exists)); 
00218       sprintf(Opt->out_vol_view, Opt->out_grid_view); 
00219    }
00220    
00221    if (SUMA_AfniExistsView(Opt->out_vol_exists, Opt->out_vol_view)) {
00222       fprintf(SUMA_STDERR, "Error 3dSurfMask:\nOutput volume %s%s exists.\n", Opt->out_vol_prefix, Opt->out_vol_view);
00223       exit(1);
00224    }
00225    
00226    if (Opt->out_grid_prefix) {
00227       if (!SUMA_AfniExistsView(Opt->out_grid_exists, Opt->out_grid_view)) {
00228          fprintf(SUMA_STDERR, "Error 3dSurfMask:\nGrid parent %s%s does not exist.\n", Opt->out_grid_prefix, Opt->out_grid_view);
00229          exit(1);
00230       }
00231    }
00232 
00233    
00234    isin = SUMA_FindVoxelsInSurface (SO, vp, &N_in, 0, NULL);
00235    if (!isin) {
00236       SUMA_S_Err("No voxels in surface");
00237       exit(1);
00238    }
00239    OptDs = SUMA_New_FormAfniDset_Opt();
00240    if (Opt->out_vol_prefix) {
00241       SUMA_FileName NewName = SUMA_StripPath(Opt->out_vol_prefix);
00242       OptDs->prefix = NewName.FileName; NewName.FileName = NULL;
00243       OptDs->prefix_path = NewName.Path; NewName.Path = NULL;
00244    }  else {
00245       OptDs->prefix = SUMA_copy_string("3dSurfMask");
00246       OptDs->prefix_path = SUMA_copy_string("./");
00247    }
00248    
00249    /* master dset */
00250    OptDs->master = SUMA_copy_string(vpname);
00251    OptDs->datum = MRI_byte;
00252    OptDs->full_list = 1;
00253    { float * isin_float = NULL;
00254       isin_float = (float *)SUMA_malloc(sizeof(float)*vp->nx*vp->ny*vp->nz);
00255       if (!isin_float) {
00256          SUMA_SL_Crit("Failed to allocate");
00257          exit(1);
00258       }
00259       
00260       if (Opt->obj_type == 2) for (i=0; i<vp->nx*vp->ny*vp->nz; ++i) { if (isin[i] > 1) isin_float[i] = 1.0; else isin_float[i] = 0.0; }                               
00261       else {
00262          for (i=0; i<vp->nx*vp->ny*vp->nz; ++i) isin_float[i] = (float)isin[i];
00263       }
00264       dset = SUMA_FormAfnidset (NULL, isin_float, vp->nx*vp->ny*vp->nz, OptDs);
00265       if (!dset) {
00266          SUMA_SL_Err("Failed to create output dataset!");
00267       } else {
00268          tross_Make_History( FuncName , argc,argv , dset ) ;
00269          DSET_write(dset) ;
00270       }
00271       SUMA_free(isin_float); isin_float = NULL;
00272    }
00273 
00274    if (vpname) SUMA_free(vpname); vpname = NULL;
00275    if (dset) { DSET_delete(dset); dset = NULL; }
00276    if (OptDs) { OptDs->mset = NULL; OptDs = SUMA_Free_FormAfniDset_Opt(OptDs);  }
00277    if (vp != SO->VolPar) SUMA_Free_VolPar(vp); vp = NULL;
00278    if (SO) SUMA_Free_Surface_Object(SO); SO = NULL;
00279    if (ps) SUMA_FreeGenericArgParse(ps); ps = NULL;
00280    if (Spec) SUMA_free(Spec); Spec = NULL;
00281    if (Opt) Opt = SUMA_Free_Generic_Prog_Options_Struct(Opt);
00282    if (!SUMA_Free_CommonFields(SUMAg_CF)) SUMA_error_message(FuncName,"SUMAg_CF Cleanup Failed!",1);
00283    exit(0);
00284    
00285 } 

SUMA_GENERIC_PROG_OPTIONS_STRUCT* SUMA_3dSurfMask_ParseInput char *    argv[],
int    argc,
SUMA_GENERIC_ARGV_PARSE   ps
 

Definition at line 59 of file SUMA_3dSurfMask.c.

References SUMA_GENERIC_ARGV_PARSE::arg_checked, argc, SUMA_GENERIC_PROG_OPTIONS_STRUCT::debug, LocalHead, SUMA_GENERIC_PROG_OPTIONS_STRUCT::obj_type, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_grid_exists, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_grid_prefix, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_grid_view, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_vol_exists, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_vol_prefix, SUMA_GENERIC_PROG_OPTIONS_STRUCT::out_vol_view, SUMA_AfniExistsView(), SUMA_AfniPrefix(), SUMA_Alloc_Generic_Prog_Options_Struct(), SUMA_Boolean, SUMA_ENTRY, SUMA_RETURN, SUMA_SKIP_COMMON_OPTIONS, and usage_3dSurfMask().

Referenced by main().

00060 {
00061    static char FuncName[]={"SUMA_BrainWrap_ParseInput"}; 
00062    SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt=NULL;
00063    int kar;
00064    SUMA_Boolean brk;
00065    SUMA_Boolean LocalHead = NOPE;
00066 
00067    SUMA_ENTRY;
00068    
00069    Opt = SUMA_Alloc_Generic_Prog_Options_Struct();
00070    Opt->obj_type = 1; /* nuanced integer values in output */
00071    kar = 1;
00072    brk = NOPE;
00073         while (kar < argc) { /* loop accross command ine options */
00074                 /*fprintf(stdout, "%s verbose: Parsing command line...\n", FuncName);*/
00075                 if (strcmp(argv[kar], "-h") == 0 || strcmp(argv[kar], "-help") == 0) {
00076                          usage_3dSurfMask(ps);
00077           exit (0);
00078                 }
00079                 
00080                 SUMA_SKIP_COMMON_OPTIONS(brk, kar);
00081       
00082       if (!brk && (strcmp(argv[kar], "-prefix") == 0))
00083       {
00084          if (kar+1 >= argc)
00085          {
00086             fprintf (SUMA_STDERR, "need a number after -prefix \n");
00087             exit (1);
00088          }
00089          Opt->out_vol_prefix = SUMA_AfniPrefix(argv[++kar], Opt->out_vol_view, NULL, &(Opt->out_vol_exists));
00090          
00091          brk = YUP;
00092       }
00093       
00094       if (!brk && (strcmp(argv[kar], "-grid_parent") == 0))
00095       {
00096          if (kar+1 >= argc)
00097          {
00098             fprintf (SUMA_STDERR, "need a dataset after -grid_parent \n");
00099             exit (1);
00100          }
00101          Opt->out_grid_prefix = SUMA_AfniPrefix(argv[++kar], Opt->out_grid_view, NULL, &(Opt->out_grid_exists));
00102          if (!SUMA_AfniExistsView(Opt->out_grid_exists, Opt->out_grid_view)) {
00103             fprintf(SUMA_STDERR, "Error 3dSurfMask:\nGrid parent %s%s does not exist.\n", Opt->out_grid_prefix, Opt->out_grid_view);
00104             exit(1);
00105          }
00106          brk = YUP;
00107       }
00108       
00109       if (!brk && (strcmp(argv[kar], "-mask_only") == 0))
00110       {
00111          Opt->obj_type = 2;
00112          brk = YUP;
00113       }
00114       
00115       if (!brk && (strcmp(argv[kar], "-debug") == 0))
00116       {
00117          if (kar+1 >= argc)
00118          {
00119             fprintf (SUMA_STDERR, "need a number after -debug \n");
00120             exit (1);
00121          }
00122          
00123          Opt->debug = atoi(argv[++kar]);
00124          brk = YUP;
00125       }
00126       if (!brk && !ps->arg_checked[kar]) {
00127                         fprintf (SUMA_STDERR,"Error 3dSurfMask:\nOption %s not understood. Try -help for usage\n", argv[kar]);
00128                         exit (1);
00129                 } else {        
00130                         brk = NOPE;
00131                         kar ++;
00132                 }
00133    }
00134    
00135    SUMA_RETURN(Opt);
00136 }

void usage_3dSurfMask SUMA_GENERIC_ARGV_PARSE   ps
 

Definition at line 11 of file SUMA_3dSurfMask.c.

References i, SUMA_free, SUMA_help_basics(), SUMA_help_IO_Args(), and SUMA_New_Additions().

Referenced by main(), and SUMA_3dSurfMask_ParseInput().

00012 {
00013       static char FuncName[]={"usage_3dSurfMask"};
00014       char * s = NULL, *sio=NULL, *st = NULL, *sts = NULL;
00015       int i;
00016       s = SUMA_help_basics();
00017       sio  = SUMA_help_IO_Args(ps);
00018       printf ( "\n"
00019                "Usage: 3dSurfMask <-i_TYPE SURFACE> <-prefix PREFIX>\n"
00020                "                <-grid_parent GRID_VOL> [-sv SURF_VOL] [-mask_only]\n"
00021                " \n"
00022                "  Creates a volumetric dataset that marks the inside\n"
00023                "    of the surface."
00024                "  Voxels in the output dataset are set to the following\n"
00025                "  values:\n"
00026                "     0: Voxel outside surface\n"
00027                "     1: Voxel just outside the surface. This means the voxel\n"
00028                "        center is outside the surface but inside the \n"
00029                "        bounding box of a triangle in the mesh. \n"
00030                "     2: Voxel contains a surface node. \n"
00031                "     3: Voxel just inside the surface. This means the voxel\n"
00032                "        center is inside the surface and inside the \n"
00033                "        bounding box of a triangle in the mesh. \n"
00034                "     4: Voxel inside the surface. \n"
00035                "\n"
00036                "  Mandatory Parameters:\n"
00037                "     -i_TYPE SURFACE: Specify input surface.\n"
00038                "             You can also use -t* and -spec and -surf\n"
00039                "             methods to input surfaces. See below\n"
00040                "             for more details.\n"
00041                "     -prefix PREFIX: Prefix of output dataset.\n"
00042                "     -grid_parent GRID_VOL: Specifies the grid for the\n"
00043                "                  output volume."
00044                "\n"
00045                "  Other parameters:\n"
00046                "     -mask_only: Produce an output dataset where voxels\n"
00047                "                 are 1 inside the surface and 0 outside,\n"
00048                "                 instead of the more nuanced output above.\n"                 
00049                "\n"                    
00050                "%s"
00051                "%s"
00052                "\n", sio,  s);
00053       SUMA_free(s); s = NULL; SUMA_free(st); st = NULL; SUMA_free(sio); sio = NULL;       
00054       s = SUMA_New_Additions(0, 1); printf("%s\n", s);SUMA_free(s); s = NULL;
00055       printf("       Ziad S. Saad SSCC/NIMH/NIH ziad@nih.gov     \n");
00056       exit(0);
00057 }

Variable Documentation

SUMA_CommonFields* SUMAg_CF = NULL
 

Global pointer to structure containing info common to all viewers

Definition at line 9 of file SUMA_3dSurfMask.c.

SUMA_SurfaceViewer* SUMAg_cSV = NULL
 

Global pointer to current Surface Viewer structure

Definition at line 3 of file SUMA_3dSurfMask.c.

SUMA_DO* SUMAg_DOv = NULL
 

Global pointer to Displayable Object structure vector

Definition at line 7 of file SUMA_3dSurfMask.c.

int SUMAg_N_DOv = 0
 

Number of DOs stored in DOv

Definition at line 8 of file SUMA_3dSurfMask.c.

int SUMAg_N_SVv = 0
 

Number of SVs realized by X

Definition at line 6 of file SUMA_3dSurfMask.c.

SUMA_SurfaceViewer* SUMAg_SVv = NULL
 

Global pointer to the vector containing the various Surface Viewer Structures SUMAg_SVv contains SUMA_MAX_SURF_VIEWERS structures

Definition at line 4 of file SUMA_3dSurfMask.c.

 

Powered by Plone

This site conforms to the following standards: