Skip to content

AFNI/NIfTI Server

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

Doxygen Source Code Documentation


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

SUMA_niml.c File Reference

#include "SUMA_suma.h"

Go to the source code of this file.


Data Structures

struct  ROI
struct  ROI_seg

Defines

#define SUMA_NODEVAL2IRGBA_CLEANUP
#define SUMA_SEND_TO_SUMA_FUNC_CLEANUP

Functions

Boolean SUMA_niml_workproc (XtPointer thereiselvis)
int SUMA_which_stream_index (SUMA_CommonFields *cf, char *nel_stream_name)
SUMA_Boolean SUMA_niml_hangup (SUMA_CommonFields *cf, char *nel_stream_name, SUMA_Boolean fromSUMA, SUMA_Boolean killit)
SUMA_Boolean SUMA_niml_call (SUMA_CommonFields *cf, int si, SUMA_Boolean fromSUMA)
 Initiates a call on stream cf->ns_v[si].

SUMA_Boolean SUMA_process_NIML_data (void *nini, SUMA_SurfaceViewer *sv)
NI_elementSUMA_makeNI_SurfIXYZ (SUMA_SurfaceObject *SO)
NI_elementSUMA_makeNI_SurfINORM (SUMA_SurfaceObject *SO)
NI_elementSUMA_makeNI_SurfIJK (SUMA_SurfaceObject *SO)
SUMA_Boolean SUMA_nel_stdout (NI_element *nel)
NI_elementSUMA_makeNI_CrossHair (SUMA_SurfaceViewer *sv)
SUMA_Boolean SUMA_CanTalkToAfni (SUMA_DO *dov, int N_dov)
void SUMA_register_workproc (XtWorkProc func, XtPointer data)
void SUMA_remove_workproc2 (XtWorkProc func, XtPointer data)
void SUMA_remove_workproc (XtWorkProc func)
Boolean SUMA_workprocess (XtPointer fred)
SUMA_NIML_DRAWN_ROISUMA_DrawnROI_to_NIMLDrawnROI (SUMA_DRAWN_ROI *ROI)
 A function to take a SUMA_DRAWN_ROI struct and return an equivalent SUMA_NIML_DRAWN_ROI struct.

SUMA_DRAWN_ROISUMA_NIMLDrawnROI_to_DrawnROI (SUMA_NIML_DRAWN_ROI *nimlROI, SUMA_Boolean ForDisplay)
 transfroms a SUMA_NIML_DRAWN_ROI * to a SUMA_DRAWN_ROI *

SUMA_NIML_DRAWN_ROISUMA_Free_NIMLDrawROI (SUMA_NIML_DRAWN_ROI *nimlROI)
 frees a nimlROI structure. These structures are created by the likes of SUMA_DrawnROI_to_NIMLDrawnROI

void SUMA_FakeIt (int Solo)
SUMA_COMM_STRUCTSUMA_Create_CommSrtuct (void)
 , creates a srtucture for holding communication variables

SUMA_COMM_STRUCTSUMA_Free_CommSrtuct (SUMA_COMM_STRUCT *cs)
SUMA_Boolean SUMA_Assign_HostName (SUMA_CommonFields *cf, char *HostName, int istream)
SUMA_Boolean SUMA_SendSumaNewSurface (SUMA_SurfaceObject *SO, SUMA_COMM_STRUCT *cs)
 sends a full surface to SUMA

SUMA_Boolean SUMA_Mesh_IJK_nel2Mesh_IJK (SUMA_SurfaceObject *SO, NI_element *nel)
NI_elementSUMA_Mesh_IJK2Mesh_IJK_nel (SUMA_SurfaceObject *SO, int *val, SUMA_Boolean cleanup, SUMA_DSET_TYPE dtype)
SUMA_Boolean SUMA_NodeXYZ_nel2NodeXYZ (SUMA_SurfaceObject *SO, NI_element *nel)
NI_elementSUMA_NodeXYZ2NodeXYZ_nel (SUMA_SurfaceObject *SO, float *val, SUMA_Boolean cleanup, SUMA_DSET_TYPE dtype)
SUMA_Boolean SUMA_VolPar_nel2SOVolPar (SUMA_SurfaceObject *SO, NI_element *nel)
 the inverse of SUMA_SOVolPar2VolPar_nel

NI_elementSUMA_SOVolPar2VolPar_nel (SUMA_SurfaceObject *SO, SUMA_VOLPAR *VolPar, SUMA_DSET_TYPE dtype)
NI_elementSUMA_NodeVal2irgba_nel (SUMA_SurfaceObject *SO, float *val, char *instanceID, int cleanup)
SUMA_Boolean SUMA_SendToSuma (SUMA_SurfaceObject *SO, SUMA_COMM_STRUCT *cs, void *data, SUMA_DSET_TYPE dtype, int action)
 Function to handle send data elements to AFNI.

SUMA_Boolean SUMA_SendToAfni (SUMA_COMM_STRUCT *cs, void *data, int action)
 Function to handle send data elements to AFNI.

SUMA_Boolean SUMA_SendDset_Afni (NI_stream ns, THD_3dim_dataset *dset, int all)

Variables

int SUMAg_N_DOv
SUMA_DOSUMAg_DOv
SUMA_CommonFieldsSUMAg_CF
SUMA_SurfaceViewerSUMAg_SVv
int SUMAg_N_SVv
int started = 0
int num_workp = 0
XtWorkProc * workp = NULL
XtPointer * datap = NULL
XtWorkProcId wpid

Define Documentation

#define SUMA_NODEVAL2IRGBA_CLEANUP
 

Value:

{ \
   if (node) SUMA_free(node); node = NULL;   \
   if (CM) SUMA_Free_ColorMap (CM); CM = NULL;  \
   if (OptScl) SUMA_free(OptScl); OptScl = NULL;   \
   if (SV) SUMA_Free_ColorScaledVect (SV); SV = NULL; \
   if (rgba) SUMA_free(rgba); rgba = NULL;   \
}
Macro specific for SUMA_NodeVal2irgba_nel

Definition at line 2791 of file SUMA_niml.c.

Referenced by SUMA_NodeVal2irgba_nel().

#define SUMA_SEND_TO_SUMA_FUNC_CLEANUP
 

Value:

{   \
        \
      SUMA_LH("Cleanup for SUMA_NodeVal2irgba_nel...");  \
      SUMA_NodeVal2irgba_nel (NULL, NULL, NULL, 1);   \
      SUMA_LH("Cleanup for SUMA_NodeXYZ2NodeXYZ_nel...");   \
      SUMA_NodeXYZ2NodeXYZ_nel (NULL, NULL, 1, SUMA_NODE_XYZ); \
      SUMA_LH("Cleanup for SUMA_Mesh_IJK2Mesh_IJK_nel..."); \
      SUMA_Mesh_IJK2Mesh_IJK_nel (NULL, NULL, 1, SUMA_NEW_MESH_IJK); \
}

Definition at line 3003 of file SUMA_niml.c.

Referenced by SUMA_SendToSuma().


Function Documentation

SUMA_Boolean SUMA_Assign_HostName SUMA_CommonFields   cf,
char *    HostName,
int    istream
 

assign new afni host name SUMA_Assign_HostName (cf, HostName, istream)

Assigns a new HostName for niml communication on a particular stream

Parameters:
cf  (SUMA_CommonFields *) pointer to Common Fields structure, field AfniHostName will be modified here
HostName  (char *) hostname in IP number form, or name form afni.nimh.nih.gov or afni (if in /etc/hosts file) NULL to set cf->HostName_v[istream] to localhost if i = SUMA_AFNI_STREAM_INDEX 127.0.0.1 otherwise. That's done to keep Shared Memory communication betwen AFNI and SUMA only.
istream  (int) if -1 then all streams are set to HostName otherwise, only HostName_v[istream] is set \ret ans (SUMA_Boolean) YUP/NOPE

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 }

SUMA_Boolean SUMA_CanTalkToAfni SUMA_DO   dov,
int    N_dov
 

ans = SUMA_CanTalkToAfni (dov, N_dov); determines if any of the Surface Viewers is allowed to talk to afni

Parameters:
dov  (SUMA_DO *) the Displayable Objects vector (ususally SUMAg_DOv)
N_dov  (int) the number of elements in dov (usually SUMAg_N_DOv) \ret ans (SUMA_Boolean) NOPE if none of the SOs shown in the viewer has both LocalDomainParentID != NULL && VolPar != NULL
This function is much different from the one prior to Tue Nov 19 11:44:24 EST 2002

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 }

SUMA_COMM_STRUCT* SUMA_Create_CommSrtuct void   
 

, creates a srtucture for holding communication variables

  • free returned structure with SUMA_free

Definition at line 2062 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, SUMA_COMM_STRUCT::comm_NI_mode, SUMA_COMM_STRUCT::ElInd, SUMA_COMM_STRUCT::Feed2Afni, SUMA_COMM_STRUCT::GoneBad, i, SUMA_COMM_STRUCT::istream, SUMA_COMM_STRUCT::kth, SUMA_COMM_STRUCT::nelps, NI_BINARY_MODE, SUMA_COMM_STRUCT::rps, SUMA_COMM_STRUCT::Send, SUMA_ENTRY, SUMA_COMM_STRUCT::suma_host_name, SUMA_malloc, SUMA_N_DSET_TYPES, SUMA_RETURN, SUMA_SL_Crit, SUMA_COMM_STRUCT::talk_suma, and SUMA_COMM_STRUCT::TrackID.

