![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsOpenGLHalfEdgeModel.cpp 00003 00004 Class OpenGLHalfEdgeModel is for creating an OpenGL Polygonal Model using 00005 half-edge data structure. 00006 00007 SUKITTI PUNAK (04/05/2005) 00008 UPDATE (05/01/2006) 00009 ******************************************************************************/ 00010 #include "TAPsOpenGLHalfEdgeModel.hpp" 00011 // Using Inclusion Model (i.e. definitions are included in declarations) 00012 // (this name.cpp is included in name.hpp) 00013 // Each friend is defined directly inside its declaration. 00014 00015 BEGIN_NAMESPACE_TAPs__OpenGL 00016 //============================================================================= 00017 //----------------------------------------------------------------------------- 00018 // default constructor 00019 template <typename T> 00020 OpenGLHalfEdgeModel<T>::OpenGLHalfEdgeModel() 00021 : HalfEdgeModel<T>(), bIsDisplayVertexNormals( false ) 00022 { 00023 #ifdef TAPs_DEBUG_MODE 00024 std::cout << "OpenGLHalfEdgeModel<" << typeid(T).name() << "> constructor\n"; 00025 #endif//TAPs_DEBUG_MODE 00026 00027 gCount = 0; 00028 } 00029 //----------------------------------------------------------------------------- 00030 // destructor 00031 template <typename T> 00032 OpenGLHalfEdgeModel<T>::~OpenGLHalfEdgeModel() 00033 { 00034 #ifdef TAPs_DEBUG_MODE 00035 std::cout << "OpenGLHalfEdgeModel<" << typeid(T).name() << "> destructor\n"; 00036 #endif//TAPs_DEBUG_MODE 00037 } 00038 //----------------------------------------------------------------------------- 00039 // Helper Fn 00040 // void DrawGL() 00041 template <typename T> 00042 void OpenGLHalfEdgeModel<T>::DrawGL ( GLenum drawMode ) 00043 { 00044 #ifdef TAPs_USE_DATA_POOL 00045 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 00046 #endif//TAPs_USE_DATA_POOL 00047 //---------------------------------------------------------------- 00048 //if ( true ) { 00049 if ( drawMode == OpenGL::Enum::POINT ) { 00050 00051 #ifdef TAPs_USE_DATA_POOL 00052 glEnableClientState( GL_VERTEX_ARRAY ); 00053 if ( typeid(T) == typeid(float) ) 00054 { 00055 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00056 } 00057 else //if ( typeid(T) == typeid(double) ) 00058 { 00059 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00060 } 00061 glPointSize( 2 ); 00062 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 00063 00064 #else //TAPs_USE_DATA_POOL 00065 HEVertex<T> *ptr = m_listVertex->Head(); 00066 glBegin( drawMode ); 00067 while ( ptr != NULL ) { 00068 // Draw the vertex 00069 glVertex3f ( 00070 static_cast<float>( (*ptr)[0] ), 00071 static_cast<float>( (*ptr)[1] ), 00072 static_cast<float>( (*ptr)[2] ) ); 00073 ptr = ptr->Next(); 00074 } 00075 glEnd(); 00076 00077 #endif//TAPs_USE_DATA_POOL 00078 } 00079 else if ( isFacetShading ) { 00080 // Draw the object 00081 //glEnable( GL_TEXTURE_2D ); 00082 HEFace<T> *facePtr = m_listFace->Head(); 00083 HEHalfEdge<T> *halfEdgePtr; 00084 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00085 while ( facePtr != NULL ) { 00086 00087 // Submaterial supported by .ASE 00088 #ifdef TAPs_SUPPORT_ASE_FORMAT 00089 int matID = facePtr->GetMaterialID(); 00090 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00091 this->submaterials[ matID ]->ApplyMaterial(); 00092 } 00093 #endif//TAPs_SUPPORT_ASE_FORMAT 00094 00095 halfEdgePtr = facePtr->IncidentHalfEdge(); 00096 glBegin( drawMode ); 00097 //for ( int i = 0; i < 3; ++i ) { 00098 do { 00100 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00101 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00102 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00103 //} 00104 // Normal of the face 00105 glNormal3f ( 00106 static_cast<float>( facePtr->GetNormal()[0] ), 00107 static_cast<float>( facePtr->GetNormal()[1] ), 00108 static_cast<float>( facePtr->GetNormal()[2] ) 00109 ); 00110 // Draw the vertex 00111 glVertex3f ( 00112 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00113 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00114 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00115 ); 00116 // DEBUG: 00117 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00118 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00119 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00120 //std::cout << "\n"; 00121 halfEdgePtr = halfEdgePtr->Next(); 00122 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00123 //std::cout << "\n"; 00124 //} 00125 glEnd(); 00126 facePtr = facePtr->Next(); 00127 } 00128 00129 // Draw the object 00130 //for ( int i = 0; i < m_iNoFaces; i++ ) 00131 //{ 00132 // glBegin( drawMode ); 00133 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00134 // { 00135 // // Draw texture 00136 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00137 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00138 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00139 // } 00140 // // Normal of the face 00141 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00142 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 00143 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00144 // // Draw the vertex 00145 // glVertex3f ( 00146 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00147 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00148 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00149 // } 00150 // glEnd(); 00151 //} 00153 } 00154 else { 00155 // Draw the object 00156 00157 #ifdef TAPs_USE_DATA_POOL 00158 glEnableClientState( GL_VERTEX_ARRAY ); 00159 glEnableClientState( GL_NORMAL_ARRAY ); 00160 if ( typeid(T) == typeid(float) ) 00161 { 00162 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00163 glNormalPointer( GL_FLOAT, 0, GetArrayOfVertexNormals().GetAddressOfDataNumber(0) ); 00164 } 00165 else //if ( typeid(T) == typeid(double) ) 00166 { 00167 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00168 glNormalPointer( GL_DOUBLE, 0, GetArrayOfVertexNormals().GetAddressOfDataNumber(0) ); 00169 } 00170 00171 #ifdef TAPs_SUPPORT_ASE_FORMAT 00172 int i = 0; 00173 HEFace<T> *facePtr = m_listFace->Head(); 00174 while ( facePtr != NULL ) { 00175 00176 // Submaterial supported by .ASE 00177 int matID = facePtr->GetMaterialID(); 00178 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00179 this->submaterials[ matID ]->ApplyMaterial(); 00180 } 00181 glDrawElements( 00182 GL_TRIANGLES, 00183 3, 00184 GL_UNSIGNED_INT, 00185 GetArrayOfIndexFaces().GetAddressOfDataNumber(i++) 00186 ); 00187 facePtr = facePtr->Next(); 00188 } 00189 #else //TAPs_SUPPORT_ASE_FORMAT 00190 glDrawElements( 00191 GL_TRIANGLES, 00192 GetArrayOfIndexFaces().GetSize()*GetArrayOfIndexFaces().GetStride(), 00193 GL_UNSIGNED_INT, 00194 GetArrayOfIndexFaces().GetAddressOfDataNumber(0) 00195 ); 00196 #endif//TAPs_SUPPORT_ASE_FORMAT 00197 00198 #else //TAPs_USE_DATA_POOL 00199 //glEnable( GL_TEXTURE_2D ); 00200 HEFace<T> *facePtr = m_listFace->Head(); 00201 HEHalfEdge<T> *halfEdgePtr; 00202 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00203 while ( facePtr != NULL ) { 00204 00205 // Submaterial supported by .ASE 00206 #ifdef TAPs_SUPPORT_ASE_FORMAT 00207 int matID = facePtr->GetMaterialID(); 00208 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00209 this->submaterials[ matID ]->ApplyMaterial(); 00210 } 00211 #endif//TAPs_SUPPORT_ASE_FORMAT 00212 00213 halfEdgePtr = facePtr->IncidentHalfEdge(); 00214 glBegin( drawMode ); 00215 //for ( int i = 0; i < 3; ++i ) { 00216 do { 00218 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00219 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00220 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00221 //} 00223 glNormal3f ( 00224 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 00225 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 00226 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 00227 ); 00228 // Draw the vertex 00229 glVertex3f ( 00230 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00231 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00232 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00233 ); 00234 // DEBUG: 00235 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00236 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00237 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00238 //std::cout << "\n"; 00239 halfEdgePtr = halfEdgePtr->Next(); 00240 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00241 //std::cout << "\n"; 00242 //} 00243 glEnd(); 00244 facePtr = facePtr->Next(); 00245 } 00246 00247 #endif//TAPs_USE_DATA_POOL 00248 00251 //for ( int i = 0; i < m_iNoFaces; i++ ) 00252 //{ 00253 // glBegin( drawMode ); 00254 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00255 // { 00256 // // Draw texture 00257 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00258 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00259 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00260 // } 00261 // // Normal of the vertex 00262 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00263 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00264 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00265 // // Draw the vertex 00266 // glVertex3f ( 00267 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00268 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00269 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00270 // } 00271 // glEnd(); 00272 //} 00274 } 00275 00276 // Draw Boundary 00277 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 00278 //if ( true ) { 00279 // glColor3f( 1.0f, 0.0f, 0.0f ); 00280 // glDisable( GL_LIGHTING ); 00281 // glBegin( GL_LINES ); 00282 // HEFace<T> *facePtr = m_listFace->Head(); 00283 // HEHalfEdge<T> *halfEdgePtr; 00284 // while ( facePtr != NULL ) { 00285 // halfEdgePtr = facePtr->IncidentHalfEdge(); 00286 // do { 00287 // if ( !halfEdgePtr->Pair() ) { 00288 // // Draw the vertex 00289 // glVertex3f ( 00290 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00291 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00292 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00293 // ); 00294 // glVertex3f ( 00295 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00296 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00297 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00298 // ); 00299 // } 00300 // halfEdgePtr = halfEdgePtr->Next(); 00301 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00302 // facePtr = facePtr->Next(); 00303 // } 00304 // glEnd(); 00305 // glEnable( GL_LIGHTING ); 00306 //} 00307 00308 // Draw Boundary 00309 if ( true ) { 00310 glColor3f( 1.0f, 0.0f, 0.0f ); 00311 glPushAttrib( GL_LIGHTING_BIT ); 00312 glDisable( GL_LIGHTING ); 00313 glBegin( GL_LINES ); 00314 if ( m_listHoleFace != NULL ) { 00315 HEFace<T> *facePtr = m_listHoleFace->Head(); 00316 HEHalfEdge<T> *halfEdgePtr; 00317 while ( facePtr != NULL ) { 00318 halfEdgePtr = facePtr->IncidentHalfEdge(); 00319 do { 00320 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 00321 // Draw the vertex 00322 glVertex3f ( 00323 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00324 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00325 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00326 ); 00327 glVertex3f ( 00328 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00329 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00330 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00331 ); 00332 //} 00333 halfEdgePtr = halfEdgePtr->Next(); 00334 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 00335 facePtr = facePtr->Next(); 00336 } 00337 } 00338 glEnd(); 00339 //glEnable( GL_LIGHTING ); 00340 glPopAttrib(); 00341 } 00342 //--------------------------------------------------------------- 00343 static HEFace<T> * g_pFace = m_listFace->Head(); 00344 //static int gCount = 0; 00345 //int gCount = 0; 00346 static int gCount2 = gCount; 00347 //static clock_t start = clock(), finish, delay; 00348 00349 //--------------------------------------------------------------- 00350 // Draw Vertex Normals 00351 if ( bIsDisplayVertexNormals ) { 00352 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00353 glDisable( GL_LIGHTING ); 00354 glColor3ub( 110, 50, 220 ); 00355 HEVertex<T> * pVertex = GetVertexList()->Head(); 00356 for ( int i = 0; i < GetNoVertices(); ++i ) { 00357 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 00358 pVertex = pVertex->Next(); 00359 } 00360 glPopAttrib(); 00361 } 00362 00363 //--------------------------------------------------------------- 00364 // Draw HalfEdge Loop(s) 00365 if ( bIsDisplayVertexNormals ) { 00366 // For Delay 00367 //delay = clock(); 00368 //if ( delay - start > 100 ) { 00369 // start = delay; 00370 // ++gCount; 00371 //} 00372 //++gCount; 00373 00374 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00375 glDisable( GL_LIGHTING ); 00376 glEnable( GL_COLOR_MATERIAL ); 00377 00378 //glColor3ub( 175, 50, 70 ); 00379 //DrawVertexNormals(); 00380 00381 /* 00382 glColor3ub( 75, 50, 175 ); 00383 DrawHalfEdgeByPrevPtrs(); 00384 00385 glColor3ub( 175, 150, 70 ); 00386 DrawHalfEdgeByNextPtrs(); 00387 //*/ 00388 00389 // while ( g_pFace ) { 00390 if ( g_pFace ) { 00391 HEHalfEdge<T> * pHalfEdge = g_pFace->IncidentHalfEdge(); 00392 HEHalfEdge<T> * pStartHalfEdge = pHalfEdge; 00393 Vector3<T> color[20]; 00394 00395 color[0] = Vector3<T>( 0.0, 1.0, 0.0 ); 00396 color[1] = Vector3<T>( 1.0, 0.0, 0.0 ); 00397 00398 color[2] = Vector3<T>( 0.0, 0.5, 0.0 ); 00399 color[3] = Vector3<T>( 0.5, 1.0, 0.5 ); 00400 00401 color[4] = Vector3<T>( 0.0, 0.0, 0.5 ); 00402 color[5] = Vector3<T>( 0.5, 0.5, 1.0 ); 00403 00404 color[6] = Vector3<T>( 0.5, 0.5, 0.0 ); 00405 color[7] = Vector3<T>( 0.3, 0.5, 0.5 ); 00406 00407 color[8] = Vector3<T>( 0.5, 0.0, 0.0 ); 00408 color[9] = Vector3<T>( 1.0, 0.5, 0.5 ); 00409 00410 int count = 0; 00411 do { 00412 //std::cout << ++count << "\n"; 00413 DrawHalfEdgePairs( pHalfEdge, color[count], color[count+1] ); 00414 count += 2; 00415 if ( count >= 10 ) count = 0; 00416 pHalfEdge = pHalfEdge->Next(); 00417 } while ( pHalfEdge != pStartHalfEdge ); 00418 //if ( gCount % 25 == 0 ) { 00419 if ( gCount > gCount2 ) { 00420 g_pFace = g_pFace->Next(); 00421 gCount2 = gCount; 00422 } 00423 } 00424 else { 00425 g_pFace = m_listFace->Head(); 00426 } 00427 00428 glPopAttrib(); 00429 } 00430 00431 //DrawVertexSimulationStatus(); 00432 00433 // Draw AABB Bounding Box 00434 //DrawBoundingAABB(); 00435 //DrawBoundingEllipsoid(); 00436 //DrawBoundingSphere(); 00437 //---------------------------------------------------------------- 00438 #ifdef TAPs_USE_DATA_POOL 00439 glPopClientAttrib(); 00440 #endif//TAPs_USE_DATA_POOL 00441 } 00442 //----------------------------------------------------------------------------- 00443 00444 00445 00446 00447 00448 //============================================================================= 00449 #ifdef TAPs_ENABLE_FACE_VERTEX_COLOR 00450 //----------------------------------------------------------------------------- 00451 template <typename T> 00452 void OpenGLHalfEdgeModel<T>::DrawGLWithFaceVertexColor_RGB ( GLenum drawMode ) 00453 { 00454 #ifdef TAPs_USE_DATA_POOL 00455 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 00456 #endif//TAPs_USE_DATA_POOL 00457 00458 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 00459 glEnable( GL_COLOR_MATERIAL ); 00460 00461 //---------------------------------------------------------------- 00462 if ( drawMode == OpenGL::Enum::POINT ) { 00463 00464 #ifdef TAPs_USE_DATA_POOL 00465 glEnableClientState( GL_VERTEX_ARRAY ); 00466 if ( typeid(T) == typeid(float) ) 00467 { 00468 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00469 } 00470 else //if ( typeid(T) == typeid(double) ) 00471 { 00472 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00473 } 00474 glPointSize( 2 ); 00475 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 00476 00477 #else //TAPs_USE_DATA_POOL 00478 HEVertex<T> *ptr = m_listVertex->Head(); 00479 glBegin( drawMode ); 00480 while ( ptr != NULL ) { 00481 // Draw the vertex 00482 glVertex3f ( 00483 static_cast<float>( (*ptr)[0] ), 00484 static_cast<float>( (*ptr)[1] ), 00485 static_cast<float>( (*ptr)[2] ) ); 00486 ptr = ptr->Next(); 00487 } 00488 glEnd(); 00489 00490 #endif//TAPs_USE_DATA_POOL 00491 } 00492 else if ( isFacetShading ) { 00493 // Draw the object 00494 //glEnable( GL_TEXTURE_2D ); 00495 HEFace<T> *facePtr = m_listFace->Head(); 00496 HEHalfEdge<T> *halfEdgePtr; 00497 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00498 while ( facePtr != NULL ) { 00499 00500 /* 00501 // Submaterial supported by .ASE 00502 #ifdef TAPs_SUPPORT_ASE_FORMAT 00503 int matID = facePtr->GetMaterialID(); 00504 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00505 this->submaterials[ matID ]->ApplyMaterial(); 00506 } 00507 #endif//TAPs_SUPPORT_ASE_FORMAT 00508 //*/ 00509 00510 halfEdgePtr = facePtr->IncidentHalfEdge(); 00511 int j = 0; 00512 glBegin( drawMode ); 00513 //for ( int i = 0; i < 3; ++i ) { 00514 do { 00516 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00517 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00518 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00519 //} 00520 // Normal of the face 00521 glNormal3f ( 00522 static_cast<float>( facePtr->GetNormal()[0] ), 00523 static_cast<float>( facePtr->GetNormal()[1] ), 00524 static_cast<float>( facePtr->GetNormal()[2] ) 00525 ); 00526 00527 // Vertex color of the face 00528 float VC[3]; 00529 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2] ); 00530 glColor3f ( VC[0], VC[1], VC[2] ); 00531 00532 // Draw the vertex 00533 glVertex3f ( 00534 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00535 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00536 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00537 ); 00538 // DEBUG: 00539 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00540 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00541 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00542 //std::cout << "\n"; 00543 halfEdgePtr = halfEdgePtr->Next(); 00544 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00545 //std::cout << "\n"; 00546 //} 00547 glEnd(); 00548 facePtr = facePtr->Next(); 00549 } 00550 00551 // Draw the object 00552 //for ( int i = 0; i < m_iNoFaces; i++ ) 00553 //{ 00554 // glBegin( drawMode ); 00555 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00556 // { 00557 // // Draw texture 00558 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00559 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00560 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00561 // } 00562 // // Normal of the face 00563 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00564 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 00565 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00566 // // Draw the vertex 00567 // glVertex3f ( 00568 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00569 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00570 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00571 // } 00572 // glEnd(); 00573 //} 00575 } 00576 else { 00577 // Draw the object 00578 00579 #ifdef TAPs_USE_DATA_POOL__ 00580 #else //TAPs_USE_DATA_POOL__ 00581 00582 //glEnable( GL_TEXTURE_2D ); 00583 HEFace<T> *facePtr = m_listFace->Head(); 00584 HEHalfEdge<T> *halfEdgePtr; 00585 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00586 while ( facePtr != NULL ) { 00587 00588 /* 00589 // Submaterial supported by .ASE 00590 #ifdef TAPs_SUPPORT_ASE_FORMAT 00591 int matID = facePtr->GetMaterialID(); 00592 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00593 this->submaterials[ matID ]->ApplyMaterial(); 00594 } 00595 #endif//TAPs_SUPPORT_ASE_FORMAT 00596 //*/ 00597 00598 halfEdgePtr = facePtr->IncidentHalfEdge(); 00599 int j = 0; 00600 glBegin( drawMode ); 00601 //for ( int i = 0; i < 3; ++i ) { 00602 do { 00604 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00605 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00606 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00607 //} 00609 glNormal3f ( 00610 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 00611 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 00612 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 00613 ); 00614 00615 //if ( isFirst ) { 00616 // static int i = 0; 00617 // std::cout << "Face# " << i++ << " V# " << j << ":\t" << halfEdgePtr->Vertex()->GetNormal() << "\n"; 00618 //} 00619 00620 // Vertex color of the face 00621 float VC[3]; 00622 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2] ); 00623 glColor3f ( VC[0], VC[1], VC[2] ); 00624 00625 // Draw the vertex 00626 glVertex3f ( 00627 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00628 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00629 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00630 ); 00631 // DEBUG: 00632 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00633 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00634 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00635 //std::cout << "\n"; 00636 halfEdgePtr = halfEdgePtr->Next(); 00637 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00638 //std::cout << "\n"; 00639 //} 00640 glEnd(); 00641 facePtr = facePtr->Next(); 00642 } 00643 00644 #endif//TAPs_USE_DATA_POOL__ 00645 00648 //for ( int i = 0; i < m_iNoFaces; i++ ) 00649 //{ 00650 // glBegin( drawMode ); 00651 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00652 // { 00653 // // Draw texture 00654 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00655 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00656 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00657 // } 00658 // // Normal of the vertex 00659 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00660 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00661 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00662 // // Draw the vertex 00663 // glVertex3f ( 00664 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00665 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00666 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00667 // } 00668 // glEnd(); 00669 //} 00671 } 00672 00673 glPopAttrib(); 00674 00675 // Draw Boundary 00676 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 00677 //if ( true ) { 00678 // glColor3f( 1.0f, 0.0f, 0.0f ); 00679 // glDisable( GL_LIGHTING ); 00680 // glBegin( GL_LINES ); 00681 // HEFace<T> *facePtr = m_listFace->Head(); 00682 // HEHalfEdge<T> *halfEdgePtr; 00683 // while ( facePtr != NULL ) { 00684 // halfEdgePtr = facePtr->IncidentHalfEdge(); 00685 // do { 00686 // if ( !halfEdgePtr->Pair() ) { 00687 // // Draw the vertex 00688 // glVertex3f ( 00689 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00690 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00691 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00692 // ); 00693 // glVertex3f ( 00694 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00695 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00696 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00697 // ); 00698 // } 00699 // halfEdgePtr = halfEdgePtr->Next(); 00700 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00701 // facePtr = facePtr->Next(); 00702 // } 00703 // glEnd(); 00704 // glEnable( GL_LIGHTING ); 00705 //} 00706 00707 // Draw Boundary 00708 if ( true ) { 00709 glColor3f( 1.0f, 0.0f, 0.0f ); 00710 glPushAttrib( GL_LIGHTING_BIT ); 00711 glDisable( GL_LIGHTING ); 00712 glBegin( GL_LINES ); 00713 if ( m_listHoleFace != NULL ) { 00714 HEFace<T> *facePtr = m_listHoleFace->Head(); 00715 HEHalfEdge<T> *halfEdgePtr; 00716 while ( facePtr != NULL ) { 00717 halfEdgePtr = facePtr->IncidentHalfEdge(); 00718 do { 00719 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 00720 // Draw the vertex 00721 glVertex3f ( 00722 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00723 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00724 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00725 ); 00726 glVertex3f ( 00727 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 00728 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 00729 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 00730 ); 00731 //} 00732 halfEdgePtr = halfEdgePtr->Next(); 00733 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 00734 facePtr = facePtr->Next(); 00735 } 00736 } 00737 glEnd(); 00738 //glEnable( GL_LIGHTING ); 00739 glPopAttrib(); 00740 } 00741 //--------------------------------------------------------------- 00742 static HEFace<T> * g_pFace = m_listFace->Head(); 00743 //static int gCount = 0; 00744 //int gCount = 0; 00745 static int gCount2 = gCount; 00746 //static clock_t start = clock(), finish, delay; 00747 00748 //--------------------------------------------------------------- 00749 // Draw Vertex Normals 00750 if ( bIsDisplayVertexNormals ) { 00751 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00752 glDisable( GL_LIGHTING ); 00753 glColor3ub( 110, 50, 220 ); 00754 HEVertex<T> * pVertex = GetVertexList()->Head(); 00755 for ( int i = 0; i < GetNoVertices(); ++i ) { 00756 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 00757 pVertex = pVertex->Next(); 00758 } 00759 glPopAttrib(); 00760 } 00761 00762 //--------------------------------------------------------------- 00763 // Draw HalfEdge Loop(s) 00764 if ( bIsDisplayVertexNormals ) { 00765 // For Delay 00766 //delay = clock(); 00767 //if ( delay - start > 100 ) { 00768 // start = delay; 00769 // ++gCount; 00770 //} 00771 //++gCount; 00772 00773 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00774 glDisable( GL_LIGHTING ); 00775 glEnable( GL_COLOR_MATERIAL ); 00776 00777 //glColor3ub( 175, 50, 70 ); 00778 //DrawVertexNormals(); 00779 00780 /* 00781 glColor3ub( 75, 50, 175 ); 00782 DrawHalfEdgeByPrevPtrs(); 00783 00784 glColor3ub( 175, 150, 70 ); 00785 DrawHalfEdgeByNextPtrs(); 00786 //*/ 00787 00788 // while ( g_pFace ) { 00789 if ( g_pFace ) { 00790 HEHalfEdge<T> * pHalfEdge = g_pFace->IncidentHalfEdge(); 00791 HEHalfEdge<T> * pStartHalfEdge = pHalfEdge; 00792 Vector3<T> color[20]; 00793 00794 color[0] = Vector3<T>( 0.0, 1.0, 0.0 ); 00795 color[1] = Vector3<T>( 1.0, 0.0, 0.0 ); 00796 00797 color[2] = Vector3<T>( 0.0, 0.5, 0.0 ); 00798 color[3] = Vector3<T>( 0.5, 1.0, 0.5 ); 00799 00800 color[4] = Vector3<T>( 0.0, 0.0, 0.5 ); 00801 color[5] = Vector3<T>( 0.5, 0.5, 1.0 ); 00802 00803 color[6] = Vector3<T>( 0.5, 0.5, 0.0 ); 00804 color[7] = Vector3<T>( 0.3, 0.5, 0.5 ); 00805 00806 color[8] = Vector3<T>( 0.5, 0.0, 0.0 ); 00807 color[9] = Vector3<T>( 1.0, 0.5, 0.5 ); 00808 00809 int count = 0; 00810 do { 00811 //std::cout << ++count << "\n"; 00812 DrawHalfEdgePairs( pHalfEdge, color[count], color[count+1] ); 00813 count += 2; 00814 if ( count >= 10 ) count = 0; 00815 pHalfEdge = pHalfEdge->Next(); 00816 } while ( pHalfEdge != pStartHalfEdge ); 00817 //if ( gCount % 25 == 0 ) { 00818 if ( gCount > gCount2 ) { 00819 g_pFace = g_pFace->Next(); 00820 gCount2 = gCount; 00821 } 00822 } 00823 else { 00824 g_pFace = m_listFace->Head(); 00825 } 00826 00827 glPopAttrib(); 00828 } 00829 00830 //DrawVertexSimulationStatus(); 00831 00832 // Draw AABB Bounding Box 00833 //DrawBoundingAABB(); 00834 //DrawBoundingEllipsoid(); 00835 //DrawBoundingSphere(); 00836 //---------------------------------------------------------------- 00837 #ifdef TAPs_USE_DATA_POOL 00838 glPopClientAttrib(); 00839 #endif//TAPs_USE_DATA_POOL 00840 } 00841 //----------------------------------------------------------------------------- 00842 template <typename T> 00843 void OpenGLHalfEdgeModel<T>::DrawGLWithFaceVertexColor_RGBA ( GLenum drawMode ) 00844 { 00845 #ifdef TAPs_USE_DATA_POOL 00846 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 00847 #endif//TAPs_USE_DATA_POOL 00848 00849 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 00850 glEnable( GL_COLOR_MATERIAL ); 00851 00852 //---------------------------------------------------------------- 00853 if ( drawMode == OpenGL::Enum::POINT ) { 00854 00855 #ifdef TAPs_USE_DATA_POOL 00856 glEnableClientState( GL_VERTEX_ARRAY ); 00857 if ( typeid(T) == typeid(float) ) 00858 { 00859 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00860 } 00861 else //if ( typeid(T) == typeid(double) ) 00862 { 00863 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 00864 } 00865 glPointSize( 2 ); 00866 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 00867 00868 #else //TAPs_USE_DATA_POOL 00869 HEVertex<T> *ptr = m_listVertex->Head(); 00870 glBegin( drawMode ); 00871 while ( ptr != NULL ) { 00872 // Draw the vertex 00873 glVertex3f ( 00874 static_cast<float>( (*ptr)[0] ), 00875 static_cast<float>( (*ptr)[1] ), 00876 static_cast<float>( (*ptr)[2] ) ); 00877 ptr = ptr->Next(); 00878 } 00879 glEnd(); 00880 00881 #endif//TAPs_USE_DATA_POOL 00882 } 00883 else if ( isFacetShading ) { 00884 // Draw the object 00885 //glEnable( GL_TEXTURE_2D ); 00886 HEFace<T> *facePtr = m_listFace->Head(); 00887 HEHalfEdge<T> *halfEdgePtr; 00888 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00889 while ( facePtr != NULL ) { 00890 00891 /* 00892 // Submaterial supported by .ASE 00893 #ifdef TAPs_SUPPORT_ASE_FORMAT 00894 int matID = facePtr->GetMaterialID(); 00895 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00896 this->submaterials[ matID ]->ApplyMaterial(); 00897 } 00898 #endif//TAPs_SUPPORT_ASE_FORMAT 00899 //*/ 00900 00901 halfEdgePtr = facePtr->IncidentHalfEdge(); 00902 int j = 0; 00903 glBegin( drawMode ); 00904 //for ( int i = 0; i < 3; ++i ) { 00905 do { 00907 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00908 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00909 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00910 //} 00911 // Normal of the face 00912 glNormal3f ( 00913 static_cast<float>( facePtr->GetNormal()[0] ), 00914 static_cast<float>( facePtr->GetNormal()[1] ), 00915 static_cast<float>( facePtr->GetNormal()[2] ) 00916 ); 00917 00918 // Vertex color of the face 00919 float VC[4]; 00920 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2], &VC[3] ); 00921 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 00922 00923 // Draw the vertex 00924 glVertex3f ( 00925 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 00926 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 00927 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 00928 ); 00929 // DEBUG: 00930 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 00931 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 00932 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 00933 //std::cout << "\n"; 00934 halfEdgePtr = halfEdgePtr->Next(); 00935 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 00936 //std::cout << "\n"; 00937 //} 00938 glEnd(); 00939 facePtr = facePtr->Next(); 00940 } 00941 00942 // Draw the object 00943 //for ( int i = 0; i < m_iNoFaces; i++ ) 00944 //{ 00945 // glBegin( drawMode ); 00946 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00947 // { 00948 // // Draw texture 00949 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00950 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00951 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00952 // } 00953 // // Normal of the face 00954 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00955 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 00956 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00957 // // Draw the vertex 00958 // glVertex3f ( 00959 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00960 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00961 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00962 // } 00963 // glEnd(); 00964 //} 00966 } 00967 else { 00968 // Draw the object 00969 00970 #ifdef TAPs_USE_DATA_POOL__ 00971 #else //TAPs_USE_DATA_POOL__ 00972 00973 //glEnable( GL_TEXTURE_2D ); 00974 HEFace<T> *facePtr = m_listFace->Head(); 00975 HEHalfEdge<T> *halfEdgePtr; 00976 //for ( int f = 0; f < GetNoFaces(); ++f ) { 00977 while ( facePtr != NULL ) { 00978 00979 /* 00980 // Submaterial supported by .ASE 00981 #ifdef TAPs_SUPPORT_ASE_FORMAT 00982 int matID = facePtr->GetMaterialID(); 00983 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 00984 this->submaterials[ matID ]->ApplyMaterial(); 00985 } 00986 #endif//TAPs_SUPPORT_ASE_FORMAT 00987 //*/ 00988 00989 halfEdgePtr = facePtr->IncidentHalfEdge(); 00990 int j = 0; 00991 glBegin( drawMode ); 00992 //for ( int i = 0; i < 3; ++i ) { 00993 do { 00995 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00996 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00997 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00998 //} 01000 glNormal3f ( 01001 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 01002 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 01003 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 01004 ); 01005 01006 //if ( isFirst ) { 01007 // static int i = 0; 01008 // std::cout << "Face# " << i++ << " V# " << j << ":\t" << halfEdgePtr->Vertex()->GetNormal() << "\n"; 01009 //} 01010 01011 // Vertex color of the face 01012 float VC[4]; 01013 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2], &VC[3] ); 01014 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 01015 01016 // Draw the vertex 01017 glVertex3f ( 01018 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01019 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01020 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01021 ); 01022 // DEBUG: 01023 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01024 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01025 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01026 //std::cout << "\n"; 01027 halfEdgePtr = halfEdgePtr->Next(); 01028 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01029 //std::cout << "\n"; 01030 //} 01031 glEnd(); 01032 facePtr = facePtr->Next(); 01033 } 01034 01035 #endif//TAPs_USE_DATA_POOL__ 01036 01039 //for ( int i = 0; i < m_iNoFaces; i++ ) 01040 //{ 01041 // glBegin( drawMode ); 01042 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01043 // { 01044 // // Draw texture 01045 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01046 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01047 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01048 // } 01049 // // Normal of the vertex 01050 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 01051 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 01052 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 01053 // // Draw the vertex 01054 // glVertex3f ( 01055 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01056 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01057 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01058 // } 01059 // glEnd(); 01060 //} 01062 } 01063 01064 glPopAttrib(); 01065 01066 //isFirst = false; 01067 01068 // Draw Boundary 01069 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 01070 //if ( true ) { 01071 // glColor3f( 1.0f, 0.0f, 0.0f ); 01072 // glDisable( GL_LIGHTING ); 01073 // glBegin( GL_LINES ); 01074 // HEFace<T> *facePtr = m_listFace->Head(); 01075 // HEHalfEdge<T> *halfEdgePtr; 01076 // while ( facePtr != NULL ) { 01077 // halfEdgePtr = facePtr->IncidentHalfEdge(); 01078 // do { 01079 // if ( !halfEdgePtr->Pair() ) { 01080 // // Draw the vertex 01081 // glVertex3f ( 01082 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01083 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01084 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01085 // ); 01086 // glVertex3f ( 01087 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01088 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01089 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01090 // ); 01091 // } 01092 // halfEdgePtr = halfEdgePtr->Next(); 01093 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01094 // facePtr = facePtr->Next(); 01095 // } 01096 // glEnd(); 01097 // glEnable( GL_LIGHTING ); 01098 //} 01099 01100 // Draw Boundary 01101 if ( true ) { 01102 glColor3f( 1.0f, 0.0f, 0.0f ); 01103 glPushAttrib( GL_LIGHTING_BIT ); 01104 glDisable( GL_LIGHTING ); 01105 glBegin( GL_LINES ); 01106 if ( m_listHoleFace != NULL ) { 01107 HEFace<T> *facePtr = m_listHoleFace->Head(); 01108 HEHalfEdge<T> *halfEdgePtr; 01109 while ( facePtr != NULL ) { 01110 halfEdgePtr = facePtr->IncidentHalfEdge(); 01111 do { 01112 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 01113 // Draw the vertex 01114 glVertex3f ( 01115 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01116 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01117 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01118 ); 01119 glVertex3f ( 01120 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01121 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01122 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01123 ); 01124 //} 01125 halfEdgePtr = halfEdgePtr->Next(); 01126 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 01127 facePtr = facePtr->Next(); 01128 } 01129 } 01130 glEnd(); 01131 //glEnable( GL_LIGHTING ); 01132 glPopAttrib(); 01133 } 01134 //--------------------------------------------------------------- 01135 static HEFace<T> * g_pFace = m_listFace->Head(); 01136 //static int gCount = 0; 01137 //int gCount = 0; 01138 static int gCount2 = gCount; 01139 //static clock_t start = clock(), finish, delay; 01140 01141 //--------------------------------------------------------------- 01142 // Draw Vertex Normals 01143 if ( bIsDisplayVertexNormals ) { 01144 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01145 glDisable( GL_LIGHTING ); 01146 glColor3ub( 110, 50, 220 ); 01147 HEVertex<T> * pVertex = GetVertexList()->Head(); 01148 for ( int i = 0; i < GetNoVertices(); ++i ) { 01149 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 01150 pVertex = pVertex->Next(); 01151 } 01152 glPopAttrib(); 01153 } 01154 01155 //--------------------------------------------------------------- 01156 // Draw HalfEdge Loop(s) 01157 if ( bIsDisplayVertexNormals ) { 01158 // For Delay 01159 //delay = clock(); 01160 //if ( delay - start > 100 ) { 01161 // start = delay; 01162 // ++gCount; 01163 //} 01164 //++gCount; 01165 01166 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01167 glDisable( GL_LIGHTING ); 01168 glEnable( GL_COLOR_MATERIAL ); 01169 01170 //glColor3ub( 175, 50, 70 ); 01171 //DrawVertexNormals(); 01172 01173 /* 01174 glColor3ub( 75, 50, 175 ); 01175 DrawHalfEdgeByPrevPtrs(); 01176 01177 glColor3ub( 175, 150, 70 ); 01178 DrawHalfEdgeByNextPtrs(); 01179 //*/ 01180 01181 // while ( g_pFace ) { 01182 if ( g_pFace ) { 01183 HEHalfEdge<T> * pHalfEdge = g_pFace->IncidentHalfEdge(); 01184 HEHalfEdge<T> * pStartHalfEdge = pHalfEdge; 01185 Vector3<T> color[20]; 01186 01187 color[0] = Vector3<T>( 0.0, 1.0, 0.0 ); 01188 color[1] = Vector3<T>( 1.0, 0.0, 0.0 ); 01189 01190 color[2] = Vector3<T>( 0.0, 0.5, 0.0 ); 01191 color[3] = Vector3<T>( 0.5, 1.0, 0.5 ); 01192 01193 color[4] = Vector3<T>( 0.0, 0.0, 0.5 ); 01194 color[5] = Vector3<T>( 0.5, 0.5, 1.0 ); 01195 01196 color[6] = Vector3<T>( 0.5, 0.5, 0.0 ); 01197 color[7] = Vector3<T>( 0.3, 0.5, 0.5 ); 01198 01199 color[8] = Vector3<T>( 0.5, 0.0, 0.0 ); 01200 color[9] = Vector3<T>( 1.0, 0.5, 0.5 ); 01201 01202 int count = 0; 01203 do { 01204 //std::cout << ++count << "\n"; 01205 DrawHalfEdgePairs( pHalfEdge, color[count], color[count+1] ); 01206 count += 2; 01207 if ( count >= 10 ) count = 0; 01208 pHalfEdge = pHalfEdge->Next(); 01209 } while ( pHalfEdge != pStartHalfEdge ); 01210 //if ( gCount % 25 == 0 ) { 01211 if ( gCount > gCount2 ) { 01212 g_pFace = g_pFace->Next(); 01213 gCount2 = gCount; 01214 } 01215 } 01216 else { 01217 g_pFace = m_listFace->Head(); 01218 } 01219 01220 glPopAttrib(); 01221 } 01222 01223 //DrawVertexSimulationStatus(); 01224 01225 // Draw AABB Bounding Box 01226 //DrawBoundingAABB(); 01227 //DrawBoundingEllipsoid(); 01228 //DrawBoundingSphere(); 01229 //---------------------------------------------------------------- 01230 #ifdef TAPs_USE_DATA_POOL 01231 glPopClientAttrib(); 01232 #endif//TAPs_USE_DATA_POOL 01233 } 01234 //----------------------------------------------------------------------------- 01235 template <typename T> 01236 bool OpenGLHalfEdgeModel<T>::EnableVertexColors ( bool b ) 01237 { 01238 if ( m_svVertexColors.size() == 0 ) m_bEnableVertexColor = false; 01239 else m_bEnableVertexColor = b; 01240 return m_bEnableVertexColor; 01241 } 01242 //----------------------------------------------------------------------------- 01243 #endif//TAPs_ENABLE_FACE_VERTEX_COLOR 01244 //============================================================================= 01245 01246 01247 01248 01249 01250 01251 01252 01253 01254 01255 01256 01257 01258 01259 01260 01261 //============================================================================= 01262 #ifdef TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 01263 //----------------------------------------------------------------------------- 01264 template <typename T> 01265 void OpenGLHalfEdgeModel<T>::DrawGLSLWithDSFaceVertex_RGB ( GLenum drawMode ) 01266 { 01267 //assert( ShaderProgram ); 01268 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->BeginGLSL(); 01269 GlobalGLSLShaderPool::SetShaderParameters( ShaderName ); 01270 01271 #ifdef TAPs_USE_DATA_POOL 01272 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 01273 #endif//TAPs_USE_DATA_POOL 01274 01275 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 01276 01277 //---------------------------------------------------------------- 01278 if ( drawMode == OpenGL::Enum::POINT ) { 01279 01280 #ifdef TAPs_USE_DATA_POOL 01281 glEnableClientState( GL_VERTEX_ARRAY ); 01282 if ( typeid(T) == typeid(float) ) 01283 { 01284 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 01285 } 01286 else //if ( typeid(T) == typeid(double) ) 01287 { 01288 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 01289 } 01290 glPointSize( 2 ); 01291 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 01292 01293 #else //TAPs_USE_DATA_POOL 01294 HEVertex<T> *ptr = m_listVertex->Head(); 01295 glBegin( drawMode ); 01296 while ( ptr != NULL ) { 01297 // Draw the vertex 01298 glVertex3f ( 01299 static_cast<float>( (*ptr)[0] ), 01300 static_cast<float>( (*ptr)[1] ), 01301 static_cast<float>( (*ptr)[2] ) ); 01302 ptr = ptr->Next(); 01303 } 01304 glEnd(); 01305 01306 #endif//TAPs_USE_DATA_POOL 01307 } 01308 else if ( isFacetShading ) { 01309 // Draw the object 01310 //glEnable( GL_TEXTURE_2D ); 01311 HEFace<T> *facePtr = m_listFace->Head(); 01312 HEHalfEdge<T> *halfEdgePtr; 01313 //for ( int f = 0; f < GetNoFaces(); ++f ) { 01314 while ( facePtr != NULL ) { 01315 01316 /* 01317 // Submaterial supported by .ASE 01318 #ifdef TAPs_SUPPORT_ASE_FORMAT 01319 int matID = facePtr->GetMaterialID(); 01320 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 01321 this->submaterials[ matID ]->ApplyMaterial(); 01322 } 01323 #endif//TAPs_SUPPORT_ASE_FORMAT 01324 //*/ 01325 01326 halfEdgePtr = facePtr->IncidentHalfEdge(); 01327 int j = 0; 01328 glBegin( drawMode ); 01329 //for ( int i = 0; i < 3; ++i ) { 01330 do { 01332 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01333 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01334 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01335 //} 01336 // Normal of the face 01337 glNormal3f ( 01338 static_cast<float>( facePtr->GetNormal()[0] ), 01339 static_cast<float>( facePtr->GetNormal()[1] ), 01340 static_cast<float>( facePtr->GetNormal()[2] ) 01341 ); 01342 01343 /* 01344 // Vertex color of the face 01345 float VC[3]; 01346 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2] ); 01347 glColor3f ( VC[0], VC[1], VC[2] ); 01348 //*/ 01349 01350 // Draw the vertex 01351 glVertex3f ( 01352 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01353 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01354 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01355 ); 01356 // DEBUG: 01357 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01358 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01359 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01360 //std::cout << "\n"; 01361 halfEdgePtr = halfEdgePtr->Next(); 01362 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01363 //std::cout << "\n"; 01364 //} 01365 glEnd(); 01366 facePtr = facePtr->Next(); 01367 } 01368 01369 // Draw the object 01370 //for ( int i = 0; i < m_iNoFaces; i++ ) 01371 //{ 01372 // glBegin( drawMode ); 01373 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01374 // { 01375 // // Draw texture 01376 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01377 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01378 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01379 // } 01380 // // Normal of the face 01381 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 01382 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 01383 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 01384 // // Draw the vertex 01385 // glVertex3f ( 01386 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01387 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01388 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01389 // } 01390 // glEnd(); 01391 //} 01393 } 01394 else { 01395 // Draw the object 01396 01397 #ifdef TAPs_USE_DATA_POOL__ 01398 #else //TAPs_USE_DATA_POOL__ 01399 01400 //glEnable( GL_TEXTURE_2D ); 01401 HEFace<T> *facePtr = m_listFace->Head(); 01402 HEHalfEdge<T> *halfEdgePtr; 01403 //for ( int f = 0; f < GetNoFaces(); ++f ) { 01404 while ( facePtr != NULL ) { 01405 01406 /* 01407 // Submaterial supported by .ASE 01408 #ifdef TAPs_SUPPORT_ASE_FORMAT 01409 int matID = facePtr->GetMaterialID(); 01410 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 01411 this->submaterials[ matID ]->ApplyMaterial(); 01412 } 01413 #endif//TAPs_SUPPORT_ASE_FORMAT 01414 //*/ 01415 01416 halfEdgePtr = facePtr->IncidentHalfEdge(); 01417 int j = 0; 01418 glBegin( drawMode ); 01419 //for ( int i = 0; i < 3; ++i ) { 01420 do { 01422 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01423 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01424 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01425 //} 01427 glNormal3f ( 01428 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 01429 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 01430 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 01431 ); 01432 01433 //if ( isFirst ) { 01434 // static int i = 0; 01435 // std::cout << "Face# " << i++ << " V# " << j << ":\t" << halfEdgePtr->Vertex()->GetNormal() << "\n"; 01436 //} 01437 01438 /* 01439 // Vertex color of the face 01440 float VC[3]; 01441 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2] ); 01442 glColor3f ( VC[0], VC[1], VC[2] ); 01443 //*/ 01444 01445 // Draw the vertex 01446 glVertex3f ( 01447 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01448 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01449 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01450 ); 01451 // DEBUG: 01452 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01453 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01454 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01455 //std::cout << "\n"; 01456 halfEdgePtr = halfEdgePtr->Next(); 01457 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01458 //std::cout << "\n"; 01459 //} 01460 glEnd(); 01461 facePtr = facePtr->Next(); 01462 } 01463 01464 #endif//TAPs_USE_DATA_POOL__ 01465 01468 //for ( int i = 0; i < m_iNoFaces; i++ ) 01469 //{ 01470 // glBegin( drawMode ); 01471 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01472 // { 01473 // // Draw texture 01474 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01475 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01476 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01477 // } 01478 // // Normal of the vertex 01479 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 01480 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 01481 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 01482 // // Draw the vertex 01483 // glVertex3f ( 01484 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01485 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01486 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01487 // } 01488 // glEnd(); 01489 //} 01491 } 01492 01493 glPopAttrib(); 01494 01495 // Draw Boundary 01496 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 01497 //if ( true ) { 01498 // glColor3f( 1.0f, 0.0f, 0.0f ); 01499 // glDisable( GL_LIGHTING ); 01500 // glBegin( GL_LINES ); 01501 // HEFace<T> *facePtr = m_listFace->Head(); 01502 // HEHalfEdge<T> *halfEdgePtr; 01503 // while ( facePtr != NULL ) { 01504 // halfEdgePtr = facePtr->IncidentHalfEdge(); 01505 // do { 01506 // if ( !halfEdgePtr->Pair() ) { 01507 // // Draw the vertex 01508 // glVertex3f ( 01509 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01510 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01511 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01512 // ); 01513 // glVertex3f ( 01514 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01515 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01516 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01517 // ); 01518 // } 01519 // halfEdgePtr = halfEdgePtr->Next(); 01520 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01521 // facePtr = facePtr->Next(); 01522 // } 01523 // glEnd(); 01524 // glEnable( GL_LIGHTING ); 01525 //} 01526 01527 // Draw Boundary 01528 if ( true ) { 01529 glColor3f( 1.0f, 0.0f, 0.0f ); 01530 glPushAttrib( GL_LIGHTING_BIT ); 01531 glDisable( GL_LIGHTING ); 01532 glBegin( GL_LINES ); 01533 if ( m_listHoleFace != NULL ) { 01534 HEFace<T> *facePtr = m_listHoleFace->Head(); 01535 HEHalfEdge<T> *halfEdgePtr; 01536 while ( facePtr != NULL ) { 01537 halfEdgePtr = facePtr->IncidentHalfEdge(); 01538 do { 01539 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 01540 // Draw the vertex 01541 glVertex3f ( 01542 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01543 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01544 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01545 ); 01546 glVertex3f ( 01547 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01548 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01549 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01550 ); 01551 //} 01552 halfEdgePtr = halfEdgePtr->Next(); 01553 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 01554 facePtr = facePtr->Next(); 01555 } 01556 } 01557 glEnd(); 01558 //glEnable( GL_LIGHTING ); 01559 glPopAttrib(); 01560 } 01561 //--------------------------------------------------------------- 01562 static HEFace<T> * g_pFace = m_listFace->Head(); 01563 //static int gCount = 0; 01564 //int gCount = 0; 01565 static int gCount2 = gCount; 01566 //static clock_t start = clock(), finish, delay; 01567 01568 //--------------------------------------------------------------- 01569 // Draw Vertex Normals 01570 if ( bIsDisplayVertexNormals ) { 01571 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01572 glDisable( GL_LIGHTING ); 01573 glColor3ub( 110, 50, 220 ); 01574 HEVertex<T> * pVertex = GetVertexList()->Head(); 01575 for ( int i = 0; i < GetNoVertices(); ++i ) { 01576 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 01577 pVertex = pVertex->Next(); 01578 } 01579 glPopAttrib(); 01580 } 01581 01582 //--------------------------------------------------------------- 01583 // Draw HalfEdge Loop(s) 01584 if ( bIsDisplayVertexNormals ) { 01585 // For Delay 01586 //delay = clock(); 01587 //if ( delay - start > 100 ) { 01588 // start = delay; 01589 // ++gCount; 01590 //} 01591 //++gCount; 01592 01593 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01594 glDisable( GL_LIGHTING ); 01595 glEnable( GL_COLOR_MATERIAL ); 01596 01597 //glColor3ub( 175, 50, 70 ); 01598 //DrawVertexNormals(); 01599 01600 /* 01601 glColor3ub( 75, 50, 175 ); 01602 DrawHalfEdgeByPrevPtrs(); 01603 01604 glColor3ub( 175, 150, 70 ); 01605 DrawHalfEdgeByNextPtrs(); 01606 //*/ 01607 01608 // while ( g_pFace ) { 01609 if ( g_pFace ) { 01610 HEHalfEdge<T> * pHalfEdge = g_pFace->IncidentHalfEdge(); 01611 HEHalfEdge<T> * pStartHalfEdge = pHalfEdge; 01612 Vector3<T> color[20]; 01613 01614 color[0] = Vector3<T>( 0.0, 1.0, 0.0 ); 01615 color[1] = Vector3<T>( 1.0, 0.0, 0.0 ); 01616 01617 color[2] = Vector3<T>( 0.0, 0.5, 0.0 ); 01618 color[3] = Vector3<T>( 0.5, 1.0, 0.5 ); 01619 01620 color[4] = Vector3<T>( 0.0, 0.0, 0.5 ); 01621 color[5] = Vector3<T>( 0.5, 0.5, 1.0 ); 01622 01623 color[6] = Vector3<T>( 0.5, 0.5, 0.0 ); 01624 color[7] = Vector3<T>( 0.3, 0.5, 0.5 ); 01625 01626 color[8] = Vector3<T>( 0.5, 0.0, 0.0 ); 01627 color[9] = Vector3<T>( 1.0, 0.5, 0.5 ); 01628 01629 int count = 0; 01630 do { 01631 //std::cout << ++count << "\n"; 01632 DrawHalfEdgePairs( pHalfEdge, color[count], color[count+1] ); 01633 count += 2; 01634 if ( count >= 10 ) count = 0; 01635 pHalfEdge = pHalfEdge->Next(); 01636 } while ( pHalfEdge != pStartHalfEdge ); 01637 //if ( gCount % 25 == 0 ) { 01638 if ( gCount > gCount2 ) { 01639 g_pFace = g_pFace->Next(); 01640 gCount2 = gCount; 01641 } 01642 } 01643 else { 01644 g_pFace = m_listFace->Head(); 01645 } 01646 01647 glPopAttrib(); 01648 } 01649 01650 //DrawVertexSimulationStatus(); 01651 01652 // Draw AABB Bounding Box 01653 //DrawBoundingAABB(); 01654 //DrawBoundingEllipsoid(); 01655 //DrawBoundingSphere(); 01656 //---------------------------------------------------------------- 01657 #ifdef TAPs_USE_DATA_POOL 01658 glPopClientAttrib(); 01659 #endif//TAPs_USE_DATA_POOL 01660 01661 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->EndGLSL(); 01662 } 01663 //----------------------------------------------------------------------------- 01664 template <typename T> 01665 void OpenGLHalfEdgeModel<T>::DrawGLSLWithDSFaceVertex_RGBA ( GLenum drawMode ) 01666 { 01667 //assert( ShaderProgram ); 01668 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->BeginGLSL(); 01669 GlobalGLSLShaderPool::SetShaderParameters( ShaderName ); 01670 01671 #ifdef TAPs_USE_DATA_POOL 01672 glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); 01673 #endif//TAPs_USE_DATA_POOL 01674 01675 glPushAttrib( GL_ENABLE_BIT | GL_ENABLE_BIT ); 01676 01677 //---------------------------------------------------------------- 01678 if ( drawMode == OpenGL::Enum::POINT ) { 01679 01680 #ifdef TAPs_USE_DATA_POOL 01681 glEnableClientState( GL_VERTEX_ARRAY ); 01682 if ( typeid(T) == typeid(float) ) 01683 { 01684 glVertexPointer( 3, GL_FLOAT, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 01685 } 01686 else //if ( typeid(T) == typeid(double) ) 01687 { 01688 glVertexPointer( 3, GL_DOUBLE, 0, GetArrayOfVertexPositions().GetAddressOfDataNumber(0) ); 01689 } 01690 glPointSize( 2 ); 01691 glDrawArrays( GL_POINTS, 0, GetArrayOfVertexPositions().GetSize() ); 01692 01693 #else //TAPs_USE_DATA_POOL 01694 HEVertex<T> *ptr = m_listVertex->Head(); 01695 glBegin( drawMode ); 01696 while ( ptr != NULL ) { 01697 // Draw the vertex 01698 glVertex3f ( 01699 static_cast<float>( (*ptr)[0] ), 01700 static_cast<float>( (*ptr)[1] ), 01701 static_cast<float>( (*ptr)[2] ) ); 01702 ptr = ptr->Next(); 01703 } 01704 glEnd(); 01705 01706 #endif//TAPs_USE_DATA_POOL 01707 } 01708 else if ( isFacetShading ) { 01709 // Draw the object 01710 //glEnable( GL_TEXTURE_2D ); 01711 HEFace<T> *facePtr = m_listFace->Head(); 01712 HEHalfEdge<T> *halfEdgePtr; 01713 //for ( int f = 0; f < GetNoFaces(); ++f ) { 01714 while ( facePtr != NULL ) { 01715 01716 /* 01717 // Submaterial supported by .ASE 01718 #ifdef TAPs_SUPPORT_ASE_FORMAT 01719 int matID = facePtr->GetMaterialID(); 01720 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 01721 this->submaterials[ matID ]->ApplyMaterial(); 01722 } 01723 #endif//TAPs_SUPPORT_ASE_FORMAT 01724 //*/ 01725 01726 halfEdgePtr = facePtr->IncidentHalfEdge(); 01727 int j = 0; 01728 glBegin( drawMode ); 01729 //for ( int i = 0; i < 3; ++i ) { 01730 do { 01732 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01733 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01734 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01735 //} 01736 // Normal of the face 01737 glNormal3f ( 01738 static_cast<float>( facePtr->GetNormal()[0] ), 01739 static_cast<float>( facePtr->GetNormal()[1] ), 01740 static_cast<float>( facePtr->GetNormal()[2] ) 01741 ); 01742 01743 /* 01744 // Vertex color of the face 01745 float VC[4]; 01746 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2], &VC[3] ); 01747 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 01748 //*/ 01749 01750 // Draw the vertex 01751 glVertex3f ( 01752 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01753 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01754 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01755 ); 01756 // DEBUG: 01757 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01758 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01759 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01760 //std::cout << "\n"; 01761 halfEdgePtr = halfEdgePtr->Next(); 01762 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01763 //std::cout << "\n"; 01764 //} 01765 glEnd(); 01766 facePtr = facePtr->Next(); 01767 } 01768 01769 // Draw the object 01770 //for ( int i = 0; i < m_iNoFaces; i++ ) 01771 //{ 01772 // glBegin( drawMode ); 01773 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01774 // { 01775 // // Draw texture 01776 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01777 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01778 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01779 // } 01780 // // Normal of the face 01781 // //glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 01782 // // static_cast<float>( m_prFace[i].GetNormal()[1] ), 01783 // // static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 01784 // // Draw the vertex 01785 // glVertex3f ( 01786 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01787 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01788 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01789 // } 01790 // glEnd(); 01791 //} 01793 } 01794 else { 01795 // Draw the object 01796 01797 #ifdef TAPs_USE_DATA_POOL__ 01798 #else //TAPs_USE_DATA_POOL__ 01799 01800 //glEnable( GL_TEXTURE_2D ); 01801 HEFace<T> *facePtr = m_listFace->Head(); 01802 HEHalfEdge<T> *halfEdgePtr; 01803 //for ( int f = 0; f < GetNoFaces(); ++f ) { 01804 while ( facePtr != NULL ) { 01805 01806 /* 01807 // Submaterial supported by .ASE 01808 #ifdef TAPs_SUPPORT_ASE_FORMAT 01809 int matID = facePtr->GetMaterialID(); 01810 if ( matID < static_cast<int>( this->submaterials.size() ) ) { 01811 this->submaterials[ matID ]->ApplyMaterial(); 01812 } 01813 #endif//TAPs_SUPPORT_ASE_FORMAT 01814 //*/ 01815 01816 halfEdgePtr = facePtr->IncidentHalfEdge(); 01817 int j = 0; 01818 glBegin( drawMode ); 01819 //for ( int i = 0; i < 3; ++i ) { 01820 do { 01822 //if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01823 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01824 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01825 //} 01827 glNormal3f ( 01828 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[0] ), 01829 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[1] ), 01830 static_cast<float>( halfEdgePtr->Vertex()->GetNormal()[2] ) 01831 ); 01832 01833 //if ( isFirst ) { 01834 // static int i = 0; 01835 // std::cout << "Face# " << i++ << " V# " << j << ":\t" << halfEdgePtr->Vertex()->GetNormal() << "\n"; 01836 //} 01837 01838 /* 01839 // Vertex color of the face 01840 float VC[4]; 01841 GetVertexColor( facePtr->GetVertexColorNo( j++ ), &VC[0], &VC[1], &VC[2], &VC[3] ); 01842 glColor4f ( VC[0], VC[1], VC[2], VC[3] ); 01843 //*/ 01844 01845 // Draw the vertex 01846 glVertex3f ( 01847 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01848 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01849 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01850 ); 01851 // DEBUG: 01852 //std::cout << halfEdgePtr->Vertex()->GetPosition()[0]; 01853 //std::cout << halfEdgePtr->Vertex()->GetPosition()[1]; 01854 //std::cout << halfEdgePtr->Vertex()->GetPosition()[2]; 01855 //std::cout << "\n"; 01856 halfEdgePtr = halfEdgePtr->Next(); 01857 } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01858 //std::cout << "\n"; 01859 //} 01860 glEnd(); 01861 facePtr = facePtr->Next(); 01862 } 01863 01864 #endif//TAPs_USE_DATA_POOL__ 01865 01868 //for ( int i = 0; i < m_iNoFaces; i++ ) 01869 //{ 01870 // glBegin( drawMode ); 01871 // for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 01872 // { 01873 // // Draw texture 01874 // if ( m_prFace[i].GetNoTexCoords() != 0 ) { 01875 // glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 01876 // static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 01877 // } 01878 // // Normal of the vertex 01879 // glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 01880 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 01881 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 01882 // // Draw the vertex 01883 // glVertex3f ( 01884 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 01885 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 01886 // static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 01887 // } 01888 // glEnd(); 01889 //} 01891 } 01892 01893 glPopAttrib(); 01894 01895 //isFirst = false; 01896 01897 // Draw Boundary 01898 //if ( drawMode == OpenGL::Enum::POLYGON_WITH_WIRE_FRAME ) { 01899 //if ( true ) { 01900 // glColor3f( 1.0f, 0.0f, 0.0f ); 01901 // glDisable( GL_LIGHTING ); 01902 // glBegin( GL_LINES ); 01903 // HEFace<T> *facePtr = m_listFace->Head(); 01904 // HEHalfEdge<T> *halfEdgePtr; 01905 // while ( facePtr != NULL ) { 01906 // halfEdgePtr = facePtr->IncidentHalfEdge(); 01907 // do { 01908 // if ( !halfEdgePtr->Pair() ) { 01909 // // Draw the vertex 01910 // glVertex3f ( 01911 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01912 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01913 // static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01914 // ); 01915 // glVertex3f ( 01916 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01917 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01918 // static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01919 // ); 01920 // } 01921 // halfEdgePtr = halfEdgePtr->Next(); 01922 // } while ( halfEdgePtr != facePtr->IncidentHalfEdge() ); 01923 // facePtr = facePtr->Next(); 01924 // } 01925 // glEnd(); 01926 // glEnable( GL_LIGHTING ); 01927 //} 01928 01929 // Draw Boundary 01930 if ( true ) { 01931 glColor3f( 1.0f, 0.0f, 0.0f ); 01932 glPushAttrib( GL_LIGHTING_BIT ); 01933 glDisable( GL_LIGHTING ); 01934 glBegin( GL_LINES ); 01935 if ( m_listHoleFace != NULL ) { 01936 HEFace<T> *facePtr = m_listHoleFace->Head(); 01937 HEHalfEdge<T> *halfEdgePtr; 01938 while ( facePtr != NULL ) { 01939 halfEdgePtr = facePtr->IncidentHalfEdge(); 01940 do { 01941 //if ( halfEdgePtr && halfEdgePtr->Next() ) { 01942 // Draw the vertex 01943 glVertex3f ( 01944 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[0] ), 01945 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[1] ), 01946 static_cast<float>( halfEdgePtr->Vertex()->GetPosition()[2] ) 01947 ); 01948 glVertex3f ( 01949 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[0] ), 01950 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[1] ), 01951 static_cast<float>( halfEdgePtr->Next()->Vertex()->GetPosition()[2] ) 01952 ); 01953 //} 01954 halfEdgePtr = halfEdgePtr->Next(); 01955 } while ( halfEdgePtr && halfEdgePtr != facePtr->IncidentHalfEdge() ); 01956 facePtr = facePtr->Next(); 01957 } 01958 } 01959 glEnd(); 01960 //glEnable( GL_LIGHTING ); 01961 glPopAttrib(); 01962 } 01963 //--------------------------------------------------------------- 01964 static HEFace<T> * g_pFace = m_listFace->Head(); 01965 //static int gCount = 0; 01966 //int gCount = 0; 01967 static int gCount2 = gCount; 01968 //static clock_t start = clock(), finish, delay; 01969 01970 //--------------------------------------------------------------- 01971 // Draw Vertex Normals 01972 if ( bIsDisplayVertexNormals ) { 01973 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01974 glDisable( GL_LIGHTING ); 01975 glColor3ub( 110, 50, 220 ); 01976 HEVertex<T> * pVertex = GetVertexList()->Head(); 01977 for ( int i = 0; i < GetNoVertices(); ++i ) { 01978 Fn::Draw3DLine( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 01979 pVertex = pVertex->Next(); 01980 } 01981 glPopAttrib(); 01982 } 01983 01984 //--------------------------------------------------------------- 01985 // Draw HalfEdge Loop(s) 01986 if ( bIsDisplayVertexNormals ) { 01987 // For Delay 01988 //delay = clock(); 01989 //if ( delay - start > 100 ) { 01990 // start = delay; 01991 // ++gCount; 01992 //} 01993 //++gCount; 01994 01995 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01996 glDisable( GL_LIGHTING ); 01997 glEnable( GL_COLOR_MATERIAL ); 01998 01999 //glColor3ub( 175, 50, 70 ); 02000 //DrawVertexNormals(); 02001 02002 /* 02003 glColor3ub( 75, 50, 175 ); 02004 DrawHalfEdgeByPrevPtrs(); 02005 02006 glColor3ub( 175, 150, 70 ); 02007 DrawHalfEdgeByNextPtrs(); 02008 //*/ 02009 02010 // while ( g_pFace ) { 02011 if ( g_pFace ) { 02012 HEHalfEdge<T> * pHalfEdge = g_pFace->IncidentHalfEdge(); 02013 HEHalfEdge<T> * pStartHalfEdge = pHalfEdge; 02014 Vector3<T> color[20]; 02015 02016 color[0] = Vector3<T>( 0.0, 1.0, 0.0 ); 02017 color[1] = Vector3<T>( 1.0, 0.0, 0.0 ); 02018 02019 color[2] = Vector3<T>( 0.0, 0.5, 0.0 ); 02020 color[3] = Vector3<T>( 0.5, 1.0, 0.5 ); 02021 02022 color[4] = Vector3<T>( 0.0, 0.0, 0.5 ); 02023 color[5] = Vector3<T>( 0.5, 0.5, 1.0 ); 02024 02025 color[6] = Vector3<T>( 0.5, 0.5, 0.0 ); 02026 color[7] = Vector3<T>( 0.3, 0.5, 0.5 ); 02027 02028 color[8] = Vector3<T>( 0.5, 0.0, 0.0 ); 02029 color[9] = Vector3<T>( 1.0, 0.5, 0.5 ); 02030 02031 int count = 0; 02032 do { 02033 //std::cout << ++count << "\n"; 02034 DrawHalfEdgePairs( pHalfEdge, color[count], color[count+1] ); 02035 count += 2; 02036 if ( count >= 10 ) count = 0; 02037 pHalfEdge = pHalfEdge->Next(); 02038 } while ( pHalfEdge != pStartHalfEdge ); 02039 //if ( gCount % 25 == 0 ) { 02040 if ( gCount > gCount2 ) { 02041 g_pFace = g_pFace->Next(); 02042 gCount2 = gCount; 02043 } 02044 } 02045 else { 02046 g_pFace = m_listFace->Head(); 02047 } 02048 02049 glPopAttrib(); 02050 } 02051 02052 //DrawVertexSimulationStatus(); 02053 02054 // Draw AABB Bounding Box 02055 //DrawBoundingAABB(); 02056 //DrawBoundingEllipsoid(); 02057 //DrawBoundingSphere(); 02058 //---------------------------------------------------------------- 02059 #ifdef TAPs_USE_DATA_POOL 02060 glPopClientAttrib(); 02061 #endif//TAPs_USE_DATA_POOL 02062 02063 GlobalGLSLShaderPool::GetShaderProgram( ShaderName )->EndGLSL(); 02064 } 02065 //----------------------------------------------------------------------------- 02066 #endif//TAPs_RENDER_BY_GLSL_DS_FACE_VERTEX 02067 //============================================================================= 02068 02069 02070 02071 02072 02073 02074 02075 02076 02077 02078 02079 02080 02081 02082 //============================================================================= 02083 // Draw by OpenGL 02084 //----------------------------------------------------------------------------- 02085 template <typename T> 02086 void OpenGLHalfEdgeModel<T>::DrawVertexNormals () 02087 { 02088 HEVertex<T> * pVertex = m_listVertex->Head(); 02089 while ( pVertex ) { 02090 OpenGLUsefulObj<T>::DrawOneHeadArrow( pVertex->GetPosition(), pVertex->GetPosition() + pVertex->GetNormal() ); 02091 pVertex = pVertex->Next(); 02092 } 02093 } 02094 //----------------------------------------------------------------------------- 02095 template <typename T> 02096 void OpenGLHalfEdgeModel<T>::DrawHalfEdgeByNextPtrs () 02097 { 02098 HEFace<T> * pFace = m_listFace->Head(); 02099 while ( pFace ) { 02100 HEHalfEdge<T> * pHalfEdge = pFace->IncidentHalfEdge(); 02101 HEHalfEdge<T> * pNextHalfEdge = pHalfEdge->Next(); 02102 HEHalfEdge<T> * pStartHalfEdge = pHalfEdge; 02103 do { 02104 OpenGLUsefulObj<T>::DrawOneHeadArrow( 02105 pHalfEdge->Vertex()->GetPosition() + pFace->GetNormal()/5, 02106 pNextHalfEdge->Vertex()->GetPosition() + pFace->GetNormal()/5 ); 02107 pHalfEdge = pHalfEdge->Next(); 02108 pNextHalfEdge = pNextHalfEdge->Next(); 02109 } while ( pHalfEdge != pStartHalfEdge ); 02110 pFace = pFace->Next(); 02111 } 02112 } 02113 //----------------------------------------------------------------------------- 02114 template <typename T> 02115 void OpenGLHalfEdgeModel<T>::DrawHalfEdgeByPrevPtrs () 02116 { 02117 HEFace<T> * pFace = m_listFace->Head(); 02118 while ( pFace ) { 02119 HEHalfEdge<T> * pHalfEdge = pFace->IncidentHalfEdge(); 02120 HEHalfEdge<T> * pPrevHalfEdge = pHalfEdge->Prev(); 02121 HEHalfEdge<T> * pStartHalfEdge = pHalfEdge; 02122 do { 02123 OpenGLUsefulObj<T>::DrawOneHeadArrow( 02124 pHalfEdge->Vertex()->GetPosition() + pFace->GetNormal()/10, 02125 pPrevHalfEdge->Vertex()->GetPosition() + pFace->GetNormal()/10 ); 02126 pHalfEdge = pHalfEdge->Next(); 02127 pPrevHalfEdge = pPrevHalfEdge->Next(); 02128 } while ( pHalfEdge != pStartHalfEdge ); 02129 pFace = pFace->Next(); 02130 } 02131 } 02132 //----------------------------------------------------------------------------- 02133 template <typename T> 02134 void OpenGLHalfEdgeModel<T>::DrawHalfEdgePairs ( const HEHalfEdge<T> * pHalfEdge, Vector3<T> & color1, Vector3<T> & color2 ) 02135 { 02136 glPushAttrib( GL_LIGHTING_BIT | GL_ENABLE_BIT ); 02137 glDisable( GL_LIGHTING ); 02138 glEnable( GL_COLOR_MATERIAL ); 02139 02140 //* 02141 glColor3f( color1[0], color1[1], color1[2] ); 02142 OpenGLUsefulObj<T>::DrawOneHeadArrow( 02143 pHalfEdge->Vertex()->GetPosition() + pHalfEdge->Face()->GetNormal()/2, 02144 pHalfEdge->Next()->Vertex()->GetPosition() + pHalfEdge->Face()->GetNormal()/2 ); 02145 //*/ 02146 02147 //* 02148 HEHalfEdge<T> * pPair = pHalfEdge->Pair(); 02149 glColor3f( color2[0], color2[1], color2[2] ); 02150 OpenGLUsefulObj<T>::DrawOneHeadArrow( 02151 pPair->Vertex()->GetPosition() + pHalfEdge->Face()->GetNormal()/4, 02152 pPair->Next()->Vertex()->GetPosition() + pHalfEdge->Face()->GetNormal()/4 ); 02153 //*/ 02154 02155 glPopAttrib(); 02156 } 02157 //----------------------------------------------------------------------------- 02158 #ifdef TAPs_ADVANCED_SIMULATION 02159 template <typename T> 02160 void OpenGLHalfEdgeModel<T>::DrawVertexSimulationStatus () 02161 { 02162 //static OpenGLUsefulObj<T> drawer; 02163 02164 glPushAttrib( GL_ENABLE_BIT | GL_POINT_BIT ); 02165 glEnable( GL_COLOR_MATERIAL ); 02166 02167 //drawer.DrawSphere( 2.05 ); 02168 02169 glPointSize( 3 ); 02170 glBegin( GL_POINTS ); 02171 HEVertex<T> * pVertex = m_listVertex->Head(); 02172 while ( pVertex ) { 02173 if ( pVertex->SimFlags.CheckSimulationConstraints( TAPs::Enum::AddOn::FIXED ) ) { 02174 glColor4f( 0.0f, 0.0f, 1.0f, 0.5f ); 02175 } 02176 else if ( pVertex->SimFlags.CheckSimulationConstraints( TAPs::Enum::AddOn::ATTACHED ) ) { 02177 glColor4f( 0.0f, 1.0f, 0.0f, 0.5f ); 02178 } 02179 else if ( pVertex->SimFlags.CheckSimulationConstraints( TAPs::Enum::AddOn::PUNCTURED ) ) { 02180 glColor4f( 1.0f, 0.0f, 0.0f, 0.5f ); 02181 } 02182 else { 02183 glColor4f( 0.5f, 0.5f, 0.5f, 0.5f ); 02184 } 02185 //glTranslatef( pVertex->GetPosition()[0], pVertex->GetPosition()[1], pVertex->GetPosition()[2] ); 02186 //drawer.DrawSphere( 1.05 ); 02187 //glTranslatef( -pVertex->GetPosition()[0], -pVertex->GetPosition()[1], -pVertex->GetPosition()[2] ); 02188 glVertex3fv( pVertex->GetPosition().GetDataFloat() ); 02189 pVertex = pVertex->Next(); 02190 } 02191 glEnd(); 02192 02193 glPopAttrib(); 02194 } 02195 #endif//TAPs_ADVANCED_SIMULATION 02196 //----------------------------------------------------------------------------- 02197 02198 //----------------------------------------------------------------------------- 02199 //============================================================================= 02200 END_NAMESPACE_TAPs__OpenGL 02201 //----------------------------------------------------------------------------- 02202 //345678901234567890123456789012345678901234567890123456789012345678901234567890 02203 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8