IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7999


Ignore:
Timestamp:
Jul 27, 2006, 2:44:05 PM (20 years ago)
Author:
Paul Price
Message:

Replacing p_psGetStatValue with two functions: psStatsSingleOption returns the single option that is set, or 0 if no matching option is set; psStatsGetValue returns the value for a requested statistic. Tests seem to pass with the new code.

Location:
trunk/psLib
Files:
15 edited

Legend:

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

    r7766 r7999  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2006-06-30 02:20:06 $
     12 *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2006-07-28 00:44:05 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4848    psMaskType* maskData = NULL;
    4949    psStats* myStats;
    50     double statVal;
    5150
    5251    if (in == NULL) {
     
    7271    }
    7372
    74     if (p_psGetStatValue(stats, &statVal) == false) {
     73    psStatsOptions statistic = psStatsSingleOption(stats->options); // Statistics option to use
     74    if (statistic == 0) {
    7575        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    7676                PS_ERRORTEXT_psImage_BAD_STAT,
     
    108108    out = psImageRecycle(out, outCols, outRows, in->type.type);
    109109
    110     #define PS_IMAGE_REBIN_CASE(type) \
    111 case PS_TYPE_##type: { \
    112         ps##type* outRowData; \
    113         ps##type* vecData = vec->data.type; \
    114         psMaskType* inRowMask = NULL; \
     110    #define PS_IMAGE_REBIN_CASE(TYPE) \
     111case PS_TYPE_##TYPE: { \
     112        ps##TYPE *outRowData; \
     113        ps##TYPE *vecData = vec->data.TYPE; \
     114        psMaskType *inRowMask = NULL; \
    115115        for (psS32 row = 0; row < outRows; row++) { \
    116             outRowData = out->data.type[row]; \
    117             psS32 inCurrentRow = row*scale; \
    118             psS32 inNextRow = (row+1)*scale; \
     116            outRowData = out->data.TYPE[row]; \
     117            psS32 inCurrentRow = row * scale; \
     118            psS32 inNextRow = (row + 1) * scale; \
    119119            for (psS32 col = 0; col < outCols; col++) { \
    120                 psS32 inCurrentCol = col*scale; \
    121                 psS32 inNextCol = (col+1)*scale; \
     120                psS32 inCurrentCol = col * scale; \
     121                psS32 inNextCol = (col + 1) * scale; \
    122122                psS32 n = 0; \
    123123                for (psS32 inRow = inCurrentRow; inRow < inNextRow && inRow < inRows; inRow++) { \
    124                     ps##type* inRowData = in->data.type[inRow]; \
     124                    ps##TYPE* inRowData = in->data.TYPE[inRow]; \
    125125                    if (mask != NULL) { \
    126126                        inRowMask = mask->data.PS_TYPE_MASK_DATA[inRow]; \
     
    134134                } \
    135135                vec->n = n; \
    136                 myStats = psVectorStats(myStats,vec,NULL,maskVec,maskVal); \
    137                 p_psGetStatValue(myStats,&statVal); \
    138                 outRowData[col] = (ps##type)statVal; \
     136                myStats = psVectorStats(myStats, vec, NULL, maskVec, maskVal); \
     137                outRowData[col] = (ps##TYPE)psStatsGetValue(myStats, statistic); \
    139138            } \
    140139        } \
  • trunk/psLib/src/imageops/psImagePixelExtract.c

    r7125 r7999  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-05-16 23:12:20 $
     10 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-07-28 00:44:05 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    210210                       const psStats* stats)
    211211{
    212     double statVal;
    213212    psStats* myStats;
    214213    psElemType type;
     
    375374    }
    376375
    377     // verify that the stats struct specifies a
    378     // single stats operation
    379     if (p_psGetStatValue(stats, &statVal) == false) {
     376    // verify that the stats struct specifies a single stats operation
     377    psStatsOptions statistic = psStatsSingleOption(stats->options);
     378    if (statistic == 0) {
    380379        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    381380                PS_ERRORTEXT_psImage_BAD_STAT,stats->options);
     
    439438                } \
    440439                myStats = psVectorStats(myStats,imgVec,NULL,maskVec,maskVal); \
    441                 (void)p_psGetStatValue(myStats,&statVal); \
    442                 *outData = statVal; \
     440                *outData = psStatsGetValue(myStats, statistic); \
    443441                if (outPosition != NULL) { \
    444442                    outPosition->x = c; \
     
    520518            }
    521519            myStats = psVectorStats(myStats, imgVec, NULL, maskVec, maskVal);
    522             (void)p_psGetStatValue(myStats, &statVal);  // we know it works cause we tested it above
    523             *outData = statVal;
     520            *outData = psStatsGetValue(myStats, statistic);
    524521            if (outPosition != NULL) {
    525522                outPosition->y = r;
     
    741738                           const psStats* stats)
    742739{
    743     double statVal;
    744 
    745740    /* check the parameters */
    746741
     
    808803    }
    809804
    810     // verify that the stats struct specifies a
    811     // single stats operation
    812     if (p_psGetStatValue(stats, &statVal) == false) {
     805    // verify that the stats struct specifies a single stats operation
     806    psStatsOptions statistic = psStatsSingleOption(stats->options);
     807    if (statistic == 0) {
    813808        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    814809                PS_ERRORTEXT_psImage_BAD_STAT,
     
    914909    for (psS32 r = 0; r < numOut; r++) {
    915910        myStats = psVectorStats(myStats,buffer[r], NULL, bufferMask[r],maskVal);
    916         (void)p_psGetStatValue(myStats,&statVal);
    917         outData[r] = statVal;
     911        outData[r] = psStatsGetValue(myStats, statistic);
    918912    }
    919913
  • trunk/psLib/src/math/psStats.c

    r7991 r7999  
    1616 * use ->min and ->max (PS_STAT_USE_RANGE)
    1717 *
    18  *  @version $Revision: 1.181 $ $Name: not supported by cvs2svn $
    19  *  @date $Date: 2006-07-27 03:51:13 $
     18 *  @version $Revision: 1.182 $ $Name: not supported by cvs2svn $
     19 *  @date $Date: 2006-07-28 00:44:05 $
    2020 *
    2121 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434/*****************************************************************************/
    3535#include "psMemory.h"
     36#include "psAbort.h"
    3637#include "psImage.h"
    3738#include "psVector.h"
     
    8081
    8182// None
    82 
    83 /*****************************************************************************/
    84 /* FUNCTION IMPLEMENTATION - LOCAL                                           */
    85 /*****************************************************************************/
    86 
    87 psBool p_psGetStatValue(const psStats* stats, psF64 *value)
    88 {
    89     psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
    90     //    switch (stats->options & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE | PS_STAT_ROBUST_FOR_SAMPLE)) {
    91     switch (stats->options & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE)) {
    92     case PS_STAT_SAMPLE_MEAN:
    93         *value = stats->sampleMean;
    94         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    95         return true;
    96 
    97     case PS_STAT_SAMPLE_MEDIAN:
    98         *value = stats->sampleMedian;
    99         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    100         return true;
    101 
    102     case PS_STAT_SAMPLE_STDEV:
    103         *value = stats->sampleStdev;
    104         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    105         return true;
    106 
    107     case PS_STAT_ROBUST_MEDIAN:
    108         *value = stats->robustMedian;
    109         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    110         return true;
    111 
    112     case PS_STAT_ROBUST_STDEV:
    113         *value = stats->robustStdev;
    114         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    115         return true;
    116 
    117     case PS_STAT_CLIPPED_MEAN:
    118         *value = stats->clippedMean;
    119         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    120         return true;
    121 
    122     case PS_STAT_CLIPPED_STDEV:
    123         *value = stats->clippedStdev;
    124         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    125         return true;
    126 
    127     case PS_STAT_MAX:
    128         *value = stats->max;
    129         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    130         return true;
    131 
    132     case PS_STAT_MIN:
    133         *value = stats->min;
    134         psTrace(__func__, 4, "---- %s(true) end ----\n", __func__);
    135         return true;
    136 
    137     default:
    138         psTrace(__func__, 4, "---- %s(false) end ----\n", __func__);
    139         return false;
    140     }
    141 }
    14283
    14384/******************************************************************************
     
    22112152    return psStatsOptionToString(stats->options);
    22122153}
     2154
     2155inline psStatsOptions psStatsSingleOption(psStatsOptions option)
     2156{
     2157    switch (option & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE)) {
     2158    case PS_STAT_SAMPLE_MEAN:
     2159    case PS_STAT_SAMPLE_MEDIAN:
     2160    case PS_STAT_SAMPLE_STDEV:
     2161    case PS_STAT_SAMPLE_QUARTILE:
     2162    case PS_STAT_ROBUST_MEDIAN:
     2163    case PS_STAT_ROBUST_STDEV:
     2164    case PS_STAT_ROBUST_QUARTILE:
     2165    case PS_STAT_FITTED_MEAN:
     2166    case PS_STAT_FITTED_STDEV:
     2167    case PS_STAT_CLIPPED_MEAN:
     2168    case PS_STAT_CLIPPED_STDEV:
     2169    case PS_STAT_MAX:
     2170    case PS_STAT_MIN:
     2171        return option & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE);
     2172    default:
     2173        return 0;
     2174    }
     2175    psAbort(__func__, "Should never get here.\n");
     2176    return 0;
     2177}
     2178
     2179inline double psStatsGetValue(const psStats *stats, psStatsOptions option)
     2180{
     2181    // We could call psStatsSingle to check, but it would be a waste since we effectively do it anyway
     2182    switch (option & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE)) {
     2183    case PS_STAT_SAMPLE_MEAN:
     2184        return stats->sampleMean;
     2185    case PS_STAT_SAMPLE_MEDIAN:
     2186        return stats->sampleMedian;
     2187    case PS_STAT_SAMPLE_STDEV:
     2188        return stats->sampleStdev;
     2189    case PS_STAT_ROBUST_MEDIAN:
     2190        return stats->robustMedian;
     2191    case PS_STAT_ROBUST_STDEV:
     2192        return stats->robustStdev;
     2193    case PS_STAT_FITTED_MEAN:
     2194        return stats->fittedMean;
     2195    case PS_STAT_FITTED_STDEV:
     2196        return stats->fittedStdev;
     2197    case PS_STAT_CLIPPED_MEAN:
     2198        return stats->clippedMean;
     2199    case PS_STAT_CLIPPED_STDEV:
     2200        return stats->clippedStdev;
     2201    case PS_STAT_MAX:
     2202        return stats->max;
     2203    case PS_STAT_MIN:
     2204        return stats->min;
     2205    case PS_STAT_SAMPLE_QUARTILE:
     2206    case PS_STAT_ROBUST_QUARTILE:
     2207        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot return a single quartile value; "
     2208                "get them yourself.\n");
     2209        return NAN;
     2210    default:
     2211        return NAN;
     2212    }
     2213    psAbort(__func__, "Should never get here.\n");
     2214    return NAN;
     2215}
  • trunk/psLib/src/math/psStats.h

    r7991 r7999  
    1414 *  @author GLG, MHPCC
    1515 *
    16  *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2006-07-27 03:51:13 $
     16 *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2006-07-28 00:44:05 $
    1818 *
    1919 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    190190);
    191191
    192 /** Extracts the statistic value specified by stats->options.
    193  *
    194  *  @return psBool    If more than one statistic result is set in stats->options,
    195  *                    false is returned and the value parameter is not set,
    196  *                    otherwise true is returned.
    197  */
    198 psBool p_psGetStatValue(
    199     const psStats* stats, ///< the statistic struct to operate on
    200 
    201     psF64 *value ///< if return is true, this is set to the specified statistic value by stats->options
    202 );
    203 
    204192
    205193// Get the statistics option from a string
     
    211199// Generate a string of statistics options from a psStats
    212200psString psStatsToString(const psStats *stats);
    213 
     201// Is only a single statistics option set?
     202inline psStatsOptions psStatsSingleOption(psStatsOptions option);
     203// Return a particular stats value
     204inline double psStatsGetValue(const psStats *stats, psStatsOptions option);
    214205
    215206/// @}
  • trunk/psLib/test/math/tst_psHist00.c

    r5117 r7999  
    1818    psTraceSetLevel(".", 0);
    1919    psTraceSetLevel("p_psVectorBinDisect", 0);
    20     psTraceSetLevel("p_psGetStatValue", 0);
    2120    psTraceSetLevel("psHistogramAlloc", 0);
    2221    psTraceSetLevel("psHistogramAllocGeneric", 0);
  • trunk/psLib/test/math/tst_psHist01.c

    r5117 r7999  
    1818    psTraceSetLevel(".", 0);
    1919    psTraceSetLevel("p_psVectorBinDisect", 0);
    20     psTraceSetLevel("p_psGetStatValue", 0);
    2120    psTraceSetLevel("psHistogramAlloc", 0);
    2221    psTraceSetLevel("psHistogramAllocGeneric", 0);
  • trunk/psLib/test/math/tst_psHist03.c

    r5117 r7999  
    2020    psTraceSetLevel(".", 0);
    2121    psTraceSetLevel("p_psVectorBinDisect", 0);
    22     psTraceSetLevel("p_psGetStatValue", 0);
    2322    psTraceSetLevel("psHistogramAlloc", 0);
    2423    psTraceSetLevel("psHistogramAllocGeneric", 0);
  • trunk/psLib/test/math/tst_psStats00.c

    r7131 r7999  
    1111*  @author GLG, MHPCC
    1212*
    13 *  @version $Revision: 1.7 $  $Name: not supported by cvs2svn $
    14 *  @date $Date: 2006-05-18 01:20:10 $
     13*  @version $Revision: 1.8 $  $Name: not supported by cvs2svn $
     14*  @date $Date: 2006-07-28 00:44:05 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    7070    //
    7171    psTraceSetLevel(".", 0);
    72     psTraceSetLevel("p_psGetStatValue", 0);
    7372    psTraceSetLevel("p_psVectorSampleMean", 10);
    7473    psTraceSetLevel("p_psVectorMax", 0);
  • trunk/psLib/test/math/tst_psStats01.c

    r5117 r7999  
    33*  @brief Contains tests for psVectorStats with max calculations.
    44*
    5 *  We extensively test the code with data type PS_TYPE_F32.  If these pass, we 
     5*  We extensively test the code with data type PS_TYPE_F32.  If these pass, we
    66*  do a much simpler test with data types PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_F64.
    77*
     
    1111*  @author GLG, MHPCC
    1212*
    13 *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
    14 *  @date $Date: 2005-09-24 01:10:00 $
     13*  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
     14*  @date $Date: 2006-07-28 00:44:05 $
    1515*
    1616* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    6060    //
    6161    psTraceSetLevel(".", 0);
    62     psTraceSetLevel("p_psGetStatValue", 0);
    6362    psTraceSetLevel("p_psVectorMax", 0);
    6463    psTraceSetLevel("p_psVectorMin", 0);
  • trunk/psLib/test/math/tst_psStats02.c

    r5117 r7999  
    33*  @brief Contains tests for psVectorStats with min calculations
    44*
    5 *  We extensively test the code with data type PS_TYPE_F32.  If these pass, we 
     5*  We extensively test the code with data type PS_TYPE_F32.  If these pass, we
    66*  do a much simpler test with data types PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_F64.
    77*
     
    1111*  @author GLG, MHPCC
    1212*
    13 *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
    14 *  @date $Date: 2005-09-24 01:10:00 $
     13*  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
     14*  @date $Date: 2006-07-28 00:44:05 $
    1515*
    1616* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    6060    //
    6161    psTraceSetLevel(".", 0);
    62     psTraceSetLevel("p_psGetStatValue", 0);
    6362    psTraceSetLevel("p_psVectorMax", 0);
    6463    psTraceSetLevel("p_psVectorMin", 0);
  • trunk/psLib/test/math/tst_psStats03.c

    r6226 r7999  
    1919    //
    2020    psTraceSetLevel(".", 0);
    21     psTraceSetLevel("p_psGetStatValue", 0);
    2221    psTraceSetLevel("p_psVectorSampleMean", 0);
    2322    psTraceSetLevel("p_psVectorCheckNonEmpty", 0);
  • trunk/psLib/test/math/tst_psStats06.c

    r5117 r7999  
    2222    //
    2323    psTraceSetLevel(".", 0);
    24     psTraceSetLevel("p_psGetStatValue", 0);
    2524    psTraceSetLevel("p_psVectorSampleMean", 0);
    2625    psTraceSetLevel("p_psVectorMax", 0);
  • trunk/psLib/test/math/tst_psStats07.c

    r7131 r7999  
    462462    psTraceSetLevel(".", TRACE_LEVEL);
    463463    psTraceSetLevel("psGaussian", TRACE_LEVEL);
    464     psTraceSetLevel("p_psGetStatValue", TRACE_LEVEL);
    465464    psTraceSetLevel("p_psVectorMax", TRACE_LEVEL);
    466465    psTraceSetLevel("p_psVectorMin", TRACE_LEVEL);
  • trunk/psLib/test/math/tst_psStats08.c

    r5117 r7999  
    2323    //
    2424    psTraceSetLevel(".", 0);
    25     psTraceSetLevel("p_psGetStatValue", 0);
    2625    psTraceSetLevel("p_psVectorMax", 0);
    2726    psTraceSetLevel("p_psVectorMin", 0);
  • trunk/psLib/test/math/tst_psStats09.c

    r7166 r7999  
    335335    //
    336336    psTraceSetLevel(".", TRACE_LEVEL);
    337     psTraceSetLevel("p_psGetStatValue", TRACE_LEVEL);
    338337    psTraceSetLevel("p_psVectorSampleMean", TRACE_LEVEL);
    339338    psTraceSetLevel("p_psVectorMax", TRACE_LEVEL);
Note: See TracChangeset for help on using the changeset viewer.