![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsModelDeformableGLSL.hpp 00003 ******************************************************************************/ 00092 /****************************************************************************** 00093 SUKITTI PUNAK (10/17/2006) 00094 UPDATE (10/29/2007) 00095 ******************************************************************************/ 00096 #ifndef TAPs_MODEL_DEFORMABLE_GLSL_HPP 00097 #define TAPs_MODEL_DEFORMABLE_GLSL_HPP 00098 00099 #include "../GLSL/TAPsGLSLFns.hpp" 00100 #include "TAPsOpenGLModel.hpp" 00101 //#include "Support/TAPsSpringPropertiesForDefModel.hpp" 00102 #include "../OpenGL/TAPsOpenGLTexture.hpp" 00103 00109 //#define TAPs_GRID_GENERATOR_BY_SOFTWARE 00110 #include "../CG/TAPsGridGenerator_ForTheDefModBasedOnMSS.hpp" 00111 00112 // For I/O Files 00113 #include <iostream> 00114 #include <fstream> 00115 #include <iomanip> 00116 //#include <cstdlib> 00117 00118 // DEBUG for PNTri Drawing 00119 //#include <TAPs/GLSL/TAPsShaderFns.hpp> 00120 //GLuint g_PNTriProg; 00121 00122 //============================================================================= 00123 // DEFINES / CHOICES 00124 //============================================================================= 00125 00126 //----------------------------------------------------------------------------- 00127 // VISUALIZATION 00128 //----------------------------------------------------------------------------- 00129 // Visualization/Rendering Selection 00130 // One of the defined statement below 00131 // should be declared in a file that declares and uses this class. 00132 // E.g. in the main file 00133 #define TAPs_DEFORMABLE_MODEL_VISUALIZATION_RT_GEN_MESH // Default 00134 //#define TAPs_DEFORMABLE_MODEL_VISUALIZATION_3D_TEXTURE // Not Finished Yet! 00135 //#define TAPs_DEFORMABLE_MODEL_VISUALIZATION_RAY_CASTING // Not Implemented Yet! 00136 //#define TAPs_DEFORMABLE_MODEL_VISUALIZATION_MESH // Not Implemented Yet! 00137 //----------------------------------------------------------------------------- 00138 #if defined ( TAPs_DEFORMABLE_MODEL_VISUALIZATION_RT_GEN_MESH ) 00139 #define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00140 #elif defined ( TAPs_DEFORMABLE_MODEL_VISUALIZATION_3D_TEXTURE ) // Not Finished Yet! 00141 #define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00142 #elif defined ( TAPs_DEFORMABLE_MODEL_VISUALIZATION_RAY_CASTING ) // Not Implemented Yet! 00143 #define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00144 #elif defined ( TAPs_DEFORMABLE_MODEL_VISUALIZATION_MESH ) // Not Implemented Yet! 00145 #define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00146 #else 00147 //#define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH // Default 00148 #endif 00149 #if defined ( TAPs_DEFORMABLE_MODEL_VISUALIZATION_RT_GEN_MESH ) 00150 #define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00151 #endif 00152 #if defined ( TAPs_DEFORMABLE_MODEL_VISUALIZATION_3D_TEXTURE ) // Not Finished Yet! 00153 #define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00154 #endif 00155 #if defined ( TAPs_DEFORMABLE_MODEL_VISUALIZATION_RAY_CASTING ) // Not Implemented Yet! 00156 #define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00157 #endif 00158 #if defined ( TAPs_DEFORMABLE_MODEL_VISUALIZATION_MESH ) // Not Implemented Yet! 00159 #define TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00160 #endif 00161 //----------------------------------------------------------------------------- 00162 // For Helping Coding 00163 //----------------------------------------------------------------------------- 00164 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00165 //... 00166 #endif 00167 //------------------------------------------------------------------- 00168 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE // NOT FINISHED YET! 00169 //... 00170 #endif 00171 //------------------------------------------------------------------- 00172 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING // NOT IMPLEMENTED YET! 00173 //... 00174 #endif 00175 //----------------------------------------------------------------------------- 00176 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH // NOT IMPLEMENTED YET! 00177 //... 00178 #endif 00179 //----------------------------------------------------------------------------- 00180 00181 //----------------------------------------------------------------------------- 00182 // Gradient Texture (on GPU) 00183 // One of the defined statement below 00184 // should be declared in a file that declares and uses this class. 00185 // E.g. in the main file 00193 //------------------------------------------------------------------- 00194 //#define TAPs_DEFORMABLE_MODEL_NOT_USE_GRADIENT_TEXTURE // For DEBUGGING 00195 00196 #if defined ( TAPs_DEFORMABLE_MODEL_NOT_USE_GRADIENT_TEXTURE ) 00197 #define TAPs_MODEL_DEFORMABLE_NOT_USE_GRADIENT_TEXTURE 00198 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_GRADIENT_TEXTURE ) 00199 #define TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00200 #else 00201 #define TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00202 #endif 00203 //----------------------------------------------------------------------------- 00204 00205 //============================================================================= 00206 // For Visualization 00207 //----------------------------------------------------------------------------- 00208 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00209 #include "TAPsModelDeformableGLSL_Visualization_RTGenMesh.hpp" 00210 #endif 00211 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE // NOT FINISHED YET! 00212 #include "TAPsModelDeformableGLSL_Visualization_3DTexture.hpp" 00213 #endif 00214 //----------------------------------------------------------------------------- 00215 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING // NOT IMPLEMENTED YET! 00216 // #include "TAPsModelDeformableGLSL_Visualization_RayCasting.hpp" 00217 #endif 00218 //----------------------------------------------------------------------------- 00219 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH // NOT IMPLEMENTED YET! 00220 // #include "TAPsModelDeformableGLSL_Visualization_Mesh.hpp" 00221 #endif 00222 //----------------------------------------------------------------------------- 00223 //============================================================================= 00224 00225 //------------------------------------------------------------------- 00226 // GPU Card/Type Selection 00227 // One of the defined statement below 00228 // should be declared in a file that declares and uses this class. 00229 // E.g. in the main file 00230 //#define TAPs_ATI 00231 //#define TAPs_NVIDIA 00232 //------------------------------------------------------------------- 00233 #if defined ( TAPs_ATI ) 00234 #define TAPs_ATI_CARD 00235 #elif defined ( TAPs_NVIDIA ) 00236 #define TAPs_NVIDIA_CARD 00237 #else 00238 #define TAPs_NVIDIA_CARD 00239 #endif 00240 //------------------------------------------------------------------- 00241 // For Helping Coding 00242 //----------------------------------------------------------------------------- 00243 #ifdef TAPs_ATI_CARD 00244 // ... 00245 #endif 00246 //----------------------------------------------------------------------------- 00247 #ifdef TAPs_NVIDIA_CARD 00248 // ... 00249 #endif 00250 //----------------------------------------------------------------------------- 00251 00252 //------------------------------------------------------------------- 00253 // Integration Method Selection 00254 // One of the defined statement below 00255 // should be declared in a file that declares and uses this class. 00256 // E.g. in the main file 00257 //#define TAPs_EXPLICIT_EULER_INTEGRATION 00258 //#define TAPs_VERLET_INTEGRATION // Default 00259 //------------------------------------------------------------------- 00260 #if defined ( TAPs_EXPLICIT_EULER_INTEGRATION ) 00261 #define TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 00262 #elif defined ( TAPs_VERLET_INTEGRATION ) 00263 #define TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 00264 #else 00265 #define TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 00266 #endif 00267 //------------------------------------------------------------------- 00268 // For Helping Coding 00269 //----------------------------------------------------------------------------- 00270 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION // NOT IMPLEMENTED YET! 00271 // ... 00272 #endif 00273 //----------------------------------------------------------------------------- 00274 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 00275 // ... 00276 #endif 00277 //----------------------------------------------------------------------------- 00278 00279 //------------------------------------------------------------------- 00280 // Connectivity Texture Arrangement Selection (for GPU) 00281 // One of the defined statement below 00282 // should be declared in a file that declares and uses this class. 00283 // E.g. in the main file 00284 //#define TAPs_USE_TEXTURE_CONNECTIVITY_ONE 00285 //#define TAPs_USE_TEXTURE_CONNECTIVITY_3X3 // Default 00295 //------------------------------------------------------------------- 00296 #if defined ( TAPs_USE_TEXTURE_CONNECTIVITY_ONE ) 00297 #define TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00298 #elif defined ( TAPs_USE_TEXTURE_CONNECTIVITY_3X3 ) // NOT FINISHED YET! 00299 #define TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 00300 #else 00301 #define TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 00302 #endif 00303 //------------------------------------------------------------------- 00304 // For Helping Coding 00305 //----------------------------------------------------------------------------- 00306 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00307 #endif 00308 //----------------------------------------------------------------------------- 00309 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 00310 #endif 00311 //----------------------------------------------------------------------------- 00312 00313 //------------------------------------------------------------------- 00314 // Connectivity Options (for GPU) 00315 // One of the defined statement below 00316 // should be declared in a file that declares and uses this class. 00317 // E.g. in the main file 00343 //------------------------------------------------------------------- 00344 // One Set 00345 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE 00346 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_VERTEX 00347 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_EDGE 00348 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_HOME 00349 00350 // Two Sets 00351 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_VERTEX 00352 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_EDGE 00353 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_HOME 00354 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_VERTEX_EDGE 00355 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_VERTEX_HOME 00356 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_EDGE_HOME 00357 00358 // Three Sets 00359 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_VERTEX_EDGE 00360 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_VERTEX_HOME 00361 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_EDGE_HOME 00362 //#define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_VERTEX_EDGE_HOME 00363 00364 // Four Sets == FULL 00365 //#define TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FULL 00366 //------------------------------------------------------------------- 00367 // Four Sets -- Full 00368 #if defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FULL ) 00369 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FULL 00370 00371 // One Set 00372 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FACE ) 00373 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE 00374 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_VERTEX ) 00375 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_VERTEX 00376 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_EDGE ) 00377 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_EDGE 00378 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_HOME ) 00379 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_HOME 00380 00381 // Two Sets 00382 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FACE_VERTEX ) 00383 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_VERTEX 00384 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FACE_EDGE ) 00385 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_EDGE 00386 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FACE_HOME ) 00387 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_HOME 00388 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_VERTEX_EDGE ) 00389 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_VERTEX_EDGE 00390 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_VERTEX_HOME ) 00391 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_VERTEX_HOME 00392 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_EDGE_HOME ) 00393 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_EDGE_HOME 00394 00395 // Three Sets 00396 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FACE_VERTEX_EDGE ) 00397 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_VERTEX_EDGE 00398 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FACE_VERTEX_HOME ) 00399 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_VERTEX_HOME 00400 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FACE_EDGE_HOME ) 00401 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_EDGE_HOME 00402 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_VERTEX_EDGE_HOME ) 00403 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_VERTEX_EDGE_HOME 00404 00405 // Plane (+ Home) 00406 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_PLANE ) 00407 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_PLANE 00408 #elif defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_PLANE_HOME ) 00409 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_PLANE_HOME 00410 00411 // Default 00412 #else // #if defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FULL ) 00413 #define TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FULL 00414 00415 #endif // #if defined ( TAPs_DEFORMABLE_MODEL_USE_CONNECTIVITY_FULL ) 00416 //------------------------------------------------------------------- 00417 // For Helping Coding 00418 //----------------------------------------------------------------------------- 00419 #ifdef TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FULL 00420 #endif 00421 //----------------------------------------------------------------------------- 00422 #ifdef TAPs_MODEL_DEFORMABLE_USE_CONNECTIVITY_FACE_VERTEX_EDGE_HOME 00423 #endif 00424 //----------------------------------------------------------------------------- 00425 00426 //============================================================================= 00427 // For Spring Properties (according to the type of connectivity) 00428 #include "Support/TAPsSpringPropertiesForDefModel.hpp" 00429 //============================================================================= 00430 00431 BEGIN_NAMESPACE_TAPs__OpenGL 00432 //============================================================================= 00433 template <typename T> 00434 class ModelDeformableGLSL : public /*virtual*/ OpenGLModel<T> { 00435 //------------------------------------------------------------------------- 00436 // (Friend Fn) put it through ostream 00437 friend std::ostream & operator<< ( std::ostream &output, ModelDeformableGLSL<T> const &o ) 00438 { 00439 output << "\n=========================================================\n" 00440 << "TAPs::OpenGL::ModelDeformableGLSL<" << typeid(T).name() << "> Class:\n" 00441 << "=========================================================\n"; 00442 //------------------------------------------------- 00443 output << o.Info(); 00444 output << "\n=========================================================\n"; 00445 //------------------------------------------------- 00446 return output; 00447 } 00448 //----------------------------------------------------------------------------- 00449 // Member Functions ----------------------------------------------------------- 00450 00451 00452 00453 //--------------- 00454 // 3D Texture(s) 00455 //static GLuint texture3D_1; 00456 //static GLuint Generate3DTexture (); 00457 00458 00459 protected: 00460 static T g_tPressureValue; // For mimicing internal pressure value 00461 public: 00462 static T GetPressureValue () { return g_tPressureValue; } 00463 static void SetPressureValue ( T val ) { g_tPressureValue = val; } 00464 00465 public: 00466 //------------------------------------------------------------------------- 00467 // default constructor 00468 ModelDeformableGLSL (); 00469 //------------------------------------------------------------------------- 00470 // destructor 00471 virtual ~ModelDeformableGLSL (); 00472 //------------------------------------------------------------------------- 00473 virtual void Default (); 00474 virtual void Clear (); 00475 //------------------------------------------------------------------------- 00476 // Initialize from GridGenerator 00477 virtual void Initialize () {}; // Abstract Virtual Fn from Model class 00478 00484 virtual int InitializeFromGridGeneratorDataFloat ( 00485 GridGenerator<T> * pGridGenerator 00486 ); 00487 00488 //------------------------------------------------------------------------- 00489 // Load from and Save to a file 00490 virtual bool LoadFromFile ( 00491 const std::string & fileName 00492 ); 00493 virtual bool SaveToFile ( 00494 const std::string & fileName 00495 ); 00496 // Helper Fns and Attributes 00497 private: 00498 // Helper Fns for LoadFromFile 00499 bool ProcessLinesOfCompilationOptions ( std::ifstream & ); 00500 bool ProcessLinesOfParameters ( std::ifstream & ); 00501 bool ProcessLinesOfSpringRestLength ( std::ifstream & ); 00502 bool ProcessLinesOfSpringStiffness ( std::ifstream & ); 00503 bool ProcessLinesOfSpringDamping ( std::ifstream & ); 00504 bool ProcessLinesOfPositions ( std::ifstream &, GLfloat * ); 00505 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 00506 bool ProcessLinesOfConnections ( std::ifstream &, GLfloat * ); 00507 #endif 00508 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00509 bool ProcessLinesOfConnections ( std::ifstream &, GLubyte * ); 00510 #endif 00511 bool ProcessLinesOfEllipsoidInfluences ( std::ifstream &, GLfloat * ); 00512 bool ProcessLinesOfVisualizedByRTGenMesh ( std::ifstream &, 00513 bool & bUseGlobalIntp, 00514 T & tGlobalIntpVal, 00515 bool & bDrawnWithPNTris, 00516 int & iPNTrisSmoothness, 00517 GLuint & ui3DTextureID 00518 ); 00519 bool ProcessLinesOfVisualizedBy3DTexture ( std::ifstream & ); 00520 //------------------------------------------------------------------------- 00521 00522 public: 00523 00524 /* // Not Implemented Yet! 00525 virtual bool InitializeFromDataFloat ( 00526 GLsizei width, 00527 GLsizei heigth, 00528 GLsizei depth, 00529 GLint internalFormat, 00530 GLenum pixel_format, 00531 GLfloat * texels 00532 ); 00533 //*/ 00534 //------------------------------------------------------------------------- 00535 virtual T GetMaxHalfLength () const; // Abstract Virtual Fn from Model class // Not Implemented Yet! 00536 virtual void ApplyAndResetTransform (); // Not Implemented Yet! 00537 //------------------------------------------------------------------------- 00538 // Calculate and set the normals 00539 virtual void CalAndSetNormals(); // Not Implemented Yet! 00540 //------------------------------------------------------------------------- 00541 // Get/Set Fn(s) 00542 Vector3<int> const & RetGridResolution () const { return m_vGridResolution; } 00543 Vector3<T> const & RetGridDimension () const { return m_vGridDimension; } 00544 Vector3<int> GetGridResolution () const { return m_vGridResolution; } 00545 Vector3<T> GetGridDimension () const { return m_vGridDimension; } 00546 int GetTotalGridElements () const { return m_iTotalElements; } 00547 T GetGridElementVolume () const { return m_fElementVolume; } 00548 //------------------------------------------------------------------------- 00549 // Calculation(s) 00550 void CalAndRecordFreqsOfHistogramRange_0_255_ToArray ( GLubyte freqs[256] ); 00551 //------------------------------------------------------------------------- 00552 // New/Delete Fn(s) 00553 //========================================================================= 00554 // Rendering/Display/Drawing Fn(s) 00555 //------------------------------------------------------------------------- 00556 // OpenGL Display Fn(s) 00557 // Inherited from OpenGLSupport 00558 //virtual void DisplayGL ( OpenGL::Enum::DrawMode = OpenGL::Enum::POLYGON ); 00559 virtual void DrawGL ( GLenum eDrawMode ); 00560 //------------------------------------------- 00561 // Internal Drawing Mode 00562 static enum DrawType { 00563 /* 00564 AS_2D_TEXTURE, 00565 AS_3D_TEXTURE, 00566 POSITION_TEXTURE, 00567 ALL_ELEMENTS, 00568 ALL_ELEMENTS_WITH_CONNECTIVITIES, 00569 //*/ 00570 00571 //* 00572 DRAW_RT_GEN_MESH, // == POSITION_TEXTURE 00573 DRAW_RT_GEN_MESH_BY_GPU, // == POSITION_TEXTURE 00574 DRAW_RT_GEN_MESH_BY_CPU, // == POSITION_TEXTURE 00575 DRAW_RT_GEN_MESH_BY_CPU_STANDARD_MC, // standard marching cubes algorithm 00576 DRAW_3D_TEXTURE, 00577 //DRAW_RAY_CASTING, // Not Implemented Yet! 00578 //DRAW_MESH, // Not Implemented Yet! 00579 DRAW_ALL_ELEMENTS, 00580 DRAW_ALL_ELEMENTS_WITH_CONNECTIVITIES, // == AS_2D_TEXTURE 00581 //*/ 00582 00583 DUMMY_DrawType 00584 }; 00585 bool IsVisualizedByRTGenMesh () { 00586 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00587 return true; 00588 #else 00589 return false; 00590 #endif 00591 } 00592 bool IsVisualizedBy3DTexture () { 00593 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00594 return true; 00595 #else 00596 return false; 00597 #endif 00598 } 00599 /* Not Implemented Yet! 00600 bool IsVisualizedByRayCasting () { 00601 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00602 return true; 00603 #else 00604 return false; 00605 #endif 00606 } 00607 bool IsVisualizedByMesh () { 00608 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00609 return true; 00610 #else 00611 return false; 00612 #endif 00613 } 00614 */ 00615 virtual void DrawByGL ( DrawType drawType = DRAW_RT_GEN_MESH ); 00616 //virtual void DrawByGLSL ( DrawType drawType = POSITION_TEXTURE ); 00617 virtual void Visualize ( DrawType drawType = DRAW_ALL_ELEMENTS ); 00618 //--------------------------------- 00619 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00620 virtual inline void VisualizeByRTGenMesh ( DrawType drawType ); 00621 virtual inline void VisualizeByRTGenMeshBySW ( DrawType drawType ); 00622 virtual inline void VisualizeByRTGenMeshBySW_StandardMC ( DrawType drawType ); 00623 #endif 00624 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00625 virtual inline void VisualizeBy3DTexture ( DrawType drawType ); 00626 #endif 00627 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00628 virtual inline void VisualizeByRayCasting ( DrawType drawType ); 00629 #endif 00630 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00631 virtual inline void VisualizeByMesh ( DrawType drawType ); 00632 #endif 00633 //--------------------------------- 00634 protected: 00635 virtual void DrawByGL_AllElementsWithConnectivities_GPU (); // This one draws pos data from GPU mem 00636 virtual void DrawByGL_AllElementsWithConnectivities_GPU_AsQuads (); // This one draws pos data from GPU mem 00637 //------------------------------------------------------------------------- 00638 //========================================================================= 00639 //----------------------------------------------------------------------------- 00640 protected: 00641 //========================================================================= 00642 // Helper Fn(s): Creations/Initializations 00643 //------------------------------------------------------------------------- 00644 int TranslateElementNumber ( int x, int y, int z ) { 00645 assert( 0 <= x && x < m_vGridResolution[0] ); 00646 assert( 0 <= y && y < m_vGridResolution[1] ); 00647 assert( 0 <= z && z < m_vGridResolution[2] ); 00648 return (z * m_vGridResolution[1] + y) * m_vGridResolution[0] + x; 00649 } 00650 //------------------------------------------------------------------------- 00651 //========================================================================= 00652 //------------------------------------------------------------------------- 00653 //========================================================================= 00654 // Helper Fn(s): Simulation/Animation 00655 //------------------------------------------------------------------------- 00656 // Inner Class for Thresholds 00657 public: 00658 class IC_Thresholds { 00659 public: 00660 //--------------------------------------- 00661 // Element Types 00662 static const int UNSET = 0; 00663 static const int OUTSIDE_MODEL = 100; 00664 //static const int RIGHT_OUTSIDE_MODEL = 200; // SAME AS RIGHT_OUTSIDE_BOUNDARY 00665 static const int RIGHT_OUTSIDE_BOUNDARY = 200; 00666 static const int ON_BOUNDARY = 300; 00667 //static const int RIGHT_INSIDE_MODEL = 400; // SAME AS RIGHT_INSIDE_BOUNDARY 00668 static const int RIGHT_INSIDE_BOUNDARY = 400; 00669 static const int INSIDE_MODEL = 500; 00670 //--------------------------------------- 00676 static const int HALF_THRESHOLD_ADD = 1; 00677 //--------------------------------------- 00681 static const int MC_LEFT_ADD = 5; 00682 static const int MC_RIGHT_ADD = 10; 00683 //--------------------------------------- 00684 // Grabbed Threshold Add 00685 static const int GRABBED_THRESHOLD_ADD = 20; 00686 //--------------------------------------- 00687 // Fixed Threshold Add 00688 static const int FIXED_THRESHOLD_ADD = 50; 00689 //--------------------------------------- 00690 static const int FLAG_STEP = 100; 00691 static const int FIXED_GRABBED_THRESHOLD= 18; 00692 //--------------------------------------- 00693 00694 00695 //============================================================================= 00696 // ADD THE CODE BELOW TO EACH SHADER FOR CONSISTENCY VALUES FOR CODING 00697 //============================================================================= 00698 /* 00699 * REFER TO "TAPsModelDeformableGLSL.hpp" FOR THESE INFO 00700 * 00701 * Represented as Vertices (XYZF) x,y,z and flag (F): 00702 * 00703 * F is 0.0 represents UNSET 00704 * 00705 * F is 100.0 represents OUTSIDE_MODEL 00706 * 00707 * F is 200.0 represents RIGHT_OUTSIDE_MODEL 00708 * 00709 * F is 300.0 represents ON_BOUNDARY 00710 * 00711 * F is 400.0 represents RIGHT_INSIDE_MODEL 00712 * 00713 * F is 500.0 represents INSIDE_MODEL 00714 * 00715 * HALF_THRESHOLD_ADD is 1.0 that add to threshold for adjusting threshold 00716 * 00717 * For visualization by marching cubes 00718 * MC_LEFT_ADD = 5; 00719 * MC_RIGHT_ADD = 10; 00720 * 00721 * GRABBED_THRESHOLD_ADD is 20.0 that add to F for grabing the element's position 00722 * 00723 * FIXED_THRESHOLD_ADD is 50.0 that add to F for fixing the element's position 00724 * 00725 #define UNSET 0.0 00726 #define OUTSIDE_MODEL 100.0 00727 #define RIGHT_OUTSIDE_MODEL 200.0 00728 #define ON_BOUNDARY 300.0 00729 #define RIGHT_INSIDE_MODEL 400.0 00730 #define INSIDE_MODEL 500.0 00731 00732 #define HALF_THRESHOLD_ADD 1.0 00733 00734 #define MC_LEFT_ADD 5.0 00735 #define MC_RIGHT_ADD 10.0 00736 00737 #define GRABBED_THRESHOLD_ADD 20.0 00738 #define FIXED_THRESHOLD_ADD 50.0 00739 00740 #define FLAG_STEP 100.0 // step value to each type of flag 00741 #define FIXED_GRABBED_THRESHOLD 18.0 // fixed or grabbed threshold 00742 #define ZERO 0.0 00743 #define fZero 0.5 // zero value 00744 //============================================================================= 00745 //*/ 00746 00747 00748 }; // END: class IC_Thresholds 00749 //--------------------------------------------------------------- 00750 protected: 00754 void VoidAnElement ( int iElementID ); 00755 //--------------------------------------------------------------- 00759 void RemoveElementConnection ( int iElementID, int iConnection ); 00760 //------------------------------------------------------------------------- 00761 //========================================================================= 00762 //------------------------------------------------------------------------- 00763 // virtual inline void CalAndSetFaceNormalsNotNormalized (); 00764 // virtual inline void NormalizeFaceNormals (); 00765 // virtual inline void DetermineFaceRings (); 00766 // virtual inline void CalAndSetElementNormals (); 00767 //------------------------------------------------------------------------- 00768 // Abstract Virtual Fns for Collision Detection from ColDetSupport class 00769 virtual void CalBoundingAABB (); 00770 virtual void CalBoundingEllipsoid (); 00771 virtual void CalBoundingSphere (); 00772 //----------------------------------------------------------------------------- 00773 // Data Members -------------------------------------------------------------- 00774 protected: 00775 //========================================================================= 00776 // CPU 00777 //------------------------------------------------------------------------- 00778 // Grid Sizes/Resolutions and Grid Spacings/Dimensions 00779 Vector3< int > m_vGridResolution; // width, height, and depth numbers 00780 // e.g. 64 x 64 x 64 00781 Vector3< T > m_vGridDimension; // width, height, and depth lengths 00782 // e.g. 0.1 x 0.1 x 0.1 00783 int m_iTotalElements; // multiplication of the grid resolutions 00784 T m_fElementVolume; // multiplication of the grid dimensions 00785 //------------------------------------------------------------------------- 00786 //========================================================================= 00787 //------------------------------------------------------------------------- 00788 // For Helping Drawing 00789 OpenGLUsefulObj< T > m_OGLUsefulObj; // for drawing useful objects 00790 //------------------------------------------------------------------------- 00791 //========================================================================= 00792 // GPU 00793 //------------------------------------------------------------------------- 00809 //------------------------------------------- 00810 // Element Status and Connectivity 00814 //T * m_tpElementStatus; // vertex status (scalar) 00829 //------------------------------------------------------------------------- 00834 protected: 00835 //------------------------------------------------------------------------- 00839 void InitConnectionConstants (); 00840 //--------------------------------- 00841 // int * m_ipElementConnect; // vertex connectivities for each vertex 00842 // arranged sequentially, 00843 // i.e. = new int[m_iTotalElements * m_iElementMaxValence]; 00844 // int m_iElementMaxValence; // vertex max valence (up to 26) 00845 //--------------------------------- 00846 // Surface Boundary 00847 int * m_ipSurfaceBoundary; // surface boundary (by indices) 00848 //------------------------------------------------------------------------- 00849 00850 //========================================================================= 00851 // GPU 00852 //------------------------------------------------------------------------- 00853 // For OpenGL Shading Language 00854 GLSLShaderManager m_glslShaderManager; 00855 GLSLProgramObject * m_glslProgramObjectForDefModelStep; // Simulation Step Computation 00856 GLSLProgramObject * m_glslProgramObjectForRelaxationConstraint; // The Provot's Paper 00857 // Provot, X. Deformation Constraints in a Mass-Spring Model to Describe Rigid Cloth Behavior. 00858 // Graphics Interface ’95, 1995, pp.147-154 00859 GLSLProgramObject * m_glslProgramObjectForDefModelCollisionDetection; // Collision Detection 00860 GLSLProgramObject * m_glslProgramObjectForDefModelCDTooltipSphereCylinder; // Collision Detection 00861 GLSLProgramObject * m_glslProgramObjectForRemovingElements; // Remove Elements by Collision 00862 00863 // Grabbing --- will read and write the offset texture 00864 GLSLProgramObject * m_glslProgramObjectForDefModelCDGrabStart; // Collision Detection for grabbing (Start) 00865 GLSLProgramObject * m_glslProgramObjectForDefModelCDGrabMove; // Collision Detection for grabbing (Move) 00866 GLSLProgramObject * m_glslProgramObjectForDefModelCDGrabEnd; // Collision Detection for grabbing (End) 00867 00868 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00869 GLSLProgramObject * m_glslProgramObjectForRemovingConnections; // Remove Connections by Collision 00870 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 00871 00872 // Connectivity has to be changed due to some changes of elements' status 00873 GLSLProgramObject * m_glslProgramObjectForUpdateConnectivity; // Update Connectivity 00874 // Apply new global connectivity, i.e. from full 26 connections to 17 connections 00875 //GLSLProgramObject * m_glslProgramObjectForChangeOfConnectivity; // Change of Connectivity 00876 //------------------------------------------------------------------------- 00877 GLuint m_glslFBO_vPosition; // Frame buffers for positions (need one buffer) 00878 //GLuint m_glslFBO_vVelocity; // Frame buffers for velocities (need one buffer) 00879 GLuint m_glslFBO_vConnectivity; // Frame buffers for connectivities (need one buffer) 00880 GLuint m_glslFBO_vCollisionDetection; // Frame buffers for collision detection (need one buffer) 00881 // Has the same size as the FBO for positions 00882 // So it can share the pixel buffer (m_glslFBO_vPosition) for positions 00883 GLuint m_glslFBO_vOffsetValues; // Frame buffers for offset values (need one buffer) 00884 // Has the same size as the FBO for positions 00885 // So it can share the pixel buffer (m_glslFBO_vPosition) for positions 00886 GLuint m_glslRBO; // Render buffers 00887 GLuint * m_glslpBufferIDForPosition; // Pixel buffers for positions (readback) (need one buffer) 00888 GLuint * m_glslpBufferIDForConnectivity; // Pixel buffers for positions (readback) (need one buffer) 00889 //GLuint * m_glslpBufferIDForCollisionDetection; // Pixel buffers for collsion detection (readback) (need one buffer) 00890 //GLuint * m_glslpVertexArrayBufferID; // 00891 //------------------------------------------- 00892 public: 00893 //------------------------------------------- 00894 // Ret OpenGL Texture Objects 00895 Texture * RetObject3DTextureHomePosition () { return m_3DTextureHomePosition; } 00896 Texture * RetObject3DTexturePosition () { return m_3DTexturePosition; } 00897 Texture * RetObject3DTextureConnectivity () { return m_3DTextureConnectivity; } 00898 Texture * RetObject3DTextureEllipsoidInfluence () { return m_3DTextureEllipsoidInfluence; } 00899 Texture * RetObject3DTextureCollisionDetection () { return m_3DTextureCollisionDetection; } 00900 Texture * RetObject3DTextureOffsetValues () { return m_3DTextureOffsetValues; } 00901 // 00902 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00903 Texture * RetObject3DTextureGradient () { return m_3DTextureGradient; } 00904 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00905 //------------------------------------------- 00906 // Get OpenGL Texture Names 00907 GLuint Get3DTextureHomePosition () 00908 { 00909 if ( !m_3DTextureHomePosition ) return NULL; 00910 return m_3DTextureHomePosition->GetTexture(0); 00911 } 00912 GLuint Get3DTexturePosition () 00913 { 00914 if ( !m_3DTexturePosition ) return NULL; 00915 return m_3DTexturePosition->GetTexture(0); 00916 } 00917 GLuint Get3DTextureConnectivity () 00918 { 00919 if ( !m_3DTextureConnectivity ) return NULL; 00920 return m_3DTextureConnectivity->GetTexture(0); 00921 } 00922 GLuint Get3DTextureEllipsoidInfluence () 00923 { 00924 if ( !m_3DTextureEllipsoidInfluence ) return NULL; 00925 return m_3DTextureEllipsoidInfluence->GetTexture(0); 00926 } 00927 GLuint Get3DTextureCollisionDetection () 00928 { 00929 if ( !m_3DTextureCollisionDetection ) return NULL; 00930 return m_3DTextureCollisionDetection->GetTexture(0); 00931 } 00932 GLuint Get3DTextureOffsetValues () 00933 { 00934 if ( !m_3DTextureOffsetValues ) return NULL; 00935 return m_3DTextureOffsetValues->GetTexture(0); 00936 } 00937 // 00938 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00939 GLuint Get3DTextureGradient () 00940 { 00941 if ( !m_3DTextureGradient ) return NULL; 00942 return m_3DTextureGradient->GetTexture(0); 00943 } 00944 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 00945 //------------------------------------------- 00946 // Check Available Visualizations 00947 bool IsVisualizedByRTGenMeshAvailable () const { 00948 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 00949 if ( m_Visualization_RTGenMesh ) return true; 00950 #endif 00951 return false; 00952 } 00953 bool IsVisualizedBy3DTextureAvailable () const { 00954 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00955 if ( m_Visualization_3DTexture ) return true; 00956 #endif 00957 return false; 00958 } 00959 00960 // Not Implemented Yet! 00961 //bool IsVisualizedByRayCastingAvailable () const { 00962 // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 00963 // if ( m_Visualization_RayCasting ) return true; 00964 // #endif 00965 // return false; 00966 //} 00967 00968 // Not Implemented Yet! 00969 //bool IsVisualizedByMeshAvailable () const { 00970 // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 00971 // if ( m_Visualization_Mesh ) return true; 00972 // #endif 00973 // return false; 00974 //} 00975 //--------------------------------------------------------------- 00976 //=============================================================== 00977 // Get Fns for Visualization by 3D Texture 00978 //--------------------------------------------------------------- 00979 GLuint Get3DTextureVisualization () 00980 { 00981 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00982 if ( !m_3DTextureVisualization ) return NULL; 00983 return m_3DTextureVisualization->GetTexture(0); 00984 #else 00985 return NULL; 00986 #endif 00987 } 00988 GLuint Get1DTextureTransferFnLUT () 00989 { 00990 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 00991 if ( !m_Visualization_3DTexture ) return NULL; 00992 return m_Visualization_3DTexture->Get1DTextureTransferFnLUT(); 00993 #else 00994 return NULL; 00995 #endif 00996 } 00997 //--------------------------------------------------------------- 00998 //=============================================================== 00999 // Get/Set Fns for Visualization by Real-Time Generate Mesh 01000 //--------------------------------------------------------------- 01001 bool GetRTGenMesh_MCUseGlobalInterpolationValue () const { 01002 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01003 if ( m_Visualization_RTGenMesh ) { 01004 return m_Visualization_RTGenMesh->GetUseGlobalInterpolationValue(); 01005 } 01006 #endif 01007 return false; 01008 } 01009 void SetRTGenMesh_MCUseGlobalInterpolationValue ( bool b ) { 01010 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01011 if ( m_Visualization_RTGenMesh ) { 01012 m_Visualization_RTGenMesh->SetUseGlobalInterpolationValue( b ); 01013 } 01014 #endif 01015 } 01022 T GetRTGenMesh_MCGlobalInterpolationValue () const { 01023 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01024 if ( m_Visualization_RTGenMesh ) { 01025 return m_Visualization_RTGenMesh->GetGlobalInterpolationValue(); 01026 } 01027 #endif 01028 return -1; 01029 } 01035 void SetRTGenMesh_MCGlobalInterpolationValue ( T val ) { 01036 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01037 if ( m_Visualization_RTGenMesh ) { 01038 m_Visualization_RTGenMesh->SetGlobalInterpolationValue( val ); 01039 } 01040 #endif 01041 } 01045 bool GetRTGenMesh_StatusDrawnWithPNTriangle () const { 01046 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01047 if ( m_Visualization_RTGenMesh ) { 01048 return m_Visualization_RTGenMesh->GetStatusDrawnWithPNTriangle(); 01049 } 01050 #endif 01051 return false; 01052 } 01056 void SetRTGenMesh_StatusDrawnWithPNTriangle ( bool b ) { 01057 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01058 if ( m_Visualization_RTGenMesh ) { 01059 m_Visualization_RTGenMesh->SetStatusDrawnWithPNTriangle( b ); 01060 } 01061 #endif 01062 } 01066 int GetRTGenMesh_PNTriangleSmoothness () const { 01067 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01068 if ( m_Visualization_RTGenMesh ) { 01069 return m_Visualization_RTGenMesh->GetPNTriangleSmoothness(); 01070 } 01071 #endif 01072 return -1; 01073 } 01077 void SetRTGenMesh_PNTriangleSmoothness ( int i ) { 01078 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01079 if ( m_Visualization_RTGenMesh ) { 01080 m_Visualization_RTGenMesh->SetPNTriangleSmoothness( i ); 01081 } 01082 #endif 01083 } 01087 void SetRTGenMesh_3DTexture ( GLuint i ) { 01088 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01089 if ( m_Visualization_RTGenMesh ) { 01090 m_Visualization_RTGenMesh->Set3DTexture( i ); 01091 } 01092 #endif 01093 } 01097 GLuint GetRTGenMesh_3DTexture () { 01098 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01099 if ( m_Visualization_RTGenMesh ) { 01100 return m_Visualization_RTGenMesh->Get3DTexture(); 01101 } 01102 #else 01103 return 0; 01104 #endif 01105 } 01106 //--------------------------------------------------------------- 01107 protected: 01108 //--------------------------------------------------------------- 01109 Texture * SetupA3DTexture ( 01110 GLenum target, 01111 GLint level, 01112 GLint internalFormat, 01113 GLsizei width, 01114 GLsizei height, 01115 GLsizei depth, 01116 GLint border, 01117 GLenum pixelFormat, 01118 GLenum dataType, 01119 //----------------------------- 01120 GLvoid * texels, // texel data 01121 //----------------------------- 01122 unsigned short numOfTextures, // number of 3D textures 01123 //----------------------------- 01124 GLint magFilter, 01125 GLint minFilter, 01126 GLint wrapS, 01127 GLint wrapT, 01128 GLint wrapR 01129 ); 01130 //--------------------------------------------------------------- 01137 #ifdef TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 01138 Texture * m_3DTextureGradient; // 1 texture: [0] -- for gradients 01139 #endif // TAPs_MODEL_DEFORMABLE_USE_GRADIENT_TEXTURE 01140 01148 Texture * m_3DTextureHomePosition; // 1 texture: [0] -- original position (for home spring / reset) 01149 01156 Texture * m_3DTexturePosition; // 2 textures: [0] -- current position 01157 // [1] -- next position 01158 // if Verlet integration, addition texture: [2] -- prev position 01159 01166 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01167 GLuint * m_gluipNameTextureVelocity; 01168 GLuint * m_gluipNameTextureVelocityNext; 01169 #endif 01170 //--------------------------------------------------------------- 01179 Texture * m_3DTextureConnectivity; // 2 textures: [0] -- current position 01180 // [1] -- update position 01181 //------------------------------------------- 01195 Texture * m_3DTextureEllipsoidInfluence; // Ellipsoid Influence Volume 01196 //------------------------------------------- 01204 Texture * m_3DTextureCollisionDetection; 01205 //------------------------------------------- 01216 Texture * m_3DTextureOffsetValues; 01217 //--------------------------------------------------------------- 01218 //=============================================================== 01219 // Data Members for Visualization 01220 //--------------------------------------------------------------- 01221 // 01222 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RT_GEN_MESH 01223 protected: 01224 ModelDeformableGLSL_Visualization_RTGenMesh<T> * m_Visualization_RTGenMesh; 01225 public: 01226 ModelDeformableGLSL_Visualization_RTGenMesh<T> * const RetVisualRTGenMesh () 01227 { return m_Visualization_RTGenMesh; } 01228 protected: 01229 #endif 01230 // 01231 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_3D_TEXTURE 01232 ModelDeformableGLSL_Visualization_3DTexture<T> * m_Visualization_3DTexture; 01233 public: 01234 ModelDeformableGLSL_Visualization_3DTexture<T> * const RetVisual3DTexture () 01235 { return m_Visualization_3DTexture; } 01236 protected: 01237 #endif 01238 // 01239 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_RAY_CASTING 01240 ModelDeformableGLSL_Visualization_RayCasting<T> * m_Visualization_RayCasting; 01241 public: 01242 ModelDeformableGLSL_Visualization_RayCasting<T> * const RetVisualRayCasting () 01243 { return m_Visualization_RayCasting; } 01244 protected: 01245 #endif 01246 // 01247 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VISUALIZATION_MESH 01248 ModelDeformableGLSL_Visualization_Mesh<T> * m_Visualization_Mesh; 01249 public: 01250 ModelDeformableGLSL_Visualization_Mesh<T> * const RetVisualMesh () 01251 { return m_Visualization_Mesh; } 01252 protected: 01253 #endif 01254 // 01255 //--------------------------------------------------------------- 01256 // Helper Fn(s) 01257 void DefaultVisualization (); 01258 void ClearVisualization (); 01259 int SetupVisualization ( 01260 enum GridGenerator<T>::VertexFlag *** pFlagDataForXYZVoxels 01261 ); 01262 //--------------------------------------------------------------- 01263 //=============================================================== 01264 //--------------------------------------------------------------- 01269 int CONNECTION_INDEX_POSITION[27]; // see InitConnectionConstants function 01270 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01271 int CONNECTION_INDEX_CONNECTIVITY[27]; // see InitConnectionConstants function 01272 #endif 01273 //------------------------------------------- 01274 // Identification Numbers (for front, center, and back planes) 01275 // -------------------------------- 01276 // | FRONT CENTER BACK | 01277 // | 00 01 02 09 10 11 18 19 20 | 01278 // | 03 04 05 12 13 14 21 22 23 | 01279 // | 06 07 08 15 16 17 24 25 26 | 01280 // -------------------------------- 01281 int m_piConnectionPattern[27]; // set #13 to not connected, i.e. zero. 01282 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01283 int m_piConnectionPatternToTextureConnectivity[27]; // set #13 to not connected, i.e. zero. 01284 #endif 01285 static enum ConnectivityPattern { 01286 FULL_ONE_RING, 01287 DUMMY 01288 }; 01289 01290 //--------------------------------------------------------------- 01291 // Swap Textures 01292 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 01293 inline void SwapPositionTextures () 01294 { 01295 // Positions 01296 // +--> previous --> current --> next -->+ 01297 // | | 01298 // +<------------------------------------+ 01299 m_3DTexturePosition->NextOfCircularBuffer(); 01300 } 01301 inline void SwapConnectivityTextures () 01302 { 01303 // Connectivity 01304 // +--> current --> next -->+ 01305 // | | 01306 // +<-----------------------+ 01307 m_3DTextureConnectivity->NextOfCircularBuffer(); 01308 } 01309 #endif 01310 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01311 inline void SwapPositionTextures () 01312 { 01313 // Swap Positions 01314 // GLuint * temp = m_gluipNameTexturePosition; 01315 // m_gluipNameTexturePosition = m_gluipNameTexturePositionNext; 01316 // m_gluipNameTexturePositionNext = temp; 01317 // Swap Velocities 01318 // temp = m_gluipNameTextureVelocity; 01319 // m_gluipNameTextureVelocity = m_gluipNameTextureVelocityNext; 01320 // m_gluipNameTextureVelocityNext = temp; 01321 } 01322 #endif 01323 01324 //========================================================================= 01325 // CPU 01326 //------------------------------------------------------------------------- 01327 // GLfloat Pointers for setting up the deformable model on GPU 01343 GLfloat * m_glpTexelForVertexPos; // currently only set to GLfloat 01344 //GLvoid * m_glpTexelForVertexPos; 01345 //----------------------------------------------------- 01346 // Represented as Colors (RGBA) for 2D textures of original data 01347 GLfloat * m_glpTexelForObjectOrigData; // currently only set to GLfloat 01348 //--------------------------------------------------------------- 01349 //------------------------------------------------------------------------- 01350 //========================================================================= 01351 01352 //------------------------------------------------------------------------- 01353 // Vendor & Card Specific 01354 /* 01355 class IC_InfoGPU { 01356 public: 01357 //InfoGPU () {} 01358 //~InfoGPU () {} 01359 static char const * getVendor () { 01360 return (char const *) glGetString( GL_VENDOR ); 01361 } 01362 static char const * getRenderer () { 01363 return (char const *) glGetString( GL_RENDERER ); 01364 } 01365 static char const * getGLVersion () { 01366 return (char const *) glGetString( GL_VERSION ); 01367 } 01368 static char const * getGLSLVersion () { 01369 return (char const *) glGetString( GL_SHADING_LANGUAGE_VERSION ); 01370 } 01371 static char const * getGLExtensions () { 01372 return (char const *) glGetString( GL_EXTENSIONS ); 01373 } 01374 }; 01375 //*/ 01376 int m_iGPUInfo; // 0 = Unspecify, 1 = ATI, 2 = NVIDIA 01377 bool m_bSupportExtension_NV_vertex_program3; 01378 //------------------------------------------------------------------------- 01379 01380 //========================================================================= 01381 // For Initializations & Setups 01382 //------------------------------------------------------------------------- 01389 bool Setup3DTexturesForSimulation ( 01390 int resolutionX, int resolutionY, int resolutionZ, 01391 T **** ptElementPosition, 01392 enum GridGenerator<T>::VertexFlag *** pcElementFlag, 01393 T **** ptElementVertexInterpolation = NULL, 01394 T tPressureValue = 1.0 01395 ); 01396 //------------------------------------------- 01402 bool Setup3DTextureForConnectivities ( 01403 int resolutionX, int resolutionY, int resolutionZ, 01404 T **** ptElementPosition, 01405 enum GridGenerator<T>::VertexFlag *** pcElementFlag, 01406 enum ConnectivityPattern cp = FULL_ONE_RING 01407 ); 01408 //------------------------------------------- 01416 bool GenerateBufferObjects (); 01417 //------------------------------------------- 01424 int SetupBuffersAndShaders (); 01425 //------------------------------------------- 01432 void UpdateParametersForShaders () { 01433 //----------------------------- 01434 // Update Parameters for GLSL Shaders 01435 UpdateParametersForSimStep(); 01436 UpdateParametersForRelaxationConstraint(); 01437 UpdateParametersForCollisionDetection(); 01438 UpdateParametersForCDTooltipSphereCylinder(); 01439 UpdateParametersForRemoveElementsByCollision(); 01440 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01441 UpdateParametersForRemoveConnectionsByCollision(); 01442 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01443 UpdateParametersForConnectivity(); 01444 // Grabbing 01445 UpdateParametersForCollisionDetectionForGrabbing(); 01446 //----------------------------- 01447 } 01448 //------------------------------------------- 01452 void SetupTextureCoordinateValues ( 01453 T & coordS, T & coordT, T & coordP, 01454 int width, int height, int depth 01455 ); 01456 //------------------------------------------- 01462 public: 01463 Vector3<T> GetTexCoordOffsetForPosition () { 01464 return Vector3<T>( 01465 offsetCoordSPosition, 01466 offsetCoordTPosition, 01467 offsetCoordRPosition ); 01468 } 01469 Vector3<T> GetTexCoordOffsetForConnection () { 01470 return Vector3<T>( 01471 offsetCoordSConnection, 01472 offsetCoordTConnection, 01473 offsetCoordRConnection ); 01474 } 01475 protected: 01476 T offsetCoordSPosition, offsetCoordTPosition, offsetCoordRPosition; 01477 T offsetCoordSConnection, offsetCoordTConnection, offsetCoordRConnection; 01478 //------------------------------------------- 01484 void SetupConnectivityPattern ( 01485 enum ConnectivityPattern CP = FULL_ONE_RING ); 01486 //------------------------------------------- 01492 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01493 void SetupAllConnections ( 01494 int resolutionX, int resolutionY, int resolutionZ, // I/Ps: 01495 GLfloat const * pVertexPosAndFlag, // I/Ps: pointer to vertex pos + flag 01496 int const connectionPattern[27], // I/Ps: connection pattern to neighbor voxel 01497 int threshold, // I/Ps: threshold value 01498 GLfloat * connectivityData // O/Ps: connectivity data 01499 ); 01500 #endif 01501 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01502 void SetupAllConnections ( 01503 int resolutionX, int resolutionY, int resolutionZ, // I/Ps: 01504 GLfloat const * pVertexPosAndFlag, // I/Ps: pointer to vertex pos + flag 01505 int const connectionPattern[27], // I/Ps: connection pattern to neighbor voxel 01506 int threshold, // I/Ps: threshold value 01507 GLubyte * connectivityData // O/Ps: connectivity data 01508 ); 01509 #endif 01510 //------------------------------------------- 01516 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01517 void SetupConnectionsOfOneElementNotOnBoundary ( 01518 int resolutionX, int resolutionY, // I/Ps: texture width & height 01519 GLfloat const * pVertexPosAndFlag, // I/Ps: pointer to vertex pos + flag 01520 int const connectionPattern[27], // I/Ps: connection pattern to neighbor voxel 01521 int x, int y, int z, // I/Ps: element location 01522 int const connectionTexture[27], // I/Ps: connection index to textures 01523 int threshold, // I/Ps: threshold value 01524 GLfloat * connectivityData // O/Ps: connectivity data 01525 ); 01526 #endif 01527 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01528 void SetupConnectionsOfOneElementNotOnBoundary ( 01529 int resolutionX, int resolutionY, // I/Ps: texture width & height 01530 GLfloat const * pVertexPosAndFlag, // I/Ps: pointer to vertex pos + flag 01531 int const connectionPattern[27], // I/Ps: connection pattern to neighbor voxel 01532 int x, int y, int z, // I/Ps: element location 01533 int threshold, // I/Ps: threshold value 01534 GLubyte * connectivityData // O/Ps: connectivity data 01535 ); 01536 #endif 01537 //------------------------------------------- 01543 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01544 void SetupConnectionsOfOneElementOnBoundary ( 01545 int resolutionX, int resolutionY, int resolutionZ, // I/Ps: texture width & height 01546 GLfloat const * pVertexPosAndFlag, // I/Ps: pointer to vertex pos + flag 01547 int const connectionPattern[27], // I/Ps: connection pattern to neighbor voxel 01548 int x, int y, int z, // I/Ps: element location 01549 int const connectionTexture[27], // I/Ps: connection index to textures 01550 int threshold, // I/Ps: threshold value 01551 GLfloat * connectivityData // O/Ps: connectivity data 01552 ); 01553 #endif 01554 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01555 void SetupConnectionsOfOneElementOnBoundary ( 01556 int resolutionX, int resolutionY, int resolutionZ, // I/Ps: texture width & height 01557 GLfloat const * pVertexPosAndFlag, // I/Ps: pointer to vertex pos + flag 01558 int const connectionPattern[27], // I/Ps: connection pattern to neighbor voxel 01559 int x, int y, int z, // I/Ps: element location 01560 int threshold, // I/Ps: threshold value 01561 GLubyte * connectivityData // O/Ps: connectivity data 01562 ); 01563 #endif 01564 //------------------------------------------------------------------------- 01565 //========================================================================= 01566 public: 01567 //========================================================================= 01568 // For Simulation by GPU 01569 //------------------------------------------------------------------------- 01570 // Model's Element Parameters 01571 T GetElementMass () const { return m_tElementMass; } 01572 void SetElementMass ( T mass ) 01573 { assert( mass > 0 ); 01574 m_tElementMass = mass; 01575 UpdateParametersForSimStep(); 01576 } 01577 //----------------------------------------------------- 01581 T GetElementApproxRadius () const { return m_tElementApproxRadius; } 01582 void SetElementApproxRadius ( T tVal ) 01583 { assert( tVal > 0 ); 01584 m_tElementApproxRadius = tVal; 01585 UpdateParametersForShaders(); 01586 } 01587 //----------------------------------------------------- 01588 // Simulation Parameters 01589 T GetSimTimeStepInSecUnit () const { return m_tTimeStep; } 01590 void SetSimTimeStepInSecUnit ( T sec ) 01591 { assert( sec >= 0 ); 01592 m_tTimeStep = sec; 01593 UpdateParametersForSimStep(); 01594 } 01595 T GetSimThreshold () const { return m_tSimThreshold; } 01596 void SetSimThreshold ( T threshold ) 01597 { assert( threshold >= 0 ); 01598 m_tSimThreshold = threshold; 01599 UpdateParametersForSimStep(); 01600 //UpdateSimStepParameters(); 01601 UpdateRelaxationConstraintParameters(); 01602 } 01603 unsigned short GetSimFramesPerPulsation () const { return m_usFramesPerPulsation; } 01604 void SetSimFramesPerPulsation ( unsigned short fpp ) 01605 { assert( fpp >= 0 ); 01606 m_usFramesPerPulsation = fpp; 01607 //UpdateParametersForSimStep(); 01608 } 01609 T GetMaxRelaxationConstraint () const { return m_tMaxRelaxation; } 01610 T GetMinRelaxationConstraint () const { return m_tMinRelaxation; } 01611 void SetMaxRelaxationConstraint ( T t ) 01612 { assert( t >= 1.0 ); 01613 m_tMaxRelaxation = t; 01614 UpdateParametersForRelaxationConstraint(); 01615 } 01616 void SetMinRelaxationConstraint ( T t ) 01617 { assert( 0 <= t && t <= 1.0 ); 01618 m_tMinRelaxation = t; 01619 UpdateParametersForRelaxationConstraint(); 01620 } 01621 //----------------------------------------------------- 01622 // Simulation Functions 01623 void SimSteps_ODE_Relax_Collide ( int iSteps ) 01624 { assert( iSteps >= 0 ); 01625 for ( int i = 0; i < iSteps; ++i ) { 01626 SimStep(); 01627 RelaxationConstraint(); 01628 CollisionDetection(); 01629 } 01630 } 01631 void SimSteps_ODE_Collide ( int iSteps ) 01632 { assert( iSteps >= 0 ); 01633 for ( int i = 0; i < iSteps; ++i ) { 01634 SimStep(); 01635 CollisionDetection(); 01636 } 01637 } 01638 void SimSteps_Relax_Collide ( int iSteps ) 01639 { assert( iSteps >= 0 ); 01640 for ( int i = 0; i < iSteps; ++i ) { 01641 RelaxationConstraint(); 01642 CollisionDetection(); 01643 } 01644 } 01645 void SimSteps_ODE_Relax ( int iSteps ) 01646 { assert( iSteps >= 0 ); 01647 for ( int i = 0; i < iSteps; ++i ) { 01648 SimStep(); 01649 RelaxationConstraint(); 01650 } 01651 } 01652 void SimSteps_ODE ( int iSteps ) 01653 { assert( iSteps >= 0 ); 01654 for ( int i = 0; i < iSteps; ++i ) { 01655 SimStep(); 01656 } 01657 } 01658 void SimSteps_Relax ( int iSteps ) 01659 { assert( iSteps >= 0 ); 01660 for ( int i = 0; i < iSteps; ++i ) { 01661 RelaxationConstraint(); 01662 } 01663 } 01664 void SimSteps_Collide ( int iSteps ) 01665 { assert( iSteps >= 0 ); 01666 for ( int i = 0; i < iSteps; ++i ) { 01667 CollisionDetection(); 01668 } 01669 } 01670 //----------------------------------------------------- 01671 void SimStep (); // ODE solver on mass-spring system 01672 void RelaxationConstraint (); // Relaxation constraint on mass-spring system 01673 Vector3<T> CollisionDetection (); // Collision Detection on elements of mass-spring system 01674 Vector3<T> RemoveElementsByCollision (); 01675 void UpdateConnectivity (); 01676 private: 01677 //------------------------------------------- 01685 void UpdateParametersForSimStep (); 01686 void UpdateParametersForRelaxationConstraint (); 01687 void UpdateParametersForCollisionDetection (); 01688 void UpdateParametersForCDTooltipSphereCylinder (); 01689 void UpdateParametersForRemoveElementsByCollision (); 01690 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01691 void UpdateParametersForRemoveConnectionsByCollision (); 01692 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01693 void UpdateParametersForConnectivity (); 01694 // Grabbing 01695 void UpdateParametersForCollisionDetectionForGrabbing(); 01696 01697 //void PrioritizeTextures (); 01698 //------------------------------------------- 01699 // Simulation State(s) 01700 bool m_bIsCollided; 01701 bool GetCollisionStatus () const { return m_bIsCollided; } 01702 void UpdateCollisionStatus ( T val ) 01703 { 01704 if ( val > Math<T>::ZERO ) m_bIsCollided = true; 01705 else m_bIsCollided = false; 01706 } 01707 //------------------------------------------- 01708 public: 01709 //------------------------------------------- 01714 Vector3<T> CollisionDetection ( 01715 int NumOfTooltips, GLfloat Tooltips[8], // Max two Tooltips (2*4) 01716 int NumOfSpheres, GLfloat CollidableSpheres[32] // Max eight Spheres (8*4) 01717 ); 01718 Vector3<T> CollisionDetectionTooltipSphereCylinder ( 01719 int NumOfTooltips, GLfloat Tooltips[8], // # of tools and tooltip sphere (4 (xyz and raidus) per tool) 01720 GLfloat fCylLowPt, GLfloat fCylHighPt, GLfloat fCylRadius, // cylinder low pt, high pt, & radius 01721 GLfloat transformMatrix[16], // | 00 04 08 12 | 01722 // | 01 05 09 13 | 01723 // | 02 06 10 14 | 01724 // | 03 07 11 15 | 01725 GLfloat invTransformMatrix[16] // | 00 04 08 12 | 01726 // | 01 05 09 13 | 01727 // | 02 06 10 14 | 01728 // | 03 07 11 15 | 01729 ); 01730 Vector3<T> CollisionDetectionForGrabbingStartOrEnd ( 01731 int NumOfTooltips, GLfloat Tooltips[8], // Max two Tooltips (2*4) 01732 bool bStart, // If true, start grabbing. If false, release grabbing. 01733 int graspID = 1 // must be greater than one 01734 ); 01735 Vector3<T> CollisionDetectionForGrabbingMove ( 01736 int NumOfTooltips, GLfloat Tooltips[8], // Max two Tooltips (2*4) 01737 int graspID = 1 // must be greater than one 01738 ); 01739 //void UpdateParametersForCollisionDetection ( ... ); 01740 01741 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01742 //------------------------------------------- 01757 Vector3<T> RemoveConnectionsByCollision ( 01758 GLfloat width, GLfloat height, // rectangle width and height 01759 01760 GLfloat transformMatrix[16], // | 00 04 08 12 | 01761 // | 01 05 09 13 | 01762 // | 02 06 10 14 | 01763 // | 03 07 11 15 | 01764 GLfloat invTransformMatrix[16] // | 00 04 08 12 | 01765 01766 // | 01 05 09 13 | 01767 // | 02 06 10 14 | 01768 // | 03 07 11 15 | 01769 ); 01770 #endif // TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01771 01772 //------------------------------------------- 01777 Vector3<T> RemoveElementsByCollision ( 01778 int NumOfTooltips, GLfloat Tooltips[8], // Max two Tooltips (2*4) 01779 int NumOfSpheres, GLfloat CollidableSpheres[32] // Max eight Spheres (8*4) 01780 ); 01781 //void UpdateRemoveElementsByCollisionParameters ( ... ); 01782 //------------------------------------------------------------------------- 01783 // DEBUG 01784 // Print out texture data using a Buffer object and a Framebuffer object 01785 void DebugTextureData ( 01786 GLsizei width, 01787 GLsizei height, 01788 GLsizei depth, 01789 GLint iComponents, 01790 GLenum target, 01791 GLenum pixelFormat, 01792 GLenum dataType, 01793 GLuint pTextureObject 01794 ); 01795 // Print out texture data using a Buffer object and a Framebuffer object 01796 void DebugTextureDataInConnectivityFormat ( 01797 GLsizei width, 01798 GLsizei height, 01799 GLsizei depth, 01800 GLint iComponents, 01801 GLenum target, 01802 GLenum pixelFormat, 01803 GLenum dataType, 01804 GLuint pTextureObject 01805 ); 01806 //------------------------------------------------------------------------- 01807 //========================================================================= 01808 protected: 01809 //========================================================================= 01810 // For Simulation 01811 //------------------------------------------------------------------------- 01812 T m_tSimThreshold; // simulation threshold (either 150.0 or 250.0) 01813 // Threshold of 150.0 will include all elements from RIGHT_OUTSIDE_MODEL 01814 // Threshold of 250.0 will not include all elements from RIGHT_OUTSIDE_MODEL 01815 //------------------------------------------- 01816 T m_tTimeStep; // time step (dt) 01817 //------------------------------------------- 01818 unsigned short m_usFramesPerPulsation; // pulsation (frames/pulsation) 01819 //------------------------------------------- 01820 T m_tMaxRelaxation; // Max Relaxation Constraint [1,inf) 01821 T m_tMinRelaxation; // Min Relaxation Constraint [0,1] 01822 //----------------------------------------------------- 01823 // Element's Parameters 01824 T m_tElementMass; // the mass of each element 01825 T m_tElementApproxRadius; // the approx radius of each element 01826 // (avg of the sum of x, y, & z dimensions divided by two) 01827 //------------------------------------------------------------------------- 01832 public: 01833 typedef SpringPropertiesForDefModel<T> SpringProp; 01834 SpringProp SPRING_PROP; 01835 T GetSpringRestLength ( enum SpringProp::CONNECT springSelection ) 01836 { 01837 return SPRING_PROP.GetSpringRestLength( springSelection ); 01838 } 01839 T GetSpringStiffness ( enum SpringProp::CONNECT springSelection ) 01840 { 01841 return SPRING_PROP.GetSpringStiffness( springSelection ); 01842 } 01843 void SetSpringRestLength ( enum SpringProp::CONNECT springSelection, T val ) 01844 { 01845 SPRING_PROP.SetSpringRestLength( springSelection, val ); 01846 UpdateParametersForSimStep(); 01847 UpdateParametersForRelaxationConstraint(); 01848 } 01849 void SetSpringStiffness ( enum SpringProp::CONNECT springSelection, T val ) 01850 { 01851 SPRING_PROP.SetSpringStiffness( springSelection, val ); 01852 UpdateParametersForSimStep(); 01853 } 01854 //----------------------------------------------------- 01855 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01856 T GetSpringDamper ( enum SpringProp::CONNECT springSelection ) 01857 { 01858 return SPRING_PROP.GetSpringDamper( springSelection ); 01859 } 01860 void SetSpringDamper ( enum SpringProp::CONNECT springSelection, T val ) 01861 { 01862 SPRING_PROP.SetSpringDamper( springSelection, val ); 01863 UpdateParametersForSimStep(); 01864 } 01865 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01866 //----------------------------------------------------- 01867 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 01868 T GetSpringDamper () 01869 { 01870 return SPRING_PROP.GetSpringDamper(); 01871 } 01872 void SetSpringDamper ( T val ) 01873 { 01874 SPRING_PROP.SetSpringDamper( val ); 01875 UpdateParametersForSimStep(); 01876 //UpdateSimStepParameters(); 01877 } 01878 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_VERLET_INTEGRATION 01879 //----------------------------------------------------- 01880 // Special Useful Get/Set Fns 01881 T GetHomeSpringStiffness () 01882 { 01883 return SPRING_PROP.GetSpringStiffness( SpringProp::CONNECT::HOME ); 01884 } 01885 void SetHomeSpringStiffness ( T val ) 01886 { 01887 SPRING_PROP.SetSpringStiffness( SpringProp::CONNECT::HOME, val ); 01888 UpdateParametersForSimStep(); 01889 //UpdateSimStepParameters(); 01890 } 01891 //------------------------------------------------------------------------- 01892 // Helper Fns 01893 public: 01894 virtual std::string Info () const; 01895 //------------------------------------------------------------------------- 01896 virtual void InfoConnectionProperties ( std::string & addToStr, 01897 enum SpringProp::CONNECT connect, int maxNumConnections = 26 ) const { 01898 char cStr[80]; 01899 if ( connect <= maxNumConnections ) { 01900 #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01901 sprintf( cStr, " %g, %g, %g", 01902 SPRING_PROP.REST_LENGTH[ connect ], 01903 SPRING_PROP.STIFFNESS[ connect ], 01904 SPRING_PROP.DAMPER[ connect ] 01905 ); 01906 #else // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01907 sprintf( cStr, " %g, %g", 01908 SPRING_PROP.REST_LENGTH[ connect ], 01909 SPRING_PROP.STIFFNESS[ connect ] 01910 ); 01911 #endif // #ifdef TAPs_MODEL_DEFORMABLE_GLSL_EXPLICIT_EULER_INTEGRATION 01912 addToStr += cStr; 01913 } 01914 } 01915 //------------------------------------------------------------------------- 01916 //========================================================================= 01917 //------------------------------------------------------------------------- 01918 }; // CLASS END: ModelDeformableGLSL ******************************************* 01919 //============================================================================= 01920 END_NAMESPACE_TAPs__OpenGL 01921 01922 //------------------------------------------------------------------- 01923 // Separate cpp file for one texel for connectivity texture 01924 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_ONE 01925 //#if !defined( TAPs_USE_EXPORT ) 01926 #include "TAPsModelDeformableGLSL_ConnectivityOne.cpp" 01927 //#endif 01928 #endif 01929 //------------------------------------------------------------------- 01930 // Separate cpp file for nine texels for connectivity texture 01931 #ifdef TAPs_MODEL_DEFORMABLE_USE_TEXTURE_CONNECTIVITY_3X3 01932 //#if !defined( TAPs_USE_EXPORT ) 01933 #include "TAPsModelDeformableGLSL_Connectivity3x3.cpp" 01934 //#endif 01935 #endif 01936 //------------------------------------------------------------------- 01937 01938 //----------------------------------------------------------------------------- 01939 // Include definition if TAPs_USE_EXPORT is not defined 01940 //#if !defined( TAPs_USE_EXPORT ) 01941 #include "TAPsModelDeformableGLSL.cpp" 01942 //#endif 01943 //----------------------------------------------------------------------------- 01944 #endif 01945 //34567890123456789012345678901234567890123456789012345678901234567890123456789 01946 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----