Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

classLaserSensingTrajectory.cpp

Committer:
mbedalvaro
Date:
2012-04-04
Revision:
4:f9d364f10335
Parent:
3:b44ff6de81bd
Child:
5:73cd58b58f95

File content as of revision 4:f9d364f10335:

#include "classLaserSensingTrajectory.h"

LaserSensingTrajectory::LaserSensingTrajectory(): lightTouched(false) {
}

LaserSensingTrajectory::~LaserSensingTrajectory() {
   // 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)
}

  
void LaserSensingTrajectory::setDelayMirrors(int delay) {
    delayMirrorSamples=delay;
}

void LaserSensingTrajectory::processSensedData() {
    // Compute max and min intensity on the loop
    maxI=0;
    minI=4096;
    int auxSize=lsdTrajectory.size();
    
    for (int i = 0; i < lsdTrajectory.size(); i++) {
        float mesI=lsdTrajectory[(i+auxSize-delayMirrorSamples)%auxSize].intensity; // I need to do "auxSize-delay" instead of "-delay" only, because otherwise I will get negative values
        if (maxI<mesI)  maxI=mesI;
        if (minI>mesI)  minI=mesI;
    }

    // Compute autoThreshold:
    if (1.0*maxI/(minI+0.1) > MIN_CONTRAST_RATIO ) {
        autoThreshold = 1.0 * (maxI-minI) * THRESHOLD_FACTOR + minI;    // THRESHOLD_FACTOR = 2/3 or 1/2 is a good value.
    } else {// ... otherwise, we consider that the saccade is FULL on something white
        autoThreshold=-1;
    }

    // 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...):
    // 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...
    // 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
    // idea of the blob "constant" internal pressure...
    lightTouched=false;
    for (int i = 0; i <  lsdTrajectory.size(); i++) {
        int delayedpoint=(i+auxSize-delayMirrorSamples)%auxSize;
        if (lsdTrajectory[delayedpoint].intensity>autoThreshold) { // this means a WHITE zone:
            lsdTrajectory[delayedpoint].lightZone= -1;//1;
        } else { // something touched: DARK ZONE
            lsdTrajectory[delayedpoint].lightZone= 2;//0;
            lightTouched=true; // (for the whole loop)
        }
    }
}