- Timestamp:
- Jul 27, 2008, 8:00:23 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080719/pswarp/src/pswarpTransformTile.c
r18666 r18752 1 # include "pswarp.h" 1 2 2 // XXX need to determine all of the needed inputs and put them in a structure 3 void pswarpTransformTileArgsFree (pswarpTransformTileArgs *args) { 4 if (!args) return; 5 return; 6 } 3 7 4 typedef struct { 5 int gridX; 6 int gridY; 7 } pswarpTransformTileOpts; 8 pswarpTransformTileArgs *pswarpTransformTileArgsAlloc() { 8 9 9 pswarpTransformTile (int gridX, int gridY) { 10 pswarpTransformTileArgs *args = (pswarpTransformTileArgs *)psAlloc(sizeof(pswarpTransformTileArgs)); 11 psMemSetDeallocator(args, (psFreeFunc)pswarpTransformTileArgsFree); 10 12 11 minX = pswarpMapGridNextGrid_Y (grid, gridY); 12 minY = pswarpMapGridNextGrid_X (grid, gridX); 13 args->input = NULL; 14 args->output = NULL; 15 args->grid = NULL; 16 args->interp = NULL; 17 args->region = NULL; 13 18 14 maxX = pswarpMapGridNextGrid_Y (grid, gridY);15 maxY = pswarpMapGridNextGrid_X (grid, gridX);19 args->gridX = 0; 20 args->gridY = 0; 16 21 17 map = grid->maps[gridX][gridY];22 args->goodPixels = 0; 18 23 19 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 24 return args; 25 } 26 27 bool pswarpTransformTile (pswarpTransformTileArgs *args) { 28 29 // int inCol0 = args->input->image->col0; 30 // int inRow0 = args->input->image->row0; 31 int inNcol = args->input->image->numCols; 32 int inNrow = args->input->image->numRows; 33 34 int outCol0 = args->output->image->col0; 35 int outRow0 = args->output->image->row0; 36 // int outNcol = args->output->image->numCols; 37 // int outNrow = args->output->image->numRows; 38 39 // XXX these are wrong (min or max is wrong) 40 int minX = pswarpMapGridNextGrid_Y (args->grid, args->gridY); 41 int minY = pswarpMapGridNextGrid_X (args->grid, args->gridX); 42 int maxX = pswarpMapGridNextGrid_Y (args->grid, args->gridY); 43 int maxY = pswarpMapGridNextGrid_X (args->grid, args->gridX); 44 45 psF32 **outImageData = args->output->image->data.F32; 46 psF32 **outVarData = args->output->weight->data.F32; 47 psMaskType **outMaskData = args->output->mask->data.U8; 48 49 pswarpMap *map = args->grid->maps[args->gridX][args->gridY]; 50 51 psImage *region = args->region; 52 53 double xInRaw, yInRaw; 54 55 // output values for this pixel 56 double imageValue; 57 double varValue; 58 psMaskType maskValue; 20 59 21 60 // Iterate over the output image pixels (parent frame) 22 61 long goodPixels = 0; // Number of input pixels landing on the output image 23 62 for (int y = minY; y < maxY; y++) { 24 int yOut = y - outRow0; // Position on image25 63 for (int x = minX; x < maxX; x++) { 26 64 … … 30 68 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate. 31 69 // both are in the parent frames of the input and output images. 32 pswarpMapApply (& inPix->x, &inPix->y, map, x + 0.5, y + 0.5);70 pswarpMapApply (&xInRaw, &yInRaw, map, x + 0.5, y + 0.5); 33 71 34 if (inPix->x - inCol0 < 0) continue; 35 if (inPix->x - inCol0 >= inImage->numCols) continue; 36 if (inPix->y - inRow0 < 0) continue; 37 if (inPix->y - inRow0 >= inImage->numRows) continue; 72 double xIn = xInRaw - outCol0; // Position on input image 73 double yIn = yInRaw - outRow0; // Position on input image 74 75 if (xIn < 0) continue; 76 if (yIn >= inNcol) continue; 77 if (yIn < 0) continue; 78 if (yIn >= inNrow) continue; 38 79 39 80 goodPixels++; 40 81 41 // XXX include mask42 // XXX apply scale and offset?43 82 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 44 double imageValue, varValue; 45 psMaskType maskValue; 46 if (!psImageInterpolate(&imageValue, &varValue, &maskValue, 47 inPix->x - inCol0, inPix->y - inRow0, interp)) { 83 if (!psImageInterpolate(&imageValue, &varValue, &maskValue, xIn, yIn, args->interp)) { 48 84 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 49 psFree(interp);50 psFree(inPix);51 psFree(grid);52 85 return false; 53 86 } 54 int xOut = x - outCol0; // Position on image 55 outImageData[yOut][xOut] = imageValue; 56 if (inVar) { 87 88 int xOut = x - outCol0; // Position on output image 89 int yOut = y - outRow0; // Position on output image 90 91 // not all images need be transformed 92 if (outImageData) { 93 outImageData[yOut][xOut] = imageValue; 94 } 95 if (outVarData) { 57 96 outVarData[yOut][xOut] = varValue; 58 97 } … … 62 101 } 63 102 } 64 65 psFree(inPix);103 args->goodPixels = goodPixels; 104 return true; 66 105 }
Note:
See TracChangeset
for help on using the changeset viewer.
