TAPs 0.7.7.3
TAPsListOfAvailableModelsForSurgery.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsListOfAvailableModelsForSurgery.hpp
00003 
00004 SUKITTI PUNAK   (08/06/2008)
00005 UPDATE          (09/03/2010)
00006 ******************************************************************************/
00007 
00012 #include "TAPsListOfAvailableModelsForSurgery.hpp"
00013 
00014 BEGIN_NAMESPACE_TAPs
00015 //=============================================================================
00016 template <typename T>
00017 std::vector< ModelForSurgery<T> * > SetupModelsForSurgery ( std::string setupFile )
00018 {
00019     // Get current directory
00020     std::string strPath( "" );
00021 #if defined (_WINDOWS) || !defined (__WINDOWS__)
00022     size_t found = setupFile.find_last_of( "/\\" );
00023     if ( found != std::string::npos ) {
00024         char path[256];
00025         _getcwd( path, 256 );
00026         // If a drive letter is not included
00027         if ( setupFile.find_last_of( ":" ) == std::string::npos ) {
00028             strPath += std::string( path ) + "/";
00029         }
00030         strPath += setupFile.substr(0,found) + "/";
00031         // Example output: 
00032         //std::cout << "Current Directory: " << path << std::endl;
00033         //  Current Directory: G:\spunak_xp\Works\TAPs\Applications\SutureApp
00034     }
00035 #endif
00036 
00037     //---------------------------------------------------------------
00038     // List of Models for Surgery
00039 
00040     /*
00041     // Organs
00042     ModelForSurgery<T> *    pOrgan_Heart            = NULL;
00043     ModelForSurgery<T> *    pOrgan_LeftKidney       = NULL;
00044     ModelForSurgery<T> *    pOrgan_RightKidney      = NULL;
00045     ModelForSurgery<T> *    pOrgan_Liver            = NULL;
00046     ModelForSurgery<T> *    pOrgan_LeftLung         = NULL;
00047     ModelForSurgery<T> *    pOrgan_RightLung        = NULL;
00048     ModelForSurgery<T> *    pOrgan_Stomach          = NULL;
00049 
00050     // For Practice
00051     ModelForSurgery<T> *    pTissueBox01            = NULL;
00052     ModelForSurgery<T> *    pTissueTwoTubes01       = NULL;
00053     //*/
00054 
00055     //---------------------------------------------------------------
00056 
00057     //
00058     bool bModelInclusionList[256];
00059     for ( int i = 0; i < 256; ++i ) {
00060         bModelInclusionList[i] = false;
00061     }
00062     std::vector< ModelForSurgery<T> * > pModels;
00063 
00064     // Open the setup file
00065     std::ifstream   ifs( setupFile.c_str(), std::ifstream::in );
00066     if ( !ifs.is_open() ) {
00067         std::cout << "Error opening the setup file (\"" << setupFile << "\") for Models for Surgery!" << std::endl;
00068         return pModels;
00069     }
00070     else {
00071         std::cout << "Open the setup file (\"" << setupFile << "\") for Models for Surgery!" << std::endl;
00072     }
00073 
00074     //*
00075     // Read the setup file
00076     const std::string delims( " ,\t" );
00077     std::string::size_type begIdx, endIdx;
00078     std::string strName;
00079     char line[256];
00080 
00081     // The first line
00082     ifs.getline( line, 256 );
00083     while ( !ifs.eof() ) {
00084         std::string parameter( line );
00085 
00086         //std::cout << "READ LINE: " << parameter << "\n";
00087 
00088         // Search beginning of the first word
00089         begIdx = parameter.find_first_not_of( delims );
00090         // While beginning of a word found
00091         while ( begIdx != std::string::npos ) {
00092             // Search end of the actual word
00093             endIdx = parameter.find_first_of( delims, begIdx );
00094             if ( endIdx == std::string::npos ) {
00095                 // End of word is end of line
00096                 endIdx = parameter.length();
00097             }
00098 
00099             // Treat # as comment
00100             if ( !(parameter[begIdx] == '#') ) {
00101                 strName = parameter.substr( begIdx, endIdx );
00102 
00103                 // Check for an model inclusion
00104 
00105                 // START: List of Organs
00106                 if ( strName.substr( begIdx, strlen("ORGAN_") ).compare( "ORGAN_" ) == 0 ) {
00107 
00108                     if ( strName.compare( "ORGAN_HEART" ) == 0 ) {
00109                         begIdx = parameter.find_first_not_of( delims, endIdx );
00110                         endIdx = parameter.find_first_of( delims, begIdx );
00111                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00112                             bModelInclusionList[ ModelForSurgery<T>::HEART ] = true;
00113                         }
00114                     }
00115                     else if ( strName.compare( "ORGAN_LEFT_KIDNEY" ) == 0 ) {
00116                         begIdx = parameter.find_first_not_of( delims, endIdx );
00117                         endIdx = parameter.find_first_of( delims, begIdx );
00118                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00119                             bModelInclusionList[ ModelForSurgery<T>::LEFT_KIDNEY ] = true;
00120                         }
00121                     }
00122                     else if ( strName.compare( "ORGAN_RIGHT_KIDNEY" ) == 0 ) {
00123                         begIdx = parameter.find_first_not_of( delims, endIdx );
00124                         endIdx = parameter.find_first_of( delims, begIdx );
00125                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00126                             bModelInclusionList[ ModelForSurgery<T>::RIGHT_KIDNEY ] = true;
00127                         }
00128                     }
00129                     else if ( strName.compare( "ORGAN_LIVER" ) == 0 ) {
00130                         begIdx = parameter.find_first_not_of( delims, endIdx );
00131                         endIdx = parameter.find_first_of( delims, begIdx );
00132                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00133                             bModelInclusionList[ ModelForSurgery<T>::LIVER ] = true;
00134                         }
00135                     }
00136                     else if ( strName.compare( "ORGAN_LEFT_LUNG" ) == 0 ) {
00137                         begIdx = parameter.find_first_not_of( delims, endIdx );
00138                         endIdx = parameter.find_first_of( delims, begIdx );
00139                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00140                             bModelInclusionList[ ModelForSurgery<T>::LEFT_LUNG ] = true;
00141                         }
00142                     }
00143                     else if ( strName.compare( "ORGAN_RIGHT_LUNG" ) == 0 ) {
00144                         begIdx = parameter.find_first_not_of( delims, endIdx );
00145                         endIdx = parameter.find_first_of( delims, begIdx );
00146                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00147                             bModelInclusionList[ ModelForSurgery<T>::RIGHT_LUNG ] = true;
00148                         }
00149                     }
00150                     else if ( strName.compare( "ORGAN_STOMACH" ) == 0 ) {
00151                         begIdx = parameter.find_first_not_of( delims, endIdx );
00152                         endIdx = parameter.find_first_of( delims, begIdx );
00153                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00154                             bModelInclusionList[ ModelForSurgery<T>::STOMACH ] = true;
00155                         }
00156                     }
00157 
00158                 } // END: List of Organs
00159 
00160                 //*
00161                 // START: List of Tissues for Practice
00162                 else if ( strName.substr( begIdx, strlen("TISSUE_") ).compare( "TISSUE_" ) == 0 ) {
00163                     if ( strName.compare( "TISSUE_BOX_01" ) == 0 ) {
00164                         begIdx = parameter.find_first_not_of( delims, endIdx );
00165                         endIdx = parameter.find_first_of( delims, begIdx );
00166                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00167                             bModelInclusionList[ ModelForSurgery<T>::TISSUE_BOX_01 ] = true;
00168                         }
00169                     }
00170                     else if ( strName.compare( "TISSUE_TWO_TUBES_01" ) == 0 ) {
00171                         begIdx = parameter.find_first_not_of( delims, endIdx );
00172                         endIdx = parameter.find_first_of( delims, begIdx );
00173                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00174                             bModelInclusionList[ ModelForSurgery<T>::TISSUE_TWO_TUBES_01 ] = true;
00175                         }
00176                     }
00177                     else if ( strName.compare( "TISSUE_HIATUS_HERNIA_01" ) == 0 ) {
00178                         begIdx = parameter.find_first_not_of( delims, endIdx );
00179                         endIdx = parameter.find_first_of( delims, begIdx );
00180                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00181                             bModelInclusionList[ ModelForSurgery<T>::TISSUE_HIATUS_HERNIA_01 ] = true;
00182                         }
00183                     }
00184                     //ADD A MODEL HERE
00185                     /*
00186                     else if ( strName.compare( "MODEL_CALL_NAME" ) == 0 ) {
00187                         begIdx = parameter.find_first_not_of( delims, endIdx );
00188                         endIdx = parameter.find_first_of( delims, begIdx );
00189                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00190                             bModelInclusionList[ ModelForSurgery<T>::MODEL_CALL_NAME ] = true;
00191                         }
00192                     }
00193                     */
00194 
00195                 } // END: List of Tissues for Practice
00196                 //*/
00197 
00198                 //*
00199                 // START: List of Rigid Objects for Practice
00200                 else if ( strName.substr( begIdx, strlen("RIGID_") ).compare( "RIGID_" ) == 0 ) {
00201                     if ( strName.compare( "RIGID_TORUS_01" ) == 0 ) {
00202                         begIdx = parameter.find_first_not_of( delims, endIdx );
00203                         endIdx = parameter.find_first_of( delims, begIdx );
00204                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00205                             bModelInclusionList[ ModelForSurgery<T>::RIGID_TORUS_01 ] = true;
00206                         }
00207                     }
00208                     //ADD A MODEL HERE
00209                     /*
00210                     else if ( strName.compare( "MODEL_CALL_NAME" ) == 0 ) {
00211                         begIdx = parameter.find_first_not_of( delims, endIdx );
00212                         endIdx = parameter.find_first_of( delims, begIdx );
00213                         if ( parameter.substr( begIdx, endIdx ).compare( "ON" ) == 0 ) {
00214                             bModelInclusionList[ ModelForSurgery<T>::MODEL_CALL_NAME ] = true;
00215                         }
00216                     }
00217                     */
00218 
00219                 } // END: List of Rigid Objects for Practice
00220                 //*/
00221 
00222                 // Check for a model inclusion
00223                 else if ( strName.compare( "*MODEL" ) == 0 ) {
00224                     ModelForSurgery<T> * pModelForSurgery = ProcessSetupModelForSurgery<T>( ifs, bModelInclusionList, strPath );
00225                     if ( pModelForSurgery ) {
00226                         pModels.push_back( pModelForSurgery );
00227                     }
00228                 }
00229             }
00230             // Set the beginning index to the last position in the input line
00231             begIdx = std::string::npos;
00232         }
00233 
00234         // Next line
00235         ifs.getline( line, 256 );
00236     }
00237 
00238     // Close the setup file
00239     ifs.close();
00240     //*/
00241 
00242     return pModels;
00243 }
00244 
00245 //-----------------------------------------------------------------------------
00246 template <typename T>
00247 ModelForSurgery<T> * ProcessSetupModelForSurgery ( std::ifstream & ifs, bool bModelInclusionList[256], std::string path )
00248 {
00249     //---------------------------------------------------------------
00250     // For Handling Transformations
00251     enum ModelForSurgery<T>::ModelType  model_type;
00252     std::string                     name( "" );
00253     std::string                     data_location( "" );
00254     bool                            bSimOn          = true;
00255     bool                            bColDetOn       = true;
00256     bool                            bRenderOn       = true;
00257     bool                            bTransformOn    = false;
00258     std::vector< std::string >      vTransformName;
00259     std::vector< T >                vTransformValue;
00260     T   tPointMass  = 1.0;
00261     T   tKstiffness = 500.0;
00262     T   tKdamper    = 100.0;
00263     T   tHomeKstiffness = 2500.0;
00264     T   tHomeKdamper    = 250.0;
00265     int iRigidity   = 1;
00266 
00267     T predefinedTimeStep = 0.01;    
00268     int numSimSubSteps   = 10;      
00269 
00270     // Read the setup file
00271     const std::string delims( " ,\t" );
00272     std::string::size_type begIdx, endIdx;
00273     std::string strName, strValue;
00274     char line[256];
00275 
00276     // The first line
00277     ifs.getline( line, 256 );
00278     while ( line[0] != '}' ) {
00279         std::string parameter( line );
00280 
00281         // Search beginning of the first word
00282         begIdx = parameter.find_first_not_of( delims );
00283         // While beginning of a word found
00284         while ( begIdx != std::string::npos ) {
00285             // Search end of the actual word
00286             endIdx = parameter.find_first_of( delims, begIdx );
00287             if ( endIdx == std::string::npos ) {
00288                 // End of word is end of line
00289                 endIdx = parameter.length();
00290             }
00291 
00292             // Treat # as comment
00293             if ( !(parameter[begIdx] == '#') ) {
00294                 strName = parameter.substr( begIdx, endIdx-begIdx );
00295 
00296                 //std::cout << strName << "\n";
00297                 
00298                 // Process Model Type -- ORGAN
00299                 if ( strName.compare( "*ORGAN_TYPE" ) == 0 ) {
00300                     begIdx = parameter.find_first_not_of( delims, endIdx );
00301                     endIdx = parameter.find_first_of( delims, begIdx );
00302                     if ( begIdx != std::string::npos ) {
00303                         if      ( parameter.substr( begIdx, endIdx-begIdx ).compare( "HEART" ) == 0 )           model_type = ModelForSurgery<T>::HEART;
00304                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "LEFT_KIDNEY" ) == 0 )     model_type = ModelForSurgery<T>::LEFT_KIDNEY;
00305                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "RIGHT_KIDNEY" ) == 0 )    model_type = ModelForSurgery<T>::RIGHT_KIDNEY;
00306                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "LIVER" ) == 0 )           model_type = ModelForSurgery<T>::LIVER;
00307                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "LEFT_LUNG" ) == 0 )       model_type = ModelForSurgery<T>::LEFT_LUNG;
00308                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "RIGHT_LUNG" ) == 0 )      model_type = ModelForSurgery<T>::RIGHT_LUNG;
00309                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "STOMACH" ) == 0 )         model_type = ModelForSurgery<T>::STOMACH;
00310                         else {
00311                             std::cout << "ERROR: *ORGAN_TYPE is not supported! -- " << parameter << "\n";
00312                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00313                             return NULL;
00314                         }
00315                         if ( bModelInclusionList[ model_type ] == false ) {
00316                             std::cout << "*ORGAN_TYPE is not included! -- " << parameter << "\n";
00317                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00318                             return NULL;
00319                         }
00320                     }
00321                     else {
00322                         std::cout << "ERROR: *ORGAN_TYPE is not specified! -- " << parameter << "\n";
00323                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00324                         return NULL;
00325                     }
00326                     //std::cout << parameter.substr( begIdx, endIdx-begIdx ) << " -- " << model_type << "\n";
00327                 }
00328 
00329                 // Process Model Type -- TISSUE
00330                 else if ( strName.compare( "*TISSUE_TYPE" ) == 0 ) {
00331                     begIdx = parameter.find_first_not_of( delims, endIdx );
00332                     endIdx = parameter.find_first_of( delims, begIdx );
00333                     if ( begIdx != std::string::npos ) {
00334                         if      ( parameter.substr( begIdx, endIdx-begIdx ).compare( "TISSUE_BOX_01" ) == 0 )       model_type = ModelForSurgery<T>::TISSUE_BOX_01;
00335                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "TISSUE_TWO_TUBES_01" ) == 0 ) model_type = ModelForSurgery<T>::TISSUE_TWO_TUBES_01;
00336                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "TISSUE_HIATUS_HERNIA_01" ) == 0 ) model_type = ModelForSurgery<T>::TISSUE_HIATUS_HERNIA_01;
00337                         // ADD A MODEL HERE
00338                         //else if   ( parameter.substr( begIdx, endIdx-begIdx ).compare( "MODEL_CALL_NAME" ) == 0 ) model_type = ModelForSurgery<T>::MODEL_CALL_NAME;
00339                         else {
00340                             std::cout << "ERROR: *TISSUE_TYPE is not supported! -- " << parameter << "\n";
00341                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00342                             return NULL;
00343                         }
00344                         if ( bModelInclusionList[ model_type ] == false ) {
00345                             std::cout << "*TISSUE_TYPE is not included! -- " << parameter << "\n";
00346                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00347                             return NULL;
00348                         }
00349                     }
00350                     else {
00351                         std::cout << "ERROR: *TISSUE_TYPE is not specified! -- " << parameter << "\n";
00352                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00353                         return NULL;
00354                     }
00355                     //std::cout << parameter.substr( begIdx, endIdx-begIdx ) << " -- " << model_type << "\n";
00356                 }
00357 
00358                 // Process Model Type -- RIGID
00359                 else if ( strName.compare( "*RIGID_TYPE" ) == 0 ) {
00360                     begIdx = parameter.find_first_not_of( delims, endIdx );
00361                     endIdx = parameter.find_first_of( delims, begIdx );
00362                     if ( begIdx != std::string::npos ) {
00363                         if  ( parameter.substr( begIdx, endIdx-begIdx ).compare( "RIGID_TORUS_01" ) == 0 )  model_type = ModelForSurgery<T>::RIGID_TORUS_01;
00364                         // ADD A MODEL HERE
00365                         //else if   ( parameter.substr( begIdx, endIdx-begIdx ).compare( "MODEL_CALL_NAME" ) == 0 ) model_type = ModelForSurgery<T>::MODEL_CALL_NAME;
00366                         else {
00367                             std::cout << "ERROR: *RIGID_TYPE is not supported! -- " << parameter << "\n";
00368                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00369                             return NULL;
00370                         }
00371                         if ( bModelInclusionList[ model_type ] == false ) {
00372                             std::cout << "*RIGID_TYPE is not included! -- " << parameter << "\n";
00373                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00374                             return NULL;
00375                         }
00376                     }
00377                     else {
00378                         std::cout << "ERROR: *RIGID_TYPE is not specified! -- " << parameter << "\n";
00379                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00380                         return NULL;
00381                     }
00382                     //std::cout << parameter.substr( begIdx, endIdx-begIdx ) << " -- " << model_type << "\n";
00383                 }
00384 
00385                 // Process Model Name
00386                 else if ( strName.compare( "*NAME" ) == 0 ) {
00387                     begIdx = parameter.find_first_not_of( delims, endIdx );
00388                     //endIdx = parameter.find_first_of( delims, begIdx );
00389                     endIdx = parameter.size();
00390                     if ( begIdx != std::string::npos ) {
00391                         name = parameter.substr( begIdx, endIdx-begIdx );
00392                         if ( name.compare( "\"\"" ) == 0 )  name = "";
00393                     }
00394                     else {
00395                         std::cout << "ERROR: *NAME is not specified! -- " << parameter << "\n";
00396                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00397                         return NULL;
00398                     }
00399                     //std::cout << "Name: " << " -- " << name << "\n";
00400                 }
00401 
00402                 // Process Model Data Location
00403                 else if ( strName.compare( "*DATA_LOCATION" ) == 0 ) {
00404                     begIdx = parameter.find_first_not_of( delims, endIdx );
00405                     endIdx = parameter.find_first_of( delims, begIdx );
00406                     if ( begIdx != std::string::npos ) {
00407                         data_location = parameter.substr( begIdx, endIdx-begIdx );
00408                         if ( data_location.compare( "\"\"" ) == 0 ) data_location = "";
00409                     }
00410                     else {
00411                         std::cout << "ERROR: *DATA_LOCATION is not specified! -- " << parameter << "\n";
00412                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00413                         return NULL;
00414                     }
00415                     //std::cout << "Data Location: " << " -- " << data_location << "\n";
00416                 }
00417 
00418                 // Process Model Simulation ON/OFF
00419                 else if ( strName.compare( "*SIMULATION" ) == 0 ) {
00420                     begIdx = parameter.find_first_not_of( delims, endIdx );
00421                     endIdx = parameter.find_first_of( delims, begIdx );
00422                     if ( begIdx != std::string::npos ) {
00423                         if      ( parameter.substr( begIdx, endIdx-begIdx ).compare( "ON" ) == 0 )  bSimOn = true;
00424                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "OFF" ) == 0 ) bSimOn = false;
00425                         else {
00426                             std::cout << "ERROR: *SIMULATION has to be set to either ON or OFF! -- " << parameter << "\n";
00427                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00428                             return NULL;
00429                         }
00430                     }
00431                     else {
00432                         std::cout << "ERROR: *SIMULATION has to be set to either ON or OFF! -- " << parameter << "\n";
00433                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00434                         return NULL;
00435                     }
00436                 }
00437 
00438                 // Process Model Collision Detection ON/OFF
00439                 else if ( strName.compare( "*COLLISION" ) == 0 ) {
00440                     begIdx = parameter.find_first_not_of( delims, endIdx );
00441                     endIdx = parameter.find_first_of( delims, begIdx );
00442                     if ( begIdx != std::string::npos ) {
00443                         if      ( parameter.substr( begIdx, endIdx-begIdx ).compare( "ON" ) == 0 )  bColDetOn = true;
00444                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "OFF" ) == 0 ) bColDetOn = false;
00445                         else {
00446                             std::cout << "ERROR: *COLLISION has to be set to either ON or OFF! -- " << parameter << "\n";
00447                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00448                             return NULL;
00449                         }
00450                     }
00451                     else {
00452                         std::cout << "ERROR: *COLLISION has to be set to either ON or OFF! -- " << parameter << "\n";
00453                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00454                         return NULL;
00455                     }
00456                 }
00457 
00458                 // Process Model Render ON/OFF
00459                 else if ( strName.compare( "*RENDER" ) == 0 ) {
00460                     begIdx = parameter.find_first_not_of( delims, endIdx );
00461                     endIdx = parameter.find_first_of( delims, begIdx );
00462                     if ( begIdx != std::string::npos ) {
00463                         if      ( parameter.substr( begIdx, endIdx-begIdx ).compare( "ON" ) == 0 )  bRenderOn = true;
00464                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "OFF" ) == 0 ) bRenderOn = false;
00465                         else {
00466                             std::cout << "ERROR: *RENDER has to be set to either ON or OFF! -- " << parameter << "\n";
00467                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00468                             return NULL;
00469                         }
00470                     }
00471                     else {
00472                         std::cout << "ERROR: *RENDER has to be set to either ON or OFF! -- " << parameter << "\n";
00473                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00474                         return NULL;
00475                     }
00476                 }
00477 
00478                 // Process Model Transformation ON/OFF
00479                 else if ( strName.compare( "*TRANSFORMATION" ) == 0 ) {
00480                     begIdx = parameter.find_first_not_of( delims, endIdx );
00481                     endIdx = parameter.find_first_of( delims, begIdx );
00482                     if ( begIdx != std::string::npos ) {
00483                         if      ( parameter.substr( begIdx, endIdx-begIdx ).compare( "ON" ) == 0 )  bTransformOn = true;
00484                         else if ( parameter.substr( begIdx, endIdx-begIdx ).compare( "OFF" ) == 0 ) bTransformOn = false;
00485                         else {
00486                             std::cout << "ERROR: *TRANSFORMATION has to be set to either ON or OFF! -- " << parameter << "\n";
00487                             while ( line[0] != '}' )    ifs.getline( line, 256 );
00488                             return NULL;
00489                         }
00490                     }
00491                     else {
00492                         std::cout << "ERROR: *TRANSFORMATION has to be set to either ON or OFF! -- " << parameter << "\n";
00493                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00494                         return NULL;
00495                     }
00496                 }
00497 
00498                 // Process Model Translation
00499                 else if ( strName.compare( "*TRANSLATION" ) == 0 ) {
00500                     vTransformName.push_back( "TRANSLATION" );
00501                     bool isOK = true;
00502                     // x
00503                     begIdx = parameter.find_first_not_of( delims, endIdx );
00504                     endIdx = parameter.find_first_of( delims, begIdx );
00505                     if ( begIdx == std::string::npos )  isOK = false;
00506                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00507                     // y
00508                     begIdx = parameter.find_first_not_of( delims, endIdx );
00509                     endIdx = parameter.find_first_of( delims, begIdx );
00510                     if ( begIdx == std::string::npos )  isOK = false;
00511                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00512                     // z
00513                     begIdx = parameter.find_first_not_of( delims, endIdx );
00514                     endIdx = parameter.find_first_of( delims, begIdx );
00515                     if ( begIdx == std::string::npos )  isOK = false;
00516                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00517                     // error
00518                     if ( !isOK ) {
00519                         std::cout << "ERROR: *TRANSLATION does not contain three values for xyz! -- " << parameter << "\n";
00520                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00521                         return NULL;
00522                     }
00523                 }
00524 
00525                 // Process Model Rotation
00526                 else if ( strName.compare( "*ROTATION_AXIS_AND_ANGLE" ) == 0 ) {
00527                     vTransformName.push_back( "ROTATION_AXIS_AND_ANGLE" );
00528                     bool isOK = true;
00529                     // x
00530                     begIdx = parameter.find_first_not_of( delims, endIdx );
00531                     endIdx = parameter.find_first_of( delims, begIdx );
00532                     if ( begIdx == std::string::npos )  isOK = false;
00533                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00534                     // y
00535                     begIdx = parameter.find_first_not_of( delims, endIdx );
00536                     endIdx = parameter.find_first_of( delims, begIdx );
00537                     if ( begIdx == std::string::npos )  isOK = false;
00538                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00539                     // z
00540                     begIdx = parameter.find_first_not_of( delims, endIdx );
00541                     endIdx = parameter.find_first_of( delims, begIdx );
00542                     if ( begIdx == std::string::npos )  isOK = false;
00543                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00544                     // angle in degree
00545                     begIdx = parameter.find_first_not_of( delims, endIdx );
00546                     endIdx = parameter.find_first_of( delims, begIdx );
00547                     if ( begIdx == std::string::npos )  isOK = false;
00548                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00549                     // error
00550                     if ( !isOK ) {
00551                         std::cout << "ERROR: *ROTATION_AXIS_AND_ANGLE does not contain four values for xyz and angle (in degree)! -- " << parameter << "\n";
00552                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00553                         return NULL;
00554                     }
00555                 }
00556 
00557                 // Process Model Scale
00558                 else if ( strName.compare( "*SCALE" ) == 0 ) {
00559                     vTransformName.push_back( "SCALE" );
00560                     bool isOK = true;
00561                     // x
00562                     begIdx = parameter.find_first_not_of( delims, endIdx );
00563                     endIdx = parameter.find_first_of( delims, begIdx );
00564                     if ( begIdx == std::string::npos )  isOK = false;
00565                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00566                     // y
00567                     begIdx = parameter.find_first_not_of( delims, endIdx );
00568                     endIdx = parameter.find_first_of( delims, begIdx );
00569                     if ( begIdx == std::string::npos )  isOK = false;
00570                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00571                     // z
00572                     begIdx = parameter.find_first_not_of( delims, endIdx );
00573                     endIdx = parameter.find_first_of( delims, begIdx );
00574                     if ( begIdx == std::string::npos )  isOK = false;
00575                     if ( isOK ) vTransformValue.push_back( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00576                     // error
00577                     if ( !isOK ) {
00578                         std::cout << "ERROR: *SCALE does not contain three values for xyz! -- " << parameter << "\n";
00579                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00580                         return NULL;
00581                     }
00582                 }
00583 
00584                 // Process Model Point Mass
00585                 else if ( strName.compare( "*POINT_MASS" ) == 0 ) {
00586                     vTransformName.push_back( "POINT_MASS" );
00587                     begIdx = parameter.find_first_not_of( delims, endIdx );
00588                     endIdx = parameter.find_first_of( delims, begIdx );
00589                     if ( begIdx != std::string::npos ) {
00590                         tPointMass = atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() );
00591                     }
00592                     else {
00593                         std::cout << "ERROR: *POINT_MASS does not contain a value! -- " << parameter << "\n";
00594                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00595                         return NULL;
00596                     }
00597                 }
00598                 // Process Model Spring Stiffness
00599                 else if ( strName.compare( "*K_STIFFNESS" ) == 0 ) {
00600                     vTransformName.push_back( "K_STIFFNESS" );
00601                     begIdx = parameter.find_first_not_of( delims, endIdx );
00602                     endIdx = parameter.find_first_of( delims, begIdx );
00603                     if ( begIdx != std::string::npos ) {
00604                         tKstiffness = atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() );
00605                     }
00606                     else {
00607                         std::cout << "ERROR: *K_STIFFNESS does not contain a value! -- " << parameter << "\n";
00608                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00609                         return NULL;
00610                     }
00611                 }
00612                 // Process Model Spring Damper
00613                 else if ( strName.compare( "*K_DAMPER" ) == 0 ) {
00614                     vTransformName.push_back( "K_DAMPER" );
00615                     begIdx = parameter.find_first_not_of( delims, endIdx );
00616                     endIdx = parameter.find_first_of( delims, begIdx );
00617                     if ( begIdx != std::string::npos ) {
00618                         tKdamper = atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() );
00619                     }
00620                     else {
00621                         std::cout << "ERROR: *K_DAMPER does not contain a value! -- " << parameter << "\n";
00622                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00623                         return NULL;
00624                     }
00625                 }
00626                 // Process Model Home Spring Stiffness
00627                 else if ( strName.compare( "*HOME_K_STIFFNESS" ) == 0 ) {
00628                     vTransformName.push_back( "HOME_K_STIFFNESS" );
00629                     begIdx = parameter.find_first_not_of( delims, endIdx );
00630                     endIdx = parameter.find_first_of( delims, begIdx );
00631                     if ( begIdx != std::string::npos ) {
00632                         tHomeKstiffness = atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() );
00633                     }
00634                     else {
00635                         std::cout << "ERROR: *HOME_K_STIFFNESS does not contain a value! -- " << parameter << "\n";
00636                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00637                         return NULL;
00638                     }
00639                 }
00640                 // Process Model Home Spring Damper
00641                 else if ( strName.compare( "*HOME_K_DAMPER" ) == 0 ) {
00642                     vTransformName.push_back( "HOME_K_DAMPER" );
00643                     begIdx = parameter.find_first_not_of( delims, endIdx );
00644                     endIdx = parameter.find_first_of( delims, begIdx );
00645                     if ( begIdx != std::string::npos ) {
00646                         tHomeKdamper = atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() );
00647                     }
00648                     else {
00649                         std::cout << "ERROR: *HOME_K_DAMPER does not contain a value! -- " << parameter << "\n";
00650                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00651                         return NULL;
00652                     }
00653                 }
00654 
00655 
00656                 // Process Model Predefined Time Step
00657                 else if ( strName.compare( "*PREDEFINED_TIME_STEP" ) == 0 ) {
00658                     vTransformName.push_back( "PREDEFINED_TIME_STEP" );
00659                     begIdx = parameter.find_first_not_of( delims, endIdx );
00660                     endIdx = parameter.find_first_of( delims, begIdx );
00661                     if ( begIdx != std::string::npos ) {
00662                         predefinedTimeStep = atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() );
00663                     }
00664                     else {
00665                         std::cout << "ERROR: *PREDEFINED_TIME_STEP does not contain a value! -- " << parameter << "\n";
00666                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00667                         return NULL;
00668                     }
00669                 }
00670                 // Process Model Number of Simulation Sub-Steps
00671                 else if ( strName.compare( "*NUM_SIM_SUB_STEPS" ) == 0 ) {
00672                     vTransformName.push_back( "NUM_SIM_SUB_STEPS" );
00673                     begIdx = parameter.find_first_not_of( delims, endIdx );
00674                     endIdx = parameter.find_first_of( delims, begIdx );
00675                     if ( begIdx != std::string::npos ) {
00676                         numSimSubSteps = static_cast<int>( atof( parameter.substr( begIdx, endIdx-begIdx ).c_str() ) );
00677                     }
00678                     else {
00679                         std::cout << "ERROR: *NUM_SIM_SUB_STEPS does not contain a value! -- " << parameter << "\n";
00680                         while ( line[0] != '}' )    ifs.getline( line, 256 );
00681                         return NULL;
00682                     }
00683                 }
00684             }
00685 
00686             // Set the beginning index to the last position in the input line
00687             begIdx = std::string::npos;
00688         }
00689         // Next line
00690         ifs.getline( line, 256 );
00691     }
00692 
00693     std::cout << "tPointMass: " << tPointMass << "\n";
00694     std::cout << "tKstiffness: " << tKstiffness << "\n";
00695     std::cout << "tKdamper: " << tKdamper << "\n";
00696     std::cout << "tHomeKstiffness: " << tHomeKstiffness << "\n";
00697     std::cout << "tHomeKdamper: " << tHomeKdamper << "\n";
00698 
00699     ModelForSurgery<T> * pModelForSurgery = NULL;
00700     data_location = path + data_location;
00701     //std::cout << "PATH: " << data_location + path << "\n";
00702     switch ( model_type ) {
00703 
00704         // Organs
00705         case ModelForSurgery<T>::HEART:
00706             pModelForSurgery = new ModelOrganHeart<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00707             break;
00708         case ModelForSurgery<T>::LEFT_KIDNEY:
00709             pModelForSurgery = new ModelOrganLeftKidney<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00710             break;
00711         case ModelForSurgery<T>::RIGHT_KIDNEY:
00712             pModelForSurgery = new ModelOrganRightKidney<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00713             break;
00714         case ModelForSurgery<T>::LIVER:
00715             pModelForSurgery = new ModelOrganLiver<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00716             break;
00717         //case ModelForSurgery<T>::LEFT_LUNG:   pModelForSurgery = new ModelOrganLeftLung<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );     break;
00718         //case ModelForSurgery<T>::RIGHT_LUNG:  pModelForSurgery = new ModelOrganRightLung<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );    break;
00719         case ModelForSurgery<T>::STOMACH:
00720             pModelForSurgery = new ModelOrganStomach<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00721             break;
00722 
00723         // For Practice
00724         case ModelForSurgery<T>::TISSUE_BOX_01:
00725             pModelForSurgery = new ModelTissueBox01<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00726             break;
00727         case ModelForSurgery<T>::TISSUE_TWO_TUBES_01:
00728             pModelForSurgery = new ModelTissueTwoTubes01<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00729             break;
00730         case ModelForSurgery<T>::TISSUE_HIATUS_HERNIA_01:
00731             pModelForSurgery = new ModelTissueHiatusHernia01<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00732             break;
00733 
00734         case ModelForSurgery<T>::RIGID_TORUS_01:
00735             pModelForSurgery = new ModelRigidTorus01<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00736             break;
00737 
00738         // ADD A MODEL HERE
00739         /*
00740         case ModelForSurgery<T>::MODEL_CALL_NAME:
00741             pModelForSurgery = new Model_NAME<T>( data_location, tPointMass, tKstiffness, tKdamper, tHomeKstiffness, tHomeKdamper, iRigidity, predefinedTimeStep, numSimSubSteps );
00742             break;
00743         */
00744     }
00745 
00746     if ( !pModelForSurgery )    std::cout << "A model of type " << model_type << "is NOT successfully set!\n";
00747 
00748     //---------------------------------------------------------------
00749     // Set properties
00750     pModelForSurgery->SetName( name );
00751     if ( bSimOn )       pModelForSurgery->SetOperationFlag( ModelForSurgery<T>::SIMULATION_ON );
00752     else                pModelForSurgery->ClearOperationFlag( ModelForSurgery<T>::SIMULATION_ON );
00753     if ( bColDetOn )    pModelForSurgery->SetOperationFlag( ModelForSurgery<T>::COLLISION_ON );
00754     else                pModelForSurgery->ClearOperationFlag( ModelForSurgery<T>::COLLISION_ON );
00755     if ( bRenderOn )    pModelForSurgery->SetOperationFlag( ModelForSurgery<T>::RENDER_ON );
00756     else                pModelForSurgery->ClearOperationFlag( ModelForSurgery<T>::RENDER_ON );
00757 
00758     //---------------------------------------------------------------
00759     // Apply Transformations
00760     TransformationSupport<T> * transform = &(pModelForSurgery->GetTransform());
00761     int nextPos = 0;
00762     for ( int i = 0; i < static_cast<int>( vTransformName.size() ); ++i ) {
00763         if      ( vTransformName[i].compare( "TRANSLATION" ) == 0 ) {
00764             transform->ApplyTranslation( vTransformValue[nextPos], vTransformValue[nextPos+1], vTransformValue[nextPos+2] );
00765             nextPos += 3;
00766         }
00767         else if ( vTransformName[i].compare( "ROTATION_AXIS_AND_ANGLE" ) == 0 ) {
00768             transform->ApplyRotationAxisAndAngle( vTransformValue[nextPos], vTransformValue[nextPos+1], vTransformValue[nextPos+2], vTransformValue[nextPos+3] );
00769             nextPos += 4;
00770         }
00771         else if ( vTransformName[i].compare( "SCALE" ) == 0 ) {
00772             transform->ApplyScale( vTransformValue[nextPos], vTransformValue[nextPos+1], vTransformValue[nextPos+2] );
00773             nextPos += 3;
00774         }
00775     }
00776     //---------------------------------------------------------------
00777 
00778     std::cout << *pModelForSurgery << " is successfully set.\n";
00779 
00780     return pModelForSurgery;
00781 }
00782 
00783 //=============================================================================
00784 END_NAMESPACE_TAPs
00785 //-----------------------------------------------------------------------------
00786 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00787 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines