TAPs 0.7.7.3
TAPsModelDefBasedOnFEMTet.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsModelDefBasedOnFEMTet.cpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (03/16/2010)
00009 UPDATE          (12/05/2010)
00010 ******************************************************************************/
00011 #include "TAPsModelDefBasedOnFEMTet.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
00017 //=============================================================================
00018 //-----------------------------------------------------------------------------
00019 template <typename T, typename DATA>
00020 ModelDefBasedOnFEMTet<T,DATA>::ModelDefBasedOnFEMTet ( std::string const & modelFile )
00021     : ModelDefBasedOnFEM<T,DATA>( modelFile )
00022 {}
00023 //-----------------------------------------------------------------------------
00024 //template <typename T, typename DATA>
00025 //ModelDefBasedOnFEMTet<T,DATA>::ModelDefBasedOnFEMTet ( ModelDefBasedOnFEMTet<T,DATA> const &orig )
00026 //  :
00027 //{}
00028 //-----------------------------------------------------------------------------
00029 template <typename T, typename DATA>
00030 ModelDefBasedOnFEMTet<T,DATA>::~ModelDefBasedOnFEMTet ()
00031 {}
00032 //-----------------------------------------------------------------------------
00033 template <typename T, typename DATA>
00034 std::string ModelDefBasedOnFEMTet<T,DATA>::StrInfo () const
00035 {
00036     std::ostringstream ss;
00037     ss << "ModelDefBasedOnFEMTet<" << typeid(T).name() << ">";
00038     ss << "\n";
00039     return ss.str();
00040 }
00041 //-----------------------------------------------------------------------------
00042 //=============================================================================
00043 // Assignment Operator
00044 //-----------------------------------------------------------------------------
00045 //template <typename T, typename DATA>
00046 //inline ModelDefBasedOnFEMTet<T,DATA> & ModelDefBasedOnFEMTet<T,DATA>::operator= ( ModelDefBasedOnFEMTet<T,DATA> const &orig )
00047 //{ 
00048 //    return *this;
00049 //}
00050 //-----------------------------------------------------------------------------
00051 //=============================================================================
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 //-----------------------------------------------------------------------------
00062 template <typename T, typename DATA>
00063 bool ModelDefBasedOnFEMTet<T,DATA>::GenerateGridsWithDimension (
00064     T iGridWidth,       
00065     T iGridHeight,      
00066     T iGridDepth,       
00067     T   mass,           
00068     T   YoungsModulus,  
00069     T   PoissonsRatio,  
00070     bool bGenElementsInsideVolume   
00071 )
00072 {
00073     std::cout << __FILE__ << " (LINE#" << __LINE__ << ") NOT IMPLEMENTED YET!\n";
00074     return false;
00075 }
00076 
00077 
00078 //-----------------------------------------------------------------------------
00079 template <typename T, typename DATA>
00080 bool ModelDefBasedOnFEMTet<T,DATA>::GenerateGridsWithSize (
00081     int iNumOfXSlices,  
00082     int iNumOfYSlices,  
00083     int iNumOfZSlices,  
00084     T   mass,           
00085     T   YoungsModulus,  
00086     T   PoissonsRatio,  
00087     bool bGenElementsInsideVolume   
00088 )
00089 {
00090     if ( !m_pHEModel ) {
00091         return false;
00092     }
00093 
00094     // Generate grids
00095     //GridGenerator<T,DATA> GridGen;
00096     m_GridGen.SetModelUseToGenGrid( m_pHEModel );
00097     if ( m_GridGen.GenerateGridsWithSize( iNumOfXSlices, iNumOfYSlices, iNumOfZSlices ) ) {
00098         // Generate FEM mesh from the generated grids
00099         if ( GenerateMeshFromGridGenerator( m_GridGen, mass, YoungsModulus, PoissonsRatio, bGenElementsInsideVolume ) ) {
00100             // Clear the generated grids
00101             m_GridGen.DeleteGrids();
00102 
00103             // Set transformation support
00104             m_FEMMesh.SetTransformationSupportPointer( &(m_pHEModel->GetTransform()) );
00105 
00106             return true;
00107         }
00108         else {
00109             std::cout << "ModelDefBasedOnFEMTet<T,DATA>::GenerateGridsWithSize(...) FAILED to generate FEM mesh!\n";
00110             // Clear the generated grids
00111             m_GridGen.DeleteGrids();
00112             return false;
00113         }
00114     }
00115     else {
00116         std::cout << "ModelDefBasedOnFEMTet<T,DATA>::GenerateGridsWithSize(...) FAILED to generate grids!\n";
00117         return false;
00118     }
00119 }
00120 
00121 
00122 //-----------------------------------------------------------------------------
00123 template <typename T, typename DATA>
00124 bool ModelDefBasedOnFEMTet<T,DATA>::GenerateMeshFromGridGenerator (
00125     GridGenerator<T,DATA> & GridGen,    
00126     T   mass,                           
00127     T   YoungsModulus,                  
00128     T   PoissonsRatio,                  
00129     bool bGenElementsInsideVolume       
00130 )
00131 {
00132     if ( !m_pHEModel ) {
00133         return false;
00134     }
00135     if ( !GridGen.IsGridGenerated() ) {
00136         return false;
00137     }
00138 
00139     // Clear data
00140     // other data are clear by MeshTetrahedraGen function
00141     m_BaryCoords.clear();
00142     //m_ElementID.clear();
00143 
00144     // Use the static function of Meshexahedra Genetator to generate the hexahedral mesh from the grid generator
00145     //if ( !FEM::MeshTetrahedraGen<T,DATA>::MeshFromGridGenerator( m_FEMMesh, m_BaryCoords, m_ElementID, GridGen, mass, YoungsModulus, PoissonsRatio, bGenElementsInsideVolume ) ) {
00146     if ( !FEM::MeshTetrahedraGen<T,DATA>::MeshFromGridGenerator( m_FEMMesh, m_BaryCoords, GridGen, mass, YoungsModulus, PoissonsRatio, bGenElementsInsideVolume ) ) {
00147         return false;
00148     }
00149 
00150     // Set the link between HEVertex and FEM element
00151     // HEVertex'ID <--> FEM element location in the element list
00152     SetHEVertexIDToElementLocation();
00153 
00154     return true;
00155 }
00156 
00157 
00158 //-----------------------------------------------------------------------------
00159 //template <typename T, typename DATA>
00160 //bool ModelDefBasedOnFEMTet<T,DATA>::GenerateBaryCoordsFromGridGenerator ( GridGenerator<T,DATA> & GridGen )
00161 //{
00162 //  int C = GridGen.GetGridSizeX();
00163 //  int R = GridGen.GetGridSizeY();
00164 //  int D = GridGen.GetGridSizeZ();
00165 //
00166 //  // Set the size of the 2D vector data structure for the baracentric coordinates
00167 //  m_BaryCoords.resize( D*R*C );
00168 //
00169 //  return true;
00170 //}
00171 
00172 
00173 //-----------------------------------------------------------------------------
00174 template <typename T, typename DATA>
00175 void ModelDefBasedOnFEMTet<T,DATA>::AdvanceSimulationStatic ()
00176 {
00177     CDUnit().MoveAllGrabbedParts();
00178     m_FEMMesh.AdvanceSimulationStatic();
00179     UpdateSurfaceMesh();
00180 }
00181 
00182 //-----------------------------------------------------------------------------
00183 template <typename T, typename DATA>
00184 void ModelDefBasedOnFEMTet<T,DATA>::AdvanceSimulationStatic_woFixedDisplacementNodes ()
00185 {
00186     CDUnit().MoveAllGrabbedParts();
00187     m_FEMMesh.AdvanceSimulationStatic_woFixedDisplacementNodes();
00188     UpdateSurfaceMesh();
00189 }
00190 
00191 //-----------------------------------------------------------------------------
00192 #ifdef  TAPs_SIM_DYNAMIC_SYSTEM
00193 template <typename T, typename DATA>
00194 void ModelDefBasedOnFEMTet<T,DATA>::AdvanceSimulationDynamic ()
00195 {
00196     CDUnit().MoveAllGrabbedParts();
00197     m_FEMMesh.AdvanceSimulationDynamic();
00198     UpdateSurfaceMesh();
00199 }
00200 #endif//TAPs_SIM_DYNAMIC_SYSTEM
00201 
00202 //-----------------------------------------------------------------------------
00203 #ifdef  TAPs_SIM_DYNAMIC_SYSTEM
00204 template <typename T, typename DATA>
00205 void ModelDefBasedOnFEMTet<T,DATA>::AdvanceSimulationDynamic_woFixedDisplacementNodes ()
00206 {
00207     CDUnit().MoveAllGrabbedParts();
00208     m_FEMMesh.AdvanceSimulationDynamic_woFixedDisplacementNodes();
00209     UpdateSurfaceMesh();
00210 }
00211 #endif//TAPs_SIM_DYNAMIC_SYSTEM
00212 
00213 //-----------------------------------------------------------------------------
00214 template <typename T, typename DATA>
00215 void ModelDefBasedOnFEMTet<T,DATA>::UpdateSurfaceMesh ()
00216 {
00217     // Iterate all vertices of the surface mesh
00218     for ( unsigned int v = 0; v < m_BaryCoords.size(); ++v ) {
00219         m_BaryCoords[v].ComputeNewVertexLocation();
00220     }
00221 
00222     // Update all extra vertices
00223     TetBarycentricCoordsForVertexRef<T> * pTetBC;
00224     for ( unsigned int v = 0; v < m_SetOfExtraVertexCoords.size(); ++v ) {
00225         pTetBC = dynamic_cast< TetBarycentricCoordsForVertexRef<T>* >( m_SetOfExtraVertexCoords[v] );
00226         pTetBC->ComputeNewVertexLocation();
00227     }
00228 
00229     // Update BVH tree
00230     // The update of normals is not done by this function.
00231     // The update of normals must be done after this but before rendering.
00232     ModelDefBasedOnFEM<T,DATA>::UpdateSurfaceMesh();
00233 
00234     // Adjust the surface mesh, i.e. the vertices that is collided with another object.
00235     //CDUnit().AdjustSurfaceMeshByCDObjs();
00236 
00237     if ( m_CD.GetCollisionStatus() ) {
00238         m_CD.SetCollisionStatus( false );
00239     }
00240 }
00241 
00242 //-----------------------------------------------------------------------------
00243 template <typename T, typename DATA>
00244 void ModelDefBasedOnFEMTet<T,DATA>::SetHEVertexIDToElementLocation ()
00245 {
00246     if ( !m_pHEModel )  return;
00247 
00248     std::list< HEVertex<T> * > pVList;
00249     // Store all vertices for linking
00250     HEVertex<T> * V = m_pHEModel->GetVertexList()->Head();
00251     while ( V ) {
00252         pVList.push_back( &(*V) );
00253         V = V->Next();
00254     }
00255     
00256 
00257     //std::cout << __FILE__ << "\n";
00258 
00259     // Do the link
00260     int c = 0;
00261     for ( unsigned int i = 0; i < m_BaryCoords.size(); ++i ) {
00262         std::list< HEVertex<T> * >::iterator it = pVList.begin();
00263         while ( it != pVList.end() ) {
00264             if ( (void *)(m_BaryCoords[i].RetVertexPtr()) == (void *)((**it).RefToPosition()) ) {
00265                 //(**it).SetID( m_ElementID[i] );
00266                 (**it).SetID( m_BaryCoords[i].GetElementID() );
00267                 pVList.erase( it );
00268 
00269                 //std::cout << ++c << ": " << m_ElementID[i] << "\n";
00270 
00271                 break;
00272             }
00273             ++it;
00274         }
00275     }
00276 }
00277 
00278 //-----------------------------------------------------------------------------
00279 template <typename T, typename DATA>
00280 bool ModelDefBasedOnFEMTet<T,DATA>::InitCD ()
00281 {
00282     if ( ModelDefBasedOnFEM<T,DATA>::InitCD() ) {
00283         m_CD.Init( m_pHEModel, &m_FEMMesh );
00284         return true;
00285     }
00286     return false;
00287 }
00288 
00289 //-----------------------------------------------------------------------------
00290 template <typename T, typename DATA>
00291 HEVertex<T> * ModelDefBasedOnFEMTet<T,DATA>::AddExtraVertexInLocalSpace (
00292     Vector3<T> location,                    
00293     int elementID,                          
00294     FEM::Element<T> * elementPtr,           
00295     Vector3<unsigned int> gridLocations,    
00296     Vector3<T> coordinates                  
00297 )
00298 {
00299     PrtNotImplementedYet( "AddExtraVertexInLocalSpace" );
00300     return NULL;
00301 }
00302 
00303 //-----------------------------------------------------------------------------
00304 template <typename T, typename DATA>
00305 bool ModelDefBasedOnFEMTet<T,DATA>::FindElementThatContainsPointInLocalSpace (
00306     Vector3<T> const & point,               
00307     unsigned int & elementID,               
00308     Vector3<unsigned int> & gridLocations,  
00309     Vector3<T> & coordinates                
00310 )
00311 {
00312     PrtNotImplementedYet( "FindElementThatContainsPointInLocalSpace" );
00313     return false;
00314 }
00315 
00316 
00317 
00318 //=============================================================================
00319 #if defined(__gl_h_) || defined(__GL_H__)
00320 //-----------------------------------------------------------------------------
00321     template <typename T, typename DATA>
00322     void ModelDefBasedOnFEMTet<T,DATA>::DrawUndeformedFEMMesh ()
00323     {
00324         m_FEMMesh.DrawUndeformedMesh();
00325     }
00326 
00327     template <typename T, typename DATA>
00328     void ModelDefBasedOnFEMTet<T,DATA>::DrawDeformedFEMMesh ()
00329     {
00330         m_FEMMesh.DrawDeformedMesh();
00331     }
00332 
00333     template <typename T, typename DATA>
00334     void ModelDefBasedOnFEMTet<T,DATA>::DrawCollidedMeshParts ()
00335     {
00336         glPushMatrix();
00337         m_pHEModel->GetTransform().TransformByOpenGLForDrawing();
00338         for ( unsigned int i = 0; i < m_CD.RefToCollidedMeshParts().size(); ++i ) {
00339             m_CD.RefToCollidedMeshParts()[i].pHEVertex->Draw();
00340         }
00341         glPopMatrix();
00342     }
00343 //-----------------------------------------------------------------------------
00344 #endif // #if defined(__gl_h_) || defined(__GL_H__)
00345 //=============================================================================
00346 
00347 //=============================================================================
00348 END_NAMESPACE_TAPs
00349 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00350 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines