iiksys.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: IIKSys.h
00004 
00005     DESCRIPTION:  Interfaces into IK sub-system classes/functions. 
00006 
00007     CREATED BY: Jianmin Zhao
00008 
00009     HISTORY: created 3 April 2000
00010 
00011  *> Copyright (c) 1994, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 
00016 #include "maxheap.h"
00017 #include "iFnPub.h"
00018 #include "INodeTab.h"
00019 
00020 // Class ids
00021 #define IKCONTROL_CLASS_ID Class_ID(0xe6f5815, 0x717f99a4)
00022 #define IKCHAINCONTROL_CLASS_ID Class_ID(0x78724378, 0x8a4fd9)
00023 #define GET_IKCHAIN_CD (GetCOREInterface()->GetDllDir().ClassDir().FindClass(CTRL_MATRIX3_CLASS_ID, IKCHAINCONTROL_CLASS_ID))
00024 
00025 #define IK_FP_INTERFACE_ID Interface_ID(0x5b734601, 0x7c7c7ece)
00026 #define IKCHAIN_FP_INTERFACE_ID Interface_ID(0x5a5e7cbe, 0x55367776)
00027 
00028 #define GET_IK_OPS_INTERFACE ((IKCmdOps*)GetCOREInterface(IK_FP_INTERFACE_ID))
00029 #define GET_IKCHAIN_FP_INTERFACE ((IKChainActions*)GET_IKCHAIN_CD->GetInterface(IKCHAIN_FP_INTERFACE_ID))
00030 
00039 class IKCmdOps : public FPStaticInterface {
00040 public:
00054   virtual INode* CreateIKChain(INode* start, INode* end, const MCHAR* solver) =0;
00057   virtual int SolverCount() const =0;
00061   virtual MSTR SolverName(int) const =0;
00065   virtual MSTR SolverUIName(int) const =0;
00066 };
00067 
00068 // class IKCmdOpsEx
00070 
00076 class IKCmdOpsEx : public IKCmdOps {
00077 public:
00080     virtual void SuspendLinkNotify() = 0;
00083     virtual void ResumeLinkNotify() = 0;
00086     virtual bool IsLinkNotifySuspended() const = 0;
00087 };
00088 
00089 #define GET_IKEX_OPS_INTERFACE ((IKCmdOpsEx*)GetCOREInterface(IK_FP_INTERFACE_ID))
00090 
00111 class IKChainActions : public FPStaticInterface {
00112 public:
00116   virtual FPStatus SnapAction() =0;
00121   virtual FPStatus IKSnapAction() =0;
00126   virtual FPStatus FKSnapAction() =0;
00127   virtual BOOL IsSnapEnabled() =0;
00132   virtual FPStatus ToggleEnabled() =0;
00137   virtual FPStatus SetPreferredAngles() =0;
00140   virtual FPStatus AssumePreferredAngles() =0;
00141 };
00142 
00143 namespace IKSys {
00144   class ZeroPlaneMap;
00145 }
00146 //
00147 // IIKChainControl
00148 //
00149 class IKSolver;
00161 class IIKChainControl: public MaxHeapOperators {
00162 public:
00163   // Reference index:
00164   //
00165   enum {
00166     kPBlockRef = 0, // ParamBlock
00167     kGoalTMRef,     // Matrix3 controller
00168     kEndJointRef,   // INode
00169     kEnableRef,     // Bool (float) controller
00170     kStartJointRef, // INode
00171     kOwningNodeRef, // Reference on a NodeMonitor that holds an indirect reference on the owning Node
00172     kLastRef
00173   };
00174   // Parameter block index:
00175   //
00176   enum {
00177     kParamBlock,
00178     kNumParamBlocks
00179   };
00180   // Paramter index of parameters in param-block of index kParamBlock:
00181   //
00182   enum {
00183     kStartJoint,    // INode, referenced by kStartJointRef
00184     kEndJoint,      // INode, referenced by kEndJointRef
00185     kSolverName,    // String
00186     kAutoEnable,    // BOOL
00187     kSwivel,        // Angle
00188     kPosThresh,     // Float
00189     kRotThresh,     // Float
00190     kIteration,     // Integer
00191     kEEDisplay,     // BOOL
00192     kEESize,        // Float
00193     kGoalDisplay,   // BOOL
00194     kGoalSize,      // Float
00195     kVHDisplay,     // BOOL
00196     kVHSize,        // Float
00197     kVHLength,      // Float
00198     kSolverDisplay, // BOOL
00199     kAutoSnap,      // BOOL
00200     kVHUseTarget,   // BOOL
00201     kVHTarget,      // INode
00202     kSAParent,      // RadioBtn_Index
00203     kLastHIIKParam
00204   };
00205 
00210   enum SplineIKParams {
00211       // Paramter ids (of PB2) of Spline IK, i.e. that on which
00212       // GoalInterfaceID() == IKSys::kSplineIKGoalID.
00213       //
00214       // Following parameter ids are inherited from the HIIK 
00215       // kStartJoint,
00216       // kEndJoint,
00217       // kSolverName,
00218       // kAutoEnable,
00219       // kEEDisplay,
00220       // kEESize,
00221       // kGoalDisplay,
00222       // kGoalSize,
00223       // kSolverDisplay,
00224       // kAutoSnap,
00225       //
00226       // Spline IK paramters start here:
00229       kPickShape = kLastHIIKParam,  
00230           kTwistHStartDisplay,      
00231           kTwistHEndDisplay,        
00232           kTwistHStartSize,         
00233           kTwistHEndSize,           
00234           kTwistHStartLength,       
00235           kTwistHEndLength,         
00236           kTwistHStartAngle,        
00237           kTwistHEndAngle,          
00238 //        kTwistHStartTarget,
00239 //        kTwistHEndTarget,
00240 //        kTwistHUseStartTarget,
00241 //        kTwistHUseEndTarget,
00242           
00243 //parameters below are in the first pop-up dialog box "Spline IK SOlver"
00251           kAutoSplineCreate,        
00252 
00253           kSplineTypeChoice,        
00254 
00259           kSplineKnotCount,         
00260 
00264           kCreateHelper,            
00265 
00272           kLinktoRootNode,          
00273           kHelpersize,              
00274           kHelperCentermarker,      
00275           kHelperAxisTripod,        
00276           kHelperCross,             
00277           kHelperBox,               
00278           kHelperScreensize,        
00279           kHelperDrawontop,         
00280           kUpnode,                  
00281           kUseUpnode,               
00282       kLastSplineIKParam            
00283   };
00285 
00286   enum SAParentSpace {
00287     kSAInGoal,
00288     kSAInStartJoint
00289   };
00290 
00291 
00292   //Spline IK Specific methods.
00293   //CAUTION: The following methods, although meaningful only to 
00294   // SplineIK solver are also accessible to HIIK and IKLimb solvers. 
00295   // We have to implement them for these latter IKSolvers, with some
00296   // reasonable return values as return, so that they don't crash.
00297 
00298   virtual float     TwistHStartAngle(TimeValue, Interval&)=0;
00299   virtual float     TwistHEndAngle(TimeValue, Interval&)=0;
00300 
00301   // IK chain delimiters
00305   virtual INode*        StartJoint() const =0;
00308   virtual INode*        EndJoint() const =0;
00311   virtual INode*        GetNode() const =0;
00312 
00313   // Vector Handle
00314   // InitPlane/InitEEAxis are the normal and End Effector Axis at the
00315   // initial pose. They are represented in the parent space.
00316   // ChainNormal is the InitPlane represented in the object space:
00317   // InitPlane() == ChainNormal * StartJoint()->InittialRotation()
00336   virtual Point3        ChainNormal(TimeValue t, Interval& valid) =0;
00338   virtual Point3        InitPlane(TimeValue t) =0;
00340   virtual Point3        InitEEAxis(TimeValue t) =0;
00342   virtual float         InitChainLength(TimeValue t) =0;
00346   virtual float         SwivelAngle(TimeValue, Interval&)=0;
00352   virtual const IKSys::ZeroPlaneMap*
00353                         DefaultZeroPlaneMap(TimeValue t) =0;
00357   virtual SAParentSpace SwivelAngleParent() const =0;
00358   
00359   // Solver
00362   virtual IKSolver*     Solver() const =0;
00363 
00366   virtual bool          SolverEnabled(TimeValue, Interval* =0)=0;
00371   virtual bool          CanAutoEnable() const =0;
00376   virtual bool          AutoEnableSet() const =0;
00380   virtual bool          Valid() const =0;
00381 
00382   // Return HIIKGOAL_ID or SPLINEIKGOAL_IK
00388   virtual Interface_ID  GoalInterfaceID() const =0;
00392   virtual BaseInterface* AcquireGoal(TimeValue, Interval&, const Matrix3& parent_of_start_joint) =0;
00393 };
00394 
00395 namespace IKSys {
00396   enum DofAxis {
00397     TransX = 0, TransY, TransZ,
00398     RotX, RotY, RotZ,
00399     DofX = 0, DofY, DofZ
00400   };
00401   enum JointType {
00402     SlidingJoint,
00403     RotationalJoint
00404   };
00405   struct DofSet : public MaxHeapOperators {
00406     DofSet() : bits(0) {}
00407     DofSet(const DofSet& src) : bits(src.bits) {}
00408     void Add(DofAxis dn) { bits |= (1 << dn); }
00409     void Clear(DofAxis dn) { bits &= ~(unsigned(1 << dn)); }
00410     int Include(DofAxis dn) const { return bits & (1 << dn); }
00411     int Count() const;
00412     unsigned bits;
00413   };
00414   inline int DofSet::Count() const
00415   {
00416    unsigned int ret;
00417    unsigned int b, i;
00418     for (b = bits, ret = 0, i = TransX; i <= RotZ; ++i) {
00419       if (b == 0) break;
00420       else if (b & 01u) {
00421         ret++;
00422       }
00423       b = b >> 1;
00424     }
00425     return ret;
00426   }
00427 }; // namespace IKSys
00428 //
00429 // IIKControl
00430 //
00441 class IIKControl: public MaxHeapOperators {
00442 public:
00443   typedef IKSys::DofAxis DofAxis;
00444   typedef IKSys::JointType JointType;
00445   typedef IKSys::DofSet DofSet;
00446 
00447   //Queries
00455   virtual bool      DofActive(DofAxis) const =0;
00460   virtual DofSet    ActiveTrans() const =0;
00465   virtual DofSet    ActiveRot() const =0;
00472   virtual DofSet    ActiveDofs() const =0;
00481   virtual INodeTab  IKChains(JointType) const =0;
00489   virtual bool      DofLowerLimited(DofAxis) const =0;
00497   virtual bool      DofUpperLimited(DofAxis) const =0;
00506   virtual Point2    DofLimits(DofAxis) const =0;
00510   virtual Point3    TransLowerLimits() const =0;
00514   virtual Point3    TransUpperLimits() const =0;
00517   virtual Point3    RotLowerLimits() const =0;
00520   virtual Point3    RotUpperLimits() const =0;
00533   virtual bool      IKBound(TimeValue t, JointType jt)=0;
00537   virtual Control*  FKSubController() const =0;
00540   virtual INode*    GetNode() const =0;
00549   virtual Point3    PrefPosition(TimeValue t, Interval& validityInterval) =0;
00558   virtual Point3    PrefRotation(TimeValue t, Interval& validityInterval) =0;
00559 
00560   // DOF values
00561   virtual Point3    TransValues(TimeValue, Interval* =0)=0;
00562   virtual Point3    RotValues(TimeValue, Interval* =0)=0;
00570   virtual void      AssignTrans(const Point3&, const Interval&)=0;
00578   virtual void      AssignRot(const Point3&, const Interval&)=0;
00587   virtual void      AssignActiveTrans(const Point3&, const Interval&)=0;
00596   virtual void      AssignActiveRot(const Point3&, const Interval&)=0;
00609   virtual void      AssignActiveTrans(const DofSet&, const float[],
00610                                       const Interval&)=0;
00623   virtual void      AssignActiveRot(const DofSet&, const float[],
00624                                     const Interval&)=0;
00630   virtual void      SetTransValid(const Interval& valid) =0;
00636   virtual void      SetRotValid(const Interval& valid) =0;
00642   virtual void      SetTRValid(const Interval& valid) =0;
00651   virtual void      SetPrefTrans(const Point3& val, TimeValue t =0) =0;
00660   virtual void      SetPrefRot(const Point3& val, TimeValue t =0) =0;
00671   virtual void      SetPrefTR(const Point3& trans, const Point3& rot,
00672                               TimeValue t =0) =0;
00673 };