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_suma.c

Go to the documentation of this file.
00001 #define DEBUG_1
00002 #ifdef DEBUG_1
00003         #define DEBUG_2
00004         #define DEBUG_3
00005 #endif
00006    
00007 /* Header FILES */
00008    
00009 #include "SUMA_suma.h"
00010 #include "../afni.h"
00011 
00012 /* CODE */
00013 
00014 
00015 SUMA_SurfaceViewer *SUMAg_cSV; /*!< Global pointer to current Surface Viewer structure*/
00016 SUMA_SurfaceViewer *SUMAg_SVv; /*!< Global pointer to the vector containing the various Surface Viewer Structures 
00017                                     SUMAg_SVv contains SUMA_MAX_SURF_VIEWERS structures */
00018 int SUMAg_N_SVv = 0; /*!< Number of SVs realized by X */
00019 SUMA_DO *SUMAg_DOv;     /*!< Global pointer to Displayable Object structure vector*/
00020 int SUMAg_N_DOv = 0; /*!< Number of DOs stored in DOv */
00021 SUMA_CommonFields *SUMAg_CF; /*!< Global pointer to structure containing info common to all viewers */
00022 
00023 #ifdef SUMA_DISASTER
00024 /*!
00025    a function to test debugging 
00026 */
00027 int * SUMA_disaster(void)
00028 {
00029    static char FuncName[]={"SUMA_disaster"};
00030    int *iv1=NULL, *iv2 = NULL, *iv3 = NULL;
00031    int N_iv1, N_iv2;
00032    int i;
00033    
00034    SUMA_ENTRY;
00035    N_iv1 = 5;
00036    N_iv2 = 5;
00037    iv1 = (int*) SUMA_calloc(N_iv1, sizeof(int));
00038    iv2 = (int*) SUMA_calloc(N_iv2, sizeof(int));
00039    
00040    /* overwrite iv1 */
00041    iv1[N_iv1] = 3;
00042    
00043    /* overwrite iv2 */
00044    iv2[N_iv2] = 7;
00045    
00046    /* free iv1 (that should give a warning)*/
00047    SUMA_free(iv1); /* without the -trace option, 
00048                       you'll get a warning of this corruption here */
00049 
00050    /* try to free iv3 although it was not allocated for */
00051    /* AFNI's functions do not check for this ...*/
00052    /* SUMA_free(iv3);*/
00053          
00054    /* don't free iv2, that should only give a warning when you exit with -trace option turned on */
00055    
00056    /* if you use -trace, you'll get a warning at the return for iv2 
00057    All allocated memory will be checked, at the return, not just iv2*/   
00058    SUMA_RETURN(iv2); 
00059 }
00060 
00061 #endif
00062 
00063 void SUMA_usage (SUMA_GENERIC_ARGV_PARSE *ps)
00064    
00065   {/*Usage*/
00066           char *sb = NULL, *sio = NULL;
00067           
00068           sb = SUMA_help_basics();
00069           sio  = SUMA_help_IO_Args(ps);
00070           printf ("\nUsage:  \n"
00071                   " Mode 1: Using a spec file to specify surfaces\n"
00072                   "                suma -spec <Spec file> \n"
00073                   "                     [-sv <SurfVol>] [-ah AfniHost]\n"
00074                   "\n"
00075                                  "   -spec <Spec file>: File containing surface specification. \n"     
00076                                  "                      This file is typically generated by \n"     
00077                                  "                      @SUMA_Make_Spec_FS (for FreeSurfer surfaces) or \n"
00078                   "                      @SUMA_Make_Spec_SF (for SureFit surfaces). \n"
00079                   "                      The Spec file should be located in the directory \n"
00080                   "                      containing the surfaces.\n"
00081                                  "   [-sv <SurfVol>]: Anatomical volume used in creating the surface \n"     
00082                                  "                    and registerd to the current experiment's anatomical \n"     
00083                                  "                    volume (using @SUMA_AlignToExperiment). \n"
00084                   "                    This parameter is optional, but linking to AFNI is \n"
00085                   "                    not possible without it.If you find the need for it \n"
00086                   "                    (as some have), you can specify the SurfVol in the \n"
00087                   "                    specfile. You can do so by adding the field \n"
00088                   "                    SurfaceVolume to each surface in the spec file. \n"
00089                   "                    In this manner, you can have different surfaces using\n"
00090                   "                    different surface volumes.\n"     
00091                                  "   [-ah <AfniHost>]: Name (or IP address) of the computer running AFNI. This \n"     
00092                                  "                     parameter is optional, the default is localhost. \n"     
00093                   "                     When both AFNI and SUMA are on the same computer, \n"
00094                   "                     communication is through shared memory. You can turn that \n"
00095                   "                     off by explicitly setting AfniHost to 127.0.0.1\n"
00096                   "   [-niml]: Start listening for NIML-formatted elements.\n"     
00097                                  "   [-dev]: Allow access to options that are not well polished for consuption.\n"     
00098                   "\n"
00099                   " Mode 2: Using -t_TYPE or -t* options to specify surfaces on command line.\n"
00100                   "         -sv, -ah, -niml and -dev are still applicable here. This mode \n"
00101                   "         is meant to simplify the quick viewing of a surface model.\n"
00102                   "                suma [-i_TYPE surface] [-t* surface] \n"
00103                   "         Surfaces specified on command line are place in a group\n"
00104                   "         called 'DefGroup'.\n"
00105                   "         If you specify nothing on command line, you will have a random\n"
00106                   "         surface created for you. Some of these surfaces are generated\n"
00107                   "         using Thomas Lewiner's sample volumes for creating isosurfaces.\n"
00108                   "         See suma -sources for a complete reference.\n"
00109                   "\n"
00110                   "%s"
00111                   "\n"
00112                   " Modes 1 & 2: You can mix the two modes for loading surfaces but the -sv\n"
00113                   "              option may not be properly applied.\n"    
00114                   "              If you mix these modes, you will have two groups of\n"
00115                   "              surfaces loaded into SUMA. You can switch between them\n"
00116                   "              using the 'Switch Group' button in the viewer controller.\n"            
00117                   "\n"
00118                   "%s"
00119                   /*"   [-iodbg] Trun on the In/Out debug info from the start.\n"
00120                                  "   [-memdbg] Turn on the memory tracing from the start.\n" */    
00121                   "   [-visuals] Shows the available glxvisuals and exits.\n"
00122                   "   [-version] Shows the current version number.\n"
00123                   "   [-latest_news] Shows the latest news for the current \n"
00124                   "                  version of the entire SUMA package.\n"
00125                   "   [-all_latest_news] Shows the history of latest news.\n"
00126                   "   [-progs] Lists all the programs in the SUMA package.\n"
00127                   "   [-sources] Lists code sources used in parts of SUMA.\n"
00128                   "\n"
00129                                  "   For help on interacting with SUMA, press 'ctrl+h' with the mouse \n"
00130                   "   pointer inside SUMA's window.\n"     
00131                                  "   For more help: http://afni.nimh.nih.gov/ssc/ziad/SUMA/SUMA_doc.htm\n"
00132                   "\n"     
00133                                  "   If you can't get help here, please get help somewhere.\n", sio, sb);
00134                   SUMA_free(sb); SUMA_free(sio);
00135                          SUMA_Version(NULL);
00136                          printf ("\n" 
00137                   "\n    Ziad S. Saad SSCC/NIMH/NIH ziad@nih.gov \n\n");
00138           exit (0);
00139   }/*Usage*/
00140      
00141 
00142 
00143 /*!
00144     a function to return some surface objects for SUMA to work with 
00145     
00146     surfaces are added to SUMAg_DOv so let them be freed there....
00147 */
00148 SUMA_SurfaceObject **SUMA_GimmeSomeSOs(int *N_SOv) 
00149 {
00150    static char FuncName[]={"SUMA_GimmeSomeSOs"};
00151    SUMA_SurfaceObject **SOv=NULL;
00152    SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt;
00153    char sid[100]; 
00154    int i, N_i;
00155    SUMA_Boolean LocalHead = NOPE;
00156    
00157    SUMA_ENTRY;
00158    
00159    Opt = (SUMA_GENERIC_PROG_OPTIONS_STRUCT *)SUMA_malloc(sizeof(SUMA_GENERIC_PROG_OPTIONS_STRUCT));
00160 
00161    N_i = 1; /* just one for now */
00162    *N_SOv = N_i; 
00163    SOv = (SUMA_SurfaceObject **) SUMA_calloc(*N_SOv, sizeof(SUMA_SurfaceObject *));
00164    
00165    for (i=0; i<N_i; ++i) {
00166       srand((unsigned int)time(NULL));
00167       do {
00168          Opt->obj_type = rand() % 10;
00169       } while (Opt->obj_type == 6);  /* six sucks! */
00170       Opt->obj_type_res = 64;
00171       Opt->debug = 0;
00172       sprintf(sid, "surf_%d", Opt->obj_type);
00173       SOv[i] = SUMA_MarchingCubesSurface(Opt);
00174       /* assign its Group and State and Side and few other things, must look like surfaces loaded with SUMA_Load_Spec_Surf*/
00175       SOv[i]->Group = SUMA_copy_string(SUMA_DEF_GROUP_NAME); /* change this in sync with string in macro SUMA_BLANK_NEW_SPEC_SURF*/
00176       SOv[i]->State = SUMA_copy_string(SUMA_DEF_STATE_NAME);
00177       SOv[i]->Label = SUMA_copy_string(sid);
00178       SOv[i]->EmbedDim = 3;
00179       SOv[i]->AnatCorrect = YUP;
00180       /* make this surface friendly for suma */
00181       if (!SUMA_PrepSO_GeomProp_GL(SOv[i])) {
00182          SUMA_S_Err("Failed in SUMA_PrepSO_GeomProp_GL");
00183          SUMA_RETURN(NULL);
00184       }
00185       /* Add this surface to SUMA's displayable objects */
00186       if (!SUMA_PrepAddmappableSO(SOv[i], SUMAg_DOv, &(SUMAg_N_DOv), 0, SUMAg_CF->DsetList)) {
00187          SUMA_S_Err("Failed to add mappable SOs ");
00188          SUMA_RETURN(NULL);
00189       }
00190    }
00191   
00192    if (Opt) SUMA_free(Opt);
00193 
00194    SUMA_RETURN(SOv);
00195 }
00196 
00197 /*!\**
00198 File : SUMA.c
00199 \author : Ziad Saad
00200 Date : Thu Dec 27 16:21:01 EST 2001
00201    
00202 Purpose : 
00203    
00204    
00205    
00206 Input paramters : 
00207 \param   
00208 \param   
00209    
00210 Usage : 
00211                 SUMA ( )
00212    
00213    
00214 Returns : 
00215 \return   
00216 \return   
00217    
00218 Support : 
00219 \sa   OpenGL prog. Guide 3rd edition
00220 \sa   varray.c from book's sample code
00221    
00222 Side effects : 
00223    
00224    
00225    
00226 ***/
00227 int main (int argc,char *argv[])
00228 {/* Main */
00229    static char FuncName[]={"suma"}; 
00230         int kar, i;
00231         SUMA_SFname *SF_name;
00232         SUMA_Boolean brk, SurfIn;
00233         char  *NameParam, *AfniHostName = NULL, *s = NULL;
00234    char *specfilename[SUMA_MAX_N_GROUPS], *VolParName[SUMA_MAX_N_GROUPS];
00235    byte InMem[SUMA_MAX_N_GROUPS];
00236         SUMA_SurfSpecFile *Specp[SUMA_MAX_N_GROUPS];   
00237    SUMA_SurfSpecFile Spec;   
00238         SUMA_Axis *EyeAxis;     
00239    SUMA_EngineData *ED= NULL;
00240    DList *list = NULL;
00241    DListElmt *Element= NULL;
00242    int iv15[15], N_iv15, ispec, nspec;
00243    struct stat stbuf;
00244    SUMA_Boolean Start_niml = NOPE, Domemtrace = YUP;
00245    SUMA_GENERIC_ARGV_PARSE *ps=NULL;
00246    SUMA_Boolean LocalHead = NOPE;
00247    
00248     
00249    SUMA_mainENTRY;
00250    
00251         /* allocate space for CommonFields structure */
00252         if (LocalHead) fprintf (SUMA_STDERR,"%s: Calling SUMA_Create_CommonFields ...\n", FuncName);
00253    SUMA_STANDALONE_INIT;
00254    if (LocalHead) fprintf (SUMA_STDERR,"%s: SUMA_Create_CommonFields Done.\n", FuncName);
00255         SUMAg_CF->isGraphical = YUP;
00256 
00257    ps = SUMA_Parse_IO_Args(argc, argv, "-i;-t;");
00258    #if 0
00259    if (argc < 2)
00260        {
00261           SUMA_usage (ps);
00262           exit (1);
00263        }
00264    #endif
00265                 
00266    /* initialize Volume Parent and AfniHostName to nothing */
00267    for (ispec=0; ispec < SUMA_MAX_N_GROUPS; ++ispec) {
00268       specfilename[ispec] = NULL;
00269       VolParName[ispec] = NULL;
00270       Specp[ispec] = NULL;
00271       InMem[ispec] = 0;
00272    }
00273         AfniHostName = NULL; 
00274         
00275       
00276         /* Allocate space for DO structure */
00277         SUMAg_DOv = SUMA_Alloc_DisplayObject_Struct (SUMA_MAX_DISPLAYABLE_OBJECTS);
00278         
00279    /* call the function to parse the other surface mode inputs */
00280    ispec = 0;
00281    if (LocalHead) SUMA_Show_IO_args(ps);
00282    if (ps->i_N_surfnames || ps->t_N_surfnames) {
00283       SUMA_LH("-i and/or -t surfaces on command line!");
00284       Specp[ispec] = SUMA_IO_args_2_spec (ps, &nspec); 
00285       if (Specp[ispec]) ++ispec;
00286       if (nspec != 1) {
00287          SUMA_S_Err("-spec is being parsed separately here, expecting one spec only from SUMA_IO_args_2_spec");
00288          exit (1);
00289       }
00290       
00291    }
00292         /* Work the options */
00293         kar = 1;
00294         brk = NOPE;
00295         SurfIn = NOPE;
00296    Domemtrace = YUP; 
00297         while (kar < argc) { /* loop accross command ine options */
00298                 /*fprintf(stdout, "%s verbose: Parsing command line...\n", FuncName);*/
00299                 
00300       if (strcmp(argv[kar], "-h") == 0 || strcmp(argv[kar], "-help") == 0) {
00301                         SUMA_usage (ps);
00302           exit (1);
00303                 }
00304                 
00305       if (strcmp(argv[kar], "-visuals") == 0) {
00306                          SUMA_ShowAllVisuals ();
00307           exit (0);
00308                 }
00309       
00310       if (strcmp(argv[kar], "-version") == 0) {
00311                          s = SUMA_New_Additions (0.0, 1);
00312           fprintf (SUMA_STDOUT,"%s\n", s); 
00313           SUMA_free(s); s = NULL;
00314           exit (0);
00315                 }
00316       
00317       if (strcmp(argv[kar], "-sources") == 0) {
00318                          s = SUMA_sources_Info();
00319           fprintf (SUMA_STDOUT,"%s\n", s); 
00320           SUMA_free(s); s = NULL;
00321           exit (0);
00322                 }
00323       
00324       if (strcmp(argv[kar], "-all_latest_news") == 0) {
00325                          s = SUMA_New_Additions (-1.0, 0);
00326           fprintf (SUMA_STDOUT,"%s\n", s); 
00327           SUMA_free(s); s = NULL;
00328           exit (0);
00329                 }
00330       
00331       if (strcmp(argv[kar], "-latest_news") == 0) {
00332                          s = SUMA_New_Additions (0.0, 0);
00333           fprintf (SUMA_STDOUT,"%s\n", s); 
00334           SUMA_free(s); s = NULL;
00335           exit (0);
00336                 }
00337       
00338       if (strcmp(argv[kar], "-progs") == 0) {
00339                          s = SUMA_All_Programs();
00340           fprintf (SUMA_STDOUT,"%s\n", s); 
00341           SUMA_free(s); s = NULL;
00342           exit (0);
00343                 }
00344       
00345                 if (!brk && (strcmp(argv[kar], "-iodbg") == 0)) {
00346                         fprintf(SUMA_STDERR,"Error %s: Obsolete, use -trace\n", FuncName);
00347                         exit (0);
00348          /*
00349          fprintf(SUMA_STDOUT,"Warning %s: SUMA running in in/out debug mode.\n", FuncName);
00350          SUMA_INOUT_NOTIFY_ON; 
00351                         brk = YUP;
00352          */
00353                 }
00354       
00355       SUMA_SKIP_COMMON_OPTIONS(brk, kar);
00356       
00357                 #if SUMA_MEMTRACE_FLAG
00358          if (!brk && (strcmp(argv[kar], "-memdbg") == 0)) {
00359                            fprintf(SUMA_STDOUT,"Error %s: -memdbg is obsolete, use -trace\n", FuncName);
00360                            exit (0);
00361             fprintf(SUMA_STDOUT,"Warning %s: SUMA running in memory trace mode.\n", FuncName);
00362                            SUMAg_CF->MemTrace = YUP;
00363             #ifdef USING_MCW_MALLOC
00364             #endif
00365                            brk = YUP;
00366                    }
00367       #endif
00368       
00369       if (!brk && (strcmp(argv[kar], "-dev") == 0)) {
00370                         fprintf(SUMA_STDOUT,"Warning %s: SUMA running in developer mode, some options may malfunction.\n", FuncName);
00371                         SUMAg_CF->Dev = YUP;
00372                         brk = YUP;
00373                 }
00374                 
00375       if (!brk && (strcmp(argv[kar], "-niml") == 0)) {
00376                         Start_niml = YUP;
00377                         brk = YUP;
00378                 }
00379       
00380                 if (!brk && (strcmp(argv[kar], "-vp") == 0 || strcmp(argv[kar], "-sa") == 0 || strcmp(argv[kar], "-sv") == 0))
00381                 {
00382                         kar ++;
00383                         if (kar >= argc)  {
00384                                 fprintf (SUMA_STDERR, "need argument after -vp|-sa|-sv \n");
00385                                 exit (1);
00386                         }
00387                         if (ispec < 1) {
00388             fprintf (SUMA_STDERR, "a -spec option must precede the first -sv option\n");
00389                                 exit (1);
00390          }
00391          if (!specfilename[ispec-1] && !Specp[ispec-1]) {
00392             fprintf (SUMA_STDERR, "a -spec option must precede each -sv option\n");
00393                                 exit (1);
00394          }
00395          VolParName[ispec-1] = argv[kar]; 
00396                         if (LocalHead) {
00397             fprintf(SUMA_STDOUT, "Found: %s\n", VolParName[ispec]);
00398          }
00399          
00400                         brk = YUP;
00401                 }               
00402                 
00403                 if (!brk && strcmp(argv[kar], "-ah") == 0)
00404                 {
00405                         kar ++;
00406                         if (kar >= argc)  {
00407                                 fprintf (SUMA_STDERR, "need argument after -ah\n");
00408                                 exit (1);
00409                         }
00410                         if (strcmp(argv[kar],"localhost") != 0) {
00411             AfniHostName = argv[kar];
00412          }else {
00413            fprintf (SUMA_STDERR, "localhost is the default for -ah\nNo need to specify it.\n");
00414          }
00415                         /*fprintf(SUMA_STDOUT, "Found: %s\n", AfniHostName);*/
00416 
00417                         brk = YUP;
00418                 }       
00419                 if (!brk && strcmp(argv[kar], "-spec") == 0)
00420                 { 
00421                    kar ++;
00422                    if (kar >= argc)  {
00423                                 fprintf (SUMA_STDERR, "need argument after -spec \n");
00424                                 exit (1);
00425                         }
00426                         
00427          if (ispec >= SUMA_MAX_N_GROUPS) {
00428             fprintf (SUMA_STDERR, "Cannot accept more than %d spec files.\n", SUMA_MAX_N_GROUPS);
00429             exit(1);
00430          }
00431          
00432                         specfilename[ispec] = argv[kar]; 
00433                         if (LocalHead) {
00434             fprintf(SUMA_STDOUT, "Found: %s\n", specfilename[ispec]);
00435          }
00436          ++ispec;
00437                         brk = YUP;
00438                 } 
00439                 
00440 
00441                 if (!brk && !ps->arg_checked[kar]) {
00442                         fprintf (SUMA_STDERR,"Error %s: Option %s not understood. Try -help for usage\n", FuncName, argv[kar]);
00443                         exit (1);
00444                 } else {        
00445                         brk = NOPE;
00446                         kar ++;
00447                 }
00448                 
00449         }/* loop accross command ine options */
00450    /* -ah option now checked for in ps */
00451    if (ps->cs->afni_host_name && !AfniHostName) {
00452       AfniHostName = SUMA_copy_string(ps->cs->afni_host_name);
00453    }
00454    
00455    /* any Specp to be found ?*/
00456    
00457         if (specfilename[0] == NULL && Specp[0] == NULL) {
00458       SUMA_SurfaceObject **SOv=NULL;
00459       int N_SOv = 0;
00460       fprintf (SUMA_STDERR,"%s: No input specified, showing random surfaces.\nUse suma -help for assistance.\n", FuncName);
00461                 /* create your own surface and put it in a spec file */
00462       SOv = SUMA_GimmeSomeSOs(&N_SOv);
00463       Specp[ispec] = SUMA_SOGroup_2_Spec (SOv, N_SOv);
00464       SUMA_free(SOv); SOv = NULL;
00465       InMem[ispec] = 1; 
00466       ++ispec;
00467         }
00468 
00469         if(!SUMA_Assign_HostName (SUMAg_CF, AfniHostName, -1)) {
00470                 fprintf (SUMA_STDERR, "Error %s: Failed in SUMA_Assign_HostName\n", FuncName);
00471                 exit (1);
00472         }
00473    
00474    #ifdef SUMA_DISASTER
00475    /* a function to test Memtracing */
00476    {
00477       int *jnk;
00478       jnk = SUMA_disaster();
00479       SUMA_free(jnk); /* without the -trace, you'll get a warning here if jnk is corrupted */
00480    }
00481    #endif
00482       
00483         /* create an Eye Axis DO */
00484         EyeAxis = SUMA_Alloc_Axis ("Eye Axis");
00485         if (EyeAxis == NULL) {
00486                 SUMA_error_message (FuncName,"Error Creating Eye Axis",1);
00487                 exit(1);
00488         }
00489 
00490         /* Store it into SUMAg_DOv */
00491         if (!SUMA_AddDO(SUMAg_DOv, &SUMAg_N_DOv, (void *)EyeAxis,  AO_type, SUMA_SCREEN)) {
00492                 SUMA_error_message (FuncName,"Error Adding DO", 1);
00493                 exit(1);
00494         }
00495         /*fprintf (SUMA_STDERR, "SUMAg_N_DOv = %d created\n", SUMAg_N_DOv);*/
00496 
00497 
00498         /* Allocate space (and initialize) Surface Viewer Structure */
00499         SUMAg_SVv = SUMA_Alloc_SurfaceViewer_Struct (SUMA_MAX_SURF_VIEWERS);
00500    
00501    /* SUMAg_N_SVv gets updated in SUMA_X_SurfaceViewer_Create
00502    and reflects not the number of elements in SUMAg_SVv which is
00503    SUMA_MAX_SURF_VIEWERS, but the number of viewers that were realized
00504    by X */
00505    
00506         /* Check on initialization */
00507         /*SUMA_Show_SurfaceViewer_Struct (SUMAg_cSV, stdout);*/
00508 
00509         /* Create the Surface Viewer Window */
00510         if (!SUMA_X_SurfaceViewer_Create ()) {
00511                 fprintf(stderr,"Error in SUMA_X_SurfaceViewer_Create. Exiting\n");
00512                 return 1;
00513         }
00514    
00515         for (i=0; i<ispec; ++i) {
00516       if (!list) list = SUMA_CreateList();
00517       ED = SUMA_InitializeEngineListData (SE_Load_Group);
00518       if (!( Element = SUMA_RegisterEngineListCommand (  list, ED, 
00519                                              SEF_cp, (void *)specfilename[i], 
00520                                              SES_Suma, NULL, NOPE, 
00521                                              SEI_Head, NULL ))) {
00522          fprintf(SUMA_STDERR,"Error %s: Failed to register command\n", FuncName);
00523          exit (1);
00524       }
00525       if (!( Element = SUMA_RegisterEngineListCommand (  list, ED, 
00526                                              SEF_ip, (void *)Specp[i], 
00527                                              SES_Suma, NULL, NOPE, 
00528                                              SEI_In, Element ))) {
00529          fprintf(SUMA_STDERR,"Error %s: Failed to register command\n", FuncName);
00530          exit (1);
00531       }
00532       if (!( Element = SUMA_RegisterEngineListCommand (  list, ED, 
00533                                              SEF_f, (void *)&InMem[i], 
00534                                              SES_Suma, NULL, NOPE, 
00535                                              SEI_In, Element ))) {
00536          fprintf(SUMA_STDERR,"Error %s: Failed to register command\n", FuncName);
00537          exit (1);
00538       }
00539       if (!( Element = SUMA_RegisterEngineListCommand (  list, ED, 
00540                                              SEF_vp, (void *)VolParName[i], 
00541                                              SES_Suma, NULL, NOPE, 
00542                                              SEI_In, Element ))) {
00543          fprintf(SUMA_STDERR,"Error %s: Failed to register command\n", FuncName);
00544          exit (1);
00545       }
00546 
00547       N_iv15 = SUMA_MAX_SURF_VIEWERS;
00548       if (N_iv15 > 15) {
00549          fprintf(SUMA_STDERR,"Error %s: trying to register more than 15 viewers!\n", FuncName);
00550          exit(1);
00551       }
00552       for (kar=0; kar<N_iv15; ++kar) iv15[kar] = kar;
00553       if (!( Element = SUMA_RegisterEngineListCommand (  list, ED, 
00554                                              SEF_iv15, (void *)iv15, 
00555                                              SES_Suma, NULL, NOPE, 
00556                                              SEI_In, Element ))) {
00557          fprintf(SUMA_STDERR,"Error %s: Failed to register command\n", FuncName);
00558          exit (1);
00559       }
00560 
00561       if (!( Element = SUMA_RegisterEngineListCommand (  list, ED, 
00562                                              SEF_i, (void *)&N_iv15, 
00563                                              SES_Suma, NULL, NOPE, 
00564                                              SEI_In, Element ))) {
00565          fprintf(SUMA_STDERR,"Error %s: Failed to register command\n", FuncName);
00566          exit (1);
00567       }
00568    }
00569    
00570    if (!SUMA_Engine (&list)) {
00571       fprintf(SUMA_STDERR,"Error %s: Failed in SUMA_Engine\n", FuncName);
00572       exit (1);
00573    }
00574    
00575    /* For some reason, I had to add the glLightfv line below
00576    to force the lightflipping done in SUMA_SetupSVforDOs to take place
00577    in the A viewer when first opened. I don't know why that is, especially
00578    since other controllers would show up lit correctly without this glLightfv line below.
00579    To make matters worse, the A controller's light0_position is correctly flipped.
00580    It is just that the shading is done as if the position was never flipped. 
00581    Actually, without the line below, the first time you hit the F key (to manually flip the light), 
00582    nothing changes, that's because the light's position is unflipped, which is supposed to 
00583    show the incorrect lighting. You'll have to hit F again to have the lighting correctly flipped 
00584    and the shading reflecting it.... ZSS, Aug. 05 04 */
00585    glLightfv(GL_LIGHT0, GL_POSITION, SUMAg_SVv[0].light0_position); 
00586 
00587    if (Start_niml) {
00588       if (!list) list = SUMA_CreateList();
00589       SUMA_REGISTER_HEAD_COMMAND_NO_DATA(list, SE_StartListening, SES_Suma, NULL);
00590 
00591       if (!SUMA_Engine (&list)) {
00592          fprintf(SUMA_STDERR, "Error %s: SUMA_Engine call failed.\n", FuncName);
00593          exit (1);   
00594       }
00595    }
00596    SUMA_FreeGenericArgParse(ps); ps = NULL;
00597    
00598         /*Main loop */
00599         XtAppMainLoop(SUMAg_CF->X->App);
00600 
00601         
00602         /* Done, clean up time */
00603           
00604         if (!SUMA_Free_Displayable_Object_Vect (SUMAg_DOv, SUMAg_N_DOv)) SUMA_error_message(FuncName,"DO Cleanup Failed!",1);
00605         if (!SUMA_Free_SurfaceViewer_Struct_Vect (SUMAg_SVv, SUMA_MAX_SURF_VIEWERS)) SUMA_error_message(FuncName,"SUMAg_SVv Cleanup Failed!",1);
00606         if (!SUMA_Free_CommonFields(SUMAg_CF)) SUMA_error_message(FuncName,"SUMAg_CF Cleanup Failed!",1);
00607   SUMA_RETURN(0);             /* ANSI C requires main to return int. */
00608 }/* Main */ 
00609 
00610 
 

Powered by Plone

This site conforms to the following standards: