TAPs 0.7.7.3
TAPsModelSurgicalSutureWithHeadNeedle.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsModelSurgicalSutureWithHeadNeedle.hpp
00003 ******************************************************************************/
00020 /******************************************************************************
00021 SUKITTI PUNAK   (07/22/2010)
00022 UPDATE          (01/20/2010)
00023 ******************************************************************************/
00024 #ifndef TAPs_MODEL_SURGICAL_SUTURE_WITH_HEAD_NEEDLE_HPP
00025 #define TAPs_MODEL_SURGICAL_SUTURE_WITH_HEAD_NEEDLE_HPP
00026 
00027 #include "../Model/RigidBodies/TAPsRigidBodyDynamics.hpp"
00028 #include "TAPsModelSurgicalSutureThread.hpp"
00029 
00030 // For collision detection
00031 #include "Support/TAPsModelSurgicalSutureWithHeadNeedle_CD.hpp"
00032 
00033 // For hiding the suture's head needle
00034 #ifdef  TAPs_ADD_MODEL_DISABLE_OPTIONS
00035 #endif//TAPs_ADD_MODEL_DISABLE_OPTIONS
00036 
00037 BEGIN_NAMESPACE_TAPs
00038 //=============================================================================
00039 template <typename T>
00040 class ModelSurgicalSutureWithHeadNeedle : public ModelSurgicalSutureThread<T> {
00041 //=============================================================================
00042 public:
00043 
00050     class CirclePath {
00051     public:
00052         
00053         CirclePath () {}
00054         ~CirclePath () {
00055             //if ( pCDSphereNode ) delete pCDSphereNode;
00056         }
00057 
00058         void Clear () { pListOfCDNodes.clear(); }
00059 
00060         T           Radius;
00061         Vector3<T>  Center;
00062         Vector3<T>  SharpPt;        
00063         Vector3<T>  EndPt;          
00064         T           CoverAngle;     
00065         T           LinkLenAngle;   
00066         Vector3<T>  NormalPlane;
00067         std::vector< Vector3<T> > InterpolatedPts;              
00068         unsigned int    IDOfFirstInterpolatedPtBeforeSharpPt;   
00069 
00070         //BVHNode<T> * pCDSphereNode;
00071 
00072         TransformationSupport<T> Trx;
00073         std::vector< BVHNode<T> * > pListOfCDNodes;
00074     };
00075 
00076     // Member Functions -------------------------------------------------------
00078     friend std::ostream & operator<< ( std::ostream &output, ModelSurgicalSutureWithHeadNeedle<T> const &obj )
00079     {
00080         output << obj.StrInfo();
00081         return output;
00082     }
00083     //-------------------------------------------------------------------------
00085     ModelSurgicalSutureWithHeadNeedle (
00086         int iNoLinks,               
00087         T tRadius,                  
00088         T tTotalLength,             
00089         T tTotalMass,               
00090         Vector3<T> & posOfVertex0 = Vector3<T>(),   
00091         ShapeInitializationParameters ShapeParameters = ShapeInitializationParameters(),    
00092         std::string * pHeadNeedleFile = NULL,   
00093         int iNoInteractionPts = 1,  
00094         T   tScaleForExtendedSharpPoint = 1     
00095 
00096 
00097     );
00099     //ModelSurgicalSutureWithHeadNeedle ( ModelSurgicalSutureWithHeadNeedle<T> const &orig );
00101     virtual ~ModelSurgicalSutureWithHeadNeedle ();
00102     //-------------------------------------------------------------------------
00104     virtual std::string StrInfo () const;
00105     //-------------------------------------------------------------------------
00106     // Overide functions from ModelElasticRod
00108     inline void SetGravitationalConstant ( T k )    { m_Parameters.Kgravity = -k; GetHeadNeedle().SetPhyPropGravitationalConstant( k ); }
00109 #ifdef  TAPs_ADD_RESTING_LEVEL_Y
00110 
00111     inline virtual void SetRestingLevel ( T y ) { ModelSurgicalSutureThread<T>::SetRestingLevel( y ); GetHeadNeedle().SetPhyPropRestingLevel( y ); }
00112 #endif//TAPs_ADD_RESTING_LEVEL_Y
00113     //-------------------------------------------------------------------------
00115     RigidBodyDynamics<T> const &    GetHeadNeedle () const  { return *m_pHeadNeedle; }
00117     RigidBodyDynamics<T> &          GetHeadNeedle ()        { return *m_pHeadNeedle; }
00119     OpenGL::HalfEdgeModel<T> const &    GetHeadNeedleAsHalfEdgeModel () const   { return *m_pHeadNeedle_asHalfEdgeModel; }
00121     OpenGL::HalfEdgeModel<T> &          GetHeadNeedleAsHalfEdgeModel ()         { return *m_pHeadNeedle_asHalfEdgeModel; }
00122     //-------------------------------------------------------------------------
00123 
00125     virtual void    Reset ();
00126 
00128     CirclePath const &  RefToHeadNeedleCirclePathCtrl () const  { return m_HeadNeedleCirclePath; }
00130     CirclePath &        RefToHeadNeedleCirclePathCtrl ()        { return m_HeadNeedleCirclePath; }
00131 
00144     virtual void    AdvanceSimulation ();
00145 
00158     virtual int FindTheClosestPointToPoint ( 
00159         Vector3<T> const & closeToPoint,    
00160         T distance_limit                    
00161     ) const;
00162 
00164     inline bool IsPointID_SutureThread ( int id ) const;
00165 
00167     inline bool IsPointID_HeadNeedle ( int id ) const;
00168 
00170     inline int GetTotalPoints() const   { return m_iTotalPoints; }
00171 
00173     inline Vector3<T> GetPositionOfHeadNeedleSharpPoint () const;
00174 
00176     inline Vector3<T> GetPositionOfPointNumberIonHeadNeedle ( unsigned int i ) const;
00177 
00179     inline void GetTwoPointsInWorldSpaceFormingLineExtendedFromHeadNeedleSharpPoint ( Vector3<T> & sharpPt, Vector3<T> & extendedPt ) const;
00180 
00182     inline void GetTwoInteractionPointPositionsInWorldSpace ( unsigned int i, unsigned int j, Vector3<T> & iPoint, Vector3<T> & jPoint ) const;
00183 
00185     inline std::vector< Vector3<T> > GetAllInteractionPointPositionsInWorldSpace () const;
00186 
00195     inline virtual bool PickAt (
00196         Vector3<T> const & closeToPoint,    
00197         T distance_limit,                   
00198         int & pickedID                      
00199     );
00200 
00204     inline virtual void PickPoint (
00205         int pickedID            
00206     );
00207 
00211     inline virtual void MovePickedPoint (
00212         int pickedID,           
00213         Vector3<T> & position   
00214     );
00215 
00219     inline virtual void UnpickPoint (
00220         int pickedID            
00221     );
00222 
00224     inline virtual void UnpickAllPoints ();
00225 
00226 #ifdef  TAPs_ADD_MODEL_DISABLE_OPTIONS
00227 
00228     void DisableHeadNeedle ()   { m_bDisableHeadNeedle = true; }
00230     void EnableHeadNeedle ()    { m_bDisableHeadNeedle = false; }
00231 
00233     bool IsHeadNeedleDisabled () const  { return m_bDisableHeadNeedle; }
00234 #endif//TAPs_ADD_MODEL_DISABLE_OPTIONS
00235 
00237     bool IsHeadNeedleBeingGrabbed ()    { return m_iHeadNeedleIPtSimFlagSetCount > 0; }
00238 
00240     bool IsHeadNeedlePositionLocked () const    { return GetHeadNeedle().IsPositionLocked(); }
00242     void LockHeadNeedlePosition ()  { GetHeadNeedle().LockPosition(); }
00244     void UnlockHeadNeedlePosition ()    { GetHeadNeedle().UnlockPosition(); }
00245 
00247     inline void SetHeadNeedlePosition ( Vector3<T> const & position );
00249     inline void SetHeadNeedleOrientation ( Quaternion<T> const & orientation );
00250 
00252     bool GetConstraintStatusOfInteractionPoint ( unsigned int i )
00253     { assert( i < m_vbIsConstrained.size() ); return m_vbIsConstrained[i]; }
00254 
00256     bool SetConstraintStatusOfInteractionPoint ( unsigned int i, bool b )
00257     { assert( i < m_vbIsConstrained.size() ); m_vbIsConstrained[i] = b; }
00258 
00259     //-------------------------------------------------------------------------
00260     // Collision Detection
00261 
00265     BVHTree<T> * GetBVHTree_HeadNeedle ()   { return m_CDUnit_HeadNeedle.GetBVHTree(); }
00266 
00268     inline void ClearAllExternalForcesAndTorques ();
00269 
00270     //-------------------------------------------------------------------------
00271     // Data Members -----------------------------------------------------------
00272 //=============================================================================
00273 protected:
00274     // Member Functions -------------------------------------------------------
00275 
00277     inline void CoupleHeadNeedleOrienAndPosWithSutureThreadOrienAndPos ();
00278 
00280     inline void SetSutureThreadOrienAndPosToFollowHeadNeedle ();
00281 
00283     void CleanUp ();
00284 
00291     bool CDRofThreadwithNeedle ();
00292 
00293     // Data Members -----------------------------------------------------------
00294     RigidBodyDynamics<T> *      m_pHeadNeedle;                  
00295     OpenGL::HalfEdgeModel<T> *  m_pHeadNeedle_asHalfEdgeModel;  
00296     InteractionPoint<T> *       m_pNeedleSharpPt;               
00297     InteractionPoint<T> *       m_pNeedleSutureConnectingPt;    
00298     int m_iTotalPoints; 
00299     int m_iHeadNeedleIPtSimFlagSetCount;    
00300 
00301     bool m_bHeadNeedlePositionLocked;   
00302 
00303     CirclePath  m_HeadNeedleCirclePath; 
00304 
00305     // For puncturing
00306     Vector3<T>  m_ExtendedHeadNeedleSharpPtPos; 
00307     std::vector<bool>   m_vbIsConstrained;      
00308 
00309     ModelSurgicalSutureWithHeadNeedle_CD<T> m_CDUnit_HeadNeedle;    
00310 
00311     bool    m_bDisableHeadNeedle;   
00312 //=============================================================================
00313 private:
00314     // Member Functions -------------------------------------------------------
00317     void FindAndAddNeedleSharpPtAndSutureConnectionPt ();
00318 
00320     void SetHeadNeedleInteractionPointsRadii ();
00321 
00323     void SetExtendedHeadNeedleSharpPt ( T scaleForExtendedSharpPoint );
00324 
00326     void InitHeadNeedleCirclePath ();
00327 
00328     // Data Members -----------------------------------------------------------
00329 //=============================================================================
00330 
00331 #if defined(__gl_h_) || defined(__GL_H__)
00332 public:
00334     virtual void Draw ();
00335 
00337     virtual void DrawOnlyHeadNeedle ();
00338 
00340     virtual void DrawOnlySutureThread ();
00341 
00343     virtual void DrawForDebugging ();
00344 
00346     virtual void DrawClue_GrabbingLocation ();
00347 
00349     virtual void DrawClue_CirclePath ();
00350 #endif
00351 
00352 //=============================================================================
00353 }; // END CLASS ModelSurgicalSutureWithHeadNeedle
00354 //=============================================================================
00355 END_NAMESPACE_TAPs
00356 //-----------------------------------------------------------------------------
00358 #include "TAPsModelSurgicalSutureWithHeadNeedle.cpp"
00359 
00361 // Include definition if TAPs_USE_EXPORT is not defined
00362 //#if !defined( TAPs_USE_EXPORT )
00363 //  #include "TAPsModelSurgicalSutureWithHeadNeedle.cpp"
00364 //#endif
00365 //-----------------------------------------------------------------------------
00366 #endif
00367 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00368 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines