Changeset 14652 for trunk/psModules/src/objects/pmModel.c
- Timestamp:
- Aug 23, 2007, 2:11:02 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmModel.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmModel.c
r13898 r14652 6 6 * @author EAM, IfA 7 7 * 8 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2007-0 6-20 02:22:26$8 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2007-08-24 00:11:02 $ 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 "pmHDU.h" 24 #include "pmFPA.h" 23 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmPSF.h" 24 28 #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); 29 #include "pmModelClass.h" 35 30 36 31 static void modelFree(pmModel *tmp) … … 45 40 pmModelAlloc(): Allocate the pmModel structure, along with its parameters, 46 41 and initialize the type member. Initialize the params to 0.0. 47 XXX EAM: simplifying code with pmModelParameterCount48 42 *****************************************************************************/ 49 43 pmModel *pmModelAlloc(pmModelType type) … … 53 47 pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel)); 54 48 psMemSetDeallocator(tmp, (psFreeFunc) modelFree); 49 50 pmModelClass *class = pmModelClassSelect (type); 51 if (class == NULL) { 52 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 53 return(NULL); 54 } 55 55 56 56 tmp->type = type; … … 62 62 tmp->residuals = NULL; // XXX should the model own this memory? 63 63 64 psS32 Nparams = pmModelParameterCount(type); 65 if (Nparams == 0) { 66 psError(PS_ERR_UNKNOWN, true, "Undefined pmModelType"); 67 return(NULL); 68 } 64 psS32 Nparams = pmModelClassParameterCount(type); 65 assert (Nparams); 69 66 70 67 tmp->params = psVectorAlloc(Nparams, PS_TYPE_F32); 71 68 tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32); 69 assert (tmp->params); 70 assert (tmp->dparams); 72 71 73 72 for (psS32 i = 0; i < tmp->params->n; i++) { … … 75 74 tmp->dparams->data.F32[i] = 0.0; 76 75 } 76 77 tmp->modelFunc = class->modelFunc; 78 tmp->modelFlux = class->modelFlux; 79 tmp->modelRadius = class->modelRadius; 80 tmp->modelLimits = class->modelLimits; 81 tmp->modelGuess = class->modelGuess; 82 tmp->modelFromPSF = class->modelFromPSF; 83 tmp->modelParamsFromPSF = class->modelParamsFromPSF; 84 tmp->modelFitStatus = class->modelFitStatus; 77 85 78 86 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); … … 92 100 new->radiusFit = model->radiusFit; 93 101 94 // XXX note that model->residuals is just a reference95 new->residuals = model->residuals;96 97 102 for (int i = 0; i < new->params->n; i++) { 98 103 new->params->data.F32[i] = model->params->data.F32[i]; 99 104 new->dparams->data.F32[i] = model->dparams->data.F32[i]; 100 105 } 106 107 // note that model->residuals is just a reference 108 new->residuals = model->residuals; 101 109 102 110 return (new); … … 123 131 x->data.F32[1] = (psF32) (row + image->row0); 124 132 psF32 tmpF; 125 pmModelFunc modelFunc; 126 127 modelFunc = pmModelFunc_GetFunction (model->type); 128 tmpF = modelFunc (NULL, model->params, x); 133 134 tmpF = model->modelFunc (NULL, model->params, x); 135 psFree(x); 136 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); 137 return(tmpF); 138 } 139 140 psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, psS32 col, psS32 row, int dx, int dy) 141 { 142 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 143 PS_ASSERT_PTR_NON_NULL(image, false); 144 PS_ASSERT_PTR_NON_NULL(model, false); 145 PS_ASSERT_PTR_NON_NULL(model->params, false); 146 147 // Allocate the x coordinate structure and convert row/col to image space. 148 // 149 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 150 x->data.F32[0] = (psF32) (col + image->col0 + dx); 151 x->data.F32[1] = (psF32) (row + image->row0 + dy); 152 psF32 tmpF; 153 154 tmpF = model->modelFunc (NULL, model->params, x); 129 155 psFree(x); 130 156 psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__); … … 137 163 pmModelOpMode mode, 138 164 bool add, 139 psMaskType maskVal 165 psMaskType maskVal, 166 int dx, 167 int dy 140 168 ) 141 169 { … … 148 176 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 149 177 psVector *params = model->params; 150 pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type); 178 151 179 psS32 imageCol; 152 180 psS32 imageRow; … … 209 237 // Convert i/j to image coord space: 210 238 // XXX should we use using 0.5 pixel offset? 211 imageCol = ix + image->col0 ;212 imageRow = iy + image->row0 ;239 imageCol = ix + image->col0 + dx; 240 imageRow = iy + image->row0 + dy; 213 241 214 242 x->data.F32[0] = (float) imageCol; … … 219 247 // add in the desired components for this coordinate 220 248 if (mode & PM_MODEL_OP_FUNC) { 221 pixelValue += model Func (NULL, params, x);249 pixelValue += model->modelFunc (NULL, params, x); 222 250 } 223 251 … … 280 308 { 281 309 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 282 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal );310 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, 0.0, 0.0); 283 311 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 284 312 return(rc); … … 294 322 { 295 323 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 296 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal );324 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, 0.0, 0.0); 297 325 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 298 326 return(rc); 299 327 } 300 328 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 329 /****************************************************************************** 330 *****************************************************************************/ 331 bool pmModelAddWithOffset(psImage *image, 332 psImage *mask, 333 pmModel *model, 334 pmModelOpMode mode, 335 psMaskType maskVal, 336 int dx, 337 int dy) 338 { 339 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 340 psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal, dx, dy); 341 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 342 return(rc); 343 } 344 345 /****************************************************************************** 346 *****************************************************************************/ 347 bool pmModelSubWithOffset(psImage *image, 348 psImage *mask, 349 pmModel *model, 350 pmModelOpMode mode, 351 psMaskType maskVal, 352 int dx, 353 int dy) 354 { 355 psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__); 356 psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal, dx, dy); 357 psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc); 358 return(rc); 359 }
Note:
See TracChangeset
for help on using the changeset viewer.