Referenced by SUMA_Parse_IO_Args().

02063 {
02064    static char FuncName[]={"SUMA_Create_CommSrtuct"};
02065    SUMA_COMM_STRUCT *cs=NULL;
02066    int i;
02067    
02068    SUMA_ENTRY;
02069    
02070    cs = (SUMA_COMM_STRUCT *)SUMA_malloc(sizeof(SUMA_COMM_STRUCT));
02071    if (!cs) {
02072       SUMA_SL_Crit("Failed to allocate");
02073       SUMA_RETURN(NULL);
02074    }
02075    
02076    cs->talk_suma = 0;
02077    cs->comm_NI_mode = NI_BINARY_MODE;
02078    cs->rps = -1.0;
02079    cs->Send = NOPE;
02080    cs->afni_Send = NOPE;
02081    cs->GoneBad = NOPE;
02082    cs->afni_GoneBad = NOPE;
02083    cs->nelps = -1.0;
02084    cs->TrackID = 0;
02085    cs->istream = -1; /* the index of the stream in SUMAg_CF->ns_v */
02086    cs->afni_istream = -1;
02087    cs->suma_host_name = NULL;
02088    cs->afni_host_name = NULL;
02089    cs->kth = 1;
02090    cs->Feed2Afni = 0;
02091    for (i=0; i<SUMA_N_DSET_TYPES; ++i) cs->ElInd[i] = 0;
02092    SUMA_RETURN(cs);
02093 }

SUMA_NIML_DRAWN_ROI* SUMA_DrawnROI_to_NIMLDrawnROI SUMA_DRAWN_ROI   ROI
 

A function to take a SUMA_DRAWN_ROI struct and return an equivalent SUMA_NIML_DRAWN_ROI struct.

See also:
SUMA_Free_NIMLDrawROI

Definition at line 1688 of file SUMA_niml.c.

References SUMA_ROI_DATUM::action, SUMA_NIML_DRAWN_ROI::ColPlaneName, SUMA_DRAWN_ROI::ColPlaneName, DListElmt_::data, dlist_head, dlist_size, dlist_tail, 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_ROI_DATUM::N_n, SUMA_NIML_DRAWN_ROI::N_ROI_datum, DListElmt_::next, SUMA_ROI_DATUM::nPath, SUMA_NIML_DRAWN_ROI::Parent_idcode_str, SUMA_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_NIML_DRAWN_ROI::Type, SUMA_DRAWN_ROI::Type, and SUMA_ROI_DATUM::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 }

void SUMA_FakeIt int    Solo
 

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, NI_element::name, ROI::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 }

SUMA_COMM_STRUCT* SUMA_Free_CommSrtuct SUMA_COMM_STRUCT   cs
 

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 }

SUMA_NIML_DRAWN_ROI* SUMA_Free_NIMLDrawROI SUMA_NIML_DRAWN_ROI   nimlROI
 

frees a nimlROI structure. These structures are created by the likes of SUMA_DrawnROI_to_NIMLDrawnROI

See also:
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 }

NI_element* SUMA_makeNI_CrossHair SUMA_SurfaceViewer   sv
 

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 }

NI_element* SUMA_makeNI_SurfIJK SUMA_SurfaceObject   SO
 

Make a NIML data element for a NI surface element IJK

Parameters:
SO  (SUMA_SurfaceObject *) surface object to turn to NI \ret NULL if you input stupid values, NI if you input smart values --------------------------------------------------------------------

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 }

NI_element* SUMA_makeNI_SurfINORM SUMA_SurfaceObject   SO
 

Make a NIML data element for a NI surface element i nx ny nz onde index followed by node normal

Parameters:
SO  (SUMA_SurfaceObject *) surface object to turn to NI \ret NULL if you input stupid values, NI if you input smart values --------------------------------------------------------------------

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 }

NI_element* SUMA_makeNI_SurfIXYZ SUMA_SurfaceObject   SO
 

Make a NIML data element for a NI surface element IXYZ

Parameters:
SO  (SUMA_SurfaceObject *) surface object to turn to NI \ret NULL if you input stupid values, NI if you input smart values --------------------------------------------------------------------

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 }

NI_element* SUMA_Mesh_IJK2Mesh_IJK_nel SUMA_SurfaceObject   SO,
int *    val,
SUMA_Boolean    cleanup,
SUMA_DSET_TYPE    dtype
 

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

See also:
SUMA_Mesh_IJK_nel2Mesh_IJK

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 }    

SUMA_Boolean SUMA_Mesh_IJK_nel2Mesh_IJK SUMA_SurfaceObject   SO,
NI_element   nel
 

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 }

SUMA_Boolean SUMA_nel_stdout NI_element   nel
 

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 }

SUMA_Boolean SUMA_niml_call SUMA_CommonFields   cf,
int    si,
SUMA_Boolean    fromSUMA
 

Initiates a call on stream cf->ns_v[si].

Parameters:
cf  (SUMA_CommonFields *) Overkill common field structure. Only fields used are the niml communication ones....
si  (int) index of stream to use
fromSUMA  (SUMA_Boolean) YUP means call is initiated from SUMA
Returns:
NOPE: Sucked YUP : Did not suck
See also:
SUMA_niml_hangup

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 }

SUMA_Boolean SUMA_niml_hangup SUMA_CommonFields   cf,
char *    nel_stream_name,
SUMA_Boolean    fromSUMA,
SUMA_Boolean    killit
 

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 }

Boolean SUMA_niml_workproc XtPointer    thereiselvis
 

NIML workprocess.

  • Read and process any new data from open connection.
(If the return is True, that means don't call this workproc again. If the return is False, that means call this workproc again.......) -------------------------------------------------------------------------

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 }

SUMA_DRAWN_ROI* SUMA_NIMLDrawnROI_to_DrawnROI SUMA_NIML_DRAWN_ROI   nimlROI,
SUMA_Boolean    ForDisplay
 

transfroms a SUMA_NIML_DRAWN_ROI * to a SUMA_DRAWN_ROI *

Parameters:
nimlROI  (SUMA_NIML_DRAWN_ROI *) the niml ROI structure
ForDisplay  (SUMA_Boolean) YUP: Action stack is created (use when ROIs will be displayed) NOPE: Action stack is not created
Returns:
ROI (SUMA_DRAWN_ROI *) the equivalent of niml ROI structure

See also:
SUMA_Free_NIMLDrawROI

Definition at line 1763 of file SUMA_niml.c.

References SUMA_ROI_DATUM::action, SUMA_DRAWN_ROI::ActionStack, SUMA_DRAWN_ROI::CE, SUMA_DRAWN_ROI::ColPlaneName, SUMA_NIML_DRAWN_ROI::ColPlaneName, dlist_init(), dlist_ins_next(), dlist_tail, SUMA_ROI_ACTION_STRUCT::DrawnROI, SUMA_DRAWN_ROI::DrawStatus, 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_DRAWN_ROI::N_CE, SUMA_ROI_DATUM::N_n, SUMA_NIML_DRAWN_ROI::N_ROI_datum, SUMA_ROI_DATUM::nPath, SUMA_DRAWN_ROI::Parent_idcode_str, SUMA_NIML_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_NIML_DRAWN_ROI::Type, SUMA_DRAWN_ROI::Type, and SUMA_ROI_DATUM::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 }

NI_element* SUMA_NodeVal2irgba_nel SUMA_SurfaceObject   SO,
float *    val,
char *    instanceID,
int    cleanup
 

A function to turn node values into a colored nel to be sent to SUMA

Parameters:
SO  (SUMA_SurfaceObject *) Surface object, domain of data
val  (float *) vector of node values to be colored and stored as nel
instanceID  (char *) a unique identifier used to tag a set of val vectors that are sent through repeated calls. With a new instanceID, static arrays are newly allocated and will continue to be used as long as instanceID does not change When instanceID changes, the function cleans up and reallocates automatically.
option  (int) Set this flag to: 1 to signal that you are done using this function for good and want to make sure any local allocations are freed. Returns NULL, does not need any previous params -1 to signal that this function is to be called just once under a particular instance and that the function should cleanup before it returns. Returns valid nel, requires all params. You can also use -1 if that is the last call in a series 0 to signal that this function will still be called under that instance

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 } 

NI_element* SUMA_NodeXYZ2NodeXYZ_nel SUMA_SurfaceObject   SO,
float *    val,
SUMA_Boolean    cleanup,
SUMA_DSET_TYPE    dtype
 

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

See also:
SUMA_NodeXYZ_nel2NodeXYZ

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 }

SUMA_Boolean SUMA_NodeXYZ_nel2NodeXYZ SUMA_SurfaceObject   SO,
NI_element   nel
 

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 }

SUMA_Boolean SUMA_process_NIML_data void *    nini,
SUMA_SurfaceViewer   sv
 

Process NIML data. ------------------------------------------------------------------------

Definition at line 379 of file SUMA_niml.c.

