Main Page   Data Structures   File List   Data Fields   Globals  

Sadie_Plot.c

Go to the documentation of this file.
00001 /*
00002 ##########################################
00003 # Sadie_Plot.c -
00004 #   Set of routines for creating plots of SADIE data in the
00005 #   session log through tcl/tk.
00006 #
00007 # RCS: $Id: Sadie_Plot.c,v 2.2 1999/03/20 00:34:26 conner Exp $ 
00008 # 
00009 # Digital Image Analysis Lab
00010 # Dept. of Electrical and Computer Engineering
00011 # University of Arizona
00012 ##########################################
00013 */
00014 
00015 
00016 
00017 #include <tcl.h>
00018 #include <tk.h>
00019 #include <stdio.h>
00020 #include <string.h>
00021 #include "sadie.h"
00022 
00023 
00024 /* RCS Indentification information */
00025 static char rcsid[] = "$Id: Sadie_Plot.c,v 2.2 1999/03/20 00:34:26 conner Exp $";
00026 
00027 #define FALSE 0
00028 #define TRUE  1
00029 
00030 
00031 extern Tcl_Interp* MainTclInterp;
00032 
00033 
00034 int **x_array_buffer;     /* The data where info is stored      */
00035 int point;                /* Counter for points used            */
00036 int count_point;          /* Flag decide to count or fill array */
00037 int plotcount = 0;
00038 
00039 
00040 int Sadie_Plot_ProfileCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00041 {
00042 
00043     int i, j;
00044     int startx, endx;
00045     int starty, endy;
00046     int option;
00047     int inimgaddr;
00048     IMAGE *inimg;
00049     char   msg[SLEN];
00050     PIXEL **arrays=NULL;
00051     char minlbl[20],maxlbl[20];
00052     
00053     if( argc <= 6 ) {
00054         return TCL_ERROR;
00055     }
00056     
00057     
00058     sscanf(argv[1], "%x", &inimgaddr);
00059     inimg = (IMAGE *) inimgaddr;
00060     
00061     if( Tcl_GetInt (interp, argv[2], &startx) != TCL_OK ) {
00062         return TCL_ERROR;
00063     }
00064     
00065     if( Tcl_GetInt (interp, argv[3], &starty) != TCL_OK ) {
00066         return TCL_ERROR;
00067     }
00068     
00069     if( Tcl_GetInt (interp, argv[4], &endx) != TCL_OK ) {
00070         return TCL_ERROR;
00071     }
00072     
00073     if( Tcl_GetInt (interp, argv[5], &endy) != TCL_OK ) {
00074         return TCL_ERROR;
00075     }
00076     
00077     if( Tcl_GetInt (interp, argv[6], &option) != TCL_OK ) {
00078         return TCL_ERROR;
00079     }
00080 
00081     
00082     
00083     /* check input */
00084     if (option != UNIT  &&  option != NORM  &&  option != LOG) {
00085         MESSAGE('E'," Option must be one of UNIT, NORM, or LOG.");
00086         return TCL_ERROR;
00087     }
00088     
00089     
00090     /* Count points*/
00091     count_point = TRUE;
00092     point = 0;
00093     brshnm(startx,starty,endx, endy);
00094     
00095     /* Allocate memory */
00096     x_array_buffer = (int **) malloc(point*sizeof(int  * ));
00097     if (x_array_buffer == (int **) NULL){
00098         sprintf(msg,"No memory for x_array_buffer");
00099         MESSAGE('E',msg);
00100         goto the_end;
00101     }
00102         
00103     for  (i = 0; i < point; i++){
00104         x_array_buffer[i] = (int  *) calloc(2, sizeof(int));
00105         if (x_array_buffer[i] == (int) NULL){
00106             sprintf (msg,"No memory for element %d",x_array_buffer[i]);
00107             MESSAGE('E',msg);
00108             goto the_end;
00109         }
00110     }
00111     
00112     /* Fill array */ 
00113     count_point = FALSE;
00114     point = 0;
00115     brshnm(startx,starty,endx, endy);
00116     
00117     
00118     /* Allocate memory for plotting */
00119     arrays = (PIXEL**)malloc(inimg->nbnd * sizeof(PIXEL*));
00120     if (!arrays) {
00121         MESSAGE('E'," Error allocating memory for plotting!");
00122         goto the_end;
00123     }
00124     for (i=0; i<inimg->nbnd; i++) {
00125         arrays[i] = NULL;
00126         arrays[i] = (PIXEL*) malloc(point * sizeof(PIXEL));
00127         if (!arrays[i]) {
00128             MESSAGE('E'," Error allocating memory for plotting!");
00129             goto the_end;
00130         }
00131     }
00132     
00133     /* Fill the plot array */
00134     for (i=0; i<inimg->nbnd; i++) {
00135         for (j=0; j < point; j++) {
00136             arrays[i][j] = inimg->data[i][x_array_buffer[j][1]][x_array_buffer[j][0]];
00137         }
00138     }
00139     
00140     sprintf(minlbl,"(%d,%d)",startx,starty);
00141     sprintf(maxlbl,"(%d,%d)",endx,endy);
00142     PLOT(arrays,inimg->nbnd,point,minlbl,maxlbl,option);
00143     
00144     if (NAMES) {
00145         MESSAGE('I'," ");
00146         MESSAGE('I'," ...............");
00147     }
00148     
00149  the_end:
00150     
00151     /* Free Array */
00152     for (i=0; i < point; i++){
00153         free(x_array_buffer[i]);
00154         x_array_buffer[i] = NULL;
00155     }
00156     
00157     free(x_array_buffer);
00158     x_array_buffer = NULL;
00159     
00160     if (arrays) {
00161         for (i=0; i<inimg->nbnd; i++) {
00162             if (arrays[i]) free(arrays[i]);
00163             arrays[i] = NULL;
00164         }
00165         free(arrays);
00166         arrays=NULL;
00167     }
00168     
00169     return TCL_OK;
00170     
00171 }
00172 
00173 
00174 
00175 int Sadie_Plot_StatisticsCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00176 {
00177     int imgaddr;
00178     IMAGE *in;
00179     int incr, nbins, matrix;
00180     double *mean=0, *dev=0, *cov=0, *cor=0;
00181     PIXEL  *gmin=0, *gmax=0, *grng=0;
00182     long   *zero=0;
00183     int rangeoption;
00184     PIXEL rangemin, rangemax;
00185     double tempval;
00186     
00187     if( argc <= 7 ) {
00188         return TCL_ERROR;
00189     }
00190     
00191     sscanf(argv[1], "%x", &imgaddr);
00192     in = (IMAGE *) imgaddr;
00193     
00194     if( Tcl_GetInt (interp, argv[2], &incr) != TCL_OK ) {
00195         return TCL_ERROR;
00196     }
00197     
00198     if( Tcl_GetInt (interp, argv[3], &nbins) != TCL_OK ) {
00199         return TCL_ERROR;
00200     }
00201     
00202     if( Tcl_GetInt (interp, argv[4], &matrix) != TCL_OK ) {
00203         return TCL_ERROR;
00204     }
00205     
00206     if( Tcl_GetInt (interp, argv[5], &rangeoption) != TCL_OK ) {
00207         return TCL_ERROR;
00208     }
00209     
00210     if( Tcl_GetDouble (interp, argv[6], &tempval) != TCL_OK ) {
00211         return TCL_ERROR;
00212     }
00213     rangemin = (PIXEL)tempval;
00214     
00215     if( Tcl_GetDouble (interp, argv[7], &tempval) != TCL_OK ) {
00216         return TCL_ERROR;
00217     }
00218     rangemax = (PIXEL)tempval;
00219     
00220     if (!CHECKIMG(in)) {
00221         Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00222         return TCL_ERROR;
00223     }
00224     if (rangeoption != IGNORE  &&  rangeoption != INCLUDE  &&  rangeoption != EXCLUDE) {
00225         MESSAGE('E'," Option must be one of IGNORE, INCLUDE, or EXCLUDE.");
00226         return TCL_ERROR;
00227     }
00228     
00229     RANGE(in);
00230     
00231     /* allocate space */
00232     if (!(mean=(double *)malloc(in->nbnd*sizeof(double)))) {
00233         MESSAGE ('E', " Memory request failed.");
00234         goto the_end;
00235     }
00236     if (!(dev=(double *)malloc(in->nbnd*sizeof(double)))) {
00237         MESSAGE ('E', " Memory request failed.");
00238         goto the_end;
00239     }
00240     if (!(gmin=(PIXEL *)malloc(in->nbnd*sizeof(PIXEL)))) {
00241         MESSAGE ('E', " Memory request failed.");
00242         goto the_end;
00243     }
00244     if (!(gmax=(PIXEL *)malloc(in->nbnd*sizeof(PIXEL)))) {
00245         MESSAGE ('E', " Memory request failed.");
00246         goto the_end;
00247     }
00248     if (!(grng=(PIXEL *)malloc(in->nbnd*sizeof(PIXEL)))) {
00249         MESSAGE ('E', " Memory request failed.");
00250         goto the_end;
00251     }
00252     if (!(zero=(long *)malloc(in->nbnd*sizeof(long)))) {
00253         MESSAGE ('E', " Memory request failed.");
00254         goto the_end;
00255     }
00256     if (!(cov=(double *)malloc(in->nbnd*in->nbnd*sizeof(double)))) {
00257         MESSAGE('E'," Memory request failed.");
00258         goto the_end;
00259     }
00260     if (!(cor=(double *)malloc(in->nbnd*in->nbnd*sizeof(double)))) {
00261         MESSAGE('E'," Memory request failed.");
00262         goto the_end;
00263     }
00264     
00265     
00266     STATS(in,incr,nbins,rangeoption,rangemin,rangemax,mean,dev,gmin,gmax,grng,zero);
00267     
00268     if (matrix) COVAR(in,incr,cov,cor);
00269     
00270     
00271  the_end:
00272     if (cov)   free(cov);
00273     if (cor)   free(cor);
00274     if (mean)  free(mean);
00275     if (dev)   free(dev);
00276     if (gmin)  free(gmin);
00277     if (gmax)  free(gmax);
00278     if (grng)  free(grng);
00279     if (zero)  free(zero);
00280     
00281     return TCL_OK;
00282 }
00283 
00284 
00285 int Sadie_Plot_CreateROICmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00286 {
00287   int imgaddr;
00288   IMAGE *in;
00289   char *name;
00290   int incr, nlev, matrix;
00291   int point1x, point2x, point1y, point2y;
00292   int xbgn, ybgn, xend, yend;
00293 
00294   if( argc <= 9 ) {
00295     return TCL_ERROR;
00296   }
00297 
00298   sscanf(argv[1], "%x", &imgaddr);
00299   in = (IMAGE *) imgaddr;
00300 
00301   if( Tcl_GetInt (interp, argv[2], &incr) != TCL_OK ) {
00302     return TCL_ERROR;
00303   }
00304 
00305   if( Tcl_GetInt (interp, argv[3], &nlev) != TCL_OK ) {
00306     return TCL_ERROR;
00307   }
00308 
00309   if( Tcl_GetInt (interp, argv[4], &matrix) != TCL_OK ) {
00310     return TCL_ERROR;
00311   }
00312 
00313   if( Tcl_GetInt (interp, argv[5], &point1x) != TCL_OK ) {
00314     return TCL_ERROR;
00315   }
00316   if( Tcl_GetInt (interp, argv[6], &point1y) != TCL_OK ) {
00317     return TCL_ERROR;
00318   }
00319   if( Tcl_GetInt (interp, argv[7], &point2x) != TCL_OK ) {
00320     return TCL_ERROR;
00321   }
00322   if( Tcl_GetInt (interp, argv[8], &point2y) != TCL_OK ) {
00323     return TCL_ERROR;
00324   }
00325   
00326   name = argv[9];
00327 
00328   if (!CHECKIMG(in)) {
00329     Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00330     return TCL_ERROR;
00331   }
00332 
00333   RANGE(in);
00334 
00335   xbgn = min(point1x, point2x);
00336   xend = max(point1x, point2x);
00337   ybgn = min(point1y, point2y);
00338   yend = max(point1y, point2y);
00339 
00340   CREATE_ROI(in, name, xbgn, ybgn, xend, yend, matrix, incr, nlev);
00341 
00342   the_end:
00343   
00344   return TCL_OK;
00345 }
00346 
00347 
00348 
00349 int Sadie_Plot_PlotArrayCmd(PIXEL *array, int arraysize)
00350 {
00351     int i, j;
00352     PIXEL gmin, gmax;
00353     int minval, maxval;
00354     char   minlbl[20], maxlbl[20];
00355 
00356 
00357     /* Find min and max plot values */
00358     gmax = gmin = array[0];
00359     for (i=0; i < arraysize; i++) {
00360        gmin = min(gmin,array[i]);
00361        gmax = max(gmax,array[i]);
00362     }
00363   
00364     minval = (int) rnd(gmin);
00365     maxval = (int) rnd(gmax);
00366 
00367     sprintf(minlbl,"%d",minval);
00368     sprintf(maxlbl,"%d",maxval);
00369 
00370     PLOT(&array,1,arraysize,(char *)minlbl,(char *)maxlbl,NORM);
00371 }
00372 
00373 
00374 
00375 
00376 /*************************************************************************
00377  *
00378  * This procedure initializes the the Sadie_Plot procedures when
00379  * this package is loaded.
00380  *
00381  *************************************************************************/
00382 int Sadie_Plot_Init(Tcl_Interp *interp) {
00383   Tcl_CreateCommand(interp, "Sadie_Plot_Profile", Sadie_Plot_ProfileCmd, 
00384         (ClientData) NULL, NULL);
00385   Tcl_CreateCommand(interp, "Sadie_Plot_Statistics", Sadie_Plot_StatisticsCmd, 
00386         (ClientData) NULL, NULL);
00387   Tcl_CreateCommand(interp, "Sadie_Plot_CreateROI", Sadie_Plot_CreateROICmd, 
00388         (ClientData) NULL, NULL);
00389   
00390   return TCL_OK;
00391 }
00392 

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