Biomechanical Joint Model
 Author: Anderson Maciel

comeclamp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Anderson Maciel                                 *
00003  *   andi.maciel@gmail.com                                                   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include        <bio/comeclamp.h>
00021 #include        <general/comescenario.h>
00022 #include        <algebra/comemesh.h>
00023 #include        <RAPID/RAPID.H>
00024 
00028 
00029 COME_Clamp::COME_Clamp(){
00030 
00031         tissue = new COME_MoleculesTissue();
00032         surface = NULL;
00033 }
00034 
00035 COME_MoleculesTissue*
00036 COME_Clamp::getTissue(){
00037 
00038         return tissue;
00039 }
00040 
00041 
00042 //Recalculates the Mesh based on the new positions of anchoring the molecules
00043 void 
00044 COME_Clamp:: updateSkin(){
00045         surface->updateSkin();
00046 }
00047 
00051 void
00052 COME_Clamp::updateSurface( bool regenerate ){
00053 
00054 //      if( regenerate ){
00055 //              updateSurface( 1.0, 150.0, 0.005 ); //1.0  120.0 0.005  
00056 //              surface.estabilishLinkVerticesFaces();
00057 
00058                 // para os pequenos 1.0, 80.0, 0.005
00059                 // para os grandes 1.0, 160.0, 0.01
00060                 //collision:   //2.3  (15)
00061 
00062 //      } else {
00063                 //generateEnvelopSurface();
00064 //      }
00065   
00066 }
00067 
00068 
00072 void
00073 COME_Clamp::getEnvelop( COME_Point3D& mins, COME_Point3D& maxs ){
00074 
00075         surface->getEnvelop( mins, maxs );
00076 }
00077 
00081 void
00082 COME_Clamp::initializeSkinning(){
00083 
00084         cout << "initialising Faces Neighbours...";
00085         this->getPointerToSurface()->initFacesNeighbours();
00086         cout << "done \ninitialising Vertices Neighbours...";
00087         this->getPointerToSurface()->initVerticesNeighbours();
00088         cout << "done\n";
00089 }
00090 
00100 
00101 bool
00102 COME_Clamp::update( double timestep, double simClock ){
00103 
00104 /*
00105         double xh , hh, h6;
00106         COME_Vector3D *dymV, *dymF, *dymT, *dymW;
00107         
00108         COME_Vector3D *dytV, *dytF, *dytT, *dytW;
00109         
00110         COME_Vector3D *ytX, *ytL, *ytP;
00111         COME_Matrix *ytR;
00112 
00113         dymV = new COME_Vector3D();
00114         dymF = new COME_Vector3D();
00115         dymT = new COME_Vector3D();
00116         dymW = new COME_Vector3D();
00117         
00118         dytV = new COME_Vector3D();
00119         dytF = new COME_Vector3D();
00120         dytT = new COME_Vector3D();
00121         dytW = new COME_Vector3D();
00122         
00123         ytX = new COME_Vector3D();
00124         ytL = new COME_Vector3D();
00125         ytP = new COME_Vector3D();
00126         ytR = new COME_Matrix();
00127 
00128         COME_Vector3D momentumTemp;
00129         COME_Vector3D w;
00130 
00131         //COME_Matrix I = COME_Matrix( rotationMatrix * inertiaTensor * rotationMatrix.getTransposed() );
00132 
00133         hh = timestep * 0.5;
00134         h6 = timestep / 6.0;
00135         xh = simClock + hh;
00136         
00137         // First step //////////////////////////////////////////////////////
00138         
00139         ytX->setVector3D( ( linearVelocity * hh ) + massCenter );
00140         ytL->setVector3D( rotationMatrix * inertiaTensor * rotationMatrix.getTransposed() * angularVelocity );
00141         momentumTemp.setVector3D( *ytL ); // save initial momentum
00142         ytP->setVector3D( linearVelocity * tissue->getMass() );
00143         ytR->setMatrix( rotationMatrix );
00144         
00145         // Second step //////////////////////////////////////////////////////
00146         derivs( xh, hh, ytX, ytL, ytP, ytR, dytV, dytF, dytT, dytW ); 
00147 
00148         ytX->setVector3D( ( *dytV * hh ) + massCenter );
00149         ytL->setVector3D( *dytW * *ytR * inertiaTensor * (*dytW * ytR->getTransposed() ) * *dytW );
00150         ytP->setVector3D( *dytV * tissue->getMass() );
00151         ytR->setMatrix( rotationMatrix );//*ytR += (*dytW); // probably non-correct
00152 
00153         // Third step //////////////////////////////////////////////////////
00154         derivs( xh, hh, ytX, ytL, ytP, ytR, dymV, dymF, dymT, dymW ); 
00155 
00156         ytX->setVector3D( ( *dymV * timestep ) + massCenter );
00157         ytL->setVector3D( *dymW * *ytR * inertiaTensor * (*dymW * ytR->getTransposed() ) * *dymW );
00158         ytP->setVector3D( *dymV * tissue->getMass() );
00159         ytR->setMatrix( rotationMatrix );//ytR->setMatrix( *( dymWR->add( *ytR ) ) );
00160 
00161         *dymV += *dytV;
00162         *dymF += *dytF;
00163         *dymT += *dytT;
00164         *dymW += *dytW;
00165 
00166 
00167         // Fourth step //////////////////////////////////////////////////////
00168         derivs( simClock + timestep, timestep, ytX, ytL, ytP, ytR, dytV, dytF, dytT, dytW ); 
00169 
00170         massCenter = ( ( linearVelocity + *dytV + ( *dymV * 2.0 ) ) * h6 ) + massCenter;
00171         COME_Vector3D rotatedVec = COME_Vector3D( angularVelocity * rotationMatrix );
00172         rotationMatrix = ( ( angularVelocity + (*dytW * *ytR) + ( *dymW * *ytR * 2.0 ) ) * h6 ).transMult( rotatedVec );
00173         angularVelocity =  rotationMatrix * inertiaTensor.getInverse() * rotationMatrix.getTransposed() * momentumTemp;
00174         linearVelocity = ( ( linearVelocity + *dytV + ( *dymV * 2.0 ) ) * h6 ) * tissue->getMass();
00175                 
00176         delete dymV;
00177         delete dymF;
00178         delete dymT;
00179         delete dymW;
00180         
00181         delete dytV; 
00182         delete dytF;
00183         delete dytT;
00184         delete dytW;
00185 
00186         delete ytX;
00187         delete ytL;
00188         delete ytP;
00189         delete ytR;
00190 */
00191         return true;
00192 }
00193 
00194 void
00195 COME_Clamp::respondCollision(){
00196 
00197         // do nothing, just to respond to virtual function declaration 
00198 }

Generated on Thu Dec 1 10:13:33 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5