HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #define KIN_CHAIN_ROT_ORDER UT_XformOrder::ZYX
30 
31 class KIN_Bone;
32 class KIN_Solver;
33 
35 {
41 };
42 
43 // "curve" solver type for Follow Curve
45 {
46 public:
52 };
53 
54 // NOT IMPLEMENTED! DO NOT USE!
56 {
57 public:
58  fpreal myTolerance; // tolerance on solution
59 };
60 
61 // Common parameters for inverse kinematics related solvers
63 {
64 public:
70 };
71 
72 // "constraint" solver type for Inverse Kinematics (IK) with Constraints
74 {
75 public:
76  fpreal myTolerance; // tolerance on solution
77 };
78 
79 // "inverse" solver type for Inverse Kinematics (IK)
81 {
82 public:
84  {
85  myResistStraight = true;
86  myTrackingThresholdFactor = 1e-03;
87  }
88 
91 };
92 
94 {
95 public:
96 
97  KIN_Chain();
98  KIN_Chain(int num_bones);
99  KIN_Chain(const KIN_Chain &copy_from);
100  ~KIN_Chain();
101 
102  static const UT_XformOrder &getXformOrder() { return myXformOrder; }
103 
104  // These functions are for getting and setting bone information.
105  // All access to a chains bones must go through the chain so that we
106  // can make sure our solver is up to date. The separate updateBone,
107  // setBoneRotate, and setBoneRotates functions are only provided
108  // for convenience. Also notice that the Chain creator no longer
109  // has to actually create or remove any bones from the chain,
110  // only to set the number of bones.
111  int getNbones() const;
112  void setNbones(int bones);
113  const KIN_Bone &getBone(int index) const
114  { return myBones(index); }
115  void updateBone(int index, fpreal length, fpreal *rot,
116  fpreal damp, const UT_Matrix4R &xform,
117  const void *data);
118  void setBoneRotate(int index, int axis, fpreal r);
119  void setBoneRotates(int index, const fpreal *r);
120  void setBoneRotates(int index, const fpreal *deg, const fpreal *rads);
121  void getBoneRotates(int index, fpreal *r) const;
122 
123  // Currently we are limited to one constraint per bone, so the
124  // interface to the bone constraints can be very simple. Any constraint
125  // that gets passed in here will be deleted by the bone.
126  void setConstraint( int index, fpreal rest[3],
127  fpreal xrange[2], fpreal yrange[2],
128  fpreal zrange[2], fpreal damp[3],
129  fpreal roll[3] );
130  fpreal constrain( int index, int axis,
131  fpreal angle, fpreal step ) const;
132 
133  // Utility functions for getting transform information for each bone
134  // or for just the chain end position.
135  void getEndPosition(UT_Vector3R &result) const;
136  void getBoneStates(UT_Matrix4R *xforms) const;
137  fpreal getLength() const;
138 
139  // Functions for setting solver information for the chain
140  // The solver types are same tokens as found in the "Solver Type" parameter
141  // of the InverseKin CHOP. See the comments for the KIN_*Parm classes above.
142  int solve(const UT_StringHolder &type, const void *parms,
143  KIN_Chain &solution);
144 
145  // Essentially a copy operator
146  void copyFrom(const KIN_Chain &src);
147  void copySubChain(const KIN_Chain &src, int from, int to);
148 
149  int64 getMemoryUsage(bool inclusive) const
150  {
151  int64 mem = inclusive ? sizeof(*this) : 0;
152  mem += myBones.getMemoryUsage(false);
153  mem += mySolverType.getMemoryUsage(false);
154  return mem;
155  }
156 
157  void updateCurrentSolverRestChain();
158 private:
159  void initializeSolver();
160  void chainChanged(KIN_ChangeType type);
161 
162  UT_Array<KIN_Bone> myBones;
163  UT_UniquePtr<KIN_Solver> mySolver;
164  UT_StringHolder mySolverType;
165  static const UT_XformOrder myXformOrder;
166 };
167 
169 void
171 {
172  auto &&bone = myBones(index);
173  if( mySolver )
174  {
175  if( !SYSisEqual( r[0], bone.getRotate(0) ) ||
176  !SYSisEqual( r[1], bone.getRotate(1) ) ||
177  !SYSisEqual( r[2], bone.getRotate(2) ) )
178  chainChanged(BONE_ROTATE);
179  }
180  bone.setRotates(r);
181 }
182 
184 void
185 KIN_Chain::setBoneRotates(int index, const fpreal *r, const fpreal *rads)
186 {
187  auto &&bone = myBones(index);
188  if( mySolver )
189  {
190  if( !SYSisEqual( r[0], bone.getRotate(0) ) ||
191  !SYSisEqual( r[1], bone.getRotate(1) ) ||
192  !SYSisEqual( r[2], bone.getRotate(2) ) )
193  chainChanged(BONE_ROTATE);
194  }
195  bone.setRotates(r,rads);
196 }
197 
199 void
201 {
202  getBone(index).getRotates(r);
203 }
204 
205 #endif
206 
KIN_ChangeType
Definition: KIN_Chain.h:34
void setBoneRotates(int index, const fpreal *r)
Definition: KIN_Chain.h:170
GLenum src
Definition: glew.h:2410
void getRotates(fpreal *r) const
Definition: KIN_Bone.h:40
GLuint index
Definition: glew.h:1814
int64 getMemoryUsage(bool inclusive) const
Definition: KIN_Chain.h:149
GA_API const UT_StringHolder rot
fpreal myTolerance
Definition: KIN_Chain.h:76
const KIN_Bone & getBone(int index) const
Definition: KIN_Chain.h:113
GLdouble angle
Definition: glew.h:9135
UT_Vector3R myTangent
Definition: KIN_Chain.h:49
long long int64
Definition: SYS_Types.h:111
fpreal myTwist
Definition: KIN_Chain.h:68
bool myOrientToNormalsFlag
Definition: KIN_Chain.h:48
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
fpreal myDampen
Definition: KIN_Chain.h:69
void getBoneRotates(int index, fpreal *r) const
Definition: KIN_Chain.h:200
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLuint GLsizei GLsizei * length
Definition: glew.h:1825
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
fpreal myTolerance
Definition: KIN_Chain.h:58
double fpreal
Definition: SYS_Types.h:276
fpreal myTrackingThresholdFactor
Definition: KIN_Chain.h:89
UT_Vector3RArray myPoints
Definition: KIN_Chain.h:50
UT_Vector3R myTwistAffectorPos
Definition: KIN_Chain.h:66
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
#define KIN_API
Definition: KIN_API.h:10
GU_API void solve(const GU_Detail &gdp_a, const GA_Range &pts_a, const GU_Detail &gdp_b, const GA_Range &pts_b, Method method, bool compute_distortion, Result &result)
static const UT_XformOrder & getXformOrder()
Definition: KIN_Chain.h:102
GLuint64EXT * result
Definition: glew.h:14007
int myTwistAffectorFlag
Definition: KIN_Chain.h:67
UT_Vector3RArray myNormals
Definition: KIN_Chain.h:51
int myResistStraight
Definition: KIN_Chain.h:90
GA_API const UT_StringHolder rest
UT_Vector3R myEndAffectorPos
Definition: KIN_Chain.h:65
bool myClosedFlag
Definition: KIN_Chain.h:47