コード例 #1
0
//-----------------------------------------------------------------------------------
void ofxCairoTexture::draw(ofPolyline & poly){
	cairo_new_path(cr);
	for(int i=0;i<(int)poly.size();i++){
		cairo_line_to(cr,poly.getVertices()[i].x,poly.getVertices()[i].y);
	}
	if(poly.isClosed())
		cairo_close_path(cr);
	cairo_stroke( cr );
}
コード例 #2
0
void ofCairoRenderer::draw(const ofPolyline & poly) const{
	cairo_new_path(cr);
	for(int i=0;i<(int)poly.size();i++){
		cairo_line_to(cr,poly.getVertices()[i].x,poly.getVertices()[i].y);
	}
	if(poly.isClosed())
		cairo_close_path(cr);
	cairo_stroke( cr );
}
コード例 #3
0
void ofCairoRenderer::draw(ofPolyline & poly){
	ofPushStyle();
	cairo_new_path(cr);
	for(int i=0;i<(int)poly.size();i++){
		cairo_line_to(cr,poly.getVertices()[i].x,poly.getVertices()[i].y);
	}
	if(poly.isClosed())
		cairo_close_path(cr);
	ofPopStyle();
}
コード例 #4
0
void testApp::interpolatePolyLine(ofPolyline& a, ofPolyline& b, ofPolyline& out, float delta){
    if(a.getVertices().size() != b.getVertices().size()){
        ofLogError("Polylines did not match in size");
        return;
    }
    
    out.clear();
    
    for(int i = 0; i < a.getVertices().size(); i++){
        out.addVertex( a.getVertices()[i].getInterpolated(b.getVertices()[i], delta) );
    }
}
コード例 #5
0
ファイル: ropeMesh.cpp プロジェクト: bestpaul1985/Thesis2013
void ropeMesh::draw(ofPolyline stroke){

    if (stroke.hasChanged()) {
        
        mesh.clear();
        
        mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
        
        vector < ofPoint > pts = stroke.getVertices();
        
        for (int i = 0; i < pts.size(); i++){
            
            int i_m_1 = MAX(i-1,0);
            int i_p_1 = MIN(i+1, pts.size()-1);
            
            ofPoint pta = pts[i_m_1];
            ofPoint ptb = pts[i];
            ofPoint ptc = pts[i_p_1];
            
            ofPoint diff = ptc - pta;
            
            float angle = atan2(diff.y, diff.x);
            
            angle += PI/2;
            
            float width = 3; //diff.length();
            
            ofPoint offsetA;
            offsetA.x = ptb.x + width * cos(angle);
            offsetA.y = ptb.y + width * sin(angle);
            
            ofPoint offsetB;
            offsetB.x = ptb.x - width * cos(angle);
            offsetB.y = ptb.y - width * sin(angle);
            
            ofSetColor(123,94,65);
          
            ofLine(offsetA, offsetB);
            
            mesh.addVertex(offsetA);
            mesh.addVertex(offsetB);
        }
    
        ofSetColor(197,155,108);
        ofFill();
        mesh.draw();
        ofSetRectMode(OF_RECTMODE_CENTER);
        if (stroke.size()>0) {
             top[num].draw(stroke.getVertices()[stroke.size()-1], width, height);
        }
    }
    
}
コード例 #6
0
ファイル: ofApp.cpp プロジェクト: mattvisco/SFPC_2016
bool operator==(const ofPolyline& lhs, const ofPolyline& rhs)
{
    vector<ofPoint> vertices1 = lhs.getVertices();
    vector<ofPoint> vertices2 = rhs.getVertices();
    if(vertices1.size() != vertices2.size()) return false;
    else {
        for(int i = 0; i < vertices1.size(); i++) {
            if(vertices1[i] != vertices2[i]) return false;
        }
    }
    return true;
}
コード例 #7
0
//----------------------------------------------------------
void ofGLRenderer::draw(ofPolyline & poly){
	if(!poly.getVertices().empty()) {
		// use smoothness, if requested:
		if (bSmoothHinted) startSmoothing();

		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), &poly.getVertices()[0].x);
		glDrawArrays(poly.isClosed()?GL_LINE_LOOP:GL_LINE_STRIP, 0, poly.size());

		// use smoothness, if requested:
		if (bSmoothHinted) endSmoothing();
	}
}
コード例 #8
0
ファイル: Plant.cpp プロジェクト: ofZach/funkyForms
void Plant::makeStroke(int i,
                       float min,
                       float max,
                       ofPolyline &centerLine,
                       ofPolyline *line1,
                       ofPolyline *line2
                       ){
    ofVec2f v = centerLine.getTangentAtIndex(i);
    float length = ofMap(i, 0, centerLine.size()-1, max, min) ;
    float angle = 90;
    float hackValue = 0.8;
    if(i==0 || i == centerLine.size()-1){
        ofVec2f p = centerLine.getVertices()[i] + v.rotate(angle)*length*hackValue;
        ofVec2f v2 = centerLine.getTangentAtIndex(i);
        ofVec2f p2 = centerLine.getVertices()[i] + v2.rotate(-angle)*length*hackValue;
        line1->lineTo(p);
        line2->lineTo(p2);
    }
    if(i>0 && i < centerLine.size()-1){
        makeCorner(line1, centerLine, i, angle, length);
        makeCorner(line2, centerLine, i, -angle, length);
    }
    if(i == centerLine.size()-1){
        ofVec2f v = centerLine.getTangentAtIndex(i);
        float length = ofMap(i, 0, centerLine.size()-1, min, min) ;
        ofVec2f _p2 = centerLine.getVertices()[i] + v.rotate(90)*length*hackValue;
        ofVec2f _p1 = centerLine.getVertices()[i] + v.rotate(180)*length*hackValue;
        ofVec2f _p3 = _p1 + (_p2 - _p1)/2;
        ofVec2f _delta = _p2 - _p1;
        ofVec2f pCenter = _p3 - _delta.getPerpendicular()*min;
        ofVec2f pLeft = pCenter - _delta/2;
        ofVec2f pRight = pCenter + _delta/2;
        
        line2->bezierTo(_p1, pLeft, pCenter);
        line1->bezierTo(_p2, pRight, pCenter);
        
        //                ofSetColor(ofColor::yellow);
        //                ofDrawCircle(p1, 5);
        //                ofSetColor(ofColor::red);
        //                ofDrawCircle(p2, 5);
        //                ofSetColor(ofColor::blueViolet);
        //                ofDrawCircle(p3, 5);
        //                ofSetColor(ofColor::darkMagenta);
        //                ofDrawCircle(pCenter, 5);
        //                ofSetColor(ofColor::lightPink);
        //                ofDrawCircle(pLeft, 5);
        //                ofSetColor(ofColor::lightSkyBlue);
        //                ofDrawCircle(pRight, 5);
    }

}
コード例 #9
0
//--------------------------------------------------------------
void ofxFatLine::setFromPolyline(ofPolyline & poly){
//	ofxFatLine();
	setGlobalColor(ofGetStyle().color);
	setGlobalWidth(ofGetStyle().lineWidth);
	if (!poly.getVertices().empty()){
		addVertices(poly.getVertices());
	for (int i = 0; i <getVertices().size(); i++) {
		addColor(globalColor);
		addWeight(globalWidth);
	}
	update();
	//*/
	}		
}
コード例 #10
0
void LaserManager::addLaserPolyline(const ofPolyline& line, ColourSystem* coloursystem, float intens){
	
	if((line.getVertices().size()==0)||(line.getPerimeter()<0.1)) return;
	
	shapes.push_back(new LaserPolyline(line, coloursystem, intens));
	
	
}
コード例 #11
0
void Path3D::set(ofPolyline &polyline){
    
    setup(); // incase path hasn't been set up yet
    
    ptIndex = 0;
    reverse = true;
    direction = 1;
    
    // ignore the first and last points for the centroid
    for (int i=1; i<polyline.getVertices().size()-1; i++){
        centroid += polyline.getVertices()[i];
    }
    centroid /= polyline.getVertices().size()-2;
    
    path = polyline;
    buildPerpFrames(path);
}
コード例 #12
0
ファイル: testApp.cpp プロジェクト: decebel/drawing-examples
//--------------------------------------------------------------
void testApp::draw(){

    
    ofBackgroundGradient(ofColor(10,10,10), ofColor(0,0,0) );
    
    /*particleA.draw();
    particleB.draw();
    particleC.draw();
    */
    if (temp.getVertices().size() > 500){
        temp.getVertices().erase(temp.getVertices().begin());
    }
    
    ofEnableAlphaBlending();
    //temp.draw();
    
    glBegin(GL_LINE_STRIP);
    for (int i = 0; i < temp.getVertices().size(); i++){
        float pct = ofMap(i, 0, temp.getVertices().size()-1, 0,1);
        ofSetColor(255,255,255,255*pct);
        glVertex2f(temp.getVertices()[i].x, temp.getVertices()[i].y);
    }
    glEnd();
    ofEndShape();
    
}
コード例 #13
0
ファイル: ofxClipper.cpp プロジェクト: neumic/ofxClipper
//--------------------------------------------------------------
ClipperLib::Polygon ofxClipper::ofPolyline_to_Polygon(ofPolyline& polyline) {
	vector<ofPoint> verts = polyline.getVertices();
    vector<ofPoint>::iterator iter;
    ClipperLib::Polygon polygon;
    for(iter = verts.begin(); iter != verts.end(); iter++) {
        ClipperLib::IntPoint ip((*iter).x * clipperGlobalScale, 
                                (*iter).y * clipperGlobalScale);
        polygon.push_back(ip);
    }
    return polygon;
}
コード例 #14
0
int XBScene1::findIntersectionHorizontal(ofPolyline &line, int posX)
{
    //loop through polyline points, left to right, when posX changes from  higher to lower from the x component of the polyline point
    vector<ofPoint> vertices = line.getVertices();
    for (int i = 0; i < vertices.size(); i++) {
        if (posX > vertices[i].x)
            continue;
        else
            return i;
    }
}
コード例 #15
0
ファイル: testApp.cpp プロジェクト: imclab/facepp
ofPoint getCentroid2D(ofPolyline  temp){
	
	vector < ofPoint > pts = temp.getVertices();
	ofPoint midPt;
	midPt.set(0,0,0);
	for (int i = 0; i <pts.size(); i++){
		midPt+= pts[i];
	}
	midPt /= MAX(1, pts.size());
	return midPt;
	
}
コード例 #16
0
//--------------------------------------------------------------
int XBScene1::findIntersectionVertical(ofPolyline &line, int posY)
{
    //TODO get closer at first, check the posY with the length of the line, so if it is higher than half the length we start comparing at the middle of the line
    //loop through polyline points, when posY changes from lower to higher from the y component of the polyline point
    vector<ofPoint> vertices = line.getVertices();
    for (int i = 0; i < vertices.size(); i++) {
        if (posY < vertices[i].y)
            continue;
        else
            return i;
    }
}
コード例 #17
0
ファイル: Clipper.cpp プロジェクト: bakercp/ofxClipper
ClipperLib::Path Clipper::toClipper(const ofPolyline& polyline,
                                    ClipperLib::cInt scale)
{
    ClipperLib::Path path;

    for (auto& vertex: polyline.getVertices())
    {
        path.push_back(toClipper(vertex, scale));
    }

    return path;
}
コード例 #18
0
void ofxPoly2Tri::triangulate(ofPolyline bounds) {
    
    vector<p2t::Point*> bound;
    vector<ofPoint>edgepoints = bounds.getVertices();
    for (int i=0;i<edgepoints.size();++i) {
        bound.push_back(new p2t::Point(edgepoints[i].x,edgepoints[i].y));
    }
    doTriangulation(bound);
    //clear the vector again
    for (vector<p2t::Point*>::iterator it = bound.begin(); it != bound.end(); ++it) {
        delete *it;
    }
}
コード例 #19
0
ofPolyline convexHull(ofPolyline & line){
    
    vector < hPoint > ptsIn;
    for (int i = 0; i < line.getVertices().size(); i++){
        hPoint pt;
        pt.x = line.getVertices()[i].x;
        pt.y = line.getVertices()[i].y;
        
        ptsIn.push_back(pt);
    }
    vector < hPoint > ptsOut;
    
    ptsOut =  calcConvexHull(ptsIn);
    
    ofPolyline out;
    
    for (int i = 0; i < ptsOut.size(); i++){
        out.addVertex(ofPoint(ptsOut[i].x, ptsOut[i].y));
    }
    
    return out;
    
}
コード例 #20
0
void ofxPolylineSave(ofPolyline & poly, string xmlPath) {
    ofXml xml;
    xml.addChild("poly");
    xml.setAttribute("closed", ofToString(poly.isClosed()));
    for(int i=0; i<poly.size(); i++) {
        ofPoint & point = poly.getVertices()[i];
        
        xml.addChild("point");
        xml.setToChild(i);
        xml.setAttribute("x", ofToString(point.x));
        xml.setAttribute("y", ofToString(point.y));
        xml.setToParent();
    }

    xml.save(xmlPath);
}
コード例 #21
0
ファイル: MovingFont.cpp プロジェクト: aquaring/polylineStudy
void MovingFont::fillPolyline(ofPolyline& polyline) {
    ofPath path;
    path.setHexColor(0x333333);
    path.setPolyWindingMode(OF_POLY_WINDING_NONZERO);
    vector<ofPoint> &vertices = polyline.getVertices();
    int size = vertices.size();
    
    for (int i = 0; i < size; i++) {
        if (i == 0) {
            path.moveTo(vertices[i].x, vertices[i].y);
        } else {
            path.lineTo(vertices[i].x, vertices[i].y);
        }
    }
    path.close();
    path.draw();
    
}
コード例 #22
0
ファイル: pen.cpp プロジェクト: VictorSigma/LSC-Graffiti-Wall
//--------------------------------------------------------------
ofMesh pen::lineToMesh(ofPolyline line,ofColor color, float thicknessOffset, ofVec2f positionOffset){ 
    ofMesh mesh;
    mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); 
    vector<ofPoint> points = line.getVertices();
    
    int brightness = 255;
    
    for(int i = 1; i < points.size(); i++){
		ofVec2f thisPoint = ofVec2f(points[i-1].x,points[i-1].y);
		ofVec2f nextPoint = ofVec2f(points[i].x,points[i].y);
		ofVec2f direction = (nextPoint - thisPoint);
		float distance = direction.length();
        
		ofVec2f unitDirection = direction.normalized();
		ofVec2f toTheLeft = unitDirection.getRotated(-90);
		ofVec2f toTheRight = unitDirection.getRotated(90);
        
		float thickness = ofMap(thisPoint.y, 0, ofGetScreenHeight(), 5, 40);
        thickness += thicknessOffset;
        
        if (thicknessOffset == 0)
            color.setBrightness(ofMap(i, 0, points.size(), 250, 200));
        
		ofVec2f leftPoint = thisPoint+toTheLeft*thickness;
		ofVec2f rightPoint = thisPoint+toTheRight*thickness;
        
        if (thicknessOffset > 0 && i == 1){
            ofVec2f tempLeftPoint = leftPoint;
            ofVec2f tempRightPoint = rightPoint;
            
            tempLeftPoint -= unitDirection * (thickness/2);
            tempRightPoint -= unitDirection * (thickness/2);
            
            mesh.addVertex(ofVec2f(tempLeftPoint.x + positionOffset.x, tempLeftPoint.y + positionOffset.y));
            mesh.addColor(color);
            mesh.addVertex(ofVec2f(tempRightPoint.x + positionOffset.x, tempRightPoint.y + positionOffset.y));
            mesh.addColor(color);
        }
        
		mesh.addVertex(ofVec2f(leftPoint.x, leftPoint.y + positionOffset.y));
        mesh.addColor(color);
		mesh.addVertex(ofVec2f(rightPoint.x, rightPoint.y + positionOffset.y));
        mesh.addColor(color);
        
        if (thicknessOffset > 0 && i == points.size()-1){
            
            leftPoint += unitDirection * (thickness/3) + positionOffset;
            rightPoint += unitDirection * (thickness/3) + positionOffset;
            
            mesh.addVertex(leftPoint);
            mesh.addColor(color);
            mesh.addVertex(rightPoint);
            mesh.addColor(color);
        }
        
        
        //Add arrow
        if (i == points.size()-1 ){
          
            leftPoint = thisPoint+toTheLeft*thickness*1.5;
            rightPoint = thisPoint+toTheRight*thickness*1.5;

            mesh.addVertex(leftPoint);
            mesh.addColor(color);
            
            mesh.addVertex(rightPoint);
            mesh.addColor(color);
     
            
            mesh.addVertex(nextPoint + unitDirection * thickness*2.5);
            mesh.addColor(color);
        }
        
        
    }
    
    return mesh;
}
コード例 #23
0
/*
 * copied from ofZack's example https://github.com/ofZach/Visvalingam-Whyatt
 */
void ofx2DTrackedMappingController::calcSimplificaiton( ofPolyline & lineToSimplify, vector < ofPoint > & results){


    results = lineToSimplify.getVertices();


    int total = lineToSimplify.size();


    // if we have 100 points, we have 98 triangles to look at
    int nTriangles = total - 2;


    triangle * triangles[ nTriangles ];

    for (int i = 1; i < total-1; i++){
        triangle * tempTri = new triangle();
        tempTri->indices[0] = i-1;
        tempTri->indices[1] = i;
        tempTri->indices[2] = i+1;
        tempTri->area = triArea(        lineToSimplify[tempTri->indices[0]],
                                        lineToSimplify[tempTri->indices[1]],
                                        lineToSimplify[tempTri->indices[2]]);
        triangles[i-1] = tempTri;
    }

    // set the next and prev triangles, use NULL on either end. this helps us update traingles that might need to be removed
    for (int i = 0; i < nTriangles; i++){
        triangles[i]->prev = (i == 0 ? NULL : triangles[i-1]);
        triangles[i]->next = (i == nTriangles-1 ? NULL : triangles[i+1]);
    }

    std::vector<triangle*> trianglesVec;

    for (int i = 0; i < nTriangles; i++){
        trianglesVec.push_back(triangles[i]);
    }



    int count = 0;
    while ( !trianglesVec.empty()){



        ofSort(trianglesVec,compareTri);

        triangle * tri = trianglesVec[0];

        results[tri->indices[1]].z = total - count;         // store the "importance" of this point in numerical order of removal (but inverted, so 0 = most improtant, n = least important.  end points are 0.
        count ++;


        if (tri->prev != NULL){
            tri->prev->next = tri->next;
            tri->prev->indices[2] = tri->indices[2];  // check!

            tri->prev->area = triArea(      lineToSimplify[tri->prev->indices[0]],
                                            lineToSimplify[tri->prev->indices[1]],
                                            lineToSimplify[tri->prev->indices[2]]);

        }

        if (tri->next != NULL){
            tri->next->prev = tri->prev;
            tri->next->indices[0] = tri->indices[0];  // check!


            tri->next->area = triArea(      lineToSimplify[tri->next->indices[0]],
                                            lineToSimplify[tri->next->indices[1]],
                                            lineToSimplify[tri->next->indices[2]]);


        }

        trianglesVec.erase(trianglesVec.begin());



    }

    // free the memory we just allocated above.
    for (int i = 0; i < nTriangles; i++){
        delete triangles[i];
    }



}
コード例 #24
0
void ofGLRenderer::draw(ofPolyline & poly){
	glVertexPointer(poly.is3D()?3:2, GL_FLOAT, sizeof(ofVec3f), &poly.getVertices()[0].x);
	glDrawArrays(poly.isClosed()?GL_LINE_LOOP:GL_LINE_STRIP, 0, poly.size());;
}