Changeset 13918
- Timestamp:
- Jun 20, 2007, 10:21:30 AM (19 years ago)
- Location:
- trunk/psLib/src/math
- Files:
-
- 2 edited
-
psVectorSmooth.c (modified) (2 diffs)
-
psVectorSmooth.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psVectorSmooth.c
r10999 r13918 13 13 #include "psLogMsg.h" 14 14 #include "psVector.h" 15 #include "psAssert.h" 16 #include "psConstants.h" 17 15 18 #include "psVectorSmooth.h" 16 #include "psAssert.h"17 18 19 19 20 psVector *psVectorSmooth(psVector *output, … … 106 107 return output; 107 108 } 109 110 111 112 psVector *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 2 2 * @brief smooth the input vector 3 3 * 4 * $Revision: 1. 2$ $Name: not supported by cvs2svn $5 * $Date: 2007-0 1-23 22:47:23$4 * $Revision: 1.3 $ $Name: not supported by cvs2svn $ 5 * $Date: 2007-06-20 20:21:30 $ 6 6 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 7 7 */ … … 13 13 /// @{ 14 14 15 // Smooth a vector with a Gaussian16 psVector *psVectorSmooth(psVector *output, // Output vector, or NULL17 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 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 20 20 ); 21 22 /// Smooth a vector with a boxcar 23 psVector *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 21 28 /// @} 22 29 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
