IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 7, 2007, 3:28:00 PM (20 years ago)
Author:
eugene
Message:

added local linear map

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/pswarpTransformReadout_Opt.c

    r10954 r10957  
    11# include "pswarp.h"
    22
    3 bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config) {
     3// NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT
     4bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config) {
     5
     6    int minX, minY, maxX, maxY;
     7    int gridX, gridY, nextGridX, nextGridY;
     8    pswarpMap *map = NULL;
    49
    510    // XXX this implementation currently ignores the use of the region
    611    psImage *region = NULL;
    7     pmCell *cell = NULL;
    812
    913    // select the current recipe
    10     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
    11 
    12     int outNx = output->image->numCols;
    13     int outNy = output->image->numRows;
     14    // psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
    1415
    1516    psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
    16     psPlane *outPix = psPlaneAlloc();   // Coordinates on the output detector
    17 
    18     psPlane *FP = psPlaneAlloc();       // Coordinates on the focal plane
    19     psPlane *TP = psPlaneAlloc();       // Coordinates on the tangent plane
    20     psSphere *sky = psSphereAlloc();    // Coordinates on the sky
    21 
    22     cell = input->parent;
    23     pmChip *chipInput = cell->parent;
    24     pmFPA *fpaInput = chipInput->parent;
    25 
    26     cell = output->parent;
    27     pmChip *chipOutput = cell->parent;
    28     pmFPA *fpaOutput = chipOutput->parent;
    29 
     17    psImage *inImage = input->image;
    3018    psF32 **outData = output->image->data.F32;
    31     psImage *inImage = input->image;
    3219
    3320    // we might want to do the rectangular regions outside of the selection independently
     
    3724    pswarpMatchRange (&minX, &minY, &maxX, &maxY, input, output);
    3825
     26    pswarpMapGrid *grid = pswarpMapGridFromImage (input, output, 128, 128);
     27
     28    // XXX need to modify the grid based on this result and force the maxError < XXX
     29    double maxError = pswarpMapGridMaxError (grid);
     30    fprintf (stderr, "maximum error using this grid sampling: %f\n", maxError);
     31
     32    pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY);
     33    pswarpMapGridNextGrid (grid, gridX, gridY, &nextGridX, &nextGridY);
     34    map = grid->maps[gridX][gridY];
     35
    3936    // Iterate over the output image pixels
    40     for (int y = 0; y < outNy; y++) {
    41         for (int x = 0; x < outNx; x++) {
     37    for (int y = minY; y < maxY; y++) {
     38        if (y >= nextGridY) {
     39            gridY ++;
     40            pswarpMapGridNextGrid (grid, gridX, gridY, &nextGridX, &nextGridY);
     41            map = grid->maps[gridX][gridY];
     42        }
     43        for (int x = minX; x < maxX; x++) {
     44            if (x >= nextGridX) {
     45                gridX ++;
     46                pswarpMapGridNextGrid (grid, gridX, gridY, &nextGridX, &nextGridY);
     47                map = grid->maps[gridX][gridY];
     48            }
     49
    4250            // Only transform those pixels requested
    43             if (!region || (region && region->data.U8[y][x])) {
    44                 // Transform!
     51            if (region && region->data.U8[y][x]) continue;
    4552
    46                 // XXX double check this 1/2 pixel offset
    47                 outPix->x = (double)x + 0.5;
    48                 outPix->y = (double)y + 0.5;
     53            // XXX double check this 1/2 pixel offset
     54            // XXX subtract 0.5,0.5 from result?
     55            pswarpMapApply (&inPix->x, &inPix->y, map, x + 0.5, y + 0.5);
    4956
    50                 psPlaneTransformApply(FP, chipOutput->toFPA, outPix);
    51                 psPlaneTransformApply (TP, fpaOutput->toTPA, FP);
    52                 psDeproject (sky, TP, fpaOutput->toSky);
    53                
    54                 psProject (TP, sky, fpaInput->toSky);
    55                 psPlaneTransformApply (FP, fpaInput->fromTPA, TP);
    56                 psPlaneTransformApply (inPix, chipInput->fromFPA, FP);
    57 
    58                 // XXX get interpolation method from the recipe
    59                 outImage->data.F32[y][x] = (psF32)psImagePixelInterpolate(image, inPix->x, inPix->y, mask, 1, NAN, PS_INTERPOLATE_BILINEAR);
    60 
    61 # if (0)
    62                 if (error) {
    63                     // Error is actually the variance
    64                     outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error,
    65                                                                                             detector->x,
    66                                                                                             detector->y,
    67                                                                                             mask, 1, NAN);
    68                 }
    69 # endif
    70 
    71                 outImage->data.F32[y][x] = (outImage->data.F32[y][x] - offset) / scale;
    72 # if (0)
    73                 if (error) {
    74                     outError->data.F32[y][x] = outError->data.F32[y][x] / SQUARE(scale);
    75                 }
    76 # endif
    77 
    78             } // Pixels of interest
    79 
     57            // XXX get interpolation method from the recipe
     58            // XXX include mask
     59            // XXX apply scale and offset?
     60            outData[y][x] = (psF32)psImagePixelInterpolate(inImage, inPix->x, inPix->y, NULL, 1, NAN, PS_INTERPOLATE_BILINEAR);
    8061        }
    81     } // Iterating over output pixels
    82 
     62    }
    8363    return true;
    8464}
    8565
     66# if (0)
     67    if (error) {
     68        // Error is actually the variance
     69        outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error,
     70                                                                                detector->x,
     71                                                                                detector->y,
     72                                                                                mask, 1, NAN);
     73    }
     74    if (error) {
     75        outError->data.F32[y][x] = outError->data.F32[y][x] / SQUARE(scale);
     76    }
     77# endif
     78
    8679   
Note: See TracChangeset for help on using the changeset viewer.