00001 #define DEBUG_1
00002 #ifdef DEBUG_1
00003 #define DEBUG_2
00004 #define DEBUG_3
00005 #endif
00006
00007
00008
00009 #include "SUMA_suma.h"
00010 #include "../afni.h"
00011
00012
00013
00014
00015 SUMA_SurfaceViewer *SUMAg_cSV;
00016 SUMA_SurfaceViewer *SUMAg_SVv;
00017
00018 int SUMAg_N_SVv = 0;
00019 SUMA_DO *SUMAg_DOv;
00020 int SUMAg_N_DOv = 0;
00021 SUMA_CommonFields *SUMAg_CF;
00022
00023 #ifdef SUMA_DISASTER
00024
00025
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
00041 iv1[N_iv1] = 3;
00042
00043
00044 iv2[N_iv2] = 7;
00045
00046
00047 SUMA_free(iv1);
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 SUMA_RETURN(iv2);
00059 }
00060
00061 #endif
00062
00063 void SUMA_usage (SUMA_GENERIC_ARGV_PARSE *ps)
00064
00065 {
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
00120
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 }
00140
00141
00142
00143
00144
00145
00146
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;
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);
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
00175 SOv[i]->Group = SUMA_copy_string(SUMA_DEF_GROUP_NAME);
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
00181 if (!SUMA_PrepSO_GeomProp_GL(SOv[i])) {
00182 SUMA_S_Err("Failed in SUMA_PrepSO_GeomProp_GL");
00183 SUMA_RETURN(NULL);
00184 }
00185
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
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 int main (int argc,char *argv[])
00228 {
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
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
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
00277 SUMAg_DOv = SUMA_Alloc_DisplayObject_Struct (SUMA_MAX_DISPLAYABLE_OBJECTS);
00278
00279
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
00293 kar = 1;
00294 brk = NOPE;
00295 SurfIn = NOPE;
00296 Domemtrace = YUP;
00297 while (kar < argc) {
00298
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
00350
00351
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
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 }
00450
00451 if (ps->cs->afni_host_name && !AfniHostName) {
00452 AfniHostName = SUMA_copy_string(ps->cs->afni_host_name);
00453 }
00454
00455
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
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
00476 {
00477 int *jnk;
00478 jnk = SUMA_disaster();
00479 SUMA_free(jnk);
00480 }
00481 #endif
00482
00483
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
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
00496
00497
00498
00499 SUMAg_SVv = SUMA_Alloc_SurfaceViewer_Struct (SUMA_MAX_SURF_VIEWERS);
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
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
00576
00577
00578
00579
00580
00581
00582
00583
00584
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
00599 XtAppMainLoop(SUMAg_CF->X->App);
00600
00601
00602
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);
00608 }
00609
00610