IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 17, 2007, 11:01:59 AM (19 years ago)
Author:
magnier
Message:

substantial cleanups of APIs:

changed pmModelGroup to pmModelClass

dropped the _GetFunctions, and moved the modelClass-specific functions
to functions pointers in the pmModel structure. These are assigned
when the model is allocated, based on the model type. Now, instead of
calling, for example,

modelFunc = pmModelFunc_GetFunctions(model->type)
modelFunc();

you just do:

model->modelFunc()

moved some of the support functions into pmModelUtils and
pmSourceUtils.

changed pmIsFooBar to pmFooBarTest for better api listing.

added functions to evaluate and add/subtract models applying an offset
between the image coordinate frame and the chip frame (required frame
for model parameters)

added function(s) to instatiate a pmModel from a pmPSF based on a
given coordinate and peak flux.

added a function to set the model normalization based on a source flux
value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20070817/psModules/src/objects/pmModel.c

    r13898 r14544  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-06-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 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "pmResiduals.h"
    2424#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"
    3526
    3627static void modelFree(pmModel *tmp)
     
    4536pmModelAlloc(): Allocate the pmModel structure, along with its parameters,
    4637and initialize the type member.  Initialize the params to 0.0.
    47 XXX EAM: simplifying code with pmModelParameterCount
    4838*****************************************************************************/
    4939pmModel *pmModelAlloc(pmModelType type)
     
    5343    pmModel *tmp = (pmModel *) psAlloc(sizeof(pmModel));
    5444    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    }
    5551
    5652    tmp->type = type;
     
    6258    tmp->residuals = NULL;              // XXX should the model own this memory?
    6359
    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);
    6962
    7063    tmp->params  = psVectorAlloc(Nparams, PS_TYPE_F32);
    7164    tmp->dparams = psVectorAlloc(Nparams, PS_TYPE_F32);
     65    assert (tmp->params);
     66    assert (tmp->dparams);
    7267
    7368    for (psS32 i = 0; i < tmp->params->n; i++) {
     
    7570        tmp->dparams->data.F32[i] = 0.0;
    7671    }
     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;
    7781
    7882    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     
    9296    new->radiusFit = model->radiusFit;
    9397
    94     // XXX note that model->residuals is just a reference
    95     new->residuals = model->residuals;
    96 
    9798    for (int i = 0; i < new->params->n; i++) {
    9899        new->params->data.F32[i]  = model->params->data.F32[i];
    99100        new->dparams->data.F32[i] = model->dparams->data.F32[i];
    100101    }
     102
     103    // note that model->residuals is just a reference
     104    new->residuals = model->residuals;
    101105
    102106    return (new);
     
    123127    x->data.F32[1] = (psF32) (row + image->row0);
    124128    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
     136psF32 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);
    129151    psFree(x);
    130152    psTrace("psModules.objects", 3, "---- %s() end ----\n", __func__);
     
    137159                          pmModelOpMode mode,
    138160                          bool add,
    139                           psMaskType maskVal
     161                          psMaskType maskVal,
     162                          int dx,
     163                          int dy
    140164    )
    141165{
     
    148172    psVector *x = psVectorAlloc(2, PS_TYPE_F32);
    149173    psVector *params = model->params;
    150     pmModelFunc modelFunc = pmModelFunc_GetFunction (model->type);
     174
    151175    psS32 imageCol;
    152176    psS32 imageRow;
     
    209233            // Convert i/j to image coord space:
    210234            // 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;
    213237
    214238            x->data.F32[0] = (float) imageCol;
     
    219243            // add in the desired components for this coordinate
    220244            if (mode & PM_MODEL_OP_FUNC) {
    221                 pixelValue += modelFunc (NULL, params, x);
     245                pixelValue += model->modelFunc (NULL, params, x);
    222246            }
    223247
     
    280304{
    281305    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);
    283307    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    284308    return(rc);
     
    294318{
    295319    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);
    297321    psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
    298322    return(rc);
    299323}
    300324
    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 *****************************************************************************/
     327bool 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 *****************************************************************************/
     343bool 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.