bool ofxLocalization::load(string languageFile){
	//flanguageFile = ofToDataPath(languageFile);
	if(ofFilePath::getFileExt(languageFile) != "csv"){
		ofLogError("ofxLocalization::load") << "Expecting CSV file extension: " << languageFile;
	}
	ofFile file(languageFile);
	if(!file.exists()){
		ofLogError("ofxLocalization::load") << " file not found: " << languageFile;
		return false;
	}
	ofBuffer csv = ofBuffer(file);
	string header = ofToLower(csv.getNextLine());
	vector<string> headerComponents = ofSplitString(header, ",",true,true);
	if(headerComponents.size() == 0){
		ofLogError("ofxLocalization::load") << "looks like your header is not a comma delimited file" << header;
		return false;
	}
	if(headerComponents[0] != "key"){
		ofLogWarning("ofxLocalization::load") << "expects the first entry to be key: " << header;
	}
	languages.clear();
	for(int i = 1; i < headerComponents.size(); i++){
		string language = headerComponents[i];
		languages.push_back(language);
		translation[language] = map<string,string>();
		ofLogVerbose("ofxLocalization::load") << "found language " << language;
	}
	
	if(languages.size() == 0){
		ofLogError("ofxLocalization::load") << "didn't find any languages in header: " << header;
		return false;
	}
	
	int line = 0;
	while (!csv.isLastLine()) {
		string nextLine = csv.getNextLine();
		vector<string> components = ofSplitString(nextLine, ",",true,true);
		if(components.size() == 0){
			ofLogVerbose("ofxLocalization::load") << " Skipping empty line " << line;
		}
		else {
			string key = components[0];
			if(key != ""){
				ofLogVerbose("ofxLocalization::load") << "building translation entry for " << key;
				keys.push_back(key);
				for(int i = 1; i < components.size(); i++){
					if(components[i] != "" && i-1 < languages.size()){
						translation[languages[i-1]][key] = components[i];
						ofLogVerbose("ofxLocalization::load") << key << "	translates to " << components[i] << " in " << languages[i-1];
					}

				}
			}
		}
		line++;
	}
	
	currentLanguage = languages[0];
	return true;
}
Exemplo n.º 2
0
Node::Node(MToken *m) {
    setup(m->inputInfo, m->outputInfo, m->iconData, m->iconSize);
    nID = m->tID;
    mtkn = m;
    module.loadImage(ofBuffer(m->iconData, m->iconSize));
    resizeIcon(60);
}
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
ofBuffer ofxOscMessage::getArgAsBlob( int index ) const
{
    if ( getArgType(index) != OFXOSC_TYPE_BLOB )
	{
        ofLogError("ofxOscMessage") << "getArgAsBlob(): argument " << index << " is not a blob";
        return ofBuffer();
	}
	else
        return ((ofxOscArgBlob*)args[index])->get();
}
Exemplo n.º 5
0
void Node::nodeBig(MToken *m) {
    setup(m->inputInfo, m->outputInfo, m->iconData, m->iconSize);
    nID = m->tID;
    mtkn = m;
    x = 0;
    y = 0;
    radius *= 3;
    module.loadImage(ofBuffer(m->iconData, m->iconSize));
    resizeIcon(60*3);
}
Exemplo n.º 6
0
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 );
}
Exemplo n.º 7
0
//--------------------------------------------------------------
void ofApp::update(){
    videos[0].update();
    videos[0].setSpeed(videoSpeed);
    
    sec = 0;
    
    if (videos[0].getCurrentFrame() >= oneMin) {
        sec = videos[0].getCurrentFrame() / oneMin;
        if (sec == 10) {
            beforeRate = rates[sec][1].asInt();
        }
    }
    videoSpeed = 10;
    currentCluster = cls[sec];

    currentRate = rates[sec][1].asInt();
    scoreRate =  ofMap(currentRate, minMaxRate.x , minMaxRate.y , -1.0, 1.0);
    
    currentTaion = taions[sec][1].asFloat();
    scoreTaion = ofMap(currentTaion, minMaxTaion.x , minMaxTaion.y, -1.0, 1.0);
    myGlitch.ShadeVal[0] =  scoreTaion / 2;
    //cout << myGlitch.ShadeVal[0] << endl;
    
    myGlitch.setFx(OFXPOSTGLITCH_CONVERGENCE,true);

    if (currentCluster == choosedCluster) {
        fileName = targetDate + "_" + ofToString(choosedCluster) + "_frame.csv";
        ofBuffer buffer = ofBufferFromFile(fileName);
        buffer.append(ofBuffer(ofToString(videos[0].getCurrentFrame()) + "\r\n" ));
        
        ofBufferToFile( fileName, buffer );
        videoSpeed = 1;
        myGlitch.setFx(OFXPOSTGLITCH_CONVERGENCE,false);
    }
    
    fbos[0].begin();
    videos[0].draw(0, 0, videoSize.x, videoSize.y);
    fbos[0].end();
}
void testApp::saveData()
{
    ofFileDialogResult f;
    f = ofSystemSaveDialog("pattern.svg", " ");
    string filePath = f.getPath();

    string svg;

    svg += "<svg xmlns=\"http://www.w3.org/2000/svg\" ";
    svg += "width=\"" + ofToString(ofGetWidth()) + "\" ";
    svg += "height=\"" + ofToString(ofGetHeight()) + "\" ";
    svg += ">\n";
    svg += "<title>" + f.getName() + "</title>\n";
    svg += "<rect x =\"0\" y =\"0\" width=\"" +
           ofToString(ofGetWidth()) + "\" " + "height=\"" + ofToString(ofGetHeight()) + "\" ";
    svg += "fill=\"#ffffff\" />\n";

    for(Circle c : circles)
    {
        ofVec3f parentPos = c.pos.getPosition();
        svg += "<path d=\"M ";
        svg += ofToString(parentPos.x + c.tri[0].x) + " ";
        svg += ofToString(parentPos.y + c.tri[0].y) + " ";
        svg += "L ";
        svg += ofToString(parentPos.x + c.tri[1].x) + " ";
        svg += ofToString(parentPos.y + c.tri[1].y) + " ";
        svg += "L ";
        svg += ofToString(parentPos.x + c.tri[2].x) + " ";
        svg += ofToString(parentPos.y + c.tri[2].y) + " ";
        svg += " z \" fill=\"#000000\" /> \n";
    }
    svg += "</svg>";

    ofFile file(filePath, ofFile::WriteOnly);
    file.writeFromBuffer(ofBuffer(svg));
    file.close();
}
Exemplo n.º 9
0
//--------------------------------------------------------------
void testApp::frameEvent() {
    
    
    
    char udpMessage1[230400];
    
    udpConnection1.Receive(udpMessage1,230400);
	ofBuffer buffer1 = ofBuffer(udpMessage1, 230400);
    
//    client.broadcast(ofToString(buffer1) + ",");
//    client.broadcast(",");
	
    if(test1.loadImage(buffer1)){
        img1.setFromPixels(test1.getPixelsRef());
        //img2.setFromPixels(test1.getPixelsRef());
        cout << "set pixels" << endl;
    }
    
    char udpMessage2[230400];
    
    udpConnection2.Receive(udpMessage2,230400);
	ofBuffer buffer2 = ofBuffer(udpMessage2, 230400);
    
    //    client.broadcast(ofToString(buffer1) + ",");
    //    client.broadcast(",");
	
    if(test2.loadImage(buffer2)){
        img2.setFromPixels(test2.getPixelsRef());
        cout << "set pixels" << endl;
    }

    char udpMessage3[230400];
    
    udpConnection3.Receive(udpMessage3,230400);
	ofBuffer buffer3 = ofBuffer(udpMessage3, 230400);
    
    //    client.broadcast(ofToString(buffer1) + ",");
    //    client.broadcast(",");
	
    if(test3.loadImage(buffer3)){
        img3.setFromPixels(test3.getPixelsRef());
        cout << "set pixels" << endl;
    }
    
    kal.setTexture(img1.getTextureReference(), 0);
    kal.setRotation(client.getFrameCount()*0.004);
    kal.update();

    kal2.setTexture(img2.getTextureReference(), 0);
    kal2.setRotation(client.getFrameCount()*0.004);
    kal2.update();
    
    kal3.setTexture(img3.getTextureReference(), 0);
    kal3.setRotation(client.getFrameCount()*0.004);
    kal3.update();
    
    int xskip = 416;
    int yskip= 720;
    
    //draw kaleidoscope on client0
    for (int y = -360; y < 361; y += yskip)
        for (int x = -324; x < client.getMWidth(); x += xskip) {
            kal.draw(x, y);
            //kal2.draw(x, y);
            //kal3.draw(x, y);
            
            //kal.draw(x + (xskip*7), y);
            //kal.draw(x + (xskip*18), y);
            ofPushStyle();
            ofSetColor(255, 0, 0);
            ofRect(x, y, 10, 10);
            ofPopStyle();
            ofPushStyle();
            ofSetColor(0, 255, 0);
            ofRect(x + (xskip*7), y, 10, 10);
            ofPopStyle();
            ofPushStyle();
            ofSetColor(0, 0, 255);
            ofRect(x + (xskip*18), y, 10, 10);
            ofPopStyle();

        }

    for (int y = 0; y < 361; y += yskip)
        for (int x = -116; x < client.getMWidth(); x += xskip) {
            kal.draw(x, y);
            //kal2.draw(x, y);
            //kal3.draw(x, y);
            //kal2.draw(x + (xskip*7), y);
            //kal3.draw(x + (xskip*18), y);
            ofPushStyle();
            ofSetColor(255, 0, 0);
            ofRect(x, y, 10, 10);
            ofPopStyle();
            ofPushStyle();
            ofSetColor(0, 255, 0);
            ofRect(x + (xskip*7), y, 10, 10);
            ofPopStyle();
            ofPushStyle();
            ofSetColor(0, 0, 255);
            ofRect(x + (xskip*18), y, 10, 10);
            ofPopStyle();
        }
    

    
//    img1.draw(0,720);
//    img1.draw(3640,720);
//    img2.draw(3640,720);
//    img2.draw(7480,720);
//    img3.draw(7480, 720);
//    
//    kal.draw(0,0);
//    kal.draw(3640, 0);
//    //kal.clear();
//    kal2.draw(3640, 0);
//
//    kal2.draw(7480, 0);
//    //kal2.clear();
//    kal3.draw(7480, 0);

    if (client.messageAvailable()) {
        vector<string> msg = client.getDataMessage();
//        vector<string> splitMsg = ofSplitString(msg[0], ",");
//        char tempMsg = ofToChar(splitMsg[0]);
//        tempBuff.set(&tempMsg, msg.size());
        
    
    }
}