diff options
| -rw-r--r-- | drawing/src/ofApp.cpp | 191 | ||||
| -rw-r--r-- | drawing/src/ofApp.h | 18 | ||||
| -rw-r--r-- | ofxHelios/example-squares/src/ofApp.cpp | 17 | ||||
| -rw-r--r-- | ofxHelios/src/ofxHelios.cpp | 86 | ||||
| -rw-r--r-- | ofxHelios/src/ofxHelios.h | 8 | ||||
| -rw-r--r-- | polyTest/src/ofApp.h | 1 |
6 files changed, 248 insertions, 73 deletions
diff --git a/drawing/src/ofApp.cpp b/drawing/src/ofApp.cpp index da00262..f84f0b0 100644 --- a/drawing/src/ofApp.cpp +++ b/drawing/src/ofApp.cpp @@ -1,9 +1,6 @@ #include "ofApp.h" #include "glew.h" -int MAX_POINTS=20000; -int LASER_INTENSITY=37; - vector<std::string> cmdnames={"moveTo","lineTo","curveTo","bezierTo","quadBezierTo","arc","arcNegative","close"}; //-------------------------------------------------------------- @@ -12,7 +9,7 @@ void ofApp::setup(){ svg.load("lorenzo.svg"); imagepaths= svg.getPaths(); - float simplify_factor=0.3f; + float simplify_factor=0.2f; std::stringstream strm; @@ -89,8 +86,16 @@ void ofApp::setup(){ dirIdx = -1; - laser.set_pts(MAX_POINTS); - laser.set_intensity(LASER_INTENSITY); + laser.set_pts(30000); + laser.set_intensity(40); + + warpframe[0]=glm::vec2(0,0); + warpframe[1]=glm::vec2(ofGetWidth(),0); + warpframe[2]=glm::vec2(ofGetWidth(),ofGetHeight()); + warpframe[3]=glm::vec2(0,ofGetHeight()); + mapping_scale=1.8; + select_warpframe=-1; + bDrawFrame=false; } //these are our directory's callbacks @@ -128,6 +133,95 @@ void ofApp::update(){ } +void ofApp::drawWarpFrame(){ + ofSetColor(255,255,255); + ofNoFill(); + for (int i=0;i<4;i++){ + ofDrawCircle(warpframe[i],25); + ofDrawLine(warpframe[i],warpframe[(i+1)%4]); + } +} + +void ofApp::gaussianElimination(float * input, int n) +{ + auto i = 0; + auto j = 0; + auto m = n - 1; + + while (i < m && j < n) + { + auto iMax = i; + for (auto k = i + 1; k < m; ++k) + { + if (fabs(input[k * n + j]) > fabs(input[iMax * n + j])) + { + iMax = k; + } + } + + if (input[iMax * n + j] != 0) + { + if (i != iMax) + { + for (auto k = 0; k < n; ++k) + { + auto ikIn = input[i * n + k]; + input[i * n + k] = input[iMax * n + k]; + input[iMax * n + k] = ikIn; + } + } + + float ijIn = input[i * n + j]; + for (auto k = 0; k < n; ++k) + { + input[i * n + k] /= ijIn; + } + + for (auto u = i + 1; u < m; ++u) + { + auto ujIn = input[u * n + j]; + for (auto k = 0; k < n; ++k) + { + input[u * n + k] -= ujIn * input[i * n + k]; + } + } + + ++i; + } + ++j; + } + + for (auto i = m - 2; i >= 0; --i) + { + for (auto j = i + 1; j < n - 1; ++j) + { + input[i * n + m] -= input[i * n + j] * input[j * n + m]; + } + } +} + +glm::mat4 ofApp::getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]) +{ + float p[8][9] = + { + { -src[0][0], -src[0][1], -1, 0, 0, 0, src[0][0] * dst[0][0], src[0][1] * dst[0][0], -dst[0][0] }, // h11 + { 0, 0, 0, -src[0][0], -src[0][1], -1, src[0][0] * dst[0][1], src[0][1] * dst[0][1], -dst[0][1] }, // h12 + { -src[1][0], -src[1][1], -1, 0, 0, 0, src[1][0] * dst[1][0], src[1][1] * dst[1][0], -dst[1][0] }, // h13 + { 0, 0, 0, -src[1][0], -src[1][1], -1, src[1][0] * dst[1][1], src[1][1] * dst[1][1], -dst[1][1] }, // h21 + { -src[2][0], -src[2][1], -1, 0, 0, 0, src[2][0] * dst[2][0], src[2][1] * dst[2][0], -dst[2][0] }, // h22 + { 0, 0, 0, -src[2][0], -src[2][1], -1, src[2][0] * dst[2][1], src[2][1] * dst[2][1], -dst[2][1] }, // h23 + { -src[3][0], -src[3][1], -1, 0, 0, 0, src[3][0] * dst[3][0], src[3][1] * dst[3][0], -dst[3][0] }, // h31 + { 0, 0, 0, -src[3][0], -src[3][1], -1, src[3][0] * dst[3][1], src[3][1] * dst[3][1], -dst[3][1] }, // h32 + }; + + gaussianElimination(&p[0][0], 9); + + return glm::mat4(p[0][8], p[3][8], 0, p[6][8], + p[1][8], p[4][8], 0, p[7][8], + 0, 0, 1, 0, + p[2][8], p[5][8], 0, 1); +} + ofPolyline ofApp::polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform){ ofPolyline tempPoly; for (auto& p:poly){ @@ -136,7 +230,24 @@ ofPolyline ofApp::polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform){ return tempPoly; } +ofPolyline ofApp::makePolygon(int num,float diam){ + ofPolyline poly; + float step=PI*2/num; + for (int i=0;i<=num;i++){ + poly.addVertex(cos(step*i)*diam,sin(step*i)*diam); + } + return poly; +} +void ofApp::drawPoly(ofPolyline poly,float x,float y){ + glPushMatrix(); + ofTranslate(x,y); + poly.draw(); + for (int i=0;i<poly.size();i++){ + ofDrawBitmapString(poly.getDegreesAtIndex(i),poly[i].x+10,poly[i].y+10,0); + } + glPopMatrix(); +} //-------------------------------------------------------------- void ofApp::draw(){ @@ -146,19 +257,27 @@ void ofApp::draw(){ int segmentsdrawn=0; int pointsdrawn=0; - float phase=fmod(ofGetElapsedTimef()/10,1); + float phase=fmod(ofGetElapsedTimef()/3,1); //movie.draw(0,0,ofGetWidth(),ofGetHeight()); //transform points of segmenter before intersecting with mask - vector <colourPolyline> lasershapes; + vector <ofPolyline> lasershapes; switch (mode){ + case 2:{ + for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ + lasershapes.push_back(shape->getPoly()); + } + break; + } case 0:{ - //int s=((int)ofGetElapsedTimef())%segmenters.size(); - //lasershapes.push_back(segmenters[s].getPoly()); - + int s=((int)(ofGetElapsedTimef()*10))%segmenters.size(); + lasershapes.push_back(segmenters[s].getPoly()); + break; + } + case 1:{ for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ auto segments=shape->getSegments(numsegments,coverage,phase); @@ -170,7 +289,7 @@ void ofApp::draw(){ break; } - case 1:{ + case 11:{ vector <ofPolyline> shapes; for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ auto segments=shape->getSegments(numsegments,coverage,phase); @@ -188,7 +307,7 @@ void ofApp::draw(){ } break; } - case 2:{ + case 12:{ vector <ofPolyline> shapes; for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ auto segments=shape->getSegments(numsegments,coverage,phase); @@ -382,13 +501,41 @@ void ofApp::draw(){ vector <ofPath> paths= svg.getPaths(); for (auto& l:paths) l.draw(); */ + + + + glm::vec2 src[]={ + glm::vec2(0,0), + glm::vec2(ofGetWidth(),0), + glm::vec2(ofGetWidth(),ofGetHeight()), + glm::vec2(0,ofGetHeight()) + }; + + glm::vec2 mp=glm::vec2(ofGetWidth()/2,ofGetHeight()/2); + + glm::vec2 scaled_dest[]={ + ((warpframe[0]-mp)*mapping_scale)+mp, + ((warpframe[1]-mp)*mapping_scale)+mp, + ((warpframe[2]-mp)*mapping_scale)+mp, + ((warpframe[3]-mp)*mapping_scale)+mp + }; + + ofMatrix4x4 warp =getPerspectiveTransformMatrix(src,scaled_dest); + + vector <ofPolyline> warpedshapes; + + for (auto s:lasershapes){ + warpedshapes.push_back(polyLineTransform(s,warp)); + } - int num = laser.draw(lasershapes); + int num = laser.draw(warpedshapes); for (auto& shape:lasershapes){ shape.draw(); } + if (bDrawFrame) drawWarpFrame(); + if (num>0){ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)); } @@ -472,6 +619,10 @@ void ofApp::keyReleased(int key){ ofSetWindowTitle("No Server"); } } + case 'w':{ + bDrawFrame=!bDrawFrame; + break; + } } } @@ -483,17 +634,23 @@ void ofApp::mouseMoved(int x, int y ){ //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ - + if (select_warpframe>-1){ + warpframe[select_warpframe]=glm::vec2(x,y); + } } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ - + for (int i=0;i<4;i++){ + if (ofPoint(x,y).distance(warpframe[i])<25){ + select_warpframe=i; + } + } } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ - + select_warpframe=-1; } //-------------------------------------------------------------- diff --git a/drawing/src/ofApp.h b/drawing/src/ofApp.h index 13b3a0b..3cf9de8 100644 --- a/drawing/src/ofApp.h +++ b/drawing/src/ofApp.h @@ -35,8 +35,6 @@ class ofApp : public ofBaseApp{ void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); - ofPolyline polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform); - vector <lineSegmenter> segmenters; vector <ofPolyline> mask; @@ -73,4 +71,20 @@ class ofApp : public ofBaseApp{ ofFbo syphonFbo; ofxHelios laser; + + void drawWarpFrame(); + + void gaussianElimination(float * input, int n); + glm::mat4 getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]); + ofPolyline polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform); + ofPolyline makePolygon(int num,float diam); + void drawPoly(ofPolyline poly,float x,float y); + + glm::vec2 warpframe[4]; + int select_warpframe; + float mapping_scale; + + bool bDrawFrame; + + }; diff --git a/ofxHelios/example-squares/src/ofApp.cpp b/ofxHelios/example-squares/src/ofApp.cpp index bddbc58..faf4ad9 100644 --- a/ofxHelios/example-squares/src/ofApp.cpp +++ b/ofxHelios/example-squares/src/ofApp.cpp @@ -8,6 +8,7 @@ int LASER_INTENSITY=37; void testApp::setup(){ laser.set_pts(MAX_POINTS); laser.set_intensity(LASER_INTENSITY); + } //-------------------------------------------------------------- @@ -38,14 +39,18 @@ void testApp::draw(){ ofBackground(0); ofSetColor(255,255,255); - ofMatrix4x4 m = ofMatrix4x4::newIdentityMatrix(); - m.rotateRad(ofGetElapsedTimef(),0,0,1); - m.translate(ofGetWidth()/2,ofGetHeight()/2,0); - ofPolyline square=polyLineTransform(makePolygon(4,200),m); + vector <ofPolyline> squares; - square.draw(); + for (int i=0;i<4;i++){ + ofMatrix4x4 m = ofMatrix4x4::newIdentityMatrix(); + m.rotateRad(ofGetElapsedTimef(),0,0,1); + m.translate(ofGetWidth()/2+(cos(i*PI*0.5)*300),ofGetHeight()/2+(sin(i*PI*0.5)*300),0); + ofPolyline square=polyLineTransform(makePolygon(4,400),m); + square.draw(); + squares.push_back(square); + } - int num = laser.draw(square); + int num = laser.draw(squares); if (num>0){ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)); diff --git a/ofxHelios/src/ofxHelios.cpp b/ofxHelios/src/ofxHelios.cpp index 0eb8e8a..d5bf812 100644 --- a/ofxHelios/src/ofxHelios.cpp +++ b/ofxHelios/src/ofxHelios.cpp @@ -9,18 +9,17 @@ #include "ofxHelios.h" /* -draw a colourpolyline - -put in mid points - -draw a vector of lines - -put in dwell points - +rounding +how long does a laser take to turn off? +we see curved on both edges betwen shapes, but not on corners */ int ofxHelios::draw(vector <ofPolyline> &lines,ofColor colour,int intensity){ - return 0; + vector <colourPolyline> output; + for (auto& line:lines){ + output.push_back(line); + } + return draw(output,intensity); } int ofxHelios::draw(ofPolyline &line,ofColor colour,int intensity){ @@ -50,23 +49,18 @@ int ofxHelios::draw(vector <colourPolyline> &lines, int intensity){ vector <HeliosPoint> points; - ofPoint prev_point=lines[0][0]; - ofColor prev_colour=lines[0].getColourAt(0); - for (auto& line:lines){ - float dist=prev_point.distance(line[0]); + float dist=abs(prev_point.distance(line[0])); if (dist>SUBDIVIDE){ - //printf("ofxHelios: creating %i join points\n",(int)joindist/SUBDIVIDE); - //dac.SetShutter(device,false); //doesn't do anything - } - for (float j=0;j<dist;j+=SUBDIVIDE){ - float amt=j/dist; - points.push_back(HeliosPoint( - (uint16_t)((prev_point.x*(1.0-amt))+(line[0].x*amt)+xoffs), - (uint16_t)((prev_point.y*(1.0-amt))+(line[0].y*amt)+xoffs), - 0,0,0,255)); //blank point + //draw blanking points if required (only between shapes) + for (float j=0;j<dist;j+=SUBDIVIDE){ + float amt=j/dist; + points.push_back(HeliosPoint( + (uint16_t)(((prev_point.x*(1.0-amt))+(line[0].x*amt)+xoffs)), + (uint16_t)(((prev_point.y*(1.0-amt))+(line[0].y*amt)+yoffs)), + 0,0,0,0)); //blank point + } } - //dac.SetShutter(device,true); //doesn't do anything for (int k=0;k<BLANK_NUM;k++){ points.push_back(HeliosPoint( (uint16_t)(line[0].x+xoffs), @@ -75,47 +69,47 @@ int ofxHelios::draw(vector <colourPolyline> &lines, int intensity){ } int i; for (i=0;i<line.size()-1;i++){ - float dist=prev_point.distance(line[i]); + float dist=abs(ofPoint(line[i]).distance(ofPoint(line[i+1]))); for (float j=0;j<dist;j+=SUBDIVIDE){ + //draw way points float amt=j/dist; points.push_back(HeliosPoint( - (uint16_t)((prev_point.x*(1.0-amt))+(line[i].x*amt)+xoffs), - (uint16_t)((prev_point.y*(1.0-amt))+(line[i].y*amt)+xoffs), - (uint8_t)((((prev_colour.r*(1.0-amt))+(line.getColourAt(i).r*amt))*laserintensity)/255.0), - (uint8_t)((((prev_colour.g*(1.0-amt))+(line.getColourAt(i).g*amt))*laserintensity)/255.0), - (uint8_t)((((prev_colour.b*(1.0-amt))+(line.getColourAt(i).b*amt))*laserintensity)/255.0), + (uint16_t)((line[i].x*(1.0-amt))+(line[i+1].x*amt)+xoffs), + (uint16_t)((line[i].y*(1.0-amt))+(line[i+1].y*amt)+yoffs), + (uint8_t)((((line.getColourAt(i).r*(1.0-amt))+(line.getColourAt(i+1).r*amt))*laserintensity)/255.0), + (uint8_t)((((line.getColourAt(i).g*(1.0-amt))+(line.getColourAt(i+1).g*amt))*laserintensity)/255.0), + (uint8_t)((((line.getColourAt(i).b*(1.0-amt))+(line.getColourAt(i+1).b*amt))*laserintensity)/255.0), (uint8_t)intensity) ); } - points.push_back(HeliosPoint( - (uint16_t)(line[i].x+xoffs), - (uint16_t)(line[i].y+yoffs), - (uint8_t)(((line.getColourAt(i).r)*laserintensity)>>8), - (uint8_t)(((line.getColourAt(i).g)*laserintensity)>>8), - (uint8_t)(((line.getColourAt(i).b)*laserintensity)>>8), - (uint8_t)intensity - )); float angle=line.getDegreesAtIndex(i); - if (angle>MAX_ANGLE){ + if (angle>MAX_ANGLE||(i==line.size()-2)){ + //dwell points to wait on a corner for laser to catch up for (int l=0;l<((angle/180)*BLANK_NUM);l++){ points.push_back(HeliosPoint( - (uint16_t)(line[i].x+xoffs), - (uint16_t)(line[i].y+yoffs), - 0,0,0,0)); //blank point + (uint16_t)(line[i+1].x+xoffs), + (uint16_t)(line[i+1].y+yoffs), + (uint8_t)(line.getColourAt(i+1).r*laserintensity/255.0), + (uint8_t)(line.getColourAt(i+1).g*laserintensity/255.0), + (uint8_t)(line.getColourAt(i+1).b*laserintensity/255.0), + (uint8_t)intensity) + ); } } - prev_point=line[i]; - prev_colour=line.getColourAt(i); + prev_point=line[i+1]; + prev_colour=line.getColourAt(i+1); } - //dac.SetShutter(device,false); //doesn't do anything for (int k=0;k<BLANK_NUM;k++){ points.push_back(HeliosPoint( (uint16_t)(prev_point.x+xoffs), (uint16_t)(prev_point.y+yoffs), - 0,0,0,0)); //blank point + (uint8_t)((prev_colour.r*laserintensity)/255.0), + (uint8_t)((prev_colour.g*laserintensity)/255.0), + (uint8_t)((prev_colour.b*laserintensity)/255.0), + (uint8_t)intensity) + ); } - } diff --git a/ofxHelios/src/ofxHelios.h b/ofxHelios/src/ofxHelios.h index 80044c3..e55e99d 100644 --- a/ofxHelios/src/ofxHelios.h +++ b/ofxHelios/src/ofxHelios.h @@ -15,8 +15,8 @@ #include "colourPolyline.h" #define SUBDIVIDE 20 -#define BLANK_NUM 20 -#define MAX_ANGLE 20.0f +#define BLANK_NUM 4 +#define MAX_ANGLE 15.0f #include <HeliosDac.h> @@ -43,6 +43,7 @@ public: pps=_pps; //dac.SetShutter(device,true); } + prev_point=ofPoint(0x7ff,0x7ff); } ~ofxHelios() @@ -76,6 +77,9 @@ public: HeliosDac dac; int pps; int laserintensity; + + ofPoint prev_point; + ofColor prev_colour; }; diff --git a/polyTest/src/ofApp.h b/polyTest/src/ofApp.h index 121d25f..5d2f07e 100644 --- a/polyTest/src/ofApp.h +++ b/polyTest/src/ofApp.h @@ -29,6 +29,7 @@ class ofApp : public ofBaseApp{ void gotMessage(ofMessage msg); void drawframe(); + void gaussianElimination(float * input, int n); glm::mat4 getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]); ofPolyline polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform); |