References SUMA_OVERLAY_PLANE_DATA::a, SUMA_SurfaceObject::AnatCorrect, SUMA_OVERLAY_PLANE_DATA::b, SUMA_CommonFields::Connected_v, SUMA_SurfaceViewer::CurGroupName, SUMA_OVERLAY_PLANE_DATA::DimFact, SUMA_NEW_SO_OPT::DoCenter, SUMA_NEW_SO_OPT::DoMetrics, SUMA_NEW_SO_OPT::DoNormals, SUMA_CommonFields::DsetList, SUMA_SurfaceObject::EmbedDim, SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceViewer::Focus_SO_ID, SUMA_OVERLAY_PLANE_DATA::g, SUMA_OVERLAY_PLANE_DATA::GlobalOpacity, SUMA_SurfaceObject::Group, SUMA_OVERLAY_PLANE_DATA::i, i, SUMA_SurfaceObject::idcode_str, SUMA_NEW_SO_OPT::idcode_str, IJK, SUMA_OVERLAY_PLANE_DATA::isBackGrnd, SUMA_SurfaceObject::Label, SUMA_SurfaceViewer::LinkAfniCrossHair, SUMA_SurfaceObject::LocalDomainParentID, LocalHead, SUMA_OVERLAY_PLANE_DATA::N, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, NI_group::name, NI_element::name, NI_BYTE, NI_ELEMENT_TYPE, NI_element_type(), NI_FLOAT, NI_get_attribute(), NI_GROUP_TYPE, NI_INT, NI_sleep(), SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, SUMA_DO::OP, SUMA_OVERLAY_PLANE_DATA::r, r, SUMA_SurfaceViewer::ResetGLStateVariables, SE_BindCrossHair, SE_Redisplay, SE_Redisplay_AllVisible, SE_SetAfniThisSurf, SE_SetCrossHair, SE_SetSOinFocus, SE_ToggleConnected, SEF_cp, SEF_fv3, SEF_i, SEF_iv3, SEF_s, SEI_Head, SEI_In, SEI_Tail, SES_Afni, SES_Suma, SES_SumaFromAfni, SES_SumaFromAny, SUMA_OVERLAY_PLANE_DATA::Show, SO_type, SOPT_ibbb, SUMA_OVERLAY_PLANE_DATA::Source, SUMA_SurfaceObject::State, strtod(), SUMA_AddDO(), SUMA_AFNI_COLORPLANE_OPACITY, SUMA_AFNI_STREAM_INDEX, SUMA_Boolean, SUMA_copy_string(), SUMA_CreateList(), SUMA_DIM_AFNI_COLOR_FACTOR, SUMA_Engine(), SUMA_ENTRY, SUMA_findSO_inDOv(), SUMA_findSOp_inDOv(), SUMA_free, SUMA_Free_Surface_Object(), SUMA_Free_VolPar(), SUMA_FreeNewSOOpt(), SUMA_InitializeEngineListData(), SUMA_iRGB_to_OverlayPointer(), SUMA_IS_EMPTY_STR_ATTR, SUMA_LH, SUMA_LOCAL, SUMA_malloc, SUMA_MAX_COMMAND_LENGTH, SUMA_MAX_DISPLAYABLE_OBJECTS, SUMA_MAX_STRING_LENGTH, SUMA_MAX_SURF_VIEWERS, SUMA_nel_stdout(), SUMA_NewNewSOOpt(), SUMA_NewSO(), SUMA_niml_hangup(), SUMA_nimlSO2SO(), SUMA_PrepAddmappableSO(), SUMA_PrepSO_GeomProp_GL(), SUMA_RECOMPUTE_NORMALS, SUMA_REGISTER_HEAD_COMMAND_NO_DATA, SUMA_REGISTER_TAIL_COMMAND_NO_DATA, SUMA_RegisteredSOs(), SUMA_RegisterEngineListCommand(), SUMA_RegisterGroup(), SUMA_RETURN, SUMA_S_Err, SUMA_SetRemixFlag(), SUMA_SetupSVforDOs(), SUMA_SL_Crit, SUMA_SL_Err, SUMA_SL_Note, SUMA_SL_Warn, SUMA_SLP_Err, SUMA_SLP_Warn, SUMA_SOGroup_2_Spec(), SUMA_SwitchGroups(), SUMA_SwitchState(), SUMA_SurfaceObject::SUMA_VolPar_Aligned, SUMA_VolPar_Attr(), SUMA_which_stream_index(), SUMA_WhichState(), SUMA_XYZmap_XYZ(), SUMAg_N_DOv, SUMAg_N_SVv, SUMA_X::TOPLEVEL, SUMA_CommonFields::TrackingId_v, tt, SUMA_OVERLAY_PLANE_DATA::Type, NI_element::vec, NI_element::vec_filled, NI_element::vec_len, NI_element::vec_num, NI_element::vec_typ, SUMA_SurfaceObject::VolPar, and SUMA_SurfaceViewer::X.

Referenced by SUMA_niml_workproc().

