Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
SUMA_coarsen.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "SUMA_suma.h"
00019 #include "SUMA_GeomComp.h"
00020 #include "SUMA_gts.h"
00021
00022 #define SURFPATCH_MAX_SURF 1
00023
00024
00025 SUMA_SurfaceViewer *SUMAg_cSV = NULL;
00026 SUMA_SurfaceViewer *SUMAg_SVv = NULL;
00027
00028 int SUMAg_N_SVv = 0;
00029 SUMA_DO *SUMAg_DOv = NULL;
00030 int SUMAg_N_DOv = 0;
00031 SUMA_CommonFields *SUMAg_CF = NULL;
00032
00033 void usage_SUMA_coarsen (SUMA_GENERIC_ARGV_PARSE *ps)
00034 {
00035 static char FuncName[]={"usage_SUMA_coarsen"};
00036 char * s = NULL, *sio=NULL;
00037 s = SUMA_help_basics();
00038 sio = SUMA_help_IO_Args (ps);
00039 printf ( "\nUsage:\n"
00040 " SurfMesh <-i_TYPE SURFACE> <-o_TYPE OUTPUT> <-edges FRAC> \n"
00041 " [-sv SURF_VOL]\n"
00042 " \n"
00043 " Example:\n"
00044 " SurfMesh -i_ply surf1.ply -o_ply surf1_half -edges 0.5\n"
00045 "\n"
00046 " Mandatory parameters:\n"
00047 " -i_TYPE SURFACE: Input surface. See below for details. \n"
00048 " You can also use the -t* method or\n"
00049 " the -spec SPECFILE -surf SURFACE method.\n"
00050 " -o_TYPE OUTPUT: Output surface, see below.\n"
00051 " -edges FRAC: surface will be simplified to number of\n"
00052 " edges times FRAC (fraction). Default is .5\n"
00053 " refines surface if edges > 1\n"
00054 "\n"
00055 "%s"
00056 "\n"
00057 "%s"
00058 "\n",sio,s); SUMA_free(sio); sio = NULL;SUMA_free(s); s = NULL;
00059 s = SUMA_New_Additions(0, 1); printf("%s\n", s);SUMA_free(s); s = NULL;
00060 printf( " Originally written by Jakub Otwinowski.\n"
00061 " Now maintained by Ziad S. Saad SSCC/NIMH/NIH ziad@nih.gov \n");
00062 printf( " This program uses the GTS library gts.sf.net\n"
00063 " for fun read \"Fast and memory efficient polygonal simplification\" (1998) \n"
00064 " and \"Evaluation of memoryless simplification\" (1999) by Lindstrom and Turk.\n");
00065 exit (0);
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 SUMA_GENERIC_PROG_OPTIONS_STRUCT *SUMA_coarsen_ParseInput (char *argv[], int argc, SUMA_GENERIC_ARGV_PARSE *ps)
00079 {
00080 static char FuncName[]={"SUMA_coarsen_ParseInput"};
00081 SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt=NULL;
00082 int kar, i, ind;
00083 char *outprefix;
00084 SUMA_Boolean brk = NOPE;
00085 void *SO_name=NULL;
00086 SUMA_Boolean exists = NOPE;
00087 SUMA_Boolean LocalHead = NOPE;
00088
00089 SUMA_ENTRY;
00090
00091 Opt = SUMA_Alloc_Generic_Prog_Options_Struct();
00092
00093 kar = 1;
00094 Opt->out_prefix = NULL;
00095 Opt->v0 = .5;
00096 brk = NOPE;
00097
00098 while (kar < argc)
00099 {
00100
00101 if (strcmp(argv[kar], "-h") == 0 || strcmp(argv[kar], "-help") == 0)
00102 {
00103 usage_SUMA_coarsen(ps);
00104 exit (0);
00105 }
00106
00107 SUMA_SKIP_COMMON_OPTIONS(brk, kar);
00108
00109
00110 if (!brk && (strcmp(argv[kar], "-edges") == 0))
00111 {
00112 if (kar+1 >= argc)
00113 {
00114 fprintf (SUMA_STDERR, "need a number after -edges \n");
00115 exit (1);
00116 }
00117 Opt->v0 = atof(argv[++kar]);
00118
00119 brk = YUP;
00120 }
00121
00122
00123 if (!brk && !ps->arg_checked[kar])
00124 {
00125 fprintf (SUMA_STDERR,"Error %s:\nOption %s not understood. Try -help for usage\n", FuncName, argv[kar]);
00126 exit (1);
00127 } else
00128 {
00129 brk = NOPE;
00130 kar ++;
00131 }
00132
00133 }
00134
00135
00136 if (ps->s_N_surfnames + ps->i_N_surfnames + ps->t_N_surfnames != 1) {
00137 SUMA_S_Err("Multiple surface specifications used. Only one surface allowed.");
00138 exit(1);
00139 }
00140
00141
00142 if (ps->o_N_surfnames) {
00143 Opt->out_prefix = SUMA_copy_string(ps->o_surfnames[0]);
00144 Opt->SurfFileType = ps->o_FT[0];
00145 Opt->SurfFileFormat = ps->o_FF[0];
00146 } else {
00147 Opt->out_prefix = SUMA_copy_string("SurfMesh_out");
00148 Opt->SurfFileType = SUMA_PLY;
00149 Opt->SurfFileFormat = SUMA_ASCII;
00150 }
00151 SO_name = SUMA_Prefix2SurfaceName(Opt->out_prefix, NULL, NULL, Opt->SurfFileType, &exists);
00152 if (exists) {
00153 fprintf(SUMA_STDERR,"Error %s:\nOutput file(s) %s* on disk.\nWill not overwrite.\n", FuncName, Opt->out_prefix);
00154 exit(1);
00155 }
00156
00157 if (SO_name) SUMA_free(SO_name); SO_name = NULL;
00158
00159
00160 SUMA_RETURN (Opt);
00161
00162 }
00163
00164 double distance(SUMA_SurfaceObject *SO, int n, int m)
00165 {
00166 int i;
00167 double result = 0;
00168 for (i = 0; i<3; i++)
00169 result += pow(SO->NodeList[n*3+i] - SO->NodeList[m*3+i], 2);
00170 return sqrt(result);
00171 }
00172
00173
00174 int main (int argc,char *argv[])
00175 {
00176 static char FuncName[]={"SurfMesh"};
00177 SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt=NULL;
00178 int SO_read = -1;
00179 int i = 0;
00180 SUMA_SurfaceObject *SO = NULL, *S2 = NULL;
00181 void *SO_name = NULL;
00182 SUMA_Boolean exists = NOPE;
00183 FILE* out = NULL;
00184 SUMA_GENERIC_ARGV_PARSE *ps=NULL;
00185 SUMA_SurfSpecFile *Spec = NULL;
00186 int N_Spec=0;
00187 SUMA_Boolean LocalHead = NOPE;
00188
00189 SUMA_mainENTRY;
00190
00191 SUMA_STANDALONE_INIT;
00192
00193
00194 ps = SUMA_Parse_IO_Args(argc, argv, "-i;-t;-spec;-s;-sv;-o;");
00195
00196
00197 SUMAg_DOv = SUMA_Alloc_DisplayObject_Struct (SUMA_MAX_DISPLAYABLE_OBJECTS);
00198
00199 if (argc < 4)
00200 {
00201 usage_SUMA_coarsen(ps);
00202 exit (1);
00203 }
00204
00205 Opt = SUMA_coarsen_ParseInput (argv, argc, ps);
00206
00207 Spec = SUMA_IO_args_2_spec(ps, &N_Spec);
00208 if (N_Spec != 1) {
00209 SUMA_S_Err("Multiple spec at input.");
00210 exit(1);
00211 }
00212
00213 SO = SUMA_Load_Spec_Surf(Spec, 0, ps->sv[0], 0);
00214 if (!SO) {
00215 fprintf (SUMA_STDERR,"Error %s:\n"
00216 "Failed to find surface\n"
00217 "in spec file. \n",
00218 FuncName );
00219 exit(1);
00220
00221 }
00222
00223 S2 = SUMA_Mesh_Resample (SO, Opt->v0);
00224
00225 SO_name = SUMA_Prefix2SurfaceName(Opt->out_prefix, NULL, NULL, Opt->SurfFileType, &exists);
00226 if (exists) {
00227 fprintf(SUMA_STDERR,"Error %s:\nOutput file(s) %s* on disk.\nWill not overwrite.\n", FuncName, Opt->out_prefix);
00228 exit(1);
00229 }
00230
00231
00232 fprintf (SUMA_STDERR,"%s: Writing surface ...\n", FuncName);
00233 if (!SUMA_Save_Surface_Object (SO_name, S2, Opt->SurfFileType, Opt->SurfFileFormat, NULL)) {
00234 fprintf (SUMA_STDERR,"Error %s: Failed to write surface object.\n", FuncName);
00235 exit (1);
00236 }
00237
00238
00239 SUMA_LH("clean up");
00240
00241
00242 if (SO_name) SUMA_free(SO_name); SO_name = NULL;
00243 if (SO) SUMA_Free_Surface_Object(SO); SO = NULL;
00244 if (S2) SUMA_Free_Surface_Object(S2); S2 = NULL;
00245 if (ps) SUMA_FreeGenericArgParse(ps); ps = NULL;
00246 if (Spec) SUMA_free(Spec); Spec = NULL;
00247 if (Opt) Opt = SUMA_Free_Generic_Prog_Options_Struct(Opt);
00248 if (!SUMA_Free_Displayable_Object_Vect (SUMAg_DOv, SUMAg_N_DOv)) {
00249 SUMA_SL_Err("DO Cleanup Failed!");
00250 }
00251
00252 if (!SUMA_Free_CommonFields(SUMAg_CF)) {SUMA_SL_Err("SUMAg_CF Cleanup Failed!");}
00253
00254 SUMA_RETURN(0);
00255 }