GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
Node.h
Go to the documentation of this file.
1 
10 /*
11  GRT MIT License
12  Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
13 
14  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
15  and associated documentation files (the "Software"), to deal in the Software without restriction,
16  including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
18  subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included in all copies or substantial
21  portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24  LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  */
29 
30 #ifndef GRT_NODE_HEADER
31 #define GRT_NODE_HEADER
32 
33 #include "../../CoreModules/GRTBase.h"
34 
35 namespace GRT{
36 
37 class Node : public GRTBase{
38 public:
42  Node();
43 
47  virtual ~Node();
48 
56  virtual bool predict(const VectorDouble &x);
57 
66  virtual bool predict(const VectorDouble &x,VectorDouble &y);
67 
74  virtual bool clear();
75 
82  virtual bool print() const;
83 
91  virtual bool getModel(ostream &stream) const;
92 
99  virtual bool saveToFile(fstream &file) const;
100 
107  virtual bool loadFromFile(fstream &file);
108 
115  virtual Node* deepCopyNode() const;
116 
122  string getNodeType() const;
123 
130  UINT getDepth() const;
131 
137  UINT getNodeID() const;
138 
144  UINT getPredictedNodeID() const;
145 
146  UINT getMaxDepth() const;
147 
153  bool getIsLeafNode() const;
154 
160  bool getHasParent() const;
161 
167  bool getHasLeftChild() const;
168 
174  bool getHasRightChild() const;
175 
176  Node *getParent() const { return parent; }
177  Node *getLeftChild() const { return leftChild; }
178  Node *getRightChild() const { return rightChild; }
179 
180  bool initNode(Node *parent,const UINT depth,const UINT nodeID,const bool isLeafNode = false);
181 
182  bool setParent(Node *parent);
183 
184  bool setLeftChild(Node *leftChild);
185 
186  bool setRightChild(Node *rightChild);
187 
188  bool setDepth(const UINT depth);
189 
190  bool setNodeID(const UINT nodeID);
191 
192  bool setIsLeafNode(const bool isLeafNode);
193 
197  typedef std::map< string, Node*(*)() > StringNodeMap;
198 
205  static Node* createInstanceFromString(string const &nodeType);
206 
212  Node* createNewInstance() const;
213 
214 protected:
215 
223  virtual bool saveParametersToFile(fstream &file) const{
224 
225  return true;
226  }
227 
235  virtual bool loadParametersFromFile(fstream &file){
236 
237  return true;
238  }
239 
240  string nodeType;
241  UINT depth;
242  UINT nodeID;
243  UINT predictedNodeID;
244  bool isLeafNode;
245  Node *parent;
246  Node *leftChild;
247  Node *rightChild;
248 
249  static StringNodeMap *getMap() {
250  if( !stringNodeMap ){ stringNodeMap = new StringNodeMap; }
251  return stringNodeMap;
252  }
253 
254 private:
255  static StringNodeMap *stringNodeMap;
256  static UINT numNodeInstances;
257 
258 };
259 
260 //These two functions/classes are used to register any new Node with the Node base class
261 template< typename T > Node* getNewNodeInstance() { return new T; }
262 
263 template< typename T >
265 public:
266  RegisterNode(string const &newNodeName) {
267  getMap()->insert( std::pair<string, Node*(*)()>(newNodeName, &getNewNodeInstance< T > ) );
268  }
269 };
270 
271 } //End of namespace GRT
272 
273 #endif //GRT_NODE_HEADER
274 
virtual Node * deepCopyNode() const
Definition: Node.cpp:267
UINT getDepth() const
Definition: Node.cpp:299
UINT getPredictedNodeID() const
Definition: Node.cpp:307
bool getHasLeftChild() const
Definition: Node.cpp:342
Definition: AdaBoost.cpp:25
virtual bool loadFromFile(fstream &file)
Definition: Node.cpp:173
virtual bool saveToFile(fstream &file) const
Definition: Node.cpp:131
virtual bool getModel(ostream &stream) const
Definition: Node.cpp:111
string getNodeType() const
Definition: Node.cpp:295
virtual bool loadParametersFromFile(fstream &file)
Definition: Node.h:235
virtual bool saveParametersToFile(fstream &file) const
Definition: Node.h:223
std::map< string, Node *(*)() > StringNodeMap
Definition: Node.h:197
virtual ~Node()
Definition: Node.cpp:55
UINT getNodeID() const
Definition: Node.cpp:303
virtual bool predict(const VectorDouble &x)
Definition: Node.cpp:59
Node * createNewInstance() const
Definition: Node.cpp:38
bool getHasParent() const
Definition: Node.cpp:338
bool getIsLeafNode() const
Definition: Node.cpp:334
virtual bool clear()
Definition: Node.cpp:69
static Node * createInstanceFromString(string const &nodeType)
Definition: Node.cpp:28
Definition: Node.h:37
bool getHasRightChild() const
Definition: Node.cpp:346
Node()
Definition: Node.cpp:42
virtual bool print() const
Definition: Node.cpp:100