Doxygen Source Code Documentation
SUMA_IV_XYZextract.c File Reference
#include "SUMA_suma.h"
Go to the source code of this file.
Functions | |
float * | SUMA_IV_XYZextract (char *IV_filename, int *N_NodeList, int IncludeIndex) |
Variables | |
SUMA_CommonFields * | SUMAg_CF |
Function Documentation
|
File :Taken from IV_XYZextract.c Author : Ziad Saad Date : Tue Nov 17 19:02:16 CST 1998 Purpose : Extracts the XYZ coordinates of the nodes in an IV file so that we can manipulate the data to our liking. The program looks for a sequence of characters that seem to indicate the start of the XYZ list. Once the sequence is found, the series of triplets is read and written out either to a file or to the screen. The sequence of triplets must be terminated by an ending sequence. The starting and ending sequences are hard coded into the program. The program outputs an error message if : If the starting or ending sequences are not found If the number of points read is not a multiple of three If the first number of the first XYZ triplet and the last character in the starting sequence are not spearated by a space (or tab). You can fix this by manually adding a space. Input paramters : IV_filename (char *) a string specifying the name of the inventor file N_NodeList (int *) will give the number of nodes in NodeList / 3 or /4 Include_Index (int) (0/1) controls the output of the function, see ahead for info Usage : NodeList = SUMA_IV_XYZextract (char *IV_filename, int *N_NodeList, int Include_Index) Returns : NodeList (float *) an Mx3 (or Mx4) vector containing the X Y Z coordinates of each node (with Include_Index = 0) or NodeIndex X Y Z coordinates of each node (with Include_Index = 1) entries on one line are separated by a tab. Support : Side effects : Definition at line 70 of file SUMA_IV_XYZextract.c. References free, i, SUMA_alloc_problem(), SUMA_calloc, SUMA_ENTRY, SUMA_error_message(), SUMA_iswordin(), SUMA_malloc, SUMA_realloc, and SUMA_RETURN. Referenced by SUMA_Load_Surface_Object_eng().
00071 {/* SUMA_IV_XYZextract */ 00072 static char FuncName[]={"SUMA_IV_XYZextract"}; 00073 char s[500],serr[500]; 00074 char seq_strt[5][30], seq_end[5][30]; 00075 float f, *linv, *NodeList; 00076 int i, ex, si, si_exit, evl, se, se_exit, cnt, cntlim,i3, i4; 00077 int nospacing, MaxAlloc = 100; 00078 div_t cnt3; 00079 FILE*iv_file; 00080 00081 SUMA_ENTRY; 00082 00083 /* intialize the number of points read to 0 */ 00084 *N_NodeList = 0; 00085 00086 linv = (float *)SUMA_malloc (MaxAlloc*sizeof(float)); 00087 if (!linv) 00088 { 00089 SUMA_alloc_problem ("Allocation error in SUMA_IV-XYZExtract"); 00090 SUMA_RETURN (NULL); 00091 } 00092 00093 /*This is the sequence to trigger reading the numbers*/ 00094 sprintf (seq_strt[0],"Coordinate3"); 00095 sprintf (seq_strt[1],"{"); 00096 sprintf (seq_strt[2],"point"); 00097 sprintf (seq_strt[3],"["); 00098 00099 si_exit = 4; /* set equal to the number of strings to be matched */ 00100 00101 /*This is a sequence to mark the end of the number list*/ 00102 sprintf (seq_end[0],"]"); 00103 sprintf (seq_end[1],"}"); /* no need to find closing Coordinate element, perhaps other properties are defined.*/ 00104 00105 se_exit = 1; /* set equal to the number of strings to be matched */ 00106 00107 iv_file = fopen (IV_filename,"r"); 00108 if (iv_file == NULL) 00109 { 00110 SUMA_error_message ("SUMA_IV_XYZextract","Could not open input file ",1); 00111 exit (1); 00112 } 00113 00114 00115 si = 0; 00116 ex = 1; 00117 cnt = 0; 00118 00119 nospacing = 0; /* this flag is used to when the last number is read and it has the first seq_end*/ 00120 /* character attached to it, ie no space ! in between*/ 00121 while (ex != EOF && si < si_exit) 00122 { 00123 ex = fscanf (iv_file,"%s",s); 00124 00125 /*evl = equal_strings (s,seq_strt[si]);*/ 00126 00127 if (strlen (seq_strt[si]) >= strlen (s)) 00128 { 00129 evl = SUMA_iswordin (seq_strt[si],s); 00130 if (evl == 1) 00131 nospacing = 0; /* There is a space between character in starting sequence and first number*/ 00132 } 00133 else 00134 { 00135 evl = SUMA_iswordin (s,seq_strt[si]); 00136 if (evl == 1) 00137 nospacing = 1; 00138 } 00139 00140 switch (evl) 00141 { 00142 case 0: 00143 si = 0; /* No match, reset the sequence counter */ 00144 break; 00145 case 1: 00146 if (nospacing == 1 && si == si_exit-1) /* it has to be the last character in the sequence*/ 00147 { 00148 sprintf (serr,"Must have a space character between first number and last character in start sequence ( %s )",s); 00149 SUMA_error_message ("SUMA_IV_XYZextract",serr,1); 00150 exit (1); 00151 00152 } 00153 si = si +1; /* increment the start sequence counter */ 00154 #ifdef DEBUG_3 00155 printf ("found %s --- si = %d\n",s,si); 00156 #endif 00157 break; 00158 default: 00159 break; 00160 } 00161 } 00162 00163 /* Now, read the series of numbers until you encounter the first string of the ending sequence*/ 00164 se = 0; 00165 nospacing = 0; 00166 00167 while (ex != EOF && se < se_exit ) 00168 { 00169 ex = fscanf (iv_file,"%s",s); 00170 /*evl = equal_strings (s,seq_end[se]);*/ 00171 00172 if (strlen (seq_end[se]) >= strlen (s)) 00173 { 00174 evl = SUMA_iswordin (seq_end[se],s); 00175 if (evl == 1) 00176 nospacing = 0; /* There is a space between last number and fisrt character in ending sequence */ 00177 } 00178 else 00179 { 00180 evl = SUMA_iswordin (s,seq_end[se]); 00181 if (evl == 1) 00182 nospacing = 1; 00183 } 00184 00185 switch (evl) 00186 { 00187 case 0: 00188 f = atof (s); 00189 linv[cnt] = f; 00190 #ifdef DEBUG_3 00191 printf ("\nNumber (%d): %d is appended to end sequence !\n",cnt,linv[cnt]); 00192 #endif 00193 00194 00195 ++cnt; 00196 00197 if (cnt >= MaxAlloc - 1) 00198 { 00199 MaxAlloc = MaxAlloc + 100; 00200 linv = (float *)SUMA_realloc ((void*) linv, MaxAlloc * sizeof(float)); 00201 if (!linv) 00202 { 00203 SUMA_alloc_problem ("Re-Allocation error in IV-FaceSetExtract"); 00204 SUMA_RETURN (NULL); 00205 } 00206 00207 } 00208 se = 0; /* no match for ending sequence, reset the counter */ 00209 break; 00210 case 1: /* found the first character in the end sequence */ 00211 if (nospacing == 1 && se == 0) /* it has to be the first character in the sequence*/ 00212 { 00213 f = atof (s); 00214 linv[cnt] = f; 00215 00216 ++cnt; 00217 #ifdef DEBUG_3 00218 printf ("\nLast number (%d): %f is appended to end sequence !\n",cnt,f); 00219 #endif 00220 } 00221 #ifdef DEBUG_3 00222 printf ("\nfound %s --- se = %d\n",s,se); 00223 #endif 00224 se = se + 1; 00225 break; 00226 default: 00227 break; 00228 } 00229 00230 } 00231 if (si < si_exit) 00232 { 00233 SUMA_error_message ("SUMA_IV_XYZextract","Could not find specified starting sequence",0); 00234 for (i=0;i<si_exit;++i) 00235 printf ("%s \t",seq_strt[i]); 00236 } 00237 else 00238 { 00239 if (se < se_exit) 00240 { 00241 SUMA_error_message ("SUMA_IV_XYZextract","Could not find specified ending sequence",0); 00242 for (i=0;i<se_exit;++i) 00243 printf ("%s \t",seq_end[i]); 00244 } 00245 else 00246 { 00247 /* check that the number of points read is multiple of 3 */ 00248 cnt3 = div (cnt,3); 00249 if (cnt3.rem != 0) 00250 { 00251 SUMA_error_message ("SUMA_IV_XYZextract","number of points read is not multiple of 3 !",0); 00252 #ifdef DEBUG_3 00253 printf ("%f XYZ sets read !!!\n",(float)cnt/3); 00254 #endif 00255 } 00256 } 00257 } 00258 00259 *N_NodeList = cnt3.quot; 00260 00261 /* Now allocate space for IV_FaceSetsextract and fill it up */ 00262 if (!IncludeIndex) 00263 NodeList = (float *) SUMA_calloc (*N_NodeList * 3, sizeof(float)); 00264 else 00265 NodeList = (float *) SUMA_calloc (*N_NodeList * 4, sizeof(float)); 00266 00267 if (!NodeList) 00268 { 00269 SUMA_alloc_problem("SUMA_IV_XYZextract : Could not allocate"); 00270 SUMA_RETURN (NULL); 00271 } 00272 00273 if (!IncludeIndex) 00274 { 00275 for (i=0; i< cnt; ++i) 00276 { 00277 NodeList[i] = linv[i]; 00278 } 00279 } 00280 else 00281 { 00282 cntlim = cnt/3; 00283 for (i=0; i < cntlim; ++i) 00284 { 00285 00286 i4 = 4*i; 00287 i3 = 3*i; 00288 NodeList[i4] = i; 00289 00290 NodeList[i4+1] = linv[i3]; 00291 NodeList[i4+2] = linv[i3+1]; 00292 NodeList[i4+3] = linv[i3+2]; 00293 00294 } 00295 00296 } 00297 00298 fclose (iv_file); 00299 free (linv); 00300 00301 SUMA_RETURN (NodeList); 00302 00303 00304 }/* SUMA_IV_XYZextract */ |
Variable Documentation
|
Global pointer to structure containing info common to all viewers Definition at line 10 of file SUMA_IV_XYZextract.c. |