Doxygen Source Code Documentation
SUMA_niml.h File Reference
Go to the source code of this file.
Function Documentation
|
||||||||||||||||
|
assign new afni host name SUMA_Assign_HostName (cf, HostName, istream) Assigns a new HostName for niml communication on a particular stream
Definition at line 2127 of file SUMA_niml.c. References SUMA_CommonFields::HostName_v, i, LocalHead, SUMA_CommonFields::NimlStream_v, SUMA_AFNI_STREAM_INDEX, SUMA_Boolean, SUMA_ENTRY, SUMA_MAX_NAME_LENGTH, SUMA_MAX_STREAMS, SUMA_RETURN, and SUMA_CommonFields::TCP_port. Referenced by main(), SUMA_SendToAfni(), and SUMA_SendToSuma().
02128 {
02129 static char FuncName[]={"SUMA_Assign_HostName"};
02130 int istart = 0, istop = 0, i = 0;
02131 SUMA_Boolean LocalHead = NOPE;
02132
02133 SUMA_ENTRY;
02134
02135 if (istream == -1) {
02136 istart = 0; istop = SUMA_MAX_STREAMS;
02137 } else {
02138 istart = istream; istop = istream + 1;
02139 }
02140
02141 for (i = istart; i < istop; ++i) {
02142 if (HostName == NULL)
02143 if (i == SUMA_AFNI_STREAM_INDEX) {
02144 sprintf(cf->HostName_v[i], "localhost"); /* using localhost will allow the use of Shared Memory.
02145 That is only allowed for SUMA<-->AFNI */
02146 } else {
02147 sprintf(cf->HostName_v[i], "127.0.0.1"); /* force TCP for the commoners */
02148 }
02149 else {
02150 if (strlen(HostName) > SUMA_MAX_NAME_LENGTH - 20) {
02151 fprintf(SUMA_STDERR,"Error %s: too long a host name (> %d chars).\n", FuncName, SUMA_MAX_NAME_LENGTH - 20);
02152 SUMA_RETURN (NOPE);
02153 }
02154 sprintf(cf->HostName_v[i],"%s", HostName);
02155 }
02156
02157 sprintf(cf->NimlStream_v[i],"tcp:%s:%d",
02158 cf->HostName_v[i], cf->TCP_port[i]);
02159
02160 if (LocalHead) fprintf(SUMA_STDOUT, "%s: Set HostName %d to %s (stream name: %s)\n",
02161 FuncName, i, cf->HostName_v[i], cf->NimlStream_v[i]);
02162 }
02163
02164 SUMA_RETURN (YUP);
02165 }
|
|
||||||||||||
|
ans = SUMA_CanTalkToAfni (dov, N_dov); determines if any of the Surface Viewers is allowed to talk to afni
Definition at line 1481 of file SUMA_niml.c. References i, SUMA_SurfaceObject::LocalDomainParentID, SUMA_Boolean, SUMA_ENTRY, SUMA_isSO(), SUMA_RETURN, and SUMA_SurfaceObject::VolPar. Referenced by SUMA_Engine().
01482 {
01483 static char FuncName[]={"SUMA_CanTalkToAfni"};
01484 int i;
01485 SUMA_SurfaceObject *SO;
01486
01487 SUMA_ENTRY;
01488
01489 for (i=0; i< N_dov; ++i) {
01490 if (SUMA_isSO(dov[i])) {
01491 SO = (SUMA_SurfaceObject *)(dov[i].OP);
01492 if (SO->LocalDomainParentID != NULL && SO->VolPar != NULL) {
01493 SUMA_RETURN (YUP);
01494 }
01495 }
01496 }
01497
01498 SUMA_RETURN (NOPE);
01499 }
|
|
|
|
A function to take a SUMA_DRAWN_ROI struct and return an equivalent SUMA_NIML_DRAWN_ROI struct.
Definition at line 1688 of file SUMA_niml.c. References SUMA_ROI_DATUM::action, SUMA_DRAWN_ROI::ColPlaneName, SUMA_NIML_DRAWN_ROI::ColPlaneName, DListElmt_::data, dlist_head, dlist_size, dlist_tail, SUMA_DRAWN_ROI::EdgeColor, SUMA_NIML_DRAWN_ROI::EdgeColor, SUMA_DRAWN_ROI::EdgeThickness, SUMA_NIML_DRAWN_ROI::EdgeThickness, SUMA_DRAWN_ROI::FillColor, SUMA_NIML_DRAWN_ROI::FillColor, i, SUMA_DRAWN_ROI::idcode_str, SUMA_NIML_DRAWN_ROI::idcode_str, SUMA_DRAWN_ROI::iLabel, SUMA_NIML_DRAWN_ROI::iLabel, SUMA_DRAWN_ROI::Label, SUMA_NIML_DRAWN_ROI::Label, LocalHead, SUMA_ROI_DATUM::N_n, SUMA_NIML_DRAWN_ROI::N_ROI_datum, DListElmt_::next, SUMA_ROI_DATUM::nPath, SUMA_DRAWN_ROI::Parent_idcode_str, SUMA_NIML_DRAWN_ROI::Parent_idcode_str, SUMA_NIML_DRAWN_ROI::ROI_datum, SUMA_DRAWN_ROI::ROIstrokelist, SUMA_Boolean, SUMA_ENTRY, SUMA_malloc, SUMA_RETURN, SUMA_SL_Err, SUMA_ROI_DATUM::Type, SUMA_DRAWN_ROI::Type, and SUMA_NIML_DRAWN_ROI::Type. Referenced by SUMA_Write_DrawnROI_NIML().
01689 {
01690 static char FuncName[]={"SUMA_DrawnROI_to_NIMLDrawnROI"};
01691 SUMA_NIML_DRAWN_ROI *nimlROI=NULL;
01692 SUMA_ROI_DATUM *ROI_Datum=NULL;
01693 DListElmt *Elm = NULL;
01694 int i = -1;
01695 SUMA_Boolean LocalHead = NOPE;
01696
01697 SUMA_ENTRY;
01698
01699 if (!ROI) {
01700 SUMA_SL_Err("Null ROI");
01701 SUMA_RETURN(NULL);
01702 }
01703
01704 /* allocate for nimlROI */
01705 nimlROI = (SUMA_NIML_DRAWN_ROI *)SUMA_malloc(sizeof(SUMA_NIML_DRAWN_ROI));
01706
01707 nimlROI->Type = (int)ROI->Type;
01708 nimlROI->idcode_str = ROI->idcode_str;
01709 nimlROI->Parent_idcode_str = ROI->Parent_idcode_str;
01710 nimlROI->Label = ROI->Label;
01711 nimlROI->iLabel = ROI->iLabel;
01712 nimlROI->N_ROI_datum = dlist_size(ROI->ROIstrokelist);
01713 nimlROI->ColPlaneName = ROI->ColPlaneName;
01714 nimlROI->FillColor[0] = ROI->FillColor[0];
01715 nimlROI->FillColor[1] = ROI->FillColor[1];
01716 nimlROI->FillColor[2] = ROI->FillColor[2];
01717 nimlROI->EdgeColor[0] = ROI->EdgeColor[0];
01718 nimlROI->EdgeColor[1] = ROI->EdgeColor[1];
01719 nimlROI->EdgeColor[2] = ROI->EdgeColor[2];
01720 nimlROI->EdgeThickness = ROI->EdgeThickness;
01721 if (!nimlROI->N_ROI_datum) {
01722 nimlROI->ROI_datum = NULL;
01723 SUMA_RETURN(nimlROI);
01724 }
01725 nimlROI->ROI_datum = (SUMA_NIML_ROI_DATUM *)SUMA_malloc(nimlROI->N_ROI_datum*sizeof(SUMA_NIML_ROI_DATUM));
01726
01727 /* now fill the ROI_datum structures */
01728 Elm = NULL;
01729 i = 0;
01730 do {
01731 if (!Elm) Elm = dlist_head(ROI->ROIstrokelist);
01732 else Elm = Elm->next;
01733 ROI_Datum = (SUMA_ROI_DATUM *)Elm->data;
01734 nimlROI->ROI_datum[i].action = ROI_Datum->action;
01735 nimlROI->ROI_datum[i].Type = ROI_Datum->Type;
01736 nimlROI->ROI_datum[i].N_n = ROI_Datum->N_n;
01737 nimlROI->ROI_datum[i].nPath = ROI_Datum->nPath;
01738
01739 /*
01740 nimlROI->ROI_datum[i].N_t = ROI_Datum->N_t;
01741 nimlROI->ROI_datum[i].tPath = ROI_Datum->tPath; */
01742 ++i;
01743 } while (Elm != dlist_tail(ROI->ROIstrokelist));
01744
01745 SUMA_RETURN(nimlROI);
01746 }
|
|
|
Definition at line 1912 of file SUMA_niml.c. References calloc, free, i, SUMA_NIML_DRAWN_ROI::idcode_str, SUMA_NIML_DRAWN_ROI::iLabel, SUMA_NIML_DRAWN_ROI::Label, malloc, SUMA_NIML_ROI_DATUM::N_n, SUMA_NIML_DRAWN_ROI::N_ROI_datum, ROI::name, NI_element::name, NI_add_column(), NI_free_element(), NI_get_attribute(), NI_HEADERSHARP_FLAG, NI_new_data_element(), NI_read_element(), NI_rowtype_define(), NI_set_attribute(), NI_stream_close(), NI_stream_open(), NI_strncpy(), NI_TEXT_MODE, NI_write_element(), ROI_seg::nod, SUMA_NIML_ROI_DATUM::nPath, ROI_seg::num_nod, ROI::num_seg, SUMA_NIML_DRAWN_ROI::Parent_idcode_str, SUMA_NIML_DRAWN_ROI::ROI_datum, ROI::seg, strtod(), SUMA_NIML_DRAWN_ROI::Type, ROI::val, NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ.
01913 {
01914 if (!Solo) {
01915 ROI *myroi ;
01916 ROI_seg *myseg , *inseg ;
01917 int roi_type ;
01918 NI_element *nel ;
01919 NI_stream ns ;
01920 char *atr ;
01921 int nseg,ii , nnod,jj ;
01922
01923 /* define struct to read from element */
01924
01925 roi_type = NI_rowtype_define( "ROI_seg" , "int,int[#1]" ) ;
01926 printf("roi_type code = %d\n",roi_type) ;
01927
01928 /* open file and read 1 data element */
01929
01930 ns = NI_stream_open( "file:qroi.dat" , "r" ) ;
01931 if( ns == NULL ){
01932 fprintf(stderr,"Can't open qroi.dat!\n"); exit(1);
01933 }
01934 nel = NI_read_element(ns,1) ; NI_stream_close(ns) ;
01935 if( nel == NULL ){
01936 fprintf(stderr,"Can't read element from qroi.dat!\n"); exit(1);
01937 }
01938
01939 /* check input element name and type */
01940
01941 printf("element name = %s\n",nel->name) ;
01942 printf(" nel->vec_num = %d\n",nel->vec_num) ; /* # of vectors */
01943 printf(" nel->vec_type[0] = %d\n",nel->vec_typ[0]) ; /* type of vec #0 */
01944 if( strcmp(nel->name,"ROI") != 0 ) exit(1) ;
01945
01946 myroi = malloc(sizeof(ROI)) ; /* create output ROI struct */
01947 atr = NI_get_attribute( nel , "ROI_val") ; /* set ROI val from attribute */
01948 myroi->val = (atr == NULL) ? 0.0 : strtod(atr,NULL) ;
01949 atr = NI_get_attribute( nel , "ROI_name") ; /* set ROI name from attribute */
01950 NI_strncpy(myroi->name,atr,128) ;
01951 myroi->num_seg = nseg = nel->vec_len ; /* element is array of ROI_seg */
01952 inseg = nel->vec[0] ; /* input array of ROI_seg */
01953 myroi->seg = malloc(sizeof(ROI_seg)*nseg); /* make output array of ROI_seg */
01954
01955 for( ii=0 ; ii < nseg ; ii++ ){ /* copy input array to output array */
01956 myroi->seg[ii].num_nod = nnod = inseg[ii].num_nod ;
01957 if( nnod > 0 ){
01958 myroi->seg[ii].nod = malloc(sizeof(int)*nnod) ;
01959 memcpy( myroi->seg[ii].nod , inseg[ii].nod , sizeof(int)*nnod ) ;
01960 } else {
01961 myroi->seg[ii].nod = NULL ;
01962 }
01963 }
01964
01965 printf(" val = %g\n"
01966 " name = %s\n"
01967 " num_seg= %d\n" , myroi->val , myroi->name , myroi->num_seg ) ;
01968 for( ii=0 ; ii < nseg ; ii++ ){
01969 printf(" Segment #%d has %d nodes:",ii,myroi->seg[ii].num_nod) ;
01970 for( jj=0 ; jj < myroi->seg[ii].num_nod ; jj++ )
01971 printf(" %d",myroi->seg[ii].nod[jj]) ;
01972 printf("\n") ;
01973 }
01974
01975 printf("\nWriting element to stdout\n") ; fflush(stdout) ;
01976 ns = NI_stream_open( "stdout:" , "w" ) ;
01977 NI_write_element( ns , nel , NI_TEXT_MODE | NI_HEADERSHARP_FLAG ) ;
01978 NI_stream_close( ns ) ; NI_free_element(nel) ;
01979 }
01980 /*********Me ROI*********/
01981 {
01982 char *idcode_str, *Parent_idcode_str, *Label, stmp[200];
01983 int *nPath0, *nPath1, N_n0, N_n1, i, niml_ROI_Datum_type;
01984 NI_element *nel ;
01985 NI_stream ns ;
01986 SUMA_NIML_DRAWN_ROI *niml_ROI = NULL;
01987
01988 idcode_str = (char*) malloc(sizeof(char) * 200); sprintf(idcode_str,"Moma- idcode_str");
01989 Parent_idcode_str = (char*) malloc(sizeof(char) * 200); sprintf(Parent_idcode_str,"El Parent");
01990 Label = (char*) malloc(sizeof(char) * 200); sprintf(Label,"Da laba");
01991 N_n0 = 3;
01992 N_n1 = 4;
01993 nPath0 = (int*) calloc(N_n0, sizeof(int));
01994 nPath1 = (int*) calloc(N_n1, sizeof(int));
01995 nPath0[0] = 2; nPath0[1] = 1; nPath0[2] = 10;
01996 nPath1[0] = 9; nPath1[1] = 7; nPath1[2] = 23; nPath1[3] = -3;
01997
01998 fprintf(stderr,"*********** Defining row type\n");
01999 niml_ROI_Datum_type = NI_rowtype_define("SUMA_NIML_ROI_DATUM", "int,int,int,int[#3]");
02000
02001 niml_ROI = (SUMA_NIML_DRAWN_ROI *)malloc(sizeof(SUMA_NIML_DRAWN_ROI));
02002 niml_ROI->Type = 4;
02003 niml_ROI->idcode_str = idcode_str;
02004 niml_ROI->Parent_idcode_str = Parent_idcode_str;
02005 niml_ROI->Label = Label;
02006 niml_ROI->iLabel = 20;
02007 niml_ROI->N_ROI_datum = 2;
02008 niml_ROI->ROI_datum = (SUMA_NIML_ROI_DATUM *)malloc(niml_ROI->N_ROI_datum*sizeof(SUMA_NIML_ROI_DATUM));
02009
02010 /* now fill the ROI_datum structures */
02011
02012 niml_ROI->ROI_datum[0].N_n = N_n0;
02013 niml_ROI->ROI_datum[1].N_n = N_n1;
02014 if (1) {
02015 fprintf(stderr,"*********** Filling ROI_datum structures\n");
02016 niml_ROI->ROI_datum[0].nPath = nPath0;
02017 niml_ROI->ROI_datum[1].nPath = nPath1;
02018 }else {
02019 fprintf(stderr,"*********** Skipping ROI_datum structure fill.\n");
02020 }
02021
02022 fprintf(stderr,"*********** Creating new data element, a column of %d elements \n", niml_ROI->N_ROI_datum);
02023 nel = NI_new_data_element("A_drawn_ROI", niml_ROI->N_ROI_datum);
02024
02025 fprintf(stderr,"*********** Adding column\n");
02026 NI_add_column( nel , niml_ROI_Datum_type, niml_ROI->ROI_datum );
02027
02028 fprintf(stderr,"*********** Setting attributes element\n");
02029 NI_set_attribute (nel, "Object_ID", niml_ROI->idcode_str);
02030 NI_set_attribute (nel, "Parent_ID", niml_ROI->Parent_idcode_str);
02031 NI_set_attribute (nel, "Label", niml_ROI->Label);
02032 sprintf(stmp,"%d", niml_ROI->iLabel);
02033 NI_set_attribute (nel, "iLabel", stmp);
02034 sprintf(stmp,"%d", niml_ROI->Type);
02035 NI_set_attribute (nel, "Type", stmp);
02036
02037 /* Now write the element */
02038 ns = NI_stream_open( "fd:1" , "w" ) ;
02039 if (NI_write_element( ns , nel , NI_TEXT_MODE | NI_HEADERSHARP_FLAG ) < 0) {
02040 fprintf(stderr,"*********** Badness, failed to write nel\n");
02041 }
02042 NI_stream_close( ns ) ;
02043
02044 /* free nel */
02045 NI_free_element(nel) ; nel = NULL;
02046
02047 /* free the rest */
02048 free(nPath0);
02049 free(nPath1);
02050 free(idcode_str);
02051 free(Parent_idcode_str);
02052 free(Label);
02053 }
02054
02055 }
|
|
|
Definition at line 2095 of file SUMA_niml.c. References SUMA_COMM_STRUCT::afni_host_name, SUMA_ENTRY, SUMA_free, SUMA_COMM_STRUCT::suma_host_name, and SUMA_RETURN. Referenced by SUMA_FreeGenericArgParse().
02096 {
02097 static char FuncName[]={"SUMA_Free_CommSrtuct"};
02098
02099 SUMA_ENTRY;
02100
02101 if (cs) {
02102 if (cs->suma_host_name) SUMA_free(cs->suma_host_name); cs->suma_host_name = NULL;
02103 if (cs->afni_host_name) SUMA_free(cs->afni_host_name); cs->afni_host_name = NULL;
02104 SUMA_free(cs);
02105 }
02106
02107 SUMA_RETURN(NULL);
02108 }
|
|
|
frees a nimlROI structure. These structures are created by the likes of SUMA_DrawnROI_to_NIMLDrawnROI
Definition at line 1878 of file SUMA_niml.c. References LocalHead, SUMA_NIML_DRAWN_ROI::ROI_datum, SUMA_Boolean, SUMA_ENTRY, SUMA_free, and SUMA_RETURN. Referenced by SUMA_OpenDrawnROI_NIML(), and SUMA_Write_DrawnROI_NIML().
01879 {
01880 static char FuncName[]={"SUMA_Free_NIMLDrawROI"};
01881 SUMA_Boolean LocalHead = NOPE;
01882
01883 SUMA_ENTRY;
01884
01885 if (!nimlROI) SUMA_RETURN(NULL);
01886
01887 if (nimlROI->ROI_datum) SUMA_free(nimlROI->ROI_datum); /* DO NOT FREE MEMORY POINTED to by fields inside nimlROI->ROI_datum */
01888 SUMA_free(nimlROI);
01889
01890 SUMA_RETURN(NULL);
01891 }
|
|
|
Definition at line 1420 of file SUMA_niml.c. References SUMA_CrossHair::c, SUMA_SurfaceViewer::Ch, SUMA_SurfaceViewer::Focus_SO_ID, NI_add_column(), NI_FLOAT, NI_new_data_element(), SUMA_SurfaceObject::SelectedNode, SUMA_calloc, SUMA_ENTRY, SUMA_free, SUMA_RETURN, SUMA_XYZ_XYZmap(), and SUMAg_N_DOv. Referenced by SUMA_Engine().
01421 {
01422 static char FuncName[]={"SUMA_makeNI_CrossHair"};
01423 NI_element *nel;
01424 float *XYZmap;
01425 int I_C = -1;
01426 SUMA_SurfaceObject *SO;
01427
01428 SUMA_ENTRY;
01429
01430 if (sv == NULL) {
01431 fprintf(SUMA_STDERR,"Error %s: Null sv.\n", FuncName);
01432 SUMA_RETURN (NULL);
01433 }
01434 if (sv->Ch == NULL) {
01435 fprintf(SUMA_STDERR,"Error %s: NULL Ch.\n", FuncName);
01436 SUMA_RETURN (NULL);
01437 }
01438
01439 SO = (SUMA_SurfaceObject *)(SUMAg_DOv[sv->Focus_SO_ID].OP);
01440 I_C = SO->SelectedNode;
01441 XYZmap = SUMA_XYZ_XYZmap (sv->Ch->c, SO, SUMAg_DOv, SUMAg_N_DOv, &I_C);
01442
01443 if (XYZmap == NULL){
01444 fprintf(SUMA_STDERR,"%s: Linkage is not posible, using current XYZ\n", FuncName);
01445 XYZmap = (float *)SUMA_calloc (3, sizeof(float));
01446 if (XYZmap == NULL) {
01447 fprintf (SUMA_STDERR, "Error %s: Give me a break !\n", FuncName);
01448 SUMA_RETURN (NULL);
01449 }
01450 XYZmap[0] = sv->Ch->c[0];
01451 XYZmap[1] = sv->Ch->c[1];
01452 XYZmap[2] = sv->Ch->c[2];
01453 }
01454
01455 /* make a new data element */
01456 nel = NI_new_data_element( "SUMA_crosshair_xyz" , 3) ;
01457
01458 if (!nel) {
01459 fprintf(SUMA_STDERR,"Error %s: Failed to allocate for nel\n", FuncName);
01460 SUMA_RETURN (NULL);
01461 }
01462
01463 NI_add_column( nel , NI_FLOAT , XYZmap );
01464
01465 if (XYZmap) SUMA_free(XYZmap);
01466
01467 SUMA_RETURN (nel);
01468 }
|
|
|
Make a NIML data element for a NI surface element IJK
Definition at line 1342 of file SUMA_niml.c. References SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::idcode_str, SUMA_SurfaceObject::Label, SUMA_SurfaceObject::LocalDomainParent, SUMA_SurfaceObject::LocalDomainParentID, SUMA_SurfaceObject::N_FaceSet, NI_add_column(), NI_INT, NI_new_data_element(), NI_set_attribute(), SUMA_ENTRY, SUMA_free, SUMA_malloc, SUMA_RETURN, SUMA_VOLPAR::vol_idcode_str, and SUMA_SurfaceObject::VolPar. Referenced by SUMA_Engine().
01343 {
01344 static char FuncName[]={"SUMA_makeNI_SurfIJK"};
01345 NI_element *nel;
01346 int ii, ip, NP;
01347 int *I, *J, *K;
01348
01349 SUMA_ENTRY;
01350
01351
01352 if (SO == NULL) {
01353 fprintf(SUMA_STDERR,"Error %s: Null SO.\n", FuncName);
01354 SUMA_RETURN (NULL);
01355 }
01356 if (SO->N_FaceSet <= 0) {
01357 fprintf(SUMA_STDERR,"Error %s: No FaceSets in SO.\n", FuncName);
01358 SUMA_RETURN (NULL);
01359 }
01360
01361 NP = SO->FaceSetDim;
01362 /* make a new data element, to be filled by columns */
01363 nel = NI_new_data_element( "SUMA_ijk" , SO->N_FaceSet) ;
01364
01365 /* make the columns to be put in the element */
01366 I = (int *) SUMA_malloc( sizeof(int) * SO->N_FaceSet ) ;
01367 J = (int *) SUMA_malloc( sizeof(int) * SO->N_FaceSet ) ;
01368 K = (int *) SUMA_malloc( sizeof(int) * SO->N_FaceSet ) ;
01369
01370 if (!nel || !I || !J || !K ) {
01371 fprintf(SUMA_STDERR,"Error %s: Failed to allocate for nel, I, J or K.\n", FuncName);
01372 SUMA_RETURN (NULL);
01373 }
01374
01375
01376 /* load the columns from the struct array */
01377
01378 for( ii=0 ; ii < SO->N_FaceSet ; ii++ ){
01379 ip = NP * ii;
01380 I[ii] = SO->FaceSetList[ip];
01381 J[ii] = SO->FaceSetList[ip+1];
01382 K[ii] = SO->FaceSetList[ip+2];
01383 }
01384
01385 /* put columns into element */
01386
01387 NI_add_column( nel , NI_INT , I ) ; SUMA_free(I) ;
01388 NI_add_column( nel , NI_INT , J ) ; SUMA_free(J) ;
01389 NI_add_column( nel , NI_INT , K ) ; SUMA_free(K) ;
01390
01391 NI_set_attribute (nel, "volume_idcode", SO->VolPar->vol_idcode_str);
01392 NI_set_attribute (nel, "surface_idcode", SO->idcode_str);
01393 NI_set_attribute (nel, "surface_label", SO->Label);
01394 NI_set_attribute (nel, "local_domain_parent_ID", SO->LocalDomainParentID);
01395 NI_set_attribute (nel, "local_domain_parent", SO->LocalDomainParent);
01396
01397 SUMA_RETURN (nel);
01398 }
|
|
|
Make a NIML data element for a NI surface element i nx ny nz onde index followed by node normal
Definition at line 1267 of file SUMA_niml.c. References SUMA_SurfaceObject::idcode_str, SUMA_SurfaceObject::Label, SUMA_SurfaceObject::LocalDomainParent, SUMA_SurfaceObject::LocalDomainParentID, SUMA_SurfaceObject::N_Node, NI_add_column(), NI_FLOAT, NI_INT, NI_new_data_element(), NI_set_attribute(), SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeNormList, SUMA_ENTRY, SUMA_free, SUMA_malloc, SUMA_RETURN, SUMA_VOLPAR::vol_idcode_str, SUMA_SurfaceObject::VolPar, xc, and yc. Referenced by SUMA_Engine().
01268 {
01269 static char FuncName[]={"SUMA_makeNI_SurfINORM"};
01270 NI_element *nel=NULL;
01271 int *ic=NULL, ii, ND, id;
01272 float *xc=NULL, *yc=NULL, *zc=NULL;
01273
01274 SUMA_ENTRY;
01275
01276
01277 if (SO == NULL) {
01278 fprintf(SUMA_STDERR,"Error %s: Null SO.\n", FuncName);
01279 SUMA_RETURN (NULL);
01280 }
01281 if (SO->N_Node <= 0) {
01282 fprintf(SUMA_STDERR,"Error %s: No nodes in SO.\n", FuncName);
01283 SUMA_RETURN (NULL);
01284 }
01285 if (!SO->NodeNormList) {
01286 fprintf(SUMA_STDERR,"Error %s: No normals in SO.\n", FuncName);
01287 SUMA_RETURN (NULL);
01288 }
01289
01290 /* make a new data element, to be filled by columns */
01291 nel = NI_new_data_element( "SUMA_node_normals" , SO->N_Node) ;
01292
01293 /* make the columns to be put in the element */
01294 #ifdef DOINDEX
01295 ic = (int *) SUMA_malloc( sizeof(int) * SO->N_Node ) ;
01296 #endif
01297 xc = (float *) SUMA_malloc( sizeof(float) * SO->N_Node ) ;
01298 yc = (float *) SUMA_malloc( sizeof(float) * SO->N_Node ) ;
01299 zc = (float *) SUMA_malloc( sizeof(float) * SO->N_Node ) ;
01300
01301 if (!nel || !xc || !yc || !zc) {
01302 fprintf(SUMA_STDERR,"Error %s: Failed to allocate for nel, ic, xc, yc or zc.\n", FuncName);
01303 SUMA_RETURN (NULL);
01304 }
01305
01306
01307 /* load the columns from the struct array */
01308 ND = SO->NodeDim;
01309 for( ii=0 ; ii < SO->N_Node ; ii++ ){
01310 #ifdef DOINDEX
01311 ic[ii] = ii;
01312 #endif
01313 id = ND * ii;
01314 xc[ii] = SO->NodeNormList[id];
01315 yc[ii] = SO->NodeNormList[id+1];
01316 zc[ii] = SO->NodeNormList[id+2];
01317 }
01318
01319 /* put columns into element */
01320
01321 #ifdef DOINDEX
01322 NI_add_column( nel , NI_INT , ic ) ; SUMA_free(ic) ;
01323 #endif
01324 NI_add_column( nel , NI_FLOAT , xc ) ; SUMA_free(xc) ;
01325 NI_add_column( nel , NI_FLOAT , yc ) ; SUMA_free(yc) ;
01326 NI_add_column( nel , NI_FLOAT , zc ) ; SUMA_free(zc) ;
01327
01328 NI_set_attribute (nel, "volume_idcode", SO->VolPar->vol_idcode_str);
01329 NI_set_attribute (nel, "surface_idcode", SO->idcode_str);
01330 NI_set_attribute (nel, "surface_label", SO->Label);
01331 NI_set_attribute (nel, "local_domain_parent_ID", SO->LocalDomainParentID);
01332 NI_set_attribute (nel, "local_domain_parent", SO->LocalDomainParent);
01333 SUMA_RETURN (nel);
01334 }
|
|
|
Make a NIML data element for a NI surface element IXYZ
Definition at line 1201 of file SUMA_niml.c. References SUMA_SurfaceObject::idcode_str, SUMA_SurfaceObject::Label, SUMA_SurfaceObject::LocalDomainParent, SUMA_SurfaceObject::LocalDomainParentID, SUMA_SurfaceObject::N_Node, NI_add_column(), NI_FLOAT, NI_INT, NI_new_data_element(), NI_set_attribute(), SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, SUMA_ENTRY, SUMA_free, SUMA_malloc, SUMA_RETURN, SUMA_VOLPAR::vol_idcode_str, SUMA_SurfaceObject::VolPar, xc, and yc. Referenced by SUMA_Engine().
01202 {
01203 static char FuncName[]={"SUMA_makeNI_SurfIXYZ"};
01204 NI_element *nel;
01205 int *ic, ii, ND, id;
01206 float *xc, *yc, *zc;
01207
01208 SUMA_ENTRY;
01209
01210
01211 if (SO == NULL) {
01212 fprintf(SUMA_STDERR,"Error %s: Null SO.\n", FuncName);
01213 SUMA_RETURN (NULL);
01214 }
01215 if (SO->N_Node <= 0) {
01216 fprintf(SUMA_STDERR,"Error %s: No nodes in SO.\n", FuncName);
01217 SUMA_RETURN (NULL);
01218 }
01219
01220 /* make a new data element, to be filled by columns */
01221 nel = NI_new_data_element( "SUMA_ixyz" , SO->N_Node) ;
01222
01223 /* make the columns to be put in the element */
01224 ic = (int *) SUMA_malloc( sizeof(int) * SO->N_Node ) ;
01225 xc = (float *) SUMA_malloc( sizeof(float) * SO->N_Node ) ;
01226 yc = (float *) SUMA_malloc( sizeof(float) * SO->N_Node ) ;
01227 zc = (float *) SUMA_malloc( sizeof(float) * SO->N_Node ) ;
01228
01229 if (!nel || !ic || !xc || !yc || !zc) {
01230 fprintf(SUMA_STDERR,"Error %s: Failed to allocate for nel, ic, xc, yc or zc.\n", FuncName);
01231 SUMA_RETURN (NULL);
01232 }
01233
01234
01235 /* load the columns from the struct array */
01236 ND = SO->NodeDim;
01237 for( ii=0 ; ii < SO->N_Node ; ii++ ){
01238 ic[ii] = ii;
01239 id = ND * ii;
01240 xc[ii] = SO->NodeList[id];
01241 yc[ii] = SO->NodeList[id+1];
01242 zc[ii] = SO->NodeList[id+2];
01243 }
01244
01245 /* put columns into element */
01246
01247 NI_add_column( nel , NI_INT , ic ) ; SUMA_free(ic) ;
01248 NI_add_column( nel , NI_FLOAT , xc ) ; SUMA_free(xc) ;
01249 NI_add_column( nel , NI_FLOAT , yc ) ; SUMA_free(yc) ;
01250 NI_add_column( nel , NI_FLOAT , zc ) ; SUMA_free(zc) ;
01251
01252 if (SO->VolPar) NI_set_attribute (nel, "volume_idcode", SO->VolPar->vol_idcode_str);
01253 NI_set_attribute (nel, "surface_idcode", SO->idcode_str);
01254 NI_set_attribute (nel, "surface_label", SO->Label);
01255 NI_set_attribute (nel, "local_domain_parent_ID", SO->LocalDomainParentID);
01256 NI_set_attribute (nel, "local_domain_parent", SO->LocalDomainParent);
01257 SUMA_RETURN (nel);
01258 }
|
|
||||||||||||||||||||
|
A function to turn triangulation to nel to be sent to SUMA There's nothing to cleanup so worry not about making a cleanup call
Definition at line 2298 of file SUMA_niml.c. References cleanup(), SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::facesetlist_idcode_str, SUMA_SurfaceObject::Group, SUMA_SurfaceObject::idcode_str, SUMA_SurfaceObject::Label, LocalHead, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, NI_add_column_stride(), NI_INT, NI_set_attribute(), SUMA_SurfaceObject::State, SUMA_AddNelCol(), SUMA_allow_nel_use(), SUMA_Boolean, SUMA_DSET_TYPE, SUMA_EMPTY_ATTR, SUMA_ENTRY, SUMA_LH, SUMA_MESH_IJK, SUMA_NEW_MESH_IJK, SUMA_NewNel(), SUMA_NODE_INT, SUMA_RETURN, and SUMA_SL_Err. Referenced by SUMA_SendSumaNewSurface(), SUMA_SendToSuma(), and SUMA_SO2nimlSO().
02299 {
02300 static char FuncName[]={"SUMA_Mesh_IJK2Mesh_IJK_nel"};
02301 static int i_in=0;
02302 char buf[500];
02303 NI_element *nel=NULL;
02304 SUMA_Boolean LocalHead = NOPE;
02305
02306 SUMA_ENTRY;
02307
02308
02309 if (dtype != SUMA_NEW_MESH_IJK && dtype != SUMA_MESH_IJK) {
02310 SUMA_SL_Err("Bad dtype for this function!");
02311 SUMA_RETURN(NULL);
02312 }
02313
02314 if (cleanup) {
02315 SUMA_LH("Cleanup...");
02316 SUMA_RETURN(NULL);
02317 }
02318
02319 if (SO->FaceSetDim != 3) { /* only deals with XYZ for the moment */
02320 SUMA_SL_Err("FaceSetDim must be 3!");
02321 SUMA_RETURN(nel);
02322 }
02323
02324 if (!i_in) {
02325 /* Initialization block. Nothing to do , really */
02326 }
02327
02328
02329 /* Now create that data element and write it out */
02330 SUMA_allow_nel_use(1);
02331 nel = SUMA_NewNel ( dtype, /* one of SUMA_DSET_TYPE */
02332 SO->idcode_str, /* idcode of Domain Parent */
02333 NULL, /* idcode of geometry parent, not useful here*/
02334 3*SO->N_FaceSet,
02335 NULL,
02336 SO->facesetlist_idcode_str);
02337 if (!nel) {
02338 fprintf (stderr,"Error %s:\nFailed in SUMA_NewNel", FuncName);
02339 SUMA_RETURN(NULL);
02340 }
02341
02342 sprintf(buf, "%d", SO->FaceSetDim);
02343 NI_set_attribute (nel, "Mesh_Dim", buf);
02344
02345 /* set the label */
02346 if (SO->Label) {
02347 sprintf(buf, "FaceSetList for surface %s", SO->Label);
02348 NI_set_attribute (nel, "Object_Label", buf);
02349 } else {
02350 NI_set_attribute (nel, "Object_Label", SUMA_EMPTY_ATTR);
02351 }
02352
02353 #if 0 /* no longer needed */
02354 if (!SO->idcode_str) { SUMA_SL_Err("Surface has a NULL idcode_str, BAD.\n"); SUMA_RETURN(NULL);}
02355 NI_set_attribute (nel, "surface_idcode", SO->idcode_str);
02356
02357 if (!SO->Group) { SUMA_SL_Err("Surface has a NULL Group, BAD.\n"); SUMA_RETURN(NULL);}
02358 NI_set_attribute(nel, "Group", SO->Group);
02359 if (!SO->Label) { NI_set_attribute(nel, "Label", "Def_MeshIJK2MeshIJK_nel"); }
02360 else NI_set_attribute(nel, "Label", SO->Label);
02361 if (!SO->State) { SUMA_SL_Err("Surface has a NULL state, BAD.\n"); SUMA_RETURN(NULL);}
02362 NI_set_attribute(nel, "State", SO->State);
02363 sprintf(buf, "%d", SO->N_Node);
02364 NI_set_attribute(nel, "N_Node", buf);
02365 NI_set_attribute(nel, "EmbedDim", "3");
02366 NI_set_attribute(nel, "AnatCorrect", "1");
02367 #endif
02368
02369 #if 0 /* the old way, no need for embellishments */
02370 /* Add the coordinate column */
02371 if (!SUMA_AddNelCol (nel, /* the famed nel */
02372 "IJK indices",
02373 SUMA_NODE_INT, /* the column's type (description),
02374 one of SUMA_COL_TYPE */
02375 (void *)val, /* the coordinates */
02376 NULL /* that's an optional structure containing
02377 attributes of the added column.
02378 Not used at the moment */
02379 ,1
02380 )) {
02381 fprintf (stderr,"Error %s:\nFailed in SUMA_AddNelCol", FuncName);
02382 SUMA_RETURN(NULL);
02383 }
02384 #else
02385 NI_add_column_stride ( nel, NI_INT, val, 1 );
02386 #endif
02387
02388 ++i_in;
02389
02390 /* return the element */
02391 SUMA_RETURN(nel);
02392
02393 }
|
|
||||||||||||
|
Definition at line 2240 of file SUMA_niml.c. References SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::facesetlist_idcode_str, SUMA_SurfaceObject::idcode_str, LocalHead, SUMA_SurfaceObject::N_FaceSet, NI_element::name, NI_get_attribute(), SUMA_Boolean, SUMA_copy_string(), SUMA_Dset_Type(), SUMA_DSET_TYPE, SUMA_ENTRY, SUMA_free, SUMA_IS_EMPTY_STR_ATTR, SUMA_malloc, SUMA_MESH_IJK, SUMA_NEW_MESH_IJK, SUMA_RETURN, SUMA_SL_Crit, SUMA_SL_Err, NI_element::vec, and NI_element::vec_len. Referenced by SUMA_nimlSO2SO().
02241 {
02242 static char FuncName[]={"SUMA_Mesh_IJK_nel2Mesh_IJK"};
02243 SUMA_DSET_TYPE dtype;
02244 char *tmp=NULL;
02245 SUMA_Boolean LocalHead = NOPE;
02246
02247 SUMA_ENTRY;
02248
02249 dtype = SUMA_Dset_Type(nel->name);
02250 if (dtype != SUMA_NEW_MESH_IJK && dtype != SUMA_MESH_IJK) {
02251 SUMA_SL_Err("Bad dtype for this function!");
02252 SUMA_RETURN(NOPE);
02253 }
02254
02255 tmp = NI_get_attribute(nel, "Parent_ID");
02256 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02257 if (strcmp(SO->idcode_str, tmp)) {
02258 SUMA_SL_Err("idcode mismatch."); SUMA_RETURN(NOPE);
02259 }
02260 }
02261 tmp = NI_get_attribute(nel, "Object_ID");
02262 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->facesetlist_idcode_str = SUMA_copy_string(tmp);
02263
02264 tmp = NI_get_attribute(nel, "Mesh_Dim");
02265 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->FaceSetDim = atoi(tmp);
02266 else SO->FaceSetDim = 0;
02267
02268 if (SO->FaceSetDim != 3) {
02269 SUMA_SL_Err("FaceSetDim must be 3!"); SUMA_RETURN(NOPE);
02270 }
02271
02272 if (SO->N_FaceSet) {
02273 if (SO->N_FaceSet == nel->vec_len/SO->FaceSetDim ) {
02274 if (!SO->FaceSetList) {
02275 SUMA_SL_Err("Bad init variables. SO->N_FaceSet == nel->vec_len/SO->FaceSetDim && !SO->FaceSetList"); SUMA_RETURN(NOPE);
02276 }
02277 } else {
02278 if (SO->FaceSetList) SUMA_free(SO->FaceSetList); SO->FaceSetList = NULL;
02279 }
02280 } else {
02281 if (SO->FaceSetList) { SUMA_SL_Err("SO->FaceSetList should be null here!"); SUMA_RETURN(NOPE); }
02282 }
02283 SO->N_FaceSet = nel->vec_len/SO->FaceSetDim;
02284 if (!SO->FaceSetList) SO->FaceSetList = (int *)SUMA_malloc(nel->vec_len * sizeof(int));
02285 if (!SO->FaceSetList) {
02286 SUMA_SL_Crit("Failed to allocate for FaceSetList"); SUMA_RETURN(NOPE);
02287 }
02288 memcpy((void*)SO->FaceSetList, nel->vec[0], nel->vec_len*sizeof(int));
02289
02290 SUMA_RETURN(YUP);
02291 }
|
|
|
Definition at line 1400 of file SUMA_niml.c. References NI_stream_close(), NI_stream_open(), NI_TEXT_MODE, NI_write_element(), SUMA_Boolean, SUMA_ENTRY, and SUMA_RETURN. Referenced by SUMA_OpenDrawnROI_NIML(), SUMA_process_NIML_data(), and SUMA_Write_DrawnROI_NIML().
01401 {
01402 static char FuncName[]={"SUMA_nel_stdout"};
01403 NI_stream nstdout;
01404
01405 SUMA_ENTRY;
01406
01407 nstdout = NI_stream_open( "fd:1","w");
01408 if( nstdout == NULL ){
01409 fprintf(SUMA_STDERR,"%s: Can't open fd:1\n", FuncName);
01410 SUMA_RETURN(NOPE);
01411 }
01412 fprintf (stdout, "\n----------------------------nel stdout begin-------------------\n");
01413 NI_write_element( nstdout , nel , NI_TEXT_MODE ) ;
01414 fprintf (stdout, "----------------------------nel stdout end -------------------\n");
01415 NI_stream_close(nstdout);
01416
01417 SUMA_RETURN(YUP);
01418 }
|
|
||||||||||||||||
|
Initiates a call on stream cf->ns_v[si].
Definition at line 286 of file SUMA_niml.c. References SUMA_CommonFields::Connected_v, SUMA_CommonFields::HostName_v, LocalHead, NI_stream_open(), NI_stream_reopen(), NI_stream_writecheck(), SUMA_CommonFields::NimlStream_v, SUMA_CommonFields::ns_flags_v, SUMA_CommonFields::ns_v, SUMA_BEEP, SUMA_Boolean, SUMA_ENTRY, SUMA_FLAG_CONNECTED, SUMA_MAX_STREAMS, SUMA_RETURN, SUMA_SL_Err, SUMA_SLP_Err, SUMA_WriteCheckWait, SUMA_WriteCheckWaitMax, and SUMA_CommonFields::TrackingId_v. Referenced by SUMA_Engine(), SUMA_SendToAfni(), and SUMA_SendToSuma().
00287 {
00288 static char FuncName[]={"SUMA_niml_call"};
00289 int nn, Wait_tot;
00290 SUMA_Boolean LocalHead = NOPE;
00291
00292 SUMA_ENTRY;
00293
00294 if (si < 0 || si >= SUMA_MAX_STREAMS) {
00295 SUMA_SL_Err("Bad value for stream index.");
00296 SUMA_RETURN(NOPE);
00297 }
00298
00299 /* find out if the stream has been established already */
00300 if (cf->ns_v[si]) { /* stream is open, nothing to do */
00301 cf->ns_flags_v[si] = SUMA_FLAG_CONNECTED;
00302 if (LocalHead) fprintf(SUMA_STDOUT,"%s: Stream existed, reusing.\n", FuncName);
00303 fprintf(SUMA_STDOUT,"%s: Connected.\n", FuncName); fflush(SUMA_STDOUT);
00304 }else { /* must open stream */
00305 /* contact afni */
00306 fprintf(SUMA_STDOUT,"%s: Contacting ...\n", FuncName); fflush(SUMA_STDOUT);
00307 cf->ns_v[si] = NI_stream_open( cf->NimlStream_v[si] , "w" ) ;
00308 if (!cf->ns_v[si]) {
00309 cf->ns_flags_v[si] = 0;
00310 cf->TrackingId_v[si] = 0;
00311
00312 if (fromSUMA) { SUMA_SLP_Err("NI_stream_open failed (1p)."); }
00313 else { SUMA_SL_Err("NI_stream_open failed (1)."); }
00314 SUMA_BEEP;
00315 cf->Connected_v[si] = !cf->Connected_v[si];
00316 SUMA_RETURN(NOPE) ;
00317 }
00318 if (!strcmp(cf->HostName_v[si],"localhost")) { /* only try shared memory when
00319 AfniHostName is localhost */
00320 fprintf (SUMA_STDERR, "%s: Trying shared memory...\n", FuncName);
00321 if( strstr( cf->NimlStream_v[si] , "tcp:localhost:" ) != NULL ) {
00322 if (!NI_stream_reopen( cf->ns_v[si] , "shm:WeLikeElvis:1M" )) {
00323 fprintf (SUMA_STDERR, "Warning %s: Shared memory communcation failed.\n", FuncName);
00324 }
00325 }
00326 }
00327 /* cf->ns_v[si] = NI_stream_open( "tcp:128.231.212.194:53211" , "w" ) ;*/
00328
00329 if( cf->ns_v[si] == NULL ){
00330 if (fromSUMA) { SUMA_SLP_Err("NI_stream_open failed (2p)");}
00331 else { SUMA_SL_Err("NI_stream_open failed (2)");}
00332 SUMA_BEEP;
00333 cf->Connected_v[si] = !cf->Connected_v[si];
00334 cf->ns_flags_v[si] = 0;
00335 cf->TrackingId_v[si] = 0;
00336
00337 SUMA_RETURN(NOPE) ;
00338 }
00339
00340 Wait_tot = 0;
00341 while(Wait_tot < SUMA_WriteCheckWaitMax){
00342 nn = NI_stream_writecheck( cf->ns_v[si] , SUMA_WriteCheckWait) ;
00343 if( nn == 1 ){
00344 fprintf(stderr,"\n") ;
00345 cf->ns_flags_v[si] = SUMA_FLAG_CONNECTED;
00346 SUMA_RETURN(YUP) ;
00347 }
00348 if( nn < 0 ){
00349 fprintf(stderr,"BAD\n");
00350 cf->Connected_v[si] = !cf->Connected_v[si];
00351 cf->ns_v[si] = NULL;
00352 cf->ns_flags_v[si] = 0;
00353 cf->TrackingId_v[si] = 0;
00354 SUMA_RETURN(NOPE);
00355 }
00356 Wait_tot += SUMA_WriteCheckWait;
00357 fprintf(SUMA_STDERR,".") ;
00358 }
00359
00360 /* make sure you did not exit because of time out */
00361 if (nn!=1) {
00362 cf->Connected_v[si] = !cf->Connected_v[si];
00363 cf->ns_v[si] = NULL;
00364 cf->ns_flags_v[si] = 0;
00365 cf->TrackingId_v[si] = 0;
00366 fprintf(SUMA_STDERR,"Error %s: WriteCheck timed out (> %d ms).\n", FuncName, SUMA_WriteCheckWaitMax);
00367 SUMA_RETURN(NOPE);
00368 }
00369 }
00370
00371 /* Stream is open */
00372 SUMA_RETURN(YUP);
00373 }
|
|
||||||||||||||||||||
|
Definition at line 232 of file SUMA_niml.c. References SUMA_CommonFields::Connected_v, i, LocalHead, NI_stream_close(), NI_stream_kill(), SUMA_CommonFields::ns_flags_v, SUMA_CommonFields::ns_v, SUMA_Boolean, SUMA_ENTRY, SUMA_LH, SUMA_RETURN, SUMA_SL_Err, SUMA_SLP_Err, SUMA_which_stream_index(), and SUMA_CommonFields::TrackingId_v. Referenced by SUMA_process_NIML_data().
00233 {
00234 static char FuncName[]={"SUMA_niml_hangup"};
00235 int i;
00236 SUMA_Boolean LocalHead = NOPE;
00237
00238 SUMA_ENTRY;
00239
00240 if (!nel_stream_name) {
00241 if (!fromSUMA) { SUMA_SL_Err("NULL stream name"); }
00242 else { SUMA_SLP_Err("NULL stream name"); }
00243 SUMA_RETURN(NOPE);
00244 }
00245
00246
00247 i = SUMA_which_stream_index (cf, nel_stream_name);
00248
00249
00250 if (i < 0) {
00251 if (!fromSUMA) { SUMA_SL_Err("Stream not found"); }
00252 else { SUMA_SLP_Err("Stream not found"); }
00253 SUMA_RETURN(NOPE);
00254 } else {
00255 SUMA_LH("Stream found.");
00256 fprintf (SUMA_STDERR,"%s: stream index %d\n", FuncName, i);
00257 if (killit) {
00258 SUMA_LH("Killing stream");
00259 NI_stream_kill(cf->ns_v[i]);
00260 }else {
00261 SUMA_LH("Just closing stream");
00262 NI_stream_close(cf->ns_v[i]);
00263 }
00264 cf->ns_v[i] = NULL;
00265 cf->Connected_v[i] = NOPE;
00266 cf->ns_flags_v[i] = 0;
00267 cf->TrackingId_v[i] = 0;
00268 }
00269
00270 SUMA_RETURN(YUP);
00271 }
|
|
|
NIML workprocess.
Definition at line 27 of file SUMA_niml.c. References SUMA_CommonFields::Listening, LocalHead, NI_element::name, NI_clock_time(), NI_free_element(), NI_get_attribute(), NI_read_element(), NI_stream_close(), NI_stream_goodcheck(), NI_stream_hasinput(), NI_stream_name(), NI_stream_open(), NI_stream_readcheck(), SUMA_CommonFields::niml_work_on, SUMA_CommonFields::NimlStream_v, SUMA_CommonFields::ns_flags_v, SUMA_CommonFields::ns_v, SE_CloseStream4All, SEF_i, SEI_Head, SES_Suma, SUMA_AFNI_STREAM_INDEX, SUMA_AFNI_STREAM_INDEX2, SUMA_BEEP, SUMA_Boolean, SUMA_CreateList(), SUMA_Engine(), SUMA_ENTRY, SUMA_FLAG_CONNECTED, SUMA_FLAG_SKIP, SUMA_FLAG_WAITING, SUMA_InitializeEngineListData(), SUMA_LH, SUMA_MAX_STREAMS, SUMA_process_NIML_data(), SUMA_RegisterEngineListCommand(), SUMA_RETURN, SUMA_CommonFields::TrackingId_v, NI_element::vec, NI_element::vec_filled, NI_element::vec_len, and NI_element::vec_num.
00028 {
00029 static char FuncName[]={"SUMA_niml_workproc"};
00030 int cc , nn, ngood = 0, id;
00031 void *nini ;
00032 char tmpcom[100], *nel_track;
00033 SUMA_SurfaceViewer *sv;
00034 NI_element *nel ;
00035 DList *list = NULL;
00036 SUMA_EngineData *ED = NULL;
00037 SUMA_Boolean LocalHead = NOPE;
00038
00039 if (SUMA_NIML_WORKPROC_IO_NOTIFY) {SUMA_ENTRY;}
00040
00041 if (!SUMAg_CF->niml_work_on) SUMAg_CF->niml_work_on = YUP;
00042
00043 sv = (SUMA_SurfaceViewer *)thereiselvis;
00044 SUMA_LH("In");
00045
00046 for (cc=0; cc<SUMA_MAX_STREAMS; ++cc) {
00047 if (cc == SUMA_AFNI_STREAM_INDEX2) continue; /* this stream is listened to by AFNI and is used by non-suma
00048 SUMA programs to communicate with AFNI directly. SUMA programs are not
00049 to receive elements back on this stream (unlike suma with SUMA_AFNI_STREAM_INDEX)
00050 because communications for now are one way only. */
00051 #if 0
00052 /* *** Pre Dec. 18 03, only SUMA talked to AFNI */
00053 /* check if stream is open */
00054
00055 if( SUMAg_CF->ns == NULL ){
00056 fprintf(SUMA_STDERR,"Error SUMA_niml_workproc: Stream is not open. \n");
00057 if (SUMA_NIML_WORKPROC_IO_NOTIFY) {
00058 SUMA_RETURN(True); /* Don't call me with that lousy stream again */
00059 }
00060 else return (True); /* to reduce the massive amounts of tracing messages */
00061 }
00062 #else
00063 /* *** post Dec. 18 03, making SUMA listen to people's needs */
00064 /* open streams that aren't open */
00065
00066
00067 if (cc != SUMA_AFNI_STREAM_INDEX && cc != SUMA_AFNI_STREAM_INDEX2) { /* Leave AFNI's stream alone, SUMA initiates the connection here,
00068 SUMA_AFNI_STREAM_INDEX2 is not needed here because of earlier
00069 condition, but it is left here as a reminder.*/
00070
00071 if (LocalHead) fprintf (SUMA_STDERR, "%s: Checking on stream %d, %s\n", FuncName, cc, SUMAg_CF->NimlStream_v[cc]);
00072 if( SUMAg_CF->ns_v[cc] == NULL && (SUMAg_CF->ns_flags_v[cc] & SUMA_FLAG_SKIP)==0 ){
00073 if (LocalHead) fprintf (SUMA_STDERR, "%s: \tNot Skipped.\n", FuncName);
00074 SUMAg_CF->ns_v[cc] = NI_stream_open( SUMAg_CF->NimlStream_v[cc] , "r" ) ;
00075 if( SUMAg_CF->ns_v[cc] == NULL ){
00076 fprintf (SUMA_STDERR, "%s: Stream %d, %s open returned NULL\n", FuncName, cc, SUMAg_CF->NimlStream_v[cc]);
00077 SUMAg_CF->ns_flags_v[cc] = SUMA_FLAG_SKIP ; continue;
00078 }
00079 if (LocalHead) fprintf (SUMA_STDERR, "%s: Stream %d, %s open returned NOT null\n", FuncName, cc, SUMAg_CF->NimlStream_v[cc]);
00080 SUMAg_CF->ns_flags_v[cc] = SUMA_FLAG_WAITING ;
00081 }else {
00082 if (SUMAg_CF->ns_v[cc] == NULL) {
00083 SUMA_LH("\tSkipped");
00084 continue;
00085 }
00086 }
00087
00088 ngood ++;
00089 } else {
00090 if( SUMAg_CF->ns_v[SUMA_AFNI_STREAM_INDEX] ) {
00091 ngood ++;
00092 } else { /* do nothing for that stream */
00093 continue;
00094 }
00095 }
00096 #endif
00097
00098 /* check if stream has gone bad */
00099 nn = NI_stream_goodcheck( SUMAg_CF->ns_v[cc] , 1 ) ;
00100
00101 if( nn < 0 ){ /* is bad */
00102 NI_stream_close( SUMAg_CF->ns_v[cc] ) ;
00103 SUMAg_CF->ns_v[cc] = NULL ; /* this will get checked next time */
00104 fprintf(SUMA_STDERR,"Error SUMA_niml_workproc: Stream %d gone bad. Stream closed. \n", cc);
00105
00106 /* close everything */
00107 if (!list) list = SUMA_CreateList();
00108 ED = SUMA_InitializeEngineListData(SE_CloseStream4All);
00109 if (!SUMA_RegisterEngineListCommand ( list, ED,
00110 SEF_i, (void*)&cc,
00111 SES_Suma, (void *)sv, NOPE,
00112 SEI_Head, NULL)) {
00113 fprintf (SUMA_STDERR, "Error %s: Failed to register command.\n", FuncName);
00114 }
00115
00116 if (!SUMA_Engine (&list)) {
00117 fprintf (SUMA_STDERR,"Error %s: Failed in SUMA_Engine.\n\a", FuncName);
00118 }
00119
00120 continue; /* skip to next stream */
00121 }
00122
00123 if (nn == 0) { /* waiting, come back later */
00124 continue;
00125 }
00126
00127 /* if here, stream is good;
00128 see if there is any data to be read */
00129
00130 if (SUMAg_CF->ns_flags_v[cc] & SUMA_FLAG_WAITING) {
00131 SUMAg_CF->ns_flags_v[cc] = SUMA_FLAG_CONNECTED;
00132 fprintf(SUMA_STDERR, "%s: ++ NIML connection opened from %s\n",
00133 FuncName, NI_stream_name(SUMAg_CF->ns_v[cc]) ) ;
00134 }
00135 #if 0
00136 /* not good enough, checks socket only, not buffer */
00137 nn = NI_stream_readcheck( SUMAg_CF->ns , 1 ) ;
00138 #else
00139 nn = NI_stream_hasinput( SUMAg_CF->ns_v[cc] , 1 ) ;
00140 #endif
00141
00142 if( nn > 0 ){ /* has data */
00143 int ct = NI_clock_time() ;
00144 if (LocalHead) fprintf(SUMA_STDERR,"%s: reading data stream", FuncName) ;
00145
00146 nini = NI_read_element( SUMAg_CF->ns_v[cc] , 1 ) ; /* read it */
00147 #if SUMA_SUMA_NIML_DEBUG /* debugging corruption of niml ...*/
00148 nel = (NI_element *)nini ;
00149 if( strcmp(nel->name,"SUMA_irgba") == 0 || strcmp(nel->name,"Node_RGBAb") == 0)
00150 {
00151 int *ibad=NULL;
00152
00153 ibad = (int *)nel->vec[0];
00154 if (ibad[0] > 1000) {
00155 fprintf (SUMA_STDERR,"**********\n\tibad[0] = %d\n****************\n", ibad[0]);
00156 fprintf (SUMA_STDOUT,"********** ibad[0] = %d ****************", ibad[0]);
00157 }
00158 if( nel->vec_len < 1 || nel->vec_filled < 1) { /* empty element? */
00159 fprintf(SUMA_STDERR,"--------\n\tEmpty SUMA_irgba (len = %d, len = %d)\n--------\n",
00160 nel->vec_len, nel->vec_filled);
00161 fprintf(SUMA_STDOUT,"-------- Empty SUMA_irgba (len = %d, filled = %d) --------",
00162 nel->vec_len, nel->vec_filled);
00163 }
00164 fprintf (SUMA_STDOUT,"\n");
00165 }
00166 #endif
00167
00168 if (LocalHead) fprintf(SUMA_STDERR," time=%d ms\n",NI_clock_time()-ct) ; ct = NI_clock_time() ;
00169
00170 if( nini != NULL ) {
00171 nel = (NI_element *)nini ;
00172 if (SUMAg_CF->TrackingId_v[cc]) {
00173 nel_track = NI_get_attribute(nel,"Tracking_ID");
00174 if (nel_track) {
00175 id = atoi(nel_track);
00176 if (id != SUMAg_CF->TrackingId_v[cc] + 1) {
00177 /* remember, "StartTracking" nel is the #1 element, first data element starts at 2 */
00178 fprintf (SUMA_STDERR,"Warning %s:\n Expected element %d, received element %d.\n",
00179 FuncName, SUMAg_CF->TrackingId_v[cc] + 1 , id );
00180 SUMA_BEEP;
00181 }
00182 SUMAg_CF->TrackingId_v[cc] = id;
00183 }
00184 }
00185 if (LocalHead) {
00186 fprintf(SUMA_STDERR,"%s: name=%s vec_len=%d vec_filled=%d, vec_num=%d\n", FuncName,\
00187 nel->name, nel->vec_len, nel->vec_filled, nel->vec_num );
00188 }
00189 if (!SUMA_process_NIML_data( nini , sv)) {
00190 fprintf(SUMA_STDERR,"Error %s: Failed in SUMA_process_NIML_data.\n", FuncName);
00191 }
00192 }
00193
00194 NI_free_element( nini ) ;
00195
00196 if (LocalHead) fprintf(SUMA_STDERR,"processing time=%d ms\n",NI_clock_time()-ct) ;
00197
00198 }
00199
00200 }/* for cc*/
00201
00202 if (ngood == 0) {
00203 SUMAg_CF->niml_work_on = NOPE;
00204 SUMAg_CF->Listening = NOPE;
00205 if (SUMA_NIML_WORKPROC_IO_NOTIFY) {
00206 SUMA_RETURN(True) ; /* don't call me back */
00207 }
00208 else return (True);
00209 }
00210
00211 if (SUMA_NIML_WORKPROC_IO_NOTIFY) {
00212 SUMA_RETURN(False) ; /* call me back baby*/
00213 }
00214 else return (False);
00215 }
|
|
||||||||||||
|
transfroms a SUMA_NIML_DRAWN_ROI * to a SUMA_DRAWN_ROI *
Definition at line 1763 of file SUMA_niml.c. References SUMA_ROI_DATUM::action, SUMA_DRAWN_ROI::ActionStack, SUMA_DRAWN_ROI::CE, SUMA_NIML_DRAWN_ROI::ColPlaneName, SUMA_DRAWN_ROI::ColPlaneName, dlist_init(), dlist_ins_next(), dlist_tail, SUMA_ROI_ACTION_STRUCT::DrawnROI, SUMA_DRAWN_ROI::DrawStatus, SUMA_NIML_DRAWN_ROI::EdgeColor, SUMA_DRAWN_ROI::EdgeColor, SUMA_NIML_DRAWN_ROI::EdgeThickness, SUMA_DRAWN_ROI::EdgeThickness, SUMA_NIML_DRAWN_ROI::FillColor, SUMA_DRAWN_ROI::FillColor, i, SUMA_NIML_DRAWN_ROI::idcode_str, SUMA_DRAWN_ROI::idcode_str, SUMA_NIML_DRAWN_ROI::iLabel, SUMA_DRAWN_ROI::iLabel, SUMA_NIML_DRAWN_ROI::Label, SUMA_DRAWN_ROI::Label, LocalHead, SUMA_DRAWN_ROI::N_CE, SUMA_ROI_DATUM::N_n, SUMA_NIML_DRAWN_ROI::N_ROI_datum, SUMA_ROI_DATUM::nPath, SUMA_NIML_DRAWN_ROI::Parent_idcode_str, SUMA_DRAWN_ROI::Parent_idcode_str, SUMA_NIML_DRAWN_ROI::ROI_datum, SUMA_ROI_ACTION_STRUCT::ROId, SUMA_DRAWN_ROI::ROIstrokelist, SUMA_DRAWN_ROI::StackPos, SUMA_AllocROIDatum(), SUMA_Boolean, SUMA_BSA_AppendStroke, SUMA_BSA_FillArea, SUMA_BSA_JoinEnds, SUMA_copy_string(), SUMA_CreateActionStack(), SUMA_ENTRY, SUMA_LH, SUMA_malloc, SUMA_PushActionStack(), SUMA_RETURN, SUMA_ROI_ClosedPath, SUMA_ROI_FilledArea, SUMA_ROI_Finished, SUMA_ROI_OpenPath, SUMA_SL_Err, SUMA_ROI_DATUM::Type, SUMA_DRAWN_ROI::Type, and SUMA_NIML_DRAWN_ROI::Type. Referenced by SUMA_OpenDrawnROI_NIML().
01764 {
01765 static char FuncName[]={"SUMA_NIMLDrawnROI_to_DrawnROI"};
01766 SUMA_ROI_ACTION_STRUCT *ROIA=NULL;
01767 SUMA_DRAWN_ROI *ROI = NULL;
01768 SUMA_ROI_DATUM *ROI_Datum = NULL;
01769 DListElmt *tmpStackPos=NULL;
01770 int i;
01771 SUMA_Boolean LocalHead = NOPE;
01772
01773 SUMA_ENTRY;
01774
01775 if (!nimlROI) SUMA_RETURN(NULL);
01776
01777 /* allocate and initialize the whimpy fields
01778 Based on SUMA_AllocateDrawnROI*/
01779 ROI = (SUMA_DRAWN_ROI *) SUMA_malloc(sizeof(SUMA_DRAWN_ROI));
01780 if ( nimlROI->Type == SUMA_ROI_OpenPath ||
01781 nimlROI->Type == SUMA_ROI_ClosedPath ||
01782 nimlROI->Type == SUMA_ROI_FilledArea ) { /* this ROI will gradually be reconstructed,
01783 start with the basics */
01784 ROI->Type = SUMA_ROI_OpenPath; /* at the end of the construction you should reach nimlROI->Type */
01785 }else {
01786 /* nothing to reconstruct */
01787 ROI->Type = nimlROI->Type;
01788 }
01789
01790 ROI->idcode_str = SUMA_copy_string(nimlROI->idcode_str);
01791 ROI->Parent_idcode_str = SUMA_copy_string(nimlROI->Parent_idcode_str);
01792 ROI->Label = SUMA_copy_string(nimlROI->Label);
01793 ROI->iLabel = nimlROI->iLabel;
01794 if (LocalHead) fprintf (SUMA_STDERR, "%s: ROI->Parent_idcode_str %s\n", FuncName, ROI->Parent_idcode_str);
01795
01796 ROI->ROIstrokelist = (DList *)SUMA_malloc (sizeof(DList));
01797 dlist_init(ROI->ROIstrokelist, SUMA_FreeROIDatum);
01798
01799 ROI->DrawStatus = SUMA_ROI_Finished;
01800 ROI->StackPos = NULL;
01801 ROI->ActionStack = SUMA_CreateActionStack ();
01802 ROI->ColPlaneName = SUMA_copy_string(nimlROI->ColPlaneName);
01803 ROI->FillColor[0] = nimlROI->FillColor[0];
01804 ROI->FillColor[1] = nimlROI->FillColor[1];
01805 ROI->FillColor[2] = nimlROI->FillColor[2];
01806 ROI->EdgeColor[0] = nimlROI->EdgeColor[0];
01807 ROI->EdgeColor[1] = nimlROI->EdgeColor[1];
01808 ROI->EdgeColor[2] = nimlROI->EdgeColor[2];
01809 ROI->EdgeThickness = nimlROI->EdgeThickness;
01810 ROI->CE = NULL;
01811 ROI->N_CE = -1;
01812 /* fill in the ROI datum stuff */
01813 for (i=0; i<nimlROI->N_ROI_datum; ++i) {
01814 ROI_Datum = SUMA_AllocROIDatum ();
01815 ROI_Datum->action = nimlROI->ROI_datum[i].action;
01816 ROI_Datum->nPath = nimlROI->ROI_datum[i].nPath;
01817 ROI_Datum->Type = nimlROI->ROI_datum[i].Type;
01818 ROI_Datum->N_n = nimlROI->ROI_datum[i].N_n;
01819 if (ForDisplay) { /* create DO/UNDO stack */
01820 ROIA = (SUMA_ROI_ACTION_STRUCT *) SUMA_malloc (sizeof(SUMA_ROI_ACTION_STRUCT));
01821 ROIA->DrawnROI = ROI;
01822 ROIA->ROId = ROI_Datum;
01823 switch (ROI_Datum->action) {
01824 case SUMA_BSA_AppendStroke:
01825 SUMA_LH("Appending Stroke Action");
01826 tmpStackPos = SUMA_PushActionStack (ROI->ActionStack, ROI->StackPos,
01827 SUMA_AddToTailROIDatum, (void *)ROIA, SUMA_DestroyROIActionData);
01828 break;
01829 case SUMA_BSA_JoinEnds:
01830 SUMA_LH("Join Ends Action");
01831 tmpStackPos = SUMA_PushActionStack (ROI->ActionStack, ROI->StackPos,
01832 SUMA_AddToTailJunctionROIDatum, (void *)ROIA, SUMA_DestroyROIActionData);
01833 break;
01834 case SUMA_BSA_FillArea:
01835 SUMA_LH("Fill Area Action");
01836 tmpStackPos = SUMA_PushActionStack (ROI->ActionStack, ROI->StackPos,
01837 SUMA_AddFillROIDatum, (void *)ROIA, SUMA_DestroyROIActionData);
01838 break;
01839 default:
01840 fprintf (SUMA_STDERR, "Error %s: Not ready to deal with this action (%d).\n",
01841 FuncName, ROI_Datum->action);
01842 break;
01843
01844 }
01845
01846 if (tmpStackPos) ROI->StackPos = tmpStackPos;
01847 else {
01848 fprintf (SUMA_STDERR, "Error %s: Failed in SUMA_PushActionStack.\n", FuncName);
01849 }
01850 } else {
01851 /* ROI will not be used for display purposes, just add datum */
01852 dlist_ins_next(ROI->ROIstrokelist, dlist_tail(ROI->ROIstrokelist), (void *)ROI_Datum);
01853 }
01854 }
01855
01856 if (ForDisplay) {
01857 /* Saved ROIs are considered finished, put a finish action on the top of the action stack */
01858 ROIA = (SUMA_ROI_ACTION_STRUCT *) SUMA_malloc (sizeof(SUMA_ROI_ACTION_STRUCT));
01859 ROIA->DrawnROI = ROI;
01860 ROIA->ROId = NULL;
01861 tmpStackPos = SUMA_PushActionStack (ROI->ActionStack, ROI->StackPos,
01862 SUMA_FinishedROI, (void *)ROIA, SUMA_DestroyROIActionData);
01863 if (tmpStackPos) ROI->StackPos = tmpStackPos;
01864 else {
01865 SUMA_SL_Err("Failed in SUMA_PushActionStack.\n");
01866 SUMA_RETURN(NULL);
01867 }
01868 }
01869 SUMA_RETURN(ROI);
01870 }
|
|
||||||||||||||||||||
|
A function to turn node values into a colored nel to be sent to SUMA
Definition at line 2817 of file SUMA_niml.c. References SUMA_SCALE_TO_MAP_OPT::ApplyClip, SUMA_SCALE_TO_MAP_OPT::BrightFact, cleanup(), SUMA_COLOR_SCALED_VECT::cV, i, SUMA_SurfaceObject::idcode_str, SUMA_SCALE_TO_MAP_OPT::IntRange, LocalHead, SUMA_SCALE_TO_MAP_OPT::MaskZero, SUMA_SurfaceObject::N_Node, NI_set_attribute(), SUMA_AddNelCol(), SUMA_allow_nel_use(), SUMA_Boolean, SUMA_CMAP_MATLAB_DEF_BYR64, SUMA_Create_ColorScaledVect(), SUMA_ENTRY, SUMA_free, SUMA_GetStandardMap(), SUMA_LH, SUMA_malloc, SUMA_NewNel(), SUMA_NODE_Ab, SUMA_NODE_Bb, SUMA_NODE_Gb, SUMA_NODE_INDEX, SUMA_NODE_Rb, SUMA_NODE_RGBAb, SUMA_NODEVAL2IRGBA_CLEANUP, SUMA_PercRange(), SUMA_RETURN, SUMA_ScaleToMap(), SUMA_ScaleToMapOptInit(), SUMA_SL_Err, SUMA_STANDARD_CMAP, and UNIQ_idcode_fill(). Referenced by SUMA_SendToSuma().
02818 {
02819 static char FuncName[]={"SUMA_NodeVal2irgba_nel"};
02820 static int i_in=0, *node=NULL;
02821 static SUMA_COLOR_MAP *CM=NULL;
02822 static SUMA_SCALE_TO_MAP_OPT * OptScl=NULL;
02823 static SUMA_STANDARD_CMAP MapType;
02824 static SUMA_COLOR_SCALED_VECT * SV=NULL;
02825 static byte *rgba=NULL;
02826 static char past_instance[50]={""};
02827 char idcode_str[50];
02828 NI_element *nel=NULL;
02829 int i, i4, i3;
02830 float IntRange[2], *Vsort= NULL;
02831 SUMA_Boolean LocalHead = NOPE;
02832
02833 SUMA_ENTRY;
02834
02835 if (cleanup == 1) {
02836 SUMA_LH("Cleanup...");
02837 SUMA_NODEVAL2IRGBA_CLEANUP;
02838 past_instance[0]='\0';
02839 i_in = 0;
02840 SUMA_RETURN(NULL);
02841 }
02842
02843 if (!instanceID) {
02844 SUMA_SL_Err("This function requires instanceID to be non-null.");
02845 SUMA_RETURN(NULL);
02846 }
02847
02848 if (strcmp(instanceID, past_instance)) {
02849 SUMA_LH("A new instance");
02850 /* clean up if necessary */
02851 if (i_in) SUMA_NODEVAL2IRGBA_CLEANUP;
02852 i_in = 0;
02853 sprintf(past_instance,"%s", instanceID);
02854 }
02855
02856
02857
02858 if (!i_in) {
02859 /* first time around */
02860 /* create the color mapping of Cx (SUMA_CMAP_MATLAB_DEF_BYR64)*/
02861 CM = SUMA_GetStandardMap (SUMA_CMAP_MATLAB_DEF_BYR64);
02862 if (CM == NULL) {
02863 fprintf (SUMA_STDERR,"Error %s: Could not get standard colormap.\n", FuncName);
02864 SUMA_RETURN (NULL);
02865 }
02866
02867 /* get the options for creating the scaled color mapping */
02868 OptScl = SUMA_ScaleToMapOptInit();
02869 if (!OptScl) {
02870 fprintf (SUMA_STDERR,"Error %s: Could not get scaling option structure.\n", FuncName);
02871 SUMA_RETURN (NULL);
02872 }
02873
02874 /* work the options a bit */
02875 OptScl->ApplyClip = NOPE;
02876 OptScl->MaskZero = NOPE;
02877 IntRange[0] = 0; IntRange[1] = 100; /* percentile clipping range*/
02878 Vsort = SUMA_PercRange (val, NULL, SO->N_Node, IntRange, IntRange, NULL);
02879 if (Vsort[0] < 0 && Vsort[SO->N_Node -1] > 0 ) {
02880 /* the new method */
02881 if (fabs(IntRange[0]) > IntRange[1]) {
02882 IntRange[1] = -IntRange[0];
02883 } else {
02884 IntRange[0] = -IntRange[1];
02885 }
02886 }
02887 OptScl->IntRange[0] = IntRange[0]; OptScl->IntRange[1] = IntRange[1];
02888 OptScl->BrightFact = 1.0;
02889
02890 /* create structure to hold the colored values */
02891 SV = SUMA_Create_ColorScaledVect(SO->N_Node);/* allocate space for the result */
02892 if (!SV) {
02893 fprintf (SUMA_STDERR,"Error %s: Could not allocate for SV.\n", FuncName);
02894 SUMA_RETURN (NULL);
02895 }
02896
02897 /* node vector */
02898 node = (int *) SUMA_malloc(sizeof(int) * SO->N_Node);
02899 /* color vectors to hold RGBA colors*/
02900 rgba = (byte *) SUMA_malloc(sizeof(byte) * SO->N_Node * 4);
02901 if (!node || !rgba) {
02902 SUMA_SL_Err("Failed to allocate for node or rgba.");
02903 SUMA_RETURN(NULL);
02904 }
02905 for (i=0; i < SO->N_Node; ++i) node[i] = i;
02906
02907 if (Vsort) SUMA_free(Vsort); Vsort = NULL;
02908 }
02909
02910 /* map the values in val to the colormap */
02911
02912 /* finally ! */
02913 if (!SUMA_ScaleToMap (val, SO->N_Node, OptScl->IntRange[0], OptScl->IntRange[1], CM, OptScl, SV)) {
02914 fprintf (SUMA_STDERR,"Error %s: Failed in SUMA_ScaleToMap.\n", FuncName);
02915 SUMA_RETURN (NOPE);
02916 }
02917
02918 /* copy the colors to rgba */
02919 for (i=0; i < SO->N_Node; ++i) {
02920 i4 = 4 * i;
02921 i3 = 3 *i;
02922 rgba[i4] = (byte)(SV->cV[i3 ] * 255); ++i4;
02923 rgba[i4] = (byte)(SV->cV[i3+1] * 255); ++i4;
02924 rgba[i4] = (byte)(SV->cV[i3+2] * 255); ++i4;
02925 rgba[i4] = 255;
02926 }
02927
02928 /* now create the niml element */
02929 UNIQ_idcode_fill (idcode_str);
02930 /* Now create that data element and write it out */
02931 SUMA_allow_nel_use(1);
02932 nel = SUMA_NewNel ( SUMA_NODE_RGBAb, /* one of SUMA_DSET_TYPE */
02933 SO->idcode_str, /* idcode of Domain Parent */
02934 NULL, /* idcode of geometry parent, not useful here*/
02935 SO->N_Node,/* Number of elements */
02936 NULL, NULL);
02937 if (!nel) {
02938 fprintf (stderr,"Error %s:\nFailed in SUMA_NewNel", FuncName);
02939 SUMA_RETURN(NULL);
02940 }
02941 /* set the surface idcode attribute */
02942 NI_set_attribute (nel, "surface_idcode", SO->idcode_str);
02943
02944 /* Add the columns */
02945 SUMA_allow_nel_use(1);
02946 if (!SUMA_AddNelCol (nel, /* the famed nel */
02947 "node index",
02948 SUMA_NODE_INDEX, /* the column's type (description),
02949 one of SUMA_COL_TYPE */
02950 (void *)node, /* the list of node indices */
02951 NULL /* that's an optional structure containing
02952 attributes of the added column.
02953 Not used at the moment */
02954 ,1 /* stride, useful when you need to copy a column
02955 from a multiplexed vector. Say you have in p
02956 [rgb rgb rgb rgb], to get the g column you
02957 send in p+1 for the column pointer and a stride
02958 of 3 */
02959 )) {
02960 fprintf (stderr,"Error %s:\nFailed in SUMA_AddNelCol", FuncName);
02961 SUMA_RETURN(NULL);
02962 }
02963
02964 /* insert from multiplexed rgb vector */
02965 SUMA_allow_nel_use(1);
02966 if (!SUMA_AddNelCol (nel, "red", SUMA_NODE_Rb, (void *)rgba, NULL ,4 )) {
02967 fprintf (stderr,"Error %s:\nFailed in SUMA_AddNelCol", FuncName);
02968 SUMA_RETURN(NULL);
02969 }
02970
02971 SUMA_allow_nel_use(1);
02972 if (!SUMA_AddNelCol (nel, "green", SUMA_NODE_Gb, (void *)(rgba+1), NULL ,4)) {
02973 fprintf (stderr,"Error %s:\nFailed in SUMA_AddNelCol", FuncName);
02974 SUMA_RETURN(NULL);
02975 }
02976
02977 SUMA_allow_nel_use(1);
02978 if (!SUMA_AddNelCol (nel, "blue", SUMA_NODE_Bb, (void *)(rgba+2), NULL ,4)) {
02979 fprintf (stderr,"Error %s:\nFailed in SUMA_AddNelCol", FuncName);
02980 SUMA_RETURN(NULL);
02981 }
02982
02983 SUMA_allow_nel_use(1);
02984 if (!SUMA_AddNelCol (nel, "alpha", SUMA_NODE_Ab, (void *)(rgba+3), NULL ,4)) {
02985 fprintf (stderr,"Error %s:\nFailed in SUMA_AddNelCol", FuncName);
02986 SUMA_RETURN(NULL);
02987 }
02988
02989
02990 ++i_in;
02991
02992 if (cleanup == -1) {
02993 SUMA_LH("Last or one call only cleanup");
02994 SUMA_NODEVAL2IRGBA_CLEANUP;
02995 past_instance[0]='\0';
02996 i_in = 0;
02997 }
02998
02999 /* return the element */
03000 SUMA_RETURN(nel);
03001
03002 }
|
|
||||||||||||||||||||
|
A function to turn node XYZ to nel to be sent to SUMA There's nothing to cleanup so worry not about making a cleanup call
Definition at line 2464 of file SUMA_niml.c. References cleanup(), SUMA_SurfaceObject::idcode_str, SUMA_SurfaceObject::Label, LocalHead, SUMA_SurfaceObject::N_Node, NI_add_column_stride(), NI_FLOAT, NI_set_attribute(), SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::nodelist_idcode_str, SUMA_AddNelCol(), SUMA_allow_nel_use(), SUMA_Boolean, SUMA_DSET_TYPE, SUMA_EMPTY_ATTR, SUMA_ENTRY, SUMA_LH, SUMA_NEW_NODE_XYZ, SUMA_NewNel(), SUMA_NODE_3C, SUMA_NODE_XYZ, SUMA_RETURN, and SUMA_SL_Err. Referenced by SUMA_SendSumaNewSurface(), SUMA_SendToSuma(), and SUMA_SO2nimlSO().
02465 {
02466 static char FuncName[]={"SUMA_NodeXYZ2NodeXYZ_nel"};
02467 static int i_in=0;
02468 char stmp[500];
02469 NI_element *nel=NULL;
02470 SUMA_Boolean LocalHead = NOPE;
02471
02472 SUMA_ENTRY;
02473
02474 if (dtype != SUMA_NEW_NODE_XYZ && dtype != SUMA_NODE_XYZ) {
02475 SUMA_SL_Err("Bad dtype for this function!");
02476 SUMA_RETURN(NULL);
02477 }
02478
02479 if (cleanup) {
02480 SUMA_LH("Cleanup...");
02481 SUMA_RETURN(NULL);
02482 }
02483
02484 if (SO->NodeDim != 3) { /* only deals with XYZ for the moment */
02485 SUMA_SL_Err("NodeDim must be 3!");
02486 SUMA_RETURN(nel);
02487 }
02488
02489 if (!i_in) {
02490 /* Initialization block. Nothing to do , really */
02491
02492 }
02493
02494
02495 /* Now create that data element and write it out */
02496 SUMA_allow_nel_use(1);
02497 nel = SUMA_NewNel ( dtype, /* one of SUMA_DSET_TYPE */
02498 SO->idcode_str, /* idcode of Domain Parent Surface*/
02499 NULL, /* idcode of geometry parent, not useful here*/
02500 3*SO->N_Node,
02501 NULL,
02502 SO->nodelist_idcode_str);
02503 if (!nel) {
02504 fprintf (stderr,"Error %s:\nFailed in SUMA_NewNel", FuncName);
02505 SUMA_RETURN(NULL);
02506 }
02507
02508 sprintf(stmp, "%d", SO->NodeDim);
02509 NI_set_attribute (nel, "Node_Dim", stmp);
02510
02511 #if 0 /* no longer needed */
02512 /* set the surface idcode attribute */
02513 NI_set_attribute (nel, "surface_idcode", SO->idcode_str);
02514 #endif
02515
02516 /* set the label */
02517 if (SO->Label) {
02518 sprintf(stmp, "NodeList for surface %s", SO->Label);
02519 NI_set_attribute (nel, "Object_Label", stmp);
02520 } else {
02521 NI_set_attribute (nel, "Object_Label", SUMA_EMPTY_ATTR);
02522 }
02523
02524 #if 0 /* old way */
02525 /* Add the coordinate column */
02526 if (!SUMA_AddNelCol (nel, /* the famed nel */
02527 "XYZ coords",
02528 SUMA_NODE_3C, /* the column's type (description),
02529 one of SUMA_COL_TYPE */
02530 (void *)val, /* the coordinates */
02531 NULL /* that's an optional structure containing
02532 attributes of the added column.
02533 Not used at the moment */
02534 ,1
02535 )) {
02536 fprintf (stderr,"Error %s:\nFailed in SUMA_AddNelCol", FuncName);
02537 SUMA_RETURN(NULL);
02538 }
02539 #else /* new way, no need for embellishments */
02540 NI_add_column_stride ( nel, NI_FLOAT, val, 1 );
02541 #endif
02542 ++i_in;
02543
02544 /* return the element */
02545 SUMA_RETURN(nel);
02546
02547
02548 }
|
|
||||||||||||
|
The inverse of SUMA_NodeXYZ2NodeXYZ_nel Definition at line 2398 of file SUMA_niml.c. References SUMA_SurfaceObject::idcode_str, LocalHead, SUMA_SurfaceObject::N_Node, NI_element::name, NI_get_attribute(), SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, SUMA_SurfaceObject::nodelist_idcode_str, SUMA_Boolean, SUMA_copy_string(), SUMA_Dset_Type(), SUMA_DSET_TYPE, SUMA_ENTRY, SUMA_free, SUMA_IS_EMPTY_STR_ATTR, SUMA_malloc, SUMA_NEW_NODE_XYZ, SUMA_NODE_XYZ, SUMA_RETURN, SUMA_SL_Crit, SUMA_SL_Err, NI_element::vec, and NI_element::vec_len. Referenced by SUMA_nimlSO2SO().
02399 {
02400 static char FuncName[]={"SUMA_NodeXYZ_nel2NodeXYZ"};
02401 char *tmp = NULL;
02402 SUMA_DSET_TYPE dtype;
02403 SUMA_Boolean LocalHead = NOPE;
02404
02405 SUMA_ENTRY;
02406
02407 dtype = SUMA_Dset_Type(nel->name);
02408
02409 if (dtype != SUMA_NODE_XYZ && dtype != SUMA_NEW_NODE_XYZ) {
02410 SUMA_SL_Err("Bad nel for this function");
02411 SUMA_RETURN(NOPE);
02412 }
02413
02414 tmp = NI_get_attribute(nel, "Node_Dim");
02415 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02416 SO->NodeDim = atoi(tmp);
02417 if (SO->NodeDim != 3) {
02418 SUMA_SL_Err("Not willing to deal with SO->NodeDim != 3");
02419 SUMA_RETURN(NOPE);
02420 }
02421 }
02422
02423 tmp = NI_get_attribute(nel, "Object_ID");
02424 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->nodelist_idcode_str = SUMA_copy_string(tmp);
02425
02426 tmp = NI_get_attribute(nel, "Parent_ID");
02427 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02428 if (strcmp(tmp, SO->idcode_str)) {
02429 SUMA_SL_Err("idcode of parent mismatch"); SUMA_RETURN(NOPE);
02430 }
02431 }
02432
02433 /* how many elements? */
02434 if (SO->N_Node) {
02435 if (SO->N_Node == nel->vec_len/SO->NodeDim) {
02436 if (!SO->NodeList) {
02437 SUMA_SL_Err("Bad initial values in SO. SO->N_Node == nel->vec_len/3 but NULL SO->NodeList");
02438 SUMA_RETURN(NOPE);
02439 }
02440 } else {
02441 /* gotta cleanup */
02442 if (SO->NodeList) SUMA_free(SO->NodeList); SO->NodeList = NULL; SO->N_Node = 0;
02443 }
02444 } else {
02445 if (SO->NodeList) { SUMA_SL_Err("Should not have a NodeList here"); SUMA_RETURN(NOPE); }
02446 }
02447
02448 SO->N_Node = nel->vec_len/SO->NodeDim;
02449 if (!SO->NodeList) SO->NodeList = (float *)SUMA_malloc(nel->vec_len * sizeof(float));
02450 if (!SO->NodeList) {
02451 SUMA_SL_Crit("Failed to allocate"); SUMA_RETURN(NOPE);
02452 }
02453 memcpy((void *)SO->NodeList, nel->vec[0], nel->vec_len * sizeof(float));
02454
02455 SUMA_RETURN(YUP);
02456 }
|
|
||||||||||||
|
Definition at line 1510 of file SUMA_niml.c. References SUMA_X_AllView::App, datap, num_workp, SUMA_ENTRY, SUMA_malloc, SUMA_realloc, SUMA_RETURNe, SUMA_workprocess(), workp, wpid, and SUMA_CommonFields::X. Referenced by SUMA_cmap_wid_postRedisplay(), SUMA_Engine(), SUMA_postRedisplay(), and SUMA_X_SurfaceViewer_Create().
01511 {
01512 static char FuncName[]={"SUMA_register_workproc"};
01513
01514 SUMA_ENTRY;
01515
01516 if( func == NULL ){
01517 fprintf(SUMA_STDERR,"Error %s: func=NULL on entry!\n", FuncName) ;
01518 SUMA_RETURNe;
01519 }
01520
01521 if( num_workp == 0 ){
01522 workp = (XtWorkProc *) SUMA_malloc( sizeof(XtWorkProc) ) ;
01523 datap = (XtPointer *) SUMA_malloc( sizeof(XtPointer) ) ;
01524 wpid = XtAppAddWorkProc(SUMAg_CF->X->App, SUMA_workprocess, NULL ) ;
01525 #ifdef WPDEBUG
01526 fprintf(stderr,"SUMA_register_workproc: wpid = %x\n",(int)wpid) ;
01527 #endif
01528 } else {
01529 workp = (XtWorkProc *) SUMA_realloc( workp, sizeof(XtWorkProc)*(num_workp+1) ) ;
01530 datap = (XtPointer*) SUMA_realloc( datap, sizeof(XtPointer) *(num_workp+1) ) ;
01531 }
01532
01533 workp[num_workp] = func ;
01534 datap[num_workp] = data ;
01535 num_workp++ ;
01536
01537 #ifdef WPDEBUG
01538 fprintf(stderr,"SUMA_register_workproc: have %d workprocs\n",num_workp) ;
01539 #endif
01540
01541 SUMA_RETURNe ;
01542 }
|
|
|
Definition at line 1593 of file SUMA_niml.c. References datap, num_workp, SUMA_ENTRY, SUMA_free, SUMA_RETURNe, workp, and wpid.
01594 {
01595 int ii , ngood ;
01596 static char FuncName[]={"SUMA_remove_workproc"};
01597
01598 SUMA_ENTRY;
01599
01600 if( func == NULL || num_workp == 0 ){
01601 fprintf(SUMA_STDERR,"Error %s: *** illegal parameters!\n", FuncName) ;
01602 SUMA_RETURNe ;
01603 }
01604
01605 if( num_workp < 1 ){
01606 #ifdef WPDEBUG
01607 fprintf(stderr,"SUMA_remove_workproc: No workprocs left\n") ;
01608 #endif
01609 XtRemoveWorkProc( wpid ) ;
01610 SUMA_free(workp) ; workp = NULL ; SUMA_free(datap) ; datap = NULL ;
01611 num_workp = 0 ;
01612 } else {
01613 for( ii=0 ; ii < num_workp ; ii++ ){
01614 if( func == workp[ii] ) { /* move last Workprocess to location of workprocess to be deleted */
01615 workp[ii] = workp[num_workp-1] ;
01616 datap[ii] = datap[num_workp-1] ;
01617 workp[num_workp-1] = NULL;
01618 num_workp--;
01619 }
01620
01621 #ifdef WPDEBUG
01622 fprintf(stderr,"SUMA_remove_workproc: %d workprocs left\n",ngood) ;
01623 #endif
01624 }
01625 }
01626
01627 SUMA_RETURNe ;
01628 }
|
|
||||||||||||
|
The difference between SUMA_remove_workproc2 and SUMA_remove_workproc is that the workprocess removed is identified not just by the function name but also the data pointer Definition at line 1548 of file SUMA_niml.c. References datap, LocalHead, num_workp, SUMA_Boolean, SUMA_ENTRY, SUMA_free, SUMA_RETURNe, workp, and wpid. Referenced by SUMA_ButtClose_pushed().
01549 {
01550 int ii , ngood ;
01551 static char FuncName[]={"SUMA_remove_workproc2"};
01552 SUMA_Boolean LocalHead = NOPE;
01553
01554 SUMA_ENTRY;
01555
01556 if (LocalHead) fprintf (SUMA_STDERR, "%s: func = %p, num_workp = %d\n", FuncName, func, num_workp);
01557
01558 if( func == NULL) {
01559 fprintf(SUMA_STDERR,"%s: *** illegal parameters!\n", FuncName) ;
01560 SUMA_RETURNe ;
01561 }
01562 if (num_workp == 0) {
01563 if (LocalHead) fprintf(SUMA_STDERR,"%s: Nothing to do.\n", FuncName) ;
01564 SUMA_RETURNe ;
01565 }
01566
01567 if( num_workp < 1 ){
01568 #ifdef WPDEBUG
01569 fprintf(SUMA_STDERR,"%s: No workprocs left\n", FuncName) ;
01570 #endif
01571 XtRemoveWorkProc( wpid ) ;
01572 SUMA_free(workp) ; workp = NULL ; SUMA_free(datap) ; datap = NULL ;
01573 num_workp = 0 ;
01574 } else {
01575 for( ii=0 ; ii < num_workp ; ii++ ){
01576 if( func == workp[ii] && data == datap[ii]) { /* move last Workprocess to location of workprocess to be deleted */
01577 workp[ii] = workp[num_workp-1] ;
01578 datap[ii] = datap[num_workp-1] ;
01579 workp[num_workp-1] = NULL;
01580 num_workp--;
01581 }
01582
01583 #ifdef WPDEBUG
01584 fprintf(SUMA_STDERR,"%s: %d workprocs left\n", FuncName, ngood) ;
01585 #endif
01586 }
01587 }
01588
01589 SUMA_RETURNe ;
01590
01591 }
|
|
||||||||||||||||
|
Definition at line 3474 of file SUMA_niml.c. References DSET_NVALS, DSET_PREFIX, LocalHead, NI_BINARY_MODE, NI_free_element(), NI_set_attribute(), NI_write_element(), NI_write_procins(), SBFLAG_INDEX, SUMA_Boolean, SUMA_ENTRY, SUMA_LH, SUMA_RETURN, SUMA_SL_Warn, THD_dataset_to_niml(), THD_nimlize_dsetatr(), and THD_subbrick_to_niml(). Referenced by SUMA_SendToAfni().
03475 {
03476 static char FuncName[]={"SUMA_SendDset_Afni"};
03477 NI_group *ngr = NULL;
03478 NI_element *nel = NULL;
03479 int iv;
03480 SUMA_Boolean LocalHead = NOPE;
03481
03482 SUMA_ENTRY;
03483
03484 if (!dset) {
03485 SUMA_SL_Warn("NULL dset, nothing to do");
03486 SUMA_RETURN(YUP);
03487 }
03488
03489 if (all == 1) {
03490 SUMA_LH("Sending all dset at once");
03491 ngr = THD_dataset_to_niml( dset ) ;
03492 NI_set_attribute( ngr , "AFNI_prefix" , DSET_PREFIX(dset) ) ;
03493 NI_write_element(ns, ngr, NI_BINARY_MODE);
03494 NI_free_element(ngr); ngr = NULL;
03495 SUMA_LH("Done.");
03496 } else {
03497 SUMA_SL_Warn("Sending one sub-brick at a time NOT TESTED IN SUMA YET");
03498 ngr = THD_nimlize_dsetatr( dset ) ; /* header only */
03499 NI_set_attribute( ngr , "AFNI_prefix" , DSET_PREFIX(dset) ) ;
03500 NI_write_procins( ns , "keep_reading" ) ;
03501 NI_write_element( ns, ngr, NI_BINARY_MODE ) ;
03502 NI_free_element( ngr ) ; ngr = NULL;
03503 for( iv=0 ; iv < DSET_NVALS(dset) ; iv++ ){
03504 nel = THD_subbrick_to_niml( dset , iv , SBFLAG_INDEX ) ;
03505 NI_write_element( ns , nel , NI_BINARY_MODE ) ;
03506 NI_free_element(nel) ; nel = NULL;
03507 }
03508 NI_write_procins( ns , "pause_reading" ) ; /* not necessary but tidy */
03509 }
03510
03511
03512 SUMA_RETURN(YUP);
03513 }
|
|
||||||||||||
|
sends a full surface to SUMA
Definition at line 2170 of file SUMA_niml.c. References SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::NodeList, SUMA_COMM_STRUCT::Send, SUMA_Boolean, SUMA_ENTRY, SUMA_Mesh_IJK2Mesh_IJK_nel(), SUMA_NEW_MESH_IJK, SUMA_NEW_NODE_XYZ, SUMA_NodeXYZ2NodeXYZ_nel(), SUMA_PREP_NEW_SURFACE, SUMA_RETURN, SUMA_SendToSuma(), SUMA_SL_Err, SUMA_SO2nimlSO(), SUMA_SURFACE_OBJECT, and SUMA_COMM_STRUCT::talk_suma.
02171 {
02172 static char FuncName[]={"SUMA_SendSumaNewSurface"};
02173 NI_group *ngr=NULL;
02174
02175 SUMA_ENTRY;
02176
02177 if (!SO || !cs) { SUMA_SL_Err("NULL surface or NULL cs"); SUMA_RETURN(NOPE); }
02178 if (!cs->Send || !cs->talk_suma) { SUMA_SL_Err("Nothing to do"); SUMA_RETURN(NOPE); }
02179
02180
02181
02182 if (0) {
02183 /* send the mesh since this is a new surface */
02184 if (!SUMA_SendToSuma (SO, cs, (void *)SO->FaceSetList, SUMA_NEW_MESH_IJK, 1)) {
02185 SUMA_SL_Err("Failed to initialize SUMA_SendToSuma");
02186 cs->Send = NOPE;
02187 cs->talk_suma = NOPE;
02188 SUMA_RETURN(NOPE);
02189 }
02190 /* now send the coordinates of the new surface */
02191 if (!SUMA_SendToSuma (SO, cs, (void *)SO->NodeList, SUMA_NEW_NODE_XYZ, 1)) {
02192 SUMA_SL_Err("Failed to initialize SUMA_SendToSuma");
02193 cs->Send = NOPE;
02194 cs->talk_suma = NOPE;
02195 SUMA_RETURN(NOPE);
02196 }
02197 /* now send the command to register the new surface with viewers*/
02198 if (!SUMA_SendToSuma (SO, cs, NULL, SUMA_PREP_NEW_SURFACE, 1)) {
02199 SUMA_SL_Err("Failed to initialize SUMA_SendToSuma");
02200 cs->Send = NOPE;
02201 cs->talk_suma = NOPE;
02202 SUMA_RETURN(NOPE);
02203 }
02204 /* now manually clean up the function that created the new surface.
02205 last SUMA_SendToSuma call will only clean up the dtype that was being sent last.
02206 SUMA_SendToSuma can only clean when the same dtype is being sent. THAT NEEDS TO BE FIXED, perhaps send
02207 a flag to indicate how many objects you intend to send of any type. If it is one object
02208 then SendToSuma will do cleanup automatically without hangup ...*/
02209 SUMA_Mesh_IJK2Mesh_IJK_nel (SO, NULL, YUP, SUMA_NEW_MESH_IJK);
02210 SUMA_NodeXYZ2NodeXYZ_nel (SO, NULL, YUP, SUMA_NEW_NODE_XYZ);
02211 } else {
02212 /* the new way */
02213 ngr = SUMA_SO2nimlSO(SO, "NodeList, FaceSetList, VolPar", 1);
02214 if (!ngr) {
02215 SUMA_SL_Err("Failed to create surface");
02216 cs->Send = NOPE;
02217 cs->talk_suma = NOPE;
02218 SUMA_RETURN(NOPE);
02219 }
02220 /* now send the command to feed the new surface to suma*/
02221 if (!SUMA_SendToSuma (SO, cs, (void*)ngr, SUMA_SURFACE_OBJECT, 1)) {
02222 SUMA_SL_Err("Failed to initialize SUMA_SendToSuma");
02223 cs->Send = NOPE;
02224 cs->talk_suma = NOPE;
02225 SUMA_RETURN(NOPE);
02226 }
02227
02228 /* now send the command to register the new surface with viewers*/
02229 if (!SUMA_SendToSuma (SO, cs, NULL, SUMA_PREP_NEW_SURFACE, 1)) {
02230 SUMA_SL_Err("Failed to initialize SUMA_SendToSuma");
02231 cs->Send = NOPE;
02232 cs->talk_suma = NOPE;
02233 SUMA_RETURN(NOPE);
02234 }
02235 }
02236
02237 SUMA_RETURN(YUP);
02238 }
|
|
||||||||||||||||
|
Function to handle send data elements to AFNI.
Definition at line 3376 of file SUMA_niml.c. References SUMA_COMM_STRUCT::afni_GoneBad, SUMA_COMM_STRUCT::afni_host_name, SUMA_COMM_STRUCT::afni_istream, SUMA_COMM_STRUCT::afni_Send, LocalHead, NI_stream_close(), NI_stream_goodcheck(), SUMA_CommonFields::ns_flags_v, SUMA_CommonFields::ns_v, SUMA_Assign_HostName(), SUMA_Boolean, SUMA_ENTRY, SUMA_LH, SUMA_niml_call(), SUMA_RETURN, SUMA_SendDset_Afni(), SUMA_SL_Err, SUMA_SL_Warn, SUMA_CommonFields::TrackingId_v, and tt.
03377 {
03378 static char FuncName[]={"SUMA_SendToAfni"};
03379 static float etm = 0.0;
03380 static int i_in = 0;
03381 char stmp[500];
03382 struct timeval tt;
03383 NI_element *nel=NULL;
03384 float *f=NULL;
03385 int n=-1, WaitClose, WaitMax, *ip = NULL;
03386 float wtm;
03387 SUMA_Boolean good = YUP;
03388 SUMA_Boolean LocalHead = NOPE;
03389
03390 SUMA_ENTRY;
03391
03392
03393 if (action == 0) { /* initialization of connection */
03394
03395 SUMA_LH("Setting up for communication with AFNI ...");
03396 cs->afni_Send = YUP;
03397 if(!SUMA_Assign_HostName (SUMAg_CF, cs->afni_host_name, cs->afni_istream)) {
03398 fprintf (SUMA_STDERR, "Error %s: Failed in SUMA_Assign_HostName", FuncName);
03399 exit (1);
03400 }
03401 if (!SUMA_niml_call (SUMAg_CF, cs->afni_istream, NOPE)) {
03402 SUMA_SL_Err("Failed in SUMA_niml_call");
03403 /* connection flag is reset in SUMA_niml_call */
03404 cs->afni_Send = NOPE;
03405 SUMA_RETURN(NOPE);
03406 }
03407
03408 /* no tracking for talking to AFNI */
03409
03410 /* here is where you would start the workprocess for this program
03411 But since communication is one way, then forget about it */
03412 ++i_in;
03413 SUMA_RETURN(YUP);
03414 }
03415
03416 if (action == 1) { /* action == 1, send data mode */
03417 if (!i_in) {
03418 SUMA_SL_Err("You must call SUMA_SendToAfni with action 0 before action 1.\nNo Communcation cleanup done.");
03419 cs->afni_Send = NOPE;
03420 SUMA_RETURN(NOPE);
03421 }
03422
03423 SUMA_LH("Creating nel and sending it");
03424
03425 /* make sure stream is till OK */
03426 if (NI_stream_goodcheck ( SUMAg_CF->ns_v[cs->afni_istream] , 1 ) < 0) {
03427 cs->afni_GoneBad = YUP;
03428 SUMA_SL_Warn("Communication stream with afni gone bad.\nShutting down communication.");
03429 cs->afni_Send = NOPE;
03430 SUMA_RETURN(YUP); /* returning without error since program should continue */
03431 }
03432
03433 if (!SUMA_SendDset_Afni( SUMAg_CF->ns_v[cs->afni_istream], (THD_3dim_dataset *)data, 1)) {
03434 SUMA_SL_Err("Failed to send dset");
03435 cs->afni_Send = NOPE;
03436 SUMA_RETURN(NOPE);
03437 }
03438
03439 ++i_in;
03440 SUMA_RETURN(YUP);
03441 }/* action == 1 */
03442
03443 if (action == 2) {
03444 if (i_in < 2) {
03445 SUMA_SL_Err("You must call SUMA_SendToAfni with action 0 and 1 before action 2.\nNo Communcation cleanup done.");
03446 cs->afni_Send = NOPE;
03447 SUMA_RETURN(NOPE);
03448 }
03449 /* reset static variables */
03450 i_in = 0;
03451 etm = 0.0;
03452
03453 /* now close the stream*/
03454 if (cs->afni_Send && !cs->afni_GoneBad) {
03455 SUMA_LH("Cleanup of nel producing functions...");
03456
03457 NI_stream_close(SUMAg_CF->ns_v[cs->afni_istream]);
03458 SUMAg_CF->ns_v[cs->afni_istream] = NULL;
03459 SUMAg_CF->ns_flags_v[cs->afni_istream] = 0;
03460 SUMAg_CF->TrackingId_v[cs->afni_istream] = 0;
03461 cs->afni_Send = NOPE;
03462 cs->afni_GoneBad = NOPE;
03463 cs->afni_istream = -1;
03464 }
03465
03466 SUMA_RETURN(YUP);
03467 }
03468
03469 /* should not get here */
03470 SUMA_SL_Err("Flow error.\nThis should not be");
03471 SUMA_RETURN(NOPE);
03472 }
|
|
||||||||||||||||||||||||
|
Function to handle send data elements to AFNI.
Definition at line 3039 of file SUMA_niml.c. References SUMA_COMM_STRUCT::comm_NI_mode, SUMA_VOLPAR::dirname, SUMA_COMM_STRUCT::ElInd, SUMA_COMM_STRUCT::Feed2Afni, SUMA_VOLPAR::filecode, SUMA_COMM_STRUCT::GoneBad, SUMA_SurfaceObject::idcode_str, SUMA_COMM_STRUCT::istream, SUMA_COMM_STRUCT::kth, LocalHead, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_COMM_STRUCT::nelps, NI_free_element(), NI_HEADERSHARP_FLAG, NI_new_data_element(), NI_set_attribute(), NI_sleep(), NI_stream_close(), NI_stream_goodcheck(), NI_stream_open(), NI_TEXT_MODE, NI_write_element(), SUMA_CommonFields::NimlStream_v, SUMA_CommonFields::ns_flags_v, SUMA_CommonFields::ns_v, SUMA_COMM_STRUCT::Send, SUMA_append_replace_string(), SUMA_Assign_HostName(), SUMA_Boolean, SUMA_DSET_TYPE, SUMA_Dset_Type_Name(), SUMA_ENTRY, SUMA_etime(), SUMA_free, SUMA_COMM_STRUCT::suma_host_name, SUMA_LH, SUMA_MESH_IJK, SUMA_Mesh_IJK2Mesh_IJK_nel(), SUMA_NEW_MESH_IJK, SUMA_NEW_NODE_XYZ, SUMA_niml_call(), SUMA_NODE_RGBAb, SUMA_NODE_XYZ, SUMA_NodeVal2irgba_nel(), SUMA_NodeXYZ2NodeXYZ_nel(), SUMA_PREP_NEW_SURFACE, SUMA_RETURN, SUMA_SEND_TO_SUMA_FUNC_CLEANUP, SUMA_SL_Err, SUMA_SL_Warn, SUMA_SURFACE_OBJECT, SUMA_COMM_STRUCT::TrackID, SUMA_CommonFields::TrackingId_v, tt, and SUMA_SurfaceObject::VolPar. Referenced by SUMA_AreaDiff(), SUMA_Chung_Smooth(), SUMA_EquateSurfaceSize(), SUMA_NN_GeomSmooth(), SUMA_Offset_GeomSmooth(), SUMA_ProjectSurfaceToSphere(), SUMA_Reposition_Touchup(), SUMA_SendSumaNewSurface(), SUMA_SkullMask(), SUMA_StretchToFitLeCerveau(), SUMA_Taubin_Smooth(), and SUMA_VolDiff().
03040 {
03041 static char FuncName[]={"SUMA_SendToSuma"};
03042 static float etm = 0.0;
03043 static int i_in = 0;
03044 char stmp[500];
03045 struct timeval tt;
03046 NI_element *nel=NULL;
03047 NI_group *ngr = NULL;
03048 float *f=NULL;
03049 int n=-1, WaitClose, WaitMax, *ip = NULL;
03050 float wtm;
03051 SUMA_Boolean good = YUP;
03052 SUMA_Boolean LocalHead = NOPE;
03053
03054 SUMA_ENTRY;
03055
03056
03057 if (action == 0) { /* initialization of connection */
03058
03059 SUMA_LH("Setting up for communication with SUMA ...");
03060 cs->Send = YUP;
03061 if(!SUMA_Assign_HostName (SUMAg_CF, cs->suma_host_name, cs->istream)) {
03062 fprintf (SUMA_STDERR, "Error %s: Failed in SUMA_Assign_HostName", FuncName);
03063 exit (1);
03064 }
03065 if (!SUMA_niml_call (SUMAg_CF, cs->istream, NOPE)) {
03066 SUMA_SL_Err("Failed in SUMA_niml_call");
03067 /* connection flag is reset in SUMA_niml_call */
03068 cs->Send = NOPE;
03069 SUMA_RETURN(NOPE);
03070 }
03071
03072 nel = NI_new_data_element("StartTracking", 0);
03073 cs->TrackID = 1; /* that's the index for StartTracking command */
03074 NI_set_attribute(nel,"ni_stream_name", SUMAg_CF->NimlStream_v[cs->istream]);
03075 sprintf(stmp, "%d", cs->TrackID);
03076 NI_set_attribute(nel,"Tracking_ID", stmp);
03077 if (NI_write_element( SUMAg_CF->ns_v[cs->istream] , nel, cs->comm_NI_mode ) < 0) {
03078 SUMA_SL_Err("Failed to start tracking.\nContinuing...");
03079 }
03080 if (nel) NI_free_element(nel); nel = NULL;
03081
03082 /* here is where you would start the workprocess for this program
03083 But since communication is one way, then forget about it */
03084 ++i_in;
03085 SUMA_RETURN(YUP);
03086 }
03087
03088 if (action == 1) { /* action == 1, send data mode */
03089 if (!i_in) {
03090 SUMA_SL_Err("You must call SUMA_SendToSuma with action 0 before action 1.\nNo Communcation cleanup done.");
03091 cs->Send = NOPE;
03092 SUMA_RETURN(NOPE);
03093 }
03094 if ((cs->ElInd[dtype] % cs->kth)) {
03095 if (LocalHead) fprintf(SUMA_STDERR,"%s: Skipping element %d of type %d\n", FuncName, cs->ElInd[dtype], dtype);
03096 ++cs->ElInd[dtype];
03097 SUMA_RETURN(YUP);
03098 }
03099 ++cs->ElInd[dtype];
03100 SUMA_LH("Creating nel and sending it");
03101 switch (dtype) {
03102 case SUMA_NODE_RGBAb:
03103 case SUMA_NODE_XYZ:
03104 case SUMA_NEW_NODE_XYZ:
03105 n = 3 * SO->N_Node;
03106 f = (float *)data;
03107 break;
03108 case SUMA_NEW_MESH_IJK:
03109 case SUMA_MESH_IJK:
03110 n = 3 * SO->N_FaceSet;
03111 ip = (int *)data;
03112 break;
03113 case SUMA_PREP_NEW_SURFACE:
03114 break;
03115 case SUMA_SURFACE_OBJECT:
03116 break;
03117 default:
03118 SUMA_SL_Err("Data type not supported.");
03119 cs->GoneBad = YUP;
03120 cs->Send = NOPE;
03121 SUMA_RETURN(NOPE);
03122 break;
03123 }
03124
03125 /* make sure stream is till OK */
03126 if (NI_stream_goodcheck ( SUMAg_CF->ns_v[cs->istream] , 1 ) < 0) {
03127 cs->GoneBad = YUP;
03128 SUMA_SL_Warn("Communication stream gone bad.\nShutting down communication.");
03129 cs->Send = NOPE;
03130 SUMA_SEND_TO_SUMA_FUNC_CLEANUP;
03131 SUMA_RETURN(YUP); /* returning without error since program should continue */
03132 }
03133
03134
03135 nel = NULL; ngr = NULL;
03136 switch (dtype) {
03137 case SUMA_NODE_RGBAb:
03138 /* colorize data */
03139 nel = SUMA_NodeVal2irgba_nel (SO, f, SO->idcode_str, 0);
03140 if (!nel) {
03141 SUMA_SL_Err("Failed in SUMA_NodeVal2irgba_nel.\nCommunication off.")
03142 cs->Send = NOPE;
03143 SUMA_RETURN(NOPE);
03144 }
03145 break;
03146 case SUMA_NODE_XYZ:
03147 case SUMA_NEW_NODE_XYZ:
03148 /* turn XYZ to nel */
03149 nel = SUMA_NodeXYZ2NodeXYZ_nel(SO, f, NOPE, dtype);
03150 if (!nel) {
03151 SUMA_SL_Err("Failed in SUMA_NodeXYZ2NodeXYZ_nel.\nCommunication off.")
03152 cs->Send = NOPE;
03153 SUMA_RETURN(NOPE);
03154 }
03155 if (cs->Feed2Afni) NI_set_attribute(nel, "Send2Afni", "DoItBaby");
03156 break;
03157 case SUMA_MESH_IJK:
03158 case SUMA_NEW_MESH_IJK:
03159 /* turn IJK to nel */
03160 nel = SUMA_Mesh_IJK2Mesh_IJK_nel(SO, ip, NOPE, dtype);
03161 if (!nel) {
03162 SUMA_SL_Err("Failed in SUMA_Mesh_IJK2Mesh_IJK_nel.\nCommunication off.")
03163 cs->Send = NOPE;
03164 SUMA_RETURN(NOPE);
03165 }
03166 break;
03167 case SUMA_PREP_NEW_SURFACE:
03168 nel = NI_new_data_element(SUMA_Dset_Type_Name(dtype), 0);
03169 NI_set_attribute (nel, "surface_idcode", SO->idcode_str);
03170 if (SO->VolPar) {
03171 char *vppref=NULL;
03172 vppref = SUMA_append_replace_string(SO->VolPar->dirname, SO->VolPar->filecode, "/", 0);
03173 NI_set_attribute(nel, "VolParFilecode", vppref); SUMA_free(vppref); vppref = NULL;
03174 if (cs->Feed2Afni) NI_set_attribute(nel, "Send2Afni", "DoItBaby");
03175 }
03176 break;
03177 case SUMA_SURFACE_OBJECT:
03178 ngr = (NI_group *)data;
03179 break;
03180 default:
03181 SUMA_SL_Err("Unexpected element. Ignoring.");
03182 SUMA_RETURN(YUP);
03183 break;
03184 }
03185
03186
03187 if (!nel && !ngr) {/* !nel */
03188 SUMA_SL_Err("Flow error.");
03189 SUMA_RETURN(NOPE);
03190 }else {/* !nel */
03191 if (nel && ngr) {
03192 SUMA_SL_Err("Flow error.");
03193 SUMA_RETURN(NOPE);
03194 }
03195 /* add tracking */
03196 ++cs->TrackID;
03197 sprintf(stmp,"%d", cs->TrackID);
03198 if (nel) {
03199 NI_set_attribute (nel, "Tracking_ID", stmp);
03200 } else if (ngr) {
03201 NI_set_attribute (ngr, "Tracking_ID", stmp);
03202 }
03203 }
03204
03205 #if SUMA_SUMA_NIML_DEBUG /* writes every element to a text file for debugging ... */
03206 {
03207 NI_stream ns;
03208 /* Test writing results in asc, 1D format */
03209 if (LocalHead) fprintf(stderr," %s:-\nWriting ascii 1D ...\n"
03210 , FuncName);
03211 /* open the stream */
03212 sprintf(stmp, "file:niml_dbg_asc_TID_%d_.1D",cs->TrackID);
03213 ns = NI_stream_open( stmp , "w" ) ;
03214 if( ns == NULL ){
03215 fprintf (stderr,"Error %s:\nCan't open Test_write_asc_1D!"
03216 , FuncName);
03217 SUMA_RETURN(NOPE);
03218 }
03219
03220 if (nel) {
03221 /* write out the element */
03222 if (NI_write_element( ns , nel ,
03223 NI_TEXT_MODE | NI_HEADERSHARP_FLAG ) < 0) {
03224 fprintf (stderr,"Error %s:\nFailed in NI_write_element"
03225 , FuncName);
03226 SUMA_RETURN(NOPE);
03227 }
03228 } else if (ngr) {
03229 /* write out the element */
03230 if (NI_write_element( ns , ngr ,
03231 NI_TEXT_MODE | NI_HEADERSHARP_FLAG ) < 0) {
03232 fprintf (stderr,"Error %s:\nFailed in NI_write_element"
03233 , FuncName);
03234 SUMA_RETURN(NOPE);
03235 }
03236 }
03237
03238 /* close the stream */
03239 NI_stream_close( ns ) ;
03240 }
03241 #endif
03242
03243 if (cs->nelps > 0) { /* make sure that you are not sending elements too fast */
03244 if (!etm) etm = 100000.0; /* first pass, an eternity */
03245 else etm = SUMA_etime(&tt, 1);
03246 wtm = 1./cs->nelps - etm;
03247 if (wtm > 0) { /* wait */
03248 SUMA_LH("Sleeping to meet refresh rate...");
03249 NI_sleep((int)(wtm*1000));
03250 }
03251 }
03252
03253 /* send it to SUMA */
03254 if (LocalHead) fprintf (SUMA_STDOUT,"Sending element %d...\n", cs->TrackID);
03255 if (nel) {
03256 if (NI_write_element( SUMAg_CF->ns_v[cs->istream] , nel, cs->comm_NI_mode ) < 0) {
03257 SUMA_LH("Failed updating SUMA...");
03258 }
03259 } else if (ngr) {
03260 if (NI_write_element( SUMAg_CF->ns_v[cs->istream] , ngr, cs->comm_NI_mode ) < 0) {
03261 SUMA_LH("Failed updating SUMA...");
03262 }
03263 }
03264 if (LocalHead) {
03265 if (cs->nelps > 0) fprintf (SUMA_STDOUT," element %d sent (%f sec)\n", cs->TrackID, SUMA_etime(&tt, 1));
03266 else fprintf (SUMA_STDOUT," element %d sent \n", cs->TrackID);
03267 }
03268 if (nel) NI_free_element(nel) ; nel = NULL;
03269 if (ngr) NI_free_element(ngr) ; ngr = NULL;
03270
03271 if (cs->nelps > 0) SUMA_etime(&tt, 0); /* start the timer */
03272 ++i_in;
03273 SUMA_RETURN(YUP);
03274 }/* action == 1 */
03275
03276 if (action == 2) {
03277 if (i_in < 2) {
03278 SUMA_SL_Err("You must call SUMA_SendToSuma with action 0 and 1 before action 2.\nNo Communcation cleanup done.");
03279 cs->Send = NOPE;
03280 SUMA_RETURN(NOPE);
03281 }
03282 /* reset static variables */
03283 i_in = 0;
03284 etm = 0.0;
03285
03286 SUMA_SEND_TO_SUMA_FUNC_CLEANUP;
03287
03288 /* now close the stream*/
03289 if (cs->Send && !cs->GoneBad) {
03290 SUMA_LH("Cleanup of nel producing functions...");
03291 /* stop tracking */
03292 nel = NI_new_data_element("StopTracking", 0);
03293 NI_set_attribute(nel,"ni_stream_name", SUMAg_CF->NimlStream_v[cs->istream]);
03294
03295 if (NI_write_element( SUMAg_CF->ns_v[cs->istream] , nel, cs->comm_NI_mode ) < 0) {
03296 SUMA_SL_Err("Failed to stop tracking.\nContinuing...");
03297 }
03298 if (nel) NI_free_element(nel); nel = NULL;
03299
03300 /* tell suma you're done with that stream */
03301 nel = NI_new_data_element("CloseKillStream",0);
03302 if (!nel) {
03303 SUMA_SL_Err("Failed to create nel");
03304 exit(1);
03305 }
03306
03307 NI_set_attribute (nel, "ni_stream_name", SUMAg_CF->NimlStream_v[cs->istream]);
03308 if (NI_write_element( SUMAg_CF->ns_v[cs->istream] , nel, cs->comm_NI_mode ) < 0) {
03309 SUMA_LH("Failed updating SUMA...");
03310 }
03311 if (nel) NI_free_element(nel) ; nel = NULL;
03312
03313
03314 /* now wait till stream goes bad */
03315 good = YUP;
03316 WaitClose = 0;
03317 WaitMax = 5000;
03318 fprintf (SUMA_STDERR,"\nWaiting for SUMA to close stream .");
03319 while (good && WaitClose < WaitMax) {
03320 if (NI_stream_goodcheck(SUMAg_CF->ns_v[cs->istream], 1) <= 0) {
03321 good = NOPE;
03322 } else {
03323 SUMA_LH("Good Check OK. Sleeping for a second...");
03324 NI_sleep(1000);
03325 fprintf (SUMA_STDERR,".");
03326 WaitClose += 1000;
03327 }
03328 }
03329
03330 if (WaitClose >= WaitMax) {
03331 SUMA_SL_Warn("\nFailed to detect closed stream.\nClosing shop anyway...");
03332 }else{
03333 fprintf (SUMA_STDERR,"Done.\n");
03334 }
03335
03336 NI_stream_close(SUMAg_CF->ns_v[cs->istream]);
03337 SUMAg_CF->ns_v[cs->istream] = NULL;
03338 SUMAg_CF->ns_flags_v[cs->istream] = 0;
03339 SUMAg_CF->TrackingId_v[cs->istream] = 0;
03340 cs->Send = NOPE;
03341 cs->GoneBad = NOPE;
03342 cs->nelps = -1.0;
03343 cs->TrackID = 0;
03344 cs->istream = -1;
03345
03346
03347
03348 }
03349
03350 SUMA_RETURN(YUP);
03351 }
03352
03353 /* should not get here */
03354 SUMA_SL_Err("Flow error.\nThis should not be");
03355 SUMA_RETURN(NOPE);
03356 }
|
|
||||||||||||||||
|
A function to turn the VolPar structure to a nel, this one's a group
Definition at line 2671 of file SUMA_niml.c. References SUMA_VOLPAR::dirname, SUMA_VOLPAR::dx, SUMA_VOLPAR::dy, SUMA_VOLPAR::dz, SUMA_VOLPAR::filecode, SUMA_VOLPAR::Hand, i, SUMA_SurfaceObject::idcode_str, SUMA_VOLPAR::idcode_str, SUMA_VOLPAR::isanat, SUMA_SurfaceObject::Label, LocalHead, NI_set_attribute(), SUMA_VOLPAR::nx, SUMA_VOLPAR::ny, SUMA_VOLPAR::nz, SUMA_VOLPAR::prefix, SUMA_VOLPAR::ROTATE_CENTER_BASE, SUMA_VOLPAR::ROTATE_CENTER_OLD, SUMA_VOLPAR::ROTATE_MATVEC, SUMA_allow_nel_use(), SUMA_Boolean, SUMA_DSET_TYPE, SUMA_EMPTY_ATTR, SUMA_ENTRY, SUMA_NEW_ID, SUMA_NewNel(), SUMA_RETURN, SUMA_SL_Err, SUMA_SURFACE_VOLUME_PARENT, SUMA_VOLPAR::TAGALIGN_MATVEC, SUMA_VOLPAR::vol_idcode_date, SUMA_VOLPAR::vol_idcode_str, SUMA_VOLPAR::VOLREG_CENTER_BASE, SUMA_VOLPAR::VOLREG_CENTER_OLD, SUMA_VOLPAR::VOLREG_MATVEC, SUMA_VOLPAR::xorg, SUMA_VOLPAR::xxorient, SUMA_VOLPAR::yorg, SUMA_VOLPAR::yyorient, SUMA_VOLPAR::zorg, and SUMA_VOLPAR::zzorient. Referenced by SUMA_SO2nimlSO().
02672 {
02673 static char FuncName[]={"SUMA_SOVolPar2VolPar_nel"};
02674 NI_element *nel=NULL;
02675 int ibuf3[3], i;
02676 float fbuf3[3];
02677 char stmp[500];
02678 SUMA_Boolean LocalHead = NOPE;
02679
02680 SUMA_ENTRY;
02681
02682 if (dtype != SUMA_SURFACE_VOLUME_PARENT) {
02683 SUMA_SL_Err("Bad dtype for this function!");
02684 SUMA_RETURN(NULL);
02685 }
02686
02687 if (!VolPar) {
02688 SUMA_SL_Err("NULL VolPar");
02689 SUMA_RETURN(NULL);
02690 }
02691
02692
02693 if (!VolPar->idcode_str) { SUMA_NEW_ID(VolPar->idcode_str, NULL); }
02694
02695 /* Now create that data element and write it out */
02696 SUMA_allow_nel_use(1);
02697 nel = SUMA_NewNel ( dtype, /* one of SUMA_DSET_TYPE */
02698 SO->idcode_str, /* idcode of Domain Parent Surface*/
02699 NULL, /* idcode of geometry parent, not useful here*/
02700 0,
02701 NULL,
02702 VolPar->idcode_str);
02703 if (!nel) {
02704 fprintf (stderr,"Error %s:\nFailed in SUMA_NewNel", FuncName);
02705 SUMA_RETURN(NULL);
02706 }
02707
02708 if (SO->Label) {
02709 sprintf(stmp,"Volume parent of %s", SO->Label);
02710 NI_set_attribute(nel, "Object_Label", stmp);
02711 } else {
02712 NI_set_attribute(nel, "Object_Label", SUMA_EMPTY_ATTR);
02713 }
02714
02715 sprintf(stmp,"%d", VolPar->isanat);
02716 NI_set_attribute(nel, "isanat", stmp);
02717
02718 sprintf(stmp,"%d", VolPar->Hand);
02719 NI_set_attribute(nel, "axis_hand", stmp);
02720
02721 if (VolPar->prefix) NI_set_attribute(nel, "prefix", VolPar->prefix);
02722 else NI_set_attribute(nel, "prefix", SUMA_EMPTY_ATTR);
02723
02724 if (VolPar->filecode) NI_set_attribute(nel, "filecode", VolPar->filecode);
02725 else NI_set_attribute(nel, "filecode", SUMA_EMPTY_ATTR);
02726
02727 if (VolPar->dirname) NI_set_attribute(nel, "dirname", VolPar->dirname);
02728 else NI_set_attribute(nel, "dirname", SUMA_EMPTY_ATTR);
02729
02730 if (VolPar->vol_idcode_str) NI_set_attribute(nel, "vol_idcode_str", VolPar->vol_idcode_str);
02731 else NI_set_attribute(nel, "vol_idcode_str", SUMA_EMPTY_ATTR);
02732
02733 if (VolPar->vol_idcode_date) NI_set_attribute(nel, "vol_idcode_date", VolPar->vol_idcode_date);
02734 else NI_set_attribute(nel, "vol_idcode_date", SUMA_EMPTY_ATTR);
02735
02736 sprintf(stmp, "%d %d %d", VolPar->nx, VolPar->ny, VolPar->nz);
02737 NI_set_attribute(nel, "nxyz", stmp);
02738
02739 sprintf(stmp, "%d %d %d", VolPar->xxorient, VolPar->yyorient, VolPar->zzorient);
02740 NI_set_attribute(nel, "xyzorient", stmp);
02741
02742 sprintf(stmp, "%f %f %f", VolPar->dx, VolPar->dy, VolPar->dz);
02743 NI_set_attribute(nel, "dxyz", stmp);
02744
02745 sprintf(stmp, "%f %f %f", VolPar->xorg, VolPar->yorg, VolPar->zorg);
02746 NI_set_attribute(nel, "xyzorg", stmp);
02747
02748 if (VolPar->VOLREG_CENTER_OLD) {
02749 stmp[0] = '\0';
02750 for (i=0; i<3; ++i) sprintf(stmp,"%s %f", stmp, VolPar->VOLREG_CENTER_OLD[i]);
02751 NI_set_attribute(nel, "VOLREG_CENTER_OLD", stmp);
02752 }
02753 if (VolPar->VOLREG_CENTER_BASE) {
02754 stmp[0] = '\0';
02755 for (i=0; i<3; ++i) sprintf(stmp,"%s %f", stmp, VolPar->VOLREG_CENTER_BASE[i]);
02756 NI_set_attribute(nel, "VOLREG_CENTER_BASE", stmp);
02757 }
02758
02759 if (VolPar->VOLREG_MATVEC) {
02760 stmp[0] = '\0';
02761 for (i=0; i<12; ++i) sprintf(stmp,"%s %f", stmp, VolPar->VOLREG_MATVEC[i]);
02762 NI_set_attribute(nel, "VOLREG_MATVEC", stmp);
02763 }
02764
02765 if (VolPar->TAGALIGN_MATVEC) {
02766 stmp[0] = '\0';
02767 for (i=0; i<12; ++i) sprintf(stmp,"%s %f", stmp, VolPar->TAGALIGN_MATVEC[i]);
02768 NI_set_attribute(nel, "TAGALIGN_MATVEC", stmp);
02769 }
02770
02771 if (VolPar->ROTATE_MATVEC) {
02772 stmp[0] = '\0';
02773 for (i=0; i<12; ++i) sprintf(stmp,"%s %f", stmp, VolPar->ROTATE_MATVEC[i]);
02774 NI_set_attribute(nel, "ROTATE_MATVEC", stmp);
02775 }
02776
02777 if (VolPar->ROTATE_CENTER_OLD) {
02778 stmp[0] = '\0';
02779 for (i=0; i<3; ++i) sprintf(stmp,"%s %f", stmp, VolPar->ROTATE_CENTER_OLD[i]);
02780 NI_set_attribute(nel, "ROTATE_CENTER_OLD", stmp);
02781 }
02782 if (VolPar->ROTATE_CENTER_BASE) {
02783 stmp[0] = '\0';
02784 for (i=0; i<3; ++i) sprintf(stmp,"%s %f", stmp, VolPar->ROTATE_CENTER_BASE[i]);
02785 NI_set_attribute(nel, "ROTATE_CENTER_BASE", stmp);
02786 }
02787 SUMA_RETURN(nel);
02788 }
|
|
||||||||||||
|
the inverse of SUMA_SOVolPar2VolPar_nel
Definition at line 2553 of file SUMA_niml.c. References SUMA_VOLPAR::dirname, SUMA_VOLPAR::dx, SUMA_VOLPAR::dy, SUMA_VOLPAR::dz, SUMA_VOLPAR::filecode, SUMA_VOLPAR::Hand, SUMA_SurfaceObject::idcode_str, SUMA_VOLPAR::idcode_str, SUMA_VOLPAR::isanat, LocalHead, NI_element::name, NI_get_attribute(), SUMA_VOLPAR::nx, SUMA_VOLPAR::ny, SUMA_VOLPAR::nz, SUMA_VOLPAR::prefix, SUMA_VOLPAR::ROTATE_CENTER_BASE, SUMA_VOLPAR::ROTATE_CENTER_OLD, SUMA_VOLPAR::ROTATE_MATVEC, SUMA_Alloc_VolPar(), SUMA_Boolean, SUMA_copy_string(), SUMA_COPY_VEC, SUMA_Dset_Type(), SUMA_DSET_TYPE, SUMA_ENTRY, SUMA_IS_EMPTY_STR_ATTR, SUMA_malloc, SUMA_RETURN, SUMA_SL_Err, SUMA_StringToNum(), SUMA_SURFACE_VOLUME_PARENT, SUMA_VOLPAR::TAGALIGN_MATVEC, SUMA_VOLPAR::vol_idcode_date, SUMA_VOLPAR::vol_idcode_str, SUMA_SurfaceObject::VolPar, SUMA_VOLPAR::VOLREG_CENTER_BASE, SUMA_VOLPAR::VOLREG_CENTER_OLD, SUMA_VOLPAR::VOLREG_MATVEC, SUMA_VOLPAR::xorg, SUMA_VOLPAR::xxorient, SUMA_VOLPAR::yorg, SUMA_VOLPAR::yyorient, SUMA_VOLPAR::zorg, and SUMA_VOLPAR::zzorient. Referenced by SUMA_nimlSO2SO().
02554 {
02555 static char FuncName[]={"SUMA_VolPar_nel2SOVolPar"};
02556 char *tmp;
02557 float fv15[15];
02558 SUMA_DSET_TYPE dtype;
02559 SUMA_Boolean LocalHead = NOPE;
02560
02561 SUMA_ENTRY;
02562
02563 dtype = SUMA_Dset_Type(nel->name);
02564 if (dtype != SUMA_SURFACE_VOLUME_PARENT) {
02565 SUMA_SL_Err("Bad dtype for this function!");
02566 SUMA_RETURN(NOPE);
02567 }
02568
02569 if (SO->VolPar) { SUMA_SL_Err("SO->VolPar must be NULL here"); SUMA_RETURN(NOPE); }
02570 SO->VolPar = SUMA_Alloc_VolPar();
02571
02572 tmp = NI_get_attribute(nel, "Object_ID");
02573 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->VolPar->idcode_str = SUMA_copy_string(tmp);
02574
02575 tmp = NI_get_attribute(nel, "Parent_ID");
02576 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02577 if (strcmp(tmp, SO->idcode_str)) {
02578 SUMA_SL_Err("idcode of parent mismatch"); SUMA_RETURN(NOPE);
02579 }
02580 }
02581
02582 tmp = NI_get_attribute(nel, "isanat");
02583 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->VolPar->isanat = atoi(tmp);
02584
02585 tmp = NI_get_attribute(nel, "axis_hand");
02586 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->VolPar->Hand = atoi(tmp);
02587
02588 tmp = NI_get_attribute(nel, "prefix");
02589 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->VolPar->prefix = SUMA_copy_string(tmp);
02590
02591 tmp = NI_get_attribute(nel, "filecode");
02592 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->VolPar->filecode = SUMA_copy_string(tmp);
02593
02594 tmp = NI_get_attribute(nel, "dirname");
02595 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->VolPar->dirname = SUMA_copy_string(tmp);
02596
02597 tmp = NI_get_attribute(nel, "vol_idcode_str");
02598 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->VolPar->vol_idcode_str = SUMA_copy_string(tmp);
02599
02600 tmp = NI_get_attribute(nel, "vol_idcode_date");
02601 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->VolPar->vol_idcode_date = SUMA_copy_string(tmp);
02602
02603 tmp = NI_get_attribute(nel, "nxyz");
02604 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) { SUMA_StringToNum(tmp, fv15, 3); SO->VolPar->nx = (int)fv15[0]; SO->VolPar->ny = (int)fv15[1]; SO->VolPar->nz = (int)fv15[2]; }
02605
02606 tmp = NI_get_attribute(nel, "xyzorient");
02607 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) { SUMA_StringToNum(tmp, fv15, 3); SO->VolPar->xxorient = (int)fv15[0]; SO->VolPar->yyorient = (int)fv15[1]; SO->VolPar->zzorient = (int)fv15[2]; }
02608
02609 tmp = NI_get_attribute(nel, "dxyz");
02610 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) { SUMA_StringToNum(tmp, fv15, 3); SO->VolPar->dx = fv15[0]; SO->VolPar->dy = fv15[1]; SO->VolPar->dz = fv15[2]; }
02611
02612 tmp = NI_get_attribute(nel, "xyzorg");
02613 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) { SUMA_StringToNum(tmp, fv15, 3); SO->VolPar->xorg = fv15[0]; SO->VolPar->yorg = fv15[1]; SO->VolPar->zorg = fv15[2]; }
02614
02615 tmp = NI_get_attribute(nel, "VOLREG_CENTER_OLD");
02616 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02617 SUMA_StringToNum(tmp, fv15, 3);
02618 SO->VolPar->VOLREG_CENTER_OLD = (float*)SUMA_malloc(sizeof(float)*3);
02619 SUMA_COPY_VEC(fv15, SO->VolPar->VOLREG_CENTER_OLD, 2, float, float);
02620 }
02621
02622 tmp = NI_get_attribute(nel, "VOLREG_CENTER_BASE");
02623 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02624 SUMA_StringToNum(tmp, fv15, 3);
02625 SO->VolPar->VOLREG_CENTER_BASE = (float*)SUMA_malloc(sizeof(float)*3);
02626 SUMA_COPY_VEC(fv15, SO->VolPar->VOLREG_CENTER_BASE, 2, float, float);
02627 }
02628
02629 tmp = NI_get_attribute(nel, "VOLREG_MATVEC");
02630 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02631 SUMA_StringToNum(tmp, fv15, 12);
02632 SO->VolPar->VOLREG_MATVEC = (float*)SUMA_malloc(sizeof(float)*12);
02633 SUMA_COPY_VEC(fv15, SO->VolPar->VOLREG_MATVEC, 2, float, float);
02634 }
02635
02636 tmp = NI_get_attribute(nel, "TAGALIGN_MATVEC");
02637 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02638 SUMA_StringToNum(tmp, fv15, 12);
02639 SO->VolPar->TAGALIGN_MATVEC = (float*)SUMA_malloc(sizeof(float)*12);
02640 SUMA_COPY_VEC(fv15, SO->VolPar->TAGALIGN_MATVEC, 2, float, float);
02641 }
02642
02643 tmp = NI_get_attribute(nel, "ROTATE_MATVEC");
02644 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02645 SUMA_StringToNum(tmp, fv15, 12);
02646 SO->VolPar->ROTATE_MATVEC = (float*)SUMA_malloc(sizeof(float)*12);
02647 SUMA_COPY_VEC(fv15, SO->VolPar->ROTATE_MATVEC, 2, float, float);
02648 }
02649
02650 tmp = NI_get_attribute(nel, "ROTATE_CENTER_OLD");
02651 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02652 SUMA_StringToNum(tmp, fv15, 3);
02653 SO->VolPar->ROTATE_CENTER_OLD = (float*)SUMA_malloc(sizeof(float)*3);
02654 SUMA_COPY_VEC(fv15, SO->VolPar->ROTATE_CENTER_OLD, 2, float, float);
02655 }
02656
02657 tmp = NI_get_attribute(nel, "ROTATE_CENTER_BASE");
02658 if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
02659 SUMA_StringToNum(tmp, fv15, 3);
02660 SO->VolPar->ROTATE_CENTER_BASE = (float*)SUMA_malloc(sizeof(float)*3);
02661 SUMA_COPY_VEC(fv15, SO->VolPar->ROTATE_CENTER_BASE, 2, float, float);
02662 }
02663
02664 SUMA_RETURN(YUP);
02665 }
|
|
||||||||||||
|
Definition at line 217 of file SUMA_niml.c. References i, LocalHead, SUMA_CommonFields::NimlStream_v, SUMA_Boolean, SUMA_ENTRY, SUMA_MAX_STREAMS, and SUMA_RETURN. Referenced by SUMA_niml_hangup(), and SUMA_process_NIML_data().
00218 {
00219 static char FuncName[]={"SUMA_which_stream_index"};
00220 int i;
00221 SUMA_Boolean LocalHead = NOPE;
00222
00223 SUMA_ENTRY;
00224
00225 for (i=0; i < SUMA_MAX_STREAMS; ++i) {
00226 if (strcmp(nel_stream_name, cf->NimlStream_v[i]) == 0) SUMA_RETURN(i);
00227 }
00228
00229 SUMA_RETURN(-1);
00230 }
|
|
|
Definition at line 1630 of file SUMA_niml.c. References datap, num_workp, SUMA_ENTRY, SUMA_free, SUMA_RETURN, and workp. Referenced by SUMA_register_workproc().
01631 {
01632 static char FuncName[]={"SUMA_workprocess"};
01633 int ii , ngood ;
01634 Boolean done ;
01635
01636 if (SUMA_WORKPROC_IO_NOTIFY) {SUMA_ENTRY;}
01637
01638 #ifdef WPDEBUG
01639 { static int ncall=0 ;
01640 if( (ncall++) % 1000 == 0 )
01641 fprintf(stderr,"SUMA_workprocess: entry %d\n",ncall) ; }
01642 #endif
01643
01644 if( num_workp == 0 ) {
01645 if (SUMA_WORKPROC_IO_NOTIFY) {
01646 SUMA_RETURN(True) ;
01647 }
01648 else return(True);
01649 }
01650
01651 for( ii=0,ngood=0 ; ii < num_workp ; ii++ ){
01652 if( workp[ii] != NULL ){
01653 done = workp[ii]( datap[ii] ) ;
01654 if( done == True ) workp[ii] = NULL ;
01655 else ngood++ ;
01656 }
01657 }
01658
01659 if( ngood == 0 ){
01660 #ifdef WPDEBUG
01661 fprintf(stderr,"Found no workprocs left\n") ;
01662 #endif
01663 SUMA_free(workp) ; workp = NULL ; SUMA_free(datap) ; datap = NULL ;
01664 num_workp = 0 ;
01665 if (SUMA_WORKPROC_IO_NOTIFY) {
01666 SUMA_RETURN(True) ;
01667 }
01668 else return (True);
01669 }
01670
01671 if (SUMA_WORKPROC_IO_NOTIFY) {
01672 SUMA_RETURN(False) ;
01673 }
01674 else return(False);
01675 }
|
|
||||||||||||||||||||
|
writes a vector of SUMA_DRAWN_ROI * to disk in NIML format
Definition at line 6061 of file SUMA_Surface_IO.c. References SUMA_NIML_DRAWN_ROI::ColPlaneName, SUMA_NIML_DRAWN_ROI::EdgeColor, SUMA_NIML_DRAWN_ROI::EdgeThickness, SUMA_NIML_DRAWN_ROI::FillColor, i, SUMA_NIML_DRAWN_ROI::idcode_str, SUMA_NIML_DRAWN_ROI::iLabel, SUMA_NIML_DRAWN_ROI::Label, LocalHead, SUMA_NIML_DRAWN_ROI::N_ROI_datum, NI_add_column(), NI_BINARY_MODE, NI_free_element(), NI_HEADERSHARP_FLAG, NI_new_data_element(), NI_set_attribute(), NI_stream_close(), NI_stream_open(), NI_TEXT_MODE, NI_write_element(), SUMA_CommonFields::nimlROI_Datum_type, SUMA_NIML_DRAWN_ROI::Parent_idcode_str, SUMA_NIML_DRAWN_ROI::ROI_datum, SUMA_ASCII, SUMA_BINARY, SUMA_Boolean, SUMA_DrawnROI_to_NIMLDrawnROI(), SUMA_Dset_Type_Name(), SUMA_ENTRY, SUMA_Extension(), SUMA_free, SUMA_Free_NIMLDrawROI(), SUMA_LH, SUMA_MAX_NAME_LENGTH, SUMA_nel_stdout(), SUMA_NODE_ROI, SUMA_RETURN, SUMA_SL_Err, SUMA_SLP_Err, and SUMA_NIML_DRAWN_ROI::Type. Referenced by SUMA_SaveDrawnROINIML().
06062 {
06063 static char FuncName[]={"SUMA_Write_DrawnROI_NIML"};
06064 char stmp[SUMA_MAX_NAME_LENGTH+20];
06065 char *newname=NULL;
06066 int i;
06067 NI_element *nel ;
06068 NI_stream ns ;
06069 SUMA_NIML_DRAWN_ROI *niml_ROI = NULL;
06070 SUMA_DRAWN_ROI *ROI = NULL;
06071 SUMA_Boolean WriteBin = NOPE, LocalHead = NOPE;
06072
06073 SUMA_ENTRY;
06074
06075 if (Format == SUMA_ASCII) WriteBin = NOPE;
06076 else if (Format == SUMA_BINARY) WriteBin = YUP;
06077 else {
06078 SUMA_SL_Err("Wrong format");
06079 SUMA_RETURN(NOPE);
06080 }
06081
06082 if (SUMAg_CF->nimlROI_Datum_type < 0) {
06083 SUMA_SL_Err("Bad niml type code");
06084 SUMA_RETURN(NOPE);
06085 }
06086 if (LocalHead) fprintf(SUMA_STDERR, "%s: roi_type code = %d\n", FuncName, SUMAg_CF->nimlROI_Datum_type) ;
06087
06088 /* add a .niml.roi extension */
06089 if (strlen(filename) >= SUMA_MAX_NAME_LENGTH-20) {
06090 SUMA_SLP_Err("Give me a break, what kind of a filename is this ?");
06091 SUMA_RETURN(NOPE);
06092 }
06093
06094 sprintf(stmp,"file:%s", filename);
06095 newname = SUMA_Extension(stmp, ".niml.roi", NOPE);
06096 SUMA_LH(newname);
06097 ns = NI_stream_open( newname , "w" ) ;
06098
06099 /* write the various ROIs */
06100 for (i=0; i < N_ROI; ++i) {
06101 ROI = ROIv[i];
06102 if (!ROI) {
06103 SUMA_SL_Err("NULL ROI!");
06104 NI_stream_close( ns ) ;
06105 SUMA_RETURN(NOPE);
06106 }
06107 /* Transform the ROI to niml friendly structure */
06108 if (!(niml_ROI = SUMA_DrawnROI_to_NIMLDrawnROI (ROI))) {
06109 SUMA_SL_Err("NULL niml_ROI!");
06110 NI_stream_close( ns ) ;
06111 SUMA_RETURN(NOPE);
06112 }
06113
06114 /* Now create a ni element */
06115 if (LocalHead) fprintf(SUMA_STDERR,"%s: Creating new element of %d segments\n", FuncName, niml_ROI->N_ROI_datum);
06116 nel = NI_new_data_element(SUMA_Dset_Type_Name(SUMA_NODE_ROI), niml_ROI->N_ROI_datum);
06117
06118 SUMA_LH("Adding column...");
06119 NI_add_column( nel , SUMAg_CF->nimlROI_Datum_type, niml_ROI->ROI_datum );
06120
06121 SUMA_LH("Setting attributes...");
06122 NI_set_attribute (nel, "Object_ID", niml_ROI->idcode_str);
06123 NI_set_attribute (nel, "Parent_ID", niml_ROI->Parent_idcode_str);
06124 NI_set_attribute (nel, "Label", niml_ROI->Label);
06125 sprintf(stmp,"%d", niml_ROI->iLabel);
06126 NI_set_attribute (nel, "iLabel", stmp);
06127 sprintf(stmp,"%d", niml_ROI->Type);
06128 NI_set_attribute (nel, "Type", stmp);
06129 NI_set_attribute (nel, "ColPlaneName", niml_ROI->ColPlaneName);
06130 sprintf(stmp,"%f %f %f", niml_ROI->FillColor[0], niml_ROI->FillColor[1],
06131 niml_ROI->FillColor[2]);
06132 NI_set_attribute (nel, "FillColor",stmp);
06133 sprintf(stmp,"%f %f %f", niml_ROI->EdgeColor[0], niml_ROI->EdgeColor[1],
06134 niml_ROI->EdgeColor[2]);
06135 NI_set_attribute (nel, "EdgeColor",stmp);
06136 sprintf(stmp,"%d", niml_ROI->EdgeThickness);
06137 NI_set_attribute (nel, "EdgeThickness", stmp);
06138
06139 if (LocalHead) SUMA_nel_stdout (nel);
06140
06141 if (!WriteBin) {
06142 SUMA_LH ("Writing element, Text mode.");
06143 if (NI_write_element( ns , nel , NI_TEXT_MODE | NI_HEADERSHARP_FLAG ) < 0) {
06144 SUMA_SL_Err("Badness, failed to write nel");
06145 NI_stream_close( ns ) ;
06146 SUMA_RETURN(NOPE);
06147 }
06148 } else {
06149 SUMA_LH ("Writing element, Binary mode.");
06150 if (NI_write_element( ns , nel , NI_BINARY_MODE) < 0) {
06151 SUMA_SL_Err("Badness, failed to write nel");
06152 NI_stream_close( ns ) ;
06153 SUMA_RETURN(NOPE);
06154 }
06155 }
06156
06157 /* free nel */
06158 NI_free_element(nel) ; nel = NULL;
06159
06160 /* free the niml_ROI structure */
06161 niml_ROI = SUMA_Free_NIMLDrawROI (niml_ROI); niml_ROI = NULL;
06162
06163 }
06164
06165 NI_stream_close( ns ) ;
06166
06167 if (newname) SUMA_free(newname);
06168
06169 SUMA_RETURN(YUP);
06170 }
|