21 #define GRT_DLL_EXPORTS 27 const std::string WeightedAverageFilter::id =
"WeightedAverageFilter";
35 init(filterSize,numDimensions);
61 if( rhs.initialized ){
74 if( preProcessing == NULL )
return false;
84 errorLog <<
"deepCopyFrom(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
93 errorLog <<
"process(const VectorFloat &inputVector) - The filter has not been initialized!" << std::endl;
97 if( inputVector.size() != numInputDimensions ){
98 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
104 if( processedData.size() == numOutputDimensions )
return true;
116 if( !file.is_open() ){
117 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
121 file <<
"GRT_WEIGHTED_AVERAGE_FILTER_FILE_V1.0" << std::endl;
123 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
124 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
125 file <<
"FilterSize: " <<
filterSize << std::endl;
132 if( !file.is_open() ){
133 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
142 if( word !=
"GRT_WEIGHTED_AVERAGE_FILTER_FILE_V1.0" ){
143 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
149 if( word !=
"NumInputDimensions:" ){
150 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
153 file >> numInputDimensions;
157 if( word !=
"NumOutputDimensions:" ){
158 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
161 file >> numOutputDimensions;
165 if( word !=
"FilterSize:" ){
166 errorLog <<
"load(fstream &file) - Failed to read FilterSize header!" << std::endl;
172 return init(filterSize,numInputDimensions);
181 if( filterSize == 0 ){
182 errorLog <<
"init(UINT filterSize,UINT numDimensions) - Filter size can not be zero!" << std::endl;
186 if( numDimensions == 0 ){
187 errorLog <<
"init(UINT filterSize,UINT numDimensions) - The number of dimensions must be greater than zero!" << std::endl;
193 this->numInputDimensions = numDimensions;
194 this->numOutputDimensions = numDimensions;
195 processedData.clear();
197 processedData.
resize(numDimensions,0);
207 errorLog <<
"init(UINT filterSize,UINT numDimensions) - Failed to resize dataBuffer!" << std::endl;
217 errorLog <<
"filter(const Float x) - The filter has not been initialized!" << std::endl;
223 if( y.size() == 0 )
return 0;
231 errorLog <<
"filter(const VectorFloat &x) - The filter has not been initialized!" << std::endl;
235 if( x.size() != numInputDimensions ){
236 errorLog <<
"filter(const VectorFloat &x) - The size of the input vector (" << x.size() <<
") does not match that of the number of dimensions of the filter (" << numInputDimensions <<
")!" << std::endl;
246 for(
unsigned int j=0; j<numInputDimensions; j++){
247 processedData[j] = 0;
251 weightSum += weights[i];
253 if( weightSum != 0.0 ) processedData[j] /= weightSum;
256 return processedData;
bool push_back(const T &value)
std::string getId() const
virtual ~WeightedAverageFilter()
UINT inputSampleCounter
A counter to keep track of the number of input samples.
static std::string getId()
virtual bool resize(const unsigned int size)
WeightedAverageFilter & operator=(const WeightedAverageFilter &rhs)
CircularBuffer< VectorFloat > dataBuffer
A buffer to store the previous N values, N = filterSize.
virtual bool deepCopyFrom(const PreProcessing *preProcessing)
The WeightedAverageFilter implements a weighted average filter that gives a larger weight to more rec...
UINT getFilterSize() const
virtual bool process(const VectorFloat &inputVector)
virtual bool save(std::fstream &file) const
UINT filterSize
The size of the filter.
Float filter(const Float x)
bool copyBaseVariables(const PreProcessing *preProcessingModule)
WeightedAverageFilter(const UINT filterSize=5, const UINT numDimensions=1)
VectorFloat getFilteredData() const
virtual bool load(std::fstream &file)
VectorFloat weights
Stores the weights for each sample in the buffer, the size of this vector will match the filterSize...
bool resize(const unsigned int newBufferSize)