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

Sadie_Plot.c

Go to the documentation of this file.
00001 
00014 /* This file is part of tclSadie.
00015 
00016    tclSadie is free software; you can redistribute it and/or modify it
00017    under the terms of the GNU General Public License as published by
00018    the Free Software Foundation; either version 2 of the License, or
00019    (at your option) any later version.
00020 
00021    tclSadie is distributed in the hope that it will be useful, but
00022    WITHOUT ANY WARRANTY; without even the implied warranty of
00023    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024    General Public License for more details.
00025 
00026    You should have received a copy of the GNU General Public License
00027    along with tclSadie; if not, write to the Free Software Foundation,
00028    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.  */
00029 
00030 #if HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif /* HAVE_CONFIG_H */
00033 #include <tcl.h>
00034 #include <tk.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037 #include <sadie.h>
00038 #include "tclsadie.h"
00039 #include "bresenham.h"
00040 #include "tclSadie_ROI.h"
00041 #if WITH_DMALLOC
00042 #include <dmalloc.h>
00043 #endif /* WITH_DMALLOC */
00044 
00073 int
00074 Sadie_Plot_ProfileCmd (ClientData client_data, Tcl_Interp *interp,
00075                        int objc, Tcl_Obj * const objv[])
00076 {
00077   int startx, endx;
00078   int starty, endy;
00079   int option, off_the_end;
00080   size_t delta_x, delta_y, point, i, j;
00081   IMAGE *inimg = NULL;
00082   PIXEL *arrays = NULL;
00083   char minlbl[SLEN], maxlbl[SLEN];
00084   bresenham_linep_t profile = NULL;
00085   uint32_t profile_col, profile_row;
00086 
00087   if (objc != 7)
00088     {
00089       Tcl_WrongNumArgs (interp, 1, objv,
00090                         "image_id start_x start_y end_x end_y option_code");
00091       return TCL_ERROR;
00092     }
00093   if ((GetSadieImageFromObj (objv[1], &inimg) != TCL_OK)
00094       || (Tcl_GetIntFromObj (interp, objv[2], &startx) != TCL_OK)
00095       || (Tcl_GetIntFromObj (interp, objv[3], &starty) != TCL_OK)
00096       || (Tcl_GetIntFromObj (interp, objv[4], &endx) != TCL_OK)
00097       || (Tcl_GetIntFromObj (interp, objv[5], &endy) != TCL_OK)
00098       || (Tcl_GetIntFromObj (interp, objv[6], &option) != TCL_OK))
00099     return TCL_ERROR;
00100   /* check input */
00101   if ((option != UNIT) && (option != NORM) && (option != LOG))
00102     {
00103       MESSAGE ('E', " Option must be one of UNIT, NORM, or LOG.");
00104       return TCL_ERROR;
00105     }
00106   /* Count points*/
00107   delta_x = (startx < endx)
00108     ? ((size_t) endx - startx) : ((size_t) startx - endx);
00109   delta_y = (starty < endy)
00110     ? ((size_t) endy - starty) : ((size_t) starty - endy);
00111   point = 1 + ((delta_x < delta_y) ? delta_y : delta_x);
00112   /* Allocate memory for plotting */
00113   arrays = calloc (inimg->nbnd * point, sizeof (PIXEL));
00114   if (arrays == NULL)
00115     {
00116       MESSAGE ('E', " Error allocating memory for plotting!");
00117       return TCL_ERROR;
00118     }
00119   /* Fill the plot array */
00120   for (i = 0; i < inimg->nbnd; i++)
00121     {
00122       off_the_end = 0;
00123       profile = bresenham_from_s_coord (startx, starty, endx, endy);
00124       for (j = 0; (!off_the_end && (j < point)); j++)
00125         {
00126           off_the_end = bresenham_next (profile, &profile_col, &profile_row);
00127           arrays[i*point+j] = inimg->data[i][profile_row][profile_col];
00128         }
00129       demolish_bresenham (&profile);
00130       if (!off_the_end || j != point)
00131         {
00132           MESSAGE ('E',
00133                    " unexpected error when retrieving data for the profile.");
00134           free (arrays);
00135           return TCL_ERROR;
00136         }
00137     }
00138   snprintf (minlbl, SLEN - 1, "(%d,%d)", startx, starty);
00139   snprintf (maxlbl, SLEN - 1, "(%d,%d)", endx, endy);
00140   PLOT (arrays, inimg->nbnd, (uint32_t)point, minlbl, maxlbl, (short)option);
00141   if (NAMES)
00142     {
00143       MESSAGE ('I', " ");
00144       MESSAGE ('I', " ...............");
00145     }
00146   free(arrays);
00147   return TCL_OK;
00148 }
00149 
00179 int
00180 Sadie_Plot_StatisticsCmd (ClientData client_data, Tcl_Interp *interp,
00181                           int objc, Tcl_Obj * const objv[])
00182 {
00183   IMAGE *in = NULL;
00184   int incr, nbins, matrix;
00185   double *mean = NULL;
00186   double *dev = NULL;
00187   double *cov = NULL;
00188   double *cor = NULL;
00189   PIXEL *gmin = NULL;
00190   PIXEL *gmax = NULL;
00191   PIXEL *grng = NULL;
00192   uint64_t *zero = NULL;
00193   int rangeoption;
00194   PIXEL rangemin, rangemax;
00195   double tmp_rangemin, tmp_rangemax;
00196 
00197   if (objc != 8)
00198     {
00199       Tcl_WrongNumArgs (interp, 1, objv,
00200                         "image_id increment n_bins matrix range_option range_min range_max");
00201       return TCL_ERROR;
00202     }
00203   if ((GetSadieImageFromObj (objv[1], &in) != TCL_OK)
00204       || (Tcl_GetIntFromObj (interp, objv[2], &incr) != TCL_OK)
00205       || (Tcl_GetIntFromObj (interp, objv[3], &nbins) != TCL_OK)
00206       || (Tcl_GetIntFromObj (interp, objv[4], &matrix) != TCL_OK)
00207       || (Tcl_GetIntFromObj (interp, objv[5], &rangeoption) != TCL_OK)
00208       || (Tcl_GetDoubleFromObj (interp, objv[6], &tmp_rangemin) != TCL_OK)
00209       || (Tcl_GetDoubleFromObj (interp, objv[7], &tmp_rangemax) != TCL_OK))
00210     return TCL_ERROR;
00211   rangemin = (PIXEL) tmp_rangemin;
00212   rangemax = (PIXEL) tmp_rangemax;
00213   if (!CHECKIMG(in))
00214     {
00215       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00216                         "couldn't identify SADIE image from input string.",
00217                         -1);
00218       return TCL_ERROR;
00219     }
00220   if ((rangeoption != IGNORE) && (rangeoption != INCLUDE)
00221       && (rangeoption != EXCLUDE))
00222     {
00223       MESSAGE ('E', " Option must be one of IGNORE, INCLUDE, or EXCLUDE.");
00224       return TCL_ERROR;
00225     }
00226   RANGE (in);
00227   /* allocate space */
00228   if ((mean = calloc (in->nbnd, sizeof (double)))
00229       && (dev = calloc (in->nbnd, sizeof (double)))
00230       && (gmin = calloc (in->nbnd, sizeof (PIXEL)))
00231       && (gmax = calloc (in->nbnd, sizeof (PIXEL)))
00232       && (grng = calloc (in->nbnd, sizeof (PIXEL)))
00233       && (zero = calloc (in->nbnd, sizeof (uint64_t)))
00234       && (cov = calloc ((size_t) in->nbnd * in->nbnd, sizeof (double)))
00235       && (cor = calloc ((size_t) in->nbnd * in->nbnd, sizeof (double))))
00236     {
00237       STATS (in, incr, nbins, (short) rangeoption, rangemin, rangemax,
00238              mean, dev, gmin, gmax, grng, zero);
00239       if (matrix)
00240         COVAR (in, incr, cov, cor);
00241     }
00242   else
00243     MESSAGE ('E', " Memory request failed.");
00244   if (cov)
00245     free(cov);
00246   if (cor)
00247     free(cor);
00248   if (mean)
00249     free(mean);
00250   if (dev)
00251     free(dev);
00252   if (gmin) 
00253     free(gmin);
00254   if (gmax)
00255     free(gmax);
00256   if (grng)
00257     free(grng);
00258   if (zero)
00259     free(zero);
00260   return TCL_OK;
00261 }
00262 
00287 int
00288 Sadie_Plot_CreateROICmd (ClientData client_data, Tcl_Interp *interp,
00289                          int objc, Tcl_Obj * const objv[])
00290 {
00291   IMAGE *in = NULL;
00292   const char *name;
00293   uint32_t incr, nlev;
00294   int matrix;
00295   uint32_t point1x, point2x, point1y, point2y;
00296   uint32_t xbgn, ybgn, xend, yend;
00297   const char *dkey;
00298 
00299   if (objc != 10 )
00300     {
00301       Tcl_WrongNumArgs (interp, 1, objv,
00302                         "image_id increment n_levels matrix point1_x point1_y point2_x point2_y name");
00303       return TCL_ERROR;
00304     }
00305   if ((GetSadieImageFromObj (objv[1], &in) != TCL_OK)
00306       || (GetSadieDkeyFromObj (objv[1], &dkey) != TCL_OK)
00307       || (GetSadieUintFromObj (interp, objv[2], &incr) != TCL_OK)
00308       || (GetSadieUintFromObj (interp, objv[3], &nlev) != TCL_OK)
00309       || (Tcl_GetIntFromObj (interp, objv[4], &matrix) != TCL_OK)
00310       || (GetSadieUintFromObj (interp, objv[5], &point1x) != TCL_OK)
00311       || (GetSadieUintFromObj (interp, objv[6], &point1y) != TCL_OK)
00312       || (GetSadieUintFromObj (interp, objv[7], &point2x) != TCL_OK)
00313       || (GetSadieUintFromObj (interp, objv[8], &point2y) != TCL_OK))
00314     return TCL_ERROR;
00315   name = Tcl_GetString (objv[9]);
00316   if (!CHECKIMG (in))
00317     {
00318       Tcl_SetStringObj (Tcl_GetObjResult (interp),
00319                         "couldn't identify SADIE image from input string.",
00320                         -1);
00321       return TCL_ERROR;
00322     }
00323   RANGE (in);
00324   xbgn = min(point1x, point2x);
00325   xend = max(point1x, point2x);
00326   ybgn = min(point1y, point2y);
00327   yend = max(point1y, point2y);
00328   CREATE_ROI (in, name, dkey, xbgn, ybgn, xend, yend, matrix, incr, nlev);
00329   return TCL_OK;
00330 }
00331 
00338 int
00339 Sadie_Plot_Init (Tcl_Interp *interp)
00340 {
00341   Tcl_CreateObjCommand (interp, "Sadie_Plot_Profile",
00342                         Sadie_Plot_ProfileCmd, NULL, NULL);
00343   Tcl_CreateObjCommand(interp, "Sadie_Plot_Statistics",
00344                        Sadie_Plot_StatisticsCmd, NULL, NULL);
00345   Tcl_CreateObjCommand(interp, "Sadie_Plot_CreateROI",
00346                        Sadie_Plot_CreateROICmd, NULL, NULL);
00347   return TCL_OK;
00348 }
00349 

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