Laser Sensing Display for UI interfaces in the real world
Fork of skinGames_forktest by
classLaserSensingTrajectory.cpp@33:43e8bc451ef0, 2012-11-05 (annotated)
- Committer:
- mbedalvaro
- Date:
- Mon Nov 05 06:08:35 2012 +0000
- Revision:
- 33:43e8bc451ef0
- Parent:
- 32:52273c3291fe
- Child:
- 34:1244fa3f2559
added resizing functions, as well as better control on the thresholding modes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 32:52273c3291fe | 1 | #include "classLaserSensingTrajectory.h" |
mbedalvaro | 32:52273c3291fe | 2 | |
mbedalvaro | 32:52273c3291fe | 3 | LaserSensingTrajectory::LaserSensingTrajectory():lightTouched(false), |
mbedalvaro | 33:43e8bc451ef0 | 4 | modeThreshold(FIXED), |
mbedalvaro | 33:43e8bc451ef0 | 5 | min_contrast_ratio(MIN_CONTRAST_RATIO), threshold_factor(THRESHOLD_FACTOR), min_acceptable_intensity(MIN_ACCEPTABLE_INTENSITY), |
mbedalvaro | 33:43e8bc451ef0 | 6 | fixedThreshold(FIXED_THRESHOLD) { |
mbedalvaro | 32:52273c3291fe | 7 | } |
mbedalvaro | 32:52273c3291fe | 8 | |
mbedalvaro | 32:52273c3291fe | 9 | LaserSensingTrajectory::~LaserSensingTrajectory() { |
mbedalvaro | 32:52273c3291fe | 10 | // 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 | 11 | } |
mbedalvaro | 32:52273c3291fe | 12 | |
mbedalvaro | 32:52273c3291fe | 13 | |
mbedalvaro | 32:52273c3291fe | 14 | void LaserSensingTrajectory::setDelayMirrors(int delay) { |
mbedalvaro | 32:52273c3291fe | 15 | delayMirrorSamples=delay; |
mbedalvaro | 32:52273c3291fe | 16 | } |
mbedalvaro | 32:52273c3291fe | 17 | |
mbedalvaro | 32:52273c3291fe | 18 | void LaserSensingTrajectory::addDelayMirrors(int add_delay) { |
mbedalvaro | 32:52273c3291fe | 19 | delayMirrorSamples+=add_delay; |
mbedalvaro | 32:52273c3291fe | 20 | } |
mbedalvaro | 32:52273c3291fe | 21 | |
mbedalvaro | 32:52273c3291fe | 22 | void LaserSensingTrajectory::processSensedData() { |
mbedalvaro | 32:52273c3291fe | 23 | // Compute max and min intensity on the loop |
mbedalvaro | 32:52273c3291fe | 24 | maxI=0; |
mbedalvaro | 32:52273c3291fe | 25 | minI=255; // ratio has been normalized between 0 and 255 |
mbedalvaro | 32:52273c3291fe | 26 | int auxSize=lsdTrajectory.size(); |
mbedalvaro | 32:52273c3291fe | 27 | |
mbedalvaro | 32:52273c3291fe | 28 | // Compute minimum and maximum intensities: |
mbedalvaro | 32:52273c3291fe | 29 | for (int i = 0; i < lsdTrajectory.size(); i++) { |
mbedalvaro | 32:52273c3291fe | 30 | unsigned char mesI=lsdTrajectory[i].intensity; |
mbedalvaro | 32:52273c3291fe | 31 | if (maxI<mesI) maxI=mesI; |
mbedalvaro | 32:52273c3291fe | 32 | if (minI>mesI) minI=mesI; |
mbedalvaro | 32:52273c3291fe | 33 | } |
mbedalvaro | 32:52273c3291fe | 34 | |
mbedalvaro | 32:52273c3291fe | 35 | // Compute autoThreshold: |
mbedalvaro | 33:43e8bc451ef0 | 36 | switch(modeThreshold) { |
mbedalvaro | 33:43e8bc451ef0 | 37 | case AUTO: |
mbedalvaro | 33:43e8bc451ef0 | 38 | if (minI==0) minI=1; |
mbedalvaro | 33:43e8bc451ef0 | 39 | if (maxI<min_acceptable_intensity) autoThreshold=255;// (we consider that the saccade is FULL on something black) |
mbedalvaro | 33:43e8bc451ef0 | 40 | else if (1.0*maxI/minI > min_contrast_ratio ) { |
mbedalvaro | 33:43e8bc451ef0 | 41 | autoThreshold = (unsigned char) (1.0 * (maxI-minI) * threshold_factor + minI); // threshold_factor = 2/3 or 1/2 is a good value. |
mbedalvaro | 33:43e8bc451ef0 | 42 | } else {// ... otherwise, we consider that the saccade is FULL on something white |
mbedalvaro | 33:43e8bc451ef0 | 43 | autoThreshold=0; |
mbedalvaro | 33:43e8bc451ef0 | 44 | } |
mbedalvaro | 33:43e8bc451ef0 | 45 | case FIXED: |
mbedalvaro | 33:43e8bc451ef0 | 46 | autoThreshold=fixedThreshold; |
mbedalvaro | 32:52273c3291fe | 47 | } |
mbedalvaro | 32:52273c3291fe | 48 | |
mbedalvaro | 32:52273c3291fe | 49 | // 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 | 50 | // 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 | 51 | // 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 | 52 | // idea of the blob "constant" internal pressure... |
mbedalvaro | 32:52273c3291fe | 53 | lightTouched=false; |
mbedalvaro | 32:52273c3291fe | 54 | // int counterLight=0; |
mbedalvaro | 32:52273c3291fe | 55 | for (int i = 0; i < lsdTrajectory.size(); i++) { |
mbedalvaro | 32:52273c3291fe | 56 | int delayedpoint=(i+auxSize+delayMirrorSamples)%auxSize; // this way we can have negative delayMirrorSamples if required (would be absurd though) |
mbedalvaro | 32:52273c3291fe | 57 | if (lsdTrajectory[delayedpoint].intensity>=autoThreshold) { // this means a WHITE zone: |
mbedalvaro | 32:52273c3291fe | 58 | lsdTrajectory[i].lightZone= -1; |
mbedalvaro | 32:52273c3291fe | 59 | // counterLight++; |
mbedalvaro | 32:52273c3291fe | 60 | } else { // something touched: DARK ZONE |
mbedalvaro | 32:52273c3291fe | 61 | lsdTrajectory[i].lightZone= 2; |
mbedalvaro | 32:52273c3291fe | 62 | lightTouched=true; // (for the whole loop) |
mbedalvaro | 32:52273c3291fe | 63 | } |
mbedalvaro | 32:52273c3291fe | 64 | } |
mbedalvaro | 32:52273c3291fe | 65 | //coko=counterLight; |
mbedalvaro | 32:52273c3291fe | 66 | // lightRatio=1.0*counterLight/lsdTrajectory.size(); |
mbedalvaro | 32:52273c3291fe | 67 | } |