21 #define GRT_DLL_EXPORTS 27 const std::string MedianFilter::id =
"MedianFilter";
35 init(filterSize,numDimensions);
60 if( rhs.initialized ){
73 if( preProcessing == NULL )
return false;
78 *
this = *
dynamic_cast<const MedianFilter*
>(preProcessing);
83 errorLog <<
"deepCopyFrom(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
92 errorLog <<
"process(const VectorFloat &inputVector) - The filter has not been initialized!" << std::endl;
96 if( inputVector.size() != numInputDimensions ){
97 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
103 if( processedData.size() == numOutputDimensions )
return true;
115 if( !file.is_open() ){
116 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
120 file <<
"GRT_MEDIAN_FILTER_FILE_V1.0" << std::endl;
122 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
123 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
124 file <<
"FilterSize: " <<
filterSize << std::endl;
131 if( !file.is_open() ){
132 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
141 if( word !=
"GRT_MEDIAN_FILTER_FILE_V1.0" ){
142 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
148 if( word !=
"NumInputDimensions:" ){
149 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
152 file >> numInputDimensions;
156 if( word !=
"NumOutputDimensions:" ){
157 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
160 file >> numOutputDimensions;
164 if( word !=
"FilterSize:" ){
165 errorLog <<
"load(fstream &file) - Failed to read FilterSize header!" << std::endl;
171 return init(filterSize,numInputDimensions);
180 if( filterSize == 0 ){
181 errorLog <<
"init(UINT filterSize,UINT numDimensions) - Filter size can not be zero!" << std::endl;
185 if( numDimensions == 0 ){
186 errorLog <<
"init(UINT filterSize,UINT numDimensions) - The number of dimensions must be greater than zero!" << std::endl;
192 this->numInputDimensions = numDimensions;
193 this->numOutputDimensions = numDimensions;
194 processedData.clear();
195 processedData.
resize(numDimensions,0);
199 errorLog <<
"init(UINT filterSize,UINT numDimensions) - Failed to resize dataBuffer!" << std::endl;
209 if( y.size() == 0 )
return 0;
217 errorLog <<
"filter(const VectorFloat &x) - The filter has not been initialized!" << std::endl;
221 if( x.
getSize() != numInputDimensions ){
222 errorLog <<
"filter(const VectorFloat &x) - The size of the input Vector (" << x.
getSize() <<
") does not match that of the number of dimensions of the filter (" << numInputDimensions <<
")!" << std::endl;
233 for(
unsigned int j=0; j<numInputDimensions; j++){
237 std::sort(tmp.begin(),tmp.end());
240 unsigned int medianIndex = (inputSampleCounter/2);
241 processedData[j] = tmp[ medianIndex ];
244 return processedData;
258 for(
unsigned int j=0; j<numInputDimensions; j++){
bool push_back(const T &value)
std::string getId() const
virtual bool resize(const unsigned int size)
bool copyBaseVariables(const PreProcessing *preProcessingModule)
bool resize(const unsigned int newBufferSize)