Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
Diff: classLaserSensingTrajectory.cpp
- Revision:
- 30:d8af03f01cd4
- Parent:
- 24:4e52031a495b
- Child:
- 32:52273c3291fe
diff -r 2fc8c12822eb -r d8af03f01cd4 classLaserSensingTrajectory.cpp --- a/classLaserSensingTrajectory.cpp Wed Jun 20 03:25:49 2012 +0000 +++ b/classLaserSensingTrajectory.cpp Fri Sep 21 10:02:35 2012 +0000 @@ -1,58 +1,58 @@ -#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::addDelayMirrors(int add_delay) { - delayMirrorSamples+=add_delay; -} - -void LaserSensingTrajectory::processSensedData() { - // Compute max and min intensity on the loop - maxI=0; - minI=255; // ratio has been normalized between 0 and 255 - int auxSize=lsdTrajectory.size(); - - // Compute minimum and maximum intensities: - for (int i = 0; i < lsdTrajectory.size(); i++) { - unsigned char mesI=lsdTrajectory[i].intensity; - if (maxI<mesI) maxI=mesI; - if (minI>mesI) minI=mesI; - } - - // Compute autoThreshold: - if (minI==0) autoThreshold=0; // (we consider that the saccade is FULL on something white) - else if (1.0*maxI/minI > MIN_CONTRAST_RATIO ) { - autoThreshold = (unsigned char) (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=0; - } - - // 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; - // int counterLight=0; - for (int i = 0; i < lsdTrajectory.size(); i++) { - int delayedpoint=(i+auxSize+delayMirrorSamples)%auxSize; // this way we can have negative delayMirrorSamples if required (would be absurd though) - if (lsdTrajectory[delayedpoint].intensity>=autoThreshold) { // this means a WHITE zone: - lsdTrajectory[i].lightZone= -1; - // counterLight++; - } else { // something touched: DARK ZONE - lsdTrajectory[i].lightZone= 2; - lightTouched=true; // (for the whole loop) - } - } - //coko=counterLight; -// lightRatio=1.0*counterLight/lsdTrajectory.size(); -} +#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::addDelayMirrors(int add_delay) { + delayMirrorSamples+=add_delay; +} + +void LaserSensingTrajectory::processSensedData() { + // Compute max and min intensity on the loop + maxI=0; + minI=255; // ratio has been normalized between 0 and 255 + int auxSize=lsdTrajectory.size(); + + // Compute minimum and maximum intensities: + for (int i = 0; i < lsdTrajectory.size(); i++) { + unsigned char mesI=lsdTrajectory[i].intensity; + if (maxI<mesI) maxI=mesI; + if (minI>mesI) minI=mesI; + } + + // Compute autoThreshold: + if (minI==0) autoThreshold=0; // (we consider that the saccade is FULL on something white) + else if (1.0*maxI/minI > MIN_CONTRAST_RATIO ) { + autoThreshold = (unsigned char) (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=0; + } + + // 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; + // int counterLight=0; + for (int i = 0; i < lsdTrajectory.size(); i++) { + int delayedpoint=(i+auxSize+delayMirrorSamples)%auxSize; // this way we can have negative delayMirrorSamples if required (would be absurd though) + if (lsdTrajectory[delayedpoint].intensity>=autoThreshold) { // this means a WHITE zone: + lsdTrajectory[i].lightZone= -1; + // counterLight++; + } else { // something touched: DARK ZONE + lsdTrajectory[i].lightZone= 2; + lightTouched=true; // (for the whole loop) + } + } + //coko=counterLight; +// lightRatio=1.0*counterLight/lsdTrajectory.size(); +}