Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Mon Jun 18 08:00:57 2012 +0000
Revision:
24:4e52031a495b
Parent:
11:62f7183a03e7
Child:
30:d8af03f01cd4
Various modifications for show at TV Asahi

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