IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 7, 2010, 12:06:22 PM (16 years ago)
Author:
Paul Price
Message:

Removing casts in psFree following change to psFree definition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psModules/src/objects/pmFootprintFindAtPoint.c

    r21183 r26533  
    2929 * so we set appropriate mask bits
    3030 *
    31  * EAM : these function were confusingly using "startspan" and "spartspan" 
     31 * EAM : these function were confusingly using "startspan" and "spartspan"
    3232 * I've rationalized them all to 'startspan'
    3333 */
     
    3636// An enum for what we should do with a Startspan
    3737//
    38 typedef enum {PM_SSPAN_DOWN = 0,        // scan down from this span
    39               PM_SSPAN_UP,              // scan up from this span
    40               PM_SSPAN_RESTART,         // restart scanning from this span
    41               PM_SSPAN_DONE             // this span is processed
    42 } PM_SSPAN_DIR;                         // How to continue searching
     38typedef enum {PM_SSPAN_DOWN = 0,        // scan down from this span
     39              PM_SSPAN_UP,              // scan up from this span
     40              PM_SSPAN_RESTART,         // restart scanning from this span
     41              PM_SSPAN_DONE             // this span is processed
     42} PM_SSPAN_DIR;                         // How to continue searching
    4343//
    4444// An enum for mask's pixel values.  We're looking for pixels that are above threshold, and
    4545// we keep extra book-keeping information in the PM_SSPAN_STOP plane.  It's simpler to be
    46 // able to check for 
     46// able to check for
    4747//
    4848enum {
    49     PM_SSPAN_INITIAL = 0x0,             // initial state of pixels.
    50     PM_SSPAN_DETECTED = 0x1,            // we've seen this pixel
    51     PM_SSPAN_STOP = 0x2                 // you may stop searching when you see this pixel
     49    PM_SSPAN_INITIAL = 0x0,             // initial state of pixels.
     50    PM_SSPAN_DETECTED = 0x1,            // we've seen this pixel
     51    PM_SSPAN_STOP = 0x2                 // you may stop searching when you see this pixel
    5252};
    5353//
     
    5555//
    5656typedef struct {
    57     const pmSpan *span;                 // save the pixel range
    58     PM_SSPAN_DIR direction;             // How to continue searching
    59     bool stop;                          // should we stop searching?
     57    const pmSpan *span;                 // save the pixel range
     58    PM_SSPAN_DIR direction;             // How to continue searching
     59    bool stop;                          // should we stop searching?
    6060} Startspan;
    6161
    6262static void startspanFree(Startspan *sspan) {
    63     psFree((void *)sspan->span);
     63    psFree(sspan->span);
    6464}
    6565
    6666static Startspan *
    67 StartspanAlloc(const pmSpan *span,      // The span in question
    68                psImage *mask,           // Pixels that we've already detected
    69                const PM_SSPAN_DIR dir   // Should we continue searching towards the top of the image?
     67StartspanAlloc(const pmSpan *span,      // The span in question
     68               psImage *mask,           // Pixels that we've already detected
     69               const PM_SSPAN_DIR dir   // Should we continue searching towards the top of the image?
    7070    ) {
    7171    Startspan *sspan = psAlloc(sizeof(Startspan));
     
    7575    sspan->direction = dir;
    7676    sspan->stop = false;
    77    
    78     if (mask != NULL) {                 // remember that we've detected these pixels
    79         psImageMaskType *mpix = &mask->data.PS_TYPE_IMAGE_MASK_DATA[span->y - mask->row0][span->x0 - mask->col0];
    80 
    81         for (int i = 0; i <= span->x1 - span->x0; i++) {
    82             mpix[i] |= PM_SSPAN_DETECTED;
    83             if (mpix[i] & PM_SSPAN_STOP) {
    84                 sspan->stop = true;
    85             }
    86         }
    87     }
    88    
     77
     78    if (mask != NULL) {                 // remember that we've detected these pixels
     79        psImageMaskType *mpix = &mask->data.PS_TYPE_IMAGE_MASK_DATA[span->y - mask->row0][span->x0 - mask->col0];
     80
     81        for (int i = 0; i <= span->x1 - span->x0; i++) {
     82            mpix[i] |= PM_SSPAN_DETECTED;
     83            if (mpix[i] & PM_SSPAN_STOP) {
     84                sspan->stop = true;
     85            }
     86        }
     87    }
     88
    8989    return sspan;
    9090}
     
    9494//
    9595static bool add_startspan(psArray *startspans, // the saved Startspans
    96                           const pmSpan *sp, // the span in question
    97                           psImage *mask, // mask of detected/stop pixels
    98                           const PM_SSPAN_DIR dir) { // the desired direction to search
     96                          const pmSpan *sp, // the span in question
     97                          psImage *mask, // mask of detected/stop pixels
     98                          const PM_SSPAN_DIR dir) { // the desired direction to search
    9999    if (dir == PM_SSPAN_RESTART) {
    100         if (add_startspan(startspans, sp, mask,  PM_SSPAN_UP) ||
    101             add_startspan(startspans, sp, NULL, PM_SSPAN_DOWN)) {
    102             return true;
    103         }
     100        if (add_startspan(startspans, sp, mask,  PM_SSPAN_UP) ||
     101            add_startspan(startspans, sp, NULL, PM_SSPAN_DOWN)) {
     102            return true;
     103        }
    104104    } else {
    105         Startspan *sspan = StartspanAlloc(sp, mask, dir);
    106         if (sspan->stop) {              // we detected a stop bit
    107             psFree(sspan);              // don't allocate new span
    108 
    109             return true;
    110         } else {
    111             psArrayAdd(startspans, 1, sspan);
    112             psFree(sspan);              // as it's now owned by startspans
    113         }
     105        Startspan *sspan = StartspanAlloc(sp, mask, dir);
     106        if (sspan->stop) {              // we detected a stop bit
     107            psFree(sspan);              // don't allocate new span
     108
     109            return true;
     110        } else {
     111            psArrayAdd(startspans, 1, sspan);
     112            psFree(sspan);              // as it's now owned by startspans
     113        }
    114114    }
    115115
     
    127127 */
    128128static bool do_startspan(pmFootprint *fp, // the footprint that we're building
    129                         const psImage *img, // the psImage we're working on
    130                         psImage *mask, // the associated masks
    131                          const float threshold, // Threshold
    132                          psArray *startspans) { // specify which span to process next
    133     bool F32 = false;                   // is this an F32 image?
     129                        const psImage *img, // the psImage we're working on
     130                        psImage *mask, // the associated masks
     131                         const float threshold, // Threshold
     132                         psArray *startspans) { // specify which span to process next
     133    bool F32 = false;                   // is this an F32 image?
    134134    if (img->type.type == PS_TYPE_F32) {
    135         F32 = true;
     135        F32 = true;
    136136    } else if (img->type.type == PS_TYPE_S32) {
    137         F32 = false;
    138     } else {                            // N.b. You can't trivially add more cases here; F32 is just a bool
    139         psError(PS_ERR_UNKNOWN, true, "Unsupported psImage type: %d", img->type.type);
    140         return NULL;
    141     }
    142 
    143     psF32 *imgRowF32 = NULL;            // row pointer if F32
    144     psS32 *imgRowS32 = NULL;            //  "   "   "  "  !F32
    145     psImageMaskType *maskRow = NULL;            //  masks's row pointer
    146    
     137        F32 = false;
     138    } else {                            // N.b. You can't trivially add more cases here; F32 is just a bool
     139        psError(PS_ERR_UNKNOWN, true, "Unsupported psImage type: %d", img->type.type);
     140        return NULL;
     141    }
     142
     143    psF32 *imgRowF32 = NULL;            // row pointer if F32
     144    psS32 *imgRowS32 = NULL;            //  "   "   "  "  !F32
     145    psImageMaskType *maskRow = NULL;            //  masks's row pointer
     146
    147147    const int row0 = img->row0;
    148148    const int col0 = img->col0;
    149149    const int numRows = img->numRows;
    150150    const int numCols = img->numCols;
    151    
     151
    152152    /********************************************************************************************************/
    153    
     153
    154154    Startspan *sspan = NULL;
    155155    for (int i = 0; i < startspans->n; i++) {
    156         sspan = startspans->data[i];
    157         if (sspan->direction != PM_SSPAN_DONE) {
    158             break;
    159         }
    160         if (sspan->stop) {
    161             break;
    162         }
     156        sspan = startspans->data[i];
     157        if (sspan->direction != PM_SSPAN_DONE) {
     158            break;
     159        }
     160        if (sspan->stop) {
     161            break;
     162        }
    163163    }
    164164    if (sspan == NULL || sspan->direction == PM_SSPAN_DONE) { // no more Startspans to process
    165         return false;
    166     }
    167     if (sspan->stop) {                  // they don't want any more spans processed
    168         return false;
     165        return false;
     166    }
     167    if (sspan->stop) {                  // they don't want any more spans processed
     168        return false;
    169169    }
    170170    /*
     
    179179     * Go through image identifying objects
    180180     */
    181     int nx0, nx1 = -1;                  // new values of x0, x1
     181    int nx0, nx1 = -1;                  // new values of x0, x1
    182182    const int di = (dir == PM_SSPAN_UP) ? 1 : -1; // how much i changes to get to the next row
    183     bool stop = false;                  // should I stop searching for spans?
     183    bool stop = false;                  // should I stop searching for spans?
    184184
    185185    for (int i = sspan->span->y -row0 + di; i < numRows && i >= 0; i += di) {
    186         imgRowF32 = img->data.F32[i];   // only one of
    187         imgRowS32 = img->data.S32[i];   //      these is valid!
    188         maskRow = mask->data.PS_TYPE_IMAGE_MASK_DATA[i];
    189         //
    190         // Search left from the pixel diagonally to the left of (i - di, x0). If there's
    191         // a connected span there it may need to grow up and/or down, so push it onto
    192         // the stack for later consideration
    193         //
    194         nx0 = -1;
    195         for (int j = x0 - 1; j >= -1; j--) {
    196             double pixVal = (j < 0) ? threshold - 100 : (F32 ? imgRowF32[j] : imgRowS32[j]);
    197             if ((maskRow[j] & PM_SSPAN_DETECTED) || pixVal < threshold) {
    198                 if (j < x0 - 1) {       // we found some pixels above threshold
    199                     nx0 = j + 1;
    200                 }
    201                 break;
    202             }
    203         }
    204 
    205         if (nx0 < 0) {                  // no span to the left
    206             nx1 = x0 - 1;               // we're going to resume searching at nx1 + 1
    207         } else {
    208             //
    209             // Search right in leftmost span
    210             //
    211             //nx1 = 0;                  // make gcc happy
    212             for (int j = nx0 + 1; j <= numCols; j++) {
    213                 double pixVal = (j >= numCols) ? threshold - 100 : (F32 ? imgRowF32[j] : imgRowS32[j]);
    214                 if ((maskRow[j] & PM_SSPAN_DETECTED) || pixVal < threshold) {
    215                     nx1 = j - 1;
    216                     break;
    217                 }
    218             }
    219            
    220             const pmSpan *sp = pmFootprintAddSpan(fp, i + row0, nx0 + col0, nx1 + col0);
    221            
    222             if (add_startspan(startspans, sp, mask, PM_SSPAN_RESTART)) {
    223                 stop = true;
    224                 break;
    225             }
    226         }
    227         //
    228         // Now look for spans connected to the old span.  The first of these we'll
    229         // simply process, but others will have to be deferred for later consideration.
    230         //
    231         // In fact, if the span overhangs to the right we'll have to defer the overhang
    232         // until later too, as it too can grow in both directions
    233         //
    234         // Note that column numCols exists virtually, and always ends the last span; this
    235         // is why we claim below that sx1 is always set
    236         //
    237         bool first = false;             // is this the first new span detected?
    238         for (int j = nx1 + 1; j <= x1 + 1; j++) {
    239             double pixVal = (j >= numCols) ? threshold - 100 : (F32 ? imgRowF32[j] : imgRowS32[j]);
    240             if (!(maskRow[j] & PM_SSPAN_DETECTED) && pixVal >= threshold) {
    241                 int sx0 = j++;          // span that we're working on is sx0:sx1
    242                 int sx1 = -1;           // We know that if we got here, we'll also set sx1
    243                 for (; j <= numCols; j++) {
    244                     double pixVal = (j >= numCols) ? threshold - 100 : (F32 ? imgRowF32[j] : imgRowS32[j]);
    245                     if ((maskRow[j] & PM_SSPAN_DETECTED) || pixVal < threshold) { // end of span
    246                         sx1 = j;
    247                         break;
    248                     }
    249                 }
    250                 assert (sx1 >= 0);
    251 
    252                 const pmSpan *sp;
    253                 if (first) {
    254                     if (sx1 <= x1) {
    255                         sp = pmFootprintAddSpan(fp, i + row0, sx0 + col0, sx1 + col0 - 1);
    256                         if (add_startspan(startspans, sp, mask, PM_SSPAN_DONE)) {
    257                             stop = true;
    258                             break;
    259                         }
    260                     } else {            // overhangs to right
    261                         sp = pmFootprintAddSpan(fp, i + row0, sx0 + col0, x1 + col0);
    262                         if (add_startspan(startspans, sp, mask, PM_SSPAN_DONE)) {
    263                             stop = true;
    264                             break;
    265                         }
    266                         sp = pmFootprintAddSpan(fp, i + row0, x1 + 1 + col0, sx1 + col0 - 1);
    267                         if (add_startspan(startspans, sp, mask, PM_SSPAN_RESTART)) {
    268                             stop = true;
    269                             break;
    270                         }
    271                     }
    272                     first = false;
    273                 } else {
    274                     sp = pmFootprintAddSpan(fp, i + row0, sx0 + col0, sx1 + col0 - 1);
    275                     if (add_startspan(startspans, sp, mask, PM_SSPAN_RESTART)) {
    276                         stop = true;
    277                         break;
    278                     }
    279                 }
    280             }
    281         }
    282 
    283         if (stop || first == false) {   // we're done
    284             break;
    285         }
    286 
    287         x0 = nx0; x1 = nx1;
     186        imgRowF32 = img->data.F32[i];   // only one of
     187        imgRowS32 = img->data.S32[i];   //      these is valid!
     188        maskRow = mask->data.PS_TYPE_IMAGE_MASK_DATA[i];
     189        //
     190        // Search left from the pixel diagonally to the left of (i - di, x0). If there's
     191        // a connected span there it may need to grow up and/or down, so push it onto
     192        // the stack for later consideration
     193        //
     194        nx0 = -1;
     195        for (int j = x0 - 1; j >= -1; j--) {
     196            double pixVal = (j < 0) ? threshold - 100 : (F32 ? imgRowF32[j] : imgRowS32[j]);
     197            if ((maskRow[j] & PM_SSPAN_DETECTED) || pixVal < threshold) {
     198                if (j < x0 - 1) {       // we found some pixels above threshold
     199                    nx0 = j + 1;
     200                }
     201                break;
     202            }
     203        }
     204
     205        if (nx0 < 0) {                  // no span to the left
     206            nx1 = x0 - 1;               // we're going to resume searching at nx1 + 1
     207        } else {
     208            //
     209            // Search right in leftmost span
     210            //
     211            //nx1 = 0;                  // make gcc happy
     212            for (int j = nx0 + 1; j <= numCols; j++) {
     213                double pixVal = (j >= numCols) ? threshold - 100 : (F32 ? imgRowF32[j] : imgRowS32[j]);
     214                if ((maskRow[j] & PM_SSPAN_DETECTED) || pixVal < threshold) {
     215                    nx1 = j - 1;
     216                    break;
     217                }
     218            }
     219
     220            const pmSpan *sp = pmFootprintAddSpan(fp, i + row0, nx0 + col0, nx1 + col0);
     221
     222            if (add_startspan(startspans, sp, mask, PM_SSPAN_RESTART)) {
     223                stop = true;
     224                break;
     225            }
     226        }
     227        //
     228        // Now look for spans connected to the old span.  The first of these we'll
     229        // simply process, but others will have to be deferred for later consideration.
     230        //
     231        // In fact, if the span overhangs to the right we'll have to defer the overhang
     232        // until later too, as it too can grow in both directions
     233        //
     234        // Note that column numCols exists virtually, and always ends the last span; this
     235        // is why we claim below that sx1 is always set
     236        //
     237        bool first = false;             // is this the first new span detected?
     238        for (int j = nx1 + 1; j <= x1 + 1; j++) {
     239            double pixVal = (j >= numCols) ? threshold - 100 : (F32 ? imgRowF32[j] : imgRowS32[j]);
     240            if (!(maskRow[j] & PM_SSPAN_DETECTED) && pixVal >= threshold) {
     241                int sx0 = j++;          // span that we're working on is sx0:sx1
     242                int sx1 = -1;           // We know that if we got here, we'll also set sx1
     243                for (; j <= numCols; j++) {
     244                    double pixVal = (j >= numCols) ? threshold - 100 : (F32 ? imgRowF32[j] : imgRowS32[j]);
     245                    if ((maskRow[j] & PM_SSPAN_DETECTED) || pixVal < threshold) { // end of span
     246                        sx1 = j;
     247                        break;
     248                    }
     249                }
     250                assert (sx1 >= 0);
     251
     252                const pmSpan *sp;
     253                if (first) {
     254                    if (sx1 <= x1) {
     255                        sp = pmFootprintAddSpan(fp, i + row0, sx0 + col0, sx1 + col0 - 1);
     256                        if (add_startspan(startspans, sp, mask, PM_SSPAN_DONE)) {
     257                            stop = true;
     258                            break;
     259                        }
     260                    } else {            // overhangs to right
     261                        sp = pmFootprintAddSpan(fp, i + row0, sx0 + col0, x1 + col0);
     262                        if (add_startspan(startspans, sp, mask, PM_SSPAN_DONE)) {
     263                            stop = true;
     264                            break;
     265                        }
     266                        sp = pmFootprintAddSpan(fp, i + row0, x1 + 1 + col0, sx1 + col0 - 1);
     267                        if (add_startspan(startspans, sp, mask, PM_SSPAN_RESTART)) {
     268                            stop = true;
     269                            break;
     270                        }
     271                    }
     272                    first = false;
     273                } else {
     274                    sp = pmFootprintAddSpan(fp, i + row0, sx0 + col0, sx1 + col0 - 1);
     275                    if (add_startspan(startspans, sp, mask, PM_SSPAN_RESTART)) {
     276                        stop = true;
     277                        break;
     278                    }
     279                }
     280            }
     281        }
     282
     283        if (stop || first == false) {   // we're done
     284            break;
     285        }
     286
     287        x0 = nx0; x1 = nx1;
    288288    }
    289289    /*
     
    309309 */
    310310pmFootprint *
    311 pmFootprintsFindAtPoint(const psImage *img,     // image to search
    312                        const float threshold,   // Threshold
    313                        const psArray *peaks, // array of peaks; finding one terminates search for footprint
    314                        int row, int col) { // starting position (in img's parent's coordinate system)
     311pmFootprintsFindAtPoint(const psImage *img,     // image to search
     312                       const float threshold,   // Threshold
     313                       const psArray *peaks, // array of peaks; finding one terminates search for footprint
     314                       int row, int col) { // starting position (in img's parent's coordinate system)
    315315   assert(img != NULL);
    316316
    317    bool F32 = false;                    // is this an F32 image?
     317   bool F32 = false;                    // is this an F32 image?
    318318   if (img->type.type == PS_TYPE_F32) {
    319319       F32 = true;
    320320   } else if (img->type.type == PS_TYPE_S32) {
    321321       F32 = false;
    322    } else {                             // N.b. You can't trivially add more cases here; F32 is just a bool
     322   } else {                             // N.b. You can't trivially add more cases here; F32 is just a bool
    323323       psError(PS_ERR_UNKNOWN, true, "Unsupported psImage type: %d", img->type.type);
    324324       return NULL;
    325325   }
    326    psF32 *imgRowF32 = NULL;             // row pointer if F32
    327    psS32 *imgRowS32 = NULL;             //  "   "   "  "  !F32
    328    
     326   psF32 *imgRowF32 = NULL;             // row pointer if F32
     327   psS32 *imgRowS32 = NULL;             //  "   "   "  "  !F32
     328
    329329   const int row0 = img->row0;
    330330   const int col0 = img->col0;
     
    339339        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    340340                "row/col == (%d, %d) are out of bounds [%d--%d, %d--%d]",
    341                 row + row0, col + col0, row0, row0 + numRows - 1, col0, col0 + numCols - 1);
     341                row + row0, col + col0, row0, row0 + numRows - 1, col0, col0 + numCols - 1);
    342342       return NULL;
    343343   }
     
    347347       return pmFootprintAlloc(0, img);
    348348   }
    349    
     349
    350350   pmFootprint *fp = pmFootprintAlloc(1 + img->numRows/10, img);
    351351/*
     
    364364   if (peaks != NULL) {
    365365       for (int i = 0; i < peaks->n; i++) {
    366            pmPeak *peak = peaks->data[i];
    367            mask->data.PS_TYPE_IMAGE_MASK_DATA[peak->y - mask->row0][peak->x - mask->col0] |= PM_SSPAN_STOP;
     366           pmPeak *peak = peaks->data[i];
     367           mask->data.PS_TYPE_IMAGE_MASK_DATA[peak->y - mask->row0][peak->x - mask->col0] |= PM_SSPAN_STOP;
    368368       }
    369369   }
     
    372372 */
    373373   psArray *startspans = psArrayAllocEmpty(1); // spans where we have to restart the search
    374    
    375    imgRowF32 = img->data.F32[row];      // only one of
    376    imgRowS32 = img->data.S32[row];      //      these is valid!
     374
     375   imgRowF32 = img->data.F32[row];      // only one of
     376   imgRowS32 = img->data.S32[row];      //      these is valid!
    377377   psImageMaskType *maskRow = mask->data.PS_TYPE_IMAGE_MASK_DATA[row];
    378378   {
    379379       int i;
    380380       for (i = col; i >= 0; i--) {
    381            pixVal = F32 ? imgRowF32[i] : imgRowS32[i];
    382            if ((maskRow[i] & PM_SSPAN_DETECTED) || pixVal < threshold) {
    383                break;
    384            }
     381           pixVal = F32 ? imgRowF32[i] : imgRowS32[i];
     382           if ((maskRow[i] & PM_SSPAN_DETECTED) || pixVal < threshold) {
     383               break;
     384           }
    385385       }
    386386       int i0 = i;
    387387       for (i = col; i < numCols; i++) {
    388            pixVal = F32 ? imgRowF32[i] : imgRowS32[i];
    389            if ((maskRow[i] & PM_SSPAN_DETECTED) || pixVal < threshold) {
    390                break;
    391            }
     388           pixVal = F32 ? imgRowF32[i] : imgRowS32[i];
     389           if ((maskRow[i] & PM_SSPAN_DETECTED) || pixVal < threshold) {
     390               break;
     391           }
    392392       }
    393393       int i1 = i;
     
    404404    */
    405405   psFree(mask);
    406    psFree(startspans);                  // restores the image pixel
    407 
    408    return fp;                           // pmFootprint really
     406   psFree(startspans);                  // restores the image pixel
     407
     408   return fp;                           // pmFootprint really
    409409}
Note: See TracChangeset for help on using the changeset viewer.