GestureRecognitionToolkit  Version: 0.1.0
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 Context : public MLBase
39 {
40 public:
41  Context(void){
42  contextType = "NOT_SET";
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->contextType = context->contextType;
72  this->initialized = context->initialized;
73  this->okToContinue = context->okToContinue;
74  this->numInputDimensions = context->numInputDimensions;
75  this->numOutputDimensions = context->numOutputDimensions;
76  this->data = context->data;
77  this->debugLog = context->debugLog;
78  this->errorLog = context->errorLog;
79  this->warningLog = context->warningLog;
80 
81  return true;
82  }
83 
84  virtual bool process(VectorFloat inputVector){ return false; }
85 
86  virtual bool reset(){ return false; }
87 
88  virtual bool updateContext(bool value){ return false; }
89 
90  //Getters
91  std::string getContextType() const { return contextType; }
92  UINT getNumInputDimensions() const { return numInputDimensions; }
93  UINT getNumOutputDimensions() const { return numOutputDimensions; }
94  bool getInitialized() const { return initialized; }
95  bool getOK() const { return okToContinue; }
96  VectorFloat getProcessedData() const { return data; }
97 
101  typedef std::map< std::string, Context*(*)() > StringContextMap;
102 
109  static Context* createInstanceFromString( const std::string &contextType);
110 
116  Context* createNewInstance() const;
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 //These two functions/classes are used to register any new Context Module with the Context base class
156 template< typename T > Context *newContextModuleInstance() { return new T; }
157 
158 template< typename T >
160 public:
161  RegisterContextModule( const std::string &newContextModuleName ) {
162  getMap()->insert( std::pair< std::string, Context*(*)() >(newContextModuleName, &newContextModuleInstance< T > ) );
163  }
164 };
165 
166 GRT_END_NAMESPACE
167 
168 #endif //GRT_CONTEXT_HEADER
virtual bool reset()
Definition: Context.h:86
std::map< std::string, Context *(*)() > StringContextMap
Definition: Context.h:101
bool loadContextSettingsFromFile(std::fstream &file)
Definition: Context.cpp:78
This is the main base class that all GRT machine learning algorithms should inherit from...
bool saveContextSettingsToFile(std::fstream &file) const
Definition: Context.cpp:64
Context * createNewInstance() const
Definition: Context.cpp:37
bool copyGRTBaseVariables(const GRTBase *GRTBase)
Definition: GRTBase.cpp:32
bool init()
Definition: Context.cpp:41
Definition: MLBase.h:70
static Context * createInstanceFromString(const std::string &contextType)
Definition: Context.cpp:28