Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Mon Oct 29 14:28:47 2012 +0000
Revision:
32:52273c3291fe
Parent:
30:d8af03f01cd4
Child:
33:43e8bc451ef0
code for Tokyo design week (starting with two colored following spots, and NO standby mode)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 32:52273c3291fe 1 #include "classLaserSensingTrajectory.h"
mbedalvaro 32:52273c3291fe 2
mbedalvaro 32:52273c3291fe 3 LaserSensingTrajectory::LaserSensingTrajectory():lightTouched(false),
mbedalvaro 32:52273c3291fe 4 min_contrast_ratio(MIN_CONTRAST_RATIO), threshold_factor(THRESHOLD_FACTOR),
mbedalvaro 32:52273c3291fe 5 min_acceptable_intensity(MIN_ACCEPTABLE_INTENSITY) {
mbedalvaro 32:52273c3291fe 6 }
mbedalvaro 32:52273c3291fe 7
mbedalvaro 32:52273c3291fe 8 LaserSensingTrajectory::~LaserSensingTrajectory() {
mbedalvaro 32:52273c3291fe 9 // 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 32:52273c3291fe 10 }
mbedalvaro 32:52273c3291fe 11
mbedalvaro 32:52273c3291fe 12
mbedalvaro 32:52273c3291fe 13 void LaserSensingTrajectory::setDelayMirrors(int delay) {
mbedalvaro 32:52273c3291fe 14 delayMirrorSamples=delay;
mbedalvaro 32:52273c3291fe 15 }
mbedalvaro 32:52273c3291fe 16
mbedalvaro 32:52273c3291fe 17 void LaserSensingTrajectory::addDelayMirrors(int add_delay) {
mbedalvaro 32:52273c3291fe 18 delayMirrorSamples+=add_delay;
mbedalvaro 32:52273c3291fe 19 }
mbedalvaro 32:52273c3291fe 20
mbedalvaro 32:52273c3291fe 21 void LaserSensingTrajectory::processSensedData() {
mbedalvaro 32:52273c3291fe 22 // Compute max and min intensity on the loop
mbedalvaro 32:52273c3291fe 23 maxI=0;
mbedalvaro 32:52273c3291fe 24 minI=255; // ratio has been normalized between 0 and 255
mbedalvaro 32:52273c3291fe 25 int auxSize=lsdTrajectory.size();
mbedalvaro 32:52273c3291fe 26
mbedalvaro 32:52273c3291fe 27 // Compute minimum and maximum intensities:
mbedalvaro 32:52273c3291fe 28 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 32:52273c3291fe 29 unsigned char mesI=lsdTrajectory[i].intensity;
mbedalvaro 32:52273c3291fe 30 if (maxI<mesI) maxI=mesI;
mbedalvaro 32:52273c3291fe 31 if (minI>mesI) minI=mesI;
mbedalvaro 32:52273c3291fe 32 }
mbedalvaro 32:52273c3291fe 33
mbedalvaro 32:52273c3291fe 34 // Compute autoThreshold:
mbedalvaro 32:52273c3291fe 35 if (maxI<min_acceptable_intensity) autoThreshold=255;// (we consider that the saccade is FULL on something black)
mbedalvaro 32:52273c3291fe 36 else if (minI==0) autoThreshold=0; // (we consider that the saccade is FULL on something white)
mbedalvaro 32:52273c3291fe 37 else if (1.0*maxI/minI > min_contrast_ratio ) {
mbedalvaro 32:52273c3291fe 38 autoThreshold = (unsigned char) (1.0 * (maxI-minI) * threshold_factor + minI); // threshold_factor = 2/3 or 1/2 is a good value.
mbedalvaro 32:52273c3291fe 39 } else {// ... otherwise, we consider that the saccade is FULL on something white
mbedalvaro 32:52273c3291fe 40 autoThreshold=0;
mbedalvaro 32:52273c3291fe 41 }
mbedalvaro 32:52273c3291fe 42
mbedalvaro 32:52273c3291fe 43 // 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 32:52273c3291fe 44 // 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 32:52273c3291fe 45 // 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 32:52273c3291fe 46 // idea of the blob "constant" internal pressure...
mbedalvaro 32:52273c3291fe 47 lightTouched=false;
mbedalvaro 32:52273c3291fe 48 // int counterLight=0;
mbedalvaro 32:52273c3291fe 49 for (int i = 0; i < lsdTrajectory.size(); i++) {
mbedalvaro 32:52273c3291fe 50 int delayedpoint=(i+auxSize+delayMirrorSamples)%auxSize; // this way we can have negative delayMirrorSamples if required (would be absurd though)
mbedalvaro 32:52273c3291fe 51 if (lsdTrajectory[delayedpoint].intensity>=autoThreshold) { // this means a WHITE zone:
mbedalvaro 32:52273c3291fe 52 lsdTrajectory[i].lightZone= -1;
mbedalvaro 32:52273c3291fe 53 // counterLight++;
mbedalvaro 32:52273c3291fe 54 } else { // something touched: DARK ZONE
mbedalvaro 32:52273c3291fe 55 lsdTrajectory[i].lightZone= 2;
mbedalvaro 32:52273c3291fe 56 lightTouched=true; // (for the whole loop)
mbedalvaro 32:52273c3291fe 57 }
mbedalvaro 32:52273c3291fe 58 }
mbedalvaro 32:52273c3291fe 59 //coko=counterLight;
mbedalvaro 32:52273c3291fe 60 // lightRatio=1.0*counterLight/lsdTrajectory.size();
mbedalvaro 32:52273c3291fe 61 }