00380 {
00381    static char FuncName[]={"SUMA_process_NIML_data"};
00382    int tt = NI_element_type(nini) ;
00383    int OverInd, loc_ID, iview, *IJK=NULL, N_Node, *FaceSetList=NULL, N_FaceSet;
00384    int i, I_C = -1, nodeid = -1, iv3[3], dest_SO_ID = -1, 
00385          N_SOlist, SOlist[SUMA_MAX_DISPLAYABLE_OBJECTS];
00386    NI_element *nel = NULL ;
00387    NI_group *ngr = NULL;
00388    SUMA_EngineData *ED = NULL; 
00389    DList *list = NULL;
00390    DListElmt *Elm = NULL;
00391    char CommString[SUMA_MAX_COMMAND_LENGTH], *nel_surfidcode = NULL, *nel_nodeid = NULL;
00392    char s[SUMA_MAX_STRING_LENGTH], sfield[100], sdestination[100], ssource[100];
00393    float **fm, dimfact,  *XYZ=NULL, *NodeList=NULL;
00394    byte *r, *g, *b;
00395    byte BrandNew = YUP;
00396    SUMA_NEW_SO_OPT *nsoopt=NULL;
00397    SUMA_Boolean Empty_irgba = NOPE,  Found = NOPE;
00398    SUMA_SurfaceObject *SO = NULL;
00399    SUMA_SurfaceViewer *svi = NULL;
00400    SUMA_OVERLAYS * tmpptr; 
00401    GLfloat *glar_ColorList = NULL;
00402    SUMA_OVERLAY_PLANE_DATA sopd;
00403    SUMA_SurfSpecFile *Spec=NULL;
00404    SUMA_Boolean iselement = YUP;
00405    SUMA_Boolean LocalHead = NOPE;
00406 
00407    /*int it;
00408    float fv3[3], fv15[15];*/
00409    /*float ft;
00410    int **im,  iv15[15];*/ /* keep unused variables undeclared to quite compiler */
00411 
00412    SUMA_ENTRY;
00413 
00414    if( tt < 0 ) {/* should never happen */
00415       fprintf(SUMA_STDERR,"Error %s: Should never have happened.\n", FuncName);
00416       SUMA_RETURN(NOPE);
00417    } 
00418 
00419   
00420    SUMA_LH("Checking on nini type");
00421    /* check if group or element */
00422    if(tt == NI_GROUP_TYPE) {
00423       iselement = NOPE; 
00424       SUMA_LH("Dealing with group");
00425    } else if (tt == NI_ELEMENT_TYPE) { 
00426       iselement = YUP; 
00427       SUMA_LH("Dealing with element");
00428    } else {
00429       fprintf(SUMA_STDERR,"Error %s: Not an element, nor a group. What the hell are you doing?\n", FuncName);
00430       SUMA_RETURN(NOPE);
00431    }
00432    
00433    
00434    if (iselement) {
00435       /* if here, have a single data element;
00436          process the data based on the element name */
00437 
00438       nel = (NI_element *) nini ;
00439 
00440       if (LocalHead)  {
00441          fprintf(SUMA_STDERR,"%s:     name=%s vec_len=%d vec_filled=%d, vec_num=%d\n", FuncName,\
00442                   nel->name, nel->vec_len, nel->vec_filled, nel->vec_num );
00443       }
00444 
00445       /*--- stream closer ---*/
00446       if( strcmp(nel->name,"CloseKillStream") == 0) { /* CloseKillStream */
00447          if (LocalHead) fprintf (SUMA_STDERR,"%s:\nClosing then killing stream %s ...\n", 
00448                                        FuncName, NI_get_attribute(nel, "ni_stream_name"));
00449          if (!SUMA_niml_hangup (SUMAg_CF, NI_get_attribute(nel, "ni_stream_name"), NOPE, YUP)) {
00450             SUMA_SL_Err("Failed in SUMA_niml_hangup.\n");
00451             SUMA_RETURN(NOPE);
00452          }
00453          SUMA_RETURN(YUP);
00454       } /* CloseStreamKill */  
00455 
00456       /*--- stream tracking ON ---*/
00457       if( strcmp(nel->name,"StartTracking") == 0) { /* Start tracking */
00458          if (LocalHead) fprintf (SUMA_STDERR,"%s:\n Starting NI element tracking for %s ...\n", 
00459                                              FuncName, NI_get_attribute(nel, "ni_stream_name"));
00460          i = SUMA_which_stream_index(SUMAg_CF, NI_get_attribute(nel, "ni_stream_name"));
00461          if ( i < 0) {
00462             SUMA_SL_Err("Failed to find stream!\n");
00463             SUMA_RETURN(NOPE);
00464          }
00465          if (NI_get_attribute(nel, "Tracking_ID")) {
00466             if (atoi(NI_get_attribute(nel, "Tracking_ID")) != 1) {
00467                SUMA_SL_Err("First tracking element is not 1.\nTracking ignored.\n");
00468                SUMA_RETURN(YUP);
00469             }
00470          }
00471          SUMA_LH("Tracking on ...");
00472          SUMAg_CF->TrackingId_v[i] = 1; /* this is to be the first element ! */
00473          SUMA_RETURN(YUP);
00474       } /* Start tracking */  
00475 
00476       /*--- stream tracking OFF ---*/
00477       if( strcmp(nel->name,"StopTracking") == 0) { /* Stop tracking */
00478          if (LocalHead) fprintf (SUMA_STDERR,"%s:\n Stopping NI element tracking for %s ...\n", 
00479                                              FuncName, NI_get_attribute(nel, "ni_stream_name"));
00480          i = SUMA_which_stream_index(SUMAg_CF, NI_get_attribute(nel, "ni_stream_name"));
00481          if ( i < 0) {
00482             SUMA_SL_Err("Failed to find stream!\n");
00483             SUMA_RETURN(NOPE);
00484          }
00485          SUMA_LH("Tracking Off ...");
00486          SUMAg_CF->TrackingId_v[i] = 0; /* this is to be the first element ! */
00487          SUMA_RETURN(YUP);
00488       } /* Stop tracking */  
00489 
00490       /*--- CrossHair XYZ --- */
00491       if( strcmp(nel->name,"SUMA_crosshair_xyz") == 0) {/* SUMA_crosshair_xyz */
00492          /* Do it for all viewers */
00493          for (iview = 0; iview < SUMAg_N_SVv; ++iview) {
00494             svi = &(SUMAg_SVv[iview]);
00495             if (svi->LinkAfniCrossHair) {/* link cross hair */
00496                /* look for the surface idcode */
00497                nel_surfidcode = NI_get_attribute(nel, "surface_idcode");
00498                if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) nel_surfidcode = NI_get_attribute(nel, "Parent_ID");
00499                if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) {
00500                   if (LocalHead) fprintf(SUMA_STDERR,"%s: surface_idcode missing in nel (%s), using svi->Focus_SO_ID.\n", FuncName, nel->name);
00501                   dest_SO_ID = svi->Focus_SO_ID; /* default */
00502                } else {
00503                   /* first try to find out if one of the displayed surfaces has a parent equal to nel_surfidcode */
00504                   if (LocalHead) fprintf (SUMA_STDERR,"%s: Searching displayed surfaces.\n", FuncName);
00505                   Found = NOPE;
00506                   i = 0;
00507                   N_SOlist = SUMA_RegisteredSOs(svi, SUMAg_DOv, SOlist);
00508                   while (i < N_SOlist && !Found) { 
00509                      SO = (SUMA_SurfaceObject *)(SUMAg_DOv[SOlist[i]].OP);
00510                      if (strcmp(nel_surfidcode, SO->LocalDomainParentID) == 0) {
00511                         Found = YUP;
00512                         dest_SO_ID = SOlist[i];
00513                      }
00514                      ++i;
00515                   }
00516                   /* if not found, look for any DO */
00517                   if (!Found) {
00518                      if (LocalHead) fprintf (SUMA_STDERR,"%s: None of the displayed surfaces (or their parents) match nel_surfidcode. Trying all of DOv...\n", FuncName);
00519                      dest_SO_ID = SUMA_findSO_inDOv (nel_surfidcode, SUMAg_DOv, SUMAg_N_DOv);
00520                      if (dest_SO_ID < 0) {
00521                         if (LocalHead) fprintf(SUMA_STDERR,"%s:%s: nel idcode is not found in DOv.\n", FuncName, nel->name);            
00522                         dest_SO_ID = svi->Focus_SO_ID; 
00523                      } else { /* good, set SO accordingly */
00524                          if (LocalHead) fprintf(SUMA_STDOUT,"%s: DOv[%d] Matched idcode\n", FuncName, dest_SO_ID);
00525                      }
00526                   }
00527                }
00528 
00529                SO = (SUMA_SurfaceObject *)(SUMAg_DOv[dest_SO_ID].OP);
00530 
00531                if (LocalHead) SUMA_nel_stdout (nel);
00532 
00533                /* check for node id */
00534                nel_nodeid = NI_get_attribute (nel, "surface_nodeid");
00535                if (!nel_nodeid) nodeid = -1;
00536                else {
00537                   if (strlen(nel_nodeid)) nodeid = (int)strtod(nel_nodeid, NULL);
00538                   else nodeid = -1;
00539                }
00540 
00541                /*-- check element for suitability --*/
00542                if( nel->vec_len    < 1 || nel->vec_filled <  1) {  /* empty element?             */
00543                   SUMA_SLP_Warn ("Empty crosshair xyz.\n");
00544                   SUMA_RETURN(YUP);
00545                }
00546 
00547                if( nel->vec_len != 3 || nel->vec_num != 1 || nel->vec_typ[0] != NI_FLOAT) {
00548                   SUMA_SLP_Err(  "SUMA_crosshair_xyz requires\n"
00549                                  "3 floats in one vector.\n");
00550                   SUMA_RETURN(NOPE);
00551                }
00552 
00553 
00554                /* nodeid is supplied, even if the distance from the cross hair to the node is large, 
00555                set a limit */
00556                if (nodeid >= 0) {
00557                   SUMA_LH("Node index courtesy of AFNI");
00558                   /* get the XYZ on the mapping reference */
00559                   I_C = -1;
00560                   XYZ = SUMA_XYZmap_XYZ (nel->vec[0], SO, SUMAg_DOv, SUMAg_N_DOv, &I_C);
00561                   if (!XYZ) {
00562                      SUMA_SL_Warn("AFNI cross hair too\n"
00563                                  "far from surface.\n"
00564                                  "No action taken.");
00565                      XBell (XtDisplay (sv->X->TOPLEVEL), 50);             
00566                      SUMA_RETURN(YUP);
00567                   }
00568                   I_C = nodeid; /* node index is set by AFNI */
00569                } else {
00570                   SUMA_LH("Searching for node index.");
00571                   /* set the cross hair XYZ for now and let SUMA_XYZmap_XYZ set the node index*/
00572                   I_C = -1;
00573                   XYZ = SUMA_XYZmap_XYZ (nel->vec[0], SO, SUMAg_DOv, SUMAg_N_DOv, &I_C);
00574 
00575                   if (XYZ == NULL || I_C < 0) {
00576                      SUMA_SL_Warn("AFNI cross hair too\n"
00577                                  "far from surface.\n"
00578                                  "No action taken.");
00579                      XBell (XtDisplay (sv->X->TOPLEVEL), 50);             
00580                      SUMA_RETURN(YUP);
00581                   }
00582                }
00583 
00584                /* attach the cross hair to the selected surface */
00585                #if 0
00586                   if (nel_surfidcode == NULL) {
00587                      fprintf(SUMA_STDERR,"Error %s: surface_idcode missing in nel (%s).\nLoose Crosshair\n", FuncName, nel->name);
00588                      iv3[0] = -1;
00589                   } else {
00590                      iv3[0] = dest_SO_ID;
00591                   }
00592                #else
00593                   iv3[0] = dest_SO_ID; /* nel_surfidcode == NULL is handled above, May 15 03*/
00594                #endif
00595 
00596                iv3[1] = I_C; /* use the closest node for a link otherwise when you switch states, you'll get a wandering cross hair */
00597                if (!list) list = SUMA_CreateList();
00598                ED = SUMA_InitializeEngineListData (SE_BindCrossHair);
00599                if (!SUMA_RegisterEngineListCommand (  list, ED, 
00600                                                       SEF_iv3, (void*)iv3,
00601                                                       SES_SumaFromAfni, (void *)svi, NOPE,
00602                                                       SEI_Head, NULL)) {
00603                   fprintf(SUMA_STDERR,"Error %s: Failed to register element\n", FuncName);
00604                   SUMA_RETURN (NOPE);
00605                }
00606 
00607                /* send cross hair coordinates */
00608                ED = SUMA_InitializeEngineListData (SE_SetCrossHair);
00609                if (!SUMA_RegisterEngineListCommand (  list, ED, 
00610                                                       SEF_fv3, (void*)XYZ,
00611                                                       SES_SumaFromAfni, svi, NOPE,
00612                                                       SEI_Tail, NULL)) {
00613                   fprintf(SUMA_STDERR,"Error %s: Failed to register element\n", FuncName);
00614                   SUMA_RETURN (NOPE);
00615                }
00616 
00617                svi->ResetGLStateVariables = YUP; 
00618 
00619                #if 0
00620                /* logic for that not too clear yet */
00621                /* set the SO in Focus */
00622                ED = SUMA_InitializeEngineListData (SE_SetSOinFocus);
00623                if (!SUMA_RegisterEngineListCommand (  list, ED, 
00624                                                       SEF_i, (void*)&dest_SO_ID,
00625                                                       SES_SumaFromAfni, (void *)svi, NOPE,
00626                                                       SEI_Tail, NULL)) {
00627                   fprintf(SUMA_STDERR,"Error %s: Failed to register element\n", FuncName);
00628                   SUMA_RETURN (NOPE);
00629                }
00630                #endif
00631 
00632                SUMA_REGISTER_TAIL_COMMAND_NO_DATA(list, SE_Redisplay, SES_SumaFromAfni, svi);
00633                if (!SUMA_Engine (&list)) {
00634                   fprintf(SUMA_STDERR, "Error %s: SUMA_Engine call failed.\n", FuncName);
00635                }
00636 
00637             } /* link cross hair */    
00638          } /* iview ... for all viewers */
00639          /* don't free nel, it's freed later on
00640             dont't free attributes obtained in NI_get_attribute, they are copies of pointers in nel  */
00641          SUMA_RETURN(YUP) ;
00642       }/* SUMA_crosshair_xyz */
00643 
00644       /* New surface mesh_IJK, This one is now obsolete, along with NewNode_XYZ, they were used to send a surface in chunks, now 
00645       I can send an entire surface. Look at commented out section in SUMA_Mesh_IJK2Mesh_IJK_nel if you want to reuse this chunk*/
00646       if (strcmp(nel->name,"NewMesh_IJK") == 0) { /* NewMesh_IJK */
00647          SUMA_SL_Err("Element obsolete. Please use SUMA_SurfaceObject");
00648          SUMA_RETURN(NOPE) ;
00649          if( nel->vec_len  < 1 || nel->vec_filled <  1) {  /* empty element?             */
00650             fprintf(SUMA_STDERR,"%s: Empty NewMesh_IJK\n", FuncName);
00651             SUMA_RETURN(NOPE);
00652          }else {
00653             if( nel->vec_num != 1 || nel->vec_typ[0] != NI_INT) {
00654                  fprintf(SUMA_STDERR,"%s: NewMesh_IJK Bad format\n", FuncName);
00655                SUMA_RETURN(NOPE);
00656             }
00657          }
00658          /* show me nel */
00659          /* if (LocalHead) SUMA_nel_stdout (nel); */
00660          /* look for the surface idcode */
00661          nel_surfidcode = NI_get_attribute(nel, "surface_idcode");
00662          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) nel_surfidcode = NI_get_attribute(nel, "Parent_ID");
00663          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) {
00664             fprintf(SUMA_STDERR,"Error %s: surface_idcode missing in nel (%s).\n", FuncName, nel->name);
00665             SUMA_RETURN(NOPE);
00666          } 
00667 
00668          SUMA_LH("Checking for new surface...");
00669          SO = SUMA_findSOp_inDOv (nel_surfidcode, SUMAg_DOv, SUMAg_N_DOv);
00670          if (SO) {
00671             fprintf(SUMA_STDERR,"Warning %s: nel idcode was found in DOv.\nChecking for mesh compatibility\n", FuncName);
00672             if (SO->N_FaceSet * SO->FaceSetDim == nel->vec_len) {
00673                fprintf(SUMA_STDERR,"Note %s: Mesh dimensions match. New mesh will be adopted.\n", FuncName);
00674             } else {
00675                fprintf(SUMA_STDERR,"Error %s: Mesh dimensions mismatch.\n", FuncName);
00676                SUMA_RETURN(NOPE);
00677             }
00678          }
00679 
00680          /* get the number of nodes */
00681          if (!NI_get_attribute(nel, "N_Node")) {
00682             fprintf(SUMA_STDERR,"Error %s: NULL or non existent N_Node field.\n", FuncName);
00683             SUMA_RETURN(NOPE);   
00684          }
00685 
00686          if (LocalHead) fprintf(SUMA_STDERR,"Number of nodes:%s...\n", NI_get_attribute(nel, "N_Node"));
00687          N_Node = atoi(NI_get_attribute(nel, "N_Node"));
00688          if (N_Node <= 0 || N_Node > 1000000) {
00689             fprintf(SUMA_STDERR,"Error %s: Bad number of nodes %d (limit of 1000000 nodes.)\n", FuncName, N_Node);
00690             SUMA_RETURN(NOPE);
00691          }
00692 
00693          if (!SO) { 
00694             SUMA_LH("A brand new surface.");
00695             BrandNew = YUP;
00696             NodeList = (float *)SUMA_malloc(3 * N_Node * sizeof(float)); /* do not use calloc so that you can see something ... */
00697             FaceSetList = (int *)SUMA_malloc(nel->vec_len * sizeof(int)); 
00698             if (!NodeList || !FaceSetList) {
00699                SUMA_SL_Crit("Failed to allocate for NodeList || FaceSetList");
00700                SUMA_RETURN(NOPE);
00701             }
00702             IJK = (int *)nel->vec[0];
00703             N_FaceSet = nel->vec_len / 3; 
00704             if (nel->vec_len % 3) {
00705                fprintf(SUMA_STDERR,"Error %s: Bad number of elements in IJK vector not divisible by 3! %d\n", FuncName, nel->vec_len);
00706                SUMA_RETURN(NOPE);
00707             }
00708             SUMA_LH("Copying new mesh");
00709             for (i=0; i < nel->vec_len; ++i) FaceSetList[i] = IJK[i];
00710             /* Now form the new surface */
00711             SUMA_LH("Now forming new surface");
00712             nsoopt = SUMA_NewNewSOOpt();
00713             nsoopt->DoNormals = NOPE; nsoopt->DoMetrics = NOPE; nsoopt->DoCenter = NOPE; 
00714             nsoopt->idcode_str = SUMA_copy_string(nel_surfidcode);      
00715             SO = SUMA_NewSO(&NodeList, N_Node, &FaceSetList, N_FaceSet, nsoopt);
00716             nsoopt=SUMA_FreeNewSOOpt(nsoopt); 
00717          } else {
00718             SUMA_LH("A refit of an existing surface.");
00719             BrandNew = NOPE;
00720             if (N_Node != SO->N_Node) {
00721                fprintf(SUMA_STDERR,"Error %s: Mismatch in number of nodes between new mesh and pre-existing one (%d vs %d)\n", FuncName, N_Node, SO->N_Node);
00722                SUMA_RETURN(NOPE);
00723             }
00724             IJK = (int *)nel->vec[0];
00725             for (i=0; i < nel->vec_len; ++i) SO->FaceSetList[i] = IJK[i];
00726          }
00727 
00728          /* work the mesh a little and add it to DOv NO LONGER DONE HERE...*/
00729          SO->Group = SUMA_copy_string(NI_get_attribute(nel, "Group"));
00730          if (!SO->Group) SO->Group = SUMA_copy_string(NI_get_attribute(nel, "Subject_Label"));
00731          SO->State = SUMA_copy_string(NI_get_attribute(nel, "State"));
00732          if (!SO->State) SO->State = SUMA_copy_string(NI_get_attribute(nel, "Layer_Name"));
00733          SO->Label = SUMA_copy_string(NI_get_attribute(nel, "Label"));
00734          if (!SO->Label) SO->Label = SUMA_copy_string(NI_get_attribute(nel, "Object_Label"));
00735          SO->EmbedDim = atoi(NI_get_attribute(nel, "EmbedDim"));
00736          if (!SO->EmbedDim) SO->EmbedDim = atoi(NI_get_attribute(nel, "Embedding_Dimension"));
00737          SO->AnatCorrect = atoi(NI_get_attribute(nel, "AnatCorrect"));
00738          if (!SO->AnatCorrect) {
00739             char *tmp = NI_get_attribute(nel, "Anatomically_Correct");
00740             if (tmp) {
00741                if (strstr(tmp,"yes")) SO->AnatCorrect = 1;
00742                else if (strstr(tmp,"no")) SO->AnatCorrect = 0;
00743             }
00744          }
00745          /* add this surface to DOv */
00746          if (BrandNew) {
00747             if (!SUMA_AddDO(SUMAg_DOv, &(SUMAg_N_DOv), (void *)SO,  SO_type, SUMA_LOCAL)) {
00748                fprintf(SUMA_STDERR,"Error %s: Error Adding DO\n", FuncName);
00749                SUMA_RETURN(NOPE);
00750             }
00751          }
00752 
00753          /* don't free nel, it's freed later on */
00754          SUMA_RETURN(YUP) ;
00755       }/* NewMesh_IJK */   
00756 
00757       if (strcmp(nel->name,"PrepNewSurface") == 0) { /* PrepNewSurface */
00758          /* show me nel */
00759          /* if (LocalHead) SUMA_nel_stdout (nel); */
00760          /* look for the surface idcode */
00761          nel_surfidcode = NI_get_attribute(nel, "surface_idcode");
00762          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) nel_surfidcode = NI_get_attribute(nel, "Parent_ID");
00763          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) {
00764             fprintf(SUMA_STDERR,"Error %s: surface_idcode missing in nel (%s).\n", FuncName, nel->name);
00765             SUMA_RETURN(NOPE);
00766          } 
00767          SUMA_LH("Looking for  surface...");
00768          SO = SUMA_findSOp_inDOv (nel_surfidcode, SUMAg_DOv, SUMAg_N_DOv);
00769          if (!SO) {
00770             fprintf(SUMA_STDERR,"Error %s: nel idcode was not found in DOv.\n", FuncName);
00771             SUMA_RETURN(NOPE);
00772          }
00773 
00774          if (LocalHead) fprintf(SUMA_STDERR,"%s: Surface SO about to be prepped: Label %s, State %s, Group %s\n", FuncName, SO->Label, SO->State, SO->Group);
00775 
00776          #if 0
00777          if (NI_get_attribute(nel, "VolParFilecode")) {
00778             SO->VolPar = SUMA_VolPar_Attr (NI_get_attribute(nel, "VolParFilecode"));
00779             if (!SO->VolPar) {
00780                SUMA_S_Err("Failed in SUMA_VolPar_Attr");
00781                SUMA_RETURN(NOPE);
00782             }
00783             SO->SUMA_VolPar_Aligned = YUP; /* Surface should already be in alignment with volume, should not call SUMA_Align_to_VolPar ... */
00784          }
00785          #else
00786             /* VolPar should have been dealt with by now */
00787             if (!SO->VolPar) SO->SUMA_VolPar_Aligned = NOPE;
00788             else SO->SUMA_VolPar_Aligned = YUP; /* Surface should already be in alignment with volume, should not call SUMA_Align_to_VolPar ... */
00789          #endif
00790 
00791          /* make this surface friendly for suma */
00792          if (!SUMA_PrepSO_GeomProp_GL(SO)) {
00793             SUMA_S_Err("Failed in SUMA_PrepSO_GeomProp_GL");
00794             SUMA_RETURN(NOPE);
00795          }
00796          /* Add this surface to SUMA's displayable objects */
00797          if (!SUMA_PrepAddmappableSO(SO, SUMAg_DOv, &(SUMAg_N_DOv), 0, SUMAg_CF->DsetList)) {
00798             SUMA_S_Err("Failed to add mappable SOs ");
00799             SUMA_RETURN(NOPE);
00800          }
00801          /* create a fake spec, be damned gates of spec! */
00802          Spec = SUMA_SOGroup_2_Spec (&SO, 1);
00803 
00804          /* register the new group with SUMA */
00805          if (!SUMA_RegisterGroup(SUMAg_CF, Spec)) {
00806             SUMA_SL_Err("Failed to register group");
00807             SUMA_RETURN(NOPE);
00808          }
00809 
00810               /* Register the surfaces in Spec file with the surface viewer and perform setups */
00811               if (LocalHead) fprintf (SUMA_STDERR, "%s: Registering surfaces with surface viewers ...\n", FuncName);
00812 
00813          for (i = 0; i< SUMA_MAX_SURF_VIEWERS; ++i) {
00814             if (!SUMA_SetupSVforDOs (*Spec, SUMAg_DOv, SUMAg_N_DOv, &(SUMAg_SVv[i]))) {
00815                               fprintf (SUMA_STDERR, "Error %s: Failed in SUMA_SetupSVforDOs function.\n", FuncName);
00816                               SUMA_RETURN(NOPE);
00817                       }
00818               }
00819 
00820          /* do not switch or redisplay yet, all you have is garbage for geometry ... */
00821          SUMA_free(Spec); Spec = NULL;
00822 
00823          /* switch viewer 0 to the group in question */
00824          if (!sv) sv = &(SUMAg_SVv[0]);
00825          if (!SUMA_SwitchGroups (sv, SO->Group)) {
00826             SUMA_SL_Err("Failed to switch groups!");
00827             SUMA_RETURN(NOPE);
00828          }
00829          if ((i = SUMA_WhichState(SO->State, sv, sv->CurGroupName)) < 0) {
00830             SUMA_SL_Err("Failed to find state!");
00831             SUMA_RETURN(NOPE);
00832          } else {
00833             if (!SUMA_SwitchState(SUMAg_DOv, SUMAg_N_DOv, sv, i, sv->CurGroupName)) {
00834                SUMA_SL_Err("Failed to switch states!");
00835                SUMA_RETURN(NOPE);
00836             }
00837          }
00838 
00839          /* do we need to notify AFNI ? */
00840          if (NI_get_attribute(nel, "Send2Afni")) {
00841             SUMA_LH("Attempting to talk to AFNI");
00842             if (!SO->VolPar) {
00843                SUMA_SL_Err("Have no VolPar, cannot send to AFNI!\nCommand ignored.");
00844             } else {
00845                if (!SUMAg_CF->Connected_v[SUMA_AFNI_STREAM_INDEX]) { /* need to send a toggle request */
00846                   if (LocalHead) fprintf(SUMA_STDERR, "%s: Sending talk request...\n", FuncName);
00847                   if (!list) list = SUMA_CreateList();
00848                   SUMA_REGISTER_HEAD_COMMAND_NO_DATA(list, SE_ToggleConnected, SES_SumaFromAny, sv);
00849                   if (!SUMA_Engine (&list)) {
00850                      fprintf(SUMA_STDERR, "Warning %s: SUMA_Engine call failed.\nContinuing...", FuncName);
00851                   } 
00852                } else {
00853                   SUMA_LH("Looks like they're talking already");
00854                }
00855                /* now send the surface */
00856                SUMA_LH("Now trying to send surface");
00857                if (!SUMAg_CF->Connected_v[SUMA_AFNI_STREAM_INDEX]) { 
00858                   fprintf(SUMA_STDERR, "Warning %s: Failed to open connection.\nContinuing...", FuncName);
00859                } else {
00860                   SUMA_LH("Making Call");
00861                   if (!list) list = SUMA_CreateList();
00862                   ED = SUMA_InitializeEngineListData (SE_SetAfniThisSurf);
00863                   if (!( Elm = SUMA_RegisterEngineListCommand (  list, ED, 
00864                                                          SEF_cp, (void *)SO->idcode_str, 
00865                                                          SES_Suma, NULL, NOPE, 
00866                                                          SEI_Tail, NULL ))) {
00867                      fprintf(SUMA_STDERR,"Error %s: Failed to register command\nIgnoring ...", FuncName);
00868                   }else {
00869                      int ti= 0;
00870                      SUMA_RegisterEngineListCommand (  list, ED, 
00871                                                          SEF_s, (void *)("NodeList, FaceSetList, NodeNormList"), 
00872                                                          SES_Suma, NULL, NOPE, 
00873                                                          SEI_In, Elm );
00874                      SUMA_RegisterEngineListCommand (  list, ED, 
00875                                                          SEF_i, (void *)&ti, /* 0, be quiet about it */
00876                                                          SES_Suma, NULL, NOPE, 
00877                                                          SEI_In, Elm );
00878                      if (!SUMA_Engine (&list)) {
00879                         fprintf(SUMA_STDERR, "Warning %s: SUMA_Engine call failed.\nContinuing...", FuncName);
00880                      }
00881                   }
00882                }   
00883             }
00884          } else {
00885             SUMA_LH("No talking to AFNI requested.");
00886          }
00887          /* don't free nel, it's freed later on */
00888          SUMA_RETURN(YUP) ;
00889       } /* PrepNewSurface */
00890 
00891       /* NewNode_XYZ NOW OBSOLETE, see comment for NewMesh_IJK*/
00892       if( strcmp(nel->name,"NewNode_XYZ") == 0) {/* NewNode_XYZ */
00893          SUMA_SL_Err("Obsolete element, please use SUMA_SurfaceObject element instead");
00894          SUMA_RETURN(NOPE);
00895          if( nel->vec_len  < 1 || nel->vec_filled <  1) {  /* empty element?             */
00896             fprintf(SUMA_STDERR,"%s: Empty NewNode_XYZ\n", FuncName);
00897             SUMA_RETURN(NOPE);
00898          }else {
00899             if( nel->vec_num != 1 || nel->vec_typ[0] != NI_FLOAT) {
00900                  fprintf(SUMA_STDERR,"%s: NewNode_XYZ Bad format\n", FuncName);
00901                SUMA_RETURN(NOPE);
00902             }
00903          }
00904          /* show me nel */
00905          /* if (LocalHead) SUMA_nel_stdout (nel); */
00906 
00907          /* look for the surface idcode */
00908          nel_surfidcode = NI_get_attribute(nel, "surface_idcode");
00909          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) nel_surfidcode = NI_get_attribute(nel, "Parent_ID");
00910          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) {
00911             fprintf(SUMA_STDERR,"Error %s: surface_idcode missing in nel (%s).\n", FuncName, nel->name);
00912             SUMA_RETURN(NOPE);
00913          } 
00914 
00915          SO = SUMA_findSOp_inDOv (nel_surfidcode, SUMAg_DOv, SUMAg_N_DOv);
00916          if (!SO) {
00917             fprintf(SUMA_STDERR,"Error %s:%s: nel idcode is not found in DOv.\n", FuncName, nel->name);
00918             SUMA_RETURN(NOPE);
00919          }
00920 
00921          /* now copy the new node coordinates over the old ones */
00922          if (nel->vec_len != SO->N_Node * 3) {
00923             fprintf(SUMA_STDERR,"Error %s:\nExpected %d * 3 = %d values, found %d\n", 
00924                FuncName, SO->N_Node, SO->N_Node * 3, nel->vec_len);
00925             SUMA_RETURN(NOPE);
00926          }
00927 
00928          XYZ = (float *)nel->vec[0];
00929          for (i=0; i < nel->vec_len; ++i) SO->NodeList[i] = XYZ[i];
00930 
00931          /* don't free nel, it's freed later on */
00932          SUMA_RETURN(YUP) ;
00933       } /* NewNode_XYZ */
00934 
00935       /* Node_XYZ */
00936       if( strcmp(nel->name,"Node_XYZ") == 0) {/* Node_XYZ */
00937          if( nel->vec_len  < 1 || nel->vec_filled <  1) {  /* empty element?             */
00938             fprintf(SUMA_STDERR,"%s: Empty Node_XYZ\n", FuncName);
00939             SUMA_RETURN(NOPE);
00940          }else {
00941             if( nel->vec_num != 1 || nel->vec_typ[0] != NI_FLOAT) {
00942                  fprintf(SUMA_STDERR,"%s: Node_XYZ Bad format\n", FuncName);
00943                SUMA_RETURN(NOPE);
00944             }
00945          }
00946          /* show me nel */
00947          /* if (LocalHead) SUMA_nel_stdout (nel); */
00948 
00949          /* look for the surface idcode */
00950          nel_surfidcode = NI_get_attribute(nel, "surface_idcode");
00951          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) nel_surfidcode = NI_get_attribute(nel, "Parent_ID");
00952          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) {
00953             fprintf(SUMA_STDERR,"Error %s: surface_idcode missing in nel (%s).\n", FuncName, nel->name);
00954             SUMA_RETURN(NOPE);
00955          } 
00956 
00957          SO = SUMA_findSOp_inDOv (nel_surfidcode, SUMAg_DOv, SUMAg_N_DOv);
00958          if (!SO) {
00959             fprintf(SUMA_STDERR,"Error %s:%s: nel idcode is not found in DOv.\n", FuncName, nel->name);
00960             SUMA_RETURN(NOPE);
00961          }
00962 
00963          /* now copy the new node coordinates over the old ones */
00964          if (nel->vec_len != SO->N_Node * 3) {
00965             fprintf(SUMA_STDERR,"Error %s:\nExpected %d * 3 = %d values, found %d\n", 
00966                FuncName, SO->N_Node, SO->N_Node * 3, nel->vec_len);
00967             SUMA_RETURN(NOPE);
00968          }
00969 
00970          XYZ = (float *)nel->vec[0];
00971          for (i=0; i < nel->vec_len; ++i) SO->NodeList[i] = XYZ[i];
00972 
00973          /* must recompute normals */
00974          SUMA_RECOMPUTE_NORMALS(SO);
00975 
00976          /* file a redisplay request */
00977          if (LocalHead) fprintf(SUMA_STDERR, "%s: Redisplaying all visible...\n", FuncName);
00978          if (!list) list = SUMA_CreateList();
00979          SUMA_REGISTER_HEAD_COMMAND_NO_DATA(list, SE_Redisplay_AllVisible, SES_SumaFromAny, sv);
00980          if (NI_get_attribute(nel, "Send2Afni")) {
00981             if (SUMAg_CF->Connected_v[SUMA_AFNI_STREAM_INDEX]) {
00982                SUMA_LH("Putting request for sending to afni ...");
00983                ED = SUMA_InitializeEngineListData (SE_SetAfniThisSurf);
00984                if (!( Elm = SUMA_RegisterEngineListCommand (  list, ED, 
00985                                                       SEF_cp, (void *)SO->idcode_str, 
00986                                                       SES_Suma, NULL, NOPE, 
00987                                                       SEI_Tail, NULL ))) {
00988                   fprintf(SUMA_STDERR,"Error %s: Failed to register command\n", FuncName);
00989                   SUMA_RETURN(NOPE);
00990                }
00991 
00992                /* You could save time and not send the NodeNormList but that means AFNI 
00993                will end up with a bad set of normals for the final version of the surface
00994                not a good idea... */
00995                   SUMA_RegisterEngineListCommand ( list, ED, 
00996                                                    SEF_s, (void *)("NodeList, NodeNormList"), 
00997                                                    SES_Suma, NULL, NOPE, 
00998                                                    SEI_In, Elm );
00999                   { int ti = 0; /* keep it quiet */
01000                      SUMA_RegisterEngineListCommand ( list, ED, 
01001                                                    SEF_i, (void *)&ti, 
01002                                                    SES_Suma, NULL, NOPE, 
01003                                                    SEI_In, Elm );
01004                   }
01005             } else {
01006                if (LocalHead) {
01007                   SUMA_SL_Note("Cannot send surface to afni, no connection established");
01008                }
01009             }
01010          } 
01011 
01012          if (!SUMA_Engine (&list)) {
01013             fprintf(SUMA_STDERR, "Error %s: SUMA_Engine call failed.\n", FuncName);
01014             SUMA_RETURN(NOPE);
01015          }
01016 
01017          /* don't free nel, it's freed later on */
01018          SUMA_RETURN(YUP) ;
01019 
01020 
01021       }/* Node_XYZ */
01022 
01023       /* SUMA_irgba Node colors */
01024       if( strcmp(nel->name,"SUMA_irgba") == 0 || strcmp(nel->name,"Node_RGBAb") == 0) {/* SUMA_irgba */
01025          if( nel->vec_len  < 1 || nel->vec_filled <  1) {  /* empty element?             */
01026             fprintf(SUMA_STDERR,"%s: Empty SUMA_irgba.\n", FuncName);
01027             Empty_irgba = YUP;
01028            }else {
01029             if( nel->vec_num != 5 || nel->vec_typ[0] != NI_INT || nel->vec_typ[1] != NI_BYTE || nel->vec_typ[2] != NI_BYTE || nel->vec_typ[3] != NI_BYTE) {
01030                  fprintf(SUMA_STDERR,"%s: SUMA_irgba Bad format\n", FuncName);
01031                SUMA_RETURN(NOPE);
01032            }
01033          }
01034          #if SUMA_SUMA_NIML_DEBUG
01035             fprintf(SUMA_STDERR,"Warning %s:\nSleeping ONLY ...\n", FuncName);
01036             NI_sleep(200);
01037             SUMA_RETURN(YUP);
01038 
01039 
01040             if (0) {  /* At times, I found the value in nel->vec[0] to be corrupted, use this to check on it */
01041                int *ibad;
01042                ibad = (int *)nel->vec[0]; 
01043                fprintf (SUMA_STDERR,"ibad[0] = %d\n", ibad[0]);
01044             }
01045          #endif
01046 
01047          /* show me nel */
01048          /* if (LocalHead) SUMA_nel_stdout (nel); */
01049 
01050          /* look for the surface idcode */
01051          nel_surfidcode = NI_get_attribute(nel, "surface_idcode");
01052          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) nel_surfidcode = NI_get_attribute(nel, "Parent_ID");
01053          if (SUMA_IS_EMPTY_STR_ATTR(nel_surfidcode)) {
01054             fprintf(SUMA_STDERR,"Error %s: surface_idcode missing in nel (%s).\n", FuncName, nel->name);
01055             SUMA_RETURN(NOPE);
01056          } 
01057 
01058          SO = SUMA_findSOp_inDOv (nel_surfidcode, SUMAg_DOv, SUMAg_N_DOv);
01059          if (!SO) {
01060             fprintf(SUMA_STDERR,"Error %s:%s: nel idcode is not found in DOv.\n", FuncName, nel->name);
01061             SUMA_RETURN(NOPE);
01062          }
01063 
01064          /* store the node colors */
01065          /* create a color overlay plane */
01066          /* you could create an overlay plane with partial node coverage but you'd have to clean up and SUMA_reallocate
01067          with each new data sent since the number of colored nodes will change. So I'll allocate for the entire node list 
01068          for the FuncAfni_0 color plane although only some values will be used*/
01069 
01070          sopd.Type = SOPT_ibbb;
01071          sopd.Source = SES_Afni;
01072          sopd.GlobalOpacity = SUMA_AFNI_COLORPLANE_OPACITY;
01073          sopd.isBackGrnd = NOPE;
01074          sopd.Show = YUP;
01075          /* dim colors from maximum intensity to preserve surface shape highlights, 
01076          division by is no longer necessary.
01077          */
01078          sopd.DimFact = SUMA_DIM_AFNI_COLOR_FACTOR;
01079          if (!Empty_irgba) {
01080             sopd.i = (void *)nel->vec[0];
01081             sopd.r = (void *)nel->vec[1];
01082             sopd.g = (void *)nel->vec[2];
01083             sopd.b = (void *)nel->vec[3];
01084             sopd.a = NULL;
01085             sopd.N = nel->vec_len;
01086          } else {
01087             sopd.i = sopd.r = sopd.g = sopd.b = sopd.a = NULL;
01088             sopd.N = 0;
01089          }
01090 
01091          if (!SUMA_iRGB_to_OverlayPointer (SO, "FuncAfni_0", &sopd, &OverInd, SUMAg_DOv, SUMAg_N_DOv, SUMAg_CF->DsetList)) {
01092             SUMA_SLP_Err("Failed to fetch or create overlay pointer.");
01093             SUMA_RETURN(NOPE);
01094          }
01095 
01096 
01097          /* register a color remix request */
01098          if (LocalHead) fprintf(SUMA_STDERR, "%s: Setting Remix Flag for all related surfaces. ...\n", FuncName);
01099          if(!SUMA_SetRemixFlag (SO->idcode_str, SUMAg_SVv, SUMAg_N_SVv)) {
01100             fprintf (SUMA_STDERR,"Error %s: Failed in SUMA_SetRemixFlag.\n", FuncName);
01101             SUMA_RETURN(NOPE);
01102          }
01103 
01104          /* file a redisplay request */
01105          if (LocalHead) fprintf(SUMA_STDERR, "%s: Redisplaying all visible...\n", FuncName);
01106          if (!list) list = SUMA_CreateList();
01107          if (strcmp(nel->name,"SUMA_irgba") == 0) {
01108             /* call from AFNI */
01109             SUMA_REGISTER_HEAD_COMMAND_NO_DATA(list, SE_Redisplay_AllVisible, SES_SumaFromAfni, sv);
01110          } else {
01111             SUMA_REGISTER_HEAD_COMMAND_NO_DATA(list, SE_Redisplay_AllVisible, SES_SumaFromAny, sv);
01112          }
01113 
01114          if (!SUMA_Engine (&list)) {
01115             fprintf(SUMA_STDERR, "Error %s: SUMA_Engine call failed.\n", FuncName);
01116             SUMA_RETURN(NOPE);
01117          }
01118 
01119          /* don't free nel, it's freed later on */
01120          SUMA_RETURN(YUP) ;
01121 
01122 
01123       }/* SUMA_irgba */
01124 
01125       /*** If here, then name of element didn't match anything ***/
01126 
01127       fprintf(SUMA_STDERR,"Error %s: Unknown NIML input: %s\n", FuncName ,nel->name) ;
01128       SUMA_RETURN(NOPE) ;
01129    } /* end parse nels */ else { /* is group */
01130       ngr = (NI_group *) nini ;
01131 
01132       if (strcmp(ngr->name,"SurfaceObject") == 0) { /* New Surface Object */
01133          SUMA_SurfaceObject *SOn=NULL;   
01134 
01135          SOn = SUMA_nimlSO2SO(ngr); 
01136          if (!SOn) {
01137             SUMA_SL_Err("Failed to interpret SO");
01138             SUMA_RETURN(NOPE) ;
01139          }
01140 
01141          SUMA_LH("Checking for new surface...");
01142          SO = SUMA_findSOp_inDOv (SOn->idcode_str, SUMAg_DOv, SUMAg_N_DOv);
01143          if (SO) {
01144             fprintf(SUMA_STDERR,"Warning %s: nel idcode was found in DOv.\nChecking for mesh compatibility\n", FuncName);
01145             if (SO->N_FaceSet * SO->FaceSetDim == SOn->N_FaceSet * SOn->FaceSetDim) {
01146                fprintf(SUMA_STDERR,"Note %s: Mesh dimensions match. New mesh will be adopted.\n", FuncName);
01147             } else {
01148                fprintf(SUMA_STDERR,"Error %s: Mesh dimensions mismatch.\n", FuncName);
01149                SUMA_RETURN(NOPE);
01150             }
01151          }
01152 
01153          if (!SO) { 
01154             SUMA_LH("A brand new surface.");
01155             BrandNew = YUP;
01156          } else {
01157             SUMA_LH("A refit of an existing surface.");
01158             BrandNew = NOPE;
01159             if (SOn->N_Node != SO->N_Node) {
01160                fprintf(SUMA_STDERR,"Error %s: Mismatch in number of nodes between new mesh and pre-existing one (%d vs %d)\n", FuncName, SO->N_Node, SO->N_Node);
01161                SUMA_RETURN(NOPE);
01162             }
01163             memcpy((void*)SO->FaceSetList, (void *)SOn->FaceSetList, SOn->N_FaceSet * SOn->FaceSetDim * sizeof(int));  /* this one's likely to be completely useless! */       
01164             memcpy((void*)SO->NodeList, (void *)SOn->NodeList, SOn->N_Node * SOn->NodeDim * sizeof(float));
01165             /* swap VolPar */
01166             if (SOn->VolPar) {
01167                if (SO->VolPar) SUMA_Free_VolPar(SO->VolPar); 
01168                SO->VolPar = SOn->VolPar;
01169                SOn->VolPar = NULL;
01170             }
01171             SUMA_Free_Surface_Object(SOn); SOn = NULL; /* alas, not needed no more. 
01172                                                    Perhaps you should consider eliminating SO's EdgeLists, area vectors and the like,
01173                                                    You should also perhaps update VolPar with SOn's... */
01174          }
01175 
01176          /* add this surface to DOv */
01177          if (BrandNew) {
01178             if (!SUMA_AddDO(SUMAg_DOv, &(SUMAg_N_DOv), (void *)SOn,  SO_type, SUMA_LOCAL)) {
01179                fprintf(SUMA_STDERR,"Error %s: Error Adding DO\n", FuncName);
01180                SUMA_RETURN(NOPE);
01181             }
01182          }
01183 
01184          /* don't free nel, it's freed later on */
01185          SUMA_RETURN(YUP) ;
01186       }
01187    
01188       /*** If here, then name of group didn't match anything ***/
01189       
01190       fprintf(SUMA_STDERR,"Error %s: Unknown NIML input: %s\n", FuncName ,ngr->name) ;
01191       SUMA_RETURN(NOPE) ;
01192    }
01193 }

void SUMA_register_workproc XtWorkProc    func,
XtPointer    data
 

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 }

void SUMA_remove_workproc XtWorkProc    func
 

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 }

void SUMA_remove_workproc2 XtWorkProc    func,
XtPointer    data
 

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 }

SUMA_Boolean SUMA_SendDset_Afni NI_stream    ns,
THD_3dim_dataset   dset,
int    all
 

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 }

SUMA_Boolean SUMA_SendSumaNewSurface SUMA_SurfaceObject   SO,
SUMA_COMM_STRUCT   cs
 

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 }

SUMA_Boolean SUMA_SendToAfni SUMA_COMM_STRUCT   cs,
void *    data,
int    action
 

Function to handle send data elements to AFNI.

Parameters:
cs  (SUMA_COMM_STRUCT *) Communication structure. (initialized when action is 0)
data  (void *) pointer to data that gets typecast as an afni dset
action  (int) 2: Make cleanup call to functions producing nel out of data Close stream 1: Create a nel out of data and send to AFNI 0: start connection with AFNI initialize cs prepare functions producing nels out of data
Returns:
errflag (SUMA_Boolean) YUP: All is OK (although connection might get closed) NOPE: Some'in bad a happening. Connections getting closed in the midst of things are not considered as errors because they should not halt the execution of the main program

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 }

