Main Page   Data Structures   File List   Data Fields   Globals  

Sadie_General.c

Go to the documentation of this file.
00001 /*
00002 ##########################################
00003 # Sadie_General.c -
00004 #   Set of routines for linking misc. SADIE routines to tcl/tk.
00005 #
00006 # RCS: $Id: Sadie_General.c,v 2.1 1999/01/14 15:37:32 conner Exp $ 
00007 # 
00008 # Digital Image Analysis Lab
00009 # Dept. of Electrical and Computer Engineering
00010 # University of Arizona
00011 ##########################################
00012 */
00013 
00014 #include <tcl.h>
00015 #include <tk.h>
00016 #include "sadie.h"
00017 
00018 /* RCS Indentification information */
00019 static char rcsid[] =
00020   "$Id: Sadie_General.c,v 2.1 1999/01/14 15:37:32 conner Exp $";
00021 
00022 int
00023 Sadie_General_CloseCmd (ClientData client_data, Tcl_Interp * interp, int argc,
00024                         char *argv[])
00025 {
00026   int imgaddr;
00027   IMAGE *theimg;
00028   char msg[SLEN];
00029 
00030   if (argc <= 1)
00031     {
00032       sprintf (msg, "Usage: Sadie_General_Close image_address");
00033       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00034       return TCL_ERROR;
00035     }
00036 
00037   sscanf (argv[1], "%x", &imgaddr);
00038   theimg = (IMAGE *) imgaddr;
00039 
00040   RELIMG (&theimg);
00041 
00042   return TCL_OK;
00043 }
00044 
00045 int
00046 Sadie_General_InitializeProgCmd (ClientData client_data, Tcl_Interp * interp,
00047                                  int argc, char *argv[])
00048 {
00049   INIT ();
00050 
00051   return TCL_OK;
00052 }
00053 
00054 int
00055 Sadie_General_FinishProgCmd (ClientData client_data, Tcl_Interp * interp,
00056                              int argc, char *argv[])
00057 {
00058   FINI ();
00059 
00060   return TCL_OK;
00061 }
00062 
00063 int
00064 Sadie_General_WidthCmd (ClientData client_data, Tcl_Interp * interp, int argc,
00065                         char *argv[])
00066 {
00067   int imgaddr;
00068   IMAGE *theimg;
00069   char msg[SLEN];
00070 
00071   if (argc <= 1)
00072     {
00073       sprintf (msg, "Usage: Sadie_General_Width image_address");
00074       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00075       return TCL_ERROR;
00076     }
00077 
00078   sscanf (argv[1], "%x", &imgaddr);
00079   theimg = (IMAGE *) imgaddr;
00080 
00081   if (!CHECKIMG (theimg))
00082     {
00083       Tcl_AppendResult (interp,
00084                         "couldn't identify SADIE image from input string.",
00085                         NULL);
00086       return TCL_ERROR;
00087     }
00088 
00089   sprintf (msg, "%d", (int) floor ((double) theimg->npix));
00090   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00091 
00092   return TCL_OK;
00093 }
00094 
00095 int
00096 Sadie_General_HeightCmd (ClientData client_data, Tcl_Interp * interp,
00097                          int argc, char *argv[])
00098 {
00099   int imgaddr;
00100   IMAGE *theimg;
00101   char msg[SLEN];
00102 
00103   if (argc <= 1)
00104     {
00105       sprintf (msg, "Usage: Sadie_General_Height image_address");
00106       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00107       return TCL_ERROR;
00108     }
00109 
00110   sscanf (argv[1], "%x", &imgaddr);
00111   theimg = (IMAGE *) imgaddr;
00112 
00113   if (!CHECKIMG (theimg))
00114     {
00115       Tcl_AppendResult (interp,
00116                         "couldn't identify SADIE image from input string.",
00117                         NULL);
00118       return TCL_ERROR;
00119     }
00120 
00121   sprintf (msg, "%d", (int) floor ((double) theimg->nlin));
00122   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00123 
00124   return TCL_OK;
00125 }
00126 
00127 int
00128 Sadie_General_GminCmd (ClientData client_data, Tcl_Interp * interp, int argc,
00129                        char *argv[])
00130 {
00131   int imgaddr;
00132   IMAGE *theimg;
00133   char msg[SLEN];
00134 
00135   if (argc <= 1)
00136     {
00137       sprintf (msg, "Usage: Sadie_General_Gmin image_address");
00138       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00139       return TCL_ERROR;
00140     }
00141 
00142   sscanf (argv[1], "%x", &imgaddr);
00143   theimg = (IMAGE *) imgaddr;
00144 
00145   if (!CHECKIMG (theimg))
00146     {
00147       Tcl_AppendResult (interp,
00148                         "couldn't identify SADIE image from input string.",
00149                         NULL);
00150       return TCL_ERROR;
00151     }
00152 
00153   RANGE (theimg);
00154 
00155   sprintf (msg, "%d", (int) floor ((double) theimg->gmin));
00156   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00157 
00158   return TCL_OK;
00159 }
00160 
00161 int
00162 Sadie_General_GmaxCmd (ClientData client_data, Tcl_Interp * interp, int argc,
00163                        char *argv[])
00164 {
00165   int imgaddr;
00166   IMAGE *theimg;
00167   char msg[SLEN];
00168 
00169   if (argc <= 1)
00170     {
00171       sprintf (msg, "Usage: Sadie_General_Gmax image_address");
00172       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00173       return TCL_ERROR;
00174     }
00175 
00176   sscanf (argv[1], "%x", &imgaddr);
00177   theimg = (IMAGE *) imgaddr;
00178 
00179   if (!CHECKIMG (theimg))
00180     {
00181       Tcl_AppendResult (interp,
00182                         "couldn't identify SADIE image from input string.",
00183                         NULL);
00184       return TCL_ERROR;
00185     }
00186 
00187   RANGE (theimg);
00188 
00189   sprintf (msg, "%d", (int) floor ((double) theimg->gmax));
00190   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00191 
00192   return TCL_OK;
00193 }
00194 
00195 int
00196 Sadie_General_GetNumBandsCmd (ClientData client_data, Tcl_Interp * interp,
00197                               int argc, char *argv[])
00198 {
00199   int inimgaddr;
00200   int number;
00201   IMAGE *inimg;
00202   char msg[SLEN];
00203 
00204   if (argc <= 1)
00205     {
00206       return TCL_ERROR;
00207     }
00208 
00209   sscanf (argv[1], "%x", &inimgaddr);
00210   inimg = (IMAGE *) inimgaddr;
00211 
00212   number = inimg->nbnd;
00213 
00214   sprintf (msg, "%d", number);
00215   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00216 
00217   return TCL_OK;
00218 
00219 }
00220 
00221 int
00222 Sadie_General_GetPixelCmd (ClientData client_data, Tcl_Interp * interp,
00223                            int argc, char *argv[])
00224 {
00225   int imgaddr;
00226   int xval, yval;
00227   double rval, gval, bval;
00228   IMAGE *theimg;
00229   char msg[SLEN];
00230 
00231   if (argc <= 3)
00232     {
00233       sprintf (msg,
00234                "Usage: Sadie_General_GetPixel image_address xcoord ycoord");
00235       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00236       return TCL_ERROR;
00237     }
00238 
00239   sscanf (argv[1], "%x", &imgaddr);
00240   theimg = (IMAGE *) imgaddr;
00241 
00242   if (Tcl_GetInt (interp, argv[2], &xval) != TCL_OK)
00243     {
00244       return TCL_ERROR;
00245     }
00246 
00247   if (Tcl_GetInt (interp, argv[3], &yval) != TCL_OK)
00248     {
00249       return TCL_ERROR;
00250     }
00251 
00252   if (!CHECKIMG (theimg))
00253     {
00254       Tcl_AppendResult (interp,
00255                         "couldn't identify SADIE image from input string.",
00256                         NULL);
00257       return TCL_ERROR;
00258     }
00259 
00260   if (theimg->nbnd == 3)
00261     {
00262       rval = (double) theimg->data[0][yval][xval];
00263       gval = (double) theimg->data[1][yval][xval];
00264       bval = (double) theimg->data[2][yval][xval];
00265     }
00266   else
00267     {
00268       rval = (double) theimg->data[0][yval][xval];
00269       gval = rval;
00270       bval = rval;
00271     }
00272 
00273   sprintf (msg, "%.4e %.4e %.4e", rval, gval, bval);
00274   Tcl_SetResult (interp, msg, TCL_VOLATILE);
00275 
00276   return TCL_OK;
00277 }
00278 
00279 int
00280 Sadie_General_SetNameCmd (ClientData client_data, Tcl_Interp * interp,
00281                           int argc, char *argv[])
00282 {
00283   int imgaddr;
00284   IMAGE *theimg;
00285   char msg[SLEN];
00286 
00287   if (argc <= 2)
00288     {
00289       sprintf (msg, "Usage: Sadie_General_SetName image_address name");
00290       Tcl_SetResult (interp, msg, TCL_VOLATILE);
00291       return TCL_ERROR;
00292     }
00293 
00294   sscanf (argv[1], "%x", &imgaddr);
00295   theimg = (IMAGE *) imgaddr;
00296 
00297   if (!CHECKIMG (theimg))
00298     {
00299       Tcl_AppendResult (interp,
00300                         "couldn't identify SADIE image from input string.",
00301                         NULL);
00302       return TCL_ERROR;
00303     }
00304   else
00305     {
00306       sprintf (theimg->text, "%s", argv[2]);
00307     }
00308 
00309   return TCL_OK;
00310 }
00311 
00312 /*************************************************************************
00313  *
00314  * This procedure initializes the the Sadie_General procedures when
00315  * this package is loaded.
00316  *
00317  *************************************************************************/
00318 int
00319 Sadie_General_Init (Tcl_Interp * interp)
00320 {
00321   Tcl_CreateCommand (interp, "Sadie_General_Close", Sadie_General_CloseCmd,
00322                      (ClientData) NULL, NULL);
00323   Tcl_CreateCommand (interp, "Sadie_General_InitializeProg",
00324                      Sadie_General_InitializeProgCmd, (ClientData) NULL,
00325                      NULL);
00326   Tcl_CreateCommand (interp, "Sadie_General_FinishProg",
00327                      Sadie_General_FinishProgCmd, (ClientData) NULL, NULL);
00328   Tcl_CreateCommand (interp, "Sadie_General_Width", Sadie_General_WidthCmd,
00329                      (ClientData) NULL, NULL);
00330   Tcl_CreateCommand (interp, "Sadie_General_Height", Sadie_General_HeightCmd,
00331                      (ClientData) NULL, NULL);
00332   Tcl_CreateCommand (interp, "Sadie_General_Gmin", Sadie_General_GminCmd,
00333                      (ClientData) NULL, NULL);
00334   Tcl_CreateCommand (interp, "Sadie_General_Gmax", Sadie_General_GmaxCmd,
00335                      (ClientData) NULL, NULL);
00336   Tcl_CreateCommand (interp, "Sadie_General_GetNumBands",
00337                      Sadie_General_GetNumBandsCmd, (ClientData) NULL, NULL);
00338   Tcl_CreateCommand (interp, "Sadie_General_GetPixel",
00339                      Sadie_General_GetPixelCmd, (ClientData) NULL, NULL);
00340   Tcl_CreateCommand (interp, "Sadie_General_SetName",
00341                      Sadie_General_SetNameCmd, (ClientData) NULL, NULL);
00342 
00343   return TCL_OK;
00344 }

Generated on Sun May 18 15:36:16 2003 for tclSadie by doxygen1.3