IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12485


Ignore:
Timestamp:
Mar 18, 2007, 12:06:58 PM (19 years ago)
Author:
magnier
Message:

fixed memory leaks on error handling, get fpa dimensions from concepts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmAstrometryDistortion.c

    r11461 r12485  
    77*  @author EAM, IfA
    88*
    9 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2007-01-31 03:12:27 $
     9*  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2007-03-18 22:06:58 $
    1111*
    1212*  Copyright 2006 Institute for Astronomy, University of Hawaii
     
    4747    psMemSetDeallocator(gradient, (psFreeFunc) pmAstromGradientFree);
    4848
    49     // XXX init any of the data values?
    50 
    5149    return (gradient);
    5250}
    5351
    54 psArray *pmAstromMeasureGradients(psArray *gradients, psArray *rawstars, psArray *refstars, psArray *matches, psMetadata *config)
     52psArray *pmAstromMeasureGradients(psArray *gradients, psArray *rawstars, psArray *refstars, psArray *matches, psRegion *region, int Nx, int Ny)
    5553{
    5654
     
    5957    }
    6058
     59    // NOTE: region specifies the FP region in pixels covered by the chip (NOT in FP units)
    6160    // determine range
    62     // XXX for the moment, I'm hard-wiring this for megacam
    63     // XXX we need to get the chip dimensions from the metadata somewhere
    64     int Nx = 2;
    65     int Ny = 2;
    66     int DX = 2080 / Nx;
    67     int DY = 4600 / Ny;
     61    int DX = (region->x1 - region->x0) / Nx;
     62    int DY = (region->y1 - region->y0) / Ny;
    6863
    6964    psPolynomial2D *local = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 1, 1);
     
    9792                pmAstromObj *raw = rawstars->data[match->raw];
    9893
    99                 if (raw->chip->x < Xmin)
    100                     continue;
    101                 if (raw->chip->x > Xmax)
    102                     continue;
    103                 if (raw->chip->y < Ymin)
    104                     continue;
    105                 if (raw->chip->y > Ymax)
    106                     continue;
     94                if (raw->chip->x < Xmin) continue;
     95                if (raw->chip->x > Xmax) continue;
     96                if (raw->chip->y < Ymin) continue;
     97                if (raw->chip->y > Ymax) continue;
    10798
    10899                pmAstromObj *ref = refstars->data[match->ref];
     
    177168}
    178169
    179 bool pmAstromFitDistortion(pmFPA *fpa, psArray *gradients, psMetadata *config)
     170bool pmAstromFitDistortion(pmFPA *fpa, psArray *gradients, double pixelScale)
    180171{
    181172
     
    233224    if (!psVectorClipFitPolynomial2D (localX, stats, mask, 0xff, dPdL, NULL, L, M)) {
    234225        psLogMsg ("psastro", 3, "failed to fit x-dir gradient\n");
    235         return false;
     226        psFree (localX);
     227        psFree (localY);
     228        goto escape;
    236229    }
    237230
    238231    if (!psVectorClipFitPolynomial2D (localY, stats, mask, 0xff, dPdM, NULL, L, M)) {
    239232        psLogMsg ("psastro", 3, "failed to fit y-dir gradient\n");
    240         return false;
     233        psFree (localX);
     234        psFree (localY);
     235        goto escape;
    241236    }
    242237
     
    310305    psFree (localY);
    311306
    312     // XXX free unneeded structures
     307    // free unneeded structures
    313308    psFree (dPdL);
    314309    psFree (dPdM);
     
    320315    psFree (mask);
    321316
    322     // XXX need to reset the fromTPA terms here
    323     // XXX choose an appropriate region based on the range of values
    324     // in L and M?
    325     // psRegion region = psRegionSet (-125000, +125000, -125000, +125000);
     317    // reset the fromTPA terms here. choose an appropriate region based on the dimensions of
     318    // the complete FPA
    326319    psRegion *region = pmFPAExtent (fpa);
     320    region->x0 *= pixelScale;
     321    region->x1 *= pixelScale;
     322    region->y0 *= pixelScale;
     323    region->y1 *= pixelScale;
     324    int xCenter = 0.5*(region->x0 + region->x1);
     325    int yCenter = 0.5*(region->y0 + region->y1);
     326    region->x0 -= xCenter;
     327    region->x1 -= xCenter;
     328    region->y0 -= yCenter;
     329    region->y1 -= yCenter;
    327330    psFree (fpa->fromTPA);
    328331    fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, *region, 50);
    329332    psFree (region);
    330333
     334    if (fpa->fromTPA == NULL) {
     335        psError (PS_ERR_UNKNOWN, false, "failed to invert fpa->toTPA\n");
     336        return false;
     337    }
     338
    331339    return true;
     340
     341escape:
     342    // free unneeded structures
     343    psFree (dPdL);
     344    psFree (dPdM);
     345    psFree (dQdL);
     346    psFree (dQdM);
     347    psFree (L);
     348    psFree (M);
     349    psFree (stats);
     350    psFree (mask);
     351    return false;
    332352}
Note: See TracChangeset for help on using the changeset viewer.