SUMA_Boolean SUMA_SendToSuma SUMA_SurfaceObject   SO,
SUMA_COMM_STRUCT   cs,
void *    data,
SUMA_DSET_TYPE    dtype,
int    action
 

Function to handle send data elements to AFNI.

Parameters:
SO  (SUMA_SurfaceObject *) pointer to surface object structure
cs  (SUMA_COMM_STRUCT *) Communication structure. (initialized when action is 0)
data  (void *) pointer to data that gets typecast as follows: (float *) if dtype == Node_RGBAb or Node_XYZ
dtype  (SUMA_DSET_TYPE) Type of nel to be produced (this determines the typecasting of data)
instanceID  (char *) a unique identifier for the instance of data sent. For data of a particular dtype, use same instanceID for data that is being sent repeatedly
action  (int) 2: Make cleanup call to functions producing nel out of data Close stream 1: Create a nel out of data and send to AFNI 0: start connection with AFNI initialize cs prepare functions producing nels out of data
Returns:
errflag (SUMA_Boolean) YUP: All is OK (although connection might get closed) NOPE: Some'in bad a happening. Connections getting closed in the midst of things are not considered as errors because they should not halt the execution of the main program NOTE: The cleanup automatically closes the connection. That is stupid whenever you need to send multiple types of data for multiple surfaces. Cleanup should be done without closing connections! See comment in function SUMA_SendSumaNewSurface's code. Also, send kth should be more clever, keeping separate counts per datatype and per surface

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 }

