Changeset 17516 for trunk/psphot/src/pmFootprintsAssignPeaks.c
- Timestamp:
- May 4, 2008, 2:10:40 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/pmFootprintsAssignPeaks.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/pmFootprintsAssignPeaks.c
r17443 r17516 8 8 psErrorCode 9 9 pmFootprintsAssignPeaks(psArray *footprints, // the pmFootprints 10 const psArray *peaks) { // the pmPeaks10 const psArray *peaks) { // the pmPeaks 11 11 assert (footprints != NULL); 12 12 assert (footprints->n == 0 || pmFootprintTest(footprints->data[0])); … … 54 54 55 55 psFree(ids); 56 // 56 57 57 // Make sure that peaks within each footprint are sorted and unique 58 //59 58 for (int i = 0; i < footprints->n; i++) { 59 60 60 pmFootprint *fp = footprints->data[i]; 61 62 // XXX are we allowed to have peak-less footprints?? 63 if (!fp->peaks->n) continue; 64 61 65 fp->peaks = psArraySort(fp->peaks, pmPeakSortBySN); 62 66 63 for (int j = 1; j < fp->peaks->n; j++) { // check for duplicates 64 if (fp->peaks->data[j] == fp->peaks->data[j-1]) { 65 (void)psArrayRemoveIndex(fp->peaks, j); 66 j--; // we moved everything down one 67 // XXX EAM : the algorithm below should be much faster than using psArrayRemove if 68 // the number of peaks in the footprint is large, or if there are no duplicates. 69 // if we have a lot of small-number peak arrays with duplicates, this may be 70 // slower. 71 72 // track the number of good peaks in the footprint 73 int nGood = 1; 74 75 // check for duplicates 76 // on first pass, we set the index to NULL if peak is a duplicate 77 // XXX EAM : this can leave behind duplicates of the same S/N 78 // (if sorted list has A, B, A, B ...) 79 for (int j = 1; j < fp->peaks->n; j++) { 80 if (fp->peaks->data[j] == fp->peaks->data[nGood]) { 81 // everything on the array has its own mem reference; free and drop this one 82 psFree (fp->peaks->data[j]); 83 fp->peaks->data[j] = NULL; 84 } else { 85 nGood ++; 67 86 } 68 87 } 88 89 // no deleted peaks, go to next footprint 90 if (nGood == fp->peaks->n) continue; 91 92 int nKeep = 0; 93 94 psArray *goodPeaks = psArrayAlloc (nGood); 95 // on second pass, save the good peaks 96 for (int j = 0; j < fp->peaks->n; j++) { // check for duplicates 97 if (fp->peaks->data[j] == NULL) continue; 98 // transfer the data (NULL to avoid double free) 99 // this is only slightly sleazy 100 goodPeaks->data[nKeep] = fp->peaks->data[j]; 101 fp->peaks->data[j] = NULL; 102 nKeep ++; 103 } 104 psAssert (nGood == nKeep, "mis-counted nKeep or nGood"); 105 106 // free the old (now NULL-filled) array 107 psFree (fp->peaks); 108 fp->peaks = goodPeaks; 69 109 } 110 111 // (void)psArrayRemoveIndex(fp->peaks, j); 112 70 113 71 114 return PS_ERR_NONE;
Note:
See TracChangeset
for help on using the changeset viewer.
