#include <TAPsOpenGLPNTriangleVolPresModel.hpp>


Definition at line 25 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
| BEGIN_NAMESPACE_TAPs__OpenGL OpenGLPNTriangleVolPresModel< T >::OpenGLPNTriangleVolPresModel | ( | ) | [inline] |
Definition at line 24 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00025 : VolPresPolygonalModel<T>(), 00026 bRunSimulation( false ), 00027 bFlagShowVertexNormals( false ), 00028 bFlagShowVertexRings( false ) 00029 { 00030 #ifdef TAPs_DEBUG_MODE 00031 std::cout << "OpenGLPNTriangleVolPresModel<" << typeid(T).name() << "> constructor\n"; 00032 #endif//TAPs_DEBUG_MODE 00033 }
| OpenGLPNTriangleVolPresModel< T >::~OpenGLPNTriangleVolPresModel | ( | ) | [inline, virtual] |
Definition at line 37 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00038 { 00039 if ( m_prPNTriCoef != NULL ) delete [] m_prPNTriCoef; 00040 if ( m_prPNTriNormal != NULL ) delete [] m_prPNTriNormal; 00041 00042 #ifdef TAPs_DEBUG_MODE 00043 std::cout << "OpenGLPNTriangleVolPresModel<" << typeid(T).name() << "> destructor\n"; 00044 #endif//TAPs_DEBUG_MODE 00045 }
| bool OpenGLPNTriangleVolPresModel< T >::AllocatePNTriangleCoefficients | ( | ) | [inline, protected] |
Definition at line 68 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00068 { 00069 m_prPNTriCoef = new float[GetNoFaces()*10*3]; 00070 if ( m_prPNTriCoef ) return true; 00071 return false; 00072 }
| bool OpenGLPNTriangleVolPresModel< T >::AllocatePNTriangleNormals | ( | ) | [inline, protected] |
Definition at line 76 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00076 { 00077 m_prPNTriNormal = new float[GetNoFaces()*6*3]; 00078 if ( m_prPNTriNormal ) return true; 00079 return false; 00080 }
| void OpenGLPNTriangleVolPresModel< T >::CalculatePNTriangleCoefficients | ( | ) | [inline, protected] |
Definition at line 139 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00139 { 00140 // Coefficients or Control Points 00141 // b003 9 00142 // / \ 00143 // / \ 00144 // b102 b012 7 8 00145 // / \ <===> 00146 // / \ 00147 // b201 b111 b021 4 5 6 00148 // / \ 00149 // / \ 00150 // b300 ---- b210 ---- b120 ---- b030 0 1 2 3 00151 int b = 0; 00152 Vector3<T> *P1, *P2, *P3; 00153 Vector3<T> *N1, *N2, *N3; 00154 Vector3<T> temp, sum; 00155 T w12, w21, w23, w32, w31, w13; 00156 for ( int f = 0; f < GetNoFaces(); ++f ) { 00157 P1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetPosition(); 00158 P2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetPosition(); 00159 P3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetPosition(); 00160 N1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetNormal(); 00161 N2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetNormal(); 00162 N3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetNormal(); 00163 // Calculate w12, w23, and w31 00164 w12 = ( (*P2) - (*P1) ) * (*N1); 00165 w21 = ( (*P1) - (*P2) ) * (*N2); 00166 w23 = ( (*P3) - (*P2) ) * (*N2); 00167 w32 = ( (*P2) - (*P3) ) * (*N3); 00168 w31 = ( (*P1) - (*P3) ) * (*N3); 00169 w13 = ( (*P3) - (*P1) ) * (*N1); 00170 // b210 00171 b += 3; 00172 sum = temp = (2*(*P1) + (*P2) - w12*(*N1)) / 3.0; 00173 *(m_prPNTriCoef+b) = temp[0]; 00174 *(m_prPNTriCoef+b+1) = temp[1]; 00175 *(m_prPNTriCoef+b+2) = temp[2]; 00176 // b120 00177 b += 3; 00178 sum += temp = (2*(*P2) + (*P1) - w21*(*N2)) / 3.0; 00179 *(m_prPNTriCoef+b) = temp[0]; 00180 *(m_prPNTriCoef+b+1) = temp[1]; 00181 *(m_prPNTriCoef+b+2) = temp[2]; 00182 // b021 00183 b += 12; 00184 sum += temp = (2*(*P2) + (*P3) - w23*(*N2)) / 3.0; 00185 *(m_prPNTriCoef+b) = temp[0]; 00186 *(m_prPNTriCoef+b+1) = temp[1]; 00187 *(m_prPNTriCoef+b+2) = temp[2]; 00188 // b012 00189 b += 6; 00190 sum += temp = (2*(*P3) + (*P2) - w32*(*N3)) / 3.0; 00191 *(m_prPNTriCoef+b) = temp[0]; 00192 *(m_prPNTriCoef+b+1) = temp[1]; 00193 *(m_prPNTriCoef+b+2) = temp[2]; 00194 // b102 00195 b -= 3; 00196 sum += temp = (2*(*P3) + (*P1) - w31*(*N3)) / 3.0; 00197 *(m_prPNTriCoef+b) = temp[0]; 00198 *(m_prPNTriCoef+b+1) = temp[1]; 00199 *(m_prPNTriCoef+b+2) = temp[2]; 00200 // b201 00201 b -= 9; 00202 sum += temp = (2*(*P1) + (*P3) - w13*(*N1)) / 3.0; 00203 *(m_prPNTriCoef+b) = temp[0]; 00204 *(m_prPNTriCoef+b+1) = temp[1]; 00205 *(m_prPNTriCoef+b+2) = temp[2]; 00206 // b111 00207 b += 3; 00208 sum /= 6.0; 00209 temp = (*P1 + *P2 + *P3) / 3.0; 00210 temp = sum + (sum - temp) / 2.0; 00211 *(m_prPNTriCoef+b) = temp[0]; 00212 *(m_prPNTriCoef+b+1) = temp[1]; 00213 *(m_prPNTriCoef+b+2) = temp[2]; 00214 00215 b += 15; // update b index 00216 } 00217 }
| void OpenGLPNTriangleVolPresModel< T >::CalculatePNTriangleNormals | ( | ) | [inline, protected] |
Definition at line 221 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00221 { 00222 // Normals 00223 // n002 5 00224 // / \ 00225 // / \ 00226 // n101 n011 <===> 3 4 00227 // / \ 00228 // / \ 00229 // n200 ---- n110 ---- n020 0 1 2 00230 int n = 0; 00231 Vector3<T> *P1, *P2, *P3; 00232 Vector3<T> *N1, *N2, *N3; 00233 Vector3<T> temp; 00234 T v12, v23, v31; 00235 for ( int f = 0; f < GetNoFaces(); ++f ) { 00236 P1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetPosition(); 00237 P2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetPosition(); 00238 P3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetPosition(); 00239 N1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetNormal(); 00240 N2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetNormal(); 00241 N3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetNormal(); 00242 //cout << *N1 << " " << *N2 << " " << *N3 << endl; 00243 Vector3<T> p12(*P2 - *P1); 00244 Vector3<T> p23(*P3 - *P2); 00245 Vector3<T> p31(*P1 - *P3); 00246 Vector3<T> n12(*N2 + *N1); 00247 Vector3<T> n23(*N3 + *N2); 00248 Vector3<T> n31(*N1 + *N3); 00249 v12 = 2.0 * (p12 * n12) / (p12 * p12); 00250 v23 = 2.0 * (p23 * n23) / (p23 * p23); 00251 v31 = 2.0 * (p31 * n31) / (p31 * p31); 00252 // n110 00253 temp = (n12 - v12*p12).Normalized(); 00254 n += 3; 00255 *(m_prPNTriNormal+n) = temp[0]; 00256 *(m_prPNTriNormal+n+1) = temp[1]; 00257 *(m_prPNTriNormal+n+2) = temp[2]; 00258 // n101 00259 temp = (n23 - v23*p23).Normalized(); 00260 n += 6; 00261 *(m_prPNTriNormal+n) = temp[0]; 00262 *(m_prPNTriNormal+n+1) = temp[1]; 00263 *(m_prPNTriNormal+n+2) = temp[2]; 00264 // n011 00265 temp = (n31 - v31*p31).Normalized(); 00266 n += 3; 00267 *(m_prPNTriNormal+n) = temp[0]; 00268 *(m_prPNTriNormal+n+1) = temp[1]; 00269 *(m_prPNTriNormal+n+2) = temp[2]; 00270 n += 6; // update n index 00271 } 00272 }
| void OpenGLPNTriangleVolPresModel< T >::CreateAndCalPNTriangles | ( | ) | [inline, protected] |
Definition at line 57 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00057 { 00058 if ( !AllocatePNTriangleCoefficients() ) exit(1); 00059 if ( !AllocatePNTriangleNormals() ) exit(1); 00060 InitializePNTriangleCoefficients(); 00061 InitializePNTriangleNormals(); 00062 CalculatePNTriangleCoefficients(); 00063 CalculatePNTriangleNormals(); 00064 }
| void OpenGLPNTriangleVolPresModel< T >::DisplayGL_DeformedFaceNo | ( | ) | [inline] |
Definition at line 862 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00863 { 00864 // Draw Normal of each particle 00865 glDisable( GL_LIGHTING ); 00866 glColor3f( 0.0f, 1.0f, 0.0f ); 00867 glBegin( GL_POLYGON ); 00868 for ( int n = 0; n < m_prFace[m_iDeformedFaceNo].GetNoVertices(); ++n ){ 00869 glVertex3f ( 00870 static_cast<float>( m_prXVertex[m_prFace[m_iDeformedFaceNo].GetVertexNo( n )][0] ), 00871 static_cast<float>( m_prXVertex[m_prFace[m_iDeformedFaceNo].GetVertexNo( n )][1] ), 00872 static_cast<float>( m_prXVertex[m_prFace[m_iDeformedFaceNo].GetVertexNo( n )][2] ) 00873 ); 00874 } 00875 glEnd(); 00876 glEnable( GL_LIGHTING ); 00877 }
| void OpenGLPNTriangleVolPresModel< T >::DisplayGL_ParticleNormals | ( | ) | [inline] |
Definition at line 814 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00815 { 00816 T x, y, z; 00817 00818 // Draw Normal of each particle 00819 glDisable( GL_LIGHTING ); 00820 glColor3f( 1.0f, 0.0f, 0.0f ); 00821 glBegin( GL_LINES ); 00822 for ( int n = 0; n < m_iNoVertices; ++n ){ 00823 m_pprParticleVertex[n]->GetPosition().GetXYZ( x, y, z ); 00824 glVertex3f( static_cast<float>( x ), static_cast<float>( y ), static_cast<float>( z ) ); 00825 glVertex3f ( 00826 static_cast<float>( x + m_pprParticleVertex[n]->GetNormal()[0] ), 00827 static_cast<float>( y + m_pprParticleVertex[n]->GetNormal()[1] ), 00828 static_cast<float>( z + m_pprParticleVertex[n]->GetNormal()[2] ) 00829 ); 00830 } 00831 glEnd(); 00832 glEnable( GL_LIGHTING ); 00833 }
| void OpenGLPNTriangleVolPresModel< T >::DisplayGL_VertexRings | ( | ) | [inline] |
Definition at line 837 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00838 { 00839 glDisable( GL_LIGHTING ); 00840 //glLineWidth( 3.0f ); 00841 glPointSize( 7.0f ); 00842 for ( int i = 0; i <= m_pcVertexRings->GetNoRings(); ++i ) { 00843 glColor3ub( 255-(i*25), 0+(i*25), 15 ); 00844 //glBegin( GL_LINE_LOOP ); 00845 glBegin( GL_POINTS ); 00846 for ( int j = m_pcVertexRings->GetRingLayers()[i]; j < m_pcVertexRings->GetRingLayers()[i+1]; ++j ) { 00847 glVertex3f ( 00848 static_cast<float>( m_prXVertex[ m_pcVertexRings->GetRingVertices()[j] ][0] ), 00849 static_cast<float>( m_prXVertex[ m_pcVertexRings->GetRingVertices()[j] ][1] ), 00850 static_cast<float>( m_prXVertex[ m_pcVertexRings->GetRingVertices()[j] ][2] ) 00851 ); 00852 } 00853 glEnd(); 00854 } 00855 glPointSize( 1.0f ); 00856 //glLineWidth( 1.0f ); 00857 glEnable( GL_LIGHTING ); 00858 }
| void OpenGLPNTriangleVolPresModel< T >::DisplayGLText | ( | T | x = 0, |
|
| T | y = 0, |
|||
| T | z = 0 | |||
| ) | [inline, virtual] |
Reimplemented in ExtendedOpenGLPNTriangleVolPresModel< T >.
Definition at line 405 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00406 { 00407 char str[128] = ""; 00408 int count = 0; 00409 T volume = CalVolume(); // for calculating centroid 00410 sprintf( str, "CalVolume: %g", volume ); 00411 Fn::DrawGLText( str, x, y-2*count++, z ); 00412 sprintf( str, "Centroid: (%10.4f, %10.4f, %10.4f)", m_vtCentroid[0], m_vtCentroid[1], m_vtCentroid[2] ); 00413 Fn::DrawGLText( str, x, y-2*count++, z ); 00414 CalVolume2(); 00415 sprintf( str, "CalVolume2: %g", m_tVolume ); 00416 Fn::DrawGLText( str, x, y-2*count++, z ); 00417 sprintf( str, "weight0: %g", m_weight[0] ); 00418 Fn::DrawGLText( str, x, y-2*count++, z ); 00419 // sprintf( str, "weight1: %g", weight[1] ); 00420 // Fn::DrawGLText( str, x, y-2*count++, z ); 00421 // sprintf( str, "weight2: %g", weight[2] ); 00422 // Fn::DrawGLText( str, x, y-2*count++, z ); 00423 // sprintf( str, "weight3: %g", weight[3] ); 00424 // Fn::DrawGLText( str, x, y-2*count++, z ); 00425 if ( m_bFlagSpringForceMode ) { 00426 sprintf( str, "Spring Force: ON" ); 00427 } 00428 else { 00429 sprintf( str, "Spring Force: OFF" ); 00430 } 00431 Fn::DrawGLText( str, x, y-2*count++, z ); 00432 if ( m_bFlagVolPresMode ) { 00433 sprintf( str, "VolPres: ON" ); 00434 } 00435 else { 00436 sprintf( str, "VolPres: OFF" ); 00437 } 00438 Fn::DrawGLText( str, x, y-2*count++, z ); 00439 }
| void OpenGLPNTriangleVolPresModel< T >::DrawGL | ( | GLenum | drawMode | ) | [inline, protected, virtual] |
*
Implements OpenGLSupport.
Reimplemented in ExtendedOpenGLPNTriangleVolPresModel< T >.
Definition at line 444 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00445 { 00446 00447 InitializePNTriangleCoefficients(); 00448 InitializePNTriangleNormals(); 00449 00450 // StepSimulation 00451 int count; 00452 if ( bRunSimulation ) { 00454 for ( count = 0; count < 5; count++ ) { 00455 StepSimulation( 0.01 ); 00456 } 00457 //*/ 00458 00459 /* 00460 for ( int i = 0; i < 5; ++i ) { 00461 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) { 00462 m_prXVertex[ m_prFace[i].GetVertexNo(j) ].SetPosition( 00463 m_prXVertex[ m_prFace[i].GetVertexNo(j) ].GetPosition() * 1.001 00464 ); 00465 //m_prXVertex[ 0].SetPosition( m_prXVertex[ 0].GetPosition() * 1.001 ); 00466 //m_prXVertex[12].SetPosition( m_prXVertex[12].GetPosition() * 1.001 ); 00467 //m_prXVertex[13].SetPosition( m_prXVertex[13].GetPosition() * 1.001 ); 00468 } 00469 } 00470 */ 00471 } 00472 00473 //if ( isFacetShading ) { 00474 if ( false ) { 00475 // Draw the object 00476 //glEnable( GL_TEXTURE_2D ); 00477 for ( int i = 0; i < m_iNoFaces; i++ ) 00478 { 00479 glBegin( drawMode ); 00480 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00481 { 00482 // Draw texture 00483 if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00484 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00485 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00486 } 00487 // Normal of the face 00488 glNormal3f ( static_cast<float>( m_prFace[i].GetNormal()[0] ), 00489 static_cast<float>( m_prFace[i].GetNormal()[1] ), 00490 static_cast<float>( m_prFace[i].GetNormal()[2] ) ); 00491 // Draw the vertex 00492 glVertex3f ( 00493 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00494 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00495 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00496 } 00497 glEnd(); 00498 } 00499 //glDisable( GL_TEXTURE_2D ); 00500 } 00501 else if ( isFacetShading ) { 00502 // Draw the object 00503 //glEnable( GL_TEXTURE_2D ); 00504 for ( int i = 0; i < m_iNoFaces; i++ ) 00505 { 00506 glBegin( drawMode ); 00507 for ( int j = 0; j < m_prFace[i].GetNoVertices(); ++j ) 00508 { 00509 // Draw texture 00510 if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00511 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00512 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00513 } 00514 // Normal of the vertex 00515 glNormal3f ( static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[0] ), 00516 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[1] ), 00517 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ].GetNormal()[2] ) ); 00518 // Draw the vertex 00519 glVertex3f ( 00520 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][0] ), 00521 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][1] ), 00522 static_cast<float>( m_prXVertex[ m_prFace[i].GetVertexNo( j ) ][2] ) ); 00523 } 00524 glEnd(); 00525 } 00526 //glDisable( GL_TEXTURE_2D ); 00527 } 00528 else { 00529 // Draw the object 00530 //glEnable( GL_TEXTURE_2D ); 00531 00532 int b[3] = { 0, 9, 27 }, n[3] = { 0, 6, 15 }; 00533 00534 /* 00535 // For FPS 00536 clock_t start, finish; 00537 start = clock(); 00538 */ 00539 //for ( int i = 0; i < m_iNoFaces; ++i ) 00540 { 00541 #ifdef TAPs_USING_GLSL 00542 if ( gbUseGPU ) { 00543 //setUniformVariables(); 00544 //DrawPNTrianglePatch(i, 10, m_prPNTriCoef, m_prPNTriNormal); 00545 #ifdef TAPS_SHADER_FNS_HPP 00546 DrawTriangleUsingHardware(m_iNoFaces, 10, m_prPNTriCoef, m_prPNTriNormal); 00547 #endif 00548 } 00549 else { 00550 // Draw Bezier Patch 00551 for ( int i = 0; i < m_iNoFaces; ++i ) 00552 DrawTriBezierPatchNo(i, 10); 00553 //DrawTriBezierPatchNo(m_iNoFaces, 10); 00554 } 00555 #else 00556 for ( int i = 0; i < m_iNoFaces; ++i ) 00557 DrawTriBezierPatchNo(i, 10); 00558 //DrawTriBezierPatchNo(m_iNoFaces, 10); 00559 #endif 00560 00561 /* 00562 glBegin( GL_LINE_LOOP ); 00563 for ( int j = 0; j < 3; ++j ) 00564 { 00565 // Draw texture 00566 if ( m_prFace[i].GetNoTexCoords() != 0 ) { 00567 glTexCoord2f( static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2 ) ), 00568 static_cast<float>( m_prFace[i].GetTexCoordHalfNo( j*2+1 ) ) ); 00569 } 00570 // Normal of the vertex 00571 glNormal3f ( static_cast<float>( m_prPNTriNormal[n[j] ] ), 00572 static_cast<float>( m_prPNTriNormal[n[j]+1] ), 00573 static_cast<float>( m_prPNTriNormal[n[j]+2] ) ); 00574 // Draw the vertex 00575 glVertex3f ( 00576 static_cast<float>( m_prPNTriCoef[ b[j] ] ), 00577 static_cast<float>( m_prPNTriCoef[ b[j]+1] ), 00578 static_cast<float>( m_prPNTriCoef[ b[j]+2] ) ); 00579 } 00580 glEnd(); 00581 */ 00582 00583 /* 00584 DrawText( "b300", 00585 static_cast<float>( m_prPNTriCoef[ b[0] ] ), 00586 static_cast<float>( m_prPNTriCoef[ b[0]+1] ), 00587 static_cast<float>( m_prPNTriCoef[ b[0]+2] ) ); 00588 DrawText( "b030", 00589 static_cast<float>( m_prPNTriCoef[ b[1] ] ), 00590 static_cast<float>( m_prPNTriCoef[ b[1]+1] ), 00591 static_cast<float>( m_prPNTriCoef[ b[1]+2] ) ); 00592 DrawText( "b003", 00593 static_cast<float>( m_prPNTriCoef[ b[2] ] ), 00594 static_cast<float>( m_prPNTriCoef[ b[2]+1] ), 00595 static_cast<float>( m_prPNTriCoef[ b[2]+2] ) ); 00596 */ 00597 00598 /* 00599 // Draw Bezier control points 00600 glPointSize(5); 00601 glDisable(GL_LIGHTING); 00602 int s; 00603 glBegin( GL_POINTS ); 00604 for ( s = 0; s < 30; s+=3 ) { 00605 // Draw the vertex 00606 glColor3ub( s*25, 0, 0 ); 00607 glVertex3f ( 00608 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00609 static_cast<float>( m_prPNTriCoef[ b[0]+s+1 ] ), 00610 static_cast<float>( m_prPNTriCoef[ b[0]+s+2 ] ) ); 00611 } 00612 glEnd(); 00613 */ 00614 00615 /* 00616 DrawText( "b300", 00617 static_cast<float>( m_prPNTriCoef[ b[0] ] ), 00618 static_cast<float>( m_prPNTriCoef[ b[0]+1] ), 00619 static_cast<float>( m_prPNTriCoef[ b[0]+2] ) ); 00620 DrawText( "b210", 00621 static_cast<float>( m_prPNTriCoef[ b[0]+3] ), 00622 static_cast<float>( m_prPNTriCoef[ b[0]+4] ), 00623 static_cast<float>( m_prPNTriCoef[ b[0]+5] ) ); 00624 DrawText( "b120", 00625 static_cast<float>( m_prPNTriCoef[ b[0]+6] ), 00626 static_cast<float>( m_prPNTriCoef[ b[0]+7] ), 00627 static_cast<float>( m_prPNTriCoef[ b[0]+8] ) ); 00628 DrawText( "b030", 00629 static_cast<float>( m_prPNTriCoef[ b[0]+9 ] ), 00630 static_cast<float>( m_prPNTriCoef[ b[0]+10] ), 00631 static_cast<float>( m_prPNTriCoef[ b[0]+11] ) ); 00632 DrawText( "b201", 00633 static_cast<float>( m_prPNTriCoef[ b[0]+12] ), 00634 static_cast<float>( m_prPNTriCoef[ b[0]+13] ), 00635 static_cast<float>( m_prPNTriCoef[ b[0]+14] ) ); 00636 DrawText( "b111", 00637 static_cast<float>( m_prPNTriCoef[ b[0]+15] ), 00638 static_cast<float>( m_prPNTriCoef[ b[0]+16] ), 00639 static_cast<float>( m_prPNTriCoef[ b[0]+17] ) ); 00640 DrawText( "b021", 00641 static_cast<float>( m_prPNTriCoef[ b[0]+18] ), 00642 static_cast<float>( m_prPNTriCoef[ b[0]+19] ), 00643 static_cast<float>( m_prPNTriCoef[ b[0]+20] ) ); 00644 DrawText( "b102", 00645 static_cast<float>( m_prPNTriCoef[ b[0]+21] ), 00646 static_cast<float>( m_prPNTriCoef[ b[0]+22] ), 00647 static_cast<float>( m_prPNTriCoef[ b[0]+23] ) ); 00648 DrawText( "b012", 00649 static_cast<float>( m_prPNTriCoef[ b[0]+24] ), 00650 static_cast<float>( m_prPNTriCoef[ b[0]+25] ), 00651 static_cast<float>( m_prPNTriCoef[ b[0]+26] ) ); 00652 DrawText( "b003", 00653 static_cast<float>( m_prPNTriCoef[ b[0]+27] ), 00654 static_cast<float>( m_prPNTriCoef[ b[0]+28] ), 00655 static_cast<float>( m_prPNTriCoef[ b[0]+29] ) ); 00656 */ 00657 00658 /* 00659 // Draw lines connecting Bezier control points 00660 glColor3ub( 0, 220, 0 ); 00661 glBegin( GL_LINE_LOOP ); 00662 s = 0; 00663 glVertex3f ( 00664 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00665 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00666 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00667 s = 3; 00668 glVertex3f ( 00669 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00670 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00671 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00672 s = 6; 00673 glVertex3f ( 00674 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00675 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00676 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00677 s = 9; 00678 glVertex3f ( 00679 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00680 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00681 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00682 s = 18; 00683 glVertex3f ( 00684 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00685 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00686 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00687 s = 24; 00688 glVertex3f ( 00689 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00690 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00691 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00692 s = 27; 00693 glVertex3f ( 00694 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00695 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00696 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00697 s = 21; 00698 glVertex3f ( 00699 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00700 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00701 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00702 s = 12; 00703 glVertex3f ( 00704 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00705 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00706 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00707 glEnd(); 00708 glBegin( GL_LINE_LOOP ); 00709 s = 3; 00710 glVertex3f ( 00711 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00712 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00713 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00714 s = 12; 00715 glVertex3f ( 00716 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00717 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00718 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00719 s = 15; 00720 glVertex3f ( 00721 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00722 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00723 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00724 glEnd(); 00725 glBegin( GL_LINE_LOOP ); 00726 s = 6; 00727 glVertex3f ( 00728 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00729 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00730 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00731 s = 15; 00732 glVertex3f ( 00733 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00734 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00735 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00736 s = 18; 00737 glVertex3f ( 00738 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00739 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00740 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00741 glEnd(); 00742 glBegin( GL_LINE_LOOP ); 00743 s = 15; 00744 glVertex3f ( 00745 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00746 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00747 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00748 s = 21; 00749 glVertex3f ( 00750 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00751 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00752 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00753 s = 24; 00754 glVertex3f ( 00755 static_cast<float>( m_prPNTriCoef[ b[0]+s ] ), 00756 static_cast<float>( m_prPNTriCoef[ b[0]+s+1] ), 00757 static_cast<float>( m_prPNTriCoef[ b[0]+s+2] ) ); 00758 glEnd(); 00759 */ 00760 00761 //glEnable(GL_LIGHTING); 00762 b[0] += 30; 00763 b[1] += 30; 00764 b[2] += 30; 00765 n[0] += 18; 00766 n[1] += 18; 00767 n[2] += 18; 00768 } 00769 /* 00770 // For FPS 00771 finish = clock(); 00772 double duration = static_cast<double>(finish - start); 00773 int dFPS; 00774 if ( duration > 0.0 ) { 00775 dFPS = CLOCKS_PER_SEC / duration; 00776 } 00777 else { 00778 dFPS = 1000; 00779 } 00780 std::cout << "FPs: " << dFPS << "\n"; 00781 */ 00782 00783 //glDisable( GL_TEXTURE_2D ); 00784 } 00785 // Display vertex normals 00786 if ( bFlagShowVertexNormals ) { 00787 DisplayGL_ParticleNormals(); 00788 } 00789 // Display vertex rings 00790 if ( bFlagShowVertexRings ) { 00791 DisplayGL_VertexRings(); 00792 } 00793 // Display the deformed face 00794 if ( bFlagShowDeformedFace ) { 00795 //DisplayGL_DeformedFaceNo(); 00796 // comment out because gpu drawing will cause it 00797 // be drawn incorrectly 00798 } 00799 00800 // Display Volume and Centroid 00801 glDisable( GL_LIGHTING ); 00802 glPushAttrib(GL_ALL_ATTRIB_BITS); 00803 glColor3ub( 200, 185, 0 ); 00804 00805 glPopAttrib(); 00806 glEnable( GL_LIGHTING ); 00807 }
| void OpenGLPNTriangleVolPresModel< T >::DrawTriBezierPatchNo | ( | int | f, | |
| int | smoothness | |||
| ) | [inline, protected] |
Definition at line 276 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00276 { 00277 int noOfVertices = smoothness*(smoothness+1)/2; 00278 float *vertex = new float[noOfVertices*3]; 00279 float *normal = new float[noOfVertices*3]; 00280 int index = 0; 00281 float uInc = 1.0 / (smoothness-1); 00282 float vInc = 1.0 / (smoothness-1); 00283 float u = 0.0f, v = 0.0f, w; 00284 float uu, vv, ww; 00285 int bCount = faceNo * 30; 00286 int nCount = faceNo * 18; 00287 float *b = m_prPNTriCoef; 00288 float *n = m_prPNTriNormal; 00289 for ( int i = 0; i < smoothness; ++i, u += uInc ) { 00290 v = 0.0f; 00291 for ( int j = 0; j < smoothness; ++j, v += vInc ) { 00292 w = 1.0f - u - v; 00293 if ( w < -0.0000001f ) break; 00294 ww = w*w; 00295 uu = u*u; 00296 vv = v*v; 00297 T magnitude = 0.0; 00298 for ( int d = 0; d < 3; ++d, ++index ) { 00299 vertex[index] = b[bCount+d]*ww*w + b[bCount+9+d]*uu*u + b[bCount+27+d]*vv*v 00300 + 3.0f*( b[bCount+3+d]*ww*u + b[bCount+6+d]*w*uu 00301 + b[bCount+12+d]*ww*v + b[bCount+18+d]*uu*v 00302 + b[bCount+21+d]*w*vv + b[bCount+24+d]*u*vv ) 00303 + b[bCount+15+d]*6.0f*w*u*v; 00304 normal[index] = n[nCount+d]*ww + n[nCount+6+d]*uu + n[nCount+15+d]*vv 00305 + n[nCount+3+d]*w*u + n[nCount+9+d]*u*v + n[nCount+12+d]*w*v; 00306 magnitude += normal[index]*normal[index]; 00307 } 00308 magnitude = sqrt(magnitude); 00309 normal[index-3] /= magnitude; 00310 normal[index-2] /= magnitude; 00311 normal[index-1] /= magnitude; 00312 } 00313 } 00314 /* 00315 glPointSize(11); 00316 int pos = 0; 00317 glBegin( GL_POINTS ); 00318 for ( int i = 0; i < noOfVertices; ++i, pos+=3 ) { 00319 glVertex3f( vertex[pos], vertex[pos+1], vertex[pos+2] ); 00320 } 00321 glEnd(); 00322 */ 00323 00324 int row1 = 0, row2 = smoothness*3; 00325 for ( int r = 1; r < smoothness; ++r, row1+=3 ) { 00326 glBegin( GL_TRIANGLE_STRIP ); 00327 for ( int i = 0; i < smoothness-r; ++i, row1+=3, row2+=3 ) { 00328 glNormal3f( normal[row1], normal[row1+1], normal[row1+2] ); 00329 glVertex3f( vertex[row1], vertex[row1+1], vertex[row1+2] ); 00330 glNormal3f( normal[row2], normal[row2+1], normal[row2+2] ); 00331 glVertex3f( vertex[row2], vertex[row2+1], vertex[row2+2] ); 00332 } 00333 glNormal3f( normal[row1], normal[row1+1], normal[row1+2] ); 00334 glVertex3f( vertex[row1], vertex[row1+1], vertex[row1+2] ); 00335 glEnd(); 00336 } 00337 /* 00338 row1 = 0; 00339 for ( int r = 0; r < noOfVertices; ++r, row1+=3 ) { 00340 glBegin( GL_LINES ); 00341 GLfloat ppp[3]; 00342 ppp[0]= normal[row1]+vertex[row1]; 00343 ppp[1]= normal[row1+1]+vertex[row1+1]; 00344 ppp[2]= normal[row1+2]+vertex[row1+2]; 00345 glVertex3f( vertex[row1], vertex[row1+1], vertex[row1+2] ); 00346 glVertex3fv( ppp ); 00347 glEnd(); 00348 }*/ 00349 /* 00350 int idx = 0; 00351 DrawText( "b300", 00352 static_cast<float>( vertex[idx] ), 00353 static_cast<float>( vertex[idx+1] ), 00354 static_cast<float>( vertex[idx+2] ) ); 00355 idx = (smoothness-1)*3; 00356 DrawText( "b030", 00357 static_cast<float>( vertex[idx] ), 00358 static_cast<float>( vertex[idx+1] ), 00359 static_cast<float>( vertex[idx+2] ) ); 00360 idx = (noOfVertices-1)*3; 00361 DrawText( "b003", 00362 static_cast<float>( vertex[idx] ), 00363 static_cast<float>( vertex[idx+1] ), 00364 static_cast<float>( vertex[idx+2] ) ); 00365 */ 00366 delete [] vertex; 00367 delete [] normal; 00368 }
| void OpenGLPNTriangleVolPresModel< T >::Initialize | ( | ) | [inline, virtual] |
Reimplemented from VolPresPolygonalModel< T >.
Reimplemented in ExtendedOpenGLPNTriangleVolPresModel< T >.
Definition at line 49 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00050 { 00051 VolPresPolygonalModel<T>::Initialize(); 00052 CreateAndCalPNTriangles(); 00053 }
| void OpenGLPNTriangleVolPresModel< T >::InitializePNTriangleCoefficients | ( | ) | [inline, protected] |
Definition at line 84 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00084 { 00085 // Coefficients or Control Points 00086 // b003 9 00087 // / \ 00088 // / \ 00089 // b102 b012 7 8 00090 // / \ <===> 00091 // / \ 00092 // b201 b111 b021 4 5 6 00093 // / \ 00094 // / \ 00095 // b300 ---- b210 ---- b120 ---- b030 0 1 2 3 00096 int b = 0; 00097 Vector3<T> *P1, *P2, *P3; 00098 for ( int f = 0; f < GetNoFaces(); ++f, b+=30 ) { 00099 // Initialize b300, b030, and b003 00100 P1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetPosition(); 00101 P2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetPosition(); 00102 P3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetPosition(); 00103 for ( int i = 0; i < 3; ++i ) { 00104 *(m_prPNTriCoef+b+i) = (*P1)[i]; 00105 *(m_prPNTriCoef+b+9+i) = (*P2)[i]; 00106 *(m_prPNTriCoef+b+27+i) = (*P3)[i]; 00107 } 00108 } 00109 }
| void OpenGLPNTriangleVolPresModel< T >::InitializePNTriangleNormals | ( | ) | [inline, protected] |
Definition at line 113 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00113 { 00114 // Normals 00115 // n002 5 00116 // / \ 00117 // / \ 00118 // n101 n011 <===> 3 4 00119 // / \ 00120 // / \ 00121 // n200 ---- n110 ---- n020 0 1 2 00122 int n = 0; 00123 Vector3<T> *N1, *N2, *N3; 00124 for ( int f = 0; f < GetNoFaces(); ++f, n+=18 ) { 00125 // Initialize n200, n020, and n002 00126 N1 = &m_prXVertex[ m_prFace[f].GetVertexNo(0) ].GetNormal(); 00127 N2 = &m_prXVertex[ m_prFace[f].GetVertexNo(1) ].GetNormal(); 00128 N3 = &m_prXVertex[ m_prFace[f].GetVertexNo(2) ].GetNormal(); 00129 for ( int i = 0; i < 3; ++i ) { 00130 *(m_prPNTriNormal+n+i) = (*N1)[i]; 00131 *(m_prPNTriNormal+n+6+i) = (*N2)[i]; 00132 *(m_prPNTriNormal+n+15+i) = (*N3)[i]; 00133 } 00134 } 00135 }
| void OpenGLPNTriangleVolPresModel< T >::PreserveVolumeByVertexNormals | ( | T | weight[4] | ) | [inline, protected, virtual] |
Reimplemented from VolPresPolygonalModel< T >.
Reimplemented in ExtendedOpenGLPNTriangleVolPresModel< T >.
Definition at line 886 of file TAPsOpenGLPNTriangleVolPresModel.cpp.
00887 { 00888 VolPresPolygonalModel<T>::PreserveVolumeByVertexNormals( wgt ); 00889 // Recalculate PN-Triangles 00890 CalculatePNTriangleCoefficients(); 00891 CalculatePNTriangleNormals(); 00892 }
| void OpenGLPNTriangleVolPresModel< T >::SetShowDeformedFace | ( | bool | b | ) | [inline] |
Definition at line 113 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
00113 { bFlagShowDeformedFace = b; }
| void OpenGLPNTriangleVolPresModel< T >::SetShowVertexNormals | ( | bool | b | ) | [inline] |
Definition at line 111 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
00111 { bFlagShowVertexNormals = b; }
| void OpenGLPNTriangleVolPresModel< T >::SetShowVertexRings | ( | bool | b | ) | [inline] |
Definition at line 112 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
00112 { bFlagShowVertexRings = b; }
| void OpenGLPNTriangleVolPresModel< T >::ToggleShowDeformedFace | ( | ) | [inline] |
Definition at line 110 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
00110 { bFlagShowDeformedFace = !bFlagShowDeformedFace; }
| void OpenGLPNTriangleVolPresModel< T >::ToggleShowVertexNormals | ( | ) | [inline] |
Definition at line 108 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
00108 { bFlagShowVertexNormals = !bFlagShowVertexNormals; }
| void OpenGLPNTriangleVolPresModel< T >::ToggleShowVertexRings | ( | ) | [inline] |
Definition at line 109 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
00109 { bFlagShowVertexRings = !bFlagShowVertexRings; }
| void OpenGLPNTriangleVolPresModel< T >::ToggleSimulation | ( | ) | [inline] |
Definition at line 107 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
00107 { bRunSimulation = !bRunSimulation; }
| std::ostream& operator<< | ( | std::ostream & | output, | |
| OpenGLPNTriangleVolPresModel< T > const & | o | |||
| ) | [friend] |
Definition at line 28 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
00029 { 00030 output << "\n======================\n" 00031 << "TAPs::OpenGL::OpenGLPNTriangleVolPresModel<" 00032 << typeid(T).name() << "> Class\n" 00033 << "======================\n"; 00034 //---------------------------------------------------------------- 00035 // Material Node from OpenGLSupport 00036 output << "\nMaterial Node" << "\n{\n" << o.material << "\n}"; 00037 //---------------------------------------------------------------- 00038 // Nodes from XPolygonalModel<T> 00039 output << "\n\nVertices " << o.m_iNoVertices << "\n{"; 00040 for ( int i = 0; i < o.m_iNoVertices; ++i ) { 00041 output << "\n #" << i << "\t" << o.m_prXVertex[i]; 00042 } 00043 output << "\n}"; 00044 //---------------------------------------------------------------- 00045 // Neighbor vertex ring#1 00046 if ( o.m_pviVertexRing1List ) { 00047 std::vector<int>::const_iterator iterator; 00048 output << "\n\nVertexRing1 " << o.m_iNoVertices << "\n{"; 00049 for ( int i = 0; i < o.m_iNoVertices; ++i ) { 00050 output << "\n #" << i; 00051 for ( iterator = o.m_pviVertexRing1List[i].begin(); 00052 iterator != o.m_pviVertexRing1List[i].end(); 00053 ++iterator ) 00054 { 00055 output << "\t" << *iterator; 00056 } 00057 } 00058 output << "\n}"; 00059 } 00060 //---------------------------------------------------------------- 00061 // Faces Node 00062 output << "\n\nFaces " << o.m_iNoFaces << "\n{"; 00063 for ( int i = 0; i < o.m_iNoFaces; ++i ) { 00064 output << "\n #" << i << "\t" << o.m_prFace[i]; 00065 } 00066 output << "\n}"; 00067 return output; 00068 }
bool OpenGLPNTriangleVolPresModel< T >::bFlagShowDeformedFace [protected] |
Definition at line 120 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
bool OpenGLPNTriangleVolPresModel< T >::bFlagShowVertexNormals [protected] |
Definition at line 118 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
bool OpenGLPNTriangleVolPresModel< T >::bFlagShowVertexRings [protected] |
Definition at line 119 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
bool OpenGLPNTriangleVolPresModel< T >::bRunSimulation [protected] |
Definition at line 117 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
| float* OpenGLPNTriangleVolPresModel< T >::m_prPNTriCoef |
Definition at line 130 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
| float* OpenGLPNTriangleVolPresModel< T >::m_prPNTriNormal |
Definition at line 131 of file TAPsOpenGLPNTriangleVolPresModel.hpp.
1.5.6