Beispiel #1
0
//vector<ofPoint>
ofPolyline ofxGetConvexHull(vector<ofPoint> points) {
  if (points.size()<3) return ofPolyline();

  ofPoint h1,h2,h3;

  sort(points.begin(), points.end(), lexicalComparison);

  vector<ofPoint> hull;

  hull.push_back(points.at(0));
  hull.push_back(points.at(1));

  int currentPoint = 2;
  int direction = 1;

  for (int i=0; i<1000; i++) { //max 1000 tries

    hull.push_back(points.at(currentPoint));

    // look at the turn direction in the last three points
    h1 = hull.at(hull.size()-3);
    h2 = hull.at(hull.size()-2);
    h3 = hull.at(hull.size()-1);

    // while there are more than two points in the hull
    // and the last three points do not make a right turn
    while (!isRightTurn(h1, h2, h3) && hull.size() > 2) {

      // remove the middle of the last three points
      hull.erase(hull.end() - 2);

      if (hull.size() >= 3) {
        h1 = hull.at(hull.size()-3);
      }
      h2 = hull.at(hull.size()-2);
      h3 = hull.at(hull.size()-1);
    }

    // going through left-to-right calculates the top hull
    // when we get to the end, we reverse direction
    // and go back again right-to-left to calculate the bottom hull
    if (currentPoint == points.size() -1 || currentPoint == 0) {
      direction = direction * -1;
    }

    currentPoint+= direction;

    if (hull.front()==hull.back()) break;
  }

  return ofPolyline(hull);
}
Beispiel #2
0
//----------------------------------------------------------
void ofPath::newSubPath(){
	if(mode==PATHS){
		paths.push_back(ofSubPath());
	}else{
		polylines.push_back(ofPolyline());
	}
}
void PMRibbonPainter::clear()
{
    polyline.clear();
    polyline = ofPolyline();

    isNewPath = true;
}
Beispiel #4
0
SmartPoly::SmartPoly(vector<ofPoint> pts, float r, ofRectangle b, ofPoint cPos) : SmartShape() {
    // Position is derived from bounding ox center
    pos = b.position + ofPoint(b.width/2,b.height/2);
    capturedPos = cPos;
    
    rotation = r;
    boundingBox = b;
    
    // Setup the poly line
    polyLine = ofPolyline();
    path = ofPath();
    for (vector<ofPoint>::iterator it = pts.begin() ; it != pts.end(); ++it){
        ofPoint p = *it;
        // All points in the poly will be stored respective to pos.
        p = p - pos;
        polyLine.addVertex(p);
        path.lineTo(p);
    }
    polyLine.close();
    path.close();
    
    // Updat the control points
    updateControlPoints();
    
    extrusionHeight = 0;
}
void CloudsVisualSystemLSystem::buildLSystem(){
    //  Clear
    //
    lsysLines.clear();
    lsysLines.push_back(ofPolyline());
    lsysNodes.clear();
    lsysOriginal.clear();
    
    LSystem sys;
    sys.initialPos.set(0,0);
    sys.unoise = 0.0;
    sys.utime = 0.0;
    
    sys.ds = lsysScale;
    sys.setAngle( lsysAngle );
    sys.addAxion( lsysAxiom );
    sys.addRule( lsysRule1 );
    if (lsysRule2.size() > 0){
        sys.addRule( lsysRule2);
    }

    sys.make( lsysDepth );
    
    lsysOriginal = sys.mesh;
    
    if ( lsysOriginal.getVertices().size() > 2){
        lineTo( lsysOriginal.getVertices()[0] );
        addNode( lsysOriginal.getVertices()[0] );
        
        for (int i = 1; i < lsysOriginal.getVertices().size();i++){
            if ( i%2 == 1){
                lineTo( lsysOriginal.getVertices()[i]);
            } else {
                if ( lsysOriginal.getVertices()[i] != lsysOriginal.getVertices()[i-1]){
                    lsysLines.push_back(ofPolyline());
                    lineTo( lsysOriginal.getVertices()[i] );
                    addNode( lsysOriginal.getVertices()[i] );
                }
            }
        }
    }
    
    if ( lsysNodes.size() > 0){
        lsysNodes[0].startTime = 0;
    }
}
void ofxFeatureFinder::mousePressed(ofMouseEventArgs &args){
    
    if (!displayRect.inside(args.x, args.y)) {
        return;
    }
    
    bDrawingRegion = true;
    
    ofPolyline line = ofPolyline();
    line.addVertex(ofVec2f(args.x - displayRect.x - cropRect.x, args.y - displayRect.y - cropRect.y));
    regions.push_back(line);
}
//--------------------------------------------------------------
void testApp::setup(){
    
    currentFrame = -1;
    
    ofBackground(255,255,255);
    ofSetColor(0, 0, 0);
    ofSetLineWidth(2);
    ofEnableSmoothing();
    ofSetFrameRate(70);
    
    leg = ofPolyline();
    recording = false;
    fileLoaded = false;
    recordedFrame = 0;
}
//--------------------------------------------------------------
void DroneAttack::update(){
    

    auto pushed = in.keyPushed;
    auto holded = in.keyHolded;
    auto pulled = in.keyPulled;
    
    if( pushed[GLFW_KEY_LEFT_SHIFT] ) cam.movespeed = 1.0f * speedFactor;
    if( pulled[GLFW_KEY_LEFT_SHIFT] ) cam.movespeed = 1.0f;

    if( pushed[GLFW_MOUSE_BUTTON_LEFT] ) paint.push_back( ofPolyline() );
    if( holded[GLFW_MOUSE_BUTTON_LEFT] ) paint.back().addVertex( cam.getPosition() + (cam.getLookAtDir() * 50.0f) );
    
    if( pushed[GLFW_MOUSE_BUTTON_RIGHT] ) cam.toggleControl();

    
}
Beispiel #9
0
//----------------------------------------------------------
void ofPath::generatePolylinesFromCommands(){
	if(mode==POLYLINES || commands.empty()) return;
	if(bNeedsPolylinesGeneration || curveResolution!=prevCurveRes){
		prevCurveRes = curveResolution;

		polylines.clear();
		int j=-1;

		for(int i=0; i<(int)commands.size();i++){
			switch(commands[i].type){
			case Command::moveTo:
				polylines.push_back(ofPolyline());
				j++;
				polylines[j].addVertex(commands[i].to);
				break;
			case Command::lineTo:
				polylines[j].addVertex(commands[i].to);
				break;
			case Command::curveTo:
				polylines[j].curveTo(commands[i].to, curveResolution);
				break;
			case Command::bezierTo:
				polylines[j].bezierTo(commands[i].cp1,commands[i].cp2,commands[i].to, curveResolution);
				break;
			case Command::quadBezierTo:
				polylines[j].quadBezierTo(commands[i].cp1,commands[i].cp2,commands[i].to, curveResolution);
				break;
			case Command::arc:
				polylines[j].arc(commands[i].to,commands[i].radiusX,commands[i].radiusY,commands[i].angleBegin,commands[i].angleEnd, circleResolution);
				break;
			case Command::arcNegative:
				polylines[j].arcNegative(commands[i].to,commands[i].radiusX,commands[i].radiusY,commands[i].angleBegin,commands[i].angleEnd, circleResolution);
				break;
			case Command::close:
				polylines[j].setClosed(true);
				break;
			}
		}

		bNeedsPolylinesGeneration = false;
		bNeedsTessellation = true;
		cachedTessellationValid=false;
	}
}
Beispiel #10
0
//--------------------------------------------------------------
void ofApp::update(){
    
    auto pushed = in.keyPushed;
    auto holded = in.keyHolded;
    auto pulled = in.keyPulled;
    
    if( pushed[GLFW_KEY_LEFT_SHIFT] ) cam.movespeed = 7.0f;
    if( pulled[GLFW_KEY_LEFT_SHIFT] ) cam.movespeed = 1.0f;
    
    if( pushed[GLFW_MOUSE_BUTTON_LEFT] ) paint.push_back( ofPolyline() );
    if( holded[GLFW_MOUSE_BUTTON_LEFT] ) paint.back().addVertex( cam.getPosition() + (cam.getLookAtDir() * 50.0f) );
    
    if( pushed[GLFW_MOUSE_BUTTON_RIGHT] ) cam.toggleControl();

    
    roadMovingFactor_33975_22294 = roadMovingFactor_33975_22294 + 1;
    roadMoving_33975_22294 = sin( ofDegToRad(roadMovingFactor_33975_22294) ) * 0.5 + 0.5;
    
    
}
Beispiel #11
0
//----------------------------------------------------------
void CALLBACK ofTessellator::end() {
    // here we take our big pile of vertices and push them at the mesh

    // deal with mesh elements (triangles, triangle fan, triangle strip)

    if(currentTriType!=GL_LINE_LOOP) {
        resultMesh.push_back(ofPrimitive(ofGetOFPrimitiveMode(currentTriType), vertices) );
    } else if ( currentTriType == GL_LINE_LOOP ) { // outline
        resultOutline.push_back( ofPolyline(vertices) );
        resultOutline.back().setClosed(true);
        // close the loop
        /*if ( vertices.size()>0 ) {
        	resultOutline.addVertex( vertices[0] );
        }*/
    }
    else {
        //ofLog( OF_LOG_WARNING, "ofTessellate: unrecognized type '%i' (expected GL_TRIANGLES, GL_TRIANGLE_FAN or GL_TRIANGLE_STRIP)", currentTriType );
    }

}
//--------------------------------------------------------------
void MoonCreator::update(){
    
    auto pushed = in.keyPushed;
    auto holded = in.keyHolded;
    auto pulled = in.keyPulled;
    
    if( pushed[GLFW_KEY_LEFT_SHIFT] ) cam.movespeed = 7.0f;
    if( pulled[GLFW_KEY_LEFT_SHIFT] ) cam.movespeed = 1.0f;
    
    if( pushed[GLFW_MOUSE_BUTTON_LEFT] ) paint.push_back( ofPolyline() );
    if( holded[GLFW_MOUSE_BUTTON_LEFT] ) paint.back().addVertex( cam.getPosition() + (cam.getLookAtDir() * 50.0f) );
    
    if( pushed[GLFW_MOUSE_BUTTON_RIGHT] ) cam.toggleControl();
    
    
//    cout << cam.getPosition() << endl;
//    cout << cam.getLookAtDir() << endl;
    

    
}
Beispiel #13
0
//----------------------------------------------------------
ofPolyline & ofPath::lastPolyline(){
	if(polylines.empty() || polylines.back().isClosed()){
		polylines.push_back(ofPolyline());
	}
	return polylines.back();
}
Beispiel #14
0
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
	polyLines.push_back(ofPolyline());
	drawingShape = true;
}
//--------------------------------------------------------------
void ofApp::update(){
    
    //kinect updates
    kinect.update();
    
    //framerate of OF might be faster than kinect
    if(kinect.isFrameNew()) {
        // process kinect depth image - turns people into Blobs
        //turn this into a black and white image
        //black out anything that is past a certain depth
        grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
        grayThreshNear = grayImage;
        grayThreshFar = grayImage;
        grayThreshNear.threshold(nearThreshold, true);
        grayThreshFar.threshold(farThreshold);
        //takes kinect depth image such that white is past a certain depth
        cvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL);
        grayImage.flagImageChanged(); //finally becomes a black and white image
        

        // set contour tracker parameters
        //Blob finder - takes white blobs and gives you all the points on its perimiter
        contourFinder.setMinArea(minArea);
        contourFinder.setMaxArea(maxArea);
        contourFinder.setThreshold(threshold);
        contourFinder.getTracker().setPersistence(persistence);
        contourFinder.getTracker().setMaximumDistance(maxDistance);
        
        // determine found contours
        contourFinder.findContours(grayImage);
    }
    
    //box2d update
    
    lines.clear();
    edges.clear();
    
    
    // add some circles every so often
   // if((int)ofRandom(0, 5) == 0) {
        ofPtr<ofxBox2dCircle> c = ofPtr<ofxBox2dCircle>(new ofxBox2dCircle);
        c.get()->setPhysics(0.2, 0.2, 0.002);
        
        //here we can change the look of the balls falling
        //c.get()->setup(box2d.getWorld(), ofRandom(0, secondWindow.getWidth()), -20, ofRandom(3, 10));
        c.get()->setup(box2d.getWorld(), ofRandom(0, secondWindow.getWidth()), -20, 4);
        c.get()->setVelocity(0, 10
                             ); // shoot them down!
        circles.push_back(c);
   // }
   
    //counterFinder.size = number of people in field of view
    for(int i = 0; i < contourFinder.size(); i++) {
        //making points from the countour of the blob
        vector<cv::Point> points = contourFinder.getContour(i);
        
        lines.push_back(ofPolyline());
        
        for (int j=0; j<points.size(); j++){
            
            ofVec3f wp = kinect.getWorldCoordinateAt(points[j].x, points[j].y);
            ofVec2f pp = kpt.getProjectedPoint(wp);

            lines.back().addVertex(
                                   ofMap(pp.x, 0, 1, 0, secondWindow.getWidth()),
                                   ofMap(pp.y, 0, 1, 0, secondWindow.getHeight())
            );
        
        }
        
        ofPtr <ofxBox2dEdge> edge = ofPtr<ofxBox2dEdge>(new ofxBox2dEdge);
        lines.back().simplify();//simplify helps to reduce the number of points because it can be computationally expensive
        
        for (int i=0; i<lines.back().size(); i++) {
            edge.get()->addVertex(lines.back()[i]);
        }
        
        //poly.setPhysics(1, .2, 1);  // uncomment this to see it fall!
        edge.get()->create(box2d.getWorld());
        edges.push_back(edge);
        
    }
    
    
    box2d.update();


}
Beispiel #16
0
//--------------------------------------------------
bool ofInsidePoly(const ofPoint & p, const vector<ofPoint> & poly){
    return ofPolyline::inside(p.x,p.y, ofPolyline(poly));
}
Beispiel #17
0
//--------------------------------------------------
bool ofInsidePoly(float x, float y, const vector<ofPoint> & polygon){
    return ofPolyline::inside(x,y, ofPolyline(polygon));
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button) {
	lines.push_back(ofPolyline());
	lines.back().addVertex(x, y);
}
Beispiel #19
0
//----------------------------------------------------------
void ofPath::newSubPath(){
	if(mode==COMMANDS){
	}else{
		polylines.push_back(ofPolyline());
	}
}
void PhotoBooth::makeButterfly() {
	bMakingButterfly = true;
	ofLogNotice() << "making butterfly..." ;
	
	// get the bounding box of the butterfly
	int nblobs = contourFinder.blobs.size();
	// butterfly should be seen by the camera as a single blob if there are no blobs, there probably isn't a butterfly
	if(nblobs > 0) {
		ofLogNotice() << "making butterfly: blob found!" ;
		
		ofRectangle bbox = contourFinder.blobs[0].boundingRect;
		ofPolyline pline = ofPolyline( contourFinder.blobs[0].pts );

		ofLogNotice() << "blob.bbox [" << bbox.x << ", " << bbox.y << ", " << bbox.width << ", " << bbox.height << "]" ;
	
		int dimx = bbox.width/2;
		int dimy = bbox.height;
		imgLeft.allocate(dimx, dimy);
		imgRight.allocate(dimx, dimy);
		ofLogNotice() << "capturing wings with dimensions (" << dimx << ", " << dimy << ")" ;

		ofPoint *psrc = new ofPoint[4];
		psrc[0].set(bbox.x, bbox.y);
		psrc[1].set((bbox.x + bbox.width/2), bbox.y);
		psrc[2].set((bbox.x + bbox.width/2), bbox.y+bbox.height);
		psrc[3].set(bbox.x, bbox.y+bbox.height);

		ofPoint *pdst = new ofPoint[4];
		pdst[0].set(0, 0);
		pdst[1].set(imgLeft.width, 0);
		pdst[2].set(imgLeft.width, imgLeft.height);
		pdst[3].set(0, imgLeft.height);
		
		// make a rect for each wing
		// capture the contents of each rect in the grayDiff image
		//grayDiff.setROI(bbox.x, bbox.y, bbox.width/2, bbox.height);
//		imgLeft.allocate(FEED_WIDTH, FEED_HEIGHT, OF_IMAGE_COLOR_ALPHA);
		imgLeft.warpIntoMe(grayDiff, psrc, pdst);
//		imgLeft.allocate(bbox.width/2, bbox.height, OF_IMAGE_COLOR_ALPHA);
//		utils::copyRoiToImage(grayDiff, imgLeft);

		psrc[0].set((bbox.x + bbox.width/2), bbox.y);
		psrc[1].set((bbox.x + bbox.width), bbox.y);
		psrc[2].set((bbox.x + bbox.width), bbox.y+bbox.height);
		psrc[3].set((bbox.x + bbox.width/2), bbox.y+bbox.height);

		//grayDiff.setROI( (bbox.x+bbox.width/2), bbox.y, bbox.width/2, bbox.height);
		imgRight.warpIntoMe(grayDiff, psrc, pdst);
//		imgRight.allocate(FEED_WIDTH, FEED_HEIGHT, OF_IMAGE_COLOR_ALPHA);
//		imgLeft.allocate(bbox.width/2, bbox.height, OF_IMAGE_COLOR_ALPHA);
//		utils::copyRoiToImage(grayDiff, imgRight);
	}
	
	// we first have to convert the warped image to an ofImage so that we can 
	// mask-out the black pixels using the makeTransparent method
	ofImage tmp1, tmp2;
	tmp1.setFromPixels(imgLeft.getPixelsRef());
	utils::makeTransparent(tmp1);
	lw.begin();
	ofClear(0, 0, 0);
	ofEnableAlphaBlending();
	tmp1.draw(0, 0, TEX_SIZE, TEX_SIZE);
	ofDisableAlphaBlending();
	lw.end();

	tmp2.setFromPixels(imgRight.getPixelsRef());
	utils::makeTransparent(tmp2);
	rw.begin();
	ofClear(0, 0, 0);
	ofEnableAlphaBlending();
	tmp2.draw(0, 0, TEX_SIZE, TEX_SIZE);
	ofDisableAlphaBlending();
	rw.end();
	
	butterfly.setWings(lw, rw);
	bMakingButterfly = false;
}