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_Surface_IO.h File Reference

Go to the source code of this file.


Data Structures

struct  SUMA_OPEN_DX_STRUCT

Defines

#define SUMA_MAX_OPEN_DX_FIELD_COMPONENTS   500
#define SUMA_MAX_OPEN_DX_FIELD_ATTRIBUTES   500
#define SUMA_MAX_OPEN_DX_OBJECTS   500
#define SUMA_OK_OPENDX_DATA_TYPE(tp)
#define SUMA_NCOL_OPENDX(dx)   ( ( ( (dx)->shape == 0 ) ? 1 : ((dx)->shape) ) )

Functions

SUMA_SurfaceObjectSUMA_Load_Surface_Object_Wrapper (char *if_name, char *if_name2, char *vp_name, SUMA_SO_File_Type SO_FT, SUMA_SO_File_Format SO_FF, char *sv_name, int debug)
 a function to simplify loading surfaces the old way The only difference with SUMA_Load_Surface_Object_eng is that it takes the file names needed in the first three character pointers usually: if_name1: (char *) name of entire surface file or the coordinates file if_name2: (char *) name of triangulation file vp_name: (char *) name of volume parent file, just for SureFit surfaces.

char * SUMA_RemoveSurfNameExtension (char *Name, SUMA_SO_File_Type oType)
 Removes the standard extension from a dataset filename.

void * SUMA_Prefix2SurfaceName (char *prefix, char *path, char *vp_name, SUMA_SO_File_Type oType, SUMA_Boolean *exists)
 A function to take a prefix (or name) and turn it into the structure needed by SUMA_Save_Surface_Object also sets *exists = YUP if completed filename exists on disk. For surfaces requiring two files, *exists = YUP if any of the files exists - free returned pointer with SUMA_free.

void * SUMA_2Prefix2SurfaceName (char *namecoord, char *nametopo, char *path, char *vp_name, SUMA_SO_File_Type oType, SUMA_Boolean *exists)
 much like SUMA_Prefix2SurfaceName, but handles the case where namecoord and nametopo are not the same consider it a more general version of SUMA_Prefix2SurfaceName

SUMA_Boolean SUMA_SureFit_Read_Coord (char *f_name, SUMA_SureFit_struct *SF)
SUMA_Boolean SUMA_SureFit_Read_Topo (char *f_name, SUMA_SureFit_struct *SF)
void SUMA_Show_SureFit (SUMA_SureFit_struct *SF, FILE *Out)
SUMA_Boolean SUMA_Free_SureFit (SUMA_SureFit_struct *SF)
SUMA_Boolean SUMA_FreeSurfer_Read (char *f_name, SUMA_FreeSurfer_struct *FS)
SUMA_Boolean SUMA_FreeSurfer_Read_eng (char *f_name, SUMA_FreeSurfer_struct *FS, int debug)
SUMA_Boolean SUMA_FreeSurfer_ReadBin_eng (char *f_name, SUMA_FreeSurfer_struct *FS, int debug)
SUMA_Boolean SUMA_Free_FreeSurfer (SUMA_FreeSurfer_struct *FS)
void SUMA_Show_FreeSurfer (SUMA_FreeSurfer_struct *FS, FILE *Out)
SUMA_Boolean SUMA_Ply_Read (char *f_name, SUMA_SurfaceObject *SO)
 Reads a Ply formatted file into a SUMA_SurfaceObject structure ans = SUMA_Ply_Read (f_name, SO);.

SUMA_Boolean SUMA_Ply_Write (char *f_name, SUMA_SurfaceObject *SO)
 Writes an SO into a .ply file ans = SUMA_Ply_Write (f_name, SO);.

SUMA_Boolean SUMA_VEC_Write (SUMA_SFname *Fname, SUMA_SurfaceObject *SO)
 writes the NodeList and FaceSetList of SO to 2 ascii files ans = SUMA_Boolean SUMA_VEC_Write (SUMA_SFname *Fname, SUMA_SurfaceObject *SO);

SUMA_Boolean SUMA_VEC_Read (SUMA_SFname *Fname, SUMA_SurfaceObject *SO)
 function to read 1D (vec) format surfaces

SUMA_Boolean SUMA_FS_Write (char *fileNm, SUMA_SurfaceObject *SO, char *firstLine)
 Function to write a surface object to a FreeSurfer .asc file format ans = SUMA_Boolean SUMA_FS_Write (fileNm, SO, firstLine);.

SUMA_Boolean SUMA_SureFit_Write (SUMA_SFname *Fname, SUMA_SurfaceObject *SO)
 writes a surface in SureFit format ans = SUMA_SureFit_Write (Fname,SO);

void SUMA_SaveDrawnROI (char *filename, void *data)
 handles saving ROI to filename.

SUMA_Boolean SUMA_SaveDrawnROI_1D (char *filename, SUMA_SurfaceObject *SO, SUMA_DRAWN_ROI *DrawnROI, int SaveWhat)
SUMA_Boolean SUMA_SaveDrawnROINIML (char *filename, SUMA_SurfaceObject *SO, SUMA_DRAWN_ROI *DrawnROI, int SaveWhat, int Format)
SUMA_1D_DRAWN_ROISUMA_Free_1DDrawROI (SUMA_1D_DRAWN_ROI *ROI1D)
 frees a ROI_1D structure. These structures are created by the likes of SUMA_DrawnROI_to_1DDrawROI

SUMA_Boolean SUMA_Write_DrawnROI_1D (SUMA_DRAWN_ROI **ROIv, int N_ROI, char *filename)
 writes a vector of SUMA_DRAWN_ROI * to disk in afni's 1D ascii format

SUMA_1D_DRAWN_ROISUMA_DrawnROI_to_1DDrawROI (SUMA_DRAWN_ROI *ROI)
 A function to take a SUMA_DRAWN_ROI struct and return an equivalent SUMA_1D_DRAWN_ROI struct.

SUMA_DRAWN_ROI ** SUMA_OpenDrawnROI_NIML (char *filename, int *N_ROI, SUMA_Boolean ForDisplay)
 Loads a niml ROI.

SUMA_DRAWN_ROI ** SUMA_OpenDrawnROI_1D (char *filename, char *Parent_idcode_str, int *N_ROI, SUMA_Boolean ForDisplay)
void SUMA_OpenDrawnROI (char *filename, void *data)
 A function to write a Surface Object into a Surefit ascii format Handles opening an ROI file.

SUMA_DSETSUMA_ROIv2Grpdataset (SUMA_DRAWN_ROI **ROIv, int N_ROIv, char *Parent_idcode_str, int Pad_to, int Pad_val)
 turns a bunch of ROIs into a NI dataset A new version of SUMA_ROIv2dataset that allows the use of dsets as groups

NI_elementSUMA_ROIv2dataset (SUMA_DRAWN_ROI **ROIv, int N_ROIv, char *Parent_idcode_str, int pad_to, int pad_val)
 turns a bunch of ROIs into a NI dataset

void SUMA_SaveSOascii (char *filename, void *data)
 handles savinf SO to ascii filename

float * SUMA_readFScurv (char *f_name, int *nrows, int *ncols, SUMA_Boolean rowmajor, SUMA_Boolean SkipCoords)
 v = SUMA_readFScurv (curvname, nrows, ncols, rowmajor, SkipCoords); Not terribly useful of a function because it is practically a .1D format!

SUMA_Boolean SUMA_BrainVoyager_Read (char *f_name, SUMA_SurfaceObject *SO, int debug)
 Load a brain voyager surface model from a .srf file.

SUMA_Boolean SUMA_FreeSurfer_WritePatch (char *fileNm, SUMA_SurfaceObject *SO, char *firstLine, SUMA_SurfaceObject *SOparent)
SUMA_FORM_AFNI_DSET_STRUCTSUMA_New_FormAfniDset_Opt (void)
SUMA_FORM_AFNI_DSET_STRUCTSUMA_Free_FormAfniDset_Opt (SUMA_FORM_AFNI_DSET_STRUCT *Opt)
THD_3dim_datasetSUMA_FormAfnidset (float *NodeList, float *vals, int N_vals, SUMA_FORM_AFNI_DSET_STRUCT *Opt)
NI_groupSUMA_SO2nimlSO (SUMA_SurfaceObject *SO, char *optlist, int nlee)
 A function to change a SurfaceObject to niml format.

SUMA_SurfaceObjectSUMA_nimlSO2SO (NI_group *ngr)
SUMA_OPEN_DX_STRUCTSUMA_Alloc_OpenDX_Struct (void)
SUMA_OPEN_DX_STRUCTSUMA_Free_OpenDX_Struct (SUMA_OPEN_DX_STRUCT *dx)
SUMA_OPEN_DX_STRUCT ** SUMA_Free_OpenDX_StructVec (SUMA_OPEN_DX_STRUCT **dxv, int nobj)
void SUMA_Show_OpenDX_Struct (SUMA_OPEN_DX_STRUCT **dxv, int N_dxv, FILE *out)
SUMA_Boolean SUMA_OpenDX_Write (char *fname, SUMA_SurfaceObject *SO)
SUMA_Boolean SUMA_OpenDx_Object_Data (char *op, int nchar, SUMA_OPEN_DX_STRUCT *dx)
 get the data values

SUMA_Boolean SUMA_OpenDx_Object_Attr (char *op, int nchar, SUMA_OPEN_DX_STRUCT *dx)
 return values of an attribute from an OpenDX object string

SUMA_Boolean SUMA_OpenDx_Object_Components (char *op, int nchar, SUMA_OPEN_DX_STRUCT *dx)
 return values of an attribute from an OpenDX object string

void * SUMA_OpenDx_Object_Header_Field (char *op, int nchar, const char *attr, char **op_end)
 return values of a header field from an OpenDX object string If you expect an int back like when attr is "rank" or "shape" ans should be type cast to (int *) before use: int ival; ival = *((int *)ans); If you expect a bunch of numbers like for "counts" "origin" "delta" then ans is (SUMA_IVEC *) or (SUMA_FVEC*) or (SUMA_DVEC *) These are freed with SUMA_free(ans->v); SUMA_free(ans); else ans should be type cast to (char **) before use: char *sval; sval = *((char **)ans); then free sval with SUMA_free(sval);

SUMA_OPEN_DX_STRUCT ** SUMA_OpenDX_Read (char *fname, int *nobj)
SUMA_OPEN_DX_STRUCTSUMA_Find_OpenDX_Object_Name (SUMA_OPEN_DX_STRUCT **dxv, int iop, char *nm, int *nf)
 returns structure containing object of a certain name in dxv do not free returned structure since it is a copy of pointer in dxv

SUMA_OPEN_DX_STRUCTSUMA_Find_OpenDX_Object_Class (SUMA_OPEN_DX_STRUCT **dxv, int iop, char *nm, int *nf)
 returns structure containing object of a certain class in dxv do not free returned structure since it is a copy of pointer in dxv

SUMA_Boolean SUMA_OpenDX_Read_SO (char *fname, SUMA_SurfaceObject *SO)
 reads an OpenDX surface. Sample surfaces provided by Aaron Carass

char * SUMA_OpenDX_Read_CruiseVolHead (char *fname, THD_3dim_dataset *dset, int loaddata)

Define Documentation

#define SUMA_MAX_OPEN_DX_FIELD_ATTRIBUTES   500
 

Definition at line 5 of file SUMA_Surface_IO.h.

Referenced by SUMA_Alloc_OpenDX_Struct(), and SUMA_Free_OpenDX_Struct().

#define SUMA_MAX_OPEN_DX_FIELD_COMPONENTS   500
 

Definition at line 4 of file SUMA_Surface_IO.h.

Referenced by SUMA_Alloc_OpenDX_Struct(), and SUMA_Free_OpenDX_Struct().

#define SUMA_MAX_OPEN_DX_OBJECTS   500
 

Definition at line 6 of file SUMA_Surface_IO.h.

Referenced by SUMA_OpenDX_Read().

#define SUMA_NCOL_OPENDX dx       ( ( ( (dx)->shape == 0 ) ? 1 : ((dx)->shape) ) )
 

Definition at line 40 of file SUMA_Surface_IO.h.

Referenced by SUMA_OpenDX2dset(), SUMA_OpenDx_Object_Data(), and SUMA_Show_OpenDX_Struct().

#define SUMA_OK_OPENDX_DATA_TYPE tp   
 

Value:

( (  tp == SUMA_int || \
                                          tp == SUMA_float ||  \
                                          tp == SUMA_double || \
                                          tp == SUMA_byte )   \
                                           ? 1 : 0 )

Definition at line 34 of file SUMA_Surface_IO.h.

Referenced by SUMA_Free_OpenDX_Struct(), and SUMA_strtol_vec().


Function Documentation

void* SUMA_2Prefix2SurfaceName char *    namecoord,
char *    nametopo,
char *    path,
char *    vp_name,
SUMA_SO_File_Type    oType,
SUMA_Boolean   exists
 

much like SUMA_Prefix2SurfaceName, but handles the case where namecoord and nametopo are not the same consider it a more general version of SUMA_Prefix2SurfaceName

Definition at line 171 of file SUMA_Surface_IO.c.

References SUMA_SFname::name_topo, SUMA_Boolean, SUMA_ENTRY, SUMA_free, SUMA_Prefix2SurfaceName(), SUMA_RETURN, SUMA_SL_Err, SUMA_SO_File_Type, SUMA_SUREFIT, and SUMA_VEC.

00172 {
00173    static char FuncName[]={"SUMA_2Prefix2SurfaceName"};
00174    SUMA_Boolean exist1, exist2;
00175    SUMA_SFname *SF_name1 = NULL, *SF_name2 = NULL;
00176    
00177    SUMA_ENTRY;
00178    
00179    if (!nametopo && !namecoord) { SUMA_RETURN(NULL); }
00180    
00181    if (!nametopo) SUMA_RETURN(SUMA_Prefix2SurfaceName (namecoord, path, vp_name, oType, exists));
00182    if (!namecoord) SUMA_RETURN(SUMA_Prefix2SurfaceName (nametopo, path, vp_name, oType, exists));
00183    
00184    if (strcmp(namecoord, nametopo) == 0) SUMA_RETURN(SUMA_Prefix2SurfaceName (nametopo, path, vp_name, oType, exists));
00185    if (oType != SUMA_SUREFIT && oType != SUMA_VEC) {
00186       SUMA_SL_Err("Wrong usage of function, namecoord and nametopo are different but surface type is neither SUMA_SUREFIT nor SUMA_VEC");
00187       SUMA_RETURN(NULL);
00188    }
00189    
00190    /* the pain in the behind case */
00191    SF_name1 = SUMA_Prefix2SurfaceName (namecoord, path, vp_name, oType, &exist1);
00192    if (!SF_name1) {
00193       SUMA_SL_Err("Failed to create name");
00194       SUMA_RETURN(NULL);
00195    }
00196    SF_name2 = SUMA_Prefix2SurfaceName (nametopo, path, vp_name, oType, &exist2);
00197    if (!SF_name2) {
00198       SUMA_free(SF_name1); SF_name1= NULL;
00199       SUMA_SL_Err("Failed to create name");
00200       SUMA_RETURN(NULL);
00201    }
00202    
00203    if (exist1 || exist2) *exists = YUP;
00204    
00205    sprintf(SF_name1->name_topo, "%s", SF_name2->name_topo);
00206    SUMA_free(SF_name2); SF_name2= NULL;
00207    
00208    SUMA_RETURN(SF_name1);
00209 }  

SUMA_OPEN_DX_STRUCT* SUMA_Alloc_OpenDX_Struct void   
 

END ATTRIBUTES specific to Surfaces*

Definition at line 7397 of file SUMA_Surface_IO.c.

References SUMA_OPEN_DX_STRUCT::attr_name, SUMA_OPEN_DX_STRUCT::attr_string, SUMA_OPEN_DX_STRUCT::bad_data, SUMA_OPEN_DX_STRUCT::class, SUMA_OPEN_DX_STRUCT::comp_name, SUMA_OPEN_DX_STRUCT::comp_value, SUMA_OPEN_DX_STRUCT::counts, SUMA_OPEN_DX_STRUCT::data, SUMA_OPEN_DX_STRUCT::data_format, SUMA_OPEN_DX_STRUCT::data_off, SUMA_OPEN_DX_STRUCT::datap, SUMA_OPEN_DX_STRUCT::delta, i, SUMA_OPEN_DX_STRUCT::items, SUMA_OPEN_DX_STRUCT::n_attr, SUMA_OPEN_DX_STRUCT::n_comp, SUMA_OPEN_DX_STRUCT::n_counts, SUMA_OPEN_DX_STRUCT::n_delta, SUMA_OPEN_DX_STRUCT::n_origin, SUMA_OPEN_DX_STRUCT::object, SUMA_OPEN_DX_STRUCT::origin, SUMA_OPEN_DX_STRUCT::rank, SUMA_OPEN_DX_STRUCT::shape, SUMA_ENTRY, SUMA_malloc, SUMA_MAX_OPEN_DX_FIELD_ATTRIBUTES, SUMA_MAX_OPEN_DX_FIELD_COMPONENTS, SUMA_RETURN, and SUMA_OPEN_DX_STRUCT::type.

Referenced by SUMA_OpenDX_Read().

07398 {
07399    static char FuncName[]={"SUMA_Alloc_OpenDX_Struct"};
07400    int i;
07401    SUMA_OPEN_DX_STRUCT *dx = NULL;
07402    
07403    SUMA_ENTRY;
07404    
07405    dx = (SUMA_OPEN_DX_STRUCT *)SUMA_malloc(sizeof(SUMA_OPEN_DX_STRUCT));
07406    dx->rank = 0;
07407    dx->shape = 0;
07408    dx->items = 0;
07409    dx->bad_data = 0;
07410    dx->object = NULL;
07411    dx->class = NULL;
07412    dx->type = NULL;
07413    dx->data = NULL;
07414    dx->data_format = 0;
07415    dx->data_off = NULL;
07416    dx->datap = NULL;
07417    dx->n_comp = 0;
07418    dx->counts = NULL;
07419    dx->n_counts = 0;
07420    dx->origin = NULL;
07421    dx->n_origin = 0;
07422    dx->delta = NULL;
07423    dx->n_delta = 0;
07424    for (i=0; i<SUMA_MAX_OPEN_DX_FIELD_COMPONENTS; ++i) { dx->comp_name[i] = dx->comp_value[i] =NULL; }
07425    dx->n_attr = 0;
07426    for (i=0; i<SUMA_MAX_OPEN_DX_FIELD_ATTRIBUTES; ++i) { dx->attr_name[i] = dx->attr_string[i] =NULL; }
07427    SUMA_RETURN(dx);
07428 }

SUMA_Boolean SUMA_BrainVoyager_Read char *    f_name,
SUMA_SurfaceObject   SO,
int    debug
 

Load a brain voyager surface model from a .srf file.

Thanks to Nikolaus Kriegeskorte for code snippets and help.

The following fields are set in SO: SO->NodeDim SO->FaceSetDim SO->NodeList SO->FaceSetList SO->N_Node; SO->N_FaceSet; SO->Name; SO->FileType; SO->FileFormat

Definition at line 2506 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::FileFormat, SUMA_SurfaceObject::FileType, i, LocalHead, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SurfaceObject::Name, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, SUMA_BINARY, SUMA_Boolean, SUMA_BRAIN_VOYAGER, SUMA_ENTRY, SUMA_filexists(), SUMA_float, SUMA_free, SUMA_int, SUMA_LH, SUMA_malloc, SUMA_MIN_PAIR, SUMA_READ_FLOAT, SUMA_RETURN, SUMA_ShowMeSome(), SUMA_SL_Crit, SUMA_SL_Err, SUMA_SL_Warn, SUMA_StripPath(), SUMA_SWAP_THIS, and SUMA_SWAP_VEC.

Referenced by SUMA_Load_Surface_Object_eng().

02507 {
02508    static char FuncName[]={"SUMA_BrainVoyager_Read"};
02509         float FileVersion, cx, cy, cz, *fbuf = NULL;
02510         int i, ii, chnk, ex, surf_type, n_neighbors, bs;
02511         char buffer[256];
02512    float fbuffer[256];
02513    FILE *fl=NULL;
02514    SUMA_Boolean LocalHead = NOPE;
02515    
02516    SUMA_ENTRY;
02517    
02518    /* check for existence */
02519         if (!SUMA_filexists(f_name)) {
02520                 fprintf(SUMA_STDERR,"Error %s: File %s does not exist or cannot be read.\n", FuncName, f_name);
02521                 SUMA_RETURN (NOPE);
02522         }else {
02523       if ( debug > 1) {
02524                    fprintf(SUMA_STDERR,"%s: File %s exists and will be read.\n", FuncName, f_name);
02525            }
02526    }
02527         
02528    fl = fopen(f_name, "r");
02529    if (!fl) {
02530       SUMA_SL_Err("Failed to open file for reading.\n");
02531       SUMA_RETURN(NOPE);
02532    }
02533    
02534    SO->N_Node=0;
02535         SO->N_FaceSet=0;
02536    
02537    /* read version, and number of nodes and facesets, assume no swapping for the moment */
02538    bs = 0;
02539    chnk = sizeof(float);
02540    ex = fread (&FileVersion, chnk, 1, fl);
02541    chnk = sizeof(int);
02542    ex = fread (&surf_type, chnk, 1, fl); /* must be 0, per website www.brainvoyager.com... */
02543    ex = fread (&(SO->N_Node), chnk, 1, fl);
02544    ex = fread (&(SO->N_FaceSet), chnk, 1, fl);
02545    if (FileVersion < 0 || FileVersion > 500000 || SO->N_Node < 0 || SO->N_FaceSet < 0) { /* trouble perhaps ? */
02546       SUMA_LH("Byte swapping needed...");
02547       bs = 1;
02548    }
02549    if (bs) {
02550       SUMA_SWAP_THIS(&FileVersion, sizeof(float));
02551       SUMA_SWAP_THIS(&surf_type, sizeof(int));
02552       SUMA_SWAP_THIS(&(SO->N_Node), sizeof(int));
02553       SUMA_SWAP_THIS(&(SO->N_FaceSet), sizeof(int));
02554    }
02555    
02556    if (LocalHead) {
02557       fprintf (SUMA_STDERR,"%s:\nSurfType is %d\nN_Node = %d, N_FaceSet = %d\n", 
02558                            FuncName, surf_type, SO->N_Node, SO->N_FaceSet);
02559    }
02560    
02561    if (FileVersion < 0 || FileVersion > 500000) { /* trouble perhaps ? */
02562       SUMA_SL_Err("Version number < 0 || > 500000 \nSeems like bad news to me, quitting...");
02563       fclose(fl);
02564       SUMA_RETURN(NOPE);
02565    }
02566    
02567    
02568    if (SO->N_Node < 0 || SO->N_FaceSet < 0) {
02569       SUMA_SL_Err("Negative values for N_Node and N_FaceSet.");
02570       fclose(fl);
02571       SUMA_RETURN(NOPE);
02572    } 
02573    
02574    SUMA_READ_FLOAT(&cx, bs, fl, ex);
02575    SUMA_READ_FLOAT(&cy, bs, fl, ex);
02576    SUMA_READ_FLOAT(&cz, bs, fl, ex);
02577    if (LocalHead) {
02578       fprintf (SUMA_STDERR,"%s:\ncenter = [%f, %f, %f]\n(Niko adds 30 to cy ...)\n", FuncName, cx, cy, cz);
02579    }
02580    SO->NodeDim = 3;
02581    SO->FaceSetDim = 3;
02582    fbuf = (float *)SUMA_malloc(SO->N_Node*sizeof(float));
02583    SO->NodeList = (float *)SUMA_malloc(SO->NodeDim*SO->N_Node*sizeof(float));
02584    SO->FaceSetList = (int *)SUMA_malloc(SO->FaceSetDim*SO->N_FaceSet*sizeof(int));
02585    if (!fbuf || !SO->NodeList || !SO->FaceSetList) {
02586       SUMA_SL_Crit("Failed to allocate.");
02587       SUMA_RETURN(NOPE);
02588    }
02589    
02590    /* read the coords */
02591    SUMA_LH("Reading coords...");
02592    ex = fread(fbuf, sizeof(float), SO->N_Node, fl);
02593    if (ex != SO->N_Node) { SUMA_SL_Warn("Failed to read all node X info"); }
02594    if (bs) SUMA_SWAP_VEC(fbuf,SO->N_Node,sizeof(float));
02595    for (i=0; i<SO->N_Node; ++i) SO->NodeList[3*i] = fbuf[i];
02596    ex = fread(fbuf, sizeof(float), SO->N_Node, fl);
02597    if (ex != SO->N_Node) { SUMA_SL_Warn("Failed to read all node Y info"); }
02598    if (bs) SUMA_SWAP_VEC(fbuf,SO->N_Node,sizeof(float));
02599    for (i=0; i<SO->N_Node; ++i) SO->NodeList[3*i+1] = fbuf[i];
02600    ex = fread(fbuf, sizeof(float), SO->N_Node, fl);
02601    if (ex != SO->N_Node) { SUMA_SL_Warn("Failed to read all node Z info"); }
02602    if (bs) SUMA_SWAP_VEC(fbuf,SO->N_Node,sizeof(float));
02603    for (i=0; i<SO->N_Node; ++i) SO->NodeList[3*i+2] = fbuf[i];
02604    SUMA_free(fbuf); fbuf = NULL;
02605    if (LocalHead) { 
02606       char *sdbg = SUMA_ShowMeSome((void *)SO->NodeList, SUMA_float, SUMA_MIN_PAIR(20, SO->N_Node), 20);
02607       fprintf(SUMA_STDERR,"%s NodeList:\n%s\n", FuncName, sdbg);
02608       SUMA_free(sdbg);sdbg = NULL;
02609    }
02610    /* skip the node normals, which would be read much like the x y z coords*/
02611    fseek(fl, SO->N_Node*3*sizeof(float), SEEK_CUR);
02612    
02613    /* skip the curvature color info */
02614    ex = fread(fbuffer, sizeof(float), 8, fl); /* colors of convex and concave stuff */
02615    if (bs) SUMA_SWAP_VEC(fbuffer,8, sizeof(float));
02616    if (LocalHead) { 
02617       char *sdbg = SUMA_ShowMeSome((void *)fbuffer, SUMA_float, 8,8);
02618       fprintf(SUMA_STDERR,"%s colorstuff:\n%s\n", FuncName, sdbg);
02619       SUMA_free(sdbg);sdbg = NULL;
02620    }
02621    fseek(fl, SO->N_Node*sizeof(float), SEEK_CUR); /* junp over mesh color */
02622    
02623    /* skip nearest neighbor info */
02624    for (i=0; i<SO->N_Node; ++i) {
02625       ex = fread(&n_neighbors, sizeof(int), 1, fl);
02626       if (bs) SUMA_SWAP_THIS(&n_neighbors, sizeof(int));
02627       fseek(fl, n_neighbors*sizeof(int), SEEK_CUR);
02628    }
02629    
02630    /* read dems triangles */
02631    SUMA_LH("Reading FaceSets...");
02632    ex = fread(SO->FaceSetList, sizeof(int), SO->N_FaceSet * SO->FaceSetDim , fl);
02633    if (ex != SO->N_FaceSet * SO->FaceSetDim) { 
02634       fprintf(SUMA_STDERR,"Error %s: Failed to read all faceset info.\nRead %d values, expected %d\n", FuncName, ex, SO->N_FaceSet * SO->FaceSetDim );
02635       SUMA_RETURN(NOPE);
02636    }
02637    
02638    if (bs) SUMA_SWAP_VEC(SO->FaceSetList,(SO->N_FaceSet * SO->FaceSetDim),sizeof(int));
02639    if (LocalHead) { 
02640       char *sdbg = SUMA_ShowMeSome((void *)SO->FaceSetList, SUMA_int, SUMA_MIN_PAIR(20, SO->N_FaceSet * SO->FaceSetDim), 20);
02641       fprintf(SUMA_STDERR,"%s FaceSetList:\n%s\n", FuncName, sdbg);
02642       SUMA_free(sdbg);sdbg = NULL;
02643    }
02644    fclose(fl); fl = NULL;
02645    
02646    SO->FileType = SUMA_BRAIN_VOYAGER;
02647    SO->Name = SUMA_StripPath(f_name);
02648    SO->FileFormat = SUMA_BINARY;    /* files are likely all BINARY_LE, must take care of that at some point*/
02649    
02650    SUMA_LH("Done.");
02651    
02652    SUMA_RETURN(YUP);
02653 }

SUMA_1D_DRAWN_ROI* SUMA_DrawnROI_to_1DDrawROI SUMA_DRAWN_ROI   ROI
 

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

See also:
SUMA_Free_1DDrawROI

Definition at line 6182 of file SUMA_Surface_IO.c.

References DListElmt_::data, dlist_head, dlist_tail, i, SUMA_DRAWN_ROI::idcode_str, SUMA_1D_DRAWN_ROI::idcode_str, SUMA_DRAWN_ROI::iLabel, SUMA_1D_DRAWN_ROI::iLabel, SUMA_1D_DRAWN_ROI::iNode, SUMA_DRAWN_ROI::Label, SUMA_1D_DRAWN_ROI::Label, LocalHead, SUMA_1D_DRAWN_ROI::N, SUMA_ROI_DATUM::N_n, DListElmt_::next, SUMA_ROI_DATUM::nPath, SUMA_DRAWN_ROI::Parent_idcode_str, SUMA_1D_DRAWN_ROI::Parent_idcode_str, SUMA_DRAWN_ROI::ROIstrokelist, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_free, SUMA_malloc, SUMA_RETURN, SUMA_SL_Err, SUMA_z_dqsort(), SUMA_DRAWN_ROI::Type, and SUMA_1D_DRAWN_ROI::Type.

Referenced by SUMA_Write_DrawnROI_1D().

06183 {
06184    static char FuncName[]={"SUMA_DrawnROI_to_1DDrawROI"};
06185    SUMA_1D_DRAWN_ROI *ROI_1D=NULL;
06186    SUMA_ROI_DATUM *ROI_Datum=NULL;
06187    DListElmt *Elm = NULL;
06188    int i = -1, cnt = 0, *isort=NULL, *iLabel=NULL, *iNode=NULL;
06189    SUMA_Boolean LocalHead = NOPE;
06190 
06191    SUMA_ENTRY;
06192 
06193    if (!ROI) {
06194       SUMA_SL_Err("Null ROI");
06195       SUMA_RETURN(NULL);
06196    }
06197    
06198    /* count the total number of nodes in ROI */
06199    
06200    /* allocate for nimlROI */
06201    ROI_1D = (SUMA_1D_DRAWN_ROI *)SUMA_malloc(sizeof(SUMA_1D_DRAWN_ROI));
06202    Elm = NULL;
06203    ROI_1D->N = 0;
06204    do {
06205       if (!Elm) Elm = dlist_head(ROI->ROIstrokelist); 
06206       else Elm = Elm->next;
06207       ROI_Datum = (SUMA_ROI_DATUM *)Elm->data;
06208       ROI_1D->N += ROI_Datum->N_n;
06209    } while (Elm != dlist_tail(ROI->ROIstrokelist));
06210       
06211    ROI_1D->Type = (int)ROI->Type;
06212    ROI_1D->idcode_str = ROI->idcode_str;
06213    ROI_1D->Parent_idcode_str = ROI->Parent_idcode_str;
06214    ROI_1D->Label = ROI->Label;
06215    ROI_1D->iNode = NULL;
06216    ROI_1D->iLabel = NULL;
06217    iNode = (int *) SUMA_calloc(ROI_1D->N, sizeof(int));
06218    iLabel = (int *) SUMA_calloc(ROI_1D->N, sizeof(int));
06219    if (!iNode || !iLabel) {
06220       SUMA_SL_Err("Failed to allocate");
06221       SUMA_RETURN(NULL);
06222    }
06223    
06224    /* now fill the node indices and the node values */
06225    Elm = NULL;
06226    cnt = 0;
06227    do {
06228       if (!Elm) Elm = dlist_head(ROI->ROIstrokelist);
06229       else Elm = Elm->next;
06230       ROI_Datum = (SUMA_ROI_DATUM *)Elm->data;
06231       for (i=0; i < ROI_Datum->N_n; ++i) {
06232          iNode[cnt] = ROI_Datum->nPath[i];
06233          iLabel[cnt] = ROI->iLabel;
06234          ++cnt;
06235       }
06236    } while (Elm != dlist_tail(ROI->ROIstrokelist));
06237    
06238    /* some node entries are redundant, clear those up */
06239    /* first sort iNode */
06240    isort = SUMA_z_dqsort( iNode, ROI_1D->N);
06241 
06242    /* Now sort the labels accordingly */
06243    ROI_1D->iLabel = (int *) SUMA_calloc(ROI_1D->N, sizeof(int));
06244    ROI_1D->iNode = (int *) SUMA_calloc(ROI_1D->N, sizeof(int));
06245    if (!ROI_1D->iNode || !ROI_1D->iLabel) {
06246       SUMA_SL_Err("Failed to allocate");
06247       SUMA_RETURN(NULL);
06248    }
06249    
06250    for (i=0; i < ROI_1D->N; ++i) {
06251       ROI_1D->iLabel[i] = iLabel[isort[i]];
06252    }
06253    if (iLabel) SUMA_free(iLabel); iLabel = NULL; /* done with unsorted version of iLabel */
06254    
06255    /* Now remove redundant entries */
06256    cnt = 0;
06257    ROI_1D->iNode[cnt] = iNode[0]; 
06258    ROI_1D->iLabel[cnt] = ROI_1D->iLabel[0];
06259    ++cnt;
06260    for (i=1;i<ROI_1D->N;++i)
06261     {
06262       if ((iNode[i] != iNode[i- 1]))
06263          {
06264             ROI_1D->iNode[cnt] = iNode[i];
06265             ROI_1D->iLabel[cnt] = ROI_1D->iLabel[i]; 
06266             ++cnt;   
06267          }
06268    }
06269 
06270    
06271    /* you would reallocate here, because cnt is always <= ROI_1D->N,
06272    but it is not worth the effort because cnt is only slightly
06273    less than ROI_1D->N */
06274    
06275    /* just update ROI_1D->N */
06276    ROI_1D->N = cnt;
06277    
06278    if (isort) SUMA_free(isort); isort = NULL;
06279    if (iNode) SUMA_free(iNode); iNode = NULL;
06280    
06281    SUMA_RETURN(ROI_1D);
06282 }

SUMA_OPEN_DX_STRUCT* SUMA_Find_OpenDX_Object_Class SUMA_OPEN_DX_STRUCT **    dxv,
int    iop,
char *    nm,
int *    nf
 

returns structure containing object of a certain class in dxv do not free returned structure since it is a copy of pointer in dxv

Definition at line 8130 of file SUMA_Surface_IO.c.

References i, LocalHead, SUMA_Boolean, SUMA_ENTRY, and SUMA_RETURN.

Referenced by SUMA_OpenDX_Read_CruiseVolHead(), and SUMA_OpenDX_Read_SO().

08131 {
08132    static char FuncName[]={"SUMA_Find_OpenDX_Object_Class"};
08133    int i;
08134    SUMA_OPEN_DX_STRUCT *dx = NULL;
08135    SUMA_Boolean LocalHead = NOPE;
08136    
08137    SUMA_ENTRY;
08138    
08139    *nf = 0;
08140    for (i=0; i<iop; ++i) {
08141       if (strstr(dxv[i]->class, nm)) { 
08142          if (!dx) dx = dxv[i]; 
08143          ++ (*nf);
08144       }
08145    }
08146    
08147    if (LocalHead) fprintf(SUMA_STDERR,"%s: Found %d objects\n", FuncName, *nf);
08148    SUMA_RETURN(dx);
08149 }

SUMA_OPEN_DX_STRUCT* SUMA_Find_OpenDX_Object_Name SUMA_OPEN_DX_STRUCT **    dxv,
int    iop,
char *    nm,
int *    nf
 

returns structure containing object of a certain name in dxv do not free returned structure since it is a copy of pointer in dxv

Definition at line 8106 of file SUMA_Surface_IO.c.

References i, LocalHead, object, SUMA_Boolean, SUMA_ENTRY, and SUMA_RETURN.

Referenced by SUMA_OpenDX_Read_CruiseVolHead(), and SUMA_OpenDX_Read_SO().

08107 {
08108    static char FuncName[]={"SUMA_Find_OpenDX_Object_Name"};
08109    int i;
08110    SUMA_OPEN_DX_STRUCT *dx = NULL;
08111    SUMA_Boolean LocalHead = NOPE;
08112    
08113    SUMA_ENTRY;
08114    
08115    *nf = 0;
08116    for (i=0; i<iop; ++i) {
08117       if (strstr(dxv[i]->object, nm)) { 
08118          if (!dx) dx = dxv[i]; 
08119          ++ (*nf);
08120       }
08121    }
08122    
08123    if (LocalHead) fprintf(SUMA_STDERR,"%s: Found %d objects\n", FuncName, *nf);
08124    SUMA_RETURN(dx);
08125 }

THD_3dim_dataset* SUMA_FormAfnidset float *    NodeList,
float *    vals,
int    N_vals,
SUMA_FORM_AFNI_DSET_STRUCT   Opt
 

(stolen from 3dUndump)

Parameters:
NodeList  (float *) (3*N_valsx1) XYZ or IJK coordinates. Can be NULL if Opt->full_list = 1. &(NodeList[3*n]) is the pointer for the coordinates of entry ni
vals  (float *) (N_valsx1) vector of values. Can be NULL, in which case the default value in Opt is used.
N_vals  (int) number of values. If Opt->full_list then N_vals must be equal to the number of voxels in the data set (dimen_ii*dimen_jj*dimen_kk) as specified by Opt's fields or the master set.
Opt  (SUMA_FORM_AFNI_DSET_STRUCT *) The famed options structure: master: Name of master dset. NULL if none mask: Name of mask dset. NULL if none. prefix: Prefix of output. Must have. orcode: Orientation string. NULL if none, like RAI, LPI, etc. do_ijk: 1 = coordinates in NodeList are voxel indices (i j k) 0 = coordinates in NodeList are voxel dicomm coordinates (x y z) dimen_ii(_jj, _kk): Number of voxels in ii (jj, kk) directions. Do not use with master option Must use either master or dimen options. datum: output data type: MRI_short(default), MRI_byte, MRI_float only. dval: Default data value (default 1). Used if vals is NULL fval: Default fill value (default 0). mmask: (byte *) mask of (dimen_ii*dimen_jj*dimen_kk x 1) values always. This can be used to pass a predefined mask. NULL if not interested in it. Cannot specify it along with mask option above. If both NodeList and Vals are null, then mmask is used as data, replaces vals in a way. If mmask points to non NULL, the memory at that pointer is freed when Opt is freed. full_list: 1 = full list, coordinates are inferred from 1D index of array. N_vals == dimen_ii*dimen_jj*dimen_kk. Requires NodeList == NULL 0 = not a full list NodeList != NULL
  • See SUMA_Free_FormAfniDset_Opt for freeing Opt and its contents
Returns:
dset (THD_3dim_dataset *) output dset. Write it to disk with : DSET_write(dset) ; Delete it with: DSET_delete(dset); dset = NULL;

  • FUNCTION NOT FULLY TESTED for all options, USE WITH CARE : Feb 08 05

Definition at line 6469 of file SUMA_Surface_IO.c.

References ADN_datum_all, ADN_directory_name, ADN_func_type, ADN_none, ADN_ntt, ADN_nvals, ADN_nxyz, ADN_prefix, ADN_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, BYTEIZE, SUMA_FORM_AFNI_DSET_STRUCT::datum, THD_3dim_dataset::daxes, SUMA_FORM_AFNI_DSET_STRUCT::dimen_ii, SUMA_FORM_AFNI_DSET_STRUCT::dimen_jj, SUMA_FORM_AFNI_DSET_STRUCT::dimen_kk, SUMA_FORM_AFNI_DSET_STRUCT::do_ijk, DSET_BRICK_ARRAY, DSET_delete, DSET_HEADNAME, DSET_NX, DSET_NY, DSET_NZ, SUMA_FORM_AFNI_DSET_STRUCT::dval, EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), free, SUMA_FORM_AFNI_DSET_STRUCT::full_list, FUNC_FIM_TYPE, THD_3dim_dataset::func_type, SUMA_FORM_AFNI_DSET_STRUCT::fval, HEAD_FUNC_TYPE, THD_ivec3::ijk, ISANAT, LOAD_FVEC3, LOAD_IVEC3, malloc, SUMA_FORM_AFNI_DSET_STRUCT::mask, SUMA_FORM_AFNI_DSET_STRUCT::master, SUMA_FORM_AFNI_DSET_STRUCT::mmask, SUMA_FORM_AFNI_DSET_STRUCT::mset, nz, SUMA_FORM_AFNI_DSET_STRUCT::orcode, SUMA_FORM_AFNI_DSET_STRUCT::prefix, SUMA_FORM_AFNI_DSET_STRUCT::prefix_path, SHORTIZE, SUMA_RETURN, SUMA_SL_Err, SUMA_SL_Warn, THD_3dmm_to_3dind(), THD_coorder_fill(), THD_coorder_to_dicom(), THD_countmask(), THD_dicomm_to_3dmm(), THD_is_file(), THD_makemask(), THD_open_dataset(), THD_dataxes::xxdel, THD_dataxes::xxmax, THD_dataxes::xxmin, THD_coorder::xxor, THD_dataxes::xxorient, THD_fvec3::xyz, THD_dataxes::yydel, THD_dataxes::yymax, THD_dataxes::yymin, THD_coorder::yyor, THD_dataxes::yyorient, THD_dataxes::zzdel, THD_dataxes::zzmax, THD_dataxes::zzmin, THD_coorder::zzor, and THD_dataxes::zzorient.

Referenced by main().

06470 {
06471    static char FuncName[]={"SUMA_FormAfnidset"};
06472    THD_coorder cord;
06473    int ii=0,jj=0,kk=0,ll=0,ijk=0 , nx=0,ny=0,nz=0 , nxyz=0 ;
06474    float      xx,yy,zz,vv=0.0 , dx,dy,dz;
06475    short               sv=0   ;
06476    byte                bv=0   ;
06477    float *fbr=NULL, fval_float, dval_float;
06478    byte *bbr=NULL, *mmask=NULL, fval_byte, dval_byte;
06479    short *sbr=NULL, fval_short, dval_short;
06480    char *orcode=NULL;
06481    float xxdown =0.0,xxup=0.0 , yydown=0.0,yyup=0.0 , zzdown=0.0,zzup=0.0 ;
06482    
06483    THD_3dim_dataset *dset=NULL, *mset=NULL, *maskset=NULL;
06484 
06485    /* check for badiosity */
06486    if( Opt->do_ijk == 0 && Opt->master == NULL ) {
06487       SUMA_SL_Err("Can't use mm coords without master.") ;
06488       SUMA_RETURN(NULL);
06489    }
06490    if( (Opt->master == NULL && Opt->mset == NULL) && Opt->dimen_ii < 2 ) {
06491       SUMA_SL_Err("Must use exactly one of Opt->master or Opt->dimen options");
06492       SUMA_RETURN(NULL);
06493    }
06494    if (Opt->master && Opt->mset) {
06495       SUMA_SL_Err("Cannot use Opt->master and Opt->mset");
06496       SUMA_RETURN(NULL);
06497    }
06498    
06499    fval_byte = (byte)Opt->fval;
06500    fval_short = (short)Opt->fval;
06501    fval_float = (float)Opt->fval;
06502    dval_byte = (byte)Opt->dval;
06503    dval_short = (short)Opt->dval;
06504    dval_float = (float)Opt->dval;
06505    
06506    if( (Opt->datum == MRI_short && dval_short == fval_short) ||
06507     (Opt->datum == MRI_float && dval_float == fval_float) ||
06508     (Opt->datum == MRI_byte  && dval_byte  == fval_byte )   ){
06509 
06510       SUMA_SL_Warn("dval and fval are the same!") ;
06511    }
06512 
06513    if (Opt->full_list && NodeList) {
06514       SUMA_SL_Err("Opt->full_list && NodeList");
06515       SUMA_RETURN(NULL);
06516    }
06517    if (!Opt->full_list && !NodeList &&!Opt->mmask) {
06518       SUMA_SL_Err("!Opt->full_list && !NodeList && !Opt->mmask");
06519       SUMA_RETURN(NULL);
06520    }
06521 
06522    if (!Opt->prefix || !Opt->prefix_path) {
06523       SUMA_SL_Err("Need a prefix and a prefix_path Joe.");
06524       SUMA_RETURN(NULL);
06525    }
06526 
06527    if (!NodeList && !vals && !Opt->mmask) {
06528       SUMA_SL_Warn("Creating a dataset of constants. (!NodeList && !vals && !Opt->mmask)");
06529    }
06530    
06531    if (Opt->master) {
06532       mset = THD_open_dataset(Opt->master);
06533       if( mset == NULL ) {
06534          SUMA_SL_Err("-master: can't open dataset" ) ; 
06535          SUMA_RETURN(dset);
06536       }
06537    }
06538    if (Opt->mset) mset = Opt->mset;
06539    
06540    if ((Opt->master || Opt->mset) && Opt->orcode) {
06541       SUMA_SL_Err("Cannot have bothpt->master && Opt->orcode");
06542       SUMA_RETURN(dset);      
06543    }
06544    
06545    if (Opt->mask && Opt->mmask) {
06546       SUMA_SL_Err("Cannot have both Opt->mask && Opt->mmask");
06547       SUMA_RETURN(dset);
06548    }
06549 
06550    if (Opt->mask) {
06551       maskset = THD_open_dataset( Opt->mask) ;
06552       if( maskset == NULL ) {
06553          SUMA_SL_Err("-mask: can't open dataset" ) ; 
06554          if (mset) {  DSET_delete(mset); mset = NULL; }
06555          SUMA_RETURN(dset);
06556       }
06557    }
06558    
06559    
06560   /*-- set orcode to value from -master, if this is needed --*/
06561 
06562   if( mset != NULL ){
06563       orcode = malloc(4) ;
06564       orcode[0] = ORIENT_typestr[mset->daxes->xxorient][0] ;
06565       orcode[1] = ORIENT_typestr[mset->daxes->yyorient][0] ;
06566       orcode[2] = ORIENT_typestr[mset->daxes->zzorient][0] ;
06567       orcode[3] = '\0' ;
06568    } else if (Opt->orcode) {
06569       orcode = malloc(4) ; orcode = strcpy(orcode, Opt->orcode);
06570    } else {
06571       SUMA_SL_Err("Huh?");
06572       if (mset) {  DSET_delete(mset); mset = NULL; }
06573       if (maskset) {  DSET_delete(maskset); maskset = NULL; }
06574       SUMA_RETURN(dset);
06575    }
06576 
06577    THD_coorder_fill( orcode , &cord ) ;  /* setup coordinate order */ 
06578 
06579    /*-- make empty dataset --*/
06580    if( mset != NULL ){                 /* from -master */
06581 
06582       dset = EDIT_empty_copy( mset ) ;
06583       EDIT_dset_items( dset ,
06584                           ADN_prefix    , Opt->prefix ,
06585                           ADN_datum_all , Opt->datum ,
06586                           ADN_nvals     , 1 ,
06587                           ADN_ntt       , 0 ,
06588                           ADN_func_type , ISANAT(mset) ? mset->func_type
06589                                                        : FUNC_FIM_TYPE ,
06590 
06591                           ADN_directory_name , Opt->prefix_path ,
06592                           ADN_none ) ;
06593 
06594    } else {                            /* from nothing */
06595      THD_ivec3 iv_nxyz   , iv_xyzorient ;
06596      THD_fvec3 fv_xyzorg , fv_xyzdel ;
06597 
06598      LOAD_IVEC3( iv_nxyz , Opt->dimen_ii , Opt->dimen_jj , Opt->dimen_kk ) ;
06599      LOAD_IVEC3( iv_xyzorient , cord.xxor , cord.yyor , cord.zzor ) ;
06600      LOAD_FVEC3( fv_xyzdel ,
06601                  ORIENT_sign[iv_xyzorient.ijk[0]]=='+' ? 1.0 : -1.0 ,
06602                  ORIENT_sign[iv_xyzorient.ijk[1]]=='+' ? 1.0 : -1.0 ,
06603                  ORIENT_sign[iv_xyzorient.ijk[2]]=='+' ? 1.0 : -1.0  ) ;
06604      LOAD_FVEC3( fv_xyzorg ,
06605                  ORIENT_sign[iv_xyzorient.ijk[0]]=='+' ? -0.5*Opt->dimen_ii : 0.5*Opt->dimen_ii,
06606                  ORIENT_sign[iv_xyzorient.ijk[1]]=='+' ? -0.5*Opt->dimen_jj : 0.5*Opt->dimen_jj,
06607                  ORIENT_sign[iv_xyzorient.ijk[2]]=='+' ? -0.5*Opt->dimen_kk : 0.5*Opt->dimen_kk ) ;
06608 
06609      dset = EDIT_empty_copy( NULL ) ;
06610 
06611      EDIT_dset_items( dset ,
06612                        ADN_nxyz      , iv_nxyz ,
06613                        ADN_xyzdel    , fv_xyzdel ,
06614                        ADN_xyzorg    , fv_xyzorg ,
06615                        ADN_xyzorient , iv_xyzorient ,
06616                        ADN_prefix    , Opt->prefix ,
06617                        ADN_datum_all , Opt->datum ,
06618                        ADN_nvals     , 1 ,
06619                        ADN_ntt       , 0 ,
06620                        ADN_type      , HEAD_FUNC_TYPE ,
06621                        ADN_func_type , FUNC_FIM_TYPE ,
06622                        ADN_directory_name , Opt->prefix_path ,
06623                     ADN_none ) ;
06624 
06625    }
06626 
06627    if( THD_is_file(DSET_HEADNAME(dset)) ) {
06628       SUMA_SL_Err("Output dataset already exists -- can't overwrite") ;
06629       exit(1);
06630    }
06631    /*-- make empty brick array for dataset --*/
06632 
06633    EDIT_substitute_brick( dset , 0 , Opt->datum , NULL ) ;  /* will make array */
06634 
06635    nx = DSET_NX(dset); ny = DSET_NY(dset); nz = DSET_NZ(dset); nxyz = nx*ny*nz;
06636 
06637    if (Opt->full_list && N_vals != nxyz) {
06638       SUMA_SL_Err("Opt->full_list && N_vals != nx*ny*nz");
06639       SUMA_RETURN(NULL);
06640    }
06641    /* 19 Feb 2004: check and make mask if desired */
06642 
06643    if( maskset != NULL &&
06644        ( DSET_NX(maskset) != nx ||
06645          DSET_NY(maskset) != ny ||
06646          DSET_NZ(maskset) != nz   ) ) {
06647      SUMA_SL_Err("mask dataset doesn't match dimension of output dataset") ;
06648      if (mset) {  DSET_delete(mset); mset = NULL; }
06649      if (maskset) {  DSET_delete(maskset); maskset = NULL; }
06650      SUMA_RETURN(NULL);
06651    }
06652 
06653    if( maskset != NULL ){
06654      mmask = THD_makemask( maskset , 0 , 1.0,-1.0 ) ;
06655      SUMA_SL_Warn("can't create mask for some reason!") ;
06656      DSET_delete(maskset) ;
06657    } else mmask = Opt->mmask;
06658 
06659    if( mmask == NULL ){
06660    } else {
06661       int nmask = THD_countmask( nxyz , mmask ) ;
06662       if( nmask == 0 ){
06663          SUMA_SL_Warn("0 voxels in mask -- ignoring it!") ;
06664          if (!Opt->mmask) free((void *)mmask) ; mmask = NULL ;
06665       } else {
06666          fprintf(SUMA_STDERR,"%s:++ %d voxels found in mask\n", FuncName, nmask) ;
06667       }
06668    }
06669 
06670    /*-- fill new dataset brick with the -fval value --*/
06671    switch( Opt->datum ){
06672       case MRI_short:
06673          if (0) fprintf(SUMA_STDERR,"%s: Filling with %d\n", FuncName, fval_short);
06674          sbr = (short *) DSET_BRICK_ARRAY(dset,0) ;
06675          for( ii=0 ; ii < nxyz ; ii++ ) sbr[ii] = fval_short ;
06676       break ;
06677 
06678       case MRI_float:
06679          fbr = (float *) DSET_BRICK_ARRAY(dset,0) ;
06680          for( ii=0 ; ii < nxyz ; ii++ ) fbr[ii] = fval_float ;
06681       break ;
06682 
06683       case MRI_byte:
06684          bbr = (byte *) DSET_BRICK_ARRAY(dset,0) ;
06685          for( ii=0 ; ii < nxyz ; ii++ ) bbr[ii] = fval_byte ;
06686       break ;
06687    }
06688 
06689    /* 24 Nov 2000: get the bounding box for the dataset */
06690 
06691    dx = fabs(dset->daxes->xxdel) ; if( dx <= 0.0 ) dx = 1.0 ;
06692    dy = fabs(dset->daxes->yydel) ; if( dy <= 0.0 ) dy = 1.0 ;
06693    dz = fabs(dset->daxes->zzdel) ; if( dz <= 0.0 ) dz = 1.0 ;
06694 
06695    if( !Opt->do_ijk ){
06696 #ifndef EXTEND_BBOX
06697       xxdown = dset->daxes->xxmin - 0.501 * dx ;
06698       xxup   = dset->daxes->xxmax + 0.501 * dx ;
06699       yydown = dset->daxes->yymin - 0.501 * dy ;
06700       yyup   = dset->daxes->yymax + 0.501 * dy ;
06701       zzdown = dset->daxes->zzmin - 0.501 * dz ;
06702       zzup   = dset->daxes->zzmax + 0.501 * dz ;
06703 #else
06704       xxdown = dset->daxes->xxmin ;
06705       xxup   = dset->daxes->xxmax ;
06706       yydown = dset->daxes->yymin ;
06707       yyup   = dset->daxes->yymax ;
06708       zzdown = dset->daxes->zzmin ;
06709       zzup   = dset->daxes->zzmax ;
06710 #endif
06711    }
06712 
06713    for (ll=0; ll<N_vals; ++ll) {
06714       /* stick 'em in */
06715       if (!Opt->full_list) {
06716          xx = NodeList[3*ll]; yy = NodeList[3*ll+1]; zz = NodeList[3*ll+2]; 
06717          if (Opt->do_ijk) {
06718             ii = (int) rint(xx) ; jj = (int) rint(yy) ; kk = (int) rint(zz) ;
06719             if( ii < 0 || ii >= nx ){
06720                fprintf(stderr,
06721                        "Warning %s: entry %d: i index=%d is invalid, ignoring...\n",
06722                        FuncName,ll,ii) ;
06723                continue ;
06724             }
06725             if( jj < 0 || jj >= ny ){
06726                fprintf(stderr,
06727                        "Warning %s: entry %d: j index=%d is invalid, ignoring...\n",
06728                        FuncName, ll,jj) ;
06729                continue ;
06730             }
06731             if( kk < 0 || kk >= nz ){
06732                fprintf(stderr,
06733                        "Warning %s: entry %d: k index=%d is invalid\n",
06734                        FuncName,ll,kk) ;
06735                continue ;
06736             }
06737          } else {   /* inputs are coordinates => must convert to index */
06738 
06739             THD_fvec3 mv , dv ;                              /* temp vectors */
06740             THD_ivec3 iv ;
06741 
06742             THD_coorder_to_dicom( &cord , &xx,&yy,&zz ) ;    /* to Dicom order */
06743             LOAD_FVEC3( dv , xx,yy,zz ) ;
06744             mv = THD_dicomm_to_3dmm( dset , dv ) ;           /* to Dataset order */
06745 
06746             /* 24 Nov 2000: check (xx,yy,zz) for being inside the box */
06747 
06748             if( mv.xyz[0] < xxdown || mv.xyz[0] > xxup ){
06749                fprintf(stderr,"+++ Warning %s: line %d: x coord=%g is outside %g .. %g\n" ,
06750                        FuncName,ll,mv.xyz[0] , xxdown,xxup ) ;
06751                continue ;
06752             }
06753             if( mv.xyz[1] < yydown || mv.xyz[1] > yyup ){
06754                fprintf(stderr,"+++ Warning %s: line %d: y coord=%g is outside %g .. %g\n" ,
06755                        FuncName,ll,mv.xyz[1] , yydown , yyup ) ;
06756                continue ;
06757             }
06758             if( mv.xyz[2] < zzdown || mv.xyz[2] > zzup ){
06759                fprintf(stderr,"+++ Warning %s: line %d: z coord=%g is outside %g .. %g\n" ,
06760                        FuncName,ll,mv.xyz[2] , zzdown , zzup ) ;
06761                continue ;
06762             }
06763 
06764             iv = THD_3dmm_to_3dind( dset , mv ) ;            /* to Dataset index */
06765             ii = iv.ijk[0]; jj = iv.ijk[1]; kk = iv.ijk[2];  /* save */
06766          }
06767 
06768          ijk = ii + jj*nx + kk*nx*ny ;
06769       } else {
06770          ijk = ll; 
06771       }
06772 
06773       if (vals) vv = vals[ll];
06774       else vv = dval_float ;   
06775 
06776       if( mmask == NULL || mmask[ijk] ){
06777          switch( Opt->datum ){
06778             case MRI_float:{
06779               if( fbr[ijk] != fval_float && fbr[ijk] != vv )
06780                 fprintf(stderr,"Overwrite voxel %d %d %d\n",ii,jj,kk) ;
06781               fbr[ijk] = vv ;
06782             }
06783             break ;
06784             case MRI_short:{
06785               sv = SHORTIZE(vv) ;
06786               if( sbr[ijk] != fval_short && sbr[ijk] != sv )
06787                 fprintf(stderr,"Overwrite voxel %d %d %d\n",ii,jj,kk) ;
06788               sbr[ijk] = sv ;
06789             }
06790             break ;
06791             case MRI_byte:{
06792               bv = BYTEIZE(vv) ;
06793               if( bbr[ijk] != fval_byte && bbr[ijk] != bv )
06794                 fprintf(stderr,"Overwrite voxel %d %d %d\n",ii,jj,kk) ;
06795               bbr[ijk] = bv ;
06796             }
06797             break ;
06798          }
06799       }
06800 
06801    }
06802    
06803    if (orcode) free(orcode); orcode = NULL;
06804    if (mmask && !Opt->mmask) free(mmask); mmask = NULL;
06805    if (mset && !Opt->mset) DSET_delete(mset); mset = NULL; 
06806 
06807    SUMA_RETURN(dset);      
06808 }

SUMA_1D_DRAWN_ROI* SUMA_Free_1DDrawROI SUMA_1D_DRAWN_ROI   ROI_1D
 

frees a ROI_1D structure. These structures are created by the likes of SUMA_DrawnROI_to_1DDrawROI

See also:
SUMA_DrawnROI_to_1DDrawROI

Definition at line 6290 of file SUMA_Surface_IO.c.

References SUMA_1D_DRAWN_ROI::iLabel, SUMA_1D_DRAWN_ROI::iNode, LocalHead, SUMA_Boolean, SUMA_ENTRY, SUMA_free, and SUMA_RETURN.

Referenced by SUMA_Write_DrawnROI_1D().

06291 {
06292    static char FuncName[]={"SUMA_Free_1DDrawROI"};
06293    SUMA_Boolean LocalHead = NOPE;
06294    
06295    SUMA_ENTRY;
06296 
06297    if (!ROI_1D) SUMA_RETURN(NULL);
06298    
06299    if (ROI_1D->iLabel) SUMA_free(ROI_1D->iLabel); 
06300    if (ROI_1D->iNode) SUMA_free(ROI_1D->iNode);
06301    
06302    SUMA_free(ROI_1D);
06303    
06304    SUMA_RETURN(NULL);
06305 }

SUMA_FORM_AFNI_DSET_STRUCT* SUMA_Free_FormAfniDset_Opt SUMA_FORM_AFNI_DSET_STRUCT   Opt
 

Definition at line 6408 of file SUMA_Surface_IO.c.

References SUMA_FORM_AFNI_DSET_STRUCT::mask, SUMA_FORM_AFNI_DSET_STRUCT::master, SUMA_FORM_AFNI_DSET_STRUCT::mmask, SUMA_FORM_AFNI_DSET_STRUCT::mset, SUMA_FORM_AFNI_DSET_STRUCT::orcode, SUMA_FORM_AFNI_DSET_STRUCT::prefix, SUMA_FORM_AFNI_DSET_STRUCT::prefix_path, SUMA_ENTRY, SUMA_free, SUMA_RETURN, and SUMA_SL_Warn.

Referenced by main().

06409 {
06410    static char FuncName[]={"SUMA_Free_FormAfniDset_Opt"};
06411    SUMA_ENTRY;
06412    
06413    if (!Opt) SUMA_RETURN(NULL);
06414    
06415    if (Opt->master) SUMA_free(Opt->master);
06416    if (Opt->mask) SUMA_free(Opt->mask);  
06417    if (Opt->mset) {
06418       SUMA_SL_Warn("mset is not freed in this function.\nMake sure it is not a lost pointer.\nSet mset to NULL to avoid seeing this message");
06419    } 
06420    if (Opt->prefix) SUMA_free(Opt->prefix);
06421    if (Opt->prefix_path) SUMA_free(Opt->prefix_path);
06422    if (Opt->mmask) SUMA_free(Opt->mmask);
06423    if (Opt->orcode) SUMA_free(Opt->orcode);
06424    SUMA_free(Opt);
06425    
06426    SUMA_RETURN(NULL);
06427 }

SUMA_Boolean SUMA_Free_FreeSurfer SUMA_FreeSurfer_struct   FS
 

free memory allocated for FreeSurfer structure

Definition at line 2409 of file SUMA_Surface_IO.c.

References SUMA_FreeSurfer_struct::FaceSetIndexInParent, SUMA_FreeSurfer_struct::FaceSetList, SUMA_FreeSurfer_struct::NodeId, SUMA_FreeSurfer_struct::NodeList, SUMA_Boolean, SUMA_ENTRY, SUMA_free, and SUMA_RETURN.

Referenced by SUMA_Load_Surface_Object_eng().

02410 {
02411         static char FuncName[]={"SUMA_Free_FreeSurfer"};
02412    
02413    SUMA_ENTRY;
02414 
02415         if (FS->FaceSetList != NULL) SUMA_free(FS->FaceSetList);
02416         if (FS->NodeList != NULL) SUMA_free(FS->NodeList);
02417         if (FS->NodeId != NULL) SUMA_free(FS->NodeId);
02418         if (FS->FaceSetIndexInParent != NULL) SUMA_free(FS->FaceSetIndexInParent);
02419         if (FS != NULL) SUMA_free(FS);
02420         SUMA_RETURN (YUP);
02421 }

SUMA_OPEN_DX_STRUCT* SUMA_Free_OpenDX_Struct SUMA_OPEN_DX_STRUCT   dx
 

Definition at line 7445 of file SUMA_Surface_IO.c.

References SUMA_OPEN_DX_STRUCT::attr_name, SUMA_OPEN_DX_STRUCT::attr_string, SUMA_OPEN_DX_STRUCT::class, SUMA_OPEN_DX_STRUCT::comp_name, SUMA_OPEN_DX_STRUCT::comp_value, SUMA_OPEN_DX_STRUCT::counts, SUMA_OPEN_DX_STRUCT::data, SUMA_OPEN_DX_STRUCT::data_off, SUMA_OPEN_DX_STRUCT::datap, SUMA_OPEN_DX_STRUCT::delta, i, SUMA_OPEN_DX_STRUCT::object, SUMA_OPEN_DX_STRUCT::origin, SUMA_ENTRY, SUMA_free, SUMA_MAX_OPEN_DX_FIELD_ATTRIBUTES, SUMA_MAX_OPEN_DX_FIELD_COMPONENTS, SUMA_OK_OPENDX_DATA_TYPE, SUMA_RETURN, SUMA_SL_Warn, and SUMA_OPEN_DX_STRUCT::type.

Referenced by SUMA_Free_OpenDX_StructVec(), SUMA_LoadDXDset(), and SUMA_OpenDX_Read_SO().

07446 {
07447    static char FuncName[]={"SUMA_Free_OpenDX_Struct"};
07448    int i;
07449    
07450    SUMA_ENTRY;
07451    
07452    if (!dx) SUMA_RETURN(dx);
07453    if (dx->object) SUMA_free(dx->object); dx->object = NULL;
07454    if (dx->class) SUMA_free(dx->class); dx->class = NULL;
07455    if (dx->data) SUMA_free(dx->data); dx->data = NULL;
07456    if (dx->data_off) SUMA_free(dx->data_off); dx->data_off = NULL;
07457    if (dx->datap) {
07458       if ( SUMA_OK_OPENDX_DATA_TYPE(SUMA_VarType2TypeCast (dx->type)) ) {
07459          SUMA_free(dx->datap); dx->datap = NULL;
07460       } else {
07461          SUMA_SL_Warn("Do not know how to free datap.\nYou now possibly have a leak on your hands.");
07462       }
07463    }
07464    if (dx->type) SUMA_free(dx->type); dx->type = NULL;
07465    for (i=0; i<SUMA_MAX_OPEN_DX_FIELD_COMPONENTS; ++i) { 
07466       if (dx->comp_name[i]) SUMA_free(dx->comp_name[i]); dx->comp_name[i] = NULL;
07467       if (dx->comp_value[i]) SUMA_free(dx->comp_value[i]); dx->comp_value[i] =NULL; 
07468    }
07469    for (i=0; i<SUMA_MAX_OPEN_DX_FIELD_ATTRIBUTES; ++i) { 
07470       if (dx->attr_name[i]) SUMA_free(dx->attr_name[i]); dx->attr_name[i] = NULL;
07471       if (dx->attr_string[i]) SUMA_free(dx->attr_string[i]); dx->attr_string[i] =NULL; 
07472    }
07473    if (dx->origin) SUMA_free(dx->origin); 
07474    if (dx->delta) SUMA_free(dx->delta);
07475    if (dx->counts) SUMA_free(dx->counts);
07476    SUMA_free(dx); dx = NULL;
07477    SUMA_RETURN(dx);
07478 }

SUMA_OPEN_DX_STRUCT** SUMA_Free_OpenDX_StructVec SUMA_OPEN_DX_STRUCT **    dxv,
int    nobj
 

Definition at line 7430 of file SUMA_Surface_IO.c.

References i, SUMA_ENTRY, SUMA_free, SUMA_Free_OpenDX_Struct(), and SUMA_RETURN.

Referenced by SUMA_OpenDX_Read_CruiseVolHead().

07431 {
07432    static char FuncName[]={"SUMA_Free_OpenDX_StructVec"};
07433    int i;
07434    
07435    SUMA_ENTRY;
07436    
07437    if (!dxv) SUMA_RETURN(NULL);
07438    for (i=0; i<nobj; ++i) {
07439       dxv[i] = SUMA_Free_OpenDX_Struct(dxv[i]);
07440    }
07441    SUMA_free(dxv); 
07442    SUMA_RETURN(NULL);
07443 }

SUMA_Boolean SUMA_Free_SureFit SUMA_SureFit_struct   SF
 

free data structure containing SureFit surface object

Definition at line 818 of file SUMA_Surface_IO.c.

References SUMA_SureFit_struct::FaceSetList, SUMA_NODE_FIRST_NEIGHB::FirstNeighb, SUMA_SureFit_struct::FN, SUMA_NODE_FIRST_NEIGHB::N_Neighb, SUMA_NODE_FIRST_NEIGHB::N_Node, SUMA_SureFit_struct::N_Node_Specs, SUMA_NODE_FIRST_NEIGHB::NodeId, SUMA_SureFit_struct::NodeId, SUMA_SureFit_struct::NodeList, SUMA_SureFit_struct::Specs_mat, SUMA_Boolean, SUMA_ENTRY, SUMA_free, SUMA_free2D(), and SUMA_RETURN.

Referenced by SUMA_Load_Surface_Object_eng().

00819 {
00820         static char FuncName[]={"SUMA_Free_SureFit"};
00821         
00822         SUMA_ENTRY;
00823 
00824         if (SF->NodeList != NULL) SUMA_free(SF->NodeList);
00825         if (SF->NodeId != NULL) SUMA_free(SF->NodeId);
00826         if (SF->Specs_mat != NULL) SUMA_free2D ((char **)SF->Specs_mat, SF->N_Node_Specs);
00827         if (SF->FN.FirstNeighb != NULL) SUMA_free2D((char **)SF->FN.FirstNeighb, SF->FN.N_Node);
00828         if (SF->FN.N_Neighb != NULL) SUMA_free(SF->FN.N_Neighb);
00829         if (SF->FN.NodeId != NULL) SUMA_free(SF->FN.NodeId);
00830         if (SF->FaceSetList != NULL) SUMA_free(SF->FaceSetList);
00831         if (SF!= NULL) SUMA_free(SF);
00832         
00833         SUMA_RETURN (YUP);
00834 }

SUMA_Boolean SUMA_FreeSurfer_Read char *    f_name,
SUMA_FreeSurfer_struct   FS
 

Definition at line 1908 of file SUMA_Surface_IO.c.

References SUMA_Boolean, SUMA_ENTRY, SUMA_FreeSurfer_Read_eng(), and SUMA_RETURN.

01909 {/* SUMA_FreeSurfer_Read */
01910    static char FuncName[]={"SUMA_FreeSurfer_Read"};
01911 
01912    SUMA_ENTRY;
01913 
01914    SUMA_RETURN(SUMA_FreeSurfer_Read_eng(f_name, FS, 1));
01915 }/* SUMA_FreeSurfer_Read */

SUMA_Boolean SUMA_FreeSurfer_Read_eng char *    f_name,
SUMA_FreeSurfer_struct   FS,
int    debug
 

** Usage : Ret = SUMA_FreeSurfer_Read_eng (surfname, FreeSurfer, debug)

For a full surface definition, it is assumed that the first line can be a comment. The second line contains the number of nodes followed by the number of FaceSets The NodeList follows with X Y Z 0 The FaceSetList follows with i1 i2 i3 0

Input paramters :

Parameters:
surfname  (char *) name of surface (or patch) file output by: mris_convert <surface_name> <surface_name.asc> or if it is a patch by mris_convert -p <patch_name> <patch_name.asc>
FreeSurfer  (SUMA_FreeSurfer_struct *) pointer to the FreeSurfer structure
debug  (int) flag specifying whether to output non-error info
Returns :
Returns:
(SUMA_Boolean) YUP/NOPE for success/failure
Support :
See also:
LoadFreeSurf.m , Side effects :

Definition at line 1954 of file SUMA_Surface_IO.c.

References amax, c, SUMA_FreeSurfer_struct::comment, SUMA_FreeSurfer_struct::FaceSetIndexInParent, SUMA_FreeSurfer_struct::FaceSetList, SUMA_FreeSurfer_struct::isPatch, LocalHead, SUMA_FreeSurfer_struct::N_FaceSet, SUMA_FreeSurfer_struct::N_Node, SUMA_FreeSurfer_struct::name, SUMA_FreeSurfer_struct::NodeId, SUMA_FreeSurfer_struct::NodeList, SUMA_ADVANCE_PAST, SUMA_ADVANCE_PAST_NUM, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_error_message(), SUMA_file_suck(), SUMA_filexists(), SUMA_free, SUMA_IS_COMMENT_LINE, SUMA_iswordin(), SUMA_LH, SUMA_MAX_STRING_LENGTH, SUMA_MAX_VEC, SUMA_RETURN, SUMA_SKIP_LINE, SUMA_SL_Crit, and SUMA_SL_Err.

Referenced by SUMA_FreeSurfer_Read(), and SUMA_Load_Surface_Object_eng().

01955 {/*SUMA_FreeSurfer_Read_eng*/
01956         static char FuncName[]={"SUMA_FreeSurfer_Read_eng"};
01957    char stmp[50]; 
01958    FILE *fs_file;
01959         int ex, cnt, jnki, amax[3], maxamax, maxamax2, id, ND, id2, NP, ip, *NodeId;
01960         float jnkf, *NodeList;
01961         char c;
01962         SUMA_Boolean LocalHead = NOPE;
01963            
01964         SUMA_ENTRY;
01965 
01966         /* check for existence */
01967         if (!SUMA_filexists(f_name)) {
01968                 fprintf(SUMA_STDERR,"Error %s: File %s does not exist or cannot be read.\n", FuncName, f_name);
01969                 SUMA_RETURN (NOPE);
01970         }else if ( debug > 1) {
01971                 fprintf(SUMA_STDERR,"%s: File %s exists and will be read.\n", FuncName, f_name);
01972         }
01973         
01974         
01975         /* start reading */
01976         fs_file = fopen (f_name,"r");
01977         if (fs_file == NULL)
01978                 {
01979                         SUMA_error_message (FuncName,"Could not open input file ",0);
01980                         SUMA_RETURN (NOPE);
01981                 }
01982 
01983         sprintf(FS->name, "%s", f_name);
01984         
01985         /* read first character and check if it is a comment */
01986         ex = fscanf (fs_file,"%c",&c);
01987         if (c == '#') {
01988                 if (LocalHead) fprintf (SUMA_STDOUT, "%s: Found comment\n", FuncName); 
01989                 
01990       /*skip till next line */
01991                 sprintf(FS->comment,"#"); 
01992                 cnt = 0;
01993                 while (ex != EOF && c != '\n') {
01994                         ex = fscanf (fs_file,"%c",&c);
01995                         if (cnt < SUMA_MAX_STRING_LENGTH-2) {
01996                                 sprintf(FS->comment, "%s%c", FS->comment, c);
01997                                 ++cnt;
01998                         } else {
01999                                 fprintf(SUMA_STDERR,"Error %s: Too long a comment in FS file, increase SUMA_FS_MAX_COMMENT_LENGTH\n", FuncName);
02000                                 SUMA_RETURN (NOPE);
02001                         }
02002                 }
02003         }
02004         
02005         /* find out if surface is patch */
02006         sprintf(stmp,"patch");
02007         if (SUMA_iswordin (FS->comment, stmp) == 1) {
02008                 FS->isPatch = YUP;
02009         }
02010         else {
02011                 FS->isPatch = NOPE;
02012         }
02013                 
02014         /* read in the number of nodes and the number of facesets */
02015         ex = fscanf(fs_file, "%d %d", &(FS->N_Node), &(FS->N_FaceSet));
02016         
02017    if (FS->N_Node <= 0 || FS->N_FaceSet <= 0) {
02018       SUMA_SL_Crit("Trouble parsing FreeSurfer file.\nNull or negative number of nodes &/| facesets.\n");
02019       SUMA_RETURN(NOPE);
02020    }
02021    
02022         if (LocalHead) fprintf (SUMA_STDOUT, "%s: Allocating for NodeList (%dx3) and FaceSetList(%dx3)\n", FuncName, FS->N_Node, FS->N_FaceSet);
02023    
02024    /* allocate space for NodeList and FaceSetList */
02025         FS->NodeList = (float *)SUMA_calloc(FS->N_Node * 3, sizeof(float));
02026         FS->FaceSetList = (int *)SUMA_calloc(FS->N_FaceSet * 3, sizeof(int));
02027         FS->NodeId = (int *)SUMA_calloc(FS->N_Node, sizeof(int));
02028         if (FS->NodeList == NULL || FS->FaceSetList == NULL || FS->NodeId == NULL) {
02029                 fprintf(SUMA_STDERR,"Error %s: Could not allocate for FS->NodeList &/| FS->FaceSetList &/| FS->NodeId\n", FuncName);
02030                 SUMA_RETURN (NOPE);
02031         } 
02032         if (FS->isPatch) {
02033                 FS->FaceSetIndexInParent = (int *)SUMA_calloc(FS->N_FaceSet, sizeof(int));
02034                 if (FS->FaceSetIndexInParent == NULL) {
02035                         fprintf(SUMA_STDERR,"Error %s: Could not allocate for FS->FaceSetIndexInParent\n", FuncName);
02036                         SUMA_RETURN (NOPE);
02037                 }
02038         } else {
02039                 FS->FaceSetIndexInParent = NULL;
02040         }
02041         
02042         if (!FS->isPatch) {
02043            if (LocalHead) fprintf (SUMA_STDOUT, "%s: Reading full surface...\n", FuncName);
02044                 /* read in the nodes */
02045                 cnt = 0;
02046                 while (ex != EOF && cnt < FS->N_Node) {
02047                         FS->NodeId[cnt] = cnt;
02048                         id = 3 * cnt;
02049                         ex = fscanf(fs_file, "%f %f %f %f", &(FS->NodeList[id]), &(FS->NodeList[id+1]),&(FS->NodeList[id+2]), &jnkf);
02050                         ++cnt;
02051                 }
02052                 if (cnt != FS->N_Node) {
02053                         fprintf(SUMA_STDERR,"Error %s: Expected %d nodes, %d read.\n", FuncName, FS->N_Node, cnt);
02054                         SUMA_RETURN (NOPE);
02055                 }
02056 
02057                 /* read in the facesets */
02058                 cnt = 0;
02059                 while (ex != EOF && cnt < FS->N_FaceSet) {
02060                         ip = 3 * cnt;
02061                         ex = fscanf(fs_file, "%d %d %d %d", &(FS->FaceSetList[ip]), &(FS->FaceSetList[ip+1]),&(FS->FaceSetList[ip+2]), &jnki);
02062                         ++cnt;
02063                 }
02064                 if (cnt != FS->N_FaceSet) {
02065                         fprintf(SUMA_STDERR,"Error %s: Expected %d FaceSets, %d read.\n", FuncName, FS->N_FaceSet, cnt);
02066                         SUMA_RETURN (NOPE);
02067                 }
02068         } /* read a full surface */
02069         else { /* that's a patch */
02070            #if 0 /* old way, simple parsing ... */
02071          if (LocalHead) fprintf (SUMA_STDOUT, "%s: Reading patch olde way...\n", FuncName);
02072                    /* Node IDs are a reference to those in the parent surface */
02073                    cnt = 0;
02074          while (ex != EOF && cnt < FS->N_Node) {
02075                            ex = fscanf(fs_file, "%d", &(FS->NodeId[cnt]));
02076                            id = 3 * cnt;
02077             /* fprintf (SUMA_STDERR, "FS->NodeId[cnt] = %d: cnt = %d, id=%d, id1 = %d, id2 = %d\n", FS->NodeId[cnt], cnt, id, id+1, id+2); */ 
02078                            ex = fscanf(fs_file, "%f %f %f", &(FS->NodeList[id]),&(FS->NodeList[id+1]),&(FS->NodeList[id+2]));
02079                            ++cnt;
02080                    }
02081          if (cnt != FS->N_Node) {
02082                            fprintf(SUMA_STDERR,"Error %s: Expected %d nodes, %d read.\n", FuncName, FS->N_Node, cnt);
02083                            SUMA_RETURN (NOPE);
02084                    }
02085 
02086          if (LocalHead) fprintf (SUMA_STDOUT, "%s: Reading FaceSets...\n", FuncName);
02087                    /* read in the facesets */
02088                    cnt = 0;
02089                    while (ex != EOF && cnt < FS->N_FaceSet) {
02090                            ex = fscanf(fs_file, "%d", &(FS->FaceSetIndexInParent[cnt]));
02091                            ip = 3 * cnt;
02092                            ex = fscanf(fs_file, "%d %d %d",  &(FS->FaceSetList[ip]), &(FS->FaceSetList[ip+1]),&(FS->FaceSetList[ip+2]));
02093                            ++cnt;
02094                    }
02095                    if (cnt != FS->N_FaceSet) {
02096                            fprintf(SUMA_STDERR,"Error %s: Expected %d FaceSets, %d read.\n", FuncName, FS->N_FaceSet, cnt);
02097                            SUMA_RETURN (NOPE);
02098                    }
02099       #else 
02100       {
02101          char *fl=NULL, *eop=NULL, *florig=NULL;
02102          int ans, pnodes, ptri, Found, nchar;
02103          double dbuf;
02104          
02105          if (LocalHead) fprintf (SUMA_STDOUT, "%s: Reading patch new way...\n", FuncName);
02106          /* suck in the bastard, perhaps this should be done from the start, maybe in the future */  
02107          fl = florig = SUMA_file_suck(f_name, &nchar);
02108          if (!nchar || !fl) { 
02109             SUMA_SL_Err("Failed to read patch file.");
02110             SUMA_RETURN(NOPE);
02111          }
02112          /* skip comment, if any */
02113          SUMA_IS_COMMENT_LINE(fl, NULL, '#', ans);
02114          if (ans) {  
02115             SUMA_LH("Skipping comment..."); 
02116             SUMA_SKIP_LINE(fl, NULL);
02117          }else {
02118             SUMA_SL_Err("Expected comment line....");
02119          }
02120          /* read in first two nums */
02121          SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); pnodes = (int)dbuf;
02122          SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); ptri = (int)dbuf;
02123          
02124          /* Node IDs are a reference to those in the parent surface */
02125                    Found = 1;
02126          cnt = 0;
02127          while (Found && cnt < FS->N_Node) {
02128                            eop = fl+50; /* don't you dare use (fl+50) instead of eop below!, else you will serch till the end all the time!
02129                            Macro Danger! */
02130             SUMA_ADVANCE_PAST(fl, eop,"vno=",Found,0);  /* The new patch format ... */
02131             SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); FS->NodeId[cnt] = (int)dbuf;
02132                            id = 3 * cnt;
02133             /* fprintf (SUMA_STDERR, "FS->NodeId[cnt] = %d: cnt = %d, id=%d, id1 = %d, id2 = %d\n", FS->NodeId[cnt], cnt, id, id+1, id+2); */ 
02134                            SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); FS->NodeList[id] = (float)dbuf;
02135             SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); FS->NodeList[id+1] = (float)dbuf;
02136             SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); FS->NodeList[id+2] = (float)dbuf;
02137                            ++cnt;
02138                    }
02139          if (cnt != FS->N_Node) {
02140                            fprintf(SUMA_STDERR,"Error %s: Expected %d nodes, %d read.\n", FuncName, FS->N_Node, cnt);
02141                            SUMA_RETURN (NOPE);
02142                    }
02143          if (LocalHead) fprintf (SUMA_STDOUT, "%s: Reading FaceSets...\n", FuncName);
02144                    /* read in the facesets */
02145                    Found = 1;
02146                    cnt = 0;
02147          while (Found && cnt < FS->N_FaceSet) {
02148                            SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); FS->FaceSetIndexInParent[cnt] = (int)dbuf;
02149                            ip = 3 * cnt;
02150                            SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); FS->FaceSetList[ip  ] = (int)dbuf;
02151                            SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); FS->FaceSetList[ip+1] = (int)dbuf;
02152                            SUMA_ADVANCE_PAST_NUM(fl, dbuf, Found); FS->FaceSetList[ip+2] = (int)dbuf;
02153                            ++cnt;
02154                    }
02155                    if (cnt != FS->N_FaceSet) {
02156                            fprintf(SUMA_STDERR,"Error %s: Expected %d FaceSets, %d read.\n", FuncName, FS->N_FaceSet, cnt);
02157                            SUMA_RETURN (NOPE);
02158                    }
02159          SUMA_free(florig); fl = florig = NULL; /*  */
02160       }   
02161       #endif   
02162       
02163                 /* The FaceSet List which will be read next, uses indices into the NodeList of the parent surface
02164                 This means that it expects a NodeList of the size of the NodeList in the parent surface. 
02165                 One could read the maximum number of nodes in the parent surface and create a NodeList of that size.
02166                 However, that would require keeping track of the link between the patch file and the parent file.
02167                 Instead, I will search through the FaceSetList for the highest index and allocate a new nodelist to match it*/
02168       
02169                 SUMA_MAX_VEC(FS->FaceSetList, FS->N_FaceSet * 3, maxamax); ++maxamax;
02170       /* make sure that the node list does not refer to nodes of an index higher than that in NodeId */
02171       SUMA_MAX_VEC(FS->NodeId, FS->N_Node, maxamax2); ++maxamax2;
02172       if (maxamax2 > maxamax) {
02173          fprintf(SUMA_STDERR,"Error %s: Found NodeId in the NodeList larger than Ids found in FaceSetList.\n", FuncName);
02174          SUMA_RETURN (NOPE);
02175       }
02176       if (LocalHead) fprintf (SUMA_STDOUT, "%s: Copying NodeList, allocating for new nodelist %dx3 elements...\n", \
02177          FuncName, maxamax);
02178          
02179                 NodeList = (float *)SUMA_calloc(maxamax * 3, sizeof(float));
02180                 NodeId = (int *)SUMA_calloc (maxamax, sizeof(int));
02181       
02182       if (NodeList == NULL || NodeId == NULL)
02183                 {
02184                         fprintf(SUMA_STDERR,"Error %s: Could not allocate for NodeList or NodeId\n", FuncName);
02185                         SUMA_RETURN (NOPE);
02186                 } 
02187                 /*Now copy pertinent nodes into NodeList */
02188                 
02189       for (cnt=0; cnt< FS->N_Node; ++cnt) {
02190                         id = 3*cnt; 
02191                         id2 = 3*FS->NodeId[cnt];
02192          /* fprintf (SUMA_STDERR, "%s: id = %d id2 = %d\n", FuncName, id, id2); */
02193                         NodeList[id2] = FS->NodeList[id];
02194                         NodeList[id2+1] = FS->NodeList[id+1];
02195                         NodeList[id2+2] = FS->NodeList[id+2];
02196                 }
02197                 
02198       /* this is redundant here, but should be done to match what comes out of a full surface */
02199       for (cnt=0; cnt< maxamax; ++cnt) {
02200          NodeId[cnt] = cnt;
02201       }
02202       
02203       /* Now free FS->NodeList & FS->NodeId */
02204                 SUMA_free(FS->NodeList);
02205                 SUMA_free(FS->NodeId);
02206       
02207                 /*make FS->NodeList be NodeList */
02208                 FS->NodeList = NodeList;
02209       FS->NodeId = NodeId;
02210                 FS->N_Node = maxamax;
02211         } /* read a patch */
02212         
02213         fclose (fs_file);
02214         SUMA_RETURN (YUP);
02215         
02216 }/* SUMA_FreeSurfer_Read_eng*/

SUMA_Boolean SUMA_FreeSurfer_ReadBin_eng char *    f_name,
SUMA_FreeSurfer_struct   FS,
int    debug
 

Thanks for info from Graham Wideman, https://wideman-one.com/gw/brain/fs/surfacefileformats.htm

Definition at line 2286 of file SUMA_Surface_IO.c.

References amax, c, SUMA_FreeSurfer_struct::FaceSetList, i, LocalHead, m1, m2, SUMA_FreeSurfer_struct::N_FaceSet, SUMA_FreeSurfer_struct::N_Node, SUMA_FreeSurfer_struct::NodeList, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_filexists(), SUMA_free, SUMA_LH, SUMA_READ_FLOAT, SUMA_READ_INT, SUMA_RETURN, SUMA_SL_Err, and SUMA_WHAT_ENDIAN.

Referenced by SUMA_Load_Surface_Object_eng().

02287 {/*SUMA_FreeSurfer_ReadBin_eng*/
02288         static char FuncName[]={"SUMA_FreeSurfer_ReadBin_eng"};
02289    char stmp[50]; 
02290    FILE *fs_file;
02291         int ex, End, rmax,  chnk, cnt, i, amax[3], maxamax, maxamax2, id, ND, id2, NP, ip, *NodeId, magic;
02292         float jnkf, *NodeList;
02293         char c;
02294    byte m1, m2, m3;
02295         SUMA_Boolean bs;
02296    SUMA_Boolean LocalHead = NOPE;
02297            
02298         SUMA_ENTRY;
02299    
02300    if (debug) LocalHead = YUP;
02301    
02302         /* check for existence */
02303         if (!SUMA_filexists(f_name)) {
02304                 fprintf(SUMA_STDERR,"Error %s: File %s does not exist or cannot be read.\n", FuncName, f_name);
02305                 SUMA_RETURN (NOPE);
02306         }else if ( debug > 1) {
02307                 fprintf(SUMA_STDERR,"%s: File %s exists and will be read.\n", FuncName, f_name);
02308         }
02309         
02310         /* start reading */
02311         fs_file = fopen (f_name,"r");
02312         if (fs_file == NULL)
02313                 {
02314                         SUMA_SL_Err ("Could not open input file ");
02315                         SUMA_RETURN (NOPE);
02316                 }
02317 
02318    SUMA_WHAT_ENDIAN(End);
02319    if (End == MSB_FIRST) {
02320       SUMA_LH("No swapping needed");
02321       bs = NOPE;
02322    } else {
02323       bs = YUP;
02324       SUMA_LH("Swapping needed");
02325    }
02326    
02327    ex = fread (&m1, 1, 1, fs_file);
02328    ex = fread (&m2, 1, 1, fs_file);
02329    ex = fread (&m3, 1, 1, fs_file);
02330    magic = (m1 << 16) + (m2 << 8) + m3 ;
02331    if (magic == (-2 & 0x00ffffff)) {
02332       SUMA_LH("OK tri");
02333    } else {
02334       SUMA_SL_Err("Failed to identify magic number for a triangulated surface.\n");
02335       SUMA_RETURN(NOPE);
02336    }
02337    chnk = sizeof(char);
02338    ex = fread (&c, chnk, 1, fs_file);
02339    rmax = 0;
02340    while (c != '\n' &&rmax < 5000) {
02341       if (LocalHead) fprintf(SUMA_STDERR,"%c",c);
02342       ex = fread (&c, chnk, 1, fs_file);
02343       ++rmax;
02344    }
02345    if (rmax >= 5000) {
02346       SUMA_SL_Err("Unexpected tres tres long comment.");
02347       SUMA_RETURN(NOPE);
02348    }
02349    SUMA_LH("End of comment");
02350    /* read one more to skip second \n */
02351    ex = fread (&c, chnk, 1, fs_file);
02352    if (c != '\n') {
02353       SUMA_SL_Err("Failed to find second newline.");
02354       SUMA_RETURN(NOPE);
02355    }else {
02356       SUMA_LH("Found end of comment");
02357    }
02358    
02359    /* read the number of nodes and the number of triangles */
02360    SUMA_READ_INT (&FS->N_Node, bs, fs_file, ex);
02361    if (FS->N_Node < 0 || FS->N_Node > 2000000) {
02362       SUMA_SL_Err("Failed to get number of nodes");
02363       SUMA_RETURN(NOPE);
02364    }else {
02365       if (LocalHead) fprintf(SUMA_STDERR,"%s: Expecting to read %d nodes.\n", FuncName, FS->N_Node);
02366    }
02367    
02368    SUMA_READ_INT (&FS->N_FaceSet, bs, fs_file, ex);
02369    if (FS->N_FaceSet < 0 || FS->N_FaceSet > 2000000) {
02370       SUMA_SL_Err("Failed to get number of triangles");
02371       SUMA_RETURN(NOPE);
02372    }else {
02373       if (LocalHead) fprintf(SUMA_STDERR,"%s: Expecting to read %d triangles.\n", FuncName, FS->N_FaceSet);
02374    }
02375    
02376    /* allocate */
02377         FS->NodeList = (float *)SUMA_calloc(FS->N_Node * 3, sizeof(float));
02378         FS->FaceSetList = (int *)SUMA_calloc(FS->N_FaceSet * 3, sizeof(int));
02379    if (!FS->NodeList || !FS->FaceSetList) {
02380       SUMA_SL_Err("Failed to allocate");
02381       SUMA_RETURN(NOPE);
02382    }
02383    
02384    /*read in the meat */
02385    for (i=0; i<FS->N_Node * 3; ++i) {
02386       SUMA_READ_FLOAT (&(FS->NodeList[i]), bs, fs_file, ex);
02387       if (ex == EOF) {
02388          SUMA_SL_Err("Premature end of file!");
02389          SUMA_free(FS->NodeList); SUMA_free(FS->FaceSetList);  FS->NodeList = NULL ; FS->FaceSetList = NULL;
02390          SUMA_RETURN(NOPE);
02391       }
02392    }
02393    for (i=0; i<FS->N_FaceSet * 3; ++i) {
02394       SUMA_READ_INT (&(FS->FaceSetList[i]), bs, fs_file, ex);
02395       if (ex == EOF) {
02396          SUMA_SL_Err("Premature end of file!");
02397          SUMA_free(FS->NodeList); SUMA_free(FS->FaceSetList);  FS->NodeList = NULL ; FS->FaceSetList = NULL;
02398          SUMA_RETURN(NOPE);
02399       }   
02400    }
02401    
02402    fclose(fs_file);
02403    SUMA_LH("Returning");
02404    SUMA_RETURN(YUP);
02405 }

SUMA_Boolean SUMA_FreeSurfer_WritePatch char *    fileNm,
SUMA_SurfaceObject   SO,
char *    firstLine,
SUMA_SurfaceObject   SOparent
 

Definition at line 2218 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::EL, SUMA_SurfaceObject::FaceSetList, fout, i, SUMA_SurfaceObject::Label, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SurfaceObject::NodeList, SUMA_Boolean, SUMA_ENTRY, SUMA_filexists(), SUMA_free, SUMA_MaskOfNodesInPatch(), SUMA_RETURN, SUMA_SL_Crit, SUMA_SL_Err, SUMA_SL_Warn, SUMA_SurfaceFileName(), and SUMA_whichTri().

Referenced by SUMA_Save_Surface_Object().

02219 {
02220    static char FuncName[]={"SUMA_FreeSurfer_WritePatch"};
02221    int cnt, i, iface;
02222    int *FaceSetIndexInParent=NULL;
02223    SUMA_Boolean *isInPatch=NULL;
02224    FILE *fout=NULL;
02225    
02226    SUMA_ENTRY;
02227    
02228    if (!fileNm || !SO || !SO_parent || !SO_parent->EL) {
02229       SUMA_SL_Err("NULL input params");
02230       SUMA_RETURN(NOPE);
02231    }
02232    
02233    if (SUMA_filexists(fileNm)) {
02234       SUMA_SL_Err("Output file exists, will not overwrite");
02235       SUMA_RETURN(NOPE);
02236    }
02237    
02238    fout = fopen(fileNm,"w");
02239    if (!fout) {
02240       SUMA_SL_Err("Failed to open file for writing.\nCheck permissions.");
02241       SUMA_RETURN(NOPE);
02242    }
02243    
02244    if (firstLine) {
02245       fprintf(fout, "%s\n", firstLine);
02246    } else {
02247       if (!SO->Label) SO->Label = SUMA_SurfaceFileName (SO, NOPE);
02248       fprintf(fout, "#!ascii version of patch %s\n", SO->Label);
02249    }
02250    
02251    /* which nodes are in this patch ? */
02252    isInPatch = SUMA_MaskOfNodesInPatch(SO, &cnt);
02253    if (!isInPatch) {
02254       SUMA_SL_Crit("Failed in SUMA_MaskOfNodesInPatch");
02255       SUMA_RETURN(NOPE);
02256    }
02257 
02258    /* number of nodes and number of triangles in mesh */
02259    fprintf(fout, "%d %d\n", cnt, SO->N_FaceSet);
02260    /* write the node coordinates */
02261    for (i=0; i < SO->N_Node; ++i) {
02262       if (isInPatch[i]) {
02263          fprintf(fout, "%d\n%f\t%f\t%f\n", i, SO->NodeList[3*i], SO->NodeList[3*i+1], SO->NodeList[3*i+2]);
02264       }
02265    }
02266    for (i=0; i < SO->N_FaceSet; ++i) {
02267       iface = SUMA_whichTri (SO_parent->EL, SO->FaceSetList[3*i], SO->FaceSetList[3*i+1], SO->FaceSetList[3*i+2], 0);
02268       if (iface < 0) {
02269          SUMA_SL_Warn("Parent surface does not contain triangle in patch!\nTriangle skipped.");
02270       } else {
02271          fprintf(fout, "%d\n%d\t%d\t%d\n", iface, SO->FaceSetList[3*i], SO->FaceSetList[3*i+1], SO->FaceSetList[3*i+2]);
02272       }
02273    }
02274    
02275    
02276    SUMA_free(FaceSetIndexInParent); FaceSetIndexInParent = NULL;
02277    SUMA_free(isInPatch); isInPatch = NULL;
02278 
02279    fclose(fout);
02280    SUMA_RETURN(YUP);
02281 }

SUMA_Boolean SUMA_FS_Write char *    fileNm,
SUMA_SurfaceObject   SO,
char *    firstLine
 

Function to write a surface object to a FreeSurfer .asc file format ans = SUMA_Boolean SUMA_FS_Write (fileNm, SO, firstLine);.

Parameters:
fileNm  (char *) name (and path) of file.
SO  (SUMA_SurfaceObject *) Surface Object
firstLine  (char *) string to place as comment (begins with #) in fileNm
Returns:
YUP/NOPE
The function will not overwrite pre-existing. Written by Brenna Bargall

Definition at line 3166 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, i, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, SUMA_Boolean, SUMA_ENTRY, SUMA_filexists(), and SUMA_RETURN.

Referenced by SUMA_Save_Surface_Object().

03167 {
03168    static char FuncName[]={"SUMA_FS_Write"};
03169    int i, j;
03170    FILE *outFile = NULL;
03171    
03172    SUMA_ENTRY;
03173    
03174    if (SUMA_filexists(fileNm)) {
03175       fprintf (SUMA_STDERR, "Error %s: file %s exists, will not overwrite.\n",FuncName, fileNm);
03176       SUMA_RETURN (NOPE);
03177    }
03178    
03179    if (SO->NodeDim != 3 || SO->FaceSetDim != 3) {
03180       fprintf (SUMA_STDERR, "Error %s: Must have NodeDim and FaceSetDim = 3.\n",FuncName);
03181       SUMA_RETURN (NOPE);
03182    }
03183 
03184    outFile = fopen(fileNm, "w");
03185    if (!outFile) {
03186       fprintf (SUMA_STDERR, "Error %s: Failed in opening %s for writing.\n",FuncName, fileNm);
03187       SUMA_RETURN (NOPE);
03188    } 
03189    
03190    fprintf (outFile,"#%s\n", firstLine);
03191    fprintf (outFile, "%d %d\n", SO->N_Node, SO->N_FaceSet);
03192 
03193    j=0;
03194    for (i=0; i<SO->N_Node; ++i) {
03195       j=SO->NodeDim * i;
03196       fprintf (outFile, "%f  %f  %f  0\n", SO->NodeList[j], SO->NodeList[j+1], SO->NodeList[j+2]);
03197    }
03198 
03199    j=0;
03200    for (i=0; i<SO->N_FaceSet; ++i) {
03201       j = SO->FaceSetDim * i;
03202       fprintf (outFile, "%d %d %d 0\n", SO->FaceSetList[j], SO->FaceSetList[j+1], SO->FaceSetList[j+2]);
03203    }
03204     
03205    
03206    fclose(outFile);
03207 
03208    SUMA_RETURN (YUP);
03209    
03210 }

SUMA_SurfaceObject* SUMA_Load_Surface_Object_Wrapper char *    if_name,
char *    if_name2,
char *    vp_name,
SUMA_SO_File_Type    SO_FT,
SUMA_SO_File_Format    SO_FF,
char *    sv_name,
int    debug
 

a function to simplify loading surfaces the old way The only difference with SUMA_Load_Surface_Object_eng is that it takes the file names needed in the first three character pointers usually: if_name1: (char *) name of entire surface file or the coordinates file if_name2: (char *) name of triangulation file vp_name: (char *) name of volume parent file, just for SureFit surfaces.

Definition at line 50 of file SUMA_Surface_IO.c.

References LocalHead, SUMA_SFname::name_coord, SUMA_SFname::name_param, SUMA_SFname::name_topo, SUMA_ASCII, SUMA_BINARY, SUMA_BINARY_BE, SUMA_Boolean, SUMA_BRAIN_VOYAGER, SUMA_ENTRY, SUMA_FF_NOT_SPECIFIED, SUMA_free, SUMA_FREE_SURFER, SUMA_FREE_SURFER_PATCH, SUMA_isExtension(), SUMA_Load_Surface_Object(), SUMA_Load_Surface_Object_eng(), SUMA_malloc, SUMA_OPENDX_MESH, SUMA_PLY, SUMA_RETURN, SUMA_SO_File_Format, SUMA_SO_File_Type, SUMA_SUREFIT, and SUMA_VEC.

00052 {
00053    static char FuncName[]={"SUMA_Load_Surface_Object_Wrapper"};
00054    SUMA_SurfaceObject *SO=NULL;
00055    void *SO_name=NULL;
00056    SUMA_SFname *SF_name = NULL;
00057    SUMA_Boolean LocalHead = NOPE;
00058 
00059    SUMA_ENTRY;
00060 
00061    switch (SO_FT) {
00062       case SUMA_SUREFIT:
00063          SF_name = (SUMA_SFname *) SUMA_malloc(sizeof(SUMA_SFname));
00064          sprintf(SF_name->name_coord,"%s", if_name);
00065          sprintf(SF_name->name_topo,"%s", if_name2); 
00066          if (!vp_name) { /* initialize to empty string */
00067             SF_name->name_param[0] = '\0'; 
00068          }
00069          else {
00070             sprintf(SF_name->name_param,"%s", vp_name);
00071          }
00072          SO_name = (void *)SF_name;
00073          if (debug > 0) fprintf (SUMA_STDOUT,"Reading %s and %s...\n", SF_name->name_coord, SF_name->name_topo);
00074          SO = SUMA_Load_Surface_Object (SO_name, SUMA_SUREFIT, SUMA_ASCII, sv_name);
00075          break;
00076       case SUMA_VEC:
00077          SF_name = (SUMA_SFname *) SUMA_malloc(sizeof(SUMA_SFname));
00078          sprintf(SF_name->name_coord,"%s", if_name);
00079          sprintf(SF_name->name_topo,"%s", if_name2); 
00080          SO_name = (void *)SF_name;
00081          fprintf (SUMA_STDOUT,"Reading %s and %s...\n", SF_name->name_coord, SF_name->name_topo);
00082          SO = SUMA_Load_Surface_Object (SO_name, SUMA_VEC, SUMA_ASCII, sv_name);
00083          break;
00084       case SUMA_FREE_SURFER:
00085       case SUMA_FREE_SURFER_PATCH:
00086          SO_name = (void *)if_name; 
00087          fprintf (SUMA_STDOUT,"Reading %s ...\n",if_name);
00088          if (SUMA_isExtension(SO_name, ".asc")) 
00089             SO = SUMA_Load_Surface_Object (SO_name, SUMA_FREE_SURFER, SUMA_ASCII, sv_name);
00090          else
00091             SO = SUMA_Load_Surface_Object_eng (SO_name, SUMA_FREE_SURFER, SUMA_BINARY_BE, sv_name, 0);
00092          break;  
00093       case SUMA_OPENDX_MESH:
00094          SO_name = (void *)if_name; 
00095          fprintf (SUMA_STDOUT,"Reading %s ...\n",if_name);
00096          SO = SUMA_Load_Surface_Object (SO_name, SUMA_OPENDX_MESH, SUMA_ASCII, sv_name);
00097          break;  
00098       case SUMA_PLY:
00099          SO_name = (void *)if_name; 
00100          fprintf (SUMA_STDOUT,"Reading %s ...\n",if_name);
00101          SO = SUMA_Load_Surface_Object (SO_name, SUMA_PLY, SUMA_FF_NOT_SPECIFIED, sv_name);
00102          break;  
00103       case SUMA_BRAIN_VOYAGER:
00104          SO_name = (void *)if_name; 
00105          fprintf (SUMA_STDOUT,"Reading %s ...\n",if_name);
00106          SO = SUMA_Load_Surface_Object (SO_name, SUMA_BRAIN_VOYAGER, SUMA_BINARY, sv_name);
00107          break;  
00108       default:
00109          fprintf (SUMA_STDERR,"Error %s: Bad format.\n", FuncName);
00110          exit(1);
00111    }
00112 
00113    if (SF_name) SUMA_free(SF_name); SF_name = NULL;
00114    SUMA_RETURN(SO);
00115 }

SUMA_FORM_AFNI_DSET_STRUCT* SUMA_New_FormAfniDset_Opt void   
 

Definition at line 6380 of file SUMA_Surface_IO.c.

References SUMA_FORM_AFNI_DSET_STRUCT::datum, SUMA_FORM_AFNI_DSET_STRUCT::dimen_ii, SUMA_FORM_AFNI_DSET_STRUCT::dimen_jj, SUMA_FORM_AFNI_DSET_STRUCT::dimen_kk, SUMA_FORM_AFNI_DSET_STRUCT::do_ijk, SUMA_FORM_AFNI_DSET_STRUCT::dval, SUMA_FORM_AFNI_DSET_STRUCT::full_list, SUMA_FORM_AFNI_DSET_STRUCT::fval, SUMA_FORM_AFNI_DSET_STRUCT::mask, SUMA_FORM_AFNI_DSET_STRUCT::master, SUMA_FORM_AFNI_DSET_STRUCT::mmask, SUMA_FORM_AFNI_DSET_STRUCT::mset, SUMA_FORM_AFNI_DSET_STRUCT::orcode, SUMA_FORM_AFNI_DSET_STRUCT::prefix, SUMA_FORM_AFNI_DSET_STRUCT::prefix_path, SUMA_ENTRY, SUMA_malloc, and SUMA_RETURN.

Referenced by main().

06381 {
06382    static char FuncName[]={"SUMA_New_FormAfniDset_Opt"};
06383    SUMA_FORM_AFNI_DSET_STRUCT *Opt=NULL;
06384    
06385    SUMA_ENTRY;
06386    
06387    Opt = (SUMA_FORM_AFNI_DSET_STRUCT*)SUMA_malloc(sizeof(SUMA_FORM_AFNI_DSET_STRUCT));
06388    
06389    Opt->master = NULL;
06390    Opt->mset = NULL;
06391    Opt->mask = NULL;
06392    Opt->prefix = NULL;
06393    Opt->prefix_path = NULL;
06394    Opt->orcode = NULL;
06395    Opt->do_ijk = 1;
06396    Opt->dimen_ii=0;
06397    Opt->dimen_jj=0;
06398    Opt->dimen_kk=0;
06399    Opt->datum=MRI_short;
06400    Opt->dval=1.0;
06401    Opt->fval=0.0;
06402    Opt->mmask=NULL;
06403    Opt->full_list = 0;
06404    
06405    SUMA_RETURN(Opt);
06406 }

SUMA_SurfaceObject* SUMA_nimlSO2SO NI_group   ngr
 

END Adding data elements *

Definition at line 7139 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::AnatCorrect, SUMA_SurfaceObject::DomainGrandParentID, SUMA_SurfaceObject::EL, SUMA_SurfaceObject::EmbedDim, SUMA_SurfaceObject::FaceNormList, SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::FileType, SUMA_SurfaceObject::FN, SUMA_SurfaceObject::Group, SUMA_SurfaceObject::Group_idcode_str, SUMA_NODE_FIRST_NEIGHB::idcode_str, SUMA_MEMBER_FACE_SETS::idcode_str, SUMA_SurfaceObject::idcode_str, SUMA_SurfaceObject::Label, SUMA_SurfaceObject::LocalDomainParentID, LocalHead, SUMA_SurfaceObject::MF, SUMA_SurfaceObject::ModelName, NI_element::name, NI_group::name, NI_ELEMENT_TYPE, NI_get_attribute(), NI_GROUP_TYPE, NI_set_attribute(), SUMA_SurfaceObject::NodeList, SUMA_SurfaceObject::NodeNormList, SUMA_SurfaceObject::OriginatorID, SUMA_SurfaceObject::OriginatorLabel, SUMA_SurfaceObject::parent_vol_idcode_str, NI_group::part, NI_group::part_num, NI_group::part_typ, SUMA_SurfaceObject::PolyArea, SUMA_SurfaceObject::Side, SUMA_SurfaceObject::StandardSpace, SUMA_SurfaceObject::State, SUMA_Alloc_SurfObject_Struct(), SUMA_Boolean, SUMA_copy_string(), SUMA_EMPTY_ATTR, SUMA_ENTRY, SUMA_Free_Surface_Object(), SUMA_IS_EMPTY_STR_ATTR, SUMA_LEFT, SUMA_Mesh_IJK_nel2Mesh_IJK(), SUMA_NEW_ID, SUMA_NO_SIDE, SUMA_NodeXYZ_nel2NodeXYZ(), SUMA_RETURN, SUMA_RIGHT, SUMA_SL_Err, SUMA_SL_Warn, SUMA_SurfaceTypeCode(), SUMA_VolPar_nel2SOVolPar(), NI_element::vec_filled, NI_element::vec_len, and NI_element::vec_num.

Referenced by SUMA_process_NIML_data().

07140 {
07141    static char FuncName[]={"SUMA_nimlSO2SO"};
07142    NI_element *nel = NULL;
07143    char stmp[500], *tmp;
07144    int ip;
07145    SUMA_SurfaceObject *SO=NULL;
07146    SUMA_Boolean LocalHead = NOPE;
07147    
07148    SUMA_ENTRY;
07149    
07150    if (!ngr) {  SUMA_SL_Err("Null ngr"); SUMA_RETURN(SO); }
07151    
07152    if (strcmp(ngr->name, "SurfaceObject")) {
07153       fprintf (SUMA_STDERR,"Error %s: group name (%s) is not (SUMA_SurfaceObject)\nObject does not appear to be a surface.", FuncName, ngr->name);
07154    }
07155    
07156    /* a new surface */
07157    SO = SUMA_Alloc_SurfObject_Struct(1); 
07158    if (!SO) { SUMA_SL_Err("Failed to create SO."); SUMA_RETURN(SO); }
07159    
07160    /** BEGIN ATTRIBUTES COMMON TO ALL OBJECTS **/ 
07161    tmp = SUMA_copy_string(NI_get_attribute(ngr,"Object_ID"));
07162    if (SUMA_IS_EMPTY_STR_ATTR(tmp)) { 
07163       SUMA_SL_Warn("No ID in nel.\nThat's not cool yall.\n I'll be adding a new one now."); SUMA_NEW_ID(SO->idcode_str, NULL); 
07164       NI_set_attribute(ngr, "Group_ID", SO->idcode_str);
07165    } else SO->idcode_str = SUMA_copy_string(tmp);
07166    
07167    tmp = NI_get_attribute(ngr, "Object_Type");
07168    if (SUMA_IS_EMPTY_STR_ATTR(tmp)) { SUMA_SL_Err("Missing Object Type."); SUMA_Free_Surface_Object(SO); SO = NULL; SUMA_RETURN(SO); }
07169    if (!strcmp(tmp, "Triangulated_Surface")) SO->FaceSetDim = 3;
07170    else {
07171       fprintf (SUMA_STDERR,"Error %s: Object_Type %s not recognized.\n", FuncName, tmp);
07172       SUMA_Free_Surface_Object(SO); SO = NULL; SUMA_RETURN(SO); 
07173    }   
07174    
07175    tmp = NI_get_attribute(ngr, "Object_Label");
07176    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->Label = SUMA_copy_string(tmp);  
07177    
07178    /* set the parent ID */
07179    tmp = NI_get_attribute(ngr, "Parent_ID");
07180    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->LocalDomainParentID = SUMA_copy_string(tmp);  
07181    
07182    
07183    /* set the grand parent ID */
07184    tmp = NI_get_attribute(ngr, "Grand_Parent_ID");
07185    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->DomainGrandParentID = SUMA_copy_string(tmp);  
07186    
07187    
07188    /** END ATTRIBUTES COMMON TO ALL OBJECTS **/      
07189    
07190    /** BEGIN ATTRIBUTES specific to Surfaces**/
07191    tmp = NI_get_attribute(ngr, "Subject_ID");
07192    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->Group_idcode_str = SUMA_copy_string(tmp); 
07193    
07194    tmp = NI_get_attribute(ngr, "Subject_Label");
07195    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->Group = SUMA_copy_string(tmp); 
07196    
07197    tmp = NI_get_attribute(ngr, "Instance_ID");
07198    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->OriginatorID = SUMA_copy_string(tmp);    
07199    
07200    tmp = NI_get_attribute(ngr, "Instance_Label");
07201    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->OriginatorLabel = SUMA_copy_string(tmp); 
07202    
07203    tmp = NI_get_attribute(ngr, "Model_Name");
07204    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->ModelName = SUMA_copy_string(tmp); 
07205    
07206    tmp = NI_get_attribute(ngr, "Side");
07207    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
07208       if (!strcmp(tmp,"none")) SO->Side = SUMA_NO_SIDE;
07209       else if (!strcmp(tmp,"left")) SO->Side = SUMA_LEFT;
07210       else if (!strcmp(tmp,"right")) SO->Side = SUMA_RIGHT;
07211    } 
07212 
07213    tmp = NI_get_attribute(ngr, "Layer_Name");
07214    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->State = SUMA_copy_string(tmp); 
07215 
07216    tmp = NI_get_attribute(ngr, "Anatomically_Correct");
07217    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) {
07218       if (!strcmp(tmp,"yes")) SO->AnatCorrect = 1; 
07219       else SO->AnatCorrect = 0; 
07220    }
07221     
07222    tmp = NI_get_attribute(ngr, "Embedding_Dimension");
07223    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->EmbedDim = atoi(tmp); 
07224    
07225    tmp = NI_get_attribute(ngr, "Surface_Creation_Software");
07226    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->FileType = SUMA_SurfaceTypeCode(tmp); 
07227    
07228    tmp = NI_get_attribute(ngr, "Standard_Space");
07229    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->StandardSpace = SUMA_copy_string(tmp); 
07230    
07231    tmp = NI_get_attribute(ngr, "SUMA_Afni_Parent_Vol_ID");
07232    if (!SUMA_IS_EMPTY_STR_ATTR(tmp)) SO->parent_vol_idcode_str = SUMA_copy_string(tmp); 
07233       
07234    
07235    /** END ATTRIBUTES specific to Surfaces**/ 
07236    
07237    /* now read the elements in this group */
07238    for( ip=0 ; ip < ngr->part_num ; ip++ ){ /* do not free elements as you process them, free with group at end */
07239       switch( ngr->part_typ[ip] ){
07240          /*-- a sub-group ==> recursion! --*/
07241          case NI_GROUP_TYPE:
07242             SUMA_SL_Err("Not ready from groups inside surface group. Group ignored"); 
07243             break ;
07244          case NI_ELEMENT_TYPE:
07245             nel = (NI_element *)ngr->part[ip] ;
07246             if (LocalHead)  {
07247                fprintf(SUMA_STDERR,"%s:     name=%s vec_len=%d vec_filled=%d, vec_num=%d\n", FuncName,\
07248                         nel->name, nel->vec_len, nel->vec_filled, nel->vec_num );
07249             }
07250 
07251             /*--- NodeList ---*/
07252             if( strcmp(nel->name,"Node_XYZ") == 0 || strcmp(nel->name,"NewNode_XYZ") == 0) { /* Get Da NodeList */
07253                if (LocalHead) fprintf (SUMA_STDERR,"%s:\nGetting NodeList...\n", 
07254                                              FuncName);
07255                if (!SUMA_NodeXYZ_nel2NodeXYZ(SO, nel)) {
07256                   SUMA_SL_Err("Failed in SUMA_NodeXYZ_nel2NodeXYZ");
07257                   SUMA_Free_Surface_Object(SO); SO = NULL; SUMA_RETURN(SO);
07258                }
07259             } else if ( strcmp(nel->name,"Mesh_IJK") == 0 || strcmp(nel->name,"NewMesh_IJK") == 0) { /* Get Da FaceSetList */ 
07260                if (LocalHead) fprintf (SUMA_STDERR,"%s:\nGetting FaceSetList...\n", 
07261                                              FuncName);
07262                if (!SUMA_Mesh_IJK_nel2Mesh_IJK(SO, nel)) {
07263                   SUMA_SL_Err("Failed in SUMA_Mesh_IJK_nel2Mesh_IJK");
07264                   SUMA_Free_Surface_Object(SO); SO = NULL; SUMA_RETURN(SO);
07265                }
07266             } else if ( strcmp(nel->name,"SurfaceVolumeParent") == 0) { /* Get Da FaceSetList */ 
07267                if (LocalHead) fprintf (SUMA_STDERR,"%s:\nGetting VolPar...\n", 
07268                                              FuncName);
07269                if (!SUMA_VolPar_nel2SOVolPar(SO, nel)) {
07270                   SUMA_SL_Err("Failed in SUMA_VolPar_nel2SOVolPar");
07271                   SUMA_Free_Surface_Object(SO); SO = NULL; SUMA_RETURN(SO);
07272                }
07273             } else {
07274                fprintf (SUMA_STDERR,"Warning %s:\n nel (%s) unknown, ignoring it.\n", FuncName, nel->name);
07275             }
07276             break;
07277          default:
07278             SUMA_SL_Err("Don't know what to make of this group element, ignoring.");
07279             break;
07280       }
07281    }
07282    
07283    if (!SO->NodeList || !SO->FaceSetList) { /* perhaps you'll remove this condition in the future ...*/
07284       SUMA_SL_Err("Looks like NodeList and/or FaceSetList not in group. Balking.\n");
07285       SUMA_Free_Surface_Object(SO); SO = NULL; SUMA_RETURN(SO);
07286    }
07287    
07288    /* check on all elements that need to be loaded */   
07289    tmp = NI_get_attribute(ngr, "Mesh_Element_ID");
07290    if (!SUMA_IS_EMPTY_STR_ATTR(tmp))  { 
07291       if (!SO->FaceSetList) { /* element was not part of this group, usually recover from other files on disk, for the moment, warning */
07292          fprintf (SUMA_STDERR,"Warning %s:\n group %s called for FaceSetList element_ID %s which was not found.\n", FuncName, ngr->name, tmp);  
07293          /* 
07294          in the future, try to load from separate file
07295          nel = SUMA_Find_nel_File(tmp); (for example) SUMA_Mesh_IJK_nel2Mesh_IJK(SO, nel) ;  NI_free_nel(nel); nel = NULL; 
07296          */     
07297       }
07298    }
07299 
07300    tmp = NI_get_attribute(ngr, "NodeList_Element_ID");
07301    if (!SUMA_IS_EMPTY_STR_ATTR(tmp))  { 
07302       if (!SO->NodeList) { /* element was not part of this group, usually recover from other files on disk, for the moment, warning */
07303          fprintf (SUMA_STDERR,"Warning %s:\n group %s called for NodeList element_ID %s which was not found.\n", FuncName, ngr->name, tmp);  
07304          /* 
07305          in the future, try to load from separate file
07306          nel = SUMA_Find_nel_File(tmp); (for example) SUMA_NodeXYZ_nel2NodeXYZ(SO, nel) ;  NI_free_nel(nel); nel = NULL; 
07307          */     
07308       }
07309    }
07310    
07311    tmp = NI_get_attribute(ngr, "facenormals_idcode_str");
07312    if (!SUMA_IS_EMPTY_STR_ATTR(tmp))  { 
07313       if (!SO->FaceNormList) { /* element was not part of this group, usually recover from other files on disk, for the moment, warning */
07314          fprintf (SUMA_STDERR,"Warning %s:\n group %s called for facenormals element_ID %s which was not found.\n", FuncName, ngr->name, tmp);  
07315          /* 
07316          in the future, try to load from separate file
07317          nel = SUMA_Find_nel_File(tmp); (for example) xxxxxx(SO, nel) ;  NI_free_nel(nel); nel = NULL; 
07318          */     
07319       }
07320    }
07321      
07322    tmp = NI_get_attribute(ngr, "Node_Normals_Element_ID");
07323    if (!SUMA_IS_EMPTY_STR_ATTR(tmp))  { 
07324       if (!SO->NodeNormList) { /* element was not part of this group, usually recover from other files on disk, for the moment, warning */
07325          fprintf (SUMA_STDERR,"Warning %s:\n group %s called for Node_Normals element_ID %s which was not found.\n", FuncName, ngr->name, tmp);  
07326          /* 
07327          in the future, try to load from separate file
07328          nel = SUMA_Find_nel_File(tmp); (for example) xxxxxx(SO, nel) ;  NI_free_nel(nel); nel = NULL; 
07329          */     
07330       }
07331    }
07332    
07333    tmp = NI_get_attribute(ngr, "Polygon_Area_Element_ID");
07334    if (!SUMA_IS_EMPTY_STR_ATTR(tmp))  { 
07335       if (!SO->PolyArea) { /* element was not part of this group, usually recover from other files on disk, for the moment, warning */
07336          fprintf (SUMA_STDERR,"Warning %s:\n group %s called for Polygon_Area element_ID %s which was not found.\n", FuncName, ngr->name, tmp);  
07337          /* 
07338          in the future, try to load from separate file
07339          nel = SUMA_Find_nel_File(tmp); (for example) xxxxxx(SO, nel) ;  NI_free_nel(nel); nel = NULL; 
07340          */     
07341       }
07342    }
07343    
07344    tmp = NI_get_attribute(ngr, "SUMA_Edge_List_Element_ID");
07345    if (!SUMA_IS_EMPTY_STR_ATTR(tmp))  { 
07346       if (!SO->EL) { /* element was not part of this group, usually recover from other files on disk, for the moment, warning */
07347          fprintf (SUMA_STDERR,"Warning %s:\n group %s called for Edge_List element_ID %s which was not found.\n", FuncName, ngr->name, tmp);  
07348          /* 
07349          in the future, try to load from separate file
07350          nel = SUMA_Find_nel_File(tmp); (for example) xxxxxx(SO, nel) ;  NI_free_nel(nel); nel = NULL; 
07351          */     
07352       }
07353    }
07354 
07355    tmp = NI_get_attribute(ngr, "SUMA_Node_Face_Member_Element_ID");
07356    if (!SUMA_IS_EMPTY_STR_ATTR(tmp))  { 
07357       if (!SO->MF) { /* element was not part of this group, usually recover from other files on disk, for the moment, warning */
07358          fprintf (SUMA_STDERR,"Warning %s:\n group %s called for Node_Face_Member element_ID %s which was not found.\n", FuncName, ngr->name, tmp);  
07359          /* 
07360          in the future, try to load from separate file
07361          nel = SUMA_Find_nel_File(tmp); (for example) xxxxxx(SO, nel) ;  NI_free_nel(nel); nel = NULL; 
07362          */     
07363       }
07364    }
07365    
07366    tmp = NI_get_attribute(ngr, "SUMA_Node_First_Neighb_Element_ID");
07367    if (!SUMA_IS_EMPTY_STR_ATTR(tmp))  { 
07368       if (!SO->FN) { /* element was not part of this group, usually recover from other files on disk, for the moment, warning */
07369          fprintf (SUMA_STDERR,"Warning %s:\n group %s called for Node_First_Neighb element_ID %s which was not found.\n", FuncName, ngr->name, tmp);  
07370          /* 
07371          in the future, try to load from separate file
07372          nel = SUMA_Find_nel_File(tmp); (for example) xxxxxx(SO, nel) ;  NI_free_nel(nel); nel = NULL; 
07373          */     
07374       }
07375    }
07376    
07377    
07378    if (SO->MF && SO->MF->idcode_str) {
07379       NI_set_attribute(ngr, "SUMA_Node_Face_Member_Element_ID", SO->MF->idcode_str);
07380    } else {
07381       NI_set_attribute(ngr, "SUMA_Node_Face_Member_Element_ID", SUMA_EMPTY_ATTR);
07382    }
07383    
07384    if (SO->FN && SO->FN->idcode_str) {
07385       NI_set_attribute(ngr, "SUMA_Node_First_Neighb_Element_ID", SO->FN->idcode_str);
07386    } else {
07387       NI_set_attribute(ngr, "SUMA_Node_First_Neighb_Element_ID", SUMA_EMPTY_ATTR);
07388    }
07389    
07390 
07391     
07392    SUMA_RETURN(SO);
07393 }

void SUMA_OpenDrawnROI char *    filename,
void *    data
 

A function to write a Surface Object into a Surefit ascii format Handles opening an ROI file.

Parameters:
filename  (char *)
data  (void *)

  • results are placed in SUMAg_DOv

Definition at line 4360 of file SUMA_Surface_IO.c.

References SUMA_X_DrawROI::curDrawnROI, SUMA_X_AllView::DrawROI, SUMA_SurfaceViewer::Focus_SO_ID, i, SUMA_SurfaceObject::idcode_str, LocalHead, SUMA_DRAWN_ROI::Parent_idcode_str, ROIdO_type, SE_Redisplay_AllVisible, SES_Suma, SUMA_AddDO(), SUMA_Boolean, SUMA_CreateList(), SUMA_Engine(), SUMA_ENTRY, SUMA_findSOp_inDOv(), SUMA_free, SUMA_InitializeDrawROIWindow(), SUMA_isExtension(), SUMA_LH, SUMA_LOCAL, SUMA_OpenDrawnROI_1D(), SUMA_OpenDrawnROI_NIML(), SUMA_Paint_SO_ROIplanes_w(), SUMA_REGISTER_TAIL_COMMAND_NO_DATA, SUMA_RETURNe, SUMA_SLP_Err, SUMA_SLP_Warn, SUMAg_N_DOv, and SUMA_CommonFields::X.

04361 {
04362    static char FuncName[]={"SUMA_OpenDrawnROI"};
04363    DList *list=NULL;
04364    SUMA_DRAWN_ROI **ROIv=NULL;
04365    int i, N_ROI;
04366    SUMA_SurfaceObject *SO=NULL;
04367    
04368    SUMA_Boolean LocalHead = NOPE;
04369    
04370    SUMA_ENTRY;
04371 
04372    SUMA_LH("Called");   
04373 
04374    /* check for type ... */
04375    
04376    if (SUMA_isExtension(filename, ".niml.roi")) {
04377       /* load niml ROI */
04378       if (!( ROIv = SUMA_OpenDrawnROI_NIML (filename, &N_ROI, YUP))) {
04379          SUMA_SLP_Err("Failed to read NIML ROI.");
04380          SUMA_RETURNe;
04381       }
04382    }else if (SUMA_isExtension(filename, ".1D.roi")) {
04383       /* load 1D ROI */
04384       /* You need to select a parent surface */
04385       SUMA_SLP_Warn("Assuming parent surface.");
04386       SO = (SUMA_SurfaceObject *)(SUMAg_DOv[SUMAg_SVv[0].Focus_SO_ID].OP);
04387       if (!( ROIv = SUMA_OpenDrawnROI_1D (filename, SO->idcode_str, &N_ROI, YUP))) {
04388          SUMA_SLP_Err("Failed to read NIML ROI.");
04389          SUMA_RETURNe;
04390       }
04391    }else {
04392       SUMA_SLP_Err(  "Failed to recognize\n"
04393                      "ROI type from filename.");
04394       SUMA_RETURNe;
04395    } 
04396    
04397    /* put those ROIs in SUMAg_DOv */
04398    for (i=0; i < N_ROI; ++i) {
04399       /* add ROI to DO list */
04400       if (!SUMA_AddDO (SUMAg_DOv, &SUMAg_N_DOv, (void *)ROIv[i], ROIdO_type, SUMA_LOCAL)) {
04401          fprintf(SUMA_STDERR,"Error %s: Failed in SUMA_AddDO.\n", FuncName);
04402       }
04403    }
04404    /* free ROIv */
04405    if (ROIv) SUMA_free(ROIv); ROIv = NULL;
04406 
04407    /* if there are no currentROIs selected, set currentROI to the
04408       first in the list */
04409    if (!SUMAg_CF->X->DrawROI->curDrawnROI) {
04410       i = 0;
04411       do {
04412          if (SUMAg_DOv[i].ObjectType == ROIdO_type) SUMAg_CF->X->DrawROI->curDrawnROI =
04413                                              (SUMA_DRAWN_ROI *)SUMAg_DOv[i].OP;
04414          ++i;
04415       } while (i < SUMAg_N_DOv && !SUMAg_CF->X->DrawROI->curDrawnROI);
04416    }
04417    
04418    if (SUMAg_CF->X->DrawROI->curDrawnROI) {
04419       SUMA_InitializeDrawROIWindow(SUMAg_CF->X->DrawROI->curDrawnROI);   
04420    }
04421    
04422    /* Now update the Paint job on the ROI plane */
04423    if (!SUMA_Paint_SO_ROIplanes_w (
04424             SUMA_findSOp_inDOv(SUMAg_CF->X->DrawROI->curDrawnROI->Parent_idcode_str, 
04425             SUMAg_DOv, SUMAg_N_DOv), SUMAg_DOv, SUMAg_N_DOv)) {
04426       SUMA_SLP_Err("Failed in SUMA_Paint_SO_ROIplanes_w.");
04427       SUMA_RETURNe;
04428    }
04429    
04430    /* put a nice redisplay here */
04431    if (!list) list = SUMA_CreateList ();
04432    SUMA_REGISTER_TAIL_COMMAND_NO_DATA(list, SE_Redisplay_AllVisible, SES_Suma, NULL); 
04433    if (!SUMA_Engine(&list)) {
04434       SUMA_SLP_Err("Failed to redisplay.");
04435       SUMA_RETURNe;
04436    }
04437    
04438    SUMA_RETURNe; 
04439 }

SUMA_DRAWN_ROI** SUMA_OpenDrawnROI_1D char *    filename,
char *    Parent_idcode_str,
int *    N_ROI,
SUMA_Boolean    ForDisplay
 

Since parent information does not exist in ROI 1D files, you need to specify the parent surface.

ans = SUMA_OpenDrawnROI_1D (filename, Parent_idcode_str);

Parameters:
filename  (char *) name of 1D file (see below for formats)
Parent_idcode_str  (char *) idcode of parent surface
N_ROI  (int *) will contain the number of ROIs read in
ForDisplay  (SUMA_Boolean) YUP: prepares ROI for display
Returns:
ans (SUMA_Boolean) YUP for good NOPE for not good.

  • The ROI is added to SUMAg_DOv
  • The 1D file can have multiple formats. Some are particularly inefficient and should not be used. But we aim to please so anything goes. You can have a varying number of columns which are i, l, r, g, b. These columns stand for index, label, red, green and blue, respectively. format 1: i Only a bunch of node (int) indices are supplied. Label of all nodes defaults to 0 and a default color is given format 2: i l Each node carries a label (int) with it. This way you can have multiple ROIs specified in one 1D file. The same color is assigned to each of the ROIs. format 3: i r g b A bunch of nodes with r g b (float) triplet specifying the nodes' colors. Obviously, since all nodes belong to the same ROI, the specification of an r g b for each node is redundant since all nodes in the same ROI have the same color. Use the niml format if that sounds crazy to you. If you want a different color for each node then you should not load the data as an ROI but as a node color file. format 4: i l r g b A bunch of nodes with labels and r g b . Like format 2 but with the possibility of specifying the colors of each ROI.

Definition at line 4481 of file SUMA_Surface_IO.c.

References far, SUMA_PARSED_NAME::FileName_NoExt, i, LocalHead, MRI_FLOAT_PTR, mri_free(), mri_read_1D(), ncol, MRI_IMAGE::nx, MRI_IMAGE::ny, r, SUMA_1DROI_to_DrawnROI(), SUMA_append_string(), SUMA_Boolean, SUMA_copy_string(), SUMA_disp_vect(), SUMA_ENTRY, SUMA_free, SUMA_Free_Parsed_Name(), SUMA_LH, SUMA_malloc, SUMA_ParseFname(), SUMA_RETURN, SUMA_SL_Err, SUMA_SLP_Err, SUMA_z_dqsort(), and SUMAg_N_DOv.

Referenced by SUMA_OpenDrawnROI().

04483 {
04484    static char FuncName[]={"SUMA_OpenDrawnROI_1D"};
04485    MRI_IMAGE *im = NULL;
04486    int ncol, nrow, *iLabel=NULL, *iNode = NULL, *isort=NULL,
04487       i, N_Labels = 0, *iStart=NULL, *iStop=NULL, cnt = 0;
04488    float *far=NULL, *r=NULL, *g=NULL, *b=NULL, *RGB=NULL;
04489    SUMA_DRAWN_ROI **ROIv=NULL;
04490    SUMA_Boolean LocalHead = NOPE;
04491    
04492    SUMA_ENTRY;
04493 
04494    SUMA_LH("Called");
04495    
04496    *N_ROI = 0;
04497    
04498    im = mri_read_1D (filename);
04499    
04500    if (!im) {
04501       SUMA_SLP_Err("Failed to read 1D file");
04502       SUMA_RETURN(NULL);
04503    }
04504    
04505    far = MRI_FLOAT_PTR(im);
04506    ncol = im->nx;
04507    nrow = im->ny;
04508    
04509    if (!ncol) {
04510       SUMA_SL_Err("Empty file");
04511       SUMA_RETURN(NULL);
04512    }
04513    if (nrow != 1 && nrow != 2 && nrow != 4 && nrow != 5) {
04514       SUMA_SL_Err("File must have\n"
04515                   " 1,2,4 or 5 columns.");
04516       mri_free(im); im = NULL;   /* done with that baby */
04517       SUMA_RETURN(NULL);
04518    }
04519    
04520    if (0 && LocalHead) {
04521       SUMA_disp_vect(far, ncol*nrow);
04522    }
04523       
04524    switch (nrow) {
04525       case 1:
04526          /* Node index only*/
04527          SUMA_LH ("1D format: i");
04528          iNode = (int *)SUMA_malloc(ncol*sizeof(int));
04529          iLabel = (int *)SUMA_malloc(1*sizeof(int));
04530          if (!iNode ||!iLabel) {
04531             SUMA_SL_Err("Failed to allocate");
04532             SUMA_RETURN(NULL);
04533          }
04534          for (i=0; i < ncol; ++i) iNode[i] = (int)far[i];
04535          mri_free(im); im = NULL;   /* done with that baby */
04536          
04537          iLabel[0] = 0;
04538          N_Labels = 1;
04539          iStart = (int *)SUMA_malloc(1*sizeof(int));
04540          iStop = (int *)SUMA_malloc(1*sizeof(int));
04541          RGB = (float *)SUMA_malloc(3*1*sizeof(float));
04542          iStart[0] = 0;
04543          iStop[0] = ncol-1;
04544          RGB[0] = 1.0; RGB[1] = 1.0; RGB[2] = 0;
04545          break;
04546       case 2:
04547          /* Node index & Node Label */
04548          SUMA_LH("1D format: i l");
04549          /* copy the node indices and labels for cleanliness */
04550          iLabel = (int *)SUMA_malloc(ncol*sizeof(int));
04551          iNode = (int *)SUMA_malloc(ncol*sizeof(int));
04552          if (!iNode || !iLabel) {
04553             SUMA_SL_Err("Failed to allocate");
04554             SUMA_RETURN(NULL);
04555          }
04556          for (i=0; i < ncol; ++i) iLabel[i] = (int)far[i+ncol];
04557          /* sort the Labels and the iNode accordingly */
04558          isort = SUMA_z_dqsort( iLabel, ncol);
04559          for (i=0; i < ncol; ++i) iNode[i] = (int)far[isort[i]];
04560 
04561          mri_free(im); im = NULL;   /* done with that baby */
04562 
04563          /* Count the number of distinct labels */
04564          N_Labels = 1;
04565          for (i=1; i < ncol; ++i) if (iLabel[i] != iLabel[i-1]) ++N_Labels;
04566          /* store where each label begins and ends */
04567          iStart = (int *)SUMA_malloc(N_Labels*sizeof(int));
04568          iStop = (int *)SUMA_malloc(N_Labels*sizeof(int));
04569          RGB = (float *)SUMA_malloc(3*N_Labels*sizeof(float));
04570          if (!iStart || !iStop) {
04571             SUMA_SL_Err("Failed to allocate");
04572             SUMA_RETURN(NULL);
04573          }
04574          cnt = 0;
04575          iStart[cnt] = 0;
04576          iStop[cnt] = ncol -1;
04577          RGB[3*cnt] = 1.0; RGB[3*cnt+1] = 1.0; RGB[3*cnt+2] = 0;
04578          for (i=1; i < ncol; ++i) {
04579             if (iLabel[i] != iLabel[i-1]) {
04580                iStop[cnt] = i-1;
04581                ++cnt; 
04582                iStart[cnt] = i;
04583                iStop[cnt] = ncol -1;
04584                RGB[3*cnt] = 1.0; RGB[3*cnt+1] = 1.0; RGB[3*cnt+2] = 0;
04585             }
04586          }
04587          break;
04588       case 4:
04589          /* Node index, R G B */
04590          SUMA_LH("1D format: i R G B");
04591          iNode = (int *)SUMA_malloc(ncol*sizeof(int));
04592          iLabel = (int *)SUMA_malloc(1*sizeof(int));
04593          r = (float *)SUMA_malloc(ncol*sizeof(float));
04594          g = (float *)SUMA_malloc(ncol*sizeof(float));
04595          b = (float *)SUMA_malloc(ncol*sizeof(float));
04596          if (!iNode || !iLabel || !r || !g || !b) {
04597             SUMA_SL_Err("Failed to allocate");
04598             SUMA_RETURN(NULL);
04599          }
04600          
04601          for (i=0; i < ncol; ++i) {
04602             iNode[i] = (int)far[i];
04603             r[i] = (float)far[i+ncol];
04604             g[i] = (float)far[i+2*ncol];
04605             b[i] = (float)far[i+3*ncol];
04606          }
04607          
04608          iLabel[0] = 0;
04609          N_Labels = 1;
04610          iStart = (int *)SUMA_malloc(1*sizeof(int));
04611          iStop = (int *)SUMA_malloc(1*sizeof(int));
04612          RGB = (float *)SUMA_malloc(3*1*sizeof(float));
04613          mri_free(im); im = NULL;   /* done with that baby */
04614         
04615          iStart[0] = 0;
04616          iStop[0] = ncol-1;
04617          RGB[0] = r[0]; RGB[1] = g[0]; RGB[2] = b[0];
04618          break;
04619       case 5:
04620          /* Node index, Node Label, R G B */
04621          SUMA_LH("1D format: i l R G B");
04622          /* copy the node indices and labels for cleanliness */
04623          iLabel = (int *)SUMA_malloc(ncol*sizeof(int));
04624          iNode = (int *)SUMA_malloc(ncol*sizeof(int));
04625          r = (float *)SUMA_malloc(ncol*sizeof(float));
04626          g = (float *)SUMA_malloc(ncol*sizeof(float));
04627          b = (float *)SUMA_malloc(ncol*sizeof(float));
04628          if (!iNode || !iLabel || !r || !g || !b) {
04629             SUMA_SL_Err("Failed to allocate");
04630             SUMA_RETURN(NULL);
04631          }
04632          for (i=0; i < ncol; ++i) iLabel[i] = (int)far[i+ncol];
04633          /* sort the Labels and the iNode accordingly */
04634          isort = SUMA_z_dqsort( iLabel, ncol);
04635          for (i=0; i < ncol; ++i) {
04636             iNode[i] = (int)far[isort[i]];
04637             r[i] = (float)far[isort[i]+2*ncol];
04638             g[i] = (float)far[isort[i]+3*ncol];
04639             b[i] = (float)far[isort[i]+4*ncol];
04640          }     
04641          mri_free(im); im = NULL;   /* done with that baby */
04642 
04643          /* Count the number of distinct labels */
04644          N_Labels = 1;
04645          for (i=1; i < ncol; ++i) if (iLabel[i] != iLabel[i-1]) ++N_Labels;
04646          /* store where each label begins and ends */
04647          iStart = (int *)SUMA_malloc(N_Labels*sizeof(int));
04648          iStop = (int *)SUMA_malloc(N_Labels*sizeof(int));
04649          RGB = (float *)SUMA_malloc(3*N_Labels*sizeof(float));
04650          if (!iStart || !iStop || !RGB) {
04651             SUMA_SL_Err("Failed to allocate");
04652             SUMA_RETURN(NULL);
04653          }
04654          cnt = 0;
04655          iStart[cnt] = 0;
04656          iStop[cnt] = ncol -1;
04657          RGB[3*cnt] = r[0]; RGB[3*cnt+1] = g[0]; RGB[3*cnt+2] = b[0];
04658          for (i=1; i < ncol; ++i) {
04659             if (iLabel[i] != iLabel[i-1]) {
04660                iStop[cnt] = i-1;
04661                ++cnt; 
04662                iStart[cnt] = i;
04663                iStop[cnt] = ncol -1;
04664                RGB[3*cnt] = r[i]; RGB[3*cnt+1] = g[i]; RGB[3*cnt+2] = b[i];
04665             }
04666          }
04667          break;
04668       default:
04669          SUMA_SLP_Err("Unrecognized 1D format");
04670          mri_free(im); im = NULL;   /* done with that baby */
04671          break;
04672    }
04673    
04674    
04675    ROIv = (SUMA_DRAWN_ROI **)SUMA_malloc(N_Labels*sizeof(SUMA_DRAWN_ROI*));
04676    
04677    for (i=0; i < N_Labels; ++i) {
04678       int Value, N_Node, *Node=NULL;
04679       float fillcolor[3], edgecolor[3];
04680       int edgethickness;
04681       char stmp[20], *Label=NULL;
04682       SUMA_PARSED_NAME *NewName=NULL; 
04683       
04684       edgethickness = 3;
04685       fillcolor[0] = RGB[3*i]; fillcolor[1] = RGB[3*i+1]; fillcolor[2] = RGB[3*i+2]; 
04686       edgecolor[0] = 0; edgecolor[1] = 0; edgecolor[2] = 1; 
04687       Value = iLabel[iStart[i]]; /* the index label of this ROI */
04688       N_Node = iStop[i] - iStart[i] + 1; /* Number of Nodes in this ROI */
04689       Node = &(iNode[iStart[i]]); /* pointer to location of first index in this ROI */
04690       /* prepare a label for these ROIs */
04691       NewName = SUMA_ParseFname (filename);
04692       if (!NewName) {
04693          Label = SUMA_copy_string("BadLabel");
04694       }else {
04695          sprintf(stmp,"(%d)", Value);
04696          Label = SUMA_append_string(stmp,NewName->FileName_NoExt);
04697       }
04698       SUMA_LH("Transforming to Drawn ROIs...");
04699       ROIv[i] = SUMA_1DROI_to_DrawnROI( Node, N_Node , 
04700                                     Value, Parent_idcode_str,
04701                                     Label, NULL,
04702                                     fillcolor, edgecolor, edgethickness, 
04703                                     SUMAg_DOv, SUMAg_N_DOv,
04704                                     ForDisplay);
04705       if (nrow == 5 || nrow == 4) {
04706          SUMA_LH("Marking as color by fillcolor");
04707          ROIv[i]->ColorByLabel = NOPE;
04708       }
04709       if (Label) SUMA_free(Label); Label = NULL;
04710       if (NewName) SUMA_Free_Parsed_Name(NewName); NewName = NULL;
04711       if (LocalHead) fprintf (SUMA_STDERR, "%s: ROI->Parent_idcode_str %s\n", FuncName, ROIv[i]->Parent_idcode_str);
04712 
04713    }
04714  
04715    SUMA_LH("Freeing...");
04716    
04717    if (iLabel) SUMA_free(iLabel); iLabel = NULL;
04718    if (isort) SUMA_free(isort); isort = NULL;
04719    if (iNode) SUMA_free(iNode); iNode = NULL;
04720    if (iStart) SUMA_free(iStart); iStart = NULL;
04721    if (iStop) SUMA_free(iStop); iStop = NULL;
04722    if (r) SUMA_free(r); r = NULL;
04723    if (g) SUMA_free(g); g = NULL;
04724    if (b) SUMA_free(b); b = NULL;
04725    if (RGB) SUMA_free(RGB); RGB = NULL;
04726    
04727    *N_ROI = N_Labels;
04728    SUMA_RETURN(ROIv);
04729      
04730 }

SUMA_DRAWN_ROI** SUMA_OpenDrawnROI_NIML char *    filename,
int *    N_ROI,
SUMA_Boolean    ForDisplay
 

Loads a niml ROI.

Parameters:
ForDisplay  (SUMA_Boolean) YUP: Performs checks to see if ROI with similar idcode already exists and if parent surface is loaded. NOPE: Does not check for above conditions.

Definition at line 4739 of file SUMA_Surface_IO.c.

References SUMA_NIML_ROI_DATUM::action, SUMA_NIML_DRAWN_ROI::ColPlaneName, SUMA_NIML_DRAWN_ROI::EdgeColor, SUMA_NIML_DRAWN_ROI::EdgeThickness, SUMA_NIML_DRAWN_ROI::FillColor, SUMA_NIML_DRAWN_ROI::idcode_str, SUMA_NIML_DRAWN_ROI::iLabel, SUMA_NIML_DRAWN_ROI::Label, LocalHead, SUMA_NIML_ROI_DATUM::N_n, SUMA_NIML_DRAWN_ROI::N_ROI_datum, NI_element::name, NI_free_element(), NI_get_attribute(), NI_read_element(), NI_stream_close(), NI_stream_open(), SUMA_CommonFields::nimlROI_Datum_type, SUMA_NIML_ROI_DATUM::nPath, SUMA_NIML_DRAWN_ROI::Parent_idcode_str, SUMA_NIML_DRAWN_ROI::ROI_datum, strtod(), SUMA_Boolean, SUMA_calloc, SUMA_copy_string(), SUMA_DeleteROI(), SUMA_ENTRY, SUMA_existDO(), SUMA_ForceUser_YesNo(), SUMA_free, SUMA_Free_NIMLDrawROI(), SUMA_IS_EMPTY_STR_ATTR, SUMA_LH, SUMA_malloc, SUMA_MAX_DISPLAYABLE_OBJECTS, SUMA_MAX_NAME_LENGTH, SUMA_nel_stdout(), SUMA_NIMLDrawnROI_to_DrawnROI(), SUMA_NO, SUMA_NO_ALL, SUMA_NODE_ROI, SUMA_RETURN, SUMA_SL_Err, SUMA_SLP_Crit, SUMA_SLP_Err, SUMA_StringToNum(), SUMA_whichDO(), SUMA_YES, SUMA_YES_ALL, SUMAg_N_DOv, SWP_DONT_CARE, SUMA_NIML_ROI_DATUM::Type, SUMA_NIML_DRAWN_ROI::Type, NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ.

Referenced by SUMA_OpenDrawnROI().

04740 { /* begin embedded function */
04741    static char FuncName[]={"SUMA_OpenDrawnROI_NIML"};
04742    char stmp[SUMA_MAX_NAME_LENGTH+100], *nel_idcode;
04743    NI_element *nel = NULL;
04744    NI_element **nelv=NULL;
04745    NI_stream ns ;
04746    int n_read=0, idat, answer, inel, iDO, N_nel;
04747    SUMA_NIML_ROI_DATUM *niml_ROI_datum_buff=NULL;
04748    SUMA_NIML_DRAWN_ROI * nimlROI=NULL;
04749    SUMA_DRAWN_ROI **ROIv=NULL;
04750    SUMA_Boolean found = YUP, AddNel = YUP, AlwaysReplace = NOPE, NeverReplace = NOPE;
04751    SUMA_Boolean LocalHead = NOPE;
04752    
04753    SUMA_ENTRY;
04754 
04755    *N_ROI = 0;
04756    
04757    if (SUMAg_CF->nimlROI_Datum_type < 0) {
04758       SUMA_SL_Err("Bad niml type code");
04759       SUMA_RETURN(NULL);
04760    }
04761    if (LocalHead) fprintf(SUMA_STDERR, "%s: roi_type code = %d\n", FuncName, SUMAg_CF->nimlROI_Datum_type) ;
04762 
04763    sprintf(stmp,"file:%s", filename);
04764    ns = NI_stream_open( stmp , "r" ) ;
04765    if( ns == NULL ){
04766       SUMA_SL_Err("Can't open ROI file"); 
04767       SUMA_RETURN(NULL);
04768    }
04769    
04770    nelv = (NI_element **) SUMA_calloc(SUMA_MAX_DISPLAYABLE_OBJECTS, sizeof(NI_element *));
04771    if (!nelv) {
04772       SUMA_SLP_Crit("Failed to allocate");
04773       SUMA_RETURN(NULL);
04774    }
04775    
04776    NeverReplace = NOPE;
04777    AlwaysReplace = NOPE;
04778    inel = 0;
04779    do {
04780       nel = NI_read_element(ns,1) ;
04781       
04782       if (nel) {
04783          found = YUP;
04784          
04785          if (LocalHead && 0) SUMA_nel_stdout (nel);
04786          
04787          if (strcmp(nel->name,SUMA_Dset_Type_Name(SUMA_NODE_ROI))) {
04788             SUMA_SLP_Err ("ni element not of the \n Node ROI variety.\nElement discarded.");
04789             NI_free_element(nel) ; nel = NULL;
04790             SUMA_RETURN(NULL);
04791          }
04792          /* somewhat redundant test */
04793          if (nel->vec_typ[0] != SUMAg_CF->nimlROI_Datum_type) {
04794             SUMA_SLP_Err ("Datum type mismatch.");
04795             NI_free_element(nel) ; nel = NULL;
04796             SUMA_RETURN(NULL);
04797          }
04798 
04799          if (ForDisplay) {
04800             /* find out if a displayable object exists with the same idcode_str */
04801             nel_idcode = NI_get_attribute( nel , "idcode_str"); /* obsolete*/
04802             if (!nel_idcode) nel_idcode = NI_get_attribute( nel , "Object_ID"); 
04803             if (SUMA_existDO(nel_idcode, SUMAg_DOv, SUMAg_N_DOv)) {
04804                if (AlwaysReplace) {
04805                   AddNel = YUP; 
04806                }
04807                if (NeverReplace) {
04808                   AddNel = NOPE;
04809                }
04810                if (!AlwaysReplace && !NeverReplace) {   /* ASk */
04811                   sprintf(stmp, "Found duplicate ROIs.\n"\
04812                                              "Replace ROI %s (%s) by\n" \
04813                                              "version in file ?", 
04814                   NI_get_attribute( nel , "Label"), nel_idcode); 
04815 
04816                   answer = SUMA_ForceUser_YesNo (SUMAg_SVv[0].X->TOPLEVEL, 
04817                                     stmp, 
04818                                     0, SWP_DONT_CARE);
04819                   if (LocalHead) fprintf (SUMA_STDERR,"%s: Got %d, You ?\n", FuncName, answer);
04820                   switch (answer) {
04821                      case SUMA_YES:
04822                         SUMA_LH("YES");
04823                         AddNel = YUP;
04824                         break;
04825 
04826                      case SUMA_NO:
04827                         SUMA_LH("NO");
04828                         /* don't add this one */
04829                         AddNel = NOPE;
04830                         break;
04831 
04832                      case SUMA_YES_ALL:
04833                         SUMA_LH("YES ALL");
04834                         /* cancel Check_Prior */
04835                         AddNel = YUP;
04836                         AlwaysReplace = YUP;
04837                         break;
04838 
04839                      case SUMA_NO_ALL:
04840                         SUMA_LH("NO ALL");
04841                         /* don't add this one and set flag to ignore the doubles */
04842                         AddNel = NOPE;
04843                         NeverReplace = YUP;
04844                         break;
04845 
04846                      default:
04847                         SUMA_SLP_Crit("Don't know what to do with this button.");
04848                         SUMA_RETURN(NULL);
04849                         break;
04850                   }
04851                } 
04852             } else {
04853                AddNel = YUP;
04854             } 
04855          
04856             /* make sure element's parent exists */
04857             if (AddNel) {
04858                SUMA_LH("Checking for Parent surface...");
04859                iDO = SUMA_whichDO(NI_get_attribute( nel , "Parent_idcode_str"), SUMAg_DOv, SUMAg_N_DOv); /* obsolete */
04860                if (iDO < 0) iDO = SUMA_whichDO(NI_get_attribute( nel , "Parent_ID"), SUMAg_DOv, SUMAg_N_DOv);
04861               
04862                if (iDO < 0) {
04863                   SUMA_SLP_Err(  "ROI's parent surface\n"
04864                                  "is not loaded. ROI is\n"
04865                                  "discarded." );
04866                   AddNel = NOPE;
04867                }
04868             }
04869          } else {
04870             AddNel = YUP; /* ignore checks */
04871          }         
04872          
04873          if (AddNel) {
04874             SUMA_LH("Adding Nel");
04875             nelv[inel] = nel;
04876             ++inel; 
04877          }else {
04878             SUMA_LH("Skipping Nel");
04879          }
04880          
04881          ++n_read;
04882       }else {
04883          found = NOPE;
04884       } 
04885       
04886    } while (found);
04887    
04888    NI_stream_close(ns) ;
04889    N_nel = inel;
04890    
04891    if( !n_read){
04892       SUMA_SL_Err("Found no elements in file!"); 
04893       SUMA_free(nelv);
04894       SUMA_RETURN(NULL);
04895    }
04896    
04897    /* Now turn those nel into ROIS */
04898    ROIv = (SUMA_DRAWN_ROI **) SUMA_malloc(N_nel*sizeof(SUMA_DRAWN_ROI*));
04899    for (inel=0; inel < N_nel; ++inel) {
04900       if (LocalHead) fprintf (SUMA_STDERR,"%s: Processing nel %d/%d...\n", FuncName, inel, N_nel);
04901       nel = nelv[inel];
04902       nel_idcode = NI_get_attribute( nel , "idcode_str"); /* obsolete */
04903       if (!nel_idcode) nel_idcode = NI_get_attribute( nel , "Object_ID"); 
04904 
04905       /* store nel in nimlROI struct */
04906 
04907       /* allocate for nimlROI */
04908       nimlROI = (SUMA_NIML_DRAWN_ROI *)SUMA_malloc(sizeof(SUMA_NIML_DRAWN_ROI));
04909       nimlROI->Type = (int)strtod(NI_get_attribute( nel , "Type"), NULL);
04910       nimlROI->idcode_str = SUMA_copy_string(NI_get_attribute( nel , "idcode_str")); /* obsolete */
04911       if (SUMA_IS_EMPTY_STR_ATTR(nimlROI->idcode_str)) nimlROI->idcode_str = SUMA_copy_string(NI_get_attribute( nel , "Object_ID"));
04912       nimlROI->Parent_idcode_str = SUMA_copy_string(NI_get_attribute( nel , "Parent_idcode_str")); /* obsolete */
04913       if (SUMA_IS_EMPTY_STR_ATTR(nimlROI->Parent_idcode_str)) nimlROI->Parent_idcode_str = SUMA_copy_string(NI_get_attribute( nel , "Parent_ID"));
04914       nimlROI->Label = SUMA_copy_string(NI_get_attribute( nel , "Label"));
04915       nimlROI->iLabel = (int)strtod(NI_get_attribute( nel , "iLabel"), NULL);
04916       nimlROI->N_ROI_datum = nel->vec_len;
04917       nimlROI->ColPlaneName = SUMA_copy_string(NI_get_attribute( nel , "ColPlaneName"));
04918       if (SUMA_StringToNum (NI_get_attribute( nel , "FillColor"), 
04919                            nimlROI->FillColor, 3) < 0) {
04920          SUMA_SLP_Err("Failed in reading FillColor.");
04921          SUMA_free(nelv);
04922          SUMA_RETURN(NULL);
04923       }
04924       if (SUMA_StringToNum (NI_get_attribute( nel , "EdgeColor"), 
04925                            nimlROI->EdgeColor, 3) < 0) {
04926          SUMA_SLP_Err("Failed in reading EdgeColor.");
04927          SUMA_free(nelv);
04928          SUMA_RETURN(NULL);
04929       }
04930       nimlROI->EdgeThickness = (int)strtod(NI_get_attribute( nel , "EdgeThickness"), NULL);              
04931       
04932       if (LocalHead) {
04933          fprintf (SUMA_STDERR,"%s: vec_type[0] = %d (%d)\n", 
04934             FuncName, nel->vec_typ[0], SUMAg_CF->nimlROI_Datum_type) ;
04935          fprintf (SUMA_STDERR,"%s: vec_len =%d\tvec_num = %d\nidcode_str %s, Parent_idcode_str %s\n",
04936             FuncName, nel->vec_len, nel->vec_num,
04937             nimlROI->idcode_str, nimlROI->Parent_idcode_str);
04938       }
04939 
04940       nimlROI->ROI_datum = (SUMA_NIML_ROI_DATUM *)SUMA_malloc(nimlROI->N_ROI_datum*sizeof(SUMA_NIML_ROI_DATUM));
04941 
04942       /* DO NOT use niml_ROI_datum_buff = (SUMA_NIML_ROI_DATUM *)nel->vec[idat];
04943       inside the loop.
04944       For the SUMA_NIML_DRAWN_ROI you have one column of (SUMA_NIML_ROI_DATUM *)
04945       ni_type = "SUMA_NIML_ROI_DATUM". If you had for type:
04946       "SUMA_NIML_ROI_DATUM, int" then you'd have two columns with the second
04947       column being a vector of ints. The only caveat is that the second column
04948       must be of equal length to the first. */
04949       niml_ROI_datum_buff = (SUMA_NIML_ROI_DATUM *)nel->vec[0]; 
04950       /* now fill the ROI_datum structures */
04951       SUMA_LH("Filling ROI datum structures...");
04952       for (idat=0; idat< nimlROI->N_ROI_datum ; ++idat) {
04953          if (LocalHead) fprintf (SUMA_STDERR,"%s: i=%d\n", FuncName, idat);
04954          nimlROI->ROI_datum[idat].action = niml_ROI_datum_buff[idat].action;
04955          nimlROI->ROI_datum[idat].Type = niml_ROI_datum_buff[idat].Type;
04956          nimlROI->ROI_datum[idat].N_n = niml_ROI_datum_buff[idat].N_n;
04957          if (nimlROI->ROI_datum[idat].N_n > 0) {
04958             if (LocalHead) fprintf (SUMA_STDERR,"%s: Copying nPath, %d values\n", FuncName, nimlROI->ROI_datum[idat].N_n);
04959             nimlROI->ROI_datum[idat].nPath = (int *)SUMA_malloc(sizeof(int)*nimlROI->ROI_datum[idat].N_n);
04960             memcpy(nimlROI->ROI_datum[idat].nPath, niml_ROI_datum_buff[idat].nPath, sizeof(int)*nimlROI->ROI_datum[idat].N_n);
04961          } else {
04962             SUMA_LH("Null nPath");
04963             nimlROI->ROI_datum[idat].nPath = NULL;
04964          } 
04965          if (LocalHead) { 
04966             fprintf (SUMA_STDERR,"%s: Segment %d\tType %d\tN_n %d\taction %d\n", 
04967                FuncName, idat, nimlROI->ROI_datum[idat].Type,  
04968                nimlROI->ROI_datum[idat].N_n,nimlROI->ROI_datum[idat].action);
04969          }
04970       }
04971 
04972       /* Does ROI already exist with the same idcode_str ?*/
04973       
04974       SUMA_LH("Checking for duplicates...");
04975       if ((iDO = SUMA_whichDO(nel_idcode, SUMAg_DOv, SUMAg_N_DOv)) >= 0) {
04976          SUMA_LH("Duplicate found ... Deleteing old one...");
04977          /* ROI already exists delete it */
04978          if (!SUMA_DeleteROI ((SUMA_DRAWN_ROI *)SUMAg_DOv[iDO].OP)) {
04979             SUMA_SLP_Err("Failed to delete ROI");
04980             SUMA_RETURN(NULL); 
04981          }
04982       }
04983       
04984       /* transfom nimlROI to a series of drawing actions */
04985       SUMA_LH("Transforming ROI to a series of actions...");
04986       ROIv[inel] = SUMA_NIMLDrawnROI_to_DrawnROI (nimlROI, ForDisplay);
04987       if (LocalHead) fprintf (SUMA_STDERR, "%s: ROI->Parent_idcode_str %s\n", FuncName, ROIv[inel]->Parent_idcode_str);
04988 
04989       /* manually free nimlROI fields that received copies of allocated space as opposed to pointer copies */
04990       if (nimlROI->idcode_str) SUMA_free(nimlROI->idcode_str);
04991       if (nimlROI->Parent_idcode_str) SUMA_free(nimlROI->Parent_idcode_str); 
04992       if (nimlROI->Label) SUMA_free(nimlROI->Label);
04993       if (nimlROI->ColPlaneName) SUMA_free(nimlROI->ColPlaneName);
04994 
04995 
04996       /* free nimlROI */
04997       nimlROI = SUMA_Free_NIMLDrawROI(nimlROI);
04998 
04999       /* free nel and get it ready for the next load */
05000       NI_free_element(nel) ; nel = NULL; 
05001             
05002    }
05003    
05004    /* free nelv */
05005    SUMA_free(nelv);
05006    
05007    *N_ROI = N_nel;
05008    SUMA_RETURN(ROIv);
05009 } 

SUMA_Boolean SUMA_OpenDx_Object_Attr char *    op,
int    nchar,
SUMA_OPEN_DX_STRUCT   dx
 

return values of an attribute from an OpenDX object string

Definition at line 7684 of file SUMA_Surface_IO.c.

References SUMA_OPEN_DX_STRUCT::attr_name, SUMA_OPEN_DX_STRUCT::attr_string, i, LocalHead, SUMA_OPEN_DX_STRUCT::n_attr, SUMA_ADVANCE_PAST, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_GET_BETWEEN_BLANKS, SUMA_LH, SUMA_RETURN, and SUMA_SL_Err.

Referenced by SUMA_OpenDX_Read().

07685 {
07686    static char FuncName[]={"SUMA_OpenDx_Object_Attr"};
07687    int i, Found, ival,imax;
07688    char *op_end, cend, *op2, *sval;
07689    char *op_orig;
07690    SUMA_Boolean LocalHead = NOPE;
07691    
07692    SUMA_ENTRY;
07693    
07694    /* get the attributes */
07695    
07696    op_orig = op; /* hide this pointer from the evils that will befall it */
07697    cend = op_orig[nchar-1]; op_orig[nchar-1] = '\0';
07698    op_end = op_orig + nchar - 1; 
07699    
07700    SUMA_ADVANCE_PAST(op,op_end,"attribute",Found, 1);
07701    sval = NULL;
07702    while (Found) {
07703       /* get the attribute's name */
07704       SUMA_GET_BETWEEN_BLANKS(op, op_end, op2);
07705       if (op2 == op) {
07706          SUMA_LH("Empty attribute?");
07707       } else {
07708          imax = op2 - op;
07709          if (imax > 5000) {
07710             SUMA_SL_Err("Unexpectedly large field!");
07711             op_orig[nchar-1] =  cend;
07712             SUMA_RETURN(NOPE);
07713          }else if (imax < 0) {
07714             SUMA_SL_Err("Negative imax!");
07715             op_orig[nchar-1] =  cend;
07716             SUMA_RETURN(NOPE);
07717          }
07718          sval = (char *)SUMA_calloc(imax + 2, sizeof(char));
07719 
07720          for (i=0; i < imax; ++i) sval[i] = op[i];
07721          sval[imax] = '\0';
07722          dx->attr_name[dx->n_attr] = sval;
07723       }
07724       op = op2;
07725       /* look for attribute string */
07726       SUMA_ADVANCE_PAST(op,op_end,"string",Found,1);
07727       if (Found) {
07728          SUMA_GET_BETWEEN_BLANKS(op, op_end, op2);
07729          if (op2 == op) {
07730             SUMA_LH("Empty string?");
07731          } else {
07732             imax = op2 - op;
07733             if (imax > 5000) {
07734                SUMA_SL_Err("Unexpectedly large field!");
07735                op_orig[nchar-1] =  cend;
07736                SUMA_RETURN(NOPE);
07737             }else if (imax < 0) {
07738                SUMA_SL_Err("Negative imax!");
07739                op_orig[nchar-1] =  cend;
07740                SUMA_RETURN(NOPE);
07741             }
07742             sval = (char *)SUMA_calloc(imax + 2, sizeof(char));
07743 
07744             for (i=0; i < imax; ++i) sval[i] = op[i];
07745             sval[imax] = '\0';
07746             dx->attr_string[dx->n_attr] = sval;
07747          }   
07748       }
07749       ++dx->n_attr;
07750       /* look for next attribute */
07751       op = op2;
07752       SUMA_ADVANCE_PAST(op,op_end,"attribute",Found,1);
07753    }
07754       
07755    op_orig[nchar-1] =  cend;
07756    SUMA_RETURN(YUP);
07757 }

SUMA_Boolean SUMA_OpenDx_Object_Components char *    op,
int    nchar,
SUMA_OPEN_DX_STRUCT   dx
 

return values of an attribute from an OpenDX object string

Definition at line 7761 of file SUMA_Surface_IO.c.

References SUMA_OPEN_DX_STRUCT::comp_name, SUMA_OPEN_DX_STRUCT::comp_value, i, LocalHead, SUMA_OPEN_DX_STRUCT::n_comp, SUMA_ADVANCE_PAST, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_GET_BETWEEN_BLANKS, SUMA_LH, SUMA_RETURN, and SUMA_SL_Err.

Referenced by SUMA_OpenDX_Read().

07762 {
07763    static char FuncName[]={"SUMA_OpenDx_Object_Components"};
07764    int i, Found, ival,imax;
07765    char *op_end, cend, *op2, *sval;
07766    char *op_orig;
07767    SUMA_Boolean LocalHead = NOPE;
07768    
07769    SUMA_ENTRY;
07770    
07771    /* get the attributes */
07772    
07773    op_orig = op; /* hide this pointer from the evils that will befall it */
07774    cend = op_orig[nchar-1]; op_orig[nchar-1] = '\0';
07775    op_end = op_orig + nchar - 1; 
07776    
07777    SUMA_ADVANCE_PAST(op,op_end,"component",Found,1);
07778    while (Found) {
07779       /* get the attribute's name */
07780       SUMA_GET_BETWEEN_BLANKS(op, op_end, op2);
07781       if (op2 == op) {
07782          SUMA_LH("Empty component?");
07783       } else {
07784          imax = op2 - op;
07785          if (imax > 5000) {
07786             SUMA_SL_Err("Unexpectedly large field!");
07787             op_orig[nchar-1] =  cend;
07788             SUMA_RETURN(NOPE);
07789          }else if (imax < 0) {
07790             SUMA_SL_Err("Negative imax!");
07791             op_orig[nchar-1] =  cend;
07792             SUMA_RETURN(NOPE);
07793          }
07794          sval = (char *)SUMA_calloc(imax + 2, sizeof(char));
07795 
07796          for (i=0; i < imax; ++i) sval[i] = op[i];
07797          sval[imax] = '\0';
07798          dx->comp_name[dx->n_comp] = sval;
07799       }
07800       op = op2;
07801       /* look for attribute string */
07802       SUMA_ADVANCE_PAST(op,op_end,"value",Found,1);
07803       if (Found) {
07804          SUMA_GET_BETWEEN_BLANKS(op, op_end, op2);
07805          if (op2 == op) {
07806             SUMA_SL_Err("No value!");
07807          } else {
07808             imax = op2 - op;
07809             if (imax > 5000) {
07810                SUMA_SL_Err("Unexpectedly large field!");
07811                op_orig[nchar-1] =  cend;
07812                SUMA_RETURN(NOPE);
07813             }else if (imax < 0) {
07814                SUMA_SL_Err("Negative imax!");
07815                op_orig[nchar-1] =  cend;
07816                SUMA_RETURN(NOPE);
07817             }
07818             sval = (char *)SUMA_calloc(imax + 2, sizeof(char));
07819 
07820             for (i=0; i < imax; ++i) sval[i] = op[i];
07821             sval[imax] = '\0';
07822             dx->comp_value[dx->n_comp] = sval;
07823          }   
07824       }else { /* try for non-existing "value" */
07825          SUMA_GET_BETWEEN_BLANKS(op, op_end, op2);
07826          if (op2 == op) {
07827             SUMA_SL_Err("No value at all");
07828          } else {
07829             imax = op2 - op;
07830             if (imax > 5000) {
07831                SUMA_SL_Err("Unexpectedly large field!");
07832                op_orig[nchar-1] =  cend;
07833                SUMA_RETURN(NOPE);
07834             }else if (imax < 0) {
07835                SUMA_SL_Err("Negative imax!");
07836                op_orig[nchar-1] =  cend;
07837                SUMA_RETURN(NOPE);
07838             }
07839             sval = (char *)SUMA_calloc(imax + 2, sizeof(char));
07840 
07841             for (i=0; i < imax; ++i) sval[i] = op[i];
07842             sval[imax] = '\0';
07843             dx->comp_value[dx->n_comp] = sval;
07844          }   
07845       }
07846       ++dx->n_comp;
07847       /* look for next component */
07848       op = op2;
07849       SUMA_ADVANCE_PAST(op,op_end,"component",Found,1);
07850    }
07851       
07852    op_orig[nchar-1] =  cend;
07853    SUMA_RETURN(YUP);
07854 }

SUMA_Boolean SUMA_OpenDx_Object_Data char *    op,
int    nchar,
SUMA_OPEN_DX_STRUCT   dx
 

get the data values

Definition at line 7583 of file SUMA_Surface_IO.c.

References SUMA_OPEN_DX_STRUCT::data, SUMA_OPEN_DX_STRUCT::data_format, SUMA_OPEN_DX_STRUCT::data_off, SUMA_OPEN_DX_STRUCT::datap, i, SUMA_OPEN_DX_STRUCT::items, LocalHead, SUMA_ADVANCE_PAST, SUMA_Boolean, SUMA_copy_string(), SUMA_COPY_TO_STRING, SUMA_ENTRY, SUMA_free, SUMA_GET_BETWEEN_BLANKS, SUMA_LH, SUMA_NCOL_OPENDX, SUMA_RETURN, SUMA_strtol_vec(), and SUMA_OPEN_DX_STRUCT::type.

Referenced by SUMA_OpenDX_Read().

07584 {
07585    static char FuncName[]={"SUMA_OpenDx_Object_Data"};
07586    int i, Found = 0, ival;
07587    char *op_end, cend, *op2, *sval;
07588    char *op_orig;
07589    SUMA_Boolean LocalHead = NOPE;
07590    
07591    SUMA_ENTRY;
07592    
07593    /* get the data */
07594    op_orig = op; /* hide this pointer from the evils that will befall it */
07595    cend = op_orig[nchar-1]; op_orig[nchar-1] = '\0';
07596    op_end = op_orig + nchar - 1; 
07597    if (LocalHead) { /* potential for huge dump if you set show to nchar! */
07598          int j, show;
07599          show = 500; /* could also use nchar */
07600          fprintf(SUMA_STDERR,"%s Object\n", FuncName);
07601          j=0; while (op[j] && j<500) { fprintf(SUMA_STDERR,"%c", op[j]); ++j; }
07602          fprintf(SUMA_STDERR,"\n");
07603    }
07604    SUMA_ADVANCE_PAST(op,op_end,"data",Found,1);
07605    sval = NULL;
07606    if (Found) {
07607       /* get the data's info */
07608       SUMA_GET_BETWEEN_BLANKS(op, op_end, op2);
07609       if (op2 == op) {
07610          SUMA_LH("Empty data?");
07611          dx->data=NULL;
07612       } else {
07613          SUMA_COPY_TO_STRING(op, op2, sval);
07614          dx->data = sval; sval = NULL;
07615       }
07616       op = op2;
07617       /* now fill datap if possible*/
07618       if (dx->data && strstr(dx->data,"follows")){
07619          int nread=0;
07620          SUMA_LH("data inside");
07621          if (LocalHead) { /* potential for huge dump! */
07622             int j, show;
07623             show = 500; /* could also use nchar */
07624             fprintf(SUMA_STDERR,"%s Object\n", FuncName);
07625             j=0; while (op[j] && j<500) { fprintf(SUMA_STDERR,"%c", op[j]); ++j; }
07626             fprintf(SUMA_STDERR,"\n");
07627          }  
07628          dx->datap = SUMA_strtol_vec(op, dx->items*SUMA_NCOL_OPENDX(dx), &nread, SUMA_VarType2TypeCast (dx->type));
07629          if (LocalHead) {
07630             fprintf(SUMA_STDERR,"%s: Read %d/%d values\n", FuncName, nread, dx->items*SUMA_NCOL_OPENDX(dx));
07631          }
07632          if (nread != dx->items*SUMA_NCOL_OPENDX(dx)) {
07633             fprintf(SUMA_STDERR,"Error %s: read in %d values, expected %d \n", FuncName, nread, dx->items*SUMA_NCOL_OPENDX(dx));
07634             op_orig[nchar-1] =  cend;
07635             SUMA_RETURN(NOPE);
07636          }
07637       }else {
07638          SUMA_LH("data does not follow");
07639          if (LocalHead) {
07640             for (i=0; i < 500; ++i) { fprintf(SUMA_STDERR,"%c", op[i]); } fprintf(SUMA_STDERR,"\n"); fflush(SUMA_STDERR);
07641          }
07642          /* ? have file name ? */
07643          if (strstr(dx->data,"file")) {
07644             SUMA_GET_BETWEEN_BLANKS(op, op_end, op2);
07645             if (op2 > op) {
07646                SUMA_free(dx->data); /* free the "file" string */
07647                SUMA_COPY_TO_STRING(op, op2, sval);
07648                dx->data = sval; sval = NULL;
07649                /* search backwards for a comma */
07650                i=strlen(dx->data)-1; Found = -1;
07651                while(i>=0 && Found <0) { if (dx->data[i] == ',') Found = i; --i; }
07652                if (Found >= 0) { 
07653                   dx->data_off = SUMA_copy_string(&(dx->data[Found+1]));
07654                   dx->data[Found]='\0';
07655                }  
07656                /* see if you have some byte order or binary business */
07657                dx->data_format = 0; /* ascii, default*/
07658                op = op_orig; SUMA_ADVANCE_PAST(op,op_end,"binary",Found,1);
07659                if (Found) {
07660                   dx->data_format = MSB_FIRST; /* default */
07661                }
07662                /* endianness, regardless of what was above, "binary" might not occur */
07663                op = op_orig; SUMA_ADVANCE_PAST(op,op_end,"msb",Found,1);
07664                if (Found) { dx->data_format = MSB_FIRST; }
07665                else {
07666                   op = op_orig; SUMA_ADVANCE_PAST(op,op_end,"lsb",Found,1);
07667                   if (Found) { dx->data_format = LSB_FIRST; }
07668                }
07669             }
07670          }
07671       }
07672    } else {
07673       SUMA_LH("No data for this object");
07674    }
07675       
07676    op_orig[nchar-1] =  cend;
07677    SUMA_RETURN(YUP);
07678 }

void* SUMA_OpenDx_Object_Header_Field char *    op,
int    nchar,
const char *    attr,
char **    op_end
 

return values of a header field from an OpenDX object string If you expect an int back like when attr is "rank" or "shape" ans should be type cast to (int *) before use: int ival; ival = *((int *)ans); If you expect a bunch of numbers like for "counts" "origin" "delta" then ans is (SUMA_IVEC *) or (SUMA_FVEC*) or (SUMA_DVEC *) These are freed with SUMA_free(ans->v); SUMA_free(ans); else ans should be type cast to (char **) before use: char *sval; sval = *((char **)ans); then free sval with SUMA_free(sval);

Definition at line 7867 of file SUMA_Surface_IO.c.

References i, LocalHead, SUMA_ADVANCE_PAST, SUMA_AdvancePastNumbers(), SUMA_Boolean, SUMA_calloc, SUMA_copy_string(), SUMA_ENTRY, SUMA_float, SUMA_GET_BETWEEN_BLANKS, SUMA_int, SUMA_LH, SUMA_RETURN, and SUMA_SL_Err.

Referenced by SUMA_OpenDX_Read().

07868 {
07869    static char FuncName[]={"SUMA_OpenDx_Object_Header_Field"};
07870    void *ans=NULL;
07871    int i, Found, ival, imax, nread;
07872    char *op_end = NULL, cend, *op2, *sval, *pp1, *pp2;
07873    char *op_orig;
07874    SUMA_Boolean LocalHead = NOPE;
07875    
07876    SUMA_ENTRY;
07877    
07878    if (opeofield) *opeofield = op;
07879    
07880    if (!attr) SUMA_RETURN(ans);
07881    op_orig = op; /* hide this pointer from the evils that will befall it */
07882    cend = op_orig[nchar-1]; op_orig[nchar-1] = '\0';
07883    /* do we have a data section to signal end of header? */
07884    op_end = NULL;
07885    pp1 = strstr(op, "data"); 
07886    if (pp1) {
07887       pp2 = strstr(op, "follows");
07888       if (pp2) op_end = pp2;
07889    }
07890    if (!op_end) op_end = op_orig + nchar - 1; /* op_end all the way at end */
07891    
07892    if (LocalHead) {
07893       fprintf(SUMA_STDERR,"%s: Object of %d chars, looking for >>>%s<<<\n", FuncName, nchar, attr );
07894    }
07895    
07896   /* get the header field's value name */
07897    SUMA_ADVANCE_PAST(op,op_end,attr,Found,1);
07898    if (Found) {
07899       SUMA_GET_BETWEEN_BLANKS(op, op_end, op2);
07900       if (op2 == op) {
07901          SUMA_LH("No field");
07902       } else {
07903          /* get the numeric fields changed*/
07904          if (strstr(attr,"rank") || strstr(attr,"shape") || strstr(attr,"items")) { /* rank, shape (matrix's second dim) are integer vals */
07905             ival = (int)strtol(op, NULL , 10);
07906             ans = (void*)&ival;
07907          } else if (strstr(attr,"counts")) { /* are a series integer vals */
07908             ans = SUMA_AdvancePastNumbers(op, &op2, SUMA_int);
07909          } else if (strstr(attr,"origin") || strstr(attr,"delta")) { /* are integer vals */
07910             ans = SUMA_AdvancePastNumbers(op, &op2, SUMA_float);
07911          } else  { /* strings*/
07912             imax = op2 - op;
07913             if (imax > 5000) {
07914                SUMA_SL_Err("Unexpectedly large field!");
07915                op_orig[nchar-1] =  cend;
07916                SUMA_RETURN(ans);
07917             }else if (imax < 0) {
07918                SUMA_SL_Err("Negative imax!");
07919                op_orig[nchar-1] =  cend;
07920                SUMA_RETURN(ans);
07921             }
07922             sval = (char *)SUMA_calloc(imax + 2, sizeof(char));
07923             
07924             for (i=0; i < imax; ++i) sval[i] = op[i];
07925             sval[imax] = '\0';
07926             ans = (void*)&sval;
07927          }    
07928          if (LocalHead) {
07929             fprintf(SUMA_STDERR,"%s: attribute >>>%s<<< is:\n", FuncName, attr);
07930             i = 0;
07931             while (op[i] && op+i != op2) {
07932                fprintf(SUMA_STDERR,"%c", op[i]); 
07933                ++i;   
07934             }
07935             fprintf(SUMA_STDERR,"\n");
07936          }
07937          
07938       }
07939       op = op2; /* advance op */
07940    } else {
07941       if (strstr(attr,"class")) {
07942          /* it looks like "class" is sometimes omitted, look for string field, which is a class */
07943          SUMA_ADVANCE_PAST(op,op_end,"field", Found,1);
07944          if (Found) sval = SUMA_copy_string("field");
07945          ans = (void*)&sval;
07946       } else {
07947          SUMA_LH("No such attribute");
07948       }
07949    }
07950       
07951    op_orig[nchar-1] =  cend;
07952    if (opeofield) *opeofield = op; 
07953    SUMA_RETURN(ans);
07954 }

SUMA_OPEN_DX_STRUCT** SUMA_OpenDX_Read char *    fname,
int *    nobj
 

See also:
http://opendx.npaci.edu/docs/html/pages/usrgu068.htm#Header_417

Definition at line 7958 of file SUMA_Surface_IO.c.

References i, LocalHead, SUMA_FVEC::n, SUMA_IVEC::n, SUMA_Alloc_OpenDX_Struct(), SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_free, SUMA_LH, SUMA_MAX_OPEN_DX_OBJECTS, SUMA_OpenDx_Object_Attr(), SUMA_OpenDx_Object_Components(), SUMA_OpenDx_Object_Data(), SUMA_OpenDx_Object_Header_Field(), SUMA_RETURN, SUMA_Show_OpenDX_Struct(), SUMA_SL_Err, SUMA_SL_Warn, SUMA_suck_file(), SUMA_FVEC::v, and SUMA_IVEC::v.

Referenced by SUMA_LoadDXDset(), SUMA_OpenDX_Read_CruiseVolHead(), and SUMA_OpenDX_Read_SO().

07959 {
07960    static char FuncName[]={"SUMA_OpenDX_Read"};
07961    int nread = 0, i = 0,  iop, *ivalp=NULL, shft=0;
07962    char *fl=NULL, **opv = NULL, *op = NULL,*sbuf=NULL, **svalp=NULL, *ope;
07963    int *nchar = NULL;
07964    SUMA_OPEN_DX_STRUCT **dxv=NULL;
07965    SUMA_FVEC *fvec=NULL;
07966    SUMA_IVEC *ivec=NULL;
07967    SUMA_Boolean LocalHead = NOPE;
07968    
07969    SUMA_ENTRY;
07970    
07971    *nobj = 0;
07972    
07973    SUMA_LH("Sucking file");
07974    nread = SUMA_suck_file( fname , &fl ) ;
07975    if (!fl) {
07976       SUMA_SL_Err("Failed to read file.");
07977       SUMA_RETURN(dxv);
07978    }
07979 
07980    if (LocalHead) fprintf(SUMA_STDERR,"%s: Read in %d chars\n", FuncName, nread);
07981    
07982    opv = (char **)SUMA_calloc(SUMA_MAX_OPEN_DX_OBJECTS, sizeof(char*));
07983    nchar = (int*)SUMA_calloc(SUMA_MAX_OPEN_DX_OBJECTS, sizeof(int));
07984    dxv = (SUMA_OPEN_DX_STRUCT **)SUMA_calloc(SUMA_MAX_OPEN_DX_OBJECTS, sizeof(SUMA_OPEN_DX_STRUCT *));
07985    
07986    /* now search for the first "object" */
07987    op = fl;
07988    iop = 0;
07989    shft = 0;
07990    do {
07991       op = strstr((op+shft), "object");
07992       if (op) {
07993          opv[iop] = op;
07994          if (iop) nchar[iop-1] = opv[iop] - opv[iop-1];
07995          if (LocalHead) {
07996             fprintf(SUMA_STDERR,"%s: Object found.\n", FuncName);
07997             i = 0;
07998             while (i<20 && op[i] !='\0') { fprintf(SUMA_STDERR,"%c",op[i]); ++i; } fprintf(SUMA_STDERR,"\n"); 
07999          }
08000          
08001          /* must skip beyond first "object" for next pass*/
08002          shft = strlen("object");
08003          ++iop;
08004       }
08005    } while (op && iop < SUMA_MAX_OPEN_DX_OBJECTS);
08006    if (iop >= SUMA_MAX_OPEN_DX_OBJECTS) {
08007       SUMA_SL_Warn("Too many objects, processing first SUMA_MAX_OPEN_DX_OBJECTS only"); 
08008    }
08009    
08010    if (iop) {/* find the length of the last object */
08011       op = opv[iop-1];
08012       while (*op !='\0') { ++op; }
08013       nchar[iop-1] = op - opv[iop-1];
08014    }
08015    
08016    if (LocalHead) {
08017       fprintf(SUMA_STDERR,"%s: %d Objects found.\n", FuncName, iop);
08018    }
08019    
08020    for (i=0; i<iop; ++i) { /* process each object's header field and data*/
08021       if ( 0 && LocalHead) { /* potentially huge dump if nmax is not controlled*/
08022          int j, nmax;
08023          nmax = 500; /* could also use nchar[i]*/
08024          fprintf(SUMA_STDERR,"%s Object %d\n", FuncName, i);
08025          op = opv[i]; for (j=0; j<nmax; ++j) fprintf(SUMA_STDERR,"%c", op[j]);
08026          fprintf(SUMA_STDERR,"\n");
08027       }
08028       /* get the class */
08029       dxv[i] = SUMA_Alloc_OpenDX_Struct();
08030       ivalp = (int *)SUMA_OpenDx_Object_Header_Field(opv[i], nchar[i], "rank", NULL);
08031       if (ivalp) dxv[i]->rank = *ivalp;
08032       ivalp = (int *)SUMA_OpenDx_Object_Header_Field(opv[i], nchar[i], "shape", NULL);
08033       if (ivalp) dxv[i]->shape = *ivalp;
08034       ivalp = (int *)SUMA_OpenDx_Object_Header_Field(opv[i], nchar[i], "items", NULL);
08035       if (ivalp) dxv[i]->items = *ivalp;
08036       svalp = (char **)SUMA_OpenDx_Object_Header_Field(opv[i], nchar[i], "object", NULL);
08037       if (svalp) dxv[i]->object = *svalp;
08038       svalp = (char **)SUMA_OpenDx_Object_Header_Field(opv[i], nchar[i], "class", NULL);
08039       if (svalp) dxv[i]->class = *svalp;
08040       svalp = (char **)SUMA_OpenDx_Object_Header_Field(opv[i], nchar[i], "type", NULL);
08041       if (svalp) dxv[i]->type = *svalp;
08042       ivec = (SUMA_IVEC*)SUMA_OpenDx_Object_Header_Field(opv[i], nchar[i], "counts", NULL);
08043       if (ivec) { dxv[i]->counts = ivec->v; dxv[i]->n_counts = ivec->n; SUMA_free(ivec); ivec = NULL;} 
08044       fvec = (SUMA_FVEC*)SUMA_OpenDx_Object_Header_Field(opv[i], nchar[i], "origin", NULL);
08045       if (fvec) { dxv[i]->origin = fvec->v; dxv[i]->n_origin = fvec->n; SUMA_free(fvec); fvec = NULL;} 
08046       { /* get the deltas */
08047          int j, k;
08048          char *rf=opv[i];
08049          j=0; 
08050          while (j<dxv[i]->n_counts) {
08051             fvec = (SUMA_FVEC*)SUMA_OpenDx_Object_Header_Field(rf, nchar[i], "delta", &ope);
08052             if (fvec && fvec->v) { 
08053                if (fvec->n < dxv[i]->n_counts) { SUMA_SL_Warn("Bad assumption about delta field.\nExpect disasters!"); }
08054                if (fvec->n > dxv[i]->n_counts) { 
08055                   SUMA_SL_Err("More values in delta that counts! Limiting to counts.\nExpect tragedy."); 
08056                   fvec->n = dxv[i]->n_counts;
08057                }
08058                if (j==0) { /* allocate */ 
08059                   dxv[i]->n_delta = dxv[i]->n_counts*dxv[i]->n_counts; 
08060                   dxv[i]->delta = (float *)SUMA_calloc(dxv[i]->n_delta, sizeof(float));
08061                }
08062                for (k=0; k<fvec->n; ++k) { 
08063                   dxv[i]->delta[(j*dxv[i]->n_counts) + k] = fvec->v[k];  
08064                }
08065                SUMA_free(fvec->v); SUMA_free(fvec); fvec = NULL;
08066             } else { /* get out */
08067                if (j) {
08068                   SUMA_SL_Warn("Expect as many deltas as counts!\nThat was not the case.");
08069                } else { /* OK, no deltas at all */ }
08070                j = dxv[i]->n_counts;
08071             }
08072             ++j; rf = ope;
08073          }
08074       } 
08075       /* now for the data */
08076       if (!SUMA_OpenDx_Object_Data(opv[i], nchar[i], dxv[i])) {
08077          SUMA_SL_Err("Failed to get data");
08078          dxv[i]->bad_data = 1;
08079       }
08080    }
08081 
08082    for (i=0; i<iop; ++i) { /* process each object's attributes*/
08083       if (!SUMA_OpenDx_Object_Attr(opv[i], nchar[i], dxv[i])) {
08084          SUMA_SL_Err("Failed in SUMA_OpenDx_Object_Attr");
08085       }
08086       if (!SUMA_OpenDx_Object_Components(opv[i], nchar[i], dxv[i])) {
08087          SUMA_SL_Err("Failed in SUMA_OpenDx_Object_Components");
08088       }
08089    }
08090 
08091    if (LocalHead) {
08092          SUMA_Show_OpenDX_Struct(dxv, iop, NULL); fflush(stdout);
08093    }
08094    
08095    if (opv) SUMA_free(opv); opv = NULL;
08096    if (nchar) SUMA_free(nchar); nchar = NULL;
08097    if (fl) SUMA_free(fl); fl = NULL; /* added Mon May 9 05, ZSS */
08098    *nobj = iop;
08099    SUMA_RETURN(dxv); 
08100 }

char* SUMA_OpenDX_Read_CruiseVolHead char *    fname,
THD_3dim_dataset   dset,
int    loaddata
 

Definition at line 8152 of file SUMA_Surface_IO.c.

References ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_nxyz, ADN_prefix, ADN_type, ADN_view_type, ADN_xyzdel, ADN_xyzorg, ADN_xyzorient, ANAT_BUCK_TYPE, SUMA_OPEN_DX_STRUCT::comp_name, SUMA_OPEN_DX_STRUCT::comp_value, SUMA_OPEN_DX_STRUCT::counts, SUMA_OPEN_DX_STRUCT::data, SUMA_OPEN_DX_STRUCT::data_format, SUMA_OPEN_DX_STRUCT::data_off, DATABLOCK_MEM_MALLOC, SUMA_OPEN_DX_STRUCT::delta, EDIT_dset_items(), EDIT_substitute_brick(), ep, fb, HEAD_ANAT_TYPE, i, THD_ivec3::ijk, LOAD_FVEC3, LOAD_IVEC3, LOAD_MAT, LocalHead, SUMA_OPEN_DX_STRUCT::n_comp, SUMA_OPEN_DX_STRUCT::n_counts, SUMA_OPEN_DX_STRUCT::n_delta, SUMA_OPEN_DX_STRUCT::origin, SUMA_ABS, SUMA_AfniPrefix(), SUMA_append_string(), SUMA_BinarySuck(), SUMA_Boolean, SUMA_byte, SUMA_calloc, SUMA_double, SUMA_ENTRY, SUMA_filexists(), SUMA_Find_OpenDX_Object_Class(), SUMA_Find_OpenDX_Object_Name(), SUMA_float, SUMA_free, SUMA_Free_OpenDX_StructVec(), SUMA_int, SUMA_LH, SUMA_NORM_VEC, SUMA_notypeset, SUMA_OpenDX_Read(), SUMA_orcode_to_orstring(), SUMA_originto3d_2_originHEAD(), SUMA_RETURN, SUMA_short, SUMA_sizeto3d_2_deltaHEAD(), SUMA_SL_Err, SUMA_VarType2TypeCast(), SUMA_WHAT_ENDIAN, THD_filename_ok(), THD_matrix_to_orientation(), SUMA_OPEN_DX_STRUCT::type, vec, VIEW_ORIGINAL_TYPE, and THD_fvec3::xyz.

Referenced by main().

08153 {
08154    static char FuncName[]={"SUMA_OpenDX_Read_CruiseVolHead"};
08155    int i = 0, nf, iop, chunk, End, bs, doff, data_type=SUMA_notypeset;
08156    THD_ivec3 iv3;
08157    THD_mat33 m33;
08158    THD_ivec3 orixyz , nxyz ;
08159    THD_fvec3 dxyz , orgxyz ;
08160    float ep[3], sp[3];
08161    char *scom=NULL, form[10], swp[10], orstr[10], xfov[100], yfov[100], zfov[100], *prefix = NULL, *dsetheadname = NULL;
08162    SUMA_OPEN_DX_STRUCT **dxv=NULL, *dxp=NULL, *dxc=NULL, *dxf=NULL, *dxa=NULL;
08163    SUMA_Boolean LocalHead = NOPE;
08164    
08165    SUMA_ENTRY;
08166    
08167    if (!dset || !fname) {
08168       SUMA_SL_Err("NULL fname || NULL dset!");
08169       SUMA_RETURN(NOPE);
08170    }
08171    
08172    prefix = SUMA_AfniPrefix(fname, NULL, NULL, NULL);
08173    if( !THD_filename_ok(prefix) ) {
08174       SUMA_SL_Err("Bad prefix");
08175       SUMA_RETURN(NOPE);
08176    } 
08177    dsetheadname = SUMA_append_string(prefix,"+orig.HEAD");
08178    if (SUMA_filexists(dsetheadname)) {
08179       SUMA_SL_Err("Bad prefix, output dset exists");
08180       SUMA_RETURN(NOPE);
08181    }
08182    SUMA_free(dsetheadname); dsetheadname = NULL;
08183    
08184    SUMA_LH("Reading objects");
08185    dxv = SUMA_OpenDX_Read(fname, &iop);
08186    if (!dxv) {
08187       SUMA_SL_Err("Failed to read DX file.");
08188       SUMA_RETURN(NOPE);
08189    }
08190    
08191    SUMA_LH("Checking for field object");
08192    dxf = SUMA_Find_OpenDX_Object_Class(dxv, iop, "field", &nf);
08193    if (!dxf || nf != 1) { SUMA_SL_Err("Failed to find one and only one field object"); goto CLEAN_EXIT; }
08194    dxp = dxc = NULL;   
08195    for (i=0; i<dxf->n_comp; ++i) {
08196       if (strstr(dxf->comp_name[i],"positions")) {
08197          dxp = SUMA_Find_OpenDX_Object_Name(dxv, iop, dxf->comp_value[i], &nf); 
08198          if (!dxp || nf != 1) { SUMA_SL_Err("Failed to find one and only one positions object"); goto CLEAN_EXIT; }
08199       }
08200       if (strstr(dxf->comp_name[i],"connections")) {
08201          dxc = SUMA_Find_OpenDX_Object_Name(dxv, iop, dxf->comp_value[i], &nf); 
08202          if (!dxc || nf != 1) { SUMA_SL_Err("Failed to find one and only one connections object"); goto CLEAN_EXIT; }
08203       }
08204       if (strstr(dxf->comp_name[i],"data")) {
08205          dxa = SUMA_Find_OpenDX_Object_Name(dxv, iop, dxf->comp_value[i], &nf); 
08206          if (!dxa || nf != 1) { SUMA_SL_Err("Failed to find one and only one data object"); goto CLEAN_EXIT; }
08207       }
08208    }
08209    
08210    if (!dxp || !dxv || !dxa) {
08211       SUMA_SL_Err("Failed to find necessary objects"); SUMA_RETURN(NOPE);
08212    }
08213    
08214    /* sanity */
08215    SUMA_LH("Sanity checks");
08216    if (!dxa->data_format) {
08217       SUMA_SL_Err("Not a binary data file!");
08218       goto CLEAN_EXIT; 
08219    }
08220    if (!dxa->data) {
08221       SUMA_SL_Err("No data file!");
08222       goto CLEAN_EXIT; 
08223    }
08224    if (dxp->n_counts != 3) {
08225       SUMA_SL_Err("counts field must have 3 values");
08226       goto CLEAN_EXIT; 
08227    }
08228    if (dxp->n_delta != 9) {
08229       SUMA_SL_Err("delta must contain 9 elements!");
08230       goto CLEAN_EXIT; 
08231    }
08232    
08233    /* form the command */
08234    SUMA_LH("Forming command");
08235    /* 3d what? */
08236    chunk = 0;
08237    form[0] = '\0';
08238    data_type = SUMA_VarType2TypeCast(dxa->type);
08239    switch (data_type) {
08240       case SUMA_float:
08241          sprintf(form,"3Df");
08242          chunk = sizeof(float);
08243          break;
08244       case SUMA_double:
08245          sprintf(form,"3Dd");
08246          chunk = sizeof(double);
08247          break;
08248       case SUMA_int:
08249          sprintf(form,"3Di");
08250          chunk = sizeof(int);
08251          break;
08252       case SUMA_short:
08253          sprintf(form,"3Ds");
08254          chunk = sizeof(short);
08255          break;
08256       case SUMA_byte:
08257          sprintf(form,"3Db");
08258          chunk = sizeof(byte);
08259          break;
08260       default:
08261          SUMA_SL_Err("No support for this type");
08262          goto CLEAN_EXIT; 
08263          break;
08264    }
08265    /* byte ordering */
08266    SUMA_WHAT_ENDIAN(End);
08267    bs = 0;
08268    swp[0] = '\0';
08269    if (End != dxa->data_format) {
08270       SUMA_LH("swapping needed");
08271       bs = 1;
08272       switch (chunk) {
08273          case 1:
08274             break;
08275          case 2:
08276             sprintf(swp,"-2swap");
08277             break;
08278          case 4:
08279             sprintf(swp,"-4swap");
08280             break;
08281          case 8:
08282             sprintf(swp,"-8swap");
08283             break;
08284          default:
08285             SUMA_SL_Err("Patchunk!");
08286             break;
08287       }
08288    }
08289    if (dxa->data_off)  doff = (int)strtol(dxa->data_off,NULL, 10);
08290    else doff = 0;
08291    
08292    /* direction that varies the fastest (x) is in the last delta
08293       count is ordered like delta. I do not know about origin yet,
08294       I assume that origin follows the ordering of count
08295       see http://opendx.npaci.edu/docs/html/pages/usrgu068.htm 
08296       for reference, someday....*/
08297    
08298    /* number of voxels */
08299    LOAD_IVEC3( nxyz   , dxp->counts[2]    , dxp->counts[1]    , dxp->counts[0] ) ;
08300    
08301    /* orientation */
08302    /* find closest orientation in RAI, delta matrix does allow for obliqueness (non diagonal matrix) but we ignore it */
08303    LOAD_MAT(m33, 
08304                dxp->delta[6], dxp->delta[7], dxp->delta[8], 
08305                dxp->delta[3], dxp->delta[4], dxp->delta[5],
08306                dxp->delta[0], dxp->delta[1], dxp->delta[2] );
08307    orixyz = THD_matrix_to_orientation( m33 );
08308 
08309    /* dimensions */
08310    {  
08311       float fb[3]; 
08312       SUMA_NORM_VEC((&(dxp->delta[6])),3, fb[0]);
08313       SUMA_NORM_VEC((&(dxp->delta[3])),3, fb[1]);
08314       SUMA_NORM_VEC((&(dxp->delta[0])),3, fb[2]);
08315       LOAD_FVEC3( dxyz   , fb[0]    , fb[1]    , fb[2]    ) ;
08316       SUMA_sizeto3d_2_deltaHEAD(orixyz, &dxyz);
08317    }
08318    
08319    /* origin , assumed to be center of first voxel*/
08320    LOAD_FVEC3( orgxyz , dxp->origin[2]    , dxp->origin[1] , dxp->origin[0]  ) ;
08321    SUMA_originto3d_2_originHEAD(orixyz, &orgxyz);
08322     
08323    /* start point (edge of origin voxel) and end point (opposite to start ) */
08324    sp[0] = dxp->origin[2] + SUMA_ABS(dxyz.xyz[0]) / 2.0;
08325    sp[1] = dxp->origin[1] + SUMA_ABS(dxyz.xyz[1]) / 2.0;
08326    sp[2] = dxp->origin[0] + SUMA_ABS(dxyz.xyz[2]) / 2.0;
08327    ep[0] = dxp->origin[2] + (nxyz.ijk[0] - 0.5) * SUMA_ABS(dxyz.xyz[0]);
08328    ep[1] = dxp->origin[1] + (nxyz.ijk[1] - 0.5) * SUMA_ABS(dxyz.xyz[1]);
08329    ep[2] = dxp->origin[0] + (nxyz.ijk[2] - 0.5) * SUMA_ABS(dxyz.xyz[2]);
08330    SUMA_orcode_to_orstring (orixyz.ijk[0], orixyz.ijk[1], orixyz.ijk[2], orstr);
08331    sprintf(xfov," -xFOV %.2f%c-%.2f%c", sp[0], orstr[0], ep[0], orstr[3]);
08332    sprintf(yfov," -yFOV %.2f%c-%.2f%c", sp[1], orstr[1], ep[1], orstr[4]);
08333    sprintf(zfov," -zFOV %.2f%c-%.2f%c", sp[2], orstr[2], ep[2], orstr[5]);
08334   
08335    
08336    scom = (char *)SUMA_calloc((strlen(dxa->data)+500), sizeof(char));
08337    sprintf(scom,"to3d %s %s %s %s -prefix %s %s:%d:0:%d:%d:%d:%s ", swp, xfov, yfov, zfov, prefix, form, doff, dxp->counts[2], dxp->counts[1], dxp->counts[0], dxa->data);
08338    
08339    
08340    if (dset) { /* form the dset header */
08341          int nvals_read = 0;
08342          EDIT_dset_items( dset ,
08343                             ADN_prefix      , prefix ,
08344                             ADN_datum_all   , data_type ,
08345                             ADN_nxyz        , nxyz ,
08346                             ADN_xyzdel      , dxyz ,
08347                             ADN_xyzorg      , orgxyz ,
08348                             ADN_xyzorient   , orixyz ,
08349                             ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
08350                             ADN_view_type   , VIEW_ORIGINAL_TYPE ,
08351                             ADN_type        , HEAD_ANAT_TYPE ,
08352                             ADN_func_type   , ANAT_BUCK_TYPE ,
08353                           ADN_none ) ;
08354 
08355          if (LoadData) {
08356             void *vec=NULL;
08357             if (!(vec = SUMA_BinarySuck(dxa->data, data_type, dxa->data_format, doff, -1, &nvals_read))) {
08358                SUMA_SL_Err("Failed to read data file"); goto CLEAN_EXIT;
08359             }
08360             EDIT_substitute_brick( dset , 0 , data_type , vec) ;      
08361             if (LocalHead) fprintf(SUMA_STDERR,"%s: Read %d values from file.\n", FuncName, nvals_read);
08362             /* DSET_write(dset) ; */
08363          }
08364    }
08365    
08366 
08367    
08368    CLEAN_EXIT:
08369    dxv = SUMA_Free_OpenDX_StructVec(dxv, iop);
08370    if (prefix) SUMA_free(prefix); prefix = NULL;
08371    
08372    SUMA_RETURN(scom);
08373 }

SUMA_Boolean SUMA_OpenDX_Read_SO char *    fname,
SUMA_SurfaceObject   SO
 

reads an OpenDX surface. Sample surfaces provided by Aaron Carass

The following fields are set in SO: SO->NodeDim SO->FaceSetDim SO->NodeList SO->FaceSetList SO->N_Node; SO->N_FaceSet; SO->Name; SO->FileType; SO->FileFormat

Definition at line 8390 of file SUMA_Surface_IO.c.

References SUMA_OPEN_DX_STRUCT::bad_data, SUMA_OPEN_DX_STRUCT::comp_name, SUMA_OPEN_DX_STRUCT::comp_value, SUMA_OPEN_DX_STRUCT::datap, SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::FileFormat, SUMA_SurfaceObject::FileType, i, SUMA_OPEN_DX_STRUCT::items, LocalHead, SUMA_OPEN_DX_STRUCT::n_comp, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SurfaceObject::Name, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, SUMA_OPEN_DX_STRUCT::rank, SUMA_OPEN_DX_STRUCT::shape, SUMA_ASCII, SUMA_Boolean, SUMA_ENTRY, SUMA_Find_OpenDX_Object_Class(), SUMA_Find_OpenDX_Object_Name(), SUMA_float, SUMA_free, SUMA_Free_OpenDX_Struct(), SUMA_int, SUMA_LH, SUMA_OPENDX_MESH, SUMA_OpenDX_Read(), SUMA_RETURN, SUMA_SL_Err, SUMA_StripPath(), SUMA_VarType2TypeCast(), and SUMA_OPEN_DX_STRUCT::type.

Referenced by SUMA_Load_Surface_Object_eng().

08391 {
08392    static char FuncName[]={"SUMA_OpenDX_Read_SO"};
08393    int i = 0, nf, iop;
08394    SUMA_OPEN_DX_STRUCT **dxv=NULL, *dxp=NULL, *dxc = NULL, *dxf = NULL, *dxo = NULL;
08395    SUMA_Boolean ans = NOPE;
08396    SUMA_Boolean LocalHead = NOPE;
08397    
08398    SUMA_ENTRY;
08399    
08400    if (!SO || !fname) {
08401       SUMA_SL_Err("NULL fname || NULL SO!");
08402       SUMA_RETURN(NOPE);
08403    }
08404    
08405    SUMA_LH("Reading objects");
08406    dxv = SUMA_OpenDX_Read(fname, &iop);
08407    if (!dxv) {
08408       SUMA_SL_Err("Failed to read DX file.");
08409       SUMA_RETURN(NOPE);
08410    }
08411    
08412    
08413    SUMA_LH("Checking for field object");
08414    dxf = SUMA_Find_OpenDX_Object_Class(dxv, iop, "field", &nf);
08415    if (!dxf || nf != 1) { SUMA_SL_Err("Failed to find one and only one field object"); goto CLEAN_EXIT; }
08416    /* get names of objects that contain positions and connections */
08417    dxp = dxc = dxo = NULL;   
08418    for (i=0; i<dxf->n_comp; ++i) {
08419       if (strstr(dxf->comp_name[i],"positions")) {
08420          dxp = SUMA_Find_OpenDX_Object_Name(dxv, iop, dxf->comp_value[i], &nf); 
08421          if (!dxp || nf != 1) { SUMA_SL_Err("Failed to find one and only one positions object"); goto CLEAN_EXIT; }
08422       }
08423       if (strstr(dxf->comp_name[i],"connections")) {
08424          dxc = SUMA_Find_OpenDX_Object_Name(dxv, iop, dxf->comp_value[i], &nf); 
08425          if (!dxc || nf != 1) { SUMA_SL_Err("Failed to find one and only one connections object"); goto CLEAN_EXIT; }
08426       }
08427       if (strstr(dxf->comp_name[i],"origin")) {
08428          dxo = SUMA_Find_OpenDX_Object_Name(dxv, iop, dxf->comp_value[i], &nf); 
08429          if (!dxo || nf != 1) { SUMA_SL_Err("Failed to find one and only one origin object.\nOrigin ignored"); }
08430       }
08431    }
08432    
08433    if (!dxp || !dxv) {
08434       SUMA_SL_Err("Failed to find necessary objects"); goto CLEAN_EXIT;
08435    }
08436    
08437    SUMA_LH("checking...");
08438    if (SUMA_VarType2TypeCast (dxp->type) != SUMA_float) {
08439       SUMA_SL_Err("Expected floats for positions"); goto CLEAN_EXIT;
08440    }
08441    if (dxp->bad_data) {
08442       SUMA_SL_Err("Problem reading data for positions"); goto CLEAN_EXIT;
08443    }
08444    if (dxp->rank != 1) {
08445       SUMA_SL_Err("Expected rank of 1 for positions"); goto CLEAN_EXIT;
08446    }
08447    if (dxp->shape != 3) {
08448       SUMA_SL_Err("Expected rank of 3 for positions"); goto CLEAN_EXIT;
08449    }
08450    if (SUMA_VarType2TypeCast (dxc->type) != SUMA_int) {
08451       SUMA_SL_Err("Expected ints for connections"); goto CLEAN_EXIT;
08452    }
08453    if (dxc->bad_data) {
08454       SUMA_SL_Err("Problem reading data for connections"); goto CLEAN_EXIT;
08455    }   
08456    if (dxc->rank != 1) {
08457       SUMA_SL_Err("Expected rank of 1 for connections"); goto CLEAN_EXIT;
08458    }
08459    if (dxc->shape != 3) {
08460       SUMA_SL_Err("Expected rank of 3 for connections"); goto CLEAN_EXIT;
08461    }
08462    /* if dxo */
08463    if (dxo) {
08464       if (SUMA_VarType2TypeCast (dxo->type) != SUMA_float) {
08465          SUMA_SL_Err("Expected floats for origin.\nOrigin ignored"); dxo = NULL;
08466       }
08467       if (!dxo->datap || dxo->shape * dxo->items != 3) {
08468          SUMA_SL_Err("Unknown origin format, ignoring origin"); dxo = NULL;
08469       }  
08470    }
08471    
08472    SUMA_LH("Take the gold");
08473    SO->FileType = SUMA_OPENDX_MESH;
08474    SO->FileFormat = SUMA_ASCII;
08475    
08476    SO->NodeDim = dxp->shape;
08477    SO->NodeList = (float *)dxp->datap; dxp->datap = NULL; /* datap will not be freed at end anymore */
08478    SO->N_Node = dxp->items;
08479    
08480    SO->FaceSetDim = dxc->shape;
08481    SO->FaceSetList = (int *)dxc->datap; dxc->datap = NULL; /* datap will not be freed at end anymore */
08482    SO->N_FaceSet = dxc->items;;
08483    SO->Name = SUMA_StripPath(fname);
08484    
08485    if (dxo) {
08486       float *fvec=(float*)dxo->datap;
08487       SUMA_LH("Adding origin");
08488       i = 0;
08489       while (i < dxp->items*dxp->shape) {
08490          SO->NodeList[i] += fvec[0]; ++i;
08491          SO->NodeList[i] += fvec[1]; ++i;
08492          SO->NodeList[i] += fvec[2]; ++i;
08493       }
08494    }
08495    
08496    /* all is well here */
08497    ans = YUP;
08498 
08499    CLEAN_EXIT:
08500    SUMA_LH("Frenching dxv");
08501    for (i=0; i<iop; ++i) {
08502       dxv[i] = SUMA_Free_OpenDX_Struct(dxv[i]);
08503    }
08504    if (dxv) SUMA_free(dxv); dxv = NULL;
08505    SUMA_RETURN(YUP);
08506 }

SUMA_Boolean SUMA_OpenDX_Write char *    fname,
SUMA_SurfaceObject   SO
 

Definition at line 7568 of file SUMA_Surface_IO.c.

References SUMA_Boolean, SUMA_ENTRY, SUMA_RETURN, and SUMA_SL_Err.

Referenced by SUMA_Save_Surface_Object().

07569 {
07570    static char FuncName[]={"SUMA_OpenDX_Write"};
07571    
07572    SUMA_ENTRY;
07573    
07574    SUMA_SL_Err("Not supported yet");
07575    
07576    SUMA_RETURN(NOPE);
07577 }

SUMA_Boolean SUMA_Ply_Read char *    f_name,
SUMA_SurfaceObject   SO
 

Reads a Ply formatted file into a SUMA_SurfaceObject structure ans = SUMA_Ply_Read (f_name, SO);.

Parameters:
f_name  (char *) name (and path) of .ply file to read. Extension .ply is optional
SO  (SUMA_SurfaceObject *) pointer to a structure to return surface in f_name in
Returns:
ans (SUMA_Boolean) YUP/NOPE
The following fields are set in SO: SO->NodeDim SO->FaceSetDim SO->NodeList SO->FaceSetList SO->N_Node; SO->N_FaceSet; SO->Name; SO->FileType; SO->FileFormat

See also:
SUMA_Ply_Write()
This function is a wrap around code by Greg Turk.

Definition at line 2795 of file SUMA_Surface_IO.c.

References equal_strings(), SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::FileFormat, SUMA_SurfaceObject::FileType, i, LocalHead, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, name, SUMA_SurfaceObject::Name, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, Face::nverts, PLY_ASCII, PLY_BINARY_BE, PLY_BINARY_LE, ply_close(), ply_get_comments(), ply_get_element(), ply_get_element_description(), ply_get_obj_info(), ply_get_property(), ply_open_for_reading(), SUMA_ASCII, SUMA_BINARY_BE, SUMA_BINARY_LE, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_free, SUMA_malloc, SUMA_PLY, SUMA_RETURN, SUMA_StripPath(), Face::verts, verts, Vertex::x, Vertex::y, and Vertex::z.

Referenced by SUMA_Load_Surface_Object_eng().

02796 {
02797    static char FuncName[]={"SUMA_Ply_Read"};
02798    int i,j,k, j3, ji;
02799    PlyFile *ply = NULL;
02800    int nelems;
02801    char **elist = NULL;
02802    int file_type;
02803    float version;
02804    int nprops;
02805    int num_elems;
02806    PlyProperty **plist = NULL;
02807    Vertex **vlist = NULL;
02808    Face **flist = NULL;
02809    char *elem_name;
02810    int num_comments;
02811    char **comments = NULL;
02812    int num_obj_info;
02813    char **obj_info = NULL;
02814    SUMA_Boolean LocalHead = NOPE;
02815    
02816    SUMA_ENTRY;
02817 
02818    /* open a PLY file for reading */
02819    ply = ply_open_for_reading(f_name, &nelems, &elist, &file_type, &version);
02820    if (!ply) {
02821       fprintf (SUMA_STDERR, "Error %s: Failed to find/read %s.\n", FuncName, f_name);
02822       SUMA_RETURN (NOPE);
02823    }
02824    
02825    /* print what we found out about the file */
02826    if (LocalHead) fprintf (SUMA_STDERR, "%s: version %f\n", FuncName, version);
02827    if (LocalHead) fprintf (SUMA_STDERR, "%s: type %d\n", FuncName, file_type);
02828 
02829    /* go through each kind of element that we learned is in the file */
02830    /* and read them */
02831 
02832    for (i = 0; i < nelems; i++) {
02833 
02834     /* get the description of the first element */
02835     elem_name = elist[i];
02836     plist = ply_get_element_description (ply, elem_name, &num_elems, &nprops);
02837 
02838     /* print the name of the element, for debugging */
02839     if (LocalHead) fprintf (SUMA_STDERR, "%s: element %s %d\n", FuncName, elem_name, num_elems);
02840 
02841     /* if we're on vertex elements, read them in */
02842     if (equal_strings ("vertex", elem_name)) {
02843 
02844       /* create a vertex list to hold all the vertices */
02845       #ifdef USE_PLY_VERTEX
02846       vlist = (Vertex **) SUMA_malloc (sizeof (Vertex *) * num_elems);
02847       #endif
02848       
02849       SO->NodeList = (float *) SUMA_calloc (3*num_elems, sizeof(float));
02850       if (!SO->NodeList) {
02851          fprintf (SUMA_STDERR, "Error %s: Failed to allocate for SO->NodeList.\n", FuncName);
02852          SUMA_RETURN(NOPE);
02853       }
02854       
02855       /* set up for getting vertex elements */
02856 
02857       ply_get_property (ply, elem_name, &vert_props[0]);
02858       ply_get_property (ply, elem_name, &vert_props[1]);
02859       ply_get_property (ply, elem_name, &vert_props[2]);
02860       
02861       SO->NodeDim = 3;
02862       SO->N_Node = num_elems;
02863       /* grab all the vertex elements */
02864       for (j = 0; j < num_elems; j++) {
02865 
02866         /* grab and element from the file */
02867         #ifdef USE_PLY_VERTEX
02868         //vlist[j] = (Vertex *) SUMA_malloc (sizeof (Vertex));
02869         //ply_get_element (ply, (void *) vlist[j]);
02870         /* print out vertex x,y,z for debugging */
02871         if (LocalHead) fprintf (SUMA_STDERR, "%s vertex: %g %g %g\n", FuncName, vlist[j]->x, vlist[j]->y, vlist[j]->z);
02872         /* copy to NodeList */
02873         j3 = SO->NodeDim*j;
02874         SO->NodeList[j3] = vlist[j]->x;
02875         SO->NodeList[j3+1] = vlist[j]->y;
02876         SO->NodeList[j3+2] = vlist[j]->z;
02877         
02878         #else
02879         j3 = SO->NodeDim*j;
02880         ply_get_element (ply, (void *) &(SO->NodeList[j3]));
02881         /* print out vertex x,y,z for debugging */
02882         if (LocalHead) fprintf (SUMA_STDERR, "%s vertex: %g %g %g\n", FuncName, 
02883          SO->NodeList[j3], SO->NodeList[j3+1], SO->NodeList[j3+2]);
02884         #endif
02885          
02886       }
02887     }
02888 
02889     /* if we're on face elements, read them in */
02890     if (equal_strings ("face", elem_name)) {
02891 
02892       /* create a list to hold all the face elements */
02893       flist = (Face **) SUMA_malloc (sizeof (Face *) * num_elems);
02894 
02895       /* set up for getting face elements */
02896 
02897       ply_get_property (ply, elem_name, &face_props[0]);
02898       ply_get_property (ply, elem_name, &face_props[1]);
02899 
02900       /* grab all the face elements */
02901       for (j = 0; j < num_elems; j++) {
02902 
02903         /* grab and element from the file */
02904         flist[j] = (Face *) SUMA_malloc (sizeof (Face));
02905         ply_get_element (ply, (void *) flist[j]);
02906 
02907         /* print out face info, for debugging */
02908         if (LocalHead) {
02909          fprintf (SUMA_STDERR,"%s face: %d, list = ", FuncName, flist[j]->intensity);
02910          for (k = 0; k < flist[j]->nverts; k++)
02911             fprintf (SUMA_STDERR,"%d ", flist[j]->verts[k]);
02912          fprintf (SUMA_STDERR,"\n");
02913         }
02914         
02915       }
02916       /* copy face elements to SO structure */
02917       SO->FaceSetDim = flist[0]->nverts;
02918       SO->N_FaceSet = num_elems;
02919       SO->FaceSetList = (int *) SUMA_calloc (SO->FaceSetDim * num_elems, sizeof(int));
02920       if (!SO->FaceSetList) {
02921          fprintf (SUMA_STDERR, "Error %s: Failed to allocate for SO->NodeList.\n", FuncName);
02922          if (SO->NodeList) SUMA_free(SO->NodeList); 
02923          SUMA_RETURN(NOPE);
02924       }
02925       
02926       for (j = 0; j < num_elems; j++) {
02927          if (flist[j]->nverts != SO->FaceSetDim) {
02928             fprintf (SUMA_STDERR, "Error %s: All FaceSets must have the same dimension for SUMA.\n", FuncName);
02929             if (SO->NodeList) SUMA_free(SO->NodeList); 
02930             if (SO->FaceSetList) SUMA_free(SO->FaceSetList);
02931             SO->NodeList = NULL;
02932             SO->FaceSetList = NULL;
02933             SUMA_RETURN(NOPE);
02934          }
02935          ji = SO->FaceSetDim * j;
02936          for (k = 0; k < flist[j]->nverts; k++)
02937             SO->FaceSetList[ji+k] = flist[j]->verts[k];
02938       }
02939     }
02940 
02941    /* fill up a few more fields */
02942    SO->FileType = SUMA_PLY;
02943    if (file_type == PLY_ASCII) SO->FileFormat = SUMA_ASCII;
02944       else if (file_type == PLY_BINARY_BE) SO->FileFormat = SUMA_BINARY_BE;
02945          else if (file_type == PLY_BINARY_LE) SO->FileFormat = SUMA_BINARY_LE;
02946             else {
02947                fprintf (SUMA_STDERR, "Error %s: PLY_TYPE %d not recognized.\n", FuncName, file_type);
02948             }
02949             
02950    SO->Name = SUMA_StripPath(f_name);
02951    
02952    /* print out the properties we got, for debugging */
02953       if (LocalHead) {
02954          for (j = 0; j < nprops; j++)
02955             fprintf (SUMA_STDERR, "%s property %s\n", FuncName, plist[j]->name);
02956       }
02957    }
02958 
02959    /* grab and print out the comments in the file */
02960    comments = ply_get_comments (ply, &num_comments);
02961    if (LocalHead) {   
02962       for (i = 0; i < num_comments; i++)
02963          fprintf (SUMA_STDERR, "%s comment = '%s'\n", FuncName, comments[i]);
02964    }
02965    
02966    /* grab and print out the object information */
02967    obj_info = ply_get_obj_info (ply, &num_obj_info);
02968    if (LocalHead) {   
02969       for (i = 0; i < num_obj_info; i++)
02970          fprintf (SUMA_STDERR, "%s obj_info = '%s'\n", FuncName, obj_info[i]);
02971    }
02972    
02973    /* free the allocations necessary for vertex and facesetlists */
02974    for (j = 0; j < SO->N_FaceSet; j++) {
02975       SUMA_free(flist[j]);
02976    }
02977    SUMA_free(flist); flist = NULL;
02978    
02979    #ifdef USE_PLY_VERTEX
02980    for (j = 0; j < SO->N_Node; j++) {
02981       SUMA_free(vlist[j]);
02982    }
02983    SUMA_free(vlist); vlist = NULL;
02984    #endif
02985    /* close the PLY file, ply structure is freed within*/
02986    ply_close (ply);
02987    
02988    /* free plist */
02989    for (j = 0; j < nprops; j++) if (plist[j]) SUMA_free (plist[j]);
02990    if (plist) SUMA_free(plist);
02991    
02992    /* free comments */
02993    for (i = 0; i < num_comments; i++) if (comments[i]) SUMA_free (comments[i]);
02994    if (comments) SUMA_free (comments);
02995    
02996    /* free elist */
02997    for (i = 0; i < nelems; i++) if (elist[i]) SUMA_free (elist[i]);
02998    if (elist) SUMA_free (elist);
02999    
03000    /* free obj_info */
03001    for (i = 0; i < num_obj_info; i++) if (obj_info[i]) SUMA_free (obj_info[i]);
03002    if (obj_info) SUMA_free (obj_info);
03003     
03004    SUMA_RETURN(YUP);
03005 }

SUMA_Boolean SUMA_Ply_Write char *    f_name_in,
SUMA_SurfaceObject   SO
 

Writes an SO into a .ply file ans = SUMA_Ply_Write (f_name, SO);.

Parameters:
f_name  (char *) name of .ply file. if .ply is not attached it will be added.
SO  (SUMA_SurfaceObject *) Surface object to write out. if SO->FileFormat = SUMA_BINARY_BE or SUMA_BINARY_LE the surface is written in binary ply format. SUMA_BINARY is set to SUMA_BINARY_BE
Returns:
ans (SUMA_Boolean) success flag.
In its current incarnation, the function does not overwrite a pre-existing file.

Definition at line 3019 of file SUMA_Surface_IO.c.

References elem_names, faces, SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::FileFormat, i, LocalHead, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, PLY_ASCII, PLY_BINARY_BE, PLY_BINARY_LE, ply_close(), ply_describe_property(), ply_element_count(), ply_header_complete(), ply_open_for_writing(), ply_put_comment(), ply_put_element(), ply_put_element_setup(), ply_put_obj_info(), SUMA_append_string(), SUMA_ASCII, SUMA_BINARY, SUMA_BINARY_BE, SUMA_BINARY_LE, SUMA_Boolean, SUMA_ENTRY, SUMA_Extension(), SUMA_FF_NOT_SPECIFIED, SUMA_filexists(), SUMA_free, SUMA_malloc, SUMA_RETURN, and verts.

Referenced by SUMA_Save_Surface_Object().

03020 {
03021    static char FuncName[]={"SUMA_Ply_Write"};
03022    int i,j;
03023    PlyFile *ply = NULL;
03024    int nelems;
03025    int file_type;
03026    float version;
03027    int nverts ;
03028    int nfaces ;
03029    char *f_name, *f_name2, *elem_names[] = { "vertex", "face" };/* list of the kinds of elements in the user's object */
03030    int n_elem_names = 2;
03031    Vertex **verts = NULL;
03032    Face *faces = NULL;
03033    SUMA_Boolean LocalHead = NOPE;
03034    
03035    SUMA_ENTRY;
03036    
03037    if (!f_name_in) {
03038       fprintf (SUMA_STDERR, "Error %s: NULL filename\n", FuncName);
03039       SUMA_RETURN (NOPE);
03040    }
03041    
03042    f_name = SUMA_Extension(f_name_in,".ply" , YUP); 
03043    f_name2  = SUMA_append_string(f_name,".ply");
03044    if (SUMA_filexists (f_name2)) {
03045       fprintf (SUMA_STDERR, "Error %s: file %s exists, will not overwrite.\n", FuncName, f_name2);
03046       SUMA_free(f_name2);f_name2 = NULL;
03047       SUMA_free(f_name);f_name = NULL;
03048       SUMA_RETURN (NOPE);
03049    }
03050    SUMA_free(f_name2); f_name2 = NULL;
03051       
03052    nverts = SO->N_Node;
03053    nfaces = SO->N_FaceSet;
03054    
03055    /* must have XYZ */
03056    if (SO->NodeDim != 3) {
03057       fprintf (SUMA_STDERR, "Error %s: SO->NodeDim != 3.\n", FuncName);
03058       SUMA_RETURN (NOPE);
03059    }
03060 
03061    /* create the object in ply format */
03062    verts = (Vertex **) SUMA_malloc (nverts*sizeof(Vertex *));
03063    faces = (Face *) SUMA_malloc (nfaces*sizeof(Face));
03064    if (!verts || !faces) {
03065       fprintf (SUMA_STDERR, "Error %s: Failed to allocate.\n", FuncName);
03066       if (verts) SUMA_free(verts);
03067       if (faces) SUMA_free(faces);
03068       SUMA_RETURN (NOPE);
03069    }
03070 
03071    for (i = 0; i < nfaces; i++) {
03072       faces[i].intensity = '\001';
03073       faces[i].nverts = SO->FaceSetDim;
03074       faces[i].verts = &(SO->FaceSetList[SO->FaceSetDim*i]);
03075    }
03076    
03077    /* open either a binary or ascii PLY file for writing */
03078    /* (the file will be called "test.ply" because the routines */
03079    /*  enforce the .ply filename extension) */
03080 
03081    switch (SO->FileFormat) {
03082       case SUMA_BINARY_BE:
03083          ply = ply_open_for_writing(f_name, n_elem_names, elem_names, PLY_BINARY_BE, &version);
03084          break;
03085       
03086       case SUMA_BINARY_LE:
03087          ply = ply_open_for_writing(f_name, n_elem_names, elem_names, PLY_BINARY_LE, &version);
03088          break;
03089       
03090       case SUMA_ASCII:
03091          ply = ply_open_for_writing(f_name, n_elem_names, elem_names, PLY_ASCII, &version);
03092          break;
03093       
03094       case SUMA_BINARY:
03095          ply = ply_open_for_writing(f_name, n_elem_names, elem_names, PLY_BINARY_BE, &version);
03096          break;
03097       
03098       case SUMA_FF_NOT_SPECIFIED:
03099          ply = ply_open_for_writing(f_name, n_elem_names, elem_names, PLY_ASCII, &version);
03100          break;      
03101       
03102       default:
03103          fprintf (SUMA_STDERR, "Error %s: %d Unrecognized file format.\n", FuncName, SO->FileFormat);
03104          SUMA_RETURN (NOPE);
03105          break;  
03106    }
03107 
03108    if (!ply) {
03109       fprintf (SUMA_STDERR,"Error %s: Failed to create %s.ply\n", FuncName, f_name);
03110       if (verts) SUMA_free(verts);
03111       if (faces) SUMA_free(faces);
03112       SUMA_RETURN (NOPE);
03113    }
03114    /* describe what properties go into the vertex and face elements */
03115 
03116    ply_element_count (ply, "vertex", nverts);
03117    ply_describe_property (ply, "vertex", &vert_props[0]);
03118    ply_describe_property (ply, "vertex", &vert_props[1]);
03119    ply_describe_property (ply, "vertex", &vert_props[2]);
03120 
03121    ply_element_count (ply, "face", nfaces);
03122    ply_describe_property (ply, "face", &face_props[0]);
03123    ply_describe_property (ply, "face", &face_props[1]);
03124 
03125    /* write a comment and an object information field */
03126    ply_put_comment (ply, "author: Greg Turk");
03127    ply_put_obj_info (ply, "random information");
03128 
03129    /* we have described exactly what we will put in the file, so */
03130    /* we are now done with the header info */
03131    ply_header_complete (ply);
03132 
03133    /* set up and write the vertex elements */
03134    ply_put_element_setup (ply, "vertex");
03135    for (i = 0; i < nverts; i++)
03136     ply_put_element (ply, (void *) &(SO->NodeList[SO->NodeDim*i]));
03137 
03138    /* set up and write the face elements */
03139    ply_put_element_setup (ply, "face");
03140    for (i = 0; i < nfaces; i++)
03141     ply_put_element (ply, (void *) &faces[i]);
03142 
03143    /* close the PLY file */
03144    ply_close (ply);
03145 
03146    /* free */
03147    if (verts) SUMA_free(verts);
03148    if (faces) SUMA_free(faces);
03149    if (f_name) SUMA_free(f_name);
03150    SUMA_RETURN (YUP);
03151 }

void* SUMA_Prefix2SurfaceName char *    prefix_in,
char *    path,
char *    vp_name,
SUMA_SO_File_Type    oType,
SUMA_Boolean   exists
 

A function to take a prefix (or name) and turn it into the structure needed by SUMA_Save_Surface_Object also sets *exists = YUP if completed filename exists on disk. For surfaces requiring two files, *exists = YUP if any of the files exists - free returned pointer with SUMA_free.

See also:
SUMA_2Prefix2SurfaceName if you have a surface with different names for coord and topo )

Definition at line 220 of file SUMA_Surface_IO.c.

References SUMA_SFname::name_coord, SUMA_SFname::name_param, SUMA_SFname::name_topo, SUMA_append_replace_string(), SUMA_append_string(), SUMA_Boolean, SUMA_BRAIN_VOYAGER, SUMA_copy_string(), SUMA_ENTRY, SUMA_filexists(), SUMA_free, SUMA_FREE_SURFER, SUMA_FREE_SURFER_PATCH, SUMA_INVENTOR_GENERIC, SUMA_malloc, SUMA_MAX_DIR_LENGTH, SUMA_MAX_NAME_LENGTH, SUMA_OPENDX_MESH, SUMA_PLY, SUMA_RemoveSurfNameExtension(), SUMA_RETURN, SUMA_SO_File_Type, SUMA_SUREFIT, and SUMA_VEC.

Referenced by main(), SUMA_2Prefix2SurfaceName(), and SUMA_coarsen_ParseInput().

00221 {
00222    static char FuncName[]={"SUMA_Prefix2SurfaceName"};
00223    SUMA_SFname *SF_name = NULL;
00224    char *ppref = NULL, *prefix=NULL;
00225    void *SO_name = NULL;
00226    
00227    SUMA_ENTRY;
00228    
00229    if (!prefix_in) {
00230       fprintf (SUMA_STDERR,"Error %s: NULL name input\n", FuncName);
00231       SUMA_RETURN(NULL);
00232    }
00233    /* trim the prefix if necessary */
00234    if (!(prefix = SUMA_RemoveSurfNameExtension (prefix_in, oType))) {
00235       fprintf (SUMA_STDERR,"Error %s: Failed to remove extension\n", FuncName);
00236       SUMA_RETURN(NULL);
00237    }
00238    
00239    if (path) {
00240       if (path[strlen(path)-1] == '/') {
00241          ppref = SUMA_append_replace_string(path, prefix, "", 0);
00242       } else {
00243          ppref = SUMA_append_replace_string(path, prefix, "/", 0);
00244       }
00245    } else {
00246       ppref = SUMA_copy_string(prefix);
00247    }
00248    
00249    switch (oType) {
00250       case SUMA_SUREFIT:
00251          SF_name = (SUMA_SFname *) SUMA_malloc(sizeof(SUMA_SFname));
00252          snprintf(SF_name->name_coord, (SUMA_MAX_DIR_LENGTH+SUMA_MAX_NAME_LENGTH+1)*sizeof(char),
00253                    "%s.coord", ppref);
00254          snprintf(SF_name->name_topo, (SUMA_MAX_DIR_LENGTH+SUMA_MAX_NAME_LENGTH+1)*sizeof(char),
00255                    "%s.topo", ppref); 
00256          if (SUMA_filexists(SF_name->name_topo) || SUMA_filexists(SF_name->name_coord)) *exists = YUP;
00257          else *exists = NOPE;
00258          if (!vp_name) { /* initialize to empty string */
00259             SF_name->name_param[0] = '\0'; 
00260          }
00261          else {
00262             snprintf(SF_name->name_param, (SUMA_MAX_DIR_LENGTH+SUMA_MAX_NAME_LENGTH+1)*sizeof(char),
00263                    "%s", vp_name);
00264          }
00265          SO_name = (void *)SF_name;
00266          break;
00267       case SUMA_VEC:
00268          if (SF_name) SUMA_free(SF_name);
00269          SF_name = (SUMA_SFname *) SUMA_malloc(sizeof(SUMA_SFname));
00270          snprintf(SF_name->name_coord, (SUMA_MAX_DIR_LENGTH+SUMA_MAX_NAME_LENGTH+1)*sizeof(char),
00271                    "%s.1D.coord", ppref);
00272          snprintf(SF_name->name_topo, (SUMA_MAX_DIR_LENGTH+SUMA_MAX_NAME_LENGTH+1)*sizeof(char),
00273                    "%s.1D.topo", ppref); 
00274          if (SUMA_filexists(SF_name->name_topo) || SUMA_filexists(SF_name->name_coord)) *exists = YUP;
00275          else *exists = NOPE;
00276          SO_name = (void *)SF_name;
00277          break;
00278       case SUMA_FREE_SURFER:
00279       case SUMA_FREE_SURFER_PATCH:
00280          SO_name = (void *)SUMA_append_string(ppref,".asc"); 
00281          if (SUMA_filexists((char*)SO_name)) *exists = YUP;
00282          else *exists = NOPE;
00283          break;  
00284       case SUMA_OPENDX_MESH:
00285          SO_name = (void *)SUMA_append_string(ppref,".dx"); 
00286          if (SUMA_filexists((char*)SO_name)) *exists = YUP;
00287          else *exists = NOPE;
00288          break;  
00289       case SUMA_PLY:
00290          SO_name = (void *)SUMA_append_string(ppref,".ply"); 
00291          if (SUMA_filexists((char*)SO_name)) *exists = YUP;
00292          else *exists = NOPE;
00293          break;  
00294       case SUMA_BRAIN_VOYAGER:
00295          SO_name = (void *)SUMA_append_string(ppref,".srf"); 
00296          if (SUMA_filexists((char*)SO_name)) *exists = YUP;
00297          else *exists = NOPE;
00298          break;
00299       case SUMA_INVENTOR_GENERIC:
00300          SO_name = (void *)SUMA_append_string(ppref,".iv"); 
00301          if (SUMA_filexists((char*)SO_name)) *exists = YUP;
00302          else *exists = NOPE;
00303          break;
00304       default:
00305          fprintf (SUMA_STDERR,"Error %s: Unknown format.\n", FuncName);
00306          SO_name = (void *)SUMA_copy_string(ppref);
00307          if (SUMA_filexists((char*)SO_name)) *exists = YUP;
00308          else *exists = NOPE;
00309          break;
00310    }
00311    
00312    if (ppref) SUMA_free(ppref);
00313    if (prefix) SUMA_free(prefix); 
00314    
00315    SUMA_RETURN(SO_name);
00316 }

float* SUMA_readFScurv char *    f_name,
int *    nrows,
int *    ncols,
SUMA_Boolean    rowmajor,
SUMA_Boolean    SkipCoords
 

v = SUMA_readFScurv (curvname, nrows, ncols, rowmajor, SkipCoords); Not terribly useful of a function because it is practically a .1D format!

Parameters:
curvname  (char *) name of ascii curvature file
nrows  (int *) will contain the number of elements in file
ncols  (int *) will contain the number of columns in file. This is 5 for curvature files if SkipCoords is not set (node index, x, y, z, data) 2 if SkipCoords (node index, data)
rowmajor  (SUMA_Boolean) if (YUP) return results in row major order, else column major
SkipCoords  (SUMA_Boolean) if (YUP) reads only node index and data value (1st and last column of curvature files (skips the intermediary coordinates)
Returns:
v (float *) vector containing curvature file data

Definition at line 1576 of file SUMA_Surface_IO.c.

References c, far, i, LocalHead, MRI_FLOAT_PTR, mri_free(), mri_read_1D(), ncol, MRI_IMAGE::nx, MRI_IMAGE::ny, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_filexists(), SUMA_free, SUMA_LH, SUMA_MAX_STRING_LENGTH, SUMA_RETURN, SUMA_SL_Crit, SUMA_SL_Err, and v.

01577 {
01578    static char FuncName[]={"SUMA_readFScurv"};
01579    MRI_IMAGE *im = NULL;
01580    float *v = NULL, jnk, *far;
01581    int cnt, ex, id, i, ncol, nvec;
01582    char c, comment[SUMA_MAX_STRING_LENGTH];
01583    FILE *fs_file = NULL;
01584    SUMA_Boolean LocalHead = NOPE;
01585    
01586    SUMA_ENTRY;
01587    
01588    /* check for existence */
01589         if (!SUMA_filexists(f_name)) {
01590                 fprintf(SUMA_STDERR,"Error %s: File %s does not exist or cannot be read.\n", FuncName, f_name);
01591                 SUMA_RETURN (NULL);
01592         }else if (LocalHead) {
01593                 fprintf(SUMA_STDERR,"%s: File %s exists and will be read.\n", FuncName, f_name);
01594         }
01595    
01596    if (SkipCoords) *ncols = 2;
01597    else *ncols = 5; /* constant */      
01598 
01599    if (*ncols !=2 && *ncols != 5) {
01600       SUMA_SL_Crit("ncols must be either 2 or 5");
01601       SUMA_RETURN(NULL);
01602    }
01603 
01604 
01605    #if 0
01606       /* thought is had the number of nodes at the top ! */
01607       /* start reading */
01608            fs_file = fopen (f_name,"r");
01609            if (fs_file == NULL) {
01610          SUMA_SL_Err ("Could not open input file");
01611          SUMA_RETURN (v);
01612            }
01613 
01614            /* read first character and check if it is a comment */
01615            ex = fscanf (fs_file,"%c",&c);
01616            if (c == '#') {
01617                    if (LocalHead) fprintf (SUMA_STDOUT, "%s: Found comment\n", FuncName); 
01618 
01619          /*skip till next line */
01620                    cnt = 0;
01621                    while (ex != EOF && c != '\n') {
01622                            ex = fscanf (fs_file,"%c",&c);
01623                            if (cnt < SUMA_MAX_STRING_LENGTH-2) {
01624                                    sprintf(comment, "%s%c", comment, c);
01625                                    ++cnt;
01626                            } else {
01627                                    fprintf(SUMA_STDERR,"Error %s: Too long a comment in curvature file, increase SUMA_MAX_STRING_LENGTH\n", FuncName);
01628                                    SUMA_RETURN (NOPE);
01629                            }
01630                    }
01631            }
01632 
01633 
01634            /* read in the number of nodes */
01635            ex = fscanf(fs_file, "%d", nrows);
01636 
01637       if (*nrows <= 0) {
01638          SUMA_SL_Crit("Trouble parsing curvature file.\nNull or negative number of nodes\n");
01639          SUMA_RETURN(NULL);
01640       }
01641 
01642            if (LocalHead) fprintf (SUMA_STDOUT, "%s: Allocating for data (%dx%d) \n", FuncName, *nrows, *ncols);
01643 
01644       v = (float *) SUMA_calloc(*nrows * *ncols, sizeof(float));
01645       if (!v) {
01646          SUMA_SL_Crit("Failed to allocate for v");
01647          SUMA_RETURN(v);
01648       }
01649 
01650       if (LocalHead) fprintf (SUMA_STDOUT, "%s: Parsing file...\n", FuncName);
01651 
01652       if (rowmajor) {
01653          cnt = 0;
01654               if (*ncols == 5) {
01655             while (ex != EOF && cnt < *nrows) {
01656                          id = *ncols * cnt;
01657                          ex = fscanf(fs_file, "%f %f %f %f %f", &(v[id]), &(v[id+1]),&(v[id+2]), &(v[id+3]), &(v[id+4]) );
01658                          ++cnt;
01659                  }
01660          } else {
01661             while (ex != EOF && cnt < *nrows) {
01662                          id = *ncols * cnt;
01663                          ex = fscanf(fs_file, "%f %f %f %f %f", &(v[id]), &jnk, &jnk, &jnk, &(v[id+1]) );
01664                          ++cnt;
01665                  }
01666          } 
01667 
01668       } else {
01669          cnt = 0;
01670               if (*ncols == 5) {
01671             while (ex != EOF && cnt < *nrows) {
01672                          ex = fscanf(fs_file, "%f %f %f %f %f", &(v[cnt]), &(v[cnt+ *nrows]),&(v[cnt+ 2 * *nrows]), &(v[cnt+ 3 * *nrows]), &(v[cnt+ 4 * *nrows]));
01673                          ++cnt;
01674                  }
01675          } else if (*nrows == 2) {
01676             while (ex != EOF && cnt < *nrows) {
01677                          ex = fscanf(fs_file, "%f %f %f %f %f", &(v[cnt]), &jnk, &jnk, &jnk, &(v[cnt+ *nrows]));
01678                          ++cnt;
01679                  }
01680          } else {
01681 
01682          }
01683       }
01684 
01685       if (cnt != *nrows) {
01686                    fprintf(SUMA_STDERR,"Error %s: Expected %d rows, %d read.\n", FuncName, *nrows, cnt);
01687                    SUMA_free(v); v = NULL;
01688          SUMA_RETURN (NULL);
01689            }
01690    #else 
01691       /* now load the input data */
01692       SUMA_LH("Reading file...");
01693       im = mri_read_1D (f_name);
01694 
01695       if (!im) {
01696          SUMA_SL_Err("Failed to read 1D file");
01697          SUMA_RETURN(NULL);
01698       }
01699 
01700       far = MRI_FLOAT_PTR(im);
01701       nvec = im->nx;
01702       ncol = im->ny;
01703       /* data in column major order at this point */
01704 
01705       if (!nvec) {
01706          SUMA_SL_Err("Empty file");
01707          SUMA_RETURN(NULL);
01708       }
01709 
01710       if (ncol != 5) {
01711          SUMA_SL_Err("Must have 5 columns in data file.");
01712          mri_free(im); im = NULL;   /* done with that baby */
01713          SUMA_RETURN(NULL);
01714       }
01715       
01716       *nrows = nvec;
01717       
01718       if (LocalHead) fprintf (SUMA_STDOUT, "%s: Allocating for data (%dx%d) \n", FuncName, *nrows, *ncols);
01719 
01720       v = (float *) SUMA_calloc(*nrows * *ncols, sizeof(float));
01721       
01722       if (!v) {
01723          SUMA_SL_Crit("Failed to allocate for v");
01724          SUMA_RETURN(v);
01725       }
01726 
01727       if (LocalHead) fprintf (SUMA_STDOUT, "%s: Parsing file...\n", FuncName);
01728 
01729       if (rowmajor) {
01730               if (*ncols == 5) {
01731             SUMA_LH("RowMajor, All Coords");
01732             for (i=0; i< *nrows; ++i) {
01733                id = *ncols*i;
01734                v[id] = far[i];
01735                v[id+1] = far[i+*nrows];
01736                v[id+2] = far[i+2 * *nrows];
01737                v[id+3] = far[i+3 * *nrows];
01738                v[id+4] = far[i+4 * *nrows];
01739             }   
01740          } else {
01741             SUMA_LH("RowMajor, Skipping Coords");
01742             for (i=0; i< *nrows; ++i) {
01743                id = *ncols*i;
01744                v[id] = far[i];
01745                v[id+1] = far[i+4 * *nrows];
01746             }
01747          } 
01748       } else {
01749               if (*ncols == 5) {
01750             SUMA_LH("ColMajor, All Coords");
01751             for (i=0; i<*ncols * *nrows; ++i) v[i] = far[i];
01752          } else if (*ncols == 2) {
01753             SUMA_LH("ColMajor, Skipping Coords");
01754             for (i=0; i<*nrows; ++i) v[i] = far[i];
01755             for (i=*nrows; i< 2 * *nrows; ++i) v[i] = far[i+3 * *nrows];
01756          } 
01757       }
01758       mri_free(im); im = NULL; far = NULL;
01759    #endif
01760    SUMA_RETURN(v);
01761 }

char* SUMA_RemoveSurfNameExtension char *    Name,
SUMA_SO_File_Type    oType
 

Removes the standard extension from a dataset filename.

Parameters:
Name  (char *) name
form  SUMA_DSET_FORMAT
Returns:
(char *) no_extension (you have to free that one with SUMA_free)

Definition at line 124 of file SUMA_Surface_IO.c.

References SUMA_BRAIN_VOYAGER, SUMA_copy_string(), SUMA_ENTRY, SUMA_Extension(), SUMA_free, SUMA_FREE_SURFER, SUMA_FREE_SURFER_PATCH, SUMA_INVENTOR_GENERIC, SUMA_OPENDX_MESH, SUMA_PLY, SUMA_RETURN, SUMA_SL_Err, SUMA_SO_File_Type, SUMA_SUREFIT, and SUMA_VEC.

Referenced by SUMA_Parse_IO_Args(), and SUMA_Prefix2SurfaceName().

00125 {
00126    static char FuncName[]={"SUMA_RemoveSurfNameExtension"};
00127    char *noex = NULL, *tmp = NULL;
00128    
00129    SUMA_ENTRY;
00130    
00131    if (!Name) { SUMA_SL_Err("NULL Name"); SUMA_RETURN(NULL); }
00132   
00133    switch (oType) {
00134       case SUMA_SUREFIT:
00135          tmp  =  SUMA_Extension(Name, ".coord", YUP);
00136          noex  =  SUMA_Extension(tmp, ".topo", YUP); SUMA_free(tmp); tmp = NULL;
00137          break;
00138       case SUMA_VEC:
00139          tmp  =  SUMA_Extension(Name, ".1D.coord", YUP);
00140          noex  =  SUMA_Extension(tmp, ".1D.topo", YUP); SUMA_free(tmp); tmp = NULL;
00141          break;
00142       case SUMA_FREE_SURFER:
00143       case SUMA_FREE_SURFER_PATCH:
00144          noex  =  SUMA_Extension(Name, ".asc", YUP);
00145          break;  
00146       case SUMA_PLY:
00147          noex  =  SUMA_Extension(Name,".ply" , YUP); 
00148          break;  
00149       case SUMA_OPENDX_MESH:
00150          noex  =  SUMA_Extension(Name,".dx" , YUP); 
00151          break;  
00152       case SUMA_INVENTOR_GENERIC:
00153          noex  =  SUMA_Extension(Name,".iv" , YUP); 
00154          break;
00155       case SUMA_BRAIN_VOYAGER:
00156          noex  =  SUMA_Extension(Name,".srf" , YUP); 
00157          break;
00158       default:
00159          /* do nothing, get back fprintf (SUMA_STDERR,"Warning %s: Bad format.\n", FuncName); */
00160          noex = SUMA_copy_string(Name);
00161          break;
00162    }
00163    
00164    SUMA_RETURN(noex);
00165 }

NI_element* SUMA_ROIv2dataset SUMA_DRAWN_ROI **    ROIv,
int    N_ROIv,
char *    Parent_idcode_str,
int    Pad_to,
int    Pad_val
 

turns a bunch of ROIs into a NI dataset

Parameters:
ROIv  (SUMA_DRAWN_ROI**) vector of ROI structures
N_ROIv  (int) number of ROI structures
Parent_idcode_str  (char *) idcode of parent surface
Pad_to  (int) create Dset that has a full node listing from node 0 to node Pad_to (a total of Pad_to + 1 nodes) Use -1 to turn off padding.
Pad_val  (int) use this value (usually 0) to label a node being padded as oppsed to a node being a part of an ROI. This option is only useful with Pad_to
Returns:
nel (NI_element *) structure to data set NULL if failed

Definition at line 5205 of file SUMA_Surface_IO.c.

References i, SUMA_DRAWN_ROI::iLabel, LocalHead, SUMA_AddNelCol(), SUMA_Boolean, SUMA_calloc, SUMA_disp_dvect(), SUMA_ENTRY, SUMA_free, SUMA_freeDrawnROI(), SUMA_LH, SUMA_NewNel(), SUMA_NODE_ILABEL, SUMA_NODE_INDEX, SUMA_NODE_ROI, SUMA_NodesInROI(), SUMA_reorder(), SUMA_RETURN, SUMA_ROI_CRUDE_COUNT_NODES, SUMA_S_Err, SUMA_SL_Crit, SUMA_SL_Err, SUMA_SLP_Warn, SUMA_UniqueInt_ind(), and SUMA_z_dqsort().

05206 {
05207    static char FuncName[]={"SUMA_ROIv2dataset"};
05208    int ii, i, nn, cnt, N_NodesTotal = 0, MaxIndex = 0,
05209       *ip=NULL, *NodesTotal=NULL, *LabelsTotal=NULL,
05210       *NodesTotal_p=NULL, *LabelsTotal_p=NULL;
05211    NI_element *nel=NULL;
05212    SUMA_Boolean LocalHead = NOPE;
05213    
05214    SUMA_ENTRY;
05215    
05216    SUMA_SL_Err("Obsolete, use SUMA_ROIv2Grpdataset");
05217    SUMA_RETURN(NULL);
05218    
05219    /* Now you have the ROIs, concatenate all NodesInROI vectors into 1*/
05220    /* count the total number of nodes */
05221    N_NodesTotal = 0;
05222    for (ii=0; ii < N_ROIv; ++ii) {
05223       SUMA_ROI_CRUDE_COUNT_NODES(ROIv[ii], cnt);
05224       if (LocalHead) {
05225          fprintf (SUMA_STDERR,"%s: ROI #%d: %d nodes\n", FuncName, ii, cnt);
05226       }
05227       N_NodesTotal += cnt;
05228    }
05229    if (LocalHead) fprintf (SUMA_STDERR,"%s: %d nodes total.\n", FuncName, N_NodesTotal);
05230 
05231    NodesTotal = (int *)SUMA_calloc(N_NodesTotal, sizeof(int));
05232    LabelsTotal = (int *)SUMA_calloc(N_NodesTotal, sizeof(int));
05233 
05234    if (!NodesTotal || !LabelsTotal) {
05235       SUMA_S_Err("Failed to allocate.");
05236       SUMA_RETURN(nel);
05237    }
05238 
05239    cnt = 0;
05240    N_NodesTotal = 0;
05241    MaxIndex = -1;
05242    for (ii=0; ii <  N_ROIv; ++ii) {
05243       SUMA_LH("Appending ROI");
05244       /* You do not need the Unique operation in SUMA_NodesInROI,
05245       but it is nice to have so that you can report the nodes that 
05246       were part of more than one ROI. If you do not Set the Unique 
05247       flag in SUMA_NodesInROI you will likely get node duplication
05248       but these nodes are in the same ROI and therefore are not
05249       duplicates to be removed....*/
05250       ip = SUMA_NodesInROI (ROIv[ii], &nn, YUP);
05251       if (LocalHead) {
05252          fprintf (SUMA_STDERR,"%s: Nodes in ROI #%d\n", FuncName, ii);
05253          SUMA_disp_dvect (ip, nn);
05254       }
05255       for (i=0; i < nn; ++i) {
05256          NodesTotal[cnt] = ip[i];
05257          LabelsTotal[cnt] = ROIv[ii]->iLabel;
05258          if (ip[i] > MaxIndex) MaxIndex = ip[i];
05259          ++cnt;
05260       }
05261       N_NodesTotal += nn;
05262       SUMA_freeDrawnROI (ROIv[ii]); ROIv[ii] = NULL; /* free the Drawn ROI */
05263       SUMA_free(ip);ip=NULL;
05264    }
05265 
05266    if (LocalHead) {
05267       SUMA_disp_dvect (NodesTotal, N_NodesTotal);
05268    }
05269 
05270    /* Now you want to make sure that no two nodes are listed twice */
05271    /* sort NodesTotal and rearrange LabelsTotal accordingly */
05272    {  int *isort = NULL, *LabelsTotal_r = NULL,
05273          *NodesTotal_u = NULL, N_NodesTotal_u, *iu = NULL;
05274       char report[100];
05275 
05276       isort = SUMA_z_dqsort(NodesTotal, N_NodesTotal);
05277       LabelsTotal_r = SUMA_reorder (LabelsTotal, isort, N_NodesTotal);
05278       SUMA_free(LabelsTotal);
05279       LabelsTotal = LabelsTotal_r; LabelsTotal_r = NULL;
05280       SUMA_free(isort); isort = NULL;
05281 
05282       /* now get the unique set of nodes */
05283       NodesTotal_u = SUMA_UniqueInt_ind (NodesTotal, N_NodesTotal, &N_NodesTotal_u, &iu);
05284       /* reorder LabelsTotal to contain data from the nodes left in NodesTotal_u */
05285       LabelsTotal_r = SUMA_reorder (LabelsTotal, iu, N_NodesTotal_u);
05286       SUMA_free(NodesTotal); NodesTotal = NULL;
05287       SUMA_free(LabelsTotal); LabelsTotal = NULL;
05288       SUMA_free(iu); iu = NULL;
05289       NodesTotal = NodesTotal_u; NodesTotal_u = NULL;
05290       LabelsTotal = LabelsTotal_r; LabelsTotal_r = NULL;
05291 
05292       if (N_NodesTotal - N_NodesTotal_u) {
05293          sprintf(report, "%d/%d nodes had duplicate entries.\n"
05294                          "(ie same node part of more than 1 ROI)\n"
05295                          "Duplicate entries were eliminated.", 
05296                          N_NodesTotal - N_NodesTotal_u , N_NodesTotal);
05297 
05298          N_NodesTotal = N_NodesTotal_u; N_NodesTotal_u = 0;
05299          SUMA_SLP_Warn(report);
05300       }
05301    }
05302 
05303    if (Pad_to > 0) {
05304       SUMA_LH("Padding to desired length");
05305       if (Pad_to < MaxIndex) {
05306          SUMA_SL_Err("ROI contains node index > padding limit\nNo padding done.");
05307          if (NodesTotal) SUMA_free(NodesTotal); NodesTotal = NULL;
05308          if (LabelsTotal) SUMA_free(LabelsTotal); LabelsTotal = NULL;
05309          SUMA_RETURN(NULL);
05310       }else {
05311          NodesTotal_p =  (int *)SUMA_calloc(Pad_to+1, sizeof(int));
05312          LabelsTotal_p = (int *)SUMA_calloc(Pad_to+1, sizeof(int));
05313          if (!NodesTotal_p || !LabelsTotal_p) {
05314             SUMA_SL_Crit("Failed to allocate for NodesTotal_p || LabelsTotal_p");
05315             if (NodesTotal) SUMA_free(NodesTotal); NodesTotal = NULL;
05316             if (LabelsTotal) SUMA_free(LabelsTotal); LabelsTotal = NULL;
05317             SUMA_RETURN(NULL);
05318          }
05319          if (Pad_val)  for(i=0; i<=Pad_to; ++i) LabelsTotal_p[i] = Pad_val;
05320          for(i=0; i<=Pad_to; ++i) NodesTotal_p[i] = i;
05321          for(i=0; i<N_NodesTotal; ++i) {
05322             LabelsTotal_p[NodesTotal[i]] = LabelsTotal[i];
05323          }
05324          SUMA_free(NodesTotal); NodesTotal = NodesTotal_p; NodesTotal_p = NULL;
05325          SUMA_free(LabelsTotal);  LabelsTotal = LabelsTotal_p; LabelsTotal_p = NULL;
05326          N_NodesTotal = Pad_to + 1;
05327       }
05328    }
05329    
05330    /* construct a NIML data set for the output */
05331    SUMA_LH("Creating nel ");
05332    nel = SUMA_NewNel ( SUMA_NODE_ROI, /* one of SUMA_DSET_TYPE */
05333                        Parent_idcode_str, /* idcode of Domain Parent */
05334                        NULL, /* idcode of geometry parent, not useful here*/
05335                        N_NodesTotal,/* Number of elements */
05336                        NULL,
05337                        NULL); 
05338 
05339    if (!nel) {
05340       SUMA_SL_Err("Failed in SUMA_NewNel");
05341       SUMA_RETURN(nel);
05342    }
05343 
05344    /* Add the index column */
05345    SUMA_LH("Adding index column...");
05346    if (!SUMA_AddNelCol (nel, "node index", SUMA_NODE_INDEX, (void *)NodesTotal, NULL, 1)) {
05347       SUMA_SL_Err("Failed in SUMA_AddNelCol");
05348       SUMA_RETURN(nel);
05349    }
05350 
05351    /* Add the label column */
05352    SUMA_LH("Adding label column...");
05353    if (!SUMA_AddNelCol (nel, "integer label", SUMA_NODE_ILABEL, (void *)LabelsTotal, NULL, 1)) {
05354       SUMA_SL_Err("Failed in SUMA_AddNelCol");
05355       SUMA_RETURN(nel);
05356    }
05357    
05358    SUMA_LH("cleanup ...");
05359    if (NodesTotal) SUMA_free(NodesTotal); NodesTotal = NULL;
05360    if (LabelsTotal) SUMA_free(LabelsTotal); LabelsTotal = NULL;
05361    
05362    SUMA_RETURN(nel);
05363 }

SUMA_DSET* SUMA_ROIv2Grpdataset SUMA_DRAWN_ROI **    ROIv,
int    N_ROIv,
char *    Parent_idcode_str,
int    Pad_to,
int    Pad_val
 

turns a bunch of ROIs into a NI dataset A new version of SUMA_ROIv2dataset that allows the use of dsets as groups

Parameters:
ROIv  (SUMA_DRAWN_ROI**) vector of ROI structures
N_ROIv  (int) number of ROI structures
Parent_idcode_str  (char *) idcode of parent surface
Pad_to  (int) create Dset that has a full node listing from node 0 to node Pad_to (a total of Pad_to + 1 nodes) Use -1 to turn off padding.
Pad_val  (int) use this value (usually 0) to label a node being padded as oppsed to a node being a part of an ROI. This option is only useful with Pad_to
Returns:
nel (NI_element *) structure to data set NULL if failed

Definition at line 5027 of file SUMA_Surface_IO.c.

References SUMA_DSET::dnel, i, SUMA_DRAWN_ROI::iLabel, LocalHead, SUMA_AddDsetNelCol(), SUMA_Boolean, SUMA_calloc, SUMA_CreateDsetPointer(), SUMA_disp_dvect(), SUMA_ENTRY, SUMA_FindDsetDataAttributeElement(), SUMA_free, SUMA_freeDrawnROI(), SUMA_LH, SUMA_NODE_ILABEL, SUMA_NODE_INDEX, SUMA_NODE_ROI, SUMA_NodesInROI(), SUMA_reorder(), SUMA_RETURN, SUMA_ROI_CRUDE_COUNT_NODES, SUMA_S_Err, SUMA_SL_Crit, SUMA_SL_Err, SUMA_SLP_Warn, SUMA_UniqueInt_ind(), and SUMA_z_dqsort().

05028 {
05029    static char FuncName[]={"SUMA_ROIv2Grpdataset"};
05030    int ii, i, nn, cnt, N_NodesTotal = 0, MaxIndex = 0,
05031       *ip=NULL, *NodesTotal=NULL, *LabelsTotal=NULL,
05032       *NodesTotal_p=NULL, *LabelsTotal_p=NULL;
05033    SUMA_DSET *dset =NULL;
05034    SUMA_Boolean LocalHead = NOPE;
05035    
05036    SUMA_ENTRY;
05037    
05038    /* Now you have the ROIs, concatenate all NodesInROI vectors into 1*/
05039    /* count the total number of nodes */
05040    N_NodesTotal = 0;
05041    for (ii=0; ii < N_ROIv; ++ii) {
05042       SUMA_ROI_CRUDE_COUNT_NODES(ROIv[ii], cnt);
05043       if (LocalHead) {
05044          fprintf (SUMA_STDERR,"%s: ROI #%d: %d nodes\n", FuncName, ii, cnt);
05045       }
05046       N_NodesTotal += cnt;
05047    }
05048    if (LocalHead) fprintf (SUMA_STDERR,"%s: %d nodes total.\n", FuncName, N_NodesTotal);
05049 
05050    NodesTotal = (int *)SUMA_calloc(N_NodesTotal, sizeof(int));
05051    LabelsTotal = (int *)SUMA_calloc(N_NodesTotal, sizeof(int));
05052 
05053    if (!NodesTotal || !LabelsTotal) {
05054       SUMA_S_Err("Failed to allocate.");
05055       SUMA_RETURN(dset);
05056    }
05057 
05058    cnt = 0;
05059    N_NodesTotal = 0;
05060    MaxIndex = -1;
05061    for (ii=0; ii <  N_ROIv; ++ii) {
05062       SUMA_LH("Appending ROI");
05063       /* You do not need the Unique operation in SUMA_NodesInROI,
05064       but it is nice to have so that you can report the nodes that 
05065       were part of more than one ROI. If you do not Set the Unique 
05066       flag in SUMA_NodesInROI you will likely get node duplication
05067       but these nodes are in the same ROI and therefore are not
05068       duplicates to be removed....*/
05069       ip = SUMA_NodesInROI (ROIv[ii], &nn, YUP);
05070       if (LocalHead) {
05071          fprintf (SUMA_STDERR,"%s: Nodes in ROI #%d\n", FuncName, ii);
05072          SUMA_disp_dvect (ip, nn);
05073       }
05074       for (i=0; i < nn; ++i) {
05075          NodesTotal[cnt] = ip[i];
05076          LabelsTotal[cnt] = ROIv[ii]->iLabel;
05077          if (ip[i] > MaxIndex) MaxIndex = ip[i];
05078          ++cnt;
05079       }
05080       N_NodesTotal += nn;
05081       SUMA_freeDrawnROI (ROIv[ii]); ROIv[ii] = NULL; /* free the Drawn ROI */
05082       SUMA_free(ip);ip=NULL;
05083    }
05084 
05085    if (LocalHead) {
05086       SUMA_disp_dvect (NodesTotal, N_NodesTotal);
05087    }
05088 
05089    /* Now you want to make sure that no two nodes are listed twice */
05090    /* sort NodesTotal and rearrange LabelsTotal accordingly */
05091    {  int *isort = NULL, *LabelsTotal_r = NULL,
05092          *NodesTotal_u = NULL, N_NodesTotal_u, *iu = NULL;
05093       char report[100];
05094 
05095       isort = SUMA_z_dqsort(NodesTotal, N_NodesTotal);
05096       LabelsTotal_r = SUMA_reorder (LabelsTotal, isort, N_NodesTotal);
05097       SUMA_free(LabelsTotal);
05098       LabelsTotal = LabelsTotal_r; LabelsTotal_r = NULL;
05099       SUMA_free(isort); isort = NULL;
05100 
05101       /* now get the unique set of nodes */
05102       NodesTotal_u = SUMA_UniqueInt_ind (NodesTotal, N_NodesTotal, &N_NodesTotal_u, &iu);
05103       /* reorder LabelsTotal to contain data from the nodes left in NodesTotal_u */
05104       LabelsTotal_r = SUMA_reorder (LabelsTotal, iu, N_NodesTotal_u);
05105       SUMA_free(NodesTotal); NodesTotal = NULL;
05106       SUMA_free(LabelsTotal); LabelsTotal = NULL;
05107       SUMA_free(iu); iu = NULL;
05108       NodesTotal = NodesTotal_u; NodesTotal_u = NULL;
05109       LabelsTotal = LabelsTotal_r; LabelsTotal_r = NULL;
05110 
05111       if (N_NodesTotal - N_NodesTotal_u) {
05112          sprintf(report, "%d/%d nodes had duplicate entries.\n"
05113                          "(ie same node part of more than 1 ROI)\n"
05114                          "Duplicate entries were eliminated.", 
05115                          N_NodesTotal - N_NodesTotal_u , N_NodesTotal);
05116 
05117          N_NodesTotal = N_NodesTotal_u; N_NodesTotal_u = 0;
05118          SUMA_SLP_Warn(report);
05119       }
05120    }
05121 
05122    if (Pad_to > 0) {
05123       SUMA_LH("Padding to desired length");
05124       if (Pad_to < MaxIndex) {
05125          SUMA_SL_Err("ROI contains node index > padding limit\nNo padding done.");
05126          if (NodesTotal) SUMA_free(NodesTotal); NodesTotal = NULL;
05127          if (LabelsTotal) SUMA_free(LabelsTotal); LabelsTotal = NULL;
05128          SUMA_RETURN(NULL);
05129       }else {
05130          NodesTotal_p =  (int *)SUMA_calloc(Pad_to+1, sizeof(int));
05131          LabelsTotal_p = (int *)SUMA_calloc(Pad_to+1, sizeof(int));
05132          if (!NodesTotal_p || !LabelsTotal_p) {
05133             SUMA_SL_Crit("Failed to allocate for NodesTotal_p || LabelsTotal_p");
05134             if (NodesTotal) SUMA_free(NodesTotal); NodesTotal = NULL;
05135             if (LabelsTotal) SUMA_free(LabelsTotal); LabelsTotal = NULL;
05136             SUMA_RETURN(NULL);
05137          }
05138          if (Pad_val)  for(i=0; i<=Pad_to; ++i) LabelsTotal_p[i] = Pad_val;
05139          for(i=0; i<=Pad_to; ++i) NodesTotal_p[i] = i;
05140          for(i=0; i<N_NodesTotal; ++i) {
05141             LabelsTotal_p[NodesTotal[i]] = LabelsTotal[i];
05142          }
05143          SUMA_free(NodesTotal); NodesTotal = NodesTotal_p; NodesTotal_p = NULL;
05144          SUMA_free(LabelsTotal);  LabelsTotal = LabelsTotal_p; LabelsTotal_p = NULL;
05145          N_NodesTotal = Pad_to + 1;
05146       }
05147    }
05148    
05149    /* construct a NIML data set for the output */
05150    SUMA_LH("Creating dset ");
05151    dset = SUMA_CreateDsetPointer(
05152                                  NULL,         /* usually the filename */
05153                                  SUMA_NODE_ROI,                /* mix and match */
05154                                  NULL,    /* no idcode, let the function create one from the filename*/
05155                                  Parent_idcode_str,       /* no domain str specified */
05156                                  N_NodesTotal    /* Number of nodes allocated for */
05157                                  ); /* DO NOT free dset, it is store in DsetList */
05158 
05159    
05160    
05161    if (!dset) {
05162       SUMA_SL_Err("Failed in SUMA_CreateDsetPointer");
05163       SUMA_RETURN(NULL);
05164    }
05165 
05166    /* Add the index column */
05167    SUMA_LH("Adding index column...");
05168    if (!SUMA_AddDsetNelCol (dset, "node index", SUMA_NODE_INDEX, (void *)NodesTotal, NULL, 1)) {
05169       SUMA_SL_Err("Failed in SUMA_AddNelCol");
05170       SUMA_RETURN(dset);
05171    }
05172 
05173    /* Add the label column */
05174    SUMA_LH("Adding label column...");
05175    if (!SUMA_AddDsetNelCol (dset, "integer label", SUMA_NODE_ILABEL, (void *)LabelsTotal, NULL, 1)) {
05176       SUMA_SL_Err("Failed in SUMA_AddNelCol");
05177       SUMA_RETURN(dset);
05178    }
05179    
05180    /* make it easy */
05181    dset->dnel = SUMA_FindDsetDataAttributeElement(dset);
05182 
05183    SUMA_LH("cleanup ...");
05184    if (NodesTotal) SUMA_free(NodesTotal); NodesTotal = NULL;
05185    if (LabelsTotal) SUMA_free(LabelsTotal); LabelsTotal = NULL;
05186    
05187    SUMA_RETURN(dset);
05188 }

void SUMA_SaveDrawnROI char *    filename,
void *    data
 

handles saving ROI to filename.

Parameters:
filename  (char *)
data  (void *) pointer to DrawnROI stucture to be saved. If you pass null then SUMAg_CF->X->DrawROI->curDrawnROI is used.

Definition at line 5925 of file SUMA_Surface_IO.c.

References SUMA_X_DrawROI::curDrawnROI, SUMA_X_AllView::DrawROI, LocalHead, SUMA_DRAWN_ROI::Parent_idcode_str, SUMA_X_DrawROI::SaveMode, SUMA_X_DrawROI::SaveWhat, SUMA_ASCII, SUMA_Boolean, SUMA_ENTRY, SUMA_findSOp_inDOv(), SUMA_LH, SUMA_RETURNe, SUMA_SaveDrawnROI_1D(), SUMA_SaveDrawnROINIML(), SUMA_SL_Err, SUMA_SLP_Err, SUMAg_N_DOv, SW_DrawROI_SaveMode, SW_DrawROI_SaveMode1D, SW_DrawROI_SaveModeNIML, SW_N_DrawROI_SaveMode, and SUMA_CommonFields::X.

05926 {
05927    static char FuncName[]={"SUMA_SaveDrawnROI"};
05928    SUMA_DRAWN_ROI *DrawnROI=NULL;
05929    SUMA_SurfaceObject *SO= NULL;
05930    SUMA_Boolean LocalHead = NOPE;
05931    
05932    SUMA_ENTRY;
05933 
05934    SUMA_LH("Called");   
05935    if (!data) {
05936       DrawnROI = SUMAg_CF->X->DrawROI->curDrawnROI;
05937    } else {
05938       DrawnROI = (SUMA_DRAWN_ROI *)data;
05939    }
05940    
05941    /* is there a DrawnROI to work with ? */
05942    if (!DrawnROI) {
05943       SUMA_SLP_Err("No ROI selected.");
05944       SUMA_RETURNe;
05945    }
05946    
05947    /* Find the parent SO of that ROI */
05948    SO = SUMA_findSOp_inDOv(DrawnROI->Parent_idcode_str, SUMAg_DOv, SUMAg_N_DOv);
05949    if (!SO) {
05950       SUMA_SLP_Err("No Parent surface found.");
05951       SUMA_RETURNe;
05952    }
05953    
05954    /* switch the type of saving */
05955    switch (SUMAg_CF->X->DrawROI->SaveMode) {
05956       case SW_DrawROI_SaveMode1D:
05957          if (!SUMA_SaveDrawnROI_1D (filename, SO, DrawnROI, SUMAg_CF->X->DrawROI->SaveWhat)) {
05958             SUMA_SLP_Err("Failed to save ROI to disk");
05959             SUMA_RETURNe;
05960          }   
05961          break;
05962       case SW_DrawROI_SaveModeNIML:
05963          if (!SUMA_SaveDrawnROINIML (filename, SO, DrawnROI, SUMAg_CF->X->DrawROI->SaveWhat, SUMA_ASCII)) {
05964             SUMA_SLP_Err("Failed to save ROI to disk");
05965             SUMA_RETURNe;
05966          }
05967          break;
05968       case SW_DrawROI_SaveMode:
05969       case SW_N_DrawROI_SaveMode:
05970       default:
05971          SUMA_SL_Err("WhatYouTalkinAbout?");
05972          SUMA_RETURNe;
05973          break;
05974    }
05975    
05976    SUMA_RETURNe;
05977 } 

SUMA_Boolean SUMA_SaveDrawnROI_1D char *    filename,
SUMA_SurfaceObject   SO,
SUMA_DRAWN_ROI   DrawnROI,
int    SaveWhat
 

Definition at line 5979 of file SUMA_Surface_IO.c.

References LocalHead, SUMA_Boolean, SUMA_ENTRY, SUMA_Find_ROIrelatedtoSO(), SUMA_free, SUMA_LH, SUMA_MAX_NAME_LENGTH, SUMA_RETURN, SUMA_SLP_Err, SUMA_Write_DrawnROI_1D(), SUMAg_N_DOv, SW_DrawROI_SaveWhatRelated, and SW_DrawROI_SaveWhatThis.

Referenced by SUMA_SaveDrawnROI().

05980 {
05981    static char FuncName[]={"SUMA_SaveDrawnROI_1D"};
05982    char stmp[SUMA_MAX_NAME_LENGTH+20];
05983    SUMA_DRAWN_ROI **ROIv = NULL;
05984    int N_ROI=0;
05985    SUMA_Boolean LocalHead = NOPE;
05986    
05987    SUMA_ENTRY;
05988    SUMA_LH("Called");   
05989 
05990    if (SaveWhat == SW_DrawROI_SaveWhatThis) {
05991       if (!SUMA_Write_DrawnROI_1D (&DrawnROI, 1, filename)) {
05992          sprintf(stmp,"Failed to write %s", filename);
05993          SUMA_SLP_Err(stmp);
05994          SUMA_RETURN(NOPE);
05995       }
05996    }else if (SaveWhat == SW_DrawROI_SaveWhatRelated){
05997       /* get the pointers to the ROIs that are related to SO*/
05998       if (!(ROIv = SUMA_Find_ROIrelatedtoSO (SO, SUMAg_DOv, SUMAg_N_DOv, &N_ROI))) {
05999          SUMA_SLP_Err("Failed to write ROIs related to SO.");
06000          SUMA_RETURN(NOPE);
06001       }
06002       if (!SUMA_Write_DrawnROI_1D (ROIv, N_ROI, filename)) {
06003          sprintf(stmp,"Failed to write %s", filename);
06004          SUMA_SLP_Err(stmp);
06005          SUMA_RETURN(NOPE);
06006       }
06007         
06008       if (ROIv) SUMA_free(ROIv);    
06009    } else {
06010       SUMA_SLP_Err("SaveWhat option not nderstood");
06011       SUMA_RETURN(NOPE);
06012    }
06013    
06014    
06015 
06016    SUMA_RETURN(YUP);
06017 }

SUMA_Boolean SUMA_SaveDrawnROINIML char *    filename,
SUMA_SurfaceObject   SO,
SUMA_DRAWN_ROI   DrawnROI,
int    SaveWhat,
int    Format
 

Definition at line 6019 of file SUMA_Surface_IO.c.

References LocalHead, SUMA_Boolean, SUMA_ENTRY, SUMA_Find_ROIrelatedtoSO(), SUMA_free, SUMA_LH, SUMA_MAX_NAME_LENGTH, SUMA_RETURN, SUMA_SLP_Err, SUMA_Write_DrawnROI_NIML(), SUMAg_N_DOv, SW_DrawROI_SaveWhatRelated, and SW_DrawROI_SaveWhatThis.

Referenced by SUMA_SaveDrawnROI().

06020 {
06021    static char FuncName[]={"SaveDrawnROINIML"};
06022    char stmp[SUMA_MAX_NAME_LENGTH+20];
06023    SUMA_DRAWN_ROI **ROIv = NULL;
06024    int N_ROI=0;
06025    SUMA_Boolean LocalHead = NOPE;
06026    
06027    SUMA_ENTRY;
06028    SUMA_LH("Called");   
06029 
06030    if (SaveWhat == SW_DrawROI_SaveWhatThis) {
06031       if (!SUMA_Write_DrawnROI_NIML (&DrawnROI, 1, filename, Format)) {
06032          sprintf(stmp,"Failed to write %s", filename);
06033          SUMA_SLP_Err(stmp);
06034          SUMA_RETURN(NOPE);
06035       }
06036    }else if (SaveWhat == SW_DrawROI_SaveWhatRelated){
06037       /* get the pointers to the ROIs that are related to SO*/
06038       if (!(ROIv = SUMA_Find_ROIrelatedtoSO (SO, SUMAg_DOv, SUMAg_N_DOv, &N_ROI))) {
06039          SUMA_SLP_Err("Failed to write ROIs related to SO.");
06040          SUMA_RETURN(NOPE);
06041       }
06042       if (!SUMA_Write_DrawnROI_NIML (ROIv, N_ROI, filename, Format)) {
06043          sprintf(stmp,"Failed to write %s", filename);
06044          SUMA_SLP_Err(stmp);
06045          SUMA_RETURN(NOPE);
06046       }
06047         
06048       if (ROIv) SUMA_free(ROIv);    
06049    } else {
06050       SUMA_SLP_Err("SaveWhat option not nderstood");
06051       SUMA_RETURN(NOPE);
06052    }
06053   
06054    SUMA_RETURN(YUP);
06055 }

void SUMA_SaveSOascii char *    filename,
void *    data
 

handles savinf SO to ascii filename

Parameters:
filename  (char *)
data  (void *) pointer to SUMA_SAVESO_STRUCT containing sv and SO be saved

Definition at line 5742 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::idcode_str, SUMA_SurfaceObject::Label, LocalHead, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, SUMA_SAVESO_STRUCT::SO, SUMA_Boolean, SUMA_ENTRY, SUMA_Extension(), SUMA_filexists(), SUMA_ForceUser_YesNo(), SUMA_free, SUMA_GetColorList(), SUMA_LH, SUMA_NO, SUMA_NO_ALL, SUMA_RETURNe, SUMA_SL_Err, SUMA_SLP_Err, SUMA_YES, SUMA_YES_ALL, SUMA_SAVESO_STRUCT::sv, and SWP_DONT_CARE.

05743 {
05744    static char FuncName[]={"SUMA_SaveSOascii"};
05745    char *newname = NULL, *newprefix = NULL, *tmp1= NULL, *tmp2= NULL;
05746    FILE *Fout = NULL;
05747    static int answer;
05748    int ND=-1, NP=-1, ii=-1, id=-1,ip=-1; 
05749    GLfloat *glar_ColorList = NULL;
05750    SUMA_SAVESO_STRUCT *SaveSO_data = NULL;
05751    SUMA_Boolean LocalHead = NOPE;
05752    
05753    SUMA_ENTRY;
05754 
05755    SUMA_LH("Called");   
05756       
05757    if (!data) {
05758       SUMA_SLP_Err("NULL data");
05759       SUMA_RETURNe;
05760    }
05761    
05762    SaveSO_data = (SUMA_SAVESO_STRUCT *)data;
05763    if (!SaveSO_data->SO || !SaveSO_data->sv) {
05764       SUMA_SLP_Err("Null SO or Null sv");
05765       if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05766       SUMA_RETURNe;
05767    }
05768    
05769    /* remove any of the extensions to be used */
05770    tmp1 = SUMA_Extension(filename, ".1D.xyz", YUP);
05771    tmp2 = SUMA_Extension(tmp1, ".1D.tri", YUP);
05772    newprefix = SUMA_Extension(tmp2, ".1D.col", YUP);
05773    if (tmp1) SUMA_free(tmp1); tmp1 = NULL;
05774    if (tmp2) SUMA_free(tmp2); tmp2 = NULL;
05775    
05776    /* add a .xyz extension */
05777    if (newname) SUMA_free(newname); newname = NULL;
05778    newname = SUMA_Extension(newprefix, ".1D.xyz", NOPE); 
05779    if (!newname) {
05780       SUMA_SL_Err("Invalid filename");
05781       if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05782       SUMA_RETURNe;
05783    }
05784    SUMA_LH(newname);
05785    /* check for filename existence */
05786    if (SUMA_filexists (newname)) {
05787       answer = SUMA_ForceUser_YesNo (SUMAg_SVv[0].X->TOPLEVEL, 
05788                                     "Prefix exists, overwrite?", 
05789                                     SUMA_NO, SWP_DONT_CARE);
05790       if (answer == SUMA_NO ||answer == SUMA_NO_ALL) {
05791          if (newname) SUMA_free(newname); newname = NULL;
05792          if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05793          SUMA_RETURNe; 
05794       }
05795    } 
05796 
05797    /* add a .tri extension */
05798    if (answer != SUMA_YES_ALL && answer != SUMA_YES) {
05799       if (newname) SUMA_free(newname);newname = NULL;
05800       newname = SUMA_Extension(newprefix, ".1D.tri", NOPE); 
05801       if (!newname) {
05802          SUMA_SL_Err("Invalid filename");
05803          if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05804          SUMA_RETURNe;
05805       }
05806       SUMA_LH(newname);
05807       /* check for filename existence */
05808       if (SUMA_filexists (newname)) {
05809          answer = SUMA_ForceUser_YesNo (SUMAg_SVv[0].X->TOPLEVEL, 
05810                                        "Prefix exists, overwrite?", 
05811                                        SUMA_NO, SWP_DONT_CARE);
05812          if (answer == SUMA_NO ||answer == SUMA_NO_ALL) {
05813             if (newname) SUMA_free(newname);newname = NULL;
05814             if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05815             SUMA_RETURNe; 
05816          }
05817       } 
05818    }
05819    
05820    /* add a .col extension */
05821    if (answer != SUMA_YES_ALL  && answer != SUMA_YES) {
05822       if (newname) SUMA_free(newname); newname = NULL;
05823       newname = SUMA_Extension(newprefix, ".1D.col", NOPE); 
05824       if (!newname) {
05825          SUMA_SL_Err("Invalid filename");
05826          if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05827          SUMA_RETURNe;
05828       }
05829       SUMA_LH(newname);
05830       /* check for filename existence */
05831       if (SUMA_filexists (newname)) {
05832          answer = SUMA_ForceUser_YesNo (SUMAg_SVv[0].X->TOPLEVEL, 
05833                                        "Prefix exists, overwrite?", 
05834                                        SUMA_NO, SWP_DONT_CARE);
05835          if (answer == SUMA_NO ||answer == SUMA_NO_ALL) {
05836             if (newname) SUMA_free(newname);newname = NULL;
05837             if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05838             SUMA_RETURNe; 
05839          }
05840       } 
05841    }
05842    
05843    /* OK, names are acceptable, proceed */
05844    ND = SaveSO_data->SO->NodeDim;
05845    NP = SaveSO_data->SO->FaceSetDim;
05846 
05847    if (newname) SUMA_free(newname);newname = NULL;
05848    newname = SUMA_Extension(newprefix, ".1D.xyz", NOPE);  
05849    if (LocalHead) fprintf (SUMA_STDERR,"%s: Preparing to write .1D.xyz %s.\n", FuncName, newname); 
05850    Fout = fopen(newname, "w");
05851    if (Fout == NULL) {
05852       fprintf(SUMA_STDERR, "Error %s: Could not open file %s for writing.\n", FuncName, newname);
05853       if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05854       SUMA_RETURNe;
05855    }
05856 
05857    fprintf(Fout, "#FileContents = Node coordinates\n#RowFormat = X Y Z\n#N_Nodes = %d\n#Source = SUMA, surface %s (idcode: %s)\n",
05858           SaveSO_data->SO->N_Node, SaveSO_data->SO->Label, SaveSO_data->SO->idcode_str);
05859    for (ii=0; ii < SaveSO_data->SO->N_Node; ++ii) {
05860       id = ND * ii;
05861       fprintf(Fout, "%f\t%f\t%f\n", \
05862          SaveSO_data->SO->NodeList[id], SaveSO_data->SO->NodeList[id+1],SaveSO_data->SO->NodeList[id+2]);
05863    }
05864    fclose (Fout);
05865 
05866    if (newname) SUMA_free(newname);newname = NULL;
05867    newname = SUMA_Extension(newprefix, ".1D.tri", NOPE);  
05868    if (LocalHead) fprintf (SUMA_STDERR,"%s: Preparing to write .1D.tri %s.\n", FuncName, newname); 
05869    Fout = fopen(newname, "w");
05870    if (Fout == NULL) {
05871       fprintf(SUMA_STDERR, "Error %s: Could not open file %s for writing.\n", FuncName, newname);
05872       if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05873       SUMA_RETURNe;
05874    }
05875    
05876    fprintf(Fout, "#FileContents = Triangles\n#RowFormat = n1 n2 n3\n#N_Tri = %d\n#Source = SUMA, surface %s (idcode: %s)\n",
05877           SaveSO_data->SO->N_FaceSet, SaveSO_data->SO->Label, SaveSO_data->SO->idcode_str);
05878    for (ii=0; ii < SaveSO_data->SO->N_FaceSet; ++ii) {
05879       ip = NP * ii;
05880       fprintf(Fout, "%d\t%d\t%d\n", \
05881          SaveSO_data->SO->FaceSetList[ip], SaveSO_data->SO->FaceSetList[ip+1],SaveSO_data->SO->FaceSetList[ip+2]);
05882    }
05883    fclose (Fout);
05884 
05885    if (newname) SUMA_free(newname);newname = NULL;
05886    newname = SUMA_Extension(newprefix, ".1D.col", NOPE);  
05887    if (LocalHead) fprintf (SUMA_STDERR,"%s: Preparing to write .1D.col %s.\n", FuncName, newname); 
05888    Fout = fopen(newname, "w");
05889    if (Fout == NULL) {
05890       fprintf(SUMA_STDERR, "Error %s: Could not open file %s for writing.\n", FuncName, newname);
05891       if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05892       SUMA_RETURNe;
05893    }
05894     glar_ColorList = SUMA_GetColorList (SaveSO_data->sv, SaveSO_data->SO->idcode_str);
05895     if (!glar_ColorList) {
05896       fprintf(SUMA_STDERR, "Error %s: NULL glar_ColorList. BAD.\n", FuncName);
05897       if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05898       SUMA_RETURNe;
05899     }
05900    fprintf(Fout, "#FileContents = Node Colors\n#RowFormat = n R G B\n#N_Nodes = %d\n#Source = SUMA, surface %s (idcode: %s)\n",
05901           SaveSO_data->SO->N_Node, SaveSO_data->SO->Label, SaveSO_data->SO->idcode_str);
05902    for (ii=0; ii < SaveSO_data->SO->N_Node; ++ii) {
05903       ip = 4 * ii;
05904       fprintf(Fout, "%d\t%f\t%f\t%f\n", \
05905          ii, glar_ColorList[ip], glar_ColorList[ip+1], glar_ColorList[ip+2]);
05906    }
05907    fclose (Fout);
05908 
05909    if (LocalHead) fprintf(SUMA_STDERR, "%s: Wrote files to disk.\n", 
05910       FuncName);
05911 
05912    if (newname) SUMA_free(newname);newname = NULL;
05913    if (SaveSO_data) SUMA_free(SaveSO_data); SaveSO_data = NULL;
05914    if (newprefix) SUMA_free(newprefix); 
05915    SUMA_RETURNe;
05916 }

void SUMA_Show_FreeSurfer SUMA_FreeSurfer_struct   FS,
FILE *    Out
 

Show elements of FreeSurfer structure

Definition at line 2426 of file SUMA_Surface_IO.c.

References SUMA_FreeSurfer_struct::comment, SUMA_FreeSurfer_struct::FaceSetIndexInParent, SUMA_FreeSurfer_struct::FaceSetList, SUMA_FreeSurfer_struct::isPatch, SUMA_FreeSurfer_struct::N_FaceSet, SUMA_FreeSurfer_struct::N_Node, SUMA_FreeSurfer_struct::NodeId, SUMA_FreeSurfer_struct::NodeList, SUMA_ENTRY, and SUMA_RETURNe.

Referenced by SUMA_Load_Surface_Object_eng().

02427 {       
02428         static char FuncName[]={"SUMA_Show_FreeSurfer"};
02429         int ND = 3, id, ip;
02430         
02431         SUMA_ENTRY;
02432 
02433         if (Out == NULL) Out = SUMA_STDOUT;
02434         if (FS->comment) fprintf (Out, "Comment: %s\n", FS->comment);
02435    else fprintf (Out, "Comment: NULL\n");
02436         fprintf (Out, "N_Node %d\n", FS->N_Node);
02437         if (FS->NodeId) {
02438       fprintf (Out, "First 2 points [id] X Y Z:\n\t[%d] %f %f %f\n\t[%d] %f %f %f\n", \
02439                    FS->NodeId[0], FS->NodeList[0], FS->NodeList[1], FS->NodeList[2],
02440                    FS->NodeId[1], FS->NodeList[3], FS->NodeList[4], FS->NodeList[5]);
02441            if (FS->N_Node > 2) {
02442          fprintf (Out, "Last 2 points [id] X Y Z:\n\t[%d] %f %f %f\n\t[%d] %f %f %f\n", \
02443                       FS->NodeId[FS->N_Node-2], FS->NodeList[3*(FS->N_Node-2)], FS->NodeList[3*(FS->N_Node-2)+1], FS->NodeList[3*(FS->N_Node-2)+2],
02444                       FS->NodeId[FS->N_Node-1], FS->NodeList[3*(FS->N_Node-1)], FS->NodeList[3*(FS->N_Node-1)+1], FS->NodeList[3*(FS->N_Node-1)+2]);
02445       }
02446    } else {
02447       fprintf (Out, "NULL NodeId\n");
02448       fprintf (Out, "First 2 points X Y Z:\n\t %f %f %f\n\t %f %f %f\n", \
02449                    FS->NodeList[0], FS->NodeList[1], FS->NodeList[2],
02450                    FS->NodeList[3], FS->NodeList[4], FS->NodeList[5]);
02451            if (FS->N_Node > 2) {
02452          fprintf (Out, "Last 2 points X Y Z:\n\t %f %f %f\n\t %f %f %f\n", \
02453                       FS->NodeList[3*(FS->N_Node-2)], FS->NodeList[3*(FS->N_Node-2)+1], FS->NodeList[3*(FS->N_Node-2)+2],
02454                       FS->NodeList[3*(FS->N_Node-1)], FS->NodeList[3*(FS->N_Node-1)+1], FS->NodeList[3*(FS->N_Node-1)+2]);
02455       }
02456    }
02457         fprintf (Out, "N_FaceSet %d\n", FS->N_FaceSet);
02458         if (!FS->isPatch) {
02459                 if (FS->N_FaceSet > 2) {
02460         fprintf (Out, "First 2 polygons:\n\t%d %d %d\n\t%d %d %d\n", \
02461                         FS->FaceSetList[0], FS->FaceSetList[1], FS->FaceSetList[2],
02462                         FS->FaceSetList[3], FS->FaceSetList[4], FS->FaceSetList[5]);
02463         fprintf (Out, "Last 2 polygons:\n%d %d %d\n%d %d %d\n", \
02464                         FS->FaceSetList[3 * (FS->N_FaceSet-2)], FS->FaceSetList[3 * (FS->N_FaceSet-2) + 1], FS->FaceSetList[3 * (FS->N_FaceSet-2) + 2],
02465                         FS->FaceSetList[3 * (FS->N_FaceSet-1)], FS->FaceSetList[3 * (FS->N_FaceSet-1) + 1], FS->FaceSetList[3 * (FS->N_FaceSet-1) + 2]);
02466       }else {
02467          fprintf (Out, "First polygon:\n\t%d %d %d\n", \
02468                         FS->FaceSetList[0], FS->FaceSetList[1], FS->FaceSetList[2]);
02469       }
02470         } else {
02471                 if (FS->N_FaceSet > 2) {
02472          fprintf (Out, "First 2 polygons:\n\t[parent ID:%d] %d %d %d\n\t[parent ID:%d] %d %d %d\n", \
02473                         FS->FaceSetIndexInParent[0], FS->FaceSetList[0], FS->FaceSetList[1], FS->FaceSetList[2],
02474                         FS->FaceSetIndexInParent[1], FS->FaceSetList[3], FS->FaceSetList[4], FS->FaceSetList[5]);
02475                    fprintf (Out, "Last 2 polygons:\n\t[parent ID:%d]%d %d %d\n\t[parent ID:%d]%d %d %d\n", \
02476                         FS->FaceSetIndexInParent[FS->N_FaceSet-2], FS->FaceSetList[3 * (FS->N_FaceSet-2)], \
02477                         FS->FaceSetList[3 * (FS->N_FaceSet-2) + 1], FS->FaceSetList[3 * (FS->N_FaceSet-2) + 2], \
02478                         FS->FaceSetIndexInParent[FS->N_FaceSet-1], FS->FaceSetList[3 * (FS->N_FaceSet-1)], \
02479                         FS->FaceSetList[3 * (FS->N_FaceSet-1) + 1], FS->FaceSetList[3 * (FS->N_FaceSet-1) + 2]);
02480       } else {
02481          fprintf (Out, "First polygon:\n\t[parent ID:%d] %d %d %d\n", \
02482                         FS->FaceSetIndexInParent[0], FS->FaceSetList[0], FS->FaceSetList[1], FS->FaceSetList[2]);
02483       }
02484         }
02485         SUMA_RETURNe;
02486 
02487 }

void SUMA_Show_OpenDX_Struct SUMA_OPEN_DX_STRUCT **    dxv,
int    N_dxv,
FILE *    out
 

Definition at line 7480 of file SUMA_Surface_IO.c.

References SUMA_OPEN_DX_STRUCT::attr_name, SUMA_OPEN_DX_STRUCT::attr_string, SUMA_OPEN_DX_STRUCT::bad_data, SUMA_OPEN_DX_STRUCT::class, SUMA_OPEN_DX_STRUCT::comp_name, SUMA_OPEN_DX_STRUCT::comp_value, SUMA_OPEN_DX_STRUCT::counts, SUMA_OPEN_DX_STRUCT::data, SUMA_OPEN_DX_STRUCT::data_format, SUMA_OPEN_DX_STRUCT::data_off, SUMA_OPEN_DX_STRUCT::datap, SUMA_OPEN_DX_STRUCT::delta, i, idx, SUMA_OPEN_DX_STRUCT::items, SUMA_OPEN_DX_STRUCT::n_attr, SUMA_OPEN_DX_STRUCT::n_comp, SUMA_OPEN_DX_STRUCT::n_counts, SUMA_OPEN_DX_STRUCT::n_delta, SUMA_OPEN_DX_STRUCT::n_origin, SUMA_OPEN_DX_STRUCT::object, SUMA_OPEN_DX_STRUCT::origin, SUMA_OPEN_DX_STRUCT::rank, SUMA_OPEN_DX_STRUCT::shape, SUMA_ENTRY, SUMA_float, SUMA_free, SUMA_int, SUMA_NCOL_OPENDX, SUMA_RETURNe, SUMA_ShowMeSome(), SUMA_SS2S, SUMA_StringAppend(), SUMA_StringAppend_va(), and SUMA_OPEN_DX_STRUCT::type.

Referenced by SUMA_LoadDXDset(), and SUMA_OpenDX_Read().

07481 {
07482    static char FuncName[]={"SUMA_Show_OpenDX_Struct"};
07483    int i, idx;
07484    SUMA_STRING *SS=NULL;
07485    char *s = NULL;
07486    SUMA_OPEN_DX_STRUCT *dx=NULL;
07487    
07488    SUMA_ENTRY;
07489    
07490    SS = SUMA_StringAppend(NULL, NULL);  
07491    if (!dxv) SS = SUMA_StringAppend(SS, "NULL dxv\n");
07492    for (idx = 0; idx < N_dxv; ++idx) {
07493       dx = dxv[idx];
07494       SS = SUMA_StringAppend_va(SS, "Object Struct %d/%d\n", idx+1, N_dxv);
07495       if (!dx) SS = SUMA_StringAppend(SS, "NULL dx\n");
07496       else {
07497          if (dx->object) SS = SUMA_StringAppend_va(SS, "object: %s\n", dx->object);
07498          else SS = SUMA_StringAppend_va(SS, "object: NULL\n"); 
07499          if (dx->class) SS = SUMA_StringAppend_va(SS, "class: %s\n", dx->class);
07500          else SS = SUMA_StringAppend_va(SS, "class: NULL\n"); 
07501          if (dx->type) SS = SUMA_StringAppend_va(SS, "type: %s\n", dx->type);
07502          else SS = SUMA_StringAppend_va(SS, "type: NULL\n"); 
07503          if (dx->rank) SS = SUMA_StringAppend_va(SS, "rank: %d\n", dx->rank);
07504          else SS = SUMA_StringAppend_va(SS, "rank: 0\n"); 
07505          if (dx->shape) SS = SUMA_StringAppend_va(SS, "shape: %d\n", dx->shape);
07506          else SS = SUMA_StringAppend_va(SS, "shape: 0\n"); 
07507          if (dx->items) SS = SUMA_StringAppend_va(SS, "items: %d\n", dx->items);
07508          else SS = SUMA_StringAppend_va(SS, "items: 0\n"); 
07509          if (dx->counts) {
07510             SS = SUMA_StringAppend_va(SS, "counts: (%d vals)\n", dx->n_counts);
07511             s = SUMA_ShowMeSome(dx->counts, SUMA_int, dx->n_counts, 5);
07512             SS = SUMA_StringAppend_va(SS, "\t%s\n", s); SUMA_free(s); s = NULL;
07513          } else SS = SUMA_StringAppend_va(SS, "counts: NULL\n");
07514          if (dx->origin) {
07515             SS = SUMA_StringAppend_va(SS, "origin: (%d vals)\n", dx->n_origin);
07516             s = SUMA_ShowMeSome(dx->origin, SUMA_float, dx->n_origin, 5);
07517             SS = SUMA_StringAppend_va(SS, "\t%s\n", s); SUMA_free(s); s = NULL;
07518          } else SS = SUMA_StringAppend_va(SS, "origin: NULL\n");
07519          if (dx->delta) {
07520             SS = SUMA_StringAppend_va(SS, "delta: (%d vals)\n", dx->n_delta);
07521             s = SUMA_ShowMeSome(dx->delta, SUMA_float, dx->n_delta, 9);
07522             SS = SUMA_StringAppend_va(SS, "\t%s\n", s); SUMA_free(s); s = NULL;
07523          }else SS = SUMA_StringAppend_va(SS, "delta: NULL\n");
07524          
07525          if (dx->data) SS = SUMA_StringAppend_va(SS, "data: %s (Data load error %d)\n", dx->data, dx->bad_data);
07526          else SS = SUMA_StringAppend_va(SS, "data: NULL\n"); 
07527          if (dx->data_off) SS = SUMA_StringAppend_va(SS, "data_off: %s \n", dx->data_off);
07528          else SS = SUMA_StringAppend_va(SS, "data_off: NULL\n"); 
07529          SS = SUMA_StringAppend_va(SS, "data_format: %d \n", dx->data_format);
07530          if (dx->datap) {
07531             s = SUMA_ShowMeSome(dx->datap, SUMA_VarType2TypeCast(dx->type), dx->items * SUMA_NCOL_OPENDX(dx), 5);
07532             SS = SUMA_StringAppend_va(SS, "\t%s\n", s); SUMA_free(s); s = NULL;
07533          }
07534          if (dx->n_comp) {
07535             SS = SUMA_StringAppend_va(SS, "components: %d\n", dx->n_comp);
07536             for (i=0; i<dx->n_comp; ++i) {  
07537                if (dx->comp_name[i]) SS = SUMA_StringAppend_va(SS, "\tname: %s\t", dx->comp_name[i]);
07538                else SS = SUMA_StringAppend_va(SS, "\tname: NULL\t"); 
07539                if (dx->comp_value[i]) SS = SUMA_StringAppend_va(SS, "\ttype: %s\n", dx->comp_value[i]);
07540                else SS = SUMA_StringAppend_va(SS, "\ttype: NULL\n"); 
07541             }    
07542          } else {
07543             SS = SUMA_StringAppend_va(SS, "components: %d\n", dx->n_comp); 
07544          }
07545          if (dx->n_attr) {
07546             SS = SUMA_StringAppend_va(SS, "attributes: %d\n", dx->n_attr);
07547             for (i=0; i<dx->n_attr; ++i) {  
07548                if (dx->attr_name[i]) SS = SUMA_StringAppend_va(SS, "\tname: %s\t", dx->attr_name[i]);
07549                else SS = SUMA_StringAppend_va(SS, "\tname: NULL\t"); 
07550                if (dx->attr_string[i]) SS = SUMA_StringAppend_va(SS, "\tstring: %s\n", dx->attr_string[i]);
07551                else SS = SUMA_StringAppend_va(SS, "\tstring: NULL\n"); 
07552             }    
07553          } else {
07554             SS = SUMA_StringAppend_va(SS, "attributes: %d\n", dx->n_attr); 
07555          }
07556       }
07557    }
07558    
07559    SUMA_SS2S(SS,s);
07560    if (!out) fprintf(stdout, "%s", s);
07561    else fprintf(out, "%s", s);
07562    
07563    SUMA_free(s); s = NULL;
07564    
07565    SUMA_RETURNe;
07566 }

void SUMA_Show_SureFit SUMA_SureFit_struct   SF,
FILE *    Out
 

Show data structure containing SureFit surface object

Definition at line 612 of file SUMA_Surface_IO.c.

References SUMA_SureFit_struct::configuration_id, SUMA_SureFit_struct::coordframe_id, SUMA_SureFit_struct::date, SUMA_SureFit_struct::encoding_coord, SUMA_SureFit_struct::encoding_topo, SUMA_SureFit_struct::FaceSetList, SUMA_NODE_FIRST_NEIGHB::FirstNeighb, SUMA_SureFit_struct::FN, SUMA_SureFit_struct::N_FaceSet, SUMA_NODE_FIRST_NEIGHB::N_Neighb, SUMA_SureFit_struct::N_Node, SUMA_SureFit_struct::N_Node_Specs, SUMA_SureFit_struct::name_coord, SUMA_SureFit_struct::name_topo, SUMA_SureFit_struct::NodeId, SUMA_SureFit_struct::NodeList, SUMA_SureFit_struct::Specs_mat, SUMA_ENTRY, and SUMA_RETURNe.

00613 {       int cnt, id, ND, NP;
00614         static char FuncName[]={"SUMA_Show_SureFit"};
00615         
00616         SUMA_ENTRY;
00617 
00618         ND = 3;
00619         NP = 3;
00620         if (Out == NULL) Out = SUMA_STDOUT;
00621         fprintf (Out, "\n%s: Coord Info\n", SF->name_coord);
00622         fprintf (Out, "N_Node %d\n", SF->N_Node);
00623         fprintf (Out, "encoding_coord: %s\nconfiguration id: %s, coordframe_id: %s\n", SF->encoding_coord,SF->configuration_id, SF->coordframe_id);
00624         fprintf (Out, "First 2 points [id] X Y Z:\n\t[%d] %f %f %f\n\t[%d] %f %f %f\n", \
00625                 SF->NodeId[0], SF->NodeList[0], SF->NodeList[1], SF->NodeList[2],
00626                 SF->NodeId[1], SF->NodeList[3], SF->NodeList[4], SF->NodeList[5]);
00627         if (SF->N_Node > 2) {
00628       fprintf (Out, "Last 2 points [id] X Y Z:\n\t[%d] %f %f %f\n\t[%d] %f %f %f\n", \
00629                    SF->NodeId[SF->N_Node-2], SF->NodeList[ND*(SF->N_Node-2)], SF->NodeList[ND*(SF->N_Node-2)+1], SF->NodeList[ND*(SF->N_Node-2)+2],
00630                    SF->NodeId[SF->N_Node-1], SF->NodeList[ND*(SF->N_Node-1)], SF->NodeList[ND*(SF->N_Node-1)+1], SF->NodeList[ND*(SF->N_Node-1)+2]);
00631         }
00632    fprintf (Out, "\n%s: Topo Info\n", SF->name_topo);
00633         fprintf (Out, "N_Node_Specs %d\n", SF->N_Node_Specs);
00634         fprintf (Out, "ecnoding_topo: %s, date %s\n",  SF->encoding_topo, SF->date);
00635         fprintf (Out, "N_FaceSet %d\n", SF->N_FaceSet);
00636         if (SF->N_FaceSet > 2) {
00637            fprintf (Out, "First 2 polygons:\n\t%d %d %d\n\t%d %d %d\n", \
00638                    SF->FaceSetList[0], SF->FaceSetList[1], SF->FaceSetList[2],
00639                    SF->FaceSetList[3], SF->FaceSetList[4], SF->FaceSetList[5]);
00640       fprintf (Out, "Last 2 polygons:\n\t%d %d %d\n\t%d %d %d\n", \
00641                    SF->FaceSetList[NP*(SF->N_FaceSet-2)], SF->FaceSetList[NP*(SF->N_FaceSet-2) + 1], SF->FaceSetList[NP*(SF->N_FaceSet-2) + 2],
00642                    SF->FaceSetList[NP*(SF->N_FaceSet-1)], SF->FaceSetList[NP*(SF->N_FaceSet-1) + 1], SF->FaceSetList[NP*(SF->N_FaceSet-1) + 2]);
00643         } else {
00644       fprintf (Out, "First polygon:\n\t%d %d %d\n", \
00645                    SF->FaceSetList[0], SF->FaceSetList[1], SF->FaceSetList[2] );
00646    }
00647    fprintf (Out, "\nNode Specs (%d):\n", SF->N_Node_Specs);
00648         fprintf (Out, "First Entry: \t%d %d %d %d %d %d\n", \
00649         SF->Specs_mat[0][0], SF->Specs_mat[0][1],SF->Specs_mat[0][2], SF->Specs_mat[0][3],SF->Specs_mat[0][4], SF->Specs_mat[0][5]);
00650         cnt = 0;
00651         while (cnt < SF->FN.N_Neighb[0]) {
00652                 fprintf (Out, "\t%d %d\n", cnt, SF->FN.FirstNeighb[0][cnt]); 
00653                 ++cnt;
00654         }
00655         fprintf (Out, "Last Entry: \t%d %d %d %d %d %d\n", \
00656                 SF->Specs_mat[SF->N_Node_Specs-1][0], SF->Specs_mat[SF->N_Node_Specs-1][1],SF->Specs_mat[SF->N_Node_Specs-1][2],\
00657                 SF->Specs_mat[SF->N_Node_Specs-1][3],SF->Specs_mat[SF->N_Node_Specs-1][4], SF->Specs_mat[SF->N_Node_Specs-1][5]);
00658         cnt = 0;
00659         while (cnt < SF->FN.N_Neighb[SF->N_Node_Specs-1]) {
00660                 fprintf (Out, "\t%d %d\n", cnt, SF->FN.FirstNeighb[SF->N_Node_Specs-1][cnt]); 
00661                 ++cnt;
00662         }
00663 
00664         SUMA_RETURNe;
00665 }

NI_group* SUMA_SO2nimlSO SUMA_SurfaceObject   SO,
char *    optlist,
int    nlee
 

A function to change a SurfaceObject to niml format.

Parameters:
SO  (SUMA_SurfaceObject *)
optlist  (char *) string indicating what parts of SO to put in ngr choose any combination of: NodeList, FaceSetList, EdgeList, MemberFace, NodeNeighb, VolPar, facenormals, NodeNormals, PolyArea,
No_LinksExternalElements  (int) 1: Do not include IDs of elements not created inside this group, i.e. not mentioned in optlist 0: So include IDs of elements that may reside on disk.
Returns:
ngr (NI_group *) a NI group element formed from SO. NOTE: That element has the SAME ID as SO!
See also:
SUMA_nimlSO2SO

Definition at line 6825 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::AnatCorrect, SUMA_SurfaceObject::DomainGrandParentID, SUMA_SurfaceObject::EL, SUMA_SurfaceObject::EmbedDim, SUMA_SurfaceObject::facenormals_idcode_str, SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_SurfaceObject::facesetlist_idcode_str, SUMA_SurfaceObject::FileType, SUMA_SurfaceObject::FN, SUMA_SurfaceObject::Group, SUMA_SurfaceObject::Group_idcode_str, SUMA_NODE_FIRST_NEIGHB::idcode_str, SUMA_MEMBER_FACE_SETS::idcode_str, SUMA_EDGE_LIST::idcode_str, SUMA_SurfaceObject::idcode_str, SUMA_SurfaceObject::Label, SUMA_SurfaceObject::LocalDomainParentID, LocalHead, SUMA_SurfaceObject::MF, SUMA_SurfaceObject::ModelName, NEL_WRITE_TX, NI_add_to_group(), NI_free_element(), NI_new_group_element(), NI_rename_group(), NI_set_attribute(), SUMA_SurfaceObject::NodeList, SUMA_SurfaceObject::nodelist_idcode_str, SUMA_SurfaceObject::nodenormals_idcode_str, SUMA_SurfaceObject::OriginatorID, SUMA_SurfaceObject::OriginatorLabel, SUMA_SurfaceObject::parent_vol_idcode_str, SUMA_SurfaceObject::polyarea_idcode_str, SUMA_SurfaceObject::Side, SUMA_SurfaceObject::StandardSpace, SUMA_SurfaceObject::State, SUMA_Boolean, SUMA_EMPTY_ATTR, SUMA_ENTRY, SUMA_iswordin(), SUMA_LEFT, SUMA_LH, SUMA_Mesh_IJK2Mesh_IJK_nel(), SUMA_NEW_ID, SUMA_NEW_MESH_IJK, SUMA_NEW_NODE_XYZ, SUMA_NO_SIDE, SUMA_NodeXYZ2NodeXYZ_nel(), SUMA_RETURN, SUMA_RIGHT, SUMA_SL_Err, SUMA_SL_Warn, SUMA_SOVolPar2VolPar_nel(), SUMA_SURFACE_VOLUME_PARENT, SUMA_SurfaceTypeString(), and SUMA_SurfaceObject::VolPar.

Referenced by SUMA_SendSumaNewSurface().

06826 {
06827    static char FuncName[]={"SUMA_SO2nimlSO"};
06828    NI_group *ngr = NULL;
06829    NI_element *nel = NULL;
06830    char stmp[500];
06831    SUMA_Boolean LocalHead = NOPE;
06832    
06833    SUMA_ENTRY;
06834    
06835    if (!SO) { 
06836       SUMA_SL_Err("Null SO"); SUMA_RETURN(ngr);
06837    }
06838    
06839    /* create group and name it */
06840    ngr = NI_new_group_element();
06841    NI_rename_group(ngr, "SurfaceObject");
06842    
06843    /** BEGIN ATTRIBUTES COMMON TO ALL OBJECTS **/ 
06844    
06845    /* set the object type attribute */
06846    switch (SO->FaceSetDim) {
06847       case 3:
06848          NI_set_attribute(ngr, "Object_Type", "Triangulated_Surface");
06849          break;
06850       default:
06851          NI_set_attribute(ngr, "Object_Type", SUMA_EMPTY_ATTR);
06852          SUMA_SL_Warn("FaceSetDim not supported");
06853          break;
06854    }      
06855    
06856    /* set the object ID */
06857    if (SO->idcode_str) {
06858       NI_set_attribute(ngr, "Object_ID", SO->idcode_str);
06859    } else {
06860       NI_set_attribute(ngr, "Object_ID", SUMA_EMPTY_ATTR);
06861    }  
06862    
06863    /* set the object Label */
06864    if (SO->Label) {
06865       NI_set_attribute(ngr, "Object_Label", SO->Label);
06866    } else {
06867       NI_set_attribute(ngr, "Object_Label", SUMA_EMPTY_ATTR);
06868    }
06869    
06870    
06871    /* set the parent ID */
06872    if (SO->LocalDomainParentID) {
06873       NI_set_attribute(ngr, "Parent_ID", SO->LocalDomainParentID);
06874    } else {
06875       NI_set_attribute(ngr, "Parent_ID", SUMA_EMPTY_ATTR);
06876    }
06877    
06878    /* set the grand parent ID */
06879    if (SO->DomainGrandParentID) {
06880       NI_set_attribute(ngr, "Grand_Parent_ID", SO->DomainGrandParentID);
06881    } else {
06882       NI_set_attribute(ngr, "Grand_Parent_ID", SUMA_EMPTY_ATTR);
06883    }
06884    
06885    /** END ATTRIBUTES COMMON TO ALL OBJECTS **/      
06886    
06887    /** BEGIN ATTRIBUTES specific to Surfaces**/
06888    if (SO->Group_idcode_str) {
06889       NI_set_attribute(ngr, "Subject_ID", SO->Group_idcode_str);
06890    } else {
06891       NI_set_attribute(ngr, "Subject_ID", SUMA_EMPTY_ATTR);
06892    }
06893    
06894    if (SO->Group) {
06895       NI_set_attribute(ngr, "Subject_Label", SO->Group);
06896    } else {
06897       NI_set_attribute(ngr, "Subject_Label", SUMA_EMPTY_ATTR);
06898    }
06899    
06900    if (SO->OriginatorID) {
06901       NI_set_attribute(ngr, "Instance_ID", SO->OriginatorID);
06902    } else {
06903       NI_set_attribute(ngr, "Instance_ID", SUMA_EMPTY_ATTR);
06904    }
06905    
06906    if (SO->OriginatorLabel) {
06907       NI_set_attribute(ngr, "Instance_Label", SO->OriginatorLabel);
06908    } else {
06909       NI_set_attribute(ngr, "Instance_Label", SUMA_EMPTY_ATTR);
06910    }
06911    
06912    if (SO->ModelName) {
06913       NI_set_attribute(ngr, "Model_Name", SO->ModelName);
06914    } else {
06915       NI_set_attribute(ngr, "Model_Name", SUMA_EMPTY_ATTR);
06916    }
06917    
06918    switch (SO->Side) {
06919       case SUMA_NO_SIDE:
06920          NI_set_attribute(ngr, "Side", "none");
06921          break;
06922       case SUMA_LEFT:
06923          NI_set_attribute(ngr, "Side", "left");
06924          break;
06925       case SUMA_RIGHT:
06926          NI_set_attribute(ngr, "Side", "right");
06927          break;
06928       default:
06929          NI_set_attribute(ngr, "Side", SUMA_EMPTY_ATTR);
06930          break;
06931    }
06932    
06933    if (SO->State) {
06934       NI_set_attribute(ngr, "Layer_Name", SO->State);
06935    } else {
06936       NI_set_attribute(ngr, "Layer_Name", SUMA_EMPTY_ATTR);
06937    }
06938    
06939    if (SO->AnatCorrect) {
06940       NI_set_attribute(ngr, "Anatomically_Correct", "yes");
06941    } else {
06942       NI_set_attribute(ngr, "Anatomically_Correct", "no");
06943    }
06944    
06945    sprintf(stmp,"%d", SO->EmbedDim);
06946    NI_set_attribute(ngr, "Embedding_Dimension", stmp);
06947    
06948    if (SO->FileType >=0) {
06949       sprintf(stmp,"%s", SUMA_SurfaceTypeString(SO->FileType));
06950       NI_set_attribute(ngr, "Surface_Creation_Software",  stmp);
06951    } else {
06952       NI_set_attribute(ngr, "Surface_Creation_Software", SUMA_EMPTY_ATTR);
06953    }
06954    
06955    NI_set_attribute(ngr, "Surface_Creation_History", SUMA_EMPTY_ATTR); 
06956    
06957    if (SO->StandardSpace) {
06958       NI_set_attribute(ngr, "Standard_Space", SO->StandardSpace);
06959    } else {
06960       NI_set_attribute(ngr, "Standard_Space", SUMA_EMPTY_ATTR);
06961    }
06962    
06963    if (!nlee || SUMA_iswordin(optlist,"FaceSetList")) {
06964       if (SO->facesetlist_idcode_str) {
06965          NI_set_attribute(ngr, "Mesh_Element_ID", SO->facesetlist_idcode_str);
06966       } else {
06967          if (SO->idcode_str) {
06968             sprintf(stmp, "facesetlist_idcode_str_%s", SO->idcode_str);
06969             SUMA_NEW_ID(SO->facesetlist_idcode_str, stmp);
06970             NI_set_attribute(ngr, "Mesh_Element_ID", SO->facesetlist_idcode_str);
06971          } else  {
06972             NI_set_attribute(ngr, "Mesh_Element_ID", SUMA_EMPTY_ATTR);
06973          }
06974       }
06975    }
06976    
06977    if (!nlee || SUMA_iswordin(optlist,"NodeList")) {
06978       if (SO->nodelist_idcode_str) {
06979          NI_set_attribute(ngr, "NodeList_Element_ID", SO->nodelist_idcode_str);
06980       } else {
06981          if (SO->idcode_str) {
06982             sprintf(stmp, "nodelist_idcode_str_%s", SO->idcode_str);
06983             SUMA_NEW_ID(SO->nodelist_idcode_str, stmp);
06984             NI_set_attribute(ngr, "NodeList_Element_ID", SO->nodelist_idcode_str);
06985          } else  {
06986             NI_set_attribute(ngr, "NodeList_Element_ID", SUMA_EMPTY_ATTR);
06987          }
06988       }
06989    }
06990    if (!nlee || SUMA_iswordin(optlist,"facenormals")) {
06991       if (SO->facenormals_idcode_str) {
06992          NI_set_attribute(ngr, "Polygon_Normals_Element_ID", SO->facenormals_idcode_str);
06993       } else {
06994          if (SO->idcode_str) {
06995             sprintf(stmp, "facenormals_idcode_str_%s", SO->idcode_str);
06996             SUMA_NEW_ID(SO->facenormals_idcode_str, stmp);
06997             NI_set_attribute(ngr, "Polygon_Normals_Element_ID", SO->facenormals_idcode_str);
06998          } else  {
06999             NI_set_attribute(ngr, "Polygon_Normals_Element_ID", SUMA_EMPTY_ATTR);
07000          }
07001       }
07002    }
07003    
07004    if (!nlee || SUMA_iswordin(optlist,"NodeNormals")) {
07005       if (SO->nodenormals_idcode_str) {
07006          NI_set_attribute(ngr, "Node_Normals_Element_ID", SO->nodenormals_idcode_str);
07007       } else {
07008          if (SO->idcode_str) {
07009             sprintf(stmp, "nodenormals_idcode_str_%s", SO->idcode_str);
07010             SUMA_NEW_ID(SO->nodenormals_idcode_str, stmp);
07011             NI_set_attribute(ngr, "Node_Normals_Element_ID", SO->nodenormals_idcode_str);
07012          } else  {
07013             NI_set_attribute(ngr, "Node_Normals_Element_ID", SUMA_EMPTY_ATTR);
07014          }
07015       }
07016    }
07017    
07018    if (!nlee || SUMA_iswordin(optlist,"PolyArea")) {
07019       if (SO->polyarea_idcode_str) {
07020          NI_set_attribute(ngr, "Polygon_Area_Element_ID", SO->polyarea_idcode_str);
07021       } else {
07022          if (SO->idcode_str) {
07023             sprintf(stmp, "polyarea_idcode_str_%s", SO->idcode_str);
07024             SUMA_NEW_ID(SO->polyarea_idcode_str, stmp);
07025             NI_set_attribute(ngr, "Polygon_Area_Element_ID", SO->polyarea_idcode_str);
07026          } else  {
07027             NI_set_attribute(ngr, "Polygon_Area_Element_ID", SUMA_EMPTY_ATTR);
07028          }
07029       }
07030    }
07031 
07032    if (!nlee || SUMA_iswordin(optlist,"EdgeList")) {
07033       /* add here the edge list, the node neighbor list and the face neighbor list IDs*/
07034       if (SO->EL && SO->EL->idcode_str) {
07035          NI_set_attribute(ngr, "SUMA_Edge_List_Element_ID", SO->EL->idcode_str);
07036       } else {
07037          NI_set_attribute(ngr, "SUMA_Edge_List_Element_ID", SUMA_EMPTY_ATTR);
07038       }
07039    }
07040    
07041    if (!nlee || SUMA_iswordin(optlist,"MemberFace")) {
07042       if (SO->MF && SO->MF->idcode_str) {
07043          NI_set_attribute(ngr, "SUMA_Node_Face_Member_Element_ID", SO->MF->idcode_str);
07044       } else {
07045          NI_set_attribute(ngr, "SUMA_Node_Face_Member_Element_ID", SUMA_EMPTY_ATTR);
07046       }
07047    }
07048    
07049    if (!nlee || SUMA_iswordin(optlist,"NodeNeighb")) {
07050       if (SO->FN && SO->FN->idcode_str) {
07051          NI_set_attribute(ngr, "SUMA_Node_First_Neighb_Element_ID", SO->FN->idcode_str);
07052       } else {
07053          NI_set_attribute(ngr, "SUMA_Node_First_Neighb_Element_ID", SUMA_EMPTY_ATTR);
07054       }
07055    }
07056 
07057    if (!nlee) {
07058       /* add the parent volume (SurfVol, NOT SurfVol_AlndExp) IDcode if present. 
07059         That ID does not usually refer to the volume from which VolPar is created. Except in the case 
07060         where you are viewing the surfaces on the orignal volume (SurfVol) then this field and
07061         SurfVol (afni dset *) ->idcode.str and VolPar->vol_idcode_str should be identical */
07062       if (SO->parent_vol_idcode_str) {
07063          NI_set_attribute(ngr, "SUMA_Afni_Parent_Vol_ID", SO->parent_vol_idcode_str);
07064       } else {
07065          NI_set_attribute(ngr, "SUMA_Afni_Parent_Vol_ID", SUMA_EMPTY_ATTR);
07066       }
07067    }
07068    
07069    /** END ATTRIBUTES specific to Surfaces**/ 
07070    
07071    /** BEGIN Adding data elements **/
07072    
07073    /* add the node list */
07074    if (SUMA_iswordin(optlist,"NodeList")) {
07075       SUMA_LH("Adding Nodelist nel...");
07076       nel = SUMA_NodeXYZ2NodeXYZ_nel (SO, SO->NodeList, 0, SUMA_NEW_NODE_XYZ);
07077       if (!nel) { SUMA_SL_Err("Failed to create nel"); NI_free_element(ngr); SUMA_RETURN(NULL); }
07078       NI_add_to_group( ngr, nel); 
07079    }
07080    
07081    /* add the faceset list */
07082    if (SUMA_iswordin(optlist,"FaceSetList")) {
07083       SUMA_LH("Adding Nodelist nel...");
07084       nel = SUMA_Mesh_IJK2Mesh_IJK_nel (SO, SO->FaceSetList, 0, SUMA_NEW_MESH_IJK);
07085       if (!nel) { SUMA_SL_Err("Failed to create nel"); NI_free_element(ngr); SUMA_RETURN(NULL); }
07086       NI_add_to_group( ngr, nel); 
07087    }   
07088    
07089    /* add the edge list */
07090    if (SUMA_iswordin(optlist,"EdgeList")) {
07091       SUMA_LH("Adding EdgeList nel...");
07092       SUMA_SL_Warn("Option not implemented yet.");
07093       if (SO->EL) {
07094          /* if (!nel) { SUMA_SL_Err("Failed to create nel"); NI_free_element(ngr); SUMA_RETURN(NULL); } 
07095          NI_add_to_group( ngr, nel); */
07096       }
07097    }
07098    
07099    /* add the member face list */
07100    if (SUMA_iswordin(optlist,"MemberFace")) {
07101       SUMA_LH("Adding Member of FaceSet nel...");
07102       SUMA_SL_Warn("Option not implemented yet.");
07103       if (SO->MF) {
07104          /* if (!nel) { SUMA_SL_Err("Failed to create nel"); NI_free_element(ngr); SUMA_RETURN(NULL); } 
07105          NI_add_to_group( ngr, nel); */
07106       }
07107    }
07108    
07109    /* add the node neighbor list */
07110    if (SUMA_iswordin(optlist,"NodeNeighb")) {
07111       SUMA_LH("Adding node neighbors nel...");
07112       SUMA_SL_Warn("Option not implemented yet.");
07113       if (SO->FN) {
07114          /* if (!nel) { SUMA_SL_Err("Failed to create nel"); NI_free_element(ngr); SUMA_RETURN(NULL); } 
07115          NI_add_to_group( ngr, nel); */
07116       }
07117    }
07118    
07119    /* add the VolPar element */
07120    if (SUMA_iswordin(optlist,"VolPar")) {
07121       SUMA_LH("Adding VolPar nel ...");
07122       if (SO->VolPar) {
07123          nel = SUMA_SOVolPar2VolPar_nel (SO, SO->VolPar, SUMA_SURFACE_VOLUME_PARENT);
07124          if (!nel) { SUMA_SL_Err("Failed to create nel"); NI_free_element(ngr); SUMA_RETURN(NULL); } 
07125          NI_add_to_group( ngr, nel); 
07126       }
07127    }
07128    
07129    /** END Adding data elements **/ 
07130    if (1) {
07131       int suc;
07132       SUMA_SL_Warn("writing SO group to DISK!");
07133       NEL_WRITE_TX(ngr, "file:Test_SO2NIML_write_asc_1D", suc);
07134    }
07135    
07136    SUMA_RETURN(ngr);
07137 }

SUMA_Boolean SUMA_SureFit_Read_Coord char *    f_name,
SUMA_SureFit_struct   SF
 

** Function: SUMA_SureFit_Read_Coord Usage : Ret = SUMA_SureFit_Read_Coord (coordname, SureFit)

Input paramters :

Parameters:
coordname  (char *) name of .coord file
SureFit  (SUMA_SureFit_struct *) pointer to the SureFit structure
Returns :
Returns:
(SUMA_Boolean) YUP/NOPE for success/failure
Support :
See also:
, Side effects :

Definition at line 340 of file SUMA_Surface_IO.c.

References SUMA_SureFit_struct::configuration_id, SUMA_SureFit_struct::coordframe_id, SUMA_SureFit_struct::encoding_coord, SUMA_SureFit_struct::N_Node, SUMA_SureFit_struct::name_coord, SUMA_SureFit_struct::NodeId, SUMA_SureFit_struct::NodeList, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_error_message(), SUMA_filexists(), SUMA_iswordin(), and SUMA_RETURN.

Referenced by SUMA_Load_Surface_Object_eng().

00341 {/*SUMA_SureFit_Read_Coord*/
00342    static char FuncName[]={"SUMA_SureFit_Read_Coord"}; 
00343    FILE *sf_file;
00344         int ex, EndHead, FoundHead, evl, cnt, skp, ND, id;
00345         char stmp[100], head_strt[100], head_end[100], s[1000], delimstr[] = {' ', '\0'}, *st;
00346         
00347         SUMA_ENTRY;
00348         
00349         ND = 3;
00350         
00351         /* check for existence */
00352         if (!SUMA_filexists(f_name)) {
00353                 fprintf(SUMA_STDERR,"File %s does not exist or cannot be read.\n", f_name);
00354                 SUMA_RETURN (NOPE);
00355         }
00356         
00357         sprintf(SF->name_coord, "%s", f_name);
00358         
00359         /* start reading */
00360         sf_file = fopen (f_name,"r");
00361         if (sf_file == NULL)
00362                 {
00363                         SUMA_error_message (FuncName,"Could not open input file ",0);
00364                         SUMA_RETURN (NOPE);
00365                 }
00366 
00367         /* read until you reach the begin header BeginHeader */
00368         ex = 1;
00369         FoundHead = 0;
00370         sprintf(head_strt,"BeginHeader");
00371         while (ex != EOF && !FoundHead)
00372         {
00373                 ex = fscanf (sf_file,"%s",s);
00374                 if (strlen (s) >= strlen(head_strt)) 
00375                         {
00376                                 evl = SUMA_iswordin (s,head_strt);
00377                                 if (evl == 1) FoundHead = 1;
00378                         }
00379         }
00380         
00381         if (!FoundHead) {
00382                 fprintf(SUMA_STDERR,"Error %s: BeginHeader not found in %s.\nPerhaps you are using old versions of Caret/SureFit files.\n", FuncName, f_name);
00383                 SUMA_RETURN (NOPE);
00384         }
00385         EndHead = 0;
00386         sprintf(head_end,"EndHeader");
00387         sprintf(delimstr," ");
00388         
00389         while (ex != EOF && !EndHead)   {
00390                 ex = fscanf (sf_file,"%s",s);
00391                 /*fprintf(stdout,"%s\n", s);*/
00392                 if (strlen (s) >= strlen(head_end)) 
00393                         {
00394                                 evl = SUMA_iswordin (s,head_end);
00395                                 if (evl == 1) EndHead = 1;
00396                         }
00397                 /* look for some tokens */
00398                 skp = 0;
00399                 if (!EndHead) {
00400                         st = strtok(s, delimstr);
00401                         sprintf(stmp,"encoding");
00402                         if (!skp && SUMA_iswordin (st, stmp) == 1) {
00403                                 /*fprintf(stdout,"Found encoding\n");*/
00404                                 ex = fscanf (sf_file,"%s",(SF->encoding_coord));
00405                                 skp = 1;
00406                         }
00407                         
00408                         sprintf(stmp,"configuration_id");
00409                         if (!skp && SUMA_iswordin (st, stmp) == 1) {
00410                                 /*fprintf(stdout,"Found configuration_id\n");*/
00411                                 ex = fscanf (sf_file,"%s",(SF->configuration_id));
00412                                 skp = 1;
00413                         }
00414                         
00415                         sprintf(stmp,"coordframe_id");
00416                         if (!skp && SUMA_iswordin (st, stmp) == 1) {
00417                                 /*fprintf(stdout,"Found configuration_id\n");*/
00418                                 ex = fscanf (sf_file,"%s",(SF->coordframe_id));
00419                                 skp = 1;
00420                         }
00421 
00422                 }
00423         }
00424         /* Now read the Number of Nodes */
00425         fscanf(sf_file, "%d", &SF->N_Node);
00426         /*fprintf (stdout,"Expecting %d nodes.\n", SF->N_Node);*/
00427         
00428         /* allocate space */
00429         SF->NodeList = (float *)SUMA_calloc(SF->N_Node * ND, sizeof(float));
00430         SF->NodeId = (int *)SUMA_calloc (SF->N_Node, sizeof(int));
00431         
00432         if (SF->NodeList == NULL || SF->NodeId == NULL) {
00433                 fprintf(SUMA_STDERR, "Error %s: Could not allocate space for NodeList &/| NodeId.\n", FuncName);
00434                 SUMA_RETURN (NOPE);
00435         }
00436         
00437         /* Now read the nodes until the end of the file */
00438                 cnt = 0;
00439                 while (ex != EOF && cnt < SF->N_Node)   {
00440                         id = cnt * ND;
00441                         ex = fscanf (sf_file,"%d %f %f %f",&(SF->NodeId[cnt]), \
00442                                         &(SF->NodeList[id]), &(SF->NodeList[id+1]), &(SF->NodeList[id+2]));
00443                         ++cnt;
00444                 }
00445         if (cnt != SF->N_Node) {
00446                 fprintf(SUMA_STDERR, "Error %s: Expecting %d Nodes, read %d.\n", FuncName, SF->N_Node, cnt);
00447                 SUMA_RETURN (NOPE);
00448         }
00449         fclose (sf_file);
00450         SUMA_RETURN (YUP); 
00451 }/*SUMA_SureFit_Read_Coord*/

SUMA_Boolean SUMA_SureFit_Read_Topo char *    f_name,
SUMA_SureFit_struct   SF
 

Definition at line 453 of file SUMA_Surface_IO.c.

References SUMA_SureFit_struct::date, SUMA_SureFit_struct::encoding_topo, SUMA_SureFit_struct::FaceSetList, SUMA_NODE_FIRST_NEIGHB::FirstNeighb, SUMA_SureFit_struct::FN, i, SUMA_SureFit_struct::N_FaceSet, SUMA_NODE_FIRST_NEIGHB::N_Neighb, SUMA_NODE_FIRST_NEIGHB::N_Neighb_max, SUMA_NODE_FIRST_NEIGHB::N_Node, SUMA_SureFit_struct::N_Node_Specs, SUMA_SureFit_struct::name_topo, SUMA_NODE_FIRST_NEIGHB::NodeId, SUMA_SureFit_struct::perimeter_id, SUMA_SureFit_struct::Specs_mat, SUMA_allocate2D(), SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_error_message(), SUMA_filexists(), SUMA_iswordin(), SUMA_MAX_NUMBER_NODE_NEIGHB, and SUMA_RETURN.

Referenced by SUMA_Load_Surface_Object_eng().

00454 {/*SUMA_SureFit_Read_Topo*/
00455         static char FuncName[]={"SUMA_SureFit_Read_Topo"}; 
00456    FILE *sf_file;
00457         int ex, EndHead, FoundHead, evl, cnt, skp, jnk, i, ip, NP;
00458         char stmp[100], head_strt[100], head_end[100], s[1000], delimstr[] = {' ', '\0'}, *st;
00459         
00460         SUMA_ENTRY;
00461 
00462         /* check for existence */
00463         if (!SUMA_filexists(f_name)) {
00464                 fprintf(SUMA_STDERR,"File %s does not exist or cannot be read.\n", f_name);
00465                 SUMA_RETURN (NOPE);
00466         }
00467         
00468         sprintf(SF->name_topo, "%s", f_name);
00469         
00470         /* start reading */
00471         sf_file = fopen (f_name,"r");
00472         if (sf_file == NULL)
00473                 {
00474                         SUMA_error_message (FuncName,"Could not open input file ",0);
00475                         SUMA_RETURN (NOPE);
00476                 }
00477 
00478         /* read until you reach the begin header BeginHeader */
00479         ex = 1;
00480         FoundHead = 0;
00481         sprintf(head_strt,"BeginHeader");
00482         while (ex != EOF && !FoundHead)
00483         {
00484                 ex = fscanf (sf_file,"%s",s);
00485                 if (strlen (s) >= strlen(head_strt)) 
00486                         {
00487                                 evl = SUMA_iswordin (s,head_strt);
00488                                 if (evl == 1) FoundHead = 1;
00489                         }
00490         }
00491         if (!FoundHead) {
00492                 fprintf(SUMA_STDERR,"Error %s: BeginHeader not found in %s.\nPerhaps you are using old versions of Caret/SureFit files.\n", FuncName, f_name);
00493                 SUMA_RETURN (NOPE);
00494         }
00495         EndHead = 0;
00496         sprintf(head_end,"EndHeader");
00497         sprintf(delimstr," ");
00498         
00499         while (ex != EOF && !EndHead)   {
00500                 ex = fscanf (sf_file,"%s",s);
00501                 /*fprintf(stdout,"%s\n", s);*/
00502                 if (strlen (s) >= strlen(head_end)) 
00503                         {
00504                                 evl = SUMA_iswordin (s,head_end);
00505                                 if (evl == 1) EndHead = 1;
00506                         }
00507                 /* look for some tokens */
00508                 skp = 0;
00509                 if (!EndHead) {
00510                         st = strtok(s, delimstr);
00511                         sprintf(stmp,"encoding");
00512                         if (!skp && SUMA_iswordin (st, stmp) == 1) {
00513                                 /*fprintf(stdout,"Found encoding\n");*/
00514                                 ex = fscanf (sf_file,"%s",(SF->encoding_topo));
00515                                 skp = 1;
00516                         }
00517                         
00518                         sprintf(stmp,"perimeter_id");
00519                         if (!skp && SUMA_iswordin (st, stmp) == 1) {
00520                                 /*fprintf(stdout,"Found perimeter_id\n");*/
00521                                 ex = fscanf (sf_file,"%s",(SF->perimeter_id));
00522                                 skp = 1;
00523                         }
00524                         
00525                         sprintf(stmp,"date");
00526                         if (!skp && SUMA_iswordin (st, stmp) == 1) {
00527                                 /*fprintf(stdout,"Found date\n");*/
00528                                 ex = fscanf (sf_file,"%s\n",(SF->date));
00529                                 skp = 1;
00530                         }
00531 
00532                 }
00533         }
00534         /* Now read the Number of Nodes Specs */
00535         fscanf(sf_file, "%d", &SF->N_Node_Specs);
00536         /*fprintf (stdout,"Expecting %d Node_Specs.\n", SF->N_Node_Specs);*/
00537         
00538         SF->FN.N_Node = SF->N_Node_Specs;
00539         SF->FN.N_Neighb_max = 0;
00540 
00541         /* allocate for Node Specs Matrix and First_Neighb structure*/
00542         SF->Specs_mat = (int **) SUMA_allocate2D(SF->N_Node_Specs, 6, sizeof(int));
00543         /*assume maximum number of neighbors is SUMA_MAX_NUMBER_NODE_NEIGHB */
00544         SF->FN.FirstNeighb = (int **) SUMA_allocate2D(SF->FN.N_Node, SUMA_MAX_NUMBER_NODE_NEIGHB, sizeof (int));
00545         SF->FN.N_Neighb = (int *) SUMA_calloc (SF->FN.N_Node, sizeof(int));
00546         SF->FN.NodeId = (int *) SUMA_calloc (SF->FN.N_Node, sizeof(int));
00547         
00548         if (SF->Specs_mat == NULL || SF->FN.FirstNeighb == NULL || SF->FN.N_Neighb == NULL || SF->FN.NodeId == NULL ){
00549                 fprintf(SUMA_STDERR, "Error %s: Could not allocate space for SF->Specs_mat &/| SF->FN.FirstNeighb &/| SF->FN.N_Neighb &/| SF->FN.NodeId.\n", FuncName);
00550                 SUMA_RETURN (NOPE);
00551         } 
00552         
00553         /* Now read the node specs */
00554         /*fprintf (stdout,"About to read specs\n");*/
00555         cnt = 0;
00556         while (ex != EOF && cnt < SF->N_Node_Specs)     {
00557                 ex = fscanf (sf_file,"%d %d %d %d %d %d",&(SF->Specs_mat[cnt][0]), &(SF->Specs_mat[cnt][1]), \
00558                                 &(SF->Specs_mat[cnt][2]), &(SF->Specs_mat[cnt][3]), &(SF->Specs_mat[cnt][4]), &(SF->Specs_mat[cnt][5]));
00559                 SF->FN.NodeId[cnt] = SF->Specs_mat[cnt][0];
00560                 SF->FN.N_Neighb[cnt] = SF->Specs_mat[cnt][1];
00561                 if (SF->FN.N_Neighb[cnt] > SUMA_MAX_NUMBER_NODE_NEIGHB-1) {
00562                         fprintf (SUMA_STDERR,"Error %s: Node %d has more neighbors (%d) than the maximum allowed (%d)\n", \
00563                                 FuncName, SF->FN.NodeId[cnt], SF->FN.N_Neighb[cnt], SUMA_MAX_NUMBER_NODE_NEIGHB-1);
00564                         SUMA_RETURN (NOPE);
00565                 }
00566                 if (SF->FN.N_Neighb[cnt] > SF->FN.N_Neighb_max) SF->FN.N_Neighb_max = SF->FN.N_Neighb[cnt];
00567                 
00568                 /* Now Read in the Neighbors info */
00569                 for (i=0; i < SF->FN.N_Neighb[cnt]; ++ i) {
00570                         ex = fscanf (sf_file,"%d %d", &jnk, &(SF->FN.FirstNeighb[cnt][i]));
00571                 }
00572                 /* seal with -1 */
00573                 SF->FN.FirstNeighb[cnt][SF->FN.N_Neighb[cnt]] = -1;
00574                 
00575                 ++cnt;
00576         }
00577         if (cnt != SF->N_Node_Specs) {
00578                 fprintf(SUMA_STDERR, "Error %s: Expecting %d NodeSpecs, read %d.\n", FuncName, SF->N_Node_Specs, cnt);
00579                 SUMA_RETURN (NOPE);
00580         }
00581         /*fprintf (stdout, "Done with Node Specs.\n");*/
00582         ex = fscanf (sf_file,"%d", &(SF->N_FaceSet));
00583         /*fprintf (stdout, "Expecting to read %d facesets.\n", SF->N_FaceSet);*/
00584         
00585         NP = 3;
00586         SF->FaceSetList = (int *) SUMA_calloc(SF->N_FaceSet * 3, sizeof(int));
00587         if (SF->FaceSetList == NULL){
00588                 fprintf(SUMA_STDERR, "Error %s: Could not allocate space for SF->FaceSetList.\n", FuncName);
00589                 SUMA_RETURN (NOPE);
00590         } 
00591         
00592         /*fprintf (stdout,"About to read FaceSets\n");*/
00593         cnt = 0;
00594         while (ex != EOF && cnt < SF->N_FaceSet)        {
00595                 ip = NP * cnt;
00596                 ex = fscanf (sf_file,"%d %d %d ",&(SF->FaceSetList[ip]), &(SF->FaceSetList[ip+1]), \
00597                                 &(SF->FaceSetList[ip+2]));
00598                 ++cnt;
00599         }
00600         if (cnt != SF->N_FaceSet) {
00601                 fprintf(SUMA_STDERR, "Error %s: Expecting %d FaceSets, read %d.\n", FuncName, SF->N_FaceSet, cnt);
00602                 SUMA_RETURN (NOPE);
00603         }
00604         fclose (sf_file);
00605         
00606 SUMA_RETURN (YUP);
00607 }/*SUMA_SureFit_Read_Topo*/

SUMA_Boolean SUMA_SureFit_Write SUMA_SFname   Fname,
SUMA_SurfaceObject   SO
 

writes a surface in SureFit format ans = SUMA_SureFit_Write (Fname,SO);

Parameters:
Fname  (SUMA_SFname *) uses the SureFit filename structure to store the names (and paths) of the NodeList (name_coord) and the FaceSetList (name_topo) files. If strlen(name_coord) == 0 then the coord file is not written out. If strlen(name_topo) == 0 then topo file is not written out
SO  (SUMA_SurfaceObject *) pointer to SO structure.
Returns:
YUP/NOPE
See also:
SUMA_SureFit_Read_Topo() , SUMA_SureFit_Read_Coord()
The function will not overwrite pre-existing files.

NOTE: Header info is incomplete. for .coord: BeginHeader configuration_id NA coordframe_id NA encoding ASCII EndHeader

for .topo: BeginHeader date NA encoding ASCII perimeter_id NA EndHeader

also, the last 4 integers in the node neighbor list lines are set to 0. I have never used them and do not know what they are for.

The naming convention of SureFit surfaces is not enforced.

Definition at line 706 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::EL, SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, SUMA_NODE_FIRST_NEIGHB::FirstNeighb, SUMA_SurfaceObject::FN, i, SUMA_SurfaceObject::N_FaceSet, SUMA_NODE_FIRST_NEIGHB::N_Neighb, SUMA_NODE_FIRST_NEIGHB::N_Node, SUMA_SurfaceObject::N_Node, SUMA_SFname::name_coord, SUMA_SFname::name_topo, SUMA_SurfaceObject::NodeDim, SUMA_NODE_FIRST_NEIGHB::NodeId, SUMA_SurfaceObject::NodeList, SUMA_Boolean, SUMA_Build_FirstNeighb(), SUMA_ENTRY, SUMA_filexists(), SUMA_Make_Edge_List(), SUMA_RETURN, and SUMA_SurfaceMetrics().

Referenced by SUMA_Save_Surface_Object().

00707 {
00708    
00709    static char FuncName[]={"SUMA_SureFit_Write"};
00710    int i, j;
00711    FILE *outFile = NULL;
00712    
00713    SUMA_ENTRY;
00714 
00715    if (strlen(Fname->name_coord)) {
00716       if (SUMA_filexists(Fname->name_coord)) {
00717          fprintf (SUMA_STDERR, "Error %s: file %s exists, will not overwrite.\n",FuncName, Fname->name_coord);
00718          SUMA_RETURN (NOPE);
00719       }
00720    }
00721    
00722    if (strlen(Fname->name_topo)) {
00723       if (SUMA_filexists(Fname->name_topo)) {
00724          fprintf (SUMA_STDERR, "Error %s: file %s exists, will not overwrite.\n",FuncName, Fname->name_topo);
00725          SUMA_RETURN (NOPE);
00726       }
00727    }
00728    
00729    if (SO->NodeDim != 3 || SO->FaceSetDim != 3) {
00730       fprintf (SUMA_STDERR, "Error %s: Must have NodeDim and FaceSetDim = 3.\n",FuncName);
00731       SUMA_RETURN (NOPE);
00732    }
00733    
00734    if (strlen(Fname->name_coord)) {
00735       outFile = fopen(Fname->name_coord, "w");
00736       if (!outFile) {
00737          fprintf (SUMA_STDERR, "Error %s: Failed in opening %s for writing.\n",FuncName, Fname->name_coord);
00738          SUMA_RETURN (NOPE);
00739       }
00740 
00741       /* write header */
00742       fprintf (outFile,"BeginHeader\nconfiguration_id NA\ncoordframe_id NA\nencoding ASCII\nEndHeader\n");
00743       fprintf (outFile,"%d\n", SO->N_Node);
00744 
00745       j=0;
00746       for (i=0; i<SO->N_Node; ++i) {
00747          j=SO->NodeDim * i;
00748          fprintf (outFile, "%d %f %f %f\n", i, SO->NodeList[j], SO->NodeList[j+1], SO->NodeList[j+2]);
00749       }
00750 
00751       fclose (outFile);
00752    }
00753    
00754    if (strlen(Fname->name_topo)) {
00755       outFile = fopen(Fname->name_topo, "w");
00756       if (!outFile) {
00757          fprintf (SUMA_STDERR, "Error %s: Failed in opening %s for writing.\n",FuncName, Fname->name_topo);
00758          SUMA_RETURN (NOPE);
00759       }
00760 
00761       /* make sure you have the first neighbor list ! */
00762       if (!SO->FN) {
00763          fprintf (SUMA_STDERR, "%s: Must compute Node Neighborhood list.\n", FuncName);
00764          if (!SUMA_SurfaceMetrics(SO, "EdgeList", NULL)){
00765             fprintf (SUMA_STDERR, "Error %s: Failed in SUMA_SurfaceMetrics.\n", FuncName);
00766             SUMA_RETURN (NOPE);
00767          }
00768          #if 0 /* better to use SUMA_SurfaceMetrics */
00769          if (!SO->EL) {
00770             fprintf (SUMA_STDERR, "%s: Computing Edge List...\n", FuncName);
00771             SO->EL = SUMA_Make_Edge_List (SO->FaceSetList, SO->N_FaceSet, SO->N_Node, SO->NodeList);
00772          }
00773          if (!SO->EL) {
00774             fprintf (SUMA_STDERR, "Error %s: Failed in SUMA_Make_Edge_List.\n", FuncName);
00775             SUMA_RETURN (NOPE);
00776          }
00777          fprintf (SUMA_STDERR, "%s: Computing FirstNeighb list.\n", FuncName);
00778          SO->FN = SUMA_Build_FirstNeighb (SO->EL, SO->N_Node);
00779          if (!SO->FN) {
00780             fprintf (SUMA_STDERR, "Error %s: Failed in SUMA_Build_FirstNeighb.\n", FuncName);
00781             SUMA_RETURN (NOPE);
00782          }
00783          #endif
00784 
00785       }
00786       /* write header */
00787       fprintf (outFile,"BeginHeader\ndate NA\nencoding ASCII\nperimeter_id NA\nEndHeader\n");
00788       fprintf (outFile,"%d\n", SO->N_Node);
00789            j = 0;
00790            while (j < SO->FN->N_Node)   {
00791          /* dunno what last 4 ints of upcoming line are */
00792                    fprintf (outFile,"%d %d 0 0 0 0\n", SO->FN->NodeId[j], SO->FN->N_Neighb[j]);
00793 
00794                    /* Now write the Neighbors info */
00795                    for (i=0; i < SO->FN->N_Neighb[j]; ++ i) {
00796                            fprintf (outFile,"%d %d\n", i, SO->FN->FirstNeighb[j][i]);
00797                    }
00798                    ++j;
00799            }
00800 
00801            fprintf (outFile,"%d\n", SO->N_FaceSet);
00802 
00803       j=0;
00804       for (i=0; i<SO->N_FaceSet; ++i) {
00805          j = SO->FaceSetDim * i;
00806          fprintf (outFile, "%d %d %d\n", SO->FaceSetList[j], SO->FaceSetList[j+1], SO->FaceSetList[j+2]);
00807       }
00808 
00809       fclose (outFile);
00810    }
00811    SUMA_RETURN (YUP);
00812 
00813 }

SUMA_Boolean SUMA_VEC_Read SUMA_SFname   Fname,
SUMA_SurfaceObject   SO
 

function to read 1D (vec) format surfaces

See also:
SUMA_VEC_Write

Definition at line 3292 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, far, LocalHead, MRI_FLOAT_PTR, mri_free(), mri_read_1D(), SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SFname::name_coord, SUMA_SFname::name_topo, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, MRI_IMAGE::nx, MRI_IMAGE::ny, SUMA_Boolean, SUMA_calloc, SUMA_ENTRY, SUMA_free, SUMA_RETURN, SUMA_SL_Err, and SUMA_SLP_Err.

Referenced by SUMA_Load_Surface_Object_eng().

03293 {
03294    static char FuncName[]={"SUMA_VEC_Read"};
03295    MRI_IMAGE *im = NULL;
03296    float *far=NULL;
03297    int icnt;
03298    SUMA_Boolean LocalHead = NOPE;
03299    
03300    SUMA_ENTRY;
03301 
03302    if (!SO || !Fname) {
03303       SUMA_SL_Err("NULL input");
03304       SUMA_RETURN(NOPE);
03305    }
03306    if (SO->NodeList || SO->FaceSetList) {
03307       SUMA_SL_Err("Non NULL SO->NodeList || SO->FaceSetList");
03308       SUMA_RETURN(NOPE);   
03309    }
03310 
03311    im = mri_read_1D (Fname->name_coord);
03312    if (!im) {
03313       SUMA_SLP_Err("Failed to read 1D file");
03314       SUMA_RETURN(NOPE);
03315    }
03316    far = MRI_FLOAT_PTR(im);
03317    SO->N_Node = im->nx;
03318    SO->NodeDim = im->ny;
03319    if (!SO->N_Node) {
03320       SUMA_SL_Err("Empty file");
03321       SUMA_RETURN(NOPE);
03322    }
03323    if (SO->NodeDim !=  3 ) {
03324       SUMA_SL_Err("File must have\n"
03325                   "3 columns.");
03326       mri_free(im); im = NULL;   /* done with that baby */
03327       SUMA_RETURN(NOPE);
03328    }
03329 
03330    SO->NodeList = (float *)SUMA_calloc (SO->N_Node*SO->NodeDim, sizeof(float));
03331    if (!SO->NodeList) {
03332       fprintf(SUMA_STDERR,"Error %s: Failed to allocate for NodeList.\n", FuncName);
03333       if (SO->NodeList) SUMA_free(SO->NodeList);
03334       if (SO->FaceSetList) SUMA_free(SO->FaceSetList);
03335       SUMA_RETURN (NOPE);
03336    }
03337 
03338    for (icnt=0; icnt < SO->N_Node; ++icnt) {
03339       SO->NodeList[3*icnt] = far[icnt];
03340       SO->NodeList[3*icnt+1] = far[icnt+SO->N_Node];
03341       SO->NodeList[3*icnt+2] = far[icnt+2*SO->N_Node];
03342    }   
03343    if (LocalHead) {
03344       fprintf (SUMA_STDERR,"%s: SO->NodeList\n Node 0: %f, %f, %f \n Node %d: %f, %f, %f \n",
03345          FuncName,
03346          SO->NodeList[0], SO->NodeList[1], SO->NodeList[2], SO->N_Node -1, 
03347          SO->NodeList[3*(SO->N_Node-1)], SO->NodeList[3*(SO->N_Node-1)+1], SO->NodeList[3*(SO->N_Node-1)+2]);
03348    }
03349    mri_free(im); im = NULL;
03350 
03351    im = mri_read_1D (Fname->name_topo);
03352    if (!im) {
03353       SUMA_SL_Err("Failed to read 1D file");
03354       SUMA_RETURN(NOPE);
03355    }
03356    far = MRI_FLOAT_PTR(im);
03357    SO->N_FaceSet = im->nx;
03358    SO->FaceSetDim = im->ny;
03359    if (!SO->N_FaceSet) {
03360       SUMA_SL_Err("Empty file");
03361       SUMA_RETURN(NOPE);
03362    }
03363    if (SO->FaceSetDim !=  3 ) {
03364       SUMA_SL_Err("File must have\n"
03365                   "3 columns.");
03366       mri_free(im); im = NULL;   /* done with that baby */
03367       SUMA_RETURN(NOPE);
03368    }
03369 
03370    SO->FaceSetList = (int *)SUMA_calloc (SO->N_FaceSet*SO->FaceSetDim, sizeof(int));
03371    if (!SO->FaceSetList) {
03372       fprintf(SUMA_STDERR,"Error %s: Failed to allocate for FaceSetList.\n", FuncName);
03373       if (SO->NodeList) SUMA_free(SO->NodeList);
03374       if (SO->FaceSetList) SUMA_free(SO->FaceSetList);
03375       SUMA_RETURN (NOPE);
03376    }
03377 
03378    for (icnt=0; icnt < SO->N_FaceSet; ++icnt) {
03379       SO->FaceSetList[3*icnt] = (int)far[icnt];
03380       SO->FaceSetList[3*icnt+1] = (int)far[icnt+SO->N_FaceSet];
03381       SO->FaceSetList[3*icnt+2] = (int)far[icnt+2*SO->N_FaceSet];
03382    }   
03383 
03384    if (LocalHead) {
03385       fprintf (SUMA_STDERR,"%s: SO->FaceSetList\n Node 0: %d, %d, %d \n Node %d: %d, %d, %d \n",
03386          FuncName,
03387          SO->FaceSetList[0], SO->FaceSetList[1], SO->FaceSetList[2], SO->N_FaceSet -1, 
03388          SO->FaceSetList[3*(SO->N_FaceSet-1)], SO->FaceSetList[3*(SO->N_FaceSet-1)+1], SO->FaceSetList[3*(SO->N_FaceSet-1)+2]);
03389    } 
03390    mri_free(im); im = NULL;
03391 
03392    SUMA_RETURN(YUP);
03393 }

SUMA_Boolean SUMA_VEC_Write SUMA_SFname   Fname,
SUMA_SurfaceObject   SO
 

writes the NodeList and FaceSetList of SO to 2 ascii files ans = SUMA_Boolean SUMA_VEC_Write (SUMA_SFname *Fname, SUMA_SurfaceObject *SO);

Parameters:
Fname  (SUMA_SFname *) uses the SureFit filename structure to store the names (and paths) of the NodeList (name_coord) and the FaceSetList (name_topo) files. if (strlen(name_coord) == 0) no coord is written if (strlen(name_topo) == 0) no topo is written
SO  (SUMA_SurfaceObject *) pointer to SO structure.
Returns:
YUP/NOPE
See also:
SUMA_VEC_Read The function will not overwrite pre-existing files.

Definition at line 3227 of file SUMA_Surface_IO.c.

References SUMA_SurfaceObject::FaceSetDim, SUMA_SurfaceObject::FaceSetList, i, SUMA_SurfaceObject::N_FaceSet, SUMA_SurfaceObject::N_Node, SUMA_SFname::name_coord, SUMA_SFname::name_topo, SUMA_SurfaceObject::NodeDim, SUMA_SurfaceObject::NodeList, SUMA_Boolean, SUMA_ENTRY, SUMA_filexists(), and SUMA_RETURN.

Referenced by SUMA_Save_Surface_Object().

03228 {
03229    
03230    static char FuncName[]={"SUMA_VEC_Write"};
03231    int i, j;
03232    FILE *outFile = NULL;
03233    
03234    SUMA_ENTRY;
03235 
03236    if (strlen(Fname->name_coord)) {
03237       if (SUMA_filexists(Fname->name_coord)) {
03238          fprintf (SUMA_STDERR, "Error %s: file %s exists, will not overwrite.\n",FuncName, Fname->name_coord);
03239          SUMA_RETURN (NOPE);
03240       }
03241    }
03242    if (strlen(Fname->name_topo)) {
03243       if (SUMA_filexists(Fname->name_topo)) {
03244          fprintf (SUMA_STDERR, "Error %s: file %s exists, will not overwrite.\n",FuncName, Fname->name_topo);
03245          SUMA_RETURN (NOPE);
03246       }
03247    }
03248    if (SO->NodeDim != 3 || SO->FaceSetDim != 3) {
03249       fprintf (SUMA_STDERR, "Error %s: Must have NodeDim and FaceSetDim = 3.\n",FuncName);
03250       SUMA_RETURN (NOPE);
03251    }
03252    
03253    if (strlen(Fname->name_coord)) {
03254       outFile = fopen(Fname->name_coord, "w");
03255       if (!outFile) {
03256          fprintf (SUMA_STDERR, "Error %s: Failed in opening %s for writing.\n",FuncName, Fname->name_coord);
03257          SUMA_RETURN (NOPE);
03258       }
03259 
03260       j=0;
03261       for (i=0; i<SO->N_Node; ++i) {
03262          j=SO->NodeDim * i;
03263          fprintf (outFile, "%f  %f  %f \n", SO->NodeList[j], SO->NodeList[j+1], SO->NodeList[j+2]);
03264       }
03265 
03266       fclose (outFile);
03267    }
03268    
03269    if (strlen(Fname->name_topo)) {   
03270       outFile = fopen(Fname->name_topo, "w");
03271       if (!outFile) {
03272          fprintf (SUMA_STDERR, "Error %s: Failed in opening %s for writing.\n",FuncName, Fname->name_topo);
03273          SUMA_RETURN (NOPE);
03274       }
03275       j=0;
03276       for (i=0; i<SO->N_FaceSet; ++i) {
03277          j = SO->FaceSetDim * i;
03278          fprintf (outFile, "%d %d %d\n", SO->FaceSetList[j], SO->FaceSetList[j+1], SO->FaceSetList[j+2]);
03279       }
03280 
03281       fclose (outFile);
03282    }
03283    
03284    SUMA_RETURN (YUP);
03285 
03286 }

SUMA_Boolean SUMA_Write_DrawnROI_1D SUMA_DRAWN_ROI **    ROIv,
int    N_ROI,
char *    filename
 

writes a vector of SUMA_DRAWN_ROI * to disk in afni's 1D ascii format

Definition at line 6312 of file SUMA_Surface_IO.c.

References fout, i, SUMA_1D_DRAWN_ROI::idcode_str, SUMA_1D_DRAWN_ROI::iLabel, SUMA_1D_DRAWN_ROI::iNode, SUMA_1D_DRAWN_ROI::Label, LocalHead, SUMA_1D_DRAWN_ROI::N, SUMA_1D_DRAWN_ROI::Parent_idcode_str, SUMA_Boolean, SUMA_DrawnROI_to_1DDrawROI(), SUMA_Dset_Type_Name(), SUMA_ENTRY, SUMA_Extension(), SUMA_free, SUMA_Free_1DDrawROI(), SUMA_LH, SUMA_NODE_ROI, SUMA_RETURN, and SUMA_SL_Err.

Referenced by SUMA_SaveDrawnROI_1D().

06313 {
06314    static char FuncName[]={"SUMA_Write_DrawnROI_1D"};
06315    char *newname=NULL;
06316    int i,j;
06317    SUMA_1D_DRAWN_ROI *ROI_1D = NULL;
06318    SUMA_DRAWN_ROI *ROI = NULL;
06319    FILE *fout=NULL;
06320    SUMA_Boolean LocalHead = NOPE;
06321 
06322    SUMA_ENTRY;
06323 
06324    /* add a .1D.roi extension */
06325    newname = SUMA_Extension(filename, ".1D.roi", NOPE); 
06326    if (!newname) {
06327       SUMA_SL_Err("Invalid filename");
06328       SUMA_RETURN(NOPE);
06329    }
06330    
06331    SUMA_LH(newname);
06332 
06333    fout = fopen(newname,"w");
06334    if (!fout) {
06335       SUMA_SL_Err("Failed to open file for writing.");
06336       SUMA_RETURN(NOPE);
06337    }
06338 
06339    /* write the various ROIs */
06340    for (i=0; i < N_ROI; ++i) {
06341       ROI = ROIv[i];
06342       if (!ROI) {
06343          SUMA_SL_Err("NULL ROI!");
06344          fclose(fout);
06345          SUMA_RETURN(NOPE);
06346       }
06347       /* Transform the ROI to niml friendly structure */
06348       if (!(ROI_1D = SUMA_DrawnROI_to_1DDrawROI (ROI))) {
06349          SUMA_SL_Err("NULL niml_ROI!");
06350          fclose(fout);
06351          SUMA_RETURN(NOPE);
06352       }
06353 
06354       /* write it out in a NIML friendly format */
06355       /* begin with attributes */
06356       fprintf (fout,"# %s\n", SUMA_Dset_Type_Name(SUMA_NODE_ROI));
06357       fprintf (fout,"#  ni_type = \"SUMA_1D_ROI_DATUMorint,int?\"\n");
06358       fprintf (fout,"#  ni_dimen = \"%d\"\n",  ROI_1D->N);
06359       fprintf (fout,"#  ni_datasize = \"???\"\n");
06360       fprintf (fout,"#  idcode_str = \"%s\"\n", ROI_1D->idcode_str);
06361       fprintf (fout,"#  Parent_idcode_str = \"%s\"\n", ROI_1D->Parent_idcode_str);
06362       fprintf (fout,"#  Label = \"%s\"\n", ROI_1D->Label);
06363       fprintf (fout,"# >\n");
06364       for (j=0; j < ROI_1D->N; ++j) 
06365          fprintf (fout," %d %d\n", ROI_1D->iNode[j], ROI_1D->iLabel[j]);
06366       fprintf (fout,"# </%s>\n", SUMA_Dset_Type_Name(SUMA_NODE_ROI));
06367       fprintf (fout,"\n");
06368        
06369       /* free the ROI_1D structure */
06370       ROI_1D = SUMA_Free_1DDrawROI (ROI_1D); ROI_1D = NULL;
06371    }
06372    
06373    fclose(fout) ; 
06374    if (newname) SUMA_free(newname);
06375    
06376    SUMA_RETURN(YUP);
06377 }
 

Powered by Plone

This site conforms to the following standards: