TAPs 0.7.7.3
TAPsModelSutureMath.hpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002 TAPsModelSutureMath.hpp
00003 
00004 A two-headed needle suture
00005 
00006 SUKITTI PUNAK   (01/30/2006)
00007 UPDATE          (06/15/2006)
00008 *******************************************************************************/
00009 #ifndef TAPs_SUTURE_MATH_MODEL_HPP
00010 #define TAPs_SUTURE_MATH_MODEL_HPP
00011 
00012 #include <TAPs/OpenGLModelFromFile/TAPsReadModels.hpp>
00013 #include "TAPsModelStrandMath.hpp"
00014 
00015 BEGIN_NAMESPACE_TAPs__OpenGL
00016 //==============================================================================
00017 template <typename T>
00018 class ModelSutureMath : public /*virtual*/ ModelStrandMath<T> {
00019     //-------------------------------------------------------------------------
00020     // (Friend Fn) put it through ostream
00021     friend std::ostream & operator<< ( std::ostream &output, ModelSutureMath<T> const &o )
00022     {
00023         output  << "\n======================\n"
00024                 <<   "TAPs::ModelSutureMath<"
00025                 << typeid(T).name() << "> Class:\n"
00026                 <<   "======================\n";
00027         //----------------------------------------------------------------
00028         output  << "\n# of Links " << o.m_iNoLinks
00029                 << "\nEach link has length " << o.m_tLinkLength 
00030                 << " and weight " << o.m_tPointWeight << "\n";
00031         return output;
00032     }
00033 //------------------------------------------------------------------------------
00034 // Member Functions ------------------------------------------------------------
00035 public:
00036     //-------------------------------------------------------------------------
00037     // Constructor(s)
00038     ModelSutureMath ();
00039     ModelSutureMath ( 
00040         int iNoLinks,   // # of links/segments
00041         T tLength,      // the strand length
00042         T tWeight,      // the strand weight
00043         Vector3<T> & posOfVertex0 = Vector3<T>(),   // position of the 1st node
00044         T tRadius = 0.05
00045     );
00046     ModelSutureMath ( 
00047         int iNoLinks,   // # of links/segments
00048         T tLength,      // the strand length
00049         T tWeight,      // the strand weight
00050         Vector3<T> & posOfVertex0,  // position of the 1st node
00051         T tRadius,
00052         const char * needle1    // Needle Type (read from file)
00053     );
00054     ModelSutureMath ( 
00055         int iNoLinks,   // # of links/segments
00056         T tLength,      // the strand length
00057         T tWeight,      // the strand weight
00058         Vector3<T> & posOfVertex0,  // position of the 1st node
00059         T tRadius,
00060         T tKRatioOfStretchingAllowed,
00061         T tKRatioOfCompressionAllowed,
00062         T tKStretching,
00063         T tKBending,
00064         T tKTwisting,
00065         T tKFriction,
00066         T tKContact,
00067         T tKGravity,
00068         const char * needle1    // Needle Type (read from file)
00069     );
00070     //-------------------------------------------------------------------------
00071     // Destructor
00072     virtual ~ModelSutureMath ();
00073     //-------------------------------------------------------------------------
00074     //-------------------------------------------------------------------------
00075     // Abstract Virtual Fn(s) from Model<T>
00076     virtual void Initialize () {};
00077     //-------------------------------------------------------------------------
00078     // Abstract Virtual Fn(s) from ColDetSupport<T>
00079     // Collision Detection Fn(s)
00080     virtual void CalBoundingAABB ()         {};
00081     virtual void CalBoundingEllipsoid ()    {};
00082     virtual void CalBoundingSphere ()       {};
00083     //-------------------------------------------------------------------------
00084     // Get/Set Fn(s)
00085     inline bool GetFixStatusOfPtNo ( int i ) 
00086     {
00087         if ( 0 <= i && i <= m_iNoLinks ) {
00088             return ModelStrandMath<T>::GetFixStatusOfPtNo( i );
00089         }
00090         else {
00091             return false;
00092         }
00093     }
00094     inline void SetFixStatusOfPtNo ( int i, bool b )
00095     {
00096         if ( 0 <= i && i <= m_iNoLinks ) {
00097             ModelStrandMath<T>::SetFixStatusOfPtNo( i, b );
00098             //m_prIsFixed[i] = b;
00099         }
00100         else {
00101             ModelStrandMath<T>::SetFixStatusOfPtNo( 0, b );
00102             //m_prIsFixed[0] = b;   // connected to head needle
00103         }
00104     }
00105     inline void ToggleFixStatusOfPtNo ( int i )
00106     {
00107         if ( 0 <= i && i <= m_iNoLinks ) {
00108             ModelStrandMath<T>::ToggleFixStatusOfPtNo( i );
00109             //m_prIsFixed[i] = !m_prIsFixed[i];
00110         }
00111         else    {};
00112     };
00113     inline virtual int  GetNumberOfLinks () 
00114         { return m_iNoLinks + m_iNoPickPts; }
00115     inline virtual int  GetNumberOfLinksWithoutHeadNeedle ()    
00116         { return m_iNoLinks; }
00117     inline virtual Vector3<T> GetPointPosition ( int i ) const;
00118     inline virtual void SetPointPosition ( 
00119         int i, const Vector3<T> & position );
00120     inline virtual void SetPointPosition ( 
00121         int i, const Vector3<T> & position, Matrix3x3<T> & rotation, 
00122         //T tMoveDistanceLimit = 100, 
00123         MultiBoundingVolume<T> const * const pMBV = NULL, 
00124         TransformationSupport<T> const * const pTransform = NULL
00125     );
00126 protected:
00127     inline virtual Vector3<T> GetNeedlesPosition ( int i ) const;
00128     inline virtual void SetNeedlesPosition ( 
00129         int i, const Vector3<T> & position, Matrix3x3<T> & rotation );
00130     //----------------------------------------------------------------
00131     // User adjustable parameters
00132     //----------------------------------------------------------------
00133     // Collision Detection
00134     //----------------------------------------------------------------
00135     //==========================================================================
00136     // Helper Fn(s)
00137     //================================================================
00138     // For Simulation
00139     //----------------------------------------------------------------
00140 protected:
00141     //----------------------------------------------------------
00142     // REMARK:  DxDt has to be static so that we can pass it to 
00143     // ODESolver Fn.
00144     // But we don't want StateToArray and ArrayToState be static.
00145     // Therefore, we need to pass userData, i.e. this pointer
00146     // as a void pointer.
00147     static bool DxDt (  
00148         T dt,                           // i/p: time step
00149         Simulation::VectorSet<T> &x,    // i/p: array  x = {pos, vel}
00150         Simulation::VectorSet<T> &xdot, // o/p: array xdot = {vel, accel}
00151         void *userData                  // o/p: array of user data
00152     );
00153     //----------------------------------------------------------
00154     void StateToArray ( T *dst );       // copy Suture states to dst array
00155     void ArrayToState ( T *src );       // copy src array to Suture states
00156     void DdtStateToArray ( T *xdot, T dt ); // copy d/dt Suture states to dst (xdot) array
00157     //void ClearForces ();  // clear (all) forces (and maybe velocities too)
00158 public:
00159     void AdvanceSimulation ( T tCurrent, T tNext );
00160     void AdvanceSimulation ( Simulation::SimClock<T> & simClock );
00161     //----------------------------------------------------------------
00162     /*
00163     // Move the vertex # i by vector u
00164     void MoveVertexNo ( int i, Vector3<T> & u );
00165     //----------------------------------------------------------------
00166     // Twist the vertex i for deg degrees
00167     void TwistVertexNo ( int i, Real deg );
00168     //----------------------------------------------------------------
00169     // Move and Twist the vertex # i by vector u and deg respectively
00170     void MoveAndTwistVertexNo ( int i, Vector3<T> & u, Real deg );
00171     */
00172     //----------------------------------------------------------------
00173     // Collision Detection
00174     //virtual bool TestOverlapWith ( BVHTree<T> const * const that );
00175     //----------------------------------------------------------------
00176     // Collision Detection For Needle(s)
00177     BVHTree<T> * GetBVHTreeNeedleLeft () // use sphere node for BVHTree
00178         { return m_pNeedleLeft->GetBVHTree(); }
00179     //BVHTree<T> * GetBVHTreeNeedleRight () // use sphere node for BVHTree
00180     //  { return m_pNeedleRight->GetBVHTree(); }
00181 protected:
00182     //----------------------------------------------------------------
00183     // Collision Detection For Needle(s)
00184     void RecordNeedleBVHNodeCenters ();
00185     void RestoreNeedleBVHNodeCenters ();
00186     void RotateNeedleBVHNodeCenters ();
00187 //==============================================================================
00188 // Data Members ----------------------------------------------------------------
00189 protected:
00190     //----------------------------------------------------------------
00191     // For Needles Positions
00192     // Use Sphere Bounding Volume Center for the positions of pick points
00193     // With the current needle model, recommend to use level 2 (4 spheres) 
00194     // thru level 4 (16 spheres).  We use level 4.
00195     int             m_iLevel;       // level number
00196     int             m_iNoPickPts;   // # of Pick Points (n * 2) for 2 needles
00197                                     // even number for left  needle
00198                                     // odd  number for right needle
00199     Vector3<T> **   m_prPickPts;    // pointer to pick points
00200     bool *          m_prbIsSharp;   // identify whether the (pickable) needle pt is sharp
00201     int             m_iNeedleSharpPt;   // Needle sharp point is one of the pickable points
00202                                         // where m_prbIsSharp must be true
00203     //std::vector<int>  m_iSharpPts;    // sharp pts of needle
00204     //Vector3<T>        m_vTransForLeftNeedle;      // translation matrix for left needle
00205     //Matrix3x3<T>  m_mRotMatForLeftNeedle;     // rotation matrix for left needle
00206 public:
00207     TransformationSupport<T> &  GetLeftNeedleTransform()    { return m_pNeedleLeft->GetTransform(); }
00208     //----------------------------------------------------------------
00209 protected:
00210     OpenGLHalfEdgeModel<T> *    m_pNeedleLeft;
00211     //OpenGLHalfEdgeModel<T> *  m_pNeedleRight;
00212 protected:
00213     void InitNeedles ();
00214     void InitNeedles ( const char * needle1 );
00215     void InitNeedlesPickPts ();
00216     void InitNeedlesPickPts ( BVHNode<T> ** node, int level );
00217     void SetNeedlesPickPts ();
00218     void InitNeedlesSharpPts ();
00219     //*/
00220     //----------------------------------------------------------------
00221     // Material Properties
00222     /*
00223     T               m_tKstretch;    // stretch allowed
00224     T               m_tKstiff;      // anti-bending
00225     T               m_tKfriction;   // surface friction/sticky
00226     T               m_tKfollow;     // how much follower follows leader
00227                                     // 0 means follow 100%
00228                                     // 1 means rigid follower
00229     //*/
00230     /*
00231     //----------------------------------------------------------------
00232     // Shape memory by cubic Bezier control points
00233     // -------------------------------------------
00234     // p^i_0, p^i_1, p^i_2, p^i_3 = p^(i+1)_0, p^(i+1)_1, ... 
00235     // Contain points that define the strand shape
00236     //
00237     //                             P7_________P8
00238     //                              /         \
00239     //     P1________P2            /           \ 
00240     //      /        \          P6/             \P9
00241     //     /          \P3        /               \
00242     //    /            \________/                 \
00243     //   /             P4      P5                  \_________...
00244     //  P0                                        P10
00245     std::set< Vector3<T> > m_setvD3BezierMemShape;
00246     std::set< int > m_setiD3BezierMemShape;
00247     void InitShapeMemory ();
00248     void ConformToShapeMemory ();
00249     //*/
00250 protected:
00251     //----------------------------------------------------------------
00252     // Shape Memory
00253 public:
00254     void SetupShape ( Vector3<T> startPosition );
00255 protected:
00256     //================================================================
00257     // For simulation
00258     //----------------------------------------------------------------
00259     Simulation::ODESolver<T> *  m_prODESolver;  // ODE solver
00260     Simulation::VectorSet<T> x0;                // #m_iStateSize
00261     Simulation::VectorSet<T> xEnd;              // #m_iStateSize
00262     int m_iStateSize;   // (#Links + 1) * 6
00263             // where 6 = 3 positions + 3 velocities (for x,y,z)
00264     int m_iLimitStepCount;
00265     //----------------------------------------------------------------
00266     // Physical Forces
00267     struct StructForce {
00268         Vector3<T> gravity;     // gravity force
00269         //Vector3<T> antiBending;   // anti-bending force
00270     };
00271     //----------------------------------------------------------------
00272     // Collision Detection
00273     struct CollisionNodePairID {
00274         int id1;
00275         int id2;
00276     };
00277 
00278 public:
00279     T GetKfollow () { return 1; }
00280     T GetKstiff () { return 1; }
00281     void SetKfollow ( T v ) {}
00282     void SetKstiff ( T v ) {}
00283 protected:
00284 //------------------------------------------------------------------------------
00285 }; // CLASS END: ModelSutureMath  **************************************************
00286 //==============================================================================
00287 END_NAMESPACE_TAPs__OpenGL
00288 //------------------------------------------------------------------------------
00289 // Include definition if TAPs_USE_EXPORT is not defined
00290 //#if !defined( TAPs_USE_EXPORT )
00291     #include "TAPsModelSutureMath.cpp"
00292 //#endif
00293 //------------------------------------------------------------------------------
00294 #endif
00295 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00296 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines