- Timestamp:
- Jul 27, 2008, 8:00:23 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080719/pswarp/src/pswarpTransformReadout_Threaded.c
r18666 r18752 15 15 int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX"); 16 16 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 19 19 // load the recipe 20 20 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); 25 22 26 23 // output mask bits … … 30 27 psAssert (mdok, "MASK.INPUT was not defined"); 31 28 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"); 43 31 44 32 // find the output pixel range … … 54 42 psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError); 55 43 56 int gridX, gridY , nextGridX, nextGridY;44 int gridX, gridY; 57 45 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) 61 48 assert ((int)(minX - outCol0) >= 0); 62 49 assert ((int)(maxX - outCol0) <= output->image->numCols); 63 50 assert ((int)(minY - outRow0) >= 0); 64 51 assert ((int)(maxY - outRow0) <= output->image->numRows); 65 66 int gridXo = gridX; 67 int nextGridXo = pswarpMapGridNextGrid_X (grid, gridX); 52 # endif 68 53 69 54 psImage *inImage = input->image; // Input image … … 76 61 maskBad, maskPoor, poorFrac); 77 62 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); 106 100 } 107 101 } 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); 166 116 } 167 117 psFree(interp); 168 psFree(inPix);169 118 psFree(grid); 170 119 171 120 // Store the variance factor and number of good pixels 172 121 if (goodPixels > 0) { 173 float varFactor = psImageInterpolateVarianceFactor(inImage->numCols / 2.0 + in Col0,174 inImage->numRows / 2.0 + in Row0,122 float varFactor = psImageInterpolateVarianceFactor(inImage->numCols / 2.0 + inImage->col0, 123 inImage->numRows / 2.0 + inImage->row0, 175 124 interp); // Variance factor: large --> small scale 176 125 psMetadataItem *vfItem = psMetadataLookup(output->analysis, PSWARP_ANALYSIS_VARFACTOR); … … 208 157 pmModel *model = source->modelPSF; // Model for this source 209 158 float xIn, yIn; // Coordinates of source 210 xIn = model->params->data.F32[PM_PAR_XPOS] - in Col0;211 yIn = model->params->data.F32[PM_PAR_YPOS] - in Row0;159 xIn = model->params->data.F32[PM_PAR_XPOS] - inImage->col0; 160 yIn = model->params->data.F32[PM_PAR_YPOS] - inImage->row0; 212 161 int xGrid, yGrid; // Grid coordinates for local map 213 162 if (!pswarpMapGridSetGrid(sourceGrid, xIn + 0.5, yIn + 0.5, &xGrid, &yGrid)) { … … 232 181 return false; 233 182 } 234 xOut += out Col0 - 0.5;235 yOut += out Row0 - 0.5;183 xOut += output->image->col0 - 0.5; 184 yOut += output->image->row0 - 0.5; 236 185 if (xOut < minX || xOut > maxX || yOut < minY || yOut > maxY) { 237 186 // It's not in the output image
Note:
See TracChangeset
for help on using the changeset viewer.
