Changeset 33587
- Timestamp:
- Mar 21, 2012, 3:59:25 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSourceMatch.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotSourceMatch.c
r32996 r33587 3 3 bool psphotMatchSourcesAddMissing (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *objects); 4 4 bool psphotMatchSourcesSetIDs (psArray *objects); 5 6 static psArray *psphotMatchFootprintCacheAlloc (int nImages); 7 static pmFootprint *psphotMatchLookupFootprint (psArray *cache, int footprintID, int imageID); 8 static pmFootprint *psphotMatchCopyFootprint (psArray *cache, pmFootprint *footprint, int imageID, psImage *image, psArray *footprints); 5 9 6 10 psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view, const char *filerule) … … 193 197 // vector to track if source for an image is found 194 198 psVector *found = psVectorAlloc(nImages, PS_TYPE_U8); 199 psArray *footprintCache = psphotMatchFootprintCacheAlloc(nImages); 195 200 196 201 for (int i = 0; i < objects->n; i++) { … … 219 224 220 225 // 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; 222 227 if (iSpansMax != -1) { // copy the footprint info 223 228 pmSource *src = obj->sources->data[iSpansMax]; … … 226 231 psAssert(src->peak->footprint->nspans == nSpansMax, "wrong footprint?"); 227 232 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; 230 234 } 231 235 … … 248 252 249 253 // 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 } 257 266 } 258 267 … … 272 281 pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER); 273 282 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 274 288 peak->assigned = true; 275 289 pmPhotObjAddSource(obj, source); … … 277 291 psFree (source); 278 292 } 279 psFree (footprint); 280 }293 } 294 psFree(footprintCache); 281 295 282 296 // how many sources do we have now? … … 309 323 return true; 310 324 } 325 326 // Cache of footprints created for unmatched sources. 327 static 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 337 static 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 353 static 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.
