Main Page | Data Structures | Directories | File List | Data Fields | Globals

Sadie_General.c

Go to the documentation of this file.
00001 
00013 /* This file is part of tclSadie.
00014 
00015    tclSadie is free software; you can redistribute it and/or modify it
00016    under the terms of the GNU General Public License as published by
00017    the Free Software Foundation; either version 2 of the License, or
00018    (at your option) any later version.
00019 
00020    tclSadie is distributed in the hope that it will be useful, but
00021    WITHOUT ANY WARRANTY; without even the implied warranty of
00022    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023    General Public License for more details.
00024 
00025    You should have received a copy of the GNU General Public License
00026    along with tclSadie; if not, write to the Free Software Foundation,
00027    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.  */
00028 
00029 #if HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif /* HAVE_CONFIG_H */
00032 #include <tcl.h>
00033 #include <tk.h>
00034 #include <sadie.h>
00035 #include <string.h>
00036 #include "tclsadie.h"
00037 #include "Sadie_Index.h"
00038 
00040 extern sad_doclistp_t global_doclist;
00041 
00053 int
00054 Sadie_General_CloseCmd (ClientData client_data, Tcl_Interp *interp,
00055                         int objc, Tcl_Obj * const objv[])
00056 {
00057   if (objc != 2)
00058     {
00059       Tcl_WrongNumArgs (interp, 1, objv, "image_ID");
00060       return TCL_ERROR;
00061     }
00062   sad_dispose_doc (global_doclist, Tcl_GetString (objv[1]));
00063   return TCL_OK;
00064 }
00065 
00075 int
00076 Sadie_General_InitializeProgCmd (ClientData client_data, Tcl_Interp *interp,
00077                                  int objc, Tcl_Obj * const objv[])
00078 {
00079   INIT ();
00080   return TCL_OK;
00081 }
00082 
00092 int
00093 Sadie_General_FinishProgCmd (ClientData client_data, Tcl_Interp *interp,
00094                              int objc, Tcl_Obj * const objv[])
00095 {
00096   FINI ();
00097   return TCL_OK;
00098 }
00099 
00110 int
00111 Sadie_General_WidthCmd (ClientData client_data, Tcl_Interp *interp,
00112                         int objc, Tcl_Obj * const objv[])
00113 {
00114   IMAGE *theimg = NULL;
00115 
00116   if (objc != 2)
00117     {
00118       Tcl_WrongNumArgs (interp, 1, objv, "image_ID");
00119       return TCL_ERROR;
00120     }
00121   if ((GetSadieImageFromObj (objv[1], &theimg) != TCL_OK)
00122       || (!CHECKIMG (theimg)))
00123     {
00124       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00125                         "couldn't identify SADIE image from input string.",
00126                         -1);
00127       return TCL_ERROR;
00128     }
00129   Tcl_SetLongObj (Tcl_GetObjResult (interp), theimg->npix);
00130   return TCL_OK;
00131 }
00132 
00143 int
00144 Sadie_General_HeightCmd (ClientData client_data, Tcl_Interp *interp,
00145                          int objc, Tcl_Obj * const objv[])
00146 {
00147   IMAGE *theimg = NULL;
00148 
00149   if (objc != 2)
00150     {
00151       Tcl_WrongNumArgs (interp, 1, objv, "image_ID");
00152       return TCL_ERROR;
00153     }
00154   if ((GetSadieImageFromObj (objv[1], &theimg) != TCL_OK)
00155       || (!CHECKIMG (theimg)))
00156     {
00157       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00158                         "couldn't identify SADIE image from input string.",
00159                         -1);
00160       return TCL_ERROR;
00161     }
00162   Tcl_SetLongObj (Tcl_GetObjResult (interp), theimg->nlin);
00163   return TCL_OK;
00164 }
00165 
00176 int
00177 Sadie_General_GminCmd (ClientData client_data, Tcl_Interp *interp,
00178                        int objc, Tcl_Obj * const objv[])
00179 {
00180   IMAGE *theimg = NULL;
00181 
00182   if (objc != 2)
00183     {
00184       Tcl_WrongNumArgs (interp, 1, objv, "image_ID");
00185       return TCL_ERROR;
00186     }
00187   if ((GetSadieImageFromObj (objv[1], &theimg) != TCL_OK)
00188       || (!CHECKIMG (theimg)))
00189     {
00190       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00191                         "couldn't identify SADIE image from input string.",
00192                         -1);
00193       return TCL_ERROR;
00194     }
00195   RANGE (theimg);
00196   Tcl_SetDoubleObj (Tcl_GetObjResult (interp), theimg->gmin);
00197   return TCL_OK;
00198 }
00199 
00210 int
00211 Sadie_General_GmaxCmd (ClientData client_data, Tcl_Interp *interp,
00212                        int objc, Tcl_Obj * const objv[])
00213 {
00214   IMAGE *theimg = NULL;
00215 
00216   if (objc != 2)
00217     {
00218       Tcl_WrongNumArgs (interp, 1, objv, "image_ID");
00219       return TCL_ERROR;
00220     }
00221   if ((GetSadieImageFromObj (objv[1], &theimg) != TCL_OK)
00222       || (!CHECKIMG (theimg)))
00223     {
00224       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00225                         "couldn't identify SADIE image from input string.",
00226                         -1);
00227       return TCL_ERROR;
00228     }
00229   RANGE (theimg);
00230   Tcl_SetDoubleObj (Tcl_GetObjResult (interp), theimg->gmax);
00231   return TCL_OK;
00232 }
00233 
00244 int
00245 Sadie_General_GetNumBandsCmd (ClientData client_data, Tcl_Interp *interp,
00246                               int objc, Tcl_Obj * const objv[])
00247 {
00248   IMAGE *theimg = NULL;
00249 
00250   if (objc != 2)
00251     {
00252       Tcl_WrongNumArgs (interp, 1, objv, "image_ID");
00253       return TCL_ERROR;
00254     }
00255   if ((GetSadieImageFromObj (objv[1], &theimg) != TCL_OK)
00256       || (!CHECKIMG (theimg)))
00257     {
00258       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00259                         "couldn't identify SADIE image from input string.",
00260                         -1);
00261       return TCL_ERROR;
00262     }
00263   Tcl_SetLongObj (Tcl_GetObjResult (interp), theimg->nbnd);
00264   return TCL_OK;
00265 }
00266 
00268 #define MAX_DISPLAY_CHANNEL 3
00269 
00270 static const int max_display_channel = MAX_DISPLAY_CHANNEL;
00271 
00291 int
00292 Sadie_General_GetPixelCmd (ClientData client_data, Tcl_Interp *interp,
00293                            int objc, Tcl_Obj * const objv[])
00294 {
00295   uint32_t xval, yval, band;
00296   IMAGE *theimg = NULL;
00297   Tcl_Obj * channel_subset[MAX_DISPLAY_CHANNEL];
00298   int err = TCL_OK;
00299 
00300   if (objc != 4)
00301     {
00302       Tcl_WrongNumArgs (interp, 1, objv, "image_ID xcoord ycoord");
00303       return TCL_ERROR;
00304     }
00305   if ((GetSadieImageFromObj (objv[1], &theimg) != TCL_OK)
00306       || (!CHECKIMG (theimg)) || (theimg->nbnd == 0))
00307     {
00308       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00309                         "couldn't identify SADIE image from input string.",
00310                         -1);
00311       return TCL_ERROR;
00312     }
00313   if ((GetSadieUintFromObj (interp, objv[2], &xval) != TCL_OK)
00314       || (GetSadieUintFromObj (interp, objv[3], &yval) != TCL_OK))
00315     return TCL_ERROR;
00316   band = 0;
00317   while ((err == TCL_OK)
00318          && (band < theimg->nbnd) && (band < max_display_channel))
00319     {
00320       channel_subset[band]
00321         = Tcl_NewDoubleObj (theimg->data[band][yval][xval]);
00322       if (channel_subset[band] == NULL)
00323         err = TCL_ERROR;
00324       else
00325         band++;
00326     }
00327   if (err != TCL_OK)
00328     {
00329       while (band != 0)
00330         Tcl_DecrRefCount (channel_subset[--band]);
00331     }
00332   else
00333     {
00334       while (band < max_display_channel)
00335         channel_subset[band++] = channel_subset[0];
00336       Tcl_SetListObj (Tcl_GetObjResult (interp),
00337                       max_display_channel, channel_subset);
00338     }
00339   return err;
00340 }
00341 
00358 int
00359 Sadie_General_SetNameCmd (ClientData client_data, Tcl_Interp *interp,
00360                           int objc, Tcl_Obj * const objv[])
00361 {
00362   IMAGE *theimg;
00363 
00364   if (objc != 3)
00365     {
00366       Tcl_WrongNumArgs (interp, 1, objv, "image_ID name");
00367       return TCL_ERROR;
00368     }
00369   if ((GetSadieImageFromObj (objv[1], &theimg) != TCL_OK)
00370       || (!CHECKIMG (theimg)))
00371     {
00372       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00373                         "couldn't identify SADIE image from input string.",
00374                         -1);
00375       return TCL_ERROR;
00376     }
00377   strncpy (theimg->text, Tcl_GetString(objv[2]), TLEN - 1);
00378   return TCL_OK;
00379 }
00380 
00391 int
00392 Sadie_General_IndexImageCmd (ClientData client_data, Tcl_Interp *interp,
00393                              int objc, Tcl_Obj * const objv[])
00394 {
00395   int err = 0;
00396   IMAGE *theimg;
00397   char msg[SLEN];
00398   const char *dkey;
00399 
00400   if (objc != 2)
00401     {
00402       Tcl_WrongNumArgs (interp, 1, objv, "image_ID");
00403       return TCL_ERROR;
00404     }
00405   if ((GetSadieImageFromObj (objv[1], &theimg) != TCL_OK)
00406       || (GetSadieDkeyFromObj (objv[1], &dkey) != TCL_OK)
00407       || (!CHECKIMG (theimg)))
00408     {
00409       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00410                         "couldn't identify SADIE image from input string.",
00411                         -1);
00412       return TCL_ERROR;
00413     }
00414   err = sad_put_doc (global_doclist, dkey, 8, theimg);
00415   if (err)
00416     {
00417       snprintf (msg, SLEN - 1,
00418                 "Sadie_General_IndexImage failed to index the image: ID = %s, error = %d",
00419                 Tcl_GetString (objv[1]), err);
00420       Tcl_SetStringObj (Tcl_GetObjResult (interp), msg, -1);
00421       return TCL_ERROR;
00422     }
00423   return TCL_OK;
00424 }
00425 
00432 int
00433 Sadie_General_Init (Tcl_Interp *interp)
00434 {
00435   Tcl_CreateObjCommand (interp, "Sadie_General_Close",
00436                         Sadie_General_CloseCmd, NULL, NULL);
00437   Tcl_CreateObjCommand (interp, "Sadie_General_InitializeProg",
00438                         Sadie_General_InitializeProgCmd, NULL, NULL);
00439   Tcl_CreateObjCommand(interp, "Sadie_General_FinishProg",
00440                        Sadie_General_FinishProgCmd, NULL, NULL);
00441   Tcl_CreateObjCommand (interp, "Sadie_General_Width",
00442                         Sadie_General_WidthCmd, NULL, NULL);
00443   Tcl_CreateObjCommand (interp, "Sadie_General_Height",
00444                         Sadie_General_HeightCmd, NULL, NULL);
00445   Tcl_CreateObjCommand (interp, "Sadie_General_Gmin",
00446                         Sadie_General_GminCmd, NULL, NULL);
00447   Tcl_CreateObjCommand (interp, "Sadie_General_Gmax",
00448                         Sadie_General_GmaxCmd, NULL, NULL);
00449   Tcl_CreateObjCommand (interp, "Sadie_General_GetNumBands",
00450                         Sadie_General_GetNumBandsCmd, NULL, NULL);
00451   Tcl_CreateObjCommand (interp, "Sadie_General_GetPixel",
00452                         Sadie_General_GetPixelCmd, NULL, NULL);
00453   Tcl_CreateObjCommand (interp, "Sadie_General_SetName",
00454                         Sadie_General_SetNameCmd, NULL, NULL);
00455   Tcl_CreateObjCommand (interp, "Sadie_General_IndexImage",
00456                         Sadie_General_IndexImageCmd, NULL, NULL);
00457   return TCL_OK;
00458 }
00459 

Generated on Fri Jul 8 14:55:01 2005 for tclSadie by  doxygen 1.4.2