Main Page   Data Structures   File List   Data Fields   Globals  

trees.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <tcl.h>
00003 #include <tk.h>
00004 #include "sadie.h"
00005 
00006 static int FLAG=0;
00007 static int DIRECTORY=1;
00008 
00009 static int libhomeset=0;
00010 static char libhome[200];
00011 static char *ProgName;
00012 
00013 
00014 /*-------------------------------------------------------------*/
00015 /* Global Sadie variables that must be set from within Tcl/Tk  */
00016 /*-------------------------------------------------------------*/
00017 short   nlev;
00018 short   csize;
00019 double  weight;
00020 double  *count;
00021 PIXEL   gain;
00022 PIXEL   bias;
00023 PIXEL   gmin;
00024 PIXEL   gmax;
00025 PIXEL   thresh;
00026 PIXEL   gbrk[2][4];
00027 PIXEL   *table;
00028 /* -------------------------------------------------------------------------- */
00029 
00030 
00031 
00032 char* msg_ptr;
00033 Tcl_Interp* MainTclInterp;
00034 
00035 
00036 #ifdef TREES_HW
00037 /* Defined in StageMotion.c */
00038 int StageMotion_Init(Tcl_Interp*);
00039 /* Defined in Sadie_Camera.c */
00040 int Sadie_Camera_Init(Tcl_Interp*);
00041 /* Defined in Sadie_Camera.c */
00042 int tkCamera_Init(Tcl_Interp*);
00043 /* Defined in FocusMotion.c */
00044 int FocusMotion_Init(Tcl_Interp*);
00045 #endif
00046 
00047 
00048 int Sadie_FileIO_Init(Tcl_Interp *interp);
00049 int Sadie_General_Init(Tcl_Interp *interp);
00050 int Sadie_Plot_Init(Tcl_Interp *interp);
00051 int Sadie_NewFunctions_Init(Tcl_Interp *interp);
00052 int Sadie_Contrast_Init(Tcl_Interp *interp);
00053 int Sadie_Filter_Init(Tcl_Interp *interp);
00054 int Sadie_Geometry_Init(Tcl_Interp *interp);
00055 int Sadie_Multi_Init(Tcl_Interp *interp);
00056 int Sadie_Classify_Init(Tcl_Interp *interp);
00057 int Sadie_Tools_Init(Tcl_Interp *interp);
00058 int Sadie_Image_Init(Tcl_Interp *interp);
00059 
00060 int Sadie_Proto_Init(Tcl_Interp *interp);
00061 
00062 int Sadie_TREES_Init(Tcl_Interp *interp);
00063 
00064 
00065 /*-Copyright Information------------------------------------------------------*/
00066 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00067 /*----------------------------------------------------------------------------*/
00068 /*-General Information--------------------------------------------------------*/
00069 /*                                                                            */
00070 /*   This function displays the command line options for use when invoking    */
00071 /*   trees.                                                                */
00072 /*                                                                            */
00073 /*----------------------------------------------------------------------------*/
00074 /*-Interface Information------------------------------------------------------*/
00075 void usage(void) {
00076         fprintf(stderr, "\nUsage: %s [options]\n",ProgName);
00077         fprintf(stderr, "Options:\n");
00078         fprintf(stderr, "\t-d <trees library directory>\n");
00079         fprintf(stderr, "\t-h\tprint this message\n");
00080         fprintf(stderr, "\n");
00081 }
00082 
00083 /*-Copyright Information------------------------------------------------------*/
00084 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00085 /*----------------------------------------------------------------------------*/
00086 /*-General Information--------------------------------------------------------*/
00087 /*                                                                            */
00088 /*   This function checks to see if a file exists.                            */
00089 /*                                                                            */
00090 /*----------------------------------------------------------------------------*/
00091 /*-Interface Information------------------------------------------------------*/
00092 int verifyfile (
00093 Tcl_Interp* interp, /*  I  The Tcl/Tk command interpreter.                    */
00094 char* name          /*  I  The name of the file.                              */
00095 ) {
00096     Tcl_Obj *cmds=NULL;
00097     char tempstr[250];
00098     int result;
00099     
00100     sprintf(tempstr,"file exists %s",name);
00101     cmds = Tcl_NewStringObj(tempstr,-1);
00102     Tcl_EvalObj(interp,cmds);
00103     Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &result);
00104 
00105     if (result) {
00106       sprintf(tempstr,"auto_mkindex [file dirname %s] *.tcl",name);
00107       cmds = Tcl_NewStringObj(tempstr,-1);
00108       Tcl_EvalObj(interp,cmds);
00109     }
00110 
00111     return result;
00112 }
00113 
00114 /*-Copyright Information------------------------------------------------------*/
00115 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00116 /*----------------------------------------------------------------------------*/
00117 /*-General Information--------------------------------------------------------*/
00118 /*                                                                            */
00119 /*   This function checks to see if the environment variable TREES_HOME    */
00120 /*   contains the location of the .tcl files needed by trees.              */
00121 /*                                                                            */
00122 /*----------------------------------------------------------------------------*/
00123 /*-Interface Information------------------------------------------------------*/
00124 int setlibdir_env (Tcl_Interp* interp) {
00125     Tcl_Obj *cmds=NULL;
00126     char *libdir=NULL;
00127     int result;
00128 
00129     /* Verify that the environment variable TREES_HOME exists */
00130     cmds = Tcl_NewStringObj("global env
00131                              info exists env(TREES_HOME)",-1);
00132     Tcl_EvalObj(interp,cmds);
00133     Tcl_GetIntFromObj(interp, Tcl_GetObjResult(interp), &result);
00134 
00135     /* Read the environment variable TREES_HOME */
00136     if (result) {
00137         cmds = Tcl_NewStringObj("global env
00138                                  set env(TREES_HOME)",-1);
00139         Tcl_EvalObj(interp,cmds);
00140         libdir = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), NULL);
00141         sprintf(libhome,"%s",libdir);
00142     }
00143     
00144     return result;
00145 }
00146 
00147 /*-Copyright Information------------------------------------------------------*/
00148 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00149 /*----------------------------------------------------------------------------*/
00150 /*-General Information--------------------------------------------------------*/
00151 /*                                                                            */
00152 /*   This function computes the default location of the .tcl files needed by  */
00153 /*   trees, based on the location of the executable.                       */
00154 /*                                                                            */
00155 /*----------------------------------------------------------------------------*/
00156 /*-Interface Information------------------------------------------------------*/
00157 int setlibdir_default (Tcl_Interp* interp) {
00158     Tcl_Obj *cmds=NULL;
00159     char *libdirroot=NULL;
00160     
00161     cmds = Tcl_NewStringObj("file dirname [info nameofexecutable]",-1);
00162     Tcl_EvalObj(interp,cmds);
00163     libdirroot = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), NULL);
00164     sprintf(libhome,"%s/../library",libdirroot);
00165     
00166     return 1;
00167 }
00168 
00169 
00170 /*-Copyright Information------------------------------------------------------*/
00171 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00172 /*----------------------------------------------------------------------------*/
00173 /*-General Information--------------------------------------------------------*/
00174 /*                                                                            */
00175 /*   This function determines the location of the .tcl library files needed   */
00176 /*   by trees.                                                             */
00177 /*                                                                            */
00178 /*----------------------------------------------------------------------------*/
00179 /*-Interface Information------------------------------------------------------*/
00180 void setlibdir (Tcl_Interp* interp) {
00181     char testfile[250];
00182     Tcl_Obj *cmds=NULL;
00183 
00184     /*
00185      * First check if the library directory was supplied
00186      * on the command line.
00187      */
00188     if (!libhomeset) {
00189         /* Check if the environment variable TREES_HOME exists */
00190         if (!setlibdir_env(interp)) {
00191             /* Finally, as a last resort, try a default location */
00192             setlibdir_default(interp);
00193         }
00194     }
00195 
00196     /* Verify that trees_main.tcl can be found in the library directory */
00197     sprintf(testfile,"%s/trees_main.tcl",libhome);
00198     if (verifyfile(interp,testfile)) {
00199         Tcl_SetVar(interp, "trees_dir", libhome, TCL_GLOBAL_ONLY);
00200         cmds = Tcl_NewStringObj("global trees_dir auto_path
00201                                  lappend auto_path $trees_dir",-1);
00202         Tcl_EvalObj(interp,cmds);
00203     } else {
00204         fprintf(stderr, "\nERROR: trees library directory: %s is not valid!\n",libhome);
00205         fprintf(stderr, "       \tYou can indicate the location of the library by using the\n");
00206         fprintf(stderr, "       \tenvironment variable TREES_HOME or the command line option -d.\n");
00207         usage();
00208         exit(0);
00209     }
00210 }
00211 
00212 
00213 int Tcl_AppInit(Tcl_Interp* interp)
00214 {
00215   int status;
00216   msg_ptr = (char *) Tcl_Alloc(1024);
00217   
00218   
00219   MainTclInterp = interp;
00220 
00221   status = Tcl_Init(interp);
00222   
00223   if (status != TCL_OK) {
00224     return TCL_ERROR;
00225   }
00226   
00227   /* Initialize Tk values. */
00228   status = Tk_Init(interp);
00229   
00230   if (status != TCL_OK) {
00231     return TCL_ERROR;
00232   }
00233   
00234 
00235   /*
00236    * Call the init procedures for included packages.  Each call should
00237    * look like this:
00238    *
00239    * if (Mod_Init(interp) == TCL_ERROR) {
00240    *     return TCL_ERROR;
00241    * }
00242    *
00243    * where "Mod" is the name of the module.
00244    */
00245 
00246 
00247 #ifdef TREES_HW
00248       Tcl_SetVar2(interp, "gui", "hardware", "1", TCL_GLOBAL_ONLY);
00249 
00250       if (StageMotion_Init(interp) == TCL_ERROR) {
00251           return TCL_ERROR;
00252       }
00253       if (Sadie_Camera_Init(interp) == TCL_ERROR) {
00254           return TCL_ERROR;
00255       }
00256       if (FocusMotion_Init(interp) == TCL_ERROR) {
00257           return TCL_ERROR;
00258       }
00259       if (tkCamera_Init(interp) == TCL_ERROR) {
00260           return TCL_ERROR;
00261       }
00262 #else
00263       Tcl_SetVar2(interp, "gui", "hardware", "0", TCL_GLOBAL_ONLY);
00264 #endif
00265 
00266 
00267   if (Sadie_FileIO_Init(interp) == TCL_ERROR) {
00268       return TCL_ERROR;
00269   }
00270   if (Sadie_General_Init(interp) == TCL_ERROR) {
00271       return TCL_ERROR;
00272   }
00273   if (Sadie_Plot_Init(interp) == TCL_ERROR) {
00274       return TCL_ERROR;
00275   }
00276   if (Sadie_NewFunctions_Init(interp) == TCL_ERROR) {
00277       return TCL_ERROR;
00278   }
00279   if (Sadie_Contrast_Init(interp) == TCL_ERROR) {
00280       return TCL_ERROR;
00281   }
00282   if (Sadie_Filter_Init(interp) == TCL_ERROR) {
00283       return TCL_ERROR;
00284   }
00285   if (Sadie_Geometry_Init(interp) == TCL_ERROR) {
00286       return TCL_ERROR;
00287   }
00288   if (Sadie_Multi_Init(interp) == TCL_ERROR) {
00289       return TCL_ERROR;
00290   }
00291   if (Sadie_Classify_Init(interp) == TCL_ERROR) {
00292       return TCL_ERROR;
00293   }
00294   if (Sadie_Tools_Init(interp) == TCL_ERROR) {
00295       return TCL_ERROR;
00296   }
00297   if (Sadie_Image_Init(interp) == TCL_ERROR) {
00298     return TCL_ERROR;
00299   }
00300 
00301 
00302   if (Sadie_Proto_Init(interp) == TCL_ERROR) {
00303     return TCL_ERROR;
00304   }
00305   
00306   if (Sadie_TREES_Init(interp) == TCL_ERROR) {
00307     return TCL_ERROR;
00308   }
00309 
00310   /* Find the location onf the library files */
00311   setlibdir(interp);
00312   printf("Initializing tclSadie with TREES_HOME=%s\n",libhome);
00313 
00314   
00315 
00316   /* Initialize the sadie program */
00317   if (Tcl_Eval(interp, "trees_main_init") == TCL_ERROR) {
00318     return TCL_ERROR;
00319   }
00320   Tk_MainLoop();
00321 
00322   return TCL_OK;
00323 }
00324 
00325 
00326 /*-Copyright Information------------------------------------------------------*/
00327 /* Copyright (c) 1999 by the University of Arizona Digital Image Analysis Lab */
00328 /*----------------------------------------------------------------------------*/
00329 /*-General Information--------------------------------------------------------*/
00330 /*                                                                            */
00331 /*   This function parses command line arguements and spawns the Tcl/Tk       */
00332 /*   command interpreter used by trees.                                    */
00333 /*                                                                            */
00334 /*----------------------------------------------------------------------------*/
00335 /*-Interface Information------------------------------------------------------*/
00336 int main(int argc, char** argv)
00337 {
00338     int i;
00339     int state=FLAG;
00340     
00341     /* Parse Command Line */
00342     
00343     ProgName = argv[0];
00344     
00345     for (i=1; i<argc; i++) {
00346         char *arg = argv[i];
00347 
00348         if (state==FLAG  &&  *arg=='-') {
00349             switch (arg[1]) {
00350             case 'd' :
00351                 /* The next arg should be a directory */
00352                 state = DIRECTORY;
00353                 break;
00354             default:
00355                 usage();
00356                 exit(0);
00357                 break;
00358             }
00359         } else if (state == DIRECTORY  && *arg!='-') {
00360             sprintf(libhome,"%s",arg);
00361             libhomeset = 1;
00362             state = FLAG;
00363         } else {
00364             usage();
00365             exit(0);
00366         }
00367     }
00368     
00369     
00370     if (state != FLAG) {
00371         fprintf(stderr, "\nERROR: Expecting parameter after: %s\n",argv[i-1]);
00372         usage();
00373         exit(0);        
00374     }   
00375     
00376     
00377     /* Start TK interpreter without passing in command line options */
00378     Tk_Main(1, argv, Tcl_AppInit);
00379 
00380     return 0;
00381 }

Generated on Wed Apr 9 08:56:15 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002