IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 31, 2008, 2:01:26 PM (18 years ago)
Author:
eugene
Message:

src/objects/Makefile.am

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmReadoutStack.c

    r17228 r18830  
    88
    99#include "pmReadoutStack.h"
     10
     11// generate the specified image
     12// XXX should it be an error for the image to exist?
     13psImage *pmReadoutSetAnalysisImage(pmReadout *readout, // Readout containing image
     14                                   const char *name, // Name of image in analysis metadata
     15                                   int numCols, int numRows, // Expected size of image
     16                                   psElemType type, // Expected type of image
     17                                   double init // Initial value
     18    )
     19{
     20    PS_ASSERT_PTR_NON_NULL(readout, false);
     21    PS_ASSERT_STRING_NON_EMPTY(name, false);
     22
     23    psImage *image = psImageAlloc(numCols, numRows, type);
     24
     25    if (!psMetadataAddImage(readout->analysis, PS_LIST_TAIL, name, 0, "Analysis image from " __FILE__, image)) {
     26        psAbort ("analysis image already exists");
     27    }
     28    psImageInit(image, init);
     29
     30    psFree (image); // we still have a view on readout->analysis
     31    return image;
     32}
     33
     34// retrieve the specified image
     35// XXX not sure why this should call psMemIncrRefCounter
     36psImage *pmReadoutGetAnalysisImage(pmReadout *readout, // Readout containing image
     37                                   const char *name       // Name of image in analysis metadata
     38    )
     39{
     40    PS_ASSERT_PTR_NON_NULL(readout, false);
     41    PS_ASSERT_STRING_NON_EMPTY(name, false);
     42
     43    bool mdok;                          // Status of MD lookup
     44    psImage *image = psMetadataLookupPtr(&mdok, readout->analysis, name);
     45    return image;
     46}
    1047
    1148psImage *pmReadoutAnalysisImage(pmReadout *readout, // Readout containing image
     
    4077}
    4178
    42 bool pmReadoutUpdateSize(pmReadout *readout, int minCols, int minRows,
    43                          int numCols, int numRows, bool mask, bool weight,
    44                          psMaskType blank)
    45 {
    46     PS_ASSERT_PTR_NON_NULL(readout, false);
    47 
    48     if (readout->image) {
    49         readout->col0 = PS_MIN(minCols, readout->col0);
    50         readout->row0 = PS_MIN(minRows, readout->row0);
    51     } else {
    52         readout->col0 = minCols;
    53         readout->row0 = minRows;
    54     }
    55 
    56     // (reAllocate the images
    57     if (!readout->image) {
    58         readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    59         psImageInit(readout->image, NAN);
    60     }
    61     if (readout->image->numCols < numCols || readout->image->numRows < numRows) {
    62         // Generate the new output image by extending the current one, or making a whole new one
    63         psImage *newImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    64         psImageInit(newImage, NAN);
    65         psImageOverlaySection(newImage, readout->image, readout->col0, readout->row0, "=");
    66         psFree(readout->image);
    67         readout->image = newImage;
    68     }
     79// XXX for the moment, use col0, row0, numCols, numRows supplied from the outside
     80bool pmReadoutStackDefineOutput(pmReadout *readout, int col0, int row0, int numCols, int numRows, bool mask, bool weight, psMaskType blank)
     81{
     82    PS_ASSERT_PTR_NON_NULL(readout, false);
     83
     84    // XXX is this an error?
     85    if (readout->image) return false;
     86    readout->col0 = col0;
     87    readout->row0 = row0;
     88
     89    // allocate the images
     90    readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     91    psImageInit(readout->image, NAN);
    6992
    7093    if (mask) {
    71         if (!readout->mask) {
    72             readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
    73             psImageInit(readout->mask, blank);
    74         }
    75         if (readout->mask->numCols < numCols || readout->mask->numRows < numRows) {
    76             psImage *newMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
    77             psImageInit(newMask, blank);
    78             psImageOverlaySection(newMask, readout->mask, readout->col0, readout->row0, "=");
    79             psFree(readout->mask);
    80             readout->mask = newMask;
    81         }
     94        // XXX is this an error?
     95        if (readout->mask) return false;
     96        readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     97        psImageInit(readout->mask, blank);
    8298    }
    8399
    84100    if (weight) {
    85         if (!readout->weight) {
    86             readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    87             psImageInit(readout->weight, NAN);
    88         }
    89         if (readout->weight->numCols < numCols || readout->weight->numRows < numRows) {
    90             psImage *newWeight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    91             psImageInit(newWeight, NAN);
    92             psImageOverlaySection(newWeight, readout->weight, readout->col0, readout->row0, "=");
    93             psFree(readout->weight);
    94             readout->weight = newWeight;
    95         }
     101        // XXX is this an error?
     102        if (readout->weight) return false;
     103        readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     104        psImageInit(readout->weight, NAN);
    96105    }
    97106
     
    99108}
    100109
    101 bool pmReadoutStackValidate(int *minInputColsPtr, int *maxInputColsPtr, int *minInputRowsPtr,
    102                             int *maxInputRowsPtr, int *numColsPtr, int *numRowsPtr,
    103                             const psArray *inputs)
     110bool pmReadoutStackSetOutputSize(int *col0, int *row0, int *numCols, int *numRows, const psArray *inputs)
    104111{
    105112    PS_ASSERT_ARRAY_NON_NULL(inputs, false);
    106     PS_ASSERT_PTR_NON_NULL(minInputColsPtr, false);
    107     PS_ASSERT_PTR_NON_NULL(maxInputColsPtr, false);
    108     PS_ASSERT_PTR_NON_NULL(minInputRowsPtr, false);
    109     PS_ASSERT_PTR_NON_NULL(maxInputRowsPtr, false);
    110     PS_ASSERT_PTR_NON_NULL(numColsPtr, false);
    111     PS_ASSERT_PTR_NON_NULL(numRowsPtr, false);
    112 
    113     // Step through each readout in the input image list to determine how big of an output image is needed to
    114     // combine these input images.
    115     int maxInputCols = 0;               // The largest input column value
    116     int maxInputRows = 0;               // The largest input row value
    117     int minInputCols = INT_MAX;         // The smallest input column value
    118     int minInputRows = INT_MAX;         // The smallest input row value
    119     int xSize = 0, ySize = 0;           // The size of the output image
     113    PS_ASSERT_PTR_NON_NULL(col0, false);
     114    PS_ASSERT_PTR_NON_NULL(row0, false);
     115    PS_ASSERT_PTR_NON_NULL(numCols, false);
     116    PS_ASSERT_PTR_NON_NULL(numRows, false);
     117
     118    // Step through each readout in the input image list to determine how big of an output
     119    // image is needed to combine these input images.
    120120
    121121    int xMin = INT_MAX;
     
    123123    int xMax = 0;
    124124    int yMax = 0;
     125    int xSize = 0;
     126    int ySize = 0;           // The size of the output image
    125127
    126128    bool valid = false;                 // Do we have a single valid input?
     
    128130        pmReadout *readout = inputs->data[i]; // Readout of interest
    129131
    130         if (!readout) {
    131             continue;
    132         }
    133         if (!readout->image) {
    134             psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %ld has NULL image.\n", i);
    135             return false;
    136         }
     132        if (!readout) continue;
    137133
    138134        // use the trimsec to define the max full range of the output pixels
     
    150146            yMax  = PS_MAX(yMax,  trimsec->y1);
    151147        }
     148        valid = true;
     149        psTrace("psModules.camera", 7, "Readout %ld: trimsec: %f,%f - %f,%f\n", i, trimsec->x0, trimsec->y0, trimsec->x1, trimsec->y1);
     150    }
     151
     152    *col0 = xMin;
     153    *row0 = yMin;
     154    *numCols = xSize;
     155    *numRows = ySize;
     156
     157    if (!valid) {
     158        psError(PS_ERR_UNKNOWN, false, "No valid input readouts.");
     159    }
     160    return valid;
     161}
     162
     163bool pmReadoutUpdateSize(pmReadout *readout, int minCols, int minRows,
     164                         int numCols, int numRows, bool mask, bool weight,
     165                         psMaskType blank)
     166{
     167    PS_ASSERT_PTR_NON_NULL(readout, false);
     168
     169    if (readout->image) {
     170        readout->col0 = PS_MIN(minCols, readout->col0);
     171        readout->row0 = PS_MIN(minRows, readout->row0);
     172    } else {
     173        readout->col0 = minCols;
     174        readout->row0 = minRows;
     175    }
     176
     177    // (reAllocate the images
     178    if (!readout->image) {
     179        readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     180        psImageInit(readout->image, NAN);
     181    }
     182    if (readout->image->numCols < numCols || readout->image->numRows < numRows) {
     183        // Generate the new output image by extending the current one, or making a whole new one
     184        psImage *newImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     185        psImageInit(newImage, NAN);
     186        psImageOverlaySection(newImage, readout->image, readout->col0, readout->row0, "=");
     187        psFree(readout->image);
     188        readout->image = newImage;
     189    }
     190
     191    if (mask) {
     192        if (!readout->mask) {
     193            readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     194            psImageInit(readout->mask, blank);
     195        }
     196        if (readout->mask->numCols < numCols || readout->mask->numRows < numRows) {
     197            psImage *newMask = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
     198            psImageInit(newMask, blank);
     199            psImageOverlaySection(newMask, readout->mask, readout->col0, readout->row0, "=");
     200            psFree(readout->mask);
     201            readout->mask = newMask;
     202        }
     203    }
     204
     205    if (weight) {
     206        if (!readout->weight) {
     207            readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     208            psImageInit(readout->weight, NAN);
     209        }
     210        if (readout->weight->numCols < numCols || readout->weight->numRows < numRows) {
     211            psImage *newWeight = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     212            psImageInit(newWeight, NAN);
     213            psImageOverlaySection(newWeight, readout->weight, readout->col0, readout->row0, "=");
     214            psFree(readout->weight);
     215            readout->weight = newWeight;
     216        }
     217    }
     218
     219    return true;
     220}
     221
     222bool pmReadoutStackValidate(int *minInputColsPtr, int *maxInputColsPtr, int *minInputRowsPtr,
     223                            int *maxInputRowsPtr, int *numColsPtr, int *numRowsPtr,
     224                            const psArray *inputs)
     225{
     226    PS_ASSERT_ARRAY_NON_NULL(inputs, false);
     227    PS_ASSERT_PTR_NON_NULL(minInputColsPtr, false);
     228    PS_ASSERT_PTR_NON_NULL(maxInputColsPtr, false);
     229    PS_ASSERT_PTR_NON_NULL(minInputRowsPtr, false);
     230    PS_ASSERT_PTR_NON_NULL(maxInputRowsPtr, false);
     231    PS_ASSERT_PTR_NON_NULL(numColsPtr, false);
     232    PS_ASSERT_PTR_NON_NULL(numRowsPtr, false);
     233
     234    // Step through each readout in the input image list to determine how big of an output image is needed to
     235    // combine these input images.
     236    int maxInputCols = 0;               // The largest input column value
     237    int maxInputRows = 0;               // The largest input row value
     238    int minInputCols = INT_MAX;         // The smallest input column value
     239    int minInputRows = INT_MAX;         // The smallest input row value
     240    int xSize = 0, ySize = 0;           // The size of the output image
     241
     242    int xMin = INT_MAX;
     243    int yMin = INT_MAX;
     244    int xMax = 0;
     245    int yMax = 0;
     246
     247    bool valid = false;                 // Do we have a single valid input?
     248    for (long i = 0; i < inputs->n; i++) {
     249        pmReadout *readout = inputs->data[i]; // Readout of interest
     250
     251        if (!readout) {
     252            continue;
     253        }
     254        if (!readout->image) {
     255            psError(PS_ERR_UNEXPECTED_NULL, true, "Input readout %ld has NULL image.\n", i);
     256            return false;
     257        }
     258
     259        // use the trimsec to define the max full range of the output pixels
     260        pmCell *cell = readout->parent; // The parent cell
     261        bool mdok = true;       // Status of MD lookup
     262        psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section
     263        if (!mdok || !trimsec || psRegionIsNaN(*trimsec)) {
     264            psWarning("CELL.TRIMSEC is not set for readout %ld --- ignored.\n", i);
     265        } else {
     266            xSize = PS_MAX(xSize, trimsec->x1 - trimsec->x0);
     267            ySize = PS_MAX(ySize, trimsec->y1 - trimsec->y0);
     268            xMin  = PS_MIN(xMin,  trimsec->x0);
     269            xMax  = PS_MAX(xMax,  trimsec->x1);
     270            yMin  = PS_MIN(yMin,  trimsec->y0);
     271            yMax  = PS_MAX(yMax,  trimsec->y1);
     272        }
    152273
    153274        valid = true;
     
    158279        minInputRows = PS_MAX(yMin, PS_MIN(minInputRows, readout->row0));
    159280        maxInputRows = PS_MIN(yMax, PS_MAX(maxInputRows, readout->row0 + readout->image->numRows));
    160         psTrace("psModules.camera", 7, "Readout %ld: offset %d,%d; size %dx%d\n", i,
    161                 readout->col0, readout->row0, readout->image->numCols, readout->image->numRows);
     281
     282        psTrace("psModules.camera", 7, "Readout %ld: offset %d,%d; size %dx%d\n", i, readout->col0, readout->row0, readout->image->numCols, readout->image->numRows);
    162283    }
    163284
Note: See TracChangeset for help on using the changeset viewer.