示例#1
0
//--------------------------------------------------------------
void testApp::draw(){
	
	// Display background
	ofSetColor(255, 255, 255, 50);
	img.draw(0, 0, ofGetWidth(), ofGetHeight());
	
	// Draw ball
	ofSetColor(255, 150, 0);
	ofCircle(ballPositionX, ballPositionY, 10);
	
	/************ DRAW PARTICLE SYSTEM ***********************/
	
	particleSystem.setTimeStep(timeStep);
	
	ofEnableAlphaBlending();
	ofSetColor(251, 236, 93, lineOpacity);
	particleSystem.setupForces();
	
	// apply per-particle forces
	glBegin(GL_LINES);
	for(int i = 0; i < particleSystem.size(); i++) {
		Particle& cur = particleSystem[i];
		
		// global force on other particles
		particleSystem.addRepulsionForce(cur, particleNeighborhood, particleRepulsion);
		
		// forces on this particle
		cur.bounceOffWalls(0, 0, ofGetWidth(), ofGetHeight());
		cur.addDampingForce();
	}
	glEnd();
	
	// Apply attraction to selected points
	for (int i=0; i < attractPts.size(); i++) {
		particleSystem.addAttractionForce(attractPts[i]->x, attractPts[i]->y, ofGetWidth(), centerAttraction);
	}
		
	// Add repulsion force by mouse click
	if(isMousePressed)
		particleSystem.addRepulsionForce(mouseX, mouseY, 100, 10);
	
	// Set the ball to repulse
	particleSystem.addRepulsionForce(ballPositionX, ballPositionY, 25, 10);
	
	particleSystem.update();
	ofSetColor(255, 255, 255, pointOpacity);
	particleSystem.draw();
	ofDisableAlphaBlending();
	
	ofSetColor(255, 255, 255);
	//ofDrawBitmapString(ofToString(kParticles) + "k particles", 32, 32);
	//ofDrawBitmapString(ofToString((int) ofGetFrameRate()) + " fps", 32, 52);
	
	
	// draw depth and color view
	//kinect.drawDepth(10, 10, 200, 150);
	//kinect.draw(220, 10, 200, 150);
	//colorImg.mirror(false, true);
	//colorImg.draw(100,100);
	
	/************ DRAW POINT CLOUD ***********************/
	
	// draw point cloud
	pointCloudX = 800;
	pointCloudY = 800;
	
	ofSetColor(0, 0, 0);
	ofPushMatrix();
	ofTranslate(pointCloudX, pointCloudY);
	drawPointCloud();
	ofPopMatrix();
	
	// Make attraction with point
	/*for (int i=0; i < cloudPts.size(); i++) {
		particleSystem.addAttractionForce(cloudPts[i]->x + 800, cloudPts[i]->y + 650, 25, 1);
		//printf("Point Clouds: %f %f \n", cloudPts[i]->x, cloudPts[i]->y);
	} */

	

	// Rotate drawing
	if(depthContours.blobs.size() == 2) {
		ofxVec2f center = depthContours.blobs[0].centroid + depthContours.blobs[1].centroid;
		
		ofxVec2f targetViewRot;
		targetViewRot.x = ofMap(center.x, 0, ofGetWidth(), -360, 360);
		targetViewRot.y = ofMap(center.y, 0, ofGetHeight(), 360, -360);
		
		viewRot += (targetViewRot - viewRot) * 0.05;
	} else {
		viewRot -= viewRot * 0.05;
	}
	
	ofxVec3f camToWorld(ofGetWidth()/depthOrig.getWidth(), ofGetHeight()/depthOrig.getHeight(), 1);
	ofxVec3f up(0, 1, 0);
	
	
gui.draw();

	
	/********** Calculate 2D Coordinate from 3D Space ********/
	GLdouble screenX = 0;
	GLdouble screenY = 0;
	GLdouble screenZ = 0;
	
	GLint viewport[4];
	GLdouble mvmatrix[16], projmatrix[16];
	
	glGetIntegerv(GL_VIEWPORT, viewport);
	glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
	glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
	
	gluProject(pointCloudX, pointCloudY, -3000,
			   mvmatrix, projmatrix, viewport,
			   &screenX, &screenY, &screenZ);
	
	screenY = ofGetHeight() - screenY;
	
	
	// Draws contours on the screen
	depthContours.draw(screenX, screenY, 640, 480);
	
	 }
示例#2
0
void draw() 
{
    ofSetColor(255);

    // A few helper variables for layout.
    int hw = width / 2;  // Half width
    int hh = height / 2; // Half height.
    int qw = width / 4;  // Quarter width.
    int qh = height / 4; // Quarter height.
    int lx = 14; // Label offset x.
    int ly = 20; // Label offset y.

    grayscaleImage.draw(0, 0, qw, qh);
    ofDrawBitmapStringHighlight("0. Grayscale", lx, ly);
    
    grayscaleBackgroundImage.draw(qw, 0, qw, qh);
    ofDrawBitmapStringHighlight("1. Background\n   (spacebar)", lx + qw, ly);


	grayscaleAbsoluteDifference.draw(0, qh, qw, qh);
    ofDrawBitmapStringHighlight("2. Grayscale - Background", lx, ly + qh);


	grayscaleBinary.draw(qw, qh, qw, qh);
    ofDrawBitmapStringHighlight("3. Threshold " + ofToString(threshold) + "\n   (-/+: change threshold)\n   (  i: invert)", lx + qw, ly + qh);

    // Here we use ofPushMatrix(), ... to scale all of the contours and bounding boxes.
    ofPushStyle();
    ofPushMatrix();
    ofTranslate(hw, 0);
    ofScale(0.5, 0.5, 1);
    grayscaleBinary.draw(0, 0);
    contourFinder.draw(); // Draw all of the contours and their bounding boxes. 
    
    // Draw our line.
    ofSetColor(ofColor::yellow);
    holePositions.draw();
    ofPopMatrix();
    ofDrawBitmapStringHighlight("4. Contours and Bounding Boxes\n   Draw a yellow line to follow\n   the center of the largest blob.", lx + hw, ly);
    ofPopStyle();
  
    colorImage.draw(0, 0);//, hw, hh);
    // ofDrawBitmapStringHighlight("5. Original", lx, ly + hh);
    
    for (int i = 0; i < contourFinder.nBlobs; ++i)
    {
        ofPolyline contour(contourFinder.blobs[i].pts);
        
        // Resample to reduce the resolution.
        contour = contour.getResampledBySpacing(5);
        
        float interpolatedIndex = offset * contour.size();
        
        ofPoint position = contour.getPointAtIndexInterpolated(interpolatedIndex); 
        ofPoint normal = contour.getNormalAtIndexInterpolated(interpolatedIndex); 
        
        // Make a line pointing normal to the contour.
        ofPoint lineEnd = position - normal * 30;
        
        ofSetColor(ofColor::yellow);
        contour.draw();
            
        ofLine(position, lineEnd);
        ofCircle(lineEnd, 2);
        
    }
    
    
}