GazeTracker
GazeTrackerDoc.h
1 #include "visageVision.h"
2 #include "Observer.h"
3 #include "Repository.h"
4 #include "GazeRenderer.h"
5 #include "VisageGazeTracker.h"
6 #include "IMouseHandler.h"
7 
8 using namespace VisageSDK;
9 
10 
11 /*! \mainpage visage|SDK GazeTracker example project
12 *
13 * \if WIN64_DOXY
14 * \htmlonly
15 * <table border="0">
16 * <tr>
17 * <td width="32"><a href="../../../../../../bin64/DEMO_GazeTracker_x64.exe"><img src="../../../../../../doc/OpenGL/images/run_sample.png" border=0 title="Run Sample (this may not work in all browsers, in such case please run DEMO_GazeTracker_x64.exe from the visageSDK\bin64 folder.)"></a></td>
18 * <td width="32"><a href="../../../../../../bin64"><img src="../../../../../../doc/OpenGL/images/open_bin_folder.png" border=0 title="Open Binary Folder (visageSDK\bin64)"></a></td>
19 * <td width="32"><a href="../../../../data/GazeTracker"><img src="../../../../../../doc/OpenGL/images/open_data_folder.png" border=0 title="Open Data Folder"></a></td>
20 * <td width="32"><a href="../../../../build/msvc140/GazeTracker"><img src="../../../../../../doc/OpenGL/images/open_project_folder.png" border=0 title="Open Project Folder"></a></td>
21 * <td width="32"><a href="../../../../source/GazeTracker"><img src="../../../../../../doc/OpenGL/images/open_source_folder.png" border=0 title="Open Source Code Folder"></a></td>
22 * </tr>
23 * </table>
24 * \endhtmlonly
25 * \else
26 * \htmlonly
27 * <table border="0">
28 * <tr>
29 * <td width="32"><a href="../../../../../../bin/DEMO_GazeTracker.exe"><img src="../../../../../../doc/OpenGL/images/run_sample.png" border=0 title="Run Sample (this may not work in all browsers, in such case please run DEMO_GazeTracker.exe from the visageSDK\bin folder.)"></a></td>
30 * <td width="32"><a href="../../../../../../bin"><img src="../../../../../../doc/OpenGL/images/open_bin_folder.png" border=0 title="Open Binary Folder (visageSDK\bin)"></a></td>
31 * <td width="32"><a href="../../../../data/GazeTracker"><img src="../../../../../../doc/OpenGL/images/open_data_folder.png" border=0 title="Open Data Folder"></a></td>
32 * <td width="32"><a href="../../../../build/msvc140/GazeTracker"><img src="../../../../../../doc/OpenGL/images/open_project_folder.png" border=0 title="Open Project Folder"></a></td>
33 * <td width="32"><a href="../../../../source/GazeTracker"><img src="../../../../../../doc/OpenGL/images/open_source_folder.png" border=0 title="Open Source Code Folder"></a></td>
34 * </tr>
35 * </table>
36 * \endhtmlonly
37 * \endif
38 *
39 * The GazeTracker example project demonstrates the following capabilities of visage|SDK:
40 *
41 * - online mode of screen space gaze estimation (from the camera).
42 *
43 * <br/><br/>
44 * In order to try the sample application, you need to have a valid license key. More information on how to obtain license key and include it in the application can be found in
45 * <a href="../../../../../../doc/OpenGL/licensing.html"><em>Licensing</em></a> section of the documentation.
46 * <br/><br/>
47 * This sample application works in two phases, static calibration and interactive calibration/estimation.
48 *
49 * In the static calibration phase application displays a calibration point as a red dot on the screen.
50 * After the user has clicked on the dot, the next calibration point in the pattern is displayed.
51 *
52 * After all calibration points are clicked, gaze tracking system is calibrated and second phase starts. In the interactive calibration/estimation phase the application draws the estimated gaze location as a blue dot on the screen. Additionally, the application displays calibration points as red dots on random positions on the screen.
53 * When the user clicks on the calibration dot, the system is recalibrated using all calibration points from the static calibration phase and interactive calibration/estimation phase.
54 *
55 * The application returns to static calibration phase by pressing SPACE button. All previously clicked calibration points are then discarded.
56 *
57 * The specific classes and methods that demonstrate visage|SDK are:
58 * - GazeTrackerDoc::StartGazeTracking(): Contains the main application loop. Initializes the screen space gaze estimation and calibrates screen space gaze estimator.
59 * During the static calibration phase, the method reads calibration points from a Repository object and displays them on screen. <br> During the interactive calibration/estimation phase, the method reads the latest estimated screen space gaze position from Observer object and displays additional calibration points.
60 *
61 * Further classes and methods that are important for detailed understanding how this
62 * sample project is implemented and how it used visage|SDK are:
63 * - Observer::Notify(): Stores gaze estimation results and tracking data for further use.
64 * - GazeRenderer::Redraw(): Draws face tracking data as well as screen space gaze tracking calibration points and results using OpenGL.
65 * - Repository::ReadFromFile(): Reads screen space calibration data from the provided file containing the calibration points.
66 * - GazeTrackerDoc::OnLeftButtonDown(): Handles mouse input from user.
67 *
68 *@see Repository, GazeRenderer, Observer
69 */
70 
71 /**
72 * The document.
73 * Main application document.
74 */
75 class GazeTrackerDoc : public IMouseHandler
76 {
77 public:
78  GazeTrackerDoc(void);
79  ~GazeTrackerDoc(void);
80 
81  /** This method contains the main application loop of the GazeTracker sample application.
82  * This method handles initalization of VisageTracker object, initialization of screen space gaze tracking system, calibration of gaze tracking system and rendering of results.
83  *
84  * The method initalizes screen space gaze tracking system by calling VisageSDK::VisageTracker::InitOnlineGazeCalibration and reads calibration data by calling Repository::ReadFromFile().
85  *
86  * In each iteration of the main application loop method GazeRenderer::Redraw() is called to display the calibration data or the estimated screen space gaze point.
87  * Additonally, the latest tracking data is aquired from Observer and displayed on the screen.
88  **/
89  void StartGazeTracking();
90 
91 
92  /**
93  * This method handles user mouse clicks.
94  *
95  * The method check if the user has clicked on currently displayed calibration point and passes it to the tracker using VisageSDK::VisageTracker::AddGazeCalibrationPoint().
96  *
97  **/
98  void OnLeftButtonDown(float x, float y);
99 
100  void ReadConfig();
101 
102 private:
103  VisageGazeTracker* tracker;
104  Repository* calibrator;
105  Observer* observer;
106  GazeRenderer* renderer;
107  Window* resWindow;
108 
109  ScreenSpaceGazeData* calibration;
110  bool isClicked;
111  bool isCalibrated;
112  int index;
113 
114  void WaitForClick();
115  void PointOutOfScreenFix(float& x, float& y, int width, int height, int pointSize);
116 
117  HANDLE trackingThreadHandle;
118  volatile bool trackerActive;
119  static void trackFromCAM(void *thisdoc);
120  void startTrackingFromCam();
121 };
122 
The document.
Class used to provide calibration data to the screen space gaze tracking system.
Definition: Repository.h:13
Simple OpenGL graphics renderer.
Definition: GazeRenderer.h:10
This implementation is used to demonstrate the use of screen space gaze data returned by the tracker...
Definition: Observer.h:12