IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13918


Ignore:
Timestamp:
Jun 20, 2007, 10:21:30 AM (19 years ago)
Author:
Paul Price
Message:

Adding psVectorBoxcar for boxcar smoothing

Location:
trunk/psLib/src/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psVectorSmooth.c

    r10999 r13918  
    1313#include "psLogMsg.h"
    1414#include "psVector.h"
     15#include "psAssert.h"
     16#include "psConstants.h"
     17
    1518#include "psVectorSmooth.h"
    16 #include "psAssert.h"
    17 
    1819
    1920psVector *psVectorSmooth(psVector *output,
     
    106107    return output;
    107108}
     109
     110
     111
     112psVector *psVectorBoxcar(psVector *output,
     113                         const psVector *input,
     114                         int size
     115                        )
     116{
     117    PS_ASSERT_VECTOR_NON_NULL(input, NULL);
     118    PS_ASSERT_INT_POSITIVE(size, NULL);
     119
     120    long num = input->n;                // Number of elements
     121    output = psVectorRecycle(output, num, input->type.type);
     122    psVector *nums = psVectorAlloc(num, PS_TYPE_U32); // Number of elements in each bin
     123    psU32 *numsData = nums->data.U32;   // Dereferenced version
     124
     125    psVectorInit(output, 0.0);
     126    psVectorInit(nums, 0);
     127
     128
     129    #define VECTOR_BOXCAR_CASE(TYPE) \
     130  case PS_TYPE_##TYPE: { \
     131      /* Dereference data */ \
     132      ps##TYPE *outputData = output->data.TYPE; \
     133      ps##TYPE *inputData = input->data.TYPE; \
     134      /* Smooth the vector */ \
     135      for (long i = 0; i < num; i++) { \
     136          for (long j = PS_MAX(0, i - size); j < PS_MIN(num, i + size + 1); j++) { \
     137              outputData[j] += inputData[i]; \
     138              numsData[j]++; \
     139          } \
     140      } \
     141      /* Normalisation */ \
     142      for (long i = 0; i < num; i++) { \
     143          outputData[i] /= numsData[i]; \
     144      } \
     145  }
     146
     147    switch (input->type.type) {
     148        VECTOR_BOXCAR_CASE(F32);
     149        VECTOR_BOXCAR_CASE(F64);
     150    default: {
     151            char* typeStr;
     152            PS_TYPE_NAME(typeStr, input->type.type);
     153            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Type %s is not valid.", typeStr);
     154            psFree(nums);
     155            return NULL;
     156        }
     157    }
     158    psFree(nums);
     159    return output;
     160}
  • trunk/psLib/src/math/psVectorSmooth.h

    r11248 r13918  
    22 * @brief smooth the input vector
    33 *
    4  * $Revision: 1.2 $ $Name: not supported by cvs2svn $
    5  * $Date: 2007-01-23 22:47:23 $
     4 * $Revision: 1.3 $ $Name: not supported by cvs2svn $
     5 * $Date: 2007-06-20 20:21:30 $
    66 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    77 */
     
    1313/// @{
    1414
    15 // Smooth a vector with a Gaussian
    16 psVector *psVectorSmooth(psVector *output, // Output vector, or NULL
    17                          const psVector *input, // Input vector (F32 or F64 only)
    18                          double sigma,  // Gausian width (standard deviations)
    19                          double Nsigma  // Number of standard deviations for Gaussian to extend (either side)
     15/// Smooth a vector with a Gaussian
     16psVector *psVectorSmooth(psVector *output, ///< Output vector, or NULL
     17                         const psVector *input, ///< Input vector (F32 or F64 only)
     18                         double sigma,  ///< Gausian width (standard deviations)
     19                         double Nsigma  ///< Number of standard deviations for Gaussian to extend
    2020                        );
     21
     22/// Smooth a vector with a boxcar
     23psVector *psVectorBoxcar(psVector *output, ///< Output vector, or NULL
     24                         const psVector *input, ///< Input vector (F32 or F64 only)
     25                         int size       ///< Boxcar size (one-sided size)
     26    );
     27
    2128/// @}
    2229#endif
Note: See TracChangeset for help on using the changeset viewer.