int HolisticRecognizer::initialize(string& strProjectName, string &strProfileName) { LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entered HolisticShapeRecognizer::Initialize" << endl; string LipiRootPath = string(getLipiPath()); string tempStr = ""; string preprocDllPath = ""; headerInfo[PROJNAME] = strProjectName; int returnStatus=0; string strNumShapes = ""; ltkShapeRecPtr = NULL; //path for holistic.cfg m_holisticCfgFile = LipiRootPath + PROJECTS_PATH_STRING + strProjectName + PROFILE_PATH_STRING + strProfileName + SEPARATOR + HOLISTIC + CONFIGFILEEXT; //path for holistic.mdt m_referenceModelFile = LipiRootPath + PROJECTS_PATH_STRING + strProjectName + PROFILE_PATH_STRING + strProfileName + SEPARATOR + HOLISTIC + DATFILEEXT; m_confMapFile = LipiRootPath + PROJECTS_PATH_STRING + strProjectName + PROFILE_PATH_STRING + strProfileName + SEPARATOR; // Read number of shapes from project.cfg tempStr = LipiRootPath + PROJECTS_PATH_STRING + strProjectName + PROFILE_PATH_STRING + PROJECT_CFG_STRING; try { //To find whether the project was dynamic or not //to read read number of shapes from project.cfg m_projectTypeDynamic = shaperecUtilInst->isProjectDynamic(tempStr, m_numShapes, returnStatus, strNumShapes); headerInfo[NUMSHAPES] = strNumShapes; preprocDllPath = LipiRootPath + SEPARATOR + "lib" + SEPARATOR + PREPROC + DLL_EXT; // initialize preprocessor returnStatus = 0; ltkShapeRecPtr = shaperecUtilInst->initializePreprocessor(preprocDllPath, returnStatus); } catch(LTKException e) { LOG( LTKLogger::LTK_LOGLEVEL_ERR) << e.getExceptionMessage() << endl; LTKReturnError(returnStatus); } //setPreprocMap(); // To add function name and the function address into the mapping variable. //Assigning Default Values assignDefaultValues(); //Reading pca configuration file returnStatus = readClassifierConfig(); return returnStatus; }
int main(void) { SnakeData Snake; void (*execute[])(SnakeData*) = { play, speed, instructions, quit }; /* functions of menu options */ Choice choice; prepareConsole(); assignDefaultValues(&Snake); while (true) { choice = menu(&Snake); execute[choice](&Snake); } return 0; }
int featurefilewriter::Initalize(const string& cfgFilepath, const string& strLipiPath, const string& strOutputPath) { try { LTKControlInfo tmpControlInfo; tmpControlInfo.lipiRoot = strLipiPath; tmpControlInfo.toolkitVersion = SUPPORTED_MIN_VERSION; tmpControlInfo.cfgFilePath = cfgFilepath; if( (tmpControlInfo.lipiRoot).empty() ) { throw LTKException(ELIPI_ROOT_PATH_NOT_SET); } if ( tmpControlInfo.toolkitVersion.empty() ) { throw LTKException(ENO_TOOLKIT_VERSION); } if ( tmpControlInfo.cfgFilePath.empty() ) { throw LTKException(EINVALID_CFG_FILE_ENTRY); } assignDefaultValues(); m_lipiRootPath = tmpControlInfo.lipiRoot; m_nnCfgFilePath = cfgFilepath; m_FDTFilePath = strOutputPath; int errorCode = initializePreprocessor(tmpControlInfo,&m_ptrPreproc); if( errorCode != SUCCESS) { LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << errorCode << " " << "featurefilewriter::Initalize()" <<endl; throw LTKException(errorCode); } //Reading configuration file errorCode = readClassifierConfig(); if( errorCode != SUCCESS) { cout<<endl<<"Encountered error in readClassifierConfig"<<endl; LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << errorCode << " " << "featurefilewriter::Initalize()" <<endl; throw LTKException(errorCode); } errorCode = initializeFeatureExtractorInstance(tmpControlInfo); if( errorCode != SUCCESS) { LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << errorCode << " " << "featurefilewriter::Initalize()" <<endl; throw LTKException(errorCode); } } catch(LTKException e) { deletePreprocessor(); //Unloading the feature Extractor instance deleteFeatureExtractorInstance(); if(NULL != m_OSUtilPtr) { delete m_OSUtilPtr; m_OSUtilPtr = NULL; } throw e; } return 0; }
SPConfig spConfigCreate(const char* filename, SP_CONFIG_MSG* msg){ int configLineCounter = 0; char line[MAX_STRING_LEN]; int n = MAX_STRING_LEN; int valueFlag = 0; /* flag == 1 if word is a value, and 0 if its a variable name */ if(filename == NULL){ *msg = SP_CONFIG_INVALID_ARGUMENT; return NULL; } SPConfig config = (SPConfig)malloc(sizeof(struct sp_config_t));//TODO free memory! if(config == NULL){ *msg = SP_CONFIG_ALLOC_FAIL; return NULL; } FILE* configFile = fopen(filename, "r"); if(configFile == NULL){ *msg = SP_CONFIG_CANNOT_OPEN_FILE; return NULL; } assignDefaultValues(config); /* for each line in the configuration file*/ while(fgets(line,n,configFile) != NULL){ char* string; const char * delimiter = EQUALS; char value[MAX_STRING_LEN]; char variableName[MAX_STRING_LEN]; char statusMSG[MAX_STRING_LEN] = INTERNAL_STATUS_SUCCESS; configLineCounter++; valueFlag = 0; if(isLineCommentLine(line)) continue; string = strtok(line, delimiter); /*making sure a non-comment line doesn't contain any Hash signs */ if (isThereAHashSignInTheMiddleOfTheLine(line)) { printf(INVALID_CONFIG_LINE_ERROR_MSG, filename, configLineCounter ); *msg = SP_CONFIG_INVALID_ARGUMENT; free(config); fclose(configFile); return NULL; } while(string != NULL ){ if(valueFlag == 0){ memset(variableName, 0, sizeof(variableName)); getCleanWordFromString(string, variableName); /*printf ("Clean variableName =%s\n",variableName);*/ /*makes sure the variable name doesn't contain any spaces*/ /* if (!isStringValid(variableName)) { printf(INVALID_CONFIG_LINE_ERROR_MSG, filename, configLineCounter ); *msg = SP_CONFIG_INVALID_ARGUMENT; free(config); fclose(configFile); return NULL; } */ } if(valueFlag == 1){ memset(value, 0, sizeof(value)); getCleanWordFromString(string, value); /*printf ("Clean valueName =%s\n",value);*/ /*makes sure the value name doesn't contain any spaces*/ /* if (!isStringValid(value)) { printf(INVALID_CONFIG_LINE_ERROR_MSG, filename, configLineCounter ); *msg = SP_CONFIG_INVALID_ARGUMENT; free(config); fclose(configFile); return NULL; }*/ assignValueToVariable(config, variableName, value, statusMSG, msg, filename, configLineCounter); if((strncmp(statusMSG, INTERNAL_STATUS_INVALID_CONFIG_LINE, 19) == 0) || (strncmp(statusMSG, INTERNAL_STATUS_CONSTRAIT_NOT_MET, 17) == 0)){ free(config); fclose(configFile); return NULL; } } string = strtok(NULL, delimiter); valueFlag = 1; } } if(strncmp(config->spImagesDirectory, INTERNAL_DEFAULT_STRING_VALUE,20) == 0){ printf(PARAMATER_IS_NOT_SET_ERROR_MSG, filename, configLineCounter, "spImagesDirectory"); *msg = SP_CONFIG_MISSING_DIR; free(config); fclose(configFile); return NULL; } if(strncmp(config->spImagesPrefix, INTERNAL_DEFAULT_STRING_VALUE,20) == 0){ printf(PARAMATER_IS_NOT_SET_ERROR_MSG, filename, configLineCounter, "spImagesPrefix"); *msg = SP_CONFIG_MISSING_PREFIX; free(config); fclose(configFile); return NULL; } if(strncmp(config->spImagesSuffix, INTERNAL_DEFAULT_STRING_VALUE,20) == 0){ printf(PARAMATER_IS_NOT_SET_ERROR_MSG, filename, configLineCounter, "spImagesSuffix"); *msg = SP_CONFIG_MISSING_PREFIX; free(config); fclose(configFile); return NULL; } if((config->spNumOfImages == -1)){ printf(PARAMATER_IS_NOT_SET_ERROR_MSG, filename, configLineCounter, "spNumOfImages" ); *msg = SP_CONFIG_MISSING_NUM_IMAGES; free(config); fclose(configFile); return NULL; } fclose(configFile); return config; }