// plug in volume function DLLExport volumeFunctionalConectivity(studyParams &vdb, int index, char *volume, void *&userData) { if (index == 1) { FunctionalConnectivity *fcconn = (FunctionalConnectivity *)userData; strcpy(vdb.motionRefVolume, volume); stringstream CmdLn; CmdLn << "bet " << volume << " " << vdb.inputDir << "RFI_sks" << vdb.trainFeatureSuffix << " " << vdb.betParameters; bet((char *)CmdLn.str().c_str()); sprintf(vdb.maskFile, "%sRFI_sks%s", vdb.inputDir, vdb.trainFeatureSuffix); if (fileExists(fcconn->correlationMapFile)) { char outputFile[500]; changeFileExt(fcconn->correlationMapFile, vdb.trainFeatureSuffix, outputFile); functionalNormalization(fcconn->correlationMapFile, fcconn->correlationMapFileRef, vdb.maskFile, outputFile, true); fcconn->connectivityCalculator.loadRegionMap(outputFile); } } return 1; }
IseOptions::IseOptions() { setLogFileName(getAppSubPath("log") + changeFileExt(getAppExeName(false), ".log"), false); setIsDaemon(true); setAllowMultiInstance(false); setServerType(DEF_SERVER_TYPE); setAssistorThreadCount(DEF_ASSISTOR_THREAD_COUNT); setUdpServerPort(DEF_UDP_SERVER_PORT); setUdpListenerThreadCount(DEF_UDP_LISTENER_THREAD_COUNT); setUdpRequestGroupCount(DEF_UDP_REQ_GROUP_COUNT); for (int i = 0; i < DEF_UDP_REQ_GROUP_COUNT; i++) { setUdpRequestQueueCapacity(i, DEF_UDP_REQ_QUEUE_CAPACITY); setUdpWorkerThreadCount(i, DEF_UDP_WORKER_THREADS_MIN, DEF_UDP_WORKER_THREADS_MAX); } setUdpRequestMaxWaitTime(DEF_UDP_REQ_MAX_WAIT_TIME); setUdpWorkerThreadTimeout(DEF_UDP_WORKER_THREAD_TIMEOUT); setUdpRequestQueueAlertLine(DEF_UDP_QUEUE_ALERT_LINE); setUdpAdjustThreadInterval(DEF_UDP_ADJUST_THREAD_INTERVAL); setTcpServerCount(DEF_TCP_SERVER_COUNT); for (int i = 0; i < DEF_TCP_SERVER_COUNT; i++) setTcpServerPort(i, DEF_TCP_SERVER_PORT); for (int i = 0; i < DEF_TCP_SERVER_COUNT; i++) setTcpServerEventLoopCount(i, DEF_TCP_SERVER_EVENT_LOOP_COUNT); setTcpClientEventLoopCount(DEF_TCP_CLIENT_EVENT_LOOP_COUNT); setTcpMaxRecvBufferSize(DEF_TCP_MAX_RECV_BUFFER_SIZE); }
// plug in finalization function DLLExport finalSVM(studyParams &vdb, void *&userData) { if (userData != NULL) { SVMProcessing *svmProcessingVar = (SVMProcessing *) userData; svmProcessingVar->cleanUp(); if (svmProcessingVar->hasPredicted) { char confusionMatrixFile[500]; sprintf(confusionMatrixFile, "%s%s%s.txt", svmProcessingVar->svmDir, "confusionMatrix", vdb.trainFeatureSuffix); svmProcessingVar->accuracyResults.saveMatrixReport(confusionMatrixFile); if (fileExists(svmProcessingVar->projectionsFilename)) { stringstream CmdLn; char pngFile[BUFF_SIZE]; // generating the projections graph png of the actual run changeFileExt(svmProcessingVar->projectionsFilename, ".png", pngFile); fprintf(stderr, "Generating svm projection graphics of the current run performance\n"); CmdLn << "fsl_tsplot -i " << svmProcessingVar->projectionsFilename << " -t \"SVM projections\" -u 1 --start=1 --finish=1 -a Projections -w 640 -h 144 -o " << pngFile; fsl_tsplot((char *)CmdLn.str().c_str()); } } delete svmProcessingVar; userData = NULL; } return 0; }
void P3DImporter::importMaterials() { int numMats = 0; fread( &numMats, sizeof( int ), 1, m_fh ); for( int i = 0; i < numMats; ++i ) { int matStrLen = 0; fread( &matStrLen, sizeof( int ), 1, m_fh ); wchar_t* materialName = new wchar_t[matStrLen]; fread( materialName, sizeof( wchar_t ), matStrLen, m_fh ); char* materialNameChar = new char[ matStrLen ]; int length = wcstombs( materialNameChar, materialName, matStrLen ); if( length == matStrLen ) materialNameChar[ matStrLen - 1 ] = '\0'; // create material std::string materialNameStr = materialNameChar + m_fileName; Material* material = Renderer::createMaterial( materialNameStr, "DiffuseShader" ); material->addUniform( "uUseNormalMap", 0 ); material->addUniform( "uUseEmissiveMap", 0 ); m_materials.push_back( materialNameStr ); int numTexs = 0; fread( &numTexs, sizeof( int ), 1, m_fh ); for( int t = 0; t < numTexs; ++t ) { int texType = -1; int texFileLen = 0; wchar_t* texFile; char* texFileChar; fread( &texType, sizeof( int ), 1, m_fh ); fread( &texFileLen, sizeof( int ), 1, m_fh ); texFile = new wchar_t[ texFileLen ]; fread( texFile, sizeof( wchar_t ), texFileLen, m_fh ); texFileChar = new char[ texFileLen ]; int length = wcstombs( texFileChar, texFile, texFileLen ); //assertion( length != texFileLen && length, "Error parsering texture file: %s", texFileChar ); if( length > 0 ) { std::string newFileName = changeFileExt( std::string( texFileChar ), ".png" ); addTextureToMaterial( material, texType, newFileName ); } } } }
//--------------------------------------------------------------------------- void LogFile::rotate(AsyncFile & file) { if( rotatedFileCount_ == 0 || file.std() || file.size() <= rotationThreshold_ ) return; file.close(); file.exclusive(true).open(); utf8::String fileExt(getFileExt(file.fileName())); uintptr_t i = rotatedFileCount_; while( i >= 1 ){ if( i == rotatedFileCount_ ){ remove(changeFileExt(file.fileName(),"." + utf8::int2Str(i - 1)) + fileExt,true); } else { rename( changeFileExt(file.fileName(),"." + utf8::int2Str(i - 1)) + fileExt, changeFileExt(file.fileName(),"." + utf8::int2Str(i)) + fileExt, true, true ); } i--; } file.close(); rename(file.fileName(),changeFileExt(file.fileName(),".0") + fileExt,true,true); }
void transformDicom(char *filename, char *outdir) { TDCMopts opts; char auxFile[1024]; defaultOptions(opts, outdir); changeFileExt(filename, "", auxFile); extractFileName(auxFile, opts.filename); // opts.isVerbose = 2; if (0) { strcpy(opts.indir, filename); nii_loadDir(&opts); } else singleDICOM(&opts, filename); }
//--------------------------------------------------------------------------- void LogFile::initialize() { new (&stdErr) LogFile; stdErr.fileName(changeFileExt(getExecutableName(),".log")); }
QStringList VideoConverter::getCommandLine() { QStringList parameters; QString extension; parameters << "-i" << validPath(videoItem->getVideoFile()); switch (convConfToUse.outputFormat) { case ofAVI: parameters << "-f" << "avi" << "-vcodec" << "mpeg4"; extension = ".avi"; break; case ofWMV: extension = ".wmv"; break; case ofMPEG1: parameters << "-vcodec" << "mpeg1video"; extension = ".mpg"; break; case ofMPEG2: parameters << "-vcodec" << "mpeg2video"; extension = ".mpeg"; break; case ofMP4: case ofMP4_hd: { QString vpre = convConfToUse.outputFormat == ofMP4 ? "default" : "hq"; // configure h264 codec #ifndef Q_OS_LINUX #ifdef Q_OS_WIN32 bool use_x264 = true; #else bool use_x264 = isRunningOn64bits(); #endif if (use_x264) parameters << "-vcodec" << "libx264" << "-fpre" << QFileInfo(ffmpegApp).absolutePath() + "/ffmpeg-presets/libx264-" + vpre + ".ffpreset"; else // no x264 support parameters << "-f" << "mp4" << "-vcodec" << "mpeg4"; #else parameters << "-vcodec" << "libx264" << "-vpre" << vpre; #endif extension = ".mp4"; break; } case ofAppleiPod: parameters << "-acodec" << "libfaac" << "-ab" << "128kb" << "-vcodec" << "mpeg4" << "-b" << "1200kb" << "-mbd" << "2" << "-cmp" << "2" << "-subcmp" << "2" << "-s" << "320x240"; extension = ".mp4"; break; case ofSonyPSP: parameters << "-acodec" << "libfaac" << "-ab" << "128kb" << "-vcodec" << "mpeg4" << "-b" << "1200kb" << "-mbd" << "2" << "-flags" << "+4mv" << "-trellis" << "2" << "-cmp" << "2" << "-subcmp" << "2" << "-r" << "30000/1001" << "-f" << "psp"; extension = ".mp4"; break; case of3GP: parameters << "-vcodec" << "mpeg4" << "-acodec" << "libfaac" << "-ar" << "8000" << "-ac" << "1" << "-ab" << "12.2k" << "-f" << "3gp"; extension = ".3gp"; break; case ofMP3: extension = ".mp3"; break; } // this is used only for NON Apple iPod videos if (convConfToUse.outputFormat != ofAppleiPod) { switch (convConfToUse.videoResolution) { case vrOriginal: break; case vr96x72: parameters << "-s" << "96x72"; break; case vr128x96: parameters << "-s" << "128x96"; break; case vr160x120: parameters << "-s" << "160x120"; break; case vr176x120: parameters << "-s" << "176x120"; break; case vr176x144: parameters << "-s" << "176x144"; break; case vr192x144: parameters << "-s" << "192x144"; break; case vr240x180: parameters << "-s" << "240x180"; break; case vr320x200: parameters << "-s" << "320x200"; break; case vr320x240: parameters << "-s" << "320x240"; break; case vr352x240: parameters << "-s" << "352x240"; break; case vr352x288: parameters << "-s" << "352x288"; break; case vr480x272: parameters << "-s" << "480x272"; break; case vr480x360: parameters << "-s" << "480x360"; break; case vr480x480: parameters << "-s" << "480x480"; break; case vr624x352: parameters << "-s" << "624x352"; break; case vr640x480: parameters << "-s" << "640x480"; break; case vr720x480: parameters << "-s" << "720x480"; break; case vr720x576: parameters << "-s" << "720x576"; break; } if (convConfToUse.videoFrameRate == vfr15) parameters << "-r" << "15"; else if (convConfToUse.videoFrameRate == vfr24) parameters << "-r" << "24"; else if (convConfToUse.videoFrameRate == vfr25) parameters << "-r" << "25"; else if (convConfToUse.videoFrameRate == vfr29_97) parameters << "-r" << "29.97"; else if (convConfToUse.videoFrameRate == vfr30) parameters << "-r" << "30"; switch (convConfToUse.audioSampleRatio) { case asrOriginal: break; case asr22050: parameters << "-ar" << "22050"; break; case asr44100: parameters << "-ar" << "44100"; break; } switch (convConfToUse.outputQuality) { case oqLower_quality: parameters << "-b" << "384k" << "-ab" << "64k"; break; case oqLow_quality: parameters << "-b" << "512k" << "-ab" << "80k"; break; case oqNormal_quality: parameters << "-b" << "640k" << "-ab" << "96k"; break; case oqMedium_quality: parameters << "-b" << "800k" << "-ab" << "96k"; break; case oqGood_quality: parameters << "-b" << "1000k" << "-ab" << "128k"; break; case oqSuperb_quality: parameters << "-b" << "1200k" << "-ab" << "128k"; break; case oqSame_quality: break; } } videoItem->setVideoFileSavedTo(uniqueFileName(changeFileExt(videoItem->getVideoFile(), extension)), this); parameters << "-y" << validPath(videoItem->getVideoFileSavedTo()); return parameters; }
// function that creates a roi map from glm and a previously defined roi in mni void emotionRoiProcessing::createROIVolume(studyParams &vdb) { // Bring MNI Mask to Subject Space char compositeFile[500], outputFile[500], name[500], regionExtractMapFile[500], roiVolumeFile[500], meanFile[500]; char pngFile[500]; double correlationExtractPercent; stringstream CmdLn; char prefix[30] = "_RFI2"; vector<vector<double>> timeseries; // generating the means file volume<float> v; // preparing timeseries variable timeseries.resize(meanCalculation.roiCount()); for (int i = 0; i < timeseries.size(); i++) timeseries[i].resize(vdb.interval.maxIndex()); // calculating the means for (int i = 0; i < vdb.interval.maxIndex(); i++) { loadVolume(vdb, v, i+1); meanCalculation.calculateMeans(v); for (int j = 0; j < meanCalculation.roiCount(); j++) timeseries[j][i] = meanCalculation.roiMean(j); } // z normalized for (int j = 0; j < timeseries.size(); j++) znormalise(timeseries[j]); // saving the result to file sprintf(meanFile, "%s%s_%s%s.txt", vdb.outputDir, vdb.subject, "means", vdb.trainFeatureSuffix); fstream Output(meanFile, fstream::in | fstream::out | fstream::trunc); for (int i = 0; i < vdb.interval.maxIndex(); i++) { for (int j = 0; j < timeseries.size(); j++) Output << timeseries[j][i] << '\t'; Output << '\n'; } Output.close(); // generating the roi means graph png fprintf(stderr, "Generating roi means graphic\n"); changeFileExt(meanFile, ".png", pngFile); CmdLn << "fsl_tsplot -i " << meanFile << " -t \"z-normalised roi means plot\" -u 1 --start=1 --finish=" << meanCalculation.roiCount() << " -a "; vector<int> roiValues; meanCalculation.getRoiValues(roiValues); // Building the labels with the intensities of the roi volume file int counter=0; CmdLn << '\"'; for (int t = 0; t < roiValues.size(); t++) { CmdLn << "Intensity " << roiValues[t]; counter++; if (counter < meanCalculation.roiCount()) CmdLn << ','; } // completing the command CmdLn << '\"'; CmdLn << " -w 640 -h 144 -o " << pngFile; fsl_tsplot((char *)CmdLn.str().c_str()); extractFileName(vdb.mniMask, name); for (int t = 0; t<strlen(name); t++) if (name[t] == '.') name[t] = '_'; sprintf(outputFile, "%s%s%s.nii", vdb.inputDir, name, vdb.trainFeatureSuffix); MniToSubject(vdb.maskFile, vdb.mniMask, vdb.mniTemplate, outputFile, prefix); // saving a composite file just to assure the side of the roi volume sprintf(compositeFile, "%s%s%s.nii", vdb.inputDir, "compositeFile", vdb.trainFeatureSuffix); uniteVolumes(vdb.rfiFile, outputFile, compositeFile); // read Region extract map file and percentage correlationExtractPercent = vdb.readedIni.GetDoubleValue("FRIEND", "PercentageOfBestVoxelsPerROI") / 100.0; strcpy(regionExtractMapFile, vdb.readedIni.GetValue("FRIEND", "ROIExtractionMapFile")); RegionExtraction extractor; // reading the mappings std::map<int, int> mappings; extractor.readMappings(regionExtractMapFile, mappings); sprintf(roiVolumeFile, "%s%s%s%s", vdb.outputDir, "ROIsMap", vdb.trainFeatureSuffix, ".nii"); // Execute segmentation extractor.regionsExtraction(outputFile, vdb.glmTOutput, vdb.featuresAllTrainSuffix, roiVolumeFile, mappings, correlationExtractPercent); // calculate initial target values for positive and negative conditions if (fileExists(roiVolumeFile)) { meanCalculation.loadReference(roiVolumeFile); positiveIndex = meanCalculation.roiIndex(3); // 3 in the intensity value of positive emotion ROI negativeIndex = meanCalculation.roiIndex(1); // 1 in the intensity value of negative emotion ROI for (int i=1; i <= vdb.interval.maxIndex(); i++) { float classnum, projection; processVolume(vdb, i, classnum, projection); } char negativeCurveFile[BUFF_SIZE], positiveCurveFile[BUFF_SIZE]; sprintf(negativeCurveFile, "%s%c%s%s.txt", vdb.outputDir, PATHSEPCHAR, "negative_curve", vdb.trainFeatureSuffix); sprintf(positiveCurveFile, "%s%c%s%s.txt", vdb.outputDir, PATHSEPCHAR, "positive_curve", vdb.trainFeatureSuffix); positiveActivationLevel.saveCurves(positiveCurveFile); negativeActivationLevel.saveCurves(negativeCurveFile); vdb.readedIni.SetDoubleValue("FRIEND", "NegativeActivationLevel", negativeActivationLevel.mean); vdb.readedIni.SetDoubleValue("FRIEND", "PositiveActivationLevel", positiveActivationLevel.mean); vdb.readedIni.SaveFile(vdb.configFileNameRead); } }