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