30 classType =
"MedianFilter";
31 preProcessingType = classType;
32 debugLog.setProceedingText(
"[DEBUG MedianFilter]");
33 errorLog.setProceedingText(
"[ERROR MedianFilter]");
34 warningLog.setProceedingText(
"[WARNING MedianFilter]");
35 init(filterSize,numDimensions);
40 classType =
"MedianFilter";
41 preProcessingType = classType;
42 debugLog.setProceedingText(
"[DEBUG MedianFilter]");
43 errorLog.setProceedingText(
"[ERROR MedianFilter]");
44 warningLog.setProceedingText(
"[WARNING MedianFilter]");
66 if( rhs.initialized ){
79 if( preProcessing == NULL )
return false;
89 errorLog <<
"clone(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
98 errorLog <<
"process(const VectorFloat &inputVector) - The filter has not been initialized!" << std::endl;
102 if( inputVector.size() != numInputDimensions ){
103 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
109 if( processedData.size() == numOutputDimensions )
return true;
122 errorLog <<
"saveModelToFile(string filename) - The MedianFilter has not been initialized" << std::endl;
127 file.open(filename.c_str(), std::ios::out);
141 if( !file.is_open() ){
142 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
146 file <<
"GRT_MEDIAN_FILTER_FILE_V1.0" << std::endl;
148 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
149 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
150 file <<
"FilterSize: " <<
filterSize << std::endl;
158 file.open(filename.c_str(), std::ios::in);
173 if( !file.is_open() ){
174 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
183 if( word !=
"GRT_MEDIAN_FILTER_FILE_V1.0" ){
184 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
190 if( word !=
"NumInputDimensions:" ){
191 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
194 file >> numInputDimensions;
198 if( word !=
"NumOutputDimensions:" ){
199 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
202 file >> numOutputDimensions;
206 if( word !=
"FilterSize:" ){
207 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read FilterSize header!" << std::endl;
213 return init(filterSize,numInputDimensions);
222 if( filterSize == 0 ){
223 errorLog <<
"init(UINT filterSize,UINT numDimensions) - Filter size can not be zero!" << std::endl;
227 if( numDimensions == 0 ){
228 errorLog <<
"init(UINT filterSize,UINT numDimensions) - The number of dimensions must be greater than zero!" << std::endl;
234 this->numInputDimensions = numDimensions;
235 this->numOutputDimensions = numDimensions;
236 processedData.clear();
237 processedData.
resize(numDimensions,0);
241 errorLog <<
"init(UINT filterSize,UINT numDimensions) - Failed to resize dataBuffer!" << std::endl;
251 if( y.size() == 0 )
return 0;
259 errorLog <<
"filter(const VectorFloat &x) - The filter has not been initialized!" << std::endl;
263 if( x.
getSize() != numInputDimensions ){
264 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;
275 for(
unsigned int j=0; j<numInputDimensions; j++){
279 std::sort(tmp.begin(),tmp.end());
282 unsigned int medianIndex = (inputSampleCounter/2);
283 processedData[j] = tmp[ medianIndex ];
286 return processedData;
296 for(
unsigned int j=0; j<numInputDimensions; j++){
bool push_back(const T &value)
virtual bool resize(const unsigned int size)
unsigned int getSize() const
std::string getPreProcessingType() const
bool copyBaseVariables(const PreProcessing *preProcessingModule)
bool resize(const unsigned int newBufferSize)