diff options
| author | Tim Redfern <tim@getdrop.com> | 2023-04-18 17:41:57 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2023-04-18 17:41:57 +0100 |
| commit | 3b89e73c157f0eef8a3479b613491c8343f9c43b (patch) | |
| tree | f0235fb52633c9889823eb4a0310d97d0cffee0a /nextus/src/ofApp.h | |
| parent | ef6ea2258969c8a1ceacf10e08085cc55ccae448 (diff) | |
loads SVGs
Diffstat (limited to 'nextus/src/ofApp.h')
| -rw-r--r-- | nextus/src/ofApp.h | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/nextus/src/ofApp.h b/nextus/src/ofApp.h index 352c6ca..a484129 100644 --- a/nextus/src/ofApp.h +++ b/nextus/src/ofApp.h @@ -36,11 +36,15 @@ class vectorPanel { panel.draw(); ofPushMatrix(); ofTranslate(size/2); - drawcontent(); + ofScale(DISPLAYSIZE.x/2.0f); + vector<colourPolyline> lines=getLines(); + for (auto& line:lines){ + line.draw(); + } ofPopMatrix(); ofPopMatrix(); } - virtual void drawcontent() {};; + virtual vector<colourPolyline> getLines() {}; private: ofVec2f size; @@ -56,16 +60,29 @@ class svgPanel: public vectorPanel{ ofVec2f _pos=ofPoint(5,5) ) : vectorPanel(_title,_size,_pos){} void load(string filename){ - ofLog()<<"loading SVG "<<filename; - + ofxSVG svg; svg.load(filename); //normalise the SVG paths to a square format - float scale=max(svg.getWidth(),svg.getHeight()); + float dimension=max(svg.getWidth(),svg.getHeight()); + + glm::vec2 src[]={ + glm::vec2(0,0), + glm::vec2(dimension,0), + glm::vec2(dimension,dimension), + glm::vec2(0,dimension) + }; - ofMatrix4x4 xform; + glm::vec2 dst[]={ //PONK coords + glm::vec2(-1,-1), + glm::vec2(1,-1), + glm::vec2(1,1), + glm::vec2(-1,1) + }; + + ofMatrix4x4 xform=lineTransformer::getPerspectiveTransformMatrix(src,dst); vector <ofPath> imagepaths= svg.getPaths(); @@ -82,7 +99,19 @@ class svgPanel: public vectorPanel{ //strm << outline.size() << "->"; //outline.simplify(contour_simplify); //strm << outline.size() << " "; - segmenters.push_back(colourLineSegmenter(outline,path.getStrokeColor())); + ofPolyline xformed=lineTransformer::polyLineTransform(xform,outline); + ofColor c1=path.getStrokeColor(); + ofColor colour=path.getFillColor(); + if (colour.r==colour.g&&colour.g==colour.b){ + colour=c1; + } + + segmenters.push_back( + colourLineSegmenter( + xformed, + path.getStrokeColor() + ) + ); //shape_selection_durations.push_back(0.0f); } @@ -105,12 +134,20 @@ class svgPanel: public vectorPanel{ //cout << "SVG: selected paths [ "<<strom.str() << " ]" <<std::endl; //cout << "SVG: found " << imagepaths.size() << " paths with " << segmenters.size() << " shapes [ " << strm.str() << " ]" <<std::endl; //select_random_shapes(shapes_duration); + ofLog()<<"loaded SVG "<<filename<<", "<<segmenters.size()<<" paths"; + + } + else { + ofLog()<<"could not load SVG "<<filename; } } - void drawcontent(){ - for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ - shape->getPoly().draw(); + vector<colourPolyline> getLines(){ + vector<colourPolyline> output; + for (auto& shape:segmenters){ + output.push_back(shape.getPoly()); } + //ofLog()<<"svg found "<<output.size()<<" lines"; + return output; } private: |
