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

tclSadie_ROI.c

Go to the documentation of this file.
00001 
00017 /* This file is part of tclSadie.
00018 
00019    tclSadie is free software; you can redistribute it and/or modify it
00020    under the terms of the GNU General Public License as published by
00021    the Free Software Foundation; either version 2 of the License, or
00022    (at your option) any later version.
00023 
00024    tclSadie is distributed in the hope that it will be useful, but
00025    WITHOUT ANY WARRANTY; without even the implied warranty of
00026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027    General Public License for more details.
00028 
00029    You should have received a copy of the GNU General Public License
00030    along with tclSadie; if not, write to the Free Software Foundation,
00031    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.  */
00032 
00033 #if HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif /* HAVE_CONFIG_H */
00036 #include <sadie.h>
00037 #include "Sadie_Index.h"
00038 #include "tclSadie_ROI.h"
00039 #if WITH_DMALLOC
00040 #include <dmalloc.h>
00041 #endif /* WITH_DMALLOC */
00042 
00044 extern sad_doclistp_t global_doclist;
00045 
00047 static const char roiprop[] = ROI_PROPERTY_NAME;
00048 
00056 static void
00057 roi_destruct (void *data)
00058 {
00059   ROIPtr rlist, victim;
00060   
00061   if (data != NULL)
00062     {
00063       rlist = (ROIPtr) data;
00064       while (rlist)
00065         {
00066           victim = rlist;
00067           free (victim->name);
00068           free (victim->zero);
00069           free (victim->gmin);
00070           free (victim->gmax);
00071           free (victim->mean);
00072           free (victim->dev);
00073           free (victim->cov);
00074           free (victim->cor);
00075           rlist = rlist->next;
00076           free (victim);
00077         }
00078     }
00079 }
00080 
00082 static const ROI null_roi =
00083   { 0, 0, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
00084 
00106 void
00107 CREATE_ROI (IMAGE *in, const char *name, const char *dkey,
00108             uint32_t xbgn, uint32_t ybgn, uint32_t xend, uint32_t yend,
00109             int matrix, uint32_t inc, uint32_t nlev)
00110 {
00111   char msg[SLEN];
00112   uint32_t i, j, k;
00113   uint64_t nval, n;
00114   PIXEL *gval = NULL;
00115   ROIPtr r = NULL;
00116   ROIPtr s = NULL;
00117 
00118   /* check input */
00119   if (!CHECKIMG (in))
00120     {
00121       MESSAGE('E', " Can't identify input image.");
00122       return;
00123     }
00124   if (!name)
00125     {
00126       MESSAGE('E', " Can't get a name for the region.");
00127       return;
00128     }
00129   if (!dkey)
00130     {
00131       MESSAGE('E', " Can't get a hash string for the image.");
00132       return;
00133     }
00134   if (NAMES)
00135     {
00136       MESSAGE('I', "");
00137       MESSAGE('I', "CREATE_ROI");
00138       MESSAGE('I', "");
00139       sprintf(msg, " Region Name:                %s", name);
00140       MESSAGE('I',msg);
00141       sprintf(msg," Region Start Point:         ( %lu , %lu )",
00142               (unsigned long) xbgn + 1, (unsigned long) ybgn + 1);
00143       MESSAGE('I',msg);
00144       sprintf(msg," Region End Point:           ( %lu , %lu )",
00145               (unsigned long) xend + 1, (unsigned long) yend + 1);
00146       MESSAGE('I',msg);
00147       sprintf(msg," Region Height:              %lu pixels",
00148               (unsigned long) (yend - ybgn) + 1);
00149       MESSAGE('I',msg);
00150       sprintf(msg," Region Width:               %lu pixels",
00151               (unsigned long) (xend - xbgn) + 1);
00152       MESSAGE('I',msg);
00153       MESSAGE('I'," ...............");
00154     }
00155   /* Determine the number of pixels in the region */
00156   nval = (uint64_t)(1 + xend - xbgn) * (uint64_t)(1 + yend - ybgn);
00157   /* Allocate space for the array of pixel values */
00158   gval = malloc (in->nbnd * nval * sizeof (PIXEL));
00159   if (gval)
00160     {
00161       r = malloc (sizeof (ROI));
00162       if (r == NULL)
00163         free (gval);
00164       else
00165         *r = null_roi;
00166     }
00167   if ((gval == NULL) || (r == NULL))
00168     {
00169       MESSAGE ('E', "Memory request failed.");
00170       return;
00171     }
00172   if (!((r->name = malloc ((strlen (name) + 1) * sizeof(char)))
00173         && (r->zero = malloc (in->nbnd * sizeof (uint64_t)))
00174         && (r->gmin = malloc (in->nbnd * sizeof (PIXEL)))
00175         && (r->gmax = malloc (in->nbnd * sizeof (PIXEL)))
00176         && (r->mean = malloc (in->nbnd * sizeof (double)))
00177         && (r->dev = malloc (in->nbnd * sizeof (double)))
00178         && (!matrix
00179             || (r->cov = malloc (in->nbnd * in->nbnd * sizeof(double))))
00180         && (!matrix
00181             || (r->cor = malloc (in->nbnd * in->nbnd * sizeof(double))))))
00182     {
00183       if (r->cor)
00184         free (r->cor);
00185       if (r->cov)
00186         free (r->cov);
00187       if (r->dev)
00188         free (r->dev);
00189       if (r->mean)
00190         free (r->mean);
00191       if (r->gmax)
00192         free (r->gmax);
00193       if (r->gmin)
00194         free (r->gmin);
00195       if (r->zero)
00196         free (r->zero);
00197       if (r->name)
00198         free (r->name);
00199       free (r);
00200       MESSAGE ('E', "Memory request failed.");
00201     }
00202   else
00203     {
00204       strcpy (r->name,name);
00205       r->nval = nval;
00206       for (n = i = 0; i < in->nbnd; i++)
00207         {
00208           for (j = ybgn; j <= yend; j++)
00209             {
00210               for (k = xbgn; k <= xend; k++, n++)
00211                 gval[n] = in->data[i][j][k];
00212             }
00213         }
00214       ROISTATS (r->name, in->nbnd, nval, gval, inc, nlev, r->gmin, r->gmax,
00215                 r->mean, r->dev, r->zero, r->cov, r->cor);
00216       r->next = NULL;
00217       s = sad_get_doc_property (global_doclist, dkey, roiprop);
00218       if (s == NULL)
00219         {
00220           if (sad_put_doc_property (global_doclist, dkey, roiprop,
00221                                     roi_destruct, (void *) r)
00222               != 0)
00223           MESSAGE ('E', " Cannot put ROI property.");
00224         }
00225       else
00226         {
00227           while (s->next != NULL)
00228             s = s->next;
00229           s->next = r;
00230         }
00231     }
00232   free (gval);
00233 }
00234 
00235 
00236 
00237 
00238 

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