21 #define GRT_DLL_EXPORTS
31 classType =
"ClassLabelChangeFilter";
32 postProcessingType = classType;
33 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
34 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
35 debugLog.setProceedingText(
"[DEBUG ClassLabelChangeFilter]");
36 errorLog.setProceedingText(
"[ERROR ClassLabelChangeFilter]");
37 warningLog.setProceedingText(
"[WARNING ClassLabelChangeFilter]");
43 classType =
"ClassLabelChangeFilter";
44 postProcessingType = classType;
45 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
46 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
47 debugLog.setProceedingText(
"[DEBUG ClassLabelChangeFilter]");
48 errorLog.setProceedingText(
"[ERROR ClassLabelChangeFilter]");
49 warningLog.setProceedingText(
"[WARNING ClassLabelChangeFilter]");
52 this->filteredClassLabel = rhs.filteredClassLabel;
53 this->labelChanged = rhs.labelChanged;
67 this->filteredClassLabel = rhs.filteredClassLabel;
68 this->labelChanged = rhs.labelChanged;
78 if( postProcessing == NULL )
return false;
85 this->filteredClassLabel = ptr->filteredClassLabel;
86 this->labelChanged = ptr->labelChanged;
98 errorLog <<
"process(const VectorDouble &inputVector) - Not initialized!" << std::endl;
102 if( inputVector.
getSize() != numInputDimensions ){
103 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
108 processedData[0] =
filter( (UINT)inputVector[0] );
113 filteredClassLabel = 0;
114 labelChanged =
false;
115 processedData.clear();
116 processedData.
resize(1,0);
125 numInputDimensions = 1;
126 numOutputDimensions = 1;
133 labelChanged =
false;
135 if( predictedClassLabel != filteredClassLabel ){
136 filteredClassLabel = predictedClassLabel;
138 return filteredClassLabel;
141 return GRT_DEFAULT_NULL_CLASS_LABEL;
147 errorLog <<
"saveModelToFile(string filename) - The ClassLabelChangeFilter has not been initialized" << std::endl;
152 file.open(filename.c_str(), std::ios::out);
166 if( !file.is_open() ){
167 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
171 file <<
"GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" << std::endl;
172 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
173 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
181 file.open(filename.c_str(), std::ios::in);
195 if( !file.is_open() ){
196 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
205 if( word !=
"GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" ){
206 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
211 if( word !=
"NumInputDimensions:" ){
212 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
215 file >> numInputDimensions;
219 if( word !=
"NumOutputDimensions:" ){
220 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
223 file >> numOutputDimensions;
ClassLabelChangeFilter & operator=(const ClassLabelChangeFilter &rhs)
virtual bool saveModelToFile(std::string filename) const
virtual bool loadModelFromFile(std::string filename)
std::string getPostProcessingType() const
virtual bool resize(const unsigned int size)
virtual ~ClassLabelChangeFilter()
bool copyBaseVariables(const PostProcessing *postProcessingModule)
virtual bool deepCopyFrom(const PostProcessing *postProcessing)
UINT filter(UINT predictedClassLabel)
The Class Label Change Filter signals when the predicted output of a classifier changes. For instance, if the output stream of a classifier was {1,1,1,1,2,2,2,2,3,3}, then the output of the filter would be {1,0,0,0,2,0,0,0,3,0}. This module is useful if you want to debounce a gesture and only care about when the gesture label changes.
virtual bool process(const VectorDouble &inputVector)