![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsModelDeformableCPU.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (12/21/2006) 00009 UPDATE (08/05/2007) 00010 ******************************************************************************/ 00011 #include "TAPsModelDeformableCPU.hpp" 00012 // Using Inclusion Model (i.e. definitions are included in declarations) 00013 // (this name.cpp is included in name.hpp) 00014 // Each friend is defined directly inside its declaration. 00015 00016 BEGIN_NAMESPACE_TAPs__OpenGL 00017 //============================================================================= 00018 //----------------------------------------------------------------------------- 00019 // default constructor 00020 template <typename T> 00021 ModelDeformableCPU<T>::ModelDeformableCPU () 00022 : OpenGLModel<T>() 00023 { 00024 //--------------------------------------------------------------- 00025 // Since Microsoft gl.h is version 1.1, 00026 // So this fn calls glewInit() for latest OpenGL version 00027 // and initialize GLSL. 00028 //GFnInitGLSL(); 00029 Default(); 00030 //--------------------------------------------------------------- 00031 //--------------------------------------------------------------- 00032 #ifdef TAPs_DEBUG_MODE 00033 std::cout << "ModelDeformableCPU<" << typeid(T).name() << "> Constructor\n"; 00034 #endif 00035 } 00036 //----------------------------------------------------------------------------- 00037 // Destructor 00038 template <typename T> 00039 ModelDeformableCPU<T>::~ModelDeformableCPU () 00040 { 00041 Clear(); 00042 //--------------------------------------------------------------- 00043 #ifdef TAPs_DEBUG_MODE 00044 std::cout << "ModelDeformableCPU<" << typeid(T).name() << "> Destructor\n"; 00045 #endif 00046 } 00047 //----------------------------------------------------------------------------- 00048 // Default 00049 template <typename T> 00050 void ModelDeformableCPU<T>::Default () 00051 { 00052 //------------------------------------------- 00053 m_vGridResolution.SetXYZ( 0, 0, 0 ); 00054 m_vGridDimension.SetXYZ( 0, 0, 0 ); 00055 m_iTotalElements = 0; 00056 m_fElementVolume = 0; 00057 //------------------------------------------- 00058 // Element Properties 00059 m_tMass = 1; 00060 //------------------------------------------- 00061 // Default Visualization 00062 DefaultVisualization(); 00063 //------------------------------------------- 00064 // Default Spring Properties 00065 //----------------------- 00066 T stiffness = 100; 00067 SPRING_PROP.SetValueForAllStiffnesses( stiffness ); 00068 //SPRING_PROP.SetValueForAllDampers( stiffness / 45000 ); // if SimStepByVerletIntegration damper is multiplied by dt 00069 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 00070 SPRING_PROP.SetValueForAllDampers( stiffness / 100 ); 00071 #endif 00072 //----------------------- 00073 // Spring Rest Lengths have to be set when the grids are created! 00074 //------------------------------------------- 00075 // Previous Step 00076 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VERLET_INTEGRATION 00077 m_tpElementPosPrev = NULL; 00078 #endif 00079 //------------------------------------------- 00080 // Current Step 00081 m_tpElementPos = NULL; 00082 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 00083 m_tpElementVel = NULL; 00084 #endif 00085 //--------------------------------- 00086 // Next Step 00087 m_tpElementPosNext = NULL; 00088 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 00089 m_tpElementVelNext = NULL; 00090 #endif 00091 //--------------------------------- 00092 // Surface 00093 m_ipSurfaceBoundary = NULL; 00094 //--------------------------------- 00095 // Connectivity 00096 m_ipElementConnect = NULL; 00097 m_iElementMaxValence = 0; 00098 //------------------------------------------- 00099 // For GLSL 00100 //m_glslProgramObject = NULL; 00101 //------------------------------------------- 00102 // For drawing useful objects 00103 //m_vOGLUsefulObj = NULL; 00104 } 00105 //----------------------------------------------------------------------------- 00106 // Clear 00107 template <typename T> 00108 void ModelDeformableCPU<T>::Clear () 00109 { 00110 //--------------------------------------------------------------- 00111 // Element Connections 00112 if ( m_ipElementConnect ) { 00113 delete [] m_ipElementConnect; 00114 //m_ipElementConnect = NULL; 00115 } 00116 //--------------------------------------------------------------- 00117 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VERLET_INTEGRATION 00118 // Element Position Previous 00119 if ( m_tpElementPosPrev ) { 00120 delete [] m_tpElementPosPrev; 00121 //m_tpElementPosPrev = NULL; 00122 } 00123 #endif 00124 //--------------------------------------------------------------- 00125 // Element Position 00126 if ( m_tpElementPos ) { 00127 delete [] m_tpElementPos; 00128 //m_tpElementPos = NULL; 00129 } 00130 //--------------------------------------------------------------- 00131 // Element Position Next 00132 if ( m_tpElementPosNext ) { 00133 delete [] m_tpElementPosNext; 00134 //m_tpElementPosNext = NULL; 00135 } 00136 //--------------------------------------------------------------- 00137 // Element Velocity 00138 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 00139 if ( m_tpElementVel ) { 00140 delete [] m_tpElementVel; 00141 //m_tpElementVel = NULL; 00142 } 00143 //--------------------------------------------------------------- 00144 // Element Velocity Next 00145 if ( m_tpElementVelNext ) { 00146 delete [] m_tpElementVelNext; 00147 //m_tpElementVelNext = NULL; 00148 } 00149 #endif 00150 //--------------------------------------------------------------- 00151 // For GLSL 00152 // if ( m_glslProgramObject ) { 00153 // m_glslShaderManager.Delete( m_glslProgramObject ); 00154 // delete m_glslProgramObject; // WHY ERROR!!! DEBUG ??? 00155 // //m_glslProgramObject = NULL; 00156 // } 00157 //--------------------------------------------------------------- 00158 /* 00159 #ifdef TAPs_DEBUG_MODE 00160 #ifdef TAPs_USE_WXWIDGETS 00161 wxLogError( wxT( "Finish clearing the deformable model data." ) ); 00162 #else 00163 std::cout << "Finish clearing the deformable model data." << std::endline; 00164 #endif 00165 #endif 00166 //*/ 00167 //--------------------------------------------------------------- 00168 // Clear Visualization 00169 ClearVisualization(); 00170 //--------------------------------------------------------------- 00171 Default(); 00172 } 00173 //----------------------------------------------------------------------------- 00174 // Default Visualization 00175 template <typename T> 00176 void ModelDeformableCPU<T>::DefaultVisualization () 00177 { 00178 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00179 m_Visualization_RTGenMesh = NULL; 00180 #endif 00181 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00182 m_Visualization_3DTexture = NULL; 00183 #endif 00184 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00185 m_Visualization_RayCasting = NULL; 00186 #endif 00187 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00188 m_Visualization_Mesh = NULL; 00189 #endif 00190 } 00191 //----------------------------------------------------------------------------- 00192 // Clear Visualization 00193 template <typename T> 00194 void ModelDeformableCPU<T>::ClearVisualization () 00195 { 00196 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00197 if ( m_Visualization_RTGenMesh ) { 00198 delete m_Visualization_RTGenMesh; 00199 } 00200 #endif 00201 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00202 if ( m_Visualization_3DTexture ) { 00203 delete m_Visualization_3DTexture; 00204 } 00205 #endif 00206 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00207 if ( m_Visualization_RayCasting ) { 00208 delete m_Visualization_RayCasting; 00209 } 00210 #endif 00211 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00212 if ( m_Visualization_Mesh ) { 00213 delete m_Visualization_Mesh; 00214 } 00215 #endif 00216 //--------------------------------- 00217 DefaultVisualization(); 00218 } 00219 //----------------------------------------------------------------------------- 00220 // Setup Visualization 00221 template <typename T> 00222 int ModelDeformableCPU<T>::SetupVisualization ( 00223 enum GridGenerator<T>::VertexFlag *** pFlagDataForXYZVoxels 00224 ) 00225 { 00227 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RT_GEN_MESH 00228 //=============================================================== 00229 // Setup visualization by real-time generated mesh 00230 //--------------------------------------------------------------- 00231 m_Visualization_RTGenMesh = new ModelDeformableCPU_Visualization_RTGenMesh<T>( this ); 00232 if ( !m_Visualization_RTGenMesh ) { 00233 #ifdef TAPs_USE_WXWIDGETS 00234 wxLogError( wxT( "ERROR: ModelDeformableGLSL --> Cannot create a real-time generated mesh for visualization of size (%i, %i, %i)!" ), 00235 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00236 #else 00237 std::cerr << "ERROR: ModelDeformableGLSL --> Cannot create a real-time generated mesh for visualization of size (" 00238 << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00239 << ")!" << std::endl; 00240 #endif 00241 return -1;//return false; 00242 } 00243 00244 //std::cout << "AFTER new m_Visualization_RTGenMesh" << std::endl; 00245 00246 if ( !m_Visualization_RTGenMesh->SetupVisualization( 00247 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 00248 pFlagDataForXYZVoxels ) ) 00249 { 00250 #ifdef TAPs_USE_WXWIDGETS 00251 wxLogError( wxT( "ERROR: ModelDeformableGLSL::SetupVisualization Fn --> Cannot a real-time generated mesh for visualization of size (%i, %i, %i)!" ), 00252 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00253 #else 00254 std::cerr << "ERROR: ModelDeformableGLSL::SetupVisualization Fn --> Cannot create a real-time generated mesh for visualization of size (" 00255 << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00256 << ")!" << std::endl; 00257 #endif 00258 return -2;//return false; 00259 } 00260 00261 //std::cout << "AFTER m_Visualization_RTGenMesh->SetupVisualization()" << std::endl; 00262 00263 //--------------------------------------------------------------- 00264 //=============================================================== 00265 #endif 00266 00267 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_3D_TEXTURE 00268 //=============================================================== 00269 // Setup a 3D Texture (for Visualization) 00270 //--------------------------------------------------------------- 00271 //m_Visualization_3DTexture = new ModelDeformableGLSL_Visualization_3DTexture<T>( this ); 00272 //if ( !m_Visualization_3DTexture ) { 00273 // #ifdef TAPs_USE_WXWIDGETS 00274 // wxLogError( wxT( "ERROR: ModelDeformableGLSL --> Cannot create 3D texture visualization of size (%i, %i, %i)!" ), 00275 // m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00276 // #else 00277 // std::cerr << "ERROR: ModelDeformableGLSL --> Cannot create 3D texture visualization of size (" 00278 // << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00279 // << ")!" << std::endl; 00280 // #endif 00281 // return -3;//return false; 00282 //} 00283 00284 //std::cout << "AFTER new m_Visualization_3DTexture" << std::endl; 00285 00286 //if ( !m_Visualization_3DTexture->SetupVisualization( 00287 // m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2], 00288 // pFlagDataForXYZVoxels ) ) 00289 //{ 00290 // #ifdef TAPs_USE_WXWIDGETS 00291 // wxLogError( wxT( "ERROR: ModelDeformableGLSL::SetupVisualization Fn --> Cannot create 3D texture of size (%i, %i, %i)!" ), 00292 // m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00293 // #else 00294 // std::cerr << "ERROR: ModelDeformableGLSL::SetupVisualization Fn --> Cannot create 3D texture of size (" 00295 // << m_vGridResolution[0] << ", " << m_vGridResolution[1] << ", " << m_vGridResolution[2] 00296 // << ")!" << std::endl; 00297 // #endif 00298 // return -4;//return false; 00299 //} 00300 00301 //std::cout << "AFTER m_Visualization_3DTexture->SetupVisualization()" << std::endl; 00302 00303 //--------------------------------------------------------------- 00304 //=============================================================== 00305 #endif 00306 00307 00308 //*/ 00309 // DEBUG 00310 //m_Visualization_RTGenMesh->Set3DTexture( m_Visualization_3DTexture->Get3DTextureVisualization() ); 00311 //*/ 00312 00313 00315 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RAY_CASTING 00316 //=============================================================== 00317 //--------------------------------------------------------------- 00318 //--------------------------------------------------------------- 00319 //=============================================================== 00320 #endif 00321 00322 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_MESH 00323 //=============================================================== 00324 //--------------------------------------------------------------- 00325 //--------------------------------------------------------------- 00326 //=============================================================== 00327 #endif 00328 00329 //--------------------------------------------------------------- 00330 //=============================================================== 00331 //--------------------------------------------------------------- 00332 return true; 00333 } 00334 //----------------------------------------------------------------------------- 00335 // Initialize 00336 template <typename T> 00337 int ModelDeformableCPU<T>::InitializeFromGridGeneratorDataFloat ( 00338 // GLint internalFormat, 00339 // GLenum pixel_format, 00340 GridGenerator<T> * pGridGenerator 00341 ) 00342 { 00343 int iElementSpaceDimension = 4; // XYZ + scalar 00344 //int iElementSpaceDimension = 3; // XYZ 00345 //int iElementSpaceDimension = 2; // XY 00346 //--------------------------------------------------------------- 00347 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VERLET_INTEGRATION 00348 if ( m_tpElementPosPrev != NULL ) return -100;//return false; 00349 #endif 00350 if ( m_tpElementPos != NULL ) return -100;//return false; 00351 if ( m_tpElementPosNext != NULL ) return -200;//return false; 00352 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 00353 if ( m_tpElementVel != NULL ) return -600;//return false; 00354 if ( m_tpElementVelNext != NULL ) return -700;//return false; 00355 #endif 00356 //------------------------------------------- 00357 if ( !pGridGenerator ) return -800;//return false; 00358 //------------------------------------------- 00359 if ( !pGridGenerator->IsGridGenerated() ) return -900;//return false; 00360 //------------------------------------------- 00361 m_vGridResolution.SetXYZ( pGridGenerator->GetGridSizeX(), 00362 pGridGenerator->GetGridSizeY(), 00363 pGridGenerator->GetGridSizeZ() ); 00364 m_vGridDimension.SetXYZ( pGridGenerator->GetGridDimensionX(), 00365 pGridGenerator->GetGridDimensionY(), 00366 pGridGenerator->GetGridDimensionZ() ); 00367 m_iTotalElements = m_vGridResolution[2] * m_vGridResolution[1] * m_vGridResolution[0]; 00368 m_fElementVolume = m_vGridDimension[2] * m_vGridDimension[1] * m_vGridDimension[0]; 00369 //--------------------------------------------------------------- 00370 // Set Mass Point Properties 00371 //m_tMass = 1 / m_iTotalElements; 00372 //--------------------------------------------------------------- 00373 // Set Spring Lengths 00374 SPRING_PROP.SetValueForAllSpringLengths( m_vGridDimension[0], m_vGridDimension[1], m_vGridDimension[2] ); 00375 00376 //--------------------------------------------------------------- 00377 // DEBUG 00378 //#ifdef TAPs_DEBUG_MODE 00379 //SPRING_PROP.PrintOut(); 00380 //#endif 00381 //--------------------------------------------------------------- 00382 int iMemorySizeForTotalElements = m_iTotalElements * iElementSpaceDimension; 00383 //--------------------------------------------------------------- 00384 // Element Positions 00385 T **** ptElementPosition = pGridGenerator->ReturnPtrToVertexPositionData(); // XYZ in 4D Array 00386 GridGenerator<T>::VertexFlag *** pcElementFlag = 00387 pGridGenerator->ReturnPtrToVertexFlagData(); // Enum in 3D Array 00388 //------------------------------------------------------------------------- 00389 /* 00390 // Position is XYZ only 00391 if ( iElementSpaceDimension == 3 ) { 00392 T * vertexData = new T[ iMemorySizeForTotalElements ]; // XYZ in 1D Array 00393 int m = 0; // XYZ Counter 00394 //--------------------------------------------------------------- 00395 // Data from pGridGenerator is arrenged in x, y, and z order. 00396 // To switch it to z, y, and x order for ordering planes in z-direction. 00397 for ( int k = 0; k < m_vGridResolution[2]; ++k ) { 00398 for ( int j = 0; j < m_vGridResolution[1]; ++j ) { 00399 for ( int i = 0; i < m_vGridResolution[0]; ++i ) { 00400 vertexData[m ] = ptElementPosition[i][j][k][0]; 00401 vertexData[m+1] = ptElementPosition[i][j][k][1]; 00402 vertexData[m+2] = ptElementPosition[i][j][k][2]; 00403 //--------------------------------------------- 00404 m += iElementSpaceDimension; 00405 } 00406 } 00407 } 00408 m_tpElementPos = vertexData; 00409 } 00410 //*/ 00411 //------------------------------------------------------------------------- 00412 // Position XYZ with Flag indicating void or occupied 00413 /*else*/ if ( iElementSpaceDimension == 4 ) { 00414 T * vertexData = new T[ iMemorySizeForTotalElements ]; // XYZ & Flag in 1D Array 00415 int m = 0; // XYZ & Flag Counter 00416 //--------------------------------------------------------------- 00417 // Data from pGridGenerator is arrenged in x, y, and z order. 00418 // To switch it to z, y, and x order for ordering planes in z-direction. 00419 for ( int k = 0; k < m_vGridResolution[2]; ++k ) { 00420 for ( int j = 0; j < m_vGridResolution[1]; ++j ) { 00421 for ( int i = 0; i < m_vGridResolution[0]; ++i ) { 00422 vertexData[m ] = ptElementPosition[i][j][k][0]; 00423 vertexData[m+1] = ptElementPosition[i][j][k][1]; 00424 vertexData[m+2] = ptElementPosition[i][j][k][2]; 00425 //--------------------------------------------- 00426 if ( pcElementFlag[i][j][k] >= GridGenerator<T>::INSIDE_MODEL ) { 00427 vertexData[m+3] = 500.0; 00428 } 00429 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::RIGHT_INSIDE_BOUNDARY ) { 00430 vertexData[m+3] = 400.0; 00431 } 00432 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::ON_BOUNDARY ) { 00433 vertexData[m+3] = 300.0; 00434 } 00435 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::RIGHT_OUTSIDE_BOUNDARY ) { 00436 vertexData[m+3] = 200.0; 00437 } 00438 else if ( pcElementFlag[i][j][k] >= GridGenerator<T>::OUTSIDE_MODEL ) { 00439 vertexData[m+3] = 100.0; 00440 } 00441 else { 00442 vertexData[m+3] = 0.0; 00443 } 00444 m += iElementSpaceDimension; 00445 } 00446 } 00447 } 00448 m_tpElementPos = vertexData; 00449 } 00450 //--------------------------------------------------------------- 00451 // Allocate (positions and velocities) data 00452 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VERLET_INTEGRATION 00453 m_tpElementPosPrev = new T[ iMemorySizeForTotalElements ]; 00454 // Initialize previous positions with current positions 00455 for ( int i = 0; i < iMemorySizeForTotalElements; ++i ) { 00456 m_tpElementPosPrev[i] = m_tpElementPos[i]; 00457 } 00458 #endif 00459 m_tpElementPosNext = new T[ iMemorySizeForTotalElements ]; 00460 //* 00461 // DEBUG 00462 // Initialize previous positions with current positions 00463 for ( int i = 0; i < iMemorySizeForTotalElements; ++i ) { 00464 if ( i % 4 == 3 ) 00465 m_tpElementPosNext[i] = m_tpElementPos[i]; 00466 } 00467 //*/ 00468 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 00469 m_tpElementVel = new T[ iMemorySizeForTotalElements ]; 00470 m_tpElementVelNext = new T[ iMemorySizeForTotalElements ]; 00471 #endif 00472 //--------------------------------------------------------------- 00473 #ifdef TAPs_DEBUG_MODE 00474 #ifdef TAPs_USE_WXWIDGETS 00475 wxLogError( wxT( " w/ (CPU) Grid Size: %i, %i, %i" ), 00476 m_vGridResolution[0], m_vGridResolution[1], m_vGridResolution[2] ); 00477 #endif 00478 #endif 00479 //--------------------------------------------------------------- 00480 // Model Initialization 00481 CalAndSetNormals(); 00482 ApplyMaterial(); 00483 SetBoundingAABBLowPoint( pGridGenerator->GetAABBMinPt() ); 00484 SetBoundingAABBHighPoint( pGridGenerator->GetAABBMaxPt() ); 00485 //CalBoundingAABB(); 00486 //CalBoundingEllipsoid(); 00487 //CalBoundingSphere(); 00488 00489 //--------------------------------------------------------------- 00490 // For GLSL 00491 //* 00492 // m_glslProgramObject = m_glslShaderManager.LoadFromFile( 00493 // "Resource/Shader/brick.vert", 00494 // "Resource/Shader/brick.frag" 00495 // ); 00496 //*/ 00497 00498 /* 00499 m_glslProgramObject = m_glslShaderManager.LoadFromFile( 00500 "Resource/Shader/minimal.vert", 00501 "Resource/Shader/minimal.frag" 00502 ); 00503 //*/ 00504 00505 // if ( m_glslProgramObject == NULL ) return -1000;//return false; 00506 //--------------------------------------------------------------- 00507 00508 InitConnectionConstants(); 00509 CreateConnectionsFullOneRing(); 00510 00511 //=============================================================== 00512 // Setup Visualization 00513 //--------------------------------------------------------------- 00514 int errCode = SetupVisualization( pcElementFlag ); 00515 if ( errCode < 0 ) { 00516 Clear(); 00517 return -1000 + errCode;//return false; 00518 } 00519 //--------------------------------------------------------------- 00520 //=============================================================== 00521 00522 return 0;//return true; 00523 } 00524 //----------------------------------------------------------------------------- 00525 // Create Boundary Surface 00526 template <typename T> 00527 void ModelDeformableCPU<T>::CreateSurfaceBoundary () 00528 { 00529 for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) { 00530 for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) { 00531 for ( int X = 0; X < m_vGridResolution[0]; ++X ) { 00532 /* 00533 if ( 400 == m_glfpElementPos[count+3] ) { 00534 glPushMatrix(); 00535 glTranslatef( 00536 m_glfpElementPos[count ], 00537 m_glfpElementPos[count+1], 00538 m_glfpElementPos[count+2] 00539 ); 00540 m_OGLUsefulObj.DrawSphere( vScale ); 00541 glPopMatrix(); 00542 } 00543 //*/ 00544 count += 4; 00545 } 00546 } 00547 } 00548 } 00549 //----------------------------------------------------------------------------- 00550 // Get Half Length 00551 template <typename T> 00552 T ModelDeformableCPU<T>::GetMaxHalfLength () const 00553 { 00554 T maxHalfSize = 0.0; 00555 // for ( int i = 0; i < m_iNoVertices; ++i ) 00556 // { 00557 // } 00558 return maxHalfSize; 00559 } 00560 //----------------------------------------------------------------------------- 00561 // Calculate and set the normals 00562 template <typename T> 00563 void ModelDeformableCPU<T>::CalAndSetNormals () 00564 { 00565 // CalAndSetFaceNormalsNotNormalized(); 00566 // DetermineFaceRings(); 00567 // CalAndSetElementNormals(); 00568 // NormalizeFaceNormals(); 00569 } 00570 //----------------------------------------------------------------------------- 00571 00572 //****************************************************************************** 00573 // ApplyAndResetTransform 00574 //****************************************************************************** 00575 //----------------------------------------------------------------------------- 00576 template <typename T> 00577 void ModelDeformableCPU<T>::ApplyAndResetTransform () 00578 { 00579 // for ( int i = 0; i < m_iNoVertices; ++i ) { 00580 // m_prXElement[i].SetPosition( 00581 // ( GetTransform().ReturnMatrixTransform() 00582 // * Vector4<T>( m_prXElement[i].GetPosition() ) 00583 // ).GetVector3() 00584 // ); 00585 // } 00586 //--------------------------------------------------------------- 00587 // Set Transformation to Identity Matrix 00588 GetTransform().MakeIdentity(); 00589 //--------------------------------------------------------------- 00590 // Recalculate Bounding Volume(s) 00591 CalBoundingAABB(); 00592 CalBoundingEllipsoid(); 00593 CalBoundingSphere(); 00594 } 00595 //----------------------------------------------------------------------------- 00596 //***************************************************************************** 00597 00598 //***************************************************************************** 00599 // Virtual Fns from Collision Detection from ColDetSupport class 00600 //***************************************************************************** 00601 //----------------------------------------------------------------------------- 00602 template <typename T> 00603 void ModelDeformableCPU<T>::CalBoundingAABB () 00604 { 00605 /* 00606 m_paBoundingAABB[0][0] = m_paBoundingAABB[1][0] = m_prXElement[0][0]; 00607 m_paBoundingAABB[0][1] = m_paBoundingAABB[1][1] = m_prXElement[0][1]; 00608 m_paBoundingAABB[0][2] = m_paBoundingAABB[1][2] = m_prXElement[0][2]; 00609 for ( int i = 1; i < m_iNoVertices; ++i ) 00610 { 00611 // Find lowest x, y, and z 00612 if ( m_paBoundingAABB[0][0] > m_prXElement[i][0] ) 00613 m_paBoundingAABB[0][0] = m_prXElement[i][0]; 00614 if ( m_paBoundingAABB[0][1] > m_prXElement[i][1] ) 00615 m_paBoundingAABB[0][1] = m_prXElement[i][1]; 00616 if ( m_paBoundingAABB[0][2] > m_prXElement[i][2] ) 00617 m_paBoundingAABB[0][2] = m_prXElement[i][2]; 00618 // Find highest x, y, and z 00619 if ( m_paBoundingAABB[1][0] < m_prXElement[i][0] ) 00620 m_paBoundingAABB[1][0] = m_prXElement[i][0]; 00621 if ( m_paBoundingAABB[1][1] < m_prXElement[i][1] ) 00622 m_paBoundingAABB[1][1] = m_prXElement[i][1]; 00623 if ( m_paBoundingAABB[1][2] < m_prXElement[i][2] ) 00624 m_paBoundingAABB[1][2] = m_prXElement[i][2]; 00625 } 00626 // Find the bounding volume center 00627 m_pBoundingCenter[0] = ( m_paBoundingAABB[0][0] + m_paBoundingAABB[1][0] ) / 2.0; 00628 m_pBoundingCenter[1] = ( m_paBoundingAABB[0][1] + m_paBoundingAABB[1][1] ) / 2.0; 00629 m_pBoundingCenter[2] = ( m_paBoundingAABB[0][2] + m_paBoundingAABB[1][2] ) / 2.0; 00630 //*/ 00631 } 00632 //----------------------------------------------------------------------------- 00633 template <typename T> 00634 void ModelDeformableCPU<T>::CalBoundingEllipsoid () 00635 { 00636 /* 00637 m_pBoundingCenter[0] = ( m_paBoundingAABB[0][0] + m_paBoundingAABB[1][0] ) / 2.0; 00638 m_pBoundingCenter[1] = ( m_paBoundingAABB[0][1] + m_paBoundingAABB[1][1] ) / 2.0; 00639 m_pBoundingCenter[2] = ( m_paBoundingAABB[0][2] + m_paBoundingAABB[1][2] ) / 2.0; 00640 m_pBoundingEllipsoid[0] = fabs( (m_paBoundingAABB[0][0] - m_paBoundingAABB[1][0])/2.0 ); 00641 m_pBoundingEllipsoid[1] = fabs( (m_paBoundingAABB[0][1] - m_paBoundingAABB[1][1])/2.0 ); 00642 m_pBoundingEllipsoid[2] = fabs( (m_paBoundingAABB[0][2] - m_paBoundingAABB[1][2])/2.0 ); 00643 //*/ 00644 00645 /* 00646 T xLength = m_paBoundingAABB[0][0] - m_paBoundingAABB[1][0]; 00647 T yLength = m_paBoundingAABB[0][1] - m_paBoundingAABB[1][1]; 00648 T zLength = m_paBoundingAABB[0][2] - m_paBoundingAABB[1][2]; 00649 xLength *= xLength; 00650 yLength *= yLength; 00651 zLength *= zLength; 00652 m_pBoundingEllipsoid[0] = sqrt( yLength + zLength ) / 2.0; 00653 m_pBoundingEllipsoid[1] = sqrt( zLength + xLength ) / 2.0; 00654 m_pBoundingEllipsoid[2] = sqrt( xLength + yLength ) / 2.0; 00655 //*/ 00656 00657 T x = m_paBoundingAABB[1][0] - m_pBoundingCenter[0]; 00658 x *= x; 00659 T y = m_paBoundingAABB[1][1] - m_pBoundingCenter[1]; 00660 y *= y; 00661 T z = m_paBoundingAABB[1][2] - m_pBoundingCenter[2]; 00662 z *= z; 00663 m_pBoundingEllipsoid[1] = sqrt( y + z ); 00664 m_pBoundingEllipsoid[2] = sqrt( z + x ); 00665 m_pBoundingEllipsoid[0] = sqrt( x + y ); 00666 } 00667 //----------------------------------------------------------------------------- 00668 template <typename T> 00669 void ModelDeformableCPU<T>::CalBoundingSphere () 00670 { 00671 /* 00672 T xLength = m_paBoundingAABB[0][0] - m_paBoundingAABB[1][0]; 00673 T yLength = m_paBoundingAABB[0][1] - m_paBoundingAABB[1][1]; 00674 T zLength = m_paBoundingAABB[0][2] - m_paBoundingAABB[1][2]; 00675 xLength *= xLength; 00676 yLength *= yLength; 00677 zLength *= zLength; 00678 m_pBoundingSphere = sqrt( xLength + yLength + zLength ) / 2.0; 00679 //*/ 00680 // T squaredLength; 00681 m_pBoundingSphere = 0; 00682 // for ( int i = 0; i < m_iNoVertices; ++i ) { 00683 // squaredLength = (m_prXElement[i].GetPosition() - m_pBoundingCenter).SquaredLength(); 00684 // if ( squaredLength > m_pBoundingSphere ) 00685 // m_pBoundingSphere = squaredLength; 00686 // } 00687 m_pBoundingSphere = sqrt( m_pBoundingSphere ); 00688 } 00689 //----------------------------------------------------------------------------- 00690 //***************************************************************************** 00691 00692 //============================================================================= 00693 // OpenGL Display Fn(s) 00694 //----------------------------------------------------------------------------- 00695 template <typename T> 00696 void ModelDeformableCPU<T>::DrawGL ( GLenum eDrawMode ) 00697 { 00698 //--------------------------------------------------------------- 00699 if ( m_tpElementPos ) { 00700 glPushAttrib( GL_POINT_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT ); 00701 glPointSize( 7 ); 00702 float r = (float)rand()/(float)(RAND_MAX+1); 00703 float g = (float)rand()/(float)(RAND_MAX+1); 00704 float b = (float)rand()/(float)(RAND_MAX+1); 00705 glColor3f( r, g, b ); 00706 glDisable( GL_LIGHTING ); 00707 glBegin( GL_POINTS ); 00708 glVertex3f( 0, 0, 0 ); 00709 glEnd(); 00710 glPopAttrib(); 00711 } 00712 } 00713 //----------------------------------------------------------------------------- 00714 template <typename T> 00715 void ModelDeformableCPU<T>::DrawByGL_AllElementsWithConnectivities () 00716 { 00717 if ( !m_tpElementPos ) return; 00718 //--------------------------------------------------------------- 00719 // GLsizei numPoints = m_vGridResolution[0] * m_vGridResolution[1]; 00720 //--------------------------------------------------------------- 00721 // Draw as Spheres 00722 int count = 0; 00723 m_OGLUsefulObj.SetColor( 0.1, 0.3, 0.25, 0.25 ); 00724 Vector3<T> vScale( 00725 // m_vGridDimension[0] / 4.0f, 00726 // m_vGridDimension[1] / 4.0f, 00727 // m_vGridDimension[2] / 4.0f 00728 00729 // m_vGridDimension[0] / 3.0f, 00730 // m_vGridDimension[1] / 3.0f, 00731 // m_vGridDimension[2] / 3.0f 00732 00733 // Good value for seeing connections 00734 // m_vGridDimension[0] / 1.25, 00735 // m_vGridDimension[1] / 1.25, 00736 // m_vGridDimension[2] / 1.25 00737 00738 // Ellipsoid touching each other 00739 // m_vGridDimension[0], 00740 // m_vGridDimension[1], 00741 // m_vGridDimension[2] 00742 00743 // Ellipsoid overlapping each other 00744 m_vGridDimension[0] * 1.25, 00745 m_vGridDimension[1] * 1.25, 00746 m_vGridDimension[2] * 1.25 00747 ); 00748 //----------------------------------------------------- 00749 // for ( int i = 0; i < m_iTotalElements; ++i ) { 00750 for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) { 00751 for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) { 00752 for ( int X = 0; X < m_vGridResolution[0]; ++X ) { 00753 /* 00754 if ( m_glfpElementPos[count+3] > 250 ) { 00755 glPushMatrix(); 00756 glTranslatef( 00757 m_glfpElementPos[count ], 00758 m_glfpElementPos[count+1], 00759 m_glfpElementPos[count+2] 00760 ); 00761 m_OGLUsefulObj.DrawSphere( vScale ); 00762 glPopMatrix(); 00763 } 00764 //*/ 00765 00766 00767 /* 00768 // DEBUG 00769 if ( X == 1 && Y == 1 && Z == 1 ) { 00770 m_OGLUsefulObj.SetColor( 1.0, 0.0, 0.5, 0.25 ); // some what red 00771 glPushMatrix(); 00772 glTranslatef( 00773 m_tpElementPos[count ], 00774 m_tpElementPos[count+1], 00775 m_tpElementPos[count+2] 00776 ); 00777 m_OGLUsefulObj.DrawSphere( vScale ); 00778 glPopMatrix(); 00779 } 00780 //*/ 00781 00782 //------------------------------- 00783 if ( 500 == m_tpElementPos[count+3] ) { 00784 m_OGLUsefulObj.SetColor( 0.10, 0.30, 0.50, 0.25 ); // some what blue 00785 glPushMatrix(); 00786 glTranslatef( 00787 m_tpElementPos[count ], 00788 m_tpElementPos[count+1], 00789 m_tpElementPos[count+2] 00790 ); 00791 m_OGLUsefulObj.DrawSphere( vScale ); 00792 glPopMatrix(); 00793 } 00794 //------------------------------- 00795 else if ( 400 == m_tpElementPos[count+3] ) { 00796 m_OGLUsefulObj.SetColor( 0.10, 0.30, 0.25, 0.25 ); // some what green 00797 glPushMatrix(); 00798 glTranslatef( 00799 m_tpElementPos[count ], 00800 m_tpElementPos[count+1], 00801 m_tpElementPos[count+2] 00802 ); 00803 m_OGLUsefulObj.DrawSphere( vScale ); 00804 glPopMatrix(); 00805 } 00806 //------------------------------- 00807 else if ( 300 == m_tpElementPos[count+3] ) { 00808 m_OGLUsefulObj.SetColor( 0.50, 0.30, 0.10, 0.25 ); // some what yellow 00809 glPushMatrix(); 00810 glTranslatef( 00811 m_tpElementPos[count ], 00812 m_tpElementPos[count+1], 00813 m_tpElementPos[count+2] 00814 ); 00815 m_OGLUsefulObj.DrawSphere( vScale ); 00816 glPopMatrix(); 00817 } 00818 //------------------------------- 00819 count += 4; 00820 } 00821 } 00822 } 00823 //------------------------------------------- 00824 // Draw Connections 00825 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00826 glLineWidth( 1 ); 00827 //glLineWidth( 3 ); 00828 glColor3f( 0.9, 1.0, 0.0 ); 00829 glDisable( GL_LIGHTING ); 00830 int idxElementPos = 0; 00831 int idxElementPos2 = 0; 00832 int idxElementConnection = 0; 00833 int iOffsetSlice = m_vGridResolution[1] * m_vGridResolution[0] * 4; 00834 int iOffsetRow = m_vGridResolution[0] * 4; 00835 int iOffsetCol = 4; 00836 //------------------------------------------------------------------ 00837 glBegin( GL_LINES ); 00838 for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) { 00839 for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) { 00840 for ( int X = 0; X < m_vGridResolution[0]; ++X ) { 00841 //if ( m_glfpElementPos[idxElementPos + 3] < 450 ) { // Skip all except an inside element 00842 if ( m_tpElementPos[idxElementPos + 3] < 250 ) { // Skip a void element 00843 idxElementConnection += m_iElementMaxValence; // Next element index 00844 } 00845 else { 00846 for ( int i = 0; i < m_iElementMaxValence; ++i ) { 00847 if ( m_ipElementConnect[idxElementConnection] != 0 ) { 00848 idxElementPos2 = idxElementPos + m_ipElementConnect[idxElementConnection]; 00849 glVertex3f( 00850 m_tpElementPos[idxElementPos ], 00851 m_tpElementPos[idxElementPos + 1], 00852 m_tpElementPos[idxElementPos + 2] 00853 ); 00854 glVertex3f( 00855 m_tpElementPos[idxElementPos2 ], 00856 m_tpElementPos[idxElementPos2 + 1], 00857 m_tpElementPos[idxElementPos2 + 2] 00858 ); 00859 } 00860 ++idxElementConnection; 00861 } 00862 } 00863 idxElementPos += 4; 00864 } 00865 } 00866 } 00867 glEnd(); 00868 glPopAttrib(); 00869 } 00870 //----------------------------------------------------------------------------- 00871 template <typename T> 00872 void ModelDeformableCPU<T>::DrawByGL ( DrawType drawType ) 00873 { 00874 /* 00875 // DEBUG 00876 static int iCount = 0; 00877 if ( !m_tpElementPos ) { 00878 iCount = 0; 00879 } 00880 else { 00881 if ( iCount < 20 ) { 00882 int idx = 3; 00883 for ( int i = 0; i < m_iTotalElements; ++i ) { 00884 if ( m_tpElementPos[idx] >= 250 ) { 00885 m_tpElementPos[idx-3] -= m_vGridDimension[0] / 5; 00886 m_tpElementPos[idx-2] -= m_vGridDimension[1] / 5; 00887 m_tpElementPos[idx-1] -= m_vGridDimension[2] / 5; 00888 break; 00889 } 00890 idx += 4; 00891 } 00892 //++iCount; 00893 } 00894 else if ( iCount > 500 ) { 00895 iCount = 0; 00896 } 00897 ++iCount; 00898 SimStepByVerletIntegration( 0.001 ); 00899 } 00900 //*/ 00901 00902 //--------------------------------------------------------------- 00903 switch ( drawType ) { 00904 case AS_2D_TEXTURE: 00905 DrawByGL_As2DTexture(); 00906 break; 00907 case AS_3D_TEXTURE: 00908 DrawByGL_As3DTexture(); 00909 break; 00910 case POSITION_TEXTURE: 00911 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RT_GEN_MESH 00912 //std::cout << "POSITION_TEXTURE -- w Gen Mesh\n"; 00913 00914 /* 00915 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00916 glDisable( GL_LIGHTING ); 00917 glPointSize( 7 ); 00918 glBegin( GL_POINTS ); 00919 glColor3f( 1, 1, 1 ); 00920 glVertex3f( 0, 0, 0 ); 00921 glEnd(); 00922 glPopAttrib(); 00923 //*/ 00924 00925 //DrawByGL_AllElementsWithConnectivities_GPU(); 00926 VisualizeByRTGenMesh( drawType ); 00927 #else // #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RT_GEN_MESH 00928 //std::cout << "POSITION_TEXTURE -- wo Gen Mesh\n"; 00929 Visualize( drawType ); 00930 #endif // #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RT_GEN_MESH 00931 break; 00932 case ALL_ELEMENTS: 00933 DrawByGL_AllElements(); 00934 break; 00935 case ALL_ELEMENTS_WITH_CONNECTIVITIES: 00936 DrawByGL_AllElementsWithConnectivities(); 00937 break; 00938 default: 00939 //DrawByGL_AllElements(); 00940 DrawByGL_AllElementsWithConnectivities(); 00941 break; 00942 } 00943 } 00944 //----------------------------------------------------------------------------- 00945 template <typename T> 00946 void ModelDeformableCPU<T>::Visualize ( DrawType drawType ) 00947 { 00948 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RT_GEN_MESH 00949 VisualizeByRTGenMesh( drawType ); 00950 #endif 00951 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_3D_TEXTURE 00952 VisualizeBy3DTexture( drawType ); 00953 #endif 00954 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RAY_CASTING 00955 VisualizeByRayCasting( drawType ); 00956 #endif 00957 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_MESH 00958 VisualizeByMesh( drawType ); 00959 #endif 00960 } 00961 //----------------------------------------------------------------------------- 00962 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RT_GEN_MESH 00963 template <typename T> 00964 void ModelDeformableCPU<T>::VisualizeByRTGenMesh ( DrawType drawType ) 00965 { 00966 //std::cout << "Start: VisualizeByRTGenMesh( drawType )" << std::endl; 00967 00968 if ( m_Visualization_RTGenMesh ) { 00969 00970 // std::cout << "Inside: VisualizeByRTGenMesh( drawType )" << std::endl; 00971 00972 m_Visualization_RTGenMesh->DrawByGL( 64 /* depth supersampling */ ); 00973 } 00974 00975 //std::cout << "End: VisualizeByRTGenMesh( drawType )" << std::endl; 00976 } 00977 #endif 00978 //----------------------------------------------------------------------------- 00979 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_3D_TEXTURE 00980 template <typename T> 00981 void ModelDeformableCPU<T>::VisualizeBy3DTexture ( DrawType drawType ) 00982 { 00983 if ( m_Visualization_3DTexture ) { 00984 m_Visualization_3DTexture->DrawByGL( 64 /* depth supersampling */ ); 00985 } 00986 } 00987 #endif 00988 //----------------------------------------------------------------------------- 00989 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_RAY_CASTING 00990 template <typename T> 00991 void ModelDeformableCPU<T>::VisualizeByRayCasting ( DrawType drawType ) 00992 { 00993 if ( m_Visualization_RayCasting ) { 00994 m_Visualization_RayCasting->DrawByGL( 64 /* depth supersampling */ ); 00995 } 00996 } 00997 #endif 00998 //----------------------------------------------------------------------------- 00999 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VISUALIZATION_MESH 01000 template <typename T> 01001 void ModelDeformableCPU<T>::VisualizeByMesh ( DrawType drawType ) 01002 { 01003 if ( m_Visualization_Mesh ) { 01004 m_Visualization_Mesh->DrawByGL( 64 /* depth supersampling */ ); 01005 } 01006 } 01007 #endif 01008 //----------------------------------------------------------------------------- 01009 //============================================================================= 01010 //----------------------------------------------------------------------------- 01011 template <typename T> 01012 void ModelDeformableCPU<T>::DrawByGL_As2DTexture () 01013 { 01014 Vector3<T> vAABBMinPt = GetBoundingAABBLowPoint(); 01015 Vector3<T> vAABBMaxPt = GetBoundingAABBHighPoint(); 01016 //--------------------------------------------------------------- 01017 if ( m_tpElementPos ) { 01018 glPushAttrib( GL_POINT_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01019 glPointSize( 7 ); 01020 float r = (float)rand()/(float)(RAND_MAX+1); 01021 float g = (float)rand()/(float)(RAND_MAX+1); 01022 float b = (float)rand()/(float)(RAND_MAX+1); 01023 glColor3f( r, g, b ); 01024 glDisable( GL_LIGHTING ); 01025 glBegin( GL_POINTS ); 01026 glVertex3f( 0, 0, 0 ); 01027 glEnd(); 01028 glPopAttrib(); 01029 } 01030 } 01031 //----------------------------------------------------------------------------- 01032 template <typename T> 01033 void ModelDeformableCPU<T>::DrawByGL_As3DTexture () 01034 { 01035 //--------------------------------------------------------------- 01036 if ( m_tpElementPos ) { 01037 glPushAttrib( GL_POINT_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01038 glPointSize( 7 ); 01039 float r = (float)rand()/(float)(RAND_MAX+1); 01040 float g = (float)rand()/(float)(RAND_MAX+1); 01041 float b = (float)rand()/(float)(RAND_MAX+1); 01042 glColor3f( r, g, b ); 01043 glDisable( GL_LIGHTING ); 01044 glBegin( GL_POINTS ); 01045 glVertex3f( 0, 0, 0 ); 01046 glEnd(); 01047 glPopAttrib(); 01048 } 01049 } 01050 //----------------------------------------------------------------------------- 01051 template <typename T> 01052 void ModelDeformableCPU<T>::DrawByGL_PositionTexture () 01053 { 01054 //--------------------------------------------------------------- 01055 if ( m_tpElementPos ) { 01056 glPushAttrib( GL_POINT_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT ); 01057 glPointSize( 7 ); 01058 float r = (float)rand()/(float)(RAND_MAX+1); 01059 float g = (float)rand()/(float)(RAND_MAX+1); 01060 float b = (float)rand()/(float)(RAND_MAX+1); 01061 glColor3f( r, g, b ); 01062 glDisable( GL_LIGHTING ); 01063 glBegin( GL_POINTS ); 01064 glVertex3f( 0, 0, 0 ); 01065 glEnd(); 01066 glPopAttrib(); 01067 } 01068 } 01069 //----------------------------------------------------------------------------- 01070 template <typename T> 01071 void ModelDeformableCPU<T>::DrawByGL_AllElements () 01072 { 01073 if ( !m_tpElementPos ) return; 01074 //--------------------------------------------------------------- 01075 // GLsizei numPoints = m_vGridResolution[0] * m_vGridResolution[1]; 01076 //--------------------------------------------------------------- 01077 /* 01078 glPushAttrib( GL_LIGHTING_BIT | GL_CURRENT_BIT | GL_POINT_BIT ); 01079 //glDisable( GL_LIGHTING ); 01080 glEnable( GL_COLOR_MATERIAL ); 01081 glPointSize( 3 ); 01082 glColor3f( 0.2f, 0.7f, 0.4f ); 01083 //*/ 01084 //------------------------------------------------- 01085 // Immediate Draw Mode 01086 //------------------------------------------- 01087 // Draw as OpenGL Primitive Points 01088 /* 01089 glBegin( GL_POINTS ); 01090 int count = 0; 01091 for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) { 01092 for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) { 01093 for ( int X = 0; X < m_vGridResolution[0]; ++X ) { 01094 if ( m_glfpElementPos[count+3] > 250 ) { 01095 glElement3f( 01096 m_glfpElementPos[count ], 01097 m_glfpElementPos[count+1], 01098 m_glfpElementPos[count+2] 01099 ); 01100 } 01101 count += 4; 01102 } 01103 } 01104 } 01105 glEnd(); 01106 glPopAttrib(); 01107 //*/ 01108 //------------------------------------------- 01109 // Draw as Spheres 01110 int count = 0; 01111 m_OGLUsefulObj.SetColor( 0.1, 0.3, 0.25, 0.25 ); 01112 Vector3<T> vScale( 01113 m_vGridDimension[0], 01114 m_vGridDimension[1], 01115 m_vGridDimension[2] 01116 //m_vGridDimension[0] / 2.0f, 01117 //m_vGridDimension[1] / 2.0f, 01118 //m_vGridDimension[2] / 2.0f 01119 //m_vGridDimension[0] / 4.0f, 01120 //m_vGridDimension[1] / 4.0f, 01121 //m_vGridDimension[2] / 4.0f 01122 ); 01123 // for ( int i = 0; i < m_iTotalElements; ++i ) { 01124 for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) { 01125 for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) { 01126 for ( int X = 0; X < m_vGridResolution[0]; ++X ) { 01127 /* 01128 if ( m_glfpElementPos[count+3] > 250 ) { 01129 glPushMatrix(); 01130 glTranslatef( 01131 m_glfpElementPos[count ], 01132 m_glfpElementPos[count+1], 01133 m_glfpElementPos[count+2] 01134 ); 01135 m_OGLUsefulObj.DrawSphere( vScale ); 01136 glPopMatrix(); 01137 } 01138 //*/ 01139 //------------------------------- 01140 if ( 500 == m_tpElementPos[count+3] ) { 01141 m_OGLUsefulObj.SetColor( 0.10, 0.30, 0.50, 0.25 ); // some what blue 01142 glPushMatrix(); 01143 glTranslatef( 01144 m_tpElementPos[count ], 01145 m_tpElementPos[count+1], 01146 m_tpElementPos[count+2] 01147 ); 01148 //m_OGLUsefulObj.DrawSphere( vScale ); 01149 m_OGLUsefulObj.DrawCube( vScale ); 01150 glPopMatrix(); 01151 } 01152 //------------------------------- 01153 else if ( 400 == m_tpElementPos[count+3] ) { 01154 m_OGLUsefulObj.SetColor( 0.10, 0.30, 0.25, 0.25 ); // some what green 01155 glPushMatrix(); 01156 glTranslatef( 01157 m_tpElementPos[count ], 01158 m_tpElementPos[count+1], 01159 m_tpElementPos[count+2] 01160 ); 01161 //m_OGLUsefulObj.DrawSphere( vScale ); 01162 m_OGLUsefulObj.DrawCube( vScale ); 01163 glPopMatrix(); 01164 } 01165 //------------------------------- 01166 else if ( 300 == m_tpElementPos[count+3] ) { 01167 m_OGLUsefulObj.SetColor( 0.50, 0.30, 0.10, 0.25 ); // some what yellow 01168 glPushMatrix(); 01169 glTranslatef( 01170 m_tpElementPos[count ], 01171 m_tpElementPos[count+1], 01172 m_tpElementPos[count+2] 01173 ); 01174 //m_OGLUsefulObj.DrawSphere( vScale ); 01175 m_OGLUsefulObj.DrawCube( vScale ); 01176 glPopMatrix(); 01177 } 01178 //------------------------------- 01179 count += 4; 01180 } 01181 } 01182 } 01183 } 01184 //----------------------------------------------------------------------------- 01185 //============================================================================= 01186 01187 //============================================================================= 01188 // Helper Fn(s): Initialize connection constants (offsets) 01189 //----------------------------------------------------------------------------- 01190 template <typename T> 01191 std::string ModelDeformableCPU<T>::Info () const 01192 { 01193 const int maxNumConnections = 26; 01194 std::string strInfo; 01195 //--------------------------------- 01196 strInfo += "Rest Length Stiffness Damper Distance Limit\n"; 01197 //================================= 01198 strInfo += "-----------\n"; 01199 strInfo += "FRONT GROUP:\n"; 01200 strInfo += "-----------"; 01201 //------------- 01202 strInfo += "\n FrontNorthWest: "; 01203 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT_NORTH_WEST, maxNumConnections ); 01204 strInfo += "\n FrontNorth: "; 01205 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT_NORTH, maxNumConnections ); 01206 strInfo += "\n FrontNorthEast: "; 01207 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT_NORTH_EAST, maxNumConnections ); 01208 //------------- 01209 strInfo += "\n FrontWest: "; 01210 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT_WEST, maxNumConnections ); 01211 strInfo += "\n Front: "; 01212 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT, maxNumConnections ); 01213 strInfo += "\n FrontEast: "; 01214 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT_EAST, maxNumConnections ); 01215 //------------- 01216 strInfo += "\n FrontSouthWest: "; 01217 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT_SOUTH_WEST, maxNumConnections ); 01218 strInfo += "\n FrontSouth: "; 01219 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT_SOUTH, maxNumConnections ); 01220 strInfo += "\n FrontSouthEast: "; 01221 InfoConnectionProperties( strInfo, SpringProp::CONNECT::FRONT_SOUTH_EAST, maxNumConnections ); 01222 //------------- 01223 strInfo += "\n"; 01224 //================================= 01225 strInfo += "------------\n"; 01226 strInfo += "CENTER GROUP:\n"; 01227 strInfo += "------------"; 01228 //------------- 01229 strInfo += "\n NorthWest: "; 01230 InfoConnectionProperties( strInfo, SpringProp::CONNECT::NORTH_WEST, maxNumConnections ); 01231 strInfo += "\n North: "; 01232 InfoConnectionProperties( strInfo, SpringProp::CONNECT::NORTH, maxNumConnections ); 01233 strInfo += "\n NorthEast: "; 01234 InfoConnectionProperties( strInfo, SpringProp::CONNECT::NORTH_EAST, maxNumConnections ); 01235 //------------- 01236 strInfo += "\n West: "; 01237 InfoConnectionProperties( strInfo, SpringProp::CONNECT::WEST, maxNumConnections ); 01238 strInfo += "\n East: "; 01239 InfoConnectionProperties( strInfo, SpringProp::CONNECT::EAST, maxNumConnections ); 01240 //------------- 01241 strInfo += "\n SouthWest: "; 01242 InfoConnectionProperties( strInfo, SpringProp::CONNECT::SOUTH_WEST, maxNumConnections ); 01243 strInfo += "\n South: "; 01244 InfoConnectionProperties( strInfo, SpringProp::CONNECT::SOUTH, maxNumConnections ); 01245 strInfo += "\n SouthEast: "; 01246 InfoConnectionProperties( strInfo, SpringProp::CONNECT::SOUTH_EAST, maxNumConnections ); 01247 //------------- 01248 strInfo += "\n"; 01249 //================================= 01250 strInfo += "----------\n"; 01251 strInfo += "BACK GROUP:\n"; 01252 strInfo += "----------"; 01253 //------------- 01254 strInfo += "\n BackNorthWest: "; 01255 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK_NORTH_WEST, maxNumConnections ); 01256 strInfo += "\n BackNorth: "; 01257 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK_NORTH, maxNumConnections ); 01258 strInfo += "\n BackNorthEast: "; 01259 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK_NORTH_EAST, maxNumConnections ); 01260 //------------- 01261 strInfo += "\n BackWest: "; 01262 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK_WEST, maxNumConnections ); 01263 strInfo += "\n Back: "; 01264 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK, maxNumConnections ); 01265 strInfo += "\n BackEast: "; 01266 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK_EAST, maxNumConnections ); 01267 //------------- 01268 strInfo += "\n BackSouthWest: "; 01269 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK_SOUTH_WEST, maxNumConnections ); 01270 strInfo += "\n BackSouth: "; 01271 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK_SOUTH, maxNumConnections ); 01272 strInfo += "\n BackSouthEast: "; 01273 InfoConnectionProperties( strInfo, SpringProp::CONNECT::BACK_SOUTH_EAST, maxNumConnections ); 01274 //------------- 01275 //strInfo += "\n"; 01276 //================================= 01277 return strInfo; 01278 } 01279 //----------------------------------------------------------------------------- 01280 template <typename T> 01281 void ModelDeformableCPU<T>::InitConnectionConstants () 01282 { 01283 int iOffsetElement = 4; 01284 int iOffsetX = iOffsetElement; 01285 int iOffsetY = m_vGridResolution[0] * iOffsetElement; 01286 int iOffsetZ = m_vGridResolution[1] * iOffsetY; 01287 //--------- 01288 CONNECTION_INDEX[SpringProp::CONNECT::EAST] = iOffsetX; 01289 CONNECTION_INDEX[SpringProp::CONNECT::NORTH]= iOffsetY; 01290 CONNECTION_INDEX[SpringProp::CONNECT::WEST] = -iOffsetX; 01291 CONNECTION_INDEX[SpringProp::CONNECT::SOUTH]= -iOffsetY; 01292 //--------- 01293 CONNECTION_INDEX[SpringProp::CONNECT::FRONT]= iOffsetZ; 01294 //--------- 01295 CONNECTION_INDEX[SpringProp::CONNECT::BACK] = -iOffsetZ; 01296 //--------- 01297 CONNECTION_INDEX[SpringProp::CONNECT::NORTH_EAST] = iOffsetY + iOffsetX; 01298 CONNECTION_INDEX[SpringProp::CONNECT::NORTH_WEST] = iOffsetY - iOffsetX; 01299 CONNECTION_INDEX[SpringProp::CONNECT::SOUTH_WEST] = -iOffsetY - iOffsetX; 01300 CONNECTION_INDEX[SpringProp::CONNECT::SOUTH_EAST] = -iOffsetY + iOffsetX; 01301 //--------- 01302 CONNECTION_INDEX[SpringProp::CONNECT::FRONT_EAST] = iOffsetZ + iOffsetX; 01303 CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH] = iOffsetZ + iOffsetY; 01304 CONNECTION_INDEX[SpringProp::CONNECT::FRONT_WEST] = iOffsetZ - iOffsetX; 01305 CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH] = iOffsetZ - iOffsetY; 01306 //--------- 01307 CONNECTION_INDEX[SpringProp::CONNECT::BACK_EAST] = -iOffsetZ + iOffsetX; 01308 CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH] = -iOffsetZ + iOffsetY; 01309 CONNECTION_INDEX[SpringProp::CONNECT::BACK_WEST] = -iOffsetZ - iOffsetX; 01310 CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH] = -iOffsetZ - iOffsetY; 01311 //--------- 01312 CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH_EAST] = iOffsetZ + iOffsetY + iOffsetX; 01313 CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH_WEST] = iOffsetZ + iOffsetY - iOffsetX; 01314 CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH_WEST] = iOffsetZ - iOffsetY - iOffsetX; 01315 CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH_EAST] = iOffsetZ - iOffsetY + iOffsetX; 01316 //--------- 01317 CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH_EAST] = -iOffsetZ + iOffsetY + iOffsetX; 01318 CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH_WEST] = -iOffsetZ + iOffsetY - iOffsetX; 01319 CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH_WEST] = -iOffsetZ - iOffsetY - iOffsetX; 01320 CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH_EAST] = -iOffsetZ - iOffsetY + iOffsetX; 01321 //--------- 01322 CONNECTION_INDEX[SpringProp::CONNECT::NOT_CONNECTED] = 0; 01323 //--------------------------------------------------------------- 01324 01325 #ifdef TAPs_DEBUG_MODE 01326 std::cout << "CONNECTION_INDEX[i]" << "\n"; 01327 for ( int i = 0; i < 27; ++i ) { 01328 std::cout << "\t" << CONNECTION_INDEX[i] << "\n"; 01329 } 01330 #endif//TAPs_DEBUG_MODE 01331 01332 } 01333 //----------------------------------------------------------------------------- 01334 //============================================================================= 01335 // Helper Fn(s): Creations/Initializations 01336 //----------------------------------------------------------------------------- 01337 template <typename T> 01338 void ModelDeformableCPU<T>::CreateConnectionsFullOneRing () 01339 { 01340 /* 01341 m_iElementMaxValence = 1; 01342 int listOfConnections[1]; 01343 listOfConnections[0] = CONNECTION_INDEX[BACK]; 01344 //*/ 01345 01346 01347 /* 01348 m_gliElementMaxValence = 6; 01349 int listOfConnections[6]; 01350 listOfConnections[0] = CONNECTION_INDEX::CENTER_EAST; 01351 listOfConnections[1] = CONNECTION_INDEX::CENTER_NORTH; 01352 listOfConnections[2] = CONNECTION_INDEX::CENTER_WEST; 01353 listOfConnections[3] = CONNECTION_INDEX::CENTER_SOUTH; 01354 listOfConnections[4] = CONNECTION_INDEX::FRONT_CENTER; 01355 listOfConnections[5] = CONNECTION_INDEX::BACK_CENTER; 01356 //*/ 01357 01358 //* 01359 //--------------------------------------------------------------- 01360 m_iElementMaxValence = 26; 01361 int listOfConnections[26]; 01362 //----------------------- 01363 listOfConnections[0] = CONNECTION_INDEX[SpringProp::CONNECT::EAST]; 01364 listOfConnections[1] = CONNECTION_INDEX[SpringProp::CONNECT::NORTH]; 01365 listOfConnections[2] = CONNECTION_INDEX[SpringProp::CONNECT::WEST]; 01366 listOfConnections[3] = CONNECTION_INDEX[SpringProp::CONNECT::SOUTH]; 01367 //----------------------- 01368 listOfConnections[4] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT]; 01369 //----------------------- 01370 listOfConnections[5] = CONNECTION_INDEX[SpringProp::CONNECT::BACK]; 01371 //----------------------- 01372 listOfConnections[6] = CONNECTION_INDEX[SpringProp::CONNECT::NORTH_EAST]; 01373 listOfConnections[7] = CONNECTION_INDEX[SpringProp::CONNECT::NORTH_WEST]; 01374 listOfConnections[8] = CONNECTION_INDEX[SpringProp::CONNECT::SOUTH_WEST]; 01375 listOfConnections[9] = CONNECTION_INDEX[SpringProp::CONNECT::SOUTH_EAST]; 01376 //----------------------- 01377 listOfConnections[10] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT_EAST]; 01378 listOfConnections[11] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH]; 01379 listOfConnections[12] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT_WEST]; 01380 listOfConnections[13] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH]; 01381 //----------------------- 01382 listOfConnections[14] = CONNECTION_INDEX[SpringProp::CONNECT::BACK_EAST]; 01383 listOfConnections[15] = CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH]; 01384 listOfConnections[16] = CONNECTION_INDEX[SpringProp::CONNECT::BACK_WEST]; 01385 listOfConnections[17] = CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH]; 01386 //----------------------- 01387 listOfConnections[18] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH_EAST]; 01388 listOfConnections[19] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH_WEST]; 01389 listOfConnections[20] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH_WEST]; 01390 listOfConnections[21] = CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH_EAST]; 01391 //----------------------- 01392 listOfConnections[22] = CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH_EAST]; 01393 listOfConnections[23] = CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH_WEST]; 01394 listOfConnections[24] = CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH_WEST]; 01395 listOfConnections[25] = CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH_EAST]; 01396 //----------------------- 01397 //*/ 01398 01399 //* 01400 //--------------------------------------------------------------- 01401 m_ipElementConnect = new int[m_iTotalElements * m_iElementMaxValence]; 01402 //--------------------------------------------------------------- 01403 int index = 0; 01404 int iOffsetSlice = m_vGridResolution[0] * m_vGridResolution[1]; 01405 //--------------------------------------------------------------- 01406 // All elements not on the boundary 01407 for ( int Z = 1; Z < m_vGridResolution[2] - 1; ++Z ) { 01408 index = Z * iOffsetSlice; 01409 for ( int Y = 1; Y < m_vGridResolution[1] - 1; ++Y ) { 01410 for ( int X = 1; X < m_vGridResolution[0] - 1; ++X ) { 01411 CreateConnectionsOfOneElementNotOnBoundary( 01412 Z, Y, X, listOfConnections, m_iElementMaxValence ); 01413 } 01414 } 01415 } 01416 //--------------------------------------------------------------- 01417 // The first (back) slice and the last (front) slice 01418 for ( int Z = 0; Z < m_vGridResolution[2]; Z += m_vGridResolution[2]-1 ) { 01419 for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) { 01420 for ( int X = 0; X < m_vGridResolution[0]; ++X ) { 01421 CreateConnectionsOfOneElementOnBoundary( 01422 Z, Y, X, listOfConnections, m_iElementMaxValence ); 01423 } 01424 } 01425 } 01426 //--------------------------------------------------------------- 01427 // The bottom slice and the top slice 01428 for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) { 01429 for ( int Y = 0; Y < m_vGridResolution[1]; Y += m_vGridResolution[1]-1 ) { 01430 for ( int X = 0; X < m_vGridResolution[0]; ++X ) { 01431 CreateConnectionsOfOneElementOnBoundary( 01432 Z, Y, X, listOfConnections, m_iElementMaxValence ); 01433 } 01434 } 01435 } 01436 //--------------------------------------------------------------- 01437 // The left slice and the right slice 01438 for ( int Z = 1; Z < m_vGridResolution[2] - 1; ++Z ) { 01439 for ( int Y = 1; Y < m_vGridResolution[1] - 1; ++Y ) { 01440 for ( int X = 0; X < m_vGridResolution[0]; X += m_vGridResolution[0]-1 ) { 01441 CreateConnectionsOfOneElementOnBoundary( 01442 Z, Y, X, listOfConnections, m_iElementMaxValence ); 01443 } 01444 } 01445 } 01446 //*/ 01447 } 01448 //----------------------------------------------------------------------------- 01449 template <typename T> 01450 void ModelDeformableCPU<T>::CreateConnectionsOfOneElementNotOnBoundary ( 01451 int z, int y, int x, int * connectionPattern, int connectionSize ) 01452 { 01453 //--------------------------------------------------------------- 01454 int iOffsetSlice = m_vGridResolution[1] * m_vGridResolution[0]; 01455 int indexThis = (z * iOffsetSlice + y * m_vGridResolution[0] + x); 01456 int idxConnection = indexThis * m_iElementMaxValence; // index for start of connections 01457 indexThis *= 4; // index for start of positions (+ flag) 01458 //--------------------------------------------------------------- 01459 static T threshold = 250; 01460 if ( m_tpElementPos[indexThis + 3] < threshold ) return; 01461 //--------------------------------------------------------------- 01462 int indexConnectedTo; 01463 //--------------------------------------------------------------- 01464 for ( int i = 0; i < connectionSize; ++i ) { 01465 //------------------------------------------------- 01466 int idx = idxConnection + i; 01467 m_ipElementConnect[idx] = CONNECTION_INDEX[SpringProp::CONNECT::NOT_CONNECTED]; 01468 //------------------------------------------------- 01469 indexConnectedTo = indexThis + connectionPattern[i]; 01470 if ( m_tpElementPos[indexConnectedTo + 3] >= threshold ) { 01471 m_ipElementConnect[idx] = connectionPattern[i]; 01472 } 01473 } 01474 } 01475 //----------------------------------------------------------------------------- 01476 template <typename T> 01477 void ModelDeformableCPU<T>::CreateConnectionsOfOneElementOnBoundary ( 01478 int z, int y, int x, int * connectionPattern, int connectionSize ) 01479 { 01480 //--------------------------------------------------------------- 01481 int iOffsetSlice = m_vGridResolution[1] * m_vGridResolution[0]; 01482 int indexThis = (z * iOffsetSlice + y * m_vGridResolution[0] + x); 01483 int idxConnection = indexThis * m_iElementMaxValence; // index for start of connections 01484 indexThis *= 4; // index for start of positions (+ flag) 01485 //--------------------------------- 01486 int iBoundEast = m_vGridResolution[0] - 1; 01487 int iBoundWest = 0; 01488 int iBoundNorth = m_vGridResolution[1] - 1; 01489 int iBoundSouth = 0; 01490 int iBoundFront = m_vGridResolution[2] - 1; 01491 int iBoundBack = 0; 01492 //--------------------------------------------------------------- 01493 static T threshold = 250; 01494 if ( m_tpElementPos[indexThis + 3] < threshold ) return; 01495 //--------------------------------------------------------------- 01496 int indexConnectedTo; 01497 //--------------------------------------------------------------- 01498 for ( int i = 0; i < connectionSize; ++i ) { 01499 //------------------------------------------------- 01500 int idx = idxConnection + i; 01501 m_ipElementConnect[idx] = CONNECTION_INDEX[SpringProp::CONNECT::NOT_CONNECTED]; 01502 indexConnectedTo = 0; 01503 //================================================= 01504 //------------------------------------------------- 01505 if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::EAST] ) { 01506 if ( x < iBoundEast ) { 01507 indexConnectedTo = indexThis + connectionPattern[i]; 01508 } 01509 } 01510 //------------------------------------------------- 01511 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::NORTH] ) { 01512 if ( y < iBoundNorth ) { 01513 indexConnectedTo = indexThis + connectionPattern[i]; 01514 } 01515 } 01516 //------------------------------------------------- 01517 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::WEST] ) { 01518 if ( x > iBoundWest ) { 01519 indexConnectedTo = indexThis + connectionPattern[i]; 01520 } 01521 } 01522 //------------------------------------------------- 01523 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::SOUTH] ) { 01524 if ( y > iBoundSouth ) { 01525 indexConnectedTo = indexThis + connectionPattern[i]; 01526 } 01527 } 01528 //================================================= 01529 //------------------------------------------------- 01530 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT] ) { 01531 if ( z < iBoundFront ) { 01532 indexConnectedTo = indexThis + connectionPattern[i]; 01533 } 01534 } 01535 //------------------------------------------------- 01536 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK] ) { 01537 if ( z > iBoundBack ) { 01538 indexConnectedTo = indexThis + connectionPattern[i]; 01539 } 01540 } 01541 //================================================= 01542 //------------------------------------------------- 01543 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::NORTH_EAST] ) { 01544 if ( y < iBoundNorth && x < iBoundEast ) { 01545 indexConnectedTo = indexThis + connectionPattern[i]; 01546 } 01547 } 01548 //------------------------------------------------- 01549 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::NORTH_WEST] ) { 01550 if ( y < iBoundNorth && x > iBoundWest ) { 01551 indexConnectedTo = indexThis + connectionPattern[i]; 01552 } 01553 } 01554 //------------------------------------------------- 01555 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::SOUTH_WEST] ) { 01556 if ( y > iBoundSouth && x > iBoundWest ) { 01557 indexConnectedTo = indexThis + connectionPattern[i]; 01558 } 01559 } 01560 //------------------------------------------------- 01561 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::SOUTH_EAST] ) { 01562 if ( y > iBoundSouth && x < iBoundEast ) { 01563 indexConnectedTo = indexThis + connectionPattern[i]; 01564 } 01565 } 01566 //================================================= 01567 //------------------------------------------------- 01568 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_EAST] ) { 01569 if ( z < iBoundFront && x < iBoundEast ) { 01570 indexConnectedTo = indexThis + connectionPattern[i]; 01571 } 01572 } 01573 //------------------------------------------------- 01574 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH] ) { 01575 if ( z < iBoundFront && y < iBoundNorth ) { 01576 indexConnectedTo = indexThis + connectionPattern[i]; 01577 } 01578 } 01579 //------------------------------------------------- 01580 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_WEST] ) { 01581 if ( z < iBoundFront && x > iBoundWest ) { 01582 indexConnectedTo = indexThis + connectionPattern[i]; 01583 } 01584 } 01585 //------------------------------------------------- 01586 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH] ) { 01587 if ( z < iBoundFront && y > iBoundSouth ) { 01588 indexConnectedTo = indexThis + connectionPattern[i]; 01589 } 01590 } 01591 //================================================= 01592 //------------------------------------------------- 01593 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_EAST] ) { 01594 if ( z > iBoundBack && x < iBoundEast ) { 01595 indexConnectedTo = indexThis + connectionPattern[i]; 01596 } 01597 } 01598 //------------------------------------------------- 01599 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH] ) { 01600 if ( z > iBoundBack && y < iBoundNorth ) { 01601 indexConnectedTo = indexThis + connectionPattern[i]; 01602 } 01603 } 01604 //------------------------------------------------- 01605 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_WEST] ) { 01606 if ( z > iBoundBack && x > iBoundWest ) { 01607 indexConnectedTo = indexThis + connectionPattern[i]; 01608 } 01609 } 01610 //------------------------------------------------- 01611 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH] ) { 01612 if ( z > iBoundBack && y > iBoundSouth ) { 01613 indexConnectedTo = indexThis + connectionPattern[i]; 01614 } 01615 } 01616 //================================================= 01617 //------------------------------------------------- 01618 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH_EAST] ) { 01619 if ( z < iBoundFront && y < iBoundNorth && x < iBoundEast ) { 01620 indexConnectedTo = indexThis + connectionPattern[i]; 01621 } 01622 } 01623 //------------------------------------------------- 01624 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH_WEST] ) { 01625 if ( z < iBoundFront && y < iBoundNorth && x > iBoundWest ) { 01626 indexConnectedTo = indexThis + connectionPattern[i]; 01627 } 01628 } 01629 //------------------------------------------------- 01630 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH_WEST] ) { 01631 if ( z < iBoundFront && y > iBoundSouth && x > iBoundWest ) { 01632 indexConnectedTo = indexThis + connectionPattern[i]; 01633 } 01634 } 01635 //------------------------------------------------- 01636 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH_EAST] ) { 01637 if ( z < iBoundFront && y > iBoundSouth && x < iBoundEast ) { 01638 indexConnectedTo = indexThis + connectionPattern[i]; 01639 } 01640 } 01641 //================================================= 01642 //------------------------------------------------- 01643 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH_EAST] ) { 01644 if ( z > iBoundBack && y < iBoundNorth && x < iBoundEast ) { 01645 indexConnectedTo = indexThis + connectionPattern[i]; 01646 } 01647 } 01648 //------------------------------------------------- 01649 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH_WEST] ) { 01650 if ( z > iBoundBack && y < iBoundNorth && x > iBoundWest ) { 01651 indexConnectedTo = indexThis + connectionPattern[i]; 01652 } 01653 } 01654 //------------------------------------------------- 01655 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH_WEST] ) { 01656 if ( z > iBoundBack && y > iBoundSouth && x > iBoundWest ) { 01657 indexConnectedTo = indexThis + connectionPattern[i]; 01658 } 01659 } 01660 //------------------------------------------------- 01661 else if ( connectionPattern[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH_EAST] ) { 01662 if ( z > iBoundBack && y > iBoundSouth && x < iBoundEast ) { 01663 indexConnectedTo = indexThis + connectionPattern[i]; 01664 } 01665 } 01666 //------------------------------------------------- 01667 //================================================= 01668 //------------------------------------------------- 01669 if ( indexConnectedTo > 0 ) { 01670 if ( m_tpElementPos[indexConnectedTo + 3] >= threshold ) { 01671 m_ipElementConnect[idx] = connectionPattern[i]; 01672 } 01673 } 01674 } 01675 } 01676 //----------------------------------------------------------------------------- 01677 //============================================================================= 01678 01679 //============================================================================= 01680 // Helper Fn(s): Simulation/Animation 01681 //----------------------------------------------------------------------------- 01682 template <typename T> 01683 void ModelDeformableCPU<T>::CalElementForceTotal ( 01684 int iElementID, T Vforce[3] ) 01685 { 01686 //--------------------------------------------------------------- 01687 // Reset the (output) force vector 01688 // Commented out if assume the force does not need to be reset! 01689 //Vforce[0] = Vforce[1] = Vforce[2] = 0; 01690 //--------------------------------------------------------------- 01691 // Calculate the Total Internal Force 01692 CalElementForceInternal ( iElementID, Vforce ); 01693 //--------------------------------------------------------------- 01694 // Calculate the Total External Force 01695 CalElementForceExternal ( iElementID, Vforce ); 01696 //--------------------------------------------------------------- 01697 } 01698 //----------------------------------------------------------------------------- 01699 template <typename T> 01700 void ModelDeformableCPU<T>::CalElementForceInternal ( 01701 int iElementID, T Vforce[3] ) 01702 { 01703 int iFromElementIdx = iElementID * 4; 01704 int iToElementIdx = 0; 01705 T Kstiffness = 0; 01706 T Kdamper = 0; 01707 T tRestLength = 1; 01708 //--------------------------------------------------------------- 01709 int start = iElementID * m_iElementMaxValence; 01710 for ( int i = start; i < start + m_iElementMaxValence; ++i ) { 01711 //------------------------------------------------- 01712 // Get the damped spring parameters 01713 //--------------------------------------- 01714 // Center to East and to West 01715 if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::EAST] ) { 01716 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::EAST]; 01717 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01718 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::EAST]; 01719 #endif 01720 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::EAST]; 01721 } 01722 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::WEST] ) { 01723 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::WEST]; 01724 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01725 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::WEST]; 01726 #endif 01727 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::WEST]; 01728 } 01729 //--------------------------------------- 01730 // Center to North and to South 01731 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::NORTH] ) { 01732 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::NORTH]; 01733 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01734 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::NORTH]; 01735 #endif 01736 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::NORTH]; 01737 } 01738 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::SOUTH] ) { 01739 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::SOUTH]; 01740 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01741 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::SOUTH]; 01742 #endif 01743 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::SOUTH]; 01744 } 01745 //--------------------------------------- 01746 // Center to Front and to Back 01747 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT] ) { 01748 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT]; 01749 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01750 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT]; 01751 #endif 01752 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT]; 01753 } 01754 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK] ) { 01755 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK]; 01756 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01757 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK]; 01758 #endif 01759 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK]; 01760 } 01761 //--------------------------------------- 01762 // Center to North East and to South West 01763 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::NORTH_EAST] ) { 01764 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::NORTH_EAST]; 01765 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01766 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::NORTH_EAST]; 01767 #endif 01768 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::NORTH_EAST]; 01769 } 01770 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::SOUTH_WEST] ) { 01771 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::SOUTH_WEST]; 01772 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01773 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::SOUTH_WEST]; 01774 #endif 01775 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::SOUTH_WEST]; 01776 } 01777 //--------------------------------------- 01778 // Center to North West and to South East 01779 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::NORTH_WEST] ) { 01780 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::NORTH_WEST]; 01781 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01782 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::NORTH_WEST]; 01783 #endif 01784 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::NORTH_WEST]; 01785 } 01786 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::SOUTH_EAST] ) { 01787 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::SOUTH_EAST]; 01788 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01789 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::SOUTH_EAST]; 01790 #endif 01791 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::SOUTH_EAST]; 01792 } 01793 //--------------------------------------- 01794 // Center to Front East and to South West 01795 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_EAST] ) { 01796 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT_EAST]; 01797 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01798 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT_EAST]; 01799 #endif 01800 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT_EAST]; 01801 } 01802 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_WEST] ) { 01803 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK_WEST]; 01804 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01805 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK_WEST]; 01806 #endif 01807 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK_WEST]; 01808 } 01809 //--------------------------------------- 01810 // Center to Front North and to Back South 01811 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH] ) { 01812 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT_NORTH]; 01813 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01814 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT_NORTH]; 01815 #endif 01816 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT_NORTH]; 01817 } 01818 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH] ) { 01819 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK_SOUTH]; 01820 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01821 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK_SOUTH]; 01822 #endif 01823 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK_SOUTH]; 01824 } 01825 //--------------------------------------- 01826 // Center to Front West and to Back East 01827 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_WEST] ) { 01828 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT_WEST]; 01829 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01830 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT_WEST]; 01831 #endif 01832 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT_WEST]; 01833 } 01834 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_EAST] ) { 01835 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK_EAST]; 01836 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01837 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK_EAST]; 01838 #endif 01839 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK_EAST]; 01840 } 01841 //--------------------------------------- 01842 // Center to Front South and to Back North 01843 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH] ) { 01844 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT_SOUTH]; 01845 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01846 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT_SOUTH]; 01847 #endif 01848 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT_SOUTH]; 01849 } 01850 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH] ) { 01851 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK_NORTH]; 01852 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01853 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK_NORTH]; 01854 #endif 01855 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK_NORTH]; 01856 } 01857 //--------------------------------------- 01858 // Center to Front North East and to Back South West 01859 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH_EAST] ) { 01860 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT_NORTH_EAST]; 01861 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01862 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT_NORTH_EAST]; 01863 #endif 01864 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT_NORTH_EAST]; 01865 } 01866 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH_WEST] ) { 01867 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK_SOUTH_WEST]; 01868 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01869 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK_SOUTH_WEST]; 01870 #endif 01871 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK_SOUTH_WEST]; 01872 } 01873 //--------------------------------------- 01874 // Center to Front North West and to Back South East 01875 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_NORTH_WEST] ) { 01876 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT_NORTH_WEST]; 01877 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01878 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT_NORTH_WEST]; 01879 #endif 01880 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT_NORTH_WEST]; 01881 } 01882 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_SOUTH_EAST] ) { 01883 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK_SOUTH_EAST]; 01884 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01885 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK_SOUTH_EAST]; 01886 #endif 01887 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK_SOUTH_EAST]; 01888 } 01889 //--------------------------------------- 01890 // Center to Front South West and to Back North East 01891 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH_WEST] ) { 01892 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT_SOUTH_WEST]; 01893 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01894 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT_SOUTH_WEST]; 01895 #endif 01896 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT_SOUTH_WEST]; 01897 } 01898 else if( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH_EAST] ) { 01899 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK_NORTH_EAST]; 01900 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01901 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK_NORTH_EAST]; 01902 #endif 01903 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK_NORTH_EAST]; 01904 } 01905 //--------------------------------------- 01906 // Center to Front South East and to Back North West 01907 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::FRONT_SOUTH_EAST] ) { 01908 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::FRONT_SOUTH_EAST]; 01909 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01910 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT_SOUTH_EAST]; 01911 #endif 01912 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::FRONT_SOUTH_EAST]; 01913 } 01914 else if ( m_ipElementConnect[i] == CONNECTION_INDEX[SpringProp::CONNECT::BACK_NORTH_WEST] ) { 01915 Kstiffness = SPRING_PROP.STIFFNESS[SpringProp::CONNECT::BACK_NORTH_WEST]; 01916 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01917 Kdamper = SPRING_PROP.DAMPER[SpringProp::CONNECT::BACK_NORTH_WEST]; 01918 #endif 01919 tRestLength = SPRING_PROP.REST_LENGTH[SpringProp::CONNECT::BACK_NORTH_WEST]; 01920 } 01921 //------------------------------------------------- 01922 //------------------------------------------------- 01923 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01924 // Calculate and add the damped spring force for 01925 // the explicit Euler integration 01926 iToElementIdx = iFromElementIdx + m_ipElementConnect[i]; 01927 AddDampedSpringForceForExplicitEulerIntegration( 01928 &m_tpElementPos[iFromElementIdx], 01929 &m_tpElementPos[iToElementIdx], 01930 &m_tpElementVel[iFromElementIdx], 01931 &m_tpElementVel[iToElementIdx], 01932 tRestLength, 01933 Kstiffness, 01934 Kdamping, 01935 Vforce 01936 ); 01937 #endif 01938 //------------------------------------------------- 01939 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VERLET_INTEGRATION 01940 // Calculate and add the undamped spring force for 01941 // the Verlet integration 01942 if ( m_ipElementConnect[i] != 0 ) { 01943 iToElementIdx = iFromElementIdx + m_ipElementConnect[i]; 01944 01945 /* 01946 // DEBUG] 01947 std::cout << "\nm_ipElementConnect[" << i%26 << "]: " << m_ipElementConnect[i] << "\n"; 01948 std::cout << "iFromElementIdx: " << iFromElementIdx << "\n"; 01949 std::cout << "iToElementIdx: " << iToElementIdx << "\n"; 01950 //*/ 01951 01952 AddUndampedSpringForceForVerletIntegration( 01953 &m_tpElementPos[iFromElementIdx], 01954 &m_tpElementPos[iToElementIdx], 01955 tRestLength, 01956 Kstiffness, 01957 Vforce 01958 ); 01959 } 01960 #endif 01961 } 01962 } 01963 //----------------------------------------------------------------------------- 01964 template <typename T> 01965 void ModelDeformableCPU<T>::CalElementForceExternal ( 01966 int iElementID, T Vforce[3] ) 01967 { 01968 } 01969 01970 //============================================================================= 01971 #ifdef TAPs_MODEL_DEFORMABLE_CPU_EXPLICIT_EULER_INTEGRATION 01972 template <typename T> 01973 void ModelDeformableCPU<T>::SimStepByExplicitEulerIntegration ( T dt ) 01974 { 01975 //--------------------------------------------------------------- 01976 for ( int i = 0; i < iTotalElements; ++i ) { 01977 CalElementNextPositionByExplicitEulerIntegration( i ); 01978 } 01979 //--------------------------------------------------------------- 01980 SwapCurrentStatesWithNextStatesForExplicitEulerIntegration(); 01981 } 01982 #endif 01983 //============================================================================= 01984 #ifdef TAPs_MODEL_DEFORMABLE_CPU_VERLET_INTEGRATION 01985 template <typename T> 01986 void ModelDeformableCPU<T>::SimStepByVerletIntegration ( T dt ) 01987 { 01988 //--------------------------------------------------------------- 01989 T dtdt_over_mass = dt * dt / m_tMass; 01990 //T tScaleForDampedForce = SPRING_PROP.DAMPER[SpringProp::CONNECT::FRONT];// / dt; 01991 T tScaleForDampedForce = 1; 01992 int iElementFlagIdx = 3; 01993 static T threshold = 250; 01994 //--------------------------------------------------------------- 01995 //* 01996 // Calculate next positions 01997 // for ( int iElementNumber = 0; iElementNumber < m_iTotalElements; ++iElementNumber ) { 01998 int iElementNumber = 0; 01999 for ( int Z = 0; Z < m_vGridResolution[2]; ++Z ) { 02000 for ( int Y = 0; Y < m_vGridResolution[1]; ++Y ) { 02001 for ( int X = 0; X < m_vGridResolution[0]; ++X ) { 02002 if ( m_tpElementPos[ iElementFlagIdx ] >= threshold ) { 02003 //std::cout << "X:" << X << " Y:" << Y << " Z:" << Z << "\n"; // DEBUG 02004 CalElementNextPositionByVerletIntegration( 02005 iElementNumber, dt, dtdt_over_mass, tScaleForDampedForce ); 02006 } 02007 iElementFlagIdx += 4; 02008 ++iElementNumber; 02009 } 02010 } 02011 } 02012 //*/ 02013 //--------------------------------------------------------------- 02014 //std::cout << "Right Before Calling Swap\n"; 02015 SwapCurrentStatesWithNextStatesForVerletIntegration(); 02016 //std::cout << "Right After Calling Swap\n"; 02017 } 02018 #endif 02019 //----------------------------------------------------------------------------- 02020 //============================================================================= 02021 02022 //----------------------------------------------------------------------------- 02023 //============================================================================= 02024 END_NAMESPACE_TAPs__OpenGL 02025 //----------------------------------------------------------------------------- 02026 //34567890123456789012345678901234567890123456789012345678901234567890123456789 02027 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----