TAPs 0.7.7.3
TAPsOpenGLModelSutureMath.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002 TAPsOpenGLModelSutureMath.cpp
00003 
00004 Class OpenGLModelSutureMath is for creating an OpenGL Suture Model.
00005 
00006 See class ModelSutureMath (in "../Model/TAPsModelSutureMath.hpp") and
00007 class OpenGLSupport ("../OpenGL/TAPsOpenGLSupport.hpp") for detail.
00008 
00009 SUKITTI PUNAK   (01/30/2006)
00010 UPDATE          (06/15/2006)
00011 *******************************************************************************/
00012 #include "TAPsOpenGLModelSutureMath.hpp"
00013 // Using Inclusion Model (i.e. definitions are included in declarations)
00014 //                       (this name.cpp is included in name.hpp)
00015 // Each friend is defined directly inside its declaration.
00016 
00017 BEGIN_NAMESPACE_TAPs__OpenGL
00018 //==============================================================================
00019 //------------------------------------------------------------------------------
00020 // Default Constructor
00021 template <typename T>
00022 OpenGLModelSutureMath<T>::OpenGLModelSutureMath ()
00023     : ModelSutureMath<T>(),
00024       m_iNumSlices( 12 ),
00025       m_iNumStacks( 13 ) 
00026       , m_uiDisplayList( 0 )
00027 {
00028     SetUpOpenGLDisplayList();
00029     SetMaterial( Enum::BLUE_NAVY );
00030 
00031     #ifdef  TAPs_ENABLE_DEBUG
00032     std::cout << "OpenGLModelSutureMath<" << typeid(T).name() << "> Default Constructor\n";
00033     #endif//TAPs_DEBUG_MODE
00034 }
00035 //------------------------------------------------------------------------------
00036 // Non-Default Constructor
00037 template <typename T>
00038 OpenGLModelSutureMath<T>::OpenGLModelSutureMath (   int iNoLinks, T tLength, T tWeight, 
00039                                             Vector3<T> & posOfVertex0,
00040                                             T radius, int numSlices, int numStacks )
00041     : ModelStrandMath<T>( iNoLinks, tLength, tWeight, posOfVertex0, radius ),
00042       ModelSutureMath<T>( iNoLinks, tLength, tWeight, posOfVertex0, radius ),
00043       m_iNumSlices( numSlices ),
00044       m_iNumStacks( numStacks )
00045       , m_uiDisplayList( 0 )
00046 {
00047     SetUpOpenGLDisplayList();
00048     SetMaterial( Enum::BLUE_NAVY );
00049 
00050     #ifdef  TAPs_ENABLE_DEBUG
00051     std::cout << "OpenGLModelSutureMath<" << typeid(T).name() << "> Non-Default Constructor\n";
00052     #endif//TAPs_DEBUG_MODE
00053 }
00054 //------------------------------------------------------------------------------
00055 // Non-Default Constructor
00056 template <typename T>
00057 OpenGLModelSutureMath<T>::OpenGLModelSutureMath (   int iNoLinks, T tLength, T tWeight, 
00058                                             Vector3<T> & posOfVertex0,
00059                                             T radius, 
00060                                             const char * needle1,   // Type of Needle (read from file)
00061                                             int numSlices, int numStacks )
00062 
00063     : ModelStrandMath<T>( iNoLinks, tLength, tWeight, posOfVertex0, radius ),
00064       ModelSutureMath<T>( iNoLinks, tLength, tWeight, posOfVertex0, radius, needle1 ),
00065       m_iNumSlices( numSlices ),
00066       m_iNumStacks( numStacks )
00067       , m_uiDisplayList( 0 )
00068 {
00069     SetUpOpenGLDisplayList();
00070     SetMaterial( Enum::BLUE_NAVY );
00071 
00072     #ifdef  TAPs_ENABLE_DEBUG
00073     std::cout << "OpenGLModelSutureMath<" << typeid(T).name() << "> Non-Default Constructor\n";
00074     #endif//TAPs_DEBUG_MODE
00075 }
00076 /*
00077 //------------------------------------------------------------------------------
00078 // Non-Default Constructor
00079 template <typename T>
00080 OpenGLModelSutureMath<T>::OpenGLModelSutureMath (   int iNoLinks, T tLength, T tWeight, 
00081                                             Vector3<T> & posOfVertex0,
00082                                             T radius, 
00083                                             T tKRatioOfStretchingAllowed,
00084                                             T tKRatioOfCompressionAllowed,
00085                                             T tKStretching,
00086                                             T tKBending,
00087                                             T tKTwisting,
00088                                             T tKFriction,
00089                                             T tKContact,
00090                                             T tKGravity,
00091                                             const char * needle1,   // Type of Needle (read from file)
00092                                             int numSlices, int numStacks )
00093 
00094     : ModelStrandMath<T>( iNoLinks, tLength, tWeight, posOfVertex0, radius, 
00095                       tKRatioOfStretchingAllowed, tKRatioOfCompressionAllowed, 
00096                       tKStretching, tKBending, tKTwisting, 
00097                       tKFriction, tKContact, tKGravity ),
00098       ModelSutureMath<T>( iNoLinks, tLength, tWeight, posOfVertex0, radius, 
00099                       tKRatioOfStretchingAllowed, tKRatioOfCompressionAllowed, 
00100                       tKStretching, tKBending, tKTwisting, 
00101                       tKFriction, tKContact, tKGravity, 
00102                       needle1 ),
00103       m_iNumSlices( numSlices ),
00104       m_iNumStacks( numStacks )
00105       , m_uiDisplayList( 0 )
00106 {
00107     SetUpOpenGLDisplayList();
00108     SetMaterial( Enum::BLUE_NAVY );
00109     #ifdef TAPs_ENABLE_DEBUG
00110     std::cout << "OpenGLModelSutureMath<" << typeid(T).name() << "> Non-Default Constructor\n";
00111     #endif
00112 }
00113 //*/
00114 //------------------------------------------------------------------------------
00115 // Destructor
00116 template <typename T>
00117 OpenGLModelSutureMath<T>::~OpenGLModelSutureMath ()
00118 {
00119     //----------------------------------------------------------------
00120     #ifdef  TAPs_ENABLE_DEBUG
00121     std::cout << "OpenGLModelSutureMath<" << typeid(T).name() << "> Destructor\n";
00122     #endif//TAPs_DEBUG_MODE
00123 }
00124 //*
00125 //------------------------------------------------------------------------------
00126 //void DisplayGL ()
00127 template <typename T>
00128 void OpenGLModelSutureMath<T>::DisplayGL ( OpenGL::Enum::DrawMode DM )
00129 {
00130     switch (DM) {
00131     case OpenGL::Enum::WIRE_FRAME:
00132         DrawNeedles( OpenGL::Enum::WIRE_FRAME );
00133         DrawGL( OpenGL::Enum::WIRE_FRAME );
00134         break;
00135     case OpenGL::Enum::POINT:
00136         DrawNeedles( OpenGL::Enum::POINT );
00137         int ptSz;
00138         glGetIntegerv( GL_POINT_SIZE, &ptSz );
00139         glPointSize( 5 );
00140         DrawGL( GL_POINTS );
00141         glPointSize( ptSz );
00142         break;
00143     default:
00144         DrawNeedles( OpenGL::Enum::POLYGON );
00145         DrawGL( GL_LINE_STRIP );
00146         break;
00147     }
00148 }
00149 //*/
00150 //------------------------------------------------------------------------------
00151 //void DisplayGLWithBVHTrees ()
00152 template <typename T>
00153 void OpenGLModelSutureMath<T>::DisplayGLWithBVHTrees ( OpenGL::Enum::DrawMode DM )
00154 {
00155     switch (DM) {
00156     case OpenGL::Enum::WIRE_FRAME:
00157         DrawNeedlesWithBVHTrees( OpenGL::Enum::WIRE_FRAME );
00158         DrawGL( OpenGL::Enum::WIRE_FRAME );
00159         break;
00160     case OpenGL::Enum::POINT:
00161         DrawNeedlesWithBVHTrees( OpenGL::Enum::WIRE_FRAME );
00162         int ptSz;
00163         glGetIntegerv( GL_POINT_SIZE, &ptSz );
00164         glPointSize( 5 );
00165         DrawGL( GL_POINTS );
00166         glPointSize( ptSz );
00167         break;
00168     default:
00169         DrawNeedlesWithBVHTrees( OpenGL::Enum::WIRE_FRAME );
00170         DrawGL( GL_LINE_STRIP );
00171         break;
00172     }
00173     //GetBVHTree()->DrawByOpenGL();
00174     //GetBVHTree()->DrawByOpenGLOnlyEndLevel();
00175     GetBVHTree()->DrawByOpenGLCollidedNodes();
00176 }
00177 //------------------------------------------------------------------------------
00178 // Helper Fn
00179 // void DrawNeedles ()
00180 template <typename T>
00181 void OpenGLModelSutureMath<T>::DrawNeedles ( OpenGL::Enum::DrawMode DM )
00182 {
00183     static int i;
00184     static T angle;
00185     static Vector3<T> dir, axis;
00186 
00187     /*
00188     //--------------------------------------------------------------------
00189     // Draw Vertices of Left Needle
00190     HEVertex<T> * vertex = m_pNeedleLeft->GetVertexList()->Head();
00191     Vector3<T> pos;
00192     glBegin( GL_LINES );
00193         while ( vertex ) {
00194             pos = vertex->GetPosition();
00195             //pos = rotMat * pos;
00196             pos = m_mRotMatForLeftNeedle * pos;
00197             pos += m_prVertex[i];
00198             glVertex3f( pos[0], pos[1], pos[2] );
00199             vertex = vertex->Next();
00200         }
00201     glEnd();
00202     //*/
00203 
00204     //*
00205     //--------------------------------------------------------------------
00206     // Draw Left Needle by OpenGL
00207     i = 0;
00208     //--------------------------------------------------------------------
00209     //glPushMatrix();
00210         m_pNeedleLeft->DisplayGL( DM );
00211     //glPopMatrix();
00212     //*/
00213 
00214     //*
00215     //--------------------------------------------------------------------
00216     // Draw Needle Pick Points
00217     if ( DM == OpenGL::Enum::POINT ) {
00218         Vector3<T> pos;
00219         glPushMatrix();
00220             glTranslatef( 
00221                 m_pNeedleLeft->GetTransform().GetTranslation()[0], 
00222                 m_pNeedleLeft->GetTransform().GetTranslation()[1], 
00223                 m_pNeedleLeft->GetTransform().GetTranslation()[2] );
00224             glPointSize( 3 );
00225             glDisable( GL_DEPTH_TEST );
00226             glBegin( GL_POINTS );
00227                 for ( int i = 0; i < m_iNoPickPts; ++i ) {
00228                     pos = m_pNeedleLeft->GetTransform().GetMatrixRotation() * *(m_prPickPts[i]);
00229                     glVertex3f( pos[0], pos[1], pos[2] );
00230                 }
00231             glEnd();
00232             glEnable( GL_DEPTH_TEST );
00233             glPointSize( 1 );
00234         glPopMatrix();
00235     }
00236     //--------------------------------------------------------------------
00237     //*/
00238 
00239     /*
00240     //--------------------------------------------------------------------
00241     // Draw Left Needle Sharp Points
00242     glEnable( GL_BLEND );
00243     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00244     SetMaterial( Enum::NEEDLE_SHARP_POINT );
00245     ApplyMaterial( Enum::FRONT );
00246     glPushMatrix();
00247         glPointSize(7);
00248         //glDisable( GL_DEPTH_TEST );
00249         glTranslatef( 
00250             m_pNeedleLeft->GetTransform().GetTranslation()[0], 
00251             m_pNeedleLeft->GetTransform().GetTranslation()[1], 
00252             m_pNeedleLeft->GetTransform().GetTranslation()[2] );
00253 
00254         //glBegin( GL_POINTS );
00256         //for ( int i = 0; i < m_iNoPickPts; ++i ) {
00257         //  //pos = m_mRotMatForLeftNeedle * *(m_prPickPts[i]);
00258         //  if ( m_prbIsSharp[i] == true ) {
00259         //      glPushMatrix();
00260         //      Vector3<T> pos = m_pNeedleLeft->GetTransform().GetMatrixRotation() * *(m_prPickPts[i]);
00261         //      //glVertex3f( pos[0], pos[1], pos[2] );
00262         //      glTranslatef( pos[0], pos[1], pos[2] );
00263         //      float radius = 4 * GetRadius();
00264         //      glScalef( radius, radius, radius );
00265         //      glCallList( m_uiDisplayList );
00266         //      glPopMatrix();
00267         //  }
00268         //}
00269 
00270         // Case there is only one sharp point on the needle
00271         {
00272             glPushMatrix();
00273             Vector3<T> pos = m_pNeedleLeft->GetTransform().GetMatrixRotation() * *(m_prPickPts[ m_iNeedleSharpPt ]);
00274             //glVertex3f( pos[0], pos[1], pos[2] );
00275             glTranslatef( pos[0], pos[1], pos[2] );
00276             float radius = 4 * GetRadius();
00277             glScalef( radius, radius, radius );
00278             glCallList( m_uiDisplayList );
00279             glPopMatrix();
00280         }
00281 
00282         //glEnd();
00283         //glEnable( GL_DEPTH_TEST );
00284         glPointSize(1);
00285     glPopMatrix();
00286     glDisable( GL_BLEND );
00287     //--------------------------------------------------------------------
00288     //*/
00289 
00290     /*
00291     //--------------------------------------------------------------------
00292     // Draw Right Needle by OpenGL
00293     i = m_iNoLinks;
00294     dir = m_prVertex[i] - m_prVertex[i-1];
00295     axis = dir ^ (-CGMath<T>::VectorY);
00296     angle = acos( (dir * (-CGMath<T>::VectorY)) / dir.Length() ) 
00297           * Math<T>::RAD_TO_DEG;
00298     glPushMatrix();
00299         glTranslatef( m_prVertex[i][0], m_prVertex[i][1], m_prVertex[i][2] );
00300         glRotatef( -angle, axis[0], axis[1], axis[2] );
00301         m_pNeedleRight->DisplayGL( DM );
00302     glPopMatrix();
00303     //*/
00304 }
00305 //------------------------------------------------------------------------------
00306 // Helper Fn
00307 // void DrawNeedlesWithBVHTrees ()
00308 template <typename T>
00309 void OpenGLModelSutureMath<T>::DrawNeedlesWithBVHTrees ( OpenGL::Enum::DrawMode DM )
00310 {
00311     static int i;
00312     static T angle;
00313     static Vector3<T> dir, axis;
00314     //--------------------------------------------------------------------
00315     // Left Needle
00316     //glPushMatrix();
00317 
00318         /*
00319         //--------------------------------------------------------------------
00320         // Draw Vertices of Left Needle
00321         HEVertex<T> * vertex = m_pNeedleLeft->GetVertexList()->Head();
00322         Vector3<T> pos;
00323         glBegin( GL_LINES );
00324             while ( vertex ) {
00325                 pos = vertex->GetPosition();
00326                 //pos = rotMat * pos;
00327                 //pos = m_mRotMatForLeftNeedle * pos;
00328                 //pos += m_prVertex[i];
00329                 glVertex3f( pos[0], pos[1], pos[2] );
00330                 vertex = vertex->Next();
00331             }
00332         glEnd();
00333         //*/
00334 
00335         m_pNeedleLeft->DisplayGL( DM );
00336         m_pNeedleLeft->GetBVHTree()->DrawByOpenGL();
00337     //glPopMatrix();
00338     /*
00339     //--------------------------------------------------------------------
00340     // Right Needle
00341     glPushMatrix();
00342         m_pNeedleRight->DisplayGL( DM );
00343         m_pNeedleRight->GetBVHTree()->DrawByOpenGL();
00344     glPopMatrix();
00345     //*/
00346 }
00347 //------------------------------------------------------------------------------
00348 // Helper Fn
00349 // void DrawGL ()
00350 template <typename T>
00351 void OpenGLModelSutureMath<T>::DrawGL ( GLenum drawMode )
00352 {
00353     StrDebug();
00354 
00355     glPushAttrib( GL_LIGHTING_BIT );
00356     //----------------------------------------------------------------
00357     //glPushAttrib( GL_ALL_ATTRIB_BITS );
00358     //ApplyMaterial( Enum::FRONT );
00359 //  Math<T>::PI;    // Initialize Math<T>::PI
00360     Vector3<T> unitZ( 0, 0, 1 );
00361     Vector3<T> direction;
00362     T currentLinkLength;
00363     Vector3<T> rotDir;
00364     T angle;
00365     //*
00366 
00367     float cylinderRadius = GetRadius();
00368     float sphereRadius   = 1.5 * cylinderRadius;
00369 
00370 #ifdef  TAPs_MAXIMIZE_SPEED
00371     if ( true )
00372 #else //TAPs_MAXIMIZE_SPEED
00373     if ( drawMode == OpenGL::Enum::WIRE_FRAME )
00374 #endif//TAPs_MAXIMIZE_SPEED
00375     {
00376         //----------------------------------------------------------------
00377         // Draw Original Line with Cylinder
00378         //SetMaterial( Enum::METAL_SILVER );
00379         //ApplyMaterial( Enum::FRONT );
00380 
00381         //* DEBUG
00382         //-------------------------------------------------
00383         // Draw previous strand position
00384         for ( int i = 0; i < m_iNoLinks; ++i ) {
00385             //-----------------------------------
00386             direction = m_prVertexPrevPos[i+1] - m_prVertexPrevPos[i];
00387             currentLinkLength = direction.Length();
00388             direction.Normalized();
00389             angle  = acos( unitZ * direction ) * Math<T>::RAD_TO_DEG;
00390             rotDir = unitZ ^ direction;
00391             glPushMatrix();
00392                 glTranslatef( 
00393                     static_cast<float>( m_prVertexPrevPos[i][0] ),
00394                     static_cast<float>( m_prVertexPrevPos[i][1] ),
00395                     static_cast<float>( m_prVertexPrevPos[i][2] )
00396                 );
00397                 glRotatef(
00398                     angle,
00399                     static_cast<float>( rotDir[0] ),
00400                     static_cast<float>( rotDir[1] ),
00401                     static_cast<float>( rotDir[2] )
00402                 );
00403 
00404                 //-----------------------------------------
00405                 // Change Color
00406             #ifdef  TAPs_MAXIMIZE_SPEED
00407             #else //TAPs_MAXIMIZE_SPEED
00408                 if ( i % 2 == 0 ) {
00409                     SetMaterial( Enum::DARK_RED_01 );
00410                 }
00411                 else {
00412                     SetMaterial( Enum::DARK_GREEN_01 );
00413                 }
00414                 ApplyMaterial( Enum::FRONT );
00415             #endif//TAPs_MAXIMIZE_SPEED
00416 
00417                 //-----------------------------------------
00418             #ifdef  TAPs_MAXIMIZE_SPEED
00419                 if ( true )
00420             #else //TAPs_MAXIMIZE_SPEED
00421                 if ( !GetFixStatusOfPtNo( i ) )
00422             #endif//TAPs_MAXIMIZE_SPEED
00423                 {
00424                     glScalef( cylinderRadius, cylinderRadius, cylinderRadius );
00425                     glCallList( m_uiDisplayList );
00426                     glScalef( 1, 1, currentLinkLength / cylinderRadius );
00427                     glCallList( m_uiDisplayList+1 );
00428                 }
00429                 else {
00430                     glScalef( sphereRadius, sphereRadius, sphereRadius );
00431                     glCallList( m_uiDisplayList );
00432                     glScalef( 0.25, 0.25, currentLinkLength / sphereRadius );
00433                     glCallList( m_uiDisplayList+1 );
00434                 }
00435             glPopMatrix();
00436         }
00437         //-------------------------------------------------
00438         //*/
00439 
00440         //-------------------------------------------------
00441         // Draw current strand position
00442 
00443         #ifdef  TAPs_STRAND_LOCK_SEGMENTS
00444         #else //TAPs_STRAND_LOCK_SEGMENTS
00445         SetMaterial( Enum::BLUE_NAVY );
00446         ApplyMaterial( Enum::FRONT );
00447         #endif//TAPs_STRAND_LOCK_SEGMENTS
00448 
00449         #ifdef  TAPs_STRAND_LOCK_SEGMENTS
00450         // For segment# 0
00451         {
00452             unsigned int s = 0;
00453             if ( m_Segments[s].isVisible ) {
00454                 if ( m_Segments[s].isLocked )   SetMaterial( Enum::BRIGHT_YELLOW );
00455                 else                            SetMaterial( Enum::BLUE_NAVY );
00456                 ApplyMaterial( Enum::FRONT );
00457                 for ( unsigned int i = m_Segments[s].start; i < m_Segments[s].end; ++i )
00458                 {
00459                     //-----------------------------------
00460                     direction = m_prVertex[i+1] - m_prVertex[i];
00461                     currentLinkLength = direction.Length();
00462                     direction.Normalized();
00463                     angle  = acos( unitZ * direction ) * Math<T>::RAD_TO_DEG;
00464                     rotDir = unitZ ^ direction;
00465                     glPushMatrix();
00466                         glTranslatef( 
00467                             static_cast<float>( m_prVertex[i][0] ),
00468                             static_cast<float>( m_prVertex[i][1] ),
00469                             static_cast<float>( m_prVertex[i][2] )
00470                         );
00471                         glRotatef(
00472                             angle,
00473                             static_cast<float>( rotDir[0] ),
00474                             static_cast<float>( rotDir[1] ),
00475                             static_cast<float>( rotDir[2] )
00476                         );
00477                         //*
00478                         
00479                         //-----------------------------------------
00480                         // Change Color
00481                     #ifdef  TAPs_MAXIMIZE_SPEED
00482                     #else //TAPs_MAXIMIZE_SPEED
00483                         #ifdef  TAPs_STRAND_DEBUG
00484                         //#ifdef    TAPs_DEBUG_MODE
00485                             //switch ( CheckSelfCrossingForKnotRecognition() ) {
00486                             switch ( special_debug_knotID_OF_MATH_MODEL ) {
00487                                 case 0: // Neg Half Knot
00488                                 case 8:     // Neg Half Knot with one more cross
00489                                 case 9:     // Neg Half Knot with one more cross
00490                                     SetMaterial( Enum::RED );
00491                                     break;
00492                                 case 1: // Pos Half Knot
00493                                 case 10:    // Neg Half Knot with one more cross
00494                                 case 11:    // Neg Half Knot with one more cross
00495                                     SetMaterial( Enum::GREEN );
00496                                     break;
00497                                 case 2: // Neg Double Knot
00498                                     SetMaterial( Enum::CYAN );
00499                                     break;
00500                                 case 3: // Pos Double Knot
00501                                     SetMaterial( Enum::MAGENTA );
00502                                     break;
00503                                 default:
00504                                     if ( i % 2 == 0 )   SetMaterial( Enum::DARK_RED_01 );
00505                                     else                SetMaterial( Enum::DARK_GREEN_01 );
00506                                     break;
00507                             }
00508                         #else //TAPs_STRAND_DEBUG
00509                         //#else //TAPs_DEBUG_MODE
00510                             if ( i % 2 == 0 )   SetMaterial( Enum::DARK_RED_01 );
00511                             else                SetMaterial( Enum::DARK_GREEN_01 );
00512                         #endif//TAPs_STRAND_DEBUG
00513                         //#endif//TAPs_DEBUG_MODE
00514                         ApplyMaterial( Enum::FRONT );
00515                     #endif//TAPs_MAXIMIZE_SPEED
00516 
00517                         //-----------------------------------------
00518                     #ifdef  TAPs_MAXIMIZE_SPEED
00519                         if ( true )
00520                     #else //TAPs_MAXIMIZE_SPEED
00521                         if ( !GetFixStatusOfPtNo( i ) )
00522                     #endif//TAPs_MAXIMIZE_SPEED
00523                         {
00524                             glScalef( cylinderRadius, cylinderRadius, cylinderRadius );
00525                             glCallList( m_uiDisplayList );
00526                             glScalef( 1, 1, currentLinkLength / cylinderRadius );
00527                             glCallList( m_uiDisplayList+1 );
00528                         }
00529                         else {
00530                             glScalef( sphereRadius, sphereRadius, sphereRadius );
00531                             glCallList( m_uiDisplayList );
00532                             glScalef( 0.25, 0.25, currentLinkLength / sphereRadius );
00533                             glCallList( m_uiDisplayList+1 );
00534                         }
00535 
00536                     glPopMatrix();
00537                     //-----------------------------------
00538                 }
00539             }
00540         }
00541         // For segment# > 0
00542         for ( unsigned int s = 1; s < m_Segments.size(); ++s ) {
00543             if ( m_Segments[s].isVisible ) {
00544                 // Change color
00545                 if ( m_Segments[s].isLocked )   SetMaterial( Enum::BRIGHT_YELLOW );
00546                 else                            SetMaterial( Enum::BLUE_NAVY );
00547                 ApplyMaterial( Enum::FRONT );
00548                 for ( unsigned int i = m_Segments[s].start; i < m_Segments[s].end; ++i )
00549         #else //TAPs_STRAND_LOCK_SEGMENTS
00550         {
00551             {
00552                 for ( int i = 0; i < m_iNoLinks; ++i )
00553         #endif//TAPs_STRAND_LOCK_SEGMENTS
00554                 {
00555                     //-----------------------------------
00556                     direction = m_prVertex[i+1] - m_prVertex[i];
00557                     currentLinkLength = direction.Length();
00558                     direction.Normalized();
00559                     angle  = acos( unitZ * direction ) * Math<T>::RAD_TO_DEG;
00560                     rotDir = unitZ ^ direction;
00561                     glPushMatrix();
00562                         glTranslatef( 
00563                             static_cast<float>( m_prVertex[i][0] ),
00564                             static_cast<float>( m_prVertex[i][1] ),
00565                             static_cast<float>( m_prVertex[i][2] )
00566                         );
00567                         glRotatef(
00568                             angle,
00569                             static_cast<float>( rotDir[0] ),
00570                             static_cast<float>( rotDir[1] ),
00571                             static_cast<float>( rotDir[2] )
00572                         );
00573                         //*
00574                         
00575                         //-----------------------------------------
00576                         // Change Color
00577                     #ifdef  TAPs_MAXIMIZE_SPEED
00578                     #else //TAPs_MAXIMIZE_SPEED
00579                         if ( i % 2 == 0 ) {
00580                             SetMaterial( Enum::DARK_RED_01 );
00581                         }
00582                         else {
00583                             SetMaterial( Enum::DARK_GREEN_01 );
00584                         }
00585                         ApplyMaterial( Enum::FRONT );
00586                     #endif//TAPs_MAXIMIZE_SPEED
00587 
00588                         //-----------------------------------------
00589                     #ifdef  TAPs_MAXIMIZE_SPEED
00590                         if ( true )
00591                     #else //TAPs_MAXIMIZE_SPEED
00592                         if ( !GetFixStatusOfPtNo( i ) )
00593                     #endif//TAPs_MAXIMIZE_SPEED
00594                         {
00595                             glScalef( cylinderRadius, cylinderRadius, cylinderRadius );
00596                             glCallList( m_uiDisplayList );
00597                             glScalef( 1, 1, currentLinkLength / cylinderRadius );
00598                             glCallList( m_uiDisplayList+1 );
00599                         }
00600                         else {
00601                             glScalef( sphereRadius, sphereRadius, sphereRadius );
00602                             glCallList( m_uiDisplayList );
00603                             glScalef( 0.25, 0.25, currentLinkLength / sphereRadius );
00604                             glCallList( m_uiDisplayList+1 );
00605                         }
00606 
00607                     glPopMatrix();
00608                     //-----------------------------------
00609                 }
00610             }
00611         }
00612         //-------------------------------------------------
00613 
00614         //===========================================================
00615         // Draw Fixed Point(s) (points also fixed if the segment is fixed.)
00616         //-----------------------------------------------------------
00617         #ifdef  TAPs_STRAND_LOCK_SEGMENTS
00618         #else //TAPs_STRAND_LOCK_SEGMENTS
00619         if ( m_setOfFixedPts.size() > 0 ) {
00620             SetMaterial( Enum::METAL_BRONZE );
00621             ApplyMaterial( Enum::FRONT );
00622             int p;
00623             std::set<int>::const_iterator pos  = m_setOfFixedPts.begin();
00624             for ( int i = 0; i < static_cast<int>( m_setOfFixedPts.size() ); ++i, ++pos ) {
00625                 p = *pos;
00626                 glPushMatrix();
00627                     glTranslatef( 
00628                         static_cast<float>( m_prVertex[p][0] ),
00629                         static_cast<float>( m_prVertex[p][1] ),
00630                         static_cast<float>( m_prVertex[p][2] )
00631                     );
00632                     //glScalef( 2, 2, 2 );
00633                     //glCallList( m_uiDisplayList );
00634                     glScalef( sphereRadius, sphereRadius, sphereRadius );
00635                     glCallList( m_uiDisplayList );
00636                 glPopMatrix();
00637             }
00638         }
00639         #endif//TAPs_STRAND_LOCK_SEGMENTS
00640         //-----------------------------------------------------------
00641         //===========================================================
00642 
00643         //DrawTorsions();
00644     }
00645     //*/
00646     else {
00647 
00648         // Draw Projection Direction
00649     #ifdef  TAPs_STRAND_DEBUG
00650         Vector3<T> projDir = GetProjectionDirection( m_prVertex[0], m_prVertex[m_iNoLinks/2], m_prVertex[m_iNoLinks] );
00651         projDir.Normalized();
00652         projDir /= 4;
00653         glPushAttrib( GL_ENABLE_BIT );
00654         glEnable( GL_COLOR_MATERIAL );
00655         projDir += m_prVertex[m_iNoLinks/2];
00656         glColor3f( 0.25, 0.75, 0.25 );
00657         OpenGLUsefulObj<T>::DrawOneHeadArrow( m_prVertex[m_iNoLinks/2], projDir );
00658         glPopAttrib();
00659     #endif//TAPs_STRAND_DEBUG
00660 
00661         //----------------------------------------------------------------
00662         // Draw Subdivision Line with Cylinder
00663         SetMaterial( Enum::BLUE_NAVY );
00664         ApplyMaterial( Enum::FRONT );
00665         if ( drawMode == OpenGL::Enum::POINT ) {
00666             //--------------------------------------------------------
00667             #ifdef  TAPs_STRAND_LOCK_SEGMENTS
00668             // For segment# >= 0
00669             for ( unsigned int s = 0; s < m_Segments.size(); ++s ) {
00670                 if ( m_Segments[s].isVisible ) {
00671                     for ( unsigned int i = m_Segments[s].start*2; i < 2*m_Segments[s].end; ++i )
00672             #else //TAPs_STRAND_LOCK_SEGMENTS
00673             {
00674                 {
00675                     for ( int i = 0; i < 2*m_iNoLinks; ++i )
00676             #endif//TAPs_STRAND_LOCK_SEGMENTS
00677                     {
00678                         glPushMatrix();
00679                             glTranslatef( 
00680                                 static_cast<float>( m_prDispVertex[i][0] ),
00681                                 static_cast<float>( m_prDispVertex[i][1] ),
00682                                 static_cast<float>( m_prDispVertex[i][2] ) 
00683                             );
00684                             glScalef( cylinderRadius, cylinderRadius, cylinderRadius );
00685                             glCallList( m_uiDisplayList );
00686                         glPopMatrix();
00687                     }
00688                 }
00689             }
00690         }
00691         else {  // If drawMode is not POINT or WIRE_FRAME.
00692             #ifdef  TAPs_STRAND_LOCK_SEGMENTS
00693             // For segment# 0
00694             {
00695                 unsigned int s = 0;
00696                 if ( m_Segments[s].isVisible ) {
00697 
00698                     // Change color
00699                     if ( m_Segments[s].isLocked ) {
00700                         SetMaterial( Enum::BRIGHT_YELLOW );
00701                     }
00702                     else {
00703                         #ifdef  TAPs_STRAND_DEBUG
00704                         //#ifdef    TAPs_DEBUG_MODE
00705                             //switch ( CheckSelfCrossingForKnotRecognition() ) {
00706                             switch ( special_debug_knotID_OF_MATH_MODEL ) {
00707                                 case 0: // Neg Half Knot
00708                                 case 8:     // Neg Half Knot with one more cross
00709                                 case 9:     // Neg Half Knot with one more cross
00710                                     SetMaterial( Enum::RED );
00711                                     break;
00712                                 case 1: // Pos Half Knot
00713                                 case 10:    // Neg Half Knot with one more cross
00714                                 case 11:    // Neg Half Knot with one more cross
00715                                     SetMaterial( Enum::GREEN );
00716                                     break;
00717                                 case 2: // Neg Double Knot
00718                                     SetMaterial( Enum::CYAN );
00719                                     break;
00720                                 case 3: // Pos Double Knot
00721                                     SetMaterial( Enum::MAGENTA );
00722                                     break;
00723                                 default:
00724                                     SetMaterial( Enum::BLUE_NAVY );
00725                                     break;
00726                             }
00727                         #else //TAPs_STRAND_DEBUG
00728                         //#else //TAPs_DEBUG_MODE
00729                             SetMaterial( Enum::BLUE_NAVY );
00730                         #endif//TAPs_STRAND_DEBUG
00731                         //#endif//TAPs_DEBUG_MODE
00732                     }
00733                     ApplyMaterial( Enum::FRONT );
00734 
00735                     // For each link in the segment
00736                     for ( unsigned int i = m_Segments[s].start*2; i < 2*m_Segments[s].end-1; ++i )
00737                     {
00738                         direction = m_prDispVertex[i+1] - m_prDispVertex[i];
00739                         currentLinkLength = direction.Length();
00740                         direction.Normalized();
00741                         angle  = acos( unitZ * direction ) * Math<T>::RAD_TO_DEG;
00742                         rotDir = unitZ ^ direction;
00743                         glPushMatrix();
00744                             glTranslatef( 
00745                                 static_cast<float>( m_prDispVertex[i][0] ),
00746                                 static_cast<float>( m_prDispVertex[i][1] ),
00747                                 static_cast<float>( m_prDispVertex[i][2] )
00748                             );
00749                             glRotatef(
00750                                 angle,
00751                                 static_cast<float>( rotDir[0] ),
00752                                 static_cast<float>( rotDir[1] ),
00753                                 static_cast<float>( rotDir[2] )
00754                             );
00755                             /*
00756                             glCallList( m_uiDisplayList );
00757                             glScalef( 1, 1, currentLinkLength );
00758                             glCallList( m_uiDisplayList+1 );
00759                             //*/
00760                             glScalef( cylinderRadius, cylinderRadius, cylinderRadius );
00761                             glCallList( m_uiDisplayList );
00762                             glScalef( 1, 1, currentLinkLength / cylinderRadius );
00763                             glCallList( m_uiDisplayList+1 );
00764                         glPopMatrix();
00765                     }
00766                 }
00767             }
00768             // For segment# > 0
00769             for ( unsigned int s = 1; s < m_Segments.size(); ++s ) {
00770                 if ( m_Segments[s].isVisible ) {
00771 
00772                     // Change color
00773                     if ( m_Segments[s].isLocked ) {
00774                         SetMaterial( Enum::BRIGHT_YELLOW );
00775                     }
00776                     else {
00777                         #ifdef  TAPs_STRAND_DEBUG
00778                         //#ifdef    TAPs_DEBUG_MODE
00779                             //switch ( CheckSelfCrossingForKnotRecognition() ) {
00780                             switch ( special_debug_knotID_OF_MATH_MODEL ) {
00781                                 case 0: // Neg Half Knot
00782                                 case 8:     // Neg Half Knot with one more cross
00783                                 case 9:     // Neg Half Knot with one more cross
00784                                     SetMaterial( Enum::RED );
00785                                     break;
00786                                 case 1: // Pos Half Knot
00787                                 case 10:    // Neg Half Knot with one more cross
00788                                 case 11:    // Neg Half Knot with one more cross
00789                                     SetMaterial( Enum::GREEN );
00790                                     break;
00791                                 case 2: // Neg Double Knot
00792                                     SetMaterial( Enum::CYAN );
00793                                     break;
00794                                 case 3: // Pos Double Knot
00795                                     SetMaterial( Enum::MAGENTA );
00796                                     break;
00797                                 default:
00798                                     SetMaterial( Enum::BLUE_NAVY );
00799                                     break;
00800                             }
00801                         #else //TAPs_STRAND_DEBUG
00802                         //#else //TAPs_DEBUG_MODE
00803                             SetMaterial( Enum::BLUE_NAVY );
00804                         #endif//TAPs_STRAND_DEBUG
00805                         //#endif//TAPs_DEBUG_MODE
00806                     }
00807                     ApplyMaterial( Enum::FRONT );
00808 
00809                     // For each link in the segment
00810                     for ( unsigned int i = m_Segments[s].start*2-1; i < 2*m_Segments[s].end-1; ++i )
00811             #else //TAPs_STRAND_LOCK_SEGMENTS
00812             {
00813                 {
00814                     // For all links in the strand
00815                     for ( int i = 0; i < 2*m_iNoLinks-1; ++i )
00816             #endif//TAPs_STRAND_LOCK_SEGMENTS
00817                     {
00818                         direction = m_prDispVertex[i+1] - m_prDispVertex[i];
00819                         currentLinkLength = direction.Length();
00820                         direction.Normalized();
00821                         angle  = acos( unitZ * direction ) * Math<T>::RAD_TO_DEG;
00822                         rotDir = unitZ ^ direction;
00823                         glPushMatrix();
00824                             glTranslatef( 
00825                                 static_cast<float>( m_prDispVertex[i][0] ),
00826                                 static_cast<float>( m_prDispVertex[i][1] ),
00827                                 static_cast<float>( m_prDispVertex[i][2] )
00828                             );
00829                             glRotatef(
00830                                 angle,
00831                                 static_cast<float>( rotDir[0] ),
00832                                 static_cast<float>( rotDir[1] ),
00833                                 static_cast<float>( rotDir[2] )
00834                             );
00835                             /*
00836                             glCallList( m_uiDisplayList );
00837                             glScalef( 1, 1, currentLinkLength );
00838                             glCallList( m_uiDisplayList+1 );
00839                             //*/
00840                             glScalef( cylinderRadius, cylinderRadius, cylinderRadius );
00841                             glCallList( m_uiDisplayList );
00842                             glScalef( 1, 1, currentLinkLength / cylinderRadius );
00843                             glCallList( m_uiDisplayList+1 );
00844                         glPopMatrix();
00845                     }
00846                 }
00847             }
00848         }
00849 
00850 
00851         //if ( drawMode == OpenGL::Enum::WIRE_FRAME ) {
00852         //  DrawBB();
00853         //}
00854 
00855 
00856         //*/
00857 
00858         //===========================================================
00859         // Draw Fixed Point(s) (points also fixed if the segment is fixed.)
00860         //-----------------------------------------------------------
00861         #ifdef  TAPs_STRAND_LOCK_SEGMENTS
00862         #else //TAPs_STRAND_LOCK_SEGMENTS
00863         if ( m_setOfFixedPts.size() > 0 ) {
00864             SetMaterial( Enum::METAL_BRONZE );
00865             ApplyMaterial( Enum::FRONT );
00866             int p;
00867             std::set<int>::const_iterator pos  = m_setOfFixedPts.begin();
00868             for ( int i = 0; i < static_cast<int>( m_setOfFixedPts.size() ); ++i, ++pos ) {
00869                 p = *pos;
00870                 glPushMatrix();
00871                     glTranslatef( 
00872                         static_cast<float>( m_prVertex[p][0] ),
00873                         static_cast<float>( m_prVertex[p][1] ),
00874                         static_cast<float>( m_prVertex[p][2] )
00875                     );
00876                     //glScalef( 2, 2, 2 );
00877                     //glCallList( m_uiDisplayList );
00878                     glScalef( sphereRadius, sphereRadius, sphereRadius );
00879                     glCallList( m_uiDisplayList );
00880                 glPopMatrix();
00881             }
00882         }
00883         #endif//TAPs_STRAND_LOCK_SEGMENTS
00884         //-----------------------------------------------------------
00885         //===========================================================
00886     }
00887     //----------------------------------------------------------------
00888     glPopAttrib();
00889     //----------------------------------------------------------------
00890     //DrawTorsions();
00891     //DrawOrigShape();
00892     //----------------------------------------------------------------
00893     //if ( drawMode == GL_POINTS ) {
00894     //  DrawBezierCurve();
00895     //}
00896 
00897     /*
00898     // DEBUG
00899     // UNFINISHED
00900     PrtSegments();
00901     for ( int i = 0; i < m_iNoLinks; ++i ) {
00902         T len = (m_prVertex[i]-m_prVertex[i+1]).Length();
00903         if ( len > 4 * m_tLinkLength ) {
00904             std::cout << "Link# " << i << " length: " << len << "\n";
00905         }
00906     }
00907     std::cout << "\n";
00908 
00909     SetMaterial( Enum::METAL_BRONZE );
00910     ApplyMaterial( Enum::FRONT );
00911     for ( int i = 0; i < m_Segments.size(); ++i ) {
00912         float radius = 1.75 * GetRadius();
00913         glPushMatrix();
00914             glTranslatef( 
00915                 static_cast<float>( m_prVertex[m_Segments[i].start][0] ),
00916                 static_cast<float>( m_prVertex[m_Segments[i].start][1] ),
00917                 static_cast<float>( m_prVertex[m_Segments[i].start][2] )
00918             );
00919             glScalef( radius, radius, radius );
00920             glCallList( m_uiDisplayList );
00921         glPopMatrix();
00922     }
00923     //*/
00924 
00925     // DEBUG Draw
00926 #ifdef  TAPs_ADVANCED_SIMULATION
00927     for ( int i = 0; i <= m_iNoLinks; ++i ) {
00928         if ( m_SimFlags[i].CheckSimulationConstraints( TAPs::Enum::AddOn::FIXED ) ) {
00929             SetMaterial( Enum::RED );
00930             ApplyMaterial( Enum::FRONT );
00931             glPushMatrix();
00932                 glTranslatef( 
00933                     static_cast<float>( m_prVertex[i][0] ),
00934                     static_cast<float>( m_prVertex[i][1] ),
00935                     static_cast<float>( m_prVertex[i][2] ) 
00936                 );
00937                 glScalef( sphereRadius, sphereRadius, sphereRadius );
00938                 glCallList( m_uiDisplayList );
00939             glPopMatrix();
00940         }
00941         if ( m_SimFlags[i].CheckSimulationConstraints( TAPs::Enum::AddOn::ATTACHED ) ) {
00942             SetMaterial( Enum::BLUE );
00943             ApplyMaterial( Enum::FRONT );
00944             glPushMatrix();
00945                 glTranslatef( 
00946                     static_cast<float>( m_prVertex[i][0] ),
00947                     static_cast<float>( m_prVertex[i][1] ),
00948                     static_cast<float>( m_prVertex[i][2] ) 
00949                 );
00950                 glScalef( sphereRadius, sphereRadius, sphereRadius );
00951                 glCallList( m_uiDisplayList );
00952             glPopMatrix();
00953         }
00954         if ( m_SimFlags[i].CheckSimulationConstraints( TAPs::Enum::AddOn::PUNCTURED ) ) {
00955             SetMaterial( Enum::WHITE );
00956             ApplyMaterial( Enum::FRONT );
00957             glPushMatrix();
00958                 glTranslatef( 
00959                     static_cast<float>( m_prVertex[i][0] ),
00960                     static_cast<float>( m_prVertex[i][1] ),
00961                     static_cast<float>( m_prVertex[i][2] ) 
00962                 );
00963                 glScalef( sphereRadius, sphereRadius, sphereRadius );
00964                 glCallList( m_uiDisplayList );
00965             glPopMatrix();
00966         }
00967         if ( m_SimFlags[i].CheckSimulationConstraints( TAPs::Enum::AddOn::SLIDABLE ) ) {
00968             SetMaterial( Enum::GREEN );
00969             ApplyMaterial( Enum::FRONT );
00970             glPushMatrix();
00971                 glTranslatef( 
00972                     static_cast<float>( m_prVertex[i][0] ),
00973                     static_cast<float>( m_prVertex[i][1] ),
00974                     static_cast<float>( m_prVertex[i][2] ) 
00975                 );
00976                 glScalef( sphereRadius, sphereRadius, sphereRadius );
00977                 glCallList( m_uiDisplayList );
00978             glPopMatrix();
00979         }
00980     }
00981 #endif//TAPs_ADVANCED_SIMULATION
00982 
00983 }
00984 /*
00985 //------------------------------------------------------------------------------
00986 // Helper Fn
00987 // DrawTorsions Fn
00988 template <typename T>
00989 void OpenGLModelSutureMath<T>::DrawTorsions ()
00990 {
00991     Vector3<T> unitZ( 0, 0, 1 );
00992     Vector3<T> direction;
00993     T currentLinkLength;
00994     Vector3<T> rotDir;
00995     T angle;
00996 //  Math<T>::PI;    // Initialize Math<T>::PI
00997     //----------------------------------------------------------------
00998     SetMaterial( Enum::RED );
00999     ApplyMaterial( Enum::FRONT );
01000     for ( int i = 0; i <= m_iNoLinks; ++i ) {
01001         direction = m_prVertex[i+1] - m_prVertex[i];
01002         currentLinkLength = direction.Length();
01003         direction.Normalized();
01004         angle  = acos( unitZ * direction ) * Math<T>::RAD_TO_DEG;
01005         rotDir = unitZ ^ direction;
01006         //------------------------------------------------------
01007         glPushMatrix();
01008         glTranslatef( 
01009             static_cast<float>( m_prVertex[i][0] ),
01010             static_cast<float>( m_prVertex[i][1] ),
01011             static_cast<float>( m_prVertex[i][2] ) );
01012         glRotatef(
01013             m_prDegRot[i],
01014             static_cast<float>( m_prVertex[i][0] ),
01015             static_cast<float>( m_prVertex[i][1] ),
01016             static_cast<float>( m_prVertex[i][2] )
01017         );
01018         glScalef( 0.03, 0.03, 0.03 );
01019         Obj::DrawOneHeadArrow();
01020         glPopMatrix();
01021     }
01022 }
01023 //*/
01024 //------------------------------------------------------------------------------
01025 // Helper Fn
01026 // void SetUpOpenGLDisplayList ()
01027 template <typename T>
01028 void OpenGLModelSutureMath<T>::SetUpOpenGLDisplayList ()
01029 {
01030     if ( !m_uiDisplayList ) {
01031         m_uiDisplayList = glGenLists( 2 );
01032         GLUquadricObj *qObj = gluNewQuadric();
01033         //------------------------------------------------------------
01034         // Sphere with strand radius
01035         glNewList( m_uiDisplayList, GL_COMPILE );
01036             //gluSphere( qObj, m_tRadius, m_iNumSlices, m_iNumStacks );
01037             gluSphere( qObj,   1.0, m_iNumSlices, m_iNumStacks );
01038         glEndList();
01039         //------------------------------------------------------------
01040         // Cylinder with strand radius and length one which must be 
01041         // scaled by the current link length of each link in 
01042         // z-coordinate
01043         glNewList( m_uiDisplayList+1, GL_COMPILE );
01044             //gluCylinder( qObj, m_tRadius, m_tRadius, 1.0, m_iNumSlices, m_iNumStacks );
01045             gluCylinder( qObj,   1.0,       1.0,       1.0, m_iNumSlices, m_iNumStacks );
01046         glEndList();
01047         gluDeleteQuadric( qObj );
01048     }
01049 }
01050 //------------------------------------------------------------------------------
01051 //==============================================================================
01052 END_NAMESPACE_TAPs__OpenGL
01053 //------------------------------------------------------------------------------
01054 //345678901234567890123456789012345678901234567890123456789012345678901234567890
01055 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines