void setup() { #ifndef INSTALL useSharedData(); #endif loadSettings(); tracker.setup(); tracker.setHaarMinSize(175); tracker.setRescale(.25); tracker.setIterations(3); tracker.setTolerance(2); tracker.setClamp(3); tracker.setAttempts(4); #ifdef INSTALL cam.setup(camWidth, camHeight, 30); #else cam.initGrabber(camWidth, camHeight, false); #endif if(rotate) { data.setup(camHeight, camWidth, binSize); } else { data.setup(camWidth, camHeight, binSize); } loadMetadata(data); presence.setDelay(0, 4); presenceFade.setLength(4, .1); presenceFade.start(); shader.load("shaders/colorbalance.vs", "shaders/colorbalance.fs"); ofDisableAntiAliasing(); glPointSize(2); ofSetLineWidth(3); ofSetLogLevel(OF_LOG_VERBOSE); }
//-------------------------------------------------------------- void testApp::draw(){ //Manual Lines--No Distortion // ofLine(0, 0, 0, ofGetScreenHeight()); // ofLine(2, 0, 2, ofGetScreenHeight()); // ofLine(4, 0, 4, ofGetScreenHeight()); // ofLine(6, 0, 6, ofGetScreenHeight()); // ofLine(8, 0, 8, ofGetScreenHeight()); //For Loop--This is where i'm having problems ofDisableAntiAliasing(); for (xPos = 0; xPos < 256; xPos++) { cout << ofGetWindowWidth() << endl; if (xPos%2 == 0) { ofSetColor(255, 0, 0); ofFill(); ofLine(xPos*2, yPos, xPos*2, 500); //make red line //cout << "xPos in modulo loop is " << xPos << endl; } } }
void mainApp::drawPreProcess() { ofBackground(80); ofPushStyle(); ofDisableAlphaBlending(); ofDisableAntiAliasing(); ofSetColor(255, 255, 255); float offsetY = 0; auto& e = mInputImage; float w = e->getLimitedPixRef().getWidth(); float h = e->getLimitedPixRef().getHeight(); float x = w * 0; e->getLimitedTexRef().draw(x, 0, w, h); e->drawCropRect(x, 0, w, h); offsetY += h; e->getCropedTextureRef().draw(x, offsetY); offsetY += e->getCropedPixelsRef().getHeight(); e->getWarpedTextureRef().draw(x, offsetY); offsetY += e->getWarpedPixelsRef().getHeight(); e->getBinaryTextureRef().draw(x, offsetY); ofPopStyle(); }
//-------------------------------------------------------------- void testApp::setup() { ofDisableAntiAliasing(); ofBackgroundHex(0x1F2C30); ofSetLogLevel(OF_LOG_NOTICE); // scrolling ground groundSpeed = 0.02; groundTimer = 0; groundRes = 50; // build the ground first for(int i=0; i<groundRes; i++) { float x = ofMap(i, 0, groundRes-1, 0, ofGetWidth()); float y = ofGetHeight()/2 + ofRandom(-30, 100); groundLine.addVertex(x, y); } box2d.init(); box2d.setGravity(0, 20); box2d.setFPS(60.0); box2d.registerGrabbing(); }
void Render::setup() { ofSetVerticalSync(vsync); ofSetFrameRate(framerate); ofBackground(100,100,100); ofEnableNormalizedTexCoords(); ofDisableAntiAliasing(); }
//-------------------------------------------------------------- void ofApp::setup(){ //set a limited frame rate, enable alpha blending, and set no anti-aliasing for more pixel arty kind of vibe. ofSetFrameRate(30); ofEnableAlphaBlending(); ofDisableAntiAliasing(); //create the sprite renderer with 2 layers, and 16x16 tiles. spriteRenderer = new ofxSpriteSheetRenderer(2, 10000, 0, 16); //load in the 64x64 pixels texture. spriteRenderer->loadTexture("link.png", 64, GL_NEAREST); //create "player" as an instance of our basicSprite struct, then set his position, speed, and default animation. player = new basicSprite(); player->pos.set(ofGetWindowWidth()/2, ofGetWindowHeight()/2); player->speed = 0.1; player->animation = walkAnimation; //override the walkAnimation's default index to have Link starting facing down. player->animation.index = 6; //loop through the grid size that we want, make a new sprite for each background tile we want, //then set its position based on the grid and our scale, then push it to the vector to hold it. //we'll be looping through the vector to access these sprites' values. for (int i = 0; i < GRIDH; i++) { for (int j = 0; j < GRIDW; j++) { basicSprite * newSprite = new basicSprite(); newSprite->pos.set(j*spriteRenderer->getTileSize()*SCALE, i*spriteRenderer->getTileSize()*SCALE); newSprite->tileName = (int)ofRandom(8,12); backgrounds.push_back(newSprite); } } }
//-------------------------------------------------------------- void testApp::setup() { ofDisableAntiAliasing(); ofBackgroundHex(0x1F2C30); ofSetLogLevel(OF_LOG_NOTICE); box2d.init(); box2d.setGravity(0, 10); box2d.setFPS(60.0); box2d.registerGrabbing(); box2d.createGround(); ground.setPhysics(0, 0, 0); ground.setup(box2d.getWorld(), ofGetWidth()/2, ofGetHeight()+200, 400); groundMesh.setUsage(GL_STATIC_DRAW); groundMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); for(int i=0; i<100; i++) { float t = ofMap(i, 0, 99, 0.0, TWO_PI); ofVec3f v(ofGetWidth()/2, ofGetHeight()+200); groundMesh.addVertex(v); v.x += cos(t)*400; v.y += sin(t)*400; groundMesh.addVertex(v); } }
void ofApp::setup(){ ofSetFrameRate(target_fps); ofSetVerticalSync(true); //ofSetWindowShape(1920, 1080); ofSetWindowPosition(0, 0); ofEnableAlphaBlending(); ofDisableAntiAliasing(); ofDisableSmoothing(); ofSetOrientation( OF_ORIENTATION_DEFAULT ); bStart = true; bLog = true; // sound int nCh = 1; int sampleRate = 48000; int bufferSizeTry = bufferSize = 2048; currentSamplePos = 0; prevSamplePos = 0; sound_stream.setup(this, 0, nCh, sampleRate, bufferSizeTry, 4); // visual int w = ofGetWindowWidth(); int h = ofGetWindowHeight(); bHandy = w<h; float longside = bHandy ? h:w; float shortside = bHandy ? w:h; canvas.set(0, 0, longside, shortside); track_len = longside * 0.9f; track_offset = longside * 0.05; start_point.x = track_offset; start_point.y = shortside/2; indicator.set(0, 0); bNeedSaveImg = false; ofSetLogLevel(OF_LOG_VERBOSE); #ifdef USE_GRABBER // video grbW = 360; grbH = 240; grabber.listDevices(); grabber.setDeviceID(1); grabber.setUseTexture(false); grabber.setPixelFormat( OF_PIXELS_RGB ); grabber.setDesiredFrameRate( target_fps ); grabber.setPixelFormat(OF_PIXELS_MONO); grabber.setup( grbW, grbH ); colorImg.allocate( grbW, grbH ); grayImg.allocate( grbW, grbH ); #endif }
//-------------------------------------------------------------- void testApp::setup(){ ofDisableAntiAliasing(); ofBackground(255,255,0); xPos = 0; yPos = 0; }
//-------------------------------------------------------------- void ofApp::keyPressed (int key){ if (key == 's'){ bSmooth = !bSmooth; if (bSmooth){ ofEnableAntiAliasing(); }else{ ofDisableAntiAliasing(); } } }
//-------------------------------------------------------------- void ofApp::keyPressed (int key){ // the key of s toggles antialiasing if (key == 's'){ bSmooth = !bSmooth; if (bSmooth){ ofEnableAntiAliasing(); }else{ ofDisableAntiAliasing(); } } }
//-------------------------------------------------------------- void ofApp::setup(){ #ifdef HEADLESS settings.load("settings.xml"); #else ofBackground(40); ofSetVerticalSync(true); ofDisableAntiAliasing(); camera.setup(); pointCloudOpts.steps = 4; pointCloudOpts.textureCoordinates = PointCloudOptions::TextureCoordinates::ColorCamera; bDraw3D = false; bDrawMesh = false; bDrawSensorDebug = false; meshFillOpacity = 100.f; gui = new ofxUICanvas(); setupGui(); #endif ofSetFrameRate(31); //ofSetLogLevel("ofxLibwebsockets", OF_LOG_VERBOSE); //ofSetLogLevel("Sockets", OF_LOG_VERBOSE); //ofSetLogLevel("VGB", OF_LOG_VERBOSE); kinect.open(); kinect.initDepth(); kinect.initColor(); kinect.initInfrared(); kinect.initBodyIndex(); kinect.initBodyFrame(); //vgb.init(kinect.getSensor(), "sap.gbd", 0); bSendData = true; bSingleUserMode = true; currLegitimateTrackingId = 0; newcomerId = 0; newcomerNumPresence = 0; newcomerNumFrameForElection = 30; sockets = new Sockets(); sockets->setup(); }
//-------------------------------------------------------------- void testApp::setup() { ofDisableAntiAliasing(); ofBackgroundHex(0xffffff); ofSetLogLevel(OF_LOG_NOTICE); ofSetVerticalSync(true); // Box2d box2d.init(); box2d.setGravity(0, 30); box2d.createGround(); box2d.setFPS(30.0); // load the lines we saved... ifstream f; f.open(ofToDataPath("lines.txt").c_str()); vector <string> strLines; while (!f.eof()) { string ptStr; getline(f, ptStr); strLines.push_back(ptStr); } f.close(); for (int i=0; i<strLines.size(); i++) { vector <string> pts = ofSplitString(strLines[i], ","); if(pts.size() > 0) { ofPtr <ofxBox2dEdge> edge = ofPtr<ofxBox2dEdge>(new ofxBox2dEdge); for (int j=0; j<pts.size(); j+=2) { if(pts[j].size() > 0) { float x = ofToFloat(pts[j]); float y = ofToFloat(pts[j+1]); edge.get()->addVertex(x, y); } } edge.get()->create(box2d.getWorld()); edges.push_back(edge); } } boxSize = 10; setupAudio(); }
//-------------------------------------------------------------- void ofApp::setup(){ np::seed_oracle(); ffmpeg_recording = false; drawElements = false; // COLORS ------------------------------ mainColor = ofColor(255, 80, 80); altColor1 = ofColor(255, 30, 30); altColor2 = ofColor(255, 100, 70); mainColorDim = mainColor.getLerped(ofColor::black, 0.4); //------------------- graphics -------------- ofBackground(0); ofSetFrameRate(30); ofDisableAntiAliasing(); np::linux_no_cursor_fix(); // -------------------------VISUALS SETUP-------------------------- ensemble.fadeToBlack.setFadeTime( 6200.0f); ensemble.fadeToBlack.setFadePoint( 0.0f, true ); #ifndef SCREENCAST ensemble.fadeToBlack.fadeIn(); #endif visuals.setup( engine.score.sections[0], ensemble ); ensemble.setup ( engine, mainColor ); visuals.setColor( mainColor ); ensemble.wolfram.setColor(mainColor); ensemble.noise.setColor(mainColor); ensemble.sub.setColor(mainColor); ensemble.cloud1.setColor(mainColor); ensemble.cloud2.setColor(mainColor); layout(); engine.score.play(); }
//-------------------------------------------------------------- void ofApp::setup(){ game_state = "title"; splatLimit = 50; paint1.loadImage("images/paint1B.png"); paint2.loadImage("images/paint2B.png"); cam.setDistance(1000); ofSetFrameRate(60); ofHideCursor(); ofEnableAlphaBlending(); ofDisableAntiAliasing(); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofSetBackgroundAuto(false); }
void Button::draw() { ofColor backgroundColor; ofColor textColor; switch (state) { case BUTTON_STATE_DISABLED: backgroundColor = disabledColor; textColor = ofColor(100); break; case BUTTON_STATE_IDLE: backgroundColor = idleColor; textColor = ofColor(255); break; case BUTTON_STATE_HOVER: backgroundColor = hoverColor; textColor = ofColor(255); break; case BUTTON_STATE_PRESSED: case BUTTON_STATE_CLICKED: backgroundColor = pressedColor; textColor = ofColor(255); break; } ofDisableAntiAliasing(); // Background ofSetColor(backgroundColor); ofRect(displayX + colorBorder + 1, displayY + colorBorder, displayWidth - (colorBorder + 4), displayHeight - (colorBorder + 3)); // Borders ofSetColor(borderColor); ofLine(displayX, displayY, displayX + displayWidth, displayY); // Top ofLine(displayX, displayY + displayHeight, displayX + displayWidth, displayY + displayHeight); // Bottom ofLine(displayX + 1, displayY, displayX + 1, displayY + displayHeight); // Left ofLine(displayX + displayWidth, displayY, displayX + displayWidth, displayY + displayHeight); // Right // Text ofEnableAntiAliasing(); ofSetColor(textColor); font.drawString(text, textX, textY); }
void Frame::draw() { ofDisableAntiAliasing(); // Background ofSetColor(backgroundColor); ofRect(displayX, displayY, displayWidth, displayHeight); // Borders ofSetColor(borderColor); ofLine(displayX, displayY, displayX + displayWidth, displayY); // Top ofLine(displayX, displayY + displayHeight, displayX + displayWidth, displayY + displayHeight); // Bottom ofLine(displayX + 1, displayY, displayX + 1, displayY + displayHeight); // Left ofLine(displayX + displayWidth, displayY, displayX + displayWidth, displayY + displayHeight); // Right // Draw buttons for (unsigned int i = 0; i < buttons.size(); i++) { buttons[i].draw(); } }
//-------------------------------------------------------------- void testApp::setup() { //disable MSAA ofDisableAntiAliasing(); texInput_.allocate(1024,768,GL_RGBA,false); ofImage img ; img.loadImage("test.png"); texInput_.loadData(img.getPixelsRef()); ofFbo::Settings defaultSetting; defaultSetting.numSamples=0; defaultSetting.textureTarget=GL_TEXTURE_2D; defaultSetting.height=768; defaultSetting.internalformat=GL_RGBA; defaultSetting.useDepth=false; defaultSetting.useStencil=false; defaultSetting.width=1024; defaultSetting.wrapModeHorizontal=GL_CLAMP_TO_EDGE; defaultSetting.wrapModeVertical=GL_CLAMP_TO_EDGE; defaultSetting.numSamples=false; fboRender_.allocate(defaultSetting); //Setup AA... aaType=0;//smaa fboAA_.allocate(defaultSetting); fboSmaaWk_.allocate(defaultSetting); texSmaaArea_.allocate(AREATEX_WIDTH,AREATEX_HEIGHT,GL_RG8,false); texSmaaArea_.loadData(areaTexBytes,AREATEX_WIDTH,AREATEX_HEIGHT,GL_RG); texSmaaArea_.setTextureMinMagFilter(GL_LINEAR,GL_LINEAR); texSmaaSearch_.allocate(SEARCHTEX_WIDTH,SEARCHTEX_HEIGHT,GL_R8,false); texSmaaSearch_.loadData(searchTexBytes,SEARCHTEX_WIDTH,SEARCHTEX_HEIGHT,GL_RED); texSmaaSearch_.setTextureMinMagFilter(GL_NEAREST,GL_NEAREST); loadShaders(); }
void ofApp::setupGL(){ ofDisableArbTex(); ofEnableBlendMode(OF_BLENDMODE_DISABLED); ofDisableDepthTest(); ofDisableAntiAliasing(); fbo_params = ofFbo::Settings(); //needs to come after the ofDisable* above fbo_params.width = realtime_width; fbo_params.height = realtime_height; fbo_params.internalformat = GL_RGB32F; fbo_params.useDepth = false; fbo_params.useStencil = false; fbo_params.wrapModeHorizontal = GL_REPEAT; fbo_params.wrapModeVertical = GL_REPEAT; fbo_params.numSamples = 0; ofSetVerticalSync(true); //does not appear to be working on windows w/ of 0.8.4 ofSetFullscreen(fullscreen); ofSetWindowShape(window_width, window_height); }
//-------------------------------------------------------------- void ofApp::setup(){ //set a limited frame rate, enable alpha blending, and set no anti-aliasing for more pixel arty kind of vibe. ofSetFrameRate(30); ofEnableAlphaBlending(); ofDisableAntiAliasing(); //create the sprite renderer with 2 layers, and 16x16 tiles. spriteRenderer = new ofxSpriteSheetRenderer(2, 10000, 0, 16); //load in the 64x64 pixels texture. spriteRenderer->loadTexture("link.png", 64, GL_NEAREST); wallBreaktimer = 0; wallBreaktimerDuration = 30; //30 frames //create "player" as an instance of our basicSprite struct, then set his position, speed, and default animation. player = new basicSprite(); initializeRandomWorld (); paintMap(); vector<ofPoint> placementOptions; for (int y = 0; y < GRIDH; y++) { for (int x = 0; x < GRIDW; x++) { basicSprite* sprite = getTile (x,y); if (!sprite->isWall) { placementOptions.push_back(sprite->pos); } } } player->pos.set(placementOptions[ofRandom(0, placementOptions.size())]); player->speed = 0.1; player->animation = walkAnimation; //override the walkAnimation's default index to have Link starting facing down. player->animation.index = 6; }
//-------------------------------------------------------------- void testApp::setup(){ ofDisableAntiAliasing(); ofSetWindowTitle("OF Bluetooth Manager"); lastConnectedDevice = -1; vector <ofxBluetoothDevice> devices = ofxBluetoothManager::listPairedDevices(); for (int i=0; i<devices.size(); i++) { RectButton btn; btn.set(20, 20+(i*32), 400, 30); btn.name = devices[i].name; btn.address = devices[i].address; buttons.push_back(btn); } ofAddListener(ofxBluetoothManager::events, this, &testApp::newBluetoothEvent); // a gui gui.setup(); gui.setPosition(430, 20); gui.add(minSlider.setup("Min", -20, -127, 1)); gui.add(maxSlider.setup("Max", 3, -127, 1)); gui.add(useRawRSSI.setup("Use Raw RSSI", false)); vector <ofxBluetoothDevice> connectedDevices = ofxBluetoothManager::getConnectedDevices(); for(int i=0; i<connectedDevices.size(); i++) { if(connectedDevices[i].isConnected) { lastConnectedDevice = i; break; } } lastTime = 0; lastRSSI = 0; }
//-------------------------------------------------------------- void ofApp::setup() { ofBackgroundHex(0xfdefc2); ofSetLogLevel(OF_LOG_NOTICE); ofSetVerticalSync(true); ofDisableAntiAliasing(); // find all the texture files and load them ofDirectory dir; ofDisableArbTex(); int n = dir.listDir("textures"); for (int i=0; i<n; i++) { textures.push_back(ofImage(dir.getPath(i))); } printf("%i Textures Loaded\n", (int)textures.size()); // Box2d box2d.init(); box2d.setGravity(0, 10); box2d.createGround(); box2d.setFPS(60.0); box2d.registerGrabbing(); }
void lineScene::draw(float x, float y, float scale){ // if ( oni->isSkeleton() ) { ofEnableAntiAliasing(); // ofEnableAlphaBlending(); // ofBackground(bgColor); ofSetColor(lineColor); ofPushMatrix(); ofTranslate(x, y); ofTranslate(160, 120); ofScale(scale, scale); ofTranslate(-160, -120); ofScale(0.5, 0.5); if ( bDrawMoire) drawMoire(); if ( bDrawBody ) drawBodyLines(); ofPopMatrix(); // ofDisableAlphaBlending(); ofDisableAntiAliasing(); // } }
void config(int id, shared_ptr<ServerApp> server) { this->id = id; this->server = server; ofSetVerticalSync(true); ofDisableAntiAliasing(); ofBackground(0); shader.loadAuto("../../../SharedData/shader/shader"); xyzMap.loadAuto("../../../SharedData/xyzMap-" + ofToString(id) + ".exr"); xyzMap.getTexture().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); confidenceMap.loadAuto("../../../SharedData/confidenceMap-" + ofToString(id) + ".exr"); confidenceMap.getTexture().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); ofLog() << xyzMap.getWidth() << " x " << xyzMap.getHeight(); ofLog() << confidenceMap.getWidth() << " x " << confidenceMap.getHeight(); #ifdef USE_AUDIO oscSender.setup("localhost", 7777); setupSpeakers(); #endif }
//-------------------------------------------------------------- void ofApp::setup() { ofDisableAntiAliasing(); ofBackgroundHex(0xfdefc2); ofSetLogLevel(OF_LOG_NOTICE); ofSetVerticalSync(true); // Box2d box2d.init(); box2d.setGravity(0, 10); box2d.createGround(); box2d.setFPS(30.0); breakupIntoTriangles = true; // load the shape we saved... auto pts = loadPoints("shape.dat"); auto poly = std::make_shared<ofxBox2dPolygon>(); poly->addVertices(pts); poly->setPhysics(1.0, 0.3, 0.3); poly->triangulatePoly(); poly->create(box2d.getWorld()); polyShapes.push_back(poly); }
//-------------------------------------------------------------- void ofApp::setup() { ofBackground(0, 0, 0); // default background to black / LEDs off ofDisableAntiAliasing(); // we need our graphics sharp for the LEDs // SYSTEM SETTINGS //-------------------------------------- stripWidth = 64; // pixel width of strip stripHeight = 2; // pixel height of strip stripsPerPort = 8; // total number of strips per port numPorts = 4; // total number of teensy ports? brightness = 0; // LED brightness fboRotate = 0; // rotate display fboFlip = false; // invert display waveSpeed = 0.05f; // animation speed drawModes = 0; // default is demo mode demoModes = 0; // default is draw white counterShape = 0; // init at zero hue = 0; // init color at red // setup our teensys teensy.setup(stripWidth, stripHeight, stripsPerPort, numPorts); // configure out teensy boards // (portName, xOffset, yOffset, width%, height%, direction) teensy.serialConfigure("tty.usbmodem14761", 0, 50, 100, 25, 0); teensy.serialConfigure("tty.usbmodem14791", 0, 25, 100, 25, 0); teensy.serialConfigure("tty.usbmodem29", 0, 0, 100, 25, 0); teensy.serialConfigure("tty.usbmodem14751", 0, 75, 100, 25, 0); // allocate our pixels, fbo, and texture teensy.pixels1.allocate(stripWidth, stripHeight*stripsPerPort*numPorts, OF_PIXELS_RGB); fbo.allocate(stripWidth, stripHeight*stripsPerPort*numPorts, GL_RGB); tex.allocate(stripWidth, stripHeight*stripsPerPort*numPorts, GL_RGB); // osc -- listen on the given port //receiver.setup(PORT); // TEST PATTERN //-------------------------------------- font.loadFont("fonts/samst.ttf", 10); // GIFS - dynamic loading //-------------------------------------- dirGif.listDir("gifs/"); gif.setup(dirGif.size()); currentGif = 0; // VIDEOS - dynamic loading //-------------------------------------- dirVid.listDir("videos/"); dirVid.sort(); //allocate the vector to have as many ofVidePlayer as files if( dirVid.size() ){ vid.assign(dirVid.size(), ofVideoPlayer()); } videoOn = false; currentVideo = 0; // IMAGES - dynamic loading //-------------------------------------- dirImg.listDir("images/"); dirImg.sort(); //allocate the vector to have as many ofImages as files if( dirImg.size() ){ img.assign(dirImg.size(), ofImage()); } currentImage = 0; }
//-------------------------------------------------------------- void ofApp::setup(){ ofBackground(255,255,255); ofDisableAntiAliasing(); //----------- //the string is printed at the top of the app //to give the user some feedback message = "loading mySettings.xml"; //we load our settings file //if it doesn't exist we can still make one //by hitting the 's' key if( XML.loadFile("mySettings.xml") ){ message = "mySettings.xml loaded!"; }else{ message = "unable to load mySettings.xml check data/ folder"; } //read the colors from XML //if the settings file doesn't exist we assigns default values (170, 190, 240) red = XML.getValue("BACKGROUND:COLOR:RED", 170); green = XML.getValue("BACKGROUND:COLOR:GREEN", 190); blue = XML.getValue("BACKGROUND:COLOR:BLUE", 240); /* "BACKGROUND:COLOR:RED" referes to a structure like this: <BACKGROUND> <COLOR> <RED>101.103516</RED> </COLOR> </BACKGROUND> */ //we initalize some of our variables lastTagNumber = 0; pointCount = 0; lineCount = 0; //------- //this is a more advanced use of ofXMLSettings //we are going to be reading multiple tags with the same name //lets see how many <STROKE> </STROKE> tags there are in the xml file int numDragTags = XML.getNumTags("STROKE:PT"); //if there is at least one <STROKE> tag we can read the list of points //and then try and draw it as a line on the screen if(numDragTags > 0){ //we push into the last STROKE tag //this temporarirly treats the tag as //the document root. XML.pushTag("STROKE", numDragTags-1); //we see how many points we have stored in <PT> tags int numPtTags = XML.getNumTags("PT"); if(numPtTags > 0){ //We then read those x y values into our //array - so that we can then draw the points as //a line on the screen //we have only allocated a certan amount of space for our array //so we don't want to read more than that amount of points int totalToRead = MIN(numPtTags, NUM_PTS); for(int i = 0; i < totalToRead; i++){ //the last argument of getValue can be used to specify //which tag out of multiple tags you are refering to. int x = XML.getValue("PT:X", 0, i); int y = XML.getValue("PT:Y", 0, i); // dragPts[i].set(x, y); line.addVertex(x, y); pointCount++; } } //this pops us out of the STROKE tag //sets the root back to the xml document XML.popTag(); } //load a monospaced font //which we will use to show part of the xml structure TTF.load("mono.ttf", 7); plotter.setup(0, 20000); plotter.setScaleMinMax(ofGetWidth(), ofGetHeight()); }
//-------------------------------------------------------------- void ofApp::setup(){ // load the file and check if it was loaded ok. Also check it's // format is correct, it needs to have: // // - a root called drawing which // - contains a background element which itself contains nodes // red, green and blue if(!xml.load("points.xml")){ ofLogError() << "Couldn't load file"; } auto drawing = xml.getChild("drawing"); if(!drawing){ drawing = xml.appendChild("drawing"); } // Look for a background tag with children red, green and blue bg = drawing.findFirst("background[red and green and blue]"); if(!bg){ // remove any possible malformed background tag drawing.removeChild("background"); // create the correct background tag and add color components bg = drawing.appendChild("background"); bg.appendChild("red").set(255); bg.appendChild("green").set(255); bg.appendChild("blue").set(255); /* // Load OF icon from svg into our custom xml format. // Needs ofxSvg in the project, won't compile otherwise ofxSVG svg; svg.load("of.svg"); for(auto path: svg.getPaths()){ path.setFilled(false); path.setStrokeWidth(1); for(auto & outline: path.getOutline()){ auto stroke = drawing.appendChild("stroke"); for(auto & p: outline){ auto pt = stroke.appendChild("pt"); pt.setAttribute("x", int(p.x * 4 + ofGetWidth()/2)); pt.setAttribute("y", int(p.y * 4 + ofGetHeight()/2)); } auto pt = stroke.appendChild("pt"); pt.setAttribute("x", int(outline[0].x * 4 + ofGetWidth()/2)); pt.setAttribute("y", int(outline[0].y * 4 + ofGetHeight()/2)); } }*/ } // select background and read it's values auto background = xml.findFirst("//background"); if(background){ // this will always be true, only to document how to search bgColor.r = background.getChild("red").getIntValue(); bgColor.g = background.getChild("green").getIntValue(); bgColor.b = background.getChild("blue").getIntValue(); } // select all strokes and iterate through them // for each stroke, create a new mesh auto strokesXml = xml.find("//drawing/stroke"); for(auto & stroke: strokesXml){ strokes.emplace_back(); strokes.back().setMode(OF_PRIMITIVE_LINE_STRIP); // for each pt in the stroke insert a new // vertex in the mesh auto pts = stroke.getChildren("pt"); for(auto & pt: pts){ auto x = pt.getAttribute("x").getIntValue(); auto y = pt.getAttribute("y").getIntValue(); strokes.back().addVertex({x,y,0}); } } //load a monospaced font //which we will use to show part of the xml structure ttf.load("mono.ttf", 7); ofDisableAntiAliasing(); }
//-------------------------------------------------------------- void testApp::keyReleased(int key){ switch (key) { case 'f': ofToggleFullscreen(); break; case '0': ofEnableBlendMode(OF_BLENDMODE_DISABLED); break; case '1': ofEnableBlendMode(OF_BLENDMODE_ALPHA); break; case '2': ofEnableBlendMode(OF_BLENDMODE_ADD); break; case '3': ofEnableBlendMode(OF_BLENDMODE_SUBTRACT); break; case '4': ofEnableBlendMode(OF_BLENDMODE_MULTIPLY); break; case '5': ofEnableBlendMode(OF_BLENDMODE_SCREEN); break; case 'a': ofEnableAntiAliasing(); break; case 'b': ofBackground(0, 0, 0, 255); break; case 'd': ofDisableAlphaBlending(); break; case 'e': ofEnableAlphaBlending(); break; case 'r': //read file importFileForStruct(); break; case 's': ofDisableAntiAliasing(); break; case 'w': ofBackground(255, 255, 255, 255); break; case ' ': { saveToFile = true; ofLog(OF_LOG_NOTICE, "calculating..."); //ペアのデータを作成 --> vector<pointPair> pointPairVectorForWriting; for (int k=0; k<image1.getWidth()*image1.getHeight(); k++) { if (k <= image1.getWidth()*image1.getHeight()) { // 左の画像を右の画像に入れ替える ofPoint referencePoint; if (enableRandomExchange) { //ランダムで交換 referencePoint = ofPoint(exchangeOrderVector[k]%(int)image1.getWidth(), exchangeOrderVector[k]/(int)image1.getWidth()); }else{ //上から順に交換 referencePoint = ofPoint(k%(int)image1.getWidth(), k/(int)image1.getWidth()); } ofColor referenceColor = image1.getColor(referencePoint.x, referencePoint.y); double minimumDistance = image1.getWidth()+image2.getHeight(); ofPoint minimumDistancePoint; unsigned char * checkImagePixels = image2.getPixels(); // 最小の距離の色を調べる for (int i=0; i<image1.getHeight(); i++) { for (int j=0; j<image1.getWidth(); j++) { if (!enableDuplicate) { // 重複を許さない if (!usedOrNotVector[i*(int)image2.getWidth()+j]) { ofColor checkColor = ofColor(checkImagePixels[(i*(int)image2.getWidth()+j)*3], checkImagePixels[(i*(int)image2.getWidth()+j)*3+1], checkImagePixels[(i*(int)image2.getWidth()+j)*3+2]); double checkDistance = getColorDistance(referenceColor, checkColor); if (checkDistance < minimumDistance) { if (!usedOrNotVector[i*(int)image2.getWidth()+j]) { minimumDistance = checkDistance; minimumDistancePoint = ofPoint(j, i); } // 同じ色の重複を許す minimumDistance = checkDistance; minimumDistancePoint = ofPoint(j, i); } } } else{ ofColor checkColor = ofColor(checkImagePixels[(i*(int)image2.getWidth()+j)*3], checkImagePixels[(i*(int)image2.getWidth()+j)*3+1], checkImagePixels[(i*(int)image2.getWidth()+j)*3+2]); double checkDistance = getColorDistance(referenceColor, checkColor); if (checkDistance < minimumDistance) { if (!usedOrNotVector[i*(int)image2.getWidth()+j]) { minimumDistance = checkDistance; minimumDistancePoint = ofPoint(j, i); } // 同じ色の重複を許す minimumDistance = checkDistance; minimumDistancePoint = ofPoint(j, i); } } } } //最も近い距離の色の組み合わせをベクターに保存 pointPair tempPointPair; tempPointPair.point1 = referencePoint; tempPointPair.point2 = minimumDistancePoint; // 重複を許さない if (!enableDuplicate) { //再利用しないために、使用したPointを保存 usedOrNotVector[minimumDistancePoint.y*(int)image2.getWidth()+minimumDistancePoint.x] = true; } pointPairVectorForWriting.push_back(tempPointPair); } } ofLog(OF_LOG_NOTICE, "pointPairVectorForWriting done!"); //<-- ペアのデータを作成 ofLog(OF_LOG_NOTICE, "X1:"+ofToString(pointPairVectorForWriting[0].point1.x)+" Y1:"+ofToString(pointPairVectorForWriting[0].point1.y)); ofLog(OF_LOG_NOTICE, "X2:"+ofToString(pointPairVectorForWriting[0].point2.x)+" Y2:"+ofToString(pointPairVectorForWriting[0].point2.y)); exportFileForStruct(pointPairVectorForWriting); ofLog(OF_LOG_NOTICE, ofToString("writing file...")); saveToFile = false; ofLog(OF_LOG_NOTICE, "done"); } break; default: break; } }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(255,255,255); ofDisableAntiAliasing(); //----------- //the string is printed at the top of the app //to give the user some feedback message = "loading mySettings.xml"; //we load our settings file //if it doesn't exist we can still make one //by hitting the 's' key if( XML.load("mySettings.xml") ){ message = "mySettings.xml loaded!"; }else{ // Ok, we didn't get a file, but that's ok, we're going // to go ahead and start making some stuff anyways! First, to // make a correct XML document, we need a root element, so // let's do that: XML.addChild("DRAWING"); // now we set our current element so we're on the right // element, so when we add new nodes, they're still inside // the root element XML.setTo("DRAWING"); message = "unable to load mySettings.xml check data/ folder"; } //read the colors from XML or, if they don't exist, because we've // loaded them from elsewhere, let's just make some stuff up //the double forward slash //RED means: search from the root of the xml for a tag could RED //otherwise the search would be relative to where you are in the xml structure. // = absolute if(XML.exists("//RED")) { red = XML.getValue<int>("//RED"); } else { red = 170; } if(XML.exists("//GREEN")) { green = XML.getValue<int>("//GREEN"); } else { green = 190; } if(XML.exists("//BLUE")) { blue = XML.getValue<int>("//BLUE"); } else { blue = 240; } // If we have STROKE nodes that we've already created, then we can go ahead and // load them into the dragPts so they're drawn to the screen if(XML.exists("STROKE")) { // This gets the first stroke (notice the [0], it's just like an array) XML.setTo("STROKE[0]"); do { // set our "current" PT to the first one if(XML.getName() == "STROKE" && XML.setTo("PT[0]")) { // get each individual x,y for each point do { int x = XML.getValue<int>("X"); int y = XML.getValue<int>("Y"); ofVec2f v(x, y); dragPts.push_back(v); } while(XML.setToSibling()); // go the next PT // go back up XML.setToParent(); } } while( XML.setToSibling() ); // go to the next STROKE } //load a monospaced font //which we will use to show part of the xml structure TTF.loadFont("mono.ttf", 7); }