TAPs 0.7.7.3
TAPsVolPresTriModel.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsVolPresTriModel.hpp
00003 
00004 A Triangulated Model that is deformable with volume preservation.
00005 
00006 SUKITTI PUNAK   (11/02/2004)
00007 UPDATE          (11/11/2004)
00008 ******************************************************************************/
00009 #ifndef TAPs_VOL_PRES_TRI_MODEL_HPP
00010 #define TAPs_VOL_PRES_TRI_MODEL_HPP
00011 
00012 #include "TAPsXTrigonalModel.hpp"
00013 #include "../GeometricDataStructure/TAPsEdge.hpp"
00014 
00015 // Physics
00016 #include "../Physics/TAPsSpringVertex.hpp"
00017 #include "../Physics/TAPsPhysics.hpp"   // for gravitational constant
00018 
00019 // For finding cubic root
00020 #include "../External/SP_Mathematics.h"
00021 
00022 BEGIN_NAMESPACE_TAPs__OpenGL
00023 //=============================================================================
00024 template <typename T>
00025 class VolPresTriModel : public /*virtual*/ XTrigonalModel<T> {
00026     //-------------------------------------------------------------------------
00027     // (Friend Fn) put it through ostream
00028     friend std::ostream & operator<< ( std::ostream &output, VolPresTriModel<T> const &o )
00029     {
00030         output  << "\n======================\n"
00031                 <<   "TAPs::VolPresTriModel<"
00032                 << typeid(T).name() << "> Class:\n"
00033                 <<   "======================\n";
00034         //----------------------------------------------------------------
00035         // Vertices Node
00036         output  << "\n\nVertices " << o.m_iNoVertices << "\n{";
00037         for ( int i = 0; i < o.m_iNoVertices; ++i ) {
00038             output << "\n  #" << i << "\t" << o.m_prVertex[i];
00039         }
00040         output  << "\n}";
00041         //----------------------------------------------------------------
00042         // Neighbor vertex ring#1
00043         if ( o.m_pviVertexRing1List ) {
00044             std::vector<int>::const_iterator iterator;
00045             output  << "\n\nVertexRing1 " << o.m_iNoVertices << "\n{";
00046             for ( int i = 0; i < o.m_iNoVertices; ++i ) {
00047                 output << "\n  #" << i;
00048                 for (   iterator = o.m_pviVertexRing1List[i].begin(); 
00049                         iterator != o.m_pviVertexRing1List[i].end();
00050                         ++iterator )
00051                 {
00052                     output << "\t" << *iterator;
00053                 }
00054             }
00055             output  << "\n}";
00056         }
00057         //----------------------------------------------------------------
00058         // Faces Node
00059         output  << "\n\nFaces " << o.m_iNoFaces  << "\n{";
00060         for ( int i = 0; i < o.m_iNoFaces; ++i ) {
00061             output << "\n  #" << i << "\t" << o.m_prFace[i];
00062         }
00063         output  << "\n}";
00064         return output;
00065     }
00066 //-----------------------------------------------------------------------------
00067 // Member Functions ------------------------------------------------------------
00068 public:
00069     //-------------------------------------------------------------------------
00070     // default constructor
00071     VolPresTriModel ();
00072     //-------------------------------------------------------------------------
00073     // destructor
00074     virtual ~VolPresTriModel ();
00075     //-------------------------------------------------------------------------
00076     virtual void Initialize ();     // virtual fn from Model class
00077     //-------------------------------------------------------------------------
00078     // Get/Set Fn(s)
00079     inline int  GetNoEdges () const { return m_iNoEdges; }
00080     inline void SetNoEdges ( int n )    { m_iNoEdges = n; }
00081     inline T GetVolume() { return m_tVolume; }
00082     inline Vector3<T> GetCentroid() { return m_vtCentroid; }
00083 protected:
00084     inline Edge const * const GetEdgeList() const { return m_prEdge; }
00085     inline void SetEdgeList( Edge *p )      { m_prEdge = p; }
00086 protected:
00087     //-------------------------------------------------------------------------
00088     // Find Edge List
00089     void DetermineEdgeList ();
00090     //-------------------------------------------------------------------------
00091     // Particles and Springs
00092     void CreateParticleVerticesFromVertices ();
00093     void CreateSpringVerticesFromEdges ();
00094 protected:
00095     //-------------------------------------------------------------------------
00096     // Volume Preservation Fn(s)
00097     T weight[4];
00098     T CalVolume ();
00099     T CalVolume2 ();
00100     void PreserveVolume ( T weight[4] );
00101     //T FindPreserveVolumeFactor ();
00102     //double d3mom0 ( double v[PTS][XYZ], double dv[PTS][XYZ], double wgt[4] );
00103     inline void d3mom0 ( T v[][3], T dv[][3], T wgt[4] );
00104     //void d3mom0 ();
00105     //-------------------------------------------------------------------------
00106 protected:
00107     // Volume
00108     T           m_tVolume;      // Volume of this object
00109     Vector3<T>  m_vtCentroid;   // Centroid of this object
00110     int         m_iNoEdges;     // Number of Edges
00111     Edge *      m_prEdge;       // Edge pointers
00112 
00113     // Spring Part
00114     //Particle<T>   ** m_pprParticle;   // particles to mirror the vertices
00115     //Spring<T> ** m_pprSpring;     // number of string is the same as number of edges
00116     ParticleVertex<T> ** m_pprParticleVertex;   // added particles to the vertices
00117     SpringVertex<T> **   m_pprSpringVertex;     // number of string is the same as number of edges
00118 
00119     //-------------------------------------------------------------------------
00120     // For Simulation
00121     void StepSimulation( T dt );
00122     //-------------------------------------------------------------------------
00123     // Calculate Forces
00124     /*
00125     void ClearForce();                      // clear force of particles to zeros
00126     void ForceDueToGravity( T g = SP_Physics::g );  // calculate (weight) force due to (acceleration of) gravity
00127     void ForceDueToViscousDamping();        // calculate (a loss) force due to viscous damping
00128     void ForceDueToViscousFluidMoving();    // calculate (wind)   force due to viscous fluid moving
00129     */
00130     // Calculate All Forces Acting on Particles
00131     void CalForces( Vector3<T> vWind = Vector3<T>(0,0,0), T g = Physics_SI::K::g );
00132     void AddSpringForces();     // calculate and add spring forces to particle forces
00133 };
00134 //=============================================================================
00135 END_NAMESPACE_TAPs__OpenGL
00136 //-----------------------------------------------------------------------------
00137 // Include definition if TAPs_USE_EXPORT is not defined
00138 //#if !defined( TAPs_USE_EXPORT )
00139     #include "TAPsVolPresTriModel.cpp"
00140 //#endif
00141 //-----------------------------------------------------------------------------
00142 #endif
00143 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00144 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines