Node.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. *
  3. * Mathematics Subpackage (VrMath)
  4. *
  5. *
  6. * Author: Samuel R. Buss, [email protected].
  7. * Web page: http://math.ucsd.edu/~sbuss/MathCG
  8. *
  9. *
  10. This software is provided 'as-is', without any express or implied warranty.
  11. In no event will the authors be held liable for any damages arising from the use of this software.
  12. Permission is granted to anyone to use this software for any purpose,
  13. including commercial applications, and to alter it and redistribute it freely,
  14. subject to the following restrictions:
  15. 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.
  16. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  17. 3. This notice may not be removed or altered from any source distribution.
  18. *
  19. *
  20. */
  21. #ifndef _CLASS_NODE
  22. #define _CLASS_NODE
  23. #include "LinearR3.h"
  24. enum Purpose {JOINT, EFFECTOR};
  25. class VectorR3;
  26. class Node {
  27. friend class Tree;
  28. public:
  29. Node(const VectorR3&, const VectorR3&, double, Purpose, double minTheta=-PI, double maxTheta=PI, double restAngle=0.);
  30. void PrintNode();
  31. void InitNode();
  32. const VectorR3& GetAttach() const { return attach; }
  33. double GetTheta() const { return theta; }
  34. double AddToTheta( double& delta ) {
  35. double orgTheta = theta;
  36. theta += delta;
  37. #if 0
  38. if (theta < minTheta)
  39. theta = minTheta;
  40. if (theta > maxTheta)
  41. theta = maxTheta;
  42. double actualDelta = theta - orgTheta;
  43. delta = actualDelta;
  44. #endif
  45. return theta; }
  46. double UpdateTheta( double& delta ) {
  47. theta = delta;
  48. return theta; }
  49. const VectorR3& GetS() const { return s; }
  50. const VectorR3& GetW() const { return w; }
  51. double GetMinTheta() const { return minTheta; }
  52. double GetMaxTheta() const { return maxTheta; }
  53. double GetRestAngle() const { return restAngle; } ;
  54. void SetTheta(double newTheta) { theta = newTheta; }
  55. void ComputeS(void);
  56. void ComputeW(void);
  57. bool IsEffector() const { return purpose==EFFECTOR; }
  58. bool IsJoint() const { return purpose==JOINT; }
  59. int GetEffectorNum() const { return seqNumEffector; }
  60. int GetJointNum() const { return seqNumJoint; }
  61. bool IsFrozen() const { return freezed; }
  62. void Freeze() { freezed = true; }
  63. void UnFreeze() { freezed = false; }
  64. //private:
  65. bool freezed; // Is this node frozen?
  66. int seqNumJoint; // sequence number if this node is a joint
  67. int seqNumEffector; // sequence number if this node is an effector
  68. double size; // size
  69. Purpose purpose; // joint / effector / both
  70. VectorR3 attach; // attachment point
  71. VectorR3 r; // relative position vector
  72. VectorR3 v; // rotation axis
  73. double theta; // joint angle (radian)
  74. double minTheta; // lower limit of joint angle
  75. double maxTheta; // upper limit of joint angle
  76. double restAngle; // rest position angle
  77. VectorR3 s; // GLobal Position
  78. VectorR3 w; // Global rotation axis
  79. Node* left; // left child
  80. Node* right; // right sibling
  81. Node* realparent; // pointer to real parent
  82. };
  83. #endif