IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33587 for trunk


Ignore:
Timestamp:
Mar 21, 2012, 3:59:25 PM (14 years ago)
Author:
bills
Message:

In psphotMatchSourcesAddMissing cache the copies of footprints made for missing
sources so that they can be reused for missing sources on an image that share
the same footprint.

File:
1 edited

Legend:

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

    r32996 r33587  
    33bool psphotMatchSourcesAddMissing (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects);
    44bool psphotMatchSourcesSetIDs (psArray *objects);
     5
     6static psArray     *psphotMatchFootprintCacheAlloc (int nImages);
     7static pmFootprint *psphotMatchLookupFootprint (psArray *cache, int footprintID, int imageID);
     8static pmFootprint *psphotMatchCopyFootprint (psArray *cache, pmFootprint *footprint, int imageID, psImage *image, psArray *footprints);
    59 
    610psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view, const char *filerule)
     
    193197    // vector to track if source for an image is found
    194198    psVector *found = psVectorAlloc(nImages, PS_TYPE_U8);
     199    psArray *footprintCache = psphotMatchFootprintCacheAlloc(nImages);
    195200
    196201    for (int i = 0; i < objects->n; i++) {
     
    219224
    220225        // we make a copy of the largest footprint; this will be used for all new sources associated with this object
    221         pmFootprint *footprint = NULL;
     226        pmFootprint *largestFootprint = NULL;
    222227        if (iSpansMax != -1) { // copy the footprint info
    223228            pmSource *src = obj->sources->data[iSpansMax];
     
    226231            psAssert(src->peak->footprint->nspans == nSpansMax, "wrong footprint?");
    227232           
    228             // we only care about the spans, do not worry about the image of this footprint
    229             footprint = pmFootprintCopyData(src->peak->footprint, NULL);
     233            largestFootprint = src->peak->footprint;
    230234        }
    231235
     
    248252           
    249253            // assign to a footprint on this readout->image
    250             if (footprint) {
    251                 peak->footprint = pmFootprintCopyData(footprint, readout->image);
    252 
    253                 // the peak does not claim ownership of the footprint (it does not free it). save a copy of this
    254                 // footprint on detections->footprints so we can free it later
    255                 psArrayAdd(detections->footprints, 100, peak->footprint);
    256                 psFree (peak->footprint);
     254            if (largestFootprint) {
     255                // we save the copies that we make of the of the footprints in a hash so that we can reuse them
     256                // for all sources that share the fooprint. Without this we had serious memory explosion in
     257                // dense fields with lots of footprints (spans are small but when you have enough of them ...)
     258                peak->footprint = psphotMatchLookupFootprint(footprintCache, largestFootprint->id, index);
     259                if (!peak->footprint) {
     260                    // the peak does not claim ownership of the footprint (it does not free it).
     261                    // psphotMatchCopyFootprint saves a copy of this
     262                    // footprint on detections->footprints so we can free it later
     263                    peak->footprint = psphotMatchCopyFootprint(footprintCache, largestFootprint,
     264                                            index, readout->image, detections->footprints);
     265                }
    257266            }
    258267           
     
    272281            pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER);
    273282
     283#if (0)
     284            fprintf(stderr, "Add mising source for obj: %5d %5d image: %d flux: %f size: %4d %4d\n",
     285                                                      i, obj->id, index, peakFlux, source->pixels->numRows, source->pixels->numCols);
     286#endif
     287
    274288            peak->assigned = true;
    275289            pmPhotObjAddSource(obj, source);
     
    277291            psFree (source);
    278292        }
    279         psFree (footprint);
    280     }
     293    }
     294    psFree(footprintCache);
    281295
    282296    // how many sources do we have now?
     
    309323    return true;
    310324}
     325
     326// Cache of footprints created for unmatched sources.
     327static psArray * psphotMatchFootprintCacheAlloc (int nImages) {
     328    psArray *cache = psArrayAlloc(nImages);
     329    for (int i = 0; i < nImages; i++) {
     330        psHash *hash = psHashAlloc(5000);
     331        cache->data[i] = hash;
     332    }
     333    return cache;
     334}
     335
     336// Find copy of footprint with given ID made for a given image
     337static pmFootprint *psphotMatchLookupFootprint (psArray *cache, int footprintID, int imageID) {
     338    psHash *hash = (psHash *) cache->data[imageID];
     339
     340    psAssert(hash != NULL, "missing hash for image %d", imageID);
     341
     342    // footprintID is the id of the original footprint.
     343    char key[32];
     344    sprintf(key, "%d", footprintID);
     345
     346    // The footprints in our hashes are the copies of that footprint for the respective images
     347    pmFootprint *copy = psHashLookup(hash, key);
     348
     349    return copy;
     350}
     351
     352// Create a copy of a given footprint for a given image
     353static pmFootprint *psphotMatchCopyFootprint (psArray *cache, pmFootprint *footprint, int imageID, psImage *image, psArray *footprints) {
     354
     355    psAssert((imageID >= 0 && imageID < cache->n), "invalid imageID %d", imageID);
     356
     357    psHash *hash = (psHash *) cache->data[imageID];
     358
     359    psAssert(hash != NULL, "missing hash for image %d", imageID);
     360
     361    char key[32];
     362    sprintf(key, "%d", footprint->id);
     363
     364    pmFootprint *copy = pmFootprintCopyData (footprint, image);
     365
     366    // save a copy in this image's hash
     367    psHashAdd(hash, key, copy);
     368
     369    // save a copy of this footprint on the passed in footprints Array so we can free it later
     370    psArrayAdd(footprints, 100, copy);
     371
     372    // drop our ref
     373    psFree(copy);
     374
     375    return copy;
     376}
Note: See TracChangeset for help on using the changeset viewer.