Laser Sensing Display for UI interfaces in the real world

Dependencies:   mbed

Fork of skinGames_forktest by Alvaro Cassinelli

Revision:
40:3ba2b0ea9f33
Parent:
36:233b12d0b1f0
--- a/classLaserSensingTrajectory.h	Wed Oct 16 15:54:39 2013 +0000
+++ b/classLaserSensingTrajectory.h	Wed Oct 16 16:14:27 2013 +0000
@@ -1,17 +1,23 @@
+/* 
+   Name: "classLaserSensingTrajectory.h"
+   
+   Description: This is a collection of LaserPoint(s), with methods to analyse the trajectory. 
+                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. 
+                Derived classes of BaseObject may have special methods to further analyse the "segmented" saccade trajectory (to compute recentering vectors, etc). 
+                Finally, this object is heavily accessed by the GLOBAL INSTANCE of laserSensingDisplay (lsd), which is the "displaying engine" running in an interrupt. 
+*/
+
 #ifndef LSDTRAJECTORY_H
 #define LSDTRAJECTORY_H
 
 #include <vector>
-using namespace std;
+#include "matrixClass.h"
 
 // Thresholding mode: 
 enum thresholdingMode {FIXED, AUTO};
-
-
-//(1) fixed threshold: 
+//(1) fixed threshold (in case of FIXED threshold mode)
 #define FIXED_THRESHOLD 35
-
-//(1) Autothreshold:
+//(2) Autothreshold (in case of AUTO threshold mode):
 // CONTRAST RATIO to compute autoThreshold:
 // MIN_CONTRAST_RATIO is the minimum contrast between max and min intensity necessary to "accept" a black and white zone:
 #define MIN_CONTRAST_RATIO 1.8//1.7 // 3 seems good when lookup table does not work 
@@ -19,16 +25,29 @@
 #define THRESHOLD_FACTOR 0.5 //0.75 // 2/3 or 1/2 are good values 
 #define MIN_ACCEPTABLE_INTENSITY 16 // if maxI< this then we consider all the saccade on something black
 
-
-struct laserSensingPoint {
-    // Position and color (after rendering)
-   unsigned short x, y; // position of the point (after rendering - its integer, because it is in "laser projector pixels")
-    // char color; // per point laser color (not used yet)
-    // Detection:
+// ================= The minimal structure for a "projected/sensed" laser point =================
+typedef struct LaserPoint {
+    //public: 
+   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?)
+   {v2.x=x; v2.y=y;};
+   LaserPoint(V2 _v2) : v2(_v2)
+   {};
+   
+   // 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 
+   // values of the sensed data:
+   void setCoord(const V2& _v2) {v2=_v2;};
+   
+   // Data:
+   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)
+   
+   // Per point displaying attributes: can include color, or polarization, or modulation, but also TIME for posing on the point, etc 
+   // (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).
+   // unsigned char myColor;  // override now by the per-object color property now. 
+   
+    // Sensed intensity for this point (in the future, color?)
     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. 
-    signed char lightZone; // the thresholded light zone (allow for negative values for simply computing "negative" forces - although this is not necessarily the best option)
-};
-
+    signed char lightZone; // the thresholded light zone (allow for negative values?)
+} LaserPoint;
 
 class LaserSensingTrajectory  {
 
@@ -37,11 +56,18 @@
     LaserSensingTrajectory();
     ~LaserSensingTrajectory();
 
+    int size() {return(lsdTrajectory.size());} 
+
     // METHODS:
-    bool processSensedData();
+    bool processSensedData(); // Basic analysis of the saccade (classification into two zones). It return the value of lightTouched for commodity.
+
     void setDelayMirrors(int); // in general, the delay will depend on the number of points being DISPLAYED (in other terms, on the size of lsdTrajectory).
     void addDelayMirrors(int add_delay);
 
+// PARAMETER ADJUSTEMENT FOR SENSING METHODS (note: perhaps better in a separated class?)
+    // NOTE: parameters for sensing the data may depend on the number of points, etc. Therefore, I provide setting methods and instance variables 
+    // for each instance of the class
+ 
     void setThresholdMode(unsigned char value) {modeThreshold=(value>0? AUTO : FIXED);};
     void setFixedThreshold(unsigned char value) {fixedThreshold=value;};
     void setMinContrastRatio(float value) {min_contrast_ratio=value;};
@@ -50,26 +76,25 @@
     void multMinContrastRatio(float multfactor) {min_contrast_ratio*=multfactor;};
     void multThresholdFactor(float multfactor) {threshold_factor*=multfactor;};
 
-    // DATA:
-    vector <laserSensingPoint> lsdTrajectory;
-    unsigned char displayColor; // per blob color
-
-    // software adjustement of mirror delay:
-    unsigned char delayMirrorSamples; // this is required because it will affect the way the blob behaves - it 
-    //could be in the laser renderer, but by putting it here we can have more per-blob fine tunning
-
+ //  PARAMETERS FOR SACCADE ANALYSIS:
+    // Adjustement of mirror delay:
+    unsigned char delayMirrorSamples; // it could be in the laser renderer, but by putting it here we can have more per-object fine tunning
     // parameters for thresholding and thresholding mode:
     thresholdingMode modeThreshold;
     float min_contrast_ratio, threshold_factor, min_acceptable_intensity;
     unsigned char autoThreshold, fixedThreshold; // 0 to 255
     
+    // TRAJECTORY DATA:
+    vector <LaserPoint> lsdTrajectory;
+    //unsigned char displayColor; // per BaseObject color (now in the baseObject class)
+    
     // Statistics and tests:
     //float lightRatio;
     unsigned char maxI, minI;     // Max and Min intensity RATIOS (normalized between 0 and 255)
     bool lightTouched;     // true if something went over the autoThreshold for the whole loop
- //   char coko;
 };
 
 #endif
 
 
+