- Timestamp:
- Aug 17, 2007, 11:01:59 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20070817/psModules/src/objects/pmModel.c
r13898 r14544 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 6-20 02:22:26$8 * @version $Revision: 1.13.6.1 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-17 21:01:59 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 23 23 #include "pmResiduals.h" 24 24 #include "pmModel.h" 25 26 /* The following types and functions need to be known by pmModel.c and are defined in 27 pmModelGroup.h. The use of pmSource and other types in pmModelGroup.h prevent us from 28 directly including it here ***/ 29 30 typedef psMinimizeLMChi2Func pmModelFunc; 31 typedef bool (*pmModelFitStatusFunc)(pmModel *model); 32 pmModelFunc pmModelFunc_GetFunction (pmModelType type); 33 pmModelFitStatusFunc pmModelFitStatusFunc_GetFunction (pmModelType type); 34 int pmModelParameterCount(pmModelType type); 25 #include "pmModelClass.h" 35 26 36 27 static void modelFree(pmModel *tmp) … … 45 36 pmModelAlloc(): Allocate the pmModel structure, along with its parameters, 46 37 and initialize the type member. Initialize the params to 0.0. 47 XXX EAM: simplifying code with pmModelParameterCount48 38 *****************************************************************************/ 49 39 pmModel *pmModelAlloc(pmModelType type) … … 53 43 pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel)); 54 44 psMemSetDeallocator(tmp, (psFreeFunc) modelFree); 45 46 pmModelClass *class = pmModelClassSelect (type); 47 if (class == NULL) { 48 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 49 return(NULL); 50 } 55 51 56 52 tmp->type = type; … … 62 58 tmp->residuals = NULL; // XXX should the model own this memory? 63 59 64 psS32 Nparams = pmModelParameterCount(type); 65 if (Nparams == 0) { 66 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 67 return(NULL); 68 } 60 psS32 Nparams = pmModelClassParameterCount(type); 61 assert (Nparams); 69 62 70 63 tmp->params = psVectorAlloc(Nparams, PS_TYPE_F32); 71 64 tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32); 65 assert (tmp->params); 66 assert (tmp->dparams); 72 67 73 68 for (psS32 i = 0; i < tmp->params->n; i++) { … … 75 70 tmp->dparams->data.F32[i] = 0.0; 76 71 } 72 73 tmp->modelFunc = class->modelFunc; 74 tmp->modelFlux = class->modelFlux; 75 tmp->modelRadius = class->modelRadius; 76 tmp->modelLimits = class->modelLimits; 77 tmp->modelGuess = class->modelGuess; 78 tmp->modelFromPSF = class->modelFromPSF; 79 tmp->modelParamsFromPSF = class->modelParamsFromPSF; 80 tmp->modelFitStatus = class->modelFitStatus; 77 81 78 82 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); … … 92 96 new->radiusFit = model->radiusFit; 93 97 94 // XXX note that model->residuals is just a reference95 new->residuals = model->residuals;96 97 98 for (int i = 0; i < new->params->n; i++) { 98 99 new->params->data.F32[i] = model->params->data.F32[i]; 99 100 new->dparams->data.F32[i] = model->dparams->data.F32[i]; 100 101 } 102 103 // note that model->residuals is just a reference 104 new->residuals = model->residuals; 101 105 102 106 return (new); … … 123 127 x->data.F32[1] = (psF32) (row + image->row0); 124 128 psF32 tmpF; 125 pmModelFunc modelFunc; 126 127 modelFunc = pmModelFunc_GetFunction (model->type); 128 tmpF = modelFunc (NULL, model->params, x); 129 130 tmpF = model->modelFunc (NULL, model->params, x); 131 psFree(x); 132 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); 133 return(tmpF); 134 } 135 136 psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, psS32 col, psS32 row, int dx, int dy) 137 { 138 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 139 PS_ASSERT_PTR_NON_NULL(image, false); 140 PS_ASSERT_PTR_NON_NULL(model, false); 141 PS_ASSERT_PTR_NON_NULL(model->params, false); 142 143 // Allocate the x coordinate structure and convert row/col to image space. 144 // 145 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 146 x->data.F32[0] = (psF32) (col + image->col0 + dx); 147 x->data.F32[1] = (psF32) (row + image->row0 + dy); 148 psF32 tmpF; 149 150 tmpF = model->modelFunc (NULL, model->params, x); 129 151 psFree(x); 130 152 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); … … 137 159 pmModelOpMode mode, 138 160 bool add, 139 psMaskType maskVal 161 psMaskType maskVal, 162 int dx, 163 int dy 140 164 ) 141 165 { … … 148 172 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 149 173 psVector *params = model->params; 150 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 174 151 175 psS32 imageCol; 152 176 psS32 imageRow; … … 209 233 // Convert i/j to image coord space: 210 234 // XXX should we use using 0.5 pixel offset? 211 imageCol = ix + image->col0 ;212 imageRow = iy + image->row0 ;235 imageCol = ix + image->col0 + dx; 236 imageRow = iy + image->row0 + dy; 213 237 214 238 x->data.F32[0] = (float) imageCol; … … 219 243 // add in the desired components for this coordinate 220 244 if (mode & PM_MODEL_OP_FUNC) { 221 pixelValue += model Func (NULL, params, x);245 pixelValue += model->modelFunc (NULL, params, x); 222 246 } 223 247 … … 280 304 { 281 305 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 282 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal );306 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, 0.0, 0.0); 283 307 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 284 308 return(rc); … … 294 318 { 295 319 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 296 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal );320 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, 0.0, 0.0); 297 321 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 298 322 return(rc); 299 323 } 300 324 301 // check for success of model fit 302 bool pmModelFitStatus (pmModel *model) 303 { 304 305 bool status; 306 307 pmModelFitStatusFunc statusFunc = pmModelFitStatusFunc_GetFunction (model->type); 308 status = statusFunc (model); 309 310 return (status); 311 } 312 325 /****************************************************************************** 326 *****************************************************************************/ 327 bool pmModelAddWithOffset(psImage *image, 328 psImage *mask, 329 pmModel *model, 330 pmModelOpMode mode, 331 psMaskType maskVal, 332 int dx, 333 int dy) 334 { 335 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 336 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, dx, dy); 337 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 338 return(rc); 339 } 340 341 /****************************************************************************** 342 *****************************************************************************/ 343 bool pmModelSubWithOffset(psImage *image, 344 psImage *mask, 345 pmModel *model, 346 pmModelOpMode mode, 347 psMaskType maskVal, 348 int dx, 349 int dy) 350 { 351 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 352 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, dx, dy); 353 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 354 return(rc); 355 }
Note:
See TracChangeset
for help on using the changeset viewer.
