IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 27, 2008, 8:00:23 AM (18 years ago)
Author:
eugene
Message:

threaded and unthreaded equivalent versions now compile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080719/pswarp/src/pswarpTransformReadout_Threaded.c

    r18666 r18752  
    1515    int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX");
    1616    int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY");
    17     psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments,
    18                                                                    "INTERPOLATION.MODE");
     17    psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments, "INTERPOLATION.MODE");
     18
    1919    // load the recipe
    2020    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
    21     if (!recipe) {
    22         psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
    23         return false;
    24     }
     21    psAssert (recipe, "missing recipe %s", PSWARP_RECIPE);
    2522
    2623    // output mask bits
     
    3027    psAssert (mdok, "MASK.INPUT was not defined");
    3128
    32     float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); // Flux fraction for "poor"
    33 
    34     // we need to apply the offset to convert parent coordinates to child coordinates for
    35     // psImagePixelInterpolate below
    36     int inCol0 = input->image->col0;
    37     int inRow0 = input->image->row0;
    38     int outCol0 = output->image->col0;
    39     int outRow0 = output->image->row0;
    40 
    41     // we might want to do the rectangular regions outside of the selection independently
    42     // psImageInit (output->image, NAN);
     29    // Flux fraction for "poor"
     30    float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC");
    4331
    4432    // find the output pixel range
     
    5442    psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError);
    5543
    56     int gridX, gridY, nextGridX, nextGridY;
     44    int gridX, gridY;
    5745    pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY);
    58     nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);
    59     pswarpMap *map = grid->maps[gridX][gridY];
    60 
     46# if (0)
     47    // XXX these asserts probably belong in the function (don't have outCol0,Row0 anyway)
    6148    assert ((int)(minX - outCol0) >= 0);
    6249    assert ((int)(maxX - outCol0) <= output->image->numCols);
    6350    assert ((int)(minY - outRow0) >= 0);
    6451    assert ((int)(maxY - outRow0) <= output->image->numRows);
    65 
    66     int gridXo = gridX;
    67     int nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);
     52# endif
    6853
    6954    psImage *inImage = input->image;    // Input image
     
    7661                                                                       maskBad, maskPoor, poorFrac);
    7762
    78     psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
    79     psF32 **outImageData = output->image->data.F32; // Output image pixels
    80     psF32 **outVarData = NULL;          // Output variance pixels
    81     psMaskType **outMaskData = NULL;    // Output mask pixels
    82     if (inVar) {
    83         if (!output->weight) {
    84             output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32);
    85             psImageInit(output->weight, NAN);
    86         }
    87         outVarData = output->weight->data.F32;
    88     }
    89     if (inMask || maskPoor || maskBad) {
    90         if (!output->mask) {
    91             output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK);
    92             psImageInit(output->mask, maskBad);
    93         }
    94         outMaskData = output->mask->data.PS_TYPE_MASK_DATA;
    95     }
    96 
    97     // create N threads
    98     for (gridY = gridYmin; gridY < gridYmax; gridY++) {
    99         for (gridX = gridXmin; gridX < gridXmax; gridX++) {
    100             pswarpTransformTile (gridX, gridY);
    101             // send function and arguments to thread manager
    102             // threadFunction (pswarpTransformTile)
    103             // while (threadFull()) {
    104             // usleep (50000);
    105             // }
     63    if (inVar && !output->weight) {
     64        output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32);
     65        psImageInit(output->weight, NAN);
     66    }
     67    if ((inMask || maskPoor || maskBad) && !output->mask) {
     68        output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK);
     69        psImageInit(output->mask, maskBad);
     70    }
     71
     72    // total number of good pixels across all tiles (summed below)
     73    int goodPixels = 0;
     74
     75    // create jobs and supply them to the threads
     76    for (gridY = 0; gridY < nGridX; gridY++) {
     77        for (gridX = 0; gridX < nGridY; gridX++) {
     78
     79            pswarpTransformTileArgs *args = pswarpTransformTileArgsAlloc();
     80
     81            // these items are just views to the data; they are not freed with args
     82            args->input = input;
     83            args->output = output;
     84            args->grid = grid;
     85            args->interp = interp;
     86            args->region = region;
     87
     88            args->gridX = gridX;
     89            args->gridY = gridY;
     90            args->goodPixels = 0;
     91
     92            // allocate a job
     93            psThreadJob *job = psThreadJobAlloc ("PSWARP_TRANSFORM_TILE", 0);
     94
     95            // construct the arguments for this job
     96            // job is pswarpTransformTile (gridX, gridY);
     97            psArrayAdd (job->args, 1, args);
     98            psThreadJobAddPending (job);
     99            psFree (args);
    106100        }
    107101    }
    108 
    109 
    110     // Iterate over the output image pixels (parent frame)
    111     long goodPixels = 0;                // Number of input pixels landing on the output image
    112     for (int y = minY; y < maxY; y++) {
    113         if (y >= nextGridY) {
    114             gridY ++;
    115             nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);
    116             map = grid->maps[gridX][gridY];
    117         }
    118 
    119         gridX = gridXo;
    120         nextGridX = nextGridXo;
    121         map = grid->maps[gridX][gridY];
    122         int yOut = y - outRow0;         // Position on image
    123         for (int x = minX; x < maxX; x++) {
    124             if (x >= nextGridX) {
    125                 gridX ++;
    126                 nextGridX = pswarpMapGridNextGrid_X (grid, gridX);
    127                 map = grid->maps[gridX][gridY];
    128             }
    129 
    130             // Only transform those pixels requested
    131             if (region && region->data.U8[y][x]) continue;
    132 
    133             // pswarpMapApply converts the output coordinate (x,y) to the input coordinate.
    134             // both are in the parent frames of the input and output images.
    135             pswarpMapApply (&inPix->x, &inPix->y, map, x + 0.5, y + 0.5);
    136 
    137             if (inPix->x - inCol0 < 0) continue;
    138             if (inPix->x - inCol0 >= inImage->numCols) continue;
    139             if (inPix->y - inRow0 < 0) continue;
    140             if (inPix->y - inRow0 >= inImage->numRows) continue;
    141 
    142             goodPixels++;
    143 
    144             // XXX include mask
    145             // XXX apply scale and offset?
    146             // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates
    147             double imageValue, varValue;
    148             psMaskType maskValue;
    149             if (!psImageInterpolate(&imageValue, &varValue, &maskValue,
    150                                     inPix->x - inCol0, inPix->y - inRow0, interp)) {
    151                 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
    152                 psFree(interp);
    153                 psFree(inPix);
    154                 psFree(grid);
    155                 return false;
    156             }
    157             int xOut = x - outCol0;     // Position on image
    158             outImageData[yOut][xOut] = imageValue;
    159             if (inVar) {
    160                 outVarData[yOut][xOut] = varValue;
    161             }
    162             if (outMaskData) {
    163                 outMaskData[yOut][xOut] = maskValue;
    164             }
    165         }
     102    // wait here for the threaded jobs to finish
     103    if (!psThreadPoolWait ()) {
     104        psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
     105        return false;
     106    }
     107    fprintf (stderr, "success for threaded jobs\n");
     108
     109    // each job records its own goodPixel values; sum them here
     110    // we have only supplied one type of job, so we can assume the types here
     111    psThreadJob *job = NULL;
     112    while ((job = psThreadJobGetDone()) != NULL) {
     113        pswarpTransformTileArgs *args = job->args->data[0];
     114        goodPixels += args->goodPixels;
     115        psFree (job);
    166116    }
    167117    psFree(interp);
    168     psFree(inPix);
    169118    psFree(grid);
    170119
    171120    // Store the variance factor and number of good pixels
    172121    if (goodPixels > 0) {
    173         float varFactor = psImageInterpolateVarianceFactor(inImage->numCols / 2.0 + inCol0,
    174                                                            inImage->numRows / 2.0 + inRow0,
     122        float varFactor = psImageInterpolateVarianceFactor(inImage->numCols / 2.0 + inImage->col0,
     123                                                           inImage->numRows / 2.0 + inImage->row0,
    175124                                                           interp); // Variance factor: large --> small scale
    176125        psMetadataItem *vfItem = psMetadataLookup(output->analysis, PSWARP_ANALYSIS_VARFACTOR);
     
    208157            pmModel *model = source->modelPSF; // Model for this source
    209158            float xIn, yIn;             // Coordinates of source
    210             xIn = model->params->data.F32[PM_PAR_XPOS] - inCol0;
    211             yIn = model->params->data.F32[PM_PAR_YPOS] - inRow0;
     159            xIn = model->params->data.F32[PM_PAR_XPOS] - inImage->col0;
     160            yIn = model->params->data.F32[PM_PAR_YPOS] - inImage->row0;
    212161            int xGrid, yGrid;           // Grid coordinates for local map
    213162            if (!pswarpMapGridSetGrid(sourceGrid, xIn + 0.5, yIn + 0.5, &xGrid, &yGrid)) {
     
    232181                return false;
    233182            }
    234             xOut += outCol0 - 0.5;
    235             yOut += outRow0 - 0.5;
     183            xOut += output->image->col0 - 0.5;
     184            yOut += output->image->row0 - 0.5;
    236185            if (xOut < minX || xOut > maxX || yOut < minY || yOut > maxY) {
    237186                // It's not in the output image
Note: See TracChangeset for help on using the changeset viewer.