示例#1
0
void ofSerialize(ofXml & xml, const ofAbstractParameter & parameter){
	if(!parameter.isSerializable()){
		return;
	}
	string name = parameter.getEscapedName();
	if(name == ""){
		name = "UnknownName";
	}
	ofXml child	= xml.findFirst(name);
	
	if(!child){
		child = xml.appendChild(name);
		ofLogVerbose("ofXml") << "creating group " << name;
	}
	if(parameter.type() == typeid(ofParameterGroup).name()){
		const ofParameterGroup & group = static_cast <const ofParameterGroup &>(parameter);
		
		ofLogVerbose("ofXml") << "group " << name;
		for(auto & p: group){
			ofSerialize(child, *p);
		}
		ofLogVerbose("ofXml") << "end group " << name;
	}else{
		string value = parameter.toString();
		child.set(value);
	}
}
示例#2
0
 void saveToXML() {
     xml.clear();
     xml.addChild("SKY");
     xml.setTo("SKY");
     
     for (auto it = stars.begin(); it != stars.end(); it++) {
         ofVec2f p = it->getPosition();
         int m = it->getMagnitude();
         int id = it->getId();
         
         ofXml star;
         star.addChild("STAR");
         star.setTo("STAR");
         star.addChild("POSITION");
         star.setTo("POSITION");
         star.addValue("X", p.x);
         star.addValue("Y", p.y);
         star.setTo("../");
         star.addValue("MAGNITUDE", m);
         star.addValue("ID", id);
         
         xml.addXml(star);
     }
     xml.save("mySettings.xml");
 }
示例#3
0
void Projector::loadXML(ofXml &xml) {
    string str;
    
    if (xml.exists("[@resolution]")) {
        str = xml.getAttribute("[@resolution]");
        width = ofToFloat(ofSplitString(str, ",")[0]);
        height = ofToFloat(ofSplitString(str, ",")[1]);
    }
}
示例#4
0
void Render::loadXML(ofXml &xml) {
    if (xml.exists("[@vsync]")) {
        string str = ofToString( xml.getAttribute("[@vsync]") );
        if (str == "on")    vsync = true;
        else                vsync = false;
    }
    if (xml.exists("[@framerate]"))
        framerate = ofToInt( xml.getAttribute("[@framerate]") );
    setup();
}
示例#5
0
//--------------------------------------------------------------
void ofxGLWarper::saveToXml(ofXml &XML, const string& warperID){
    
    XML.removeChild(warperID);//if child doesn't exist yet, it's ok.
    auto c = XML.appendChild(warperID);
    for(int i =0; i<4; i++){
		auto nc = c.appendChild("corner");
        nc.appendChild("x").set(corners[i]->x);
        nc.appendChild("y").set(corners[i]->y);
    }
    c.appendChild("active").set(active);
}
示例#6
0
void ofxControlPanel::loadSequencerFromXml(ofXml &xml)
{
    if (xml.exists("Sequencer"))
    {
        xml.setTo("Sequencer");
        if (!sequencerMade) {
            createSequencer();
        }
        sequencer->setFromXml(xml);
        xml.setToParent();
    }
    else {
        ofLog(OF_LOG_ERROR, "No sequencer found in preset");
    }
}
示例#7
0
//--------------------------------------------------------------
void ofxGLWarper::loadFromXml(ofXml &XML, const string& warperID){
    auto c = XML.getChild(warperID);
    if(!c){
        ofLog(OF_LOG_ERROR, "ofxGLWarper : incorrrect xml formating. No \"" + warperID + "\" tag found");
        return;
    }
	
    if (c.find("corner").size()<4 ) {
        ofLog(OF_LOG_ERROR, "ofxGLWarper : incorrrect xml formating. less than 4 \"corner\" tags found");
        return;
    }
	auto cor = c.getChildren("corner");
	int i = 0;
	for(auto& ch: cor){
        if(i<4){
            corners[i] = glm::vec2(ch.getChild("x").getFloatValue(), ch.getChild("y").getFloatValue());
        } 
		i++;
    }

    this->activate(c.getChild("active").getBoolValue());

    processMatrices();
    //ofLog(OF_LOG_WARNING, "ofxGLWarper : xml object loaded OK!."); // Since the method works, this can be quiet...

}
示例#8
0
void ofDeserialize(const ofXml & xml, ofAbstractParameter & parameter){
	if(!parameter.isSerializable()){
		return;
	}
	string name = parameter.getEscapedName();
	
	ofXml child = xml.findFirst(name);
	if(child){
		if(parameter.type() == typeid(ofParameterGroup).name()){
			ofParameterGroup & group = static_cast <ofParameterGroup &>(parameter);
			for(auto & p: group){
				ofDeserialize(child, *p);
			}
		}else{
			if(parameter.type() == typeid(ofParameter <int> ).name()){
				parameter.cast <int>() = child.getIntValue();
			}else if(parameter.type() == typeid(ofParameter <float> ).name()){
				parameter.cast <float>() = child.getFloatValue();
			}else if(parameter.type() == typeid(ofParameter <bool> ).name()){
				parameter.cast <bool>() = child.getBoolValue();
			}else if(parameter.type() == typeid(ofParameter <string> ).name()){
				parameter.cast <string>() = child.getValue();
			}else{
				parameter.fromString(child.getValue());
			}
		}
	}
}
示例#9
0
ofXml::ofXml( const ofXml& rhs ) {

    document = new Poco::XML::Document();
    Poco::XML::Node *n = document->importNode(rhs.getPocoDocument()->documentElement(), true);
    document->appendChild(n);
    
    element = document->documentElement();
}
示例#10
0
bool ofxFadeEffect::settings::deserialize( ofXml X )
{
	ofParameterGroup G;
	G.setName("fxShake_Settings");

	X.deserialize(G);
	bool bSuc = X.exists(G.getName());
	if(bSuc)
	{
		alphaFrom = G.getInt("alphaFrom");
		alphaTo = G.getInt("alphaTo");
		time = G.getFloat("time");
		delay = G.getFloat("delay");
	}

	return bSuc;	
}
示例#11
0
bool ofxImageThing::settings::deserialize( ofXml X )
{
	ofParameterGroup G;
	G.setName("ofxImageThing_Settings");

	X.deserialize(G);
	bool bSuc = X.exists(G.getName());
	if(bSuc)
	{
		imgPath= G.getString("imgPath");
		imgColor = G.getColor("imgColor");
		width = G.getFloat("width");
		height = G.getFloat("height");
		imgAlpha = G.getFloat("imgAlpha");
	}

	return bSuc;	
}
示例#12
0
void ofxControlPanel::saveSequencerToXml(ofXml &xml)
{
    if (sequencerMade)
    {
        ofXml xmlSequencer;
        xmlSequencer.addChild("Sequencer");
        xmlSequencer.setTo("Sequencer");
        sequencer->getXml(xmlSequencer);
        xml.addXml(xmlSequencer);
    }
}
示例#13
0
void ofxControlPanel::setFromXml(ofXml &xml)
{
    ofxControlWidget::setFromXml(xml);
    if (xml.exists("Sequencer"))
    {
        if (!sequencerMade) {
            createSequencer();
        }
        sequencer->setFromXml(xml);
    }
    else {
        ofLog(OF_LOG_ERROR, "No sequencer found in preset");
    }
}
示例#14
0
void Socket::loadXML(ofXml &xml) {
    if (xml.exists("socket[@enabled]")) {
        string str = ofToString(xml.getAttribute("socket[@enabled]"));
        if (str == "on") enabled = true;
        else             enabled = false;
    }
    
    if (xml.exists("socket[@host]"))
        host = ofToString( xml.getAttribute("socket[@host]") );
    if (xml.exists("socket[@send]"))
        send = ofToInt( xml.getAttribute("socket[@send]") );
    if (xml.exists("socket[@receive]"))
        receive = ofToInt( xml.getAttribute("socket[@receive]") );
    
    if (enabled)
        setup();
}
示例#15
0
 void setupFromXml(string filename) {
     size = ofVec2f(ofGetWidth(), ofGetHeight());
     if (xml.load(filename)) {
         xml.setTo("STAR[0]");
         do {
             xml.setTo("POSITION");
             int x = xml.getValue<float>("X");
             int y = xml.getValue<float>("Y");
             xml.setToParent();
             int m = xml.getValue<int>("MAGNITUDE");
             int id = xml.getValue<int>("ID");
             
             BPStar s;
             s.setPosition(x, y);
             s.setMagnitude(m);
             s.setId(id);
             stars.push_back(s);
         }while( xml.setToSibling() ); // go to next STAR
     } else {
         
     }
     shader.load("","SkyShader.frag");
     skyShader.setup();
 }
示例#16
0
void Socket::saveXML(ofXml &xml) {
    xml.setTo("socket");

    if (enabled) xml.setAttribute("enabled", "on");
    else         xml.setAttribute("enabled", "off");
    
    xml.setAttribute("host", ofToString(host));
    xml.setAttribute("send", ofToString(send));
    xml.setAttribute("receive", ofToString(receive));

    xml.setToParent();
}
示例#17
0
void Projector::saveXML(ofXml &xml) {
    // color
    xml.setAttribute("brightness", ofToString(roundTo(brightness, .001)));
    xml.setAttribute("contrast", ofToString(roundTo(contrast, .001)));
    xml.setAttribute("saturation", ofToString(roundTo(hue, .001)) +  "," + ofToString(roundTo(saturation, .001)) +  "," + ofToString(roundTo(lightness, .001))  );

    //camera
    xml.setAttribute("position", ofToString(roundTo(cameraPosition.x, .01)) +  "," + ofToString(roundTo(cameraPosition.y, .01)) +  "," + ofToString(roundTo(cameraPosition.z, .01)) );
    xml.setAttribute("orientation", ofToString(roundTo(cameraOrientation.x, .01)) +  "," + ofToString(roundTo(cameraOrientation.y, .01)) +  "," + ofToString(roundTo(cameraOrientation.z, .01)) );
    xml.setAttribute("fov", ofToString(roundTo(cameraFov, .01)));
    xml.setAttribute("offset", ofToString(roundTo(cameraOffset.x, .001)) +  "," + ofToString(roundTo(cameraOffset.y, .001)) );
    
    // plane
    plane.save(xml);
	curves.save(projectorStartingIndex);
    mask.save(projectorStartingIndex);    
}
示例#18
0
void ofXml::addXml( ofXml& xml, bool copyAll ) {
    
    Poco::XML::Node *n = 0;
    if(copyAll) {
        n = document->importNode(xml.getPocoDocument()->documentElement(), true);
    } else {
        if(xml.getPocoElement() == 0 || xml.getPocoElement() == xml.getPocoDocument()->documentElement()) {
            n = document->importNode(xml.getPocoDocument()->documentElement(), true);
        } else {
            n = document->importNode( xml.getPocoElement(), true);
        }
    }

    // we have an element, i.e. the document has child nodes
    // or we don't, so append it directly to the document
    if( element ) {
        element->appendChild(n);
    } else {
        document->appendChild(n);
    }
    
}
示例#19
0
    void setup() {
        ofBackground(255);
        ofSetFrameRate(60);
        
        config.load("config.xml");
        defaultLength = config.getFloatValue("cable/length/default");
        minLength = config.getFloatValue("cable/length/min");
        maxLength = config.getFloatValue("cable/length/max");
        host = config.getValue("osc/host");
        sendPort = config.getIntValue("osc/sendPort");
        receivePort = config.getIntValue("osc/receive");
        
        oscSend.setup(host, sendPort);
        oscReceive.setup(receivePort);
        
        local.setup("Local");
        remote.setup("Remote");
        
        zeros.setup("Zeros");
        zeros.add(nwZero.setup("NW Zero"));
        zeros.add(neZero.setup("NE Zero"));
        zeros.add(seZero.setup("SE Zero"));
        zeros.add(swZero.setup("SW Zero"));

        nwZero.addListener(this, &ofApp::zeroNW);
        neZero.addListener(this, &ofApp::zeroNE);
        seZero.addListener(this, &ofApp::zeroSE);
        swZero.addListener(this, &ofApp::zeroSW);
        
        local.gui.loadFromFile("settings.xml");
        
        local.gui.setPosition(10, 10);
        zeros.setPosition(10, 200);
        remote.gui.setPosition(10, 310);
        
    }
void KinectV2Classifier::setFromLearnXml(ofXml &xml)
{
    xml.setTo("LearnInfo");
    
    if (xml.exists("Classes")) {
        xml.setTo("Classes");
        if (xml.exists("Class[0]"))
        {
            xml.setTo("Class[0]");
            do {
                addClass(xml.getValue<string>("Name"));
            }
            while(xml.setToSibling());
            xml.setToParent();
        }
        xml.setToParent();
    }
    
    if (xml.exists("Ranges")) {
        xml.setTo("Ranges");
        if (xml.exists("Joint[0]"))
        {
            int idx = 0;
            xml.setTo("Joint[0]");
            do {
                min[idx] = xml.getValue<float>("Min");
                max[idx] = xml.getValue<float>("Max");
                idx++;
            }
            while(xml.setToSibling());
            xml.setToParent();
        }
        xml.setToParent();
    }
    
    if (xml.exists("Training")) {
        xml.setTo("Training");
        if (xml.exists("Entry[0]"))
        {
            xml.setTo("Entry[0]");
            do {
                double label = xml.getValue<double>("Label");
                vector<string> featureVectorS = ofSplitString(xml.getValue<string>("Features"), ",");
                vector<float> entry;
                entry.push_back(label);
                for (auto f : featureVectorS) {
                    entry.push_back(ofToFloat(f));
                }
                data.addEntry(entry);
            }
            while(xml.setToSibling());
            xml.setToParent();
        }
        xml.setToParent();
    }
    
    if (xml.exists("Model")) {
        xml.setTo("Model");
        string path = xml.getValue<string>("Path");
        svm.loadModel(path);
        trained = true;
        xml.setToParent();
    }
    xml.setToParent();
}
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();
}
示例#22
0
void Render::saveXML(ofXml &xml) {
    if (vsync)  xml.setAttribute("vsync", "on" );
    else        xml.setAttribute("vsync", "off" );

    xml.setAttribute("framerate", ofToString(framerate) );
}
示例#23
0
 Status::Status( ofXml& X )
 {
   X.deserialize(S);
 }
