21 #define GRT_DLL_EXPORTS 27 const std::string ClassLabelTimeoutFilter::id =
"ClassLabelTimeoutFilter";
35 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
36 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
37 init(timeoutDuration,filterMode);
43 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
44 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
47 this->filteredClassLabel = rhs.filteredClassLabel;
48 this->filterMode = rhs.filterMode;
49 this->timeoutDuration = rhs.timeoutDuration;
50 this->classLabelTimers = rhs.classLabelTimers;
64 this->filteredClassLabel = rhs.filteredClassLabel;
65 this->filterMode = rhs.filterMode;
66 this->timeoutDuration = rhs.timeoutDuration;
67 this->classLabelTimers = rhs.classLabelTimers;
77 if( postProcessing == NULL )
return false;
79 if( this->
getId() == postProcessing->
getId() ){
84 this->filteredClassLabel = ptr->filterMode;
85 this->filterMode = ptr->filterMode;
86 this->timeoutDuration = ptr->timeoutDuration;
87 this->classLabelTimers = ptr->classLabelTimers;
97 #ifdef GRT_SAFE_CHECKING 99 errorLog <<
"process(const VectorDouble &inputVector) - Not initialized!" << std::endl;
103 if( inputVector.
getSize() != numInputDimensions ){
104 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
110 processedData[0] =
filter( (UINT)inputVector[0] );
115 filteredClassLabel = 0;
116 classLabelTimers.clear();
117 processedData.clear();
118 processedData.
resize(1,0);
126 if( filterMode != ALL_CLASS_LABELS && filterMode != INDEPENDENT_CLASS_LABELS ){
127 errorLog <<
"init(double timeoutDuration,UINT filterMode) - Unkown filter mode!" << std::endl;
131 this->timeoutDuration = timeoutDuration;
132 this->filterMode = filterMode;
133 numInputDimensions = 1;
134 numOutputDimensions = 1;
135 initialized =
reset();
142 if( predictedClassLabel == 0 && classLabelTimers.size() == 0 ){
143 filteredClassLabel = predictedClassLabel;
144 return filteredClassLabel;
147 bool matchFound =
false;
150 switch( filterMode ){
151 case ALL_CLASS_LABELS:
154 if( classLabelTimers.size() == 0 ){
155 filteredClassLabel = predictedClassLabel;
156 classLabelTimers.push_back(
ClassLabelAndTimer(predictedClassLabel,timeoutDuration) );
159 if( classLabelTimers[0].timerReached() ){
161 classLabelTimers.clear();
165 filteredClassLabel = 0;
166 if( predictedClassLabel ){
167 filteredClassLabel =
filter( predictedClassLabel );
170 }
else filteredClassLabel = 0;
174 case INDEPENDENT_CLASS_LABELS:
177 if( classLabelTimers.size() > 0 ){
178 iter = classLabelTimers.begin();
180 while( iter != classLabelTimers.end() ){
181 if( iter->getClassLabel() == predictedClassLabel ){
183 if( iter->timerReached() ){
185 iter->set(predictedClassLabel,timeoutDuration);
189 filteredClassLabel = predictedClassLabel;
191 }
else filteredClassLabel = 0;
196 if( iter->timerReached() ){
198 iter = classLabelTimers.erase( iter );
207 classLabelTimers.push_back(
ClassLabelAndTimer(predictedClassLabel,timeoutDuration) );
208 filteredClassLabel = predictedClassLabel;
214 return filteredClassLabel;
219 for(UINT i=0; i<classLabelTimers.
getSize(); i++){
220 if( classLabelTimers[i].timerReached() ){
230 if( !file.is_open() ){
231 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
235 file <<
"GRT_CLASS_LABEL_TIMEOUT_FILTER_FILE_V1.0" << std::endl;
236 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
237 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
238 file <<
"FilterMode: " << filterMode << std::endl;
239 file <<
"TimeoutDuration: " << timeoutDuration << std::endl;
246 if( !file.is_open() ){
247 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
256 if( word !=
"GRT_CLASS_LABEL_TIMEOUT_FILTER_FILE_V1.0" ){
257 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
262 if( word !=
"NumInputDimensions:" ){
263 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
266 file >> numInputDimensions;
270 if( word !=
"NumOutputDimensions:" ){
271 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
274 file >> numOutputDimensions;
278 if( word !=
"FilterMode:" ){
279 errorLog <<
"load(fstream &file) - Failed to read FilterMode header!" << std::endl;
285 if( word !=
"TimeoutDuration:" ){
286 errorLog <<
"load(fstream &file) - Failed to read TimeoutDuration header!" << std::endl;
289 file >> timeoutDuration;
292 return init(timeoutDuration,filterMode);
296 this->timeoutDuration = timeoutDuration;
304 if( filterMode != ALL_CLASS_LABELS && filterMode != INDEPENDENT_CLASS_LABELS )
return false;
305 this->filterMode = filterMode;
std::string getId() const
The Class Label Timeout Filter is a useful post-processing module which debounces a gesture (i...
virtual ~ClassLabelTimeoutFilter()
ClassLabelTimeoutFilter(const unsigned long timeoutDuration=1000, const UINT filterMode=ALL_CLASS_LABELS)
virtual bool resize(const unsigned int size)
virtual bool load(std::fstream &file) override
virtual bool reset() override
bool setTimeoutDuration(const unsigned long timeoutDuration)
This is the main base class that all GRT PostProcessing algorithms should inherit from...
bool setFilterMode(const UINT filterMode)
static std::string getId()
bool copyBaseVariables(const PostProcessing *postProcessingModule)
virtual bool save(std::fstream &file) const override
ClassLabelTimeoutFilter & operator=(const ClassLabelTimeoutFilter &rhs)
virtual bool process(const VectorDouble &inputVector) override
virtual bool deepCopyFrom(const PostProcessing *postProcessing) override
UINT filter(const UINT predictedClassLabel)