Biomechanical Joint Model
 Author: Anderson Maciel

comevertex3d.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 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 
00027 //   DATE........: June/05/2001
00031 
00032 #include <algebra/comevertex3d.h>
00033 #include <algebra/comematrix.h>
00034 #include <bio/comemolecule.h>
00035 #include <algebra/comemesh.h>
00036 #include <math.h>
00037 
00038 
00040 // Description: Class "COME_Vertex3D" constructor without parameter.
00041 // Parameters.: -
00042 // Return.....: -
00043 
00044 COME_Vertex3D::COME_Vertex3D( void ){
00045         x = 0;
00046     y = 0;
00047     z = 0;
00048         color[0] = .9;
00049         color[1] = .7;
00050         color[2] = .3;
00051         collide = true;
00052         ownerFace = 0;
00053         //collisionCount = 0;
00054         //velocityCount = 0;
00055 }
00056 
00058 // Description: Class "COME_Vertex3D" constructor with parameters.
00059 // Parameters.: double xi (initial x value), 
00060 //                              double yi (initial y value),
00061 //                              double zi (initial z value).
00062 // Return.....: -
00063 
00064 COME_Vertex3D::COME_Vertex3D( double xi, double yi, double zi) {
00065         x = xi;
00066     y = yi;
00067     z = zi;
00068         color[0] = .9;
00069         color[1] = .7;
00070         color[2] = .3;
00071         collide = true; 
00072         ownerFace = 0;
00073         //collisionCount = 0;
00074         //velocityCount = 0;
00075 }
00076 
00077 COME_Vertex3D::COME_Vertex3D( double xi, double yi, double zi, COME_Vector3D n) {
00078         x = xi;
00079     y = yi;
00080     z = zi;
00081         normal = n;
00082         color[0] = .9;
00083         color[1] = .7;
00084         color[2] = .3;
00085         collide = true; 
00086         ownerFace = 0;
00087         //collisionCount = 0;
00088         //velocityCount = 0;
00089 }
00090 
00091 
00092 
00094 // Description: Class "COME_Vertex3D" constructor with parameters.
00095 // Parameters.: COME_Vertex3D (object).
00096 // Return.....: -
00097 
00098 COME_Vertex3D::COME_Vertex3D(const COME_Vertex3D &v) {
00099         x = v.x ;
00100     y = v.y ;
00101     z = v.z ;
00102         normal = v.normal;
00103         normalGlobalPosition = v.normalGlobalPosition;
00104         texCoord = v.texCoord;
00105 
00106         color[0] = v.color[0];
00107         color[1] = v.color[1];
00108         color[2] = v.color[2];
00109         color[3] = v.color[3];
00110         
00111         ownerFace = v.ownerFace;
00112         anchors = v.anchors;
00113         localPositions = v.localPositions;
00114         
00115         pPlane = v.pPlane;
00116         collide = v.collide;
00117         collide = true;
00118         //collisionCount = v.collisionCount;
00119         //velocityCount = v.velocityCount;
00120 }
00121 
00123 // Description: Class "COME_Vertex3D" constructor with parameters.
00124 // Parameters.: COME_Vertex3D (object).
00125 // Return.....: -
00126 
00127 COME_Vertex3D::COME_Vertex3D( COME_Vertex3D *v ) {
00128         x = v->x ;
00129     y = v->y ;
00130     z = v->z ;
00131         normal = v->normal;
00132         normalGlobalPosition = v->normalGlobalPosition;
00133 
00134         color[0] = v->color[0];
00135         color[1] = v->color[1];
00136         color[2] = v->color[2];
00137         color[3] = v->color[3];
00138         
00139         ownerFace = v->ownerFace;
00140         anchors = v->anchors;
00141         localPositions = v->localPositions;
00142         
00143         pPlane = v->pPlane;
00144         collide = v->collide;
00145         collide = true;
00146         //collisionCount = v->collisionCount;
00147         //velocityCount = v->velocityCount;
00148 }
00149 
00150 
00152 // Description: Operator=
00153 // Parameters.: COME_Vertex3D (object).
00154 // Return.....: COME_Vertex3D (object).
00155 
00156 COME_Vertex3D& COME_Vertex3D :: operator= ( COME_Vertex3D& v ) {
00157 
00158         if ( this == &v ) return ( *this ) ;
00159         
00160         x = v.x ;
00161         y = v.y ;
00162         z = v.z ;
00163         anchors=v.anchors;
00164         normal=v.normal;
00165         normalGlobalPosition=v.normalGlobalPosition;
00166         localPositions = v.localPositions;
00167         neighbourFaces= v.neighbourFaces;
00168         ownerFace = v.ownerFace;
00169         color[0] = v.color[0];
00170         color[1] = v.color[1];
00171         color[2] = v.color[2];
00172         color[3] = v.color[3];
00173         
00174         pPlane = v.pPlane;
00175         collide = collide;
00176         //collisionCount = v.collisionCount;
00177         //velocityCount = v.velocityCount;
00178         
00179         return ( *this ) ;
00180 }
00181 
00182 
00184 // Description: Operator=
00185 // Parameters.: COME_Vector3D (object).
00186 // Return.....: COME_Vertex3D (object).
00187 
00188 COME_Vertex3D& COME_Vertex3D :: operator= ( const COME_Vector3D& v ) {
00189       if ( this == (COME_Vertex3D *)&v ) return ( *this ) ;
00190       x = v.x ;
00191       y = v.y ;
00192       z = v.z ;
00193       return ( *this ) ;
00194 }
00195 
00197 // Description: Operator+=
00198 // Parameters.: COME_Vector3D (object).
00199 // Return.....: COME_Vertex3D (object).
00200 
00201 COME_Vertex3D& COME_Vertex3D :: operator+= ( const COME_Vector3D& v ) {
00202       if ( this == (COME_Vertex3D *)&v ) return ( *this ) ;
00203       x += v.x ;
00204       y += v.y ;
00205       z += v.z ;
00206       return ( *this ) ;
00207 }
00208 
00209 
00210 void
00211 COME_Vertex3D::setNormal( COME_Vector3D n ){
00212 
00213         normal = n;
00214 }
00215 
00216 void
00217 COME_Vertex3D::setCollisionDisp( COME_Vector3D c ){
00218 
00219         collisionDisp = c;
00220         /*if( ( c.x == 0.0 ) && ( c.y == 0.0 ) && ( c.z == 0.0 ) )
00221                 collisionCount = 0;
00222         else
00223                 collisionCount = 1;*/
00224 }
00225 
00226 void
00227 COME_Vertex3D::setVelocityDisp( COME_Vector3D c ){
00228 
00229         velocityDisp = c;
00230         /*if( ( c.x == 0.0 ) && ( c.y == 0.0 ) && ( c.z == 0.0 ) )
00231                 velocityCount = 0;
00232         else
00233                 velocityCount = 1;*/
00234 }
00235 
00236 void
00237 COME_Vertex3D::addCollisionDisp( COME_Vector3D c ){
00238 
00239         //collisionDisp += c;
00240         //collisionCount++;
00241         
00242         if( c.vpModule() > collisionDisp.vpModule() ) collisionDisp = c;
00243 }
00244 
00245 void
00246 COME_Vertex3D::addVelocityDisp( COME_Vector3D c ){
00247 
00248         //velocityDisp += c;
00249         //velocityCount++;
00250         
00251         if( c.vpModule() > velocityDisp.vpModule() ) velocityDisp = c;
00252 }
00253 
00254 double*
00255 COME_Vertex3D::getColor( void ){
00256         return color;
00257 }
00258 
00259 void 
00260 COME_Vertex3D::setColor (double *c){
00261         color[0] = c[0];
00262         color[1] = c[1];
00263         color[2] = c[2];
00264         color[3] = c[3];
00265 }
00266 void
00267 COME_Vertex3D::setNormalGlobalPosition( COME_Vector3D n ){
00268 
00269         normalGlobalPosition = n;
00270 }
00271 
00272 void
00273 COME_Vertex3D::setOwnerFace( int index ){
00274 
00275         ownerFace = index;
00276 }
00277 
00278 void
00279 COME_Vertex3D::setTexCoord( COME_Point2D newUV ){
00280 
00281         texCoord = newUV;
00282 }
00283 
00284 void
00285 COME_Vertex3D::setCollide( bool yesno ){
00286         
00287         collide = yesno;
00288 }
00289 
00290 void
00291 COME_Vertex3D::addAnchor( COME_Molecule* newAnchor ){
00292 
00293         anchors.push_back( newAnchor );
00294         //newAnchor->addBuoy( this );
00295 }
00296 
00297 void
00298 COME_Vertex3D::addLocalPosition( COME_Point3D newPosition ){
00299 
00300         localPositions.push_back( newPosition );
00301 }
00302 
00303 bool
00304 COME_Vertex3D::getCollide(){
00305         
00306         return collide;
00307 }
00308 
00309 COME_Vector3D
00310 COME_Vertex3D::getNormal( void ){
00311 
00312         return normal;
00313 }
00314 
00315 COME_Vector3D
00316 COME_Vertex3D::getCollisionDisp( void ){
00317 
00318         return collisionDisp;
00319 }
00320 
00321 COME_Vector3D
00322 COME_Vertex3D::getVelocityDisp( void ){
00323 
00324         return velocityDisp;
00325 }
00326 
00327 COME_Vector3D
00328 COME_Vertex3D::getCollisionDispAvg( void ){
00329 
00330         //if( collisionCount == 0 ) return COME_Vector3D();
00331         //printf( "dispCollision: %f %f %f count %d \n", collisionDisp.x, collisionDisp.y, collisionDisp.z, collisionCount );
00332         return collisionDisp;// / (double)collisionCount;
00333 }
00334 
00335 COME_Vector3D
00336 COME_Vertex3D::getBlendedVelocity( void ){
00337 
00338         COME_Vector3D blendedVelocity;
00339         double sumDists = 0.0;
00340 
00341         int i;
00342         for( i = 0; i < localPositions.size(); i++ ){
00343 
00344                 sumDists += pow( localPositions[i].vpDistance( COME_Point3D() ), 2.0 );
00345         }
00346         
00347         for( int i = 0; i < localPositions.size(); i++ ){
00348 
00349                 double wi = ( 1.0 - ( ( pow( localPositions[i].vpDistance( COME_Point3D() ), 2.0 ) ) / sumDists ) ) / (double)(localPositions.size()-1);
00350                 blendedVelocity = blendedVelocity + ( anchors[i]->getVelocity() * wi );
00351         }
00352 
00353         return blendedVelocity;
00354 }
00355 
00356 COME_Vector3D
00357 COME_Vertex3D::getVelocityDispAvg( void ){
00358 
00359         //if( velocityCount == 0 ) return COME_Vector3D();
00360         //printf( "dispVelocity: %f %f %f count %d \n", velocityDisp.x, velocityDisp.y, velocityDisp.z, velocityCount );
00361         return velocityDisp; // / (double)velocityCount;
00362 }
00363 
00364 COME_Vector3D*
00365 COME_Vertex3D::getNormalGlobalPositionPt( void ){
00366 
00367         return &normalGlobalPosition;
00368 }
00369 
00370 COME_Vector3D
00371 COME_Vertex3D::getNormalGlobalPosition( void ){
00372 
00373         return normalGlobalPosition;
00374 }
00375 
00376 int
00377 COME_Vertex3D::getOwnerFace( void ){
00378 
00379         return ownerFace;
00380 }
00381 
00382 vector<COME_Molecule*>&
00383 COME_Vertex3D::getAnchors( void ){
00384 
00385         return anchors;
00386 }
00387 
00388 vector<COME_Molecule*>*
00389 COME_Vertex3D::getAnchorsPt( void ){
00390 
00391         return &anchors;
00392 }
00393 
00394 vector<COME_Point3D>&
00395 COME_Vertex3D::getLocalPositions( void ){
00396 
00397         return localPositions;
00398 }
00399 
00400 COME_Point2D
00401 COME_Vertex3D::getTexCoord( void ){
00402 
00403         return texCoord;
00404 }
00405 
00406 bool
00407 COME_Vertex3D::hasFixedAnchor( void ){
00408 
00409         for( int i = 0; i < anchors.size(); i++ ){
00410 
00411                 if( anchors[i]->isFixed() )
00412                         return true;
00413         }
00414 
00415         return false;
00416 }
00417 
00418 double
00419 COME_Vertex3D::getStress( void ){
00420 
00421         double localStress = 0.0;
00422         for( int i = 0; i < anchors.size(); i++ ){
00423 
00424                 localStress += anchors[i]->getStress();
00425         }
00426 
00427         return ( localStress / ((double) anchors.size() ) );
00428 }
00429 
00430 double
00431 COME_Vertex3D::getStrain( void ){
00432 
00433         double localStrain = 0.0;
00434         for( int i = 0; i < anchors.size(); i++ ){
00435 
00436                 localStrain += anchors[i]->getStrain();
00437         }
00438 
00439         return ( localStrain / ((double) anchors.size() ) );
00440 }
00441 
00442 COME_Vector3D
00443 COME_Vertex3D::getColorMaterial( void ){
00444 
00445         if( anchors.size() ){
00446 
00447                 return anchors[0]->getMaterial()->getColor();
00448         }
00449 
00450         return COME_Vector3D(1, 1, 1);
00451 }
00452 
00456 COME_Point3D
00457 COME_Vertex3D::getBlendedPosition( void ){
00458 
00459         COME_Point3D blendedPoint;
00460         double w = 0;
00461 
00462         for( int i = 0; i < localPositions.size(); i++ ){
00463 
00464                 double wi = ( 1.0 / localPositions[i].vpDistance( COME_Point3D() ) );
00465                 blendedPoint = blendedPoint + ( ( (*anchors[i]->getLocalFrame()) * localPositions[i] ) * wi );
00466                 w += wi;
00467         }
00468 
00469         return ( blendedPoint * (1.0/w) );
00470 }
00471 
00472 void
00473 COME_Vertex3D:: addNeighbour(int faceIndex, COME_Mesh *theMesh ){
00474         
00475         neighbourFaces.push_back(faceIndex);
00476         
00477         COME_Face *theFace = theMesh->getAFacePt( faceIndex );
00478         for( int iF = 0; iF < theFace->getNumberVertices(); iF ++ ){
00479         
00480                 COME_Vertex3D* theVertex = theFace->getVertexGlobalPositionPt(iF);
00481                 if(  theVertex != this ){
00482                         neighborVerts.push_back( theVertex );
00483                 }
00484         }
00485 }
00486 
00487 vector<int>
00488 COME_Vertex3D:: getNeighbourFaces(){
00489         return neighbourFaces;
00490 }
00491 
00492 vector<COME_Vertex3D *>
00493 COME_Vertex3D:: getNeighborVerts(){
00494         return neighborVerts;
00495 }
00496 
00497 COME_Point3D
00498 COME_Vertex3D::getVertexAsPoint3D(){
00499 
00500         return COME_Point3D( x, y, z );
00501 }
00502 
00503 bool
00504 COME_Vertex3D::anchorsCollide(){
00505 
00506         for( int i = 0; i < anchors.size(); i++ ){
00507         
00508                 if( anchors[i]->isCollide() )
00509                         return true;
00510         }
00511         return false;
00512         
00513 }
00514 
00515 COME_Vertex3D *
00516 COME_Vertex3D:: getNeighborClosestTo( COME_Vertex3D *vPos ){
00517 
00518         double distMin = this->vpDistance( vPos->getVertexAsPoint3D() );
00519         COME_Vertex3D * vClosest = this;
00520         
00521         for( int iNV = 0; iNV < neighborVerts.size(); iNV++ ){
00522         
00523                 if( neighborVerts[iNV]->vpDistance( vPos->getVertexAsPoint3D() ) < distMin ){
00524                         distMin = neighborVerts[iNV]->vpDistance( vPos->getVertexAsPoint3D() );
00525                         vClosest = neighborVerts[iNV];
00526                 }
00527         }
00528         return vClosest;
00529 }

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