TAPs 0.7.7.3
TAPsVolPresPolygonalModel.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsVolPresPolygonalModel.hpp
00003 
00004 A Polygonal Model that is deformable with volume preservation.
00005 
00006 SUKITTI PUNAK   (11/11/2004)
00007 UPDATE          (11/15/2004)
00008 ******************************************************************************/
00009 #ifndef TAPs_VOL_PRES_POLYGONAL_MODEL_HPP
00010 #define TAPs_VOL_PRES_POLYGONAL_MODEL_HPP
00011 
00012 #include <ctime>
00013 #include "TAPsXPolygonalModel.hpp"
00014 #include "../GeometricDataStructure/TAPsEdge.hpp"
00015 #include "../GeometricDataStructure/TAPsVertexRings.hpp"
00016 
00017 // Physics
00018 #include "../Physics/TAPsSpringVertex.hpp"
00019 #include "../Physics/TAPsPhysics.hpp"   // for gravitational constant
00020 
00021 // For finding cubic root
00022 #include "../External/SP_Mathematics.h"
00023 
00024 BEGIN_NAMESPACE_TAPs__OpenGL
00025 //=============================================================================
00026 template <typename T>
00027 class VolPresPolygonalModel : public /*virtual*/ XPolygonalModel<T> {
00028     //-------------------------------------------------------------------------
00029     // (Friend Fn) put it through ostream
00030     friend std::ostream & operator<< ( std::ostream &output, VolPresPolygonalModel<T> const &o )
00031     {
00032         output  << "\n======================\n"
00033                 <<   "TAPs::VolPresPolygonalModel<"
00034                 << typeid(T).name() << "> Class:\n"
00035                 <<   "======================\n";
00036         //----------------------------------------------------------------
00037         // Vertices Node
00038         output  << "\n\nVertices " << o.m_iNoVertices << "\n{";
00039         for ( int i = 0; i < o.m_iNoVertices; ++i ) {
00040             output << "\n  #" << i << "\t" << o.m_prVertex[i];
00041         }
00042         output  << "\n}";
00043         //----------------------------------------------------------------
00044         // Neighbor vertex ring#1
00045         if ( o.m_pviVertexRing1List ) {
00046             std::vector<int>::const_iterator iterator;
00047             output  << "\n\nVertexRing1 " << o.m_iNoVertices << "\n{";
00048             for ( int i = 0; i < o.m_iNoVertices; ++i ) {
00049                 output << "\n  #" << i;
00050                 for (   iterator = o.m_pviVertexRing1List[i].begin(); 
00051                         iterator != o.m_pviVertexRing1List[i].end();
00052                         ++iterator )
00053                 {
00054                     output << "\t" << *iterator;
00055                 }
00056             }
00057             output  << "\n}";
00058         }
00059         //----------------------------------------------------------------
00060         // Faces Node
00061         output  << "\n\nFaces " << o.m_iNoFaces  << "\n{";
00062         for ( int i = 0; i < o.m_iNoFaces; ++i ) {
00063             output << "\n  #" << i << "\t" << o.m_prFace[i];
00064         }
00065         output  << "\n}";
00066         return output;
00067     }
00068 //-----------------------------------------------------------------------------
00069 // Member Functions ------------------------------------------------------------
00070 public:
00071     //-------------------------------------------------------------------------
00072     // default constructor
00073     VolPresPolygonalModel ();
00074     //-------------------------------------------------------------------------
00075     // destructor
00076     virtual ~VolPresPolygonalModel ();
00077     //-------------------------------------------------------------------------
00078     // Virtual Fns from XPolygonalModel class which from Model class
00079     virtual void Initialize ();
00080     virtual void ApplyAndResetTransform ();
00081     //-------------------------------------------------------------------------
00082     // Get/Set Fn(s)
00083     inline int  GetDeformedFaceNo () const  
00084     {
00085         std::cout << "Deformed Face#: " << m_iDeformedFaceNo << "\n";
00086         return m_iDeformedFaceNo;
00087     }
00088     inline void SetDeformedFaceNo ( int faceNo )
00089     {
00090         m_iDeformedFaceNo = faceNo;
00091         std::cout << "Deformed Face#: " << m_iDeformedFaceNo << "\n";
00092     }
00093     inline int  GetNoEdges () const { return m_iNoEdges; }
00094     inline void SetNoEdges ( int n )    { m_iNoEdges = n; }
00095     inline T GetVolume() { return m_tVolume; }
00096     inline Vector3<T> GetCentroid() { return m_vtCentroid; }
00097     //-------------------------------------------------------------------------
00098     // Toggle Modes
00099     inline void ToggleVolumePreservationMode () { m_bFlagVolPresMode = !m_bFlagVolPresMode; }
00100     inline void ToggleSpringForceMode () { m_bFlagSpringForceMode = !m_bFlagSpringForceMode; }
00101 protected:
00102     inline Edge const * const GetEdgeList() const { return m_prEdge; }
00103     inline void SetEdgeList( Edge *p )      { m_prEdge = p; }
00104 protected:
00105     //-------------------------------------------------------------------------
00106     // Find Edge List
00107     void DetermineEdgeList ();
00108     //-------------------------------------------------------------------------
00109     // Particles and Springs
00110     void CreateParticleVerticesFromVertices ();
00111     void CreateSpringVerticesFromEdges ();
00112     //-------------------------------------------------------------------------
00113     // Volume Preservation Fn(s)
00114     T m_weight[4];
00115     virtual T CalVolume ();
00116     virtual T CalVolume2 ();
00117     virtual void PreserveVolumeByVertexNormals( T weight[4] );
00118     virtual void PreserveVolume ( T weight[4] );
00119     inline void d3mom0 ( T v[][3], T dv[][3], T wgt[4] );
00120     inline void DeformVertex ( int v, Vector3<T> & deformVector );
00121     inline void DeformVertices ( int vList[], int size, Vector3<T> & deformVector );
00122     //-------------------------------------------------------------------------
00123     // For Simulation
00124     void StepSimulation( T dt );
00125     //-------------------------------------------------------------------------
00126     // Calculate Forces
00127     /*
00128     void ClearForce();                      // clear force of particles to zeros
00129     void ForceDueToGravity( T g = SP_Physics::g );  // calculate (weight) force due to (acceleration of) gravity
00130     void ForceDueToViscousDamping();        // calculate (a loss) force due to viscous damping
00131     void ForceDueToViscousFluidMoving();    // calculate (wind)   force due to viscous fluid moving
00132     */
00133     // Calculate All Forces Acting on Particles
00134     void CalForces( Vector3<T> vWind = Vector3<T>(0,0,0), T g = Physics_SI::K::g );
00135     void AddSpringForces();     // calculate and add spring forces to particle forces
00136     //-------------------------------------------------------------------------
00137 protected:
00138     // Volume
00139     T           m_tVolume;      // Volume of this object
00140     Vector3<T>  m_vtCentroid;   // Centroid of this object
00141     int         m_iNoEdges;     // Number of Edges
00142     Edge *      m_prEdge;       // Edge pointers
00143     bool *      m_bFlagFixed;   // Status: Fixed/Unfixed status for each vertex
00144     Vector3<T> *    m_pvDeformVector;   // Deform Vector for each vertex
00145     int         m_iDeformedFaceNo;      // Deformed Face #
00146     VertexRings *   m_pcVertexRings;    // vertex rings (make ptr in case of needed more than one)
00147 
00148     // Calculation Modes
00149     bool    m_bFlagVolPresMode;         // true --> Volume is preserved
00150     bool    m_bFlagSpringForceMode;     // true --> Spring forces are activated
00151 
00152     // Spring Part
00153     //Particle<T>   ** m_pprParticle;   // particles to mirror the vertices
00154     //Spring<T> ** m_pprSpring;     // number of string is the same as number of edges
00155     ParticleVertex<T> ** m_pprParticleVertex;   // adding particle properties to the vertices
00156     SpringVertex<T> **   m_pprSpringVertex;     // number of springs is the same as number of edges
00157 };
00158 //=============================================================================
00159 END_NAMESPACE_TAPs__OpenGL
00160 //-----------------------------------------------------------------------------
00161 // Include definition if TAPs_USE_EXPORT is not defined
00162 //#if !defined( TAPs_USE_EXPORT )
00163     #include "TAPsVolPresPolygonalModel.cpp"
00164 //#endif
00165 //-----------------------------------------------------------------------------
00166 #endif
00167 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00168 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines