//-------------------------------------------------- string ofxCsvRow::toString(const vector<string> &row, bool quote, const string &separator) { if(quote) { // quote field vector<string> fields; for(auto field : row) { fields.push_back("\""+field+"\""); } return ofJoinString(fields, separator); } else { // no quotes return ofJoinString(row, separator); } }
string generateCombineSource(int passes, float downsample) { vector<string> combineNames; for(int i = 0; i < passes; i++) { combineNames.push_back("s" + ofToString(i)); } stringstream src; if ( ofIsGLProgrammableRenderer() ){ src << "#version 150\n"; src << "uniform sampler2DRect " << ofJoinString(combineNames, ",") << ";\n"; src << "uniform float brightness;\n"; if(downsample == 1) { src << "const float scaleFactor = 1.;\n"; } else { src << "const float scaleFactor = " << downsample << ";\n"; } src << "in vec2 vTexCoord;\n"; src << "out vec4 vFragColor;\n"; src << "void main(void) {\n"; src << "\tvec2 tc = vTexCoord;\n"; for(int i = 0; i < passes; i++) { src << "\tvFragColor " << (i == 0 ? "=" : "+="); src << " texture(" << combineNames[i] << ", tc);"; src << (i + 1 != passes ? " tc *= scaleFactor;" : ""); src << "\n"; } src << "\tvFragColor *= brightness / " << passes << ".;\n"; src << "}\n"; } else { src << "#version 120\n"; src << "#extension GL_ARB_texture_rectangle : enable\n"; src << "uniform sampler2DRect " << ofJoinString(combineNames, ",") << ";\n"; src << "uniform float brightness;\n"; if(downsample == 1) { src << "const float scaleFactor = 1.;\n"; } else { src << "const float scaleFactor = " << downsample << ";\n"; } src << "void main(void) {\n"; src << "\tvec2 tc = gl_TexCoord[0].st;\n"; for(int i = 0; i < passes; i++) { src << "\tgl_FragColor " << (i == 0 ? "=" : "+="); src << " texture2DRect(" << combineNames[i] << ", tc);"; src << (i + 1 != passes ? " tc *= scaleFactor;" : ""); src << "\n"; } src << "\tgl_FragColor *= brightness / " << passes << ".;\n"; src << "}\n"; } return src.str(); }
void ofApp::callApi() { video.setPaused(true); visionImage.grabScreen(10, 10, 1280, 720); visionImage.save("visionImage.png"); cout << "API CALL" << endl; string json = ofSystem("php /Users/shma/work/vision/vision.php " + ofFilePath::getAbsolutePath("visionImage.png") + " LABEL_DETECTION"); vision.parse(json); loading = true; words.clear(); for(int i = 0; i < vision["responses"][0]["labelAnnotations"][0].size(); i++) { words.push_back(vision["responses"][0]["labelAnnotations"][i]["description"].asString()); } string word = ofJoinString(words, ","); string fileName = "abc.txt"; int frame = video.getCurrentFrame(); b = b + ("[" + ofToString(frame) + "," + word + "]\r\n,"); ofBuffer buffer = ofBuffer( b ); ofBufferToFile( fileName, buffer ); video.setPaused(false); }
void ofxRedisGlob::subscribeThread() { redisContext *sub_rctx; redisReply *sub_reply; struct timeval timeout = { 1, 500000 }; sub_rctx = redisConnectWithTimeout(hostname.c_str(), port, timeout); if (sub_rctx == NULL || sub_rctx->err) { if (sub_rctx) { printf("Connection error: %s\n", sub_rctx->errstr); redisFree(sub_rctx); } else { printf("Connection error: can't allocate redis context\n"); } return; } string cmd = "SUBSCRIBE " + ofJoinString(get_keys, " "); sub_reply = (redisReply *)redisCommand(sub_rctx,cmd.c_str()); freeReplyObject(sub_reply); while(isThreadRunning() && redisGetReply(sub_rctx,(void **)&sub_reply) == REDIS_OK) { if (!strcmp(sub_reply->element[0]->str, "message")) { string channel = sub_reply->element[1]->str; string value = sub_reply->element[2]->str; lock(); get_map[channel] = value; unlock(); } freeReplyObject(sub_reply); } }
//3000 using broadcast //-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); receiver.resize( portList.size()); receiverHub.resize( portList.size()); testSender.resize( portList.size()); senderFromHub.resize( portList.size()); loggers.resize( portList.size()); for(int i=0; i<portList.size(); i++){ receiver[i].setup(portList[i]); receiverHub[i].setup(portList[i]+1); //sender[i].setup("localhost", portList[i]+1); testSender[i].setup("localhost", portList[i]); senderFromHub[i].setup("localhost", portList[i]+10); } //get broadcast vector<string> splited = ofSplitString(localhost, "."); if(splited[0] == "169" && splited[1] == "254"){ splited[2] = "255"; } splited[3] = "255"; broadcast = ofJoinString(splited, "."); senderBroad.setup(broadcast, 3000); //latersender laterSender.resize(10); for(int i=0; i<laterSender.size(); i++) { for(int j=0; j<portList.size(); j++) { laterSender[i].addPort(portList[j]+1); } } }
string ofxWordWrap(string input, int maxWidth, ofTrueTypeFont *font) { vector<string> lines = ofSplitString(input,"\n"); for (int l=0; l<lines.size(); l++) { vector<string> words = ofSplitString(lines[l]," "); int strWidth=0; for (int w=0; w<words.size(); w++) { int nextWidth = font ? font->stringWidth(words[w]+"i") : words[w].length()+1; if (strWidth+nextWidth < maxWidth) { strWidth+=nextWidth; } else { strWidth=nextWidth; words[w] = "\n" + words[w]; } } lines[l] = ofJoinString(words, " "); } return ofJoinString(lines, "\n"); }
//---------- void OscManager::oscReceiveTouchOscChanges(ofxOscMessage &msg) { vector<string> m = ofSplitString(msg.getAddress(), "/"); if (m.size()>1 && m[m.size()-1].length()==1 && ofToInt(m[m.size()-1])>0) { int idx = ofToInt(m[m.size()-1]); m.pop_back(); string address = ofJoinString(m, "/"); if (inputTrackers.count(address) > 0) { oscReceiveProcessTouchOscMessage(address, msg, idx); } } }
void Interface::save( int index ) { vector<string> list; for (int i=0; i<slider.size(); i++) { list.push_back( ofToString( *slider[i].value ) ); } string text = ofJoinString( list," " ); string fileName = "presets/preset" + ofToString( index ) + ".txt"; ofBuffer buffer = ofBuffer( text ); ofBufferToFile( fileName, buffer ); }
void ofxBaseShaderNode::setParameter(string path, int v){ try{ vector<string> tokens = ofSplitString(path, "/", true); string elem = tokens.back(); tokens.pop_back(); getParameter(ofJoinString(tokens, "/")).getInt(elem) = v; } catch(exception e){ cout<<"warning: bad parameter path "<<path<<endl; } }
void CloudsVisualSystemBalloons::selfDrawBackground(){ //we are using this to draw what keywords are missing content if(mainKeyword != ""){ string keystodraw = "PICKED RANDOM PRESET\n"; keystodraw += mainKeyword + "\n" + ofJoinString(keywords, ","); ofPushMatrix(); ofScale(5,5); ofDrawBitmapString(keystodraw, 20,20); ofPopMatrix(); } }
void Compiler::_replaceIncludes(std::string& fileContents) { Poco::RegularExpression includesExpression("#include .*\n"); Poco::RegularExpression::Match match; std::vector<std::string> includes; int numMatches = 0; std::size_t matchOffset = 0; while (matchOffset < fileContents.size()) { if (includesExpression.match(fileContents, matchOffset, match) == 0) break; std::string include; includesExpression.extract(fileContents, match.offset, include); includes.push_back(include); matchOffset = match.offset + match.length; numMatches++; } includesExpression.subst(fileContents, "", Poco::RegularExpression::RE_GLOBAL); ofStringReplace(fileContents, "<includes>", ofJoinString(includes, "")); ofStringReplace(fileContents, "<line>", ofToString(includes.size())); }
void run(){ test_eq(ofTrimFront(" trim this string "),"trim this string ","trimfront"); test_eq(ofTrimBack(" trim this string ")," trim this string","trimback"); test_eq(ofTrim(" trim this string "),"trim this string","trim"); auto split0 = ofSplitString("hi this is a split test", " "); test_eq(split0.size(),6u,"split size"); test_eq(split0[0],"hi","split 0"); test_eq(split0[1],"this","split 1"); test_eq(split0[2],"is","split 2"); test_eq(split0[3],"a","split 3"); test_eq(split0[4],"split","split 4"); test_eq(split0[5],"test","split 5"); auto split1 = ofSplitString(" hi this is a split test ", " "); test_eq(split1.size(),8u,"split no trim size"); test_eq(split1[0],"","split no trim 0"); test_eq(split1[1],"hi","split no trim 1"); test_eq(split1[2],"this","split no trim 2"); test_eq(split1[3],"is","split no trim 3"); test_eq(split1[4],"a","split no trim 4"); test_eq(split1[5],"split","split no trim 5"); test_eq(split1[6],"test","split no trim 6"); test_eq(split1[7],"","split no trim 7"); auto split2 = ofSplitString(" hi this is a split test ", " ", true, true); test_eq(split2.size(),6u,"split trim size"); test_eq(split2[0],"hi","split trim 0"); test_eq(split2[1],"this","split trim 1"); test_eq(split2[2],"is","split trim 2"); test_eq(split2[3],"a","split trim 3"); test_eq(split2[4],"split","split trim 4"); test_eq(split2[5],"test","split trim 5"); auto split3 = ofSplitString(" hi this is a split test ", " ", true, true); test_eq(split2.size(),6u,"split trim2 size"); test_eq(split2[0],"hi","split trim2 0"); test_eq(split2[1],"this","split trim2 1"); test_eq(split2[2],"is","split trim2 2"); test_eq(split2[3],"a","split trim2 3"); test_eq(split2[4],"split","split trim2 4"); test_eq(split2[5],"test","split trim2 5"); test_eq(ofJoinString({"hi","this","is","a","join","test"}," "),"hi this is a join test","join string"); test_eq(ofJoinString({"hi"}," "),"hi","join string 1 element"); test_eq(ofJoinString({}," "),"","join string 0 elements"); std::string replace = "hi this is a replace test"; ofStringReplace(replace,"replace","replaceeee"); test_eq(replace , "hi this is a replaceeee test","replace string element"); test_eq(ofToLower("AbCéÉBbCcc"),"abcéébbccc","tolower"); test_eq(ofToUpper("AbCéÉBbCcc"),"ABCÉÉBBCCC","toupper"); // test #4363 std::vector<string> strs; strs.push_back("hi"); strs.push_back("this"); strs.push_back("is"); strs.push_back("a"); strs.push_back("join"); strs.push_back("test"); test_eq(ofJoinString(strs,","),"hi,this,is,a,join,test","test #4363"); }
void CloudsIntroSequence::drawHelperType(){ ofPushStyle(); glDisable(GL_DEPTH_TEST); ofDisableLighting(); if(!helperFont.isLoaded() || currentHelperFontSize != helperFontSize){ //helperFont.loadFont(GetCloudsDataPath() + "font/Blender-BOOK.ttf", helperFontSize); #ifdef OCULUS_RIFT helperFont.loadFont(GetFontPath(), helperFontSize-2 ); //hack! #else helperFont.loadFont(GetFontPath(), helperFontSize ); //hack! #endif currentHelperFontSize = helperFontSize; } string helpHoverText; ofVec3f basePosition(0,0,0); float helperTextOpacity = 0.0; float scaleModifier = 1.0;// * ofGetMouseX() / ofGetWidth(); #ifdef OCULUS_RIFT if(!startedOnclick){ if(introNodeThree.hover || introNodeTwo.finished){ helpHoverText = "< " + GetTranslationForString("LOOK CENTER"); basePosition = introNodeTwo.worldPosition; helperTextOpacity = powf(ofMap(ofGetElapsedTimef(), CalibrationNode::nodeActivatedTime, CalibrationNode::nodeActivatedTime+.8,0.0,.8,true), 2.) * (1.0 - introNodeThree.percentComplete); } else if(introNodeTwo.hover || introNodeOne.finished){ helpHoverText = GetTranslationForString("LOOK RIGHT") + " >"; basePosition = introNodeOne.worldPosition; helperTextOpacity = powf(ofMap(ofGetElapsedTimef(), CalibrationNode::nodeActivatedTime, CalibrationNode::nodeActivatedTime+.8,0.0,.8,true), 2.); } else { helpHoverText = "< " + GetTranslationForString("LOOK LEFT"); basePosition = introNodeThree.worldPosition; helperTextOpacity = (currentTitleOpacity - titleTypeOpacity) * (1.0 - introNodeOne.percentComplete); } helperFont.setLetterSpacing(helperFontTracking); } #endif if(caughtQuestion != NULL){ basePosition = caughtQuestion->hoverPosition; helpHoverText = GetTranslationForString( caughtQuestion->question ); helperTextOpacity = ofMap(caughtQuestion->hoverPercentComplete, 0.0, .05, 0.0, 1.0, true); scaleModifier = .5; helperFont.setLetterSpacing(helperFontTracking*.1); } //draw the text if(helpHoverText != ""){ ofPushMatrix(); helpHoverText = ofToUpper(helpHoverText); float hoverTextWidth = helperFont.stringWidth(helpHoverText); float hoverTextWidth2,questionTextHeight2; string secondLine; bool twoLines = hoverTextWidth > 500; if(helpHoverText.find("\n") != string::npos){ twoLines = true; vector<string> split = ofSplitString(helpHoverText, "\n", true,true); helpHoverText = split[0]; secondLine = split[1]; hoverTextWidth = helperFont.stringWidth(helpHoverText); hoverTextWidth2 = helperFont.stringWidth(secondLine); // cout << "QUESTION " << helpHoverText << " " << secondLine << endl; } else if(twoLines){ vector<string> pieces = ofSplitString(helpHoverText, " ", true,true); vector<string> firstHalf; vector<string> secondHalf; int halfsize = pieces.size() / 2; firstHalf.insert(firstHalf.begin(), pieces.begin(), pieces.begin() + halfsize); secondHalf.insert(secondHalf.begin(), pieces.begin() + halfsize, pieces.end()); helpHoverText = ofJoinString(firstHalf, " "); secondLine = ofJoinString(secondHalf, " "); hoverTextWidth = helperFont.stringWidth(helpHoverText); hoverTextWidth2 = helperFont.stringWidth(secondLine); } float hoverTextHeight = helperFont.stringHeight(helpHoverText); //basePosition = ofVec3f(0,0,warpCamera.getPosition().z + questionZStopRange.max); #ifdef OCULUS_RIFT getOculusRift().multBillboardMatrix( basePosition ); #else ofTranslate(basePosition); #endif ofRotate(180, 0, 0, 1); //flip around ofScale(scaleModifier*helperFontScale, scaleModifier*helperFontScale, scaleModifier*helperFontScale); ofSetColor(255,255*helperTextOpacity); bool showAbove = !bUseOculusRift && caughtQuestion != NULL && caughtQuestion->tunnelQuadrantIndex == 2; int yOffsetMult = (showAbove) ? -1 : 1; //helperFont.drawString(helpHoverText, -hoverTextWidth/2, yOffsetMult * (helperFontY - hoverTextHeight/2) ); // cout << "helper text opacity " << helperTextOpacity << endl; // cout << "helper font y " << helperFontY << endl; if(twoLines){ if(showAbove){ // cout << "drawing " << helpHoverText << " w " << hoverTextWidth << " h " << helperFontY + hoverTextHeight*1.5 << endl; // cout << "drawing " << secondLine << " w " << hoverTextWidth << " h " << hoverTextHeight << endl; helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY + hoverTextHeight*1.5) ); helperFont.drawString(secondLine, -hoverTextWidth2*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5)); } else{ // cout << "drawing " << secondLine << " w " << hoverTextWidth << " h " << hoverTextHeight << endl; // cout << "drawing " << helpHoverText << " w " << hoverTextWidth << " h " << hoverTextHeight << endl; helperFont.drawString(secondLine, -hoverTextWidth2*.5, yOffsetMult * (helperFontY + hoverTextHeight*1.5) ); helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5)); } } else{ helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5)); } ofPopMatrix(); } if(firstQuestionStopped){ ofPushMatrix(); float questionhintAlpha = ofMap(ofGetElapsedTimef(), firstQuestionStoppedTime, firstQuestionStoppedTime+2, 0.0, .2, true) * (1.0-helperTextOpacity); float hintTextWidth = helperFont.stringWidth(GetTranslationForString("SELECT A QUESTION")); float hintTextHeight = helperFont.stringHeight(GetTranslationForString("SELECT A QUESTION")); basePosition = ofVec3f(0,0,warpCamera.getPosition().z + questionZStopRange.max); #ifdef OCULUS_RIFT getOculusRift().multBillboardMatrix( basePosition ); #else ofTranslate(basePosition); #endif ofRotate(180, 0, 0, 1); //flip around ofScale(helperFontScale*.8, helperFontScale*.8, helperFontScale*.8); ofSetColor(255, 255*questionhintAlpha); helperFont.drawString(GetTranslationForString("SELECT A QUESTION"), -hintTextWidth*.5, hintTextHeight*.5 ); if(caughtQuestion != NULL){ float questionHoldAlpha = ofMap(caughtQuestion->hoverPercentComplete, .2, .3, 0.0, .2, true); ofSetColor(255, 255*questionHoldAlpha); #ifdef MOUSE_INPUT // string textPrompt = GetTranslationForString("CLICK TO SELECT"); string textPrompt = GetTranslationForString(""); #else string textPrompt = GetTranslationForString("HOLD TO SELECT"); #endif hintTextWidth = helperFont.stringWidth(textPrompt); hintTextHeight = helperFont.stringWidth(textPrompt); helperFont.drawString(textPrompt, -hintTextWidth*.5, hintTextHeight*.5 ); } ofPopMatrix(); } ofEnableLighting(); glEnable(GL_DEPTH_TEST); ofPopStyle(); }
string ofxStringBeforeLast(string str, string key) { vector<string> items = ofSplitString(str, key); items.pop_back(); return ofJoinString(items, key); }
void Project::_saveAddons() { ofBuffer buffer(ofJoinString(_addons, "\n")); ofBufferToFile(_path + "/addons.make", buffer); }
void KinectV2Classifier::setLearnXml(ofXml &xml) { // first save the classifier if (trained) { svm.saveModel(ofToDataPath("svmModel.dat")); } // event-parameter mappings xml.addChild("LearnInfo"); xml.setTo("LearnInfo"); // classes xml.addChild("Classes"); xml.setTo("Classes"); for (int i=0; i<classes.size(); i++) { ofXml xml_; xml_.addChild("Class"); xml_.setTo("Class"); xml_.addValue("Name", classes[i]); xml.addXml(xml_); } xml.setToParent(); // ranges xml.addChild("Ranges"); xml.setTo("Ranges"); for (int i=0; i<min.size(); i++) { ofXml xml_; xml_.addChild("Joint"); xml_.setTo("Joint"); xml_.addValue("Min", min[i]); xml_.addValue("Max", max[i]); xml.addXml(xml_); } xml.setToParent(); vector<vector<float> > & entries = data.getEntries(); if (entries.size() > 0) { xml.addChild("Training"); xml.setTo("Training"); for (int i = 0; i < entries.size(); i++) { vector<string> featureStringV; for (int f=1; f<entries[i].size(); f++) { featureStringV.push_back(ofToString(entries[i][f])); } string featureString = ofJoinString(featureStringV, ","); double label = entries[i][0]; ofXml xml_; xml_.addChild("Entry"); xml_.setTo("Entry"); xml_.addValue("Label", label); xml_.addValue("Features", featureString); xml.addXml(xml_); } xml.setToParent(); } if (trained) { xml.addChild("Model"); xml.setTo("Model"); xml.addValue("Path", ofToDataPath("svmModel.dat")); xml.setToParent(); } xml.setToParent(); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetVerticalSync(true); // gui stuff gui.setup("my panel"); // most of the time you don't need a name gui.add(radius.setup("radius", 10, 1, 200)); gui.add(angleThickness.setup("angle thick", 10,2,180)); gui.add(offset.setup("offset", 10.0f,0,180)); gui.add(zPos.setup("z pos",600,0,1000)); gui.add(twists.setup("twists",8,0,32)); gui.add(numSections.setup("sections",64,4,1024)); gui.add(colorA.setup("colorA", ofColor(100, 100, 140), ofColor(0, 0), ofColor(255, 255))); gui.add(colorB.setup("colorB", ofColor(100, 100, 140), ofColor(0, 0), ofColor(255, 255))); gui.add(colorC.setup("colorC", ofColor(100, 100, 140), ofColor(0, 0), ofColor(255, 255))); gui.add(colorD.setup("colorD", ofColor(100, 100, 140), ofColor(0, 0), ofColor(255, 255))); gui.add(rotSpeed.setup("rot. speed",0.0f,-5.0f,5.0f)); gui.add(bBackground.setup("redraw background", true)); gui.add(backgroundColor.setup("bg color",ofColor(0,0,0),ofColor(0,0),ofColor(255,255))); gui.add(bDrawCurve1.setup("draw curve 1", true)); gui.add(bDrawCurve2.setup("draw curve 2", true)); gui.add(bDrawCurve3.setup("draw curve 3", true)); gui.add(res.setup("res",8,3,64)); gui.loadFromFile("settings.xml"); bHide = false; capture = false; drawFaces = 0; // Load a CSV File. if(csv.load("curves.csv")) { //csv.trim(); // Trim leading/trailing whitespace from non-quoted fields. // Like with C++ vectors, the index operator is a quick way to grab row // & col data, however this will cause a crash if the row or col doesn't // exist, ie. the file didn't load. ofLog() << "Print out a specific CSV value"; ofLog() << csv[0][1]; // also you can write... ofLog() << csv[0].at(1); // or you can get the row itself... ofxCsvRow row = csv[0]; ofLog() << row.getString(1); } // A safer method is to use the getters which will do a check on the // given row & col indices but will be slightly slower. ofLog() << "Print out the first value"; ofLog() << csv.getRow(0).getString(0); // Print the table to the console. ofLog() << "Print the table"; //csv.print(); // Uses default separator ",". // ... or do it manually for(auto row : csv) { ofLog() << ofJoinString(row, "|"); } ofVec3f a,b,c,d; for(int i=0;i<csv.getNumRows();i+=5){ ofLog() << "first: " << ofJoinString(csv.getRow(i),"<<>>"); ofLog() << "2nd: " << ofJoinString(csv.getRow(i+1),"<<>>"); ofLog() << "3rd: " << ofJoinString(csv.getRow(i+2),"<<>>"); ofLog() << "4th: " << ofJoinString(csv.getRow(i+3),"<<>>"); ofLog() << "5th: " << ofJoinString(csv.getRow(i+4),"///////////"); a.set(csv.getRow(i).getFloat(0), csv.getRow(i).getFloat(1), csv.getRow(i).getFloat(2) ); b.set(csv.getRow(i+1).getFloat(0), csv.getRow(i+1).getFloat(1), csv.getRow(i+1).getFloat(2) ); c.set(csv.getRow(i+2).getFloat(0), csv.getRow(i+2).getFloat(1), csv.getRow(i+2).getFloat(2) ); d.set(csv.getRow(i+3).getFloat(0), csv.getRow(i+3).getFloat(1), csv.getRow(i+3).getFloat(2) ); curves.push_back(new ofxCurve(a,b,c,d)); } a.set(0,0,0); b.set(200,0,0); c.set(0,200,200); d.set(0,200,0); curve = new ofxCurve(a,b,c,d); ofBackground(backgroundColor); }