示例#1
0
void TouchManager::drawFingerStatus(int x, int y){
	map<int, TouchEvent*>::iterator it = touches.begin();
	float rectSizeW = 40;
	float rectSizeH = 20;
	float padding = 10;
	int xx = x;
	for (;it!=touches.end(); it++){
		if(it->second){
			string type;
			ofColor c;
			switch (it->second->type) {
				case TouchEvent::TYPE_UP: type= "UP"; c = ofColor::purple; break;
				case TouchEvent::TYPE_DOWN: type= "DOWN"; c = ofColor::yellow;break;
				case TouchEvent::TYPE_MOVE: type= "MOVE"; c = ofColor::blue; break;
				case TouchEvent::TYPE_EXIT: type= "EXIT"; c = ofColor::red; break;
				case TouchEvent::TYPE_ENTER: type= "ENTER"; c = ofColor::green; break;
				case TouchEvent::TYPE_CLICK: type= "CLICK"; c = ofColor::magenta; break;
				case TouchEvent::TYPE_SCROLLWHEEL: type= "CLICK"; c = ofColor::darkorange; break;
			}
			ofSetColor(c);
			ofDrawRectangle(xx, y, rectSizeW, rectSizeH);
			ofSetColor(255);
			ofDrawBitmapString(ofToString(it->first), xx + 4, y + rectSizeH - 5 );
			float secondsAlive = (ofGetSystemTimeMicros() - it->second->timestamp) / 1000000.0f;
			ofDrawBitmapString(type + "\n" + ofToString(secondsAlive, 1), xx + 4, y + rectSizeH + 16);
			xx += padding + rectSizeW;
		}
	}
}
示例#2
0
    void setup() {
        int side = 32;
        int n = side * side;
        
        // first, generate some data on a random walk modulo one
        initial.clear();
        ofVec2f cur;
        ofSeedRandom(ofGetSystemTimeMicros());
        for(int i = 0; i < n; i++) {
            cur += ofVec2f(ofRandomf(), ofRandomf()) * .01;
            cur.x = fmodf(cur.x, 1);
            cur.y = fmodf(cur.y, 1);
            initial.push_back(cur);
        }
        
        // then build the grid
        grid = makeGrid(side, side);

        // and finally, match the grid to the data
        auto start = ofGetElapsedTimeMillis();
        grid = solver.match(initial, grid);
        auto stop = ofGetElapsedTimeMillis();
        
        // 625 points in 64ms
        // 1024 points in 211ms
        // 4096 points in 8841ms
        cout << grid.size() << " points in " <<  (stop - start) << "ms" << endl;
        
        ofBackground(0);
        glPointSize(6);
    }
