IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 18, 2007, 5:41:17 PM (19 years ago)
Author:
Paul Price
Message:

Moving important recyclable code into pmReadoutStack.c

File:
1 edited

Legend:

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

    r13768 r13871  
    1313#include "pmFPAMaskWeight.h"
    1414#include "pmConceptsAverage.h"
     15#include "pmReadoutStack.h"
    1516
    1617#include "pmReadoutCombine.h"
     
    6667        return false;
    6768    }
     69    for (int i = 0; i < inputs->n; i++) {
     70        pmReadout *readout = inputs->data[i]; // Readout of interest
     71        if (params->weights && !readout->weight) {
     72            psError(PS_ERR_UNEXPECTED_NULL, true,
     73                    "Rejection based on weights requested, but no weights supplied for image %d.\n", i);
     74            return false;
     75        }
     76    }
    6877
    6978    bool first = !output->image;        // First pass through?
     
    96105    }
    97106
    98     // Step through each readout in the input image list to determine how big of an output image is needed to
    99     // combine these input images.
    100     int maxInputCols = 0;               // The largest input column value
    101     int maxInputRows = 0;               // The largest input row value
    102     int minInputCols = INT_MAX;         // The smallest input column value
    103     int minInputRows = INT_MAX;         // The smallest input row value
    104     int xSize = 0, ySize = 0;           // The size of the output image
    105 
    106     int xMin = INT_MAX;
    107     int yMin = INT_MAX;
    108     int xMax = 0;
    109     int yMax = 0;
    110 
    111     bool valid = false;                 // Do we have a single valid input?
    112     for (long i = 0; i < inputs->n; i++) {
    113         pmReadout *readout = inputs->data[i]; // Readout of interest
    114 
    115         if (!readout || !readout->image) {
    116             psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %ld is NULL or has NULL image.\n", i);
    117             return false;
    118         }
    119 
    120         // use the trimsec to define the max full range of the output pixels
    121         pmCell *cell = readout->parent; // The parent cell
    122         bool mdok = true;       // Status of MD lookup
    123         psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section
    124         if (!mdok || !trimsec || psRegionIsNaN(*trimsec)) {
    125             psLogMsg(__func__, PS_LOG_WARN, "CELL.TRIMSEC is not set for readout %ld --- ignored.\n", i);
    126         } else {
    127             xSize = PS_MAX(xSize, trimsec->x1 - trimsec->x0);
    128             ySize = PS_MAX(ySize, trimsec->y1 - trimsec->y0);
    129             xMin  = PS_MIN(xMin,  trimsec->x0);
    130             xMax  = PS_MAX(xMax,  trimsec->x1);
    131             yMin  = PS_MIN(yMin,  trimsec->y0);
    132             yMax  = PS_MAX(yMax,  trimsec->y1);
    133         }
    134 
    135         if (params->weights && !readout->weight) {
    136             psError(PS_ERR_UNEXPECTED_NULL, true,
    137                     "Rejection based on weights requested, but no weights supplied for image %ld.\n", i);
    138             return false;
    139         }
    140 
    141         valid = true;
    142 
    143         // Range of pixels on output image
    144         minInputCols = PS_MAX (xMin, PS_MIN(minInputCols, readout->col0));
    145         maxInputCols = PS_MIN (xMax, PS_MAX(maxInputCols, readout->col0 + readout->image->numCols));
    146         minInputRows = PS_MAX (yMin, PS_MIN(minInputRows, readout->row0));
    147         maxInputRows = PS_MIN (yMax, PS_MAX(maxInputRows, readout->row0 + readout->image->numRows));
    148         psTrace("psModules.imcombine", 7, "Readout %ld: offset %d,%d; size %dx%d\n", i,
    149                 readout->col0, readout->row0, readout->image->numCols, readout->image->numRows);
    150     }
    151 
    152     if (!valid) {
    153         psError(PS_ERR_IO, true, "No valid inputs.\n");
    154         return NULL;
    155     }
    156 
    157     // Update the origin
    158     // XXX EAM : use a macro (see psImage.h for PS_IMAGE_SET_ROW0, etc)
    159     if (output->image) {
    160         *(psS32 *) &(output->col0) = PS_MIN(minInputCols, output->col0);
    161         *(psS32 *) &(output->row0) = PS_MIN(minInputRows, output->row0);
    162     } else {
    163         *(psS32 *) &(output->col0) = minInputCols;
    164         *(psS32 *) &(output->row0) = minInputRows;
    165     }
     107    int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine
     108    int xSize, ySize;                   // Size of the output image
     109    if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize,
     110                                inputs)) {
     111        psError(PS_ERR_UNKNOWN, false, "No valid input readouts.");
     112        return false;
     113    }
     114
     115    pmReadoutUpdateSize(output, minInputCols, minInputRows, xSize, ySize, true);
    166116    psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0);
    167 
    168     // Allocate the output products
    169 
    170     if (!output->image) {
    171         output->image = psImageAlloc(xSize, ySize, PS_TYPE_F32);
    172     }
    173     if (output->image->numCols < xSize || output->image->numRows < ySize) {
    174         // Generate the new output image by extending the current one, or making a whole new one
    175         psImage *newImage = psImageAlloc(xSize, ySize, PS_TYPE_F32);
    176         psImageInit(newImage, 0.0);
    177         psImageOverlaySection(newImage, output->image, output->col0, output->row0, "=");
    178         psFree(output->image);
    179         output->image = newImage;
    180     }
    181 
    182     if (!output->mask) {
    183         output->mask = psImageAlloc(xSize, ySize, PS_TYPE_U8);
    184     }
    185     if (output->mask->numCols < xSize || output->mask->numRows < ySize) {
    186         psImage *newMask = psImageAlloc(xSize, ySize, PS_TYPE_U8);
    187         psImageInit(newMask, 0);
    188         psImageOverlaySection(newMask, output->mask, output->col0, output->row0, "=");
    189         psFree(output->mask);
    190         output->mask = newMask;
    191     }
    192117
    193118    psStatsOptions combineStdev = 0; // Statistics option for weights
     
    426351    psFree(inputCells);
    427352
     353    output->data_exists = true;
     354    output->parent->data_exists = true;
     355    output->parent->parent->data_exists = true;
     356
    428357    return success;
    429358}
Note: See TracChangeset for help on using the changeset viewer.