Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Thu Apr 17 08:04:14 2014 +0000
Revision:
47:199042980678
Parent:
40:3ba2b0ea9f33
publishing for sharing with Ken Iwasaki

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 40:3ba2b0ea9f33 1 /*
mbedalvaro 40:3ba2b0ea9f33 2 Name: "classLaserSensingTrajectory.h"
mbedalvaro 40:3ba2b0ea9f33 3
mbedalvaro 40:3ba2b0ea9f33 4 Description: This is a collection of LaserPoint(s), with methods to analyse the trajectory.
mbedalvaro 40:3ba2b0ea9f33 5 Each object of BaseObject class contain one instance of this class; parameters to analyse the saccade (ex: threshold, etc), can be set in a per-object basis.
mbedalvaro 40:3ba2b0ea9f33 6 Derived classes of BaseObject may have special methods to further analyse the "segmented" saccade trajectory (to compute recentering vectors, etc).
mbedalvaro 40:3ba2b0ea9f33 7 Finally, this object is heavily accessed by the GLOBAL INSTANCE of laserSensingDisplay (lsd), which is the "displaying engine" running in an interrupt.
mbedalvaro 40:3ba2b0ea9f33 8 */
mbedalvaro 40:3ba2b0ea9f33 9
mbedalvaro 32:52273c3291fe 10 #ifndef LSDTRAJECTORY_H
mbedalvaro 32:52273c3291fe 11 #define LSDTRAJECTORY_H
mbedalvaro 32:52273c3291fe 12
mbedalvaro 32:52273c3291fe 13 #include <vector>
mbedalvaro 40:3ba2b0ea9f33 14 #include "matrixClass.h"
mbedalvaro 32:52273c3291fe 15
mbedalvaro 33:43e8bc451ef0 16 // Thresholding mode:
mbedalvaro 33:43e8bc451ef0 17 enum thresholdingMode {FIXED, AUTO};
mbedalvaro 40:3ba2b0ea9f33 18 //(1) fixed threshold (in case of FIXED threshold mode)
mbedalvaro 33:43e8bc451ef0 19 #define FIXED_THRESHOLD 35
mbedalvaro 40:3ba2b0ea9f33 20 //(2) Autothreshold (in case of AUTO threshold mode):
mbedalvaro 32:52273c3291fe 21 // CONTRAST RATIO to compute autoThreshold:
mbedalvaro 32:52273c3291fe 22 // MIN_CONTRAST_RATIO is the minimum contrast between max and min intensity necessary to "accept" a black and white zone:
mbedalvaro 32:52273c3291fe 23 #define MIN_CONTRAST_RATIO 1.8//1.7 // 3 seems good when lookup table does not work
mbedalvaro 32:52273c3291fe 24 // THRESHOLD_FACTOR is where the threshold is actually placed between the min and max detected (with good contrast):
mbedalvaro 32:52273c3291fe 25 #define THRESHOLD_FACTOR 0.5 //0.75 // 2/3 or 1/2 are good values
mbedalvaro 32:52273c3291fe 26 #define MIN_ACCEPTABLE_INTENSITY 16 // if maxI< this then we consider all the saccade on something black
mbedalvaro 32:52273c3291fe 27
mbedalvaro 40:3ba2b0ea9f33 28 // ================= The minimal structure for a "projected/sensed" laser point =================
mbedalvaro 40:3ba2b0ea9f33 29 typedef struct LaserPoint {
mbedalvaro 40:3ba2b0ea9f33 30 //public:
mbedalvaro 40:3ba2b0ea9f33 31 LaserPoint(float x, float y) //: v2={x,y} //filling structs "by list"... we could have custom constructors for them though (but what would be the advantage?)
mbedalvaro 40:3ba2b0ea9f33 32 {v2.x=x; v2.y=y;};
mbedalvaro 40:3ba2b0ea9f33 33 LaserPoint(V2 _v2) : v2(_v2)
mbedalvaro 40:3ba2b0ea9f33 34 {};
mbedalvaro 40:3ba2b0ea9f33 35
mbedalvaro 40:3ba2b0ea9f33 36 // Setting method only for COORDINATES (otherwise we can use the default copy constructor '=', but in case of re-projecting, we don't need to change the
mbedalvaro 40:3ba2b0ea9f33 37 // values of the sensed data:
mbedalvaro 40:3ba2b0ea9f33 38 void setCoord(const V2& _v2) {v2=_v2;};
mbedalvaro 40:3ba2b0ea9f33 39
mbedalvaro 40:3ba2b0ea9f33 40 // Data:
mbedalvaro 40:3ba2b0ea9f33 41 V2 v2; // position of the point in image plane (after rendering - it's an UNSIGNED SHORT, because it is in "laser projector pixels", i.e, DA units)
mbedalvaro 40:3ba2b0ea9f33 42
mbedalvaro 40:3ba2b0ea9f33 43 // Per point displaying attributes: can include color, or polarization, or modulation, but also TIME for posing on the point, etc
mbedalvaro 40:3ba2b0ea9f33 44 // (for the time being, the time one poses on a point can be controlled by just REPEATING the point... not nice, but well, it's a start).
mbedalvaro 40:3ba2b0ea9f33 45 // unsigned char myColor; // override now by the per-object color property now.
mbedalvaro 40:3ba2b0ea9f33 46
mbedalvaro 40:3ba2b0ea9f33 47 // Sensed intensity for this point (in the future, color?)
mbedalvaro 32:52273c3291fe 48 unsigned char intensity; // detected intensity (in fact, this will be the REFLECTIVITY RATIO if using LUT table, and it's between 0 and 1, but we will multiply by 255 to avoid using a float.
mbedalvaro 40:3ba2b0ea9f33 49 signed char lightZone; // the thresholded light zone (allow for negative values?)
mbedalvaro 40:3ba2b0ea9f33 50 } LaserPoint;
mbedalvaro 32:52273c3291fe 51
mbedalvaro 32:52273c3291fe 52 class LaserSensingTrajectory {
mbedalvaro 32:52273c3291fe 53
mbedalvaro 32:52273c3291fe 54 public:
mbedalvaro 32:52273c3291fe 55
mbedalvaro 32:52273c3291fe 56 LaserSensingTrajectory();
mbedalvaro 32:52273c3291fe 57 ~LaserSensingTrajectory();
mbedalvaro 32:52273c3291fe 58
mbedalvaro 40:3ba2b0ea9f33 59 int size() {return(lsdTrajectory.size());}
mbedalvaro 40:3ba2b0ea9f33 60
mbedalvaro 32:52273c3291fe 61 // METHODS:
mbedalvaro 40:3ba2b0ea9f33 62 bool processSensedData(); // Basic analysis of the saccade (classification into two zones). It return the value of lightTouched for commodity.
mbedalvaro 40:3ba2b0ea9f33 63
mbedalvaro 32:52273c3291fe 64 void setDelayMirrors(int); // in general, the delay will depend on the number of points being DISPLAYED (in other terms, on the size of lsdTrajectory).
mbedalvaro 32:52273c3291fe 65 void addDelayMirrors(int add_delay);
mbedalvaro 32:52273c3291fe 66
mbedalvaro 40:3ba2b0ea9f33 67 // PARAMETER ADJUSTEMENT FOR SENSING METHODS (note: perhaps better in a separated class?)
mbedalvaro 40:3ba2b0ea9f33 68 // NOTE: parameters for sensing the data may depend on the number of points, etc. Therefore, I provide setting methods and instance variables
mbedalvaro 40:3ba2b0ea9f33 69 // for each instance of the class
mbedalvaro 40:3ba2b0ea9f33 70
mbedalvaro 33:43e8bc451ef0 71 void setThresholdMode(unsigned char value) {modeThreshold=(value>0? AUTO : FIXED);};
mbedalvaro 33:43e8bc451ef0 72 void setFixedThreshold(unsigned char value) {fixedThreshold=value;};
mbedalvaro 32:52273c3291fe 73 void setMinContrastRatio(float value) {min_contrast_ratio=value;};
mbedalvaro 32:52273c3291fe 74 void setThresholdFactor(float value) {threshold_factor=value;};
mbedalvaro 33:43e8bc451ef0 75 void setMinAcceptableIntensity(unsigned char value) {min_acceptable_intensity=value;};
mbedalvaro 32:52273c3291fe 76 void multMinContrastRatio(float multfactor) {min_contrast_ratio*=multfactor;};
mbedalvaro 32:52273c3291fe 77 void multThresholdFactor(float multfactor) {threshold_factor*=multfactor;};
mbedalvaro 32:52273c3291fe 78
mbedalvaro 40:3ba2b0ea9f33 79 // PARAMETERS FOR SACCADE ANALYSIS:
mbedalvaro 40:3ba2b0ea9f33 80 // Adjustement of mirror delay:
mbedalvaro 40:3ba2b0ea9f33 81 unsigned char delayMirrorSamples; // it could be in the laser renderer, but by putting it here we can have more per-object fine tunning
mbedalvaro 33:43e8bc451ef0 82 // parameters for thresholding and thresholding mode:
mbedalvaro 33:43e8bc451ef0 83 thresholdingMode modeThreshold;
mbedalvaro 32:52273c3291fe 84 float min_contrast_ratio, threshold_factor, min_acceptable_intensity;
mbedalvaro 33:43e8bc451ef0 85 unsigned char autoThreshold, fixedThreshold; // 0 to 255
mbedalvaro 32:52273c3291fe 86
mbedalvaro 40:3ba2b0ea9f33 87 // TRAJECTORY DATA:
mbedalvaro 40:3ba2b0ea9f33 88 vector <LaserPoint> lsdTrajectory;
mbedalvaro 40:3ba2b0ea9f33 89 //unsigned char displayColor; // per BaseObject color (now in the baseObject class)
mbedalvaro 40:3ba2b0ea9f33 90
mbedalvaro 32:52273c3291fe 91 // Statistics and tests:
mbedalvaro 32:52273c3291fe 92 //float lightRatio;
mbedalvaro 32:52273c3291fe 93 unsigned char maxI, minI; // Max and Min intensity RATIOS (normalized between 0 and 255)
mbedalvaro 32:52273c3291fe 94 bool lightTouched; // true if something went over the autoThreshold for the whole loop
mbedalvaro 32:52273c3291fe 95 };
mbedalvaro 32:52273c3291fe 96
mbedalvaro 32:52273c3291fe 97 #endif
mbedalvaro 32:52273c3291fe 98
mbedalvaro 32:52273c3291fe 99
mbedalvaro 40:3ba2b0ea9f33 100