示例#3
0
//--------------------------------------------------------------
void ReactiveSpaceApp::draw()
{
	glClearColor(0.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT || GL_DEPTH_BUFFER_BIT);
	ofSetColor(255);

#ifdef DEBUG_DRAW
	long newMS = ofGetSystemTimeMicros();
#endif

	pCurrentScene->Render();

#ifdef DEBUG_DRAW
	newMS = ofGetSystemTimeMicros() - newMS;
	sceneDrawMS = (sceneDrawMS * 3 + newMS) * 0.25;
#endif


#ifdef DEBUG_DRAW
	ofPushMatrix();
	ofSetColor(200, 255, 0, 255);
	ofFill();

	ofDrawBitmapString("Framerate: " + ofToString(ofGetFrameRate(), 2), 10.f, 10.f);
	ofDrawBitmapString("Kinect Update Time: " + ofToString(kinectUpdateMS * 0.001f, 1), 10.f, 25.f);
	ofDrawBitmapString("OpenCV Update Time: " + ofToString(openCVUpdateMS * 0.001f, 1), 10.f, 40.f);
	ofDrawBitmapString("Scene Update Time: " + ofToString(sceneUpdateMS * 0.001f, 1), 10.f, 55.f);
	ofDrawBitmapString("Scene Draw Time: " + ofToString(sceneDrawMS * 0.001f, 1), 10.f, 70.f);
	ofPopMatrix();

	openCVManager->debugDraw();
#endif

	//switch scene if necessary
	if (m_currentSceneNum != m_nextSceneNum)
	{
		pCurrentScene->onUnload();
		m_currentSceneNum = m_nextSceneNum;
		pCurrentScene = m_scenes[m_currentSceneNum];
		pCurrentScene->convertPeopleVector();
		pCurrentScene->convertHandVector();
		pCurrentScene->onLoad();
	}
}
示例#4
0
文件: ofApp.cpp 项目: marcpadro/poe
//--------------------------------------------------------------
void ofApp::update(){
    
    if ( ! (++count %= UPDATE_TEMPLATE) ) updateTemplate();
    
    unsigned char* result = resultImage.getPixels();
    
    const int size = resultImage.getPixelsRef().size();
    
    //count = ++count % 200;
    //if (!count) fade(result, resultImage.getPixelsRef().size());
    //resultImage.update();
    
    there_was_buffer = there_is_buffer;
    
    to_feed = MAX_TO_FEED;
    while (to_feed && ( (remaining > 0) || (there_is_buffer = remaining = getBuffer()) ) )
    {
        if (to_feed == MAX_TO_FEED && !is_random ) fade(result, size);
        feed(result);
    }
    
    if (there_is_buffer || there_was_buffer)
    {
        resultImage.update();
        ostringstream stream;
        
        stream << ofGetUnixTime();
        stream << ofGetSystemTimeMicros();
        stream << ".png";
        string filename = stream.str();
        string path = RESULT_DIR + filename;
        resultImage.saveImage(path);
        //cout << "Image Saved: " << path << "\n";
        
#if SAVE_RESULT == 0
        if ( previousResult != "" ) ofFile::removeFile( RESULT_DIR + previousResult );
        
        result_dir.open( RESULT_DIR );
        if (!result_dir.exists()) ofExit();
        
        previousResult = latestResult;
        latestResult = filename;
#endif
    }
    
    
}
示例#5
0
void TouchManager::dispatchTouchUp(int id, const ofVec2f &p)
{
	// check if this touch exists
	map<int, TouchEvent*>::iterator eventIt = touches.find(id);
	if (eventIt == touches.end()) {
		ofLogWarning("TouchManager", "received touchUp for id (%d) without touchDown. ignoring this touch.", id);
		return;
	}

	// update touch info
	TouchEvent* event = eventIt->second;
	event->prevPosition = event->position;
	event->prevVelocity = event->velocity;
	event->prevTimestamp = event->timestamp;
	event->position = p;
	event->timestamp = ofGetSystemTimeMicros();

	// there is a problem with calculating the velocity when delta time is too small
	// sometimes we get events with delta time of 0 or 1 ms
	if (event->timestamp - event->prevTimestamp > 5000) {
		event->velocity = (p - event->prevPosition)*1000000 / (event->timestamp-event->prevTimestamp);
		event->velocitySmoothed += (event->velocity-event->velocitySmoothed)*velocitySmoothCoeff;
	}

	Node* node = getComponentUnder(p);
	if (node == NULL) {
		ofLogError("TouchManager","could not find node for touchUp");
		endTouch(id);
		return;
	}

	if (event->receiver == NULL) {
		ofLogNotice("TouchManager","this touch does not belong to any component");
		endTouch(id);
		return;
	}

    event->type = TouchEvent::TYPE_UP;
	event->receiver->touchUp(id, event);

	ofNotifyEvent(eventEveryTouchUp, *event, this);

	endTouch(id);
}
示例#6
0
//------------------------------------------------------------------------------
void ofApp::setup()
{
	//ofToggleFullscreen();
	
	ofBackground(0,0,0);	
    ofSeedRandom(ofGetSystemTimeMicros());
    ofSetLogLevel(OF_LOG_VERBOSE);
	ofLogToFile("Log.txt",false);
	font.loadFont("frabk.ttf", 26, false);

	settings.useHDMIForAudio = false;	//default true
	settings.enableLooping = false;		//default true
	settings.enableTexture = true;		//default true
	settings.listener = this;			//this app extends ofxOMXPlayerListener so it will receive events ;
	
	if(!settings.enableTexture) {
		settings.displayRect.width=320;
		settings.displayRect.height=240;
		settings.displayRect.x =0;
		settings.displayRect.y =0;
	}		  
    
    string path = "videos";
    int maxvids = 100;
	vidreader.setup(maxvids,path);
	bLoading = true;
	bInitVids = false;
    bShowInfo = true;
    bTriggerNextMovie = false;
    bReceivedEvent = false;

    bExiting = false;	
	bEndMovie = false;
	ratio = 0.0f;
	currentVideo = "";
	curTime = ofGetElapsedTimeMillis();
	prevTime = curTime;
	
    ofAddListener(loader.youTubeURLEvent, this, &ofApp::receivedYouTubeURLEvent);
    
    getNewVideo();

}
示例#7
0
//--------------------------------------------------------------
void ReactiveSpaceApp::update()
{
	//get time since last step
	float stepTime = ofGetElapsedTimeMillis();
	stepTimeDelta = stepTime - stepTimeLast;

	float timeScale = stepTimeDelta / 16.f;

#ifdef DEBUG_DRAW
	long newMS = kinectUpdateMS;
	newMS = ofGetSystemTimeMicros();
#endif

	//update kinect
	HRESULT hr = kinectManager->update(timeScale);
	if (FAILED(hr) && !kinectManager->isFailed())
	{
		cout << "\nkinect failed to update frame";
		//do something so user knows
	}

#ifdef DEBUG_DRAW
	newMS = ofGetSystemTimeMicros() - newMS;
	kinectUpdateMS = (kinectUpdateMS * 3 + newMS) * 0.25;
	newMS = ofGetSystemTimeMicros();
#endif

	//update open cv
	openCVManager->update(timeScale);

#ifdef DEBUG_DRAW
	newMS = ofGetSystemTimeMicros() - newMS;
	openCVUpdateMS = (openCVUpdateMS * 3 + newMS) * 0.25;
#endif

	//set last step time to current time
	stepTimeLast = stepTime;

	//step scene
#ifdef DEBUG_DRAW
	newMS = ofGetSystemTimeMicros();
#endif

	pCurrentScene->Update(timeScale);

#ifdef DEBUG_DRAW
	newMS = ofGetSystemTimeMicros() - newMS;
	sceneUpdateMS = (sceneUpdateMS * 3 + newMS) * 0.25;
#endif
}
示例#8
0
void TouchManager::dispatchTouchMove(int id, const ofVec2f &p)
{
	// check if this touch exists
	map<int, TouchEvent*>::iterator eventIt = touches.find(id);
	if (eventIt == touches.end()) {
		ofLogWarning("TouchManager", "received touchMove for id (%d) without touchDown. ignoring this touch.", id);
		return;
	}

	// update touch info
	TouchEvent* event = eventIt->second;

	// discard if same position as the previous touch
	if (event->prevPosition == p) {
		return;
	}

	event->travelDistance += fabs(event->prevPosition.x - event->position.x) + fabs(event->prevPosition.y - event->position.y); //manhattan distance to save some cpu
	event->prevPosition = event->position;
	event->prevVelocity = event->velocity;
	event->prevTimestamp = event->timestamp;
	event->position = p;
	event->timestamp = ofGetSystemTimeMicros();

	// there is a problem with calculating the velocity when delta time is too small
	// sometimes we get events with delta time of 0 or 1 ms
	if (event->timestamp - event->prevTimestamp > 5000) {
		event->velocity = (p - event->prevPosition)*1000000 / (event->timestamp-event->prevTimestamp);
		event->velocitySmoothed += (event->velocity-event->velocitySmoothed)*velocitySmoothCoeff;
	}


	if (event->receiver == NULL) {
		// the original component of this touch was destroyed
		// ignore this touch
		ofLogVerbose("TouchManager","ignoring touch id: %d",id);
		return;
	}

	// find node below touch point
	Node *node = getComponentUnder(p);
	if (node == NULL) {
		ofLogError("TouchManager","could not find node for touchMove");
		return;
	}

	// handle touch exit/enter events
	if (node != event->receiver &&
		event->lastSeenAbove == event->receiver) {
		// touch just went out of the origin receiver area,
		// send touchExit
		event->type = TouchEvent::TYPE_EXIT;
		event->receiver->touchExit(id, event);
	}
	else if (node == event->receiver &&
			 event->lastSeenAbove != event->receiver) {
		// touch just went into the origin receiver area,
		// send touchEnter
		event->type = TouchEvent::TYPE_ENTER;
		event->receiver->touchEnter(id, event);
	}

	event->lastSeenAbove = node;

	// send touchMove
	event->type = TouchEvent::TYPE_MOVE;
	event->receiver->touchMove(id, event);

	// notify listeners for every touch move
	ofNotifyEvent(eventEveryTouchMove, *event, this);
}
示例#9
0
//--------------------------------------------------------------
void ofApp::draw(){
	ofSleepMillis(100);
	
	int newVal = lidar_read(fd);
	unsigned char  st = lidar_status(fd);
	//ver = lidar_version(fd);
	//printf("%3.0d cm \n", res);
	lidar_status_print(st);

	if (newVal < 2) {
		// Handle strange case where lidar reports 1cm when should be infinity
		newVal = 10000;
	}
	
	// increment up to max smoothing (deals with initial state)
	if (nSamplesToSmooth < maxSamplesToSmooth ) nSamplesToSmooth++; 
	// Calculate the weight of new value
	float newWeight = ((float)1)/((float)nSamplesToSmooth); 
	// Calculate the smoothed PWM value
	smoothPwm = ((float) newVal)*newWeight + smoothPwm*(1-newWeight);
	
	counter++;
	
	if (pitchBend) { // Pitch bend mode
		//cout << ofGetSystemTimeMicros() << "," << blinkTimer << endl;
		if (ofGetSystemTimeMicros() - blinkTimer >= 200000) {
			
			// Blink the LED
			if (gpio15outState) {
				gpio15->setval_gpio("0");
				gpio15outState = false;
			} else {
				gpio15->setval_gpio("1");
				gpio15outState = true;
			}
			
			if (gpio21outState) {
				gpio21->setval_gpio("0");
				gpio21outState = false;
			} else {
				gpio21->setval_gpio("1");
				gpio21outState = true;
			}
			
			// Play sound
			pitchSound.play();
			float soundSpeed = 1.5f - ofMap(smoothPwm, minDist, maxDist, 0.f, 1.f, true);
			pitchSound.setSpeed( soundSpeed );
			//ofSoundSetVolume(ofClamp(0.5f + smoothPwm, 0, 1));
			cout << getDateTimeString() << ", " << counter << " loops, " << ofGetFrameRate() 
				<< "Hz , " << smoothPwm << " cm" << " , " << soundSpeed <<", " << (int) st;
			if (gpio15outState){
				cout << ",LED=ON";
			} else {
				cout << ",LED=OFF";
			}
			cout << endl;
			
			blinkTimer = ofGetSystemTimeMicros();
			counter = 0;
		}
	} else if (volBend) { // Volume bend mode
		float soundVolume = 1.f - ofMap(smoothPwm, minDist, maxDist, 0.f, 1.f, true);
		
		if (ofGetSystemTimeMicros() - blinkTimer >= 1000000) {
			volSound.play();
			
			// Blink the LED
			if (gpio15outState) {
				gpio15->setval_gpio("0");
				gpio15outState = false;
			} else {
				gpio15->setval_gpio("1");
				gpio15outState = true;
			}
			
			if (gpio21outState) {
				gpio21->setval_gpio("0");
				gpio21outState = false;
			} else {
				gpio21->setval_gpio("1");
				gpio21outState = true;
			}
			
			cout << getDateTimeString() << ", " << counter << " loops, " << ofGetFrameRate() 
				<< "Hz , " << smoothPwm << " cm" << " , " << soundVolume <<", " << (int) st;
			if (gpio15outState){
				cout << ",LED=ON";
			} else {
				cout << ",LED=OFF";
			}
			cout << endl;
				
			blinkTimer = ofGetSystemTimeMicros();
			counter = 0;
		}
		volSound.setVolume(soundVolume);
		ofSoundSetVolume(soundVolume);
	}
	
	// Log data to file
	if (ofGetElapsedTimeMillis() - logTimer >= 60000) {

		
		// Get the temperature
		FILE *temperatureFile;
		double T;
		temperatureFile = fopen ("/sys/class/thermal/thermal_zone0/temp", "r");
		if (temperatureFile == NULL) {
			cout << "Failed to read temp file\n";
		} else {
			fscanf (temperatureFile, "%lf", &T);
			T /= 1000;
			//printf ("The temperature is %6.3f C.\n", T);
			fclose (temperatureFile);
		}
		
		// Log the data
		logTimer = ofGetElapsedTimeMillis();
		//string logFileName = "/logs/livestream/livestream01.log";
		string logFileName = "/logs/livestream/livestream_" + hostname + ".log";
		ofstream mFile;
		mFile.open(logFileName.c_str(), ios::out | ios::app);
		mFile << getDateTimeString() << ",TC," << T;
		for (int j=0; j<nSensors; j++) {
			float tempData = tempSensor.read(j);
			mFile << ",T" << j << "," << tempData;
		}
		mFile << ",DL," << smoothPwm << " cm" << ",LR," << ofGetFrameRate() << "Hz,";
		mFile << endl;
		mFile.close();
	}
}
示例#10
0
//--------------------------------------------------------------
void ofApp::setup(){
	ofSetVerticalSync(false);
	//ofSetFrameRate(10000)
	
	counter = 0;
	blinkTimer = ofGetSystemTimeMicros();
	logTimer = ofGetElapsedTimeMillis();
	
	// Setup GPIOs
	gpio15  = new GPIO("15");
	gpio15->export_gpio();
	gpio15->setdir_gpio("out");
	gpio15->setval_gpio("0");
	gpio15outState = false;
	
	gpio21  = new GPIO("21");
	gpio21->export_gpio();
	gpio21->setdir_gpio("out");
	gpio21->setval_gpio("0");
	gpio21outState = false;

	// PWM smoothing parameters
	nSamplesToSmooth = 0;
	maxSamplesToSmooth = 1; // determines smoothing
	smoothPwm = 0; // smoothed PWM value
	minDist = 30; //cm
	maxDist = 30*20; //cm
	
	// Sound output
	pitchSound.loadSound("sounds/INT18PIPES1.mp3");
	pitchSound.setVolume(0.3f);
	pitchSound.setMultiPlay(false);
	
	volSound.loadSound("sounds/Tp10.wav");
	volSound.setVolume(0.3f);
	volSound.setMultiPlay(true);
	
	ofSoundSetVolume(1.0f);

	volBend = true;
	pitchBend = false;
	
	// Init I2C
	fd = lidar_init(false);
	if (fd == -1) 
	{
		printf("initialization error\n");
		ofApp::exit();
	}
	
	// Get the host name
	int z;  
	char buf[32];  
	z = gethostname(buf,sizeof buf);
	if ( z != -1 ) {
		hostname = string(buf);
		//printf("host name = '%s'\n",buf); 
		cout << "host name = " 	<< hostname << endl;
	} else {
		cout << "host name unknown" << endl;
		hostname = "unknown";
	}
	
	// Write initialization to the log
	string logFileName = "/logs/livestream/livestream_" + hostname + ".log";
	ofstream mFile;
	mFile.open(logFileName.c_str(), ios::out | ios::app);
	mFile << getDateTimeString() << ",INITILIZATION" << endl;
	mFile.close();
	
	nSensors = tempSensor.listDevices();
}