HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
KIN_Chain.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: KIN_Chain.h ( Kinematics Library, C++)
7  *
8  * COMMENTS:
9  * This class holds the specification of a kinematic
10  * chain. The chain is specified as a string of the
11  * form: "length rx ry rz, ..., length rx ry rz;"
12  */
13 
14 #ifndef __KIN_Chain__
15 #define __KIN_Chain__
16 
17 #include "KIN_API.h"
18 #include "KIN_Bone.h"
19 #include <UT/UT_Array.h>
20 #include <UT/UT_Matrix4.h>
21 #include <UT/UT_StringHolder.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <UT/UT_Vector3.h>
24 #include <UT/UT_Vector3Array.h>
25 #include <UT/UT_XformOrder.h>
26 #include <SYS/SYS_Inline.h>
27 #include <SYS/SYS_Math.h>
28 
29 class KIN_Bone;
30 class KIN_Solver;
31 
33 {
39 };
40 
41 // "curve" solver type for Follow Curve
43 {
44 public:
50 };
51 
52 // NOT IMPLEMENTED! DO NOT USE!
54 {
55 public:
56  fpreal myTolerance; // tolerance on solution
57 };
58 
59 // Common parameters for inverse kinematics related solvers
61 {
62 public:
68 };
69 
70 // "constraint" solver type for Inverse Kinematics (IK) with Constraints
72 {
73 public:
74  fpreal myTolerance; // tolerance on solution
75 };
76 
77 // "inverse" solver type for Inverse Kinematics (IK)
79 {
80 public:
82  {
83  myResistStraight = true;
84  myTrackingThresholdFactor = 1e-03;
85  }
86 
89 };
90 
92 {
93 public:
94 
95  KIN_Chain();
96  KIN_Chain(const KIN_Chain &copy_from);
97  ~KIN_Chain();
98 
99  static const UT_XformOrder &getXformOrder() { return myXformOrder; }
100 
101  // These functions are for getting and setting bone information.
102  // All access to a chains bones must go through the chain so that we
103  // can make sure our solver is up to date. The separate updateBone,
104  // setBoneRotate, and setBoneRotates functions are only provided
105  // for convenience. Also notice that the Chain creator no longer
106  // has to actually create or remove any bones from the chain,
107  // only to set the number of bones.
108  int getNbones() const;
109  void setNbones(int bones);
110  const KIN_Bone &getBone(int index) const
111  { return myBones(index); }
112  void updateBone(int index, fpreal length, fpreal *rot,
113  fpreal damp, const UT_Matrix4R &xform,
114  const void *data);
115  void setBoneRotate(int index, int axis, fpreal r);
116  void setBoneRotates(int index, const fpreal *r);
117  void getBoneRotates(int index, fpreal *r) const;
118 
119  // Currently we are limited to one constraint per bone, so the
120  // interface to the bone constraints can be very simple. Any constraint
121  // that gets passed in here will be deleted by the bone.
122  void setConstraint( int index, fpreal rest[3],
123  fpreal xrange[2], fpreal yrange[2],
124  fpreal zrange[2], fpreal damp[3],
125  fpreal roll[3] );
126  fpreal constrain( int index, int axis,
127  fpreal angle, fpreal step ) const;
128 
129  // Utility functions for getting transform information for each bone
130  // or for just the chain end position.
131  void getEndPosition(UT_Vector3R &result) const;
132  void getBoneStates(UT_Matrix4R *xforms) const;
133  fpreal getLength() const;
134 
135  // Functions for setting solver information for the chain
136  // The solver types are same tokens as found in the "Solver Type" parameter
137  // of the InverseKin CHOP. See the comments for the KIN_*Parm classes above.
138  int solve(const char *type, const void *parms,
139  KIN_Chain &solution);
140 
141  // Essentially a copy operator
142  void copyFrom(const KIN_Chain &src);
143  void copySubChain(const KIN_Chain &src, int from, int to);
144 
145  int64 getMemoryUsage(bool inclusive) const
146  {
147  int64 mem = inclusive ? sizeof(*this) : 0;
148  mem += myBones.getMemoryUsage(false);
149  mem += mySolverType.getMemoryUsage(false);
150  return mem;
151  }
152 
153 private:
154  void initializeSolver();
155  void chainChanged(KIN_ChangeType type);
156 
157  UT_Array<KIN_Bone> myBones;
158  UT_UniquePtr<KIN_Solver> mySolver;
159  UT_StringHolder mySolverType;
160  const void *mySolverParms;
161  static const UT_XformOrder myXformOrder;
162 };
163 
165 void
167 {
168  auto &&bone = myBones(index);
169  if( !SYSisEqual( r[0], bone.getRotate(0) ) ||
170  !SYSisEqual( r[1], bone.getRotate(1) ) ||
171  !SYSisEqual( r[2], bone.getRotate(2) ) )
172  chainChanged(BONE_ROTATE);
173  bone.setRotates(r);
174 }
175 
177 void
179 {
180  getBone(index).getRotates(r);
181 }
182 
183 #endif
184 
KIN_ChangeType
Definition: KIN_Chain.h:32
void setBoneRotates(int index, const fpreal *r)
Definition: KIN_Chain.h:166
void getRotates(fpreal *r) const
Definition: KIN_Bone.h:37
int64 getMemoryUsage(bool inclusive) const
Definition: KIN_Chain.h:145
GA_API const UT_StringHolder rot
fpreal myTolerance
Definition: KIN_Chain.h:74
const KIN_Bone & getBone(int index) const
Definition: KIN_Chain.h:110
UT_Vector3R myTangent
Definition: KIN_Chain.h:47
long long int64
Definition: SYS_Types.h:106
fpreal myTwist
Definition: KIN_Chain.h:66
bool myOrientToNormalsFlag
Definition: KIN_Chain.h:46
State solve(const PositiveDefMatrix &A, const Vector< typename PositiveDefMatrix::ValueType > &b, Vector< typename PositiveDefMatrix::ValueType > &x, Preconditioner< typename PositiveDefMatrix::ValueType > &preconditioner, const State &termination=terminationDefaults< typename PositiveDefMatrix::ValueType >())
Solve Ax = b via the preconditioned conjugate gradient method.
fpreal myDampen
Definition: KIN_Chain.h:67
void getBoneRotates(int index, fpreal *r) const
Definition: KIN_Chain.h:178
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:480
GLboolean * data
Definition: glcorearb.h:130
fpreal myTolerance
Definition: KIN_Chain.h:56
double fpreal
Definition: SYS_Types.h:269
fpreal myTrackingThresholdFactor
Definition: KIN_Chain.h:87
UT_Vector3RArray myPoints
Definition: KIN_Chain.h:48
UT_Vector3R myTwistAffectorPos
Definition: KIN_Chain.h:64
GLuint index
Definition: glcorearb.h:785
#define KIN_API
Definition: KIN_API.h:10
static const UT_XformOrder & getXformOrder()
Definition: KIN_Chain.h:99
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
int myTwistAffectorFlag
Definition: KIN_Chain.h:65
GLboolean r
Definition: glcorearb.h:1221
UT_Vector3RArray myNormals
Definition: KIN_Chain.h:49
int myResistStraight
Definition: KIN_Chain.h:88
GA_API const UT_StringHolder rest
UT_Vector3R myEndAffectorPos
Definition: KIN_Chain.h:63
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
GLenum src
Definition: glcorearb.h:1792
bool myClosedFlag
Definition: KIN_Chain.h:45