Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Mon Apr 02 05:33:44 2012 +0000
Revision:
3:b44ff6de81bd
Parent:
0:345b3bc7a0ea
Child:
4:f9d364f10335
working but needs a lot of calibration and optimization. In particular the laser renderer - I am going to modify it, that's why I commit now.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:345b3bc7a0ea 1 #include "classLaserSensingTrajectory.h"
mbedalvaro 0:345b3bc7a0ea 2
mbedalvaro 0:345b3bc7a0ea 3 LaserSensingTrajectory::LaserSensingTrajectory(): lightTouched(false) {
mbedalvaro 0:345b3bc7a0ea 4 }
mbedalvaro 0:345b3bc7a0ea 5
mbedalvaro 0:345b3bc7a0ea 6 LaserSensingTrajectory::~LaserSensingTrajectory() {
mbedalvaro 0:345b3bc7a0ea 7 // lsdTrajectory.clear(); // there is no need to clear the vector, the destructor of this vector is called by default (and it's NOT a vector of pointers)
mbedalvaro 0:345b3bc7a0ea 8 }
mbedalvaro 0:345b3bc7a0ea 9
mbedalvaro 0:345b3bc7a0ea 10 void LaserSensingTrajectory::processSensedData() {
mbedalvaro 0:345b3bc7a0ea 11 // Compute max and min intensity on the loop
mbedalvaro 0:345b3bc7a0ea 12 maxI=0;
mbedalvaro 0:345b3bc7a0ea 13 minI=4096;
mbedalvaro 0:345b3bc7a0ea 14 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 0:345b3bc7a0ea 15 float mesI=lsdTrajectory[i].intensity;
mbedalvaro 0:345b3bc7a0ea 16 if (maxI<mesI) maxI=mesI;
mbedalvaro 0:345b3bc7a0ea 17 if (minI>mesI) minI=mesI;
mbedalvaro 0:345b3bc7a0ea 18 }
mbedalvaro 0:345b3bc7a0ea 19
mbedalvaro 0:345b3bc7a0ea 20 // Compute autoThreshold:
mbedalvaro 0:345b3bc7a0ea 21 if (1.0*maxI/(minI+0.1) > MIN_CONTRAST_RATIO ) {
mbedalvaro 0:345b3bc7a0ea 22 autoThreshold = 1.0 * (maxI-minI) * THRESHOLD_FACTOR + minI; // THRESHOLD_FACTOR = 2/3 or 1/2 is a good value.
mbedalvaro 0:345b3bc7a0ea 23 } else {// ... otherwise, we consider that the saccade is FULL on something white
mbedalvaro 0:345b3bc7a0ea 24 autoThreshold=-1;
mbedalvaro 0:345b3bc7a0ea 25 }
mbedalvaro 0:345b3bc7a0ea 26
mbedalvaro 0:345b3bc7a0ea 27 // Segment the trajectory (only two levels for the time being, but we can have more - meaning different forces, real or even complex values to have different angle forces...):
mbedalvaro 0:345b3bc7a0ea 28 // NOTE: if using 1 and -1 instead of 1 and 0, we can avoid having to add a "blob internal pressure"! -1 means a force towards the interior, and +1 outwards...
mbedalvaro 0:345b3bc7a0ea 29 // This means that the loop will naturally become inside-out depending on the color of the main surface! (but will mantain its normal size). Much better and elegant solution than the
mbedalvaro 0:345b3bc7a0ea 30 // idea of the blob "constant" internal pressure...
mbedalvaro 0:345b3bc7a0ea 31 lightTouched=false;
mbedalvaro 0:345b3bc7a0ea 32 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 0:345b3bc7a0ea 33 if (lsdTrajectory[i].intensity>autoThreshold) { // this means a WHITE zone:
mbedalvaro 3:b44ff6de81bd 34 lsdTrajectory[i].lightZone= 2;//-1;//1;
mbedalvaro 0:345b3bc7a0ea 35 } else { // something touched: DARK ZONE
mbedalvaro 0:345b3bc7a0ea 36 lsdTrajectory[i].lightZone= 2;//0;
mbedalvaro 0:345b3bc7a0ea 37 lightTouched=true; // (for the whole loop)
mbedalvaro 0:345b3bc7a0ea 38 }
mbedalvaro 0:345b3bc7a0ea 39 }
mbedalvaro 0:345b3bc7a0ea 40 }