Getting Data

The TET C++ SDK, which is a reference implementation of the TET API in C++, simplifies the connectivity and communication with the server and allows for straightforward data parsing. In this tutorial the use of the prebuilt C++ GazeApi library is assumed.

To get set up, go to the C++ SDK on GitHub. From here, you will need to clone the C++ SDK project, or download the zipped snapshot of the code. You can either build the C++ GazeApi library manually, or include the source files directly into your own C++ project. Please note that the C++ SDK depends on Boost. For information on obtaining and installing a recent version of Boost, please consult the Boost website.

To get started first include the main gaze api header to the implementation:

#include <gazeapi.h>

Including the gazeapi.h header is sufficient to work with the C++ SDK as it also includes the gazeapi_types.h and gazeapi_interfaces.h headers. In the constructor of MyGaze class we construct the API with no verbose, and tell the API to connect to the Eye Tracker server on the default TCP port 6555. The server must be running before we can connect to it. The API automatically sets the version number that is has been released for. Once the connection has been established we setup a listener for the pushed gaze data. The alternative is to manually fetch gaze data upon request. Objects that wish to automatically receive gaze data should implement the IGazeListener interface. This interface contains the on_gaze_data callback method that will receive the coordinates of the estimated on-screen gaze position, size of the pupils, position relative to the sensor, etc.

Note the Eye Tracker Server must be calibrated before the application can receive any gaze-related details from the GazeData object.

// --- MyGaze definition
class MyGaze : public gtl::IGazeListener
    // IGazeListener
    void on_gaze_data( gtl::GazeData const & gaze_data );
    gtl::GazeApi m_api;

// --- MyGaze implementation
    : m_api( 0 ) // verbose_level 0 (disabled)
    // Connect to the server on the default TCP port (6555)
    if( m_api.connect() )
        // Enable GazeData notifications
        m_api.add_listener( *this );

    m_api.remove_listener( *this );

void MyGaze::on_gaze_data( gtl::GazeData const & gaze_data )
    if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
        gtl::Point2D const & smoothedCoordinates = gaze_data.avg;
        // Move GUI point, do hit-testing, log coordinates, etc.

Additional points of interest

In the SDK we find the ITrackerStateListener inteface which provides the method on_tracker_connection_changed(int tracker_state) which is called whenever the device has been (re)connected or disconnected. The tracker_state argument can be one of the following anonymous enum values

    TRACKER_CONNECTED          = 0,

State needs to be CONNECTED(0) for the server to work. The NOUSB3(3) means that the device has been connected to a USB2 host.