TAPs 0.7.7.3
TAPsSpringHalfEdgeModel.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsSpringHalfEdgeModel.hpp
00003 
00004 A Spring Half-Edge Model is a spring model with underlie polygon data is based 
00005 on half-edge data structure:
00006 
00007 ----------------------------------------------------------------------
00008 A HalfEdgeModel (TAPsHalfEdgeModel.hpp) is
00009   A Polygonal Model based on half-edge data structure contains:
00010     HEVertexList<T> *m_listVertex;      // HEVertex in a list
00011     HEFaceList<T>   *m_listFace;        // HEFace in a list
00012     HEFaceList<T>   *m_listHoleFace;    // Hole HEFace in a list
00013 
00014     A hole face represents a hole in the surface.
00015 ----------------------------------------------------------------------
00016 
00017 SUKITTI PUNAK   (02/27/2006)
00018 UPDATE          (04/10/2006)
00019 ******************************************************************************/
00020 #ifndef TAPs_SPRING_HALF_EDGE_MODEL_HPP
00021 #define TAPs_SPRING_HALF_EDGE_MODEL_HPP
00022 
00023 #include "TAPsHalfEdgeModel.hpp"
00024 //#include "../Physics/TAPsParticleRef.hpp"
00025 #include "../Physics/TAPsSpringRef.hpp"
00026 #include "../Simulation/TAPsSimClock.hpp"
00027 #include "../Simulation/TAPsListOfODESolvers.hpp"   // For ODE Solvers
00028 
00029 /*==============================================================================
00030 Half-Edge Data Structure:
00031 =========================
00032 HEVertex class is a class for 3D half-edge vertex.
00033   - position
00034   - normal
00035   - incident half-edge
00036 HEFace class is a class for 3D half-edge Face.
00037   - normal
00038   - vertex loop (in CCW order)
00039   - texture coordinates for the vertex loop
00040   - incident half-edge
00041 HEHalfEdge class is a class for 3D half-edge.
00042   - originating vertex
00043   - incident face
00044   - pair of this half-edge
00045   - next half-edge (CCW)
00046   - previous half-edge (CW)
00047                                                       *
00048                                                       *
00049                           E2                          *
00050              V3 <--------------------- V2             *
00051               \                        /\             *
00052                \                      /               *
00053              E3 \         F0      E1 /                *
00054                  \                  /                 *
00055                   \                /                  *
00056                   _\/     E0      /                   *
00057                     V0 --------> V1                   *
00058                                                       *
00059                                                       *
00060                          |                            *
00061                    \_    |    _/                      *
00062                      \_  |  _/                        *
00063                        \ | /                          *
00064                 -------- V --------                   *
00065                       _/ | \_                         *
00066                     _/   |   \_                       *
00067                    /     |     \                      *
00068                          |                            *
00069                                                       *
00070                                                       *
00071 ==============================================================================*/
00072 
00073 
00074 BEGIN_NAMESPACE_TAPs__OpenGL
00075 //=============================================================================
00076 template <typename T>
00077 class SpringHalfEdgeModel : public /*virtual*/ HalfEdgeModel<T> {
00078     //-------------------------------------------------------------------------
00079     // (Friend Fn) put it through ostream
00080     friend std::ostream & operator<< ( std::ostream &output, SpringHalfEdgeModel<T> const &o )
00081     {
00082         // NOT FINISHED YET!
00083 
00084         output  << "\n======================\n"
00085                 <<   "TAPs::SpringHalfEdgeModel<"
00086                 << typeid(T).name() << "> Class:\n"
00087                 <<   "======================\n";
00088         //----------------------------------------------------------------
00089         output << "Name: " << o.GetName() << "\n";
00090         // Vertex Nodes
00091         output  << "\n\nVertices " << o.m_listVertex->Size();
00092         /*
00093         int i;
00094         i = 0;
00095         HEVertex<T> *vertex = o.m_listVertex->Head();
00096         output << "\n{";
00097         while ( vertex ) {
00098             output << "\n  #" << ++i << "\t" << *vertex;
00099             vertex = vertex->Next();
00100         }
00101         output  << "\n}";
00102         //*/
00103         //----------------------------------------------------------------
00104         // Face Nodes
00105         output  << "\n\nFaces " << o.m_listFace->Size();
00106         /*
00107         i = 0;
00108         HEFace<T> *face = o.m_listFace->Head();
00109         output << "\n{";
00110         while ( face ) {
00111             output << "\n  #" << ++i << "\t" << *face;
00112             face = face->Next();
00113         }
00114         output  << "\n}";
00115         //*/
00116         //----------------------------------------------------------------
00117         // Hole Face Nodes
00118         output  << "\n\nHole Faces " << o.m_listHoleFace->Size();
00119         /*
00120         i = 0;
00121         face = o.m_listHoleFace->Head();
00122         output << "\n{";
00123         while ( face ) {
00124             output << "\n  #" << ++i << "\t" << *face;
00125             face = face->Next();
00126         }
00127         output  << "\n}";
00128         //*/
00129         //----------------------------------------------------------------
00130         return output;
00131     }
00132 //-----------------------------------------------------------------------------
00133 // Member Functions ------------------------------------------------------------
00134 public:
00135     //-------------------------------------------------------------------------
00136     // default constructor
00137     SpringHalfEdgeModel ();
00138     //-------------------------------------------------------------------------
00139     // destructor
00140     virtual ~SpringHalfEdgeModel ();
00141     //-------------------------------------------------------------------------
00142     // Create Mesh Springs
00143     void CreateMeshSprings ( int rigidity = 1, T mass = 1, T Ks = 1, T Kd = 1 );
00144     //-------------------------------------------------------------------------
00145     // Virtual Fns from HalfEdgeModel ---> Model class
00146     virtual void Initialize ();
00147     //-------------------------------------------------------------------------
00148     // Get/Set Fn(s)
00149     int GetRigidity ()   const  { return m_iRigidity; }
00150     T   GetKPointMass () const  { return m_tPtMass; }
00151     T   GetKStiffness () const  { return m_tKStiffness; }
00152     T   GetKDamper ()    const  { return m_tKDamper; }
00153     void SetKPointMass ( T val )    { m_tPtMass = val; }
00154     void SetKStiffness ( T val )    { m_tKStiffness = val; }
00155     void SetKDamper ( T val )       { m_tKDamper = val; }
00156     //-------------------------------------------------------------------------
00157 protected:
00158     void ChangeConstantStiffnessOfAllSprings ( T val );
00159     void ChangeConstantDampingOfAllSprings ( T val );
00160     void ChangeMassOfAllPoints ( T val );
00161     //-------------------------------------------------------------------------
00162 protected:
00163     //-------------------------------------------------------------------------
00164     // Helper Fn(s)
00165     void DeleteAllData ();              // Delete All Spring Data
00166     void SetListOf1RingVertices ();     // Find & Set one-ring vertices
00167     void PrepareData ();                // Set HEVertex pointer (m_ptrHEVertex)
00168     void SetMassOfParticles ( T mass ); // Create particles (m_listParticleRef)
00169     // Create springs (m_listSpringRef)
00170     bool CheckASpringExistance ( int p1, int p2 );
00171     void CreateASpring ( T Ks, T Kd, int p1, int p2, int hops );
00172     void CreateSprings ( T Ks, T Kd, int rigidity = 1 );
00173     void BFSCreateSprings ( 
00174                 T Ks, T Kd, int rigidity,       // Ks, Kd, & hop distance
00175                 int p1, int p2,                 // particle#1 & #2
00176                 std::vector<int> & particleSet, // set of connected particles
00177                 bool * isMark );                // marked particles in particleSet
00178 //  void DFSCreateSprings ( 
00179 //              T Ks, T Kd, int rigidity,       // Ks, Kd, & hop distance
00180 //              int p1, int p2,                 // particle#1 & #2
00181 //              std::vector<int> & particleSet, // set of connected particles
00182 //              bool * isMark );                // marked particles in particleSet
00183     //-------------------------------------------------------------------------
00184 //-----------------------------------------------------------------------------
00185 // Data Members  ---------------------------------------------------------------
00186 protected:
00187     //--------------------------------------------------------------------
00188     // Spring Data
00189     // Since List of HEVertex composes the mesh
00190     // In order to create spring connecting between HEVertex,
00191     // First create pointers to HEVertex for pointing to ParticleRef
00192     // Second create integer list of connected vertices for each HEVertex
00193     // Third create integer list of springs
00194     //
00195     //  std::vector<HEVertex<T> *>
00196     //  m_ptrHEVertex
00197     //   ----------- 
00198     //  |     *------- 0 ------------------------> V0 --> V1 --> ... --> V(n-1)
00199     //   -----------   |                                                    ^
00200     //  |     .     |   \                                                   | 
00201     //  |     .     |    \                                                  |
00202     //  |     .     |     \                                                 |
00203     //   -----------       |                                                |
00204     //  |     *-----|- #HEVertices - 1 ------------------------------------
00205     //   -----------       |     |
00206     //                     |      \
00207     //  std::vector<int> * |       \
00208     //  m_ptriListConnectedVertex   \
00209     //   -----------       |         \
00210     //  | | | ... | | 0 <--+          \
00211     //   -----------       |           \
00212     //  |     .     |      |            \
00213     //  |     .     |      |             |
00214     //  |     .     |      |             |
00215     //   -----------       |             |
00216     //  | | | ... | | #HEVertices - 1 <--+
00217     //   -----------       |             |
00218     //                     |             |
00219     //  std::vector<int> * |             |
00220     //  m_ptriListSpring   |             |
00221     //   -----------       |             |
00222     //  | | | ... | | 0 <--+             |
00223     //   -----------                     |
00224     //  |     .     |                    |
00225     //  |     .     |                    |
00226     //  |     .     |                    |
00227     //   -----------                     |
00228     //  | | | ... | | #HEVertices - 1 <--+
00229     //   ----------- 
00230     //
00231     //  std::list<ParticleRef<T> *>
00232     //  m_ptrParticleRef
00233     //   -----------
00234     //  |     *     | 0 -------------------------> P0 --> P1 --> ... --> P(n-1)
00235     //   -----------                                                        ^
00236     //  |     .     |                                                       | 
00237     //  |     .     |                                                       |
00238     //  |     .     |                                                       |
00239     //   -----------                                                        |
00240     //  |     *-----|- #Particles - 1 --------------------------------------
00241     //   -----------
00242     //
00243     //  std::list<SpringRef<T> *>
00244     //  m_ptrSpringRef
00245     //   -----------
00246     //  |     *     | 0 -------------------------> S0 --> S1 --> ... --> S(s-1)
00247     //   -----------                                                        ^
00248     //  |     .     |                                                       | 
00249     //  |     .     |                                                       |
00250     //  |     .     |                                                       |
00251     //   -----------                                                        |
00252     //  |     *-----|- #Springs - 1 ----------------------------------------
00253     //   -----------
00254     //
00255     //  std::list< ParticleRef<T> > m_listParticleRef
00256     //
00257     //  std::list< SpringRef<T> >   m_listSpringRef
00258     //
00259     //--------------------------------------------------------------------
00260     // Not Finish Yet!!!
00261     // These values have to be set into the springs
00262     // !!!
00263     T                           m_tPtMass;          // mass of point (vertex)
00264     T                           m_tKStiffness;      // stiffness constant
00265     T                           m_tKDamper;         // damper   constant
00266     //-----------------------------------------------------
00267     int                         m_iRigidity;
00268     std::vector<HEVertex<T> *>  m_vpHEVertex;       // Pointers to HEVertex
00269     std::vector<int> *          m_pviListVertexRing1;   // one-ring neighbor vertices
00270     std::vector<int> *          m_pviListConnectedVertex;
00271                                 // List of connected vertices
00272     std::vector<int> *          m_pviListSpring;
00273                                 // List of springs connecting neighbor vertices
00274     //std::list< ParticleRef<T> >   m_listParticleRef;  // List of Particles
00275     //std::list< SpringRef<T> > m_listSpringRef;    // List of Springs
00276     std::vector< ParticleRef<T> * > m_vpParticleRef;    // Pointers to ParticleRef
00277     std::vector< SpringRef<T> * >   m_vpSpringRef;      // Pointers to SpringRef
00278     //-------------------------------------------------------------------------
00279     //*
00280     //=========================================================================
00281     // For simulation
00282     //-------------------------------------------------------------------------
00283 public:
00284     virtual void AdvanceSimulation ( T tCurrent, T tNext );
00285     virtual void AdvanceSimulation ( Simulation::SimClock<T> & simClock );
00286     //-------------------------------------------------------------------------
00287 protected:
00288     // REMARK:  DxDt has to be static so that we can pass it to 
00289     // ODESolver Fn.
00290     // But we don't want StateToArray and ArrayToState be static.
00291     // Therefore, we need to pass userData, i.e. this pointer
00292     // as a void pointer.
00293     static bool DxDt (  
00294         T dt,                           // i/p: time step
00295         Simulation::VectorSet<T> &x,    // i/p: array  x = {pos, vel}
00296         Simulation::VectorSet<T> &xdot, // o/p: array xdot = {vel, accel}
00297         void *userData                  // o/p: array of user data
00298     );
00299     //-------------------------------------------------------------------------
00300     void StateToArray ( T *dst );           // copy states to dst array
00301     void ArrayToState ( T *src );           // copy src array to states
00302     void DdtStateToArray ( T *xdot, T dt ); // copy d/dt states to dst 
00303                                             // (xdot) array
00304     void ClearAllForces (); // clear (all) forces (and maybe velocities too)
00305     //-------------------------------------------------------------------------
00306     Simulation::ODESolver<T> *  m_prODESolver;  // ODE solver
00307     Simulation::VectorSet<T> *  x0;             // pointer to x0 Data
00308     Simulation::VectorSet<T> *  xEnd;           // pointer to xEnd Data
00309     Simulation::VectorSet<T>    xData_1;        // #m_iStateSize * 6
00310     Simulation::VectorSet<T>    xData_2;        // #m_iStateSize * 6
00311     int                         m_iStateSize;   // #Mass Points (#mesh vertices)
00312                                 // where 6 = 3 positions + 3 velocities (for x,y,z)
00313     int                         m_iLimitStepCount;
00314     //-------------------------------------------------------------------------
00315     //*/
00316     //-------------------------------------------------------------------------
00317 }; // CLASS END: SpringHalfEdgeModel ******************************************
00318 //=============================================================================
00319 END_NAMESPACE_TAPs__OpenGL
00320 //-----------------------------------------------------------------------------
00321 // Include definition if TAPs_USE_EXPORT is not defined
00322 //#if !defined( TAPs_USE_EXPORT )
00323     #include "TAPsSpringHalfEdgeModel.cpp"
00324 //#endif
00325 //-----------------------------------------------------------------------------
00326 #endif
00327 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00328 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines