Changeset 15756 for trunk/psModules/src/camera/pmReadoutFake.c
- Timestamp:
- Dec 6, 2007, 3:57:15 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmReadoutFake.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmReadoutFake.c
r15424 r15756 20 20 #include "pmSource.h" 21 21 #include "pmSourceUtils.h" 22 #include "pmModelUtils.h" 22 23 23 24 #define MODEL_TYPE "PS_MODEL_RGAUSS" // Type of model to use 24 25 25 26 26 pmReadout *pmReadoutFakeFromSources(int numCols, int numRows, const psArray *sources, 27 float fwhm, float minFlux) 27 bool pmReadoutFakeFromSources(pmReadout *readout, int numCols, int numRows, const psArray *sources, 28 const psVector *xOffset, const psVector *yOffset, pmPSF *psf, float minFlux, 29 int radius) 28 30 { 29 PS_ASSERT_INT_LARGER_THAN(numCols, 0, NULL); 30 PS_ASSERT_INT_LARGER_THAN(numRows, 0, NULL); 31 PS_ASSERT_ARRAY_NON_NULL(sources, NULL); 32 PS_ASSERT_FLOAT_LARGER_THAN(fwhm, 0.0, NULL); 33 PS_ASSERT_FLOAT_LARGER_THAN(minFlux, 0.0, NULL); 31 PS_ASSERT_PTR_NON_NULL(readout, false); 32 PS_ASSERT_INT_LARGER_THAN(numCols, 0, false); 33 PS_ASSERT_INT_LARGER_THAN(numRows, 0, false); 34 PS_ASSERT_ARRAY_NON_NULL(sources, false); 35 if (xOffset || yOffset) { 36 PS_ASSERT_VECTOR_NON_NULL(xOffset, false); 37 PS_ASSERT_VECTOR_NON_NULL(yOffset, false); 38 PS_ASSERT_VECTORS_SIZE_EQUAL(xOffset, yOffset, false); 39 PS_ASSERT_VECTOR_TYPE(xOffset, PS_TYPE_S32, false); 40 PS_ASSERT_VECTOR_TYPE_EQUAL(xOffset, yOffset, false); 41 if (xOffset->n != sources->n) { 42 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 43 "Number of offset vectors (%ld) and sources (%ld) doesn't match", 44 xOffset->n, sources->n); 45 return false; 46 } 47 } 48 PS_ASSERT_PTR_NON_NULL(psf, false); 49 if (radius > 0 && isfinite(minFlux) && minFlux > 0.0) { 50 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot define both minimum flux and fixed radius."); 51 return false; 52 } 34 53 35 pmReadout *readout = pmReadoutAlloc(NULL); // Output readout 36 readout->image = psImage Alloc(numCols, numRows, PS_TYPE_F32);54 55 readout->image = psImageRecycle(readout->image, numCols, numRows, PS_TYPE_F32); 37 56 psImageInit(readout->image, 0); 38 57 39 58 int numSources = sources->n; // Number of stars 40 59 60 #if 0 41 61 pmModelType modelType = pmModelClassGetType(MODEL_TYPE); // Type of PSF model 42 62 assert(modelType >= 0); … … 65 85 psAbort("Unsupported model type: %d", modelType); 66 86 } 87 #endif 67 88 89 pmModel *fakeModel = pmModelFromPSFforXY(psf, (float)numCols / 2.0, (float)numRows / 2.0, 90 1.0); // Fake model, with central intensity of 1.0 68 91 float flux0 = fakeModel->modelFlux(fakeModel->params); // Flux for central intensity of 1.0 69 70 92 71 93 for (int i = 0; i < numSources; i++) { … … 93 115 pmSource *fakeSource = pmSourceAlloc(); // Fake source to generate 94 116 fakeSource->peak = pmPeakAlloc(x, y, fakeModel->params->data.F32[PM_PAR_I0], PM_PEAK_LONE); 95 float radius = fakeModel->modelRadius(fakeModel->params, minFlux); // Radius of interest for source117 float fakeRadius = radius > 0 ? radius : fakeModel->modelRadius(fakeModel->params, minFlux); // Radius 96 118 97 if (!pmSourceDefinePixels(fakeSource, readout, x, y, radius)) { 98 psError(PS_ERR_UNKNOWN, false, "Unable to define pixels for source."); 99 psFree(readout); 100 psFree(fakeModel); 101 return NULL; 102 } 103 104 if (!pmModelAdd(fakeSource->pixels, NULL, fakeModel, PM_MODEL_OP_FULL, 0)) { 105 psError(PS_ERR_UNKNOWN, false, "Unable to add model of source to image."); 106 psFree(readout); 107 psFree(fakeModel); 108 return NULL; 119 if (xOffset) { 120 if (!pmSourceDefinePixels(fakeSource, readout, x + xOffset->data.S32[i], 121 y + yOffset->data.S32[i], fakeRadius)) { 122 psError(PS_ERR_UNKNOWN, false, "Unable to define pixels for source."); 123 psFree(readout); 124 psFree(fakeModel); 125 return false; 126 } 127 if (!pmModelAddWithOffset(fakeSource->pixels, NULL, fakeModel, PM_MODEL_OP_FULL, 0, 128 - xOffset->data.S32[i], - yOffset->data.S32[i])) { 129 psError(PS_ERR_UNKNOWN, false, "Unable to add model of source to image."); 130 psFree(readout); 131 psFree(fakeModel); 132 return false; 133 } 134 } else { 135 if (!pmSourceDefinePixels(fakeSource, readout, x, y, fakeRadius)) { 136 psError(PS_ERR_UNKNOWN, false, "Unable to define pixels for source."); 137 psFree(readout); 138 psFree(fakeModel); 139 return false; 140 } 141 if (!pmModelAdd(fakeSource->pixels, NULL, fakeModel, PM_MODEL_OP_FULL, 0)) { 142 psError(PS_ERR_UNKNOWN, false, "Unable to add model of source to image."); 143 psFree(readout); 144 psFree(fakeModel); 145 return false; 146 } 109 147 } 110 148 psFree(fakeSource); … … 113 151 psFree(fakeModel); 114 152 115 return readout;153 return true; 116 154 }
Note:
See TracChangeset
for help on using the changeset viewer.
