Tree.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. *
  3. * Inverse Kinematics software, with several solvers including
  4. * Selectively Damped Least Squares Method
  5. * Damped Least Squares Method
  6. * Pure Pseudoinverse Method
  7. * Jacobian Transpose Method
  8. *
  9. *
  10. * Author: Samuel R. Buss, [email protected].
  11. * Web page: http://www.math.ucsd.edu/~sbuss/ResearchWeb/ikmethods/index.html
  12. *
  13. *
  14. This software is provided 'as-is', without any express or implied warranty.
  15. In no event will the authors be held liable for any damages arising from the use of this software.
  16. Permission is granted to anyone to use this software for any purpose,
  17. including commercial applications, and to alter it and redistribute it freely,
  18. subject to the following restrictions:
  19. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  20. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  21. 3. This notice may not be removed or altered from any source distribution.
  22. *
  23. *
  24. */
  25. #include "LinearR3.h"
  26. #include "Node.h"
  27. #ifndef _CLASS_TREE
  28. #define _CLASS_TREE
  29. class Tree {
  30. public:
  31. Tree();
  32. int GetNumNode() const { return nNode; }
  33. int GetNumEffector() const { return nEffector; }
  34. int GetNumJoint() const { return nJoint; }
  35. void InsertRoot(Node*);
  36. void InsertLeftChild(Node* parent, Node* child);
  37. void InsertRightSibling(Node* parent, Node* child);
  38. // Accessors based on node numbers
  39. Node* GetJoint(int);
  40. Node* GetEffector(int);
  41. const VectorR3& GetEffectorPosition(int);
  42. // Accessors for tree traversal
  43. Node* GetRoot() const { return root; }
  44. Node* GetSuccessor ( const Node* ) const;
  45. Node* GetParent( const Node* node ) const { return node->realparent; }
  46. void Compute();
  47. void Print();
  48. void Init();
  49. void UnFreeze();
  50. private:
  51. Node* root;
  52. int nNode; // nNode = nEffector + nJoint
  53. int nEffector;
  54. int nJoint;
  55. void SetSeqNum(Node*);
  56. Node* SearchJoint(Node*, int);
  57. Node* SearchEffector(Node*, int);
  58. void ComputeTree(Node*);
  59. void PrintTree(Node*);
  60. void InitTree(Node*);
  61. void UnFreezeTree(Node*);
  62. };
  63. inline Node* Tree::GetSuccessor ( const Node* node ) const
  64. {
  65. if ( node->left ) {
  66. return node->left;
  67. }
  68. while ( true ) {
  69. if ( node->right ) {
  70. return ( node->right );
  71. }
  72. node = node->realparent;
  73. if ( !node ) {
  74. return 0; // Back to root, finished traversal
  75. }
  76. }
  77. }
  78. #endif