IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 13, 2010, 4:42:21 PM (16 years ago)
Author:
eugene
Message:

modify pmFootprintCullPeaks to reduce repeated allocs

File:
1 edited

Legend:

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

    r23187 r27672  
    5353    assert(nspan >= 0);
    5454    footprint->npix = 0;
     55    footprint->nspans = 0; // we may allocate more spans than we set -- this is the number of active spans
    5556    footprint->spans = psArrayAllocEmpty(nspan);
    5657    footprint->peaks = psArrayAlloc(0);
     
    7374}
    7475
     76bool pmFootprintAllocEmptySpans (pmFootprint *footprint, int nSpans) {
     77
     78    psArrayRealloc (footprint->spans, nSpans);
     79    for (int i = 0; i < nSpans; i++) {
     80        footprint->spans->data[i] = pmSpanAlloc(-1, -1, -1);
     81    }
     82    footprint->spans->n = nSpans;
     83    return true;
     84}
     85
     86// reset the footprint containers
     87bool pmFootprintInit(pmFootprint *footprint) {
     88
     89    footprint->bbox.x0 = footprint->bbox.y0 = 0;
     90    footprint->bbox.x1 = footprint->bbox.y1 = -1;
     91    footprint->nspans = 0;
     92    return true;
     93}
     94
    7595bool pmFootprintTest(const psPtr ptr) {
    7696    return (psMemGetDeallocator(ptr) == (psFreeFunc)footprintFree);
     
    103123    psArrayAdd(fp->spans, 1, sp);
    104124    psFree(sp);
    105    
     125
     126    fp->nspans ++;
     127
    106128    fp->npix += x1 - x0 + 1;
    107129
    108     if (fp->spans->n == 1) {
     130    if (fp->nspans == 1) {
    109131        fp->bbox.x0 = x0;
    110132        fp->bbox.x1 = x1;
     
    121143}
    122144
     145
     146// Set the next available elements of the nSpan entry in footprint->spans
     147pmSpan *pmFootprintSetSpan(pmFootprint *fp,     // the footprint to add to
     148                           const int y,         // row to add
     149                           int x0,              // range of
     150                           int x1) {            // columns
     151
     152    if (x1 < x0) {
     153        int tmp = x0;
     154        x0 = x1;
     155        x1 = tmp;
     156    }
     157
     158    int N = fp->nspans;
     159    if (N == fp->spans->n) {
     160        // if we need more space, extend fp->spans as needed
     161        int Nalloc = fp->spans->n + 100;
     162        psArrayRealloc(fp->spans, Nalloc);
     163        fp->spans->n = Nalloc;
     164        for (int i = N; i < fp->spans->n; i++) {
     165            fp->spans->data[i] = pmSpanAlloc(-1, -1, -1);
     166        }
     167    }
     168
     169    pmSpan *span = fp->spans->data[N];
     170    span->y = y;
     171    span->x0 = x0;
     172    span->x1 = x1;
     173
     174    fp->nspans ++;
     175
     176    fp->npix += x1 - x0 + 1;
     177
     178    if (fp->nspans == 1) {
     179        fp->bbox.x0 = x0;
     180        fp->bbox.x1 = x1;
     181        fp->bbox.y0 = y;
     182        fp->bbox.y1 = y;
     183    } else {
     184        if (x0 < fp->bbox.x0) fp->bbox.x0 = x0;
     185        if (x1 > fp->bbox.x1) fp->bbox.x1 = x1;
     186        if (y < fp->bbox.y0) fp->bbox.y0 = y;
     187        if (y > fp->bbox.y1) fp->bbox.y1 = y;
     188    }
     189
     190    return span;
     191}
     192
    123193void pmFootprintSetBBox(pmFootprint *fp) {
    124194    assert (fp != NULL);
    125     if (fp->spans->n == 0) {
     195    if (fp->nspans == 0) {
    126196        return;
    127197    }
     
    132202    int y1 = sp->y;
    133203
    134     for (int i = 1; i < fp->spans->n; i++) {
     204    for (int i = 1; i < fp->nspans; i++) {
    135205        sp = fp->spans->data[i];
    136206       
     
    150220   assert (fp != NULL);
    151221   int npix = 0;
    152    for (int i = 0; i < fp->spans->n; i++) {
     222   for (int i = 0; i < fp->nspans; i++) {
    153223       pmSpan *span = fp->spans->data[i];
    154224       npix += span->x1 - span->x0 + 1;
Note: See TracChangeset for help on using the changeset viewer.