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