示例#1
0
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;
}
示例#2
0
//----------------------------------------------------------
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);
	}
}
示例#3
0
//----------------------------------------------------------
void ofGLRenderer::draw(const ofPath & shape) const{
	ofColor prevColor;
	if(shape.getUseShapeColor()){
		prevColor = ofGetStyle().color;
	}
	ofGLRenderer * mut_this = const_cast<ofGLRenderer*>(this);
	if(shape.isFilled()){
		const ofMesh & mesh = shape.getTessellation();
		if(shape.getUseShapeColor()){
			mut_this->setColor( shape.getFillColor(),shape.getFillColor().a);
		}
		draw(mesh,OF_MESH_FILL);
	}
	if(shape.hasOutline()){
		float lineWidth = ofGetStyle().lineWidth;
		if(shape.getUseShapeColor()){
			mut_this->setColor( shape.getStrokeColor(), shape.getStrokeColor().a);
		}
		mut_this->setLineWidth( shape.getStrokeWidth() );
		const vector<ofPolyline> & outlines = shape.getOutline();
		for(int i=0; i<(int)outlines.size(); i++)
			draw(outlines[i]);
		mut_this->setLineWidth(lineWidth);
	}
	if(shape.getUseShapeColor()){
		mut_this->setColor(prevColor);
	}
}
示例#4
0
bool Clipper::addPath(const ofPath& paths,
                      ClipperLib::PolyType PolyTyp,
                      bool autoClose,
                      ClipperLib::cInt scale)
{
    return addPolylines(paths.getOutline(), PolyTyp, autoClose, scale);
}
示例#5
0
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();
}
//--------------------------------------------------------------
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;
}
示例#7
0
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;
}
//--------------------------------------------------------------
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;
}
示例#9
0
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
void ofxClipper::ofPath_to_Polygons(ofPath& path,ClipperLib::Polygons& polygons) {
    return ofxPolylines_to_Polygons(path.getOutline(),polygons);
}
示例#10
0
ClipperLib::Paths Clipper::toClipper(const ofPath& path, ClipperLib::cInt scale)
{
    return toClipper(path.getOutline(), scale);
}