void pathFactory::mousePointerStraight(ofPath &p, float x_dim, float y_dim, float t_size){ vector<ofPoint> tpoints; float tw = 0.3; float sw = 0.074; float cl = 1; float al = 0.74; float bl = 0.55; tpoints.push_back(ofPoint(0,0)); tpoints.push_back(ofPoint(-tw,al));//a1 tpoints.push_back(ofPoint(-sw,bl)); // b1 tpoints.push_back(ofPoint(-sw,cl)); //c1 tpoints.push_back(ofPoint(sw,cl));//c2 tpoints.push_back(ofPoint(sw,bl)); // b2 tpoints.push_back(ofPoint(tw,al)); //a2 tpoints.push_back(ofPoint(0,0)); for(int i = 0; i < tpoints.size(); i++){ tpoints[i] *= ofVec2f(x_dim, y_dim); tpoints[i] *= t_size; p.lineTo(tpoints[i]); } p.close(); }
void ShapeContentRect::push(ofPath& path) { vector<ofPath::Command>& command = path.getCommands(); int command_count_prev = command.size(); path.rectRounded(pos_-size_/2.f, size_.x, size_.y, roundness_); command_count_ = command.size() - command_count_prev; }
// Temporary fix until OF 0.8.0 static void rectangle(ofPath & path, const ofRectangle & r){ path.moveTo(r.getTopLeft()); path.lineTo(r.getTopRight()); path.lineTo(r.getBottomRight()); path.lineTo(r.getBottomLeft()); path.close(); }
void ShapeContentEllipse::push(ofPath& path) { vector<ofPath::Command>& command = path.getCommands(); int command_count_prev = command.size(); path.ellipse(pos_.x, pos_.y, size_.x, size_.y); path.close(); command_count_ = command.size() - command_count_prev; }
ofRectangle ofxGetBoundingBox(ofPath &path) { ofRectangle rect; for (int i=0; i<path.getOutline().size(); i++) { ofRectangle b = path.getOutline().at(i).getBoundingBox(); if (i==0) rect = b; else rect.growToInclude(b); } return rect; }
void ofPath::append(const ofPath & path){ if(mode==COMMANDS){ for(auto & command: path.getCommands()){ addCommand(command); } }else{ for(auto & poly: path.getOutline()){ polylines.push_back(poly); } } flagShapeChanged(); }
void ShapeContentFill::pop(ofPath& path) { ofPushStyle(); path.setFilled(true); ofColor prev = path.getFillColor(); float opacity = prev.a/255.f*opacity_; path.setFillColor(ofColor(color_, opacity*255)); ofEnableBlendMode(blend_mode_); path.draw(); path.setFillColor(prev); ofPopStyle(); }
void handlePathDrawStyle(ofPath& p) { p.setFilled(m_hasFill); p.setFillColor(m_fillColor); p.setStrokeColor(m_strokeColor); if( m_hasStroke ) { p.setStrokeWidth(m_strokeWeight); } else { p.setStrokeWidth(0); } }
void ofSetCurrentRenderer(ofPtr<ofBaseRenderer> renderer_){ renderer = renderer_; renderer->setupGraphicDefaults(); if(renderer->rendersPathPrimitives()){ shape.setMode(ofPath::PATHS); }else{ shape.setMode(ofPath::POLYLINES); } shape.setUseShapeColor(false); ofSetStyle(currentStyle); }
void ofxSimplifyPath(ofPath &path, int iterations, float amount) { for (int iteration=0; iteration<iterations; iteration++) { vector<ofSubPath> &subpaths = path.getSubPaths(); for (int i=0; i<subpaths.size(); i++) { vector<ofSubPath::Command> &commands = subpaths[i].getCommands(); if (commands.size()<amount) continue; for (int j=0; j<commands.size()-1; j++) { if (commands[j].to.distance(commands[j+1].to)<3) { commands[j].to = (commands[j].to+commands[j+1].to)/2; commands.erase(commands.begin()+j+1); } } } } path.flagShapeChanged(); }
void pathFactory::roundedRect(ofPath &p, float x_dim, float y_dim, float t_size){ ofRectangle r; r.setFromCenter(0,0, x_dim * t_size, y_dim * t_size); p.rectRounded(r, t_size/10); }
void ofSetCurrentRenderer(ofPtr<ofBaseRenderer> renderer_,bool setDefaults){ renderer = renderer_; if(renderer->rendersPathPrimitives()){ shape.setMode(ofPath::COMMANDS); }else{ shape.setMode(ofPath::POLYLINES); } shape.setUseShapeColor(false); if(setDefaults){ renderer->setupGraphicDefaults(); ofSetStyle(currentStyle); ofBackground(currentStyle.bgColor); } }
bool Clipper::addPath(const ofPath& paths, ClipperLib::PolyType PolyTyp, bool autoClose, ClipperLib::cInt scale) { return addPolylines(paths.getOutline(), PolyTyp, autoClose, scale); }
void ofxSimplifyPath(ofPath &path, int iterations, float amount, float distance) { //wat doet amount?? should be distance??? for (int iteration=0; iteration<iterations; iteration++) { vector<ofSubPath> &subpaths = path.getSubPaths(); for (int i=0; i<subpaths.size(); i++) { vector<ofSubPath::Command> &commands = subpaths[i].getCommands(); if (commands.size()<amount) continue; for (int j=1; j<commands.size()-2; j++) { //laat eerste en laatste punt met rust if (commands[j].to.distance(commands[j+1].to)<distance) { commands[j].to = (commands[j].to+commands[j+1].to)/2; commands.erase(commands.begin()+j+1); } } } } path.flagShapeChanged(); }
void ShapeContentShape::pop(ofPath& path) { vector<ofPath::Command>& command = path.getCommands(); while(command_count_-- > 0) { command.pop_back(); } }
void ShapeContentPoly::push(ofPath& path) { vector<ofPath::Command>& command = path.getCommands(); int command_count_prev = command.size(); command_count_ = command.size() - command_count_prev; }
void draw(){ path.draw(); path2.draw(); ofPushMatrix(); ofTranslate(300, 0); for ( auto p : unioned ) { p.draw(); } ofPopMatrix(); ofPushMatrix(); ofTranslate(600, 0); for ( auto p : diffed ) { p.draw(); } ofPopMatrix(); }
void ShapeContentPath::push(ofPath& path) { vector<ofPath::Command>& command = path.getCommands(); int command_count_prev = command.size(); vector<ofPath::Command>& my_command = path_.getCommands(); for(vector<ofPath::Command>::iterator it = my_command.begin(); it != my_command.end(); ++it) { command.push_back(*it); } command_count_ = command.size() - command_count_prev; }
void Svg::setupShape(struct svgtiny_shape * shape, ofPath & path){ float* p = shape->path; path.setFilled(false); if(shape->fill != svgtiny_TRANSPARENT){ path.setFilled(true); path.setFillHexColor(shape->fill); path.setPolyWindingMode(OF_POLY_WINDING_NONZERO); } if(shape->stroke != svgtiny_TRANSPARENT){ path.setStrokeWidth(shape->stroke_width); path.setStrokeHexColor(shape->stroke); } for(int i = 0; i < (int)shape->path_length;){ if(p[i] == svgtiny_PATH_MOVE){ path.moveTo(p[i + 1], p[i + 2]); i += 3; } else if(p[i] == svgtiny_PATH_CLOSE){ path.close(); i += 1; } else if(p[i] == svgtiny_PATH_LINE){ path.lineTo(p[i + 1], p[i + 2]); i += 3; } else if(p[i] == svgtiny_PATH_BEZIER){ path.bezierTo(p[i + 1], p[i + 2], p[i + 3], p[i + 4], p[i + 5], p[i + 6]); i += 7; } else{ ofLogError("Svg") << "setupShape(): SVG parse error"; i += 1; } } }
void drawBranch(float x, float y, float radius, int level) { path.clear(); path.setStrokeColor(ofColor::blueSteel); path.setStrokeWidth(level*2); path.arc(x,y, radius,radius, -180, 0); path.draw(); ofFill(); ofSetColor(56); ofCircle(x, y, level*3); if (level > 0 ){ drawBranch(x-radius, y+radius/2, radius/2, level-1); drawBranch(x+radius, y+radius/2, radius/2, level-1); } // return drawBranch(x, y, radius, level); }
vector<ofPoint*> ofxGetPointsFromPath(ofPath &path) { vector<ofPoint*> points; vector<ofSubPath> &subpaths = path.getSubPaths(); for (int i=0; i<subpaths.size(); i++) { vector<ofSubPath::Command> &commands = subpaths[i].getCommands(); for (int j=0; j<commands.size(); j++) { points.push_back(&commands[j].to); } } return points; }
void keyPressed(int key) { switch (key) { case '/': case '\\': case '$': case '#': case '|': case '%': case '@': case '^': case '&': case '_': side.setShape(key); break; case '3': side.is3D=!side.is3D; break; case '<': twists-=.5; break; case '>': twists+=.5; break; case '\'': twists=0; break; case '?': showHelp(); break; case 'a': side.toggle(); break; case 'b': useSubpathColors=!useSubpathColors; break; case 'C': canvas.createCircle(); break; case 'c': canvas.clear(); files.unloadFile(); break; case 'd': debug=!debug; refreshDebugInfo(); break; case 'e': print(true); break; case 'f': ofToggleFullscreen(); break; case 'k': path.setFilled(!path.isFilled()); path.flagShapeChanged(); break; case 'h': objectHeight+=5; if (objectHeight>maxObjectHeight) objectHeight=maxObjectHeight; break; case 'H': objectHeight-=5; if (objectHeight<3) objectHeight=3; break; case 'G': ultimaker.sendCommand("G28 X0 Y0 Z0\nM84",2); break; case 'A': ultimaker.sendCommand("M84"); break; case 'T': ultimaker.sendCommand("M109 S230"); break; case 'l': files.loadNext(); break; case 'L': files.loadPrevious(); break; case 'o': files.load(); break; case 'p': case 'm': case OF_KEY_RETURN: print(); break; case 'q': stop(); break; // case 'r': ultimaker.setRelative(); break; case 'S': files.save(); break; case 's': files.saveAs(); break; case '`': showSubPathLines=!showSubPathLines; case 't': ultimaker.sendCommand("M105",1); break; case 'u': case 'z': canvas.undo(); break; case '~': files.deleteCurrentFile(); break; case ' ': files.listDir(); break; case 'x': files.saveSvg(resourceFolder+"template.svg",documentFolder+"output.svg"); break; case 27: if (ultimaker.isThreadRunning()) ultimaker.stopThread(); break; case 'n': cloneApp(); break; //run new instance of Doodle3D case 'i': cout << getNumInstances() << endl; break; } }
//-------------------------------------------------------------- ofMesh ofApp::createMeshFromPath(ofPath path, float thickness){ ofMesh mesh; // get outline of original path (for sides) vector <ofPolyline> outline = path.getOutline(); // add front to mesh mesh.append(path.getTessellation()); // get number of vertices in original path int numVerts = mesh.getNumVertices(); // define offset based on thickness ofVec3f offset = ofVec3f(0, 0, -thickness); // translate path path.translate(offset); // add back to mesh mesh.append(path.getTessellation()); // add sides to mesh (via indices) for(int j = 0; j < outline.size(); j++){ int outlineSize = outline[j].getVertices().size(); vector <int> outlineIndices; for(int i = 1; i < outlineSize; i++){ ofVec3f & v = outline[j].getVertices()[i]; int originalIndex = -1; for(int k = 0; k < numVerts; k++){ if(v.match(mesh.getVertices()[k])){ originalIndex = k; break; } } outlineIndices.push_back(originalIndex); } for(int i = 0; i < outlineIndices.size(); i++){ const int a = outlineIndices[i]; const int b = outlineIndices[(i + 1) % outlineIndices.size()]; const int c = outlineIndices[i] + numVerts; const int d = outlineIndices[(i + 1) % outlineIndices.size()] + numVerts; mesh.addTriangle(a, b, c); mesh.addTriangle(c, b, d); } } return mesh; }
vector<ofPolyline> ofxGetPolylinesFromPath(ofPath path) { vector<ofPolyline> polylines; vector<ofSubPath> &subpaths = path.getSubPaths(); for (int i=0; i<subpaths.size(); i++) { ofPolyline poly; vector<ofSubPath::Command> &commands = subpaths[i].getCommands(); for (int j=0; j<commands.size()-1; j++) { poly.addVertex(commands[i].to); } polylines.push_back(poly); } return polylines; }
//-------------------------------------------------------------- ofPath ofApp::resamplePath(ofPath path, float spacing){ ofPath resampledPath; vector <ofPolyline> polylines = path.getOutline(); for(int j = 0; j < polylines.size(); j++){ ofPolyline spacePoly = polylines[j].getResampledBySpacing(spacing); resampledPath.moveTo(spacePoly[0]); for(int k = 1; k < spacePoly.size(); k++){ resampledPath.lineTo(spacePoly[k]); } resampledPath.lineTo(spacePoly[0]); } return resampledPath; }
// ----------------------------------- void Letter::setup(ofPath letter, float depth) { // Tessellation is subdividing a concave polygon into convex polygons. front = letter.getTessellation(); back = front; // Loop through all of the vertices in the "back" mesh // and move them back in on the "z" axis vector<ofPoint>& f = front.getVertices(); vector<ofPoint>& b = back.getVertices(); for(int j=0; j< f.size(); j++) { f[j].z += depth/2.0; b[j].z -= depth/2.0; } }
void ShapeContentStroke::pop(ofPath& path) { ofPushStyle(); path.setFilled(false); ofColor prev = path.getStrokeColor(); float opacity = prev.a/255.f*opacity_; path.setStrokeColor(ofColor(color_, opacity*255)); path.setStrokeWidth(stroke_width_); ofEnableBlendMode(blend_mode_); path.draw(); path.setStrokeColor(prev); ofPopStyle(); }
bool ofxEpilog::send(ofPath path) { // // TODO([email protected]): test again and finish implementation // if (!tcp_client.isConnected()) { return false; } ofBuffer buffer; vector<ofPolyline> line = path.getOutline(); for (int i=0; i<line.size(); i++) { if(!send(line[i])) return false; } return true; }
void ShapeContentGroup::pop(ofPath& path) { if(transform_.isDirty()) { transform_.refreshMatrix(); } transform_.pushMatrix(); ofColor prev_st = path.getStrokeColor(); ofColor prev_fi = path.getFillColor(); float opacity_st = prev_st.a/255.f*opacity_; float opacity_fi = prev_fi.a/255.f*opacity_; path.setStrokeColor(ofColor(prev_st, opacity_st*255)); path.setFillColor(ofColor(prev_fi, opacity_fi*255)); for(vector<ShapeContent*>::reverse_iterator it = content_.rbegin(); it != content_.rend(); ++it) { (*it)->pop(path); } path.setStrokeColor(prev_st); path.setFillColor(prev_fi); transform_.popMatrix(); }
//---------------------------------------------------------- void ofGLRenderer::draw(ofPath & shape){ ofColor prevColor; if(shape.getUseShapeColor()){ prevColor = ofGetStyle().color; } if(shape.isFilled()){ ofMesh & mesh = shape.getTessellation(); if(shape.getUseShapeColor()){ setColor( shape.getFillColor() * ofGetStyle().color,shape.getFillColor().a/255. * ofGetStyle().color.a); } draw(mesh); } if(shape.hasOutline()){ float lineWidth = ofGetStyle().lineWidth; if(shape.getUseShapeColor()){ setColor( shape.getStrokeColor() * ofGetStyle().color, shape.getStrokeColor().a/255. * ofGetStyle().color.a); } setLineWidth( shape.getStrokeWidth() ); vector<ofPolyline> & outlines = shape.getOutline(); for(int i=0; i<(int)outlines.size(); i++) draw(outlines[i]); setLineWidth(lineWidth); } if(shape.getUseShapeColor()){ setColor(prevColor); } }