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