void printCocktail(Cocktail* c) { if (!c) return; cout << "____________________" << endl; if (!c->getName().empty()) cout << "Name: " << c->getName() << endl; if (!c->getImagePath().empty()) cout << "Image path: " << c->getImagePath() << endl; if (!c->getBaseRecipe().empty()) cout << "Base recipe: " << c->getBaseRecipe() << endl; if (!c->getOptionalRecipe().empty()) cout << "Optional recipe: " << c->getOptionalRecipe() << endl; if (!c->getIngredientList().empty()) { list<Ingredient*> list = c->getIngredientList(); cout << "Ingredients: " << list.size() << endl; while (!list.empty()) { Ingredient* i = list.front(); cout << i->getName() << " " << i->getQuantity() << " " << i->isImportant() << endl; list.pop_front(); } } cout << "____________________" << endl; }
TEST(Ingredient, DISABLED_view) { Ingredient * ingre = new Ingredient(); //mix_by_itself(*ingre); mix_raw_data(*ingre); for (size_t i = 0; i < ingre->bunch_size(); ++i) { MotionsViewer * v = new MotionsViewer(ingre->raw_before_cook[i]); v->get_camera().distance += 2; } }
TEST(Ingredient, DISABLED_cook_patches) { Ingredient * ingre = new Ingredient(); //mix_by_itself(*ingre); mix_raw_data(*ingre); cout << "motion size: " << ingre->size_mot() << " & " << "posture size: " << ingre->size_pos() << endl; PatchCooker cooker_(ingre); time_t start_time; time(&start_time); vector<pair_section> psec = cooker_.init_interactions(); time_t cur_time; time(&cur_time); cout << "Interactions Detecting time is " << difftime(cur_time, start_time) << endl; cooker_.init_EETable(); time_t mid_time; time(&mid_time); cooker_.agglomerative_cluster(); time(&cur_time); cout << "Clustering time is " << difftime(cur_time, mid_time) << endl; /*size_t boundary_pose_size = 6; cooker_.mold_motion_patches(boundary_pose_size); cooker_.cook_motion_patches();*/ cooker_.tcook_motion_patches(); time(&cur_time); cout << "Total time is " << difftime(cur_time, start_time) << endl; if (!cooker_.patches->empty()) { cooker_.evaluate_this_system(); string save_file_str = "cooked_rawData_chicken_6"; //write_patches(cooker_.get_all_patches(), save_file_str); PatchesViewer * v = new PatchesViewer(cooker_.get_all_patches()); //v->set_origin_motions(cooker_); v->get_camera().distance += 2; } for (size_t i = 0; i < ingre->bunch_size(); ++i) { vector<pair_section> bunch_sect; for (auto it = psec.begin(); it != psec.end(); ++it) { if (it->bunch_idx == i) { bunch_sect.push_back(*it); } } MotionsViewer * v = new MotionsViewer(ingre->raw_before_cook[i]); v->interact_pair = bunch_sect; v->get_camera().distance += 2; } }
TEST(Ingredient, DISABLED_comb_determine) { Ingredient * ingre = new Ingredient(); //mix_by_itself(*ingre); mix_raw_data(*ingre); cout << "motion size: " << ingre->size_mot() << " & " << "posture size: " << ingre->size_pos() << endl; PatchCooker cooker_(ingre); time_t start_time; time(&start_time); vector<pair_section> psec = cooker_.init_interactions(); time_t cur_time; time(&cur_time); cout << "Interactions Detecting time is " << difftime(cur_time, start_time) << endl; cooker_.init_EETable(); time_t mid_time; time(&mid_time); cooker_.agglomerative_cluster(3.5); time(&cur_time); cout << "Clustering time is " << difftime(cur_time, mid_time) << endl; cooker_.comb_cook_motion_patches(4); time(&cur_time); cout << "Total time is " << difftime(cur_time, start_time) << endl; vector<pair_section> bunch_sect; for (size_t i = 0; i < ingre->bunch_size(); ++i) { for (auto it = psec.begin(); it != psec.end(); ++it) { if (it->bunch_idx == i) { bunch_sect.push_back(*it); } } MotionsViewer * v = new MotionsViewer(ingre->raw_before_cook[i]); v->interact_pair = bunch_sect; v->get_camera().distance += 2; } if (!cooker_.patches->empty()) { cooker_.evaluate_this_system(); PatchesViewer * pv = new PatchesViewer(cooker_.get_all_patches()); pv->interact_pair = bunch_sect; pv->set_origin_motions(cooker_); pv->get_camera().distance += 2; } }
TEST(Ingredient, DISABLED_dofinder) { Ingredient * ingre = new Ingredient(); //mix_by_itself(*ingre); mix_raw_data(*ingre); PatchCooker cooker_(ingre); vector<pair_section> psec = cooker_.init_interactions(); for (size_t i = 0; i < ingre->bunch_size(); ++i) { vector<pair_section> bunch_sect; for (auto it = psec.begin(); it != psec.end(); ++it) { if (it->bunch_idx == i) { bunch_sect.push_back(*it); } } MotionsViewer * v = new MotionsViewer(ingre->raw_before_cook[i]); v->interact_pair = bunch_sect; v->get_camera().distance += 2; } }
TEST(Ingredient, DISABLED_combi_save_patches) { Ingredient * ingre = new Ingredient(); //mix_by_itself(*ingre); mix_raw_data(*ingre); cout << "motion size: " << ingre->size_mot() << " & " << "posture size: " << ingre->size_pos() << endl; PatchCooker cooker_(ingre); time_t start_time; time(&start_time); vector<pair_section> psec = cooker_.init_interactions(); time_t cur_time; time(&cur_time); cout << "Interactions Detecting time is " << difftime(cur_time, start_time) << endl; cooker_.init_EETable(); time_t mid_time; time(&mid_time); cooker_.agglomerative_cluster(); time(&cur_time); cout << "Clustering time is " << difftime(cur_time, mid_time) << endl; cooker_.comb_cook_motion_patches(); time(&cur_time); cout << "Total time is " << difftime(cur_time, start_time) << endl; if (!cooker_.patches->empty()) { cooker_.evaluate_this_system(); string save_file_str = "cooked_rawData_chicken_combi_6"; write_patches(cooker_.get_all_patches(), save_file_str); PatchesViewer * v = new PatchesViewer(cooker_.get_all_patches()); //v->set_origin_motions(cooker_); v->get_camera().distance += 2; } }
void ObjectLayer::CreateIngredient(Ingredient::Type type, const Vec2& pos) { Ingredient* item; Ingredient::DefInfo def; switch (type) { case Ingredient::IT_PORK: item = Pork::create(); item->SetDef(def); item->InitWeaponInfo(); break; case Ingredient::IT_BEEF: item = Beef::create(); item->SetDef(def); item->InitWeaponInfo(); break; case Ingredient::IT_WHEAT: item = Wheat::create(); item->SetDef(def); item->InitWeaponInfo(); break; case Ingredient::IT_RICE: item = Rice::create(); item->SetDef(def); item->InitWeaponInfo(); break; case Ingredient::IT_ONION: item = Onion::create(); item->SetDef(def); item->InitWeaponInfo(); break; case Ingredient::IT_BEAN: item = Bean::create(); item->SetDef(def); item->InitWeaponInfo(); break; case Ingredient::IT_PEPPER: item = Pepper::create(); item->SetDef(def); item->InitWeaponInfo(); break; default: return; } auto physicsLayer = this->getParent(); auto layerPos = physicsLayer->getPositionX(); item->setPosition(Vec2(pos.x - layerPos, pos.y)); this->addChild(item); }
void Inventory::ingredientQuanitityAdjustment(Ingredient ingredientbeingChanged, int newQuantity) { if(ifInStock(ingredientbeingChanged)) { ingredientsInStock.at(searchForIngredient(ingredientbeingChanged)).setQuantity(newQuantity); }// if(isInStock(ingredientbeingChanged)) else { ingredientbeingChanged.setQuantity(newQuantity); addIngredient(ingredientbeingChanged); }// if(isInStock(ingredientbeingChanged)) }// void Inventory::ingredientQuanitityAdjustment(Ingredient ingredientbeingChanged, int newQuantity)
int Inventory::searchForIngredient(Ingredient ingredientToFind) { int tempCounter = 0; int indexOfVectorIngredient = 0; std::string tempNameHolder; for( tempCounter = 0; tempCounter < ingredientsInStock.size(); tempCounter++ ) { tempNameHolder = ingredientsInStock.at(tempCounter).getName(); if(ingredientToFind.getName() == tempNameHolder) { indexOfVectorIngredient = tempCounter; }//if(comparisonString == ingredientToSearchfor) }// for( tempCounter = 0; tempCounter < ingredientVector.size(); tempCounter++ ) return indexOfVectorIngredient; }// void Inventory::searchForIngredient(Ingredient ingredientToFind)
bool Inventory::ifInStock(Ingredient ingredientToFind) { bool ingredientWasFound = false; int tempCounter = 0; std::string tempNameHolder; for( tempCounter = 0; tempCounter < ingredientsInStock.size(); tempCounter++ ) { tempNameHolder = ingredientsInStock.at(tempCounter).getName(); if(ingredientToFind.getName() == tempNameHolder) { ingredientWasFound = true; }// if(ingredientToFind.getName() == tempNameHolder) }// for( tempCounter = 0; tempCounter < ingredientInStock.size(); tempCounter++ ) return ingredientWasFound; }// bool Inventory::ifInStock(Ingredient ingredientToFind)
//case 3: open and subtract inventory lists from a file from the current inventory lists void MenuList::subtractInventoryFile(string inFileName){ cin.clear(); cin.ignore(); vector <Ingredient> tempIngredientInventory; vector <Equipment> tempEquipmentInventory; cout << "Please enter the file name:" << endl; cin >> inFileName; // while(getline(cin,inFileName)){ TiXmlDocument doc; bool loadOkay = doc.LoadFile(inFileName.c_str()); if(!loadOkay){ cerr << doc.ErrorDesc() << endl; }else{ //define root - recipeCollection TiXmlElement *inventoryElement = doc.RootElement(); Recipe recipe; while(inventoryElement){ //ingredientlist TiXmlElement *ingredientlistElement = inventoryElement->FirstChildElement(); //equipment TiXmlElement *equipmentElement = ingredientlistElement->NextSiblingElement(); //ingredient TiXmlElement *ingredientElement = ingredientlistElement->FirstChildElement(); if(strcmp(inventoryElement->Value(),"inventory")!=0){ if(!silent){ cerr << "cannot open file: " << inFileName << endl; } } //Read ingredientList while(ingredientlistElement && ingredientElement){ if(strcmp(ingredientElement->Value(), "ingredient")== 0){ Ingredient ingredient; tempIngredientInventory.push_back(ingredient.inputIngredient(ingredientElement)); } else{ cout << "no ingredient" << endl;; } ingredientElement = ingredientElement->NextSiblingElement(); } //Read equipmentList while(equipmentElement){ if(strcmp(equipmentElement->Value(), "equipment")== 0){ Equipment equipment; equipment.equipment = equipmentElement->GetText(); equipment.count =1; tempEquipmentInventory.push_back(equipment); // cout << equipmentElement->GetText() << endl; }else{ cout << "no equipment"; } equipmentElement = equipmentElement->NextSiblingElement(); } break; } //subtract the ingredient inventory list for (int i=0; i < ingredientInventory.size(); i++){ for(int j=0; j < tempIngredientInventory.size() ; j++) if(ingredientInventory[i].fooditem==tempIngredientInventory[j].fooditem){ if(ingredientInventory[i].quantity-tempIngredientInventory[j].quantity > 0){ ingredientInventory[i].quantity=ingredientInventory[i].quantity-tempIngredientInventory[j].quantity; if(ingredientInventory[i].unit!=tempIngredientInventory[j].unit){ ingredientInventory[i].unit=ingredientInventory[i].unit+tempIngredientInventory[j].unit; } }else{ ingredientInventory.erase(ingredientInventory.begin()+i); } } } for (int i=0; i < equipmentInventory.size(); i++){ for(int j=0; j < tempEquipmentInventory.size(); j++){ if(equipmentInventory[i].equipment==tempEquipmentInventory[j].equipment){ if (equipmentInventory[i].count-tempEquipmentInventory[j].count>0){ equipmentInventory[i].count=equipmentInventory[i].count-tempEquipmentInventory[j].count; }else{ equipmentInventory.erase(equipmentInventory.begin()+i); } } } } if (!silent){ cout << "Subtract inventory completed" << endl; } return; } }
void MenuList::inputRecipe(){ cin.clear(); cin.ignore(); string inFileName; string line; vector<string> inFileNames; cout << "Please enter the file name:" << endl; // cin >> inFileName; while(getline(cin,line)){ stringstream record(line); record >> inFileName; TiXmlDocument doc; bool loadOkay = doc.LoadFile(inFileName.c_str()); if(!loadOkay){ cerr << doc.ErrorDesc() << endl; }else{ //define root - recipeCollection TiXmlElement *recipeElement = doc.RootElement(); Recipe recipe; while(recipeElement){ //recipe title TiXmlElement *titleElement = recipeElement->FirstChildElement(); TiXmlElement *recipeinfoElement = NULL; TiXmlElement * ingredientlistElement = NULL; TiXmlElement * servingElement = NULL; TiXmlElement * notesElement = NULL; TiXmlElement *preparationElement = NULL; TiXmlElement *equipmentElement = NULL; if(strcmp(titleElement->NextSiblingElement()->Value(),"recipeinfo")==0){ //recipeinfo recipeinfoElement = titleElement->NextSiblingElement(); //ingredientlist ingredientlistElement = recipeinfoElement->NextSiblingElement(); }else{ ingredientlistElement = titleElement->NextSiblingElement(); } //preparation preparationElement = ingredientlistElement->NextSiblingElement(); //ingredient TiXmlElement *ingredientElement = ingredientlistElement->FirstChildElement(); //equipment // equipmentElement = preparationElement->FirstChildElement(); if(strcmp(preparationElement->NextSiblingElement()->Value(),"serving")==0){ servingElement = preparationElement->NextSiblingElement(); if(strcmp(servingElement->NextSiblingElement()->Value(),"notes")==0){ notesElement = servingElement->NextSiblingElement(); } }else if (strcmp(preparationElement->NextSiblingElement()->Value(),"notes")==0){ notesElement = preparationElement->NextSiblingElement(); } if(strcmp(recipeElement->Value(),"recipe")!=0){ cerr << "cannot open recipe file: " << inFileName << endl; } //Read title if(titleElement && (strcmp(titleElement->Value(), "title")== 0)){ recipe.recipeTitle = titleElement->GetText(); // cout << titleElement->GetText() << endl; }else{ cout << "no recipe title" << endl;; } //Read ingredientList while(ingredientlistElement && ingredientElement){ if(strcmp(ingredientElement->Value(), "ingredient")== 0){ Ingredient ingredient; recipe.ingredientsList.push_back(ingredient.inputIngredient(ingredientElement)); }else{ cout << "no ingredient" << endl; } ingredientElement = ingredientElement->NextSiblingElement(); } //Read equipmentList while(preparationElement && equipmentElement){ if(strcmp(equipmentElement->Value(), "equipment")== 0){ Equipment equipment; equipment.equipment = equipmentElement->GetText(); equipment.count =1; recipe.equipmentList.push_back(equipment); // cout << equipmentElement->GetText() << endl; }else{ cout << "no equipment" << endl; } equipmentElement = equipmentElement->NextSiblingElement(); } recipeCollection.push_back(recipe); if (!silent){ cout << "New recipe loaded" << endl; } return; } } } }
bool IngreComp(Ingredient &ingre1, Ingredient &ingre2) { return ((ingre1.getName() < ingre2.getName()) ? true : false); }
AssemblageHelper::E_FileStatus ComponentReader::parseIngredient( Ingredient** out_ingredient, ifstream* p_file ) { AssemblageHelper::E_FileStatus status = AssemblageHelper::FileStatus_OK; Ingredient* ingredient = NULL; char componentPrefix = ' '; status = AssemblageHelper::peekNextCharFromStream( &componentPrefix, p_file ); // If there's no error and componentName defines a component if( status == AssemblageHelper::FileStatus_OK && componentPrefix == 'c' ) { string componentName =""; status = AssemblageHelper::readLineFromStream( NULL, &componentName, p_file ); if( !ComponentFactory::isComponentRegistrered( componentName )) { status = AssemblageHelper::FileStatus_COMPONENT_NOT_FOUND; throw AssemblageException("Component "+componentName+" not found! ", __FILE__,__FUNCTION__,__LINE__); } else { Component* comp = ComponentFactory::createInstance( componentName ); if( comp->getComponentTypeId() == ComponentType::NON_EXISTING) { status = AssemblageHelper::FileStatus_COMPONENT_TYPE_IDX_NOT_SET; } else { ingredient = new Ingredient( componentName ); char nextPrefix = ' '; // As long as the file is ok and the next line defines data. Create ComponentData do { status = AssemblageHelper::peekNextCharFromStream( &nextPrefix, p_file ); string dataLine = ""; if( nextPrefix == 'd') { // read componentName, make sure it's data status = AssemblageHelper::readLineFromStream( NULL, &dataLine, p_file ); ComponentData data; status = parseComponentDataLine( &data, dataLine ); if( status == AssemblageHelper::FileStatus_OK || status == AssemblageHelper::FileStatus_END_OF_FILE ) { ingredient->addData( data ); } } } while( status == AssemblageHelper::FileStatus_OK && nextPrefix == 'd'); } delete comp; } } if( out_ingredient != NULL) { *out_ingredient = ingredient; } else { delete ingredient; ingredient = NULL; } return status; }
void IngredientParserDialog::parseText() { previewIngView->clear(); Q3ListViewItem *last_item = 0; int line_num = 0; QStringList ingredients; if (ingredientTextEdit->document()->isEmpty()) ingredients = QStringList(); else ingredients = ingredientTextEdit->toPlainText().split( '\n', QString::SkipEmptyParts); for ( QStringList::const_iterator it = ingredients.constBegin(); it != ingredients.constEnd(); ++it ) { QString line = (*it).simplified(); ++line_num; int format_at = 0; Ingredient ing; //======amount======// int first_space = line.indexOf( " ", format_at+1 ); if ( first_space == -1 ) first_space = line.length(); int second_space = line.indexOf( " ", first_space+1 ); if ( second_space == -1 ) second_space = line.length(); Ingredient i; bool ok; i.setAmount(line.mid(format_at,second_space-format_at),&ok); if ( !ok ) { i.setAmount(line.mid(format_at,first_space-format_at),&ok); if ( ok ) format_at = first_space+1; } else format_at = second_space+1; if ( ok ) { ing.amount = i.amount; ing.amount_offset = i.amount_offset; } else kDebug()<<"no amount on line "<<line_num; //======unit======// first_space = line.indexOf( " ", format_at+1 ); if ( first_space == -1 ) first_space = line.length(); bool isUnit = false; QString unitCheck = line.mid(format_at,first_space-format_at); for ( UnitList::const_iterator unit_it = m_unitList.constBegin(); unit_it != m_unitList.constEnd(); ++unit_it ) { if ( (*unit_it).name() == unitCheck || (*unit_it).plural() == unitCheck || (*unit_it).nameAbbrev() == unitCheck || (*unit_it).pluralAbbrev() == unitCheck ) { isUnit = true; format_at = first_space+1; break; } } if ( isUnit ) { ing.units.setName(unitCheck); ing.units.setPlural(unitCheck); } else kDebug()<<"no unit on line "<<line_num; //======ingredient======// int ing_end = line.indexOf( QRegExp("(,|;)"), format_at+1 ); if ( ing_end == -1 ) ing_end = line.length(); ing.name = line.mid(format_at,ing_end-format_at); format_at = ing_end+2; //======prep method======// int end = line.length(); ing.prepMethodList = ElementList::split(",",line.mid(format_at,end-format_at)); last_item = new IngListViewItem(previewIngView,last_item,ing); enableButtonOk( true ); } }