GestureRecognitionToolkit  Version: 0.2.5
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
Context.h
Go to the documentation of this file.
1 
31 #ifndef GRT_CONTEXT_HEADER
32 #define GRT_CONTEXT_HEADER
33 
34 #include "MLBase.h"
35 
36 GRT_BEGIN_NAMESPACE
37 
38 class GRT_API Context : public MLBase
39 {
40 public:
41  Context( const std::string &id = "" ) : MLBase( id, MLBase::CONTEXT )
42  {
43  initialized = false;
44  okToContinue = true;
45  numInputDimensions = 0;
46  numOutputDimensions = 0;
47  numContextInstances++;
48  }
49 
50  virtual ~Context(void){
51  if( --numContextInstances == 0 ){
52  delete stringContextMap;
53  stringContextMap = NULL;
54  }
55  }
56 
57  //Clone method
58  virtual bool deepCopyFrom(const Context *rhs){ return false; }
59 
60  bool copyBaseVariables(const Context *context){
61 
62  if( context == NULL ){
63  errorLog << "copyBaseVariables(const Context *context) - context pointer is NULL!" << std::endl;
64  return false;
65  }
66 
67  if( !this->copyGRTBaseVariables( context ) ){
68  return false;
69  }
70 
71  this->initialized = context->initialized;
72  this->okToContinue = context->okToContinue;
73  this->numInputDimensions = context->numInputDimensions;
74  this->numOutputDimensions = context->numOutputDimensions;
75  this->data = context->data;
76  this->debugLog = context->debugLog;
77  this->errorLog = context->errorLog;
78  this->warningLog = context->warningLog;
79 
80  return true;
81  }
82 
83  virtual bool process(VectorFloat inputVector){ return false; }
84 
85  virtual bool reset() override { return false; }
86 
87  virtual bool updateContext(bool value){ return false; }
88 
89  //Getters
90  std::string getContextType() const { return contextType; }
91  bool getInitialized() const { return initialized; }
92  bool getOK() const { return okToContinue; }
93  VectorFloat getProcessedData() const { return data; }
94 
98  typedef std::map< std::string, Context*(*)() > StringContextMap;
99 
106  static Context* create( std::string const &id );
107 
113  Context* create() const;
114 
115  GRT_DEPRECATED_MSG( "createNewInstance is deprecated, use create instead.", Context* createNewInstance() const );
116  GRT_DEPRECATED_MSG( "createInstanceFromString is deprecated, use create instead.", static Context* createInstanceFromString( const std::string &id ) );
117 
118 protected:
124  bool init();
125 
131  bool saveContextSettingsToFile( std::fstream &file ) const;
132 
138  bool loadContextSettingsFromFile( std::fstream &file );
139 
140  std::string contextType;
141  bool initialized;
142  bool okToContinue;
143  VectorFloat data;
144 
145  static StringContextMap *getMap(){
146  if( !stringContextMap ){ stringContextMap = new StringContextMap; }
147  return stringContextMap;
148  }
149 
150 private:
151  static StringContextMap *stringContextMap;
152  static UINT numContextInstances;
153 };
154 
155 template< typename T > Context *createNewContextModuleInstance() { return new T; }
156 
161 template< typename T >
163 public:
164  RegisterContextModule( const std::string &newContextModuleName ) {
165  getMap()->insert( std::pair< std::string, Context*(*)() >(newContextModuleName, &createNewContextModuleInstance< T > ) );
166  }
167 };
168 
169 GRT_END_NAMESPACE
170 
171 #endif //GRT_CONTEXT_HEADER
virtual bool reset() override
Definition: Context.h:85
MLBase(const std::string &id="", const BaseType type=BASE_TYPE_NOT_SET)
Definition: MLBase.cpp:26
std::map< std::string, Context *(*)() > StringContextMap
Definition: Context.h:98
Context * createNewContextModuleInstance()
Returns a pointer to a new instance of the template class, the caller is responsible for deleting the...
Definition: Context.h:155
This class provides an interface for classes to register themselves with the Context base class...
Definition: Context.h:162
GRT_DEPRECATED_MSG("saveModelToFile(std::string filename) is deprecated, use save(const std::string &filename) instead", virtual bool saveModelToFile(const std::string &filename) const )
bool copyGRTBaseVariables(const GRTBase *GRTBase)
Definition: GRTBase.cpp:43
This is the main base class that all GRT machine learning algorithms should inherit from...
Definition: MLBase.h:72