Changeset 12941
- Timestamp:
- Apr 20, 2007, 2:02:35 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_02_branch/psModules/src/objects/pmModel.c
r9810 r12941 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $9 * @date $Date: 200 6-10-31 19:38:44$8 * @version $Revision: 1.9.6.1 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-04-21 00:02:35 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 21 21 #include <string.h> 22 22 #include <pslib.h> 23 #include "pmResiduals.h" 23 24 #include "pmModel.h" 24 25 … … 49 50 { 50 51 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 52 51 53 pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel)); 54 psMemSetDeallocator(tmp, (psFreeFunc) modelFree); 52 55 53 56 tmp->type = type; … … 57 60 tmp->radiusFit = 0; 58 61 tmp->status = PM_MODEL_UNTRIED; 62 tmp->residuals = NULL; // XXX should the model own this memory? 59 63 60 64 psS32 Nparams = pmModelParameterCount(type); … … 72 76 } 73 77 74 psMemSetDeallocator(tmp, (psFreeFunc) modelFree);75 78 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); 76 79 return(tmp); … … 88 91 new->status = model->status; 89 92 new->radiusFit = model->radiusFit; 93 94 // XXX note that model->residuals is just a reference 95 new->residuals = model->residuals; 90 96 91 97 for (int i = 0; i < new->params->n; i++) { … … 147 153 psF32 skyValue = params->data.F32[0]; 148 154 psF32 pixelValue; 149 150 for (psS32 i = 0; i < image->numRows; i++) { 151 for (psS32 j = 0; j < image->numCols; j++) { 152 if ((mask != NULL) && mask->data.U8[i][j]) 155 156 float xCenter = model->params->data.F32[PM_PAR_XPOS]; 157 float yCenter = model->params->data.F32[PM_PAR_YPOS]; 158 float Io = model->params->data.F32[PM_PAR_I0]; 159 160 int xBin = 1; 161 int yBin = 1; 162 float xResidCenter = 0.0; 163 float yResidCenter = 0.0; 164 165 psImageInterpolateOptions *Ro = NULL; 166 psImageInterpolateOptions *Rx = NULL; 167 psImageInterpolateOptions *Ry = NULL; 168 if (model->residuals) { 169 Ro = psImageInterpolateOptionsAlloc( 170 PS_INTERPOLATE_BILINEAR, 171 model->residuals->Ro, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0); 172 Rx = psImageInterpolateOptionsAlloc( 173 PS_INTERPOLATE_BILINEAR, 174 model->residuals->Rx, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0); 175 Ry = psImageInterpolateOptionsAlloc( 176 PS_INTERPOLATE_BILINEAR, 177 model->residuals->Ry, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0); 178 179 xBin = model->residuals->xBin; 180 yBin = model->residuals->yBin; 181 xResidCenter = model->residuals->xCenter; 182 yResidCenter = model->residuals->yCenter; 183 } 184 185 for (psS32 iy = 0; iy < image->numRows; iy++) { 186 for (psS32 ix = 0; ix < image->numCols; ix++) { 187 if ((mask != NULL) && mask->data.U8[iy][ix]) 153 188 continue; 154 189 … … 156 191 // 'center' option changes meaning of i,j: 157 192 if (center) { 158 imageCol = j - 0.5*image->numCols + model->params->data.F32[2];159 imageRow = i - 0.5*image->numRows + model->params->data.F32[3];193 imageCol = ix - 0.5*image->numCols + xCenter; 194 imageRow = iy - 0.5*image->numRows + yCenter; 160 195 } else { 161 imageCol = j+ image->col0;162 imageRow = i + image->row0;196 imageCol = ix + image->col0; 197 imageRow = iy + image->row0; 163 198 } 164 199 … … 173 208 } 174 209 210 // get the contribution from the residual model 211 // XXX for a test, do this for all sources and all pixels 212 if (Ro) { 213 // fractional image position 214 // this is wrong for the 'center' case 215 float ox = xBin*(ix + 0.5 + image->col0 - xCenter) + xResidCenter; 216 float oy = yBin*(iy + 0.5 + image->row0 - yCenter) + yResidCenter; 217 218 psU8 mflux = 0; 219 double Fo = 0.0; 220 double Fx = 0.0; 221 double Fy = 0.0; 222 psImageInterpolate (&Fo, NULL, &mflux, ox, oy, Ro); 223 psImageInterpolate (&Fx, NULL, &mflux, ox, oy, Rx); 224 psImageInterpolate (&Fy, NULL, &mflux, ox, oy, Ry); 225 226 if (!mflux && isfinite(Fo) && isfinite(Fx) && isfinite(Fy)) { 227 double flux = Fo + xCenter*Fx + yCenter*Fy; 228 pixelValue += Io*flux; 229 } 230 } 175 231 176 232 // add or subtract the value 177 if (add 178 ) { 179 image->data.F32[i][j] += pixelValue; 180 } 181 else { 182 image->data.F32[i][j] -= pixelValue; 233 if (add) { 234 image->data.F32[iy][ix] += pixelValue; 235 } else { 236 image->data.F32[iy][ix] -= pixelValue; 183 237 } 184 238 } 185 239 } 186 240 psFree(x); 241 psFree(Ro); 242 psFree(Rx); 243 psFree(Ry); 187 244 psTrace("psModules.objects", 3, "---- %s(true) end ----\n", __func__); 188 245 return(true);
Note:
See TracChangeset
for help on using the changeset viewer.
