summaryrefslogtreecommitdiff
path: root/drawing
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2018-01-20 01:16:15 +0000
committerTim Redfern <tim@getdrop.com>2018-01-20 01:16:15 +0000
commit05be256f7b2c106101ec990a06e7dbf474ff9dda (patch)
treea8380f98ef27b90ce740cd007f72662b1a12221c /drawing
parentfa21034b7548ab0c1553f57caa6208b90cf28bdf (diff)
correct clipping mask
Diffstat (limited to 'drawing')
-rw-r--r--drawing/bin/data/lorenzo.svg20
-rw-r--r--drawing/src/ofApp.cpp59
2 files changed, 61 insertions, 18 deletions
diff --git a/drawing/bin/data/lorenzo.svg b/drawing/bin/data/lorenzo.svg
index 5adc446..193d208 100644
--- a/drawing/bin/data/lorenzo.svg
+++ b/drawing/bin/data/lorenzo.svg
@@ -50,7 +50,7 @@
showgrid="false"
showguides="false"
inkscape:zoom="0.64916666"
- inkscape:cx="124.17182"
+ inkscape:cx="607.86902"
inkscape:cy="440.28878"
inkscape:window-x="0"
inkscape:window-y="31"
@@ -86,28 +86,28 @@
style="stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1" /><path
id="path10622"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 871.31507,173.98746 c 0,-7.4358 -0.7078,-14.5472 -2.1134,-21.3344 -1.4118,-6.7928 -4.0364,-12.6848 -7.8807,-17.6822 -3.8437,-4.9967 -9.2257,-8.9734 -16.144,-11.9163 -6.9196,-2.9426 -16.0188,-4.4203 -27.2927,-4.4203 -11.2795,0 -20.4388,1.4777 -27.48479,4.4203 -7.05095,2.9429 -12.49232,6.9196 -16.33665,11.9163 -3.84369,4.9974 -6.47462,10.8894 -7.87952,17.6822 -1.41181,6.7872 -2.11466,13.8986 -2.11466,21.3344 l 0,326.879 c 0,7.4295 0.70285,14.5406 2.11466,21.3344 1.4049,6.7862 4.03583,12.6847 7.87952,17.6815 3.84433,4.9977 9.2857,8.9678 16.33665,11.9169 7.04599,2.9429 16.20529,4.4198 27.48479,4.4198 11.2739,0 20.3731,-1.4769 27.2927,-4.4198 6.9183,-2.9491 12.3003,-6.9192 16.144,-11.9169 3.8443,-4.9968 6.4689,-10.8953 7.8807,-17.6815 1.4056,-6.7938 2.1134,-13.9049 2.1134,-21.3344 z m -62.6558,-1.5373 c 0,-4.6135 0.6365,-8.0726 1.9213,-10.3797 1.2797,-2.3061 3.7123,-3.4591 7.3037,-3.4591 5.892,0 8.8414,4.6131 8.8414,13.8388 l 0,329.5693 c 0,9.2256 -2.9494,13.8382 -8.8414,13.8382 -3.5914,0 -6.024,-1.0927 -7.3037,-3.2667 -1.2848,-2.1806 -1.9213,-5.7061 -1.9213,-10.5715 z" /><path
+ d="m 808.65927,502.01946 c 0,4.8654 0.6365,8.3909 1.9213,10.5715 1.2797,2.174 3.7123,3.2667 7.3037,3.2667 5.892,0 8.8414,-4.6126 8.8414,-13.8382 l 0,-329.5693 c 0,-9.2257 -2.9494,-13.8388 -8.8414,-13.8388 -3.5914,0 -6.024,1.153 -7.3037,3.4591 -1.2848,2.3071 -1.9213,5.7662 -1.9213,10.3797 z m 62.6558,-1.153 c 0,7.4295 -0.7078,14.5406 -2.1134,21.3344 -1.4118,6.7862 -4.0364,12.6847 -7.8807,17.6815 -3.8437,4.9977 -9.2257,8.9678 -16.144,11.9169 -6.9196,2.9429 -16.0188,4.4198 -27.2927,4.4198 -11.2795,0 -20.4388,-1.4769 -27.48479,-4.4198 -7.05095,-2.9491 -12.49232,-6.9192 -16.33665,-11.9169 -3.84369,-4.9968 -6.47462,-10.8953 -7.87952,-17.6815 -1.41181,-6.7938 -2.11466,-13.9049 -2.11466,-21.3344 l 0,-326.879 c 0,-7.4358 0.70285,-14.5472 2.11466,-21.3344 1.4049,-6.7928 4.03583,-12.6848 7.87952,-17.6822 3.84433,-4.9967 9.2857,-8.9734 16.33665,-11.9163 7.04599,-2.9426 16.20529,-4.4203 27.48479,-4.4203 11.2739,0 20.3731,1.4777 27.2927,4.4203 6.9183,2.9429 12.3003,6.9196 16.144,11.9163 3.8443,4.9974 6.4689,10.8894 7.8807,17.6822 1.4056,6.7872 2.1134,13.8986 2.1134,21.3344 z" /><path
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 589.6808,556.21906 0,-237.84871 -32.44094,237.84871 -44.59063,0 0,-437.45188 44.59063,0 0,212.45 32.39445,-212.45 0.0465,0.0114 0,-0.0114 44.59,0 0,437.45188 z"
+ d="m 634.27081,556.21906 0,-437.45188 -44.59,0 0,0.0114 -0.0465,-0.0114 -32.39445,212.45 0,-212.45 -44.59063,0 0,437.45188 44.59063,0 32.44094,-237.84871 0,237.84871 z"
id="path10620" /><path
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 750.61884,556.21906 0,-40.3614 -59.19696,-356.72908 59.19696,0 0,-40.3614 -106.86212,0 0,35.36403 60.35032,361.72645 -56.12172,0 0,40.3614 z"
+ d="m 647.98532,556.21906 0,-40.3614 56.12172,0 -60.35032,-361.72645 0,-35.36403 106.86212,0 0,40.3614 -59.19696,0 59.19696,356.72908 0,40.3614 z"
id="path10618" /><path
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 403.6304,556.21906 96.48375,0 0,-40.3614 -51.89375,0 0,-158.77912 49.97186,0 0,-40.36235 -49.97186,0 0,-157.58761 51.89375,0 0,-40.3614 -96.48375,0 z"
+ d="m 403.6304,118.76718 96.48375,0 0,40.3614 -51.89375,0 0,157.58761 49.97186,0 0,40.36235 -49.97186,0 0,158.77912 51.89375,0 0,40.3614 -96.48375,0 z"
id="path10616" /><path
id="path10612"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 319.8324,376.35041 9.22565,0 c 5.89196,0 8.84012,4.61311 8.84012,13.83876 l 0,111.83038 c 0,9.22501 -2.94816,13.83812 -8.84012,13.83812 l -9.22565,0 z m 0,-257.58323 -44.59063,0 0,437.45188 53.81628,0 c 11.27264,0 20.37311,-1.47685 27.29142,-4.42033 6.91957,-2.94943 12.30145,-6.91958 16.14459,-11.91631 3.8437,-4.99737 6.46899,-10.89528 7.88072,-17.68253 1.40562,-6.79273 2.11402,-13.90476 2.11402,-21.33402 l 0,-109.1394 c 0,-6.15041 -0.25782,-11.14722 -0.76909,-14.99179 -0.51627,-3.84378 -1.47749,-7.05062 -2.88311,-9.60992 -1.41054,-2.56484 -3.26674,-4.67854 -5.57345,-6.34254 -2.30608,-1.66962 -5.12906,-3.14092 -8.45712,-4.42041 3.32806,-1.79544 6.15104,-3.59143 8.45712,-5.38132 2.30671,-1.79599 4.16291,-3.97665 5.57345,-6.53499 1.40562,-2.56484 2.36684,-5.70569 2.88311,-9.41715 0.51127,-3.7182 0.76909,-8.3973 0.76909,-14.03152 l 0,-202.22965 -44.59063,0 0,203.38364 c 0,8.45593 -2.56389,13.06903 -7.68676,13.83788 l -10.37901,0 z" /><path
+ d="m 319.8324,335.9887 10.37901,0 c 5.12287,-0.76885 7.68676,-5.38195 7.68676,-13.83788 l 0,-203.38364 44.59063,0 0,202.22965 c 0,5.63422 -0.25782,10.31332 -0.76909,14.03152 -0.51627,3.71146 -1.47749,6.85231 -2.88311,9.41715 -1.41054,2.55834 -3.26674,4.739 -5.57345,6.53499 -2.30608,1.78989 -5.12906,3.58588 -8.45712,5.38132 3.32806,1.27949 6.15104,2.75079 8.45712,4.42041 2.30671,1.664 4.16291,3.7777 5.57345,6.34254 1.40562,2.5593 2.36684,5.76614 2.88311,9.60992 0.51127,3.84457 0.76909,8.84138 0.76909,14.99179 l 0,109.1394 c 0,7.42926 -0.7084,14.54129 -2.11402,21.33402 -1.41173,6.78725 -4.03702,12.68516 -7.88072,17.68253 -3.84314,4.99673 -9.22502,8.96688 -16.14459,11.91631 -6.91831,2.94348 -16.01878,4.42033 -27.29142,4.42033 l -53.81628,0 0,-437.45188 44.59063,0 z m 0,179.86897 9.22565,0 c 5.89196,0 8.84012,-4.61311 8.84012,-13.83812 l 0,-111.83038 c 0,-9.22565 -2.94816,-13.83876 -8.84012,-13.83876 l -9.22565,0 z" /><path
id="path10608"
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 191.44564,172.45017 c 0,-4.61342 0.63653,-8.07261 1.92189,-10.37964 1.27917,-2.30608 3.71169,-3.45911 7.30313,-3.45911 5.89203,0 8.84201,4.6131 8.84201,13.83875 l 0,329.56935 c 0,9.22565 -2.94998,13.8382 -8.84201,13.8382 -3.59144,0 -6.02396,-1.09267 -7.30313,-3.26674 -1.28536,-2.18058 -1.92189,-5.70609 -1.92189,-10.57146 z m 62.6564,1.5373 c 0,-7.43576 -0.70841,-14.54715 -2.11395,-21.33433 -1.4118,-6.79281 -4.03583,-12.68484 -7.88079,-17.68221 -3.8437,-4.99674 -9.22565,-8.97339 -16.14396,-11.91631 -6.91957,-2.94261 -16.01878,-4.42033 -27.29268,-4.42033 -11.27947,0 -20.4388,1.47772 -27.48419,4.42033 -7.05094,2.94292 -12.49294,6.91957 -16.33664,11.91631 -3.84433,4.99737 -6.47518,10.8894 -7.88016,17.68221 -1.41181,6.78718 -2.11466,13.89857 -2.11466,21.33433 l 0,326.87902 c 0,7.42957 0.70285,14.54065 2.11466,21.33441 1.40498,6.78622 4.03583,12.68476 7.88016,17.68149 3.8437,4.99769 9.2857,8.96784 16.33664,11.91695 7.04539,2.94284 16.20472,4.41978 27.48419,4.41978 11.2739,0 20.37311,-1.47694 27.29268,-4.41978 6.91831,-2.94911 12.30026,-6.91926 16.14396,-11.91695 3.84496,-4.99673 6.46899,-10.89527 7.88079,-17.68149 1.40554,-6.79376 2.11395,-13.90484 2.11395,-21.33441 z" /><path
+ d="m 254.10204,500.86649 c 0,7.42957 -0.70841,14.54065 -2.11395,21.33441 -1.4118,6.78622 -4.03583,12.68476 -7.88079,17.68149 -3.8437,4.99769 -9.22565,8.96784 -16.14396,11.91695 -6.91957,2.94284 -16.01878,4.41978 -27.29268,4.41978 -11.27947,0 -20.4388,-1.47694 -27.48419,-4.41978 -7.05094,-2.94911 -12.49294,-6.91926 -16.33664,-11.91695 -3.84433,-4.99673 -6.47518,-10.89527 -7.88016,-17.68149 -1.41181,-6.79376 -2.11466,-13.90484 -2.11466,-21.33441 l 0,-326.87902 c 0,-7.43576 0.70285,-14.54715 2.11466,-21.33433 1.40498,-6.79281 4.03583,-12.68484 7.88016,-17.68221 3.8437,-4.99674 9.2857,-8.97339 16.33664,-11.91631 7.04539,-2.94261 16.20472,-4.42033 27.48419,-4.42033 11.2739,0 20.37311,1.47772 27.29268,4.42033 6.91831,2.94292 12.30026,6.91957 16.14396,11.91631 3.84496,4.99737 6.46899,10.8894 7.88079,17.68221 1.40554,6.78718 2.11395,13.89857 2.11395,21.33433 z m -62.6564,1.15303 c 0,4.86537 0.63653,8.39088 1.92189,10.57146 1.27917,2.17407 3.71169,3.26674 7.30313,3.26674 5.89203,0 8.84201,-4.61255 8.84201,-13.8382 l 0,-329.56935 c 0,-9.22565 -2.94998,-13.83875 -8.84201,-13.83875 -3.59144,0 -6.02396,1.15303 -7.30313,3.45911 -1.28536,2.30703 -1.92189,5.76622 -1.92189,10.37964 z" /><path
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 32.306768,556.21906 44.59063,0 0,-397.09048 56.506542,0 0,-40.3614 -101.097172,0 z"
+ d="m 32.306768,118.76718 101.097172,0 0,40.3614 -56.506542,0 0,397.09048 -44.59063,0 z"
id="path10606" /><path
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 879.28447,66.65956 -854.946552,0 0,44.59 854.946552,0 z"
+ d="m 879.28447,111.24956 -854.946552,0 0,-44.59 854.946552,0 z"
id="path10604" /><path
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:0.07932836;stroke-opacity:1"
- d="m 879.28447,563.73626 -854.946552,0 0,44.5904 854.946552,0 z"
+ d="m 879.28447,608.32666 -854.946552,0 0,-44.5904 854.946552,0 z"
id="path3852" /></g></svg> \ No newline at end of file
diff --git a/drawing/src/ofApp.cpp b/drawing/src/ofApp.cpp
index 89b7b97..28bca20 100644
--- a/drawing/src/ofApp.cpp
+++ b/drawing/src/ofApp.cpp
@@ -2,6 +2,8 @@
#include "glew.h"
+vector<std::string> cmdnames={"moveTo","lineTo","curveTo","bezierTo","quadBezierTo","arc","arcNegative","close"};
+
//--------------------------------------------------------------
void ofApp::setup(){
ofxSVG svg;
@@ -17,13 +19,30 @@ void ofApp::setup(){
cout << "Drawing: found " << paths.size() << " paths with " << segmenters.size() << " shapes" <<std::endl;
- svg.load("shapes.svg");
+ svg.load("lorenzo.svg");
paths= svg.getPaths();
- for (int i=0;i<paths.size();i++){
- vector <ofPolyline> outlines= paths[i].getOutline();
- for (int j=0;j<outlines.size();j++){
- mask.push_back(outlines[j]);
+
+ for (auto& path:paths){
+ //paths[i].setMode(ofPath::COMMANDS);
+ path.setPolyWindingMode(OF_POLY_WINDING_ODD);
+
+ vector <ofPolyline> outlines= path.getOutline();
+ for (auto& outline:outlines){
+ mask.push_back(outline);
+ }
+ /*
+ vector<ofPath::Command> cmds=paths[i].getCommands();
+
+ std::stringstream strm;
+ strm << "Mask: found " << cmds.size() << " commands (";
+ for (auto& cmd:cmds){
+ strm << cmdnames[cmd.type] <<",";
}
+
+ strm << ")" << std::endl;
+ cout << strm.str();
+ */
+
}
cout << "Mask: found " << paths.size() << " paths with " << mask.size() << " shapes" <<std::endl;
@@ -78,14 +97,33 @@ void ofApp::draw(){
}
clipper.addPolylines(shapes,ClipperLib::ptSubject);
vector<ofPolyline> clipped = clipper.getClippedLines(ClipperLib::ctIntersection);
- segmentsdrawn=clipped.size();
for (auto& clip: clipped)
{
clip.draw();
+ segmentsdrawn++;
pointsdrawn+=clip.size();
}
+ break;
}
case 2:{
+ vector <ofPolyline> shapes;
+ 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++){
+ shapes.push_back(*segment);
+ }
+ }
+ clipper.addPolylines(shapes,ClipperLib::ptSubject);
+ vector<ofPolyline> clipped = clipper.getClippedLines(ClipperLib::ctDifference);
+ for (auto& clip: clipped)
+ {
+ clip.draw();
+ segmentsdrawn++;
+ pointsdrawn+=clip.size();
+ }
+ break;
+ }
+ case 3:{
int w=ofRandom(1000);
segmenters[w%segmenters.size()].draw();
segmentsdrawn=1;
@@ -93,7 +131,12 @@ void ofApp::draw(){
break;
}
}
-
+ /*
+ ofxSVG svg;
+ svg.load("lorenzos.svg");
+ vector <ofPath> paths= svg.getPaths();
+ for (auto& l:paths) l.draw();
+ */
std::stringstream strm;
@@ -141,7 +184,7 @@ void ofApp::keyReleased(int key){
break;
}
case 'p':{
- mode=(mode+1)%3;
+ mode=(mode+1)%4;
break;
}
}