Changeset 13918 for trunk/psLib/src/math/psVectorSmooth.c
- Timestamp:
- Jun 20, 2007, 10:21:30 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psVectorSmooth.c (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 }
Note:
See TracChangeset
for help on using the changeset viewer.