示例#24
0
void Projector::loadXML2(ofXml &xml) {
    string str;
    float val;

    // color
    if (xml.exists("[@brightness]")) {
        brightness = ofToFloat( xml.getAttribute("[@brightness]"));
    }
    if (xml.exists("[@contrast]")) {
        contrast = ofToFloat( xml.getAttribute("[@contrast]") );
    }
    if (xml.exists("[@saturation]")) {
        saturation = ofToFloat( xml.getAttribute("[@saturation]") );
    }

    // plane warp
    plane.width = width;
    plane.height = height;
    plane.load(xml, projectorStartingIndex);


    // camera position
    if (xml.exists("[@position]")) {
        str = xml.getAttribute("[@position]");
        float azi  = ofToFloat(ofSplitString(str, ",")[0]);
        float ele  = ofToFloat(ofSplitString(str, ",")[1]);
        float dis  = ofToFloat(ofSplitString(str, ",")[2]);
        setCameraPosition(azi, ele, dis);
    }

    // camera orientation
    if (xml.exists("[@orientation]")) {
        str = xml.getAttribute("[@orientation]");
        float roll = ofToFloat(ofSplitString(str, ",")[0]);
        float tilt = ofToFloat(ofSplitString(str, ",")[1]);
        float pan = ofToFloat(ofSplitString(str, ",")[2]);
        setCameraOrientation(roll, tilt, pan);
    }

    // camera lens fov
    if (xml.exists("[@fov]")) {
        val = ofToFloat( xml.getAttribute("[@fov]") );
        setCameraFov(val);
    }

    //camera lens offset
    if (xml.exists("[@offset]")) {
        str = xml.getAttribute("[@offset]");
        float offX  = ofToFloat(ofSplitString(str, ",")[0]);
        float offY  = ofToFloat(ofSplitString(str, ",")[1]);
        setCameraOffset(offX, offY);
    }

	curves.load(projectorStartingIndex);

    mask.width = width;
    mask.height = height;
    mask.load(projectorStartingIndex);
}
void ofxShaderGraph::buildFromXml(ofXml x){
    unordered_set<string> root_names;

    x.reset();
    unsigned long n = x.getNumChildren();

    params.setName(x.getName());

    //first pass, create all nodes and set defaults
    for(unsigned long i=0; i<n; i++){
        x.reset();
        x.setToChild(i);
        if(x.getName()!="node")
            continue;
        string name = x.getAttribute("name");
        if(name==""){
            cout<<"ofxShaderGraph warning: anonymous node in XML"<<endl;
            continue;
        }
        ofxBaseShaderNode *node;
        ofFbo::Settings node_fbo_settings = fbo_settings;
        //check for modifications to fbo_settings
        if(x.setTo("scale")){
            float scale = x.getFloatValue();
            node_fbo_settings.width*=scale;
            node_fbo_settings.height*=scale;
            x.setToParent();
        }
        string format = x.getAttribute("format");
        if(format!=""){
            if(format=="rgba8")
                node_fbo_settings.internalformat = GL_RGBA8;
            else if(format=="rgba16")
                node_fbo_settings.internalformat = GL_RGBA16;
            else if(format=="rgba32f")
                node_fbo_settings.internalformat = GL_RGBA32F;
            else if(format=="rgba16f")
                node_fbo_settings.internalformat = GL_RGBA16F;
            else if(format=="rgb8")
                node_fbo_settings.internalformat = GL_RGB8;
            else if(format=="rgb16")
                node_fbo_settings.internalformat = GL_RGB16;
            else if(format=="rgb32f")
                node_fbo_settings.internalformat = GL_RGB32F;
            else if(format=="rgb16f")
                node_fbo_settings.internalformat = GL_RGB16F;
        }
        //check for node to swap buffers with
        string swap_name = x.getAttribute("swap");
        if(swap_name != ""){
            //don't duplicate pairs
            if(swap.count(swap_name)==0){
                cout<<"ofxShaderGraph: "<<name<<" swaps with "<<swap_name<<endl;
                swap.insert(pair<string, string>(name, swap_name));
            }else{
                cout<<"ofxShaderGraph warning: ignoring duplicate swap of"<<name<<" with "<<swap_name<<endl;
            }
        }
        //check for color to init buffer to
        if(x.setTo("init")){
            float val = x.getFloatValue();
            init.insert(pair<string, float>(name, val));
            x.setToParent();
        }
        //check for shader path
        string shader_name = x.getAttribute("shader");
        if(shader_name == ""){
            //shaderless node
            node = new ofxConstantShaderNode(allocator, node_fbo_settings, name);
        }
        else{
            ofShader *shader = new ofShader();
            stringstream shader_path;
            shader_path<<ofToDataPath("../../src/shader/")<<shader_name;
            shader->load(shader_path.str());
            if(!shader->isLoaded()){
                cout<<"ofxShaderGraph warning: shader "<<shader_name<<" failed to load from path "<<shader_path.str()<<endl;
            }
            else{
                cout<<"ofxShaderGraph: loaded shader "<<shader_name<<endl;
            }
            node = new ofxBaseShaderNode(allocator, node_fbo_settings, name, shader);
        }
        //grab all of the new node's parameters
        params.add(node->getParameterGroup());
        //put it in the map from names to nodes
        nodes.insert(pair<string, ofxBaseShaderNode*>(name, node));
        //everything goes in root_names, to be removed when is appears as an input
        root_names.insert(name);

        cout<<"ofxShaderGraph: inserted node "<<name<<endl;

        //set defaults
        if(x.setTo("defaults") && x.setToChild(0)){
            do{
                string param_type = x.getName();
                string param_name = x.getAttribute("name");
                if(param_type=="float"){
                    float v = x.getFloatValue();
                    node->setParameter(param_name, v);
                }else if(param_type=="int"){
                    int v = x.getIntValue();
                    node->setParameter(param_name, v);
                }else{
                    cout<<"ofxShaderGraph warning: parameter type "<<param_type<<" unsupported"<<endl;
                }
            }while(x.setToSibling());
            x.setToParent();
            x.setToParent();
        }

        //set aliases
        /*if(x.setTo("aliases") && x.setToChild(0)){
            do{
                string param_type = x.getName();
                string param_name = x.getAttribute("name");
                string alias_name = x.getValue();
                if(param_type=="float"){
                    auto alias_param = aliases.getFloat(alias_name);
                    node->setParameterAlias(param_name, alias_param);
                }else if(param_type=="int"){
                    auto alias_param = aliases.getInt(alias_name);
                    node->setParameterAlias(param_name, alias_param);
                }else{
                    cout<<"ofxShaderGraph warning: aliased parameter type "<<param_type<<" unsupported"<<endl;
                }
            }while(x.setToSibling());
            x.setToParent();
            x.setToParent();
        }*/
    }

    //second pass, fill in inputs for each node and remove all referenced nodes from root_names
    for(unsigned long i=0; i<n; i++){
        x.reset();
        x.setToChild(i);
        if(x.getName()!="node")
            continue;
        string name = x.getAttribute("name");
        if(name=="")
            continue;
        ofxBaseShaderNode *node = nodes[name];

        //set inputs
        if(!x.setTo("inputs"))
            continue;
        if(!x.setToChild(0))
            continue;
        do{
            string input_name = x.getValue();
            if(nodes.find(input_name) == nodes.end()){
                cout << "ofxShaderGraph error: node "<<name<<" lists input "<<input_name<<" which does not exist"<<endl;
            }
            else{
                ofxBaseShaderNode *input = nodes.at(input_name);
                node->inputs.push_back(input);
                input->num_dependents++;
                root_names.erase(input_name);
                cout<<"ofxShaderGraph: connected node "<<input_name<<" to node "<<name<<endl;
            }
        }while(x.setToSibling());
    }

    //populate roots
    for(string root_name:root_names){
        ofxBaseShaderNode *root_node = nodes.at(root_name);
        roots.insert(root_node);
        cout<<"ofxShaderGraph: node "<<root_name<<" is a root"<<endl;
    }

}