NI_element* SUMA_SOVolPar2VolPar_nel SUMA_SurfaceObject   SO,
SUMA_VOLPAR   VolPar,
SUMA_DSET_TYPE    dtype
 

A function to turn the VolPar structure to a nel, this one's a group

See also:
SUMA_VolPar_nel2SOVolPar

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_VOLPAR::idcode_str, SUMA_SurfaceObject::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 }

SUMA_Boolean SUMA_VolPar_nel2SOVolPar SUMA_SurfaceObject   SO,
NI_element   nel
 

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_VOLPAR::idcode_str, SUMA_SurfaceObject::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 }

int SUMA_which_stream_index SUMA_CommonFields   cf,
char *    nel_stream_name
 

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 }

Boolean SUMA_workprocess XtPointer    fred
 

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 }

Variable Documentation

XtPointer* datap = NULL [static]
 

Definition at line 1505 of file SUMA_niml.c.

Referenced by SUMA_register_workproc(), SUMA_remove_workproc(), SUMA_remove_workproc2(), and SUMA_workprocess().

int num_workp = 0 [static]
 

Definition at line 1503 of file SUMA_niml.c.

Referenced by SUMA_register_workproc(), SUMA_remove_workproc(), SUMA_remove_workproc2(), and SUMA_workprocess().

