![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsSpringRef.hpp 00003 00004 SpringRef class is a class for creating a spring connecting between two 00005 ParticleRef objects (refer to TAPsParticleRef.hpp). 00006 It needs to know (ref) the address of the particles. 00007 00008 SUKITTI PUNAK (02/24/2006) 00009 UPDATE (03/01/2006) 00010 ******************************************************************************/ 00011 #ifndef TAPs_SPRING_REF_HPP 00012 #define TAPs_SPRING_REF_HPP 00013 00014 #include "TAPsParticleRef.hpp" 00015 00016 BEGIN_NAMESPACE_TAPs 00017 template <typename T> 00018 class SpringRef { 00019 //============================================================================= 00020 //------------------------------------------------------------------------- 00021 // put it through ostream 00022 friend std::ostream &operator<< ( std::ostream &output, SpringRef<T> const &S ) 00023 { 00024 output << "Spring<" << typeid(T).name() << "> ==> " 00025 << "\n -------START--SPRING_VERTEX--INFO-------" 00026 << "\n Particle#1: " << *(S.m_refP1) 00027 << "\n Particle#2: " << *(S.m_refP2) 00028 << "\n K Constant: " << S.m_tK 00029 << "\n D Damping: " << S.m_tD 00030 << "\n L Length: " << S.m_tL 00031 << "\n Force#1: " << S.GetForce1() 00032 << "\n Force#2: " << S.GetForce2() 00033 << "\n Current Length: " << S.GetCurrentLength() 00034 << "\n --------END--SPRING_VERTEX--INFO--------\n"; 00035 return output; 00036 } 00037 //----------------------------------------------------------------------------- 00038 private: 00039 // Data Members ======================================================== 00040 ParticleRef<T> * m_refP1; // reference to connected ParticleRef #1 00041 ParticleRef<T> * m_refP2; // reference to connected ParticleRef #2 00042 T m_tK; // tensile spring constant (K) 00043 T m_tD; // damping factor (D) 00044 T m_tL; // rest length of spring (L) 00045 //------------------------------------------------------ 00046 int m_iNumHops; // number of hops on mesh 00047 //------------------------------------------------------------------------- 00048 public: 00049 // Member Functions ==================================================== 00050 SpringRef ( // The rest length is calculated 00051 ParticleRef<T> & P1, 00052 ParticleRef<T> & P2, 00053 T k, T d, 00054 int hops = 1 ); // Constructor 00055 //---------------------------------------------------------------- 00056 SpringRef ( // The rest length is given 00057 ParticleRef<T> & P1, 00058 ParticleRef<T> & P2, 00059 T k, T d, T l, 00060 int hops = 1 ); // Constructor 00061 //---------------------------------------------------------------- 00062 ~SpringRef (); // Destructor 00063 //------------------------------------------------------------------------- 00064 // Calculate and Return the (Internal) Force of a Spring 00065 Vector3<T> GetForce1 () const; 00066 Vector3<T> GetForce2 () const; 00067 void GetForce ( Vector3<T> & F1, Vector3<T> & F2 ) const; 00068 void CalAndSetForce (); 00069 //------------------------------------------------------------------------- 00070 // Get/Set Functions 00071 // REMARK: No const for Particle<T> & and const after the get fns 00072 // so that the return ref can be modified. 00073 inline ParticleRef<T> & GetParticleOne (); 00074 inline ParticleRef<T> & GetParticleTwo (); 00075 inline ParticleRef<T> const & GetParticleOne () const; 00076 inline ParticleRef<T> const & GetParticleTwo () const; 00077 inline T GetConstantK () const; 00078 inline T GetDampingD () const; 00079 inline T GetRestLengthL () const; 00080 inline T GetCurrentLength () const; 00081 inline void SetConstantK ( T Ks ); 00082 inline void SetDampingD ( T Kd ); 00083 inline void SetRestLengthL ( T length ); 00084 //------------------------------------------------------------------------- 00085 //========================================================================== 00086 // Create Spring Connections for Mesh (Vertex, XVertex, HalfEdge) 00087 // All O/P pointers must be null pointers! 00088 // To avoid memory leak, the O/P pointers must be "delete []" by user. 00089 //-------------------------------------------- 00090 // Create Spring Connections for Mesh Vertex 00091 static void SpringsCreation ( 00092 Vertex<T> * meshVertex, // I/P: Mesh Vertex 00093 int * vertexNo, // O/P: vertex# associates Mesh Vertex w/ Spring# 00094 ParticleRef<T> * particleNo, // O/P: particle# 00095 T mass, // I/P: mass for each particle 00096 SpringRef<T> * springNo, // O/P: Spring# 00097 T Ks, T Kd, // I/P: Spring Stiffness and Damping Constant 00098 int hopDistance = 1 // I/P: Number of distance/rigidity for spring connection 00099 ); 00100 //-------------------------------------------- 00101 // Create Spring Connections for Mesh XVertex 00102 static void SpringsCreation ( 00103 XVertex<T> * meshVertex, // I/P: Mesh XVertex 00104 int * vertexNo, // O/P: vertex# associates Mesh XVertex w/ Spring# 00105 ParticleRef<T> * particleNo, // O/P: particle# 00106 T mass, // I/P: mass for each particle 00107 SpringRef<T> * springNo, // O/P: Spring# 00108 T Ks, T Kd, // I/P: Spring Stiffness and Damping Constant 00109 int hopDistance = 1 // I/P: Number of distance/rigidity for spring connection 00110 ); 00111 //-------------------------------------------- 00112 // Create Spring Connections for Mesh HEVertex 00113 static void SpringsCreation ( 00114 HEVertexList<T> * meshVertex, // I/P: Mesh HEVertex 00115 std::list<int> & vertexNo, // O/P: vertex# associates Mesh HEVertex w/ Spring# 00116 std::list< ParticleRef<T> > & particleList, // O/P: Particle List 00117 T mass, // I/P: mass for each particle 00118 std::list< SpringRef<T> > & springNo, // O/P: Spring List 00119 T Ks, T Kd, // I/P: Spring Stiffness and Damping Constant 00120 int hopDistance = 1 // I/P: Number of distance/rigidity for spring connection 00121 ); 00122 private: 00123 //static void SpringCreation 00124 //------------------------------------------------------------------------- 00125 private: 00126 // Member Functions ------------------------------------------------------- 00127 // Prohibited Functions =================================================== 00128 // Since a spring refers to two particles, therefore 00129 // Copy Constructor and Assignment Operator are prohibited. 00130 SpringRef<T> const & operator= ( SpringRef<T> const &S ) // assignment operator 00131 { 00132 std::cerr << "SpringRef<T> operator= must not be used!\n"; 00133 exit( 1 ); 00134 } 00135 // Data Members ----------------------------------------------------------- 00136 //========================================================================= 00137 #if defined(__gl_h_) || defined(__GL_H__) 00138 public: 00139 // DrawByOpenGL 00140 virtual void DrawByOpenGL () const; 00141 virtual inline void DrawByOpenGL ( int hopNumber ) const; 00142 virtual inline void DrawByOpenGL ( int startHopNumber, int endHopNumber ) const; 00143 #endif 00144 //------------------------------------------------------------------------- 00145 }; // END CLASS SpringRef 00146 //============================================================================= 00147 END_NAMESPACE_TAPs 00148 //----------------------------------------------------------------------------- 00149 // Include definition if TAPs_USE_EXPORT is not defined 00150 //#if !defined( TAPs_USE_EXPORT ) 00151 #include "TAPsSpringRef.cpp" 00152 //#endif 00153 //----------------------------------------------------------------------------- 00154 #endif 00155 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00156 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8