void phdGimbal2d::getKeyPoints(ofPolyline & _keys) { _keys.clear(); _keys.addVertex( 1.00, 0.0); _keys.addVertex( 0.75, 0.0); _keys.addVertex( 0.00, 0.0); _keys.addVertex( 0.00,-1.0); getTransformedPolyline(_keys, _keys, getOTSMatrix()); }
//-------------------------------------------------------------- void testApp::newPath() { path.clear(); // A path is a series of connected points // A more sophisticated path might be a curve path.addVertex(0, ofGetHeight()/2); path.addVertex(ofRandom(0, ofGetWidth()/2), ofRandom(0, ofGetHeight())); path.addVertex(ofRandom(ofGetWidth()/2, ofGetWidth()), ofRandom(0, ofGetHeight())); path.addVertex(ofGetWidth(), ofGetHeight()/2); }
void bezierSplinePoints(ofPolyline pnts, int count, int segments, ofPolyline & points) { double mu, mudelta; int x1, y1, x2, y2, n, h; ofVec2f pha, phb; if(count < 4 || count > 16383) return; // Phantom Points pha = ofVec2f(2.0*pnts[0].x-pnts[1].x, 2.0*pnts[0].y-pnts[1].y); phb = ofVec2f(2.0*pnts[count-1].x-pnts[count-2].x, 2.0*pnts[count-1].y-pnts[count-2].y); mudelta = 1.0 / segments; for(n = 2; n < count; n++) { mu = 0; if(n == 2) { x1 = Calculate(mu,pha.x,pnts[n-2].x,pnts[n-1].x,pnts[n].x); y1 = Calculate(mu,pha.y,pnts[n-2].y,pnts[n-1].y,pnts[n].y); } else if(n == count) { x1 = Calculate(mu,pnts[n-3].x,pnts[n-2].x,pnts[n-1].x,phb.x); y1 = Calculate(mu,pnts[n-3].y,pnts[n-2].y,pnts[n-1].y,phb.y); } else { x1 = Calculate(mu,pnts[n-3].x,pnts[n-2].x,pnts[n-1].x,pnts[n].x); y1 = Calculate(mu,pnts[n-3].y,pnts[n-2].y,pnts[n-1].y,pnts[n].y); } points.addVertex(x1, y1); mu = mu + mudelta; for(h = 1; h < segments; h++) { if(n == 2) { x2 = Calculate(mu,pha.x,pnts[n-2].x,pnts[n-1].x,pnts[n].x); y2 = Calculate(mu,pha.y,pnts[n-2].y,pnts[n-1].y,pnts[n].y); } else if(n == count) { x2 = Calculate(mu,pnts[n-3].x,pnts[n-2].x,pnts[n-1].x,phb.x); y2 = Calculate(mu,pnts[n-3].y,pnts[n-2].y,pnts[n-1].y,phb.y); } else { x2 = Calculate(mu,pnts[n-3].x,pnts[n-2].x,pnts[n-1].x,pnts[n].x); y2 = Calculate(mu,pnts[n-3].y,pnts[n-2].y,pnts[n-1].y,pnts[n].y); } points.addVertex(x2, y2); mu = mu + mudelta; } } }
void ofxPolylineLoad(ofPolyline & poly, string xmlPath) { ofXml xml; bool bLoaded = xml.load(xmlPath); if(bLoaded == false) { return; } xml.setTo("poly"); bool bClosed = ofToInt(xml.getAttribute("closed")); poly.clear(); int numOfPoints = xml.getNumChildren(); for(int i=0; i<numOfPoints; i++) { xml.setToChild(i); float x = ofToFloat(xml.getAttribute("x")); float y = ofToFloat(xml.getAttribute("y")); poly.addVertex(x, y); } if(bClosed == true) { poly.close(); } }
void contourToConvexHull(ofPolyline &src, ofPolyline &dst) { dst.clear(); vector<hPoint> P(src.size()); for(int i = 0; i < src.size(); i++) { P[i].x = src[i].x; P[i].y = src[i].y; } int n = src.size(), k = 0; vector<hPoint> H(2*n); // Sort points lexicographically sort(P.begin(), P.end()); // Build lower hull for (int i = 0; i < n; i++) { while (k >= 2 && cross(H[k-2], H[k-1], P[i]) <= 0) k--; H[k++] = P[i]; } // Build upper hull for (int i = n-2, t = k+1; i >= 0; i--) { while (k >= t && cross(H[k-2], H[k-1], P[i]) <= 0) k--; H[k++] = P[i]; } H.resize(k); for(int i = 0; i < H.size(); i++) { dst.addVertex(H[i].x + 500, H[i].y); } }
void update() { // Update our little offset thingy. offset += 0.01; if (offset > 1) { offset = 0; } // Update our camera. grabber.update(); // If the camera has a new frame to offer us ... if (grabber.isFrameNew()) { // Make a copy of our grabber pixels in the colorImage. colorImage.setFromPixels(grabber.getPixelsRef()); // When we assign a color image to a grayscale image, it is converted automatically. grayscaleImage = colorImage; // If we set learnBackground to true using the keyboard, we'll take a snapshot of // the background and use it to create a clean foreground image. if (learnBackground == true) { // We assign the grayscaleImage to the grayscaleBackgroundImage. grayscaleBackgroundImage = grayscaleImage; // Now we set learnBakground so we won't set a background unless // explicitly directed to with a keyboard command. learnBackground = false; } // Create a difference image by comparing the background and the current grayscale images. grayscaleAbsoluteDifference.absDiff(grayscaleBackgroundImage, grayscaleImage); // Assign grayscaleAbsoluteDifference to the grayscaleBinary image. grayscaleBinary = grayscaleAbsoluteDifference; // Then threshold the grayscale image to create a binary image. grayscaleBinary.threshold(threshold, invert); // Find contours (blobs) that are between the size of 20 pixels and // 1 / 3 * (width * height) of the camera. Also find holes. contourFinder.findContours(grayscaleBinary, 100, (width * height) / 3.0, 10, true); // Get the biggest blob and use it to draw. if (contourFinder.nBlobs > 0) { holePositions.addVertex(contourFinder.blobs[0].boundingRect.getCenter()); } else { holePositions.clear(); } } }
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) ); } }
curvedSquare::curveSquare() { x = 100; y = 100; speedX = ofRandom(-1, 1); // and random speed and direction speedY = ofRandom(-1, 1); dim = 20; myPoly.addVertex(x,y); myPoly.bezierTo(x,y,x-6,y+1,x-9, y+6); myPoly.bezierTo(x-12,y+9,x-12,y+17,x-12,y+17); myPoly.addVertex(x-12,y+44); myPoly.addVertex(x+14,y+44); myPoly.bezierTo(x+14,y+44,x+22,y+44,x+26,y+41); myPoly.bezierTo(x+30,y+38,x+30,y+32,x+30,y+32); myPoly.addVertex(x+30,y); myPoly.addVertex(x+30,y); myPoly.close(); }
// ---------------------------------------------------------- void WaveformForBuffer(const ofxAudioUnitTap::MonoSamples &buffer, float width, float height, ofPolyline &outLine, unsigned sampleRate) // ---------------------------------------------------------- { outLine.clear(); const float xStep = width / (buffer.size() / sampleRate); float x = 0; for (int i = 0; i < buffer.size(); i += sampleRate, x += xStep) { #if TARGET_OS_IPHONE SInt16 s = SInt16(buffer[i] >> 9); float y = ofMap(s, -32768, 32767, height, 0, true); #else float y = ofMap(buffer[i], -1, 1, height, 0, true); #endif outLine.addVertex(ofPoint(x, y)); } }
//-------------------------------------------------------------- void Path3D::parsePts(string filename, ofPolyline &polyline){ ofFile file = ofFile(ofToDataPath(filename)); polyline.clear(); if(!file.exists()){ ofLogError("The file " + filename + " is missing"); } ofBuffer buffer(file); //Read file for (ofBuffer::Line it = buffer.getLines().begin(); it != buffer.getLines().end(); it++) { string line = *it; float scalar = 10; ofVec3f offset; if (filename == "path_XZ.txt"){ offset = ofVec3f(0, 0, 0); scalar = 3; } else if (filename == "path_YZ.txt"){ offset = ofVec3f(0, 0, 0); scalar = 3; } else{ offset = ofVec3f(0, 0, .25); scalar = 3; } ofStringReplace(line, "{", ""); ofStringReplace(line, "}", ""); cout<<line<<endl; vector<string> coords = ofSplitString(line, ", "); // get x y z coordinates ofVec3f p = ofVec3f(ofToFloat(coords[0])*scalar,ofToFloat(coords[1])*scalar,ofToFloat(coords[2])*scalar); p += offset; polyline.addVertex(p); } }
//-------------------------------------------------------------- void testApp::update(){ particleA.pos.set(mouseX, mouseY); particleB.resetForce(); connector.update(); particleB.addDampingForce(); particleB.update(); particleC.resetForce(); connector2.update(); particleC.addDampingForce(); particleC.update(); if (ofGetMousePressed()) temp.addVertex(particleC.pos); }