Biomechanical Joint Model
 Author: Anderson Maciel

come_modeljointqglwidget.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 <come_modeljointqglwidget.h>
00021 #include <comemodeljoint.h>
00022 #include <general/comescenario.h>
00023 #include <general/comesimulator.h>
00024 #include <kinematics/comepolyaxialjoint.h>
00025 #include <physics/comecollide.h>
00026 #include <kinematics/comedof.h>
00027 //#include <physics/comeproximity.h>
00028 #include <qcheckbox.h>
00029 #include <qtimer.h>
00030 #include <qcursor.h>
00031 #include <qslider.h>
00032 #include <qpopupmenu.h>
00033 #include <qspinbox.h>
00034 #include <qstatusbar.h>
00035 #include <qlistbox.h>
00036 #include <qradiobutton.h>
00037 #include <qlcdnumber.h>
00038 #include <qpushbutton.h>
00039 #include <qfont.h>
00040 #include <GL/glut.h>
00041 
00042 double oldClock;
00043 
00044 COME_ModelJointQGLWidget::COME_ModelJointQGLWidget( QWidget *parent, const char *name )
00045  : COME_QGLWidget( parent, name )
00046 {
00047         oldClock = 0.0;
00048 }
00049 
00050 
00051 COME_ModelJointQGLWidget::~COME_ModelJointQGLWidget()
00052 {
00053 }
00054 
00055 void
00056 COME_ModelJointQGLWidget::draw(){
00057 
00058         //CGparameter 
00059         //cgGLSetParameter3fv(cgGetNamedParameter(fragmentProgram, "lightColor"), lightColor);
00060         
00061         if( scene ){
00062 
00063                 // Display simulation data
00064                 if( (((COME_ModelJoint*)getGlobal())->sim ) && ( ((COME_ModelJoint*)getGlobal())->sim->isRunning() ) ){
00065                         
00066                         char chrClock[10];
00067                         sprintf( chrClock, "%2.4f", ((COME_ModelJoint*)getGlobal())->sim->getClock() );
00068                         ((COME_ModelJoint*)getGlobal())->lcdForceClock->display(chrClock);
00069                 } else {
00070                         if( ((COME_ModelJoint*)getGlobal())->sim->getStop() ){
00071                                 ((COME_ModelJoint*)getGlobal())->bpStartForce->setDown( false );
00072                                 ((COME_ModelJoint*)getGlobal())->sim->setStop(false);
00073                         }
00074                 }
00075 
00076                 scene->lock();
00077                 
00078                 
00080                 glDisable(GL_LIGHTING);
00081                 if (((COME_ModelJoint*)getGlobal())->cbProximities->isChecked()){
00082                         vector<COME_Proximity>* drawPS = scene->getCollisionDetector()->getProximityStructurePt();
00083                         for( int iPS = 0; iPS < drawPS->size(); iPS++ ){
00084                 
00085                                 COME_Point3D bPosition = ((*drawPS)[iPS].pointOnB);
00086                                 COME_Point3D aPosition = (*((*drawPS)[iPS].objA));
00087                                 
00088                                 glBegin(GL_LINES);
00089                                         glColor3f(1.0,1.0,1.0);
00090                                         glVertex3f(aPosition.x,aPosition.y,aPosition.z);
00091                                         glVertex3f(bPosition.x, bPosition.y, bPosition.z);
00092                                 glEnd();
00093 
00094                                 glPushMatrix();
00095                                         glTranslatef(bPosition.getX(),bPosition.getY(),bPosition.getZ());
00096                                         glColor3f(0,1,1);
00097                                         glutSolidSphere(0.02*((double)((COME_ModelJoint*)getGlobal())->sliderScale->value()/100.0), 15, 15);
00098                                 glPopMatrix();
00099                                 
00100                                 /*for( int iNF = 0; iNF < (*drawPS)[iPS].faceB->getNeighbourFaces().size(); iNF++ ){
00101                                 
00102                                         COME_Point3D pSphere = ((COME_Mesh*)((*drawPS)[iPS].faceB->getParent()))->getAFacePt( (*drawPS)[iPS].faceB->getNeighbourFaces()[iNF] )->getClosestPointOnFaceToPoint( aPosition );
00103                                         glPushMatrix();
00104                                                 glTranslatef(pSphere.getX(),pSphere.getY(),pSphere.getZ());
00105                                                 glColor3f(0,0,0);
00106                                                 glutSolidSphere(0.02*((double)((COME_ModelJoint*)getGlobal())->sliderScale->value()/100.0), 15, 15);
00107                                         glPopMatrix();
00108                                         
00109                                 }*/
00110                         }
00111                 }
00112                 glEnable(GL_LIGHTING);
00113                 
00115                 
00116                 int offset = 20;
00117                 char chrType[100];
00118                 strcpy( chrType, "0.0");
00119                 QString lineStress = "";
00120                 int organName = 0;
00121                 for( int iP = 0; iP < scene->getPatientList()->size(); iP++ ){
00122                         
00123                         glDisable(GL_LIGHTING);
00124                                 glColor3f( 1, 1, 1 );
00125                                 drawText(10,400, "Top stresses (failure stress) [kPa]:" );
00126                                 
00127                                 COME_Joint *hipjoint = scene->getPatient(iP)->getJointByName("hip");
00128                                 if( hipjoint ){
00129                                         COME_Point3D jointStatus = ((COME_PolyaxialJoint *)hipjoint)->getCurrentAngles();
00130                                         drawText(width()-100,460, "Hip angles:" );
00131                                         sprintf( chrType, "Ext/Flex: %4.2f°", jointStatus.x );
00132                                         drawText(width()-100,460+offset*1, chrType );
00133                                         sprintf( chrType, "Add/Abd: %4.2f°", jointStatus.y );
00134                                         drawText(width()-100,460+offset*2, chrType );
00135                                         sprintf( chrType, "Int/Ext rot: %4.2f°", jointStatus.z );
00136                                         drawText(width()-100,460+offset*3, chrType );
00137                                 }
00138                         glEnable(GL_LIGHTING);
00139                         
00140                         //Main loop: For each organ display the object
00141                         list<COME_BioStructure*>::const_iterator iterOrgans;
00142                         
00143                         for( iterOrgans = ((list<COME_BioStructure *>*)scene->getPatient(iP)->getPtOrganList())->begin(); iterOrgans != ((list<COME_BioStructure *>*)scene->getPatient(iP)->getPtOrganList())->end(); iterOrgans++  ){
00144                                 glDisable(GL_LIGHTING);
00145                                         glColor3f( 1, 1, 1 );
00146                                         if( (*iterOrgans)->getTissue()->getShape()->size() > 0 )
00147                                                 sprintf( chrType, "%10.1f (%10.1f )", (*iterOrgans)->getTopStress()/1000.0, (*iterOrgans)->getTissue()->getMoleculesMaterial()->getMaxStress()/1000.0 );
00148                                         else
00149                                                 sprintf( chrType, "Not computed for bone." );
00150                                         lineStress = QString( (*iterOrgans)->getDescription().c_str() ) + QString( ": " ) + QString( chrType );
00151                                         drawText(10,420 + offset*organName, lineStress );
00152                                         
00153                                         // ROM stuff
00154                                         if( (*iterOrgans)->getTissue()->getShape()->size() > 0 ){
00155                                                 if ( hipjoint ) { 
00156                                                         COME_Point3D currentStatus = ((COME_PolyaxialJoint *)hipjoint)->getCurrentAngles();
00157                                                         if( !( ( (*iterOrgans)->getTopStress() >= (*iterOrgans)->getTissue()->getMoleculesMaterial()->getMaxStress() ) && (((COME_ModelJoint*)getGlobal())->cbStressLimit->isChecked()) )){
00158                                                         
00159                                                                 double fMin, fMax, aMin, aMax, tMin, tMax;
00160                                                                 if( currentStatus.x < ( hipjoint->getDofList()[0]->getComfortMin() * 180.0 / M_PI ) )
00161                                                                         hipjoint->getDofList()[0]->setComfortMin( currentStatus.x * M_PI / 180.0 );
00162                                                                 if( currentStatus.x > ( hipjoint->getDofList()[0]->getComfortMax() * 180.0 / M_PI ) )
00163                                                                         hipjoint->getDofList()[0]->setComfortMax( currentStatus.x * M_PI / 180.0 );
00164                                                                 
00165                                                                 if( currentStatus.y < ( hipjoint->getDofList()[1]->getComfortMin() * 180.0 / M_PI ) )
00166                                                                         hipjoint->getDofList()[1]->setComfortMin( currentStatus.y * M_PI / 180.0 );
00167                                                                 if( currentStatus.y > ( hipjoint->getDofList()[1]->getComfortMax() * 180.0 / M_PI ) )
00168                                                                         hipjoint->getDofList()[1]->setComfortMax( currentStatus.y * M_PI / 180.0 );
00169                                                                 
00170                                                                 if( currentStatus.z < ( hipjoint->getDofList()[2]->getComfortMin() * 180.0 / M_PI ) )
00171                                                                         hipjoint->getDofList()[2]->setComfortMin( currentStatus.z * M_PI / 180.0 );
00172                                                                 if( currentStatus.z > ( hipjoint->getDofList()[2]->getComfortMax() * 180.0 / M_PI ) )
00173                                                                         hipjoint->getDofList()[2]->setComfortMax( currentStatus.z * M_PI / 180.0 );
00174                                                         
00175                                                         } else if ( (*iterOrgans)->getTissue()->getMoleculesMaterial()->getMaxStress() > 0.0 ) {
00176                                                                 printf( "Limit found!! ROM by stress: F/E[%4.2f° %4.2f°] A/A[%4.2f° %4.2f°] T[%4.2f° %4.2f°] \n",
00177                                                                 hipjoint->getDofList()[0]->getComfortMin() * 180.0 / M_PI,
00178                                                                 hipjoint->getDofList()[0]->getComfortMax() * 180.0 / M_PI,
00179                                                                 hipjoint->getDofList()[1]->getComfortMin() * 180.0 / M_PI,
00180                                                                 hipjoint->getDofList()[1]->getComfortMax() * 180.0 / M_PI,
00181                                                                 hipjoint->getDofList()[2]->getComfortMin() * 180.0 / M_PI,
00182                                                                 hipjoint->getDofList()[2]->getComfortMax() * 180.0 / M_PI );
00183                                                         }
00184                                                         
00185                                                         sprintf( chrType, "ROM by stress: F/E[%4.2f° %4.2f°] A/A[%4.2f° %4.2f°] T[%4.2f° %4.2f°]",
00186                                                                 hipjoint->getDofList()[0]->getComfortMin() * 180.0 / M_PI,
00187                                                                 hipjoint->getDofList()[0]->getComfortMax() * 180.0 / M_PI,
00188                                                                 hipjoint->getDofList()[1]->getComfortMin() * 180.0 / M_PI,
00189                                                                 hipjoint->getDofList()[1]->getComfortMax() * 180.0 / M_PI,
00190                                                                 hipjoint->getDofList()[2]->getComfortMin() * 180.0 / M_PI,
00191                                                                 hipjoint->getDofList()[2]->getComfortMax() * 180.0 / M_PI
00192                                                         );
00193                                                         lineStress = (*iterOrgans)->getDescription().c_str() + QString( chrType );
00194                                                         drawText(150, 20 + offset*organName, lineStress );
00195                                                 }
00196                                         }
00197                                 
00198                                 glEnable(GL_LIGHTING);
00199                                 
00200                                 list<COME_Molecule*>::const_iterator iterCells;
00201                                 glPushName(organName++);
00202 
00203                                 // testing collision volume sphere
00204                                 if (((COME_ModelJoint*)getGlobal())->cbCollisionVolume->isChecked()){
00205                                         glutSolidSphere((*iterOrgans)->getCollisionRadius(), 15, 15);
00206                                 }
00207 
00208                                 //Draw the Sphere Model                 
00209                                 if (((COME_ModelJoint*)getGlobal())->cbSpheres->isChecked()){
00210                                         for ( iterCells = (*iterOrgans)->getTissue()->getShape()->begin(); iterCells != (*iterOrgans)->getTissue()->getShape()->end(); iterCells++ ){
00211                                                 
00212                                                 //if( !( (*iterOrgans)->getDescription() == "pubofemoral" ) ) continue ; // used for RNW04 demo to highlight ligament
00213                                         
00214                                                 COME_Point3D position = (*iterCells)->getGlobalPosition();
00215                                                 glPushMatrix();
00216                                                         glTranslatef(position.getX(),position.getY(),position.getZ());
00217 
00218                                                         if( (*iterCells)->intersectClamp() || (*iterCells)->isFixed() ){
00219                                                                 glColor3f( 1.0 - (*iterCells)->getMaterial()->getColor().getPointAsArray()[0], 1.0 - (*iterCells)->getMaterial()->getColor().getPointAsArray()[1], 1.0 - (*iterCells)->getMaterial()->getColor().getPointAsArray()[2]);
00220                                                                 if( (*iterCells)->intersectClamp() || (*iterCells)->getDescription() == "origin" ){
00221                                                                         glColor3f( 1.0 - (*iterCells)->getMaterial()->getColor().getPointAsArray()[0], (*iterCells)->getMaterial()->getColor().getPointAsArray()[1], 1.0 - (*iterCells)->getMaterial()->getColor().getPointAsArray()[2]);
00222                                                                 }
00223                                                         } else {
00224                                                                 glColor3f((*iterCells)->getMaterial()->getColor().getPointAsArray()[0],(*iterCells)->getMaterial()->getColor().getPointAsArray()[1],(*iterCells)->getMaterial()->getColor().getPointAsArray()[2]);
00225                                                         }
00226                                                         glutSolidSphere((*iterCells)->getRadius()*((double)((COME_ModelJoint*)getGlobal())->sliderScale->value()/100.0), 15, 15);
00227                                                 glPopMatrix();
00228                                                 
00229                                                 // TEMP draw displacements
00230                                                 /*COME_Point3D dispPosition = (*iterCells)->getINITPositionGlobal();
00231                                                 glBegin(GL_LINES);
00232                                                         glColor3f(1.0,1.0,1.0);
00233                                                         glVertex3f(position.x,position.y,position.z);
00234                                                         glVertex3f(dispPosition.x, dispPosition.y, dispPosition.z);
00235                                                 glEnd();*/
00236                                                 
00237                                                 if( ((COME_ModelJoint*)getGlobal())->cbLinks->isChecked() ){
00238                                                         glDisable(GL_LIGHTING);
00239                                                         list<COME_MoleculeLink*>::iterator iterThis;
00240                                                         for(iterThis = (*iterCells)->getConnectionList()->begin(); !( iterThis == (*iterCells)->getConnectionList()->end() ); iterThis++){
00241                                                                 COME_Point3D position2 = (*iterThis)->getOtherElement((*iterCells))->getGlobalPosition();
00242                                                                 glBegin(GL_LINES);
00243                                                                         glColor3f(0.9,0.9,0.9);
00244                                                                         glVertex3f(position.getX(),position.getY(),position.getZ());
00245                                                                         glVertex3f(position2.getX(),position2.getY(),position2.getZ());
00246                                                                 glEnd();
00247                                                         }
00248                                                         glEnable(GL_LIGHTING);
00249                                                 }
00250                                         }
00251                                 }
00252         
00253         
00254                                 //Draw the Mesh Model
00255                                 if (((COME_ModelJoint*)getGlobal())->cbMesh->isChecked()){
00256                                 
00257                                         if (((COME_ModelJoint*)getGlobal())->cbTexture->isChecked()){
00258                                                 glEnable(GL_TEXTURE_2D);
00259                                         }
00260                                         
00261                                         COME_Mesh* mesh = (*iterOrgans)->getPointerToSurface();
00262                                         if( mesh ){
00263                                                 glBindTexture(GL_TEXTURE_2D, *(mesh->getTextureID()) ); 
00264                                                 vector <COME_Face> faces = mesh->getFaces();
00265                                                 vector<COME_Vertex3D>* allVertices = mesh->getVerticesGlobalPt();
00266                 
00267                                                 for (int i = 0; faces.size()> i; i++){
00268                                                         
00269                                                         //glColor3f(faces[i].getColor()[0],faces[i].getColor()[1],faces[i].getColor()[2]);
00270 
00271                                                         //Draw Mesh Triangles
00272                                                         glBegin(GL_TRIANGLES);
00273                                                                 for ( int j=0;j<3;j++){
00274                                                                         int indexVertex = faces[i].getIndexVertex(j); 
00275                                                                         COME_Vector3D normal = allVertices->at(indexVertex).getNormalGlobalPosition();
00276                                                                         glNormal3f(normal.x,normal.y,normal.z);
00277                                                                         //printf( "NORMALS: %f %f %f \n", normal.x,normal.y,normal.z );
00278                                                                         COME_Vertex3D vertex = allVertices->at(indexVertex);
00279                                                                         
00280                                                                         // COLOR STRESS
00281                                                                         if (((COME_ModelJoint*)getGlobal())->rbStress->isChecked()){
00282                                                                                 double R, B, maxS = 3000;
00283                                                                                 double S = vertex.getStress();
00284                                                                                 if( S < maxS / 2.0 ){
00285                                                                                         B = ( 2.0 / maxS ) * S;
00286                                                                                         R = 0.0;
00287                                                                                 } else {
00288                                                                                         R = ( 2.0 / maxS ) * ( S - maxS / 2.0);
00289                                                                                         B = 1.0;
00290                                                                                 }
00291                                                 
00292                                                                                 R += 0.3;
00293                                                                                 B += 0.3;
00294                                                                                 
00295                                                                                 glColor3f(R, 0.3, B);
00296                                                                         }
00297                                                                         
00299                                                                         if (((COME_ModelJoint*)getGlobal())->rbMaterial->isChecked()){
00300                                                                                 glColor3f(vertex.getColorMaterial().getX(),vertex.getColorMaterial().getY(),vertex.getColorMaterial().getZ());
00301                                                                         }
00302                                                                         
00304                                                                         if (((COME_ModelJoint*)getGlobal())->rbCollision->isChecked()){
00305                                                                                 glColor3f(vertex.getColor()[0],vertex.getColor()[1],vertex.getColor()[2]);
00306                                                                         }
00307 
00309                                                                         /*if( ( (*iterOrgans)->getDescription() == "femurbone" ) || ( (*iterOrgans)->getDescription() == "pelvisbone" ) )
00310                                                                                 glColor3f( 1.0,1.0, 1.0);
00311                                                                         if( ( (*iterOrgans)->getDescription() == "femurcart" ) || ( (*iterOrgans)->getDescription() == "pelviscart" ) )
00312                                                                                 glColor3f( 0.8,0.8, 0.2);
00313                                                                         if( (*iterOrgans)->getDescription() == "labrum" )
00314                                                                                 glColor3f( 0.7,0.7, 0.7);
00315                                                                         */
00316                                                                         glTexCoord2f(vertex.getTexCoord().getX(),vertex.getTexCoord().getY());
00317                                                                         glVertex3d(vertex.x,vertex.y,vertex.z);
00318                                                                 }
00319                                                         glEnd();
00320                                                         /*for ( int j=0;j<3;j++){
00321                                                                 int indexVertex = faces[i].getIndexVertex(j); 
00322                                                                 COME_Vertex3D vertex = allVertices->at(indexVertex);
00323                                                                 //glPushMatrix();
00324                                                                 //      glTranslatef(vertex.pPlane.x,vertex.pPlane.y,vertex.pPlane.z);
00325                                                                 //      glutSolidSphere(0.05*((double)((COME_ModelJoint*)getGlobal())->sliderScale->value()/500.0), 8, 8);
00326                                                                 //glPopMatrix();
00327 
00328                                                                 if( vertex.getCollide() ) {
00329                                                                         glPushMatrix();
00330                                                                                 glColor3f(1, 1, 1);
00331                                                                                 glTranslatef( vertex.x,vertex.y,vertex.z );
00332                                                                                 glutSolidSphere(0.02*((double)((COME_ModelJoint*)getGlobal())->sliderScale->value()/100.0), 15, 15);
00333                                                                         glPopMatrix();
00334                                                                 }
00335                                                         }*/
00336                                                         glDisable(GL_LIGHTING);
00337                                                         if(((COME_ModelJoint*)getGlobal())->cbNormals->isChecked()){
00338                                                                 for ( int k=0;k<3;k++){
00339                                                                         int indexVertex = faces[i].getIndexVertex(k);
00340                                                                         COME_Vector3D normal = allVertices->at(indexVertex).getNormalGlobalPosition();
00341                                                                         COME_Vertex3D vertex = allVertices->at(indexVertex);
00342                                                                         glBegin(GL_LINES);
00343                                                                         glColor3f(1.0,1.0,1.0);
00344                                                                         glVertex3f(vertex.x,vertex.y,vertex.z);
00345                                                                         glVertex3f(vertex.x+(sceneRadius()/20.0*normal.x),vertex.y+(sceneRadius()/20.0*normal.y), vertex.z+(sceneRadius()/20.0*normal.z));
00346                                                                         glEnd();
00347                                                                 }
00348                                                         }
00349                                                         glEnable(GL_LIGHTING);
00350                                                         
00352                                                         if(((COME_ModelJoint*)getGlobal())->cbNormals->isChecked()){
00353                                                                 glDisable(GL_LIGHTING);
00354                                                                 for ( int k=0;k<3;k++){
00355                                                                         int indexVertex = faces[i].getIndexVertex(k); 
00356                                                                         COME_Vector3D normal = allVertices->at(indexVertex).getBlendedVelocity();//getCollisionDispAvg();
00357                                                                         COME_Vector3D velocity = allVertices->at(indexVertex).getVelocityDispAvg();
00358                                                                         COME_Vertex3D vertex = allVertices->at(indexVertex);
00359                                                                         glBegin(GL_LINES);
00360                                                                         glColor3f(0.1,0.1,0.1);
00361                                                                         glVertex3f(vertex.x,vertex.y,vertex.z);
00362                                                                         glVertex3f(vertex.x+normal.x,vertex.y+normal.y, vertex.z+normal.z);
00363                                                                         glEnd();
00364                                                                         glBegin(GL_LINES);
00365                                                                         glColor3f(1.0,1.0,1.0);
00366                                                                         glVertex3f(vertex.x,vertex.y,vertex.z);
00367                                                                         glVertex3f(vertex.x+velocity.x,vertex.y+velocity.y, vertex.z+velocity.z);
00368                                                                         glEnd();
00369                                                                 }
00370                                                                 glEnable(GL_LIGHTING);
00371                                                         }
00372                                                 }
00373                                         }
00374                                         if (((COME_ModelJoint*)getGlobal())->cbTexture->isChecked()){
00375                                                 glDisable(GL_TEXTURE_2D);
00376                                         }
00377                                 }
00378                                 glPopName();
00379                         }
00380                 }
00381 
00382                 scene->unlock();
00383                 
00384                 if (((COME_ModelJoint*)getGlobal())->cbMakeMovie->isChecked())
00385                         if( oldClock < ((COME_ModelJoint*)getGlobal())->sim->getClock() ){
00386                                 saveSnapshot(true, true); // Warning, overwrite mode
00387                                 oldClock = ((COME_ModelJoint*)getGlobal())->sim->getClock();
00388                         }
00389         }
00390         
00391 }
00392 
00393 void
00394 COME_ModelJointQGLWidget::keyPressEvent(QKeyEvent *e){
00395 
00396   // Get event state key
00397   const Qt::ButtonState state = (Qt::ButtonState)(e->state() & Qt::KeyButtonMask);
00398   // Bug in Qt : use 0x0f00 instead of Qt::KeyButtonMask with Qt versions < 3.1
00399 
00400   // A simple switch on e->key() is not sufficient if we want to take state key into account.
00401   // With a switch, it would have been impossible to separate 'F' from 'CTRL+F'.
00402   // That's why we use imbricated if...else and a "handled" boolean.
00403   bool handled = false;
00404   switch( e->key() ){
00405 
00406         case Qt::Key_Right:
00407                 if(state==Qt::ShiftButton){
00408                         ((COME_ModelJoint*)getGlobal())->rotateSelected( 1, 0, 0 );
00409                         handled = true;
00410                 } else
00411                 if(state==Qt::ControlButton){
00412                         ((COME_ModelJoint*)getGlobal())->translateSelected( 1, 0, 0 );
00413                         handled = true;
00414                 } else
00415                 if(state==Qt::AltButton){
00416                         ((COME_ModelJoint*)getGlobal())->scaleSelected( 1, 0, 0 );
00417                         handled = true;
00418                 }
00419                 break;
00420         case Qt::Key_Left:
00421                 if(state==Qt::ShiftButton){
00422                         ((COME_ModelJoint*)getGlobal())->rotateSelected( -1, 0, 0 );
00423                         handled = true;
00424                 } else
00425                 if(state==Qt::ControlButton){
00426                         ((COME_ModelJoint*)getGlobal())->translateSelected( -1, 0, 0 );
00427                         handled = true;
00428                 } else
00429                 if(state==Qt::AltButton){
00430                         ((COME_ModelJoint*)getGlobal())->scaleSelected( -1, 0, 0 );
00431                         handled = true;
00432                 }
00433                 break;
00434         case Qt::Key_Up:
00435                 if(state==Qt::ShiftButton){
00436                         ((COME_ModelJoint*)getGlobal())->rotateSelected( 0, 1, 0 );
00437                         handled = true;
00438                 } else
00439                 if(state==Qt::ControlButton){
00440                         ((COME_ModelJoint*)getGlobal())->translateSelected( 0, 1, 0 );
00441                         handled = true;
00442                 } else
00443                 if(state==Qt::AltButton){
00444                         ((COME_ModelJoint*)getGlobal())->scaleSelected( 0, 1, 0 );
00445                         handled = true;
00446                 }
00447                 break;
00448         case Qt::Key_Down:
00449                 if(state==Qt::ShiftButton){
00450                         ((COME_ModelJoint*)getGlobal())->rotateSelected( 0, -1, 0 );
00451                         handled = true;
00452                 } else
00453                 if(state==Qt::ControlButton){
00454                         ((COME_ModelJoint*)getGlobal())->translateSelected( 0, -1, 0 );
00455                         handled = true;
00456                 } else
00457                 if(state==Qt::AltButton){
00458                         ((COME_ModelJoint*)getGlobal())->scaleSelected( 0, -1, 0 );
00459                         handled = true;
00460                 }
00461                 break;
00462         case Qt::Key_PageUp:
00463                 if(state==Qt::ShiftButton){
00464                         ((COME_ModelJoint*)getGlobal())->rotateSelected( 0, 0, 1 );
00465                         handled = true;
00466                 } else
00467                 if(state==Qt::ControlButton){
00468                         ((COME_ModelJoint*)getGlobal())->translateSelected( 0, 0, 1 );
00469                         handled = true;
00470                 } else
00471                 if(state==Qt::AltButton){
00472                         ((COME_ModelJoint*)getGlobal())->scaleSelected( 0, 0, 1 );
00473                         handled = true;
00474                 }
00475                 break;
00476         case Qt::Key_PageDown:
00477                 if(state==Qt::ShiftButton){
00478                         ((COME_ModelJoint*)getGlobal())->rotateSelected( 0, 0, -1 );
00479                         handled = true;
00480                 } else
00481                 if(state==Qt::ControlButton){
00482                         ((COME_ModelJoint*)getGlobal())->translateSelected( 0, 0, -1 );
00483                         handled = true;
00484                 } else
00485                 if(state==Qt::AltButton){
00486                         ((COME_ModelJoint*)getGlobal())->scaleSelected( 0, 0, -1 );
00487                         handled = true;
00488                 }
00489                 break;
00490   }
00491 
00492         if (!handled){
00493                 COME_QGLWidget::keyPressEvent(e);
00494         } else {
00495                 updateGL();
00496         }
00497 }
00498 
00499 void
00500 COME_ModelJointQGLWidget::postSelection(const QPoint& point){
00501 
00502         if( selectedName() == -1 )
00503         {
00504                 // Unselect all if no object is selected.
00505                 scene->getPatient(0)->unselectAll();
00506                 ((COME_ModelJoint*)getGlobal())->statusBar()->message( "No object selected.", 1000 );
00507         }
00508         else {
00509                 
00510                 if( scene->getPatient(0)->getOrgan( selectedName() ) ){
00511                         char chMessage[30];
00512                         sprintf( chMessage, "Object %d selected in patient 0.", selectedName() );
00513                         ((COME_ModelJoint*)getGlobal())->statusBar()->message( chMessage, 1000 );
00514                         scene->getPatient(0)->unselectAll();
00515                         scene->getPatient(0)->getOrgan( selectedName() )->select(true);
00516                 }
00517         }
00518 
00519 }
00520 
00521 void
00522 COME_ModelJointQGLWidget::drawWithNames(){
00523 
00524         draw();
00525 }
00526 
00527 
00528 void
00529 COME_ModelJointQGLWidget::loadTextures() {
00530   
00531         for( int iP = 0; iP < scene->getPatientList()->size(); iP++ ){
00532                 //Main loop: For each organ display the object
00533                 list<COME_BioStructure*>::const_iterator iterOrgans;
00534                 
00535                 for( iterOrgans = ((list<COME_BioStructure *>*)scene->getPatient(iP)->getPtOrganList())->begin(); iterOrgans != ((list<COME_BioStructure *>*)scene->getPatient(iP)->getPtOrganList())->end(); iterOrgans++  ){
00536                 
00537                         COME_Mesh* currMesh = (*iterOrgans)->getPointerToSurface();
00538                         
00539                         if( ( currMesh ) && ( currMesh->getTexture() ) ){
00540         
00541                                 // Create Texture       
00542                                 glGenTextures(1, currMesh->getTextureID() );
00543                                 glBindTexture(GL_TEXTURE_2D, *(currMesh->getTextureID()) );   // 2d texture (x and y size)
00544                                 
00545                                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture
00546                                 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture
00547                                 
00548                                 // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, 
00549                                 // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.
00550                                 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, currMesh->getTexture()->sizeX, currMesh->getTexture()->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, currMesh->getTexture()->data);
00551                         }
00552                 }
00553         }
00554 }
00555 
00556 void
00557 COME_ModelJointQGLWidget::init(){
00558 
00559         //loadTextures();
00560         COME_QGLWidget::init();
00561 }

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