Changeset 12771 for trunk/pswarp/src/pswarpTransformReadout_Opt.c
- Timestamp:
- Apr 5, 2007, 5:38:16 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/pswarp/src/pswarpTransformReadout_Opt.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarpTransformReadout_Opt.c
r12744 r12771 2 2 3 3 // NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT 4 bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config) { 5 6 bool status; 7 int minX, minY, maxX, maxY; 8 int gridXo, gridX, gridY, nextGridXo, nextGridX, nextGridY; 9 pswarpMap *map = NULL; 10 psImageInterpolateMode interpolationMode = PS_INTERPOLATE_NONE; 11 4 bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config) 5 { 12 6 // XXX this implementation currently ignores the use of the region 13 7 psImage *region = NULL; … … 15 9 psTimerStart ("warp"); 16 10 17 // select the current recipe 18 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 19 if (!recipe) { 20 psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n"); 21 return false; 22 } 23 24 int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX"); 25 if (!status) nGridX = 128; 26 int nGridY = psMetadataLookupS32 (&status, recipe, "GRID.NY"); 27 if (!status) nGridY = 128; 28 29 char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE"); 30 if (!name) { 31 interpolationMode = PS_INTERPOLATE_BILINEAR; 32 psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n"); 33 } else { 34 interpolationMode = psImageInterpolateModeFromString (name); 35 if (interpolationMode == PS_INTERPOLATE_NONE) { 36 interpolationMode = PS_INTERPOLATE_BILINEAR; 37 psLogMsg ("pswarp", 3, "unknown interpolation mode %s, defaulting to bilinear interpolation\n", name); 38 } 39 } 40 41 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 42 psImage *inImage = input->image; 43 psF32 **outData = output->image->data.F32; 11 // Get grid size 12 int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX"); 13 int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY"); 14 psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments, 15 "INTERPOLATION.MODE"); 16 psMaskType maskIn = psMetadataLookupU8(NULL, config->arguments, "MASK.IN"); // Mask for input data 17 psMaskType maskPoor = psMetadataLookupU8(NULL, config->arguments, "MASK.POOR"); // Mask for "poor" data 18 psMaskType maskBad = psMetadataLookupU8(NULL, config->arguments, "MASK.IN"); // Mask for bad data 19 float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); // Flux fraction for "poor" 44 20 45 21 // we need to apply the offset to convert parent coordinates to child coordinates for … … 54 30 55 31 // find the output pixel range 32 int minX, minY, maxX, maxY; 56 33 pswarpMatchRange (&minX, &minY, &maxX, &maxY, input, output); 57 34 … … 64 41 psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError); 65 42 43 int gridX, gridY, nextGridX, nextGridY; 66 44 pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY); 67 45 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY); 68 map = grid->maps[gridX][gridY];46 pswarpMap *map = grid->maps[gridX][gridY]; 69 47 70 48 assert ((int)(minX - outCol0) >= 0); … … 73 51 assert ((int)(maxY - outRow0) <= output->image->numRows); 74 52 75 gridXo = gridX;76 nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);53 int gridXo = gridX; 54 int nextGridXo = pswarpMapGridNextGrid_X (grid, gridX); 77 55 78 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage, 79 NULL, NULL, 0, NAN, NAN, 0, 0, 0.0); 56 psImage *inImage = input->image; // Input image 57 psImage *inVar = input->weight; // Input weight map 58 psImage *inMask = input->mask; // Input mask 59 60 // Interpolation options 61 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(interpolationMode, inImage, 62 inVar, inMask, maskIn, NAN, NAN, 63 maskPoor, maskBad, poorFrac); 64 65 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 66 psF32 **outImageData = output->image->data.F32; // Output image pixels 67 psF32 **outVarData; // Output variance pixels 68 psMaskType **outMaskData; // Output mask pixels 69 if (inVar) { 70 if (!output->weight) { 71 output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32); 72 } 73 outVarData = output->weight->data.F32; 74 } 75 if (inMask) { 76 if (!output->mask) { 77 output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK); 78 } 79 outMaskData = output->mask->data.PS_TYPE_MASK_DATA; 80 } 80 81 81 82 // Iterate over the output image pixels (parent frame) … … 112 113 // XXX apply scale and offset? 113 114 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 114 double value; 115 if (!psImageInterpolate(&value, NULL, NULL, inPix->x - inCol0, inPix->y - inRow0, interp)) { 115 double imageValue, varValue; 116 psMaskType maskValue; 117 if (!psImageInterpolate(&imageValue, &varValue, &maskValue, 118 inPix->x - inCol0, inPix->y - inRow0, interp)) { 116 119 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 117 120 psFree(interp); … … 120 123 return false; 121 124 } 122 outData[y-outRow0][x-outCol0] = value; 125 outImageData[y-outRow0][x-outCol0] = imageValue; 126 if (inVar) { 127 outVarData[y-outRow0][x-outCol0] = varValue; 128 } 129 if (inMask) { 130 outMaskData[y-outRow0][x-outCol0] = maskValue; 131 } 123 132 } 124 133 }
Note:
See TracChangeset
for help on using the changeset viewer.
