IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7740


Ignore:
Timestamp:
Jun 28, 2006, 2:27:51 PM (20 years ago)
Author:
Paul Price
Message:

Optimising for speed: dereferencing pointers, moving some things around.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmReadoutCombine.c

    r7362 r7740  
    55 *  @author GLG, MHPCC
    66 *
    7  *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2006-06-06 03:32:59 $
     7 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2006-06-29 00:27:51 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    126126    long minInputCols = LONG_MAX;       // The smallest input column value
    127127    long minInputRows = LONG_MAX;       // The smallest input row value
    128     psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_U8); // Mask for stack
    129     mask->n = inputs->n;
    130128
    131129    bool haveWeights = false;           // Do we have weight images?
     
    245243
    246244    // We loop through each pixel in the output image.  We loop through each input readout.  We determine if
    247     // that output pixel is contained in the image from that readout.  If so, we save it in psVector
    248     // tmpPixels.  If not, we set a mask for that element in tmpPixels.  Then, we mask off pixels not between
    249     // fracLow and fracHigh.  Then we call the vector stats routine on those pixels/mask.  Then we set the
    250     // output pixel value to the result of the stats call.
     245    // that output pixel is contained in the image from that readout.  If so, we save it in psVector pixels.
     246    // If not, we set a mask for that element in pixels.  Then, we mask off pixels not between fracLow and
     247    // fracHigh.  Then we call the vector stats routine on those pixels/mask.  Then we set the output pixel
     248    // value to the result of the stats call.
    251249
    252250    psVector *pixels = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of pixels
    253251    pixels->n = inputs->n;
     252    psF32 *pixelsData = pixels->data.F32; // Dereference pixels
     253
     254    psVector *mask   = psVectorAlloc(inputs->n, PS_TYPE_U8); // Mask for stack
     255    mask->n = inputs->n;
     256    psU8 *maskData = mask->data.U8;     // Dereference mask
     257
    254258    psVector *weights = NULL;           // Stack of weights
     259    psF32 *weightsData = NULL;          // Dereference weights
    255260    if (haveWeights) {
    256261        weights = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of weights
    257262        weights->n = inputs->n;
     263        weightsData = weights->data.F32;
    258264    }
    259265    psVector *index = NULL;             // The indices to sort the pixels
     
    274280    }
    275281
     282    // Dereference output products
     283    psF32 **outputImage  = output->image->data.F32; // Output image
     284    psU8  **outputMask   = output->mask->data.U8; // Output mask
     285    psF32 **outputWeight = output->weight->data.F32; // Output weight map
     286
    276287    for (int i = minInputRows; i < maxInputRows; i++) {
     288        int yOut = i - output->row0; // y position on output readout
    277289        #if 0
     290
    278291        if (psTraceGetLevel(__func__) > 9) {
    279292            printf("Processing row %d\r", i);
     
    282295        #endif
    283296        for (int j = minInputCols; j < maxInputCols; j++) {
     297            int xOut = j - output->col0; // x position on output readout
     298
    284299            int numValid = 0;           // Number of valid pixels in the stack
    285             memset(mask->data.U8, 0, mask->n * sizeof(psU8)); // Reset the mask
     300            memset(maskData, 0, mask->n * sizeof(psU8)); // Reset the mask
    286301            for (int r = 0; r < inputs->n; r++) {
    287302                pmReadout *readout = inputs->data[r]; // Input readout
     
    296311                }
    297312
    298                 pixels->data.F32[r] = image->data.F32[yIn][xIn];
     313                pixelsData[r] = image->data.F32[yIn][xIn];
    299314
    300315                // Check mask
    301                 if (readout->mask && readout->mask->data.U8[yIn][xIn] & maskVal) {
    302                     mask->data.U8[r] = 1;
     316                psImage *roMask = readout->mask; // The mask image
     317                if (roMask && roMask->data.U8[yIn][xIn] & maskVal) {
     318                    maskData[r] = 1;
    303319                    continue;
    304320                }
     
    307323            }
    308324
    309             int yOut = i - output->row0; // y position on output readout
    310             int xOut = j - output->col0; // x position on output readout
    311 
    312325            if (numValid == 0) {
    313                 output->mask->data.U8[yOut][xOut] = PM_MASK_FLAT;
    314                 output->image->data.F32[yOut][xOut] = NAN;
     326                outputMask[yOut][xOut] = PM_MASK_FLAT;
     327                outputImage[yOut][xOut] = NAN;
    315328                continue;
    316329            }
     
    322335                int numHigh = numValid * params->fracHigh; // Number of high pixels to clip
    323336                // Low pixels
     337                psS32 *indexData = index->data.S32; // Dereference index
    324338                for (int k = 0, numMasked = 0; numMasked < numLow && k < index->n; k++) {
    325339                    // Don't count the ones that are already masked
    326                     if (!mask->data.U8[index->data.S32[k]]) {
    327                         mask->data.U8[index->data.S32[k]] = 1;
     340                    if (!maskData[indexData[k]]) {
     341                        maskData[indexData[k]] = 1;
    328342                        numMasked++;
    329343                    }
     
    332346                for (int k = pixels->n - 1, numMasked = 0; numMasked < numHigh && k >= 0; k--) {
    333347                    // Don't count the ones that are already masked
    334                     if (! mask->data.U8[index->data.S32[k]]) {
    335                         mask->data.U8[index->data.S32[k]] = 1;
     348                    if (! maskData[indexData[k]]) {
     349                        maskData[indexData[k]] = 1;
    336350                        numMasked++;
    337351                    }
     
    341355            // Combination
    342356            psVectorStats(stats, pixels, weights, mask, 1);
    343             output->image->data.F32[yOut][xOut] = getStat(stats, params->combine);
     357            outputImage[yOut][xOut] = getStat(stats, params->combine);
    344358            if (haveWeights) {
    345359                float stdev = getStat(stats, combineStdev);
    346                 output->weight->data.F32[yOut][xOut] = PS_SQR(stdev); // Variance
     360                outputWeight[yOut][xOut] = PS_SQR(stdev); // Variance
    347361            }
    348362        }
Note: See TracChangeset for help on using the changeset viewer.