TAPs 0.7.7.3
TAPsHETriMeshOneModelMultiParts.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsHETriMeshOneModelMultiParts.cpp
00003 
00004 SUKITTI PUNAK   (10/02/2009)
00005 UPDATE          (10/02/2009)
00006 ******************************************************************************/
00007 
00013 #include "TAPsHETriMeshOneModelMultiParts.hpp"
00014 // Using Inclusion Model (i.e. definitions are included in declarations)
00015 //                       (this name.cpp is included in name.hpp)
00016 // Each friend is defined directly inside its declaration.
00017 //-----------------------------------------------------------------------------
00018 BEGIN_NAMESPACE_TAPs__OpenGL
00019 //=============================================================================
00020 #ifdef  TAPs_ADVANCED_SIMULATION
00021 template <typename T> unsigned int HETriMeshOneModelMultiParts<T>::TotalModels = 0;
00022 #endif//TAPs_ADVANCED_SIMULATION
00023 //-----------------------------------------------------------------------------
00024 // default constructor
00025 template <typename T>
00026 HETriMeshOneModelMultiParts<T>::HETriMeshOneModelMultiParts ()
00027     : HalfEdgeModel<T>(), 
00028       m_iRigidity( 1 ), 
00029       m_tPtMass( 1 ), 
00030       m_tKStiffness( 1 ), 
00031       m_tKDamper( 0.5 ), 
00032       m_tHomeKStiffness( 1 ), 
00033       m_tHomeKDamper( 0.5 ) 
00034 
00035 #ifdef  TAPs_ADVANCED_SIMULATION
00036       //, AdvSimID( TotalModels++ )
00037 #endif//TAPs_ADVANCED_SIMULATION
00038 
00039 #ifdef  TAPs_USE_WXWIDGETS
00040       , pDialogs( NULL )
00041 #endif//TAPs_USE_WXWIDGETS
00042 
00043 {
00044     //---------------------------------------------------------------
00045     //std::cout << "Number of Vertex: " << GetNoVertices();
00046     //std::cout << "Number of Vertex: " << GetNoVertices();
00047     #ifdef  TAPs_ENABLE_DEBUG
00048     std::cout << "HETriMeshOneModelMultiParts<" << typeid(T).name() << "> Constructor\n";
00049     #endif//TAPs_ENABLE_DEBUG
00050 
00051 #ifdef  TAPs_USE_CUDA
00052     // Data Members for CUDA
00053     m_cudaVertexList            = NULL;
00054     m_cudaPrevVertexList        = NULL;
00055     m_cudaHomeVertexList        = NULL;
00056     m_cudaVertexConnectionList  = NULL;
00057     m_cudaMaxConnectionSize     = 0;
00058     m_cudaID                    = 0;
00059 #endif//TAPs_USE_CUDA
00060 
00061 }
00062 //-----------------------------------------------------------------------------
00063 // destructor
00064 template <typename T>
00065 HETriMeshOneModelMultiParts<T>::~HETriMeshOneModelMultiParts ()
00066 {
00067     DeleteAllData();
00068     //---------------------------------------------------------------
00069     // For simulation
00070     delete m_prODESolver;
00071     //---------------------------------------------------------------
00072     #ifdef  TAPs_ENABLE_DEBUG
00073     std::cout << "HETriMeshOneModelMultiParts<" << typeid(T).name() << "> Destructor\n";
00074     #endif//TAPs_ENABLE_DEBUG
00075 }
00076 //-----------------------------------------------------------------------------
00077 // Initialize
00078 // a virtual fn from Model class
00079 template <typename T>
00080 void HETriMeshOneModelMultiParts<T>::Initialize ()
00081 {
00082     HalfEdgeModel<T>::Initialize();
00083     //---------------------------------------------------------------
00084     #ifdef  TAPs_ENABLE_DEBUG
00085     std::cout << "++++++++++++++Initialize HALF-EDGE SPRING MODEL++++++++++++++\n";
00086     #endif//TAPs_ENABLE_DEBUG
00087 }
00088 //-----------------------------------------------------------------------------
00089 // Create Mesh Springs
00090 template <typename T>
00091 void HETriMeshOneModelMultiParts<T>::CreateMeshSprings ( 
00092         T mass,         
00093         T Ks,           
00094         T Kd,           
00095         T HKs,          
00096         T HKd,          
00097         int rigidity,   
00098         T predefinedTimeStep,       
00099         int numSimSubSteps,         
00100         bool enableColDet,          
00101         bool enableSimulation       
00102 )
00103 {
00104     PrepareData();
00105 
00106     //---------------------------------------------------------------
00107     // For Simulation
00108     if ( ( m_prODESolver = new Simulation::ODESolverEuler<T>() ) == NULL ) {
00109     //if ( ( m_prODESolver = new Simulation::ODESolverMidpoint<T>() ) == NULL ) {
00110     //if ( ( m_prODESolver = new Simulation::ODESolverRungeKutta4<T>() ) == NULL ) {
00111         #ifdef TAPs_ENABLE_DEBUG
00112         std::cerr   << "ERROR => HETriMeshOneModelMultiParts Constructor:" 
00113                     << " Cannot allocate memory for an ODE solver!" 
00114                     << std::endl;
00115         #endif
00116         delete this;
00117         return;
00118     }
00119     //---------------------------------------------------------------
00120     // Create ODE Solver
00121     m_iStateSize = static_cast<int>( m_pHEVertexList->size() );
00122     m_prODESolver->SetSize( m_iStateSize * 6 );
00123     x0   = &xData_1;
00124     xEnd = &xData_2;
00125     x0->resize(   m_iStateSize * 6 );
00126     xEnd->resize( m_iStateSize * 6 );
00127     StateToArray( &(*xEnd)[0] );
00128     //---------------------------------------------------------------
00129     #ifdef  TAPs_ENABLE_DEBUG
00130     std::cout << "++++++++++++++HALF-EDGE SPRING MODEL++++++++++++++\n";
00131     std::cout << "++++++++++++++ --> m_iStateSize = " << m_iStateSize << "\n";
00132     std::cout << "++++++++++++++HALF-EDGE SPRING MODEL++++++++++++++\n";
00133     #endif//TAPs_ENABLE_DEBUG
00134     //---------------------------------------------------------------
00135     SetListOf1RingVertices();
00136     SetMassOfParticles( mass );
00137     //---------------------------------------------------------------
00138     // Create Multiparts
00139 
00140     // Have to come after SetListOf1RingVertices()
00141     SeparateIntoParts(
00142         mass,       
00143         Ks,         
00144         Kd,         
00145         HKs,        
00146         HKd,        
00147         rigidity,   
00148         predefinedTimeStep,     
00149         numSimSubSteps,         
00150         enableColDet,           
00151         enableSimulation        
00152     );
00153     //---------------------------------------------------------------
00154     // Create home spring of each HEVertexPtrWithExtraInfo in m_pHEVertexList
00155     for ( int p = 0; p < static_cast<int>( m_Parts.size() ); ++p ) {
00156         for ( int i = 0; i < static_cast<int>( m_Parts[p].GetVertexList().size() ); ++i ) {
00157             // Create home spring from a particle
00158             //*
00159             SpringRef<T> * newSpring = new SpringRef<T>( 
00160                                             (m_Parts[ p ].GetVertexList()[i]->GetHomeParticle()), 
00161                                             *(m_Parts[ p ].GetVertexList()[i]->GetParticleRef()), 
00162                                             HKs, HKd, 
00163                                             //0, 0,
00164                                             0           // # of hops (0 means home spring)
00165             );
00166             m_vpSpringRef.push_back( newSpring );
00167             m_Parts[ p ].GetSpringList().push_back( newSpring );
00168             //*/
00169         }
00170     }
00171 
00172     //---------------------------------------------------------------
00173     CreateSprings( Ks, Kd, rigidity );  // A recursive method for creating springs on mesh
00174     //CreateSprings( 0, 0, rigidity );  // A recursive method for creating springs on mesh
00175 
00176     #ifdef  TAPs_ENABLE_DEBUG
00177     std::cout << "Spring Mesh Rigidity: " << m_iRigidity << "\n";
00178     std::cout << "The Total Number of Springs is " << static_cast<int>(m_vpSpringRef.size()) << "\n";
00179     #endif//TAPs_ENABLE_DEBUG
00180 
00181     /*
00182     // DEBUG
00183     for ( int i = 0; i < static_cast<int>( m_Parts.size() ); ++i ) {
00184         std::cout << "Part# " << i << "contains " << m_Parts[i].GetVertexList().size() << " vertices\n";
00185         for ( int j = 0; j < static_cast<int>( m_Parts[i].GetVertexList().size() ); ++j ) {
00186             std::cout << *(m_Parts[i].GetVertexList()[j]);
00187         }
00188         std::cout << "\n";
00189     }
00190     //*/
00191 
00192     #ifdef  TAPs_USE_CUDA
00193     for ( int p = 0; p < static_cast<int>( m_Parts.size() ); ++p ) {
00194         m_Parts[p].CUDA_Initialize();
00195     }
00196     CUDA_Initialize_All();
00197     #endif//TAPs_USE_CUDA
00198 
00199     #ifdef  TAPs_USE_WXWIDGETS
00200     pDialogs = new WX::WXHETriMeshOneModelMultiPartsParameters( & m_Parts );
00201     #endif//TAPs_USE_WXWIDGETS
00202 
00203 }
00204 //-----------------------------------------------------------------------------
00205 //*****************************************************************************
00206 
00207 //*****************************************************************************
00208 // Helper Fn(s)
00209 //-----------------------------------------------------------------------------
00210 template <typename T>
00211 void HETriMeshOneModelMultiParts<T>::ChangeConstantStiffnessOfAllSprings ( T val )
00212 {
00213     std::vector< SpringRef<T> * >::iterator pos;
00214     for ( pos = m_vpSpringRef.begin(); pos < m_vpSpringRef.end(); ++pos ) {
00215         (*pos)->SetConstantK( val );
00216     }
00217 }
00218 //-----------------------------------------------------------------------------
00219 template <typename T>
00220 void HETriMeshOneModelMultiParts<T>::ChangeConstantDampingOfAllSprings ( T val )
00221 {
00222     std::vector< SpringRef<T> * >::iterator pos;
00223     for ( pos = m_vpSpringRef.begin(); pos < m_vpSpringRef.end(); ++pos ) {
00224         (*pos)->SetDampingD( val );
00225     }
00226 }
00227 //-----------------------------------------------------------------------------
00228 template <typename T>
00229 void HETriMeshOneModelMultiParts<T>::ChangeMassOfAllPoints ( T val )
00230 {
00231     std::vector< HEvertexPtrWithExtraInfo<T> >::iterator pos;
00232     for ( pos = m_pHEVertexList->begin(); pos < m_pHEVertexList->end(); ++pos ) {
00233         (*pos).GetListParticleRef()->SetMass( val );
00234     }
00235 }
00236 //-----------------------------------------------------------------------------
00237 //*****************************************************************************
00238 
00239 //*****************************************************************************
00240 // Helper Fn(s)
00241 //-----------------------------------------------------------------------------
00242 template <typename T>
00243 void HETriMeshOneModelMultiParts<T>::DeleteAllData ()
00244 {
00245     // Clear spring references
00246     for ( int i = 0; i < static_cast<int>( m_vpSpringRef.size() ); ++i ) {
00247         delete m_vpSpringRef[i];
00248     }
00249     m_vpSpringRef.clear();
00250 
00251     // Clear vertex list
00252     for ( int i = 0; i < static_cast<int>( m_HEVertexList_1.size() ); ++i ) {
00253         delete m_HEVertexList_1[i];
00254     }
00255     m_HEVertexList_1.clear();
00256 
00257     // Clear particle references
00258     for ( int i = 0; i < static_cast<int>( m_svpParticleRef.size() ); ++i ) {
00259         delete m_svpParticleRef[i];
00260     }
00261     m_svpParticleRef.clear();
00262 
00263     // Clear multi-parts
00264     m_Parts.clear();
00265 
00266     #ifdef  TAPs_USE_CUDA
00267     CUDA_Cleanup_All();
00268     #endif//TAPs_USE_CUDA
00269 }
00270 //-----------------------------------------------------------------------------
00271 template <typename T>
00272 void HETriMeshOneModelMultiParts<T>::SetListOf1RingVertices ()
00273 {
00274     HEHalfEdge<T> * firstHalfEdge, * currentHalfEdge;
00275     HEVertex<T> *   heVertex = GetVertexList()->Head();
00276     HEVertex<T> *   currentVertex;
00277 
00278     /* Doesn't Work???
00279     for ( int v = 0; v < static_cast<int>( GetVertexList()->Size() ); ++v ) {
00280         m_HEVertexList[v].CreateListVertexFirstRing( GetVertexList() );
00281 
00282         for ( int i = 0; i < static_cast<int>( m_HEVertexList[v].GetListVertexFirstRing().size() ); ++i ) {
00283             m_pviListVertexRing1[v].push_back( i );
00284         }
00285     }
00286     //*/
00287 
00288     int size = static_cast<int>( m_pHEVertexList->size() );
00289     for ( int v = 0; v < size; ++v ) {
00290         currentHalfEdge = firstHalfEdge = heVertex->IncidentHalfEdge();
00291         do {
00292             currentVertex = currentHalfEdge->Pair()->Vertex();
00293             for ( int i = 0; i < size; ++i ) {
00294                 if ( currentVertex == (*m_pHEVertexList)[i]->GetHEVertexPtr() ) {
00295                     (*m_pHEVertexList)[v]->GetListVertexFirstRing().push_back( i );
00296                     break;
00297                 }
00298             }
00299             currentHalfEdge = currentHalfEdge->Pair()->Next();
00300         } while ( firstHalfEdge != currentHalfEdge );
00301         heVertex = heVertex->Next();
00302     }
00303 }
00304 //-----------------------------------------------------------------------------
00305 template <typename T>
00306 void HETriMeshOneModelMultiParts<T>::PrepareData ()
00307 {
00308     m_pHEVertexList     = &m_HEVertexList_1;
00309 
00310     // Setup pointers to HEVertex
00311     HEVertex<T> * heVertex = GetVertexList()->Head();
00312 
00313     int i = 0;
00314     while ( heVertex ) {
00315         m_svpParticleRef.push_back( new ParticleRef<T>( heVertex->GetProtectedPosition() ) );
00316 
00317         // The position in the particle reference will be set as a home position 
00318         // when HEVertexPtrWithExtraInfo constructor below is called.
00319         m_pHEVertexList->push_back( new HEVertexPtrWithExtraInfo<T>( heVertex, m_svpParticleRef[i] ) );
00320 
00321         ++i;
00322         heVertex = heVertex->Next();
00323     }
00324 }
00325 //-----------------------------------------------------------------------------
00326 template <typename T>
00327 void HETriMeshOneModelMultiParts<T>::SeparateIntoParts ( 
00328         T mass,         
00329         T Ks,           
00330         T Kd,           
00331         T HKs,          
00332         T HKd,          
00333         int rigidity,   
00334         T predefinedTimeStep,       
00335         int numSimSubSteps,         
00336         bool enableColDet,          
00337         bool enableSimulation       
00338 )
00339 {
00340     // Set Data Members of this object
00341     m_tPtMass       = mass;
00342     m_tKStiffness   = Ks;
00343     m_tKDamper      = Kd;
00344     m_tHomeKStiffness   = HKs;
00345     m_tHomeKDamper      = HKd;
00346     m_tPredefinedTimeStep = predefinedTimeStep;
00347     m_iNumSimSubSteps = numSimSubSteps;
00348 
00349     m_Parts.push_back( SimPropForMultiPartMeshModel_HalfEdge<T>( mass, Ks, Kd, TAPs::Enum::MODEL_DEFORM, predefinedTimeStep, numSimSubSteps, enableColDet, enableSimulation ) );
00350     m_Parts.push_back( SimPropForMultiPartMeshModel_HalfEdge<T>( mass, Ks, Kd, TAPs::Enum::MODEL_DEFORM, predefinedTimeStep, numSimSubSteps, enableColDet, enableSimulation ) );
00351 
00352     int size = static_cast<int>( m_pHEVertexList->size() );
00353 
00354     m_tmpForPuttingSpringRefIntoParts.clear();
00355 
00356     for ( int i = 0; i < size; ++i ) {
00357         if ( (*m_pHEVertexList)[i]->GetParticleRef()->GetPosition()[1] > 0 ) {
00358             m_Parts[0].GetVertexList().push_back( (*m_pHEVertexList)[i] );
00359             m_tmpForPuttingSpringRefIntoParts.push_back( 0 );
00360         }
00361         else {
00362             m_Parts[1].GetVertexList().push_back( (*m_pHEVertexList)[i] );
00363             m_tmpForPuttingSpringRefIntoParts.push_back( 1 );
00364         }
00365     }
00366 
00367     for ( int i = 0; i < static_cast<int>( m_Parts.size() ); ++i ) {
00368         m_Parts[i].SetODESolver( TAPs::Enum::EULER );
00369         //m_Parts[i].SetODESolver( TAPs::Enum::MIDPOINT );
00370         //m_Parts[i].SetODESolver( TAPs::Enum::RUNGE_KUTTA_4 );
00371         
00372         if ( i % 2 == 0 ) {
00373             m_Parts[i].SetModelType( TAPs::Enum::MODEL_DEFORM );
00374         }
00375         else {
00376             m_Parts[i].SetModelType( TAPs::Enum::MODEL_DEFORM_ELASTIC );
00377         }
00378 
00379         std::cout << "m_Parts[" << i << "] size: " << m_Parts[i].Size() << "\n";
00380     }
00381 }
00382 //-----------------------------------------------------------------------------
00383 template <typename T>
00384 void HETriMeshOneModelMultiParts<T>::SetMassOfParticles ( T mass )
00385 {
00386     for ( int i = 0; i < static_cast<int>( m_pHEVertexList->size() ); ++i ) {
00387         (*m_pHEVertexList)[i]->GetParticleRef()->SetMass( mass );
00388     }
00389 }
00390 //-----------------------------------------------------------------------------
00391 template <typename T>
00392 bool HETriMeshOneModelMultiParts<T>::CheckASpringExistance ( int p1, int p2 )
00393 {
00394     int size = static_cast<int>( (*m_pHEVertexList)[p1]->GetListConnectedVertices().size() );
00395     for ( int i = 0; i < size; ++i ) {
00396         if ( (*m_pHEVertexList)[p1]->GetListConnectedVertices()[i] == p2 )  return true;
00397     }
00398     return false;
00399 }
00400 //-----------------------------------------------------------------------------
00401 template <typename T>
00402 void HETriMeshOneModelMultiParts<T>::CreateASpring ( 
00403                 T Ks, T Kd, int p1, int p2, int hops )
00404 {
00405     SpringRef<T> * newSpring = new SpringRef<T>( 
00406                                     *((*m_pHEVertexList)[p1]->GetParticleRef()), 
00407                                     *((*m_pHEVertexList)[p2]->GetParticleRef()), 
00408                                     Ks, Kd, 
00409                                     hops );
00410     m_vpSpringRef.push_back( newSpring );
00411     (*m_pHEVertexList)[p1]->GetListConnectedVertices().push_back( p2 );
00412     (*m_pHEVertexList)[p2]->GetListConnectedVertices().push_back( p1 );
00413     //std::cout << "# of Hops: " << hops << "\n";
00414     //std::cout << "Create Spring with " << hops << " hop(s)\n";
00415 
00416     m_Parts[ m_tmpForPuttingSpringRefIntoParts[p1] ].GetSpringList().push_back( newSpring );
00417     m_Parts[ m_tmpForPuttingSpringRefIntoParts[p2] ].GetSpringList().push_back( newSpring );
00418 }
00419 //-----------------------------------------------------------------------------
00420 template <typename T>
00421 void HETriMeshOneModelMultiParts<T>::CreateSprings ( T Ks, T Kd, int rigidity )
00422 {
00423     m_iRigidity = rigidity;
00424     int size = static_cast<int>( m_pHEVertexList->size() );
00425     bool * isMark = new bool[size];
00426     //---------------------------------------------------------------
00427     for ( int i = 0; i < size; ++i ) {
00428         isMark[i] = false;      // prepare for spring creation
00429     }
00430     // Create springs on the object's surface
00431     for ( int i = 0; i < size; ++i ) {
00432         std::vector<int> particleSet;       // start as empty set
00433         BFSCreateSprings(   Ks, Kd, 0, 
00434                             i, i,           // particle#1, particle#2
00435                             particleSet, 
00436                             isMark );
00437         for ( int j = 0; j < static_cast<int>( particleSet.size() ); ++j ) {
00438             isMark[ particleSet[j] ] = false;
00439         }
00440     }
00441 
00442     /*
00443     //---------------------------------------------------------------
00444     for ( int i = 0; i < size; ++i ) {
00445         isMark[i] = false;      // prepare for spring creation
00446     }
00447     // Create opposite springs inside the object
00448     for ( int i = 0; i < size; ++i ) {
00449         std::cout << "isMark["<<i<<"]" << isMark[i] << "\n";
00450         if ( isMark[i] ) continue;
00451         T maxDist = 0;
00452         int idx1 = -1;
00453         int idx2 = -1;
00454         int idx3 = -1;
00455         int idx4 = -1;
00456         for ( int j = 0; j < size; ++j ) {
00457             T dist = ((*m_pHEVertexList)[i]->GetParticleRef()->GetPosition() - (*m_pHEVertexList)[j]->GetParticleRef()->GetPosition()).Length();
00458             if ( dist > maxDist ) {
00459                 maxDist = dist;
00460                 idx4 = idx3;
00461                 idx3 = idx2;
00462                 idx2 = idx1;
00463                 idx1 = j;
00464 
00465                 std::cout << i << "\t\tindices: " << idx1 << ", " << idx2 << ", " << idx3 << ", " << idx4 << "\n";
00466             }
00467         }
00468         bool bCreated = false;
00469         T Ks_opp = Ks / 10;
00470         if ( !bCreated && idx1 > -1 && !isMark[idx1] ) {
00471             if ( !CheckASpringExistance( i, idx1 ) ) 
00472             {
00473                 isMark[idx1] = true;
00474                 CreateASpring( Ks_opp, Kd, i, idx1, 1 );
00475                 bCreated = true;
00476                 std::cout << "opposite: " << i << " and " << idx1 << "\n";
00477             }
00478         }
00479         if ( !bCreated && idx2 > -1 && !isMark[idx2] ) {
00480             if ( !CheckASpringExistance( i, idx2 ) )
00481             {
00482                 isMark[idx2] = true;
00483                 CreateASpring( Ks_opp, Kd, i, idx2, 1 );
00484                 bCreated = true;
00485                 std::cout << "opposite: " << i << " and " << idx2 << "\n";
00486             }
00487         }
00488         if ( !bCreated && idx3 > -1 && !isMark[idx3] ) {
00489             if ( !CheckASpringExistance( i, idx3 ) )
00490             {
00491                 isMark[idx3] = true;
00492                 CreateASpring( Ks_opp, Kd, i, idx3, 1 );
00493                 bCreated = true;
00494                 std::cout << "opposite: " << i << " and " << idx3 << "\n";
00495             }
00496         }
00497         if ( !bCreated && idx4 > -1 ) {
00498             if ( !CheckASpringExistance( i, idx4 ) )
00499             {
00500                 isMark[idx4] = true;
00501                 CreateASpring( Ks_opp, Kd, i, idx4, 1 );
00502                 bCreated = true;
00503                 std::cout << "opposite: " << i << " and " << idx4 << "\n";
00504             }
00505         }
00506     }
00507     //*/
00508 
00509     m_tmpForPuttingSpringRefIntoParts.clear();
00510 }
00511 //-----------------------------------------------------------------------------
00512 template <typename T>
00513 void HETriMeshOneModelMultiParts<T>::BFSCreateSprings ( 
00514                 T Ks, T Kd, int rigidity,       // Ks, Kd, & hop distance
00515                 int p1, int p2,                 // particle#1 & #2
00516                 std::vector<int> & particleSet, // set of connected particles
00517                 bool * isMark )                 // marked particles in particleSet
00518 {
00519     if ( rigidity >= m_iRigidity ) return;
00520     //---------------------------------------------------------------
00521     // Keep the particle reference in particleSet
00522     // And mark it as visited
00523     particleSet.push_back( p2 );
00524     isMark[ p2 ] = true;
00525     //---------------------------------------------------------------
00526     // Traverse each edge of p1
00527     ++rigidity;
00528     int p3;
00529     for ( int i = 0; i < static_cast<int>( (*m_pHEVertexList)[p2]->GetListVertexFirstRing().size() ); ++i ) {
00530         p3 = (*m_pHEVertexList)[p2]->GetListVertexFirstRing()[i];
00531         if ( !isMark[ p3 ] ) {
00532             if ( !CheckASpringExistance( p1, p3 ) ) {
00533                 CreateASpring( Ks, Kd, p1, p3, rigidity );
00534             }
00535         }
00536     }
00537     // This makes it become Breadth First Search
00538     for ( int i = 0; i < static_cast<int>( (*m_pHEVertexList)[p2]->GetListVertexFirstRing().size() ); ++i ) {
00539         p3 = (*m_pHEVertexList)[p2]->GetListVertexFirstRing()[i];
00540         BFSCreateSprings( Ks, Kd, rigidity, p1, p3, particleSet, isMark );
00541     }
00542     //---------------------------------------------------------------
00543 }
00544 /*
00545 //-----------------------------------------------------------------------------
00546 template <typename T>
00547 void HETriMeshOneModelMultiParts<T>::DFSCreateSprings ( 
00548                 T Ks, T Kd, int rigidity,       // Ks, Kd, & hop distance
00549                 int p1, int p2,                 // particle#1 & #2
00550                 std::vector<int> & particleSet, // set of connected particles
00551                 bool * isMark )                 // marked particles in particleSet
00552 {
00553     if ( rigidity >= m_iRigidity ) return;
00554     //---------------------------------------------------------------
00555     // Keep the particle reference in particleSet
00556     // And mark it as visited
00557     particleSet.push_back( p2 );
00558     isMark[ p2 ] = true;
00559     //---------------------------------------------------------------
00560     // Traverse each edge of p1
00561     ++rigidity;
00562     int p3;
00563     for ( int i = 0; i < static_cast<int>( m_pviListVertexRing1[p2].size() ); ++i ) {
00564         p3 = m_pviListVertexRing1[p2][i];
00565         if ( !isMark[ p3 ] ) {
00566             if ( !CheckASpringExistance( p1, p3 ) ) {
00567                 CreateASpring( Ks, Kd, p1, p3, rigidity );
00568             }
00569             DFSCreateSprings( Ks, Kd, rigidity, p1, p3, particleSet, isMark );
00570         }
00571     }
00572     //---------------------------------------------------------------
00573 }
00574 //*/
00575 //-----------------------------------------------------------------------------
00576 //*****************************************************************************
00577 
00578 
00579 //-----------------------------------------------------------------------------
00580 template <typename T>
00581 void HETriMeshOneModelMultiParts<T>::ApplyAndResetTransform ()
00582 {
00583     // Apply to each home position
00584     std::vector< HEVertexPtrWithExtraInfo<T> * >::iterator pos = m_pHEVertexList->begin();
00585     while ( pos != m_pHEVertexList->end() ) {
00586         (*pos)->SetHomePosition( 
00587             ( GetTransform().RefToMatrixTransform() * Vector4<T>( (*pos)->GetHomePosition() ) ).GetVector3()
00588         );
00589         ++pos;
00590     }
00591 
00592     // Apply to the whole mesh of HalfEdgeModel
00593     // After this statement the transformation matrix is reset to identity
00594     HalfEdgeModel<T>::ApplyAndResetTransform();
00595 
00596     // Have to come after HalfEdgeModel<T>::ApplyAndResetTransform();
00597     for ( int p = 0; p < static_cast<int>( m_Parts.size() ); ++p ) {
00598         m_Parts[p].UpdateStateToArray();
00599     }
00600 
00601     // Update Springs
00602     std::vector< SpringRef<T> * >::iterator sprPos = m_vpSpringRef.begin();
00603     while ( sprPos != m_vpSpringRef.end() ) {
00604         (*sprPos)->SetRestLengthL( (*sprPos)->GetCurrentLength() );
00605         ++sprPos;
00606     }
00607 }
00608 //-----------------------------------------------------------------------------
00609 
00610 
00611 //=============================================================================
00612 // For Simulation
00613 //-----------------------------------------------------------------------------
00614 // Advance Simulation
00615 template <typename T>
00616 void HETriMeshOneModelMultiParts<T>::AdvanceSimulation ( T tCurrent, T tNext )
00617 {
00618     #ifdef  TAPs_USE_CUDA
00619 
00620     std::cout << __FILE__ << " " << __LINE__ << " -- ";
00621     std::cout << "HETriMeshOneModelMultiParts<T>::AdvanceSimulation ( T tCurrent, T tNext ) IS NOT IMPLEMENTED YET!\n";
00622 
00623         /*
00624         CUDA_CopyVertexToMem();
00625         Global__HETriMeshOneModelMultiParts_AdvSim( 
00626             m_pHEVertexList->size(),    //!< number of vertices
00627             64,                         //!< number of threads
00628             tCurrent, tNext, 
00629             m_cudaVertexList, 
00630             m_cudaPrevVertexList, 
00631             m_cudaHomeVertexList, 
00632             m_cudaVertexConnectionList, 
00633             m_cudaMaxConnectionSize 
00634         );
00635         CUDA_CopyMemToVertex();
00636 
00637         GetBVHTree()->Update(); // commented out to rely on CDR to update the collided BVNodes
00638         CalAndSetNormals();
00639         //*/
00640 
00641     #else //TAPs_USE_CUDA
00642 
00643         for ( int i = 0; i < static_cast<int>( m_Parts.size() ); ++i ) {
00644             m_Parts[i].AdvSim( tCurrent, tNext );
00645         }
00646         GetBVHTree()->Update(); // commented out to rely on CDR to update the collided BVNodes
00647         CalAndSetNormals();
00648 
00649     #endif//TAPs_USE_CUDA
00650 }
00651 //-----------------------------------------------------------------------------
00652 // Advance Simulation
00653 template <typename T>
00654 void HETriMeshOneModelMultiParts<T>::AdvanceSimulation ( T tCurrent )
00655 {
00656     //GetTransform().SetMatrixTransform( GetTransform().GetMatrixTransform() * Matrix4x4<T>( 1, 0, 0, 0.1, 0, 1, 0, 0.1, 0, 0, 1, 0.1, 0, 0, 0, 1 ) );
00657 
00658     #ifdef  TAPs_USE_CUDA
00659 
00660         //PrintDebug_ConnectionList();
00661         //PrintDebug();
00662 
00663         // Copy the (current) vertex positions of the object to memory for transfering to CUDA.
00664         CUDA_CopyVertexToMem();
00665 
00666         // Call the wrapper function for 
00667         TAPs::CUDA::Global__HETriMeshOneModelMultiParts_AdvSim( 
00668             m_cudaID,
00669             m_pHEVertexList->size(),    
00670             64,                         
00671             tCurrent,                   
00672             GetPredefinedTimeStep(),    
00673             GetNumSimSubSteps(),        
00674             GetKPointMass(),            
00675             GetKStiffness(),            
00676             GetKDamper(),               
00677             GetHomeKStiffness(),        
00678             GetHomeKDamper(),           
00679             m_cudaVertexList, 
00680             m_cudaPrevVertexList, 
00681             m_cudaHomeVertexList, 
00682             m_cudaVertexConnectionList, 
00683             m_cudaMaxConnectionSize 
00684         );
00685 
00686         // The new vertex positions are returned by CUDA to memory for previous vertex positions.
00687         // So the new vertex positions must be copied to the vertex positions of the object.
00688         CUDA_CopyMemToPrevVertex();
00689         // Then the previous and current vertex pointers (that point to memory for transfering to CUDA) are swapped.
00690         // So that now the previous becomes current and the current becomes previous.
00691         CUDA_SwapBuffers();
00692 
00693         GetBVHTree()->Update(); // commented out to rely on CDR to update the collided BVNodes
00694         CalAndSetNormals();
00695 
00696     #else //TAPs_USE_CUDA
00697 
00698         for ( int i = 0; i < static_cast<int>( m_Parts.size() ); ++i ) {
00699             m_Parts[i].AdvSim( tCurrent );
00700             //std::cout << "AdvanceSimulation m_Parts[" << i << "]\n";
00701         }
00702         GetBVHTree()->Update(); // commented out to rely on CDR to update the collided BVNodes
00703         CalAndSetNormals();
00704 
00705     #endif//TAPs_USE_CUDA
00706 }
00707 //-----------------------------------------------------------------------------
00708 // Advance Simulation
00709 template <typename T>
00710 void HETriMeshOneModelMultiParts<T>::AdvanceSimulation ( Simulation::SimClock<T> & simClock )
00711 {
00712     std::cout << "HETriMeshOneModelMultiParts<T>::AdvanceSimulation ( Simulation::SimClock<T> & simClock ) -- NOT IMPLEMENTED YET!!!\n";
00713 }
00714 //-----------------------------------------------------------------------------
00715 // DxDt
00716 template <typename T>
00717 bool HETriMeshOneModelMultiParts<T>::DxDt ( 
00718     T                       dt,         // I/P: time step
00719     Simulation::VectorSet<T> &  x,      // I/p: array  x = {pos, vel}
00720     Simulation::VectorSet<T> &  xdot,   // O/P: array xdot = {vel, accel}
00721     void *                  userData    // O/P: array of user data
00722 )
00723 {
00724     //-----------------------------------------------------
00725     // Convert userData ptr to ModelStrand ptr
00726     HETriMeshOneModelMultiParts<T> *pThis = static_cast<HETriMeshOneModelMultiParts<T> *>( userData );
00727     assert( pThis );
00728 
00729     //*
00730     pThis->ClearAllForces();
00731     //-----------------------------------------------------
00732     for ( int i = 0; i < static_cast<int>( pThis->m_vpSpringRef.size() ); ++i ) {
00733         pThis->m_vpSpringRef[i]->CalAndSetForce();
00734         //std::cout << "Force1: " << pThis->m_vpSpringRef[i]->GetForce1() << "\n";
00735         //std::cout << "Force2: " << pThis->m_vpSpringRef[i]->GetForce2() << "\n";
00736     }
00737     /*
00738     //-----------------------------------------------------
00739     for ( int i = 0; i < pThis->m_iStateSize; ++i ) {
00740 //      pThis->(*m_pHEVertexList)[i]->GetListParticleRef()->SetVelocity( 0, 0, 0 );
00741 //      pThis->(*m_pHEVertexList)[i]->GetListParticleRef()->SetForce( 0, 0, 0 );
00742 
00743         if ( (*pThis->m_pHEVertexList)[i]->GetParticleRef()->GetFixStatus() ) {
00744             (*pThis->m_pHEVertexList)[i]->GetParticleRef()->SetVelocity( 0, 0, 0 );
00745             (*pThis->m_pHEVertexList)[i]->GetParticleRef()->SetForce( 0, 0, 0 );
00746         }
00747         else {
00748 //          (*pThis->m_pHEVertexList)[i]->GetListParticleRef()->SetForce( 0, 0, 0 );
00749 //          pThis->m_prForce[i] = pThis->m_StructForce[i].gravity;
00750 //          pThis->m_prVelocity[i][1] = pThis->m_prForce[i][1] * 
00751 //                                      pThis->m_prVertex[i][1] *
00752 //                                      dt;
00753             //Vector3<T> newForce = (*pThis->m_pHEVertexList)[i].GetParticleRef()->GetForce() / 10;
00754             //(*pThis->m_pHEVertexList)[i].GetParticleRef()->SetForce( newForce );
00755         }
00756     }
00757     //*/
00758 
00759     //-----------------------------------------------------
00760     pThis->DdtStateToArray( &xdot[0], dt );
00761     //-----------------------------------------------------
00762     return true;
00763 }
00764 //-----------------------------------------------------------------------------
00765 // StateToArray
00766 template <typename T>
00767 void HETriMeshOneModelMultiParts<T>::StateToArray ( T *dst )
00768 {
00769     //*
00770     for ( int i = 0; i < m_iStateSize; ++i ) {
00771         *(dst++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetPosition()[0];
00772         *(dst++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetPosition()[1];
00773         *(dst++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetPosition()[2];
00774         *(dst++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetVelocity()[0];
00775         *(dst++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetVelocity()[1];
00776         *(dst++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetVelocity()[2];
00777     }
00778     //*/
00779 }
00780 //-----------------------------------------------------------------------------
00781 // ArrayToState
00782 template <typename T>
00783 void HETriMeshOneModelMultiParts<T>::ArrayToState ( T *src )
00784 {
00785     //*
00786     for ( int i = 0; i < m_iStateSize; ++i ) {
00787         (*m_pHEVertexList)[i]->GetParticleRef()->SetPosition( *src, *(src+1), *(src+2) );
00788         src += 3;
00789         (*m_pHEVertexList)[i]->GetParticleRef()->SetVelocity( *src, *(src+1), *(src+2) );
00790         src += 3;
00791     }
00792     //*/
00793 }
00794 //-----------------------------------------------------------------------------
00795 // DdtStateToArray
00796 template <typename T>
00797 void HETriMeshOneModelMultiParts<T>::DdtStateToArray ( T *xdot, T dt )
00798 {
00799     //*
00800     for ( int i = 0; i < m_iStateSize; ++i ) {
00801         if ( (*m_pHEVertexList)[i]->GetParticleRef()->GetFixStatus() ) {
00802             *(xdot++) = 
00803             *(xdot++) = 
00804             *(xdot++) = 
00805             *(xdot++) = 
00806             *(xdot++) = 
00807             *(xdot++) = 0;
00808         }
00809         else {
00810             //m_prForce[i] = m_StructForce[i].gravity;
00811             //m_prVelocity[i][1] = m_prForce[i][1] * m_prVertex[i][1] * dt;
00812             //----------------------------------------
00813             *(xdot++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetVelocity()[0];
00814             *(xdot++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetVelocity()[1];
00815             *(xdot++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetVelocity()[2];
00816             *(xdot++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetForce()[0];
00817             *(xdot++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetForce()[1];
00818             *(xdot++) = (*m_pHEVertexList)[i]->GetParticleRef()->GetForce()[2];
00819         }
00820     }
00821     //*/
00822 }
00823 //*/
00824 //-----------------------------------------------------------------------------
00825 // ClearForces
00826 template <typename T>
00827 void HETriMeshOneModelMultiParts<T>::ClearAllForces ()
00828 {
00829     for ( int i = 0; i < static_cast<int>( m_pHEVertexList->size() ); ++i ) {
00830         (*m_pHEVertexList)[i]->GetParticleRef()->SetForce( 0, 0, 0 );
00831     }
00832 }
00833 //-----------------------------------------------------------------------------
00834 //=============================================================================
00835 
00836 
00837 //=============================================================================
00838 #ifdef  TAPs_USE_CUDA
00839 //-----------------------------------------------------------------------------
00840 
00841 template <typename T>
00842 bool HETriMeshOneModelMultiParts<T>::CUDA_Initialize_All ()
00843 {
00844     bool result = true;
00845     if ( !CUDA_Initialize_VertexList() )            result = false;
00846     if ( !CUDA_Initialize_PrevVertexList() )        result = false;
00847     if ( !CUDA_Initialize_HomeVertexList() )        result = false;
00848     if ( !CUDA_Initialize_VertexConnectionList() )  result = false;
00849 
00850     std::cout << "# vertices: " << m_pHEVertexList->size() << "\tMax connection size: " << m_cudaMaxConnectionSize << "\n";
00851 
00852     /*
00853     m_cudaDeviceData = new TAPs_CUDA_DATA_HETriMeshOneModelMultiParts( 
00854         m_pHEVertexList->size(), m_cudaMaxConnectionSize 
00855     );
00856     if ( !m_cudaDeviceData )    result = false;
00857     //*/
00858 
00859     //std::cout << "m_cudaID: " << m_cudaID << "\n";
00860 
00861     TAPs::CUDA::InitailizeDataForVertexList( 
00862         m_cudaID,                   
00863         m_pHEVertexList->size(),    
00864         m_cudaMaxConnectionSize,    
00865         m_cudaVertexList,           
00866         m_cudaPrevVertexList,       
00867         m_cudaHomeVertexList,       
00868         m_cudaVertexConnectionList  
00869     );
00870 
00871     //std::cout << "m_cudaID: " << m_cudaID << "\n";
00872 
00873     return result;
00874 }
00875 
00876 template <typename T>
00877 bool HETriMeshOneModelMultiParts<T>::CUDA_Initialize_VertexList ()
00878 {
00879     CUDA_Cleanup_VertexList();
00880 
00881     std::cout << "m_cudaVertexList size: " << m_pHEVertexList->size() * 4 << "\n";
00882 
00883     unsigned int size = sizeof(float) * m_pHEVertexList->size() * 4;
00884 
00885     // Vertex List
00886     m_cudaVertexList = (float *)malloc( size );
00887     if ( m_cudaVertexList ) {
00888         CUDA_CopyVertexToMem();
00889     }
00890     else {
00891         std::cout << "ERROR: Could not allocate memory for (Vertex List) CUDA!" << std::endl;
00892         exit( -1 );
00893     }
00894 
00895     return true;    
00896 }
00897 
00898 template <typename T>
00899 bool HETriMeshOneModelMultiParts<T>::CUDA_Initialize_PrevVertexList ()
00900 {
00901     CUDA_Cleanup_PrevVertexList();
00902 
00903     std::cout << "m_cudaPrevVertexList size: " << m_pHEVertexList->size() * 4 << "\n";
00904 
00905     unsigned int size = sizeof(float) * m_pHEVertexList->size() * 4;
00906 
00907     // Previous Vertex List
00908     m_cudaPrevVertexList = (float *)malloc( size );
00909     if ( m_cudaPrevVertexList ) {
00910         CUDA_CopyPrevVertexToMem();
00911         //for ( int i = 0; i < 10; ++i ) {
00912         //  int p = i*4;
00913         //  printf( "V#%d: %g %g %g %g\n", i, m_cudaPrevVertexList[p], m_cudaPrevVertexList[p+1], m_cudaPrevVertexList[p+2], m_cudaPrevVertexList[p+3] );
00914         //}
00915     }
00916     else {
00917         std::cout << "ERROR: Could not allocate memory for (Previous Vertex List) CUDA!" << std::endl;
00918         exit( -1 );
00919     }
00920 
00921     return true;    
00922 }
00923 
00924 template <typename T>
00925 bool HETriMeshOneModelMultiParts<T>::CUDA_Initialize_HomeVertexList ()
00926 {
00927     CUDA_Cleanup_HomeVertexList();
00928 
00929     std::cout << "m_cudaHomeVertexList size: " << m_pHEVertexList->size() * 4 << "\n";
00930 
00931     unsigned int size = sizeof(float) * m_pHEVertexList->size() * 4;
00932 
00933     // Home Vertex List
00934     m_cudaHomeVertexList = (float *)malloc( size );
00935     if ( m_cudaHomeVertexList ) {
00936         CUDA_CopyHomeVertexToMem();
00937     }
00938     else {
00939         std::cout << "ERROR: Could not allocate memory for (Home Vertex List) CUDA!" << std::endl;
00940         exit( -1 );
00941     }
00942 
00943     return true;    
00944 }
00945 
00946 template <typename T>
00947 bool HETriMeshOneModelMultiParts<T>::CUDA_Initialize_VertexConnectionList ()
00948 {
00949     CUDA_Cleanup_VertexConnectionList();
00950 
00951     // Find the maximum connection list of a vertex
00952     m_cudaMaxConnectionSize = (*m_pHEVertexList)[0]->GetListConnectedVertices().size();
00953     for ( int i = 1; i < static_cast<int>( m_pHEVertexList->size() ); ++i ) {
00954         if ( m_cudaMaxConnectionSize < (*m_pHEVertexList)[i]->GetListConnectedVertices().size() ) {
00955             m_cudaMaxConnectionSize = (*m_pHEVertexList)[i]->GetListConnectedVertices().size();
00956         }
00957     }
00958 
00959     std::cout << "m_cudaMaxConnectionSize: " << m_cudaMaxConnectionSize << "\n";
00960     std::cout << "m_cudaVertexConnectionList size: " << m_pHEVertexList->size() * m_cudaMaxConnectionSize << "\n";
00961 
00962     unsigned int size;
00963 #ifdef  TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
00964     size = sizeof(float) * m_pHEVertexList->size() * m_cudaMaxConnectionSize * 4;
00965     m_cudaVertexConnectionList = (float *)malloc( size );
00966 #else //TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
00967     size = sizeof(int) * m_pHEVertexList->size() * m_cudaMaxConnectionSize;
00968     m_cudaVertexConnectionList = (int *)malloc( size );
00969 #endif//TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
00970 
00971     // Vertex Connection List
00972     if ( m_cudaVertexConnectionList ) {
00973         CUDA_CopyVertexConnectionToMem();
00974     }
00975     else {
00976         std::cout << "ERROR: Could not allocate memory for (Vertex Connection List) CUDA!" << std::endl;
00977         exit( -1 );
00978     }
00979 
00980     return true;    
00981 }
00982 
00983 template <typename T>
00984 void HETriMeshOneModelMultiParts<T>::CUDA_Cleanup_All ()
00985 {
00986     CUDA_Cleanup_VertexList();
00987     CUDA_Cleanup_PrevVertexList();
00988     CUDA_Cleanup_HomeVertexList();
00989     CUDA_Cleanup_VertexConnectionList();
00990 }
00991 
00992 template <typename T>
00993 void HETriMeshOneModelMultiParts<T>::CUDA_Cleanup_VertexList ()
00994 {
00995     if ( m_cudaVertexList ) {
00996         free( m_cudaVertexList );
00997         m_cudaVertexList = NULL;
00998     }
00999 }
01000 
01001 template <typename T>
01002 void HETriMeshOneModelMultiParts<T>::CUDA_Cleanup_PrevVertexList ()
01003 {
01004     if ( m_cudaPrevVertexList ) {
01005         free( m_cudaPrevVertexList );
01006         m_cudaPrevVertexList = NULL;
01007     }
01008 }
01009 
01010 template <typename T>
01011 void HETriMeshOneModelMultiParts<T>::CUDA_Cleanup_HomeVertexList ()
01012 {
01013     if ( m_cudaHomeVertexList ) {
01014         free( m_cudaHomeVertexList );
01015         m_cudaHomeVertexList = NULL;
01016     }
01017 }
01018 
01019 template <typename T>
01020 void HETriMeshOneModelMultiParts<T>::CUDA_Cleanup_VertexConnectionList ()
01021 {
01022     if ( m_cudaVertexConnectionList ) {
01023         free( m_cudaVertexConnectionList );
01024         m_cudaVertexConnectionList = NULL;
01025         m_cudaMaxConnectionSize = 0;
01026     }
01027 }
01028 
01029 template <typename T>
01030 void HETriMeshOneModelMultiParts<T>::CUDA_CopyVertexToMem ()
01031 {
01032     if ( !m_cudaVertexList )    return;
01033     for ( unsigned int i = 0, p = 0; i < static_cast<unsigned int>( m_pHEVertexList->size() ); ++i ) {
01034         m_cudaVertexList[p++] = (*m_pHEVertexList)[i]->GetHEVertexPtr()->GetPosition()[0];
01035         m_cudaVertexList[p++] = (*m_pHEVertexList)[i]->GetHEVertexPtr()->GetPosition()[1];
01036         m_cudaVertexList[p++] = (*m_pHEVertexList)[i]->GetHEVertexPtr()->GetPosition()[2];
01037         m_cudaVertexList[p++] = 1;
01038     }
01039 }
01040 
01041 template <typename T>
01042 void HETriMeshOneModelMultiParts<T>::CUDA_CopyPrevVertexToMem ()
01043 {
01044     if ( !m_cudaPrevVertexList )    return;
01045     for ( unsigned int i = 0, p = 0; i < static_cast<unsigned int>( m_pHEVertexList->size() ); ++i ) {
01046         m_cudaPrevVertexList[p++] = (*m_pHEVertexList)[i]->GetHEVertexPtr()->GetPosition()[0];
01047         m_cudaPrevVertexList[p++] = (*m_pHEVertexList)[i]->GetHEVertexPtr()->GetPosition()[1];
01048         m_cudaPrevVertexList[p++] = (*m_pHEVertexList)[i]->GetHEVertexPtr()->GetPosition()[2];
01049         m_cudaPrevVertexList[p++] = 1;
01050     }
01051 }
01052 
01053 template <typename T>
01054 void HETriMeshOneModelMultiParts<T>::CUDA_CopyMemToVertex ()
01055 {
01056     if ( !m_cudaVertexList )    return;
01057     for ( unsigned int i = 0, p = 0; i < static_cast<unsigned int>( m_pHEVertexList->size() ); ++i ) {
01058         (*m_pHEVertexList)[i]->GetHEVertexPtr()->SetPosition( 
01059             m_cudaVertexList[p  ],
01060             m_cudaVertexList[p+1],
01061             m_cudaVertexList[p+2]
01062         );
01063         p += 4;
01064     }
01065 }
01066 
01067 template <typename T>
01068 void HETriMeshOneModelMultiParts<T>::CUDA_CopyMemToPrevVertex ()
01069 {
01070     if ( !m_cudaPrevVertexList )    return;
01071     for ( unsigned int i = 0, p = 0; i < static_cast<unsigned int>( m_pHEVertexList->size() ); ++i ) {
01072         (*m_pHEVertexList)[i]->GetHEVertexPtr()->SetPosition( 
01073             m_cudaPrevVertexList[p  ],
01074             m_cudaPrevVertexList[p+1],
01075             m_cudaPrevVertexList[p+2]
01076         );
01077         p += 4;
01078     }
01079 }
01080 
01081 template <typename T>
01082 void HETriMeshOneModelMultiParts<T>::CUDA_CopyHomeVertexToMem ()
01083 {
01084     if ( !m_cudaHomeVertexList )    return;
01085     for ( unsigned int i = 0, p = 0; i < static_cast<unsigned int>( m_pHEVertexList->size() ); ++i ) {
01086         //Vector3<T> worldPos = m_pHEVertexList)[i]->GetHomePosition();
01087         m_cudaHomeVertexList[p++] = (*m_pHEVertexList)[i]->GetHomePosition()[0];
01088         m_cudaHomeVertexList[p++] = (*m_pHEVertexList)[i]->GetHomePosition()[1];
01089         m_cudaHomeVertexList[p++] = (*m_pHEVertexList)[i]->GetHomePosition()[2];
01090         m_cudaHomeVertexList[p++] = 1;
01091     }
01092 }
01093 
01094 template <typename T>
01095 void HETriMeshOneModelMultiParts<T>::CUDA_CopyMemToHomeVertex ()
01096 {
01097     if ( !m_cudaHomeVertexList )    return;
01098     for ( unsigned int i = 0, p = 0; i < static_cast<unsigned int>( m_pHEVertexList->size() ); ++i ) {
01099         (*m_pHEVertexList)[i]->SetHomePosition( 
01100             Vector3<T> (
01101                 m_cudaHomeVertexList[p  ],
01102                 m_cudaHomeVertexList[p+1],
01103                 m_cudaHomeVertexList[p+2]
01104             )
01105         );
01106         p += 4;
01107     }
01108 }
01109 
01110 template <typename T>
01111 void HETriMeshOneModelMultiParts<T>::CUDA_CopyVertexConnectionToMem ()
01112 {
01113     if ( !m_cudaVertexConnectionList )  return;
01114 
01115 #ifdef  TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
01116     std::cout << "NOT IMPLEMENTED YET!" << " File: " << __FILE__ << " Line: " << __LINE__ << std::endl;
01117 #else //TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
01118     for ( unsigned int i = 0, p = 0; i < static_cast<unsigned int>( m_pHEVertexList->size() ); ++i, p+=m_cudaMaxConnectionSize ) {
01119         unsigned int n = 0;
01120         for ( ; n < static_cast<int>( (*m_pHEVertexList)[i]->GetListConnectedVertices().size() ); ++n ) {
01121             m_cudaVertexConnectionList[p+n] = (*m_pHEVertexList)[i]->GetListConnectedVertices()[n];
01122         }
01123         for ( ; n < m_cudaMaxConnectionSize; ++n ) {
01124             m_cudaVertexConnectionList[p+n] = -1;
01125         }
01126     }
01127 #endif//TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
01128 
01129 }
01130 
01131 /*
01132 template <typename T>
01133 void HETriMeshOneModelMultiParts<T>::CUDA_CopyMemToVertexConnection ()
01134 {
01135     if ( !m_cudaVertexConnectionList )  return;
01136 
01137 #ifdef  TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
01138     std::cout << "NOT IMPLEMENTED YET!" << " File: " << __FILE__ << " Line: " << __LINE__ << std::endl;
01139     //for ( int i = 0, p = 0; i < static_cast<int>( m_pHEVertexList->size() ); ++i, p+=m_cudaMaxConnectionSize ) {
01140     //  for ( int n = 0; n < static_cast<int>( (*m_pHEVertexList)[i]->GetListConnectedVertices().size() ); ++n ) {
01141     //      float fValue = m_cudaVertexConnectionList[p+n];
01142     //      int iVal = static_cast<int>(fVal);
01143     //      if ( fVal+0.5f >= iVal+1 ) {
01144     //          (*m_pHEVertexList)[i]->GetListConnectedVertices()[n] = iVal+1;
01145     //      }
01146     //      else {
01147     //          (*m_pHEVertexList)[i]->GetListConnectedVertices()[n] = iVal;
01148     //      }
01149 
01150     //  }
01151     //}
01152 #else //TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
01153     for ( int i = 0, p = 0; i < static_cast<int>( m_pHEVertexList->size() ); ++i, p+=m_cudaMaxConnectionSize ) {
01154         for ( int n = 0; n < static_cast<int>( (*m_pHEVertexList)[i]->GetListConnectedVertices().size() ); ++n ) {
01155             (*m_pHEVertexList)[i]->GetListConnectedVertices()[n] = m_cudaVertexConnectionList[p+n];
01156         }
01157     }
01158 #endif//TAPs_CUDA_MSS_INDIVIDUAL_SPRING_PROPS
01159 
01160 }
01161 //*/
01162 
01163 template <typename T>
01164 void HETriMeshOneModelMultiParts<T>::CUDA_SwapBuffers ()
01165 {
01166     float * tmpPtr = m_cudaVertexList;
01167     m_cudaVertexList = m_cudaPrevVertexList;
01168     m_cudaPrevVertexList = tmpPtr;
01169 }
01170 
01171 //-----------------------------------------------------------------------------
01172 #endif//TAPs_USE_CUDA
01173 //=============================================================================
01174 
01175 
01176 #ifdef  TAPs_USE_WXWIDGETS
01177 //=============================================================================
01178     template <typename T>
01179     void HETriMeshOneModelMultiParts<T>::ShowPropertyDialog ( wxWindow * parent )
01180     {
01181         if ( pDialogs == NULL ) {
01182             wxMessageDialog( NULL, "HETriMeshOneModelMultiParts' Property Dialog was not created!", "Info", wxOK );
01183             return;
01184         }
01185         if ( pDialogs->IsInitialized() ) {
01186             // If the dialog is shown, then close it.
01187             if ( pDialogs->IsShown() ) {
01188                 pDialogs->Close();
01189             }
01190             // If the dialog is not shown, then show it.
01191             else {
01192                 pDialogs->PropertyDialog<T>( parent, &GetTransform(), &GetListOfParts() );
01193             }
01194         }
01195         else {
01196             wxMessageDialog( NULL, "HETriMeshOneModelMultiParts' Property Dialog is not available!", "Info", wxOK );
01197         }
01198     }
01199 //=============================================================================
01200 #endif//TAPs_USE_WXWIDGETS
01201 
01202 //-----------------------------------------------------------------------------
01203 //=============================================================================
01204 END_NAMESPACE_TAPs__OpenGL
01205 //-----------------------------------------------------------------------------
01206 //34567890123456789012345678901234567890123456789012345678901234567890123456789
01207 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines