GestureRecognitionToolkit  Version: 0.2.0
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 GRT_BEGIN_NAMESPACE
36 
37 class GRT_API Node : public GRTBase{
38 public:
42  Node();
43 
47  virtual ~Node();
48 
56  virtual bool predict(const VectorFloat &x);
57 
66  virtual bool predict(const VectorFloat &x,VectorFloat &y);
67 
75  virtual bool computeFeatureWeights( VectorFloat &weights ) const;
76 
84  virtual bool computeLeafNodeWeights( MatrixFloat &weights ) const;
85 
92  virtual bool clear();
93 
100  virtual bool print() const;
101 
109  virtual bool getModel( std::ostream &stream ) const;
110 
117  virtual bool save( std::fstream &file ) const;
118 
125  virtual bool load( std::fstream &file );
126 
133  virtual Node* deepCopyNode() const;
134 
140  std::string getNodeType() const;
141 
148  UINT getDepth() const;
149 
155  UINT getNodeID() const;
156 
162  UINT getPredictedNodeID() const;
163 
164  UINT getMaxDepth() const;
165 
171  bool getIsLeafNode() const;
172 
178  bool getHasParent() const;
179 
185  bool getHasLeftChild() const;
186 
192  bool getHasRightChild() const;
193 
194  Node *getParent() const { return parent; }
195  Node *getLeftChild() const { return leftChild; }
196  Node *getRightChild() const { return rightChild; }
197 
198  bool initNode(Node *parent,const UINT depth,const UINT nodeID,const bool isLeafNode = false);
199 
200  bool setParent(Node *parent);
201 
202  bool setLeftChild(Node *leftChild);
203 
204  bool setRightChild(Node *rightChild);
205 
206  bool setDepth(const UINT depth);
207 
208  bool setNodeID(const UINT nodeID);
209 
210  bool setIsLeafNode(const bool isLeafNode);
211 
215  typedef std::map< std::string, Node*(*)() > StringNodeMap;
216 
223  static Node* createInstanceFromString( std::string const &nodeType );
224 
230  Node* createNewInstance() const;
231 
232 protected:
233 
241  virtual bool saveParametersToFile( std::fstream &file ) const{ return true; }
242 
250  virtual bool loadParametersFromFile( std::fstream &file ){ return true; }
251 
252  std::string nodeType;
253  UINT depth;
254  UINT nodeID;
255  UINT predictedNodeID;
256  bool isLeafNode;
257  Node *parent;
258  Node *leftChild;
259  Node *rightChild;
260 
261  static StringNodeMap *getMap() {
262  if( !stringNodeMap ){ stringNodeMap = new StringNodeMap; }
263  return stringNodeMap;
264  }
265 
266  private:
267  static StringNodeMap *stringNodeMap;
268  static UINT numNodeInstances;
269 
270 };
271 
272 //These two functions/classes are used to register any new Node with the Node base class
273 template< typename T > Node* getNewNodeInstance() { return new T; }
274 
275 template< typename T >
277  public:
278  RegisterNode(std::string const &newNodeName) {
279  getMap()->insert( std::pair< std::string, Node*(*)() >(newNodeName, &getNewNodeInstance< T > ) );
280  }
281 };
282 
283 GRT_END_NAMESPACE
284 
285 #endif //GRT_NODE_HEADER
286 
Definition: Node.h:37
virtual bool loadParametersFromFile(std::fstream &file)
Definition: Node.h:250
virtual bool saveParametersToFile(std::fstream &file) const
Definition: Node.h:241
std::map< std::string, Node *(*)() > StringNodeMap
Definition: Node.h:215