Eyetribe_Language Tutorials C++

来源:互联网 发布:股票赢家软件 编辑:程序博客网 时间:2024/06/02 01:24

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 SDK’s GazeApi is assumed. 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 thegazeapi_types.h and gazeapi_interfaces.h headers. In the constructor of the class we tell the API to connect to the Eye Tracker server in push mode on the default TCP port6555. The server must be running before we can connect to it. The API automatically sets the version number that is has been released for. The first argument toconnect() is bool push_mode, which is set to true. 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 theon_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 definitionclass MyGaze : public gtl::IGazeListener{    public:        MyGaze();        ~MyGaze();    private:        // IGazeListener        void on_gaze_data( gtl::GazeData const & gaze_data );    private:        gtl::GazeApi m_api;};// --- MyGaze implementationMyGaze::MyGaze(){    // Connect to the server in push mode on the default TCP port (6555)    if( m_api.connect( true ) )    {        // Enable GazeData notifications        m_api.add_listener( *this );    }}MyGaze::~MyGaze(){    m_api.remove_listener( *this );    m_api.disconnect();}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 methodon_tracker_connection_changed(int tracker_state) which is called whenever the device has been (re)connected or disconnected. Thetracker_state argument can be one of the following anonymous enum values

enum{    TRACKER_CONNECTED          = 0,    TRACKER_NOT_CONNECTED      = 1,    TRACKER_CONNECTED_BADFW    = 2,    TRACKER_CONNECTED_NOUSB3   = 3,    TRACKER_CONNECTED_NOSTREAM = 4};

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.

0 0
原创粉丝点击