diff options
| author | Tim Redfern <tim@getdrop.com> | 2018-01-28 22:20:49 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2018-01-28 22:20:49 +0000 |
| commit | 64c89ab53447a004002ec0b0db94fd0a1e632cf6 (patch) | |
| tree | 65ce3b4802bbb0656cc1a8c843c81d7a3fcda8c9 /drawing/src/ofApp.cpp | |
| parent | 404746784ce6ef2b87c396a12451947fee28b244 (diff) | |
POC driver
Diffstat (limited to 'drawing/src/ofApp.cpp')
| -rw-r--r-- | drawing/src/ofApp.cpp | 117 |
1 files changed, 108 insertions, 9 deletions
diff --git a/drawing/src/ofApp.cpp b/drawing/src/ofApp.cpp index d110414..9376723 100644 --- a/drawing/src/ofApp.cpp +++ b/drawing/src/ofApp.cpp @@ -7,7 +7,7 @@ vector<std::string> cmdnames={"moveTo","lineTo","curveTo","bezierTo","quadBezier //-------------------------------------------------------------- void ofApp::setup(){ ofxSVG svg; - svg.load("bars.svg"); + svg.load("haring.svg"); imagepaths= svg.getPaths(); for (int i=0;i<imagepaths.size();i++){ @@ -59,6 +59,46 @@ void ofApp::setup(){ movie.play(); threshold=128; + + //setup our directory + dir.setup(); + //setup our client + client.setup(); + + syphonFbo.allocate(800,600); + + //register for our directory's callbacks + ofAddListener(dir.events.serverAnnounced, this, &ofApp::serverAnnounced); + // not yet implemented + //ofAddListener(dir.events.serverUpdated, this, &ofApp::serverUpdated); + ofAddListener(dir.events.serverRetired, this, &ofApp::serverRetired); + + dirIdx = -1; +} + +//these are our directory's callbacks +void ofApp::serverAnnounced(ofxSyphonServerDirectoryEventArgs &arg) +{ + for( auto& dir : arg.servers ){ + ofLogNotice("ofxSyphonServerDirectory Server Announced")<<" Server Name: "<<dir.serverName <<" | App Name: "<<dir.appName; + } + dirIdx = 0; +} + +void ofApp::serverUpdated(ofxSyphonServerDirectoryEventArgs &arg) +{ + for( auto& dir : arg.servers ){ + ofLogNotice("ofxSyphonServerDirectory Server Updated")<<" Server Name: "<<dir.serverName <<" | App Name: "<<dir.appName; + } + dirIdx = 0; +} + +void ofApp::serverRetired(ofxSyphonServerDirectoryEventArgs &arg) +{ + for( auto& dir : arg.servers ){ + ofLogNotice("ofxSyphonServerDirectory Server Retired")<<" Server Name: "<<dir.serverName <<" | App Name: "<<dir.appName; + } + dirIdx = 0; } //-------------------------------------------------------------- @@ -96,7 +136,7 @@ void ofApp::draw(){ //transform points of segmenter before intersecting with mask switch (mode){ - case 0:{ + case 7:{ for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ auto segments=shape->getSegments(numsegments,coverage,phase); for (auto segment=segments.begin();segment!=segments.end();segment++){ @@ -239,14 +279,49 @@ void ofApp::draw(){ break; } - case 7: { - movie.update(); - ofPoint scale=ofPoint(ofGetWidth()/movie.getWidth(),ofGetHeight()/movie.getHeight()); - if (movie.isFrameNew()){ - colorImg.setFromPixels(movie.getPixels()); + case 0: { + ofPoint scale; + if(dir.isValidIndex(dirIdx)){ + //client.update(); + /* + scale=ofPoint(ofGetWidth()/client.getWidth(),ofGetHeight()/client.getHeight()); + ofPixels pixels; + ofTexture texture=client.getTexture(); + texture.bind(); + texture.readToPixels(pixels); + texture.unbind(); + colorImg.setFromPixels(pixels); grayImage = colorImg; grayImage.threshold(threshold); contourFinder.findContours(grayImage, 20, (340*240)/3, 10, true); + */ + scale=ofPoint(ofGetWidth()/syphonFbo.getWidth(),ofGetHeight()/syphonFbo.getHeight()); + + syphonFbo.begin(); + client.draw(0, 0, syphonFbo.getWidth(),syphonFbo.getHeight()); + syphonFbo.end(); + //syphonFbo.draw(0,0,ofGetWidth(),ofGetHeight()); //works + //printf("got fbo: %ix%i format %i\n",syphonFbo.getWidth(),syphonFbo.getHeight(),syphonFbo.getTexture().getPixelFormat()); + //syphonFbo.updateTexture(0); + ofPixels pixels; + syphonFbo.getTexture().readToPixels(pixels); + //printf("got texture: %ix%i format %i\n",pixels.getWidth(),pixels.getHeight(),pixels.getPixelFormat()); + //pixels are in RGBA format allegedly, but maybe this is the problem + colorImg.setFromPixels(pixels); + colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); //mangled + grayImage = colorImg; + grayImage.threshold(threshold); + contourFinder.findContours(grayImage, 20, (340*240)/3, 10, true); + } + else { + movie.update(); + scale=ofPoint(ofGetWidth()/movie.getWidth(),ofGetHeight()/movie.getHeight()); + if (movie.isFrameNew()){ + colorImg.setFromPixels(movie.getPixels()); + grayImage = colorImg; + grayImage.threshold(threshold); + contourFinder.findContours(grayImage, 20, (340*240)/3, 10, true); + } } vector <colourPolyline> shapes; for (int i = 0; i < contourFinder.nBlobs; i++){ @@ -281,9 +356,9 @@ void ofApp::draw(){ std::stringstream strm; strm << "mode: " << mode << " segments: "<<segmentsdrawn<< " points: "<<pointsdrawn; - ofSetWindowTitle(strm.str()); + //ofSetWindowTitle(strm.str()); - mainOutputSyphonServer.publishScreen(); + //mainOutputSyphonServer.publishScreen(); } @@ -335,6 +410,30 @@ void ofApp::keyReleased(int key){ threshold=min(threshold+1,255); break; } + case ' ':{ + if (dir.size() > 0) + { + dirIdx++; + if(dirIdx > dir.size() - 1) + dirIdx = 0; + + client.set(dir.getDescription(dirIdx)); + string serverName = client.getServerName(); + string appName = client.getApplicationName(); + + if(serverName == ""){ + serverName = "null"; + } + if(appName == ""){ + appName = "null"; + } + ofSetWindowTitle(serverName + ":" + appName); + } + else + { + ofSetWindowTitle("No Server"); + } + } } } |