int started = 0 [static]
 

Flag to tell if NIML things are initialized.

Definition at line 16 of file SUMA_niml.c.

SUMA_CommonFields* SUMAg_CF  
 

Global pointer to structure containing info common to all viewers

Definition at line 8 of file SUMA_niml.c.

SUMA_DO* SUMAg_DOv  
 

Global pointer to Displayable Object structure vector

Definition at line 7 of file SUMA_niml.c.

int SUMAg_N_DOv  
 

Number of DOs stored in DOv

Definition at line 6 of file SUMA_niml.c.

Referenced by SUMA_makeNI_CrossHair(), and SUMA_process_NIML_data().

int SUMAg_N_SVv  
 

Number of SVs stored in SVv

Definition at line 10 of file SUMA_niml.c.

Referenced by SUMA_process_NIML_data().

SUMA_SurfaceViewer* SUMAg_SVv  
 

Global pointer to the vector containing the various Surface Viewer Structures

Definition at line 9 of file SUMA_niml.c.

XtWorkProc* workp = NULL [static]
 

Definition at line 1504 of file SUMA_niml.c.

Referenced by SUMA_register_workproc(), SUMA_remove_workproc(), SUMA_remove_workproc2(), and SUMA_workprocess().

XtWorkProcId wpid [static]
 

Definition at line 1506 of file SUMA_niml.c.

Referenced by SUMA_register_workproc(), SUMA_remove_workproc(), and SUMA_remove_workproc2().

 

Powered by Plone

This site conforms to the following standards: