Beispiel #1
0
//--------------------------------------------------------------
void game2::draw(){
		
	if(debug){cout << endl << "****** START DRAW ******" << endl;}
	if(debug){timer1 = ofGetElapsedTimeMillis();}
	
	ofSetColor(255);
	ofNoFill();
	
	//______DRAW BACKGROUND
	if(debug){cout << "draw background" << endl;}
	//draw background, turns black on collision
	if(collision==true){
		ofBackground(20);
		if(debug){cout << "!COLLISION!" << endl;}
	}else{
		if(backgroundVid.isLoaded()){
			backgroundVid.draw(backgroundPos.x,backgroundPos.y,2560,1440);
		}
	}
	
	ofEnableAlphaBlending(); //turn on alpha channel

	//______DRAW ROCKET
	if(debug){cout << "draw rocket" << endl;}
	if(myRocket.vel.x!=0 && myRocket.vel.y!=0){
		angle = myRocket.rotateRocket();
	}
	if(abs(angle)>365){angle=0;}
	if(!angle){angle=0;}
	
	ofSetColor(255);
	ofPushMatrix();
		ofTranslate(myRocket.rocketPos.x, myRocket.rocketPos.y, 0);
		ofRotateZ(angle);	
		myRocket.draw();
//		ofNoFill();
//		ofSetColor(255,0,0);	
//		ofRect(-30,-40,rocketKillBox.width,rocketKillBox.height);
//		ofFill();
//		ofSetColor(200);
	ofPopMatrix();
	
	//______DRAW FISH
	if(debug){cout << "draw fish" << endl;}
	bool firstFish = true;
	ofVec2f prevFishPos;
	float xenoSpeed = 0.1;
	bool xenoOnOff = true;
	for(int i=0;i<fishes.size();i++){
		if(fishes[i].bFound == true){ //draw following fish
			prevFishPos = fishes[i].drawFollowing(myRocket.rocketPos, prevFishPos, angle, xenoSpeed, firstFish, xenoOnOff);
			firstFish = false;
			xenoSpeed += 0.02;
		}else{ //draw static fish
			fishes[i].drawStatic(myRocket.rocketPos);
		}
	}
	
	//______DRAW MONSTERS
	if(debug){cout << "draw monsters" << endl;}
	//draw monsters (only those that are visible in our view)
	for(int i=0;i<monsters.size();i++){
		//draw monster
		ofSetColor(255);
		monsters[i]->draw();
		//draw monster position
		ofSetColor(200);
		//ofDrawBitmapString(ofToString(monsters[i]->attraction+monsterSpeed),monsters[i]->pos.x+40,monsters[i]->pos.y+36);	
	}

	//______DRAW BORDER
	//draw border if we have reached the edge
	if(debug){cout << "draw border" << endl;}
	ofFill();
	if(moveRight==false){
		for(int i=0;i<40;i++){
			ofSetColor(0,0,0,15);
			ofRect((myRocket.rocketPos.x+100)+(i*10),-200,500,ofGetHeight()+400);
		}
	}
	else if(moveLeft==false){
		for(int i=0;i<40;i++){
			ofSetColor(0,0,0,15);
			ofRect((myRocket.rocketPos.x-100)-(i*10),-200,-500,ofGetHeight()+400);
		}
	}
	else if(moveUp==false){
		for(int i=0;i<40;i++){
			ofSetColor(0,0,0,15);
			ofRect(-200,(myRocket.rocketPos.y-70)-(i*7),ofGetWidth()+400,-500);
		}		
	}
	else if(moveDown==false){
		for(int i=0;i<40;i++){
			ofSetColor(0,0,0,15);
			ofRect(-200,(myRocket.rocketPos.y+70)+(i*7),ofGetWidth()+400,500);
		}			
	}else{
		//do nothing
	}
	
	ofDisableAlphaBlending(); //turn off alpha
	
	//______DRAW DEBUG STUFF
	ofSetColor(200);
	if(debug){
		ofDrawBitmapString("DIFFICULTY:"+ofToString((int)(monsterSpeed*100)),5,ofGetHeight()-115);
		ofDrawBitmapString("ANGLE:"+ofToString((int)angleCorr)+"' MIN:"+ofToString((int)angleMin)+" MAX:"+ofToString((int)angleMax),5,ofGetHeight()-100);
		ofDrawBitmapString("FAUX ROCKET POS: "+ofToString((int)myRocket.rocketFauxPos.x)+","+ofToString((int)myRocket.rocketFauxPos.y),5,ofGetHeight()-85);
		ofDrawBitmapString("BACKGROUND POS: "+ofToString((int)backgroundPos.x)+","+ofToString((int)backgroundPos.y),5,ofGetHeight()-70);
		ofDrawBitmapString("FRAME RATE: "+ofToString(ofGetFrameRate()),5,ofGetHeight()-55);
		ofDrawBitmapString("MONSTERS: "+ofToString(monsters.size()),5,ofGetHeight()-40);
		ofDrawBitmapString("COLLISION: "+ofToString(collision),5,ofGetHeight()-25);
		ofDrawBitmapString("REAL ROCKET POS: "+ofToString((int)myRocket.rocketPos.x)+","+ofToString((int)myRocket.rocketPos.y),5,ofGetHeight()-10);
	}
	
	if(debug){timer2 = ofGetElapsedTimeMillis();}
	if(debug){cout << "__ DRAW TIME (millis): " << (timer2-timer1) << endl;}
		
	
}
//----------------------------------------------------------------------------------
void ofxCvBlobFinder::draw(float x, float y, float w, float h) {

    // draw blobs
    //ofxCvContourFinder::draw(x, y, w, h);
    // scale blob
    float scalex = 0.0f;
    float scaley = 0.0f;

    if (_width != 0) {
        scalex = w / _width;
    }
    else {
        scalex = 1.0f;
    }

    if (_height != 0) {
        scaley = h / _height;
    }
    else {
        scaley = 1.0f;
    }


    ofSetPolyMode(OF_POLY_WINDING_NONZERO);
    // apply transformation
    glPushMatrix();
    glTranslatef(x, y, 0.0);
    glScalef(scalex, scaley, 0.0);


#define DRAW_BLOB_VECTOR(points) do{ \
        ofBeginShape(); \
        for(int i = 0; i < (points).size(); i++){ \
          ofVertex((points[i]).x, (points[i]).y); \
        } \
        ofEndShape(true); \
      } while(0)

    ofNoFill();
    for (int j = 0; j < blobz.size(); j++) {
        ofSetColor(0xFF0000);

        DRAW_BLOB_VECTOR( blobz[j].getPoints());

        ofSetColor(0x00FF00);
        DRAW_BLOB_VECTOR(blobz[j].getHullPoints());

        ofSetColor(0x0000FF);
        DRAW_BLOB_VECTOR( blobz[j].getApproxPoints());

        ofSetColor(0x00ffae);
        ofRectangle c = blobz[j].getBoundingBox();
        
        ostringstream s; 
        s << j << "Area = " << blobz[j].getArea();
        
        ofDrawBitmapString(s.str(), c.x, c.y);
        ofRect(c.x, c.y, c.width, c.height);
    }

    glPopMatrix();
}
Beispiel #3
0
//--------------------------------------------------------------
void testApp::draw(){
    if(red<bgRed){
        red += 1;
    }
    if(red>bgRed){
        red -= 1;
    }
    if (green < bgGreen){
        green += 1;
    }
    if (green > bgGreen){
        green -= 1;
    }
    if(blue < bgBlue)
    {
        blue += 1;
    }
    if(blue > bgBlue)
    {
        blue -= 1;
    }
    ofBackground(red,green,blue);

    ofEnableAlphaBlending();
	// draw the fft resutls:
	if(playingNow == 7)
    {
        ofSetColor(red*25+5,green*10+5,blue*18);
    }
    else if (playingNow == 8)
    {
        ofSetColor(green+27,blue*2+55,red*0);
    }
    else
    {
        ofSetColor(blue,red,green);
    }
	float width = (float)(5*1024) / nBandsToGet;

	if(fftStyle == 2)
    {
	for (int i = 0;i < nBandsToGet; i++){
		// (we use negative height here, because we want to flip them
		// because the top corner is 0,0)
		ofRect(i*width,ofGetHeight(),width,-(fftSmoothed[i] * 800));
		ofRect(i*width,0,width,(fftSmoothed[i] * 800));
		ofRect(ofGetWidth()-i*width,0,width,(fftSmoothed[i] * 800));
		ofRect(ofGetWidth()-i*width,ofGetHeight(),width,-(fftSmoothed[i] * 800));
	}
        red = red + (float)fftSmoothed[8]/2;
        green = green + (float)fftSmoothed[8]/2;
        blue = blue + (float)fftSmoothed[8]/2;
    }

    if(fftStyle == 1)
    {
        for (int i = 0;i < nBandsToGet; i++){
		// (we use negative height here, because we want to flip them
		// because the top corner is 0,0)
		ofRect((ofGetWidth()/2)+(i*width),ofGetHeight()/2,width,-(fftSmoothed[i] * 400));
		ofRect((ofGetWidth()/2)+(i*width),ofGetHeight()/2,width,(fftSmoothed[i] * 400));
		ofRect((ofGetWidth()/2-i*width),ofGetHeight()/2,width,(fftSmoothed[i] * 400));
		ofRect((ofGetWidth()/2-i*width),ofGetHeight()/2,width,-(fftSmoothed[i] * 400));
	}
        red = red + (float)fftSmoothed[8]/2;
        green = green + (float)fftSmoothed[8]/2;
        blue = blue + (float)fftSmoothed[8]/2;
    }

    if(fftStyle == 3)
    {
        for (int i = 0;i < nBandsToGet; i++){
        ofRect(i*width,ofGetHeight(),width,-(fftSmoothed[i] * 200));
		ofRect(i*width,ofGetHeight()/2,width,(fftSmoothed[i] * 200));
		ofRect(ofGetWidth()-i*width,ofGetHeight()/2,width,(fftSmoothed[i] * 200));
		ofRect(ofGetWidth()-i*width,ofGetHeight(),width,-(fftSmoothed[i] * 200));

		ofRect((ofGetWidth()/2)+(i*width),ofGetHeight(),width,-(fftSmoothed[i] * 400));
		ofRect((ofGetWidth()/2)+(i*width),ofGetHeight()/2,width,(fftSmoothed[i] * 400));
		ofRect((ofGetWidth()/2-i*width),ofGetHeight()/2,width,(fftSmoothed[i] * 400));
		ofRect((ofGetWidth()/2-i*width),ofGetHeight(),width,-(fftSmoothed[i] * 400));
        }
        red = red + (float)fftSmoothed[8]/2;
        green = green + (float)fftSmoothed[8]/2;
        blue = blue + (float)fftSmoothed[8]/2;
    }

    ofDisableAlphaBlending();
	// finally draw the playing circle:

	ofEnableAlphaBlending();

        if(playingNow == 7)
        {
            ofSetColor(red*25+5,green*10+5,blue*18,100);
        }

        else if (playingNow == 8)
        {
            ofSetColor(green+27,blue*2+55,red*0,100);
        }
        else
        {
            ofSetColor(green,blue,red,100);
        }

		float circleWidth = (float)(5*1024) / nBandsToGet;

		if (fftStyle == 2 || fftStyle == 1)
        {
            int j = 1;
            for (int i = 0;i < nBandsToGet; i++){
                if(j == 1){
                    ofCircle(ofGetWidth()/4, ofGetHeight()/4,-(fftSmoothed[i] * 100));
                    j++;
                }
                else if(j == 2)
                {
                    ofCircle((3*ofGetWidth())/4,ofGetHeight()/4,-(fftSmoothed[i] * 100));
                    j++;
                }
                else if(j == 3)
                {
                    ofCircle(ofGetWidth()/4, (3*ofGetHeight())/4,-(fftSmoothed[i] * 100));
                    j++;
                }
                else if(j == 4)
                {
                    ofCircle((3*ofGetWidth())/4, (3*ofGetHeight())/4,-(fftSmoothed[i] * 100));
                    j=1;
                }
            }
        }

        if(fftStyle == 3)
        {
            int j = 1;
            for (int i = 0;i < nBandsToGet; i++){

                if (j == 1)
                {
                    ofCircle(ofRandom((ofGetWidth()/4)-10,(ofGetWidth()/4)+10), ofRandom((ofGetHeight()/4)-10, (ofGetHeight()/4)+10),-(fftSmoothed[i] * 75));
                    j++;
                }

                if (j == 2)
                {
                    ofCircle(ofRandom(((3*ofGetWidth())/4)-10,((3*ofGetWidth())/4)+10),ofRandom((ofGetHeight()/4)-10,(ofGetHeight()/4)+10),-(fftSmoothed[i] * 75));
                    j=1;
                }

            }
        }
		//ofCircle(px, py,50);
	ofDisableAlphaBlending();

	ofSetHexColor(0xffffff);
	ofDrawBitmapString("Fps: "+ ofToString(ofGetFrameRate()), 15,15);
	ofDrawBitmapString("Song: "+ ofToString(song),15,30);
	ofDrawBitmapString("Artist: "+ofToString(artist),15,45);
	ofDrawBitmapString("Press H for help",15,75);

    if(help == true)
    {
        ofDrawBitmapString("Quit Visualizer: ESC",15,90);
        ofDrawBitmapString("Change Song: A or D",15,105);
        ofDrawBitmapString("Change Visualization: 1, 2, or 3",15,120);
        ofDrawBitmapString("1: Rorschach",15,135);
        ofDrawBitmapString("2: Sludge Pit",15,150);
        ofDrawBitmapString("3: Closet Monster",15,165);
    }
	//ofCircle(px, py,8);
}
//--------------------------------------------------------------
void testApp::draw(){

	//--------------------------- circles
	//let's draw a circle:
	ofSetColor(255,130,0);
	float radius = 50 + 10 * sin(counter);
	ofFill();		// draw "filled shapes"
	ofCircle(100,400,radius);

	// now just an outline
	ofNoFill();
	ofSetColor(0xCCCCCC);
	ofCircle(100,400,80);

	// use the bitMap type
	// note, this can be slow on some graphics cards
	// because it is using glDrawPixels which varies in
	// speed from system to system.  try using ofTrueTypeFont
	// if this bitMap type slows you down.
	ofSetColor(0x000000);
	ofDrawBitmapString("circle", 75,500);


	//--------------------------- rectangles
	ofFill();
	for (int i = 0; i < 200; i++){
		ofSetColor((int)ofRandom(0,255),(int)ofRandom(0,255),(int)ofRandom(0,255));
		ofRect(ofRandom(250,350),ofRandom(350,450),ofRandom(10,20),ofRandom(10,20));
	}
	ofSetColor(0x000000);
	ofDrawBitmapString("rectangles", 275,500);

	//---------------------------  transparency
	ofSetColor(0x00FF33);
	ofRect(400,350,100,100);
	// alpha is usually turned off - for speed puposes.  let's turn it on!
	ofEnableAlphaBlending();
	ofSetColor(255,0,0,127);   // red, 50% transparent
	ofRect(450,430,100,33);
	ofSetColor(255,0,0,(int)(counter * 10.0f) % 255);   // red, variable transparent
	ofRect(450,370,100,33);
	ofDisableAlphaBlending();

	ofSetColor(0x000000);
	ofDrawBitmapString("transparency", 410,500);

	//---------------------------  lines
	// a bunch of red lines, make them smooth if the flag is set

	if (bSmooth){
		ofEnableSmoothing();
	}

	ofSetColor(0xFF0000);
	for (int i = 0; i < 20; i++){
		ofLine(600,300 + (i*5),800, 250 + (i*10));
	}

	if (bSmooth){
		ofDisableSmoothing();
	}

	ofSetColor(0x000000);
	ofDrawBitmapString("lines\npress 's' to toggle smoothness", 600,500);

}
//--------------------------------------------------------------
void testApp::draw(){

	ofSetColor(255, 255, 255);

	//glPushMatrix();
	//glScalef(0.75, 0.75, 0.75);

	//recordDepth.draw(0,0,640,480);
	//baseDepth.draw(640, 0, 640, 480);
	
	colorDepthImage.draw(0, 0, 1024, 768);
	//depthBaseMask.draw(640, 0, 640, 480);

	//glPopMatrix();

	ofSetColor(255, 255, 0);

	string statusBaseline	= (string)(isBaselineSet ? "BASELINE SET" : "BASELINE NOT SET");
/*	string statusRec		= (string)(!isRecording ? "READY" : "RECORDING");
	string statusSkeleton	= "";//(string)(isTracking ? "TRACKING USERS: " + (string)(isLive ? ofToString(recordUser.getNumberOfTrackedUsers()) : ofToString(playUser.getNumberOfTrackedUsers())) + "" : "NOT TRACKING USERS");
	string statusSmoothSkel = "";//(string)(isLive ? ofToString(recordUser.getSmoothing()) : ofToString(playUser.getSmoothing()));
	string statusHands		= "";//(string)(isTrackingHands ? "TRACKING HANDS: " + (string)(isLive ? ofToString(recordHandTracker.getNumTrackedHands()) : ofToString(playHandTracker.getNumTrackedHands())) + ""  : "NOT TRACKING");
	string statusFilter		= (string)(isFiltering ? "FILTERING" : "NOT FILTERING");
	string statusFilterLvl	= "";//ofToString(filterFactor);
	string statusSmoothHand = "";//(string)(isLive ? ofToString(recordHandTracker.getSmoothing()) : ofToString(playHandTracker.getSmoothing()));
	string statusMask		= (string)(!isMasking ? "HIDE" : (isTracking ? "SHOW" : "YOU NEED TO TURN ON TRACKING!!"));
	string statusCloud		= (string)(isCloud ? "ON" : "OFF");
	string statusCloudData	= (string)(isCPBkgnd ? "SHOW BACKGROUND" : (isTracking ? "SHOW USER" : "YOU NEED TO TURN ON TRACKING!!"));
*/
	string statusHardware;

#ifdef TARGET_OSX // only working on Mac at the moment
	ofPoint statusAccelerometers = hardware.getAccelerometers();
	stringstream	statusHardwareStream;

	statusHardwareStream
	<< "ACCELEROMETERS:"
	<< " TILT: " << hardware.getTiltAngle() << "/" << hardware.tilt_angle
	<< " x - " << statusAccelerometers.x
	<< " y - " << statusAccelerometers.y
	<< " z - " << statusAccelerometers.z;

	statusHardware = statusHardwareStream.str();
#endif

	stringstream msg;

	msg
//	<< "    s : start/stop recording  : " << statusRec << endl
	<< "    0 : set new baseline	  : " << statusBaseline << endl
/*	<< "    t : skeleton tracking     : " << statusSkeleton << endl
	<< "( / ) : smooth skely (openni) : " << statusSmoothSkel << endl
	<< "    h : hand tracking         : " << statusHands << endl
	<< "    f : filter hands (custom) : " << statusFilter << endl
	<< "[ / ] : filter hands factor   : " << statusFilterLvl << endl
	<< "; / ' : smooth hands (openni) : " << statusSmoothHand << endl
	<< "    m : drawing masks         : " << statusMask << endl
	<< "    c : draw cloud points     : " << statusCloud << endl
	<< "    b : cloud user data       : " << statusCloudData << endl
*/	<< "- / + : nearThreshold         : " << ofToString(nearThreshold) << endl
	<< "< / > : farThreshold          : " << ofToString(farThreshold) << endl
	<< endl
//	<< "File  : " << oniRecorder.getCurrentFileName() << endl
	<< "FPS   : " << ofToString(ofGetFrameRate()) << "  " << statusHardware << endl;

	ofDrawBitmapString(msg.str(), 20, 700);

}
Beispiel #6
0
void ofApp::draw()
{
    ofBackground(0,0,0);

    ofSetHexColor(0xffffff);
    
    int row = 0;
    int col = 0;
    
    int x = 0;
    int y = 0;
    
    int w = ofGetWidth() / NUM_COLS;
    int h = ofGetHeight() / NUM_ROWS;
    
    float totalKbps = 0;
    float totalFPS = 0;
    
    for (std::size_t i = 0; i < grabbers.size(); ++i)
    {
        x = col * w;
        y = row * h;

        // draw in a grid
        row = (row + 1) % NUM_ROWS;

        if (row == 0)
        {
            col = (col + 1) % NUM_COLS;
        }

        
        ofPushMatrix();
        ofTranslate(x,y);
        ofSetColor(255,255,255,255);
        grabbers[i]->draw(0,0,w,h); // draw the camera
        
        ofEnableAlphaBlending();
        
        // draw the info box
        ofSetColor(0,80);
        ofDrawRectangle(5,5,w-10,h-10);
        
        float kbps = grabbers[i]->getBitRate() / 1000.0f; // kilobits / second, not kibibits / second
        totalKbps+=kbps;
        
        float fps = grabbers[i]->getFrameRate();
        totalFPS+=fps;
        
        std::stringstream ss;
        
        // ofToString formatting available in 0072+
        ss << "          NAME: " << grabbers[i]->getCameraName() << endl;
        ss << "          HOST: " << grabbers[i]->getHost() << endl;
        ss << "           FPS: " << ofToString(fps,  2/*,13,' '*/) << endl;
        ss << "          Kb/S: " << ofToString(kbps, 2/*,13,' '*/) << endl;
        ss << " #Bytes Recv'd: " << ofToString(grabbers[i]->getNumBytesReceived(),  0/*,10,' '*/) << endl;
        ss << "#Frames Recv'd: " << ofToString(grabbers[i]->getNumFramesReceived(), 0/*,10,' '*/) << endl;
        ss << "Auto Reconnect: " << (grabbers[i]->getAutoReconnect() ? "YES" : "NO") << endl;
        ss << " Needs Connect: " << (grabbers[i]->getNeedsReconnect() ? "YES" : "NO") << endl;
        ss << "Time Till Next: " << grabbers[i]->getTimeTillNextAutoRetry() << " ms" << endl;
        ss << "Num Reconnects: " << ofToString(grabbers[i]->getReconnectCount()) << endl;
        ss << "Max Reconnects: " << ofToString(grabbers[i]->getMaxReconnects()) << endl;
        ss << "  Connect Fail: " << (grabbers[i]->hasConnectionFailed() ? "YES" : "NO") << endl;
        // display neuraltalk's caption
        ss << "       Caption: " << description << endl;

        ofSetColor(255);
        ofDrawBitmapString(ss.str(), 10, 10+12);
        
        ofDisableAlphaBlending();
        
        ofPopMatrix();
    }
    
    // keep track of some totals
    float avgFPS = totalFPS / NUM_CAMERAS;
    float avgKbps = totalKbps / NUM_CAMERAS;

    ofEnableAlphaBlending();
    ofSetColor(0,80);
    ofDrawRectangle(5,5, 150, 40);
    
    ofSetColor(255);
    // ofToString formatting available in 0072+
    ofDrawBitmapString(" AVG FPS: " + ofToString(avgFPS,2/*,7,' '*/), 10,17);
    ofDrawBitmapString("AVG Kb/S: " + ofToString(avgKbps,2/*,7,' '*/), 10,29);
    ofDrawBitmapString("TOT Kb/S: " + ofToString(totalKbps,2/*,7,' '*/), 10,41);
    ofDisableAlphaBlending();

}
Beispiel #7
0
//--------------------------------------------------------------
void testApp::draw() {

	ofSetColor(255, 255, 255);

	if(bDrawPointCloud) {
		ofPushMatrix();
		ofTranslate(420, 320);
		// we need a proper camera class
		drawPointCloud();
		ofPopMatrix();
	}
    else {
		if(!bPlayback) {
			// draw from the live kinect
			kinect.drawDepth(10, 10, 400, 300);
			kinect.draw(420, 10, 400, 300);
		}
        else {
			// draw from the player
			kinectPlayer.drawDepth(10, 10, 400, 300);
			kinectPlayer.draw(420, 10, 400, 300);
		}

		grayImage.draw(10, 320, 400, 300);
		contourFinder.draw(10, 320, 400, 300);
	
        #ifdef USE_TWO_KINECTS
        kinect2.draw(420, 320, 400, 300);
        #endif
    }

	// draw recording/playback indicators
	ofPushMatrix();
	ofTranslate(25, 25);
	ofFill();
	if(bRecord) {
		ofSetColor(255, 0, 0);
		ofCircle(0, 0, 10);
	}
	if(bPlayback) {
		ofSetColor(0, 255, 0);
		ofTriangle(-10, -10, -10, 10, 10, 0);
	}
	ofPopMatrix();


	// draw instructions
	ofSetColor(255, 255, 255);
	stringstream reportStream;
	reportStream << "accel is: " << ofToString(kinect.getMksAccel().x, 2) << " / "
								 << ofToString(kinect.getMksAccel().y, 2) << " / "
								 << ofToString(kinect.getMksAccel().z, 2) << endl
				 << "press p to switch between images and point cloud, rotate the point cloud with the mouse" << endl
				 << "using opencv threshold = " << bThreshWithOpenCV <<" (press spacebar)" << endl
				 << "set near threshold " << nearThreshold << " (press: + -)" << endl
				 << "set far threshold " << farThreshold << " (press: < >) num blobs found " << contourFinder.nBlobs
				 	<< ", fps: " << ofGetFrameRate() << endl
				 << "press c to close the connection and o to open it again, connection is: " << kinect.isConnected() << endl
				 << "press UP and DOWN to change the tilt angle: " << angle << " degrees" << endl
				 << "press r to record and q to playback, record is: " << bRecord << ", playback is: " << bPlayback;
	ofDrawBitmapString(reportStream.str(),20,652);
}
Beispiel #8
0
//--------------------------------------------------------------
void testApp::draw()
{
	
	ofSetHexColor(0xA4A4A4);
	ofRect(720, 15, 720, 450);
	grayImage.draw(715, 20, 715, 445);
	
	ofSetHexColor(0xA4A4A4);
	ofRect(10, 15, 720, 450);
	ofSetHexColor(0xA4A4A4);
	ofSetColor(22, 22, 22);
	grayImage.draw(10, 20, 715, 445);
    contourFinder.draw(10, 20, 715, 445);
	
	ofSetHexColor(0xFFFFFF);
	ofDrawBitmapString("accel is: " + ofToString(kinect.getMksAccel().x, 2) + " / " 
									+ ofToString(kinect.getMksAccel().y, 2) + " / "
									+ ofToString(kinect.getMksAccel().z, 2), 20, 458 );
	
	
	static ofxVec3f newPoint;
	if(contourFinder.blobs.size() == 1) {
		ofxCvBlob &blob = contourFinder.blobs[0];
		grayThreshFar.setROI(blob.boundingRect);
		double minValue, maxValue;
		CvPoint minLoc, maxLoc;
		cvMinMaxLoc(grayThreshFar.getCvImage(), &minValue, &maxValue, &minLoc, &maxLoc, NULL);
		grayThreshFar.resetROI();
		newPoint.x = maxLoc.x + blob.boundingRect.x;
		newPoint.y = maxLoc.y + blob.boundingRect.y;
		
		float accelX = kinect.getMksAccel().x;
		float accelY = kinect.getMksAccel().y;
		
		ofxOscMessage m;
		m.setAddress( "/mouse/position" );		
		m.addIntArg( newPoint.x );
		m.addIntArg( newPoint.y );
		m.addFloatArg(accelX);
		m.addFloatArg(accelY);
		sender.sendMessage( m );
		
		// when in the "beat" region:
		synth.setSpeed(0.3f + ((float)(ofGetHeight() - newPoint.y) / (float)ofGetHeight())*0.8f);
		synth.setPosition(0.0f + ((float)(ofGetHeight() - newPoint.x) / (float)ofGetHeight())*1.0f);
		
	}

	if (contourFinder.blobs.size()==3) {
		synth.setLoop(true);
		synth.play();		
		synth.setSpeed(1.0f);

	}
	
	if (contourFinder.blobs.size()==4) {
		ofxOscMessage h;
		h.setAddress("/reset");
		h.addStringArg("yes");
		sender.sendMessage(h);
	}
	
	//---------------------------  transparency
	ofSetHexColor(0x00FF33);
	//ofRect(newPoint.x,newPoint.y,100,100);
		
	char reportStr[1024];
	//printf("esto es %i", bThreshWithOpenCV);
	sprintf(reportStr, "probando Opencv+ kinect = %i (s)\nset umbral cercano %i (press: + -)\nset umbral lejano %i (press: < >) num blobs econtrados %i, fps: %f movidax: %f",bThreshWithOpenCV, nearThreshold, farThreshold, contourFinder.nBlobs, ofGetFrameRate()), newPoint.x;
	ofDrawBitmapString(reportStr, 20, 690);
}
Beispiel #9
0
//--------------------------------------------------------------
void ofApp::draw(){

	ofSetColor(225);
	ofNoFill();
	
    float chSz = bufferSize/3;
	// draw the left input channel:
	{
        ofPushStyle();
        ofPushMatrix();
        ofTranslate(100, 15, 0);
        ofSetColor(225);
        ofDrawBitmapString("Left Channel", 4, 18);
        ofSetLineWidth(1);
        ofRect(0, 0, chSz, 200);
        ofSetColor(ofColor::orange);
        ofSetLineWidth(3);
        ofBeginShape();
        for (int i = 0; i < bufferSize; i++){
            ofVertex(i/(bufferSize/chSz), 100 - filterBank.getLeftBuffer()[i]*45);
        }
        ofEndShape(false);
        ofPopMatrix();
        ofPopStyle();
	}
	// draw the right input channel:
	{
        ofPushStyle();
		ofPushMatrix();
		ofTranslate(200+chSz, 15, 0);
		ofSetColor(225);
		ofDrawBitmapString("Right Channel", 4, 18);
		ofSetLineWidth(1);
		ofRect(0, 0, chSz, 200);
		ofSetColor(ofColor::orange);
		ofSetLineWidth(3);
        ofBeginShape();
        for (int i = 0; i < bufferSize; i++){
            ofVertex(i/(bufferSize/chSz), 100 - filterBank.getRightBuffer()[i]*45);
        }
        ofEndShape(false);
		ofPopMatrix();
        ofPopStyle();
	}
    
	//Draw FilterBank
	{
        ofPushStyle();
        ofPushMatrix();
        ofTranslate (100,250,0);
            filterBank.draw(800,400);
        ofPopMatrix();
        ofPopStyle();
	}
	ofSetColor(225);

	string reportString =  "Sampling Rate: "+ ofToString(SR) +"\nBuffer size: "+ ofToString(bufferSize);
	ofDrawBitmapString(reportString, 10, 700);


}
Beispiel #10
0
//--------------------------------------------------------------
void ofApp::draw(){
    // sphere animation
    ofPushStyle();
    ofEnableDepthTest();
    ofEnableLighting();
    light.enable();
    ofSetHexColor(0xcccccc);
    ofSpherePrimitive sphere;
    sphere.setRadius(sin(ofGetElapsedTimef() * 4.0) * 100 + 200);
    sphere.setResolution(mouseX / 2.0);
    sphere.setPosition(ofGetWidth()/2, ofGetHeight()/2, 0);
    sphere.drawWireframe();
    ofDisableLighting();
    ofDisableDepthTest();
    ofPopStyle();
    
    // stats
    ofPushStyle();
    ofPushMatrix();
    ofTranslate(left, top);
    ofEnableAlphaBlending();
    
    ofSetColor(0, 0, 0, 204);
    ofRect(0, 0, width, height);
    float scale = float(height - 14 - padding*2) / maxValue;
    
    if (mode == 0) { // FPS
        ofSetHexColor(0x00ffff);
        
        ofBeginShape();
        ofVertex(width-padding, height-padding);
        for (int i = 0; i < fpsList.size(); i++) {
            float length = fpsList[i] * scale;
            if (length > height) {
                length = height;
            }
            ofVertex(width - padding - i, height - padding - length);
        }
        ofVertex(width - padding - fpsList.size() + 1, height - padding);
        ofEndShape();
        
        ofSetColor(0, 0, 0, 204);
        ofRect(0, 0, width, 14);
        ofSetHexColor(0x00ffff);
        ofDrawBitmapString(ofToString(curretFps, 0) + " fps", 2, 11);
    }
    if (mode == 1) { // MS
        ofSetHexColor(0x00ff00);
        
        ofBeginShape();
        ofVertex(width-padding, height-padding);
        for (int i = 0; i < msList.size(); i++) {
            float length = msList[i] * scale;
            if (length > height) {
                length = height;
            }
            ofVertex(width - padding - i, height - padding - length);
        }
        ofVertex(width - padding - msList.size() + 1, height - padding);
        ofEndShape();
        
        ofSetColor(0, 0, 0, 204);
        ofRect(0, 0, width, 14);
        ofSetHexColor(0x00ff00);
        ofDrawBitmapString(ofToString(currentMs, 0) + " ms", 2, 11);
    }
    
    ofPopMatrix();
    ofPopStyle();
}
Beispiel #11
0
//--------------------------------------------------------------
void testApp::draw(){

	ofSetColor(255, 255, 255);

	glPushMatrix();
	glScalef(0.75, 0.75, 0.75);

	if (isLive) {

		recordDepth.draw(0,0,640,480);
		recordImage.draw(640, 0, 640, 480);

		depthRangeMask.draw(0, 480, 320, 240);	// can use this with openCV to make masks, find contours etc when not dealing with openNI 'User' like objects
        
        opFlow.draw(640,480);
        
		if (isTracking) {
			recordUser.draw();

			if (isMasking) drawMasks();
			if (isCloud) drawPointCloud(&recordUser, 1);	// 0 gives you all point clouds; use userID to see point clouds for specific users
            
            if(!isPlaying){
                midiOut.sendControlChange(synthChan, 92, 127);
                midiOut.sendControlChange(effectsChan, 92, 127);
                //midiOut.sendControlChange(synthChan, 90, 127);

                isPlaying = true;
            }
            
            for(int i = 1; i == recordUser.getNumberOfTrackedUsers(); i++)
            {
                ofxTrackedUser* currentUser = recordUser.getTrackedUser(i);
                
                if(currentUser != NULL){
                    if(currentUser->skeletonTracking)
                    
                        xPadSynth = ofMap(currentUser->left_lower_arm.position[1].X, 0, ofGetWidth()/1.5, 0, 127);
                        yPadSynth = ofMap(currentUser->left_lower_arm.position[1].Y, 0, ofGetHeight()/1.5, 127, 0);
                        xPadEffects = ofMap(currentUser->right_lower_arm.position[1].X, 0, ofGetWidth()/1.5, 0, 127);
                        yPadEffects = ofMap(currentUser->right_lower_arm.position[1].Y, 0, ofGetWidth()/1.5, 127, 0);
                        
                        midiOut.sendControlChange(synthChan, 12, xPadSynth);
                        midiOut.sendControlChange(synthChan, 13, yPadSynth);
                        midiOut.sendControlChange(effectsChan, 12, xPadEffects);
                        midiOut.sendControlChange(effectsChan, 13, yPadEffects);
                }

                
                
                                /*ofxLimb leftArm = recordUser.getTrackedUser(i)->left_lower_arm;
        
                xPadSynth = ofMap(rightArm.position[1].X, 0, ofGetWidth()/1.5, 0, 127);
                yPadSynth = ofMap(rightArm.position[1].Y, 0, ofGetHeight()/1.5, 127, 0);
                xPadEffects = ofMap(leftArm.position[1].X, 0, ofGetWidth()/1.5, 0, 127);
                yPadEffects = ofMap(leftArm.position[1].Y, 0, ofGetWidth()/1.5, 0, 127);

                midiOut.sendControlChange(synthChan, 12, xPadSynth);
                midiOut.sendControlChange(synthChan, 13, yPadSynth);
                midiOut.sendControlChange(effectsChan, 12, xPadEffects);
                midiOut.sendControlChange(effectsChan, 13, yPadEffects);*/
                 
            
            }

		} else {
            if(isPlaying){
                midiOut.sendControlChange(synthChan, 92, 0);
                midiOut.sendControlChange(effectsChan, 92, 0);
                //midiOut.sendControlChange(synthChan, 90, 0);

                isPlaying = false;
            }
        }
        
		if (isTrackingHands)
        {
			recordHandTracker.drawHands();
        }

	} else {

		playDepth.draw(0,0,640,480);
		playImage.draw(640, 0, 640, 480);

		depthRangeMask.draw(0, 480, 320, 240);	// can use this with openCV to make masks, find contours etc when not dealing with openNI 'User' like objects

		if (isTracking) {
			playUser.draw();

			if (isMasking) drawMasks();
			if (isCloud) drawPointCloud(&playUser, 0);	// 0 gives you all point clouds; use userID to see point clouds for specific users

		}
		if (isTrackingHands)
			playHandTracker.drawHands();
	}

	glPopMatrix();

	ofSetColor(255, 255, 0);

	string statusPlay		= (string)(isLive ? "LIVE STREAM" : "PLAY STREAM");
	string statusRec		= (string)(!isRecording ? "READY" : "RECORDING");
	string statusSkeleton	= (string)(isTracking ? "TRACKING USERS: " + (string)(isLive ? ofToString(recordUser.getNumberOfTrackedUsers()) : ofToString(playUser.getNumberOfTrackedUsers())) + "" : "NOT TRACKING USERS");
	string statusSmoothSkel = (string)(isLive ? ofToString(recordUser.getSmoothing()) : ofToString(playUser.getSmoothing()));
	string statusHands		= (string)(isTrackingHands ? "TRACKING HANDS: " + (string)(isLive ? ofToString(recordHandTracker.getNumTrackedHands()) : ofToString(playHandTracker.getNumTrackedHands())) + ""  : "NOT TRACKING");
	string statusFilter		= (string)(isFiltering ? "FILTERING" : "NOT FILTERING");
	string statusFilterLvl	= ofToString(filterFactor);
	string statusSmoothHand = (string)(isLive ? ofToString(recordHandTracker.getSmoothing()) : ofToString(playHandTracker.getSmoothing()));
	string statusMask		= (string)(!isMasking ? "HIDE" : (isTracking ? "SHOW" : "YOU NEED TO TURN ON TRACKING!!"));
	string statusCloud		= (string)(isCloud ? "ON" : "OFF");
	string statusCloudData	= (string)(isCPBkgnd ? "SHOW BACKGROUND" : (isTracking ? "SHOW USER" : "YOU NEED TO TURN ON TRACKING!!"));

	string statusHardware;

#ifdef TARGET_OSX // only working on Mac at the moment
	ofPoint statusAccelerometers = hardware.getAccelerometers();
	stringstream	statusHardwareStream;

	statusHardwareStream
	<< "ACCELEROMETERS:"
	<< " TILT: " << hardware.getTiltAngle() << "/" << hardware.tilt_angle
	<< " x - " << statusAccelerometers.x
	<< " y - " << statusAccelerometers.y
	<< " z - " << statusAccelerometers.z;

	statusHardware = statusHardwareStream.str();
#endif

	stringstream msg;

	msg
	<< "    s : start/stop recording  : " << statusRec << endl
	<< "    p : playback/live streams : " << statusPlay << endl
	<< "    t : skeleton tracking     : " << statusSkeleton << endl
	<< "( / ) : smooth skely (openni) : " << statusSmoothSkel << endl
	<< "    h : hand tracking         : " << statusHands << endl
	<< "    f : filter hands (custom) : " << statusFilter << endl
	<< "[ / ] : filter hands factor   : " << statusFilterLvl << endl
	<< "; / ' : smooth hands (openni) : " << statusSmoothHand << endl
	<< "    m : drawing masks         : " << statusMask << endl
	<< "    c : draw cloud points     : " << statusCloud << endl
	<< "    b : cloud user data       : " << statusCloudData << endl
	<< "- / + : nearThreshold         : " << ofToString(nearThreshold) << endl
	<< "< / > : farThreshold          : " << ofToString(farThreshold) << endl
	<< endl
	<< "File  : " << oniRecorder.getCurrentFileName() << endl
	<< "FPS   : " << ofToString(ofGetFrameRate()) << "  " << statusHardware << endl;

	ofDrawBitmapString(msg.str(), 20, 560);
    
    
    stringstream midiText;
	midiText << "connected to port " << midiOut.getPort() 
    << " \"" << midiOut.getName() << "\"" << endl
    << "is virtual?: " << midiOut.isVirtual() << endl << endl
    << "sending to channel " << channel << endl << endl
    << "current program: " << currentPgm << endl << endl
    << "note: " << note << endl
    << "velocity: " << velocity << endl
    << "Xsynth: " << xPadSynth << endl
    << "Ysynth: " << yPadSynth << endl
    << "Xeffects: " << xPadSynth << endl
    << "Yeffects: " << yPadSynth << endl
    << "touch: " << touch << endl
    << "polytouch: " << polytouch;
	ofDrawBitmapString(midiText.str(), 700, 560);

}
void ofxComposer::customDraw(){
    ofPushView();
    ofPushStyle();
    ofPushMatrix();

    ofEnableAlphaBlending();
    
#ifdef USE_OFXGLEDITOR
    //  Draw the GLEditor if it�s not inside a Patch
    //
    if (bEditMode && !bGLEditorPatch){
        ofPushMatrix();
        ofRotate(180, 1, 0, 0);
        ofTranslate(0, -ofGetWindowHeight());
        ofSetColor(editorFgColor);
        editorFbo.draw(0, 0);
        ofPopMatrix();
    }
#endif
    
    //  Draw Patches
    //
    for(map<int,patch*>::iterator it = patches.begin(); it != patches.end(); it++ ){
        it->second->customDraw();
    }
    
    //  Draw active line
    //
    //mili
    ofVec3f mouse_transformed = ofVec3f(ofGetMouseX(), ofGetMouseY(), 0.0)*this->getGlobalTransformMatrix();
    //
    if (selectedDot >= 0){
        ofLine(patches[selectedDot]->getOutPutPosition(), ofPoint(mouse_transformed.x,mouse_transformed.y));
    }
    
    //mili - nodes aligned
    ofVec3f scale = ((ofCamera*)this->getParent())->getScale();
    if (verticalAlign1) {
        ofSetColor(255, 208, 111);
        ofLine(verticalAlign1, 0, verticalAlign1, ofGetHeight()*scale.y);
    }
    if (verticalAlign2) {
        ofSetColor(255, 208, 111);
        ofLine(verticalAlign2, 0, verticalAlign2, ofGetHeight()*scale.y);
    }
    if (verticalAlign3) {
        ofSetColor(255, 208, 111);
        ofLine(verticalAlign3, 0, verticalAlign3, ofGetHeight()*scale.y);
    }
    if (horizontalAlign1) {
        ofSetColor(255, 208, 111);
        ofLine(0, horizontalAlign1, ofGetWidth()*scale.x, horizontalAlign1);
    }
    if (horizontalAlign2) {
        ofSetColor(255, 208, 111);
        ofLine(0, horizontalAlign2, ofGetWidth()*scale.x, horizontalAlign2);
    }
    if (horizontalAlign3) {
        ofSetColor(255, 208, 111);
        ofLine(0, horizontalAlign3, ofGetWidth()*scale.x, horizontalAlign3);
    }
    //
        
    //  Draw Help screen
    //
    if (bHelp){
        ofSetColor(255);
        ofDrawBitmapString(helpScreen, 20, ofGetWindowHeight()*0.5- 11.0*15.0);
    }
    
    ofDisableBlendMode();
    ofEnableAlphaBlending();

    ofPopMatrix();
    ofPopStyle();
    ofPopView();
    
    
    // nico multipleSelect
    ofPushMatrix();
        ofNoFill();
        ofRect(multipleSelectRectangle);
    ofPopMatrix();
    
}
//-------------------------------
void ofxControlPanel::draw(){
    if( hidden ) return;

    ofPushStyle();
    ofEnableAlphaBlending();

        float panelH = boundingBox.height;
        if( minimize ){
            panelH = topBar.height;
        }

        glPushMatrix();
            glTranslatef(boundingBox.x, boundingBox.y, 0);
            //draw the background
            ofFill();
            glColor4fv(bgColor.getColorF());
            ofRect(0, 0, boundingBox.width, panelH);

            //draw the outline
            ofNoFill();
            glColor4fv(outlineColor.getColorF());
            ofRect(0, 0, boundingBox.width, panelH);
            ofLine(0, topBar.height, boundingBox.width, topBar.height);
        glPopMatrix();

        ofRect(minimizeButton.x, minimizeButton.y, minimizeButton.width, minimizeButton.height);

	if ( bDoSaveRestore )
	{
        ofPushStyle();
            ofFill();

            if( saveDown )glColor4fv(fgColor.getSelectedColorF());
            else glColor4fv(fgColor.getColorF());

            ofRect(saveButton.x, saveButton.y, saveButton.width,saveButton.height);
            ofSetColor(255, 255, 255);
		if(bUseTTFFont) {
			guiTTFFont.drawString("save", saveButton.x + 3, saveButton.y + saveButton.height -4);
		}
		else {
			ofDrawBitmapString("save", saveButton.x + 3, saveButton.y + saveButton.height -3);
		}

        ofPopStyle();

        ofPushStyle();
            ofFill();

            if( restoreDown )glColor4fv(fgColor.getSelectedColorF());
            else glColor4fv(fgColor.getColorF());

            ofRect(restoreButton.x, restoreButton.y, restoreButton.width,restoreButton.height);
            ofSetColor(255, 255, 255);
		if(bUseTTFFont) {
			guiTTFFont.drawString("restore", restoreButton.x + 3, restoreButton.y + restoreButton.height -4);
		}
		else {
			ofDrawBitmapString("restore", restoreButton.x + 3, restoreButton.y + restoreButton.height -3);
		}
		ofPopStyle();
	}

        ofPushMatrix();
            ofTranslate(2,0,0);
            glColor4fv(textColor.getColorF());
            guiBaseObject::renderText();
        ofPopMatrix();

        if( !minimize ){

            //don't let gui elements go out of their panels
            glEnable(GL_SCISSOR_TEST);
            glScissor(boundingBox.x, ofGetHeight() - ( boundingBox.y + boundingBox.height - (-2 + topSpacing) ), boundingBox.width - borderWidth , boundingBox.height);

                for(int i = 0; i < (int) panelTabs.size(); i++){
                    if( i == selectedPanel){
                        ofPushStyle();
                            ofFill();
                            glColor4fv(fgColor.getSelectedColorF());
                            ofRect(panelTabs[i].x, panelTabs[i].y, panelTabs[i].width, panelTabs[i].height);
                            glColor4fv(outlineColor.getColorF());
                        ofPopStyle();
                    }
                    glColor4fv(outlineColor.getColorF());
                    ofNoFill();
                    ofRect(panelTabs[i].x, panelTabs[i].y, panelTabs[i].width, panelTabs[i].height);
                }

                glPushMatrix();
                    glTranslatef(hitArea.x, hitArea.y, 0);
                    for(int i = 0; i < (int) panels.size(); i++){
                        if( i == selectedPanel )panels[i]->render();
                    }
                glPopMatrix();

            glDisable(GL_SCISSOR_TEST);
        }

    ofPopStyle();
}
//--------------------------------------------------------------
void testApp::draw(){
    
    ofBackground(0, 0, 0);
    
    string text;
    int textX = 20;
    int textY = 20;
    
    //Draw the training info
    ofSetColor(255, 255, 255);
    text = "------------------- TrainingInfo -------------------";
    ofDrawBitmapString(text, textX,textY);
    
    if( record ) ofSetColor(255, 0, 0);
    else ofSetColor(255, 255, 255);
    textY += 15;
    text = record ? "RECORDING" : "Not Recording";
    ofDrawBitmapString(text, textX,textY);
    
    ofSetColor(255, 255, 255);
    textY += 15;
    text = "TrainingClassLabel: " + ofToString(trainingClassLabel);
    ofDrawBitmapString(text, textX,textY);
    
    textY += 15;
    text = "NumTrainingSamples: " + ofToString(trainingData.getNumSamples());
    ofDrawBitmapString(text, textX,textY);
    
    
    //Draw the prediction info
    textY += 30;
    text = "------------------- Prediction Info -------------------";
    ofDrawBitmapString(text, textX,textY);
    
    textY += 15;
    text =  pipeline.getTrained() ? "Model Trained: YES" : "Model Trained: NO";
    ofDrawBitmapString(text, textX,textY);
    
    textY += 15;
    text = "PredictedClassLabel: " + ofToString(pipeline.getPredictedClassLabel());
    ofDrawBitmapString(text, textX,textY);
    
    textY += 15;
    text = "Likelihood: " + ofToString(pipeline.getMaximumLikelihood());
    ofDrawBitmapString(text, textX,textY);
    
    textY += 15;
    text = "SampleRate: " + ofToString(ofGetFrameRate(),2);
    ofDrawBitmapString(text, textX,textY);
    
    
    //Draw the info text
    textY += 30;
    text = "InfoText: " + infoText;
    ofDrawBitmapString(text, textX,textY);

	//Draw number of hands currently dragged
    textY += 15;
	text = "Number of tracked hands: "+ ofToString(noOfTrackedHands);
	ofSetColor(255, 0, 0);
    ofDrawBitmapString(text, textX,textY);
    ofSetColor(255, 255, 255);

    //Draw the timeseries data
    if( record  && noOfHands == noOfTrackedHands){
        ofFill();
        for(UINT i=0; i<timeseries.getNumRows(); i++){
            double x = timeseries[i][0];
            double y = timeseries[i][1];
            //double r = ofMap(i,0,timeseries.getNumRows(),0,255);
            //double g = 0;
            //double b = 255-r;
		    //ofSetColor(r,g,b); 
            ofSetColor(250,0,0);
            ofEllipse(300+x,500-y,5,5);

		   if(noOfHands >= 2){
				ofSetColor(0,80,255);
				x = timeseries[i][3];
                y = timeseries[i][4];
				ofEllipse(300+x,500-y,5,5);
			}
        }
    }
    
    if( pipeline.getTrained()  && noOfHands == noOfTrackedHands){
        
        //Draw the data in the DTW input buffer
        DTW *dtw = pipeline.getClassifier< DTW >();
        
        if( dtw != NULL ){
            vector< VectorDouble > inputData = dtw->getInputDataBuffer();
            for(UINT i=0; i<inputData.size(); i++){
                double x = inputData[i][0];
                double y = inputData[i][1];
              //  double r = ofMap(i,0,inputData.size(),0,255);
              //  double g = 0;
             //   double b = 255-r;
                
                ofSetColor(250,0,0);
                ofEllipse(300+x,500-y,5,5);

		    if(noOfHands >= 2){
				ofSetColor(0,80,250);
				 x = inputData[i][3];
                 y = inputData[i][4];
				 ofEllipse(300+x,500-y,5,5);
			}
            }
        }
    }
    
}
Beispiel #15
0
//--------------------------------------------------------------
void testApp::draw(){
	
	ofDrawBitmapString("test", 10, 10);
	
	//////////////////////////
	// BACKGROUND HIGHLIGHT
	//////////////////////////
	//
	glDisable(GL_DEPTH_TEST);
	ofPushStyle();
	ofSetColor(100, 100, 100);
	ofRect(viewGrid[iMainCamera]);
	ofPopStyle();
	glEnable(GL_DEPTH_TEST);
	//
	//////////////////////////
	
	
	
	//////////////////////////
	// DRAW ALL VIEWPORTS
	//////////////////////////
	//
	
	//draw main viewport
	cameras[iMainCamera]->begin(viewMain);
	drawScene(iMainCamera);
	
	//calculate mouse ray whilst this camera is active
	updateMouseRay();
	
	cameras[iMainCamera]->end();
	
	//draw side viewports
	for (int i=0; i<N_CAMERAS; i++)
	{
		cameras[i]->begin(viewGrid[i]);
		drawScene(i);
		cameras[i]->end();
	}
	
	//
	//////////////////////////
	
	
	
	//////////////////////////
	// DRAW STUFF ON TOP
	//////////////////////////
	//
	ofPushStyle();
	glDepthFunc(GL_ALWAYS); // draw on top of everything
	
	//draw some labels
	ofSetColor(255, 255, 255);
	ofDrawBitmapString("Press keys 1-4 to select a camera for main view", viewMain.x + 20, 30);
	ofDrawBitmapString("Camera selected: " + ofToString(iMainCamera+1), viewMain.x + 20, 50);
	ofDrawBitmapString("Press 'f' to toggle fullscreen", viewMain.x + 20, 70);
	ofDrawBitmapString("Press 'p' to toggle parents on OrthoCamera's", viewMain.x + 20, 90);
	
	ofDrawBitmapString("EasyCam",	viewGrid[0].x + 20, viewGrid[0].y + 30);
	ofDrawBitmapString("Front",		viewGrid[1].x + 20, viewGrid[1].y + 30);
	ofDrawBitmapString("Top",		viewGrid[2].x + 20, viewGrid[2].y + 30);
	ofDrawBitmapString("Left",		viewGrid[3].x + 20, viewGrid[3].y + 30);

	//draw outlines on views
	ofSetLineWidth(5);
	ofNoFill();
	ofSetColor(255, 255, 255);
	//
	for (int i=0; i<N_CAMERAS; i++)
		ofRect(viewGrid[i]);
	//
	ofRect(viewMain);
	
	glDepthFunc(GL_LESS);
	ofPopStyle();
	//
	//////////////////////////
}
Beispiel #16
0
//--------------------------------------------------------------
void ofApp::draw()
{

	ofBackground(ofColor(120,120,120));
    
    ofSetColor(100);
        if (sensor0 == true)
        {
        	ofDrawBitmapString("I am sad..make me happy...", 50, 50);
        	 ofEllipse(250, 250, 300 ,300);
        	  ofSetColor(0,0,255);
  			  ofFill();
			  ofRect(200, 210 , 30, 50);
			  ofSetColor(0,0,255);
			  ofFill();
			  ofRect(300, 210 , 30, 50);
			  ofSetColor(0,0,255);
			  ofFill();
			  //ofBezier(150, 295, 200, 370, 300, 370, 350, 295);
			  ofLine(150, 295, 350, 295);
			  ofLine(160, 180, 210, 135);
			  ofLine(160, 180, 290, 180);
        	
            
        }
        	
        

        if ((sensor0 == false) && (sensor1 == true))
        {
        	ofDrawBitmapString("Hey! You are awesome!", 50,50);
        	
        	 ofEllipse(250, 250, 300 ,300);
        	 ofSetColor(0,0,255);
  			  ofFill();
			  ofEllipse(200, 210 , 30, 70);
			  ofSetColor(0,0,255);
			  ofFill();
			  ofEllipse(300, 210 , 30, 70);
			  ofSetColor(0,0,255);
			  ofFill();
			  ofBezier(150, 295, 200, 370, 300, 370, 350, 295);
			  ofLine(150, 295, 350, 295);
			//  ofLine(160, 180, 210, 135);
			 // ofLine(160, 180, 290,180 ); 

        }


         if ((sensor0 == false) && (sensor1 == false) && (sensor2 == true)){
        	  ofDrawBitmapString("Hahahahaha", 50,50);
        	
        	 ofEllipse(250, 250, 300 ,300);
        	 ofSetColor(0,0,255);
  			  ofFill();
			  ofEllipse(200, 210 , 30, 70);
			  ofSetColor(0,0,255);
			  ofFill();
			  ofEllipse(300, 210 , 30, 70);
			  ofSetColor(0,0,255);
			  ofFill();
			 // ofBezier(150, 295, 200, 370, 300, 370, 350, 295);
			  ofEllipse(245,295,150,50);
			  //ofLine(150, 295, 350, 295); 
			//  ofLine(160, 180, 210, 135);
			 // ofLine(160, 180, 290,180 );
			}
	
}
Beispiel #17
0
//--------------------------------------------------------------
void testApp::draw() {
	ofDrawBitmapString(floatMsg,20,20);
	ofDrawBitmapString(intMsg,20,40);
	ofDrawBitmapString("click to enable/disable events",20,60);
}
Beispiel #18
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    if(img.getWidth() > 0){
        ofDrawBitmapString("Image:", 10, 160);
        img.draw(10, 180);
    }
    
	// display instructions
    int x = 10;
    int y = 20;
	string buf;
	buf = "WELCOME TO BARBARA'S INSTALLATION";
	ofDrawBitmapString(buf, x, y);
    ofDrawBitmapString("press 'p' to play all videos", x, y+=30);
    ofDrawBitmapString("press 'l' to toggle looping on and off", x, y+=15);
    ofDrawBitmapString("press 's' to stop playing", x, y+=15);
    ofDrawBitmapString("press 'n' to play next video", x, y+=15);
    ofDrawBitmapString("press 'b' to go back to previous video", x, y+=15);
    ofDrawBitmapString("press 'i' to toggle info screen", x, y+=15);
    ofDrawBitmapString("press 'c' to clear log messages", x, y+=15);
    ofDrawBitmapString("press 'Q' to quit HPlayer", x, y+=15);
    filesToPlayTextInput->setPosition(x, y+=15);
    filesToPlayTextInput->draw();
    
    playButton->setPosition(x+300+5, y);
    loopButton->setPosition(x+300+5+75+5, y);
    toggleButton->setPosition(x+300+5+75+5+75+5, y);
    playButton->draw();
    loopButton->draw();
    toggleButton->draw();
    y += 45;
    

    //print all statuses
    for (int iCurPi = 0; iCurPi < NUM_RPIS; ++iCurPi){
        string str = "RPI" + to_string(iCurPi+1) + ": " + m_sRpiStatuses[iCurPi] + "\n";
        ofDrawBitmapString(str, x, y += 15);
    }

    ofDrawBitmapString("------------------------------------------", x, y+=15);
    
    //print received osc messages
    for(int i = 0; i < NUM_MSG_STRINGS; i++){
        ofDrawBitmapString(msg_strings[i], x, y+=15);
    }

}
//----------------------------------------------------------------------------------
void ofxCvBlobFinder::draw(float x, float y, float w, float h) {
    
    // draw blobs
    //ofxCvContourFinder::draw(x, y, w, h);
    // scale blob
    float scalex = 0.0f;
    float scaley = 0.0f;
    
    if (_width != 0) {
        scalex = w / _width;
    }
    else {
        scalex = 1.0f;
    }
    
    if (_height != 0) {
        scaley = h / _height;
    }
    else {
        scaley = 1.0f;
    }
    
    
    ofSetPolyMode(OF_POLY_WINDING_NONZERO);
    // apply transformation
    glPushMatrix();
    glTranslatef(x, y, 0.0);
    glScalef(scalex, scaley, 0.0);
    
    
#define DRAW_BLOB_VECTOR(points) do{ \
ofBeginShape(); \
for(int i = 0; i < (points).size(); i++){ \
ofVertex((points[i]).x, (points[i]).y); \
} \
ofEndShape(true); \
} while(0)
    
    ofNoFill();
    for (int j = 0; j < blobz.size(); j++) {
        ofSetHexColor(0xFF0000);
        DRAW_BLOB_VECTOR( blobz[j].getPoints());
        
        ofSetHexColor(0x00FF00);
        DRAW_BLOB_VECTOR(blobz[j].getHullPoints());
        
        ofSetHexColor(0x0000FF);
        DRAW_BLOB_VECTOR( blobz[j].getApproxPoints());
        
        ofSetHexColor(0x00ffae);
        ofRectangle c = blobz[j].getBoundingBox();
        
        
        // draw bounding box
        ostringstream s;
        s << j << "Area = " << blobz[j].getArea();
        
        ofDrawBitmapString(s.str(), c.x, c.y + 50);
        ofRect(c.x, c.y, c.width, c.height);
        
        // get convexity defects
        vector<ofxCvConvexityDefect> cd = blobz[j].getConvexityDefects();
        ofSetHexColor(0x00effe);
        for(int i=0; i < cd.size(); i++){
            ofLine(cd[i].start.x, cd[i].start.y, cd[i].end.x, cd[i].end.y);
            ofCircle(cd[i].defect.x, cd[i].defect.y, 2);
            float angle = atan2f( ( (float) (cd[i].end.y - cd[i].start.y) ) , ( (float) (cd[i].end.x - cd[i].start.x)));
            float x = cd[i].defect.x - sinf(angle) * cd[i].length;
            float y = cd[i].defect.y + cosf(angle) * cd[i].length;
            ofSetHexColor(0xF0F0F0);
            ofLine(cd[i].defect.x, cd[i].defect.y, x, y);
        }
    }
    
    for (int k = 0; k < blobParams.size(); k++){
        ofDrawBitmapString("Blob:" + ofToString(blobParams[k].id), blobParams[k].position);
    }
    
    glPopMatrix();
}
//--------------------------------------------------------------
void testApp::draw(){
    
//Scale to make Camera Image Fullscreen
ofScale((float)ofGetWidth()/width,(float)ofGetHeight()/height);
    
ofPushMatrix();    
    
ofSetColor(255, 255, 255);

	if (isLive) {
        //Draw RGB CAM image
		recordImage.draw(0, 0, width, height);
		if (isTracking) {
			
            // DEBUG Draw Skeleton
            if(isDebug) recordUser.draw();
            if(isCalibrating) calibrateThereminPosition();
            trackClosestUser();            
            
            
            // DEBUG Draw Charges
            if(isDebug){
                for(int c = 0; c < nbCharges; c++){
                        charge[c].aff();
                }
            }
            
            //Draw the Magic
            drawEFieldLines();
                
		}
    }
    
ofPopMatrix();    
    
// On Screen Debugging and Status
//--------------------------------------------------------------
if(isDebug){
    
	ofSetColor(255, 255, 0);

	string statusSkeleton	= (string)(isTracking ? "TRACKING USERS: " + (string)(isLive ? ofToString(recordUser.getNumberOfTrackedUsers()) : ofToString(playUser.getNumberOfTrackedUsers())) + "" : "NOT TRACKING USERS");
	string statusMask		= (string)(!isMasking ? "HIDE" : (isTracking ? "SHOW" : "YOU NEED TO TURN ON TRACKING!!"));
    
    //new
    string statusCalibrating = (string)(isCalibrating ? "ON" : "OFF");
    string statusDebug = (string)(isDebug ? "ON" : "OFF");

	string statusHardware;

#ifdef TARGET_OSX // only working on Mac at the moment
	ofPoint statusAccelerometers = hardware.getAccelerometers();
	stringstream	statusHardwareStream;

	statusHardwareStream
	<< "ACCELEROMETERS:"
	<< " TILT: " << hardware.getTiltAngle() << "/" << hardware.tilt_angle
	<< " x - " << statusAccelerometers.x
	<< " y - " << statusAccelerometers.y
	<< " z - " << statusAccelerometers.z;

	statusHardware = statusHardwareStream.str();
#endif

	stringstream msg;
    
	msg
    << "    c : calibrate Theremin pos: " << ofToString(statusCalibrating) << endl
    << "    d : debug toggle          : " << statusDebug << endl
	<< "    m : drawing masks         : " << statusMask << endl
	<< "- / + : nearThreshold         : " << ofToString(nearThreshold) << endl
	<< "< / > : farThreshold          : " << ofToString(farThreshold) << endl
	<< "File  : " << oniRecorder.getCurrentFileName() << endl
	<< "FPS   : " << ofToString(ofGetFrameRate()) << "  " << statusHardware << endl;

	ofDrawBitmapString(msg.str(), 10, 80);
    
    
    stringstream guiMsg;
    
    int r =lineColor.r;
    int g =lineColor.g;
    int b =lineColor.b;
    
	guiMsg
    << "  + / - : Globals can be adjusted up or down using the listed keys" << endl
    << "  1 / Q : Line segment length,   lower is more complex : " << ofToString(intensPas) << endl
    << "  2 / W : Last Mile Drawing,     lower is more complex : " << ofToString(dMin2) << endl
	<< "  3 / E : Number of Iterations, higher is more complex : " << ofToString(numFieldIterations) << endl
	<< "  4 / R : Line Weight                                  : " << ofToString(lineWeight) << endl
	<< "  5 / T : Line Color,                    RED component : " << ofToString(r) << endl
	<< "  6 / Y : Line Color,                  GREEN component : " << ofToString(g) << endl
	<< "  7 / U : Line Color,                   BLUE component : " << ofToString(b) << endl
    << "  8 / I : Line Alpha,                  ALPHA component : " << ofToString(lineAlpha) << endl
	<< "  FPS   : " << ofToString(ofGetFrameRate());
    
	ofDrawBitmapString(guiMsg.str(), 10, 340);
}
}
Beispiel #21
0
void testApp::draw() {
	ofBackground(245);
    ofSetColor(255);  //everything drawn with white tint
	kinect.drawDepth(0, 0);
	easyCam.begin();
    
    ofScale(1, -1, -1);
    //ofTranslate(0, 0, -200);
    
   

    ofSetColor(0);
	int width = kinect.getWidth();
	int height = kinect.getHeight();
	
	float* distancePixels = kinect.getDistancePixels(); 
    ofMesh cloud;
    cloud.setMode(OF_PRIMITIVE_POINTS);

    float minZ = 1500;
    float minX = 0;
    float minY = 0;
    float dist = 1500;
    float secondZ = 1500;
    float secondX = 0;
    float secondY = 0;
    
	for(int y = 0; y < height; y++) {
		for(int x = 0; x < width; x++) {
			int i = y * width + x;
			float z = distancePixels[i];
            
            if(z !=0 && z < 1500 && drawCloud == true) cloud.addVertex(ConvertProjectiveToRealWorld(x, y, z));
			
            if(z != 0 && z < minZ) {
                minZ= z;
                minX = x;
                minY = y;
                forepoint = ConvertProjectiveToRealWorld(minX, minY, minZ);
			}
            else if ( z !=0 && z > minZ && z-minZ < dist) {
                dist = z - minZ;
                secondZ = z;
                secondX = x;
                secondY = y;
                
            }
		}
	}
    if(drawCloud) cloud.draw();
    
    //secondPoint = ConvertProjectiveToRealWorld(secondX, secondY, secondZ);

    ofSetColor(50);
    if(doDrawing) {
        drawing.addVertex(forepoint);
        //drawing2.addVertex(secondPoint);
    }
    //drawing.draw();
    //drawing2.draw();
    
   
    //ofCircle(secondPoint.x, secondPoint.y, 5);
    
    if(drawCopy) {
        meshCopy.draw();
    }
        
    easyCam.end();
    
    //averaging the data in a region around the forepoint
    ofNoFill();
    int searchRadius = 64;
    int searchDistance = 100;
    int count = 0;
    ofVec3f sum = ofVec3f(0, 0, 0);

    ofRect(minX-searchRadius/2, minY+searchRadius/2, searchRadius, searchRadius);
    for(int x = -searchRadius/2; x < searchRadius/2; x++) {
        for (int y = -searchRadius/2; y < searchRadius/2; y++) {
            int curx = x+minX;
            int cury = y+ minY;
            if( curx < width && curx >0 && y + cury >0 && cury < height) {
                int i = cury*width + curx;
                float z = distancePixels[i];
                if(z!=0 && z-minZ < searchDistance) {
                    sum.x+= curx;
                    sum.y+= cury;
                    //unlike x and y, z is taken from distancePixels[i] so dont adjust for current (x, y) like curx cury
                    sum.z+= z;
                    count++;
                }
            }
        }
    }
    
    //we are only looking at a single point. no perspective issue involed?
    //ofVec3f avg = ConvertProjectiveToRealWorld(sum.x/count, sum.y/count, sum.z/count);
    
    ofSetColor(0, 255, 0);
    ofFill();
    ofCircle(avg.x, avg.y, 5);
    ofSetColor(255, 0, 0);
    ofFill();
    ofCircle(forepoint.x, forepoint.y, 5);
    
    ofSetColor(0);
    ofDrawBitmapString( "space bar to render / t to resume", 50, 100);
    ofDrawBitmapString( ofToString(forepoint.x) + "/" + ofToString(avg.x), 50, 150);
}
//----------------------------------------------------------------------------
//    Theremin Position Calibration
//
//    If in Calibration Mode, then Detect Markers and move charges accordingly
//----------------------------------------------------------------------------
void testApp::calibrateThereminPosition(){
        // Draw Threshold image and allow user to adjust for lighting conditions
        ofSetHexColor(0x555555);
        grayThres.mirror(false,true);
        grayThres.draw(0, 0);
        
        // Display Marker Data nad instruction for calibration.
        ofSetHexColor(0xff0000);  
        ofDrawBitmapString(ofToString(artk.getNumDetectedMarkers()) + " marker(s) found", 10, 20);
        ofDrawBitmapString("Threshold: " + ofToString(threshold), 10, 30);
        ofDrawBitmapString("Use the Up/Down keys to adjust the threshold until both markers are visible.", 10, 40); 
        ofDrawBitmapString("blue circles will apear over the markers when it's good.", 10, 50);
        ofDrawBitmapString("Press the 'c' key when done.", 10,60);
        ofDrawBitmapString("Press the 'd' key to show more debug info.", 10,70);    
        
        // See if marker ID '0' was detected
        // and draw a circle in the center with the ID number.
        int myIndex = artk.getMarkerIndex(0);
        ofPoint center;
        int depth;
        if(myIndex >= 0) {	
            //Get the center of Marker '0'
            center = artk.getDetectedMarkerCenter(myIndex);
            
            //Draw location
            ofSetHexColor(0x000055);
            ofCircle(width-center.x,center.y,30);
            ofSetHexColor(0x00ff00);
            ofDrawBitmapString("0",width-center.x,center.y,10);
            depth = recordDepth.getPixelDepth(width-center.x,center.y);
            ofDrawBitmapString(ofToString(depth),width-center.x,center.y+20,10);
            
            //Store Position
            marker0.set(center.x,center.y,depth);
        }
        
        // See if marker ID '1' was detected
        // and draw a circle in the center with the ID number.
        myIndex = artk.getMarkerIndex(1);
        if(myIndex >= 0) {	
            
            //Get the center of Marker '1'
            center = artk.getDetectedMarkerCenter(myIndex);
            
            //Draw Location
            ofSetHexColor(0x000055);
            ofCircle(width-center.x,center.y,30);
            ofSetHexColor(0x00ff00);
            ofDrawBitmapString("1",width-center.x,center.y,10);
            depth = recordDepth.getPixelDepth(width-center.x,center.y);
            ofDrawBitmapString(ofToString(depth),width-center.x,center.y+20,10);
            
            //Store Position
            marker1.set(center.x,center.y,depth);
        }
      
        //Calculate Distance (pixels) Between Markers
        ofVec2f temp0;
        temp0.set(marker0.x, marker0.y);
        ofVec2f temp1;
        temp1.set(marker1.x,marker1.y);
        ofVec2f temp2 = temp0 - temp1;
        
    float distFactor = abs(temp0.distance(temp1))/realMarkerDist;
    
    //Theremin volume
    charge[2].set(width-marker0.x-distFactor*75,marker0.y-distFactor*50,0,-1000);
    charge[3].set(width-marker0.x-distFactor*200,marker0.y-distFactor*50,0,-1000.0);
    
    //Theremin pitch
    charge[4].set(width-marker1.x+distFactor*50,marker1.y-distFactor*485,0,-1000.0);
    charge[5].set(width-marker1.x+distFactor*50,marker1.y-distFactor*100,0,-1000.0);
  
}
//-------------------------------------------------------------
void captureApp::draw(){
	
	if( state == CAP_STATE_DECODING ){
		camera3D.place();
		ofBackground(0, 0, 0);
		glEnable(GL_DEPTH_TEST);
			ofPushMatrix();
				ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2, -200);		
				ofRotate( ofMap(saveIndex, 0, imageSaver.getSize(), 180 -8, 180 + 8, true), 0, 1, 0);
				decoder.drawCloud();
			ofPopMatrix();
		glDisable(GL_DEPTH_TEST);			
		camera3D.remove();	
		//decoder.drawCurrentFrame(0, 0, 320, 240);
		
//		ofNoFill();
//		ofSetColor(100, 100, 100, 255);
//		ofRect( ofGetWidth()/4, ofGetHeight()-150, ofGetWidth()/2, 20);	
//		ofFill();
//		ofRect( ofGetWidth()/4, ofGetHeight()-150, ofMap(saveIndex, 0, imageSaver.getSize(), 0.0, 1.0, true) * (float)(ofGetWidth()/2), 20);			
		return;
	}
	
	if(!panel.getValueB("frameByFrame")){
		patternFrame = ofGetFrameNum() / panel.getValueI("patternRate");
	}
	
	if (!panel.getValueB("brightnessSetting")){
		ofSetColor(255, 255, 255, 255);
		curGenerator->get(patternFrame).draw(0, 0);
	} else {
		int checkBrightness = panel.getValueI("checkBrightness");
		ofSetColor(checkBrightness, checkBrightness, checkBrightness);
		ofRect(0, 0, ofGetWidth(), ofGetHeight());
	}
	
	if( state == CAP_STATE_CAPTURE ){
		return;
	}
	
	if( panel.getValueB("bSpotLight") ){
		if( state < CAP_STATE_FADEIN ){
			spotLightAlpha = 1.0;
		}else if( state > CAP_STATE_END_DECODE ){
			spotLightAlpha += 0.05;	
			spotLightAlpha = ofClamp(spotLightAlpha, 0, 1);	
		}
	}else if(  !panel.getValueB("bSpotLight") || state == CAP_STATE_CAPTURE ){
		spotLightAlpha = 0.0;
	}
	
	if( state == CAP_STATE_FADEIN ){
		float alpha = ofMap(ofGetElapsedTimef(), fadeInStartTime, fadeInStartTime + panel.getValueF("fadeInTime"), 255, 0.0);
		
		ofPushStyle();
		ofEnableAlphaBlending();
		ofSetColor(0, 0, 0, alpha);
		ofRect(0, 0, ofGetWidth(), ofGetHeight());
		ofPopStyle();
	}
	
	if( state >= CAP_STATE_END_DECODE ){
		ofPushStyle();
		ofSetColor(0, 0, 0, 255);
		ofRect(0, 0, ofGetWidth(), ofGetHeight());
		ofPopStyle();
	}
	
	if( spotLightAlpha <= 0.01 ){
		spotLightAlpha = 0.0;
	}else{
		ofPushStyle();
		ofEnableAlphaBlending();
		float val = 255.0 * panel.getValueF("spotLightBrightness");
		ofSetColor(val, val, val, spotLightAlpha*255.0);
		spotLightImage.draw( ofGetWidth()/2, ofGetHeight()/2, ofGetWidth(), ofGetHeight() );		
		ofPopStyle();
		
		if( state == CAP_STATE_FADEIN ){
			spotLightAlpha *= 0.94;
		}
	}
	
	// fade out/in the button
	serial.writeByte((unsigned int) (spotLightAlpha * 255));
	
	if( state == CAP_STATE_CAPTURE || state == CAP_STATE_FADEIN ){
		return;
	}
	
	if(debugState == CAP_DEBUG) {
		int cameraRate   = panel.getValueI("cameraRate");
		int cameraOffset = panel.getValueI("cameraOffset");
		ofPushStyle();
		ofPushMatrix();
		int padding = 8;
		ofTranslate(panel.getWidth() + padding * 2, padding);
		int recentWidth = 160;
		int recentHeight = 120;
		
		if( panel.getValueB("largeVideo") ){
			recentWidth		= 640;
			recentHeight	= 480;
		}
		
		for(int i = 0; i < curGenerator->size(); i++) {
			ofPushMatrix();
			ofTranslate(
						(i % 3) * (recentWidth + padding),
						(i / 3) * (recentHeight + padding));
			ofSetColor(255, 255, 255);
			if(needsUpdate[i]) {
				recent[i].update();
				needsUpdate[i] = false;
			}
			recent[i].draw(0, 0, recentWidth, recentHeight);
			ofSetColor(255, 0, 0);
			ofNoFill();
			ofRect(0, 0, recentWidth, recentHeight);
			
			// ito wrote..begin
			
			if (i == 0 && panel.getValueB("SHOW_RED") ) {
				ofImage clipping;
				getClipping(recent[i], clipping);
				ofEnableAlphaBlending();
				clipping.update();
				ofSetColor(255, 0, 0);
				clipping.draw(0, 0, recentWidth, recentHeight);
				ofDisableAlphaBlending();
			}
			
			// it wrote..end
			ofPopMatrix();
		}
		ofPopMatrix();
		ofPopStyle();
		
		panel.draw();
		
		if( do1394 && settings != NULL ){
			if( camState == CAMERA_OPEN ){
				settings->draw();
			}
		}
		
		ofSetColor(255, 0, 0);
		ofDrawBitmapString("app fps: " + ofToString(ofGetFrameRate(), 2), 810, 20);
		if(camState == CAMERA_OPEN)
			ofDrawBitmapString("cam fps: "+ofToString(camFps, 2), 810, 40);	
		if( panel.getValueB("B_FACE_TRIGGER") ){
			face.draw(800, 54, 50, 30);
		}else{
			ofDrawBitmapString("face trigger is off\n", 810, 50+18);
		}
	}
}
Beispiel #24
0
//--------------------------------------------------------------
void ofApp::draw() {
    
    float spinX = sin(ofGetElapsedTimef()*.35f);
    float spinY = cos(ofGetElapsedTimef()*.075f);
    
    if(bMousePressed) {
        spinX = spinY = 0.0f;
    }
    
    ofEnableDepthTest();
    
    ofEnableLighting();
    pointLight.enable();
    pointLight2.enable();
    pointLight3.enable();
    
	material.begin();
    
    
    ofSetColor(180);
    ofNoFill();
    ofDrawSphere(ofGetWidth()/2, ofGetHeight()/2, ofGetWidth());
    
    if(mode == 1 || mode == 3) texture.getTexture().bind();
    if(mode == 2) vidGrabber.getTexture().bind();
    
    
    // Plane //
    plane.setPosition(ofGetWidth()*.2, ofGetHeight()*.25, 0);
    plane.rotate(spinX, 1.0, 0.0, 0.0);
    plane.rotate(spinY, 0, 1.0, 0.0);
    
    
    if(mode == 3) {
        deformPlane = plane.getMesh();
        // x = columns, y = rows //
        ofVec3f planeDims = plane.getResolution();
        float planeAngleX = ofGetElapsedTimef()*3.6;
        float planeAngleInc = 3.f/(float)planeDims.x;
        ofVec3f vert;
        for(int i = 0; i < deformPlane.getNumIndices(); i++ ) {
            planeAngleX += planeAngleInc;
            int ii = deformPlane.getIndex( i );
            vert = deformPlane.getVertex( ii );
            vert.z += cos(planeAngleX) * 50;
            deformPlane.setVertex( ii, vert );
        }
    }
    
    if(bFill) {
        ofFill();
        ofSetColor(255);
        if(mode == 3) {
            plane.transformGL();
            deformPlane.draw();
            plane.restoreTransformGL();
        } else {
            plane.draw();
        }
    }
    if(bWireframe) {
        ofNoFill();
        ofSetColor(0, 0, 0);
        if(!bFill) ofSetColor(255);
        plane.setPosition(plane.getPosition().x, plane.getPosition().y, plane.getPosition().z+1);
        //if(bFill) {
        if( mode == 3 ) {
            ofSetColor(255);
        }
        plane.drawWireframe();
        //}
        plane.setPosition(plane.getPosition().x, plane.getPosition().y, plane.getPosition().z-2);
        
    }
    
    
    // Box //
    box.setPosition(ofGetWidth()*.5, ofGetHeight()*.25, 0);
    box.rotate(spinX, 1.0, 0.0, 0.0);
    box.rotate(spinY, 0, 1.0, 0.0);
    
    if(bFill) {
        ofFill();
        ofSetColor(255);
        if(mode == 3) {
            box.transformGL();
            for(int i = 0; i < ofBoxPrimitive::SIDES_TOTAL; i++ ) {
                ofPushMatrix();
                ofTranslate( boxSides[i].getNormal(0) * sin(ofGetElapsedTimef()) * 50  );
                boxSides[i].draw();
                ofPopMatrix();
            }
            box.restoreTransformGL();
        } else {
            box.draw();
        }
    }
    if(bWireframe) {
        ofNoFill();
        ofSetColor(0, 0, 0);
        if(!bFill) ofSetColor(255);
        box.setScale(1.01f);
        if(mode == 3) {
            ofSetColor(255);
        }
        box.drawWireframe();
        box.setScale(1.f);
    }
    
    
    // Sphere //
    sphere.setPosition(ofGetWidth()*.8f, ofGetHeight()*.25, 0);
    sphere.rotate(spinX, 1.0, 0.0, 0.0);
    sphere.rotate(spinY, 0, 1.0, 0.0);
    
    if(mode == 3) {
        sphere.setMode( OF_PRIMITIVE_TRIANGLES );
        triangles = sphere.getMesh().getUniqueFaces();
    }
    
    if(bFill) {
        ofFill();
        ofSetColor(255);
        if(mode == 3) {
            float angle = ofGetElapsedTimef()*3.2;
            float strength = (sin( angle+.25 )) * .5f * 5.f;
            ofVec3f faceNormal;
            for(int i = 0; i < triangles.size(); i++ ) {
                // store the face normal here.
                // we change the vertices, which makes the face normal change
                // every time that we call getFaceNormal //
                faceNormal = triangles[i].getFaceNormal();
                for(int j = 0; j < 3; j++ ) {
                    triangles[i].setVertex( j, triangles[i].getVertex(j) + faceNormal * strength);
                }
            }
            sphere.getMesh().setFromTriangles( triangles );
        }
        sphere.draw();
        
    }
    if(bWireframe) {
        ofNoFill();
        ofSetColor(0, 0, 0);
        if(!bFill) ofSetColor(255);
        sphere.setScale(1.01f);
        sphere.drawWireframe();
        sphere.setScale(1.f);
    }
    
    
    // ICO Sphere //
    icoSphere.setPosition(ofGetWidth()*.2, ofGetHeight()*.75, 0);
    icoSphere.rotate(spinX, 1.0, 0.0, 0.0);
    icoSphere.rotate(spinY, 0, 1.0, 0.0);
    
    if(mode == 3) {
        triangles = icoSphere.getMesh().getUniqueFaces();
    }
    
    if(bFill) {
        ofFill();
        ofSetColor(255);
        
        if(mode == 3) {
            float angle = (ofGetElapsedTimef() * 1.4);
            ofVec3f faceNormal;
            for(int i = 0; i < triangles.size(); i++ ) {
                float frc = ofSignedNoise(angle* (float)i * .1, angle*.05) * 4;
                faceNormal = triangles[i].getFaceNormal();
                for(int j = 0; j < 3; j++ ) {
                    triangles[i].setVertex(j, triangles[i].getVertex(j) + faceNormal * frc );
                }
            }
            icoSphere.getMesh().setFromTriangles( triangles );
        }
        
        icoSphere.draw();
    }
    if(bWireframe) {
        ofNoFill();
        ofSetColor(0, 0, 0);
        if(!bFill) ofSetColor(255);
        icoSphere.setScale(1.01f);
        icoSphere.drawWireframe();
        icoSphere.setScale(1.f);
    }
    
    
    // Cylinder //
    if(mode == 3) {
        topCap      = cylinder.getTopCapMesh();
        bottomCap   = cylinder.getBottomCapMesh();
        body        = cylinder.getCylinderMesh();
    }
    
    cylinder.setPosition(ofGetWidth()*.5, ofGetHeight()*.75, 0);
    cylinder.rotate(spinX, 1.0, 0.0, 0.0);
    cylinder.rotate(spinY, 0, 1.0, 0.0);
    if(bFill) {
        ofFill();
        ofSetColor(255);
        if(mode == 3) {
            cylinder.transformGL();
            ofPushMatrix(); {
                if(topCap.getNumNormals() > 0) {
                    ofTranslate( topCap.getNormal(0) * (cos(ofGetElapsedTimef()*5)+1)*.5f * 100 );
                    topCap.draw();
                }
            } ofPopMatrix();
            ofPushMatrix(); {
                if(bottomCap.getNumNormals() > 0) {
                    ofTranslate( bottomCap.getNormal(0) * (cos(ofGetElapsedTimef()*4)+1)*.5f * 100 );
                    bottomCap.draw();
                }
            } ofPopMatrix();
            ofPushMatrix(); {
                float scale = (cos(ofGetElapsedTimef()*3)+1)*.5f + .2;
                ofScale( scale, scale, scale );
                body.draw();
            } ofPopMatrix();
            cylinder.restoreTransformGL();
        } else {
            cylinder.draw();
        }
    }
    if(bWireframe) {
        ofNoFill();
        ofSetColor(0, 0, 0);
        if(!bFill || mode == 3) ofSetColor(255);
        cylinder.setScale(1.01f);
        cylinder.drawWireframe();
        cylinder.setScale(1.0f);
    }
    
    
    // Cone //
    cone.setPosition(ofGetWidth()*.8, ofGetHeight()*.75, 0);
    cone.rotate(spinX, 1.0, 0.0, 0.0);
    cone.rotate(spinY, 0, 1.0, 0.0);
    
    if(mode == 3) {
        bottomCap   = cone.getCapMesh();
        body        = cone.getConeMesh();
    }
    if(bFill) {
        ofFill();
        ofSetColor(255);
        if(mode == 3) {
            cone.transformGL();
            ofPushMatrix();
            if(bottomCap.getNumNormals() > 0 ) {
                ofTranslate( bottomCap.getNormal(0) * cone.getHeight()*.5 );
                ofRotate( sin(ofGetElapsedTimef()*5) * RAD_TO_DEG, 1, 0, 0);
                bottomCap.draw();
            }
            ofPopMatrix();
            
            ofPushMatrix();
            ofRotate(90, 1, 0, 0);
            ofRotate( (cos(ofGetElapsedTimef()*6) +1)*.5 * 360 , 1, 0, 0 );
            body.draw();
            ofPopMatrix();
            cone.restoreTransformGL();
        } else {
            cone.draw();
        }
    }
    if(bWireframe) {
        ofNoFill();
        ofSetColor(0, 0, 0);
        if(!bFill || mode == 3) ofSetColor(255);
        cone.setScale(1.01f);
        cone.drawWireframe();
        cone.setScale(1.0f);
    }
    
    if(mode == 1 || mode == 3) texture.getTexture().unbind();
    if(mode == 2) vidGrabber.getTexture().unbind();
    
    material.end();
    ofDisableLighting();
    
    if(bDrawLights) {
        ofFill();
        ofSetColor(pointLight.getDiffuseColor());
        pointLight.draw();
        ofSetColor(pointLight2.getDiffuseColor());
        pointLight2.draw();
        ofSetColor(pointLight3.getDiffuseColor());
        pointLight3.draw();
    }
    
    if(bDrawNormals) {
        ofSetColor(225, 0, 255);
        plane.drawNormals(20, bSplitFaces);
        box.drawNormals(20, bSplitFaces);
        sphere.drawNormals(20, bSplitFaces);
        icoSphere.drawNormals(20, bSplitFaces);
        cylinder.drawNormals(20, bSplitFaces);
        cone.drawNormals(20, bSplitFaces);
    }
    if(bDrawAxes) {
        plane.drawAxes(plane.getWidth()*.5+30);
        box.drawAxes(box.getWidth()+30);
        sphere.drawAxes(sphere.getRadius()+30);
        icoSphere.drawAxes(icoSphere.getRadius()+30);
        cylinder.drawAxes(cylinder.getHeight()+30);
        cone.drawAxes(cone.getHeight()+30);
    }
    
    ofDisableDepthTest();
    
    ofFill();
    
    ofSetColor(0);
    ofDrawRectangle(plane.getPosition().x-154, plane.getPosition().y + 120, 140, 24);
    ofSetColor(255);
    ofDrawBitmapString("ofPlanePrimitive", plane.getPosition().x-150, plane.getPosition().y+136 );
    
    ofSetColor(0);
    ofDrawRectangle(box.getPosition().x-154, box.getPosition().y + 120, 126, 24);
    ofSetColor(255);
    ofDrawBitmapString("ofBoxPrimitive", box.getPosition().x-150, box.getPosition().y+136 );
    
    ofSetColor(0);
    ofDrawRectangle(sphere.getPosition().x-154, sphere.getPosition().y + 120, 148, 24);
    ofSetColor(255);
    ofDrawBitmapString("ofSpherePrimitive", sphere.getPosition().x-150, sphere.getPosition().y+136 );
    
    ofSetColor(0);
    ofDrawRectangle(icoSphere.getPosition().x-154, icoSphere.getPosition().y + 120, 168, 24);
    ofSetColor(255);
    ofDrawBitmapString("ofIcoSpherePrimitive", icoSphere.getPosition().x-150, icoSphere.getPosition().y+136 );
    
    ofSetColor(0);
    ofDrawRectangle(cylinder.getPosition().x-154, cylinder.getPosition().y + 120, 160, 24);
    ofSetColor(255);
    ofDrawBitmapString("ofCylinderPrimitive", cylinder.getPosition().x-150, cylinder.getPosition().y+136 );
    
    ofSetColor(0);
    ofDrawRectangle(cone.getPosition().x-154, cone.getPosition().y + 120, 136, 24);
    ofSetColor(255);
    ofDrawBitmapString("ofConePrimitive", cone.getPosition().x-150, cone.getPosition().y+136 );
        
    if(bInfoText) {
        stringstream ss;
        ss << "Framerate: " << ofToString(ofGetFrameRate(),0) << "\n";
        ss << "(f): Toggle Fullscreen"<<endl<<"(s): Draw Solid Shapes"<<endl<<"(w): Draw Wireframes"<<endl;
        ss <<"(1/2/3/4): Set Resolutions" <<endl<<"(n): Draw Normals"<<"\n(LEFT/RIGHT): Set Mode "<<ofToString(mode,0)<<endl;
        ss <<"(z): Split Faces " <<bSplitFaces<<endl;
        ss <<"(a): Draw Axes"<<endl<<"(l): Render lights"<<endl<<"(t): Info Text"<<endl;
        
        ofDrawBitmapString(ss.str().c_str(), 20, 20);
    }
    
    
}
Beispiel #25
0
//--------------------------------------------------------------
void testApp::draw(){
	
	
	ofNoFill();
	
	pitchIn = (float)AA.pitch; //pitch input
	myPos = (pitchIn * 100) / 3000 ;  // x position on screen
	
	ofSetHexColor(0x000000);
	//ofDrawBitmapString( "pitch is : " + ofToString(myPos) + "\namplitude is : " + ofToString(scaledVol * 100.0, 0), 32,ofGetHeight()-20);
	ofDrawBitmapString("alexmilesdesign.com \npitch 1.1\n\nf = toggle fullscreen\nn = more sensitive \nm = less sensitive", 20, 30);
	
	//ofDrawBitmapString("Scaled average vol (0-100): " + ofToString(scaledVol * 100.0, 0), 32, 18);

	if (myPos <= 10.0f) {
		ofSetColor(20, 249, 135);
	}
	else if (myPos > 10.0f && myPos < 20.0f){
		ofSetColor(90, 81, 81);
	}
	else if ( myPos > 20.0f && myPos <= 30.0f) {
		ofSetColor(180, 16, 0);
	}
	else if ( myPos >= 31.0f && myPos <= 40.0f ) {
		ofSetColor(155, 46, 18);
	}
	else if ( myPos >= 41.0f && myPos <= 50.0f ) {
		ofSetColor(18, 255,140);
	}
	else if ( myPos >= 51.0f && myPos <= 60.0f ) {
		ofSetColor(90, 255, 19);
	}
	else if ( myPos >= 61.0f && myPos <= 70.0f ) {
		ofSetColor(81, 220, 44);
	}
	else if ( myPos >= 71.0f && myPos <= 80.0f ) {
		ofSetColor(38, 158, 254);
	}
	else if ( myPos >= 81.0f && myPos <= 90.0f ) {
		ofSetColor(47, 38, 233);
	}
	else if ( myPos >= 91.0f && myPos <= 100.0f ) {
		ofSetColor(233, 125, 38);
	}
	else if ( myPos >= 101.0f && myPos <= 110.0f ) {
		ofSetColor(233, 38, 116);
	}
	else if ( myPos >= 111.0f && myPos <= 120.0f ) {
		ofSetColor(114, 4, 48);
	}
	else if ( myPos >= 121.0f && myPos <= 130.0f ) {
		ofSetColor(228, 216, 79);
	}
	else if ( myPos >= 131.0f && myPos <= 140.0f ) {
		ofSetColor(228, 114, 79);
	}
	else if ( myPos >= 141.0f ) {
		ofSetColor(233, 255, 0);
	}
	
	ofFill();		
	ofCircle(ofGetWidth()/2, ofGetHeight()/2, scaledVol * 890.0f);
	
	/*  //lets draw the volume history as a graph
	ofBeginShape();
	for (int i = 0; i < volHistory.size(); i++){
		if( i == 0 ) ofVertex(i, 400);
		
		ofVertex(i, 400 - volHistory[i] * 70);
		
		if( i == volHistory.size() -1 ) ofVertex(i, 400);
	}
	ofEndShape(false);	 */	

	
}
Beispiel #26
0
//--------------------------------------------------------------
void testApp::draw() {
    ofSetColor(255, 255, 255);

    ofPushMatrix();
    // draw debug (ie., image, depth, skeleton)
//    openNIDevice.drawDebug();
    openNIDevice.drawImage(0, 0, ofGetWidth(), ofGetHeight());
    openNIDevice.drawHands(0, 0, ofGetWidth(), ofGetHeight());
    ofPopMatrix();

    ofPushMatrix();
    // get number of current hands
    int numHands = openNIDevice.getNumTrackedHands();



    // some DMX channels
    DMX.setLevel(6, 0);                                     // set color wheel (0-127) or cycle speed (128-255)
    DMX.setLevel(11, 4);                                    // shutter (0-3 blackout; 4 - 7 open; 8-215 strobe)
    DMX.setLevel(10, 255);                                  // dimmer 0-255
    DMX.setLevel(7, activeGobo);                            // choose gobo
    DMX.setLevel(12, 0);                                    // control functions
    DMX.setLevel(9, 0);                                     // set prism
    DMX.setLevel(8, 0);                                     //set gobo rotation (0-63 indexing), 64-147 rotation speed. +inverse
    DMX.update();


    string info;

    // iterate through users
    for (int i = 0; i < numHands; i++) {

        // get a reference to this user
        ofxOpenNIHand & hand = openNIDevice.getTrackedHand(i);

        // get hand position
        ofPoint & handPosition = hand.getPosition();

        // set dmx to follow hand
        //
        // center max and min position of hand and scale it to moving head wider angles of motion
        ofPoint range;
        range.set(160, 120); // range of motion from center x & y
        panScaled = ofMap(handPosition.x, (ofGetWidth()*.5)-range.x, (ofGetWidth()*.5)+range.x, .5, .4,true);
        tiltScaled = ofMap(handPosition.y, (ofGetHeight()*.5)-range.y, (ofGetHeight()*.5)+range.y,0.3, 0.1,true);

        // using ofxDmxUtils setrotation to calculate the fine and coarse channels for each axys (pan/tilt)
        DMX.setLevel(1, ofxDmxUtils::setRotation(panScaled, panMax).x);
        DMX.setLevel(2, ofxDmxUtils::setRotation(panScaled, panMax).y);

        DMX.setLevel(3, ofxDmxUtils::setRotation(tiltScaled, tiltMax).x);
        DMX.setLevel(4, ofxDmxUtils::setRotation(tiltScaled, tiltMax).y);

        info += "hand X: " + ofToString(handPosition.x) + "  scaled: " + ofToString(panScaled) + "\nhand Y: "+ ofToString(handPosition.y)+ "  scaled: " + ofToString(tiltScaled);

    }
    ofPopMatrix();


    // draw some info regarding hand pos and scaled values
    ofSetColor(0, 255, 0);
    ofDrawBitmapString(info, 20, ofGetHeight()-20);
}
Beispiel #27
0
//--------------------------------------------------------------
void testApp::draw(){
    
    quadWarp.begin();
    
    ofSetColor(255);
    
    
    image.setAnchorPoint(scale*ofGetWidth()/2, scale*ofGetHeight()/2);
    image.draw(ofGetWidth()/2, ofGetHeight()/2, scale*ofGetWidth(), scale*ofGetHeight());
    
    
    ofFill();
    
    
    
    for (vector<star>::iterator iter=stars.begin(); iter!=stars.end(); iter++) {
        
        float k=128/iter->pos.z;
        
        float x = iter->pos.x*k+ofGetWidth()/2;
        float y = iter->pos.y*k+ofGetHeight()/2;
        float size = (1-iter->pos.z/MAX_DEPTH) * 5;
        //float color = 
        
        ofColor color;
        //float dist = iter->chan ? lEnv[(bufferCounter-1)%lEnv.size()] : rEnv[(bufferCounter-1)%rEnv.size()];
        //float hue = iter->chan ? 0 : 160;
        //float sat = ofMap(dist, -50, 0, 0, 255,true);
        float brt = (1-iter->pos.z/MAX_DEPTH)*255;
        
        float b = sin((ofGetElapsedTimeMillis()-iter->startTime)*iter->frequency*PI*2/1000+iter->phase);
        
        color.setHsb(130+ofRandom(60),ofRandom(50),brt*ofMap(b, -1, 1, 0.75, 1),255); // 
        //color.setBrightness(brt);
        ofSetColor(color.r,color.g,color.b);
        
        
        ofCircle(x, y, size/2);
                        
        
    }
    
    ofNoFill();
    
    if (bDebug) {
        
        for (vector<channel>::iterator iter=channels.begin();iter!=channels.end();iter++) {
            
            ofPushMatrix();
            ofTranslate(10+(VECTOR_SIZE+10)*distance(channels.begin(),iter), 0,0);
    
            ofPushMatrix();
            ofTranslate(0, 10, 0);
            drawGraph(iter->peakVec, bufferCounter, iter->thresholds, true);
            ofPopMatrix();
           
            ofPushMatrix();
            ofTranslate(0, RECT_HEIGHT+20, 0);
            drawGraph(iter->peakVec, bufferCounter, iter->thresholds, false);
            ofPopMatrix();
            
            ofPushMatrix();
            ofTranslate(0, 2*RECT_HEIGHT+30, 0);
            drawGraph(iter->envelopeVec, bufferCounter, iter->thresholds, false);
            ofPopMatrix();
                       
            ofPushMatrix();
            ofTranslate(0, 3*RECT_HEIGHT+40, 0);
            drawGraph(iter->limiterVec, bufferCounter, iter->thresholds, false);
            ofPopMatrix();
        
            ofPopMatrix();
        
            
            //ofSetColor(255*((d+1) & 0x4), 255*((d+1) & 0x2), 255*((d+1) & 0x1));
            
        }
            
        
        drawCounter++;
        
        ofSetColor(225);
        string reportString = "buffers received: "+ofToString(bufferCounter)+"\ndraw routines called: "+ofToString(drawCounter)+"\nticks: " + ofToString(soundStream.getTickCount());
        ofDrawBitmapString(reportString, 32, 589);
    }
    
    quadWarp.end();
    quadWarp.draw();
    
}
//--------------------------------------------------------------
void ofApp::draw(){
	ofBackground(0);
	
	string s = string("") + 
	"\n" + 
	"Purple boxes (4 of them) are generic nodes with simple circular motion, linked in a hierarchy (with ofNode::setParent).\n" + 
	"Yellow boxes (2 of them) are cameras. You are looking through one of them so can only see one box on screen.\n" + 
	"\n" + 
	"KEYS:\n" + 
	"\n" + 
	"z reset transforms\n" + 
	"\n" + 
	"v switch camera to view: " + ofToString(camToView) + "\n" +
	"\n" + 
	
	"o toggle mouse orbit for cam\n" + 
	
	"\n" + 
	"c switch camera to configure: " + ofToString(camToConfigure) + "\n" +
	" t cycle lookat\n" + 
	" p cycle parent\n" +
	" LEFT pan left\n" + 
	" RIGHT pan right\n" + 
	" UP tilt up\n" + 
	" DOWN tilt down\n" + 
	" , roll left\n" + 
	" . roll right\n" + 
	" a truck left\n" + 
	" d truck right\n" + 
	" w dolly forward\n" + 
	" s dolly backward\n" + 
	" r boom up\n" + 
	" f boom down\n";
	glDisable(GL_CULL_FACE);
	ofSetColor(255);
	ofDisableLighting();
	ofDrawBitmapString(s, ofPoint(20, 20));
	
	glEnable(GL_CULL_FACE);
	ofEnableLighting();
	// update camera transforms
	for(int i=0; i<kNumCameras; i++) {
		
		// lookat node if it has one
		if(lookatIndex[i] >= 0) cam[i].lookAt(testNodes[lookatIndex[i]]);
		
		// mouse orbit camera
		if(doMouseOrbit[i] && ofGetMousePressed(0)) {
			static float lon = 0;
			static float lat = 0;
			
			lon = ofClamp(lon + mouseX - ofGetPreviousMouseX(), -180, 180);
			lat = ofClamp(lat + mouseY - ofGetPreviousMouseY(), -90, 90);
			
			if(lookatIndex[i] < 0) {
				cam[i].orbit(lon, lat, orbitRadius);
			} else {
				cam[i].orbit(lon, lat, orbitRadius, testNodes[lookatIndex[1]]);
			}
		}
		
	} 
	
	// activate camera
	cam[camToView].begin();
	
	
	// draw world axis
	ofDrawAxis(100);
	
	// draw testNodes
	for(int i=0; i<kNumTestNodes; i++) {
		ofSetColor(255, 128, 255);
		testNodes[i].draw();
	}
	
	// draw cameras
	for(int i=0; i<kNumCameras; i++) {
		ofSetColor(255, 255, 0);
		cam[i].draw();
		
		// draw line from cam to its lookat
		if(lookatIndex[i] >= 0) {
			ofSetColor(0, 255, 255);
			ofVec3f v1 = cam[i].getGlobalPosition();
			ofVec3f v2 = testNodes[lookatIndex[i]].getGlobalPosition();
            ofDrawLine(v1,v2);
		}
		
		// draw line from cam to its parent
		if(parentIndex[i] >= 0) {
			ofSetColor(255, 255, 0);
			ofVec3f v1 = cam[i].getGlobalPosition();
			ofVec3f v2 = testNodes[parentIndex[i]].getGlobalPosition();
            ofDrawLine(v1,v2);
		}
	}
	
	// restore view to previous state (default openFrameworks view)
	cam[camToView].end();
}
Beispiel #29
0
//--------------------------------------------------------------
void ofApp::setup(){
    
    // SETUP
    // imageDir, imageSavePath = location of images, path to save the final grid image
    // nx, ny = size of the grid (make sure there are at least nx*ny images in imageDir!)
    // w, h = size of the image thumbnails
    // perplexity, theta (for t-SNE, see 'example' for explanation of these)
    
    // -------------- SET FILE I/O ---------------
    
    string imageDir = "../../../../../../../../../Volumes/BenSnell/torsos-7k/photos-jpg"; // source directory
    
    string folderName = "torsos_7k_all"; // destination directory

    // -------------------------------------------
    
    nx = 87;
    ny = 87;
    w = 340;
    h = 510;
    perplexity = 75;
    theta = 0.001;

    
    /////////////////////////////////////////////////////////////////////
    // CCV activations -> t-SNE embedding -> grid assignments
    
    // get images recursively from directory
    ofLog() << "Gathering images...";
    ofDirectory dir = ofDirectory(imageDir);
    scan_dir_imgs(dir);
    if (imageFiles.size() < nx * ny) {
        ofLog(OF_LOG_ERROR, "There are less images in the directory than the grid size requested (nx*ny="+ofToString((nx*ny))+"). Exiting to save you trouble...");
//        ofExit(); // not enough images to fill the grid, so quitting
    }
    
    // load all the images
//    for(int i=0; i<nx*ny; i++) {
//        if (i % 20 == 0)    ofLog() << " - loading image "<<i<<" / "<<nx*ny<<" ("<<dir.size()<<" in dir)";
//        images.push_back(ofImage());
//        images.back().load(imageFiles[i]);
////        images.back().resize(w, h); // ADDED -- DOES THIS WORK?
//    }
    for(int i=0; i<imageFiles.size(); i++) {
        if (i % 20 == 0)    ofLog() << " - loading image "<<i<<" / "<<imageFiles.size()<<" ("<<dir.size()<<" in dir)";
        images.push_back(ofImage());
        images.back().load(imageFiles[i]);
        //        images.back().resize(w, h); // ADDED -- DOES THIS WORK?
    }
    

    // resize images to w x h
    for (int i=0; i<images.size(); i++) {
        if (images[i].getWidth() > images[i].getHeight()) {
            images[i].crop((images[i].getWidth()-images[i].getHeight()) * 0.5, 0, images[i].getHeight(), images[i].getHeight());
        }
        else if (images[i].getHeight() > images[i].getWidth()) {
            images[i].crop(0, (images[i].getHeight()-images[i].getWidth()) * 0.5, images[i].getWidth(), images[i].getWidth());
        }
        images[i].resize(w, h);
    }
    
    // setup ofxCcv
    ccv.setup("image-net-2012.sqlite3");
    
    // encode all of the images with ofxCcv
    ofLog() << "Encoding images...";
    for (int i=0; i<images.size(); i++) {
        if (i % 20 == 0) ofLog() << " - encoding image "<<i<<" / "<<images.size();
        vector<float> encoding = ccv.encode(images[i], ccv.numLayers()-1);
        encodings.push_back(encoding);
    }
    
    // run t-SNE and load image points to imagePoints
    ofLog() << "Run t-SNE on images";
    tsneVecs = tsne.run(encodings, 2, perplexity, theta, true);
    // tsneVecs contains {x, y} for each image in images
    
    // save tsne
    ofFile tsneFile;
    tsneFile.open(folderName + "/" + "tsne_only_metadata.csv", ofFile::WriteOnly);
    tsneFile << "image_name,tsne_x,tsne_y";
    for (int i = 0; i < images.size(); i++) {
        tsneFile << "\n";
        tsneFile << imageFiles[i].getFileName() << ",";
        tsneFile << ofToString(tsneVecs[i][0]) << ",";
        tsneFile << ofToString(tsneVecs[i][1]);
    }
    tsneFile.close();
    
    ofExit(); // TEMP!!!
    
    // solve assignment grid
    vector<ofVec2f> tsnePoints; // convert vector<double> to ofVec2f
    for (auto t : tsneVecs) tsnePoints.push_back(ofVec2f(t[0], t[1]));
    vector<ofVec2f> gridPoints = makeGrid(nx, ny);
    solvedGrid = solver.match(tsnePoints, gridPoints, false);
    
    // export data to csv containing names and positions of images
    bool bExport = true;
    if (bExport) {
        int nImages = images.size(); //nx * ny;
        ofFile file;
        file.open(folderName + "/" + "tsne_metadata.csv", ofFile::WriteOnly);
        file << "image_name,grid_row,grid_column,grid_x_norm,grid_y_norm,tsne_x,tsne_y";
        for (int i = 0; i < nImages; i++) {
            file << "\n";
            file << imageFiles[i].getFileName() << ",";
            file << ofToString(solvedGrid[i].x * (nx-1)) << ",";
            file << ofToString(solvedGrid[i].y * (ny-1)) << ",";
            file << ofToString(solvedGrid[i].x) << ",";
            file << ofToString(solvedGrid[i].y) << ",";
            file << ofToString(tsneVecs[i][0]) << ",";
            file << ofToString(tsneVecs[i][1]);
        }
        file.close();
    }
    
    // save image grid
    bool bSaveGrid = true;
    if (bSaveGrid) {
        string imageGridName = "tsne_grid.png";
        ofFbo fbo;
        fbo.allocate(nx * w, ny * h);
        fbo.begin();
        ofClear(0, 0);
        ofBackground(0);
        for (int i=0; i<solvedGrid.size(); i++) {
            float x = (fbo.getWidth() - w) * solvedGrid[i].x;
            float y = (fbo.getHeight() - h) * solvedGrid[i].y;
            images[i].draw(x, y, w, h);
        }
        fbo.end();
        ofImage img;
        fbo.readToPixels(img);
        img.save(folderName + "/" + imageGridName);
    }
    
    // save image clusters
    bool bSaveClusters = true;
    float imgScale = 0.5;
    if (bSaveClusters) {
        string imageClustersName = "tsne_clusters.png";
        ofFbo fbo;
        fbo.allocate(nx * w, ny * h);
        fbo.begin();
        ofClear(0, 0);
        ofBackground(255);
        for (int i=0; i<tsneVecs.size(); i++) {
            float x = (fbo.getWidth() - w) * tsneVecs[i][0];
            float y = (fbo.getHeight() - h) * tsneVecs[i][1];
            ofSetColor(255, 180);
            images[i].draw(x, y, w * imgScale, h * imgScale);
            ofSetColor(0);
            ofDrawBitmapString(imageFiles[i].getFileName(), x, y + h * imgScale);
        }
        fbo.end();
        ofImage img;
        fbo.readToPixels(img);
        img.save(folderName + "/" + imageClustersName);
    }
    
    // setup gui
    gui.setup();
    gui.add(scale.set("scale", 1.0, 0.0, 1.0));
}
Beispiel #30
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    switch (mode){
            
        case CALIBRATEDEPTH: // depth threshold calibration mode (with gui)
        {
            float w = width*0.5; float h = height*0.5;
            
            layers[0].draw(0,0,w,h);
            layers[1].draw(w,0,w,h);
            layers[2].draw(0,h,w,h);
            layers[3].draw(w,h,w,h);
            
            // draw gui to adjust depth of each layer threshold
            depthGui.draw();
            
            // draw percentage shown of each layer
            ofSetColor(0);
            ofDrawRectangle(0,height-100,width*0.5,100);
            ofSetColor(255);
            ofPushMatrix();
            ofTranslate(10,height-90);
            for (int l=0; l<4; l++){
                ofTranslate(0,20);
                string pct = "% of layer " + ofToString(l) + ": " + ofToString(layers[l].pctShown);
                ofDrawBitmapString(pct, 0,0);
            }
            ofPopMatrix();
            break;
        }
            
        case KINECT: // manual kinect warping mode - shows original kinect depth img and warp result
        {
            kinect.drawDepth(0,0,640,480);
            kinectWarp.draw(650,0,width-660,(width-660)/640*480);
            for (int i=0; i<4; i++){
                if (cornerSelect == i) ofSetColor(0,255,0);
                ofDrawCircle(kinectCorners[i], 5);
                ofSetColor(255);
            }
            break;
        }
            
        case AUTOKINECT: // auto kinect warping mode - shows warped kinect img and CV estimation results
        {
            ofPushMatrix();
            ofScale(width/640,height/480);
            
            kinectRaw.draw(0,0);
            contourFinder.draw();
            
            ofSetColor(0,255,0);
            for (int p=0; p<4; p++){
                ofDrawCircle(kinectCorners[p].x,kinectCorners[p].y,5);
            }
            ofSetColor(255);
            
            ofPopMatrix();
            break;
        }
            
            
        // normal play mode!
    
        default:
        {
            for (int l=layers.size()-1; l>=0; l--){ // draw layers bottom to top
                layers[l].draw(0,0,width,height);
            }
            break;
        }
    }
}