IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23241


Ignore:
Timestamp:
Mar 9, 2009, 4:02:26 PM (17 years ago)
Author:
Paul Price
Message:

Fix memory corruption that I think occurs when multiple sources from the same image are within the matching radius.

Location:
trunk/psModules/src/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceMatch.c

    r23233 r23241  
    1616#define SOURCE_FAINTEST 50.0            // Faintest magnitude to consider
    1717#define SOURCES_MAX_LEAF 2              // Maximum number of points on a tree leaf
    18 
     18#define ARRAY_BUFFER 16                 // Buffer for array
    1919
    2020//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    113113}
    114114
    115 pmSourceMatch *pmSourceMatchAlloc(int num // Maximum number of images
    116     )
     115pmSourceMatch *pmSourceMatchAlloc(void)
    117116{
    118117    pmSourceMatch *match = psAlloc(sizeof(pmSourceMatch)); // Match data
     
    120119
    121120    match->num = 0;
    122     match->mag = psVectorAllocEmpty(num, PS_TYPE_F32);
    123     match->magErr = psVectorAllocEmpty(num, PS_TYPE_F32);
    124     match->image = psVectorAllocEmpty(num, PS_TYPE_U32);
    125     match->index = psVectorAllocEmpty(num, PS_TYPE_U32);
    126     match->mask = psVectorAllocEmpty(num, PS_TYPE_VECTOR_MASK);
     121    match->mag = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_F32);
     122    match->magErr = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_F32);
     123    match->image = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_U32);
     124    match->index = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_U32);
     125    match->mask = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_VECTOR_MASK);
    127126
    128127    return match;
     
    136135{
    137136    int num = match->num;               // Number of matches
    138     psAssert(num <= match->mag->nalloc, "Too many matches.");
    139     psAssert(num <= match->magErr->nalloc, "Too many matches.");
    140     psAssert(num <= match->image->nalloc, "Too many matches.");
    141     psAssert(num <= match->index->nalloc, "Too many matches.");
     137
     138    match->mag = psVectorExtend(match->mag, match->mag->nalloc, 1);
     139    match->magErr = psVectorExtend(match->magErr, match->magErr->nalloc, 1);
     140    match->image = psVectorExtend(match->image, match->image->nalloc, 1);
     141    match->index = psVectorExtend(match->index, match->index->nalloc, 1);
     142    match->mask = psVectorExtend(match->mask, match->mask->nalloc, 1);
    142143
    143144    match->mag->data.F32[num] = mag;
     
    148149    match->num++;
    149150
    150     match->mag->n = match->magErr->n = match->image->n = match->index->n = match->mask->n = match->num;
     151    return;
    151152}
    152153
     
    185186            matches = psArrayAlloc(numSources);
    186187            for (int j = 0; j < numSources; j++) {
    187                 pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
     188                pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
    188189                pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    189190                matches->data[j] = match;
    190191            }
    191192            numMaster += numSources;
    192             goto match_image_done;
    193         }
    194 
    195         if (boundsImage->x0 > boundsMaster->x1 || boundsImage->x1 < boundsMaster->x0 ||
    196             boundsImage->y0 > boundsMaster->y1 || boundsImage->y1 < boundsMaster->y0) {
     193        } else if (boundsImage->x0 > boundsMaster->x1 || boundsImage->x1 < boundsMaster->x0 ||
     194                   boundsImage->y0 > boundsMaster->y1 || boundsImage->y1 < boundsMaster->y0) {
     195            // Bounds don't overlap --- can just add everything in to the master list
    197196            psTrace("psModules.objects", 7, "Bounds don't overlap\n");
    198             // Add everything in to the master list
    199197            long size = numMaster + numSources; // New size
    200198            xMaster = psVectorRealloc(xMaster, size);
     
    207205                   numSources * PSELEMTYPE_SIZEOF(PS_TYPE_F32));
    208206            for (int j = 0, k = numMaster; j < numSources; j++, k++) {
    209                 pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
     207                pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
    210208                pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    211209                matches->data[k] = match;
     
    215213            yMaster->n = size;
    216214            matches->n = size;
    217 
    218             goto match_image_done;
    219         }
    220 
    221         // Match with the master list
    222         {
     215        } else {
     216            // Match with the master list
    223217            psTree *tree = psTreePlant(2, SOURCES_MAX_LEAF, xMaster, yMaster); // kd Tree with sources
    224             long numMatch = 0;              // Number of matches
     218            long numMatch = 0;          // Number of matches
    225219
    226220            long size = numMaster + numSources; // New size
     
    241235                } else {
    242236                    // Add to the master list
    243                     pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
     237                    pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
    244238                    pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
    245239                    xMaster->data.F32[numMaster] = xImage->data.F32[j];
     
    255249        }
    256250
    257     match_image_done:
    258251        psFree(boundsImage);
    259252        psFree(xImage);
     
    306299                continue;
    307300            }
    308             int image = match->image->data.S32[j]; // Index of image
    309             int index = match->index->data.S32[j]; // Index of source for image
    310             psArray *list = sourceArrays->data[image]; // List of interest
    311             source = list->data[index];
     301            int imgIndex = match->image->data.S32[j]; // Index of image
     302            int srcIndex = match->index->data.S32[j]; // Index of source for image
     303            psArray *list = sourceArrays->data[imgIndex]; // List of interest
     304            source = list->data[srcIndex];
    312305            break;
    313306        }
  • trunk/psModules/src/objects/pmSourceMatch.h

    r23233 r23241  
    3333
    3434/// Allocator for pmSourceMatch
    35 pmSourceMatch *pmSourceMatchAlloc(int num // Maximum number of images
    36                                   );
     35pmSourceMatch *pmSourceMatchAlloc(void);
    3736
    3837/// Add a source to a match
Note: See TracChangeset for help on using the changeset viewer.