Пример #1
0
void MonoTexCube::drawAll()
{
    loadMaterial();
    loadModel();
    draw();
    unloadModel();
    unloadMaterial();
}
Пример #2
0
// deallocates the memory used
void SVMProcessing::cleanUp()
{
	fprintf(stderr, "Unloading model, if any loaded.\n");
   if (model!=NULL) unloadModel(model);

   fprintf(stderr, "Closing log file, if open.\n");
   if (svmLog)
   {
	   fclose(svmLog);
	   svmLog = 0;
   }

   if (projectionsFile)
   {
	   fclose(projectionsFile);
	   svmLog = 0;
   }
   fprintf(stderr, "Clean up finished.\n");
}
Пример #3
0
ResourceModel::~ResourceModel()
{
	unloadModel();
	
}
Пример #4
0
// handles the training
void SVMProcessing::train()
{
	char prefix[BUFF_SIZE], lastCummulativeTrainingFile[BUFF_SIZE], actualCummulativeTrainingFile[BUFF_SIZE], 
		cummulativeModelFile[BUFF_SIZE], cummulativeTestingFile[BUFF_SIZE];
   vector <int> classes, indices;
   
   std::stringstream CmdLn;
   
   vdbPtr->getFinalVolumeFormat(prefix);
   
   // calculating the sliding window and saving a 4D volume
   estimateActivation(1, vdbPtr->interval.maxIndex(), vdbPtr->slidingWindowSize, prefix, vdbPtr->train4DFile);
   
   // getting the volume indexes, excluding the baseline and the first ones discarted by haemodynamic stabilization
   // vdbPtr->interval.getVolumeIndices(vdbPtr->offset, 1, vdbPtr->interval.maxIndex(), indices);
    
   // added on 02AUG2016
   fillVolumeIndexes(vdbPtr,indices);
    
   // getting a vector containing the classes for each volume
   vdbPtr->interval.getClassArray(classes);
   
   char svmMask[BUFF_SIZE], svmTestingFile[BUFF_SIZE];
   sprintf(svmMask, "%s%s", vdbPtr->featuresSuffix, vdbPtr->trainFeatureSuffix);

   if (cummulativeTraining)
   {
	   if (fileExists(featuresTestMask))
	   {
		   fprintf(stderr, "################## Updating %s to %s due to cummulative train option ########################## \n", svmMask, featuresTestMask);
		   CmdLn.str("");
		   CmdLn << "fslmaths " << featuresTestMask << " " << svmMask;
		   fslmaths((char *)CmdLn.str().c_str());
	   }
   }
   
   // transforms the 4D volume in a svm like input file
   saveSVMFile(vdbPtr->train4DFile, svmMask, svmTrainingFile, 0, indices, classes);
   
   CmdLn.str("");
   SVMObj svmObject;
   
   // training
   CmdLn << "svmtrain -t 0 " << svmTrainingFile << " " << svmModelFile;
   svmObject.train(CmdLn.str().c_str());

   CmdLn.str("");

   sprintf(svmTestingFile, "%s%s%s%s", svmDir, "training", vdbPtr->trainFeatureSuffix, ".tst");

   // testing the training data
   CmdLn << "svmpredict " << svmTrainingFile << " " << svmModelFile << " " << svmTestingFile;
   svmObject.predict(CmdLn.str().c_str());
   generateProjetionsGraph(svmTestingFile);

   // testing the training data with the prediction model
   if (fileExists(svmModelPredictFile))
   {
	   CmdLn.str("");
	   sprintf(svmTestingFile, "%s%s%s%s", svmDir, "testing", vdbPtr->trainFeatureSuffix, ".tst");
	   CmdLn << "svmpredict " << svmTrainingFile << " " << svmModelPredictFile << " " << svmTestingFile;
	   svmObject.predict(CmdLn.str().c_str());
	   generateProjetionsGraph(svmTestingFile);
   }

   if (cummulativeTraining)
   {
	   sprintf(lastCummulativeTrainingFile, "%s%s%s%s", svmDir, "cummulative_training", vdbPtr->testFeatureSuffix, ".txt");
	   sprintf(actualCummulativeTrainingFile, "%s%s%s%s", svmDir, "cummulative_training", vdbPtr->trainFeatureSuffix, ".txt");

	   if (fileExists(lastCummulativeTrainingFile))
	   {
		   mergeFiles(svmTrainingFile, lastCummulativeTrainingFile, actualCummulativeTrainingFile);
	   }
	   else copyFile(svmTrainingFile, actualCummulativeTrainingFile);

	   sprintf(cummulativeModelFile, "%s%s%s%s%s", svmDir, "cummulative_", vdbPtr->subject, vdbPtr->trainFeatureSuffix, ".model");

	   // training
	   CmdLn.str("");
	   CmdLn << "svmtrain -t 0 " << actualCummulativeTrainingFile << " " << cummulativeModelFile;
	   svmObject.train(CmdLn.str().c_str());

	   CmdLn.str("");

	   sprintf(cummulativeTestingFile, "%s%s%s%s", svmDir, "cummulative_training", vdbPtr->trainFeatureSuffix, ".tst");


	   // testing the cummulative training data
	   CmdLn << "svmpredict " << actualCummulativeTrainingFile << " " << cummulativeModelFile << " " << cummulativeTestingFile;
	   svmObject.predict(CmdLn.str().c_str());
	   generateProjetionsGraph(cummulativeTestingFile);

	   /*
	   if (fileExists(svmModelPredictFile))
	   {
	   CmdLn.str("");
	   sprintf(cummulativeTestingFile, "%s%s%s%s", svmDir, "cummulative_testing", vdbPtr->trainFeatureSuffix, ".tst");
	   CmdLn << "svmpredict " << actualCummulativeTrainingFile << " " << svmModelPredictFile << " " << cummulativeTestingFile;
	   svmObject.predict(CmdLn.str().c_str());
	   generateProjetionsGraph(cummulativeTestingFile);
	   }
	   */
   }

   
   // Generating weight map volume
   fprintf(stderr, "Generating weight map volumes\n");
   
   sprintf(svmMask, "%s.nii", vdbPtr->featuresTrainSuffix);

   fileExists(svmMask);

   fprintf(stderr, "using %s \n", svmMask);
   model=svm_load_model(svmModelFile);
   if (model != NULL)
   {
	  generateWeightVolume(model, svmMask, 1, svmWeightNormFile);
	  generateWeightVolume(model, svmMask, 0, svmWeightFile);
	  unloadModel(model);
   }

   if (cummulativeTraining)
   {
	   char cummulativeSvmWeightNormFile[BUFF_SIZE], cummulativeSvmWeightFile[BUFF_SIZE];
	   sprintf(cummulativeSvmWeightNormFile, "%s%s%s%s", svmDir, "cummulative_weights_norm", vdbPtr->trainFeatureSuffix, ".nii");
	   sprintf(cummulativeSvmWeightFile, "%s%s%s%s", svmDir, "cummulative_weights", vdbPtr->trainFeatureSuffix, ".nii");

	   model = svm_load_model(cummulativeModelFile);
	   if (model != NULL)
	   {
		   generateWeightVolume(model, svmMask, 1, cummulativeSvmWeightNormFile);
		   generateWeightVolume(model, svmMask, 0, cummulativeSvmWeightFile);
		   unloadModel(model);
	   }
   }
}