int main(void) { double a, b, c; double dlt; seperator(); printf("This program solves quadratic equation ax^2 + bx + c = 0 \n"); printf("Enter the value of a ---> "); scanf("%lf", &a); printf("Enter the value of b ---> "); scanf("%lf", &b); printf("Enter the value of c ---> "); scanf("%lf", &c); seperator(); dlt = delta(a, b, c); printf("Delta = %.3lf \n", dlt); if(dlt==0) { printf("Since delta is zero solution is single real root... \n"); singleRoot(a, b); } else if(dlt>0) { printf("Since delta is greater than zero solution is two real roots... \n"); reelRoot(a, b, dlt); } else { printf("Since delta is less than zero solution is two complex roots... \n"); complexRoot(a, b, dlt); } seperator(); return 0; }
void TTTScoreboard::drawScoreboard(sf::RenderWindow& window) { sf::RectangleShape seperator(sf::Vector2f(WIDTH - padding * 4, 2)); seperator.setPosition(padding * 2, HEIGHT - 10); seperator.setFillColor(LINE_COLOR); window.draw(seperator); shapeXScore.setRotation(45); window.draw(shapeXScore); shapeXScore.setRotation(-45); window.draw(shapeXScore); window.draw(shapeOScore); dot.setPosition(shapeXScore.getPosition() + sf::Vector2f(40, -12)); dot.setFillColor(X_COLOR); window.draw(dot); dot.setPosition(shapeXScore.getPosition() + sf::Vector2f(40, 12)); window.draw(dot); dot.setPosition(shapeOScore.getPosition() + sf::Vector2f(40, -12)); dot.setFillColor(O_COLOR); window.draw(dot); dot.setPosition(shapeOScore.getPosition() + sf::Vector2f(40, 12)); window.draw(dot); window.draw(XScoreText); window.draw(OScoreText); }
std::string Utilities::RemoveSuffix(const std::string& inInput) { std::string seperator("."); unsigned int pos = inInput.find_last_of(seperator); if (pos != std::string::npos) { return inInput.substr(0, pos); } else { return inInput; } }
std::string Utilities::GetFileName(const std::string& inInput) { std::string seperator("\\"); unsigned int pos = inInput.find_last_of(seperator); if(pos != std::string::npos) { return inInput.substr(pos + 1); } else { return inInput; } }
std::string const& CBundle::ResourcePath() { #if defined(_MSC_VER) std::string seperator("\\"); #else std::string seperator("/"); #endif std::map<std::string, std::string>& pathMap = _Instance->_paths; std::map<std::string, std::string>::iterator pairFound = pathMap.find ("resources"); if (pairFound != pathMap.end()) { return pairFound->second; } std::string& path = pathMap["resources"]; const size_t lastSlash = _Instance->_execute.rfind (seperator); if (std::string::npos == lastSlash) { std::cerr << __func__ << ": find last '"<<seperator<<"' from '" << _Instance->_execute << "' failed." << std::endl; return path; } path = _Instance->_execute.substr (0, lastSlash); #if defined(_MSC_VER) path += seperator + "resources" + seperator; // `\resources\` #else path += seperator + ".." + seperator + "Resources" + seperator; // `/../Resources/` #endif std::cout << __func__ << ": resource path : " << path << std::endl; return path; }
void dump_fastlog( void ) { extern unsigned char top_ret; extern unsigned char bot_ret; newline(); if(variables.current_cyl_idx < cfg.num_cyls && variables.lastknock_tpfd[variables.current_cyl_idx] < 1500 && variables.lastknock_tpfd[variables.current_cyl_idx] ) { snprintf(output, OUTPUT_LEN, "%05lu", TICKS_PER_MIN/((unsigned long int) variables.lastknock_tpfd[variables.current_cyl_idx] *90)); print_str(output); seperator(); snprintf(output, OUTPUT_LEN, "%u", cfg.firing_order[variables.current_cyl_idx]); } else { snprintf(output, OUTPUT_LEN, "00000"); print_str(output); seperator(); snprintf(output, OUTPUT_LEN, "0"); } print_str(output); seperator(); dtostrf( (float) (variables.lastknock_volts[variables.current_cyl_idx] * TEN_BIT_LSB), 5, 3, output); print_str(output); seperator(); snprintf(output, OUTPUT_LEN, "%u - %02X - %02X ", variables.rknock, top_ret, bot_ret); print_str(output); return; }
/** * Store credentials to file. * The current content of credentials is stored to a file * with the given path. If file exists it will be overwritten. * If file do not exist a new file is created. * @param path * @return */ bool Credentials::storeCredentialsToFile(const QString &path) { QFile file(path); if (! file.open(QFile::WriteOnly)) { m_errorMsg = QString("Could not open file !"); return false; } QString seperator(":"); QTextStream outStream(&file); QList<Key> keyList = m_credentials.keys(); for (int index=0; index<keyList.size(); ++index) { Key key = keyList[index]; QString keyString = m_keyNames[key]; QString value = m_credentials.value(keyList[index], QString()); outStream << keyString << seperator << value << endl; } file.close(); return true; }
int main( int argc, char **argv ) { std::string seperator(" "); // write std::vector<float> arr; arr.push_back(1.0); arr.push_back(2.0); arr.push_back(3.0); arr.push_back(4.0); std::ofstream ofs("output.txt"); for (int i = 0; i < arr.size(); ++i) { ofs << arr[i] << seperator; } ofs << std::endl; ofs.close(); // read std::vector<float> arr1; std::ifstream ifs("output.txt"); std::string cur_line; while(std::getline(ifs,cur_line)) { while (cur_line.size()) { std::string tmp = jj::get_substr(cur_line, seperator); if (!tmp.compare(seperator)) continue; arr1.push_back( jj::str2double(tmp) ); } } ifs.close(); // verify for (int i = 0; i < arr.size(); ++i) { assert(arr[i] == arr1[i]); } }
void DirectxData::Release() { selectedShader = NO_INDEX; fadeAmount = 0.0f; if (shadows) { shadows->Release(); } for(auto& texture : textures) { texture->Release(); } for(auto& mesh : meshes) { mesh->Release(); } for(auto& mesh : terrain) { mesh->Release(); } for(auto& water : waters) { water->Release(); } for(auto& shader : shaders) { shader->Release(); } for (auto& emitter : emitters) { emitter->Release(); } quad.Release(); sceneTarget.Release(); blurTarget.Release(); backBuffer.Release(); preEffectsTarget.Release(); for (unsigned int i = 0; i < drawStates.size(); ++i) { SafeRelease(&drawStates[i]); } for (unsigned int i = 0; i < samplers.size(); ++i) { SafeRelease(&samplers[i]); } SafeRelease(&noBlendState); SafeRelease(&alphaBlendState); SafeRelease(&alphaBlendMultiply); SafeRelease(&writeState); SafeRelease(&noWriteState); SafeRelease(&swapchain); SafeRelease(&context); SafeRelease(&device); if(debug) { debug->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL); debug->Release(); debug = nullptr; std::string seperator(100, '='); OutputDebugString((seperator + "\n").c_str()); } }
int main(int argc, char* argv[]) { /// generate XML for microglia video images std::string str = std::string("XML"); if( argc == 5 && std::string(argv[1]) == str && atoi(argv[2]) >= 1) // generate project file for the image sequences { SomaExtractor *Somas = new SomaExtractor(); SomaExtractor::OutputImageType::Pointer inputImage = Somas->Read8BitImage("1_8bit.tif"); int width = inputImage->GetLargestPossibleRegion().GetSize()[0]; int height = inputImage->GetLargestPossibleRegion().GetSize()[1]; int row = atoi(argv[3]); // arrange them row by col int col = atoi(argv[4]); std::ofstream ofs("Project.xml"); ofs<< "<?xml version=\"1.0\" ?>"<<std::endl; ofs<< "<Source>"<<std::endl; for( int i = 1; i <= atoi(argv[2]); i++) { int rown = (i-1) / col; int coln = (i-1) % col; int tx = width * 1.1 * coln; int ty = height * 1.1 * rown; ofs<<"\t"<<"<File FileName=\""<<i<<"_CV_ANT.swc\""<<"\t"<<"Type=\"Trace\"\ttX=\""<<tx<<"\"\ttY=\""<<ty<<"\"\ttZ=\"0\"/>"<<std::endl; ofs<<"\t"<<"<File FileName=\""<<i<<"_8bit.tif\""<<"\t"<<"Type=\"Image\"\ttX=\""<<tx<<"\"\ttY=\""<<ty<<"\"\ttZ=\"0\"/>"<<std::endl; ofs<<"\t"<<"<File FileName=\""<<i<<"_soma.mhd\""<<"\t"<<"Type=\"Soma\"\ttX=\""<<tx<<"\"\ttY=\""<<ty<<"\"\ttZ=\"0\"/>"<<std::endl; //ofs<<"\t"<<"<File FileName=\""<<i<<"_soma_features.txt\""<<"\t"<<"Type=\"Nuclei_Table\"\ttX=\""<<tx<<"\"\ttY=\""<<ty<<"\"\ttZ=\"0\"/>"<<std::endl; } ofs<< "</Source>"<<std::endl; delete Somas; return 0; } if( argc < 2 || atoi(argv[1]) < 0 || atoi(argv[1]) > 6) { std::cout<<"Debris: SomaExtraction <0> <IntensityImage> <DebrisImage> <SomaSeeds.txt>"<<std::endl; //std::cout<<"Derbis: SomaExtraction <InputImageFileName> <Centroids.txt> <DiceWidth (typically 100)> <hole filling (typically 10)>\n"; std::cout<<"SomaExtraction: SomaExtraction <1> <InputImageFileName> <InitialContourLabeledImage> <Options>\n"; std::cout<<"SomaExtraction without seeds: SomaExtraction <2> <InputImageFileName> <Options>\n"; std::cout<<"Get Statistics of the image: SomaExtraction <3> <InputImageFileName> \n"; std::cout<<"Normalize intensity: SomaExtraction <4> <InputImageFileName> <Gaussian Blur Sigma> <Global Median> <ratio threshold, if below, autothresholding to keep background>\n"; return 0; } SomaExtractor *Somas = new SomaExtractor(); if( atoi(argv[1]) == 0) /// debris accumulation { std::cout<< "Reading Montage1"<<std::endl; SomaExtractor::OutputImageType::Pointer inputImage = Somas->Read8BitImage(argv[2]); std::cout<< "Reading Montage2"<<std::endl; SomaExtractor::OutputImageType::Pointer debrisImage = Somas->Read8BitImage(argv[3]); std::vector< itk::Index<3> > somaSeeds; std::vector< itk::Index<3> > debrisSeeds; Somas->ReadSeedpoints( argv[4], somaSeeds, 0); std::cout<< somaSeeds.size()<<std::endl; std::cout<< "Generating Debris Centroids..."<<std::endl; Somas->GetDebrisCentroids( debrisImage, debrisSeeds); //Somas->ReadSeedpoints( argv[3], debrisSeeds, 0); std::cout<< debrisSeeds.size()<<std::endl; std::cout<< "Associating Debris with Nucleus..."<<std::endl; Somas->AssociateDebris(inputImage, somaSeeds, debrisSeeds); } else if( atoi(argv[1]) == 1) /// soma segmentation with initial contours { Somas->LoadOptions( argv[4]); // Load params std::cout << "Set input image" << std::endl; //SomaExtractor::ProbImageType::Pointer image = Somas->SetInputImageByPortion(argv[1]); // Load microglia image by portion SomaExtractor::ProbImageType::Pointer image = Somas->SetInputImage(argv[2]); // Load microglia image 16bit std::string InputFilename = std::string(argv[2]); std::string somaImageName = InputFilename; somaImageName.erase(somaImageName.length()-4,somaImageName.length()); somaImageName.append("_soma.mhd"); std::string somaCentroidName = InputFilename; somaCentroidName.erase(somaCentroidName.length()-4,somaCentroidName.length()); somaCentroidName.append("_centroids.txt"); std::string somaFeatureName = InputFilename; somaFeatureName.erase(somaFeatureName.length()-4,somaFeatureName.length()); somaFeatureName.append("_soma_features.txt"); std::cout << "Set initial contour" << std::endl; SomaExtractor::SegmentedImageType::Pointer initialContourImage = Somas->SetInitalContourImage(argv[3]); // Load labeled nucleus image clock_t SomaExtraction_start_time = clock(); std::cout<< "Segmenting..."<<std::endl; std::vector< itk::Index<3> > seedVector; /// SegmentSoma2: GVF Active Contour SomaExtractor::SegmentedImageType::Pointer segImage = Somas->SegmentSomaUsingGradient(image, initialContourImage, seedVector); std::cout << "Total time for SomaExtraction is: " << (clock() - SomaExtraction_start_time) / (float) CLOCKS_PER_SEC << std::endl; /// Compute soma features and write new seeds back if( segImage) { std::cout<< "Writing "<< somaImageName<<std::endl; Somas->writeImage(somaImageName.c_str(), segImage); std::cout<< "Writing "<< somaCentroidName<<std::endl; Somas->writeCentroids( somaCentroidName.c_str() ,seedVector); vtkSmartPointer<vtkTable> table = Somas->ComputeSomaFeatures(segImage); std::cout<< "Writing "<< somaFeatureName<<std::endl; ftk::SaveTable(somaFeatureName.c_str(), table); } } else if( atoi(argv[1]) == 2) /// soma segmentation without initial seeds { Somas->LoadOptions( argv[3]); // Load params std::cout << "Set input image" << std::endl; SomaExtractor::OutputImageType::Pointer image = Somas->Read16BitImage(argv[2]); // Load microglia image 16bit std::string InputFilename = std::string(argv[2]); //std::string bit8FileName = InputFilename; //bit8FileName.erase(bit8FileName.length()-4,bit8FileName.length()); //bit8FileName.append("_8bit.tif"); //Somas->writeImage(bit8FileName.c_str(), image); std::string somaImageName = InputFilename; somaImageName.erase(somaImageName.length()-4,somaImageName.length()); somaImageName.append("_soma.nrrd"); std::string somaCentroidName = InputFilename; somaCentroidName.erase(somaCentroidName.length()-4,somaCentroidName.length()); somaCentroidName.append("_centroids.txt"); std::string somaFeatureName = InputFilename; somaFeatureName.erase(somaFeatureName.length()-4,somaFeatureName.length()); somaFeatureName.append("_soma_features.txt"); std::vector< itk::Index<3> > seedVector; SomaExtractor::ProbImageType::Pointer binImagePtr = Somas->GenerateSeedPoints(image, seedVector); //Somas->ReadSeedpoints(argv[3], seedVector, false); clock_t SomaExtraction_start_time = clock(); std::cout<< "Segmenting..."<<std::endl; /// SegmentSoma1: Active Contour without GVF, eliminate small objects SomaExtractor::SegmentedImageType::Pointer segImage = Somas->SegmentSoma(seedVector, binImagePtr); std::cout << "Total time for SomaExtraction is: " << (clock() - SomaExtraction_start_time) / (float) CLOCKS_PER_SEC << std::endl; /// Compute soma features and write new seeds back if( segImage) { std::cout<< "Writing "<< somaImageName<<std::endl; Somas->writeImage(somaImageName.c_str(), segImage); std::cout<< "Writing "<< somaCentroidName<<std::endl; Somas->writeCentroids( somaCentroidName.c_str() ,seedVector); vtkSmartPointer<vtkTable> table = Somas->ComputeSomaFeatures(segImage); std::cout<< "Writing "<< somaFeatureName<<std::endl; ftk::SaveTable(somaFeatureName.c_str(), table); } } else if( atoi(argv[1]) == 3 && argc == 3) // print out mean and std and the ratio { std::string InputFilename = std::string(argv[2]); char * pch = argv[2]; std::string str; str += "/"; char * token1 = strtok(pch,"/"); char * token2 = strtok(NULL,"/"); while( token2 != NULL) { str += std::string(token1) + "/"; token1 = token2; token2 = strtok(NULL,"/"); } str += "statistics.txt"; std::cout<<str<<std::endl; SomaExtractor::ProbImageType::Pointer image = Somas->SetInputImage(InputFilename.c_str()); Somas->CaculateMeanStd(str, image); } else if( atoi(argv[1]) == 4 && argc == 6) /// normalize the intensity: get background image { std::string InputFilename = std::string(argv[2]); SomaExtractor::ProbImageType::Pointer image = Somas->SetInputImage(InputFilename.c_str()); SomaExtractor::ProbImageType2D::Pointer backgroundImage = Somas->GetBackgroundImageByFirstSlice(image, atof(argv[3])); std::string imageName = InputFilename; imageName.erase(imageName.length()-7,imageName.length()); imageName.append("Ndsu.TIF"); SomaExtractor::UShortImageType::Pointer rescaledImage = Somas->DevideAndScale(image, backgroundImage, atof(argv[4]), atof(argv[5])); Somas->writeImage(imageName.c_str(), rescaledImage); } else if( atoi( argv[1]) == 5) { SomaExtractor::ProbImageType::Pointer inputImage = Somas->SetInputImage8bit(argv[2]); //std::vector< itk::Index<3> > seedVector; //Somas->ReadSeedpoints(argv[3], seedVector, true); Somas->LoadOptions( argv[4]); // Load params vnl_vector<int> seperator(4); seperator[0] = 16; seperator[1] = 23; seperator[2] = 30; seperator[3] = 49; vnl_vector<double> curvature(4); curvature[0] = 0.5; curvature[1] = 0.45; curvature[2] = 0.4; curvature[3] = 0.45; SomaExtractor::SegmentedImageType::Pointer segImage = Somas->SegmentHeart(argv[2], argv[3], inputImage, seperator, curvature); if( segImage) { std::string inputName = std::string(argv[2]); std::string somaImageName = inputName; somaImageName.erase(somaImageName.length()-4,somaImageName.length()); somaImageName.append("_seg.mhd"); Somas->writeImage(somaImageName.c_str(), segImage); //Somas->writeCentroids( argv[3],seedVector); inputName.erase(inputName.length()-4,inputName.length()); inputName.erase(inputName.begin()); int id = atoi(inputName.c_str()); vtkSmartPointer<vtkTable> table = Somas->ComputeHeartFeatures(segImage); ftk::SaveTableAppend("features.txt", table, id); } } //else if( atoi(argv[1]) == 5 && argc == 5) /// normalize by the input background //{ // std::string InputFilename = std::string(argv[2]); // SomaExtractor::ProbImageType::Pointer image = Somas->SetInputImage(InputFilename.c_str()); // SomaExtractor::ProbImageType2D::Pointer backgroundImage = Somas->SetInputImageFloat2D(argv[3]); // SomaExtractor::UShortImageType::Pointer rescaledImage = Somas->DevideAndScaleToOriginalMean(image, backgroundImage, atoi(argv[4])); // // std::string imageName = InputFilename; // imageName.erase(imageName.length()-4,imageName.length()); // imageName.append("_normalize.tif"); // Somas->writeImage(imageName.c_str(), rescaledImage); //} //else if( atoi(argv[1]) == 6 && argc == 5) /// normalize the intensity: get background image //{ // std::string InputFilename = std::string(argv[2]); // //SomaExtractor::ProbImageType::Pointer image = Somas->SetInputImage(argv[2]); // //SomaExtractor::ProbImageType2D::Pointer backgroundImage = Somas->GetBackgroundImage(image, atof(argv[3])); // SomaExtractor::ProbImageType2D::Pointer backModel = Somas->SetInputImage2D(argv[2]); // SomaExtractor::ProbImageType2D::Pointer backimage = Somas->SetInputImage2D(argv[3]); // //std::string imageName = InputFilename; // //imageName.erase(imageName.length()-4,imageName.length()); // //imageName.append("_background.nrrd"); // //Somas->WriteFloat2DImage(imageName.c_str(), backgroundImage); // //std::cout<<"Read background image"<<std::endl; // // // //std::cout<<"NormalizeUsingBackgroundImage"<<std::endl; // Somas->NormalizeUsingBackgroundImage(backModel, backimage, atof(argv[4])); // /*std::string imageName = InputFilename; // imageName.erase(imageName.length()-4,imageName.length()); // imageName.append("_normalize.tif"); // SomaExtractor::UShortImageType::Pointer normalizedImage = Somas->NormalizeUsingBackgroundImage(image, backgroundImage); // Somas->writeImage(imageName.c_str(), normalizedImage);*/ //} //else if( atoi(argv[1]) == 7 && argc == 7) // get seed coordinates //{ // std::vector< itk::Index<3> > seedVector; // Somas->ReadSeedpoints(argv[2], seedVector, false); // std::cout<< "Original Seed Size: "<<seedVector.size()<<std::endl; // std::string InputFilename = std::string(argv[2]); // std::string outputFilename = InputFilename; // outputFilename.erase(outputFilename.length()-4,outputFilename.length()); // outputFilename.append("_crop.txt"); // std::vector< itk::Index<3> > seedInRegion; // Somas->GetSeedpointsInRegion(seedVector, seedInRegion, atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), atoi(argv[6])); // std::cout<< "Seed Size in region: "<<seedInRegion.size()<<std::endl; // Somas->writeCentroids(outputFilename.c_str(), seedInRegion); //} delete Somas; return 0; }
void dump_datalog(void) { unsigned char i = 0; static unsigned char datalog_count = 0; if(datalog_count-- <= 0 && cfg.datalog_header_count < 255) { newline(); snprintf_P(output, OUTPUT_LEN, datalog_title, cfg.seperator, cfg.seperator, cfg.seperator); print_str(output); for(i = 0; i < cfg.num_cyls; i++) { snprintf_P(output, OUTPUT_LEN, cylinder_header, cfg.seperator, cfg.firing_order[i], cfg.seperator, cfg.firing_order[i]); print_str(output); } datalog_count = cfg.datalog_header_count; seperator(); print_str("knock?"); } newline(); snprintf(output, OUTPUT_LEN, "%05d", variables.rpm); print_str(output); seperator(); dtostrf( ((float)(variables.timer_overflows ) / OVERFLOWS_PER_SEC ) + ((float)TCNT1/TICKS_PER_SEC) , 5, 3, output); print_str(output); seperator(); /* snprintf(output, OUTPUT_LEN, "%d", variables.rknock); print_str(output); seperator(); */ dtostrf( (float)(variables.rknock) * TEN_BIT_LSB, 5, 3, output); print_str(output); seperator(); dtostrf( (float)(variables.cur_knock_thresh) * TEN_BIT_LSB, 5, 3, output); // snprintf(output, OUTPUT_LEN, "%d", variables.cur_knock_thresh); print_str(output); // snprintf(output, OUTPUT_LEN, " %d", variables.current_cyl_idx); // print_str(output); seperator(); for(i = 0; i < cfg.num_cyls; i++) { dtostrf( (((float)(variables.lastknock_timer_overflows[i]) ) / OVERFLOWS_PER_SEC) + ((float)(variables.lastknock_timer_val[i])/TICKS_PER_SEC), 5, 3, output); print_str(output); snprintf(output, OUTPUT_LEN, "%s%d%s", cfg.seperator,variables.number_of_knocks[i],cfg.seperator); print_str(output); } if(variables.isknock) print_str("YES"); else print_str("NO"); return; }