IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 7, 2008, 12:23:06 PM (18 years ago)
Author:
Paul Price
Message:

map->stats doesn't have to be defined except for psImageMapGenerate: some may want to make their own map (e.g., pmPSFmodelRead). Created assertions for psImageMap, and an assertion for the statistics (used in psImageMapGenerate).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageMap.c

    r15841 r19960  
    77 *  @author Eugene Magnier, IfA
    88 *
    9  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-12-15 01:20:03 $
     9 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2008-10-07 22:23:06 $
    1111 *
    1212 *  Copyright 2007 Institute for Astronomy, University of Hawaii
     
    3737#include "psImageMap.h"
    3838
    39 static void psImageMapFree(psImageMap *map) {
    40 
    41     if (!map) return;
    42 
     39static void imageMapFree(psImageMap *map)
     40{
    4341    psFree(map->map);
    4442    psFree(map->error);
     
    4947}
    5048
    51 psImageMap *psImageMapAlloc(const psImage *field, psImageBinning *binning, psStats *stats) {
    52     PS_ASSERT_IMAGE_NON_NULL(field, NULL);
    53     assert (binning);
    54     assert (stats);
    55 
    56     psImageMap *map = (psImageMap*)psAlloc(sizeof(psImageMap));
    57     psMemSetDeallocator(map, (psFreeFunc)psImageMapFree);
    58 
    59     map->binning = psMemIncrRefCounter (binning);
    60     map->stats   = psMemIncrRefCounter (stats);
     49psImageMap *psImageMapAlloc(const psImage *field, psImageBinning *binning, psStats *stats)
     50{
     51    psAssert(field, "Require field image");
     52    psAssert(binning, "Require binning");
     53    // stats may be NULL
     54
     55    psImageMap *map = psAlloc(sizeof(psImageMap));
     56    psMemSetDeallocator(map, (psFreeFunc)imageMapFree);
     57
     58    map->binning = psMemIncrRefCounter(binning);
     59    map->stats   = psMemIncrRefCounter(stats);
    6160
    6261    map->col0 = field->col0;
     
    6564    map->numRows = field->numRows;
    6665
    67     map->map     = psImageAlloc (binning->nXruff, binning->nYruff, PS_TYPE_F32);
    68     psImageInit (map->map, 0.0);
    69 
    70     map->error   = psImageAlloc (binning->nXruff, binning->nYruff, PS_TYPE_F32);
    71     psImageInit (map->error, 0.0);
    72 
    73     psImageBinningSetScale (map->binning, PS_IMAGE_BINNING_CENTER);
    74     psImageBinningSetSkipByOffset (map->binning, map->col0, map->row0);
     66    map->map = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32);
     67    psImageInit(map->map, 0.0);
     68
     69    map->error = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32);
     70    psImageInit(map->error, 0.0);
     71
     72    psImageBinningSetScale(map->binning, PS_IMAGE_BINNING_CENTER);
     73    psImageBinningSetSkipByOffset(map->binning, map->col0, map->row0);
    7574
    7675    return map;
     
    8079{
    8180    PS_ASSERT_PTR(ptr, false);
    82     return ( psMemGetDeallocator(ptr) == (psFreeFunc) psImageMapFree);
     81    return (psMemGetDeallocator(ptr) == (psFreeFunc)imageMapFree);
    8382}
    8483
    8584// allocate the image map using the psImageBinning supplied
    86 psImageMap *psImageMapNoImageAlloc(psImageBinning *binning, psStats *stats) {
    87 
    88     assert (binning);
    89     assert (stats);
    90 
    91     psImageMap *map = (psImageMap*)psAlloc(sizeof(psImageMap));
    92     psMemSetDeallocator(map, (psFreeFunc)psImageMapFree);
    93 
    94     map->stats   = psMemIncrRefCounter (stats);
    95     map->binning = psMemIncrRefCounter (binning);
    96 
    97     map->map     = psImageAlloc (binning->nXruff, binning->nYruff, PS_TYPE_F32);
    98     psImageInit (map->map, 0.0);
    99 
    100     map->error   = psImageAlloc (binning->nXruff, binning->nYruff, PS_TYPE_F32);
    101     psImageInit (map->error, 0.0);
     85psImageMap *psImageMapNoImageAlloc(psImageBinning *binning, psStats *stats)
     86{
     87    psAssert(binning, "Require binning");
     88    // stats may be NULL
     89
     90    psImageMap *map = psAlloc(sizeof(psImageMap));
     91    psMemSetDeallocator(map, (psFreeFunc)imageMapFree);
     92
     93    map->binning = psMemIncrRefCounter(binning);
     94    map->stats   = psMemIncrRefCounter(stats);
     95
     96    map->col0 = 0;
     97    map->row0 = 0;
     98    map->numCols = 0;
     99    map->numRows = 0;
     100
     101    map->map = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32);
     102    psImageInit(map->map, 0.0);
     103
     104    map->error = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32);
     105    psImageInit(map->error, 0.0);
    102106
    103107    return map;
     
    106110bool psImageMapModifyScale(psImageMap *map, int nXruff, int nYruff)
    107111{
    108     assert (map);
     112    PS_ASSERT_IMAGE_MAP_NON_NULL(map, false);
    109113
    110114    map->binning->nXruff = nXruff;
    111115    map->binning->nYruff = nYruff;
    112116
    113     psImageRecycle (map->map, nXruff, nYruff, PS_TYPE_F32);
    114     psImageRecycle (map->error, nXruff, nYruff, PS_TYPE_F32);
    115 
    116     psImageBinningSetScale (map->binning, PS_IMAGE_BINNING_CENTER);
    117     psImageBinningSetSkipByOffset (map->binning, map->col0, map->row0);
     117    map->map = psImageRecycle(map->map, nXruff, nYruff, PS_TYPE_F32);
     118    map->error = psImageRecycle(map->error, nXruff, nYruff, PS_TYPE_F32);
     119
     120    psImageBinningSetScale(map->binning, PS_IMAGE_BINNING_CENTER);
     121    psImageBinningSetSkipByOffset(map->binning, map->col0, map->row0);
    118122
    119123    return true;
     
    125129                        const psVector *f, const psVector *df, float badFrac)
    126130{
    127     // XXX asserts
     131    PS_ASSERT_IMAGE_MAP_NON_NULL(map, false);
     132    PS_ASSERT_IMAGE_MAP_STATS(map, false);
     133    PS_ASSERT_VECTOR_NON_NULL(x, false);
     134    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, false);
     135    PS_ASSERT_VECTOR_NON_NULL(y, false);
     136    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false);
     137    PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, false);
     138    PS_ASSERT_VECTOR_NON_NULL(f, false);
     139    PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F32, false);
     140    PS_ASSERT_VECTORS_SIZE_EQUAL(x, f, false);
     141    if (df) {
     142        PS_ASSERT_VECTOR_NON_NULL(df, false);
     143        PS_ASSERT_VECTOR_TYPE(df, PS_TYPE_F32, false);
     144        PS_ASSERT_VECTORS_SIZE_EQUAL(x, df, false);
     145    }
    128146
    129147    psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_MASK);
     
    260278                             const psVector *f, const psVector *df, float badFrac)
    261279{
    262     // XXX Asserts
     280    PS_ASSERT_IMAGE_MAP_NON_NULL(map, false);
     281    PS_ASSERT_IMAGE_MAP_STATS(map, false);
     282    PS_ASSERT_VECTOR_NON_NULL(x, false);
     283    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, false);
     284    PS_ASSERT_VECTOR_NON_NULL(y, false);
     285    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false);
     286    PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, false);
     287    PS_ASSERT_VECTOR_NON_NULL(f, false);
     288    PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F32, false);
     289    PS_ASSERT_VECTORS_SIZE_EQUAL(x, f, false);
     290    if (df) {
     291        PS_ASSERT_VECTOR_NON_NULL(df, false);
     292        PS_ASSERT_VECTOR_TYPE(df, PS_TYPE_F32, false);
     293        PS_ASSERT_VECTORS_SIZE_EQUAL(x, df, false);
     294    }
    263295
    264296    int nXruff, nYruff;
     
    304336
    305337// x,y are in fractional pixel coords of the fine image (pixel center: 0.5)
    306 double psImageMapEval(const psImageMap *map, float x, float y) {
    307 
    308     double result;
    309 
    310     result = psImageUnbinPixel_V2(x, y, map->map, map->binning);
    311 
    312     return result;
    313 }
    314 
    315 psVector *psImageMapEvalVector(const psImageMap *map, const psVector *x, const psVector *y) {
    316 
    317     assert (x);
    318     assert (y);
    319     assert (x->n == y->n);
    320     assert (map);
    321 
    322     psVector *result = psVectorAlloc (x->n, PS_TYPE_F32);
     338double psImageMapEval(const psImageMap *map, float x, float y)
     339{
     340    // This may be called in a type loop, so no assertions
     341    return psImageUnbinPixel_V2(x, y, map->map, map->binning);
     342}
     343
     344psVector *psImageMapEvalVector(const psImageMap *map, const psVector *x, const psVector *y)
     345{
     346    PS_ASSERT_IMAGE_MAP_NON_NULL(map, NULL);
     347    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
     348    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
     349    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
     350    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
     351    PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, NULL);
     352
     353    psVector *result = psVectorAlloc(x->n, PS_TYPE_F32); // Results to return
    323354
    324355    for (int i = 0; i < x->n; i++) {
Note: See TracChangeset for help on using the changeset viewer.