![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsModelDefBasedOnFEMTet_CD.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (04/15/2010) 00009 UPDATE (12/05/2010) 00010 ******************************************************************************/ 00011 #include "TAPsModelDefBasedOnFEMTet_CD.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__FEM 00017 //============================================================================= 00018 //----------------------------------------------------------------------------- 00019 template <typename T> 00020 ModelDefBasedOnFEMTet_CD<T>::ModelDefBasedOnFEMTet_CD () 00021 : ModelDefBasedOnFEM_CD() 00022 {} 00023 //----------------------------------------------------------------------------- 00024 //template <typename T> 00025 //ModelDefBasedOnFEMTet_CD<T>::ModelDefBasedOnFEMTet_CD ( ModelDefBasedOnFEMTet_CD<T> const &orig ) 00026 // : 00027 //{} 00028 //----------------------------------------------------------------------------- 00029 template <typename T> 00030 ModelDefBasedOnFEMTet_CD<T>::~ModelDefBasedOnFEMTet_CD () 00031 {} 00032 //----------------------------------------------------------------------------- 00033 template <typename T> 00034 std::string ModelDefBasedOnFEMTet_CD<T>::StrInfo () const 00035 { 00036 std::ostringstream ss; 00037 ss << "ModelDefBasedOnFEMTet_CD<" << typeid(T).name() << ">"; 00038 ss << "\n"; 00039 return ss.str(); 00040 } 00041 //----------------------------------------------------------------------------- 00042 //============================================================================= 00043 // Assignment Operator 00044 //----------------------------------------------------------------------------- 00045 //template <typename T> 00046 //inline ModelDefBasedOnFEMTet_CD<T> & ModelDefBasedOnFEMTet_CD<T>::operator= ( ModelDefBasedOnFEMTet_CD<T> const &orig ) 00047 //{ 00048 // return *this; 00049 //} 00050 //----------------------------------------------------------------------------- 00051 //============================================================================= 00052 00053 //----------------------------------------------------------------------------- 00054 template <typename T> 00055 bool ModelDefBasedOnFEMTet_CD<T>::Init ( 00056 OpenGL::OpenGLHalfEdgeTrigonalModel<T> * pHEModel, 00057 FEM::MeshTetrahedra<T> * pFEMMesh 00058 ) 00059 { 00060 ModelDefBasedOnFEM_CD<T>::Init( pHEModel ); 00061 m_pFEMMesh = pFEMMesh; 00062 return true; 00063 } 00064 00065 //----------------------------------------------------------------------------- 00066 template <typename T> 00067 bool ModelDefBasedOnFEMTet_CD<T>::CDRwith ( 00068 MultiBoundingVolume<T> * const pMBVObj 00069 ) 00070 { 00071 // CD 00072 bool bResult = CORE_CDwith( pMBVObj ); 00073 // CR 00074 if ( bResult ) { 00075 CORE_CR(); 00076 } 00077 return bResult; 00078 } 00079 00080 //----------------------------------------------------------------------------- 00081 template <typename T> 00082 bool ModelDefBasedOnFEMTet_CD<T>::CDRwith ( 00083 MultiBoundingVolume<T> * const pMBVObj, 00084 TransformationSupport<T> * const pTransform 00085 ) 00086 { 00087 TransformationSupport<T> trx = pMBVObj->GetTransform(); 00088 pMBVObj->GetTransform().RefToMatrixTransform() = pTransform->RefToMatrixTransform() * pMBVObj->GetTransform().RefToMatrixTransform(); 00089 // CD 00090 bool bResult = CORE_CDwith( pMBVObj ); 00091 // CR 00092 if ( bResult ) { 00093 CORE_CR(); 00094 } 00095 pMBVObj->GetTransform() = trx; 00096 return bResult; 00097 } 00098 00099 //----------------------------------------------------------------------------- 00100 template <typename T> 00101 bool ModelDefBasedOnFEMTet_CD<T>::CORE_CDwith ( 00102 MultiBoundingVolume<T> * const pMBVObj 00103 ) 00104 { 00105 // [07/07/2010] 00106 // ClearCollidedParts() has been moved out. 00107 // Without resetting collided parts, 00108 // this collision detection fn will not affect previous collision tests. 00109 // So that we can do collision test of this object with more than one MBV object. 00110 // But ClearCollidedParts() has to be explicitly called 00111 // to clear the collided parts before each main collision detection test. 00112 // 00113 return ModelDefBasedOnFEM_CD<T>::CORE_CDwith( pMBVObj, &m_ListOfCDObjs ); 00114 } 00115 00116 //----------------------------------------------------------------------------- 00117 template <typename T> 00118 void ModelDefBasedOnFEMTet_CD<T>::CORE_CR () 00119 { 00120 for ( unsigned int i = 0; i < m_ListOfCDObjs.size(); ++i ) { 00121 GenCDForcesOnFEMMeshByCDObj( m_ListOfCDObjs[i] ); 00122 } 00123 } 00124 00125 //----------------------------------------------------------------------------- 00126 template <typename T> 00127 void ModelDefBasedOnFEMTet_CD<T>::ClearCollidedParts () 00128 { 00129 m_pFEMMesh->ClearAllCDLoads(); 00130 //for ( unsigned int i = 0; i < m_ListOfCDObjs.size(); ++i ) { 00131 // ClearFEMMeshAdjustmentFromCDObj( m_ListOfCDObjs[i] ); 00132 //} 00133 m_ListOfCDObjs.clear(); 00134 } 00135 00136 //----------------------------------------------------------------------------- 00137 template <typename T> 00138 void ModelDefBasedOnFEMTet_CD<T>::GenCDForcesOnFEMMeshByCDObj ( CDObj<T> & cdObj ) 00139 { 00140 // Set collision (i.e. point) force 00141 cdObj.PtForce.SetID( cdObj.pHEVertex->GetID() ); 00142 cdObj.PtForce.RefToPosition() = cdObj.pHEVertex->GetBarycentricPtr()->RetGenBaryCoords(); 00143 cdObj.PtForce.RefToForce() = cdObj.PosAdj * m_tCDForceScale; 00144 // Add the collision force to the FEM mesh 00145 // The force referred in cdObj is in FEM local coordinates. 00146 // Therefore no coordinates conversion is needed. 00147 m_pFEMMesh->AddCDForceInLocalCoordinates( &cdObj.PtForce ); 00148 } 00149 00150 //----------------------------------------------------------------------------- 00151 template <typename T> 00152 void ModelDefBasedOnFEMTet_CD<T>::GenGrabbedForcesOnFEMMeshByCDObj ( 00153 CDObj<T> & cdObj, 00154 Vector3<T> const & grabbingObjPos_LS 00155 ) 00156 { 00157 // Set collision (i.e. point) force 00158 cdObj.PtForce.SetID( cdObj.pHEVertex->GetID() ); 00159 cdObj.PtForce.RefToPosition() = cdObj.pHEVertex->GetBarycentricPtr()->RetGenBaryCoords(); 00160 00161 //cdObj.PtForce.RefToForce() = cdObj.PosAdj * -m_tGrabbedForceScale; 00162 Vector3<T> dv = grabbingObjPos_LS - cdObj.pHEVertex->GetPosition(); 00163 cdObj.PtForce.RefToForce() = dv * m_tGrabbedForceScale; 00164 cdObj.PosAdj = grabbingObjPos_LS; 00165 00166 // Add the collision force to the FEM mesh 00167 // The force referred in cdObj is in FEM local coordinates. 00168 // Therefore no coordinates conversion is needed. 00169 m_pFEMMesh->AddCDForceInLocalCoordinates( &cdObj.PtForce ); 00170 } 00171 00172 //----------------------------------------------------------------------------- 00173 template <typename T> 00174 void ModelDefBasedOnFEMTet_CD<T>::AdjustSurfaceMeshByCDObjs () 00175 { 00176 for ( unsigned int i = 0; i < m_ListOfCDObjs.size(); ++i ) { 00177 AdjustSurfaceMeshVertexPositionByCDObj( m_ListOfCDObjs[i] ); 00178 } 00179 } 00180 00181 //----------------------------------------------------------------------------- 00182 template <typename T> 00183 void ModelDefBasedOnFEMTet_CD<T>::AdjustSurfaceMeshVertexPositionByCDObj ( CDObj<T> & cdObj ) 00184 { 00185 // Move the vertex position 00186 //cdObj.pHEVertex->GetProtectedPosition() = cdObj.PosAdj; 00187 cdObj.pHEVertex->GetProtectedPosition() += cdObj.PosAdj; 00188 } 00189 00190 //----------------------------------------------------------------------------- 00191 template <typename T> 00192 void ModelDefBasedOnFEMTet_CD<T>::AdjustSurfaceMeshVertexPositionDueToGrabbedVertex ( CDObj<T> & cdObj ) 00193 { 00194 // Move the vertex position 00195 cdObj.pHEVertex->GetProtectedPosition() = cdObj.PosAdj; 00196 } 00197 00199 //template <typename T> 00200 //void ModelDefBasedOnFEMTet_CD<T>::ClearFEMMeshAdjustmentFromCDObj ( CDObj<T> & cdObj ) 00201 //{ 00202 // cdObj.pHEVertex->SetMarkedStatus( false ); 00203 //} 00204 00205 00206 00207 00208 //============================================================================= 00209 // Grabbing 00210 //----------------------------------------------------------------------------- 00211 template <typename T> 00212 void ModelDefBasedOnFEMTet_CD<T>::MoveGrabbedPart ( int grabbedPartID ) 00213 { 00214 // Check against invalid range 00215 if ( grabbedPartID < 0 || grabbedPartID >= MAX_NUMBER_OF_GRABBED_PARTS ) return; 00216 00217 // Move the grabbed part 00218 if ( m_ListOfGrabbedParts_IsGrabbedStatus[ grabbedPartID ] ) { 00219 Matrix4x4<T> invTrx = m_pHEModel->GetTransform().GetInverseMatrixTransform(); 00220 for ( std::vector< GrabbedPartData >::iterator it = m_ListOfGrabbedParts.begin(); it != m_ListOfGrabbedParts.end(); ++it ) { 00221 if ( grabbedPartID == it->ID ) { 00222 Vector3<T> grabbingPos = invTrx * *it->pGrabbingPosition; 00223 for ( std::vector< CDObj<T> >::iterator data = it->GrabbedVertices.begin(); data != it->GrabbedVertices.end(); ++data ) { 00224 GenGrabbedForcesOnFEMMeshByCDObj( *data, grabbingPos ); 00225 } 00226 break; 00227 } 00228 } 00229 } 00230 } 00231 //----------------------------------------------------------------------------- 00232 template <typename T> 00233 void ModelDefBasedOnFEMTet_CD<T>::MoveAllGrabbedParts () 00234 { 00235 Matrix4x4<T> invTrx = m_pHEModel->GetTransform().GetInverseMatrixTransform(); 00236 for ( std::vector< GrabbedPartData >::iterator it = m_ListOfGrabbedParts.begin(); it != m_ListOfGrabbedParts.end(); ++it ) { 00237 Vector3<T> grabbingPos = invTrx * *it->pGrabbingPosition; 00238 for ( std::vector< CDObj<T> >::iterator data = it->GrabbedVertices.begin(); data != it->GrabbedVertices.end(); ++data ) { 00239 GenGrabbedForcesOnFEMMeshByCDObj( *data, grabbingPos ); 00240 } 00241 } 00242 } 00243 //----------------------------------------------------------------------------- 00244 // Grabbing 00245 //============================================================================= 00246 00247 00248 00249 00250 //============================================================================= 00251 #if defined(__gl_h_) || defined(__GL_H__) 00252 //----------------------------------------------------------------------------- 00253 //----------------------------------------------------------------------------- 00254 #endif // #if defined(__gl_h_) || defined(__GL_H__) 00255 //============================================================================= 00256 00257 //============================================================================= 00258 END_NAMESPACE_TAPs__FEM 00259 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00260 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----