Changeset 18353
- Timestamp:
- Jun 27, 2008, 4:30:13 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ppStack/src/ppStackSources.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackSources.c
r18346 r18353 15 15 psRegion *bounds; // Bounding box for sources 16 16 psArray *sources; // Sources within region 17 psVector *indices; // Indices from tree to sources 17 18 psTree *tree; // kd tree with sources 18 19 } ppStackSourceList; … … 42 43 psFree(list->bounds); 43 44 psFree(list->sources); 45 psFree(list->indices); 44 46 psFree(list->tree); 45 47 } … … 48 50 // Returns number of valid sources 49 51 static long stackSourcesParse(psRegion **bounds, // Region to update with bounding box 50 psVector **x, psVector **y, // Vectors to return 52 psVector **x, psVector **y, // Coordinate vectors to return 53 psVector **indices, // Source indices to return 51 54 const psArray *sources // Input sources 52 55 ) … … 54 57 psAssert(bounds, "Must be given a region for bounding box"); 55 58 psAssert(x && y, "Must be given vectors"); 59 psAssert(indices, "Must be given indices"); 56 60 psAssert(sources, "Must be given sources"); 57 61 58 long num = sources->n; // Number of sources 59 *x = psVectorRecycle(*x, num, PS_TYPE_F32); 60 *y = psVectorRecycle(*y, num, PS_TYPE_F32); 62 long numSources = sources->n; // Number of sources 63 *x = psVectorRecycle(*x, numSources, PS_TYPE_F32); 64 *y = psVectorRecycle(*y, numSources, PS_TYPE_F32); 65 *indices = psVectorRecycle(*indices, numSources, PS_TYPE_U32); 61 66 float xMin = INFINITY, xMax = -INFINITY, yMin = INFINITY, yMax = -INFINITY; // Bounds of sources 62 long num Valid = 0;// Number of valid sources63 for (long i = 0; i < num ; i++) {67 long num = 0; // Number of valid sources 68 for (long i = 0; i < numSources; i++) { 64 69 pmSource *source = sources->data[i]; // Source of interest 65 if (!source ) {70 if (!source || source->mode & SOURCE_MASK) { 66 71 continue; 67 72 } 68 73 69 numValid++;70 74 float xSrc, ySrc; // Coordinates of source 71 75 coordsFromSource(&xSrc, &ySrc, source); … … 74 78 if (ySrc < yMin) yMin = ySrc; 75 79 if (ySrc > yMax) yMax = ySrc; 76 } 80 81 (*x)->data.F32[num] = xSrc; 82 (*y)->data.F32[num] = ySrc; 83 (*indices)->data.U32[num] = i; 84 num++; 85 } 86 (*x)->n = num; 87 (*y)->n = num; 88 (*indices)->n = num; 77 89 78 90 if (*bounds) { … … 85 97 } 86 98 87 return numValid; 99 psTrace("ppStack.sources", 8, "%ld sources: bounds are [%.2f:%.2f,%.2f:%.2f]\n", 100 num, xMin, xMax, yMin, yMax); 101 102 return num; 88 103 } 89 104 … … 100 115 list->sources = psMemIncrRefCounter(sources); 101 116 list->bounds = NULL; 117 list->indices = NULL; 102 118 103 119 psVector *x = NULL, *y = NULL; // Source coordinates 104 stackSourcesParse(&list->bounds, &x, &y, sources);120 stackSourcesParse(&list->bounds, &x, &y, &list->indices, sources); 105 121 list->tree = psTreePlant(2, SOURCES_MAX_LEAF, x, y); // kd Tree with sources 106 122 psFree(x); … … 123 139 124 140 list->sources = oldSources = psArrayRealloc(oldSources, numOld + numNew); 141 for (long i = 0; i < numNew; i++) { 142 psArrayAdd(oldSources, 1, newSources->data[i]); 143 } 125 144 psFree(list->tree); 126 145 127 146 psVector *x = NULL, *y = NULL; // Source coordinates 128 stackSourcesParse(&list->bounds, &x, &y, list->sources);147 stackSourcesParse(&list->bounds, &x, &y, &list->indices, list->sources); 129 148 list->tree = psTreePlant(2, SOURCES_MAX_LEAF, x, y); // kd Tree with sources 130 149 psFree(x); … … 158 177 psArray *sources = *sourcesPtr; // Sources to compare with list 159 178 psVector *x = NULL, *y = NULL; // Coordinates of sources 179 psVector *indices = NULL; // Indices for sources 160 180 psRegion *bounds = NULL; // Bounding box for sources 161 long numSources = sources->n; // Number of sources 162 stackSourcesParse(&bounds, &x, &y, sources); 181 long numSources = stackSourcesParse(&bounds, &x, &y, &indices, sources); // Number of (good) sources 163 182 164 183 if (bounds->x0 > list->bounds->x1 || bounds->x1 < list->bounds->x0 || 165 184 bounds->x0 > list->bounds->x1 || bounds->x1 < list->bounds->x0) { 166 185 // Bounds don't overlap, so the sources don't either 186 psTrace("ppStack.sources", 7, "Bounds don't overlap\n"); 167 187 psFree(x); 168 188 psFree(y); 189 psFree(indices); 169 190 psFree(bounds); 170 191 return 0; … … 179 200 psArray *outside = psArrayAllocEmpty(numSources); // Sources that don't correlate 180 201 for (long i = 0; i < numSources; i++) { 181 pmSource *source = sources->data[i]; // New source182 if (!source) {183 continue;184 }185 202 coords->data.F32[0] = x->data.F32[i]; 186 203 coords->data.F32[1] = y->data.F32[i]; … … 189 206 numOut++; 190 207 if (outside) { 191 psArrayAdd(outside, 1, source );208 psArrayAdd(outside, 1, sources->data[indices->data.U32[i]]); 192 209 } 193 210 continue; 194 211 } 195 212 196 pmSource *listSource = list->sources->data[match]; // Source in list 213 pmSource *listSource = list->sources->data[list->indices->data.U32[match]]; // Source in list 214 pmSource *source = sources->data[indices->data.U32[i]]; // Source of interest 197 215 float listMag = listSource->psfMag; // Magnitude of source in list 198 216 float sourceMag = source->psfMag; // Magnitude of source … … 207 225 psFree(x); 208 226 psFree(y); 227 228 psTrace("ppStack.sources", 7, "%ld sources (vs %d) overlap list %d\n", numIn, minOverlap, listIndex); 209 229 210 230 if (numIn > minOverlap) { … … 220 240 } 221 241 float meanDiff = stats->clippedMean; // Mean magnitude difference 242 psTrace("ppStack.sources", 7, "Magnitude difference is %f\n", meanDiff); 222 243 psFree(stats); 223 244 … … 235 256 236 257 // Suck sources from this list into the first one we found. 258 psTrace("ppStack.sources", 4, "Bridge found: Merging lists."); 259 237 260 ppStackSourceListExtend(*merge, list->sources); 238 261 psFree(list); … … 245 268 } 246 269 // Put the sources that didn't correlate into the list 270 psTrace("ppStack.sources", 4, "Extending list"); 247 271 ppStackSourceListExtend(list, outside); 248 272 *merge = list; … … 306 330 if (!merge) { 307 331 // The source list is disjoint, so throw them into a new list 332 psTrace("ppStack.sources", 4, "Disjoint source: Creating new list"); 308 333 ppStackSourceList *list = ppStackSourceListAlloc(sources); 309 334 psArrayAdd(lists, 1, list); … … 371 396 if (numIn == 0) { 372 397 // It doesn't match anything at all. Merge it in to the first list. 398 psTrace("ppStack.sources", 4, "Disjoint list: Merging into first"); 373 399 ppStackSourceListExtend(firstList, list->sources); 374 400 } … … 380 406 FILE *srcFile = fopen("sources.txt", "w"); 381 407 for (long i = 0; i < firstList->sources->n; i++) { 408 pmSource *source = firstList->sources->data[i]; 409 if (source->mode & SOURCE_MASK) { 410 continue; 411 } 382 412 float x, y; 383 coordsFromSource(&x, &y, firstList->sources->data[i]);413 coordsFromSource(&x, &y, source); 384 414 fprintf(srcFile, "%f\t%f\n", x, y); 385 415 }
Note:
See TracChangeset
for help on using the changeset viewer.
