IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 7, 2006, 8:52:03 PM (20 years ago)
Author:
eugene
Message:

extensive cleanup of memory handling : no more leaks!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotBasicDeblend.c

    r6319 r6379  
    11# include "psphot.h"
    22
    3 // 2006.02.02 : no leaks? (creates source->blend entries)
    4 // XXX if I free sources, I still have 54 leaks?
     3// 2006.02.07 : no leaks
    54bool psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky) {
    65
     
    3534    // this results in an index of increasing SN
    3635
    37     // temporary array for overlapping objects we find
    38     psArray *overlap = psArrayAlloc (100);
    39 
    4036    // examine sources in decreasing SN order
    4137    for (int i = sources->n - 1; i >= 0; i--) {
     
    4541        if (source->mode & PM_SOURCE_BLEND) continue;
    4642
     43        // temporary array for overlapping objects we find
     44        // XXX psArrayAlloc should set ->n to 0 *and* all objects to NULL
     45        // XXX I need a psArrayEmpty function to free the elements without the array
     46        // XXX then, I could allocate 'overlap' once outside the loop and only
     47        // XXX clear at the end of each loop
     48        psArray *overlap = psArrayAlloc (100);
    4749        overlap->n = 0;
    4850
     
    7375        }
    7476
     77        if (overlap->n == 0) {
     78            psFree (overlap);
     79            continue;
     80        }
     81
     82        // this source has overlapping neighbors, check for actual blends
    7583        // generate source contour (1/4 peak counts)
    76         if (overlap->n > 0) {
    77             // set the threshold based on user inputs
    78             threshold = FRACTION * (source->peak->counts - source->moments->Sky) + source->moments->Sky;
    79             threshold = PS_MAX (threshold, minThreshold);
     84        // set the threshold based on user inputs
     85        threshold = FRACTION * (source->peak->counts - source->moments->Sky) + source->moments->Sky;
     86        threshold = PS_MAX (threshold, minThreshold);
    8087
    81             // generate a basic contour (set of x,y coordinates at-or-below flux level)
    82             psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold);
    83             if (contour == NULL) continue;
     88        // generate a basic contour (set of x,y coordinates at-or-below flux level)
     89        psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold);
     90        if (contour == NULL) {
     91            psFree (overlap);
     92            continue;
     93        }
    8494
    85             // the source contour consists of two vectors, xv and yv.  the contour is
    86             // a series of coordinate pairs, (xv[i],yv[i]) & (xv[i+1],yv[i+1]).  both
    87             // coordinate pairs have the same yv[] value, with xv[i] corresponding to
    88             // the left boundary and xv[i+1] corresponding to the right boundary
     95        // the source contour consists of two vectors, xv and yv.  the contour is
     96        // a series of coordinate pairs, (xv[i],yv[i]) & (xv[i+1],yv[i+1]).  both
     97        // coordinate pairs have the same yv[] value, with xv[i] corresponding to
     98        // the left boundary and xv[i+1] corresponding to the right boundary
    8999
    90             psVector *xv = contour->data[0];
    91             psVector *yv = contour->data[1];
    92             for (int k = 0; k < overlap->n; k++) {
    93                 testSource = overlap->data[k];
    94                 if (testSource->peak->counts > source->peak->counts) continue;
    95                 for (int j = 0; j < xv->n; j+=2) {
    96                     if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue;
    97                     if (xv->data.F32[j+0] > testSource->peak->x) break;
    98                     if (xv->data.F32[j+1] < testSource->peak->x) break;
     100        psVector *xv = contour->data[0];
     101        psVector *yv = contour->data[1];
     102        for (int k = 0; k < overlap->n; k++) {
     103            testSource = overlap->data[k];
     104            if (testSource->peak->counts > source->peak->counts) continue;
     105            for (int j = 0; j < xv->n; j+=2) {
     106                if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue;
     107                if (xv->data.F32[j+0] > testSource->peak->x) break;
     108                if (xv->data.F32[j+1] < testSource->peak->x) break;
    99109
    100                     testSource->mode |= PM_SOURCE_BLEND;
     110                testSource->mode |= PM_SOURCE_BLEND;
    101111
    102                     // add this to the list of source->blends
    103                     if (source->blends == NULL) {
    104                         source->blends = psArrayAlloc (16);
    105                         source->blends->n = 0;
    106                     }
    107                     psArrayAdd (source->blends, 16, testSource);
     112                // add this to the list of source->blends
     113                if (source->blends == NULL) {
     114                    source->blends = psArrayAlloc (16);
     115                    source->blends->n = 0;
     116                }
    108117
    109                     Nblend ++;
    110                     j = xv->n;
    111                 }
    112             } 
    113             psFree (contour);
    114         }
     118                psArrayAdd (source->blends, 16, testSource);
     119
     120                Nblend ++;
     121                j = xv->n;
     122            }
     123        } 
     124        psFree (overlap);
     125        psFree (contour);
    115126    }
    116127    psLogMsg ("psphot.deblend", 3, "identified %d blended objects (%f sec)\n", Nblend, psTimerMark ("psphot"));
    117128
    118     char *breakPt = psMetadataLookupPtr (&status, config, "BREAK_POINT");
     129    char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT");
    119130    if (!strcasecmp (breakPt, "DEBLEND")) exit (0);
    120131
    121132    psFree (SN);
    122133    psFree (index);
    123     psFree (overlap);
    124    
    125134    return true;
    126135}
Note: See TracChangeset for help on using the changeset viewer.