int ns__MatToJPG (struct soap *soap, char *InputMatFilename, char **OutputMatFilename) { double start, end; start = omp_get_wtime(); Mat src; /* check if it is not 8U then convert to 8UC(n) */ int chan = src.channels(); if( src.type() != 0 || src.type() != 8 || src.type() != 16 ) { src.convertTo(src, CV_8UC(chan)); } /* generate output file name */ *OutputMatFilename = (char*)soap_malloc(soap, FILENAME_SIZE); getOutputFilename(OutputMatFilename,".jpg"); if(!imwrite(*OutputMatFilename, src)) { cerr<< "MatToJPG:: can not save mat to jpg file" << endl; return soap_receiver_fault(soap, "MatToJPG:: can not save mat to jpg file", NULL); } src.release(); end = omp_get_wtime(); cerr<<"ns__MatToJPG "<<"time elapsed "<<end-start<<endl; return SOAP_OK; }
int MainWindow::appendEnergy(std::ofstream& outfile, uint methodIndex, int basisIndex, uint jobtypeIndex, uint solvIndex){ //return values // 0:OK //-1:cannot open log file //-2:TODO error termination TODO //-3:TODO no termination found TODO //-4:cannot find output block start //-5:cannot find output block end std::string outputBlock; QString inputPath; int ret; double energy; inputPath=ui->inputFolderBox->text(); if (!inputPath.endsWith('/')) inputPath.append("/"); inputPath.append(getOutputFilename(methodIndex, basisIndex, jobtypeIndex, solvIndex)); inputPath.append(".log"); ret=getOutputBlock(inputPath.toStdString(), outputBlock); if (ret<0) return ret; if (checkedMethods[methodIndex]=="HF"||checkedMethods[methodIndex]=="B3LYP"||checkedMethods[methodIndex]=="B3PW91"||checkedMethods[methodIndex]=="M05"|| checkedMethods[methodIndex]=="M052X"||checkedMethods[methodIndex]=="M06"||checkedMethods[methodIndex]=="M062X"){ energy= std::stod(outputBlock.substr(outputBlock.find("\\HF=-")+4, outputBlock.find("\\", outputBlock.find("\\HF=-")+4)-4-outputBlock.find("\\HF=-"))); } if (checkedMethods[methodIndex]=="MP2"){ energy= std::stod(outputBlock.substr(outputBlock.find("\\MP2=-")+5, outputBlock.find("\\", outputBlock.find("\\MP2=-")+5)-5-outputBlock.find("\\MP2=-"))); } if (checkedMethods[methodIndex]=="CCSD"){ energy= std::stod(outputBlock.substr(outputBlock.find("\\CCSD=-")+6, outputBlock.find("\\", outputBlock.find("\\CCSD=-")+6)-6-outputBlock.find("\\CCSD=-"))); } outfile<<energy<<";"; return 0; }
QString MainWindow::writeGJF(uint methodIndex, int basisIndex, uint jobtypeIndex, uint solvIndex){ //output path and filename handling QString outputPath=ui->OutputFolderBox->text(); if (!outputPath.endsWith('/')) outputPath.append("/"); QString outputFilename=getOutputFilename(methodIndex, basisIndex, jobtypeIndex, solvIndex); outputPath.append(outputFilename); outputPath.append(".gjf"); std::ofstream outfile; outfile.open(outputPath.toStdString(), std::ios::trunc); //write link0 settings if (ui->checkpointBox->isChecked()){ outfile<<"%chk="<<outputFilename.toStdString()<<".chk"<<std::endl; } if (!ui->link0settings->toPlainText().isEmpty()){ outfile<<ui->link0settings->toPlainText().toStdString()<<std::endl; } outfile<<getRouteLine(methodIndex, basisIndex, jobtypeIndex, solvIndex); //empty line outfile<<std::endl; //job title outfile<<outputFilename.toStdString()<<std::endl; //empty line outfile<<std::endl; //charge and multiplicity outfile<<ui->chargeSpinbox->value()<<" "<<ui->multiplicitySpinbox->value()<<std::endl; //the molecule specification outfile<<ui->MolSpecTextbox->toPlainText().toStdString(); //end the file with 3 newlines and close it outfile<<std::endl<<std::endl<<std::endl; outfile.close(); return outputPath; }
int ns__bitwiseAnd( struct soap *soap, char *src1, char *src2, char **OutputMatFilename) { double start, end; start = omp_get_wtime(); Mat matSrc1; if(!readMat(src1, matSrc1)) { cerr << "And :: src1 can not read bin file" << endl; return soap_receiver_fault(soap, "And :: src1 can not read bin file", NULL); } Mat matSrc2; if(!readMat(src2, matSrc2)) { cerr << "And :: src2 can not read bin file" << endl; return soap_receiver_fault(soap, "And :: src2 can not read bin file", NULL); } int cols = matSrc1.cols ; int srcType1 = matSrc1.type(); int srcType2 = matSrc2.type(); if(srcType1 != srcType2 ) { matSrc2.convertTo(matSrc2, srcType1); } Mat dst; bitwise_and(matSrc1, matSrc2, dst); /* generate output file name */ *OutputMatFilename = (char*)soap_malloc(soap, 60); getOutputFilename(OutputMatFilename,"_bitwiseAnd"); /* save to bin */ if(!saveMat(*OutputMatFilename, dst)) { cerr << "And:: save mat to binary file" << endl; return soap_receiver_fault(soap, "And :: save mat to binary file", NULL); } matSrc1.release(); matSrc2.release(); dst.release(); end = omp_get_wtime(); cerr<<"ns__And time elapsed "<<end-start<<endl; return SOAP_OK; }
// FIXME: what's this? // 1. A function called by someone else that does something? // Call it complete() or some other verb // 2. An event handler called when something else completes? // Call it onThingComplete() void BootStrap::completed() { WaitForSingleObject( m_progressDialogShown, INFINITE ); HWND hwndOkButton = GetDlgItem( m_hwndDialog, IDC_BUTTONOK ); HWND hwndCancelButton = GetDlgItem( m_hwndDialog, IDC_BUTTONCANCEL ); EnableWindow( hwndOkButton, true ); EnableWindow( hwndCancelButton, false ); RegistryUtils::DeleteValue( m_bootStrapHkey, m_mediaPlayerName ); if( !m_tracksFound ) { SetWindowTextW( GetDlgItem( m_hwndDialog, IDC_LABEL ), m_strNoTracksFoundLabel.c_str() ); RegistryUtils::CloseRegKey( m_bootStrapHkey ); return; } xmlBuffer << L"</bootstrap>\n"; int maxUtf8Size = xmlBuffer.str().size() * 2; char* utf8Data = new char[maxUtf8Size]; int utf8Size = EncodingUtils::UnicodeToUtf8( xmlBuffer.str().c_str(), xmlBuffer.str().length(), utf8Data, maxUtf8Size ); FILE* file = _wfopen( getOutputFilename().c_str(), L"wb" ); fwrite( utf8Data, sizeof(char), utf8Size, file ); fclose( file ); if( m_scrobSub ) m_scrobSub->BootstrapComplete( m_userName.c_str() ); SetWindowTextW( GetDlgItem( m_hwndDialog, IDC_LABEL ), m_strCompleteLabel.c_str() ); RegistryUtils::CloseRegKey( m_bootStrapHkey ); m_bootStrapHkey = NULL; SetFocus( hwndOkButton ); log( "bootstrap completed, will wait for dialogthread event" ); WaitForSingleObject( m_hDialogThread, INFINITE ); log( "dialogthread event wait over" ); }
bool FileHandler::process_folder(std::string inputFolder, std::string outputFolder, FrameProcessor* processor) { // get file name std::string tmp_inputFile, tmp_outputFile, windowName = outputFolder; cv::Mat input, output; cv::Mat tmp_bgDynamics, m, tmp_bgNoise, tmp_gradMagnMap, tmp_rawOut; double minVal, maxVal, epsilon = 1e-6; for (fs::directory_iterator it(inputFolder), end; it != end; ++it) { if (fs::is_regular_file(it->path()) && (it->path().filename().string().find(m_inputSuffix) != std::string::npos)) { tmp_inputFile = it->path().filename().string(); tmp_outputFile = getOutputFilename(tmp_inputFile); } input = cv::imread(it->path().string(), CV_LOAD_IMAGE_COLOR); output.create(input.size(), CV_8U); processor->process(input, output); if (m_showProcessing) { tmp_bgDynamics = (processor->getBackgroundDynamics()); // TODO: find a way to normalize matrix such that it can be visualized tmp_bgNoise = processor->getNoiseMap(); tmp_gradMagnMap = processor->getGradMagnMap(); tmp_rawOut = processor->getRawOutput(); cv::imshow(windowName, output); cv::imshow(windowName + " Input", input); cv::imshow("Background dynamics", tmp_bgDynamics); cv::imshow("Raw segmentation", tmp_rawOut); cv::imshow("Background Noise", tmp_bgNoise); cv::imshow("Gradient magnitude map", tmp_gradMagnMap); if (cv::waitKey(1) == 27) // 27 = ESC break; } cv::imwrite(outputFolder + "\\" + tmp_outputFile, output); } processor->resetProcessor(); input.release(); output.release(); tmp_bgNoise.release(); tmp_bgDynamics.release(); cv::destroyAllWindows(); return true; }
void MainWindow::on_gatherEnergyButton_clicked(){ if ((methodCount*basisCount*jobtypeCount*solvCount)==0){ QMessageBox::information(this, tr("Nothing to do"), tr("No output file can be read. Tick more checkboxes.")); }else{ if (ui->inputFolderBox->text().isEmpty()){ QMessageBox::information(this, tr("No input folder"), tr("Specify the input folder.")); }else{ if (ui->NameStub->text().isEmpty()){ QMessageBox::information(this, tr("No naming stub"), tr("Specify a naming stub.")); }else{ if (ui->energyOutputBox->text().isEmpty()){ QMessageBox::information(this, tr("No energy output file"), tr("Specify the energy output file.")); }else{ remove(ui->energyOutputBox->text().toStdString().c_str()); std::ofstream outfile; outfile.open(ui->energyOutputBox->text().toStdString().c_str()); outfile<<std::setprecision(15); outfile<<" ;"; if (checkedBasises.size()>0){ for (uint j=0; j<checkedBasises.size(); j++){ outfile<<checkedBasises[j]<<";"; } outfile<<std::endl; } for (uint i=0; i<checkedMethods.size(); i++){ for (uint k=0; k<checkedJobtypes.size(); k++){ for (uint l=0; l<checkedSolv.size(); l++){ outfile<<getOutputFilename(i,-1,k,l).toStdString()<<";"; if (checkedBasises.size()>0){ for (uint j=0; j<checkedBasises.size(); j++){ int ret=appendEnergy(outfile, i,j,k,l); if (ret<0) QMessageBox::warning(this, tr("appendEenergy Failed"), ("appendEnegy failed with error "+QVariant(ret).toString())); } }else{ int ret=appendEnergy(outfile, i,-1,k,l); if (ret<0) QMessageBox::warning(this, tr("appendEenergy Failed"), ("appendEnegy failed with error "+QVariant(ret).toString())); } outfile<<std::endl; } } } outfile.close(); } } } } }
int ns__dilate( struct soap *soap, char *InputMatFilename, char *elementFilename, int iteration=1, char **OutputMatFilename=NULL) { double start, end; start = omp_get_wtime(); Mat src; if(!readMat(InputMatFilename, src)) { cerr << "dilate :: can not read bin file" << endl; return soap_receiver_fault(soap, "dilate :: can not read bin file", NULL); } Mat dst; Mat element; if(!readMat(elementFilename, element)) { cerr<<"dilate :: use default element"<<endl; element.release(); dilate(src, dst, Mat(), Point(-1, -1), iteration); } else { cerr<<"dilate :: use defined element"<<endl; dilate(src, dst, element, Point(-1, -1), iteration); } /* generate output file name */ *OutputMatFilename = (char*)soap_malloc(soap, 60); getOutputFilename(OutputMatFilename,"_dilate"); /* save to bin */ if(!saveMat(*OutputMatFilename, dst)) { cerr << "dilate :: save mat to binary file" << endl; return soap_receiver_fault(soap, "dilate :: save mat to binary file", NULL); } src.release(); dst.release(); element.release(); return SOAP_OK; }