Beispiel #1
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    ofSetColor(255,160);
    ofDrawBitmapString("OF FPS "+ofToString(ofGetFrameRate()), 30, ofGetWindowHeight()-50);
    ofDrawBitmapString("Robot FPS "+ofToString(robot.robot.getThreadFPS()), 30, ofGetWindowHeight()-65);
    
    gizmo.setViewDimensions(viewportSim.width, viewportSim.height);
    
    // show realtime robot
    cams[0]->begin(viewportReal);
    tcpNode.draw();
    paths.draw();
    robot.robot.model.draw();
    drawMocap();
    cams[0]->end();
    
    // show simulation robot
    cams[1]->begin(viewportSim);
    if (parameters.bFollow)
        gizmo.draw(*cams[1]);
    paths.draw();
    robot.movement.draw(0);
    drawMocap();
    cams[1]->end();
    
    drawGUI();
    
}
Beispiel #2
0
//--------------------------------------------------------------
// MARK: DRAW
//--------------------------------------------------------------
void testApp::draw(){

    fbo.begin();
    
    glPushAttrib(GL_ALL_ATTRIB_BITS);  
    glEnable(GL_BLEND);  
    glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);  
    
    ofSetColor(0, iFboAlpha);
    ofRect(0, 0, FBO_W, FBO_H);
    
    runParticles(streetParticles, *streetPath);
    runParticles(neighborhoodParticles, *neighborhoodPath);
    runParticles(cityParticles, *cityPath);
    
    glDisable(GL_BLEND);  
    glPopAttrib(); 
        
    fbo.end();
    
    ofEnableAlphaBlending();
    fbo.draw(0, 0);
    ofDisableAlphaBlending();
    
    if(isGUIActive) {
        ofShowCursor();
        drawGUI();
    } else {
        ofHideCursor();
    }
    
}
Beispiel #3
0
/**
 * @brief Main run function for this stage. Performs all processing.
 *
*/
void BoxesStage::run(void)
{
	//Save state for next draw call
	glPushMatrix();

	//Save state to change back to 2D after switching to 3D
	glPushMatrix();

	//Switch to 3D
	setup3D();

	//Disable blending temporarily so we can draw the teapot. Draw the teapot, and enable it again.
	glDisable(GL_BLEND);
	drawTeapot();	
	glEnable(GL_BLEND);

	//Switch back for 2D
	glPopMatrix();
	
	//Draw GUI on top
	drawGUI();
	
	//And revert for the next draw call
	glPopMatrix();
}
Beispiel #4
0
//--------------------------------------------------------------
void ccs::setup(){
	svrGui = ofxGui::Instance(this);
	//ofxNxmlFile storedFile("config.nxml");
	setupServer();
	drawGUI();
	serverIsRunning = false;
	runServerRequest = srvAutoStart;
}
void FrameThresholder::process(unsigned char *src, unsigned char *dest, SDL_Surface *display) {

    tiled_bernsen_threshold( thresholder, dest, src, srcBytes, width,  height, tile_size, gradient );

    //simple_threshold( src, srcBytes,dest,width, height,128 );
    //simple_adaptive_threshold( src, srcBytes,dest,width, height, 16 );
    //overlapped_adaptive_threshold( src, srcBytes,dest,width, height, 8 );
    //overlapped_adaptive_threshold2( src, srcBytes,dest,width, height, 32, gradient );

    if (setGradient) drawGUI(display);
}
Beispiel #6
0
// ========================= Setup must be in this order
void ccwServer::setup()
{
	webGuiPort = DEFAULT_WEBGUI_PORT;
	resetStateFlags();
	
	ccwGui = ofxGui::Instance(this); // Instance handle
	
	testForPlugins();
	setupHttpServer();
	drawGUI();
	populateWebGui();
}
void XBScene1::drawIntoFBO()
{
    XBScene1GUI *myGUI = (XBScene1GUI *) gui;

    float windowScale = XBSettingsManager::getInstance().getWindowScale();

    fbo.begin();
    {
        ofPushMatrix();
        ofScale(windowScale, windowScale);
        if (showFacadeImage)
            templateImage.draw(0, 0);
        else
            ofBackground(0);

        if (showTemplate) {
            ofSetColor(255);
            svg.draw();
        }

        drawDirector();
        drawPiano();

        // draw time markers
        if (myGUI->showTimeMarker) {
            ofSetColor(220);
            ofDrawLine(0, violinTimeIndex, ofGetWidth() / windowScale, violinTimeIndex);
            ofDrawLine(celloTimeIndex, 0, celloTimeIndex, ofGetHeight() / windowScale);
        }

        if(myGUI->drawWindows)
            drawWindows();

        // mask for removing the windows
        if (maskWindows == true) {
            ofPushStyle();
            ofEnableBlendMode(OF_BLENDMODE_MULTIPLY);
            mask.draw(0, 0);
            ofPopStyle();
        }
        drawViolinCello();
        ofPopMatrix();
        drawMusiciansWindows();

        drawGUI();
    }
    fbo.end();
    blur.apply(&fbo, 1, myGUI->blurAmount);
    if(animating)
        myGUI->glowAmount.getParameter().cast<int>() = animtedGlowAmount;
    applyPostFX();
}
Beispiel #8
0
int main(int argc,char** argv)
{
	pthread_t listener_thread;
	RawMode = false;
	if (argc == 3)
	{
		if(strcmp(argv[2],"debug")==0)
		sensor.SetDebug(4);
	}
	if (argc >= 2)
	{
		fflush(NULL);
		if(!sensor.Open(argv[1]))
		{
			printf("Error: Could not open device %s\n",argv[1]);
			_exit(0);
		}
		fflush(NULL);
		if(!sensor.VerifyConnection())
		{
			printf("Error: Could not verify connection\n");
			_exit(0);
		}

	}	
	else
	{
		printf ("ASIM Tester %s\n",SDM_VERSION);
		printf("Usage: %s device [debug]\n",argv[0]);
		_exit(0);
	}
	
	/* initialize curses*/
	initscr();
	keypad(stdscr,TRUE);
	nonl();
	cbreak();
	noecho();

	drawGUI();
	pthread_create(&listener_thread,NULL,&Listener,NULL);
	sleep(2);
	//reset();
	//sleep(1);
	init();
	sleep(1);
	version();
	while(1)
		menu();
	pthread_join(listener_thread,NULL);
	return 0;
}
Beispiel #9
0
void ofApp::draw(){

    if (state.syphonEnabled) {
        outputSyphonServer.publishTexture(&texture);
    } else {
        ofPushMatrix();
            ofTranslate((ofGetWidth() - texture.getWidth()) / 2.0, 0);
            texture.draw(0, 0);
        ofPopMatrix();
    }
    
    drawGUI();
}
void client::draw()
{
    ofSetLineWidth(1);
    ofPushMatrix();
    ofTranslate(area.getX(),area.getY());
    drawGUI();
    string msg;
    msg += name + " ip " + ofToString(ip);
    msg += " : " + ofToString(port);

    ofSetColor(255,255,255);
    verdana14.drawString(msg, 20, 20);
    verdana14.drawString("Rigid", 40, 50);
    verdana14.drawString("Markers", 140, 50);
    verdana14.drawString("Skeleton", 240, 50);

    
    ofPopMatrix();
}
Beispiel #11
0
void BaseApp::makeFrame() {
    if (!configDialog->isVisible()) controls();

    renderer->resetStatistics();

#ifdef PROFILE
    if (keys[KEY_F11]) {
        renderer->profileFrameStart(frameTime);
    }
#endif

    beginFrame();
    drawFrame();
    drawGUI();
    endFrame();

#ifdef PROFILE
    renderer->profileFrameEnd();
#endif


#define SAMPLE_INTERVAL 0.1f

    // Output frameTimes if enabled
    static float accTime = 0;
    static int nFrames = 0;

    if (benchMarkFile) {
        accTime += frameTime;
        nFrames++;

        if (accTime >= SAMPLE_INTERVAL) {
            fprintf(benchMarkFile, "%f\n", nFrames / accTime);

            nFrames = 0;
            accTime = 0;
        }
    } else {
        nFrames = 0;
        accTime = 0;
    }
}
Beispiel #12
0
void DtouchFinder::process(unsigned char *src, unsigned char *dest, SDL_Surface *display) {

	FiducialData *fdata = NULL;
	int count = frecognition->process(src,dest,&fdata);

	// process symbols
	for(int i=0;i< count;i++) {

		//apply distortion
		int index = fdata[i].getCentre().y*width+fdata[i].getCentre().x;
		fdata[i].setCentre(DTPoint(dmap[index].x,dmap[index].y));

		FiducialObject *existing_fiducial = NULL;

		// check if we have an ID/Position conflict
		for (std::list<FiducialObject>::iterator fiducial = fiducialList.begin(); fiducial!=fiducialList.end(); fiducial++) {

			float distance = fiducial->distance(fdata[i].getCentre().x,fdata[i].getCentre().y);

			if (fdata[i].getId()==fiducial->fiducial_id) {
				// find and match a fiducial we had last frame already ...
				if(existing_fiducial) {
					if (distance<existing_fiducial->distance(fdata[i].getCentre().x,fdata[i].getCentre().y))
						existing_fiducial = &(*fiducial);
				} else {
					existing_fiducial = &(*fiducial);
					for (int j=0;j<count;j++) {
						if ((i!=j) && (fiducial->distance(fdata[j].getCentre().x,fdata[j].getCentre().y)<distance)) {
							existing_fiducial = NULL;
							break;
						}
					}	
				}
			} else if (distance<5.0f) {
				// do we have a different ID at the same place?

				// this correct wrong or invalid fiducial IDs
				// assuming that between two frames
				// there can't be a rapid exchange of tw symbols
				// at the same place
				fdata[i].setId(fiducial->fiducial_id);
				existing_fiducial = &(*fiducial);
				break;
			}
		}
		
		if  (existing_fiducial!=NULL) {
			// just update the fiducial from last frame ...
			existing_fiducial->update(fdata[i].getCentre().x,fdata[i].getCentre().y,fdata[i].getAngle(),0,0);
		} else {
			// add the newly found object
			FiducialObject addFiducial(session_id, fdata[i].getId(), width, height);
			addFiducial.update(fdata[i].getCentre().x,fdata[i].getCentre().y,fdata[i].getAngle(),0,0);
			fiducialList.push_back(addFiducial);
#ifndef NO_MIDI
			if (midi_server!=NULL) midi_server->sendAddMessage(fdata[i].getId());
#endif
			if (msg_listener) {
				//char add_message[16];
				//sprintf(add_message,"add obj %d %ld",fdata[i].getId(),session_id);
				//msg_listener->setMessage(std::string(add_message));
				std::stringstream add_message;
				add_message << "add obj " << " " << fdata[i].getId() << " " << session_id;
				msg_listener->setMessage(add_message.str());
			}
			session_id++;
		}

		drawObject(fdata[i].getId(),(int)(fdata[i].getCentre().x),(int)(fdata[i].getCentre().y),display,1);
	}

	if (tuio_server) sendTuioMessages();
#ifndef NO_MIDI
	if (midi_server) sendMidiMessages();
#endif
	if (show_grid) drawGrid(src,dest,display);
	if (show_settings) drawGUI(display);
	delete[] fdata;
}
Beispiel #13
0
void Engine::draw() {
    this->getMap()->draw();
    drawGUI();
}
Beispiel #14
0
//--------------------------------------------------------------
void testApp::draw(){

// MARK: DRAW KINECT POINT CLOUD    
//    int inc = 20;
//    for (int i = 0; i < kinect.pointCloud.size(); i+=inc) {
//        
//        float z = (kinect.pointCloud[i].z < 0.001) ? 1 : kinect.pointCloud[i].z;
//
//        float prox = (1.0 - z);
//        float sz = pow(prox, 3) * inc;
//        ofCircle(kinect.pointCloud[i].x * (float)ofGetWidth(), kinect.pointCloud[i].y * (float)ofGetHeight(), sz);
//
//        int limit_w = kinect.getOutputWidth();
//        if(i % limit_w == 0) {
//            i += inc * limit_w;
//        }
//    }
    
    
// MARK: DRAW BOX2D PARTICLES TO FBO
    fbo.begin();
    ofClear(0, 0, 0, 255);
    
    if(isFilterActive) {
        shader.begin();
        shader.setUniform1i("u_ratio", ledRatio);
    }
    
    for(int i = 0; i < b2dParticles.size(); i++) {
        CustomParticle p = b2dParticles[i];
        Data * customData = (Data*)p.getData();        
        
        
        if(kinect.pointCloud.size() > 0) {
//            int relativeX = ofMap(p.getPosition().x, 0, FBO_W, 0, kinect.getOutputWidth());            
            int relativeX = ofMap(p.getPosition().x, 0, FBO_W, 0, OUTPUT_SCREEN_W);
            relativeX = ofMap(relativeX, 0, OUTPUT_SCREEN_W, 0, kinect.getOutputWidth());
            int relativeY = ofMap(p.getPosition().y, 0, FBO_H, 0, kinect.getOutputHeight());
            
            int relativeKinectIndex = relativeX + (kinect.getOutputWidth() * relativeY);
            
            if(relativeKinectIndex < kinect.pointCloud.size()) {
                ofPoint kinectPoint = kinect.pointCloud[relativeKinectIndex];
                float z = (kinectPoint.z < 0.001) ? 1 : kinectPoint.z;
                float prox = 1.2 - z;
                
                float sz = 0;
                switch(customData->scope) {
                    case PERSONAL:
                        sz += personalMinParticleSize;
                        break;
                    case NEIGHBORHOOD:
                        sz += neighborhoodMinParticleSize;
                        break;
                    case CITY:
                        sz += cityMinParticleSize;
                        break;
                }                
                sz += prox * 80.0;

                float r = p.getRadius();
                
                // property = (target - property) / speed
                r += (sz - r) / 4.0f;
                
                p.setRadius(r);
            }
        }    

        p.draw();
    }
    
    if(isDebugingBox2d) { 
        ofEnableAlphaBlending();
        
        // DRAW JOINTS
        for(int j = 0; j < b2dJoints.size(); j++) {
            ofSetColor(255, 70);
            b2dJoints[j].draw();        
        }
        
        // DRAW ANCHORS
        ofSetColor(70);
        ofCircle(personalAnchorBottom.getPosition(), 4);
        ofCircle(personalAnchorTop.getPosition(), 4);
        ofCircle(personalAnchorLeft.getPosition(), 4);
        ofCircle(personalAnchorRight.getPosition(), 4);
        ofCircle(neighborhoodAnchorBottom.getPosition(), 4);
        ofCircle(neighborhoodAnchorTop.getPosition(), 4);
        ofCircle(neighborhoodAnchorLeft.getPosition(), 4);
        ofCircle(neighborhoodAnchorRight.getPosition(), 4);
        ofCircle(cityAnchorBottom.getPosition(), 4);
        ofCircle(cityAnchorTop.getPosition(), 4);
        ofCircle(cityAnchorLeft.getPosition(), 4);
        ofCircle(cityAnchorRight.getPosition(), 4);
    }

    if(isFilterActive) {        
        shader.end();
    }
    
    fbo.end();
    
    ofSetColor(255);
    fbo.draw(0,0);
// --------------------------------------------
    
// CHEAT: PILLARS MASK
    ofSetColor(25, 255);
    ofFill();
    ofRect(OUTPUT_SCREEN_W/3.0, 0, (FBO_W-OUTPUT_SCREEN_W)/2.0, FBO_H);
    ofRect(FBO_W - (OUTPUT_SCREEN_W/3.0) - (FBO_W-OUTPUT_SCREEN_W)/2.0, 0, (FBO_W-OUTPUT_SCREEN_W)/2.0, FBO_H);
// --------------------------------------------
    
    if(isGUIActive) {
        drawGUI();
    }
    
}
void FidtrackFinderClassic::process(unsigned char *src, unsigned char *dest, SDL_Surface *display) {

	// segmentation
	step_segmenter( &segmenter, dest );
	// fiducial recognition
	int count = find_fiducials120( fiducials, MAX_FIDUCIAL120_COUNT,  &partialSegmentTopology, &segmenter);

	// process symbols
	for(int i=0;i< count;i++) {

		//apply distortion
		int index = (int)floor(fiducials[i].y)*width+(int)floor(fiducials[i].x);
		fiducials[i].x = dmap[index].x;
		fiducials[i].y = dmap[index].y;

		FiducialObject *existing_fiducial = NULL;

		// check if we have an ID/Position conflict
		// or correct an INVALID_FIDUCIAL120_ID if we had an ID in the last frame
		for (std::list<FiducialObject>::iterator fiducial = fiducialList.begin(); fiducial!=fiducialList.end(); fiducial++) {

			float distance = fiducial->distance(fiducials[i].x,fiducials[i].y);

			if (fiducials[i].id==fiducial->fiducial_id) {
				// find and match a fiducial we had last frame already ...
				if(existing_fiducial) {
					if (distance<existing_fiducial->distance(fiducials[i].x,fiducials[i].y))
						existing_fiducial = &(*fiducial);
				} else {
					existing_fiducial = &(*fiducial);
					for (int j=0;j<count;j++) {
						if ((i!=j) && (fiducial->distance(fiducials[j].x,fiducials[j].y)<distance)) {
							existing_fiducial = NULL;
							break;
						}
					}	
				}
			} else  if (distance<5.0f) {
				// do we have a different ID at the same place?
	
				// this should correct wrong or invalid fiducial IDs
				// assuming that between two frames
				// there can't be a rapid exchange of tw symbols
				// at the same place	

				/*if (fiducials[i].id==INVALID_FIDUCIAL120_ID) printf("corrected invalid ID to %d at %f %f\n",fiducials[i].id,fiducials[i].x/width,fiducials[i].y/height);
				else if (fiducials[i].id!=pos->classId) printf("corrected wrong ID from %d to %d at %f %f\n",fiducials[i].id,pos->classId,fiducials[i].x/width,fiducials[i].y/height);*/

				fiducials[i].id=fiducial->fiducial_id;
				existing_fiducial = &(*fiducial);
				break;
			}
		}

		if  (existing_fiducial!=NULL) {
			// just update the fiducial from last frame ...
			existing_fiducial->update(fiducials[i].x,fiducials[i].y,fiducials[i].angle,0,0);
		} else if  (fiducials[i].id!=INVALID_FIDUCIAL120_ID) {
			// add the newly found object
			FiducialObject addFiducial(session_id, fiducials[i].id, width, height);
			addFiducial.update(fiducials[i].x,fiducials[i].y,fiducials[i].angle,0,0);
			fiducialList.push_back(addFiducial);
#ifndef DISABLE_MIDISERVER
			if (midi_server!=NULL) midi_server->sendAddMessage(fiducials[i].id);
#endif
			if (msg_listener) {
				//char add_message[16];
				//sprintf(add_message,"add obj %d %ld",fiducials[i].id,session_id);
				//msg_listener->setMessage(std::string(add_message));
				std::stringstream add_message;
				add_message << "add obj " << fiducials[i].id << " " << session_id;
				msg_listener->setMessage(add_message.str());
			}
			session_id++;
		}

		if (fiducials[i].id!=INVALID_FIDUCIAL120_ID) drawObject(fiducials[i].id,(int)(fiducials[i].x),(int)(fiducials[i].y),display,1);

	} 

	if (tuio_server) sendTuioMessages();
#ifndef DISABLE_MIDISERVER
	if (midi_server) sendMidiMessages();
#endif
	if (show_grid) drawGrid(src,dest,display);
	if (show_settings) drawGUI(display);
}
Beispiel #16
0
void loop() {
    // Though counter-intuitive, game creation cannot be in setup because of varying arduino boot times and boot gibberish
    if (!gameCreated) {
        drawGUI();
        while(!waitUntil(JOYSTICK_BUTTON_PIN, false));
        if (!startNetwork()) {
            tft.fillScreen(ST7735_BLACK); // we must clear all conflicting messages from screen
            tft.setCursor(0,0);
            dualPrint("Network connection failed!");
            dualPrint("Please ensure:");
            dualPrint("1) both arduinos are connected");
            dualPrint("2) both parties pressed the joystick");
            dualPrint("If both are true, consult someone who");
            dualPrint("looks like he knows what he's talking about");
            dualPrint("Reset both Arduinos to try again");
            while(1);
        }
        /* Extensibility Goal:
         * Enable colour selection here, time permissible
         */
        gameCreated = true;
    }
    if (!gameStarted) {
        setSpawns(&player1, &player2);
        setColour(&player1, &player2);
        tft.fillScreen(ST7735_BLACK);
        startCountdown();
        gameStarted = true;
    }
    winner = gameOver(&player1.currentPosition, &player2.currentPosition);
    if (winner) {
        tft.setCursor(0, 80);
        String message;
        switch (winner) {
        case -1:
            message = "YOU SUPER TIE";
            break;
        case 1:
            message = "YOU SUPER WIN";
            player1.score++;
            break;
        case 2:
            message = "YOU SUPER LOSE";
            player2.score++;
            break;
        }
        tft.println(message);
        tft.println("SCORES:");
        tft.print("You: ");
        tft.print(player1.score);
        tft.print(" | Him: ");
        tft.println(player2.score);
        tft.println("Again? <Press Joystick>");
        waitUntil(JOYSTICK_BUTTON_PIN, LOW);
        memset(&wallPositions, 0, 2560); // 2560 is a magic number because size_ts were acting unexpectedly
        gameStarted = false;
        tft.fillScreen(ST7735_BLACK);
    } else {
        // add a wall ad draw car at current position
        addWallPosition(player1.currentPosition);
        addWallPosition(player2.currentPosition);
        tft.fillRect(player1.currentPosition.x, player1.currentPosition.y, 2, 2, player1.colour);
        tft.fillRect(player2.currentPosition.x, player2.currentPosition.y, 2, 2, player2.colour);
        movement_t newDirection = getJoystickInput();
        if (validInput(newDirection, player1.direction)) player1.direction = newDirection;
        sendDeltas(&player1.direction);
        receiveDeltas(&player2.direction);
        player1.currentPosition.x += player1.direction.x;
        player1.currentPosition.y += player1.direction.y;
        player2.currentPosition.x += player2.direction.x;
        player2.currentPosition.y += player2.direction.y;
        delay(75); // this is how we control the game speed
        /* Extensibility Goal:
         * Find a more efficient and reliable way of controlling game speed.
         * Implement it, and allow it to be customized
         */
    }
}
Beispiel #17
0
// -------------------------------------------------------
// render
// -------------------------------------------------------
void MeshGenTestState::render() {
	_scene->draw();
	drawGUI();
}
void FidtrackFinder::process(unsigned char *src, unsigned char *dest, SDL_Surface *display) {

/*
	#ifdef WIN32
		long start_time = GetTickCount();
	#else
		struct timeval tv;
		struct timezone tz;
		gettimeofday(&tv,&tz);
		long start_time = (tv.tv_sec*1000000)+(tv.tv_usec);
	#endif
*/

	// segmentation
	step_segmenter( &segmenter, dest );
	// fiducial recognition
	int fid_count = find_fiducialsX( fiducials, MAX_FIDUCIAL_COUNT,  &fidtrackerx, &segmenter, width, height);

	float total_leaf_size = 0.0f;
	float total_fiducial_size = 0.0f;
	int valid_fiducial_count = 0;

	// process found symbols
	for(int i=0;i< fid_count;i++) {
		if ( fiducials[i].id >=0 ) {
			valid_fiducial_count ++;
			total_leaf_size += fiducials[i].leaf_size;
			total_fiducial_size += fiducials[i].root_size;
		}
		
		FiducialObject *existing_fiducial = NULL;
		// update objects we had in the last frame
		// also check if we have an ID/position conflict
		// or correct an INVALID_FIDUCIAL_ID if we had an ID in the last frame
		for (std::list<FiducialObject>::iterator fiducial = fiducialList.begin(); fiducial!=fiducialList.end(); fiducial++) {
	
			float distance = fiducial->distance(fiducials[i].x,fiducials[i].y);
	
			if (fiducials[i].id==fiducial->fiducial_id)  {
				// find and match a fiducial we had last frame already ...
				if(!existing_fiducial) {
					existing_fiducial = &(*fiducial);

					for (int j=0;j<fid_count;j++) {
						if ( (i!=j) && (fiducials[j].id==fiducial->fiducial_id) && (fiducial->distance(fiducials[j].x,fiducials[j].y)<distance)) {
							//check if there is another fiducial with the same id closer
							existing_fiducial = NULL;
							break;
						}
					}	
										
					if (existing_fiducial!=NULL) {
					for (std::list<FiducialObject>::iterator test = fiducialList.begin(); test!=fiducialList.end(); test++) {
						FiducialObject *test_fiducial = &(*test);
						if ( (test_fiducial!=existing_fiducial) && (test_fiducial->fiducial_id==existing_fiducial->fiducial_id) && (test_fiducial->distance(fiducials[i].x,fiducials[i].y)<distance)) {
							//check if there is another fiducial with the same id closer
							existing_fiducial = NULL;
							break;
						}
					}}
				} /*else if (distance<existing_fiducial->distance(fiducials[i].x,fiducials[i].y)) {
						existing_fiducial = &(*fiducial);
					// is this still necessary?
				} */

			} else if ((distance<average_fiducial_size/1.2) && (abs(fiducials[i].node_count-fiducial->node_count)<=FUZZY_NODE_RANGE)) {
				// do we have a different ID at the same place?
				// this should correct wrong or invalid fiducial IDs
				// assuming that between two frames
				// there can't be a rapid exchange of two symbols
				// at the same place
				
				for (int j=0;j<fid_count;j++) {
					if ( (i!=j) && (fiducial->distance(fiducials[j].x,fiducials[j].y)<distance)) goto fiducialList_loop_end;
				}	
				
				if (fiducials[i].id==INVALID_FIDUCIAL_ID) {
					//printf("corrected invalid ID to %d (%ld)\n", fiducial->fiducial_id,fiducial->session_id);
					
					//two pixel threshold since missing/added leaf nodes result in a slightly different position
					float dx = abs(fiducial->getX() - fiducials[i].x);
					float dy = abs(fiducial->getY() - fiducials[i].y);
					if ((dx<2.0f) && (dy<2.0f)) {
						fiducials[i].x = (short int)fiducial->getX();
						fiducials[i].y = (short int)fiducial->getY();
					}
					
					fiducials[i].angle=fiducial->getAngle();
					fiducials[i].id=fiducial->fiducial_id;
					fiducial->state = FIDUCIAL_INVALID;
					drawObject(fiducials[i].id,(int)(fiducials[i].x),(int)(fiducials[i].y),display,0);
				} else /*if (fiducials[i].id!=fiducial->fiducial_id)*/ {

					if (!fiducial->checkIdConflict(session_id,fiducials[i].id)) {
						//printf("corrected wrong ID from %d to %d (%ld)\n", fiducials[i].id,fiducial->fiducial_id,fiducial->session_id);
						fiducials[i].id=fiducial->fiducial_id;
					} else {
						session_id++;
					}
				}
				
				existing_fiducial = &(*fiducial);
				break;
			}
			
			fiducialList_loop_end:;
		}
		
		if  (existing_fiducial!=NULL) {
			// just update the fiducial from last frame ...
			existing_fiducial->update(fiducials[i].x,fiducials[i].y,fiducials[i].angle,fiducials[i].root_size,fiducials[i].leaf_size);
			if(existing_fiducial->state!=FIDUCIAL_INVALID) drawObject(existing_fiducial->fiducial_id,(int)(existing_fiducial->getX()),(int)(existing_fiducial->getY()),display,1);
		} else if  (fiducials[i].id!=INVALID_FIDUCIAL_ID) {
			// add the newly found object
			session_id++;
			FiducialObject addFiducial(session_id, fiducials[i].id, width, height,fiducials[i].root_colour,fiducials[i].node_count);
			addFiducial.update(fiducials[i].x,fiducials[i].y,fiducials[i].angle,fiducials[i].root_size,fiducials[i].leaf_size);
			drawObject(fiducials[i].id,(int)(fiducials[i].x),(int)(fiducials[i].y),display,1);
			fiducialList.push_back(addFiducial);
#ifndef DISABLE_MIDISERVER
			if (midi_server!=NULL) midi_server->sendAddMessage(fiducials[i].id);
#endif
			if (msg_listener) {
				std::stringstream add_message;
				add_message << "add obj " << session_id << " " << fiducials[i].id;
				msg_listener->setMessage(add_message.str());
			}
		}
			
		//else drawObject(fiducials[i].id,(int)(fiducials[i].x),(int)(fiducials[i].y),display,0);

	}

	if (valid_fiducial_count>0) {
		average_leaf_size = (average_leaf_size + total_leaf_size/(double)valid_fiducial_count)/2;
		average_fiducial_size = (average_fiducial_size +  total_fiducial_size/(double)valid_fiducial_count)/2;
	}
	//std::cout << "leaf size: " << average_leaf_size << std::endl;
	//std::cout << "fiducial size: " << average_fiducial_size << std::endl;
	//std::cout << "finger size: " << average_finger_size << std::endl;

	float min_object_size = average_fiducial_size - average_fiducial_size/4.0f;
	float max_object_size = average_fiducial_size + average_fiducial_size/4.0f;
	
	float min_finger_size = average_finger_size - average_finger_size/1.75f;
	float max_finger_size = average_finger_size + average_finger_size/1.75f;
	
	// plain object tracking
	int min_region_size = min_finger_size;
	int max_region_size = max_object_size;
	if ((average_finger_size==0) || (min_region_size>min_object_size)) min_region_size = min_object_size;
	int reg_count = find_regionsX( regions, MAX_FIDUCIAL_COUNT, &fidtrackerx, &segmenter, width, height, min_region_size, max_region_size);
	//std::cout << reg_count << std::endl;

	//if (average_fiducial_size>width/4) goto send_messages;
	for(int j=0;j< reg_count;j++) {

		//printf("region: %d %d\n", regions[j].x, regions[j].y);
		//printf("region: %d %d\n", regions[j].width, regions[j].height);

/*		
			//reactable specific temporary hack
			//check if object is within the inner circle
		float dx =  width/2 - regions[j].x;
		float dy = height/2 - regions[j].y;
		float distance = sqrt(dx*dx+dy*dy);
		if (distance>(height/2-height/10)) continue;
		
*/
		int diff = abs(regions[j].width - regions[j].height);
		int max_diff = regions[j].width;
		if (regions[j].height > regions[j].width) max_diff = regions[j].height/2.0f;
				
		// plain objects
		if ((regions[j].width>min_object_size) && (regions[j].width<max_object_size) &&
			(regions[j].height>min_object_size) && (regions[j].height<max_object_size) && diff < max_diff) {

			//printf("region: %d %d\n", regions[j].width, regions[j].height);
			FiducialObject *existing_fiducial = NULL;
			for (std::list<FiducialObject>::iterator fiducial = fiducialList.begin(); fiducial!=fiducialList.end(); fiducial++) {
				float distance = fiducial->distance(regions[j].x,regions[j].y);
				if ((distance<average_fiducial_size/1.5f) && (fiducial->root_colour==regions[j].colour)) {
					existing_fiducial = &(*fiducial);
	
					// check if the fiducial was already found anyway
					for (int i=0;i<fid_count;i++) {
						float dx = fiducials[i].x - regions[j].x;
						float dy = fiducials[i].y - regions[j].y;
						distance = sqrt(dx*dx+dy*dy);
						if ( distance<average_fiducial_size/1.5f) {
							existing_fiducial->setBlobOffset(dx,dy);
							existing_fiducial = NULL;
							break;
						}
					}
					if (existing_fiducial != NULL) break;
				}
			}
			if (existing_fiducial!=NULL) {

				FloatPoint offset = existing_fiducial->getBlobOffset();
				float xpos = regions[j].x + offset.x;
				float ypos = regions[j].y + offset.y;
				float angle = existing_fiducial->getAngle();

				//two pixel threshold since root node blobs do not provide a precise position
				float dx = abs(existing_fiducial->getX() - xpos);
				float dy = abs(existing_fiducial->getY() - ypos);
				if ((dx<2.0f) && (dy<2.0f)) {
					xpos = existing_fiducial->getX();
					ypos = existing_fiducial->getY();
				}
				
				existing_fiducial->update(xpos,ypos,angle,(regions[j].width+regions[j].height)/2,0);
				//printf("region: %d %d\n", regions[j].width, regions[j].height);
				//printf("recovered plain fiducial %d (%ld)\n", existing_fiducial->fiducial_id,existing_fiducial->session_id);
				existing_fiducial->state = FIDUCIAL_REGION;
				drawObject(existing_fiducial->fiducial_id,xpos,ypos,display,2);
			} //else goto plain_analysis;
						
		// plain fingers
		} else if (detect_finger && (regions[j].colour==255) && (regions[j].width>min_finger_size) && (regions[j].width<max_finger_size) && 
			(regions[j].height>min_finger_size) && (regions[j].height<max_finger_size) && diff < max_diff) {

			//check first if the finger is valid
			//printf("candidate: %d %d\n", regions[j].width, regions[j].height);
			int finger_match = check_finger(&regions[j],dest,(unsigned char*)(display->pixels));
			if(finger_match<0) continue;//goto plain_analysis;
			//printf("finger: %d %d\n", regions[j].width, regions[j].height);

			FingerObject *existing_finger = NULL;
			float closest = width;

			// ignore fingers within existing fiducials
			for (std::list<FiducialObject>::iterator fiducial = fiducialList.begin(); fiducial!=fiducialList.end(); fiducial++) {
				if (fiducial->distance(regions[j].x, regions[j].y)<fiducial->root_size/2) goto region_loop_end;
			}
			
			// attach to existing fingers in the list
			for (std::list<FingerObject>::iterator finger = fingerList.begin(); finger!=fingerList.end(); finger++) {
		
				float distance = finger->distance(regions[j].x,regions[j].y);
				if ((distance<average_finger_size*2) && (distance<closest)){
					existing_finger = &(*finger);
					closest = distance;
					
					//is there another finger closer than that?
					if (distance>average_finger_size/2) {
					for(int k=0;k< reg_count;k++) {
						if(j==k) continue;
						 if ((regions[k].width>min_finger_size) && (regions[k].width<max_finger_size) && 
							(regions[k].height>min_finger_size) && (regions[k].height<max_finger_size) && diff < max_diff) {
							
							int dx = abs(regions[k].x - regions[j].x);
							int dy = abs(regions[k].y - regions[j].y);
							float dist = sqrt((float)(dx*dx+dy*dy));
							if (dist<=distance) { existing_finger=NULL; closest=dist; break;  }
						}
					}}
					
					if (existing_finger!=NULL) {
						for (std::list<FingerObject>::iterator test = fingerList.begin(); test!=fingerList.end(); test++) {
							FingerObject *test_finger = &(*test);
							if ( (test_finger!=existing_finger) && (test_finger->distance(regions[j].x,regions[j].y)<distance)) {
								//check if there is another fiducial with the same id closer
								existing_finger = NULL;
								break;
							}
						}}
					

				}
			}

			// update or add the finger
			if  (existing_finger!=NULL) {			
				existing_finger->update(regions[j].x,regions[j].y,regions[j].area);
			} else if (finger_match==1) {
				// add the newly found cursor
				FingerObject addFinger(width, height);				
				addFinger.update(regions[j].x,regions[j].y,regions[j].area);
				fingerList.push_back(addFinger);
			} else continue; //goto plain_analysis;
	
			drawObject(FINGER_ID,(int)(regions[j].x),(int)(regions[j].y),display,1);
			region_loop_end:;
		} /*else if (	(regions[j].width>average_leaf_size*2) && (regions[j].height>average_leaf_size*2)) {
			plain_analysis:;
			//do the plain object analysis larger than twice the leaf size.
	
			bool analyse = true;
			// check if object is within any found fiducial
			for (std::list<FiducialObject>::iterator fiducial = fiducialList.begin(); fiducial!=fiducialList.end(); fiducial++) {
				float distance = fiducial->distance(regions[j].x,regions[j].y);
				if (distance<average_fiducial_size/2) { analyse = false; break; }
			}
	
			if (analyse) obj_analyzer->process(&regions[j],src, dest, display);	

		}*/

	}
	
	
	if (tuio_server!=NULL) {
		sendTuioMessages();
		if (detect_finger) sendCursorMessages();
	} else {
#ifndef DISABLE_MIDISERVER    
        if (midi_server!=NULL) sendMidiMessages();
#endif
    } 
	
	if (show_grid) drawGrid(src,dest,display);
	if (show_settings) drawGUI(display);
	//printStatistics(start_time);
}