summaryrefslogtreecommitdiff
path: root/gui/src/ofApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src/ofApp.cpp')
-rw-r--r--gui/src/ofApp.cpp301
1 files changed, 258 insertions, 43 deletions
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp
index 81e9e0c..689d5ad 100644
--- a/gui/src/ofApp.cpp
+++ b/gui/src/ofApp.cpp
@@ -3,6 +3,8 @@
const ofPoint mainwindowsize=ofPoint(1200,900);
+
+
//--------------------------------------------------------------
void ofApp::setup(){
warpframe[0]=glm::vec2(0,0);
@@ -14,6 +16,8 @@ void ofApp::setup(){
gui.setup();
+ source=SVG_outlines;
+
//==================================================== ofxNDI
senderName[0] = 0; // The sender name used for display
@@ -31,19 +35,26 @@ void ofApp::setup(){
//============================ GUI
- gui.add(NDIthreshold.setup("threshold", 140, 0, 255));
- gui.add(NDIsimplify.setup("simplify", 0.2f, 0.0f, 1.0f));
- gui.add(NDIuseColour.setup("use colour", true));
- gui.add(NDIcolR.setup("red", 140, 0, 255));
- gui.add(NDIcolR.setup("green", 140, 0, 255));
- gui.add(NDIcolG.setup("blue", 140, 0, 255));
+ gui.add(contour_threshold.setup("threshold", 140, 0, 255));
+ gui.add(contour_simplify.setup("simplify", 0.2, 0.0, 1.0));
+ gui.add(contour_useColour.setup("use colour", true));
+ gui.add(laser_R.setup("red", 140, 0, 255));
+ gui.add(laser_G.setup("green", 140, 0, 255));
+ gui.add(laser_B.setup("blue", 140, 0, 255));
+ gui.add(laser_intensity.setup("intensity", 30, 0, 255));
+ gui.add(laser_points.setup("points", 20000, 0, 40000));
+ gui.add(shapes_randomise.setup("randomise shapes", true));
+ gui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 0.8));
+ gui.add(shapes_duration.setup("shape duration", 5, 0, 25));
+ framecounter=0;
}
//--------------------------------------------------------------
void ofApp::updateOutput(ofEventArgs & args){
-
+ laser.set_pts(laser_points);
+ laser.set_intensity(laser_intensity);
}
@@ -139,13 +150,17 @@ void ofApp::update(){
}
}
+
+ if (movie.isLoaded()){
+ movie.update();
+ }
}
const ofPoint previewframesize=ofPoint(320,240);
-//--------------------------------------------------------------
-void ofApp::draw(){
+//-------------------------------------------------------------- GUI
+void ofApp::draw(){
ofBackground(0);
ofSetColor(255);
@@ -154,10 +169,10 @@ void ofApp::draw(){
gui.draw();
//================================== NDI
-
+/*
glPushMatrix();
- glTranslatef(256,0,0);
+ glTranslatef(230,0,0);
ofDrawRectangle(20,20,previewframesize.x+4,previewframesize.y+4);
@@ -202,6 +217,46 @@ void ofApp::draw(){
glPopMatrix();
+ //================================== NDI
+
+ glPushMatrix();
+
+ glTranslatef(230,300,0);
+*/
+ //================================== video
+
+ glPushMatrix();
+
+ glTranslatef(230,0,0);
+
+ ofDrawRectangle(20,20,previewframesize.x+4,previewframesize.y+4);
+
+ if (movie.isLoaded()){
+ movie.draw(22, 22, previewframesize.x, previewframesize.y);
+ }
+
+ glPopMatrix();
+
+ //================================== SVG
+
+ glPushMatrix();
+
+ float scale=previewframesize.x/mainwindowsize.x;
+
+ glTranslatef(230,300,0);
+
+ ofDrawRectangle(20,20,previewframesize.x+4,previewframesize.y+4);
+
+ glTranslatef(22,22,0);
+
+ glScalef(scale,scale,scale);
+
+ for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){
+ shape->getPoly().draw();
+ }
+
+ glPopMatrix();
+
}
void ofApp::drawOutput(ofEventArgs & args){
@@ -210,35 +265,124 @@ void ofApp::drawOutput(ofEventArgs & args){
ofSetColor(255,255,255);
- ofMatrix4x4 m = ofMatrix4x4::newIdentityMatrix();
- m.rotateRad(ofGetElapsedTimef(),0,0,1);
- m.translate(ofGetWidth()/2,ofGetHeight()/2,0);
+ vector <colourPolyline> laserOutput;
+
+ switch (source){
+ case TEST:{
+ ofMatrix4x4 m = ofMatrix4x4::newIdentityMatrix();
+ m.rotateRad(ofGetElapsedTimef(),0,0,1);
+ m.translate(ofGetWidth()/2,ofGetHeight()/2,0);
+
+ glm::vec2 src[]={
+ glm::vec2(0,0),
+ glm::vec2(ofGetWidth(),0),
+ glm::vec2(ofGetWidth(),ofGetHeight()),
+ glm::vec2(0,ofGetHeight())
+ };
- glm::vec2 src[]={
- glm::vec2(0,0),
- glm::vec2(ofGetWidth(),0),
- glm::vec2(ofGetWidth(),ofGetHeight()),
- glm::vec2(0,ofGetHeight())
- };
+ ofMatrix4x4 warp =lineTransformer::getPerspectiveTransformMatrix(src,warpframe);
- ofMatrix4x4 warp =lineTransformer::getPerspectiveTransformMatrix(src,warpframe);
+ //drawPoly(polyLineTransform(makePolygon(4,200),m),200,200);
+ //drawPoly(polyLineTransform(makePolygon(5,200),m),-200,200);
+ //drawPoly(polyLineTransform(makePolygon(6,200),m),-200,-200);
+
+ ofPolyline poly=lineTransformer::polyLineTransform(warp,
+ lineTransformer::polyLineTransform(m,
+ lineTransformer::makePolygon(6,200)
+ )
+ );
+ laserOutput.push_back(colourPolyline(poly,ofColor(laser_R,laser_G,laser_B)));
+
+ }
+ case NDI:{
+ ofPoint scale=ofPoint(mainwindowsize.x/ndiImage.getWidth(),mainwindowsize.x/ndiImage.getHeight());
+
+ //does not work no matter what the fuck you do
+
+ //grayImage.setFromPixels(pixels.getData(),ndiImage.getWidth(),ndiImage.getHeight());
+
+ //grayImage.draw(0,0,mainwindowsize.x,mainwindowsize.y);
+
+ grayImage = colorImg;
+
+ grayImage.threshold(contour_threshold);
+
+ //virtual int findContours( ofxCvGrayscaleImage& input,
+ // int minArea, int maxArea,
+ // int nConsidered, bool bFindHoles,
+ // bool bUseApproximation = true);
+ contourFinder.findContours(grayImage, 20, (340*240)/3, 10, true);
+
+ for (int i = 0; i < contourFinder.nBlobs; i++){
+ colourPolyline shape;
+ for (auto& point:contourFinder.blobs[i].pts){
+ ofVec3f p=point*scale;
+ ofColor c=colorImg.getPixels().getColor(point.x,point.y);
+ shape.addVertex(p,contour_useColour?c:ofColor(laser_R,laser_G,laser_B));
+ }
+ shape.simplify(contour_simplify);
+ laserOutput.push_back(shape);
+ }
+ break;
+
+ }
+ case Player:{
+ if (movie.isLoaded()){
+ ofPoint scale=ofPoint(mainwindowsize.x/movie.getWidth(),mainwindowsize.y/movie.getHeight());
+ colorImg.setFromPixels(movie.getPixels());
+ grayImage = colorImg;
+ grayImage.threshold(contour_threshold);
+ contourFinder.findContours(grayImage, 20, (340*240)/3, 10, true);
+ for (int i = 0; i < contourFinder.nBlobs; i++){
+ colourPolyline shape;
+ for (auto& point:contourFinder.blobs[i].pts){
+ ofVec3f p=point*scale;
+ ofColor c=colorImg.getPixels().getColor(point.x,point.y);
+ shape.addVertex(p,contour_useColour?c:ofColor(laser_R,laser_G,laser_B));
+ }
+ shape.simplify(contour_simplify);
+ laserOutput.push_back(shape);
+ }
+ }
+ break;
+ }
+ case SVG_outlines:{
+ if (shapes_randomise){
+ if (framecounter==0){
+ select_random_shapes();
+ framecounter=shapes_duration;
+ }
+ for (auto s:shape_selection){
+ laserOutput.push_back(colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B)));
+ }
+ framecounter--;
+ }
+ else {
+ for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){
+ laserOutput.push_back(colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B)));
+ }
+ }
+ break;
+ }
+ }
- //drawPoly(polyLineTransform(makePolygon(4,200),m),200,200);
- //drawPoly(polyLineTransform(makePolygon(5,200),m),-200,200);
- //drawPoly(polyLineTransform(makePolygon(6,200),m),-200,-200);
+ int num = laser.draw(laserOutput);
- lineTransformer::drawPoly(
- lineTransformer::polyLineTransform(
- lineTransformer::polyLineTransform(
- lineTransformer::makePolygon(6,200)
- ,m)
- ,warp)
- ,0,0);
+ for (auto& shape:laserOutput){
+ shape.draw();
+ }
- if (bDrawFrame){
+ if (bDrawFrame){
lineTransformer::drawWarpFrame(warpframe);
}
+ if (num>0){
+ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num));
+ }
+ else {
+ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser error ");
+ }
+
}
//--------------------------------------------------------------
@@ -251,11 +395,28 @@ void ofApp::exit() {
//--------------------------------------------------------------
void ofApp::outputKeyPressed(ofKeyEventArgs &args){
+ keyPressed(args);
+
+
+}
+
+void ofApp::keyPressed(ofKeyEventArgs &args){
if (args.key==OF_KEY_COMMAND){
commandPressed=true;
}
switch(args.key){
+ case 'q':{
+ source--;
+ if (source<0){
+ source=Source_end-1;
+ }
+ break;
+ }
+ case 'p':{
+ source=(source+1)%Source_end;
+ break;
+ }
case 'w':{
bDrawFrame=!bDrawFrame;
break;
@@ -264,12 +425,6 @@ void ofApp::outputKeyPressed(ofKeyEventArgs &args){
commandPressed=true;
}
}
-
-
-}
-
-void ofApp::keyPressed(ofKeyEventArgs &args){
-
}
//--------------------------------------------------------------
@@ -334,15 +489,76 @@ void ofApp::windowResized(int w, int h){
}
+void ofApp::select_random_shapes(){
+ shape_selection.clear();
+ while (shape_selection.size()<(segmenters.size()*shapes_amount)){
+ int selection=rand()%segmenters.size();
+ if (shape_selection.find(selection)==shape_selection.end()){
+ shape_selection.insert(selection);
+ }
+ }
+ std::stringstream strm;
+ for (auto& s:shape_selection){
+ strm << s <<" ";
+ }
+ //cout << "randomly selected (" << strm.str() <<") \n";
+}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
+
+ if (dragInfo.position.x>250&&dragInfo.position.x<570&&dragInfo.position.y>20&&dragInfo.position.y<266){
+ std::string filename= *dragInfo.files.begin();
+ if (movie.load(filename)){
+ cout << "loaded "<< filename<<std::endl;
+ movie.setLoopState(OF_LOOP_NORMAL);
+ movie.play();
+ }
+ else {
+ cout << "failed to load"<<std::endl;
+ }
+ }
+
+ if (dragInfo.position.x>250&&dragInfo.position.x<570&&dragInfo.position.y>320&&dragInfo.position.y<566){
+ std::string filename= *dragInfo.files.begin();
+ svg.load(filename);
+ vector <ofPath> imagepaths= svg.getPaths();
+
+ std::stringstream strm;
+
+ if (imagepaths.size()){
+ segmenters.clear();
+ for (auto& path:imagepaths){
+ path.setPolyWindingMode(OF_POLY_WINDING_ODD);
+
+ vector <ofPolyline> outlines= path.getOutline();
+ for (auto& outline:outlines){
+ strm << outline.size() << "->";
+ outline.simplify(contour_simplify);
+ strm << outline.size() << " ";
+ segmenters.push_back(lineSegmenter(outline));
+ }
+ strm << " , ";
+ }
+
+ cout << "SVG: found " << imagepaths.size() << " paths with " << segmenters.size() << " shapes [ " << strm.str() << " ]" <<std::endl;
+ select_random_shapes();
+ }
+
+ }
+
+}
+
+ //printf("%s at %i %i \n",dragInfo.files.begin(),dragInfo.position.x,dragInfo.position.y);
//std::string filenames;
-
+ //cout << dragInfo.files.begin()->c_str()<<","<<dragInfo.position.x<<","<<dragInfo.position.y<<std::endl;
+
//for (auto f = dragInfo.files.begin(); f != dragInfo.files.end(); f++){
- // if (f!=dragInfo.files.begin()){
- // filenames=filenames+", ";
- // }
+ // cout << f->c_str()<<","<<dragInfo.position.x<<","<<dragInfo.position.y<<std::endl;
+ //if (f!=dragInfo.files.begin()){
+ // filenames=filenames+", ";
+ //}
+ //}
// filenames=filenames+*f;
// if (dragInfo.position.y<200){
@@ -353,4 +569,3 @@ void ofApp::dragEvent(ofDragInfo dragInfo){
//}
-}