TAPs 0.7.7.3
TAPsModelDeformableGLSL_Connectivity3x3.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsModelDeformableGLSL_Connectivity3x3.cpp
00003 ******************************************************************************/
00008 /******************************************************************************
00009 SUKITTI PUNAK   (10/17/2006)
00010 UPDATE          (09/12/2007)
00011 ******************************************************************************/
00012 #include "TAPsModelDeformableGLSL.hpp"
00013 //#include "TAPsModelDeformableGLSL_Connectivity3x3.hpp"
00014 // Using Inclusion Model (i.e. definitions are included in declarations)
00015 //                       (this name.cpp is included in name.hpp)
00016 // Each friend is defined directly inside its declaration.
00017 
00018 BEGIN_NAMESPACE_TAPs__OpenGL
00019 //=============================================================================
00020 //-----------------------------------------------------------------------------
00022 // START FNs FOR TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3
00024 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3
00025 //-----------------------------------------------------------------------------
00026 
00027 //=============================================================================
00028 // For Initializations & Setups
00029 //-----------------------------------------------------------------------------
00030 template <typename T>
00031 void ModelDeformableGLSL<T>::SetupConnectivityPattern ( 
00032     enum ConnectivityPattern CP 
00033 )
00034 {
00035     // PROVIDE CONNECTIONS ARRANGED IN THESE INDICES ORDER
00036     //-------------------------------------------
00037     // Identification Numbers (for front, center, and back planes)
00038     // --------------------------------
00039     // |   FRONT    CENTER     BACK   |
00040     // | 00 01 02  09 10 11  18 19 20 |
00041     // | 03 04 05  12 13 14  21 22 23 |
00042     // | 06 07 08  15 16 17  24 25 26 |
00043     //  int     m_uiConnectivityPattern[27];    // skip/ignore the center, #13
00044     //---------------------------------------
00045     switch ( CP ) {
00046         case FULL_ONE_RING:
00047         default:
00048             //---------------------------------------------
00049             // FOR POSITIONS
00050             // Front Plane
00051             m_piConnectionPattern[ 0] = CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH_WEST];
00052             m_piConnectionPattern[ 1] = CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH];
00053             m_piConnectionPattern[ 2] = CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH_EAST];
00054             m_piConnectionPattern[ 3] = CONNECTION_INDEX_POSITION[SpringProp::FRONT_WEST];
00055             m_piConnectionPattern[ 4] = CONNECTION_INDEX_POSITION[SpringProp::FRONT];
00056             m_piConnectionPattern[ 5] = CONNECTION_INDEX_POSITION[SpringProp::FRONT_EAST];
00057             m_piConnectionPattern[ 6] = CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH_WEST];
00058             m_piConnectionPattern[ 7] = CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH];
00059             m_piConnectionPattern[ 8] = CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH_EAST];
00060             // Center Plane
00061             m_piConnectionPattern[ 9] = CONNECTION_INDEX_POSITION[SpringProp::NORTH_WEST];
00062             m_piConnectionPattern[10] = CONNECTION_INDEX_POSITION[SpringProp::NORTH];
00063             m_piConnectionPattern[11] = CONNECTION_INDEX_POSITION[SpringProp::NORTH_EAST];
00064             m_piConnectionPattern[12] = CONNECTION_INDEX_POSITION[SpringProp::WEST];
00065             m_piConnectionPattern[13] = CONNECTION_INDEX_POSITION[SpringProp::NOT_CONNECTED];
00066             m_piConnectionPattern[14] = CONNECTION_INDEX_POSITION[SpringProp::EAST];
00067             m_piConnectionPattern[15] = CONNECTION_INDEX_POSITION[SpringProp::SOUTH_WEST];
00068             m_piConnectionPattern[16] = CONNECTION_INDEX_POSITION[SpringProp::SOUTH];
00069             m_piConnectionPattern[17] = CONNECTION_INDEX_POSITION[SpringProp::SOUTH_EAST];
00070             // Back Plane
00071             m_piConnectionPattern[18] = CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH_WEST];
00072             m_piConnectionPattern[19] = CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH];
00073             m_piConnectionPattern[20] = CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH_EAST];
00074             m_piConnectionPattern[21] = CONNECTION_INDEX_POSITION[SpringProp::BACK_WEST];
00075             m_piConnectionPattern[22] = CONNECTION_INDEX_POSITION[SpringProp::BACK];
00076             m_piConnectionPattern[23] = CONNECTION_INDEX_POSITION[SpringProp::BACK_EAST];
00077             m_piConnectionPattern[24] = CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH_WEST];
00078             m_piConnectionPattern[25] = CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH];
00079             m_piConnectionPattern[26] = CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH_EAST];
00080             //---------------------------------------------
00081             //---------------------------------------------
00082             // FOR CONNECTIVITIES
00083             // Front Plane
00084             m_piConnectionPatternToTextureConnectivity[ 0] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_NORTH_WEST];
00085             m_piConnectionPatternToTextureConnectivity[ 1] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_NORTH];
00086             m_piConnectionPatternToTextureConnectivity[ 2] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_NORTH_EAST];
00087             m_piConnectionPatternToTextureConnectivity[ 3] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_WEST];
00088             m_piConnectionPatternToTextureConnectivity[ 4] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT];
00089             m_piConnectionPatternToTextureConnectivity[ 5] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_EAST];
00090             m_piConnectionPatternToTextureConnectivity[ 6] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_SOUTH_WEST];
00091             m_piConnectionPatternToTextureConnectivity[ 7] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_SOUTH];
00092             m_piConnectionPatternToTextureConnectivity[ 8] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::FRONT_SOUTH_EAST];
00093             // Center Plane
00094             m_piConnectionPatternToTextureConnectivity[ 9] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::NORTH_WEST];
00095             m_piConnectionPatternToTextureConnectivity[10] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::NORTH];
00096             m_piConnectionPatternToTextureConnectivity[11] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::NORTH_EAST];
00097             m_piConnectionPatternToTextureConnectivity[12] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::WEST];
00098             m_piConnectionPatternToTextureConnectivity[13] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::NOT_CONNECTED];
00099             m_piConnectionPatternToTextureConnectivity[14] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::EAST];
00100             m_piConnectionPatternToTextureConnectivity[15] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::SOUTH_WEST];
00101             m_piConnectionPatternToTextureConnectivity[16] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::SOUTH];
00102             m_piConnectionPatternToTextureConnectivity[17] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::SOUTH_EAST];
00103             // Back Plane
00104             m_piConnectionPatternToTextureConnectivity[18] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_NORTH_WEST];
00105             m_piConnectionPatternToTextureConnectivity[19] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_NORTH];
00106             m_piConnectionPatternToTextureConnectivity[20] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_NORTH_EAST];
00107             m_piConnectionPatternToTextureConnectivity[21] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_WEST];
00108             m_piConnectionPatternToTextureConnectivity[22] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK];
00109             m_piConnectionPatternToTextureConnectivity[23] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_EAST];
00110             m_piConnectionPatternToTextureConnectivity[24] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_SOUTH_WEST];
00111             m_piConnectionPatternToTextureConnectivity[25] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_SOUTH];
00112             m_piConnectionPatternToTextureConnectivity[26] = CONNECTION_INDEX_CONNECTIVITY[SpringProp::BACK_SOUTH_EAST];
00113             //---------------------------------------------
00114             /*
00115             #ifdef  TAPs_DEBUG_MODE
00116             std::cout << "Connection Pattern\n";
00117             std::cout << "------------------\n";
00118             for ( int i = 0; i < 27; ++i ) {
00119                 std::cout << "m_piConnectionPattern[" << i << "]: " << m_piConnectionPattern[i] << "\n";
00120             }
00121             std::cout << "------------------\n";
00122             #endif//TAPs_DEBUG_MODE
00123             //*/
00124             //---------------------------------------------
00125         break;
00126     }
00127 }
00128 //-----------------------------------------------------------------------------
00129 //=============================================================================
00130 
00131 
00132 //*****************************************************************************
00133 // BEGIN: Setup3DTexturesForConnectivities
00134 //-----------------------------------------------------------------------------
00135 template <typename T>
00136 bool ModelDeformableGLSL<T>::Setup3DTextureForConnectivities ( 
00137     int resolutionX, int resolutionY, int resolutionZ, 
00138     T ****                                  ptElementPosition, 
00139     enum GridGenerator<T>::VertexFlag ***   pcElementFlag, 
00140     enum ConnectivityPattern cp
00141 )
00142 {
00143     //---------------------------------------------------------------
00144     // Values of Textures for Connectivities
00145     // 4 components for one FCB+1, and 3(width) x 3(height) for one plane
00146     GLenum      target          =   m_3DTexturePosition->GetTarget();
00147     GLint       level           =   m_3DTexturePosition->GetLevel();
00148     GLint       internalFormat  =   GL_RGBA32F_ARB;
00149     GLsizei     width           =   m_3DTexturePosition->GetWidth()  * 3;
00150     GLsizei     height          =   m_3DTexturePosition->GetHeight() * 3;
00151     GLsizei     depth           =   m_3DTexturePosition->GetDepth();
00152     GLint       border          =   m_3DTexturePosition->GetBorder();
00153     GLenum      pixelFormat     =   GL_RGBA;
00154     GLenum      dataType        =   m_3DTexturePosition->GetDataType();
00155     //
00156     unsigned char   internalFormatNumOfComponents   =   4;
00157     unsigned char   pixelFormatNumOfComponents      =   4;
00158     //
00159     unsigned short  numOfTextures   =   2;
00160     //---------------------------------------------------------------
00161     //-------------------------------------------
00162     // From the header file
00163     //-------------------------------------------
00164     // Identification Numbers (for front, center, and back planes)
00165     // --------------------------------
00166     // |   FRONT    CENTER     BACK   |
00167     // | 00 01 02  09 10 11  18 19 20 |
00168     // | 03 04 05  12 13 14  21 22 23 |
00169     // | 06 07 08  15 16 17  24 25 26 |
00170     //  int     m_uiConnectivityPattern[27];    // skip/ignore the center, #13
00171     // --------------------------------
00172     SetupConnectivityPattern( ConnectivityPattern::FULL_ONE_RING );
00173     // After the above statement m_piConnectionPattern and 
00174     //   m_piConnectionPatternToTextureConnectivity
00175     //   are set according to the passed ConnectivityPattern argument.
00176     //---------------------------------------------------------------
00177     // Setup Data for Connectivities
00178     //*******************************************
00179     // The coordinate (s,t) values must be mapped to range [0,1]
00180     SetupTextureCoordinateValues( 
00181         offsetCoordSPosition, offsetCoordTPosition, offsetCoordRPosition, 
00182         m_3DTexturePosition->GetWidth(),
00183         m_3DTexturePosition->GetHeight(),
00184         m_3DTexturePosition->GetDepth()
00185     );
00186     SetupTextureCoordinateValues( 
00187         offsetCoordSConnection, offsetCoordTConnection, offsetCoordRConnection, 
00188         width, 
00189         height, 
00190         depth 
00191     );
00192 
00193     /*
00194     // DEBUG
00195     std::cout << "offsetCoordsPosition: " 
00196             << offsetCoordSPosition << " " 
00197             << offsetCoordTPosition << " " 
00198             << offsetCoordRPosition << "\n";
00199     std::cout << "offsetCoordsConnection: " 
00200             << offsetCoordSConnection << " " 
00201             << offsetCoordTConnection << " " 
00202             << offsetCoordRConnection << "\n";
00203     //*/
00204 
00205     //*******************************************
00206     //===============================================================
00207     // Setup Texture for Connectivities
00208     //---------------------------------------------------------------
00209     unsigned int offset = width * height * pixelFormatNumOfComponents;
00210     //-----------------------------------------------------
00211     int iMemorySizeForTotalElements = offset * resolutionZ;
00212     GLfloat * connectivityData = new GLfloat[ iMemorySizeForTotalElements ];
00213     assert( connectivityData );
00214     for ( int i = 0; i < iMemorySizeForTotalElements; ++i ) {
00215         connectivityData[i] = 0;
00216     }
00217 
00218     //-----------------------------------------------------
00219     // DEBUG
00220 #ifdef  TAPs_DEBUG_MODE
00221     std::cout << "size of connectivityData: " << iMemorySizeForTotalElements << "\n";
00222     std::cout << "m_piConnectionPattern[27]: " << "\n";
00223     std::cout << " FRONT        CENTER           BACK \n";
00224     std::cout << m_piConnectionPattern[ 0] << " " << m_piConnectionPattern[ 1] << " " << m_piConnectionPattern[ 2] << "\t\t";
00225     std::cout << m_piConnectionPattern[ 9] << " " << m_piConnectionPattern[10] << " " << m_piConnectionPattern[11] << "\t\t";
00226     std::cout << m_piConnectionPattern[18] << " " << m_piConnectionPattern[19] << " " << m_piConnectionPattern[20] << "\n";
00227     //
00228     std::cout << m_piConnectionPattern[ 3] << " " << m_piConnectionPattern[ 4] << " " << m_piConnectionPattern[ 5] << "\t\t";
00229     std::cout << m_piConnectionPattern[12] << " " << m_piConnectionPattern[13] << " " << m_piConnectionPattern[14] << "\t\t";
00230     std::cout << m_piConnectionPattern[21] << " " << m_piConnectionPattern[22] << " " << m_piConnectionPattern[23] << "\n";
00231     //
00232     std::cout << m_piConnectionPattern[ 6] << " " << m_piConnectionPattern[ 7] << " " << m_piConnectionPattern[ 8] << "\t\t";
00233     std::cout << m_piConnectionPattern[15] << " " << m_piConnectionPattern[16] << " " << m_piConnectionPattern[17] << "\t\t";
00234     std::cout << m_piConnectionPattern[24] << " " << m_piConnectionPattern[25] << " " << m_piConnectionPattern[26] << "\n";
00235 #endif//TAPs_DEBUG_MODE
00236     //-----------------------------------------------------
00237 
00238     //-----------------------------------------------------
00239     SetupAllConnections( 
00240         resolutionX, resolutionY, resolutionZ, 
00241         m_glpTexelForVertexPos, 
00242         m_piConnectionPattern, 
00243         //250.0,                    // Threshold value  (without outside data)
00244         //150.0,                    // Threshold value  (with inside data)
00245         m_tSimThreshold,
00246         connectivityData 
00247     );
00248     //-----------------------------------------------------
00249     // One 3D texture for Connectivities
00250     m_3DTextureConnectivity = new Texture( 
00251         target, level, internalFormat, 
00252         width, height, depth, 
00253         border, pixelFormat, dataType, 
00254         //connectivityData,             // texels
00255         NULL,                           // texels
00256         numOfTextures, 
00257         GL_NEAREST, GL_NEAREST,         // mag & min filter
00258         GL_CLAMP, GL_CLAMP, GL_CLAMP    // wrap s, t, & r
00259     );
00260     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00261     //---------------------------------
00262     // Current (for reading) [0] & Change (for writing) [1]
00263     for ( int i = 0; i < numOfTextures; ++i ) {
00264         GLuint texName = m_3DTextureConnectivity->GetTexture( i );
00265         glBindTexture( GL_TEXTURE_3D, texName );
00266         glTexImage3D( 
00267             m_3DTextureConnectivity->GetTarget(),
00268             m_3DTextureConnectivity->GetLevel(),
00269             m_3DTextureConnectivity->GetInternalFormat(),
00270             m_3DTextureConnectivity->GetWidth(),
00271             m_3DTextureConnectivity->GetHeight(),
00272             m_3DTextureConnectivity->GetDepth(),
00273             m_3DTextureConnectivity->GetBorder(),
00274             m_3DTextureConnectivity->GetPixelFormat(),
00275             m_3DTextureConnectivity->GetDataType(),
00276             connectivityData 
00277         );
00278         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00279     }
00280     //---------------------------------------------------------------
00281     //===============================================================
00282     //---------------------------------------------------------------
00283     delete [] connectivityData;
00284     //---------------------------------------------------------------
00285 
00286     //---------------------------------------------------------------
00287     // DEBUG: Print out the Element Home Positions after setup
00288 #ifdef  TAPs_DEBUG_MODE
00289     assert ( m_3DTextureHomePosition );
00290     //for ( int i = 0; i < m_3DTextureHomePosition->GetNumberOfTextures(); ++i ) {
00291     for ( int i = 0; i < 1; ++i ) {
00292         std::cout << "\nm_3DTextureHomePosition -- Texture#" << i << ":\n";
00293         DebugTextureData( 
00294             m_3DTextureHomePosition->GetWidth(), 
00295             m_3DTextureHomePosition->GetHeight(), 
00296             m_3DTextureHomePosition->GetDepth(), 
00297             m_3DTextureHomePosition->GetInternalFormatNumberOfComponents(), 
00298             m_3DTextureHomePosition->GetTarget(), 
00299             m_3DTextureHomePosition->GetPixelFormat(), 
00300             m_3DTextureHomePosition->GetDataType(), 
00301             m_3DTextureHomePosition->GetTexture(i)
00302         );
00303     }
00304 #endif//TAPs_DEBUG_MODE
00305     //---------------------------------------------------------------
00306     // DEBUG: Print out the Element Positions after setup
00307 #ifdef  TAPs_DEBUG_MODE
00308     assert ( m_3DTexturePosition );
00309     //for ( int i = 0; i < m_3DTexturePosition->GetNumberOfTextures(); ++i ) {
00310     for ( int i = 0; i < 1; ++i ) {
00311         std::cout << "\nm_3DTexturePosition -- Texture#" << i << ":\n";
00312         DebugTextureData( 
00313             m_3DTexturePosition->GetWidth(), 
00314             m_3DTexturePosition->GetHeight(), 
00315             m_3DTexturePosition->GetDepth(), 
00316             m_3DTexturePosition->GetInternalFormatNumberOfComponents(), 
00317             m_3DTexturePosition->GetTarget(), 
00318             m_3DTexturePosition->GetPixelFormat(), 
00319             m_3DTexturePosition->GetDataType(), 
00320             m_3DTexturePosition->GetTexture(i)
00321         );
00322     }
00323 #endif//TAPs_DEBUG_MODE
00324     //---------------------------------------------------------------
00325     // DEBUG: Print out the Connectivity Data after setup
00326 #ifdef  TAPs_DEBUG_MODE
00327     assert( m_3DTextureConnectivity );
00328     //for ( int i = 0; i < m_3DTextureConnectivity->GetNumberOfTextures(); ++i ) {
00329     for ( int i = 0; i < 1; ++i ) {
00330         std::cout << "\nm_3DTextureConnectivity -- Texture#" << i << ":\n";
00331         DebugTextureDataInConnectivityFormat( 
00332             m_3DTextureConnectivity->GetWidth(),
00333             m_3DTextureConnectivity->GetHeight(),
00334             m_3DTextureConnectivity->GetDepth(),
00335             m_3DTextureConnectivity->GetInternalFormatNumberOfComponents(),
00336             m_3DTextureConnectivity->GetTarget(),
00337             m_3DTextureConnectivity->GetPixelFormat(),
00338             m_3DTextureConnectivity->GetDataType(),
00339             m_3DTextureConnectivity->GetTexture(i)
00340         );
00341     }
00342 #endif//TAPs_DEBUG_MODE
00343     //---------------------------------------------------------------
00344 
00345     //---------------------------------------------------------------
00346     return true;
00347 }
00348 //-----------------------------------------------------------------------------
00349 // END: Setup3DTextureForConnectivities
00350 //*****************************************************************************
00351 
00352 
00353 //*****************************************************************************
00354 // BEGIN: SetupAllConnections
00355 //-----------------------------------------------------------------------------
00356 template <typename T>
00357 void ModelDeformableGLSL<T>::SetupAllConnections ( 
00358     int resolutionX, int resolutionY, int resolutionZ,  // I/Ps:
00359     GLfloat const * pVertexPosAndFlag,  // I/Ps: pointer to vertex pos + flag
00360     int const connectionPattern[27],    // I/Ps: connection pattern
00361     int threshold,                      // I/Ps: threshold value
00362     GLfloat * connectivityData          // O/Ps: connectivity data
00363 )
00364 {
00365     //-------------------------------------------------
00366     // Create connection index to textures
00367     //   Index
00368     // ----------------------------------------------------------------------
00369     // |         FRONT (x)    |        CENTER (y)    |         BACK (z)     |
00370     // |   00     01     02   |   09     10     11   |   18     19     20   |
00371     // |   03     04     05   |   12     13     14   |   21     22     23   |
00372     // |   06     07     08   |   15     16     17   |   24     25     26   |
00373     // ----------------------------------------------------------------------
00374     //   Data
00375     // ----------------------------------------------------------------------
00376     // |         FRONT (x)    |        CENTER (y)    |         BACK (z)     |
00377     // | 0z+y-x 0z+y-0 0z+y+x | 1z+y-x 1z+y-0 1z+y+x | 2z+y-x 2z+y-0 2z+y+x |
00378     // | 0z-0-x 0z-0-0 0z-0+x | 1z-0-x 1z-0-0 1z-0+x | 2z-0-x 2z-0-0 2z-0+x |
00379     // | 0z-y-x 0z-y-0 0z-y+x | 1z-y-x 1z-y-0 1z-y+x | 2z-y-x 2z-y-0 2z-y+x |
00380     // ----------------------------------------------------------------------
00381 
00382     //---------------------------------------------------------------
00383     // All elements not on the boundary
00384     for ( int Z = 1; Z < resolutionZ-1; ++Z ) {
00385         for ( int Y = 1; Y < resolutionY-1; ++Y ) {
00386             for ( int X = 1; X < resolutionX-1; ++X ) {
00387                 SetupConnectionsOfOneElementNotOnBoundary( 
00388                     resolutionX, resolutionY, 
00389                     pVertexPosAndFlag, 
00390                     connectionPattern, 
00391                     X, Y, Z, 
00392                     m_piConnectionPatternToTextureConnectivity, 
00393                     threshold, 
00394                     connectivityData 
00395                 );
00396             }
00397         }
00398     }
00399     //---------------------------------------------------------------
00400     // The first (and back) slice and the last (and front) slice
00401     for ( int Z = 0; Z < resolutionZ; Z += resolutionZ-1 ) {
00402         for ( int Y = 0; Y < resolutionY; ++Y ) {
00403             for ( int X = 0; X < resolutionX; ++X ) {
00404                 SetupConnectionsOfOneElementOnBoundary( 
00405                     resolutionX, resolutionY, resolutionZ, 
00406                     pVertexPosAndFlag, 
00407                     connectionPattern, 
00408                     X, Y, Z, 
00409                     m_piConnectionPatternToTextureConnectivity, 
00410                     threshold, 
00411                     connectivityData 
00412                 );
00413             }
00414         }
00415     }
00416     //---------------------------------------------------------------
00417     // The bottom slice and the top slice
00418     for ( int Z = 0; Z < resolutionZ; ++Z ) {
00419         for ( int Y = 0; Y < resolutionY; Y += resolutionY-1 ) {
00420             for ( int X = 0; X < resolutionX; ++X ) {
00421                 SetupConnectionsOfOneElementOnBoundary( 
00422                     resolutionX, resolutionY, resolutionZ, 
00423                     pVertexPosAndFlag, 
00424                     connectionPattern, 
00425                     X, Y, Z, 
00426                     m_piConnectionPatternToTextureConnectivity, 
00427                     threshold, 
00428                     connectivityData 
00429                 );
00430             }
00431         }
00432     }
00433     //---------------------------------------------------------------
00434     // The left slice and the right slice
00435     for ( int Z = 1; Z < resolutionZ-1; ++Z ) {
00436         for ( int Y = 1; Y < resolutionY-1; ++Y ) {
00437             for ( int X = 0; X < resolutionX; X += resolutionX-1 ) {
00438                 SetupConnectionsOfOneElementOnBoundary( 
00439                     resolutionX, resolutionY, resolutionZ, 
00440                     pVertexPosAndFlag, 
00441                     connectionPattern, 
00442                     X, Y, Z, 
00443                     m_piConnectionPatternToTextureConnectivity, 
00444                     threshold, 
00445                     connectivityData 
00446                 );
00447             }
00448         }
00449     }
00450 }
00451 //-----------------------------------------------------------------------------
00452 // END: SetupAllConnections
00453 //*****************************************************************************
00454 
00455 
00456 //*****************************************************************************
00457 // BEGIN: SetupConnectionsOfOneElementNotOnBoundary
00458 //-----------------------------------------------------------------------------
00459 template <typename T>
00460 void ModelDeformableGLSL<T>::SetupConnectionsOfOneElementNotOnBoundary ( 
00461     int resolutionX, int resolutionY,   // I/Ps: texture width & height
00462     GLfloat const * pVertexPosAndFlag,  // I/Ps: pointer to vertex pos + flag
00463     int const connectionPattern[27],    // I/Ps: connection pattern to neighbor voxel
00464     int x, int y, int z,                // I/Ps: element location
00465     int const connectionTexture[27],    // I/Ps: connection index to textures
00466     int threshold,                      // I/Ps: threshold value
00467     GLfloat * connectivityData          // O/Ps: connectivity data
00468 )
00469 {
00470     //-------------------------------------------------
00471     // Indices to the original voxel data
00472     int iOffsetSlice = resolutionX * resolutionY;                   // 4 for positions + flag
00473     int indexThis    = (z*iOffsetSlice + y*resolutionX + x)*4 + 3;  // + 3 for accessing the flag
00474     int indexConnectedTo;
00475     // Indices to the connectivity texture
00476     int idxConnectionTextureBase = (z*iOffsetSlice*9 + (1+3*y)*resolutionX*3 + (1+3*x))*4;  // 3x3 for extra width & height of connectivity texture
00477     int idxConnectionTexture;
00478     //-------------------------------------------------
00479     // Check if this voxel does not represent void
00480     //static T threshold = 250;
00481 
00482     // DEBUG
00483     //std::cout << "NOT ON BOUNDARY: Threshold (" << pVertexPosAndFlag[indexThis] << ") -- XYZ: " << x << " " << y << " " << z << "\n";
00484 
00485     if ( pVertexPosAndFlag[indexThis] < threshold ) return;
00486     //-------------------------------------------------
00487     //-------------------------------------------------
00488     // Identification Numbers (for front, center, and back planes)
00489     // --------------------------------
00490     // |   FRONT    CENTER     BACK   |
00491     // | 00 01 02  09 10 11  18 19 20 |
00492     // | 03 04 05  12 13 14  21 22 23 |
00493     // | 06 07 08  15 16 17  24 25 26 |
00494     // --------------------------------
00495 
00496     // DEBUG
00497     //std::cout << "NOT ON BOUNDARY: Passed Threshold Test -- XYZ: " << x << " " << y << " " << z << "\n";
00498 
00499 
00500     for ( int i = 0; i < 27; ++i ) {
00501         indexConnectedTo = indexThis + connectionPattern[i];
00502 
00503         // DEBUG
00504         //connectivityData[indexConnectedTo] = 101;
00505 
00506         // DEBUG
00507         //std::cout << "THRESHOLD: pVertexPosAndFlag[" << indexConnectedTo << "] = " << pVertexPosAndFlag[indexConnectedTo] << " -- ";
00508 
00509         idxConnectionTexture = idxConnectionTextureBase + connectionTexture[i];
00510         //
00511         if ( connectionPattern[i] != 0 && pVertexPosAndFlag[indexConnectedTo] >= threshold ) {
00512             //std::cout << "PASSED: write to #: " << idxConnectionTexture << "\n";
00513             connectivityData[idxConnectionTexture] = 1.0;
00514         }
00515         else {
00516             //std::cout << "FAILED:\n";
00517             connectivityData[idxConnectionTexture] = 0.0;
00518         }
00519     }
00520     //-----------------------------------------------------
00521     // Add Connection for Home Spring
00522     idxConnectionTexture = idxConnectionTextureBase + connectionTexture[13];
00523     connectivityData[idxConnectionTexture] = 1.0;
00524     //-----------------------------------------------------
00525 }
00526 //-----------------------------------------------------------------------------
00527 // END: SetupConnectionsOfOneElementNotOnBoundary
00528 //*****************************************************************************
00529 
00530 
00531 //*****************************************************************************
00532 // BEGIN: SetupConnectionsOfOneElementOnBoundary
00533 //-----------------------------------------------------------------------------
00534 template <typename T>
00535 void ModelDeformableGLSL<T>::SetupConnectionsOfOneElementOnBoundary ( 
00536     int resolutionX, int resolutionY, int resolutionZ,  // I/Ps: texture width & height
00537     GLfloat const * pVertexPosAndFlag,  // I/Ps: pointer to vertex pos + flag
00538     int const connectionPattern[27],    // I/Ps: connection pattern to neighbor voxel
00539     int x, int y, int z,                // I/Ps: element location
00540     int const connectionTexture[27],    // I/Ps: connection index to textures
00541     int threshold,                      // I/Ps: threshold value
00542     GLfloat * connectivityData          // O/Ps: connectivity data
00543 )
00544 {
00545     //-------------------------------------------------
00546     // Indices to the original voxel data
00547     int iOffsetSlice = resolutionX * resolutionY;                   // 4 for positions + flag
00548     int indexThis    = (z*iOffsetSlice + y*resolutionX + x)*4 + 3;  // + 3 for accessing the flag
00549     int indexConnectedTo;
00550     // Indices to the connectivity texture
00551     int idxConnectionTextureBase = (z*iOffsetSlice*9 + (1+3*y)*resolutionX*3 + (1+3*x))*4;  // 3x3 for extra width & height of connectivity texture
00552     int idxConnectionTexture;
00553     //-------------------------------------------------
00554     // Check if this voxel does not represent void
00555     //static T threshold = 250;
00556 
00557     // DEBUG
00558     //std::cout << "ON BOUNDARY: Threshold (" << pVertexPosAndFlag[indexThis] << ") -- XYZ: " << x << " " << y << " " << z << "\n";
00559 
00560     if ( pVertexPosAndFlag[indexThis] < threshold ) return;
00561     //-------------------------------------------------
00562     int iBoundEast  = resolutionX - 1;
00563     int iBoundWest  = 0;
00564     int iBoundNorth = resolutionY - 1;
00565     int iBoundSouth = 0;
00566     int iBoundFront = resolutionZ - 1;
00567     int iBoundBack  = 0;
00568     //-------------------------------------------------
00569     // Identification Numbers (for front, center, and back planes)
00570     // --------------------------------
00571     // |   FRONT    CENTER     BACK   |
00572     // | 00 01 02  09 10 11  18 19 20 |
00573     // | 03 04 05  12 13 14  21 22 23 |
00574     // | 06 07 08  15 16 17  24 25 26 |
00575     // --------------------------------
00576 
00577     // DEBUG
00578     //std::cout << "NOT ON BOUNDARY: Passed Threshold Test -- XYZ: " << x << " " << y << " " << z << "\n";
00579 
00580     for ( int i = 0; i < 27; ++i ) {
00581         indexConnectedTo = 0;
00582         idxConnectionTexture = idxConnectionTextureBase + connectionTexture[i];
00583         //=================================================
00584         //-------------------------------------------------
00585         if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::EAST] ) {
00586             if ( x < iBoundEast ) {
00587                 indexConnectedTo = indexThis + connectionPattern[i];
00588             }
00589         }
00590         //-------------------------------------------------
00591         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::NORTH] ) {
00592             if ( y < iBoundNorth ) {
00593                 indexConnectedTo = indexThis + connectionPattern[i];
00594             }
00595         }
00596         //-------------------------------------------------
00597         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::WEST] ) {
00598             if ( x > iBoundWest ) {
00599                 indexConnectedTo = indexThis + connectionPattern[i];
00600             }
00601         }
00602         //-------------------------------------------------
00603         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::SOUTH] ) {
00604             if ( y > iBoundSouth ) {
00605                 indexConnectedTo = indexThis + connectionPattern[i];
00606             }
00607         }
00608         //=================================================
00609         //-------------------------------------------------
00610         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT] ) {
00611             if ( z < iBoundFront ) {
00612                 indexConnectedTo = indexThis + connectionPattern[i];
00613             }
00614         }
00615         //-------------------------------------------------
00616         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK] ) {
00617             if ( z > iBoundBack ) {
00618                 indexConnectedTo = indexThis + connectionPattern[i];
00619             }
00620         }
00621         //=================================================
00622         //-------------------------------------------------
00623         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::NORTH_EAST] ) {
00624             if ( y < iBoundNorth && x < iBoundEast ) {
00625                 indexConnectedTo = indexThis + connectionPattern[i];
00626             }
00627         }
00628         //-------------------------------------------------
00629         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::NORTH_WEST] ) {
00630             if ( y < iBoundNorth && x > iBoundWest ) {
00631                 indexConnectedTo = indexThis + connectionPattern[i];
00632             }
00633         }
00634         //-------------------------------------------------
00635         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::SOUTH_WEST] ) {
00636             if ( y > iBoundSouth && x > iBoundWest ) {
00637                 indexConnectedTo = indexThis + connectionPattern[i];
00638             }
00639         }
00640         //-------------------------------------------------
00641         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::SOUTH_EAST] ) {
00642             if ( y > iBoundSouth && x < iBoundEast ) {
00643                 indexConnectedTo = indexThis + connectionPattern[i];
00644             }
00645         }
00646         //=================================================
00647         //-------------------------------------------------
00648         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT_EAST] ) {
00649             if ( z < iBoundFront && x < iBoundEast ) {
00650                 indexConnectedTo = indexThis + connectionPattern[i];
00651             }
00652         }
00653         //-------------------------------------------------
00654         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH] ) {
00655             if ( z < iBoundFront && y < iBoundNorth ) {
00656                 indexConnectedTo = indexThis + connectionPattern[i];
00657             }
00658         }
00659         //-------------------------------------------------
00660         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT_WEST] ) {
00661             if ( z < iBoundFront && x > iBoundWest ) {
00662                 indexConnectedTo = indexThis + connectionPattern[i];
00663             }
00664         }
00665         //-------------------------------------------------
00666         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH] ) {
00667             if ( z < iBoundFront && y > iBoundSouth ) {
00668                 indexConnectedTo = indexThis + connectionPattern[i];
00669             }
00670         }
00671         //=================================================
00672         //-------------------------------------------------
00673         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK_EAST] ) {
00674             if ( z > iBoundBack && x < iBoundEast ) {
00675                 indexConnectedTo = indexThis + connectionPattern[i];
00676             }
00677         }
00678         //-------------------------------------------------
00679         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH] ) {
00680             if ( z > iBoundBack && y < iBoundNorth ) {
00681                 indexConnectedTo = indexThis + connectionPattern[i];
00682             }
00683         }
00684         //-------------------------------------------------
00685         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK_WEST] ) {
00686             if ( z > iBoundBack && x > iBoundWest ) {
00687                 indexConnectedTo = indexThis + connectionPattern[i];
00688             }
00689         }
00690         //-------------------------------------------------
00691         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH] ) {
00692             if ( z > iBoundBack && y > iBoundSouth ) {
00693                 indexConnectedTo = indexThis + connectionPattern[i];
00694             }
00695         }
00696         //=================================================
00697         //-------------------------------------------------
00698         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH_EAST] ) {
00699             if ( z < iBoundFront && y < iBoundNorth && x < iBoundEast ) {
00700                 indexConnectedTo = indexThis + connectionPattern[i];
00701             }
00702         }
00703         //-------------------------------------------------
00704         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT_NORTH_WEST] ) {
00705             if ( z < iBoundFront && y < iBoundNorth && x > iBoundWest ) {
00706                 indexConnectedTo = indexThis + connectionPattern[i];
00707             }
00708         }
00709         //-------------------------------------------------
00710         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH_WEST] ) {
00711             if ( z < iBoundFront && y > iBoundSouth && x > iBoundWest ) {
00712                 indexConnectedTo = indexThis + connectionPattern[i];
00713             }
00714         }
00715         //-------------------------------------------------
00716         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::FRONT_SOUTH_EAST] ) {
00717             if ( z < iBoundFront && y > iBoundSouth && x < iBoundEast ) {
00718                 indexConnectedTo = indexThis + connectionPattern[i];
00719             }
00720         }
00721         //=================================================
00722         //-------------------------------------------------
00723         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH_EAST] ) {
00724             if ( z > iBoundBack && y < iBoundNorth && x < iBoundEast ) {
00725                 indexConnectedTo = indexThis + connectionPattern[i];
00726             }
00727         }
00728         //-------------------------------------------------
00729         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK_NORTH_WEST] ) {
00730             if ( z > iBoundBack && y < iBoundNorth && x > iBoundWest ) {
00731                 indexConnectedTo = indexThis + connectionPattern[i];
00732             }
00733         }
00734         //-------------------------------------------------
00735         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH_WEST] ) {
00736             if ( z > iBoundBack && y > iBoundSouth && x > iBoundWest ) {
00737                 indexConnectedTo = indexThis + connectionPattern[i];
00738             }
00739         }
00740         //-------------------------------------------------
00741         else if ( connectionPattern[i] == CONNECTION_INDEX_POSITION[SpringProp::BACK_SOUTH_EAST] ) {
00742             if ( z > iBoundBack && y > iBoundSouth && x < iBoundEast ) {
00743                 indexConnectedTo = indexThis + connectionPattern[i];
00744             }
00745         }
00746         //-------------------------------------------------
00747         //=================================================
00748         //-------------------------------------------------
00749         if ( indexConnectedTo > 0 && pVertexPosAndFlag[indexConnectedTo] >= threshold ) {
00750                 connectivityData[idxConnectionTexture] = 1.0;
00751         }
00752         else {
00753             connectivityData[idxConnectionTexture] = 0.0;
00754         }
00755     }
00756     //-----------------------------------------------------
00757     // Add Connection for Home Spring
00758     idxConnectionTexture = idxConnectionTextureBase + connectionTexture[13];
00759     connectivityData[idxConnectionTexture] = 1.0;
00760     //-----------------------------------------------------
00761 }
00762 //-----------------------------------------------------------------------------
00763 // END: SetupConnectionsOfOneElementOnBoundary
00764 //*****************************************************************************
00765 
00766 
00767 //*****************************************************************************
00768 // BEGIN: DrawByGL_AllElementsWithConnectivities_GPU
00769 //-----------------------------------------------------------------------------
00770 template <typename T>
00771 void ModelDeformableGLSL<T>::DrawByGL_AllElementsWithConnectivities_GPU ()
00772 {
00773 //*
00774     //---------------------------------------------------------------
00775     if ( !m_3DTexturePosition ) return;
00776     //---------------------------------------------------------------
00777     glPushAttrib( GL_ALL_ATTRIB_BITS );
00778     //-----------------------------------------------------
00779     GLsizei sizeForPosition = 
00780             m_3DTexturePosition->GetWidth() *
00781             m_3DTexturePosition->GetHeight() *
00782             m_3DTexturePosition->GetDepth() *
00783             m_3DTexturePosition->GetInternalFormatNumberOfComponents();
00784     GLfloat * dataForPosition = new GLfloat[ sizeForPosition ];
00785     //
00786     GLsizei sizeForConnectivity = 
00787             m_3DTextureConnectivity->GetWidth() *
00788             m_3DTextureConnectivity->GetHeight() *
00789             m_3DTextureConnectivity->GetDepth() *
00790             m_3DTextureConnectivity->GetInternalFormatNumberOfComponents();
00791     GLfloat * dataForConnectivity = new GLfloat[ sizeForConnectivity ];
00792     //
00793     {
00794         int i = 0;
00795         //=================================================
00796         // Read data for positions from a texture to memory
00797         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00798         m_3DTexturePosition->BindTexture(0);
00799         glGetTexImage( 
00800             m_3DTexturePosition->GetTarget(),
00801             m_3DTexturePosition->GetLevel(),
00802             m_3DTexturePosition->GetPixelFormat(),
00803             m_3DTexturePosition->GetDataType(),
00804             dataForPosition
00805         );
00806         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00807         //=================================================
00808         //=================================================
00809         // Read data for connectivities from a texture to memory
00810         glBindBuffer( GL_PIXEL_PACK_BUFFER, 0 );
00811         m_3DTextureConnectivity->BindTexture(0);
00812         glGetTexImage( 
00813             m_3DTextureConnectivity->GetTarget(),
00814             m_3DTextureConnectivity->GetLevel(),
00815             m_3DTextureConnectivity->GetPixelFormat(),
00816             m_3DTextureConnectivity->GetDataType(),
00817             dataForConnectivity
00818         );
00819         TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00820         //=================================================
00821     }
00822     //---------------------------------------------------------------
00823     TAPs::OpenGL::Fn::CHECK_GL_ERROR();
00824     //-----------------------------------------------------
00825     glPopAttrib();
00826     //---------------------------------------------------------------
00827 
00828     /*
00829     //===============================================================
00830     // Drawing
00831     //---------------------------------------------------------------
00832     // Draw as Points
00833     glPushAttrib( GL_ALL_ATTRIB_BITS );
00834     int count = 0;
00835     glPointSize( 1 );
00836     glColor3f( 0.45, 0.47, 0.49 );
00837     glDisable( GL_LIGHTING );
00838     glBegin( GL_POINTS );
00839     //-----------------------------------------------------
00840     for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) {
00841         for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) {
00842             for ( int X = 0; X < m_vGridResolution[0]; ++X ) {
00843 
00844                 //if ( dataForPosition[count+3] > IC_Thresholds::OUTSIDE_MODEL ) {
00845                 //  glVertex3f( 
00846                 //      dataForPosition[count  ], 
00847                 //      dataForPosition[count+1], 
00848                 //      dataForPosition[count+2] 
00849                 //  );
00850                 //}
00851 
00853                 //if ( X == 1 && Y == 1 && Z == 1 ) {
00854                 //  glVertex3f( 
00855                 //      dataForPosition[count  ], 
00856                 //      dataForPosition[count+1], 
00857                 //      dataForPosition[count+2] 
00858                 //  );
00859                 //}
00860 
00861                 //-------------------------------
00862                 if ( IC_Thresholds::INSIDE_MODEL <= dataForPosition[count+3] ) {
00863                     glVertex3f( 
00864                         dataForPosition[count  ], 
00865                         dataForPosition[count+1], 
00866                         dataForPosition[count+2] 
00867                     );
00868                 }
00869                 //-------------------------------
00870                 else 
00871                     if ( IC_Thresholds::RIGHT_INSIDE_BOUNDARY <= dataForPosition[count+3] ) {
00872                     glVertex3f( 
00873                         dataForPosition[count  ], 
00874                         dataForPosition[count+1], 
00875                         dataForPosition[count+2] 
00876                     );
00877                 }
00878                 //-------------------------------
00879                 else if ( IC_Thresholds::ON_BOUNDARY <= dataForPosition[count+3] ) {
00880                     glVertex3f( 
00881                         dataForPosition[count  ], 
00882                         dataForPosition[count+1], 
00883                         dataForPosition[count+2] 
00884                     );
00885                 }
00886                 //-------------------------------
00887                 //else {
00888                 //        glVertex3f( 
00889                 //                dataForPosition[count  ], 
00890                 //                dataForPosition[count+1], 
00891                 //                dataForPosition[count+2] 
00892                 //        );
00893                 //}
00894                 //-------------------------------
00895                 count += 4;
00896             }
00897         }
00898     }
00899     glEnd();
00900     glPopAttrib();
00901     //---------------------------------
00902     //*/
00903     
00904 
00905     //*
00906     //===============================================================
00907     // Drawing
00908     //---------------------------------------------------------------
00909     // Draw as Spheres
00910     glPushAttrib( GL_ALL_ATTRIB_BITS );
00911     glEnable( GL_LIGHTING );
00912     //glEnable( GL_BLEND );
00913 
00914     int count = 0;
00915     m_OGLUsefulObj.SetColor( 0.1, 0.3, 0.25, 0.25 );
00916     Vector3<T> vScale( 
00917         // Ellipsoid touching each other
00918         //m_vGridDimension[0], 
00919         //m_vGridDimension[1], 
00920         //m_vGridDimension[2] 
00921 
00922         m_vGridDimension[0] / 4.0f, 
00923         m_vGridDimension[1] / 4.0f, 
00924         m_vGridDimension[2] / 4.0f 
00925     );
00926     //-----------------------------------------------------
00927     for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) {
00928         for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) {
00929             for ( int X = 0; X < m_vGridResolution[0]; ++X ) {
00930                 //-------------------------------
00931                 if ( IC_Thresholds::INSIDE_MODEL <= dataForPosition[count+3] ) {
00932                     m_OGLUsefulObj.SetColor( 0.10, 0.30, 0.50, 1.0 );   // some what blue
00933                     glPushMatrix();
00934                     glTranslatef( 
00935                         dataForPosition[count  ], 
00936                         dataForPosition[count+1], 
00937                         dataForPosition[count+2] 
00938                     );
00939                     m_OGLUsefulObj.DrawSphere( vScale );
00940                     glPopMatrix();
00941                 }
00942                 //-------------------------------
00943                 else if ( IC_Thresholds::RIGHT_INSIDE_BOUNDARY <= dataForPosition[count+3] ) {
00944                     m_OGLUsefulObj.SetColor( 0.10, 0.30, 0.25, 1.0 );   // some what green
00945                     glPushMatrix();
00946                     glTranslatef( 
00947                         dataForPosition[count  ], 
00948                         dataForPosition[count+1], 
00949                         dataForPosition[count+2] 
00950                     );
00951                     m_OGLUsefulObj.DrawSphere( vScale );
00952                     glPopMatrix();
00953                 }
00954                 //-------------------------------
00955                 else if ( IC_Thresholds::ON_BOUNDARY <= dataForPosition[count+3] ) {
00956                     m_OGLUsefulObj.SetColor( 0.50, 0.30, 0.10, 1.0 );   // some what yellow
00957                     glPushMatrix();
00958                     glTranslatef( 
00959                         dataForPosition[count  ], 
00960                         dataForPosition[count+1], 
00961                         dataForPosition[count+2] 
00962                     );
00963                     m_OGLUsefulObj.DrawSphere( vScale );
00964                     glPopMatrix();
00965                 }
00966                 //-------------------------------
00967                 else if ( IC_Thresholds::RIGHT_OUTSIDE_BOUNDARY <= dataForPosition[count+3] ) {
00968                     m_OGLUsefulObj.SetColor( 0.50, 0.25, 0.25, 1.0 );   // red
00969                     glPushMatrix();
00970                     glTranslatef( 
00971                         dataForPosition[count  ], 
00972                         dataForPosition[count+1], 
00973                         dataForPosition[count+2] 
00974                     );
00975                     m_OGLUsefulObj.DrawSphere( vScale );
00976                     glPopMatrix();
00977                 }
00978 
00992 
00993                 count += 4;
00994             }
00995         }
00996     }
00997     glPopAttrib();
00998     //---------------------------------
00999     //*/
01000 
01001     //*
01002     //-------------------------------------------
01003     // Draw Connections
01004     glPushAttrib( GL_ALL_ATTRIB_BITS );
01005     glLineWidth( 1 );
01006     //glLineWidth( 3 );
01007     glColor3f( 0.9, 1.0, 0.0 );
01008     glDisable( GL_LIGHTING );
01009     int idxElementPos = 0;
01010     int idxElementPos2 = 0;
01011     int idxElementConnection = 0;
01012     int idxConnectionBase = 0;
01013     int iOffsetSlice = m_vGridResolution[1] * m_vGridResolution[0] * 4;
01014     int iOffsetRow = m_vGridResolution[0] * 4;
01015     int iOffsetCol = 4;
01016     //------------------------------------------------------------------
01017     // ----------------------------------------------------------------------
01018     // |        FRONT(x)      |       CENTER(y)      |        BACK(z)       |
01019     // | 00(NW) 01(N)  02(NE) | 09(NW) 10(N)  11(NE) | 18(NW) 19(N)  20(NE) |
01020     // | 03(W)  04(C)  05(E)  | 12(W)  13(C)  14(E)  | 21(W)  22(C)  23(E)  |
01021     // | 06(SW) 07(S)  08(SE) | 15(SW) 16(S)  17(SE) | 24(SW) 25(S)  26(SE) |
01022     // ----------------------------------------------------------------------
01023     GLubyte color[3*27] = {
01024         100, 100, 0,        // FNW
01025         100, 100, 0,        // FN
01026         100, 100, 0,        // FNE
01027         100, 100, 0,        // FW
01028         100, 100, 255,      // FC
01029         100, 100, 0,        // FE
01030         100, 100, 0,        // FSW
01031         100, 100, 0,        // FS
01032         100, 100, 0,        // FSE
01033         //
01034         0, 100, 100,        // NW
01035         0, 255, 100,        // N
01036         0, 100, 100,        // NE
01037         255, 100, 100,      // W
01038         0, 100, 100,        // C
01039         255, 100, 100,      // E
01040         0, 100, 100,        // SW
01041         0, 255, 100,        // S
01042         0, 100, 100,        // SE
01043         //
01044         100, 0, 100,        // BNW
01045         100, 0, 100,        // BN
01046         100, 0, 100,        // BNE
01047         100, 0, 100,        // BW
01048         100, 0, 255,        // BC
01049         100, 0, 100,        // BE
01050         100, 0, 100,        // BSW
01051         100, 0, 100,        // BS
01052         100, 0, 100         // BSE
01053     };
01054     //------------------------------------------------------------------
01055     glBegin( GL_LINES );
01056     for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) {
01057         for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) {
01058             for ( int X = 0; X < m_vGridResolution[0]; ++X ) {
01059                 
01060                 //if ( m_glfpElementPos[idxElementPos + 3] < 450 ) {    // Skip all except an inside element
01061 
01062 
01063                 //if (   dataForPosition[idxElementPos + 3] < 250 
01064                 //  && dataForPosition[idxElementPos + 3] > 450 ) {
01065 
01066                 //if ( dataForPosition[idxElementPos + 3] < 150 ) { // Skip a void element
01067                 if ( false ) {
01068                 }
01069                 else {
01070                     for ( int i = 0; i < 27; ++i ) {
01071                         glColor3ubv( &color[i*3] );
01072                         idxConnectionBase = 
01073                               (Z*m_vGridResolution[0]*m_vGridResolution[1]*9 
01074                             + (1+3*Y)*m_vGridResolution[0]*3 
01075                             + (1+3*X))*4;   // 3x3 for extra width & height of connectivity texture
01076                         idxElementConnection = 
01077                             idxConnectionBase + m_piConnectionPatternToTextureConnectivity[i];
01078                         if ( dataForConnectivity[idxElementConnection] != 0 ) {
01079                             idxElementPos2 = idxElementPos + m_piConnectionPattern[i];
01080                             //if ( dataForPosition[idxElementPos2+3] >= m_tSimThreshold ) {
01081                                 glVertex3f( 
01082                                     dataForPosition[idxElementPos    ], 
01083                                     dataForPosition[idxElementPos + 1], 
01084                                     dataForPosition[idxElementPos + 2] 
01085                                 );
01086                                 glVertex3f( 
01087                                     dataForPosition[idxElementPos2    ], 
01088                                     dataForPosition[idxElementPos2 + 1], 
01089                                     dataForPosition[idxElementPos2 + 2] 
01090                                 );
01091                             //}
01092                         }
01093                     }
01094                 }
01095                 idxElementPos += 4;
01096             }
01097         }
01098     }
01099     glEnd();
01100     glPopAttrib();
01101     //*/
01102     //---------------------------------------------------------------
01103     //===============================================================
01104 
01108     //glPushAttrib( GL_ALL_ATTRIB_BITS );
01109     //glLineWidth( 3 );
01111     //glColor3ub( 240/2, 220/2, 130/2 );
01112     //glEnable( GL_COLOR_MATERIAL );
01113     //glEnable( GL_LIGHTING );
01114     //int iOffsetSlice = m_vGridResolution[1] * m_vGridResolution[0] * 4;
01115     //int iOffsetRow = m_vGridResolution[0] * 4;
01116     //int iOffsetCol = 4;
01122     //int idx[8] = {
01123     //  0, 
01124     //  iOffsetCol, 
01125     //  iOffsetRow + iOffsetCol, 
01126     //  iOffsetRow, 
01127     //  iOffsetSlice, 
01128     //  iOffsetSlice + iOffsetCol, 
01129     //  iOffsetSlice + iOffsetRow + iOffsetCol, 
01130     //  iOffsetSlice + iOffsetRow 
01131     //};
01132     //bool set[8];
01134     //int idxQ[6+8][4] = {
01135     //  { 0, 3, 2, 1 },     // back
01136     //  { 4, 5, 6, 7 },     // front
01137     //  { 7, 6, 2, 3 },     // top
01138     //  { 0, 1, 5, 4 },     // bottom
01139     //  { 0, 4, 7, 3 },     // left
01140     //  { 1, 2, 6, 5 },     // right
01141     //  //
01142     //  { 7, 6, 1, 0 },     // crossv1
01143     //  { 6, 2, 0, 4 },     // crossv2
01144     //  { 2, 3, 4, 5 },     // crossv3
01145     //  { 3, 7, 5, 1 },     // crossv4
01146     //  { 7, 4, 1, 2 },     // crossh1
01147     //  { 6, 5, 0, 3 },     // crossh2
01148     //  { 2, 1, 4, 7 },     // crossh3
01149     //  { 3, 0, 5, 6 }      // crossh4
01150     //};
01151     //int idxT[6+8][4][3] = {
01152     //  {{ 0, 3, 2 }, { 0, 3, 1 }, { 0, 2, 1 }, { 3, 2, 1 }},   // back
01153     //  {{ 4, 5, 6 }, { 4, 5, 7 }, { 4, 6, 7 }, { 5, 6, 7 }},   // front
01154     //  {{ 7, 6, 2 }, { 7, 6, 3 }, { 7, 2, 3 }, { 6, 2, 3 }},   // top
01155     //  {{ 0, 1, 5 }, { 0, 1, 4 }, { 0, 5, 4 }, { 1, 5, 4 }},   // bottom
01156     //  {{ 0, 4, 7 }, { 0, 4, 3 }, { 0, 7, 3 }, { 4, 7, 3 }},   // left
01157     //  {{ 1, 2, 6 }, { 1, 2, 5 }, { 1, 6, 5 }, { 2, 6, 5 }},   // right
01158     //  //
01159     //  {{ 7, 6, 1 }, { 7, 6, 0 }, { 7, 1, 0 }, { 6, 1, 0 }},   // crossv1
01160     //  {{ 6, 2, 0 }, { 6, 2, 4 }, { 6, 0, 4 }, { 2, 0, 4 }},   // crossv2
01161     //  {{ 2, 3, 4 }, { 2, 3, 5 }, { 2, 4, 5 }, { 3, 4, 5 }},   // crossv3
01162     //  {{ 3, 7, 5 }, { 3, 7, 1 }, { 3, 5, 1 }, { 7, 5, 1 }},   // crossv4
01163     //  {{ 7, 4, 1 }, { 7, 4, 2 }, { 7, 1, 2 }, { 4, 1, 2 }},   // crossh1
01164     //  {{ 6, 5, 0 }, { 6, 5, 3 }, { 6, 0, 3 }, { 5, 0, 3 }},   // crossh2
01165     //  {{ 2, 1, 4 }, { 2, 1, 7 }, { 2, 4, 7 }, { 1, 4, 7 }},   // crossh3
01166     //  {{ 3, 0, 5 }, { 3, 0, 6 }, { 3, 5, 6 }, { 0, 5, 6 }}    // crossh4
01167     //};
01169     //for ( int Z = 0; Z < m_vGridResolution[2]-1; ++Z ) {
01170     //  int offsetZ = Z * iOffsetSlice;
01171     //  for ( int Y = 0; Y < m_vGridResolution[1]-1; ++Y ) {
01172     //      int offsetYZ = Y * iOffsetRow + offsetZ;
01173     //      idx[0] = offsetYZ;
01174     //      idx[1] = idx[0] + iOffsetCol;
01175     //      idx[2] = idx[1] + iOffsetRow;
01176     //      idx[3] = idx[0] + iOffsetRow;
01177     //      idx[4] = idx[0] + iOffsetSlice;
01178     //      idx[5] = idx[4] + iOffsetCol;
01179     //      idx[6] = idx[5] + iOffsetRow;
01180     //      idx[7] = idx[4] + iOffsetRow;
01181     //      for ( int X = 0; X < m_vGridResolution[0]-1; ++X ) {
01182     //          for ( int i = 0; i < 8; ++i ) {
01183     //              if ( dataForPosition[idx[i] + 3] > 250 ) {
01184     //                  set[i] = true;
01185     //              }
01186     //              else {
01187     //                  set[i] = false;
01188     //              }
01189     //          }
01190     //          // Draw Quad Cases
01191     //          for ( int i = 0; i < 6+8; ++i ) {
01192     //              if ( set[ idxQ[i][0] ] && set[ idxQ[i][1] ] && set[ idxQ[i][2] ] && set[ idxQ[i][3] ] ) {
01193     //                  glBegin( GL_QUADS );
01194     //                  //-----------------------
01195     //                  // Normal
01196     //                  Vector3<T> v1(  
01197     //                      dataForPosition[idx[ idxQ[i][1] ]  ] - dataForPosition[idx[ idxQ[i][0] ]  ], 
01198     //                      dataForPosition[idx[ idxQ[i][1] ]+1] - dataForPosition[idx[ idxQ[i][0] ]+1], 
01199     //                      dataForPosition[idx[ idxQ[i][1] ]+2] - dataForPosition[idx[ idxQ[i][0] ]+2] );
01200     //                  Vector3<T> v2(  
01201     //                      dataForPosition[idx[ idxQ[i][2] ]  ] - dataForPosition[idx[ idxQ[i][0] ]  ], 
01202     //                      dataForPosition[idx[ idxQ[i][2] ]+1] - dataForPosition[idx[ idxQ[i][0] ]+1], 
01203     //                      dataForPosition[idx[ idxQ[i][2] ]+2] - dataForPosition[idx[ idxQ[i][0] ]+2] );
01204     //                  Vector3<T> normal = ( v1 ^ v2 ).Normalized();
01205     //                  glNormal3f( normal[0], normal[1], normal[2] );
01206     //                  //-----------------------
01207     //                  for ( int j = 0; j < 4; ++j ) {
01208     //                      glVertex3f( dataForPosition[idx[ idxQ[i][j] ]  ], 
01209     //                                  dataForPosition[idx[ idxQ[i][j] ]+1], 
01210     //                                  dataForPosition[idx[ idxQ[i][j] ]+2] );
01211     //                  }
01212     //                  glEnd();
01213     //              }
01214     //              else {
01215     //                  // Draw Tri Sub-Cases
01216     //                  for ( int k = 0; k < 4; ++k ) {
01217     //                      if ( set[ idxT[i][k][0] ] && set[ idxT[i][k][1] ] && set[ idxT[i][k][2] ] ) {
01218     //                          glBegin( GL_TRIANGLES );
01219     //                          //-----------------------
01220     //                          // Normal
01221     //                          Vector3<T> v1(  
01222     //                              dataForPosition[idx[ idxT[i][k][1] ]  ] - dataForPosition[idx[ idxT[i][k][0] ]  ], 
01223     //                              dataForPosition[idx[ idxT[i][k][1] ]+1] - dataForPosition[idx[ idxT[i][k][0] ]+1], 
01224     //                              dataForPosition[idx[ idxT[i][k][1] ]+2] - dataForPosition[idx[ idxT[i][k][0] ]+2] );
01225     //                          Vector3<T> v2(  
01226     //                              dataForPosition[idx[ idxT[i][k][2] ]  ] - dataForPosition[idx[ idxT[i][k][0] ]  ], 
01227     //                              dataForPosition[idx[ idxT[i][k][2] ]+1] - dataForPosition[idx[ idxT[i][k][0] ]+1], 
01228     //                              dataForPosition[idx[ idxT[i][k][2] ]+2] - dataForPosition[idx[ idxT[i][k][0] ]+2] );
01229     //                          Vector3<T> normal = ( v1 ^ v2 ).Normalized();
01230     //                          glNormal3f( normal[0], normal[1], normal[2] );
01231     //                          //-----------------------
01232     //                          for ( int j = 0; j < 3; ++j ) {
01233     //                              glVertex3f( dataForPosition[idx[ idxT[i][k][j] ]  ], 
01234     //                                          dataForPosition[idx[ idxT[i][k][j] ]+1], 
01235     //                                          dataForPosition[idx[ idxT[i][k][j] ]+2] );
01236     //                          }
01237     //                          glEnd();
01238     //                          break;
01239     //                      }
01240     //                  }
01241     //              }
01242     //          }
01243     //          //-------------------------------
01244     //          for ( int i = 0; i < 8; ++i ) {
01245     //              idx[i] += 4;
01246     //          }
01247     //          //-------------------------------
01248     //      }
01249     //  }
01250     //}
01251     //glPopAttrib();
01252     //---------------------------------------------------------------
01253     //===============================================================
01254     //*/
01255 
01256     //---------------------------------------------------------------
01257     //===============================================================
01258     delete [] dataForPosition;
01259     delete [] dataForConnectivity;
01260 }
01261 //-----------------------------------------------------------------------------
01262 // END: DrawByGL_AllElementsWithConnectivities_GPU
01263 //*****************************************************************************
01264 
01265 
01266 //-----------------------------------------------------------------------------
01267 #endif
01268 
01269 // END FNs FOR TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3
01271 //-----------------------------------------------------------------------------
01272 //=============================================================================
01273 END_NAMESPACE_TAPs__OpenGL
01274 //-----------------------------------------------------------------------------
01275 //34567890123456789012345678901234567890123456789012345678901234567890123456789
01276 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines