TAPs 0.7.7.3
TAPsOpenGLPNTriangleVolPresModel.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsOpenGLPNTriangleVolPresModel.hpp
00003 
00004 (X <==> Extra)
00005 Class OpenGLPNTriangleVolPresModel is for creating an OpenGL PN-Triangle 
00006 Model with volume preservation.
00007 
00008 See class VolPresTriModel for details.
00009 
00010 SUKITTI PUNAK   (04/15/2005)
00011 UPDATE          (05/25/2005)
00012 ******************************************************************************/
00013 #ifndef TAPs_OPENGL_PN_TRIANGLE_VOLPRES_MODEL_HPP
00014 #define TAPs_OPENGL_PN_TRIANGLE_VOLPRES_MODEL_HPP
00015 
00016 extern bool gbUseGPU;
00017 
00018 #include <ctime>
00019 #include "TAPsVolPresPolygonalModel.hpp"
00020 
00021 BEGIN_NAMESPACE_TAPs__OpenGL
00022 //=============================================================================
00023 template <typename T>
00024 class OpenGLPNTriangleVolPresModel : public /*virtual*/ VolPresPolygonalModel<T> {
00025     //-------------------------------------------------------------------------
00026     // put it through ostream
00027     friend std::ostream & operator<< ( std::ostream &output, OpenGLPNTriangleVolPresModel<T> const &o )
00028     {
00029         output  << "\n======================\n"
00030                 <<   "TAPs::OpenGL::OpenGLPNTriangleVolPresModel<"
00031                 << typeid(T).name() << "> Class\n"
00032                 <<   "======================\n";
00033         //----------------------------------------------------------------
00034         // Material Node from OpenGLSupport
00035         output  << "\nMaterial Node" << "\n{\n" << o.material << "\n}";
00036         //----------------------------------------------------------------
00037         // Nodes from XPolygonalModel<T>
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_prXVertex[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     OpenGLPNTriangleVolPresModel ();
00074     //-------------------------------------------------------------------------
00075     // destructor
00076     virtual ~OpenGLPNTriangleVolPresModel ();
00077     //-------------------------------------------------------------------------
00078     // Initialize (virtual fn from Model class)
00079     // (override Initialize fn from XPolygonalModel class)
00080     virtual void Initialize ();
00081 protected:
00082     //-------------------------------------------------------------------------
00083     // Virtual fns from class VolPresPolygonalModel
00084     virtual void PreserveVolumeByVertexNormals( T weight[4] );
00085     //-------------------------------------------------------------------------
00086     // Helper Fn for creating and calculating PN-Triangles
00087     void CreateAndCalPNTriangles ();
00088     bool AllocatePNTriangleCoefficients ();     // 10 coefficients/face
00089     bool AllocatePNTriangleNormals  ();         //  6 normals/face
00090     void InitializePNTriangleCoefficients ();   // b300, b030, and b003
00091     void InitializePNTriangleNormals  ();       // n200, n020, and n002
00092     void CalculatePNTriangleCoefficients ();    // all (10-3) coefficients
00093     void CalculatePNTriangleNormals  ();        // all  (6-3) coefficients
00094     void DrawTriBezierPatchNo(int f, int smoothness);
00095 public:
00096     //-------------------------------------------------------------------------
00097     //void DisplayGL()
00098     //virtual void DisplayGL( OpenGL::Enum::DrawMode DM = OpenGL::Enum::POLYGON );
00099     virtual void DisplayGLText( T x = 0, T y = 0, T z = 0 );
00100     //-------------------------------------------------------------------------
00101     // For Simulation
00102     void DisplayGL_VertexRings ();
00103     void DisplayGL_ParticleNormals ();
00104     void DisplayGL_DeformedFaceNo ();
00105 public:
00106     void ToggleSimulation ()    { bRunSimulation = !bRunSimulation; }
00107     void ToggleShowVertexNormals () { bFlagShowVertexNormals = !bFlagShowVertexNormals; }
00108     void ToggleShowVertexRings ()   { bFlagShowVertexRings = !bFlagShowVertexRings; }
00109     void ToggleShowDeformedFace ()  { bFlagShowDeformedFace = !bFlagShowDeformedFace; }
00110     void SetShowVertexNormals ( bool b )    { bFlagShowVertexNormals = b; }
00111     void SetShowVertexRings ( bool b )      { bFlagShowVertexRings = b; }
00112     void SetShowDeformedFace ( bool b )     { bFlagShowDeformedFace = b; }
00113     //-------------------------------------------------------------------------
00114 // Data Members
00115 protected:
00116     bool bRunSimulation;
00117     bool bFlagShowVertexNormals;
00118     bool bFlagShowVertexRings;
00119     bool bFlagShowDeformedFace;
00120     //-------------------------------------------------------------------------
00121 protected:
00122     //-------------------------------------------------------------------------
00123     // Helper Fn
00124     // void DrawGL()
00125     virtual void DrawGL( GLenum );
00126 // Data Members  ---------------------------------------------------------------
00127 //protected:
00128 public:
00129     float * m_prPNTriCoef;      // PNTriCoef pointer   (#faces * 10 * 3)
00130     float * m_prPNTriNormal;    // PNTriNormal pointer (#faces *  6 * 3)
00131 //-----------------------------------------------------------------------------
00132 };
00133 //=============================================================================
00134 END_NAMESPACE_TAPs__OpenGL
00135 //-----------------------------------------------------------------------------
00136 // Include definition if TAPs_USE_EXPORT is not defined
00137 //#if !defined( TAPs_USE_EXPORT )
00138     #include "TAPsOpenGLPNTriangleVolPresModel.cpp"
00139 //#endif
00140 //-----------------------------------------------------------------------------
00141 #endif
00142 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00143 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines