Changeset 6062 for branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c
- Timestamp:
- Jan 19, 2006, 4:38:28 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c
r5974 r6062 3 3 4 4 #include "pslib.h" 5 #include "pm Astrometry.h"5 #include "pmFPA.h" 6 6 #include "pmChipMosaic.h" 7 7 … … 34 34 // Get the maximum extent of the mosaic image 35 35 int xMin = INT_MAX; 36 int xMax = 0;36 int xMax = - INT_MAX; 37 37 int yMin = INT_MAX; 38 int yMax = 0;38 int yMax = - INT_MAX; 39 39 for (int i = 0; i < source->n; i++) { 40 40 psImage *image = source->data[i]; // The image of interest 41 if (!image) { 42 continue; 43 } 41 44 42 45 assert(image->type.type == PS_TYPE_F32); // Only implemented for F32 images so far. … … 74 77 for (int i = 0; i < source->n; i++) { 75 78 psImage *image = source->data[i]; // The image of interest 79 if (!image) { 80 continue; 81 } 76 82 if (xBinSource->data.S32[i] == xBinTarget && yBinSource->data.S32[i] == yBinTarget && 77 83 xFlip->data.U8[i] == 0 && yFlip->data.U8[i] == 0) { … … 107 113 108 114 // Mosaic a chip together into a single image 109 static psImage *mosaicChip(pmChip *chip,// Chip to mosaic110 int xBinChip, int yBinChip // Binning of mosaic image in x and y111 )115 static bool mosaicChip(pmChip *chip,// Chip to mosaic 116 int xBinChip, int yBinChip // Binning of mosaic image in x and y 117 ) 112 118 { 113 119 114 120 psArray *cells = chip->cells; // The array of cells 115 121 psArray *images = psArrayAlloc(cells->n); // Array of images that will be mosaicked 122 psArray *weights = psArrayAlloc(cells->n); // Array of weight images to be mosaicked 123 psArray *masks = psArrayAlloc(cells->n); // Array of mask images to be mosaicked 116 124 psVector *x0 = psVectorAlloc(cells->n, PS_TYPE_S32); // Origin x coordinates 117 125 psVector *y0 = psVectorAlloc(cells->n, PS_TYPE_S32); // Origin y coordinates … … 126 134 x0->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0"); 127 135 y0->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0"); 136 psTrace(__func__, 9, "Cell %d: x0=%d y0=%d\n", i, x0->data.S32[i], y0->data.S32[i]); 128 137 xBin->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.XBIN"); 129 138 yBin->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.XBIN"); … … 159 168 } 160 169 psImage *image = ((pmReadout*)readouts->data[0])->image; // The image to put into the mosaic 170 psImage *weight = ((pmReadout*)readouts->data[0])->weight; 171 psImage *mask = ((pmReadout*)readouts->data[0])->weight; 161 172 images->data[i] = psImageSubset(image, *trimsec); // Trimmed image 162 } 163 173 weights->data[i] = weight ? psImageSubset(weight, *trimsec) : NULL; 174 masks->data[i] = mask ? psImageSubset(mask, *trimsec) : NULL; 175 } 164 176 // Mosaic the images together and we're done 165 psImage *mosaic = p_pmImageMosaic(images, xFlip, yFlip, xBin, yBin, xBinChip, yBinChip, x0, y0); 177 psImage *image = p_pmImageMosaic(images, xFlip, yFlip, xBin, yBin, xBinChip, yBinChip, x0, y0); 178 psImage *weight = p_pmImageMosaic(weights, xFlip, yFlip, xBin, yBin, xBinChip, yBinChip, x0, y0); 179 psImage *mask = p_pmImageMosaic(masks, xFlip, yFlip, xBin, yBin, xBinChip, yBinChip, x0, y0); 166 180 167 181 // Clean up … … 173 187 psFree(yFlip); 174 188 psFree(images); 175 176 return mosaic; 189 psFree(weights); 190 psFree(masks); 191 192 // Chop off all the component cells, and put in a new one 193 194 #if 1 195 // XXX For the sake of getting something working, I am not going to bother with sorting out where 196 // the double free is coming from. I'm going to drop the pointers on the array and create a memory 197 // leak. We can clean this up later, when we're not under as much pressure. 198 chip->cells = psArrayAlloc(0); 199 #else 200 201 psArrayElementsFree(chip->cells); 202 chip->cells = psArrayRealloc(chip->cells, 0); 203 chip->cells->n = 0; 204 #endif 205 206 pmCell *cell = pmCellAlloc(chip, NULL, __func__); // New cell 207 cell->exists = true; 208 cell->process = true; 209 pmReadout *readout = pmReadoutAlloc(cell); // New readout 210 readout->image = image; 211 readout->weight = weight; 212 readout->mask = mask; 213 //psFree(readout); 214 215 return true; 177 216 } 178 217 … … 193 232 194 233 numChips++; 195 psImage *mosaic = mosaicChip(chip, xBinChip, yBinChip); // Mosaic of cells within the chip 196 197 // Chop off all the component cells, and put in a new one 198 psArrayElementsFree(chip->cells); 199 chip->cells = psArrayRealloc(chip->cells, 1); 200 pmCell *cell = pmCellAlloc(chip, NULL, __func__); // New cell 201 pmReadout *readout = pmReadoutAlloc(cell); // New readout 202 readout->image = mosaic; 203 psFree(readout); 234 mosaicChip(chip, xBinChip, yBinChip); // Mosaic of cells within the chip 235 204 236 } 205 237
Note:
See TracChangeset
for help on using the changeset viewer.
