Doxygen Source Code Documentation
        
Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search   
3destpdf.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 
00019 #define PROGRAM_NAME "3destpdf"                      
00020 #define PROGRAM_AUTHOR "B. D. Ward"                        
00021 #define PROGRAM_DATE "20 January 2000"           
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 #include "mrilib.h"
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 static char * anat_filename = NULL;      
00038 
00039 static THD_3dim_dataset * anat;                 
00040 
00041 static float min_val_float;                 
00042 static float max_val_float;                 
00043 
00044 static Boolean quiet = FALSE;            
00045 
00046 #define MAX_STRING_LENGTH 80
00047 
00048 
00049 
00050 
00051 
00052 
00053 void estPDF_error (char * message)
00054 {
00055   fprintf (stderr, "\n");
00056   fprintf (stderr, "%s Error: %s \n", PROGRAM_NAME, message);
00057   exit(1);
00058 }
00059 
00060 
00061 
00062 
00063 
00064 
00065 #define MTEST(ptr) \
00066 if((ptr)==NULL) \
00067 ( estPDF_error ("Cannot allocate memory") )
00068      
00069 
00070 
00071 
00072 
00073 
00074 #include "estpdf3.c"                    
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 void display_help_menu()
00083 {
00084   printf 
00085     (
00086      "This program estimates the PDF for a dataset.\n\n"
00087      "Usage: \n"
00088      "3destpdf \n"
00089      "-anat filename    Filename of anat dataset to be segmented            \n"
00090       );
00091   
00092   exit(0);
00093 }
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 void get_options
00102 (
00103   int argc,                        
00104   char ** argv                      
00105 )
00106 
00107 {
00108   int nopt = 1;                     
00109   int ival, index;                  
00110   float fval;                       
00111   char message[MAX_STRING_LENGTH];  
00112 
00113 
00114   
00115   if (argc < 2 || strncmp(argv[1], "-help", 5) == 0)  display_help_menu();  
00116    
00117 
00118   
00119   while (nopt < argc )
00120     {
00121 
00122       
00123       if (strncmp(argv[nopt], "-anat", 5) == 0)
00124         {
00125           nopt++;
00126           if (nopt >= argc)  estPDF_error ("need argument after -anat ");
00127           anat_filename = malloc (sizeof(char) * MAX_STRING_LENGTH);
00128           MTEST (anat_filename);
00129           strcpy (anat_filename, argv[nopt]);
00130 
00131           anat = THD_open_one_dataset (anat_filename);
00132           if (!ISVALID_3DIM_DATASET (anat))
00133             {
00134               sprintf (message, "Can't open dataset: %s\n", anat_filename); 
00135               estPDF_error (message); 
00136             } 
00137           THD_load_datablock (anat->dblk); 
00138           if (DSET_ARRAY(anat,0) == NULL)
00139             {
00140               sprintf (message, "Can't access data: %s\n", anat_filename); 
00141               estPDF_error (message); 
00142             }
00143 
00144           nopt++;
00145           continue;
00146         }
00147       
00148 
00149       
00150       sprintf(message,"Unrecognized command line option: %s\n", argv[nopt]);
00151       estPDF_error (message);
00152       
00153     }
00154 
00155   
00156 }
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 void initialize_program 
00165 (
00166   int argc,                        
00167   char ** argv                      
00168 )
00169 
00170 {
00171   float parameters [DIMENSION];    
00172   Boolean ok = TRUE;               
00173 
00174   int nx, ny, nz, nxy, nxyz, ixyz;       
00175   int n;                                 
00176   short * sfim = NULL;                   
00177   short * rfim = NULL;                    
00178   int icount;
00179   int lower_cutoff = 25;
00180 
00181   
00182   get_options (argc, argv);
00183 
00184 
00185   
00186   if (anat == NULL)  estPDF_error ("Unable to read anat dataset");
00187   nx = DSET_NX(anat);   ny = DSET_NY(anat);   nz = DSET_NZ(anat);
00188   nxy = nx*ny;   nxyz = nxy*nz;
00189   sfim  = (short *) DSET_BRICK_ARRAY(anat,0) ;
00190   if (sfim == NULL)  estPDF_error ("Unable to read anat dataset");
00191   rfim = (short *) malloc (sizeof(short) * nxyz);   MTEST (rfim);
00192 
00193 
00194   
00195   icount = 0;
00196   for (ixyz = 0;  ixyz < nxyz;  ixyz++)
00197     if (sfim[ixyz] > lower_cutoff)
00198       {
00199         rfim[icount] = sfim[ixyz];
00200         icount++;
00201       }
00202   printf ("%d voxels above lower cutoff = %d \n", icount, lower_cutoff);
00203 
00204 
00205   
00206   estpdf_short (icount, rfim, parameters);
00207   min_val_float = parameters[4] - 2.0*parameters[5];
00208   max_val_float = parameters[7] + 2.0*parameters[8];
00209   
00210    
00211   if (! quiet)
00212     {
00213       printf ("\n");
00214       printf ("Control inputs: \n");
00215       printf ("anat filename = %s \n", anat_filename);
00216       printf ("min value = %f \n", min_val_float);
00217       printf ("max value = %f \n", max_val_float);
00218     }
00219 
00220 
00221 }
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 int main
00230 (
00231   int argc,                
00232   char ** argv              
00233 )
00234 
00235 {
00236 
00237   
00238   printf ("\n\n");
00239   printf ("Program: %s \n", PROGRAM_NAME);
00240   printf ("Author:  %s \n", PROGRAM_AUTHOR);
00241   printf ("Date:    %s \n", PROGRAM_DATE);
00242   printf ("\n");
00243 
00244   
00245   
00246   initialize_program (argc, argv);
00247 
00248   
00249 
00250 }
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258